Subscribe to bus messages, no events fired

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Subscribe to bus messages, no events fired

testermax
Hi,

I`m currently working on a C# WPF application. I need to subscribe to error messages etc. that the bus submitts.
I can currently only recieve messages from the "SyncMessage" event, but not the "Message" event...

Whatever I do to try to fire an error state, the message handler wont trigger.
How can I get the message event to fire?

public GstreamPlayer()
        {
            InitializeComponent();

            // Handle usercontrol errors in designmode
            if (DesignerProperties.GetIsInDesignMode(this)) return;

            Loaded += GstreamPlayer_Loaded;
            // Initialize Gstreamer
            Gst.Application.Init();

            // Enable detailed debug info from Gstreamer
            Debug.SetActive(true);

            // Setup Playbin element
            _playbin = ElementFactory.Make("playbin", "playbin");
            _playbin.Bus.EnableSyncMessageEmission();
            _playbin.Bus.AddSignalWatch();
           
            // Playbin syncmessage handler
            _playbin.Bus.SyncMessage += delegate (object bus, SyncMessageArgs sargs)
            {
                var msg = sargs.Message;

                if (!Gst.Video.Global.IsVideoOverlayPrepareWindowHandleMessage(msg))
                    return;

                var src = msg.Src as Element;
                if (src == null)
                    return;

                try
                {
                    src["force-aspect-ratio"] = true;
                }
                catch (PropertyNotFoundException) { }
                Element overlay = null;
                if (src is Bin)
                    overlay = ((Bin)src).GetByInterface(VideoOverlayAdapter.GType);

                // Bind GStreamer Windowhandle to winform control handle
                var adapter = new VideoOverlayAdapter(overlay.Handle) {WindowHandle = _videoDisplayHandle};
                adapter.HandleEvents(true);
            };
           

            // Playbin Bus message handler
            _playbin.Bus.Message += delegate (object bus, MessageArgs margs) {
                Message message = margs.Message;

                switch (message.Type)
                {
                   case MessageType.Error:
                        GLib.GException err;
                        string msg;

                        message.ParseError(out err, out msg);
                        Console.WriteLine($"Error message: {msg}");
                        break;

                    case Gst.MessageType.Eos:
                        Console.WriteLine("End of Stream");
                        break;
                }
            };

        }
Reply | Threaded
Open this post in threaded view
|

Re: Subscribe to bus messages, no events fired

Tim Müller
On Mon, 2017-08-21 at 09:48 -0700, testermax wrote:

Hi Joachim,

> I`m currently working on a C# WPF application. I need to subscribe to
> error messages etc. that the bus submitts.
> I can currently only recieve messages from the "SyncMessage" event,
> but not the "Message" event...
>
> Whatever I do to try to fire an error state, the message handler wont
> trigger. How can I get the message event to fire?

Bus.AddSignalWatch() requires a running GLib (or Gtk+) main loop
running to work.

On a side note, the playbin element itself implements the
GstVideoOverlay interface as well, so you don't have to wait for a
prepare-window-handle sync message, but can just set things directly on
it and it will proxy it to any sinks later.

Cheers
 -Tim

--
Tim Müller, Centricular Ltd - http://www.centricular.com

Join us at the GStreamer Conference!
21-22 October 2017 in Prague, Czech Republic
http://gstreamer.freedesktop.org/conference/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Subscribe to bus messages, no events fired

testermax
Hi Tim,

Thank you for your tip regarding the playbin and the prepare-window-handle event!

My goal is to have a lean implementation,with as few dependencies as possible, while
being notified when the stream is interupted, or other errors occurs, and be able to resume when the stream is back.

Is this possible while only depend on gst library?

My code so far...

 public GstreamPlayer()
        {
            InitializeComponent();

            Loaded += GstreamPlayer_Loaded;
            // Initialize Gstreamer
            Gst.Application.Init();
           
            // Enable detailed debug info from Gstreamer
            Debug.SetActive(true);

            // Setup Playbin element
            _playbin = ElementFactory.Make("playbin", "playbin");
           
        }

        // Get winform control (panel) handle
        private void GstreamPlayer_Loaded(object sender, RoutedEventArgs e)
        {
            // Playbin implements GstVideoOverlay interface, prepare-window-handle not neccessary
            _videoDisplayHandle = (ulong)VideoDisplay.Handle;
            _adapter = new VideoOverlayAdapter(_playbin.Handle) { WindowHandle = _videoDisplayHandle };
            _adapter.HandleEvents(true);
        }

Reply | Threaded
Open this post in threaded view
|

Re: Subscribe to bus messages, no events fired

Tim Müller
On Tue, 2017-08-22 at 06:51 -0700, testermax wrote:

Hi,

> My goal is to have a lean implementation,with as few dependencies as
> possible, while being notified when the stream is interupted, or
> other errors occurs, and be able to resume when the stream is back.
>
> Is this possible while only depend on gst library?

GStreamer depends on GLib, so that dependency will always be there no
matter what (pretty much the only hard depdency it has).

You don't have to run a GLib main loop (event loop) to get messages
from a GstBus, but Bus.AddSignalWatch() relies on it.

There are other ways, you can just manually check the bus for messages
with Bus.Pop() or Bus.TimedPop() from time to time when it's convenient
for you. If you have your own event loop, you can also schedule an
event from the sync message handler so that the event loop is woken up
in the main thread and can process the message from there.

Cheers
 -Tim

--
Tim Müller, Centricular Ltd - http://www.centricular.com

Join us at the GStreamer Conference!
21-22 October 2017 in Prague, Czech Republic
http://gstreamer.freedesktop.org/conference/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel