2016-12-05 21:12:24 +00:00
|
|
|
|
# GstBin
|
|
|
|
|
|
2017-04-21 23:04:52 +00:00
|
|
|
|
`GstBin` is a container element for other `GstElements`. It makes
|
2016-12-05 21:12:24 +00:00
|
|
|
|
possible to group elements together so that they can be treated as one
|
2016-12-22 07:25:41 +00:00
|
|
|
|
single `GstElement`. A `GstBin` provides a `GstBus` for the children and
|
2016-12-05 21:12:24 +00:00
|
|
|
|
collates messages from them.
|
|
|
|
|
|
2017-04-21 23:04:52 +00:00
|
|
|
|
## Adding/removing elements
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
2017-03-17 21:17:03 +00:00
|
|
|
|
The basic functionality of a bin is to add and remove `GstElement`
|
2016-12-05 21:12:24 +00:00
|
|
|
|
to/from it. `gst_bin_add()` and `gst_bin_remove()` perform these
|
|
|
|
|
operations respectively.
|
|
|
|
|
|
|
|
|
|
The bin maintains a parent-child relationship with its elements (see
|
2019-05-26 22:32:55 +00:00
|
|
|
|
[relations](additional/design/relations.md)).
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
|
|
|
|
## Retrieving elements
|
|
|
|
|
|
2016-12-22 07:25:41 +00:00
|
|
|
|
`GstBin` provides a number of functions to retrieve one or more children
|
2016-12-05 21:12:24 +00:00
|
|
|
|
from itself. A few examples of the provided functions:
|
|
|
|
|
|
|
|
|
|
* `gst_bin_get_by_name()` retrieves an element by name.
|
|
|
|
|
* `gst_bin_iterate_elements()` returns an iterator to all the children.
|
|
|
|
|
|
2017-04-21 23:04:52 +00:00
|
|
|
|
## Element management
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
2016-12-22 07:25:41 +00:00
|
|
|
|
The most important function of the `GstBin` is to distribute all
|
2017-04-21 23:04:52 +00:00
|
|
|
|
`GstElement` operations on itself to all of its children. These
|
|
|
|
|
operations include:
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
|
|
|
|
- state changes
|
|
|
|
|
|
|
|
|
|
- index get/set
|
|
|
|
|
|
|
|
|
|
- clock get/set
|
|
|
|
|
|
|
|
|
|
The state change distribution is the most complex and is explained in
|
2019-05-26 22:32:55 +00:00
|
|
|
|
[states](additional/design/states.md).
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
|
|
|
|
## GstBus
|
|
|
|
|
|
2016-12-22 07:25:41 +00:00
|
|
|
|
The `GstBin` creates a `GstBus` for its children and distributes it when
|
2016-12-05 21:12:24 +00:00
|
|
|
|
child elements are added to the bin. The bin attaches a sync handler to
|
|
|
|
|
receive messages from children. The bus for receiving messages from
|
2016-12-22 07:25:41 +00:00
|
|
|
|
children is distinct from the bin’s own externally-visible `GstBus`.
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
|
|
|
|
Messages received from children are forwarded intact onto the bin’s
|
2016-12-22 07:25:41 +00:00
|
|
|
|
external message bus, except for EOS and `SEGMENT_START`/`DONE` which are
|
2016-12-05 21:12:24 +00:00
|
|
|
|
handled specially.
|
|
|
|
|
|
2016-12-22 07:25:41 +00:00
|
|
|
|
`ASYNC_START`/`ASYNC_STOP` messages received from the children are used to
|
2016-12-05 21:12:24 +00:00
|
|
|
|
trigger a recalculation of the current state of the bin, as described in
|
2019-05-26 22:32:55 +00:00
|
|
|
|
[states](additional/design/states.md).
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
2016-12-22 07:25:41 +00:00
|
|
|
|
The application can retrieve the external `GstBus` and integrate it in the
|
2016-12-05 21:12:24 +00:00
|
|
|
|
mainloop or it can just `pop()` messages off in its own thread.
|
|
|
|
|
|
2017-04-21 23:04:52 +00:00
|
|
|
|
When a bin goes to `READY` it will clear all cached messages.
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
|
|
|
|
## EOS
|
|
|
|
|
|
2017-03-17 21:17:03 +00:00
|
|
|
|
The sink elements will post an `EOS` message on the bus when they reach
|
|
|
|
|
`EOS`. This message is only posted to the bus when the sink element is
|
|
|
|
|
in `PLAYING`.
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
2017-03-17 21:17:03 +00:00
|
|
|
|
The bin collects all `EOS` messages and forwards it to the application as
|
|
|
|
|
soon as all the sinks have posted an `EOS`.
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
2017-03-17 21:17:03 +00:00
|
|
|
|
The list of queued `EOS` messages is cleared when the bin goes to `PAUSED`
|
|
|
|
|
again. This means that all elements should repost the `EOS` message when
|
|
|
|
|
going to `PLAYING` again.
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
|
|
|
|
## SEGMENT_START/DONE
|
|
|
|
|
|
|
|
|
|
A bin collects `SEGMENT_START` messages but does not post them to the
|
|
|
|
|
application. It counts the number of `SEGMENT_START` messages and posts a
|
|
|
|
|
`SEGMENT_STOP` message to the application when an equal number of
|
2016-12-22 07:25:41 +00:00
|
|
|
|
`SEGMENT_STOP` messages were received.
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
2017-03-17 21:17:03 +00:00
|
|
|
|
The cached `SEGMENT_START`/`STOP` messages are cleared when going to `READY`.
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
|
|
|
|
## DURATION
|
|
|
|
|
|
2017-04-21 23:04:52 +00:00
|
|
|
|
When a `DURATION` query is performed on a bin, it will forward the query
|
2016-12-05 21:12:24 +00:00
|
|
|
|
to all its sink elements. The bin will calculate the total duration as
|
|
|
|
|
the MAX of all returned durations and will then cache the result so that
|
2016-12-22 07:25:41 +00:00
|
|
|
|
any further queries can use the cached version. The reason for caching the
|
2016-12-05 21:12:24 +00:00
|
|
|
|
result is because the duration of a stream typically does not change
|
|
|
|
|
that often.
|
|
|
|
|
|
|
|
|
|
A `GST_MESSAGE_DURATION_CHANGED` posted by an element will clear the
|
|
|
|
|
cached duration value so that the bin will query the sinks again. This
|
|
|
|
|
message is typically posted by elements that calculate the duration of
|
|
|
|
|
the stream based on some average bitrate, which might change while
|
|
|
|
|
playing the stream. The `DURATION_CHANGED` message is posted to the
|
2017-03-17 21:17:03 +00:00
|
|
|
|
application, which can then fetch the updated `DURATION`.
|
2016-12-05 21:12:24 +00:00
|
|
|
|
|
|
|
|
|
## Subclassing
|
|
|
|
|
|
2016-12-22 07:25:41 +00:00
|
|
|
|
Subclasses of `GstBin` are free to implement their own add/remove
|
|
|
|
|
functions. It is a good idea to update the `GList` of children so
|
2016-12-05 21:12:24 +00:00
|
|
|
|
that the `_iterate()` functions can still be used if the custom bin
|
|
|
|
|
allows access to its children.
|
|
|
|
|
|
|
|
|
|
Any bin subclass can also implement a custom message handler by
|
2016-12-22 07:25:41 +00:00
|
|
|
|
overriding the default one.
|