I’m developing a C# WPF application using OSSBuild and gstreamersharp. I’m using XOverlayAdapter to display video on a hosted WindowsForms control to which I have a Windows handle. Everything is working nicely except the situation when I set the playbin2 state to NULL or READY. This is exactly what I’m doing (I stripped out all checks if the elements have been created correctly):
-
Create a playbin
Gst.BasePlugins.PlayBin2 playBin = new Gst.BasePlugins.PlayBin2(); playBin.PlayFlags &= ~((Gst.BasePlugins.PlayBin2.PlayFlagsType)(1 << 2)); playBin.Bus.AddSignalWatch(); playBin.Bus.EnableSyncMessageEmission(); playBin.Bus.Message += new Gst.MessageHandler(OnPlayBinMessage); -
Create a videosink
Gst.Video.VideoSink videoSink = Gst.ElementFactory.Make("dshowvideosink") as Gst.Video.VideoSink; videoSink["force-aspect-ratio"] = true; -
Associate the videosink with a WindowsForms control (screen) to display the video in a rectangular area in my WPF window.
Gst.Interfaces.XOverlayAdapter overlayAdapter = new Gst.Interfaces.XOverlayAdapter(videoSink.Handle); overlayAdapter.XwindowId = (ulong)screen.Handle; -
Attach the videosink to the playbin
playBin.VideoSink = videoSink; -
Set playbin’s URI to some video file on my hard drive
playBin.SetState(Gst.State.Ready); playBin.Uri = @"file:///" + fileName.Replace('\\', '/'); playBin.SetState(Gst.State.Paused); -
Now I can play and pause the video by changing the state of the playbin
playBin.SetState(Gst.State.Playing); playBin.SetState(Gst.State.Paused);So far so good, everything is working smoothly, I can play, pause, seek the video displayed in a rectangular area in my window. The problems start when I try to play another video file. According to all manuals found on the net, I should set the pipeline state to NULL or READY before changing the URI:
-
Open another video file
playBin.SetState(Gst.State.Ready); playBin.Uri = @"file:///" + newFileName.Replace('\\', '/'); playBin.SetState(Gst.State.Playing);
Unfortunately this causes the rectangular area in my window to become black and a separate window created by GStreamer. It has nothing to do with changing the URI, it is setting the playbin state to NULL or READY which disconnects the video output from the overlay. What am I doing wrong?
The solution is to prevent the videosink from changing its state.
Credit to Stefan Sauer from the gstreamer-devel mailing list.