:right-sidebar: True CollectPads =================================================================== .. currentmodule:: gi.repository.GstBase .. class:: CollectPads(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gst.Object`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` Manages a set of pads that operate in collect mode. This means that control is given to the manager of this object when all pads have data. - Collectpads are created with :func:`~gi.repository.GstBase.CollectPads.new`. A callback should then be installed with gst_collect_pads_set_function (). - Pads are added to the collection with :func:`~gi.repository.GstBase.CollectPads.add_pad`/ :func:`~gi.repository.GstBase.CollectPads.remove_pad`. The pad has to be a sinkpad. When added, the chain, event and query functions of the pad are overridden. The element_private of the pad is used to store private information for the collectpads. - For each pad, data is queued in the _chain function or by performing a pull_range. - When data is queued on all pads in waiting mode, the callback function is called. - Data can be dequeued from the pad with the :func:`~gi.repository.GstBase.CollectPads.pop` method. One can peek at the data with the :func:`~gi.repository.GstBase.CollectPads.peek` function. These functions will return :const:`None` if the pad received an EOS event. When all pads return :const:`None` from a :func:`~gi.repository.GstBase.CollectPads.peek`, the element can emit an EOS event itself. - Data can also be dequeued in byte units using the :func:`~gi.repository.GstBase.CollectPads.available`, :func:`~gi.repository.GstBase.CollectPads.read_buffer` and :func:`~gi.repository.GstBase.CollectPads.flush` calls. - Elements should call :func:`~gi.repository.GstBase.CollectPads.start` and :func:`~gi.repository.GstBase.CollectPads.stop` in their state change functions to start and stop the processing of the collectpads. The :func:`~gi.repository.GstBase.CollectPads.stop` call should be called before calling the parent element state change function in the PAUSED_TO_READY state change to ensure no pad is blocked and the element can finish streaming. - :func:`~gi.repository.GstBase.CollectPads.set_waiting` sets a pad to waiting or non-waiting mode. CollectPads element is not waiting for data to be collected on non-waiting pads. Thus these pads may but need not have data when the callback is called. All pads are in waiting mode by default. Constructors ------------ .. rst-class:: interim-class .. class:: CollectPads :no-index: .. classmethod:: new() -> ~gi.repository.GstBase.CollectPads Create a new instance of :obj:`~gi.repository.GstBase.CollectPads`\. MT safe. Methods ------- .. rst-class:: interim-class .. class:: CollectPads :no-index: .. method:: add_pad(pad: ~gi.repository.Gst.Pad, size: int, destroy_notify: ~typing.Callable[[~gi.repository.GstBase.CollectData], None], lock: bool) -> ~gi.repository.GstBase.CollectData | None Add a pad to the collection of collect pads. The pad has to be a sinkpad. The refcount of the pad is incremented. Use :func:`~gi.repository.GstBase.CollectPads.remove_pad` to remove the pad from the collection again. You specify a size for the returned :obj:`~gi.repository.GstBase.CollectData` structure so that you can use it to store additional information. You can also specify a :obj:`~gi.repository.GstBase.CollectDataDestroyNotify` that will be called just before the :obj:`~gi.repository.GstBase.CollectData` structure is freed. It is passed the pointer to the structure and should free any custom memory and resources allocated for it. Keeping a pad locked in waiting state is only relevant when using the default collection algorithm (providing the oldest buffer). It ensures a buffer must be available on this pad for a collection to take place. This is of typical use to a muxer element where non-subtitle streams should always be in waiting state, e.g. to assure that caps information is available on all these streams when initial headers have to be written. The pad will be automatically activated in push mode when ``pads`` is started. MT safe. :param pad: the pad to add :param size: the size of the returned :obj:`~gi.repository.GstBase.CollectData` structure :param destroy_notify: function to be called before the returned :obj:`~gi.repository.GstBase.CollectData` structure is freed :param lock: whether to lock this pad in usual waiting state .. method:: available() -> int Query how much bytes can be read from each queued buffer. This means that the result of this call is the maximum number of bytes that can be read from each of the pads. This function should be called with ``pads`` STREAM_LOCK held, such as in the callback. MT safe. .. method:: clip_running_time(cdata: ~gi.repository.GstBase.CollectData, buf: ~gi.repository.Gst.Buffer, user_data: ~typing.Any = None) -> ~typing.Tuple[~gi.repository.Gst.FlowReturn, ~gi.repository.Gst.Buffer] Convenience clipping function that converts incoming buffer's timestamp to running time, or clips the buffer if outside configured segment. Since 1.6, this clipping function also sets the DTS parameter of the GstCollectData structure. This version of the running time DTS can be negative. G_MININT64 is used to indicate invalid value. :param cdata: collect data of corresponding pad :param buf: buffer being clipped :param user_data: user data (unused) .. method:: event_default(data: ~gi.repository.GstBase.CollectData, event: ~gi.repository.Gst.Event, discard: bool) -> bool Default :obj:`~gi.repository.GstBase.CollectPads` event handling that elements should always chain up to to ensure proper operation. Element might however indicate event should not be forwarded downstream. :param data: collect data of corresponding pad :param event: event being processed :param discard: process but do not send event downstream .. method:: flush(data: ~gi.repository.GstBase.CollectData, size: int) -> int Flush ``size`` bytes from the pad ``data``\. This function should be called with ``pads`` STREAM_LOCK held, such as in the callback. MT safe. :param data: the data to use :param size: the number of bytes to flush .. method:: peek(data: ~gi.repository.GstBase.CollectData) -> ~gi.repository.Gst.Buffer | None Peek at the buffer currently queued in ``data``\. This function should be called with the ``pads`` STREAM_LOCK held, such as in the callback handler. MT safe. :param data: the data to use .. method:: pop(data: ~gi.repository.GstBase.CollectData) -> ~gi.repository.Gst.Buffer | None Pop the buffer currently queued in ``data``\. This function should be called with the ``pads`` STREAM_LOCK held, such as in the callback handler. MT safe. :param data: the data to use .. method:: query_default(data: ~gi.repository.GstBase.CollectData, query: ~gi.repository.Gst.Query, discard: bool) -> bool Default :obj:`~gi.repository.GstBase.CollectPads` query handling that elements should always chain up to to ensure proper operation. Element might however indicate query should not be forwarded downstream. :param data: collect data of corresponding pad :param query: query being processed :param discard: process but do not send event downstream .. method:: read_buffer(data: ~gi.repository.GstBase.CollectData, size: int) -> ~gi.repository.Gst.Buffer | None Get a subbuffer of ``size`` bytes from the given pad ``data``\. This function should be called with ``pads`` STREAM_LOCK held, such as in the callback. MT safe. :param data: the data to use :param size: the number of bytes to read .. method:: remove_pad(pad: ~gi.repository.Gst.Pad) -> bool Remove a pad from the collection of collect pads. This function will also free the :obj:`~gi.repository.GstBase.CollectData` and all the resources that were allocated with :func:`~gi.repository.GstBase.CollectPads.add_pad`. The pad will be deactivated automatically when ``pads`` is stopped. MT safe. :param pad: the pad to remove .. method:: set_buffer_function(func: ~typing.Callable[[~gi.repository.GstBase.CollectPads, ~gi.repository.GstBase.CollectData, ~gi.repository.Gst.Buffer, ~typing.Any], ~gi.repository.Gst.FlowReturn], user_data: ~typing.Any = None) -> None Set the callback function and user data that will be called with the oldest buffer when all pads have been collected, or :const:`None` on EOS. If a buffer is passed, the callback owns a reference and must unref it. MT safe. :param func: the function to set :param user_data: user data passed to the function .. method:: set_clip_function(clipfunc: ~typing.Callable[[~gi.repository.GstBase.CollectPads, ~gi.repository.GstBase.CollectData, ~gi.repository.Gst.Buffer, ~typing.Any], ~typing.Tuple[~gi.repository.Gst.FlowReturn, ~gi.repository.Gst.Buffer]], user_data: ~typing.Any = None) -> None Install a clipping function that is called right after a buffer is received on a pad managed by ``pads``\. See :obj:`~gi.repository.GstBase.CollectPadsClipFunction` for more info. :param clipfunc: clip function to install :param user_data: user data to pass to ``clip_func`` .. method:: set_compare_function(func: ~typing.Callable[[~gi.repository.GstBase.CollectPads, ~gi.repository.GstBase.CollectData, int, ~gi.repository.GstBase.CollectData, int, ~typing.Any], int], user_data: ~typing.Any = None) -> None Set the timestamp comparison function. MT safe. :param func: the function to set :param user_data: user data passed to the function .. method:: set_event_function(func: ~typing.Callable[[~gi.repository.GstBase.CollectPads, ~gi.repository.GstBase.CollectData, ~gi.repository.Gst.Event, ~typing.Any], bool], user_data: ~typing.Any = None) -> None Set the event callback function and user data that will be called when collectpads has received an event originating from one of the collected pads. If the event being processed is a serialized one, this callback is called with ``pads`` STREAM_LOCK held, otherwise not. As this lock should be held when calling a number of CollectPads functions, it should be acquired if so (unusually) needed. MT safe. :param func: the function to set :param user_data: user data passed to the function .. method:: set_flush_function(func: ~typing.Callable[[~gi.repository.GstBase.CollectPads, ~typing.Any], None], user_data: ~typing.Any = None) -> None Install a flush function that is called when the internal state of all pads should be flushed as part of flushing seek handling. See :obj:`~gi.repository.GstBase.CollectPadsFlushFunction` for more info. .. versionadded:: 1.4 :param func: flush function to install :param user_data: user data to pass to ``func`` .. method:: set_flushing(flushing: bool) -> None Change the flushing state of all the pads in the collection. No pad is able to accept anymore data when ``flushing`` is :const:`True`. Calling this function with ``flushing`` :const:`False` makes ``pads`` accept data again. Caller must ensure that downstream streaming (thread) is not blocked, e.g. by sending a FLUSH_START downstream. MT safe. :param flushing: desired state of the pads .. method:: set_function(func: ~typing.Callable[[~gi.repository.GstBase.CollectPads, ~typing.Any], ~gi.repository.Gst.FlowReturn], user_data: ~typing.Any = None) -> None CollectPads provides a default collection algorithm that will determine the oldest buffer available on all of its pads, and then delegate to a configured callback. However, if circumstances are more complicated and/or more control is desired, this sets a callback that will be invoked instead when all the pads added to the collection have buffers queued. Evidently, this callback is not compatible with :func:`~gi.repository.GstBase.CollectPads.set_buffer_function` callback. If this callback is set, the former will be unset. MT safe. :param func: the function to set :param user_data: user data passed to the function .. method:: set_query_function(func: ~typing.Callable[[~gi.repository.GstBase.CollectPads, ~gi.repository.GstBase.CollectData, ~gi.repository.Gst.Query, ~typing.Any], bool], user_data: ~typing.Any = None) -> None Set the query callback function and user data that will be called after collectpads has received a query originating from one of the collected pads. If the query being processed is a serialized one, this callback is called with ``pads`` STREAM_LOCK held, otherwise not. As this lock should be held when calling a number of CollectPads functions, it should be acquired if so (unusually) needed. MT safe. :param func: the function to set :param user_data: user data passed to the function .. method:: set_waiting(data: ~gi.repository.GstBase.CollectData, waiting: bool) -> None Sets a pad to waiting or non-waiting mode, if at least this pad has not been created with locked waiting state, in which case nothing happens. This function should be called with ``pads`` STREAM_LOCK held, such as in the callback. MT safe. :param data: the data to use :param waiting: boolean indicating whether this pad should operate in waiting or non-waiting mode .. method:: src_event_default(pad: ~gi.repository.Gst.Pad, event: ~gi.repository.Gst.Event) -> bool Default :obj:`~gi.repository.GstBase.CollectPads` event handling for the src pad of elements. Elements can chain up to this to let flushing seek event handling be done by :obj:`~gi.repository.GstBase.CollectPads`\. .. versionadded:: 1.4 :param pad: src :obj:`~gi.repository.Gst.Pad` that received the event :param event: event being processed .. method:: start() -> None Starts the processing of data in the collect_pads. MT safe. .. method:: stop() -> None Stops the processing of data in the collect_pads. this function will also unblock any blocking operations. MT safe. .. method:: take_buffer(data: ~gi.repository.GstBase.CollectData, size: int) -> ~gi.repository.Gst.Buffer | None Get a subbuffer of ``size`` bytes from the given pad ``data``\. Flushes the amount of read bytes. This function should be called with ``pads`` STREAM_LOCK held, such as in the callback. MT safe. :param data: the data to use :param size: the number of bytes to read Fields ------ .. rst-class:: interim-class .. class:: CollectPads :no-index: .. attribute:: data ``GList`` of :obj:`~gi.repository.GstBase.CollectData` managed by this :obj:`~gi.repository.GstBase.CollectPads`\. .. attribute:: object .. attribute:: priv .. attribute:: stream_lock