Next: , Previous: Overview, Up: Top


2 GstBin

Base class and element that can contain other elements

2.1 Overview

<gst-bin> is an element that can contain other <gst-element>, allowing them to be managed as a group. Pads from the child elements can be ghosted to the bin, see <gst-ghost-pad>. This makes the bin look like any other elements and enables creation of higher-level abstraction elements.

A new <gst-bin> is created with gst-bin-new. Use a <gst-pipeline> instead if you want to create a toplevel bin because a normal bin doesn't have a bus or handle clock distribution of its own.

After the bin has been created you will typically add elements to it with gst-bin-add. You can remove elements with gst-bin-remove.

An element can be retrieved from a bin with gst-bin-get-by-name, using the elements name. gst-bin-get-by-name-recurse-up is mainly used for internal purposes and will query the parent bins when the element is not found in the current bin.

An iterator of elements in a bin can be retrieved with gst-bin-iterate-elements. Various other iterators exist to retrieve the elements in a bin.

gst-object-unref is used to drop your reference to the bin.

The element-added signal is fired whenever a new element is added to the bin. Likewise the element-removed signal is fired whenever an element is removed from the bin.

2.2 Notes

A <gst-bin> internally intercepts every <gst-message> posted by its children and implements the following default behaviour for each of them:

GST_MESSAGE_SEGMENT_START

GST_MESSAGE_SEGMENT_DONE

GST_MESSAGE_DURATION

GST_MESSAGE_CLOCK_LOST

GST_MESSAGE_CLOCK_PROVIDE

OTHERS

This message is only posted by sinks in the PLAYING state. If all sinks posted the EOS message, this bin will post and EOS message upwards.

just collected and never forwarded upwards. The messages are used to decide when all elements have completed playback of their segment.

Is posted by <gst-bin> when all elements that posted a SEGMENT_START have posted a SEGMENT_DONE.

Is posted by an element that detected a change in the stream duration. The default bin behaviour is to clear any cached duration values so that the next duration query will perform a full duration recalculation. The duration change is posted to the application so that it can refetch the new duration with a duration query.

This message is posted by an element when it can no longer provide a clock. The default bin behaviour is to check if the lost clock was the one provided by the bin. If so and the bin is currently in the PLAYING state, the message is forwarded to the bin parent. This message is also generated when a clock provider is removed from the bin. If this message is received by the application, it should PAUSE the pipeline and set it back to PLAYING to force a new clock distribution.

This message is generated when an element can provide a clock. This mostly happens when a new clock provider is added to the bin. The default behaviour of the bin is to mark the currently selected clock as dirty, which will perform a clock recalculation the next time the bin is asked to provide a clock. This message is never sent tot the application but is forwarded to the parent of the bin.

posted upwards.

A <gst-bin> implements the following default behaviour for answering to a <gst-query:>

GST_QUERY_POSITION

OTHERS

If the query has been asked before with the same format and the bin is a toplevel bin (ie. has no parent), use the cached previous value. If no previous value was cached, the query is sent to all sink elements in the bin and the MAXIMUM of all values is returned. If the bin is a toplevel bin the value is cached. If no sinks are available in the bin, the query fails.

The query is sent to all sink elements in the bin and the MAXIMUM of all values is returned. If no sinks are available in the bin, the query fails.

the query is forwarded to all sink elements, the result of the first sink that answers the query successfully is returned. If no sink is in the bin, the query fails.

A <gst-bin> will by default forward any event sent to it to all sink elements. If all the sinks return TRUE, the bin will also return TRUE, else FALSE is returned. If no sinks are in the bin, the event handler will return TRUE.

Last reviewed on 2006-04-28 (0.10.6)

2.3 Usage

— Class: <gst-bin>

This <gobject> class defines the following properties:

async-handling
The bin will handle Asynchronous state changes
— Signal on <gst-bin>: element-added (arg0 <gst-element>)

Will be emitted after the element was added to the bin.

— Signal on <gst-bin>: element-removed (arg0 <gst-element>)

Will be emitted after the element was removed from the bin.

— Function: gst-bin-new (name mchars)   (ret <gst-element>)

Creates a new bin with the given name.

name
the name of the new bin
ret
a new <gst-bin>
— Function: gst-bin-add (self <gst-bin>) (element <gst-element>)   (ret bool)
— Method: add

Adds the given element to the bin. Sets the element's parent, and thus takes ownership of the element. An element can only be added to one bin.

If the element's pads are linked to other pads, the pads will be unlinked before the element is added to the bin.

MT safe.

bin
a <gst-bin>
element
the <gst-element> to add
ret
TRUE if the element could be added, FALSE if the bin does not want to accept the element.
— Function: gst-bin-remove (self <gst-bin>) (element <gst-element>)   (ret bool)
— Method: remove

Removes the element from the bin, unparenting it as well. Unparenting the element means that the element will be dereferenced, so if the bin holds the only reference to the element, the element will be freed in the process of removing it from the bin. If you want the element to still exist after removing, you need to call gst-object-ref before removing it from the bin.

