GstBase.BaseSink

g 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

Subclasses:

None

Methods

Inherited:

Gst.Element (81), Gst.Object (27), GObject.Object (37)

Structs:

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

get_blocksize ()

get_drop_out_of_segment ()

get_last_sample ()

get_latency ()

get_max_bitrate ()

get_max_lateness ()

get_processing_deadline ()

get_render_delay ()

get_stats ()

get_sync ()

get_throttle_time ()

get_ts_offset ()

is_async_enabled ()

is_last_sample_enabled ()

is_qos_enabled ()

query_latency ()

set_async_enabled (enabled)

set_blocksize (blocksize)

set_drop_out_of_segment (drop_out_of_segment)

set_last_sample_enabled (enabled)

set_max_bitrate (max_bitrate)

set_max_lateness (max_lateness)

set_processing_deadline (processing_deadline)

set_qos_enabled (enabled)

set_render_delay (delay)

set_sync (sync)

set_throttle_time (throttle)

set_ts_offset (offset)

wait (time)

wait_clock (time)

wait_preroll ()

Virtual Methods

Inherited:

Gst.Element (16), Gst.Object (1), GObject.Object (7)

do_activate_pull (active)

do_event (event)

do_fixate (caps)

do_get_caps (filter)

do_get_times (buffer)

do_prepare (buffer)

do_prepare_list (buffer_list)

do_preroll (buffer)

do_propose_allocation (query)

do_query (query)

do_render (buffer)

do_render_list (buffer_list)

do_set_caps (caps)

do_start ()

do_stop ()

do_unlock ()

do_unlock_stop ()

do_wait_event (event)

Properties

Inherited:

Gst.Object (2)

Name

Type

Flags

Short Description

async

bool

r/w

Go asynchronously to PAUSED

blocksize

int

r/w

Size in bytes to pull per buffer (0 = default)

enable-last-sample

bool

r/w

Enable the last-sample property

last-sample

Gst.Sample

r

The last sample received in the sink

max-bitrate

int

r/w

The maximum bits per second to render (0 = disabled)

max-lateness

int

r/w

Maximum number of nanoseconds that a buffer can be late before it is dropped (-1 unlimited)

processing-deadline

int

r/w

Maximum processing time for a buffer in nanoseconds

qos

bool

r/w

Generate Quality-of-Service events upstream

render-delay

int

r/w

Additional render delay of the sink in nanoseconds

stats

Gst.Structure

r

Sink Statistics

sync

bool

r/w

Sync on the clock

throttle-time

int

r/w

The time to keep between rendered buffers (0 = disabled)

ts-offset

int

r/w

Timestamp offset in nanoseconds

Signals

Inherited:

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

Fields

Inherited:

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

Name

Type

Access

Description

can_activate_pull

bool

r

can_activate_push

bool

r

clock_id

object

r

element

Gst.Element

r

eos

bool

r

flushing

bool

r

have_newsegment

bool

r

have_preroll

bool

r

max_lateness

int

r

need_preroll

bool

r

offset

int

r

pad_mode

Gst.PadMode

r

playing_async

bool

r

preroll_cond

GLib.Cond

r

preroll_lock

GLib.Mutex

r

running

bool

r

segment

Gst.Segment

r

sinkpad

Gst.Pad

r

sync

bool

r

Class Details

class GstBase.BaseSink(**kwargs)
Bases:

Gst.Element

Abstract:

Yes

Structure:

GstBase.BaseSinkClass

GstBase.BaseSink is the base class for sink elements in GStreamer, such as xvimagesink or filesink. It is a layer on top of Gst.Element that provides a simplified interface to plugin writers. GstBase.BaseSink handles many details for you, for example: preroll, clock synchronization, state changes, activation in push or pull mode, and queries.

In most cases, when writing sink elements, there is no need to implement class methods from Gst.Element or to set functions on pads, because the GstBase.BaseSink infrastructure should be sufficient.

GstBase.BaseSink provides support for exactly one sink pad, which should be named “sink”. A sink implementation (subclass of GstBase.BaseSink) should install a pad template in its class_init function, like so:

static void
my_element_class_init (GstMyElementClass *klass)
{
  GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);

  // sinktemplate should be a #GstStaticPadTemplate with direction
  // %GST_PAD_SINK and name "sink"
  gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate);

  gst_element_class_set_static_metadata (gstelement_class,
      "Sink name",
      "Sink",
      "My Sink element",
      "The author <my.sink@my.email>");
}

