Element

class Element(**properties: Any)

Superclasses: Object, InitiallyUnowned, Object

Subclasses: Bin

GstElement is the abstract base class needed to construct an element that can be used in a GStreamer pipeline. Please refer to the plugin writers guide for more information on creating Element subclasses.

The name of a Element can be get with element_get_name() and set with element_set_name(). For speed, ELEMENT_NAME() can be used in the core when using the appropriate locking. Do not use this in plug-ins or applications in order to retain ABI compatibility.

Elements can have pads (of the type Pad). These pads link to pads on other elements. Buffer flow between these linked pads. A Element has a GList of Pad structures for all their input (or sink) and output (or source) pads. Core and plug-in writers can add and remove pads with add_pad() and remove_pad().

An existing pad of an element can be retrieved by name with get_static_pad(). A new dynamic pad can be created using request_pad() with a PadTemplate. An iterator of all pads can be retrieved with iterate_pads().

Elements can be linked through their pads. If the link is straightforward, use the link() convenience function to link two elements, or link_many() for more elements in a row. Use link_filtered() to link two elements constrained by a specified set of Caps. For finer control, use link_pads() and link_pads_filtered() to specify the pads to link on each element by name.

Each element has a state (see State). You can get and set the state of an element with get_state() and set_state(). Setting a state triggers a StateChange. To get a string representation of a State, use state_get_name().

You can get and set a Clock on an element using get_clock() and set_clock(). Some elements can provide a clock for the pipeline if the GST_ELEMENT_FLAG_PROVIDE_CLOCK flag is set. With the provide_clock() method one can retrieve the clock provided by such an element. Not all elements require a clock to operate correctly. If the ``GST_ELEMENT_FLAG_REQUIRE_CLOCK``() flag is set, a clock should be set on the element with set_clock().

Note that clock selection and distribution is normally handled by the toplevel Pipeline so the clock functions are only to be used in very specific situations.

Methods

class Element
abort_state() None

Abort the state change of the element. This function is used by elements that do asynchronous state changes and find out something is wrong.

This function should be called with the STATE_LOCK held.

MT safe.

classmethod add_metadata(key: str, value: str) None
Parameters:
  • key

  • value

add_pad(pad: Pad) bool

Adds a pad (link point) to element. pad’s parent will be set to element; see set_parent() for refcounting information.

Pads are automatically activated when added in the PAUSED or PLAYING state.

The pad and the element should be unlocked when calling this function.

This function will emit the Element::pad-added signal on the element.

Parameters:

pad – the Pad to add to the element.

classmethod add_pad_template(templ: PadTemplate) None
Parameters:

templ

add_property_deep_notify_watch(property_name: str | None, include_value: bool) int

Added in version 1.10.

Parameters:
  • property_name – name of property to watch for changes, or NULL to watch all properties

  • include_value – whether to include the new property value in the message

add_property_notify_watch(property_name: str | None, include_value: bool) int

Added in version 1.10.

Parameters:
  • property_name – name of property to watch for changes, or NULL to watch all properties

  • include_value – whether to include the new property value in the message

classmethod add_static_metadata(key: str, value: str) None
Parameters:
  • key

  • value

classmethod add_static_pad_template(static_templ: StaticPadTemplate) None
Parameters:

static_templ

classmethod add_static_pad_template_with_gtype(static_templ: StaticPadTemplate, pad_type: type) None
Parameters:
  • static_templ

  • pad_type

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

Calls func from another thread and passes user_data to it. This is to be used for cases when a state change has to be performed from a streaming thread, directly via set_state() or indirectly e.g. via SEEK events.

Calling those functions directly from the streaming thread will cause deadlocks in many situations, as they might involve waiting for the streaming thread to shut down from this very streaming thread.

MT safe.

Added in version 1.10.

Parameters:
  • func – Function to call asynchronously from another thread

  • user_data – Data to pass to func

change_state(transition: StateChange) StateChangeReturn

Perform transition on element.

This function must be called with STATE_LOCK held and is mainly used internally.

Parameters:

transition – the requested transition

continue_state(ret: StateChangeReturn) StateChangeReturn

Commit the state change of the element and proceed to the next pending state if any. This function is used by elements that do asynchronous state changes. The core will normally call this method automatically when an element returned SUCCESS from the state change function.

If after calling this method the element still has not reached the pending state, the next state change is performed.

This method is used internally and should normally not be called by plugins or applications.

This function must be called with STATE_LOCK held.

Parameters:

ret – The previous state return value

create_all_pads() None

Creates a pad for each pad template that is always available. This function is only useful during object initialization of subclasses of Element.

foreach_pad(func: Callable[[...], bool], *user_data: Any) bool

Call func with user_data for each of element’s pads. func will be called exactly once for each pad that exists at the time of this call, unless one of the calls to func returns False in which case we will stop iterating pads and return early. If new pads are added or pads are removed while pads are being iterated, this will not be taken into account until next time this function is used.

Added in version 1.14.

Parameters:
  • func – function to call for each pad

  • user_data – user data passed to func

foreach_sink_pad(func: Callable[[...], bool], *user_data: Any) bool

Call func with user_data for each of element’s sink pads. func will be called exactly once for each sink pad that exists at the time of this call, unless one of the calls to func returns False in which case we will stop iterating pads and return early. If new sink pads are added or sink pads are removed while the sink pads are being iterated, this will not be taken into account until next time this function is used.

Added in version 1.14.

Parameters:
  • func – function to call for each sink pad

  • user_data – user data passed to func

foreach_src_pad(func: Callable[[...], bool], *user_data: Any) bool

Call func with user_data for each of element’s source pads. func will be called exactly once for each source pad that exists at the time of this call, unless one of the calls to func returns False in which case we will stop iterating pads and return early. If new source pads are added or source pads are removed while the source pads are being iterated, this will not be taken into account until next time this function is used.

Added in version 1.14.

Parameters:
  • func – function to call for each source pad

  • user_data – user data passed to func

get_base_time() int

Returns the base time of the element. The base time is the absolute time of the clock when this element was last put to PLAYING. Subtracting the base time from the clock time gives the running time of the element.

get_bus() Bus | None

Returns the bus of the element. Note that only a Pipeline will provide a bus for the application.

get_clock() Clock | None

Gets the currently configured clock of the element. This is the clock as was last set with set_clock().

Elements in a pipeline will only have their clock set when the pipeline is in the PLAYING state.

get_compatible_pad(pad: Pad, caps: Caps | None = None) Pad | None

Looks for an unlinked pad to which the given pad can link. It is not guaranteed that linking the pads will work, though it should work in most cases.

This function will first attempt to find a compatible unlinked ALWAYS pad, and if none can be found, it will request a compatible REQUEST pad by looking at the templates of element.

Parameters:
  • pad – the Pad to find a compatible one for.

  • caps – the Caps to use as a filter.

get_compatible_pad_template(compattempl: PadTemplate) PadTemplate | None

Retrieves a pad template from element that is compatible with compattempl. Pads from compatible templates can be linked together.

Parameters:

compattempl – the PadTemplate to find a compatible template for

get_context(context_type: str) Context | None

Gets the context with context_type set on the element or NULL.

MT safe.

Added in version 1.8.

Parameters:

context_type – a name of a context to retrieve

get_context_unlocked(context_type: str) Context | None

Gets the context with context_type set on the element or NULL.

Added in version 1.8.

Parameters:

context_type – a name of a context to retrieve

get_contexts() list[Context]

Gets the contexts set on the element.

MT safe.

Added in version 1.8.

get_current_clock_time() int

Returns the current clock time of the element, as in, the time of the element’s clock, or GST_CLOCK_TIME_NONE if there is no clock.

Added in version 1.18.

get_current_running_time() int

Returns the running time of the element. The running time is the element’s clock time minus its base time. Will return GST_CLOCK_TIME_NONE if the element has no clock, or if its base time has not been set.

Added in version 1.18.

get_factory() ElementFactory | None

Retrieves the factory that was used to create this element.

get_metadata(key: str) str

Get metadata with key in klass.

Added in version 1.14.

Parameters:

key – the key to get

get_pad_template(name: str) PadTemplate | None

Retrieves a padtemplate from element with the given name.

Added in version 1.14.

Parameters:

name – the name of the PadTemplate to get.

get_pad_template_list() list[PadTemplate]

Retrieves a list of the pad templates associated with element. The list must not be modified by the calling code.

Added in version 1.14.

get_request_pad(name: str) Pad | None

The name of this function is confusing to people learning GStreamer. request_pad_simple() aims at making it more explicit it is a simplified request_pad().

Deprecated since version 1.20: Prefer using request_pad_simple() which provides the exact same functionality.

Parameters:

name – the name of the request Pad to retrieve.

get_start_time() int

Returns the start time of the element. The start time is the running time of the clock when this element was last put to PAUSED.

Usually the start_time is managed by a toplevel element such as Pipeline.

MT safe.

get_state(timeout: int) tuple[StateChangeReturn, State, State]

Gets the state of the element.

For elements that performed an ASYNC state change, as reported by set_state(), this function will block up to the specified timeout value for the state change to complete. If the element completes the state change or goes into an error, this function returns immediately with a return value of SUCCESS or FAILURE respectively.

For elements that did not return ASYNC, this function returns the current and pending state immediately.

This function returns NO_PREROLL if the element successfully changed its state but is not able to provide data yet. This mostly happens for live sources that only produce data in PLAYING. While the state change return is equivalent to SUCCESS, it is returned to the application to signal that some sink elements might not be able to complete their state change because an element is not producing data to complete the preroll. When setting the element to playing, the preroll will complete and playback will start.

Parameters:

timeout – a ClockTime to specify the timeout for an async state change or CLOCK_TIME_NONE for infinite timeout.

get_static_pad(name: str) Pad | None

Retrieves a pad from element by name. This version only retrieves already-existing (i.e. ‘static’) pads.

Parameters:

name – the name of the static Pad to retrieve.

is_locked_state() bool

Checks if the state of an element is locked. If the state of an element is locked, state changes of the parent don’t affect the element. This way you can leave currently unused elements inside bins. Just lock their state before changing the state from GST_STATE_NULL.

MT safe.

iterate_pads() Iterator

Retrieves an iterator of element’s pads. The iterator should be freed after usage. Also more specialized iterators exists such as iterate_src_pads() or iterate_sink_pads().

The order of pads returned by the iterator will be the order in which the pads were added to the element.

iterate_sink_pads() Iterator

Retrieves an iterator of element’s sink pads.

The order of pads returned by the iterator will be the order in which the pads were added to the element.

iterate_src_pads() Iterator

Retrieves an iterator of element’s source pads.

The order of pads returned by the iterator will be the order in which the pads were added to the element.

Links src to dest. The link must be from source to destination; the other direction will not be tried. The function looks for existing pads that aren’t linked yet. It will request new pads if necessary. Such pads need to be released manually when unlinking. If multiple links are possible, only one is established.

Make sure you have added your elements to a bin or pipeline with add() before trying to link them.

Parameters:

dest – the Element containing the destination pad.

Links src to dest using the given caps as filtercaps. The link must be from source to destination; the other direction will not be tried. The function looks for existing pads that aren’t linked yet. It will request new pads if necessary. If multiple links are possible, only one is established.

Make sure you have added your elements to a bin or pipeline with add() before trying to link them.

Parameters:
  • dest – the Element containing the destination pad.

  • filter – the Caps to filter the link, or None for no filter.

Links the two named pads of the source and destination elements. Side effect is that if one of the pads has no parent, it becomes a child of the parent of the other element. If they have different parents, the link fails.

Parameters:
  • srcpadname – the name of the Pad in source element or None for any pad.

  • dest – the Element containing the destination pad.

  • destpadname – the name of the Pad in destination element, or None for any pad.

Links the two named pads of the source and destination elements. Side effect is that if one of the pads has no parent, it becomes a child of the parent of the other element. If they have different parents, the link fails. If caps is not None, makes sure that the caps of the link is a subset of caps.

Parameters:
  • srcpadname – the name of the Pad in source element or None for any pad.

  • dest – the Element containing the destination pad.

  • destpadname – the name of the Pad in destination element or None for any pad.

  • filter – the Caps to filter the link, or None for no filter.

Links the two named pads of the source and destination elements. Side effect is that if one of the pads has no parent, it becomes a child of the parent of the other element. If they have different parents, the link fails.

Calling link_pads_full() with flags == DEFAULT is the same as calling link_pads() and the recommended way of linking pads with safety checks applied.

This is a convenience function for link_full().

Parameters:
  • srcpadname – the name of the Pad in source element or None for any pad.

  • dest – the Element containing the destination pad.

  • destpadname – the name of the Pad in destination element, or None for any pad.

  • flags – the PadLinkCheck to be performed when linking pads.

lost_state() None

Brings the element to the lost state. The current state of the element is copied to the pending state so that any call to get_state() will return ASYNC.

An ASYNC_START message is posted. If the element was PLAYING, it will go to PAUSED. The element will be restored to its PLAYING state by the parent pipeline when it prerolls again.

This is mostly used for elements that lost their preroll buffer in the PAUSED or PLAYING state after a flush, they will go to their pending state again when a new preroll buffer is queued. This function can only be called when the element is currently not in error or an async state change.

This function is used internally and should normally not be called from plugins or applications.

make_from_uri(type: URIType, uri: str, elementname: str | None = None) Element

Creates an element for handling the given URI.

Parameters:
  • type – Whether to create a source or a sink

  • uri – URI to create an element for

  • elementname – Name of created element, can be None.

message_full(type: MessageType, domain: int, code: int, text: str | None, debug: str | None, file: str, function: str, line: int) None

Post an error, warning or info message on the bus from inside an element.

type must be of GST_MESSAGE_ERROR, GST_MESSAGE_WARNING or GST_MESSAGE_INFO.

MT safe.

Parameters:
  • type – the MessageType

  • domain – the GStreamer GError domain this message belongs to

  • code – the GError code belonging to the domain

  • text – an allocated text string to be used as a replacement for the default message connected to code, or None

  • debug – an allocated debug message to be used as a replacement for the default debugging information, or None

  • file – the source code file where the error was generated

  • function – the source code function where the error was generated

  • line – the source code line where the error was generated

message_full_with_details(type: MessageType, domain: int, code: int, text: str | None, debug: str | None, file: str, function: str, line: int, structure: Structure) None

Post an error, warning or info message on the bus from inside an element.

type must be of GST_MESSAGE_ERROR, GST_MESSAGE_WARNING or GST_MESSAGE_INFO.

Added in version 1.10.

Parameters:
  • type – the MessageType

  • domain – the GStreamer GError domain this message belongs to

  • code – the GError code belonging to the domain

  • text – an allocated text string to be used as a replacement for the default message connected to code, or None

  • debug – an allocated debug message to be used as a replacement for the default debugging information, or None

  • file – the source code file where the error was generated

  • function – the source code function where the error was generated

  • line – the source code line where the error was generated

  • structure – optional details structure

no_more_pads() None

Use this function to signal that the element does not expect any more pads to show up in the current pipeline. This function should be called whenever pads have been added by the element itself. Elements with GST_PAD_SOMETIMES pad templates use this in combination with autopluggers to figure out that the element is done initializing its pads.

This function emits the Element::no-more-pads signal.

MT safe.

post_message(message: Message) bool

Post a message on the element’s Bus. This function takes ownership of the message; if you want to access the message after this call, you should add an additional reference before calling.

