Sink is the base class for sink elements in GStreamer, such as xvimagesink or filesink.
It is a layer on top of Element that provides a simplified interface to plugin writers.
Sink 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 Element
or to set functions on pads, because the Sink infrastructure should be sufficient.
Sink provides support for exactly one sink pad, which should be named "sink". A sink implementation
(subclass of Sink) 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 <[email protected]>");
}
Sink will handle the prerolling correctly. This means that it will return
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, Sink will synchronise on the clock using the times returned from
GstBaseSinkClass::get_times
s. If this function returns 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 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 wait_preroll to perform the blocking
wait.
Upon receiving the EOS event in the PLAYING state, Sink will wait for the clock to reach the time
indicated by the stop time of the last GstBaseSinkClass::get_times
s 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.
Sink will internally use the 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.
Sink will by default report the current playback position in 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
s 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
s
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 Sink
. 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 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
s method does not return a valid start time or max-lateness is set to -1 (the default). Subclasses can
use 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.
- public virtual bool @unlock ()
- public virtual bool activate_pull (bool active)
- public FlowReturn do_preroll (MiniObject obj)
If the this spawns its own thread
for pulling buffers from upstream it should call this method after it has pulled a buffer.
- public virtual bool event (Event event)
- public virtual Caps fixate (Caps caps)
- public uint get_blocksize ()
Get the number of bytes that the sink will pull when it is operating
in pull mode.
- public virtual Caps get_caps (Caps? filter)
Called to get sink pad caps from the subclass.
- public bool get_drop_out_of_segment ()
Checks if this is currently
configured to drop buffers which are outside the current segment
- public Sample? get_last_sample ()
Get the last sample that arrived in the sink and was used for preroll
or for rendering.
- public ClockTime get_latency ()
Get the currently configured latency.
- public uint64 get_max_bitrate ()
Get the maximum amount of bits per second that the sink will render.
- public int64 get_max_lateness ()
Gets the max lateness value.
- public ClockTime get_processing_deadline ()
Get the processing deadline of this.
- public ClockTime get_render_delay ()
Get the render delay of this.
- public Structure get_stats ()
Return various Sink statistics.
- public bool get_sync ()
Checks if this is currently
configured to synchronize against the clock.
- public uint64 get_throttle_time ()
Get the time that will be inserted between frames to control the
maximum buffers per second.
- public virtual void get_times (Buffer buffer, out ClockTime start, out ClockTime end)
Get the start and end times for syncing on this buffer.
- public ClockTimeDiff get_ts_offset ()
Get the synchronisation offset of this
.
- public bool is_async_enabled ()
Checks if this is currently
configured to perform asynchronous state changes to PAUSED.
- public bool is_last_sample_enabled ()
Checks if this is currently
configured to store the last received sample in the last-sample property.
- public bool is_qos_enabled ()
Checks if this is currently
configured to send Quality-of-Service events upstream.
- public virtual FlowReturn prepare (Buffer buffer)
- public virtual FlowReturn prepare_list (BufferList buffer_list)
- public virtual FlowReturn preroll (Buffer buffer)
- public virtual bool propose_allocation (Query query)
- public virtual bool query (Query query)
- public bool query_latency (out bool live, out bool upstream_live, out ClockTime min_latency, out ClockTime max_latency)
Query the sink for the latency parameters.
- public virtual FlowReturn render (Buffer buffer)
- public virtual FlowReturn render_list (BufferList buffer_list)
- public void set_async_enabled (bool enabled)
Configures this to perform all state
changes asynchronously.
- public void set_blocksize (uint blocksize)
Set the number of bytes that the sink will pull when it is operating
in pull mode.
- public virtual bool set_caps (Caps caps)
- public void set_drop_out_of_segment (bool drop_out_of_segment)
Configure this to drop buffers which
are outside the current segment
- public void set_last_sample_enabled (bool enabled)
Configures this to store the last
received sample in the last-sample property.
- public void set_max_bitrate (uint64 max_bitrate)
Set the maximum amount of bits per second that the sink will render.
- public void set_max_lateness (int64 max_lateness)
Sets the new max lateness value to max_lateness
.
- public void set_processing_deadline (ClockTime processing_deadline)
Maximum amount of time (in nanoseconds) that the pipeline can take for
processing the buffer.
- public void set_qos_enabled (bool enabled)
Configures this to send
Quality-of-Service events upstream.
- public void set_render_delay (ClockTime delay)
Set the render delay in this to
delay
.
- public void set_sync (bool sync)
Configures this to synchronize on
the clock or not.
- public void set_throttle_time (uint64 throttle)
Set the time that will be inserted between rendered buffers.
- public void set_ts_offset (ClockTimeDiff offset)
Adjust the synchronisation of this
with offset
.
- public virtual bool start ()
- public virtual bool stop ()
- public virtual bool unlock_stop ()
- public FlowReturn wait (ClockTime time, out ClockTimeDiff jitter)
This function will wait for preroll to complete and will then block
until time
is reached.
- public ClockReturn wait_clock (ClockTime time, out ClockTimeDiff jitter)
This function will block until time
is reached.
- public virtual FlowReturn wait_event (Event event)
- public FlowReturn wait_preroll ()
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.