Writing a Source

Source elements are the start of a data streaming pipeline. Source elements have no sink pads and have one or more source pads. We will focus on single-sourcepad elements here, but the concepts apply equally well to multi-sourcepad elements. This chapter will explain the essentials of source elements, which features it should implement and which it doesn't have to, and how source elements will interact with other elements in a pipeline.

The get()-function

Source elements have the special option of having a _get ()-function rather than a _loop ()- or _chain ()-function. A _get ()-function is called by the scheduler every time the next elements needs data. Apart from corner cases, every source element will want to be _get ()-based.


static GstData *	gst_my_source_get	(GstPad *pad);

static void
gst_my_source_init (GstMySource *src)
{
[..]
  gst_pad_set_get_function (src->srcpad, gst_my_source_get);
}

static GstData *
gst_my_source_get (GstPad *pad)
{
  GstBuffer *buffer;

  buffer = gst_buffer_new ();
  GST_BUFFER_DATA (buf) = g_strdup ("hello pipeline!");
  GST_BUFFER_SIZE (buf) = strlen (GST_BUFFER_DATA (buf));
  /* terminating '/0' */
  GST_BUFFER_MAZSIZE (buf) = GST_BUFFER_SIZE (buf) + 1;

  return GST_DATA (buffer);
}