GstApp.AppSink

g GObject.GInterface GObject.GInterface Gst.URIHandler Gst.URIHandler GObject.GInterface->Gst.URIHandler GObject.InitiallyUnowned GObject.InitiallyUnowned Gst.Object Gst.Object GObject.InitiallyUnowned->Gst.Object GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gst.Element Gst.Element GstBase.BaseSink GstBase.BaseSink Gst.Element->GstBase.BaseSink Gst.Object->Gst.Element GstApp.AppSink GstApp.AppSink Gst.URIHandler->GstApp.AppSink GstBase.BaseSink->GstApp.AppSink

Subclasses:

None

Methods

Inherited:

GstBase.BaseSink (31), Gst.Element (81), Gst.Object (27), GObject.Object (37), Gst.URIHandler (4)

Structs:

Gst.ElementClass (10), GObject.ObjectClass (5)

get_buffer_list_support ()

get_caps ()

get_drop ()

get_emit_signals ()

get_max_buffers ()

get_wait_on_eos ()

is_eos ()

pull_preroll ()

pull_sample ()

set_buffer_list_support (enable_lists)

set_caps (caps)

set_drop (drop)

set_emit_signals (emit)

set_max_buffers (max)

set_wait_on_eos (wait)

try_pull_preroll (timeout)

try_pull_sample (timeout)

Virtual Methods

Inherited:

GstBase.BaseSink (18), Gst.Element (16), Gst.Object (1), GObject.Object (7), Gst.URIHandler (2)

do_eos ()

do_new_preroll ()

do_new_sample ()

do_pull_preroll ()

do_pull_sample ()

do_try_pull_preroll (timeout)

do_try_pull_sample (timeout)

Properties

Inherited:

GstBase.BaseSink (13), Gst.Object (2)

Name

Type

Flags

Short Description

buffer-list

bool

r/w

Use buffer lists

caps

Gst.Caps

r/w

The allowed caps for the sink pad

drop

bool

r/w

Drop old buffers when the buffer queue is filled

emit-signals

bool

r/w

Emit new-preroll and new-sample signals

eos

bool

r

Check if the sink is EOS or not started

max-buffers

int

r/w

The maximum number of buffers to queue internally (0 = unlimited)

wait-on-eos

bool

r/w

Wait for all buffers to be processed after receiving an EOS

Signals

Inherited:

Gst.Element (3), Gst.Object (1), GObject.Object (1)

Name

Short Description

eos

Signal that the end-of-stream has been reached.

new-preroll

Signal that a new preroll sample is available.

new-sample

Signal that a new sample is available.

new-serialized-event

Signal that a new downstream serialized event is available.

pull-preroll

Get the last preroll sample in appsink.

pull-sample

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/None state.

try-pull-object

This function blocks until a sample or an event becomes available or the appsink element is set to the READY/None state or the timeout expires.

try-pull-preroll

Get the last preroll sample in appsink.

try-pull-sample

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/None state or the timeout expires.

Fields

Inherited:

Gst.Element (3), Gst.Object (1), GObject.Object (1)

Name

Type

Access

Description

basesink

GstBase.BaseSink

r

Class Details

class GstApp.AppSink(**kwargs)
Bases:

GstBase.BaseSink, Gst.URIHandler

Abstract:

No

Structure:

GstApp.AppSinkClass

Appsink is a sink plugin that supports many different methods for making the application get a handle on the GStreamer data in a pipeline. Unlike most GStreamer elements, Appsink provides external API functions.

appsink can be used by linking to the gstappsink.h header file to access the methods or by using the appsink action signals and properties.

The normal way of retrieving samples from appsink is by using the GstApp.AppSink.pull_sample() and GstApp.AppSink.pull_preroll() methods. These methods block until a sample becomes available in the sink or when the sink is shut down or reaches EOS. There are also timed variants of these methods, GstApp.AppSink.try_pull_sample() and GstApp.AppSink.try_pull_preroll(), which accept a timeout parameter to limit the amount of time to wait.

