![]() |
![]() |
![]() |
GStreamer 0.10 Library Reference Manual | ![]() |
---|---|---|---|---|
#include <gst/base/gstbasesink.h> GstBaseSink; GstBaseSinkClass; gboolean gst_base_sink_query_latency (GstBaseSink *sink, gboolean *live, gboolean *upstream_live, GstClockTime *min_latency, GstClockTime *max_latency); GstClockTime gst_base_sink_get_latency (GstBaseSink *sink); GstFlowReturn gst_base_sink_wait_preroll (GstBaseSink *sink); void gst_base_sink_set_sync (GstBaseSink *sink, gboolean sync); gboolean gst_base_sink_get_sync (GstBaseSink *sink); void gst_base_sink_set_max_lateness (GstBaseSink *sink, gint64 max_lateness); gint64 gst_base_sink_get_max_lateness (GstBaseSink *sink); gboolean gst_base_sink_is_qos_enabled (GstBaseSink *sink); void gst_base_sink_set_qos_enabled (GstBaseSink *sink, gboolean enabled); #define GST_BASE_SINK_PAD (obj)
"max-lateness" gint64 : Read / Write "preroll-queue-len" guint : Read / Write / Construct "qos" gboolean : Read / Write "sync" gboolean : Read / Write
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 base_init function, like so:
static void my_element_base_init (gpointer g_class) { GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class); // sinktemplate should be a GstStaticPadTemplate with direction // GST_PAD_SINK and name "sink" gst_element_class_add_pad_template (gstelement_class, gst_static_pad_template_get (&sinktemplate)); // see GstElementDetails gst_element_class_set_details (gstelement_class, &details); }
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 GstBaseSink::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 GstBaseSink::render will be called. Subclasses should minimally implement this method.
Since 0.10.3 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. Since 0.10.11 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_NEWSEGMENT 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 overriden by very specific elements (such as file sinks) which need to handle the newsegment event specially.
GstBaseSink provides an overridable ::buffer_alloc function that can be used by sinks that want to do reverse negotiation or to provide custom buffers (hardware buffers for example) to upstream elements.
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 send upstream with these numbers. This information can then be used by upstream elements to reduce their processing rate, for example.
Last reviewed on 2006-09-27 (0.10.11)
typedef struct { GstElementClass parent_class; /* get caps from subclass */ GstCaps* (*get_caps) (GstBaseSink *sink); /* notify subclass of new caps */ gboolean (*set_caps) (GstBaseSink *sink, GstCaps *caps); /* allocate a new buffer with given caps */ GstFlowReturn (*buffer_alloc) (GstBaseSink *sink, guint64 offset, guint size, GstCaps *caps, GstBuffer **buf); /* get the start and end times for syncing on this buffer */ void (*get_times) (GstBaseSink *sink, GstBuffer *buffer, GstClockTime *start, GstClockTime *end); /* start and stop processing, ideal for opening/closing the resource */ gboolean (*start) (GstBaseSink *sink); gboolean (*stop) (GstBaseSink *sink); /* unlock any pending access to the resource. subclasses should unlock * any function ASAP. */ gboolean (*unlock) (GstBaseSink *sink); /* notify subclass of event, preroll buffer or real buffer */ gboolean (*event) (GstBaseSink *sink, GstEvent *event); GstFlowReturn (*preroll) (GstBaseSink *sink, GstBuffer *buffer); GstFlowReturn (*render) (GstBaseSink *sink, GstBuffer *buffer); /* ABI additions */ /* when an ASYNC state change to PLAYING happens */ /* with LOCK */ GstStateChangeReturn (*async_play) (GstBaseSink *sink); /* start or stop a pulling thread */ gboolean (*activate_pull)(GstBaseSink *sink, gboolean active); /* fixate sink caps during pull-mode negotiation */ void (*fixate) (GstBaseSink *sink, GstCaps *caps); } 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.
GstElementClass parent_class; | Element parent class |
get_caps () | Called to get sink pad caps from the subclass |
set_caps () | Notify subclass of changed caps |
buffer_alloc () | Subclasses can override to perform custom buffer allocations |
get_times () | Called to get the start and end times for synchronising the passed buffer to the clock |
start () | Start processing. Ideal for opening resources in the subclass |
stop () | Stop processing. Subclasses should use this to close resources. |
unlock () | Unlock any pending access to the resource. Subclasses should unblock any blocked function ASAP |
event () | Override this to handle events arriving on the sink pad |
preroll () | Called to present the preroll buffer if desired |
render () | Called when a buffer should be presented or output, at the correct moment if the GstBaseSink has been set to sync to the clock. |
async_play () | Subclasses should override this when they need to perform special processing when changing to the PLAYING state asynchronously. Called with the OBJECT_LOCK held. |
activate_pull () | 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. |
fixate () | Only useful in pull mode, this vmethod will be called in response to gst_pad_fixate_caps() being called on the sink pad. Implement if you have ideas about what should be the default values for the caps you support. |
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 possitive value.
This function is mostly used by subclasses.
sink : | the sink |
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 |
Returns : | TRUE if the query succeeded. |
Since 0.10.12
GstClockTime gst_base_sink_get_latency (GstBaseSink *sink);
Get the currently configured latency.
sink : | the sink |
Returns : | The configured latency. |
Since 0.10.12
GstFlowReturn gst_base_sink_wait_preroll (GstBaseSink *sink);
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.
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_WRONG_STATE).
sink : | the sink |
Returns : | GST_FLOW_OK if the preroll completed and processing can continue. Any other return value should be returned from the render vmethod. |
Since 0.10.11
void gst_base_sink_set_sync (GstBaseSink *sink, gboolean sync);
Configures sink to synchronize on the clock or not. When sync is FALSE, incomming samples will be played as fast as possible. If sync is TRUE, the timestamps of the incomming buffers will be used to schedule the exact render time of its contents.
sink : | the sink |
sync : | the new sync value. |
Since 0.10.4
gboolean gst_base_sink_get_sync (GstBaseSink *sink);
Checks if sink is currently configured to synchronize against the clock.
sink : | the sink |
Returns : | TRUE if the sink is configured to synchronize against the clock. |
Since 0.10.4
void 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.
sink : | the sink |
max_lateness : | the new max lateness value. |
Since 0.10.4
gint64 gst_base_sink_get_max_lateness (GstBaseSink *sink);
Gets the max lateness value. See gst_base_sink_set_max_lateness for more details.
sink : | the sink |
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. |
Since 0.10.4
gboolean gst_base_sink_is_qos_enabled (GstBaseSink *sink);
Checks if sink is currently configured to send Quality-of-Service events upstream.
sink : | the sink |
Returns : | TRUE if the sink is configured to perform Quality-of-Service. |
Since 0.10.5
void gst_base_sink_set_qos_enabled (GstBaseSink *sink, gboolean enabled);
Configures sink to send Quality-of-Service events upstream.
sink : | the sink |
enabled : | the new qos value. |
Since 0.10.5
"max-lateness" gint64 : Read / Write
Maximum number of nanoseconds that a buffer can be late before it is dropped (-1 unlimited).
Allowed values: >= G_MAXULONG
Default value: -1
"preroll-queue-len" guint : Read / Write / Construct
Number of buffers to queue during preroll.
Default value: 0
"qos" gboolean : Read / Write
Generate Quality-of-Service events upstream.
Default value: FALSE