Parameters:

message – a Message to post

provide_clock() Clock | None

Get the clock provided by the given element. > An element is only required to provide a clock in the PAUSED > state. Some elements can provide a clock in other states.

query(query: Query) bool

Performs a query on the given element.

For elements that don’t implement a query handler, this function forwards the query to a random srcpad or to the peer of a random linked sinkpad of this element.

Please note that some queries might need a running pipeline to work.

Parameters:

query – the Query.

query_convert(src_format: Format, src_val: int, dest_format: Format) tuple[bool, int]

Queries an element to convert src_val in src_format to dest_format.

Parameters:
  • src_format – a Format to convert from.

  • src_val – a value to convert.

  • dest_format – the Format to convert to.

query_duration(format: Format) tuple[bool, int]

Queries an element (usually top-level pipeline or playbin element) for the total stream duration in nanoseconds. This query will only work once the pipeline is prerolled (i.e. reached PAUSED or PLAYING state). The application will receive an ASYNC_DONE message on the pipeline bus when that is the case.

If the duration changes for some reason, you will get a DURATION_CHANGED message on the pipeline bus, in which case you should re-query the duration using this function.

Parameters:

format – the Format requested

query_position(format: Format) tuple[bool, int]

Queries an element (usually top-level pipeline or playbin element) for the stream position in nanoseconds. This will be a value between 0 and the stream duration (if the stream duration is known). This query will usually only work once the pipeline is prerolled (i.e. reached PAUSED or PLAYING state). The application will receive an ASYNC_DONE message on the pipeline bus when that is the case.

If one repeatedly calls this function one can also create a query and reuse it in query().

Parameters:

format – the Format requested

register(plugin: Plugin | None, name: str, rank: int, type: type) bool

Create a new elementfactory capable of instantiating objects of the type and add the factory to plugin.

Parameters:
  • pluginPlugin to register the element with, or None for a static element.

  • name – name of elements of this type

  • rank – rank of element (higher rank means more importance when autoplugging)

  • type – GType of element to register

release_request_pad(pad: Pad) None

Makes the element free the previously requested pad as obtained with request_pad().

This does not unref the pad. If the pad was created by using request_pad(), release_request_pad() needs to be followed by unref() to free the pad.

MT safe.

Parameters:

pad – the Pad to release.

remove_pad(pad: Pad) bool

Removes pad from element. pad will be destroyed if it has not been referenced elsewhere using unparent().

This function is used by plugin developers and should not be used by applications. Pads that were dynamically requested from elements with request_pad() should be released with the release_request_pad() function instead.

Pads are not automatically deactivated so elements should perform the needed steps to deactivate the pad in case this pad is removed in the PAUSED or PLAYING state. See set_active() for more information about deactivating pads.

The pad and the element should be unlocked when calling this function.

This function will emit the Element::pad-removed signal on the element.

Parameters:

pad – the Pad to remove from the element.

remove_property_notify_watch(watch_id: int) None

Added in version 1.10.

Parameters:

watch_id – watch id to remove

request_pad(templ: PadTemplate, name: str | None = None, caps: Caps | None = None) Pad | None

Retrieves a request pad from the element according to the provided template. Pad templates can be looked up using get_static_pad_templates().

The pad should be released with release_request_pad().

Parameters:
  • templ – a PadTemplate of which we want a pad of.

  • name – the name of the request Pad to retrieve. Can be None.

  • caps – the caps of the pad we want to request. Can be None.

request_pad_simple(name: str) Pad | None

Retrieves a pad from the element by name (e.g. “src_``%d``”). This version only retrieves request pads. The pad should be released with release_request_pad().

This method is slower than manually getting the pad template and calling request_pad() if the pads should have a specific name (e.g. name is “src_1” instead of “src_``%u``”).

Note that this function was introduced in GStreamer 1.20 in order to provide a better name to get_request_pad(). Prior to 1.20, users should use get_request_pad() which provides the same functionality.

