2016-12-05 21:12:24 +00:00
|
|
|
# GstBus
|
|
|
|
|
2016-12-22 07:32:05 +00:00
|
|
|
The `GstBus` is an object responsible for delivering `GstMessages` in a
|
2016-12-05 21:12:24 +00:00
|
|
|
first-in first-out way from the streaming threads to the application.
|
|
|
|
|
|
|
|
Since the application typically only wants to deal with delivery of
|
2016-12-22 07:32:05 +00:00
|
|
|
these messages from one thread, the `GstBus` will marshall the messages
|
2016-12-05 21:12:24 +00:00
|
|
|
between different threads. This is important since the actual streaming
|
2016-12-22 07:32:05 +00:00
|
|
|
of media is done in other threads (streaming threads) than the
|
2016-12-05 21:12:24 +00:00
|
|
|
application. It is also important to not block the streaming threads
|
|
|
|
while the application deals with the message.
|
|
|
|
|
2016-12-22 07:32:05 +00:00
|
|
|
The `GstBus` provides support for `GSource` based notifications. This makes
|
2016-12-05 21:12:24 +00:00
|
|
|
it possible to handle the delivery in the glib mainloop. Different
|
2016-12-22 07:32:05 +00:00
|
|
|
`GSources` can be added to the same bin provided they listen to different
|
2016-12-05 21:12:24 +00:00
|
|
|
message types.
|
|
|
|
|
|
|
|
A message is posted on the bus with the `gst_bus_post()` method. With
|
|
|
|
the `gst_bus_peek()` and `_pop()` methods one can look at or retrieve a
|
|
|
|
previously posted message.
|
|
|
|
|
2016-12-22 07:32:05 +00:00
|
|
|
The bus can be polled with the `gst_bus_poll()` method. This method
|
2016-12-05 21:12:24 +00:00
|
|
|
blocks up to the specified timeout value until one of the specified
|
2016-12-22 07:32:05 +00:00
|
|
|
message types are posted on the bus. The application can then `_pop()`
|
|
|
|
these messages from the bus to handle them.
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
|
|
It is also possible to get messages from the bus without any thread
|
|
|
|
marshalling with the `gst_bus_set_sync_handler()` method. This makes
|
2016-12-22 07:32:05 +00:00
|
|
|
it possible to react to a message in the same thread that posted it
|
|
|
|
on the bus. This should only be used if the application is able
|
2016-12-05 21:12:24 +00:00
|
|
|
to deal with messages from different threads.
|
|
|
|
|
2016-12-22 07:32:05 +00:00
|
|
|
If no messages are popped from the bus with either a `GSource` or
|
2016-12-05 21:12:24 +00:00
|
|
|
`gst_bus_pop()`, they remain on the bus.
|
|
|
|
|
2017-04-21 23:19:55 +00:00
|
|
|
When a pipeline or bin goes from `READY` into `NULL` state, it will set its
|
2016-12-05 21:12:24 +00:00
|
|
|
bus to flushing, ie. the bus will drop all existing and new messages on
|
2016-12-22 07:32:05 +00:00
|
|
|
the bus. This is necessary because bus messages hold references to the
|
2016-12-05 21:12:24 +00:00
|
|
|
bin/pipeline or its elements, so there are circular references that need
|
|
|
|
to be broken if one ever wants to be able to destroy a bin or pipeline
|
|
|
|
properly.
|