GstBaseSink
GstBaseSink is the base class for sink elements in GStreamer, such as xvimagesink or filesink. It is a layer on top of GstElement that provides a simplified interface to plugin writers. GstBaseSink 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 GstElement or to set functions on pads, because the GstBaseSink infrastructure should be sufficient.
GstBaseSink provides support for exactly one sink pad, which should be named "sink". A sink implementation (subclass of GstBaseSink) 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>");
}
GstBaseSink will handle the prerolling correctly. This means that it will return GST_STATE_CHANGE_ASYNC from a state change to PAUSED until the first buffer arrives in this element. The base class will call the 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, GstBaseSink will synchronise on the clock using the times returned from 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 sync property to FALSE.
After synchronisation the virtual method render will be called. Subclasses should minimally implement this method.
Subclasses that synchronise on the clock in the 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 gst_base_sink_wait_preroll to perform the blocking wait.
Upon receiving the EOS event in the PLAYING state, GstBaseSink will wait for the clock to reach the time indicated by the stop time of the last 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.
GstBaseSink will internally use the GST_EVENT_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.
GstBaseSink 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 set_caps function will be called when the subclass should configure itself to process a specific media type.
The start and stop virtual methods will be called when resources should be allocated. Any preroll, render and set_caps function will be called between the start and stop calls.
The event virtual method will be called when an event is received by GstBaseSink. Normally this method should only be overridden by very specific elements (such as file sinks) which need to handle the newsegment event specially.
The unlock method is called when the elements should unblock any blocking operations they perform in the render method. This is mostly useful when the render method performs a blocking write on a file descriptor, for example.
The 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 get_times method does not return a valid start time or max-lateness is set to -1 (the default). Subclasses can use gst_base_sink_set_max_lateness to configure the max-lateness value.
The 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 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.
GstBaseSink
GObject ╰──GInitiallyUnowned ╰──GstObject ╰──GstElement ╰──GstBaseSink
The opaque GstBaseSink data structure.
Members
element
(GstElement)
–
sinkpad
(GstPad *)
–
pad_mode
(GstPadMode)
–
offset
(guint64)
–
can_activate_pull
(gboolean)
–
can_activate_push
(gboolean)
–
preroll_lock
(GMutex)
–
preroll_cond
(GCond)
–
eos
(gboolean)
–
need_preroll
(gboolean)
–
have_preroll
(gboolean)
–
playing_async
(gboolean)
–
have_newsegment
(gboolean)
–
segment
(GstSegment)
–
Class structure
GstBaseSinkClass
Subclasses can override any of the available virtual methods or not, as needed. At the minimum, the render method should be overridden to output/present buffers.
Fields
parent_class
(GstElementClass)
–
Element parent class
Methods
gst_base_sink_do_preroll
GstFlowReturn gst_base_sink_do_preroll (GstBaseSink * sink, GstMiniObject * obj)
If the sink spawns its own thread for pulling buffers from upstream it should call this method after it has pulled a buffer. If the element needed to preroll, this function will perform the preroll and will then block until the element state is changed.
This function should be called with the PREROLL_LOCK held.
Parameters:
sink
–
the sink
obj
(
[transfer: none])
–
the mini object that caused the preroll
GST_FLOW_OK if the preroll completed and processing can continue. Any other return value should be returned from the render vmethod.
gst_base_sink_get_blocksize
guint gst_base_sink_get_blocksize (GstBaseSink * sink)
Get the number of bytes that the sink will pull when it is operating in pull mode.
Parameters:
sink
–
the number of bytes sink will pull in pull mode.
gst_base_sink_get_drop_out_of_segment
gboolean gst_base_sink_get_drop_out_of_segment (GstBaseSink * sink)
Checks if sink is currently configured to drop buffers which are outside the current segment
Parameters:
sink
–
the sink
TRUE if the sink is configured to drop buffers outside the current segment.
Since : 1.12
gst_base_sink_get_last_sample
GstSample * gst_base_sink_get_last_sample (GstBaseSink * sink)
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 GstCaps on the sample can be used to determine the type of the buffer.
Free-function: gst_sample_unref
Parameters:
sink
–
the sink
a GstSample. gst_sample_unref after usage. This function returns NULL when no buffer has arrived in the sink yet or when the sink is not in PAUSED or PLAYING.
gst_base_sink_get_latency
GstClockTime gst_base_sink_get_latency (GstBaseSink * sink)
Get the currently configured latency.
Parameters:
sink
–
the sink
The configured latency.
gst_base_sink_get_max_bitrate
guint64 gst_base_sink_get_max_bitrate (GstBaseSink * sink)
Get the maximum amount of bits per second that the sink will render.
Parameters:
sink
–
the maximum number of bits per second sink will render.
Since : 1.2
gst_base_sink_get_max_lateness
gint64 gst_base_sink_get_max_lateness (GstBaseSink * sink)
Gets the max lateness value. See gst_base_sink_set_max_lateness for more details.
Parameters:
sink
–
the sink
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.
gst_base_sink_get_processing_deadline
GstClockTime gst_base_sink_get_processing_deadline (GstBaseSink * sink)
Get the processing deadline of sink. see gst_base_sink_set_processing_deadline for more information about the processing deadline.
Parameters:
sink
–
the processing deadline
Since : 1.16
gst_base_sink_get_render_delay
GstClockTime gst_base_sink_get_render_delay (GstBaseSink * sink)
Get the render delay of sink. see gst_base_sink_set_render_delay for more information about the render delay.
Parameters:
sink
–
the render delay of sink.
gst_base_sink_get_stats
GstStructure * gst_base_sink_get_stats (GstBaseSink * sink)
Return various GstBaseSink statistics. This function returns a GstStructure
with name application/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
Parameters:
sink
–
pointer to GstStructure
Since : 1.18
gst_base_sink_get_sync
gboolean gst_base_sink_get_sync (GstBaseSink * sink)
Checks if sink is currently configured to synchronize against the clock.
Parameters:
sink
–
the sink
TRUE if the sink is configured to synchronize against the clock.
gst_base_sink_get_throttle_time
guint64 gst_base_sink_get_throttle_time (GstBaseSink * sink)
Get the time that will be inserted between frames to control the maximum buffers per second.
Parameters:
sink
–
the number of nanoseconds sink will put between frames.
gst_base_sink_get_ts_offset
GstClockTimeDiff gst_base_sink_get_ts_offset (GstBaseSink * sink)
Get the synchronisation offset of sink.
Parameters:
sink
–
the sink
The synchronisation offset.
gst_base_sink_is_async_enabled
gboolean gst_base_sink_is_async_enabled (GstBaseSink * sink)
Checks if sink is currently configured to perform asynchronous state changes to PAUSED.
Parameters:
sink
–
the sink
TRUE if the sink is configured to perform asynchronous state changes.
gst_base_sink_is_last_sample_enabled
gboolean gst_base_sink_is_last_sample_enabled (GstBaseSink * sink)
Checks if sink is currently configured to store the last received sample in the last-sample property.
Parameters:
sink
–
the sink
TRUE if the sink is configured to store the last received sample.
gst_base_sink_is_qos_enabled
gboolean gst_base_sink_is_qos_enabled (GstBaseSink * sink)
Checks if sink is currently configured to send Quality-of-Service events upstream.
Parameters:
sink
–
the sink
TRUE if the sink is configured to perform Quality-of-Service.
gst_base_sink_query_latency
gboolean gst_base_sink_query_latency (GstBaseSink * sink, gboolean * live, gboolean * upstream_live, GstClockTime * min_latency, GstClockTime * max_latency)
Query the sink for the latency parameters. The latency will be queried from the upstream elements. live will be TRUE if sink 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.
Parameters:
sink
–
the sink
live
(
[out][allow-none])
–
if the sink is live
upstream_live
(
[out][allow-none])
–
if an upstream element is live
min_latency
(
[out][allow-none])
–
the min latency of the upstream elements
max_latency
(
[out][allow-none])
–
the max latency of the upstream elements
TRUE if the query succeeded.
gst_base_sink_set_async_enabled
gst_base_sink_set_async_enabled (GstBaseSink * sink, gboolean enabled)
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:
sink
–
the sink
enabled
–
the new async value.
gst_base_sink_set_blocksize
gst_base_sink_set_blocksize (GstBaseSink * sink, guint blocksize)
Set the number of bytes that the sink will pull when it is operating in pull mode.
gst_base_sink_set_drop_out_of_segment
gst_base_sink_set_drop_out_of_segment (GstBaseSink * sink, gboolean drop_out_of_segment)
Configure sink to drop buffers which are outside the current segment
Parameters:
sink
–
the sink
drop_out_of_segment
–
drop buffers outside the segment
Since : 1.12
gst_base_sink_set_last_sample_enabled
gst_base_sink_set_last_sample_enabled (GstBaseSink * sink, gboolean enabled)
Configures sink to store the last received sample in the last-sample property.
Parameters:
sink
–
the sink
enabled
–
the new enable-last-sample value.
gst_base_sink_set_max_bitrate
gst_base_sink_set_max_bitrate (GstBaseSink * sink, guint64 max_bitrate)
Set the maximum amount of bits per second that the sink will render.
Since : 1.2
gst_base_sink_set_max_lateness
gst_base_sink_set_max_lateness (GstBaseSink * sink, gint64 max_lateness)
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:
sink
–
the sink
max_lateness
–
the new max lateness value.
gst_base_sink_set_processing_deadline
gst_base_sink_set_processing_deadline (GstBaseSink * sink, GstClockTime 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.
This function is usually called by subclasses.
Since : 1.16
gst_base_sink_set_qos_enabled
gst_base_sink_set_qos_enabled (GstBaseSink * sink, gboolean enabled)
Configures sink to send Quality-of-Service events upstream.
Parameters:
sink
–
the sink
enabled
–
the new qos value.
gst_base_sink_set_render_delay
gst_base_sink_set_render_delay (GstBaseSink * sink, GstClockTime delay)
Set the render delay in sink 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.
gst_base_sink_set_sync
gst_base_sink_set_sync (GstBaseSink * sink, gboolean sync)
Configures sink 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.
Parameters:
sink
–
the sink
sync
–
the new sync value.
gst_base_sink_set_throttle_time
gst_base_sink_set_throttle_time (GstBaseSink * sink, guint64 throttle)
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.
gst_base_sink_set_ts_offset
gst_base_sink_set_ts_offset (GstBaseSink * sink, GstClockTimeDiff offset)
Adjust the synchronisation of sink 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.
Parameters:
sink
–
the sink
offset
–
the new offset
gst_base_sink_wait
GstFlowReturn gst_base_sink_wait (GstBaseSink * sink, GstClockTime time, GstClockTimeDiff * jitter)
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:
sink
–
the sink
time
–
the running_time to be reached
jitter
(
[out][allow-none])
–
the jitter to be filled with time diff, or NULL
gst_base_sink_wait_clock
GstClockReturn gst_base_sink_wait_clock (GstBaseSink * sink, GstClockTime time, GstClockTimeDiff * jitter)
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 event vmethod or when receiving a buffer in the 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:
sink
–
the sink
time
–
the running_time to be reached
jitter
(
[out][allow-none])
–
the jitter to be filled with time diff, or NULL
gst_base_sink_wait_preroll
GstFlowReturn gst_base_sink_wait_preroll (GstBaseSink * sink)
If the 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 render method can block on something else than the clock, it must also be ready to unblock immediately on the unlock method and cause the 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.
Parameters:
sink
–
the sink
GST_FLOW_OK if the preroll completed and processing can continue. Any other return value should be returned from the render vmethod.
Properties
blocksize
“blocksize” guint
The amount of bytes to pull when operating in pull mode.
Flags : Read / Write
enable-last-sample
“enable-last-sample” gboolean
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 NULL. This can be useful if you need buffers to be released as soon as possible, eg. if you're using a buffer pool.
Flags : Read / Write
max-bitrate
“max-bitrate” guint64
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.
Flags : Read / Write
Since : 1.2
processing-deadline
“processing-deadline” guint64
Maximum amount of time (in nanoseconds) that the pipeline can take for processing the buffer. This is added to the latency of live pipelines.
Flags : Read / Write
Since : 1.16
render-delay
“render-delay” guint64
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.
Flags : Read / Write
stats
“stats” GstStructure *
Various GstBaseSink statistics. This property returns a GstStructure
with name application/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
Flags : Read
Since : 1.18
throttle-time
“throttle-time” guint64
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.
Flags : Read / Write
ts-offset
“ts-offset” gint64
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.
Flags : Read / Write
Virtual Methods
activate_pull
gboolean activate_pull (GstBaseSink * sink, gboolean active)
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:
sink
–
active
–
event
gboolean event (GstBaseSink * sink, GstEvent * event)
Override this to handle events arriving on the sink pad
Parameters:
sink
–
event
–
fixate
GstCaps * fixate (GstBaseSink * sink, GstCaps * caps)
Only useful in pull mode. Implement if you have ideas about what should be the default values for the caps you support.
Parameters:
sink
–
caps
–
get_caps
GstCaps * get_caps (GstBaseSink * sink, GstCaps * filter)
Called to get sink pad caps from the subclass
Parameters:
sink
–
filter
–
get_times
get_times (GstBaseSink * sink, GstBuffer * buffer, GstClockTime * start, GstClockTime * end)
Called to get the start and end times for synchronising the passed buffer to the clock
Parameters:
sink
–
buffer
–
start
–
end
–
prepare
GstFlowReturn prepare (GstBaseSink * sink, GstBuffer * buffer)
Called to prepare the buffer for render and preroll. This function is called before synchronisation is performed.
Parameters:
sink
–
buffer
–
prepare_list
GstFlowReturn prepare_list (GstBaseSink * sink, GstBufferList * buffer_list)
Called to prepare the buffer list for render_list. This function is called before synchronisation is performed.
Parameters:
sink
–
buffer_list
–
preroll
GstFlowReturn preroll (GstBaseSink * sink, GstBuffer * buffer)
Called to present the preroll buffer if desired.
Parameters:
sink
–
buffer
–
propose_allocation
gboolean propose_allocation (GstBaseSink * sink, GstQuery * query)
configure the allocation query
Parameters:
sink
–
query
–
query
gboolean query (GstBaseSink * sink, GstQuery * query)
perform a GstQuery on the element.
Parameters:
sink
–
query
–
render
GstFlowReturn render (GstBaseSink * sink, GstBuffer * buffer)
Called when a buffer should be presented or output, at the correct moment if the GstBaseSink has been set to sync to the clock.
Parameters:
sink
–
buffer
–
render_list
GstFlowReturn render_list (GstBaseSink * sink, GstBufferList * buffer_list)
Same as render but used with buffer lists instead of buffers.
Parameters:
sink
–
buffer_list
–
set_caps
gboolean set_caps (GstBaseSink * sink, GstCaps * caps)
Notify subclass of changed caps
Parameters:
sink
–
caps
–
start
gboolean start (GstBaseSink * sink)
Start processing. Ideal for opening resources in the subclass
Parameters:
sink
–
stop
gboolean stop (GstBaseSink * sink)
Stop processing. Subclasses should use this to close resources.
Parameters:
sink
–
unlock
gboolean unlock (GstBaseSink * sink)
Unlock any pending access to the resource. Subclasses should unblock any blocked function ASAP and call gst_base_sink_wait_preroll
Parameters:
sink
–
unlock_stop
gboolean unlock_stop (GstBaseSink * sink)
Clear the previous unlock request. Subclasses should clear any state they set during unlock, and be ready to continue where they left off after gst_base_sink_wait_preroll, gst_base_sink_wait or gst_wait_sink_wait_clock return or render is called again.
Parameters:
sink
–
wait_event
GstFlowReturn wait_event (GstBaseSink * sink, GstEvent * event)
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:
sink
–
event
–
Function Macros
GST_BASE_SINK_PAD
#define GST_BASE_SINK_PAD(obj) (GST_BASE_SINK_CAST (obj)->sinkpad)
Gives the pointer to the GstPad object of the element.
Parameters:
obj
–
base sink instance
Constants
GST_BASE_SINK_FLOW_DROPPED
#define GST_BASE_SINK_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS
A GstFlowReturn that can be returned from render to indicate that the output buffer was not rendered.
Note that this is currently not support for render_list virtual method.
Since : 1.24
The results of the search are