Appsink will internally use a queue to collect buffers from the streaming thread. If the application is not pulling samples fast enough, this queue will consume a lot of memory over time. The “max-buffers” property can be used to limit the queue size. The “drop” property controls whether the streaming thread blocks or if older buffers are dropped when the maximum queue size is reached. Note that blocking the streaming thread can negatively affect real-time performance and should be avoided.

If a blocking behaviour is not desirable, setting the “emit-signals” property to True will make appsink emit the “new-sample” and “new-preroll” signals when a sample can be pulled without blocking.

The “caps” property on appsink can be used to control the formats that appsink can receive. This property can contain non-fixed caps, the format of the pulled samples can be obtained by getting the sample caps.

If one of the pull-preroll or pull-sample methods return None, the appsink is stopped or in the EOS state. You can check for the EOS state with the “eos” property or with the GstApp.AppSink.is_eos() method.

The eos signal can also be used to be informed when the EOS state is reached to avoid polling.

get_buffer_list_support()
Returns:

True if self supports buffer lists.

Return type:

bool

Check if self supports buffer lists.

New in version 1.12.

get_caps()
Returns:

the Gst.Caps accepted by the sink. gst_caps_unref() after usage.

Return type:

Gst.Caps or None

Get the configured caps on self.

get_drop()
Returns:

True if self is dropping old buffers when the queue is filled.

Return type:

bool

Check if self will drop old buffers when the maximum amount of queued buffers is reached.

get_emit_signals()
Returns:

True if self is emitting the “new-preroll” and “new-sample” signals.

Return type:

bool

Check if appsink will emit the “new-preroll” and “new-sample” signals.

get_max_buffers()
Returns:

The maximum amount of buffers that can be queued.

Return type:

int

Get the maximum amount of buffers that can be queued in self.

get_wait_on_eos()
Returns:

True if self will wait for all buffers to be consumed when an EOS is received.

Return type:

bool

Check if self will wait for all buffers to be consumed when an EOS is received.

is_eos()
Returns:

True if no more samples can be pulled and the appsink is EOS.

Return type:

bool

Check if self is EOS, which is when no more samples can be pulled because an EOS event was received.

This function also returns True when the appsink is not in the PAUSED or PLAYING state.

pull_preroll()
Returns:

a Gst.Sample or None when the appsink is stopped or EOS. Call gst_sample_unref() after usage.

Return type:

Gst.Sample or None

Get the last preroll sample in self. This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling GstApp.AppSink.pull_sample().

If an EOS event was received before any buffers, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

This function blocks until a preroll sample or EOS is received or the appsink element is set to the READY/None state.

pull_sample()
Returns:

a Gst.Sample or None when the appsink is stopped or EOS. Call gst_sample_unref() after usage.

Return type:

Gst.Sample or None

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/None state.

This function will only return samples when the appsink is in the PLAYING state. All rendered buffers will be put in a queue so that the application can pull samples at its own rate. Note that when the application does not pull samples fast enough, the queued buffers could consume a lot of memory, especially when dealing with raw video frames.

If an EOS event was received before any buffers, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

set_buffer_list_support(enable_lists)
Parameters:

enable_lists (bool) – enable or disable buffer list support

Instruct self to enable or disable buffer list support.

For backwards-compatibility reasons applications need to opt in to indicate that they will be able to handle buffer lists.

New in version 1.12.

set_caps(caps)
Parameters:

caps (Gst.Caps or None) – caps to set

Set the capabilities on the appsink element. This function takes a copy of the caps structure. After calling this method, the sink will only accept caps that match caps. If caps is non-fixed, or incomplete, you must check the caps on the samples to get the actual used caps.

set_drop(drop)
Parameters:

drop (bool) – the new state

Instruct self to drop old buffers when the maximum amount of queued buffers is reached.

