:right-sidebar: True Bin =================================================================== .. currentmodule:: gi.repository.Gst .. class:: Bin(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gst.Element`, :class:`~gi.repository.Gst.Object`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gst.Pipeline` Implemented Interfaces: :class:`~gi.repository.Gst.ChildProxy` :obj:`~gi.repository.Gst.Bin` is an element that can contain other :obj:`~gi.repository.Gst.Element`\, allowing them to be managed as a group. Pads from the child elements can be ghosted to the bin, see :obj:`~gi.repository.Gst.GhostPad`\. This makes the bin look like any other elements and enables creation of higher-level abstraction elements. A new :obj:`~gi.repository.Gst.Bin` is created with :func:`~gi.repository.Gst.Bin.new`. Use a :obj:`~gi.repository.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 :func:`~gi.repository.Gst.Bin.add`. You can remove elements with :func:`~gi.repository.Gst.Bin.remove`. An element can be retrieved from a bin with :func:`~gi.repository.Gst.Bin.get_by_name`, using the elements name. :func:`~gi.repository.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 :func:`~gi.repository.Gst.Bin.iterate_elements`. Various other iterators exist to retrieve the elements in a bin. :func:`~gi.repository.Gst.Object.unref` is used to drop your reference to the bin. The :obj:`~gi.repository.Gst.Bin`\::element-added signal is fired whenever a new element is added to the bin. Likewise the :obj:`~gi.repository.Gst.Bin`\::element-removed signal is fired whenever an element is removed from the bin. A :obj:`~gi.repository.Gst.Bin` internally intercepts every :obj:`~gi.repository.Gst.Message` posted by its children and implements the following default behaviour for each of them: - :const:`~gi.repository.Gst.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. - :const:`~gi.repository.Gst.MessageType.SEGMENT_START`: Just collected and never forwarded upwards. The messages are used to decide when all elements have completed playback of their segment. - :const:`~gi.repository.Gst.MessageType.SEGMENT_DONE`: Is posted by :obj:`~gi.repository.Gst.Bin` when all elements that posted a SEGMENT_START have posted a SEGMENT_DONE. - :const:`~gi.repository.Gst.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 :const:`~gi.repository.Gst.MessageType.STREAM_START` message, signaling the active start of a (new) stream. - :const:`~gi.repository.Gst.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. - :const:`~gi.repository.Gst.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 :obj:`~gi.repository.Gst.Bin` implements the following default behaviour for answering to a :obj:`~gi.repository.Gst.Query`\: - :const:`~gi.repository.Gst.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. - :const:`~gi.repository.Gst.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 :obj:`~gi.repository.Gst.Bin` will by default forward any event sent to it to all sink ( :const:`~gi.repository.Gst.EventTypeFlags.UPSTREAM` ) or source ( :const:`~gi.repository.Gst.EventTypeFlags.DOWNSTREAM` ) elements depending on the event type. If all the elements return :const:`True`, the bin will also return :const:`True`, else :const:`False` is returned. If no elements of the required type are in the bin, the event handler will return :const:`True`. Constructors ------------ .. rst-class:: interim-class .. class:: Bin :no-index: .. classmethod:: new(name: str | None = None) -> ~gi.repository.Gst.Element Creates a new bin with the given name. :param name: the name of the new bin Methods ------- .. rst-class:: interim-class .. class:: Bin :no-index: .. method:: add(element: ~gi.repository.Gst.Element) -> bool 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 :func:`~gi.repository.Gst.Element.set_state`, or use :func:`~gi.repository.Gst.Element.sync_state_with_parent`. The bin or pipeline will not take care of this for you. :param element: the :obj:`~gi.repository.Gst.Element` to add .. method:: do_add_element(self, element: ~gi.repository.Gst.Element) -> bool :param element: .. method:: do_deep_element_added(self, sub_bin: ~gi.repository.Gst.Bin, child: ~gi.repository.Gst.Element) -> None :param sub_bin: :param child: .. method:: do_deep_element_removed(self, sub_bin: ~gi.repository.Gst.Bin, child: ~gi.repository.Gst.Element) -> None :param sub_bin: :param child: .. method:: do_do_latency(self) -> bool .. method:: do_element_added(self, child: ~gi.repository.Gst.Element) -> None :param child: .. method:: do_element_removed(self, child: ~gi.repository.Gst.Element) -> None :param child: .. method:: do_handle_message(self, message: ~gi.repository.Gst.Message) -> None :param message: .. method:: do_remove_element(self, element: ~gi.repository.Gst.Element) -> bool :param element: .. method:: find_unlinked_pad(direction: ~gi.repository.Gst.PadDirection) -> ~gi.repository.Gst.Pad | None 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, or :const:`None` otherwise. If a pad is found, the caller owns a reference to it and should use :func:`~gi.repository.Gst.Object.unref` on the pad when it is not needed any longer. :param direction: whether to look for an unlinked source or sink pad .. method:: get_by_interface(iface: ~gobject.GType) -> ~gi.repository.Gst.Element | None 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 :func:`~gi.repository.Gst.Bin.iterate_all_by_interface`. This function recurses into child bins. :param iface: the :obj:`~gi.repository.GObject.Type` of an interface .. method:: get_by_name(name: str) -> ~gi.repository.Gst.Element | None Gets the element with the given name from a bin. This function recurses into child bins. :param name: the element name to search for .. method:: get_by_name_recurse_up(name: str) -> ~gi.repository.Gst.Element | None Gets the element with the given name from this bin. If the element is not found, a recursion is performed on the parent bin. :param name: the element name to search for .. method:: get_suppressed_flags() -> ~gi.repository.Gst.ElementFlags .. versionadded:: 1.10 .. method:: iterate_all_by_element_factory_name(factory_name: str) -> ~gi.repository.Gst.Iterator | None 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 of :obj:`~gi.repository.Gst.Element`\. .. versionadded:: 1.18 :param factory_name: the name of the :obj:`~gi.repository.Gst.ElementFactory` .. method:: iterate_all_by_interface(iface: ~gobject.GType) -> ~gi.repository.Gst.Iterator | None 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 :obj:`~gi.repository.Gst.Element`\. :param iface: the :obj:`~gi.repository.GObject.Type` of an interface .. method:: iterate_elements() -> ~gi.repository.Gst.Iterator | None Gets an iterator for the elements in this bin. .. method:: iterate_recurse() -> ~gi.repository.Gst.Iterator | None Gets an iterator for the elements in this bin. This iterator recurses into GstBin children. .. method:: iterate_sinks() -> ~gi.repository.Gst.Iterator | None Gets an iterator for all elements in the bin that have the ``GST_ELEMENT_FLAG_SINK`` flag set. .. method:: iterate_sorted() -> ~gi.repository.Gst.Iterator | None 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. .. method:: iterate_sources() -> ~gi.repository.Gst.Iterator | None Gets an iterator for all elements in the bin that have the ``GST_ELEMENT_FLAG_SOURCE`` flag set. .. method:: recalculate_latency() -> bool Queries ``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_LATENCY`` is posted on the bus. This function simply emits the :obj:`~gi.repository.Gst.Bin`\::do-latency signal so any custom latency calculations will be performed. .. method:: remove(element: ~gi.repository.Gst.Element) -> bool 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 :func:`~gi.repository.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. :param element: the :obj:`~gi.repository.Gst.Element` to remove .. method:: set_suppressed_flags(flags: ~gi.repository.Gst.ElementFlags) -> None Suppresses the given flags on the bin. :obj:`~gi.repository.Gst.ElementFlags` of 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. .. versionadded:: 1.10 :param flags: the :obj:`~gi.repository.Gst.ElementFlags` to suppress .. method:: sync_children_states() -> bool Synchronizes the state of every child of ``bin`` with the state of ``bin``\. See also :func:`~gi.repository.Gst.Element.sync_state_with_parent`. .. versionadded:: 1.6 Properties ---------- .. rst-class:: interim-class .. class:: Bin :no-index: .. attribute:: props.async_handling :type: bool The type of the None singleton. .. attribute:: props.message_forward :type: bool The type of the None singleton. Signals ------- .. rst-class:: interim-class .. class:: Bin.signals :no-index: .. method:: deep_element_added(sub_bin: ~gi.repository.Gst.Bin, element: ~gi.repository.Gst.Element) -> None The type of the None singleton. .. versionadded:: 1.10 :param sub_bin: the :obj:`~gi.repository.Gst.Bin` the element was added to :param element: the :obj:`~gi.repository.Gst.Element` that was added to ``sub_bin`` .. method:: deep_element_removed(sub_bin: ~gi.repository.Gst.Bin, element: ~gi.repository.Gst.Element) -> None The type of the None singleton. .. versionadded:: 1.10 :param sub_bin: the :obj:`~gi.repository.Gst.Bin` the element was removed from :param element: the :obj:`~gi.repository.Gst.Element` that was removed from ``sub_bin`` .. method:: do_latency() -> bool The type of the None singleton. .. method:: element_added(element: ~gi.repository.Gst.Element) -> None The type of the None singleton. :param element: the :obj:`~gi.repository.Gst.Element` that was added to the bin .. method:: element_removed(element: ~gi.repository.Gst.Element) -> None The type of the None singleton. :param element: the :obj:`~gi.repository.Gst.Element` that was removed from the bin Virtual Methods --------------- .. rst-class:: interim-class .. class:: Bin :no-index: .. method:: do_add_element(element: ~gi.repository.Gst.Element) -> bool The type of the None singleton. :param element: the element to be added .. method:: do_deep_element_added(sub_bin: ~gi.repository.Gst.Bin, child: ~gi.repository.Gst.Element) -> None The type of the None singleton. :param sub_bin: the :obj:`~gi.repository.Gst.Bin` to which the element was added :param child: the element that was added .. method:: do_deep_element_removed(sub_bin: ~gi.repository.Gst.Bin, child: ~gi.repository.Gst.Element) -> None The type of the None singleton. :param sub_bin: the :obj:`~gi.repository.Gst.Bin` from which the element was removed :param child: the element that was removed .. method:: do_do_latency() -> bool The type of the None singleton. .. method:: do_element_added(child: ~gi.repository.Gst.Element) -> None The type of the None singleton. :param child: the element that was added .. method:: do_element_removed(child: ~gi.repository.Gst.Element) -> None The type of the None singleton. :param child: the element that was removed .. method:: do_handle_message(message: ~gi.repository.Gst.Message) -> None The type of the None singleton. :param message: the message to be handled .. method:: do_remove_element(element: ~gi.repository.Gst.Element) -> bool The type of the None singleton. :param element: the element to be removed Fields ------ .. rst-class:: interim-class .. class:: Bin :no-index: .. attribute:: child_bus Internal bus for handling child messages .. attribute:: children The list of children in this bin .. attribute:: children_cookie Updated whenever ``children`` changes .. attribute:: clock_dirty The bin needs to select a new clock .. attribute:: clock_provider The element that provided ``provided_clock`` .. attribute:: element .. attribute:: messages Queued and cached messages .. attribute:: numchildren The number of children in this bin .. attribute:: polling The bin is currently calculating its state .. attribute:: priv .. attribute:: provided_clock The last clock selected .. attribute:: state_dirty The bin needs to recalculate its state (deprecated)