'gst_bus_add_watch' not getting bus messages

Tim-Philipp Müller t.i.m at zen.co.uk
Tue Dec 4 04:37:23 PST 2012

On Tue, 2012-12-04 at 01:12 -0800, deepthips wrote:


> I am using 'gst_bus_add_watch' for monitoring bus messages. For a long time,
> I had  an issue that the bus call function was not getting called. Tried
> gst_bus_set_sync_handler as well. Then found the root issue to be a sleep in
> the main function. Found that the sleep was causing a delay by which buscall
> function was not getting invoked. Now, I have integrated this to a large
> application and again I am not getting bus messages. Something like sleep or
> some other loop may be causing this issue. But no idea on how to debug this.
> Is there any mechanism by which I can get past this.? Is there any way by
> which I can listen to bus messages without using 'gst_bus_add_watch' or
> gst_bus_set_sync_handler . Both are not working.

It sounds like you need to take a step back and try to understand how
main loops / event loops work. If you use an event loop like GMainLoop,
you should ideally never use sleep() or any other operation that blocks
for longer amounts of time. You can schedule timeouts if you need
something done in N milliseconds/seconds/minutes time. You don't have to
use a main loop of course, but if you do, that's how it works.
gst_bus_add_watch() will only work if you do use a main loop.

If you don't use a main loop, you need to pop messages off the bus
yourself regularly from your application thread.

You can install a bus sync handler to somehow signal your application
thread that there's a new message on the bus (e.g. if you use some other
event loop), but you should generally not do things from a sync handler,
esp. not change pipeline state and the like.


More information about the gstreamer-devel mailing list