Added in version 1.20.

Parameters:

name – the name of the request Pad to retrieve.

seek(rate: float, format: Format, flags: SeekFlags, start_type: SeekType, start: int, stop_type: SeekType, stop: int) bool

Sends a seek event to an element. See new_seek() for the details of the parameters. The seek event is sent to the element using send_event().

MT safe.

Parameters:
  • rate – The new playback rate

  • format – The format of the seek values

  • flags – The optional seek flags.

  • start_type – The type and flags for the new start position

  • start – The value of the new start position

  • stop_type – The type and flags for the new stop position

  • stop – The value of the new stop position

seek_simple(format: Format, seek_flags: SeekFlags, seek_pos: int) bool

Simple API to perform a seek on the given element, meaning it just seeks to the given position relative to the start of the stream. For more complex operations like segment seeks (e.g. for looping) or changing the playback rate or seeking relative to the last configured playback segment you should use seek().

In a completely prerolled PAUSED or PLAYING pipeline, seeking is always guaranteed to return True on a seekable media type or False when the media type is certainly not seekable (such as a live stream).

Some elements allow for seeking in the READY state, in this case they will store the seek event and execute it when they are put to PAUSED. If the element supports seek in READY, it will always return True when it receives the event in the READY state.

Parameters:
  • format – a Format to execute the seek in, such as GST_FORMAT_TIME

  • seek_flags – seek options; playback applications will usually want to use GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT here

  • seek_pos – position to seek to (relative to the start); if you are doing a seek in GST_FORMAT_TIME this value is in nanoseconds - multiply with GST_SECOND to convert seconds to nanoseconds or with GST_MSECOND to convert milliseconds to nanoseconds.

send_event(event: Event) bool

Sends an event to an element. If the element doesn’t implement an event handler, the event will be pushed on a random linked sink pad for downstream events or a random linked source pad for upstream events.

This function takes ownership of the provided event so you should gst_event_ref() it if you want to reuse the event after this call.

MT safe.

Parameters:

event – the Event to send to the element.

set_base_time(time: int) None

Set the base time of an element. See get_base_time().

MT safe.

Parameters:

time – the base time to set.

set_bus(bus: Bus | None = None) None

Sets the bus of the element. Increases the refcount on the bus. For internal use only, unless you’re testing elements.

MT safe.

Parameters:

bus – the Bus to set.

set_clock(clock: Clock | None = None) bool

Sets the clock for the element. This function increases the refcount on the clock. Any previously set clock on the object is unreffed.

Parameters:

clock – the Clock to set for the element.

set_context(context: Context) None

Sets the context of the element. Increases the refcount of the context.

MT safe.

Parameters:

context – the Context to set.

set_locked_state(locked_state: bool) bool

Locks the state of an element, so state changes of the parent don’t affect this element anymore.

Note that this is racy if the state lock of the parent bin is not taken. The parent bin might’ve just checked the flag in another thread and as the next step proceed to change the child element’s state.

MT safe.

Parameters:

locked_stateTrue to lock the element’s state

classmethod set_metadata(longname: str, classification: str, description: str, author: str) None
Parameters:
  • longname

  • classification

  • description

  • author

set_start_time(time: int) None

Set the start time of an element. The start time of the element is the running time of the element when it last went to the PAUSED state. In READY or after a flushing seek, it is set to 0.

Toplevel elements like Pipeline will manage the start_time and base_time on its children. Setting the start_time to GST_CLOCK_TIME_NONE on such a toplevel element will disable the distribution of the base_time to the children and can be useful if the application manages the base_time itself, for example if you want to synchronize capture from multiple pipelines, and you can also ensure that the pipelines have the same clock.

MT safe.

Parameters:

time – the base time to set.

set_state(state: State) StateChangeReturn

Sets the state of the element. This function will try to set the requested state by going through all the intermediary states and calling the class’s state change function for each.

