<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >GstStaticPadTemplate</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79;charset=UTF-8"><LINK REL="HOME" TITLE="GStreamer Plugin Writer's Guide (0.10.36)" HREF="index.html"><LINK REL="UP" TITLE="Constructing the Boilerplate" HREF="chapter-building-boiler.html"><LINK REL="PREVIOUS" TITLE="GstElementDetails" HREF="section-boiler-details.html"><LINK REL="NEXT" TITLE="Constructor Functions" HREF="section-boiler-constructors.html"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" ><SPAN CLASS="application" >GStreamer</SPAN > Plugin Writer's Guide (0.10.36)</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="section-boiler-details.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 3. Constructing the Boilerplate</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="section-boiler-constructors.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="section-boiler-padtemplates" >3.5. GstStaticPadTemplate</A ></H1 ><P > A GstStaticPadTemplate is a description of a pad that the element will (or might) create and use. It contains: </P ><P ></P ><UL ><LI ><P >A short name for the pad.</P ></LI ><LI ><P >Pad direction.</P ></LI ><LI ><P > Existence property. This indicates whether the pad exists always (an <SPAN CLASS="QUOTE" >"always"</SPAN > pad), only in some cases (a <SPAN CLASS="QUOTE" >"sometimes"</SPAN > pad) or only if the application requested such a pad (a <SPAN CLASS="QUOTE" >"request"</SPAN > pad). </P ></LI ><LI ><P >Supported types by this element (capabilities).</P ></LI ></UL ><P > For example: </P ><PRE CLASS="programlisting" > static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ( "sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS ("ANY") ); </PRE ><P > Those pad templates are registered during the <CODE CLASS="function" >_base_init ()</CODE > function. Pads are created from these templates in the element's <CODE CLASS="function" >_init ()</CODE > function using <CODE CLASS="function" >gst_pad_new_from_template ()</CODE >. The template can be retrieved from the element class using <CODE CLASS="function" >gst_element_class_get_pad_template ()</CODE >. See below for more details on this. In order to create a new pad from this template using <CODE CLASS="function" >gst_pad_new_from_template ()</CODE >, you will need to declare the pad template as a global variable. More on this subject in <A HREF="chapter-building-pads.html" >Chapter 4</A >. </P ><PRE CLASS="programlisting" > 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)); } </PRE ><P > 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: </P ><PRE CLASS="programlisting" > 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 ]" ) ); </PRE ><P > Values surrounded by curly brackets (<SPAN CLASS="QUOTE" >"{"</SPAN > and <SPAN CLASS="QUOTE" >"}"</SPAN >) are lists, values surrounded by square brackets (<SPAN CLASS="QUOTE" >"["</SPAN > and <SPAN CLASS="QUOTE" >"]"</SPAN >) are ranges. Multiple sets of types are supported too, and should be separated by a semicolon (<SPAN CLASS="QUOTE" >";"</SPAN >). Later, in the chapter on pads, we will see how to use types to know the exact format of a stream: <A HREF="chapter-building-pads.html" >Chapter 4</A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="section-boiler-details.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="section-boiler-constructors.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >GstElementDetails</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="chapter-building-boiler.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Constructor Functions</TD ></TR ></TABLE ></DIV ></BODY ></HTML >