set_emit_signals(emit)
Parameters:

emit (bool) – the new state

Make appsink emit the “new-preroll” and “new-sample” signals. This option is by default disabled because signal emission is expensive and unneeded when the application prefers to operate in pull mode.

set_max_buffers(max)
Parameters:

max (int) – the maximum number of buffers to queue

Set the maximum amount of buffers that can be queued in self. After this amount of buffers are queued in appsink, any more buffers will block upstream elements until a sample is pulled from self.

set_wait_on_eos(wait)
Parameters:

wait (bool) – the new state

Instruct self to wait for all buffers to be consumed when an EOS is received.

try_pull_preroll(timeout)
Parameters:

timeout (int) – the maximum amount of time to wait for the preroll sample

Returns:

a Gst.Sample or None when the appsink is stopped or EOS or the timeout expires. Call gst_sample_unref() after usage.

Return type:

Gst.Sample or None

Get the last preroll sample in self. This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling GstApp.AppSink.pull_sample().

If an EOS event was received before any buffers or the timeout expires, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

This function blocks until a preroll sample or EOS is received, the appsink element is set to the READY/None state, or the timeout expires.

New in version 1.10.

try_pull_sample(timeout)
Parameters:

timeout (int) – the maximum amount of time to wait for a sample

Returns:

a Gst.Sample or None when the appsink is stopped or EOS or the timeout expires. Call gst_sample_unref() after usage.

Return type:

Gst.Sample or None

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/None state or the timeout expires.

This function will only return samples when the appsink is in the PLAYING state. All rendered buffers will be put in a queue so that the application can pull samples at its own rate. Note that when the application does not pull samples fast enough, the queued buffers could consume a lot of memory, especially when dealing with raw video frames.

If an EOS event was received before any buffers or the timeout expires, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

New in version 1.10.

do_eos() virtual
do_new_preroll() virtual
Return type:

Gst.FlowReturn

do_new_sample() virtual
Return type:

Gst.FlowReturn

do_pull_preroll() virtual
Returns:

a Gst.Sample or None when the appsink is stopped or EOS. Call gst_sample_unref() after usage.

Return type:

Gst.Sample or None

Get the last preroll sample in appsink. This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling GstApp.AppSink.pull_sample().

If an EOS event was received before any buffers, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

This function blocks until a preroll sample or EOS is received or the appsink element is set to the READY/None state.

do_pull_sample() virtual
Returns:

a Gst.Sample or None when the appsink is stopped or EOS. Call gst_sample_unref() after usage.

Return type:

Gst.Sample or None

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/None state.

This function will only return samples when the appsink is in the PLAYING state. All rendered buffers will be put in a queue so that the application can pull samples at its own rate. Note that when the application does not pull samples fast enough, the queued buffers could consume a lot of memory, especially when dealing with raw video frames.

If an EOS event was received before any buffers, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

do_try_pull_preroll(timeout) virtual
Parameters:

timeout (int) – the maximum amount of time to wait for the preroll sample

Returns:

a Gst.Sample or None when the appsink is stopped or EOS or the timeout expires. Call gst_sample_unref() after usage.

Return type:

Gst.Sample or None

Get the last preroll sample in appsink. This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling GstApp.AppSink.pull_sample().

If an EOS event was received before any buffers or the timeout expires, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

This function blocks until a preroll sample or EOS is received, the appsink element is set to the READY/None state, or the timeout expires.

New in version 1.10.

do_try_pull_sample(timeout) virtual
Parameters:

timeout (int) – the maximum amount of time to wait for a sample

Returns:

a Gst.Sample or None when the appsink is stopped or EOS or the timeout expires. Call gst_sample_unref() after usage.

Return type:

Gst.Sample or None

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/None state or the timeout expires.

This function will only return samples when the appsink is in the PLAYING state. All rendered buffers will be put in a queue so that the application can pull samples at its own rate. Note that when the application does not pull samples fast enough, the queued buffers could consume a lot of memory, especially when dealing with raw video frames.