This function can return GST_STATE_CHANGE_ASYNC, in which case the element will perform the remainder of the state change asynchronously in another thread. An application can use get_state() to wait for the completion of the state change or it can wait for a ASYNC_DONE or STATE_CHANGED on the bus.

State changes to READY or NULL never return GST_STATE_CHANGE_ASYNC.

Parameters:

state – the element’s new State.

classmethod set_static_metadata(longname: str, classification: str, description: str, author: str) None
Parameters:
  • longname

  • classification

  • description

  • author

state_change_return_get_name(state_ret: StateChangeReturn) str

Gets a string representing the given state change result.

Parameters:

state_ret – a StateChangeReturn to get the name of.

state_get_name(state: State) str

Gets a string representing the given state.

Parameters:

state – a State to get the name of.

sync_state_with_parent() bool

Tries to change the state of the element to the same as its parent. If this function returns False, the state of element is undefined.

type_set_skip_documentation(type: type) None

Marks type as “documentation should be skipped”. Can be useful for dynamically registered element to be excluded from plugin documentation system.

Example:

GType my_type;
GTypeInfo my_type_info;

// Fill "my_type_info"
...

my_type = g_type_register_static (GST_TYPE_MY_ELEMENT, "my-type-name",
   &my_type_info, 0);
gst_element_type_set_skip_documentation (my_type);
gst_element_register (plugin, "my-plugin-feature-name", rank, my_type);

Added in version 1.20.

Parameters:

type – a Type of element

Unlinks all source pads of the source element with all sink pads of the sink element to which they are linked.

If the link has been made using link(), it could have created an requestpad, which has to be released using release_request_pad().

Parameters:

dest – the sink Element to unlink.

Unlinks the two named pads of the source and destination elements.

This is a convenience function for unlink().

Parameters:
  • srcpadname – the name of the Pad in source element.

  • dest – a Element containing the destination pad.

  • destpadname – the name of the Pad in destination element.

Signals

class Element.signals
no_more_pads() None

This signals that the element will not generate more dynamic pads. Note that this signal will usually be emitted from the context of the streaming thread.

pad_added(new_pad: Pad) None

a new Pad has been added to the element. Note that this signal will usually be emitted from the context of the streaming thread. Also keep in mind that if you add new elements to the pipeline in the signal handler you will need to set them to the desired target state with set_state() or sync_state_with_parent().

Parameters:

new_pad – the pad that has been added

pad_removed(old_pad: Pad) None

a Pad has been removed from the element

Parameters:

old_pad – the pad that has been removed

Virtual Methods

class Element
do_change_state(transition: StateChange) StateChangeReturn

Perform transition on element.

This function must be called with STATE_LOCK held and is mainly used internally.

Parameters:

transition – the requested transition

do_get_state(timeout: int) tuple[StateChangeReturn, State, State]

Gets the state of the element.

For elements that performed an ASYNC state change, as reported by set_state(), this function will block up to the specified timeout value for the state change to complete. If the element completes the state change or goes into an error, this function returns immediately with a return value of SUCCESS or FAILURE respectively.

For elements that did not return ASYNC, this function returns the current and pending state immediately.

This function returns NO_PREROLL if the element successfully changed its state but is not able to provide data yet. This mostly happens for live sources that only produce data in PLAYING. While the state change return is equivalent to SUCCESS, it is returned to the application to signal that some sink elements might not be able to complete their state change because an element is not producing data to complete the preroll. When setting the element to playing, the preroll will complete and playback will start.

Parameters:

timeout – a ClockTime to specify the timeout for an async state change or CLOCK_TIME_NONE for infinite timeout.

do_no_more_pads() None

Use this function to signal that the element does not expect any more pads to show up in the current pipeline. This function should be called whenever pads have been added by the element itself. Elements with GST_PAD_SOMETIMES pad templates use this in combination with autopluggers to figure out that the element is done initializing its pads.

This function emits the Element::no-more-pads signal.

MT safe.