If the element's pads are linked to other pads, the pads will be unlinked before the element is removed from the bin.

MT safe.

bin
a <gst-bin>
element
the <gst-element> to remove
ret
TRUE if the element could be removed, FALSE if the bin does not want to remove the element.
— Function: gst-bin-get-by-name (self <gst-bin>) (name mchars)   (ret <gst-element>)
— Method: get-by-name

Gets the element with the given name from a bin. This function recurses into child bins.

Returns NULL if no element with the given name is found in the bin.

MT safe. Caller owns returned reference.

bin
a <gst-bin>
name
the element name to search for
ret
the <gst-element> with the given name, or NULL
— Function: gst-bin-get-by-name-recurse-up (self <gst-bin>) (name mchars)   (ret <gst-element>)
— Method: get-by-name-recurse-up

Gets the element with the given name from this bin. If the element is not found, a recursion is performed on the parent bin.

Returns NULL if: - no element with the given name is found in the bin

MT safe. Caller owns returned reference.

bin
a <gst-bin>
name
the element name to search for
ret
the <gst-element> with the given name, or NULL
— Function: gst-bin-get-by-interface (self <gst-bin>) (interface <gtype>)   (ret <gst-element>)
— Method: get-by-interface

Looks for an element inside the bin that implements the given interface. If such an element is found, it returns the element. You can cast this element to the given interface afterwards. If you want all elements that implement the interface, use gst-bin-iterate-all-by-interface. This function recurses into child bins.

MT safe. Caller owns returned reference.

bin
a <gst-bin>
iface
the <g-type> of an interface
ret
A <gst-element> inside the bin implementing the interface
— Function: gst-bin-iterate-elements (self <gst-bin>)   (ret <gst-iterator*>)
— Method: iterate-elements

Gets an iterator for the elements in this bin.

Each element yielded by the iterator will have its refcount increased, so unref after use.

MT safe. Caller owns returned value.

bin
a <gst-bin>
ret
a <gst-iterator> of <gst-element>, or NULL
— Function: gst-bin-iterate-recurse (self <gst-bin>)   (ret <gst-iterator*>)
— Method: iterate-recurse

Gets an iterator for the elements in this bin. This iterator recurses into GstBin children.

Each element yielded by the iterator will have its refcount increased, so unref after use.

MT safe. Caller owns returned value.

bin
a <gst-bin>
ret
a <gst-iterator> of <gst-element>, or NULL
— Function: gst-bin-iterate-sinks (self <gst-bin>)   (ret <gst-iterator*>)
— Method: iterate-sinks

Gets an iterator for all elements in the bin that have the <gst-element-is-sink> flag set.

Each element yielded by the iterator will have its refcount increased, so unref after use.

MT safe. Caller owns returned value.

bin
a <gst-bin>
ret
a <gst-iterator> of <gst-element>, or NULL
— Function: gst-bin-iterate-sorted (self <gst-bin>)   (ret <gst-iterator*>)
— Method: iterate-sorted

Gets an iterator for the elements in this bin in topologically sorted order. This means that the elements are returned from the most downstream elements (sinks) to the sources.

This function is used internally to perform the state changes of the bin elements.

Each element yielded by the iterator will have its refcount increased, so unref after use.

MT safe. Caller owns returned value.

bin
a <gst-bin>
ret
a <gst-iterator> of <gst-element>, or NULL
— Function: gst-bin-iterate-sources (self <gst-bin>)   (ret <gst-iterator*>)
— Method: iterate-sources

Gets an iterator for all elements in the bin that have no sinkpads and have the <gst-element-is-sink> flag unset.

Each element yielded by the iterator will have its refcount increased, so unref after use.

MT safe. Caller owns returned value.

bin
a <gst-bin>
ret
a <gst-iterator> of <gst-element>, or NULL
— Function: gst-bin-iterate-all-by-interface (self <gst-bin>) (interface <gtype>)   (ret <gst-iterator*>)
— Method: iterate-all-by-interface

Looks for all elements inside the bin that implements the given interface. You can safely cast all returned elements to the given interface. The function recurses inside child bins. The iterator will yield a series of <gst-element> that should be unreffed after use.

Each element yielded by the iterator will have its refcount increased, so unref after use.

MT safe. Caller owns returned value.

bin
a <gst-bin>
iface
the <g-type> of an interface
ret
a <gst-iterator> of <gst-element> for all elements in the bin implementing the given interface, or NULL
— Function: gst-bin-find-unconnected-pad (self <gst-bin>) (direction <gst-pad-direction>)   (ret <gst-pad>)
— Method: find-unconnected-pad

Recursively looks for elements with an unconnected pad of the given direction within the specified bin and returns an unconnected pad if one is found, or NULL otherwise. If a pad is found, the caller owns a reference to it and should use gst-object-unref on the pad when it is not needed any longer.

bin
bin in which to look for elements with unconnected pads
direction
whether to look for an unconnected source or sink pad
ret
unconnected pad of the given direction, or NULL.

Since 0.10.3