GstBase.BaseSink will handle the prerolling correctly. This means that it will return Gst.StateChangeReturn.ASYNC from a state change to PAUSED until the first buffer arrives in this element. The base class will call the #GstBaseSinkClass::preroll vmethod with this preroll buffer and will then commit the state change to the next asynchronously pending state.

When the element is set to PLAYING, GstBase.BaseSink will synchronise on the clock using the times returned from #GstBaseSinkClass::get_times. If this function returns Gst.CLOCK_TIME_NONE for the start time, no synchronisation will be done. Synchronisation can be disabled entirely by setting the object GstBase.BaseSink :sync property to False.

After synchronisation the virtual method #GstBaseSinkClass::render will be called. Subclasses should minimally implement this method.

Subclasses that synchronise on the clock in the #GstBaseSinkClass::render method are supported as well. These classes typically receive a buffer in the render method and can then potentially block on the clock while rendering. A typical example is an audiosink. These subclasses can use GstBase.BaseSink.wait_preroll() to perform the blocking wait.

Upon receiving the EOS event in the PLAYING state, GstBase.BaseSink will wait for the clock to reach the time indicated by the stop time of the last #GstBaseSinkClass::get_times call before posting an EOS message. When the element receives EOS in PAUSED, preroll completes, the event is queued and an EOS message is posted when going to PLAYING.

GstBase.BaseSink will internally use the Gst.EventType.SEGMENT events to schedule synchronisation and clipping of buffers. Buffers that fall completely outside of the current segment are dropped. Buffers that fall partially in the segment are rendered (and prerolled). Subclasses should do any subbuffer clipping themselves when needed.

GstBase.BaseSink will by default report the current playback position in Gst.Format.TIME based on the current clock time and segment information. If no clock has been set on the element, the query will be forwarded upstream.

The #GstBaseSinkClass::set_caps function will be called when the subclass should configure itself to process a specific media type.

The #GstBaseSinkClass::start and #GstBaseSinkClass::stop virtual methods will be called when resources should be allocated. Any #GstBaseSinkClass::preroll, #GstBaseSinkClass::render and #GstBaseSinkClass::set_caps function will be called between the #GstBaseSinkClass::start and #GstBaseSinkClass::stop calls.

The #GstBaseSinkClass::event virtual method will be called when an event is received by GstBase.BaseSink. Normally this method should only be overridden by very specific elements (such as file sinks) which need to handle the newsegment event specially.

The #GstBaseSinkClass::unlock method is called when the elements should unblock any blocking operations they perform in the #GstBaseSinkClass::render method. This is mostly useful when the #GstBaseSinkClass::render method performs a blocking write on a file descriptor, for example.

The GstBase.BaseSink :max-lateness property affects how the sink deals with buffers that arrive too late in the sink. A buffer arrives too late in the sink when the presentation time (as a combination of the last segment, buffer timestamp and element base_time) plus the duration is before the current time of the clock. If the frame is later than max-lateness, the sink will drop the buffer without calling the render method. This feature is disabled if sync is disabled, the #GstBaseSinkClass::get_times method does not return a valid start time or max-lateness is set to -1 (the default). Subclasses can use GstBase.BaseSink.set_max_lateness() to configure the max-lateness value.

The GstBase.BaseSink :qos property will enable the quality-of-service features of the basesink which gather statistics about the real-time performance of the clock synchronisation. For each buffer received in the sink, statistics are gathered and a QOS event is sent upstream with these numbers. This information can then be used by upstream elements to reduce their processing rate, for example.

The GstBase.BaseSink :async property can be used to instruct the sink to never perform an ASYNC state change. This feature is mostly usable when dealing with non-synchronized streams or sparse streams.

get_blocksize()
Returns:

the number of bytes self will pull in pull mode.

Return type:

int

Get the number of bytes that the sink will pull when it is operating in pull mode.

get_drop_out_of_segment()
Returns:

True if the sink is configured to drop buffers outside the current segment.

Return type:

bool

Checks if self is currently configured to drop buffers which are outside the current segment

New in version 1.12.

get_last_sample()
Returns:

a Gst.Sample. gst_sample_unref() after usage. This function returns None when no buffer has arrived in the sink yet or when the sink is not in PAUSED or PLAYING.