do_pad_added(pad: Pad) None
Parameters:

pad

do_pad_removed(pad: Pad) None
Parameters:

pad

do_post_message(message: Message) bool

Post a message on the element’s Bus. This function takes ownership of the message; if you want to access the message after this call, you should add an additional reference before calling.

Parameters:

message – a Message to post

do_provide_clock() Clock | None

Get the clock provided by the given element. > An element is only required to provide a clock in the PAUSED > state. Some elements can provide a clock in other states.

do_query(query: Query) bool

Performs a query on the given element.

For elements that don’t implement a query handler, this function forwards the query to a random srcpad or to the peer of a random linked sinkpad of this element.

Please note that some queries might need a running pipeline to work.

Parameters:

query – the Query.

do_release_pad(pad: Pad) None
Parameters:

pad

do_request_new_pad(templ: PadTemplate, name: str | None = None, caps: Caps | None = None) Pad | None

Retrieves a request pad from the element according to the provided template. Pad templates can be looked up using get_static_pad_templates().

The pad should be released with release_request_pad().

Parameters:
  • templ – a PadTemplate of which we want a pad of.

  • name – the name of the request Pad to retrieve. Can be None.

  • caps – the caps of the pad we want to request. Can be None.

do_send_event(event: Event) bool

Sends an event to an element. If the element doesn’t implement an event handler, the event will be pushed on a random linked sink pad for downstream events or a random linked source pad for upstream events.

This function takes ownership of the provided event so you should gst_event_ref() it if you want to reuse the event after this call.

MT safe.

Parameters:

event – the Event to send to the element.

do_set_bus(bus: Bus | None = None) None

Sets the bus of the element. Increases the refcount on the bus. For internal use only, unless you’re testing elements.

MT safe.

Parameters:

bus – the Bus to set.

do_set_clock(clock: Clock | None = None) bool

Sets the clock for the element. This function increases the refcount on the clock. Any previously set clock on the object is unreffed.

Parameters:

clock – the Clock to set for the element.

do_set_context(context: Context) None

Sets the context of the element. Increases the refcount of the context.

MT safe.

Parameters:

context – the Context to set.

do_set_state(state: State) StateChangeReturn

Sets the state of the element. This function will try to set the requested state by going through all the intermediary states and calling the class’s state change function for each.

This function can return GST_STATE_CHANGE_ASYNC, in which case the element will perform the remainder of the state change asynchronously in another thread. An application can use get_state() to wait for the completion of the state change or it can wait for a ASYNC_DONE or STATE_CHANGED on the bus.

State changes to READY or NULL never return GST_STATE_CHANGE_ASYNC.

Parameters:

state – the element’s new State.

do_state_changed(oldstate: State, newstate: State, pending: State) None
Parameters:
  • oldstate

  • newstate

  • pending

Fields

class Element
base_time

The time of the clock right before the element is set to PLAYING. Subtracting base_time from the current clock time in the PLAYING state will yield the running_time against the clock.

bus

The bus of the element. This bus is provided to the element by the parent element or the application. A Pipeline has a bus of its own.

clock

The clock of the element. This clock is usually provided to the element by the toplevel Pipeline.

contexts

List of contexts

current_state

The current state of an element

last_return

The last return value of an element state change

next_state

The next state of an element, can be GST_STATE_VOID_PENDING if the element is in the correct state.

numpads

Number of pads of the element, includes both source and sink pads.

numsinkpads

Number of sink pads of the element.

numsrcpads

Number of source pads of the element.

object
pads

List of pads

Updated whenever the a pad is added or removed

pending_state

The final state the element should go to, can be GST_STATE_VOID_PENDING if the element is in the correct state

sinkpads

List of sink pads

srcpads

List of source pads

start_time

The running_time of the last PAUSED state

state_cond

Used to signal completion of a state change

Used to detect concurrent execution of set_state() and get_state()

state_lock

Used to serialize execution of set_state()

target_state

The target state of an element as set by the application