[gst-devel] GStreamer in double loop

Jeffrey Barish jeff_barish at earthlink.net
Sat Jun 20 18:21:47 CEST 2009


Arnout Vandecappelle wrote:

>  [This is actually not about GStreamer anymore, but what the heck.]
> 
> On Friday 19 June 2009 00:48:39 Jeffrey Barish wrote:
>> Here's what's baffling me.  This works:
>>
>>         loop = gobject.MainLoop()
>>         context = loop.get_context()
>>         while True:
>>             context.iteration(False)
>>             time.sleep(1.0)
>>
>> This doesn't:
>>
>>         loop = gobject.MainLoop()
>>         context = loop.get_context()
>>         while True:
>>             context.iteration(True)
> 
>  Since you haven't registered any sources for the main loop, it will block
> forever.  And unless you created another thread or signal handler
> somewhere that calls loop.quit(), there is no way to get out of it.
> 
>> The difference is that the second one blocks on the iteration.  What is
>> it about blocking that is incompatible with running this code in its own
>> thread?
> 
>  AFAIK mainloops aren't really meant to be controlled from multiple
>  threads.
> Inside the context.iteration(True), the mainloop will block waiting for an
> event on any of its registered sources.  Once it's blocking, I don't think
> adding a source from another thread interrupts the block.  You'd probably
> need to do a loop.quit() and re-run the mainloop.

Thanks again for the suggestion.  I did register a source for the main loop,
I just didn't show that code.  Neither of the two versions would work
without a source.  The source is playbin2, which is instantiated in the
main thread (as both loops need to communicate with it).  I serialize
communication with playbin2 from the two threads using a thread-safe queue
(except that for some reason it does not work to set a property on playbin2
(e.g., 'uri') through the queue, so I set that one directly).  Now that the
code is working, I can tell you that the gobject loop is getting messages
from playbin2 even though they are in different threads.

I solved the problem by adding a gobject.threads_init call.  I believe that
this call is required only by the Python bindings for gobject.

The only remaining problem of which I am aware (aside from the strangeness
with setting the uri property) is this error message:

Received message [<GstGError at 0x9ebaf90>, 'gstbin.c(2240):
gst_bin_do_latency_func (): /GstPlayBin2:player:\nFailed to configure
latency of 0:00:00.000000000']

I get this error message at every segue.  Anyone know what it means?
-- 
Jeffrey Barish





More information about the gstreamer-devel mailing list