9a5638cb3c2f66c404537db2a98be623b7c737eb
[platform/upstream/gstreamer.git] / markdown / design / gstbus.md
1 # GstBus
2
3 The `GstBus` is an object responsible for delivering `GstMessages` in a
4 first-in first-out way from the streaming threads to the application.
5
6 Since the application typically only wants to deal with delivery of
7 these messages from one thread, the `GstBus` will marshall the messages
8 between different threads. This is important since the actual streaming
9 of media is done in other threads (streaming threads) than the
10 application. It is also important to not block the streaming threads
11 while the application deals with the message.
12
13 The `GstBus` provides support for `GSource` based notifications. This makes
14 it possible to handle the delivery in the glib mainloop. Different
15 `GSources` can be added to the same bin provided they listen to different
16 message types.
17
18 A message is posted on the bus with the `gst_bus_post()` method. With
19 the `gst_bus_peek()` and `_pop()` methods one can look at or retrieve a
20 previously posted message.
21
22 The bus can be polled with the `gst_bus_poll()` method. This method
23 blocks up to the specified timeout value until one of the specified
24 message types are posted on the bus. The application can then `_pop()`
25 these messages from the bus to handle them.
26
27 It is also possible to get messages from the bus without any thread
28 marshalling with the `gst_bus_set_sync_handler()` method. This makes
29 it possible to react to a message in the same thread that posted it 
30 on the bus. This should only be used if the application is able
31 to deal with messages from different threads.
32
33 If no messages are popped from the bus with either a `GSource` or
34 `gst_bus_pop()`, they remain on the bus.
35
36 When a pipeline or bin goes from `READY` into `NULL` state, it will set its
37 bus to flushing, ie. the bus will drop all existing and new messages on
38 the bus. This is necessary because bus messages hold references to the
39 bin/pipeline or its elements, so there are circular references that need
40 to be broken if one ever wants to be able to destroy a bin or pipeline
41 properly.