Return type:

Gst.Sample or None

Get the last sample that arrived in the sink and was used for preroll or for rendering. This property can be used to generate thumbnails.

The Gst.Caps on the sample can be used to determine the type of the buffer.

Free-function: gst_sample_unref

get_latency()
Returns:

The configured latency.

Return type:

int

Get the currently configured latency.

get_max_bitrate()
Returns:

the maximum number of bits per second self will render.

Return type:

int

Get the maximum amount of bits per second that the sink will render.

New in version 1.2.

get_max_lateness()
Returns:

The maximum time in nanoseconds that a buffer can be late before it is dropped and not rendered. A value of -1 means an unlimited time.

Return type:

int

Gets the max lateness value. See GstBase.BaseSink.set_max_lateness() for more details.

get_processing_deadline()
Returns:

the processing deadline

Return type:

int

Get the processing deadline of self. see GstBase.BaseSink.set_processing_deadline() for more information about the processing deadline.

New in version 1.16.

get_render_delay()
Returns:

the render delay of self.

Return type:

int

Get the render delay of self. see GstBase.BaseSink.set_render_delay() for more information about the render delay.

get_stats()
Returns:

pointer to Gst.Structure

Return type:

Gst.Structure

Return various GstBase.BaseSink statistics. This function returns a Gst.Structure with name application/x-gst-base-sink-stats with the following fields:

New in version 1.18.

get_sync()
Returns:

True if the sink is configured to synchronize against the clock.

Return type:

bool

Checks if self is currently configured to synchronize against the clock.

get_throttle_time()
Returns:

the number of nanoseconds self will put between frames.

Return type:

int

Get the time that will be inserted between frames to control the maximum buffers per second.

get_ts_offset()
Returns:

The synchronisation offset.

Return type:

int

Get the synchronisation offset of self.

is_async_enabled()
Returns:

True if the sink is configured to perform asynchronous state changes.

Return type:

bool

Checks if self is currently configured to perform asynchronous state changes to PAUSED.

is_last_sample_enabled()
Returns:

True if the sink is configured to store the last received sample.

Return type:

bool

Checks if self is currently configured to store the last received sample in the last-sample property.

is_qos_enabled()
Returns:

True if the sink is configured to perform Quality-of-Service.

Return type:

bool

Checks if self is currently configured to send Quality-of-Service events upstream.

query_latency()
Returns:

True if the query succeeded.

live:

if the sink is live

upstream_live:

if an upstream element is live

min_latency:

the min latency of the upstream elements

max_latency:

the max latency of the upstream elements

Return type:

(bool, live: bool, upstream_live: bool, min_latency: int, max_latency: int)

Query the sink for the latency parameters. The latency will be queried from the upstream elements. live will be True if self is configured to synchronize against the clock. upstream_live will be True if an upstream element is live.

If both live and upstream_live are True, the sink will want to compensate for the latency introduced by the upstream elements by setting the min_latency to a strictly positive value.

This function is mostly used by subclasses.

set_async_enabled(enabled)
Parameters:

enabled (bool) – the new async value.

Configures self to perform all state changes asynchronously. When async is disabled, the sink will immediately go to PAUSED instead of waiting for a preroll buffer. This feature is useful if the sink does not synchronize against the clock or when it is dealing with sparse streams.

set_blocksize(blocksize)
Parameters:

blocksize (int) – the blocksize in bytes

Set the number of bytes that the sink will pull when it is operating in pull mode.

set_drop_out_of_segment(drop_out_of_segment)
Parameters:

drop_out_of_segment (bool) – drop buffers outside the segment

Configure self to drop buffers which are outside the current segment

New in version 1.12.

set_last_sample_enabled(enabled)
Parameters:

enabled (bool) – the new enable-last-sample value.

Configures self to store the last received sample in the last-sample property.

set_max_bitrate(max_bitrate)
Parameters:

max_bitrate (int) – the max_bitrate in bits per second

Set the maximum amount of bits per second that the sink will render.

New in version 1.2.

set_max_lateness(max_lateness)
Parameters:

max_lateness (int) – the new max lateness value.

Sets the new max lateness value to max_lateness. This value is used to decide if a buffer should be dropped or not based on the buffer timestamp and the current clock time. A value of -1 means an unlimited time.

set_processing_deadline(processing_deadline)
Parameters:

