Combining GStreamer, AnyEvent and EV (perl)

I am trying to use GStreamer in an existing perl application that uses AnyEvent with an EV event loop. This is not a Glib application. I downloaded EV :: Glib to get the main Glib loop to use EV. I freely admit that with regard to Glib, I am rather ignorant. I think I have all the bits that I need, but I struggle (can't) get them to work together.

If I use the standalone perl program to build the GStreamer pipeline and then put it in the PLAYING state, it all just works. I don't need to do anything with Glib mainloop or tickle the GStreamer bus otherwise.

Building the same pipeline in my existing application in the context of an AnyEvent event handler, then it will not be able to execute the pipeline. I played with various ways trying to use it, including calling $pipeline->get_bus->poll() . If I repeat ...->poll() in the original event handler (i.e. the handler does not return), then it works, but this is clearly an invalid solution. Calling ...->poll() in the AnyEvent timer callback does not start the pipeline.

My best guess at the moment is that EV :: Glib provides some level of integration, but does not actually run the necessary bits of the main loop. What am I missing?

+4
source share
2 answers

I came here with a similar question regarding the use of EV :: Glib, but in the end I had no problems using it. Perhaps I am missing what you are trying to do here.

Here is a simple script I knocked to check how EV :: Glib works:

 use EV::Glib; use Gtk2 '-init'; my $t = EV::timer 1, 1, sub { print "I am here!\n" }; Glib::Timeout->add(1000, sub { print "I am also here!\n" }); my $window = Gtk2::Window->new('toplevel'); $window->signal_connect(delete_event => sub { EV::unloop }); my $button = Gtk2::Button->new('Action'); $button->signal_connect(clicked => sub { print("Hello Gtk2-EV-Perl\n"); }); $window->add($button); $window->show_all; EV::loop; 

In this case, the signal handler on the button will work, and so will both timer events. Thus, the EV cycle will correctly manage everything.

The main problem that I see in the documentation : "This [module] makes Glib compatible with EV. A call to the main Glib loop is more or less equivalent to EV :: loop calls (but not vice versa, you need to use the Glib mainloop functions)." This means that if you attach the EV :: loop event, it will not match Glib :: mainloop and therefore may not “tickle” (or “tickle”) your GStreamer event. Perhaps this may be the problem you are facing, especially if you use AnyEvent and its generic callbacks, which probably go to EV :: loop calls instead of Glib :: MainLoop calls.

This is just an assumption - I never used GStreamer myself, and I certainly don’t know what you are trying to achieve without seeing more code. But I think my final conclusion is pretty sound advice regardless: if you use something specific for Glib, you should probably connect events to it using Glib.

0
source

EV :: Glib embeds Glib in EV - you (and everyone else) must use EV to make it work. Most likely gstreamer does not know about this and disrespectfully calls the glib mainloop functions inside, which does not work.

Fortunately, there is another module that does just the opposite: Glib :: EV. This module makes use of Glib EV internally. When using it, you can / should use the glib functions of mainloop (you can use EV observers, but you cannot call glib functions from EV callbacks, since glib does not support this).

This may be better suited to your application, since applications using glib will “just work” because using EV is completely internal.

Another possible problem is that perl modules are dynamically linked and only "accidentally" get the same library. In order for this to work, you need to make sure that all perl modules are linked to one common glib library.

0
source

All Articles