GstBaseSrc

GstBaseSrc — Base class for getrange based source elements

Synopsis


#include <gst/base/gstbasesrc.h>


            GstBaseSrc;
enum        GstBaseSrcFlags;
gboolean    gst_base_src_is_live            (GstBaseSrc *src);
void        gst_base_src_set_live           (GstBaseSrc *src,
                                             gboolean live);
void        gst_base_src_set_format         (GstBaseSrc *src,
                                             GstFormat format);
#define     GST_BASE_SRC_PAD                (obj)


Description

This is a generice base class for source elements. The following types of sources are supported:

  • random access sources like files

  • seekable sources

  • live sources

The source can be configured to operate in a any GstFormat with the gst_base_src_set_format(). This format determines the format of the internal GstSegment and the GST_EVENT_NEW_SEGMENT. The default format for GstBaseSrc is GST_FORMAT_BYTES.

GstBaseSrc always supports the push mode scheduling. If the following conditions are met, it also supports pull mode scheduling:

  • the format is set to GST_FORMAT_BYTES (default).

  • GstBaseSrc::is_seekable returns TRUE.

If all the conditions are met for operating in pull mode, GstBaseSrc is automatically seekable in push mode as well. The following conditions must be met to make the element seekable in push mode when the format is not GST_FORMAT_BYTES:

When the default format is not GST_FORMAT_BYTES, the element should ignore the offset and length in the GstBaseSrc::create method. It is recommended to subclass GstPushSrc instead in this situation.

GstBaseSrc has support for live sources. Live sources are sources that produce data at a fixed rate, such as audio or video capture. A typical live source also provides a clock to export the rate at which they produce data. Use gst_base_src_set_live() to activate the live source mode.

A live source does not produce data in the PAUSED state, this means that the GstBaseSrc::create method will not be called in PAUSED but only in PLAYING. To signal the pipeline that the element will not produce data, its return value from the READY to PAUSED state will be GST_STATE_CHANGE_NO_PREROLL.

A typical live source will timestamp the buffers they create with the current stream time of the pipeline. This is why they can only produce data in PLAYING, when the clock is actually distributed and running.

The GstBaseSrc::get_times method can be used to implement pseudo-live sources. The base source will wait for the specified stream time returned in GstBaseSrc::get_times before pushing out the buffer. It only makes sense to implement the ::get_times function if the source is a live source.

There is only support in GstBaseSrc for one source pad, which should be named "src". A source implementation (subclass of GstBaseSrc) 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);
  // srctemplate should be a GstStaticPadTemplate with direction
  // GST_PAD_SRC and name "src"
  gst_element_class_add_pad_template (gstelement_class,
      gst_static_pad_template_get (&srctemplate));
  // see GstElementDetails
  gst_element_class_set_details (gstelement_class, &details);
}

Last reviewed on 2005-12-18 (0.10.0)

Details

GstBaseSrc

typedef struct {
  GstElement     element;
} GstBaseSrc;

The opaque GstBaseSrc data structure.

GstElement element; the parent element.

enum GstBaseSrcFlags

typedef enum {
  GST_BASE_SRC_STARTED           = (GST_ELEMENT_FLAG_LAST << 0),
  /* padding */
  GST_BASE_SRC_FLAG_LAST         = (GST_ELEMENT_FLAG_LAST << 2)
} GstBaseSrcFlags;

The GstElement flags that a basesrc element may have.

GST_BASE_SRC_STARTED has source been started
GST_BASE_SRC_FLAG_LAST offset to define more flags

gst_base_src_is_live ()

gboolean    gst_base_src_is_live            (GstBaseSrc *src);

Check if an element is in live mode.

src : base source instance
Returns : TRUE if element is in live mode.

gst_base_src_set_live ()

void        gst_base_src_set_live           (GstBaseSrc *src,
                                             gboolean live);

If the element listens to a live source, the livemode should be set to TRUE. This declares that this source can't seek.

src : base source instance
live : new live-mode

gst_base_src_set_format ()

void        gst_base_src_set_format         (GstBaseSrc *src,
                                             GstFormat format);

Sets the default format of the source. This will be the format used for sending NEW_SEGMENT events and for performing seeks.

If a format of GST_FORMAT_BYTES is set, the element will be able to operate in pull mode if the GstBaseSrc::is_seekable returns TRUE.

Since: 0.10.1

src : base source instance
format : the format to use

GST_BASE_SRC_PAD()

#define GST_BASE_SRC_PAD(obj)                 (GST_BASE_SRC_CAST (obj)->srcpad)

Gives the pointer to the GstPad object of the element.

obj : base source instance

See Also

GstPushSrc, GstBaseTransform, GstBaseSink