<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >Pads</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="GStreamer Application Development Manual" HREF="index.html"><LINK REL="UP" TITLE="Basic API" HREF="part-basic-api.html"><LINK REL="PREVIOUS" TITLE="More about GstElementFactory" HREF="section-elements-factories.html"><LINK REL="NEXT" TITLE="Capabilities of a pad" HREF="section-api-caps.html"></HEAD ><BODY CLASS="chapter" 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 > Application Development Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="section-elements-factories.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="section-api-caps.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="chapter" ><H1 ><A NAME="chapter-pads-api" ></A >Chapter 13. Pads</H1 ><P > As we have seen in <A HREF="chapter-elements.html" >Chapter 4</A >, the pads are the element's interface to the outside world. </P ><P > The specific type of media that the element can handle will be exposed by the pads. The description of this media type is done with capabilities(see <A HREF="section-caps.html" >Section 5.2</A >) </P ><P > Pads are either source or sink pads. The terminology is defined from the view of the element itself: elements accept data on their sink pads, and send data out on their source pads. Sink pads are drawn on the left, while source pads are drawn on the right of an element. In general, data flows from left to right in the graph.<A NAME="AEN487" HREF="#FTN.AEN487" ><SPAN CLASS="footnote" >[1]</SPAN ></A > </P ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="section-pads-api-type" >13.1. Types of pads</A ></H1 ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="section-pads-api-dynamic" >13.1.1. Dynamic pads</A ></H2 ><P > You can attach a signal to an element to inform you when the element has created a new pad from one of its padtemplates. The following piece of code is an example of how to do this: </P ><PRE CLASS="programlisting" > static void pad_link_func (GstElement *parser, GstPad *pad, GstElement *pipeline) { g_print("***** a new pad %s was created\n", gst_pad_get_name(pad)); gst_element_set_state (pipeline, GST_STATE_PAUSED); if (strncmp (gst_pad_get_name (pad), "private_stream_1.0", 18) == 0) { // set up an AC3 decoder pipeline ... // link pad to the AC3 decoder pipeline ... } gst_element_set_state (GST_ELEMENT (audio_thread), GST_STATE_READY); } int main(int argc, char *argv[]) { GstElement *pipeline; GstElement *mpeg2parser; // create pipeline and do something useful ... mpeg2parser = gst_element_factory_make ("mpegdemux", "mpegdemux"); g_signal_connect (G_OBJECT (mpeg2parser), "new_pad", pad_link_func, pipeline); ... // start the pipeline gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); ... } </PRE ><DIV CLASS="note" ><P ></P ><TABLE CLASS="note" WIDTH="100%" BORDER="0" ><TR ><TD WIDTH="25" ALIGN="CENTER" VALIGN="TOP" ><IMG SRC="../images/note.gif" HSPACE="5" ALT="Note"></TD ><TD ALIGN="LEFT" VALIGN="TOP" ><P > A pipeline cannot be changed in the PLAYING state. </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="sect2" ><H2 CLASS="sect2" ><A NAME="section-pads-api-request" >13.1.2. Request pads</A ></H2 ><P > The following piece of code can be used to get a pad from the tee element. After the pad has been requested, it can be used to link another element to it. </P ><PRE CLASS="programlisting" > ... GstPad *pad; ... element = gst_element_factory_make ("tee", "element"); pad = gst_element_get_request_pad (element, "src%d"); g_print ("new pad %s\n", gst_pad_get_name (pad)); ... </PRE ><P > The gst_element_get_request_pad method can be used to get a pad from the element based on the name_template of the padtemplate. </P ><P > It is also possible to request a pad that is compatible with another pad template. This is very useful if you want to link an element to a multiplexer element and you need to request a pad that is compatible. The gst_element_get_compatible_pad is used to request a compatible pad, as is shown in the next example. </P ><PRE CLASS="programlisting" > ... GstPadTemplate *templ; GstPad *pad; ... element = gst_element_factory_make ("tee", "element"); mad = gst_element_factory_make ("mad", "mad"); templ = gst_element_get_pad_template_by_name (mad, "sink"); pad = gst_element_get_compatible_pad (element, templ); g_print ("new pad %s\n", gst_pad_get_name (pad)); ... </PRE ></DIV ></DIV ></DIV ><H3 CLASS="FOOTNOTES" >Notes</H3 ><TABLE BORDER="0" CLASS="FOOTNOTES" WIDTH="100%" ><TR ><TD ALIGN="LEFT" VALIGN="TOP" WIDTH="5%" ><A NAME="FTN.AEN487" HREF="chapter-pads-api.html#AEN487" ><SPAN CLASS="footnote" >[1]</SPAN ></A ></TD ><TD ALIGN="LEFT" VALIGN="TOP" WIDTH="95%" ><P > In reality, there is no objection to data flowing from a source pad to the sink pad of an element upstream. Data will, however, always flow from a source pad of one element to the sink pad of another. </P ></TD ></TR ></TABLE ><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-elements-factories.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-api-caps.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >More about GstElementFactory</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="part-basic-api.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Capabilities of a pad</TD ></TR ></TABLE ></DIV ></BODY ></HTML >