If an EOS event was received before any buffers or the timeout expires, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

New in version 1.10.

Signal Details

GstApp.AppSink.signals.eos(app_sink)
Signal Name:

eos

Flags:

RUN_LAST

Parameters:

app_sink (GstApp.AppSink) – The object which received the signal

Signal that the end-of-stream has been reached. This signal is emitted from the streaming thread.

GstApp.AppSink.signals.new_preroll(app_sink)
Signal Name:

new-preroll

Flags:

RUN_LAST

Parameters:

app_sink (GstApp.AppSink) – The object which received the signal

Return type:

Gst.FlowReturn

Signal that a new preroll sample is available.

This signal is emitted from the streaming thread and only when the “emit-signals” property is True.

The new preroll sample can be retrieved with the “pull-preroll” action signal or GstApp.AppSink.pull_preroll() either from this signal callback or from any other thread.

Note that this signal is only emitted when the “emit-signals” property is set to True, which it is not by default for performance reasons.

GstApp.AppSink.signals.new_sample(app_sink)
Signal Name:

new-sample

Flags:

RUN_LAST

Parameters:

app_sink (GstApp.AppSink) – The object which received the signal

Return type:

Gst.FlowReturn

Signal that a new sample is available.

This signal is emitted from the streaming thread and only when the “emit-signals” property is True.

The new sample can be retrieved with the “pull-sample” action signal or GstApp.AppSink.pull_sample() either from this signal callback or from any other thread.

Note that this signal is only emitted when the “emit-signals” property is set to True, which it is not by default for performance reasons.

GstApp.AppSink.signals.new_serialized_event(app_sink)
Signal Name:

new-serialized-event

Flags:

RUN_LAST

Parameters:

app_sink (GstApp.AppSink) – The object which received the signal

Return type:

bool

Signal that a new downstream serialized event is available.

This signal is emitted from the streaming thread and only when the “emit-signals” property is True.

The new event can be retrieved with the “try-pull-object” action signal or gst_app_sink_pull_object() either from this signal callback or from any other thread.

EOS will not be notified using this signal, use GstApp.AppSink ::eos instead. EOS cannot be pulled either, use GstApp.AppSink.is_eos() to check for it.

Note that this signal is only emitted when the “emit-signals” property is set to True, which it is not by default for performance reasons.

The callback should return True if the event has been handled, which will skip basesink handling of the event, False otherwise.

New in version 1.20.

GstApp.AppSink.signals.pull_preroll(app_sink)
Signal Name:

pull-preroll

Flags:

RUN_LAST, ACTION

Parameters:

app_sink (GstApp.AppSink) – The object which received the signal

Returns:

a Gst.Sample or None when the appsink is stopped or EOS.

Return type:

Gst.Sample or None

Get the last preroll sample in appsink. This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling GstApp.AppSink.pull_sample() or the “pull-sample” action signal.

If an EOS event was received before any buffers, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

This function blocks until a preroll sample or EOS is received or the appsink element is set to the READY/None state.

GstApp.AppSink.signals.pull_sample(app_sink)
Signal Name:

pull-sample

Flags:

RUN_LAST, ACTION

Parameters:

app_sink (GstApp.AppSink) – The object which received the signal

Returns:

a Gst.Sample or None when the appsink is stopped or EOS.

Return type:

Gst.Sample or None

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/None state.

This function will only return samples when the appsink is in the PLAYING state. All rendered samples will be put in a queue so that the application can pull samples at its own rate.

Note that when the application does not pull samples fast enough, the queued samples could consume a lot of memory, especially when dealing with raw video frames. It’s possible to control the behaviour of the queue with the “drop” and “max-buffers” properties.

If an EOS event was received before any buffers, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

GstApp.AppSink.signals.try_pull_object(app_sink, timeout)
Signal Name:

try-pull-object

Flags:

RUN_LAST, ACTION

Parameters:
  • app_sink (GstApp.AppSink) – The object which received the signal

  • timeout (int) – the maximum amount of time to wait for a sample

Returns:

a Gst.Sample or a Gst.Event or None when the appsink is stopped or EOS or the timeout expires.

Return type:

Gst.MiniObject or None

This function blocks until a sample or an event becomes available or the appsink element is set to the READY/None state or the timeout expires.

This function will only return samples when the appsink is in the PLAYING state. All rendered samples and events will be put in a queue so that the application can pull them at its own rate. Events can be pulled when the appsink is in the READY, PAUSED or PLAYING state.

Note that when the application does not pull samples fast enough, the queued samples could consume a lot of memory, especially when dealing with raw video frames. It’s possible to control the behaviour of the queue with the “drop” and “max-buffers” properties.

This function will only pull serialized events, excluding the EOS event for which this functions returns None. Use GstApp.AppSink.is_eos() to check for the EOS condition.

This signal is a variant of GstApp.AppSink ::try-pull-sample: that can be used to handle incoming events as well as samples.

Note that future releases may extend this API to return other object types so make sure that your code is checking for the actual type it is handling.

New in version 1.20.

GstApp.AppSink.signals.try_pull_preroll(app_sink, timeout)
Signal Name:

try-pull-preroll

Flags:

RUN_LAST, ACTION

Parameters:
  • app_sink (GstApp.AppSink) – The object which received the signal

  • timeout (int) – the maximum amount of time to wait for the preroll sample

Returns:

a Gst.Sample or None when the appsink is stopped or EOS or the timeout expires.

Return type:

Gst.Sample or None

Get the last preroll sample in appsink. This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling GstApp.AppSink.pull_sample() or the “pull-sample” action signal.

If an EOS event was received before any buffers or the timeout expires, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

This function blocks until a preroll sample or EOS is received, the appsink element is set to the READY/None state, or the timeout expires.

New in version 1.10.

GstApp.AppSink.signals.try_pull_sample(app_sink, timeout)
Signal Name:

try-pull-sample

Flags:

RUN_LAST, ACTION

Parameters:
  • app_sink (GstApp.AppSink) – The object which received the signal

  • timeout (int) – the maximum amount of time to wait for a sample

Returns:

a Gst.Sample or None when the appsink is stopped or EOS or the timeout expires.

Return type:

Gst.Sample or None

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/None state or the timeout expires.

This function will only return samples when the appsink is in the PLAYING state. All rendered samples will be put in a queue so that the application can pull samples at its own rate.

Note that when the application does not pull samples fast enough, the queued samples could consume a lot of memory, especially when dealing with raw video frames. It’s possible to control the behaviour of the queue with the “drop” and “max-buffers” properties.

If an EOS event was received before any buffers or the timeout expires, this function returns None. Use GstApp.AppSink.is_eos () to check for the EOS condition.

New in version 1.10.

Property Details

GstApp.AppSink.props.buffer_list
Name:

buffer-list

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Use buffer lists

GstApp.AppSink.props.caps
Name:

caps

Type:

Gst.Caps

Default Value:

None

Flags:

READABLE, WRITABLE

The allowed caps for the sink pad

GstApp.AppSink.props.drop
Name:

drop

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Drop old buffers when the buffer queue is filled

GstApp.AppSink.props.emit_signals
Name:

emit-signals

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Emit new-preroll and new-sample signals

GstApp.AppSink.props.eos
Name:

eos

Type:

bool

Default Value:

True

Flags:

READABLE

Check if the sink is EOS or not started

GstApp.AppSink.props.max_buffers
Name:

max-buffers

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

The maximum number of buffers to queue internally (0 = unlimited)

GstApp.AppSink.props.wait_on_eos
Name:

wait-on-eos

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

Wait for all buffers to be processed after receiving an EOS