BaseSink
Superclasses: Element
, Object
, InitiallyUnowned
, Object
- Constructors:
BaseSink(**properties)
Methods
- class BaseSink
- get_blocksize() int
Get the number of bytes that the sink will pull when it is operating in pull mode.
- get_drop_out_of_segment() bool
Checks if
sink
is currently configured to drop buffers which are outside the current segmentAdded in version 1.12.
- get_last_sample() Sample | 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
Caps
on the sample can be used to determine the type of the buffer.Free-function: gst_sample_unref
- get_max_bitrate() int
Get the maximum amount of bits per second that the sink will render.
Added in version 1.2.
- get_max_lateness() int
Gets the max lateness value. See
set_max_lateness()
for more details.
- get_processing_deadline() int
Get the processing deadline of
sink
. seeset_processing_deadline()
for more information about the processing deadline.Added in version 1.16.
- get_render_delay() int
Get the render delay of
sink
. seeset_render_delay()
for more information about the render delay.
- get_stats() Structure
Return various
BaseSink
statistics. This function returns aStructure
with nameapplication/x-gst-base-sink-stats
with the following fields:“average-rate” G_TYPE_DOUBLE average frame rate
“dropped” G_TYPE_UINT64 Number of dropped frames
“rendered” G_TYPE_UINT64 Number of rendered frames
Added in version 1.18.
- get_throttle_time() int
Get the time that will be inserted between frames to control the maximum buffers per second.
- is_async_enabled() bool
Checks if
sink
is currently configured to perform asynchronous state changes to PAUSED.
- is_last_sample_enabled() bool
Checks if
sink
is currently configured to store the last received sample in the last-sample property.
- is_qos_enabled() bool
Checks if
sink
is currently configured to send Quality-of-Service events upstream.
- query_latency() tuple[bool, bool, bool, int, int]
Query the sink for the latency parameters. The latency will be queried from the upstream elements.
live
will beTrue
ifsink
is configured to synchronize against the clock.upstream_live
will beTrue
if an upstream element is live.If both
live
andupstream_live
areTrue
, the sink will want to compensate for the latency introduced by the upstream elements by setting themin_latency
to a strictly positive value.This function is mostly used by subclasses.
- set_async_enabled(enabled: bool) None
Configures
sink
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.- Parameters:
enabled – the new async value.
- set_blocksize(blocksize: int) None
Set the number of bytes that the sink will pull when it is operating in pull mode.
- Parameters:
blocksize – the blocksize in bytes
- set_drop_out_of_segment(drop_out_of_segment: bool) None
Configure
sink
to drop buffers which are outside the current segmentAdded in version 1.12.
- Parameters:
drop_out_of_segment – drop buffers outside the segment
- set_last_sample_enabled(enabled: bool) None
Configures
sink
to store the last received sample in the last-sample property.- Parameters:
enabled – the new enable-last-sample value.
- set_max_bitrate(max_bitrate: int) None
Set the maximum amount of bits per second that the sink will render.
Added in version 1.2.
- Parameters:
max_bitrate – the max_bitrate in bits per second
- set_max_lateness(max_lateness: int) None
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.- Parameters:
max_lateness – the new max lateness value.
- set_processing_deadline(processing_deadline: int) None
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.
Added in version 1.16.
- Parameters:
processing_deadline – the new processing deadline in nanoseconds.
- set_qos_enabled(enabled: bool) None
Configures
sink
to send Quality-of-Service events upstream.- Parameters:
enabled – the new qos value.
- set_render_delay(delay: int) None
Set the render delay in
sink
todelay
. 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.
- Parameters:
delay – the new delay
- set_sync(sync: bool) None
Configures
sink
to synchronize on the clock or not. Whensync
isFalse
, incoming samples will be played as fast as possible. Ifsync
isTrue
, the timestamps of the incoming buffers will be used to schedule the exact render time of its contents.- Parameters:
sync – the new sync value.
- set_throttle_time(throttle: int) None
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.
- Parameters:
throttle – the throttle time in nanoseconds
- set_ts_offset(offset: int) None
Adjust the synchronisation of
sink
withoffset
. 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.- Parameters:
offset – the new offset
- wait(time: int) tuple[FlowReturn, 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.- Parameters:
time – the running_time to be reached
- wait_clock(time: int) tuple[ClockReturn, 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_CLOCK_BADTIME
is returned. Likewise, if synchronisation is disabled in the element or there is no clock, no synchronisation is done and%GST_CLOCK_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 theGstBaseSinkClass
::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.- Parameters:
time – the running_time to be reached
- wait_preroll() 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 theGstBaseSinkClass
::unlock method and cause theGstBaseSinkClass
::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_FLOW_OK
.This function will block until a state change to PLAYING happens (in which case this function returns
%GST_FLOW_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_FLOW_FLUSHING
).This function should only be called with the PREROLL_LOCK held, like in the render function.
Properties
- class BaseSink
- props.async: bool
If set to
True
, the basesink will perform asynchronous state changes. When set toFalse
, the sink will not signal the parent when it prerolls. Use this option when dealing with sparse streams or when synchronisation is not required.
- props.enable_last_sample: bool
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 toNone
. This can be useful if you need buffers to be released as soon as possible, eg. if you’re using a buffer pool.
- props.last_sample: Sample
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.
- props.max_bitrate: int
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.
Added in version 1.2.
- props.processing_deadline: int
Maximum amount of time (in nanoseconds) that the pipeline can take for processing the buffer. This is added to the latency of live pipelines.
Added in version 1.16.
- props.render_delay: int
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.
- props.stats: Structure
Various
BaseSink
statistics. This property returns aStructure
with nameapplication/x-gst-base-sink-stats
with the following fields:“average-rate” G_TYPE_DOUBLE average frame rate
“dropped” G_TYPE_UINT64 Number of dropped frames
“rendered” G_TYPE_UINT64 Number of rendered frames
Added in version 1.18.
Virtual Methods
- class BaseSink
- do_activate_pull(active: bool) bool
Subclasses should override this when they can provide an alternate method of spawning a thread to drive the pipeline in pull mode. Should start or stop the pulling thread, depending on the value of the “active” argument. Called after actually activating the sink pad in pull mode. The default implementation starts a task on the sink pad.
- Parameters:
active
- do_event(event: Event) bool
Override this to handle events arriving on the sink pad
- Parameters:
event
- do_fixate(caps: Caps) Caps
Only useful in pull mode. Implement if you have ideas about what should be the default values for the caps you support.
- Parameters:
caps
- do_get_caps(filter: Caps | None = None) Caps
Called to get sink pad caps from the subclass.
- Parameters:
filter
- do_get_times(buffer: Buffer) tuple[int, int]
Get the start and end times for syncing on this buffer.
- Parameters:
buffer
- do_prepare(buffer: Buffer) FlowReturn
Called to prepare the buffer for
render
andpreroll
. This function is called before synchronisation is performed.- Parameters:
buffer
- do_prepare_list(buffer_list: BufferList) FlowReturn
Called to prepare the buffer list for
render_list
. This function is called before synchronisation is performed.- Parameters:
buffer_list
- do_preroll(buffer: Buffer) FlowReturn
Called to present the preroll buffer if desired.
- Parameters:
buffer
- do_render(buffer: Buffer) FlowReturn
Called when a buffer should be presented or output, at the correct moment if the
BaseSink
has been set to sync to the clock.- Parameters:
buffer
- do_render_list(buffer_list: BufferList) FlowReturn
Same as
render
but used with buffer lists instead of buffers.- Parameters:
buffer_list
- do_unlock() bool
Unlock any pending access to the resource. Subclasses should unblock any blocked function ASAP and call
wait_preroll()
- do_unlock_stop() bool
Clear the previous unlock request. Subclasses should clear any state they set during
GstBaseSinkClass
::unlock, and be ready to continue where they left off afterwait_preroll()
,wait()
or gst_wait_sink_wait_clock() return orGstBaseSinkClass
::render is called again.
- do_wait_event(event: Event) FlowReturn
Override this to implement custom logic to wait for the event time (for events like EOS and GAP). Subclasses should always first chain up to the default implementation.
- Parameters:
event