[gst-devel] How can I have two main loops in my program??

Tim-Philipp Müller t.i.m at zen.co.uk
Tue Mar 16 12:52:37 CET 2010


On Tue, 2010-03-16 at 02:36 -0800, wanting2learn wrote:

> Hi I have a program with its own main 'while' loop that must be executed for
> my program to work.
> 
> I wish to add also a  g_main_loop_run (loop) so that I can monitor gstreamer
> event messages as in
> :http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-helloworld.html
> 
> Is it possible to have two loops running in my program.  I have tried adding
> the code to let me monitor messages but I can't seem to get it to work.
> (i.e. I cant seem to get any messages in my bus_call function)
> 
> I guess my question is: Can I have a g_main_loop_run as well as my own while
> loop?  Or will g_main_loop_run block my program?

You don't need to run a GLib main loop to monitor messages on the
pipeline bus. It's how it's often done, especially with GUI
applications, but it's not the only way. You could just check for
messages using something like

  while ((msg = gst_bus_pop (bus))) {
    ... handle message ...
    gst_message_unref (msg);
  }

once in a while (if there is already another main loop, I'm sure you can
set up a timer or something).

 Cheers
  -Tim





More information about the gstreamer-devel mailing list