CollectPads

class CollectPads(**properties: Any)

Superclasses: Object, InitiallyUnowned, 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 new(). A callback should then be installed with gst_collect_pads_set_function ().

  • Pads are added to the collection with add_pad()/ 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 pop() method. One can peek at the data with the peek() function. These functions will return None if the pad received an EOS event. When all pads return None from a peek(), the element can emit an EOS event itself.

  • Data can also be dequeued in byte units using the available(), read_buffer() and flush() calls.

  • Elements should call start() and stop() in their state change functions to start and stop the processing of the collectpads. The 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.

  • 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

class CollectPads
classmethod new() CollectPads

Create a new instance of CollectPads.

MT safe.

Methods

class CollectPads
add_pad(pad: Pad, size: int, destroy_notify: Callable[[CollectData], None], lock: bool) 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 remove_pad() to remove the pad from the collection again.

You specify a size for the returned CollectData structure so that you can use it to store additional information.

You can also specify a CollectDataDestroyNotify that will be called just before the 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.

Parameters:
  • pad – the pad to add

  • size – the size of the returned CollectData structure

  • destroy_notify – function to be called before the returned CollectData structure is freed

  • lock – whether to lock this pad in usual waiting state

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.

clip_running_time(cdata: CollectData, buf: Buffer, user_data: None) tuple[FlowReturn, 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.

Parameters:
  • cdata – collect data of corresponding pad

  • buf – buffer being clipped

  • user_data – user data (unused)

event_default(data: CollectData, event: Event, discard: bool) bool

Default CollectPads event handling that elements should always chain up to to ensure proper operation. Element might however indicate event should not be forwarded downstream.

Parameters:
  • data – collect data of corresponding pad

  • event – event being processed

  • discard – process but do not send event downstream

flush(data: 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.

Parameters:
  • data – the data to use

  • size – the number of bytes to flush

peek(data: CollectData) 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.

Parameters:

data – the data to use

pop(data: CollectData) 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.

Parameters:

data – the data to use

query_default(data: CollectData, query: Query, discard: bool) bool

Default CollectPads query handling that elements should always chain up to to ensure proper operation. Element might however indicate query should not be forwarded downstream.

Parameters:
  • data – collect data of corresponding pad

  • query – query being processed

  • discard – process but do not send event downstream

read_buffer(data: CollectData, size: int) 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.

Parameters:
  • data – the data to use

  • size – the number of bytes to read

remove_pad(pad: Pad) bool

Remove a pad from the collection of collect pads. This function will also free the CollectData and all the resources that were allocated with add_pad().

The pad will be deactivated automatically when pads is stopped.

MT safe.

Parameters:

pad – the pad to remove

set_buffer_function(func: Callable[[...], FlowReturn], *user_data: Any) None

Set the callback function and user data that will be called with the oldest buffer when all pads have been collected, or None on EOS. If a buffer is passed, the callback owns a reference and must unref it.

MT safe.

Parameters:
  • func – the function to set

  • user_data – user data passed to the function

set_clip_function(clipfunc: Callable[[...], tuple[FlowReturn, Buffer]], *user_data: Any) None

Install a clipping function that is called right after a buffer is received on a pad managed by pads. See CollectPadsClipFunction for more info.

Parameters:
  • clipfunc – clip function to install

  • user_data – user data to pass to clip_func

set_compare_function(func: Callable[[...], int], *user_data: Any) None

Set the timestamp comparison function.

MT safe.

Parameters:
  • func – the function to set

  • user_data – user data passed to the function

set_event_function(func: Callable[[...], bool], *user_data: Any) 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.

Parameters:
  • func – the function to set

  • user_data – user data passed to the function

set_flush_function(func: Callable[[...], None], *user_data: Any) 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 CollectPadsFlushFunction for more info.

Added in version 1.4.

Parameters:
  • func – flush function to install

  • user_data – user data to pass to func

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 True. Calling this function with flushing 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.

Parameters:

flushing – desired state of the pads

set_function(func: Callable[[...], FlowReturn], *user_data: Any) 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 set_buffer_function() callback. If this callback is set, the former will be unset.

MT safe.

Parameters:
  • func – the function to set

  • user_data – user data passed to the function

set_query_function(func: Callable[[...], bool], *user_data: Any) 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.

Parameters:
  • func – the function to set

  • user_data – user data passed to the function

set_waiting(data: 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.

Parameters:
  • data – the data to use

  • waiting – boolean indicating whether this pad should operate in waiting or non-waiting mode

src_event_default(pad: Pad, event: Event) bool

Default CollectPads event handling for the src pad of elements. Elements can chain up to this to let flushing seek event handling be done by CollectPads.

Added in version 1.4.

Parameters:
  • pad – src Pad that received the event

  • event – event being processed

start() None

Starts the processing of data in the collect_pads.

MT safe.

stop() None

Stops the processing of data in the collect_pads. this function will also unblock any blocking operations.

MT safe.

take_buffer(data: CollectData, size: int) 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.

Parameters:
  • data – the data to use

  • size – the number of bytes to read

Fields

class CollectPads
data

GList of CollectData managed by this CollectPads.

object
priv
stream_lock