GstBaseSink

GstBaseSink — Base class for sink elements

Synopsis


#include <gst/base/gstbasesink.h>


            GstBaseSink;
            GstBaseSinkClass;
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)


Description

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.

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_NEW_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 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 dropped buffer it will also send a QoS message upstream.

Last reviewed on 2006-03-31 (0.10.5)

Details

GstBaseSink

typedef struct {
  GstElement	 element;
} GstBaseSink;

The opaque GstBaseSink data structure.

GstElement element; the parent element.
GstPad *sinkpad;
GstActivateMode pad_mode;
guint64 offset;
gboolean can_activate_pull;
gboolean can_activate_push;
GQueue *preroll_queue;
gint preroll_queue_max_len;
gint preroll_queued;
gint buffers_queued;
gint events_queued;
gboolean eos;
gboolean eos_queued;
gboolean need_preroll;
gboolean have_preroll;
gboolean playing_async;
gboolean have_newsegment;
GstSegment segment;
GstClockID clock_id;
GstClockTime end_time;
gboolean sync;
gboolean flushing;
gpointer _gst_reserved[GST_PADDING_LARGE - 1];

GstBaseSinkClass

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);
} 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;
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.

gst_base_sink_set_sync ()

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


gst_base_sink_get_sync ()

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


gst_base_sink_set_max_lateness ()

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


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.

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


gst_base_sink_is_qos_enabled ()

gboolean    gst_base_sink_is_qos_enabled    (GstBaseSink *sink);

Checks if sink is currently configured to send QoS events upstream.

sink : the sink
Returns : TRUE if the sink is configured to perform QoS.

Since 0.10.5


gst_base_sink_set_qos_enabled ()

void        gst_base_sink_set_qos_enabled   (GstBaseSink *sink,
                                             gboolean enabled);

Configures sink to send QoS events upstream.

sink : the sink
enabled : the new qos value.

Since 0.10.5


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.

obj : base sink instance

See Also

GstBaseTransform, GstBaseSource