processing_deadline (int) – the new processing deadline in nanoseconds.

Maximum amount of time (in nanoseconds) that the pipeline can take for processing the buffer. This is added to the latency of live pipelines.

This function is usually called by subclasses.

New in version 1.16.

set_qos_enabled(enabled)
Parameters:

enabled (bool) – the new qos value.

Configures self to send Quality-of-Service events upstream.

set_render_delay(delay)
Parameters:

delay (int) – the new delay

Set the render delay in self to delay. The render delay is the time between actual rendering of a buffer and its synchronisation time. Some devices might delay media rendering which can be compensated for with this function.

After calling this function, this sink will report additional latency and other sinks will adjust their latency to delay the rendering of their media.

This function is usually called by subclasses.

set_sync(sync)
Parameters:

sync (bool) – the new sync value.

Configures self to synchronize on the clock or not. When sync is False, incoming samples will be played as fast as possible. If sync is True, the timestamps of the incoming buffers will be used to schedule the exact render time of its contents.

set_throttle_time(throttle)
Parameters:

throttle (int) – the throttle time in nanoseconds

Set the time that will be inserted between rendered buffers. This can be used to control the maximum buffers per second that the sink will render.

set_ts_offset(offset)
Parameters:

offset (int) – the new offset

Adjust the synchronisation of self with offset. A negative value will render buffers earlier than their timestamp. A positive value will delay rendering. This function can be used to fix playback of badly timestamped buffers.

wait(time)
Parameters:

time (int) – the running_time to be reached

Returns:

Gst.FlowReturn

jitter:

the jitter to be filled with time diff, or None

Return type:

(Gst.FlowReturn, jitter: int)

This function will wait for preroll to complete and will then block until time is reached. It is usually called by subclasses that use their own internal synchronisation but want to let some synchronization (like EOS) be handled by the base class.

This function should only be called with the PREROLL_LOCK held (like when receiving an EOS event in the ::event vmethod or when handling buffers in ::render).

The time argument should be the running_time of when the timeout should happen and will be adjusted with any latency and offset configured in the sink.

wait_clock(time)
Parameters:

time (int) – the running_time to be reached

Returns:

Gst.ClockReturn

jitter:

the jitter to be filled with time diff, or None

Return type:

(Gst.ClockReturn, jitter: int)

This function will block until time is reached. It is usually called by subclasses that use their own internal synchronisation.

If time is not valid, no synchronisation is done and Gst.ClockReturn.BADTIME is returned. Likewise, if synchronisation is disabled in the element or there is no clock, no synchronisation is done and Gst.ClockReturn.BADTIME is returned.

This function should only be called with the PREROLL_LOCK held, like when receiving an EOS event in the #GstBaseSinkClass::event vmethod or when receiving a buffer in the #GstBaseSinkClass::render vmethod.

The time argument should be the running_time of when this method should return and is not adjusted with any latency or offset configured in the sink.

wait_preroll()
Returns:

Gst.FlowReturn.OK if the preroll completed and processing can continue. Any other return value should be returned from the render vmethod.

Return type:

Gst.FlowReturn

If the #GstBaseSinkClass::render method performs its own synchronisation against the clock it must unblock when going from PLAYING to the PAUSED state and call this method before continuing to render the remaining data.

If the #GstBaseSinkClass::render method can block on something else than the clock, it must also be ready to unblock immediately on the #GstBaseSinkClass::unlock method and cause the #GstBaseSinkClass::render method to immediately call this function. In this case, the subclass must be prepared to continue rendering where it left off if this function returns Gst.FlowReturn.OK.

This function will block until a state change to PLAYING happens (in which case this function returns Gst.FlowReturn.OK) or the processing must be stopped due to a state change to READY or a FLUSH event (in which case this function returns Gst.FlowReturn.FLUSHING).

This function should only be called with the PREROLL_LOCK held, like in the render function.

do_activate_pull(active) virtual
Parameters:

active (bool) –

Return type:

bool

do_event(event) virtual
Parameters:

event (Gst.Event) –

Return type:

bool

do_fixate(caps) virtual
Parameters:

caps (Gst.Caps) –

Return type:

Gst.Caps

do_get_caps(filter) virtual
Parameters:

filter (Gst.Caps or None) –

Return type:

Gst.Caps

Called to get sink pad caps from the subclass.

do_get_times(buffer) virtual
Parameters:

