summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2009-10-02 11:53:09 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-10-02 11:53:09 +0200
commita8161aaf9dd8ec0d731ffa7ab422b87111b1bad4 (patch)
tree408ad73acf5fec32c107d60ff8de993df90d0d1b
parentaff62828ea66aced8c4be2e5cd16b4fec53c6246 (diff)
Updating GtkVideoPlayer sample
Handle bus messages, set the XWindowID from a sync handler, use playbin2, ...
-rw-r--r--samples/GtkVideoPlayer.cs113
-rw-r--r--samples/Makefile.am20
2 files changed, 82 insertions, 51 deletions
diff --git a/samples/GtkVideoPlayer.cs b/samples/GtkVideoPlayer.cs
index e04b569..395bfff 100644
--- a/samples/GtkVideoPlayer.cs
+++ b/samples/GtkVideoPlayer.cs
@@ -10,7 +10,8 @@ using Gst.BasePlugins;
public class MainWindow : Gtk.Window {
DrawingArea _da;
- Pipeline _pipeline;
+ ulong _xWindowId;
+ PlayBin2 _playbin;
HScale _scale;
Label _lbl;
bool _updatingScale;
@@ -21,6 +22,19 @@ public class MainWindow : Gtk.Window {
Gst.Application.Init ();
MainWindow window = new MainWindow ();
window.ShowAll ();
+
+ switch (System.Environment.OSVersion.Platform) {
+ case PlatformID.Unix:
+ window._xWindowId = gdk_x11_drawable_get_xid (window._da.GdkWindow.Handle);
+ break;
+ case PlatformID.Win32NT:
+ case PlatformID.Win32S:
+ case PlatformID.Win32Windows:
+ case PlatformID.WinCE:
+ window._xWindowId = (ulong) gdk_win32_drawable_get_handle (window._da.GdkWindow.Handle);
+ break;
+ }
+
Gtk.Application.Run ();
}
@@ -31,6 +45,7 @@ public class MainWindow : Gtk.Window {
_da = new DrawingArea ();
_da.ModifyBg (Gtk.StateType.Normal, new Gdk.Color (0, 0, 0));
_da.SetSizeRequest (400, 300);
+ _da.DoubleBuffered = false;
vBox.PackStart (_da);
_scale = new HScale (0, 1, 0.01);
@@ -75,6 +90,13 @@ public class MainWindow : Gtk.Window {
void OnDeleteEvent (object sender, DeleteEventArgs args) {
Gtk.Application.Quit ();
+
+ if (_playbin != null) {
+ _playbin.SetState (Gst.State.Null);
+ _playbin.Dispose ();
+ _playbin = null;
+ }
+
args.RetVal = true;
}
@@ -85,47 +107,56 @@ public class MainWindow : Gtk.Window {
if (dialog.Run () == (int) ResponseType.Accept) {
_pipelineOK = false;
- if (_pipeline != null) {
- _pipeline.SetState (Gst.State.Null);
- _pipeline.Dispose ();
+ if (_playbin != null) {
+ _playbin.SetState (Gst.State.Null);
+ } else {
+ _playbin = new PlayBin2 ();
}
_scale.Value = 0;
- _pipeline = new Pipeline (string.Empty);
+ if (_playbin == null)
+ Console.WriteLine ("Unable to create element 'playbin'");
- Element playbin = ElementFactory.Make ("playbin", "playbin");
- XvImageSink sink = XvImageSink.Make ("sink");
+ _playbin.Bus.EnableSyncMessageEmission ();
+ _playbin.Bus.AddSignalWatch ();
- if (_pipeline == null)
- Console.WriteLine ("Unable to create pipeline");
- if (playbin == null)
- Console.WriteLine ("Unable to create element 'playbin'");
- if (sink == null)
- Console.WriteLine ("Unable to create element 'sink'");
-
- _pipeline.Add (playbin);
-
- switch (System.Environment.OSVersion.Platform) {
- case PlatformID.Unix:
- (sink as XOverlay).XwindowId = gdk_x11_drawable_get_xid (_da.GdkWindow.Handle);
- break;
- case PlatformID.Win32NT:
- case PlatformID.Win32S:
- case PlatformID.Win32Windows:
- case PlatformID.WinCE:
- (sink as XOverlay).XwindowId = (ulong) gdk_win32_drawable_get_handle (_da.GdkWindow.Handle);
- break;
- }
+ _playbin.Bus.SyncMessage += delegate (object bus, SyncMessageArgs sargs) {
+ Gst.Message msg = sargs.Message;
+ if (msg == null || msg.Type != Gst.MessageType.Element ||
+ msg.Structure == null || msg.Structure.Name == null ||
+ !msg.Structure.Name.Equals ("prepare-xwindow-id"))
+ return;
+
+ (msg.Src as XOverlay).XwindowId = _xWindowId;
+ (msg.Src as XOverlay).HandleEvents (true);
+ };
+
+ _playbin.Bus.Message += delegate (object bus, MessageArgs margs) {
+ Message message = margs.Message;
+
+ switch (message.Type) {
+ case Gst.MessageType.Error:
+ Enum err;
+ string msg;
+
+ message.ParseError (out err, out msg);
+ Console.WriteLine (String.Format ("Error message: {0}", msg));
+ _pipelineOK = false;
+ break;
+ case Gst.MessageType.Eos:
+ Console.WriteLine ("EOS");
+ break;
+ }
+ };
- playbin["video-sink"] = sink;
- playbin["uri"] = "file://" + dialog.Filename;
+ _playbin["uri"] = "file://" + dialog.Filename;
- StateChangeReturn sret = _pipeline.SetState (Gst.State.Playing);
+ StateChangeReturn sret = _playbin.SetState (Gst.State.Playing);
if (sret == StateChangeReturn.Async) {
State state, pending;
- sret = _pipeline.GetState (out state, out pending, Clock.Second * 5);
+ sret = _playbin.GetState (out state, out pending, Clock.Second * 5);
}
if (sret == StateChangeReturn.Success)
@@ -138,13 +169,13 @@ public class MainWindow : Gtk.Window {
}
void ButtonPlayClicked (object sender, EventArgs args) {
- if ( (_pipeline != null) && _pipelineOK)
- _pipeline.SetState (Gst.State.Playing);
+ if ( (_playbin != null) && _pipelineOK)
+ _playbin.SetState (Gst.State.Playing);
}
void ButtonPauseClicked (object sender, EventArgs args) {
- if ( (_pipeline != null) && _pipelineOK)
- _pipeline.SetState (Gst.State.Paused);
+ if ( (_playbin != null) && _pipelineOK)
+ _playbin.SetState (Gst.State.Paused);
}
void ScaleValueChanged (object sender, EventArgs args) {
@@ -154,20 +185,20 @@ public class MainWindow : Gtk.Window {
long duration;
Gst.Format fmt = Gst.Format.Time;
- if ( (_pipeline != null) && _pipelineOK && _pipeline.QueryDuration (ref fmt, out duration)) {
+ if ( (_playbin != null) && _pipelineOK && _playbin.QueryDuration (ref fmt, out duration) && duration != -1) {
long pos = (long) (duration * _scale.Value);
- //Console.WriteLine ("Seek to {0}/{1} ({2}%)", pos, duration, _scale.Value);
+ Console.WriteLine ("Seek to {0}/{1} ({2}%)", pos, duration, _scale.Value);
- _pipeline.Seek (Format.Time, SeekFlags.Flush, pos);
+ _playbin.Seek (Format.Time, SeekFlags.Flush | SeekFlags.KeyUnit, pos);
}
}
bool UpdatePos () {
Gst.Format fmt = Gst.Format.Time;
long duration, pos;
- if ( (_pipeline != null) && _pipelineOK &&
- _pipeline.QueryDuration (ref fmt, out duration) &&
- _pipeline.QueryPosition (ref fmt, out pos)) {
+ if ( (_playbin != null) && _pipelineOK &&
+ _playbin.QueryDuration (ref fmt, out duration) &&
+ _playbin.QueryPosition (ref fmt, out pos)) {
_lbl.Text = string.Format ("{0} / {1}", TimeString (pos), TimeString (duration));
_updatingScale = true;
diff --git a/samples/Makefile.am b/samples/Makefile.am
index 5c16985..f9e05c8 100644
--- a/samples/Makefile.am
+++ b/samples/Makefile.am
@@ -17,34 +17,34 @@ assemblies=$(top_builddir)/gstreamer-sharp/gstreamer-sharp.dll
references=$(addprefix -r:, $(assemblies)) $(GLIB_SHARP_LIBS)
playbin-player.exe: $(srcdir)/PlayBinPlayer.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/PlayBinPlayer.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/PlayBinPlayer.cs
decodebin-transcoder.exe: $(srcdir)/DecodeBinTranscoder.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/DecodeBinTranscoder.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/DecodeBinTranscoder.cs
helloworld.exe: $(srcdir)/HelloWorld.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/HelloWorld.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/HelloWorld.cs
typefind.exe: $(srcdir)/TypeFind.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/TypeFind.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/TypeFind.cs
queueexample.exe: $(srcdir)/QueueExample.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/QueueExample.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/QueueExample.cs
metadata.exe: $(srcdir)/MetaData.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/MetaData.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/MetaData.cs
mp3launchparse.exe: $(srcdir)/MP3LaunchParse.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/MP3LaunchParse.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(srcdir)/MP3LaunchParse.cs
appsrc.exe: $(srcdir)/AppSrc.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(MONO_CAIRO_LIBS) $(srcdir)/AppSrc.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(MONO_CAIRO_LIBS) $(srcdir)/AppSrc.cs
transform-sample.exe: $(srcdir)/TransformSample.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(MONO_CAIRO_LIBS) $(srcdir)/TransformSample.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(MONO_CAIRO_LIBS) $(srcdir)/TransformSample.cs
gtk-video-player.exe: $(srcdir)/GtkVideoPlayer.cs $(assemblies)
- $(CSC) -out:$@ $(GLIBSHARP_LIBS) $(references) $(GTK_SHARP_LIBS) $(srcdir)/GtkVideoPlayer.cs
+ $(CSC) -debug -out:$@ $(GLIBSHARP_LIBS) $(references) $(GTK_SHARP_LIBS) $(srcdir)/GtkVideoPlayer.cs
link:
ln -sf $(top_builddir)/gstreamer-sharp/gstreamer-sharp.dll gstreamer-sharp.dll