Class Bin
- All Implemented Interfaces:
ChildProxy,Proxy
- Direct Known Subclasses:
Pipeline
GstBin is an element that can contain other GstElement, allowing them to be
managed as a group.
Pads from the child elements can be ghosted to the bin, see GstGhostPad.
This makes the bin look like any other elements and enables creation of
higher-level abstraction elements.
A new GstBin is created with gst_bin_new(). Use a GstPipeline 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 GstBin::element-added signal is fired whenever a new element is added to
the bin. Likewise the GstBin::element-removed signal is fired whenever an
element is removed from the bin.
A GstBin internally intercepts every GstMessage posted by its children and
implements the following default behaviour for each of them:
MessageType.EOS: 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.
MessageType.SEGMENT_START: Just collected and never forwarded upwards. The messages are used to decide when all elements have completed playback of their segment.
MessageType.SEGMENT_DONE: Is posted byGstBinwhen all elements that posted a SEGMENT_START have posted a SEGMENT_DONE.
MessageType.DURATION_CHANGED: Is posted by an element that detected a change in the stream duration. The duration change is posted to the application so that it can refetch the new duration with a duration query.
Note that these messages can be posted before the bin is prerolled, in which case the duration query might fail.
Note also that there might be a discrepancy (due to internal buffering/queueing) between the stream being currently displayed and the returned duration query.
Applications might want to also query for duration (and changes) by
listening to the MessageType.STREAM_START message, signaling the active start
of a (new) stream.
MessageType.CLOCK_LOST: 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.
MessageType.CLOCK_PROVIDE: 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 to the application but is forwarded to the parent of the bin.
- OTHERS: posted upwards.
A GstBin implements the following default behaviour for answering to a
GstQuery:
QueryType.DURATION: The bin will forward the query to all sink elements contained within and will return the maximum value. If no sinks are available in the bin, the query fails.
QueryType.POSITION: 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.
- OTHERS: 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 GstBin will by default forward any event sent to it to all sink
( EventTypeFlags.UPSTREAM ) or source ( EventTypeFlags.DOWNSTREAM ) elements
depending on the event type.
If all the elements return true, the bin will also return true, else false
is returned. If no elements of the required type are in the bin, the event
handler will return true.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSubclasses can overrideGstBinClass::add_element andGstBinClass::remove_element to update the list of children in the bin.static classBin.Builder<B extends Bin.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theDeepElementAddedCallbackcallback.static interfaceFunctional interface declaration of theDeepElementRemovedCallbackcallback.static interfaceFunctional interface declaration of theDoLatencyCallbackcallback.static interfaceFunctional interface declaration of theElementAddedCallbackcallback.static interfaceFunctional interface declaration of theElementRemovedCallbackcallback.Nested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.Element
Element.Element$Impl, Element.ElementClass, Element.NoMorePadsCallback, Element.PadAddedCallback, Element.PadRemovedCallbackNested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.GstObject
GstObject.DeepNotifyCallback, GstObject.Object$Impl, GstObject.ObjectClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallbackNested classes/interfaces inherited from interface org.freedesktop.gstreamer.gst.ChildProxy
ChildProxy.ChildAddedCallback, ChildProxy.ChildProxy$Impl, ChildProxy.ChildProxyInterface, ChildProxy.ChildRemovedCallback -
Constructor Summary
ConstructorsConstructorDescriptionBin()Creates a new Bin.Creates a new bin with the given name.Bin(MemorySegment address) Create a Bin proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the given element to the bin.protected booleanaddElement(Element element) Method to add an element to the bin.voidAdds anull-terminated list of elements to a bin.protected BinasParent()Returns this instance as if it were its parent type.static Bin.Builder<? extends Bin.Builder> builder()ABin.Builderobject constructs aBinwith the specified properties.protected voiddeepElementAdded(Bin subBin, Element child) Method called when an element was added somewhere in the bin hierarchy.protected voiddeepElementRemoved(Bin subBin, Element child) Method called when an element was removed somewhere in the bin hierarchy.protected booleanprotected voidelementAdded(Element child) Method called when an element was added to the bin.protected voidelementRemoved(Element child) Method called when an element was removed from the bin.voidemitDeepElementAdded(@Nullable Bin subBin, @Nullable Element element) Emits the "deep-element-added" signal.voidemitDeepElementRemoved(@Nullable Bin subBin, @Nullable Element element) Emits the "deep-element-removed" signal.booleanEmits the "do-latency" signal.voidemitElementAdded(@Nullable Element element) Emits the "element-added" signal.voidemitElementRemoved(@Nullable Element element) Emits the "element-removed" signal.@Nullable PadfindUnlinkedPad(PadDirection direction) Recursively looks for elements with an unlinked pad of the given direction within the specified bin and returns an unlinked pad if one is found, ornullotherwise.@Nullable ElementgetByInterface(Type iface) Looks for an element inside the bin that implements the given interface.@Nullable ElementGets the element with the given name from a bin.@Nullable ElementgetByNameRecurseUp(String name) Gets the element with the given name from this bin.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the Bin classprotected voidhandleMessage(Message message) Method to handle a message from the children.@Nullable IteratoriterateAllByElementFactoryName(String factoryName) Looks for all elements inside the bin with the given element factory name.@Nullable IteratoriterateAllByInterface(Type iface) Looks for all elements inside the bin that implements the given interface.@Nullable IteratorGets an iterator for the elements in this bin.@Nullable IteratorGets an iterator for the elements in this bin.@Nullable IteratorGets an iterator for all elements in the bin that have theGST_ELEMENT_FLAG_SINKflag set.@Nullable IteratorGets an iterator for the elements in this bin in topologically sorted order.@Nullable IteratorGets an iterator for all elements in the bin that have theGST_ELEMENT_FLAG_SOURCEflag set.Will be emitted after the element was added tosubBin.Will be emitted after the element was removed fromsubBin.onDoLatency(Bin.DoLatencyCallback handler) Will be emitted when the bin needs to perform latency calculations.onElementAdded(Bin.ElementAddedCallback handler) Will be emitted after the element was added to the bin.Will be emitted after the element was removed from the bin.booleanQueries this Bin for the current latency and reconfigures this latency on all the elements using a LATENCY event.booleanRemoves the element from the bin, unparenting it as well.protected booleanremoveElement(Element element) Method to remove an element from the bin.voidremoveMany(Element element1, Object... varargs) Removes a list of elements from a bin.voidsetSuppressedFlags(Set<ElementFlags> flags) Suppresses the given flags on the bin.voidsetSuppressedFlags(ElementFlags... flags) Suppresses the given flags on the bin.booleanSynchronizes the state of every child of this Bin with the state ofbin.See also gst_element_sync_state_with_parent().Methods inherited from class org.freedesktop.gstreamer.gst.Element
abortState, addPad, addPropertyDeepNotifyWatch, addPropertyNotifyWatch, callAsync, changeState, continueState, createAllPads, decorateStreamId, decorateStreamIdPrintf, emitNoMorePads, emitPadAdded, emitPadRemoved, foreachPad, foreachSinkPad, foreachSrcPad, getBaseTime, getBus, getClock, getCompatiblePad, getCompatiblePadTemplate, getContext, getContexts, getContextUnlocked, getCurrentClockTime, getCurrentRunningTime, getFactory, getMetadata, getPadTemplate, getPadTemplateList, getRequestPad, getStartTime, getState, getStaticPad, isLockedState, iteratePads, iterateSinkPads, iterateSrcPads, link, linkFiltered, linkMany, linkPads, linkPadsFiltered, linkPadsFull, linkPadsFull, lostState, makeFromUri, messageFull, messageFull, messageFullWithDetails, messageFullWithDetails, noMorePads, onNoMorePads, onPadAdded, onPadRemoved, padAdded, padRemoved, postMessage, provideClock, query, queryConvert, queryDuration, queryPosition, register, releasePad, releaseRequestPad, removePad, removePropertyNotifyWatch, requestPad, requestPadSimple, seek, seek, seekSimple, seekSimple, sendEvent, setBaseTime, setBus, setClock, setContext, setLockedState, setStartTime, setState, stateChanged, stateChangeReturnGetName, stateGetName, syncStateWithParent, typeSetSkipDocumentation, unlink, unlinkMany, unlinkPadsMethods inherited from class org.freedesktop.gstreamer.gst.GstObject
addControlBinding, checkUniqueness, deepNotify, defaultDeepNotify, defaultError, emitDeepNotify, getControlBinding, getControlRate, getGValueArray, getName, getParent, getPathString, getValue, getValueArray, hasActiveControlBindings, hasAncestor, hasAsAncestor, hasAsParent, onDeepNotify, ref, refSink, removeControlBinding, replace, setControlBindingDisabled, setControlBindingsDisabled, setControlRate, setName, setParent, suggestNextSync, syncValues, unparent, unrefMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.freedesktop.gstreamer.gst.ChildProxy
childAdded, childRemoved, emitChildAdded, emitChildRemoved, get, getChildByIndex, getChildByName, getChildByNameRecurse, getChildrenCount, getProperty, lookup, onChildAdded, onChildRemoved, set, setProperty
-
Constructor Details
-
Bin
Create a Bin proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Bin
Creates a new bin with the given name.- Parameters:
name- the name of the new bin
-
Bin
public Bin()Creates a new Bin.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
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.
When you add an element to an already-running pipeline, you will have to take care to set the state of the newly-added element to the desired state (usually PLAYING or PAUSED, same you set the pipeline to originally) with gst_element_set_state(), or use gst_element_sync_state_with_parent(). The bin or pipeline will not take care of this for you.
- Parameters:
element- theGstElementto add- Returns:
trueif the element could be added,falseif the bin does not want to accept the element.
-
addMany
Adds anull-terminated list of elements to a bin. This function is equivalent to calling gst_bin_add() for each member of the list. The return value of each gst_bin_add() is ignored.- Parameters:
element1- theGstElementelement to add to the binvarargs- additional elements to add to the bin
-
findUnlinkedPad
Recursively looks for elements with an unlinked pad of the given direction within the specified bin and returns an unlinked pad if one is found, ornullotherwise. 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.- Parameters:
direction- whether to look for an unlinked source or sink pad- Returns:
- unlinked pad of the given direction.
-
getByInterface
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.- Parameters:
iface- theGTypeof an interface- Returns:
- A
GstElementinside the bin implementing the interface
-
getByName
-
getByNameRecurseUp
-
getSuppressedFlags
-
iterateAllByElementFactoryName
Looks for all elements inside the bin with the given element factory name. The function recurses inside child bins. The iterator will yield a series ofGstElement.- Parameters:
factoryName- the name of theGstElementFactory- Returns:
- a
GstIteratorofGstElementfor all elements in the bin with the given element factory name - Since:
- 1.18
-
iterateAllByInterface
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 ofGstElement.- Parameters:
iface- theGTypeof an interface- Returns:
- a
GstIteratorofGstElementfor all elements in the bin implementing the given interface
-
iterateElements
Gets an iterator for the elements in this bin.- Returns:
- a
GstIteratorofGstElement
-
iterateRecurse
Gets an iterator for the elements in this bin. This iterator recurses into GstBin children.- Returns:
- a
GstIteratorofGstElement
-
iterateSinks
Gets an iterator for all elements in the bin that have theGST_ELEMENT_FLAG_SINKflag set.- Returns:
- a
GstIteratorofGstElement
-
iterateSorted
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 and for clock selection.
- Returns:
- a
GstIteratorofGstElement
-
iterateSources
Gets an iterator for all elements in the bin that have theGST_ELEMENT_FLAG_SOURCEflag set.- Returns:
- a
GstIteratorofGstElement
-
recalculateLatency
public boolean recalculateLatency()Queries this Bin for the current latency and reconfigures this latency on all the elements using a LATENCY event.This method is typically called on the pipeline when a
GST_MESSAGE_LATENCYis posted on the bus.This function simply emits the
GstBin::do-latency signal so any custom latency calculations will be performed.- Returns:
trueif the latency could be queried and reconfigured.
-
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.
- Parameters:
element- theGstElementto remove- Returns:
trueif the element could be removed,falseif the bin does not want to remove the element.
-
removeMany
Removes a list of elements from a bin. This function is equivalent to calling gst_bin_remove() with each member of the list.- Parameters:
element1- the firstGstElementto remove from the binvarargs-null-terminated list of elements to remove from the bin
-
setSuppressedFlags
Suppresses the given flags on the bin.GstElementFlagsof a child element are propagated when it is added to the bin. When suppressed flags are set, those specified flags will not be propagated to the bin.- Parameters:
flags- theGstElementFlagsto suppress- Since:
- 1.10
-
setSuppressedFlags
Suppresses the given flags on the bin.GstElementFlagsof a child element are propagated when it is added to the bin. When suppressed flags are set, those specified flags will not be propagated to the bin.- Parameters:
flags- theGstElementFlagsto suppress- Since:
- 1.10
-
syncChildrenStates
public boolean syncChildrenStates()Synchronizes the state of every child of this Bin with the state ofbin.See also gst_element_sync_state_with_parent().- Returns:
trueif syncing the state was successful for all children, otherwisefalse.- Since:
- 1.6
-
addElement
Method to add an element to the bin.- Parameters:
element- the element to be added- Returns:
trueif theelementwas added
-
deepElementAdded
-
deepElementRemoved
-
doLatency
protected boolean doLatency() -
elementAdded
Method called when an element was added to the bin.- Parameters:
child- the element that was added
-
elementRemoved
Method called when an element was removed from the bin.- Parameters:
child- the element that was removed
-
handleMessage
Method to handle a message from the children.- Parameters:
message- the message to be handled
-
removeElement
Method to remove an element from the bin.- Parameters:
element- the element to be removed- Returns:
trueif theelementwas removed
-
onDeepElementAdded
public SignalConnection<Bin.DeepElementAddedCallback> onDeepElementAdded(Bin.DeepElementAddedCallback handler) Will be emitted after the element was added tosubBin.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 1.10
- See Also:
-
emitDeepElementAdded
Emits the "deep-element-added" signal. SeeonDeepElementAdded(org.freedesktop.gstreamer.gst.Bin.DeepElementAddedCallback). -
onDeepElementRemoved
public SignalConnection<Bin.DeepElementRemovedCallback> onDeepElementRemoved(Bin.DeepElementRemovedCallback handler) Will be emitted after the element was removed fromsubBin.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 1.10
- See Also:
-
emitDeepElementRemoved
Emits the "deep-element-removed" signal. SeeonDeepElementRemoved(org.freedesktop.gstreamer.gst.Bin.DeepElementRemovedCallback). -
onDoLatency
Will be emitted when the bin needs to perform latency calculations. This signal is only emitted for toplevel bins or whenGstBin:async-handling is enabled.Only one signal handler is invoked. If no signals are connected, the default handler is invoked, which will query and distribute the lowest possible latency to all sinks.
Connect to this signal if the default latency calculations are not sufficient, like when you need different latencies for different sinks in the same pipeline.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDoLatency
public boolean emitDoLatency()Emits the "do-latency" signal. SeeonDoLatency(org.freedesktop.gstreamer.gst.Bin.DoLatencyCallback). -
onElementAdded
Will be emitted after the element was added to the bin.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitElementAdded
Emits the "element-added" signal. SeeonElementAdded(org.freedesktop.gstreamer.gst.Bin.ElementAddedCallback). -
onElementRemoved
public SignalConnection<Bin.ElementRemovedCallback> onElementRemoved(Bin.ElementRemovedCallback handler) Will be emitted after the element was removed from the bin.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitElementRemoved
Emits the "element-removed" signal. SeeonElementRemoved(org.freedesktop.gstreamer.gst.Bin.ElementRemovedCallback). -
builder
ABin.Builderobject constructs aBinwith the specified properties. Use the variousset...()methods to set properties, and finish construction withBin.Builder.build().- Returns:
- the builder object
-