[gst-devel] GStreamer in double loop

Jan Schmidt thaytan at noraisin.net
Thu Jun 18 18:57:14 CEST 2009

On Thu, 2009-06-18 at 10:21 -0600, Jeffrey Barish wrote:
> GStreamer requires gobject.  gobject runs in a loop, normally by calling the
> run method on the main loop.  That loop blocks until there is something to
> do.  I also need to monitor sockets over which I send commands about what
> GStreamer is supposed to do.  Normally, it runs in a loop that blocks until
> a command arrives on a socket.  It is not possible to run both of these
> loops in the same thread using the normal procedure because they both
> block.  One possibility is to perform the looping manually.  gobject has a
> method that makes it possible to perform an iteration of the context.  I
> could check the sockets and then perform an iteration that blocks.  I would
> repeat those two steps every time a message arrives from gobject.  But
> there are long periods when no messages arrive, so I could be missing
> commands that have arrived on a socket while I am waiting for a GStreamer
> message.  If I make the iteration nonblocking, then the loop will buzz too
> quickly and the CPU load will go to 100%.  If I put in a sleep, I can get
> the CPU load under control, but then I will be missing both GStreamer
> messages and socket commands while sleeping.  If I block on the socket
> access, I could be tardy in responding to GStreamer messages.  So this
> approach doesn't work.

You can use GLib's GIOChannel API to register the socket file
descriptor, and get the GObject mainloop to poll it for you efficiently.

See g_io_channel_unix_new () and g_io_add_watch ()

Jan Schmidt <thaytan at noraisin.net>

More information about the gstreamer-devel mailing list