GstBase.BaseSink¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
Go asynchronously to PAUSED |
||
r/w |
Size in bytes to pull per buffer (0 = default) |
||
r/w |
Enable the last-sample property |
||
r |
The last sample received in the sink |
||
r/w |
The maximum bits per second to render (0 = disabled) |
||
r/w |
Maximum number of nanoseconds that a buffer can be late before it is dropped (-1 unlimited) |
||
r/w |
Maximum processing time for a buffer in nanoseconds |
||
r/w |
Generate Quality-of-Service events upstream |
||
r/w |
Additional render delay of the sink in nanoseconds |
||
r |
Sink Statistics |
||
r/w |
Sync on the clock |
||
r/w |
The time to keep between rendered buffers (0 = disabled) |
||
r/w |
Timestamp offset in nanoseconds |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
can_activate_pull |
r |
||
can_activate_push |
r |
||
clock_id |
r |
||
element |
r |
||
eos |
r |
||
flushing |
r |
||
have_newsegment |
r |
||
have_preroll |
r |
||
max_lateness |
r |
||
need_preroll |
r |
||
offset |
r |
||
pad_mode |
r |
||
playing_async |
r |
||
preroll_cond |
r |
||
preroll_lock |
r |
||
running |
r |
||
segment |
r |
||
sinkpad |
r |
||
sync |
r |
Class Details¶
- class GstBase.BaseSink(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
GstBase.BaseSink
is the base class for sink elements in GStreamer, such as xvimagesink or filesink. It is a layer on top ofGst.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 theGstBase.BaseSink
infrastructure should be sufficient.GstBase.BaseSink
provides support for exactly one sink pad, which should be named “sink”. A sink implementation (subclass ofGstBase.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 returnGst.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 returnsGst.CLOCK_TIME_NONE
for the start time, no synchronisation will be done. Synchronisation can be disabled entirely by setting the objectGstBase.BaseSink
:sync
property toFalse
.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 theGst.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 inGst.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 useGstBase.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()[source]¶
- Returns:
the number of bytes self will pull in pull mode.
- Return type:
Get the number of bytes that the sink will pull when it is operating in pull mode.
- get_drop_out_of_segment()[source]¶
- Returns:
True
if the sink is configured to drop buffers outside the current segment.- Return type:
Checks if self is currently configured to drop buffers which are outside the current segment
New in version 1.12.
- get_last_sample()[source]¶
- Returns:
a
Gst.Sample
. gst_sample_unref() after usage. This function returnsNone
when no buffer has arrived in the sink yet or when the sink is not in PAUSED or PLAYING.- Return type:
Gst.Sample
orNone
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()[source]¶
- Returns:
The configured latency.
- Return type:
Get the currently configured latency.
- get_max_bitrate()[source]¶
- Returns:
the maximum number of bits per second self will render.
- Return type:
Get the maximum amount of bits per second that the sink will render.
New in version 1.2.
- get_max_lateness()[source]¶
- 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:
Gets the max lateness value. See
GstBase.BaseSink.set_max_lateness
() for more details.
- get_processing_deadline()[source]¶
- Returns:
the processing deadline
- Return type:
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()[source]¶
- Returns:
the render delay of self.
- Return type:
Get the render delay of self. see
GstBase.BaseSink.set_render_delay
() for more information about the render delay.
- get_stats()[source]¶
- Returns:
pointer to
Gst.Structure
- Return type:
Return various
GstBase.BaseSink
statistics. This function returns aGst.Structure
with nameapplication/x-gst-base-sink-stats
with the following fields:“average-rate”
GObject.TYPE_DOUBLE
average frame rate“dropped”
GObject.TYPE_UINT64
Number of dropped frames“rendered”
GObject.TYPE_UINT64
Number of rendered frames
New in version 1.18.
- get_throttle_time()[source]¶
- Returns:
the number of nanoseconds self will put between frames.
- Return type:
Get the time that will be inserted between frames to control the maximum buffers per second.
- get_ts_offset()[source]¶
- Returns:
The synchronisation offset.
- Return type:
Get the synchronisation offset of self.
- is_async_enabled()[source]¶
-
Checks if self is currently configured to perform asynchronous state changes to PAUSED.
- is_last_sample_enabled()[source]¶
-
Checks if self is currently configured to store the last received sample in the last-sample property.
- is_qos_enabled()[source]¶
-
Checks if self is currently configured to send Quality-of-Service events upstream.
- query_latency()[source]¶
- 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 beTrue
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)[source]¶
- 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)[source]¶
- 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)[source]¶
- 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)[source]¶
- 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)[source]¶
- 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)[source]¶
- 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)[source]¶
- 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)[source]¶
- Parameters:
enabled (
bool
) – the new qos value.
Configures self to send Quality-of-Service events upstream.
- set_render_delay(delay)[source]¶
- 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)[source]¶
- 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 isTrue
, the timestamps of the incoming buffers will be used to schedule the exact render time of its contents.
- set_throttle_time(throttle)[source]¶
- 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)[source]¶
- 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)[source]¶
- Parameters:
time (
int
) – the running_time to be reached- Returns:
-
- 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)[source]¶
- Parameters:
time (
int
) – the running_time to be reached- Returns:
-
- 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 andGst.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()[source]¶
- 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:
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 returnsGst.FlowReturn.FLUSHING
).This function should only be called with the PREROLL_LOCK held, like in the render function.
- do_activate_pull(active) virtual¶
-
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.
- do_event(event) virtual¶
-
Override this to handle events arriving on the sink pad
- do_fixate(caps) virtual¶
-
Only useful in pull mode. Implement if you have ideas about what should be the default values for the caps you support.
- do_get_caps(filter) virtual¶
-
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:
Get the start and end times for syncing on this buffer.
- do_prepare(buffer) virtual¶
- Parameters:
buffer (
Gst.Buffer
) –- Return type:
Called to prepare the buffer for render and preroll. This function is called before synchronisation is performed.
- do_prepare_list(buffer_list) virtual¶
- Parameters:
buffer_list (
Gst.BufferList
) –- Return type:
Called to prepare the buffer list for render_list. This function is called before synchronisation is performed.
- do_preroll(buffer) virtual[source]¶
- Parameters:
buffer (
Gst.Buffer
) –- Return type:
Called to present the preroll buffer if desired.
- do_propose_allocation(query) virtual¶
-
configure the allocation query
- do_render(buffer) virtual¶
- Parameters:
buffer (
Gst.Buffer
) –- Return type:
Called when a buffer should be presented or output, at the correct moment if the
GstBase.BaseSink
has been set to sync to the clock.
- do_render_list(buffer_list) virtual¶
- Parameters:
buffer_list (
Gst.BufferList
) –- Return type:
Same as render but used with buffer lists instead of buffers.
- do_set_caps(caps) virtual¶
-
Notify subclass of changed caps
- do_stop() virtual¶
- Return type:
Stop processing. Subclasses should use this to close resources.
- do_unlock() virtual¶
- Return type:
Unlock any pending access to the resource. Subclasses should unblock any blocked function ASAP and call
GstBase.BaseSink.wait_preroll
()
- do_unlock_stop() virtual¶
- Return type:
Clear the previous unlock request. Subclasses should clear any state they set during #GstBaseSinkClass::unlock, and be ready to continue where they left off after
GstBase.BaseSink.wait_preroll
(),GstBase.BaseSink.wait
() or gst_wait_sink_wait_clock() return or #GstBaseSinkClass::render is called again.
Property Details¶
- GstBase.BaseSink.props.async_¶
-
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.
- GstBase.BaseSink.props.blocksize¶
-
The amount of bytes to pull when operating in pull mode.
- GstBase.BaseSink.props.enable_last_sample¶
-
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.
- GstBase.BaseSink.props.last_sample¶
- Name:
last-sample
- Type:
- Default Value:
- Flags:
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¶
-
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¶
-
Maximum number of nanoseconds that a buffer can be late before it is dropped (-1 unlimited)
- GstBase.BaseSink.props.processing_deadline¶
-
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¶
-
Generate Quality-of-Service events upstream
- GstBase.BaseSink.props.render_delay¶
-
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:
- Default Value:
- Flags:
Various
GstBase.BaseSink
statistics. This property returns aGst.Structure
with nameapplication/x-gst-base-sink-stats
with the following fields:“average-rate”
GObject.TYPE_DOUBLE
average frame rate“dropped”
GObject.TYPE_UINT64
Number of dropped frames“rendered”
GObject.TYPE_UINT64
Number of rendered frames
New in version 1.18.
- GstBase.BaseSink.props.sync¶
-
Sync on the clock
- GstBase.BaseSink.props.throttle_time¶
-
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.