void OnBusSyncMessage(object o, SyncMessageArgs sargs) { Gst.Message msg = sargs.Message; if (!Gst.Video.Global.IsVideoOverlayPrepareWindowHandleMessage(msg)) { return; } Element src = msg.Src as Element; if (src == null) { return; } try { src["force-aspect-ratio"] = true; } catch (PropertyNotFoundException) { /* Don't care */ } Element overlay = (src as Gst.Bin)?.GetByInterface(VideoOverlayAdapter.GType); if (overlay == null) { Console.WriteLine("Overlay is null"); return; } VideoOverlayAdapter adapter = new VideoOverlayAdapter(overlay.Handle); adapter.WindowHandle = _videoPanelHandle; adapter.HandleEvents(true); }
static void HandleRealized(object sender, EventArgs e) { var widget = (Widget)sender; var window = widget.Window; IntPtr windowID = IntPtr.Zero; // Retrieve window handler from GDK switch (System.Environment.OSVersion.Platform) { case PlatformID.Unix: windowID = gdk_x11_window_get_xid(window.Handle); break; case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: windowID = gdk_win32_drawable_get_handle(window.Handle); break; } Element overlay = null; if (Playbin is Gst.Bin) { overlay = ((Gst.Bin)Playbin).GetByInterface(VideoOverlayAdapter.GType); } VideoOverlayAdapter adapter = new VideoOverlayAdapter(overlay.Handle); adapter.WindowHandle = windowID; adapter.HandleEvents(true); }
void OnBusSyncMessage(object o, SyncMessageArgs args) { Bus bus = o as Bus; Gst.Message msg = args.Message; if (!Gst.Video.Global.IsVideoOverlayPrepareWindowHandleMessage(msg)) { return; } Element src = msg.Src as Element; if (src == null) { return; } src = _pipeline; Element overlay = null ?? (src as Gst.Bin)?.GetByInterface(VideoOverlayAdapter.GType); Assert(overlay != null, "Overlay is null"); VideoOverlayAdapter adapter = new VideoOverlayAdapter(overlay.Handle); adapter.WindowHandle = _videoPanelHandle; adapter.HandleEvents(true); }
private void OnBusSyncMessage(object o, SyncMessageArgs sargs) { var message = sargs.Message; if (!Gst.Video.Global.IsVideoOverlayPrepareWindowHandleMessage(message)) { return; } var src = message.Src as Element; if (src == null) { return; } try { src["force-aspect-ratio"] = true; } catch { /* ignored */ } _adapter = new VideoOverlayAdapter(src.Handle); _adapter.WindowHandle = _windowHandle; _adapter.HandleEvents(true); }
void HandleRealized(object sender, EventArgs e) { var vpanel = sender as Panel; _videoPanelHandle = vpanel.Handle; Element overlay = ((Gst.Bin)_playbin).GetByInterface(VideoOverlayAdapter.GType); VideoOverlayAdapter adapter = new VideoOverlayAdapter(overlay.Handle); adapter.WindowHandle = _videoPanelHandle; adapter.HandleEvents(true); }
private bool FindXOverlay() { Element video_sink = null; Element xoverlay_element; bool found_xoverlay; video_sink = (Element)playbin ["video-sink"]; lock (video_mutex) { if (video_sink == null) { xoverlay = null; return(false); } xoverlay_element = video_sink is Bin ? ((Bin)video_sink).GetByInterface(VideoOverlayAdapter.GType) : video_sink; if (xoverlay_element == null) { return(false); } xoverlay = new VideoOverlayAdapter(xoverlay_element.Handle); if (!PlatformDetection.IsWindows) { // We can't rely on aspect ratio from dshowvideosink if (xoverlay != null) { try { xoverlay_element ["force-aspect-ratio"] = true; } catch (PropertyNotFoundException) { } } } if (xoverlay != null) { try { xoverlay_element ["handle-events"] = false; } catch (PropertyNotFoundException) { } } found_xoverlay = (xoverlay != null) ? true : false; return(found_xoverlay); } }
public void InitPipeline() { if (IsPlaying) { ChangeStateWithDelay(Gst.State.Null); } PipelineBuilder builder = new PipelineBuilder(); if (recorder) { builder.AppendRecorder(); } pipeline = builder.BuildPipeline(); pipeline.Bus.EnableSyncMessageEmission(); pipeline.Bus.AddSignalWatch(); pipeline.Bus.SyncMessage += delegate(object bus, SyncMessageArgs sargs) { Message msg = sargs.Message; if (!GlobalVideo.IsVideoOverlayPrepareWindowHandleMessage(msg) || !(msg.Src is Element)) { return; } VideoOverlayAdapter adapter = new VideoOverlayAdapter(msg.Src.Handle); adapter.WindowHandle = gdk_x11_window_get_xid(drawing_area.Window.Handle); }; pipeline.Bus.Message += delegate(object bus, MessageArgs margs) { Message message = margs.Message; switch (message.Type) { case Gst.MessageType.Error: GLib.GException err; string msg; message.ParseError(out err, out msg); Console.WriteLine(String.Format("Error message: {0}", msg)); break; case Gst.MessageType.Eos: Console.WriteLine("EOS"); break; } }; }
private void OnBusSyncMessage(object o, SyncMessageArgs sargs) { Bus bus = o as Bus; Gst.Message msg = sargs.Message; if (!Gst.Video.Global.IsVideoOverlayPrepareWindowHandleMessage(msg)) { bus.Dispose(); msg.Dispose(); return; } Element src = msg.Src as Element; if (src == null) { bus.Dispose(); msg.Dispose(); return; } try { src["force-aspect-ratio"] = true; } catch (PropertyNotFoundException ex) { Console.WriteLine(ex.Message, ex); } Element overlay = (_pipeline)?.GetByInterface(VideoOverlayAdapter.GType); var _adapter = new VideoOverlayAdapter(overlay.Handle); _adapter.WindowHandle = _handle; _adapter.HandleEvents(true); bus.Dispose(); msg.Dispose(); overlay?.Dispose(); src?.Dispose(); }
private void Bus_SyncMessage(object o, SyncMessageArgs args) { if (Gst.Video.Global.IsVideoOverlayPrepareWindowHandleMessage(args.Message)) { System.Diagnostics.Debug.WriteLine("Bus_SyncMessage: Message prepare window handle received by: " + args.Message.Src.Name + " " + args.Message.Src.GetType().ToString()); if (args.Message.Src != null) { // these checks were in the testvideosrc example and failed, args.Message.Src is always Gst.Element??? if (args.Message.Src is Gst.Video.VideoSink) System.Diagnostics.Debug.WriteLine("Bus_SyncMessage: source is VideoSink"); else System.Diagnostics.Debug.WriteLine("Bus_SyncMessage: source is NOT VideoSink"); if (args.Message.Src is Gst.Bin) System.Diagnostics.Debug.WriteLine("Bus_SyncMessage: source is Bin"); else System.Diagnostics.Debug.WriteLine("Bus_SyncMessage: source is NOT Bin"); try { args.Message.Src["force-aspect-ratio"] = true; } catch (PropertyNotFoundException) { } try { Gst.Video.VideoOverlayAdapter adapter = new VideoOverlayAdapter(args.Message.Src.Handle); adapter.WindowHandle = windowHandle; adapter.HandleEvents(true); System.Diagnostics.Debug.WriteLine("Bus_SyncMessage: Handle passed to adapter: " + windowHandle.ToString()); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Bus_SyncMessage: Exception Thrown (overlay stage): " + ex.Message); } } } else { string info; IntPtr prt; args.Message.ParseInfo(out prt, out info); System.Diagnostics.Debug.WriteLine("Bus_SyncMessage: " + args.Message.Type.ToString() + " - " + info); } }
void ButtonOpenClicked(object sender, EventArgs args) { FileChooserDialog dialog = new FileChooserDialog ("Open", this, FileChooserAction.Open, new object[] { "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept }); dialog.SetCurrentFolder (Environment.GetFolderPath (Environment.SpecialFolder.Personal)); if (dialog.Run () == (int) ResponseType.Accept) { _pipelineOK = false; if (_playbin != null) { _playbin.SetState (Gst.State.Null); } else { _playbin = ElementFactory.Make ("playbin", "playbin"); } _scale.Value = 0; if (_playbin == null) Console.WriteLine ("Unable to create element 'playbin'"); _playbin.Bus.EnableSyncMessageEmission (); _playbin.Bus.AddSignalWatch (); _playbin.Bus.SyncMessage += delegate (object bus, SyncMessageArgs sargs) { Gst.Message msg = sargs.Message; if (!Gst.Video.GlobalVideo.IsVideoOverlayPrepareWindowHandleMessage (msg)) return; Element src = msg.Src as Element; if (src == null) return; try { src["force-aspect-ratio"] = true; } catch (PropertyNotFoundException) {} Element overlay = null; if(src is Gst.Bin) overlay = ((Gst.Bin) src).GetByInterface (VideoOverlayAdapter.GType); VideoOverlayAdapter adapter = new VideoOverlayAdapter (overlay.Handle); adapter.WindowHandle = _xWindowId; adapter.HandleEvents (true); }; _playbin.Bus.Message += delegate (object bus, MessageArgs margs) { Message message = margs.Message; switch (message.Type) { case Gst.MessageType.Error: GLib.GException 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; } }; switch (System.Environment.OSVersion.Platform) { case PlatformID.Unix: _playbin["uri"] = "file://" + dialog.Filename; break; case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: _playbin["uri"] = "file:///" + dialog.Filename.Replace("\\","/"); break; } StateChangeReturn sret = _playbin.SetState (Gst.State.Playing); if (sret == StateChangeReturn.Async) { State state, pending; sret = _playbin.GetState (out state, out pending, Constants.SECOND * 5L); } if (sret == StateChangeReturn.Success) { Console.WriteLine ("State change successful"); _pipelineOK = true; } else { Console.WriteLine ("State change failed for {0} ({1})\n", dialog.Filename, sret); } } dialog.Destroy (); }
void ButtonOpenClicked(object sender, EventArgs args) { FileChooserDialog dialog = new FileChooserDialog("Open", this, FileChooserAction.Open, new object[] { "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept }); dialog.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); if (dialog.Run() == (int)ResponseType.Accept) { _pipelineOK = false; if (_playbin != null) { _playbin.SetState(Gst.State.Null); } else { _playbin = ElementFactory.Make("playbin", "playbin"); } _scale.Value = 0; if (_playbin == null) { Console.WriteLine("Unable to create element 'playbin'"); } _playbin.Bus.EnableSyncMessageEmission(); _playbin.Bus.AddSignalWatch(); _playbin.Bus.SyncMessage += delegate(object bus, SyncMessageArgs sargs) { Gst.Message msg = sargs.Message; if (!Gst.Video.GlobalVideo.IsVideoOverlayPrepareWindowHandleMessage(msg)) { return; } Element src = msg.Src as Element; if (src == null) { return; } try { src["force-aspect-ratio"] = true; } catch (PropertyNotFoundException) {} Element overlay = null; if (src is Gst.Bin) { overlay = ((Gst.Bin)src).GetByInterface(VideoOverlayAdapter.GType); } VideoOverlayAdapter adapter = new VideoOverlayAdapter(overlay.Handle); adapter.WindowHandle = _xWindowId; adapter.HandleEvents(true); }; _playbin.Bus.Message += delegate(object bus, MessageArgs margs) { Message message = margs.Message; switch (message.Type) { case Gst.MessageType.Error: GLib.GException 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; } }; switch (System.Environment.OSVersion.Platform) { case PlatformID.Unix: _playbin["uri"] = "file://" + dialog.Filename; break; case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: _playbin["uri"] = "file:///" + dialog.Filename.Replace("\\", "/"); break; } StateChangeReturn sret = _playbin.SetState(Gst.State.Playing); if (sret == StateChangeReturn.Async) { State state, pending; sret = _playbin.GetState(out state, out pending, Constants.SECOND * 5L); } if (sret == StateChangeReturn.Success) { Console.WriteLine("State change successful"); _pipelineOK = true; } else { Console.WriteLine("State change failed for {0} ({1})\n", dialog.Filename, sret); } } dialog.Destroy(); }
static void HandleRealized(object sender, EventArgs e) { var widget = (Widget)sender; var window = widget.Window; IntPtr windowID = IntPtr.Zero; // Retrieve window handler from GDK switch (System.Environment.OSVersion.Platform) { case PlatformID.Unix: windowID = gdk_x11_window_get_xid (window.Handle); break; case PlatformID.Win32NT: case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: windowID = gdk_win32_drawable_get_handle (window.Handle); break; } Element overlay = null; if(Playbin is Gst.Bin) overlay = ((Gst.Bin) Playbin).GetByInterface (VideoOverlayAdapter.GType); VideoOverlayAdapter adapter = new VideoOverlayAdapter (overlay.Handle); adapter.WindowHandle = windowID; adapter.HandleEvents (true); }
internal void InvalidateOverlay() { lock (video_mutex) { xoverlay = null; } }
// Test Server: // gst-launch-1.0 videotestsrc ! openh264enc ! h264parse ! rtph264pay ! udpsink host=127.0.0.1 port=5555 // Client stream with recording and showing: // gst-launch-1.0 -vvv -e udpsrc caps=\"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264\" port=5555 ! // rtph264depay ! h264parse ! tee name=videoTee videoTee. ! queue ! mp4mux ! filesink location=test.mp4 videoTee. ! queue ! avdec_h264 ! d3dvideosink /// <summary> /// A window that is separate from the main UI and plays a GStreamer RTP feed. /// </summary> /// <param name="Port"> The port that the RTP stream is sending data to. </param> /// <param name="BufferSizeMs"> The time in milliseconds of buffering of the feed. </param> public RTPVideoWindow(int Port, string StreamName, string RecordingPath, int BufferSizeMs = 200) { DataContext = this; this.Port = Port; this.StreamName = StreamName; this.BufferSizeMs = BufferSizeMs; this.RecordingPath = RecordingPath; Pipeline = new Pipeline(); Window window = GetWindow(this); WindowInteropHelper wih = new WindowInteropHelper(this); wih.EnsureHandle(); // Generate Window Handle if current HWND is NULL (always occurs because background window) VideoOverlayAdapter overlay = new VideoOverlayAdapter(VideoSink.Handle); overlay.WindowHandle = wih.Handle; // Allow forwarding of EOS to all elements in the pipeline for shutdown Pipeline["message-forward"] = true; UDP["port"] = Port; UDP["caps"] = Caps; JitterBuffer["latency"] = BufferSizeMs; FileSink["location"] = RecordingPath + GetRecordingFilename(); Filter["caps"] = FilterCaps; Pipeline.Add(UDP, JitterBuffer, Depay, Parse, Tee, Q1, Filter, Mux, FileSink, Q2, Dec, VideoSink); if (!Element.Link(UDP, JitterBuffer, Depay, Parse, Tee)) { Console.WriteLine("Failed To Link UDP, JitterBufferm, Depay, Parser, Tee"); } //if(!Parse.Link(Tee)) { Console.WriteLine("Failed To Link Parser to Tee"); } if (!Element.Link(Q1, Filter, Mux, FileSink)) { Console.WriteLine("Failed To Link Queue1, Mux, FileSink"); } if (!Element.Link(Q2, Dec, VideoSink)) { Console.WriteLine("Failed To Link Queue2, Decoder, VideoSink"); } PadTemplate TeeSrcPadTemplate = Tee.GetPadTemplate("src_%u"); Pad TeeQ1Pad = Tee.RequestPad(TeeSrcPadTemplate); Pad Q1Pad = Q1.GetStaticPad("sink"); Pad TeeQ2Pad = Tee.RequestPad(TeeSrcPadTemplate); Pad Q2Pad = Q2.GetStaticPad("sink"); if (TeeQ1Pad.Link(Q1Pad) != PadLinkReturn.Ok) { Console.WriteLine("Failed To Link Tee to Queue1"); } if (TeeQ2Pad.Link(Q2Pad) != PadLinkReturn.Ok) { Console.WriteLine("Failed To Link Tee to Queue2"); } Q1Pad.Unref(); Q2Pad.Unref(); Pipeline.SetState(State.Null); Closing += OnCloseEvent; InitializeComponent(); }
private bool FindXOverlay() { Element video_sink = null; Element xoverlay_element; bool found_xoverlay; video_sink = (Element)playbin ["video-sink"]; lock (video_mutex) { if (video_sink == null) { xoverlay = null; return false; } xoverlay_element = video_sink is Bin ? ((Bin)video_sink).GetByInterface (VideoOverlayAdapter.GType) : video_sink; if (xoverlay_element == null) { return false; } xoverlay = new VideoOverlayAdapter (xoverlay_element.Handle); if (!PlatformDetection.IsWindows) { // We can't rely on aspect ratio from dshowvideosink if (xoverlay != null) { try { xoverlay_element ["force-aspect-ratio"] = true; } catch (PropertyNotFoundException) { } } } if (xoverlay != null) { try { xoverlay_element ["handle-events"] = false; } catch (PropertyNotFoundException) { } } found_xoverlay = (xoverlay != null) ? true : false; return found_xoverlay; } }