buffer (Gst.Buffer) –

Returns:

start:

the start #GstClockTime

end:

the end #GstClockTime

Return type:

(start: int, end: int)

Get the start and end times for syncing on this buffer.

do_prepare(buffer) virtual
Parameters:

buffer (Gst.Buffer) –

Return type:

Gst.FlowReturn

do_prepare_list(buffer_list) virtual
Parameters:

buffer_list (Gst.BufferList) –

Return type:

Gst.FlowReturn

do_preroll(buffer) virtual
Parameters:

buffer (Gst.Buffer) –

Return type:

Gst.FlowReturn

do_propose_allocation(query) virtual
Parameters:

query (Gst.Query) –

Return type:

bool

do_query(query) virtual
Parameters:

query (Gst.Query) –

Return type:

bool

do_render(buffer) virtual
Parameters:

buffer (Gst.Buffer) –

Return type:

Gst.FlowReturn

do_render_list(buffer_list) virtual
Parameters:

buffer_list (Gst.BufferList) –

Return type:

Gst.FlowReturn

do_set_caps(caps) virtual
Parameters:

caps (Gst.Caps) –

Return type:

bool

do_start() virtual
Return type:

bool

do_stop() virtual
Return type:

bool

do_unlock() virtual
Return type:

bool

do_unlock_stop() virtual
Return type:

bool

do_wait_event(event) virtual
Parameters:

event (Gst.Event) –

Return type:

Gst.FlowReturn

Property Details

GstBase.BaseSink.props.async_
Name:

async

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

If set to True, the basesink will perform asynchronous state changes. When set to False, the sink will not signal the parent when it prerolls. Use this option when dealing with sparse streams or when synchronisation is not required.

GstBase.BaseSink.props.blocksize
Name:

blocksize

Type:

int

Default Value:

4096

Flags:

READABLE, WRITABLE

The amount of bytes to pull when operating in pull mode.

GstBase.BaseSink.props.enable_last_sample
Name:

enable-last-sample

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

Enable the last-sample property. If False, basesink doesn’t keep a reference to the last buffer arrived and the last-sample property is always set to None. This can be useful if you need buffers to be released as soon as possible, eg. if you’re using a buffer pool.

GstBase.BaseSink.props.last_sample
Name:

last-sample

Type:

Gst.Sample

Default Value:

None

Flags:

READABLE

The last buffer that arrived in the sink and was used for preroll or for rendering. This property can be used to generate thumbnails. This property can be None when the sink has not yet received a buffer.

GstBase.BaseSink.props.max_bitrate
Name:

max-bitrate

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

Control the maximum amount of bits that will be rendered per second. Setting this property to a value bigger than 0 will make the sink delay rendering of the buffers when it would exceed to max-bitrate.

New in version 1.2.

GstBase.BaseSink.props.max_lateness
Name:

max-lateness

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE

Maximum number of nanoseconds that a buffer can be late before it is dropped (-1 unlimited)

GstBase.BaseSink.props.processing_deadline
Name:

processing-deadline

Type:

int

Default Value:

20000000

Flags:

READABLE, WRITABLE

Maximum amount of time (in nanoseconds) that the pipeline can take for processing the buffer. This is added to the latency of live pipelines.

New in version 1.16.

GstBase.BaseSink.props.qos
Name:

qos

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Generate Quality-of-Service events upstream

GstBase.BaseSink.props.render_delay
Name:

render-delay

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

The additional delay between synchronisation and actual rendering of the media. This property will add additional latency to the device in order to make other sinks compensate for the delay.

GstBase.BaseSink.props.stats
Name:

stats

Type:

Gst.Structure

Default Value:

None

Flags:

READABLE

Various GstBase.BaseSink statistics. This property returns a Gst.Structure with name application/x-gst-base-sink-stats with the following fields:

New in version 1.18.

GstBase.BaseSink.props.sync
Name:

sync

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

Sync on the clock

GstBase.BaseSink.props.throttle_time
Name:

throttle-time

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

The time to insert between buffers. This property can be used to control the maximum amount of buffers per second to render. Setting this property to a value bigger than 0 will make the sink create THROTTLE QoS events.

GstBase.BaseSink.props.ts_offset
Name:

ts-offset

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

Controls the final synchronisation, a negative value will render the buffer earlier while a positive value delays playback. This property can be used to fix synchronisation in bad files.