3.5. GstStaticPadTemplate

A GstStaticPadTemplate is a description of a pad that the element will (or might) create and use. It contains:

For example:


static GstStaticPadTemplate sink_factory =
GST_STATIC_PAD_TEMPLATE (
  "sink",
  GST_PAD_SINK,
  GST_PAD_ALWAYS,
  GST_STATIC_CAPS ("ANY")
);


      

Those pad templates are registered during the _base_init () function. Pads are created from these templates in the element's _init () function using gst_pad_new_from_template (). The template can be retrieved from the element class using gst_element_class_get_pad_template (). See below for more details on this. In order to create a new pad from this template using gst_pad_new_from_template (), you will need to declare the pad template as a global variable. More on this subject in Chapter 4.


static GstStaticPadTemplate sink_factory = [..],
    src_factory = [..];

static void
gst_my_filter_base_init (gpointer klass)
{
  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
[..]

  gst_element_class_add_pad_template (element_class,
	gst_static_pad_template_get (&src_factory));
  gst_element_class_add_pad_template (element_class,
	gst_static_pad_template_get (&sink_factory));
}

The last argument in a template is its type or list of supported types. In this example, we use 'ANY', which means that this element will accept all input. In real-life situations, you would set a mimetype and optionally a set of properties to make sure that only supported input will come in. This representation should be a string that starts with a mimetype, then a set of comma-separates properties with their supported values. In case of an audio filter that supports raw integer 16-bit audio, mono or stereo at any samplerate, the correct template would look like this:


static GstStaticPadTemplate sink_factory =
GST_STATIC_PAD_TEMPLATE (
  "sink",
  GST_PAD_SINK,
  GST_PAD_ALWAYS,
  GST_STATIC_CAPS (
    "audio/x-raw-int, "
      "width = (int) 16, "
      "depth = (int) 16, "
      "endianness = (int) BYTE_ORDER, "
      "channels = (int) { 1, 2 }, "
      "rate = (int) [ 8000, 96000 ]"
  )
);
    

Values surrounded by curly brackets ("{" and "}") are lists, values surrounded by square brackets ("[" and "]") are ranges. Multiple sets of types are supported too, and should be separated by a semicolon (";"). Later, in the chapter on pads, we will see how to use types to know the exact format of a stream: Chapter 4.