2003-01-09 14:15:37 +00:00
|
|
|
<chapter id="cha-links">
|
2000-08-16 21:38:57 +00:00
|
|
|
<title>Connecting elements</title>
|
|
|
|
<para>
|
2003-01-09 14:15:37 +00:00
|
|
|
You can link the different pads of elements together so that the elements
|
2000-08-16 21:38:57 +00:00
|
|
|
form a chain.
|
|
|
|
</para>
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
<figure float="1" id="sec-link">
|
|
|
|
<title>Visualisation of three linked elements</title>
|
2001-12-13 15:24:00 +00:00
|
|
|
<mediaobject>
|
|
|
|
<imageobject>
|
2003-01-09 14:15:37 +00:00
|
|
|
<imagedata fileref="images/linked-elements.&magic;" format="&MAGIC;" />
|
2001-12-13 15:24:00 +00:00
|
|
|
</imageobject>
|
|
|
|
</mediaobject>
|
2000-08-16 21:38:57 +00:00
|
|
|
</figure>
|
|
|
|
<para>
|
2003-01-09 14:15:37 +00:00
|
|
|
By linking these three elements, we have created a very simple
|
2002-09-14 14:13:34 +00:00
|
|
|
chain. The effect of this will be that the output of the source element
|
2002-09-08 21:17:16 +00:00
|
|
|
(element1) will be used as input for the filter element (element2). The
|
|
|
|
filter element will do something with the data and send the result to
|
|
|
|
the final sink element (element3).
|
2000-08-16 21:38:57 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-09-14 14:13:34 +00:00
|
|
|
Imagine the above graph as a simple MPEG audio decoder. The source
|
|
|
|
element is a disk source, the filter element is the MPEG decoder and
|
2002-09-08 21:17:16 +00:00
|
|
|
the sink element is your audiocard. We will use this simple graph to
|
2002-09-14 14:13:34 +00:00
|
|
|
construct an MPEG player later in this manual.
|
2000-08-16 21:38:57 +00:00
|
|
|
</para>
|
2002-03-31 15:28:51 +00:00
|
|
|
|
|
|
|
<sect1 id="sec-conn-basic">
|
2003-01-09 14:15:37 +00:00
|
|
|
<title>Making simple links</title>
|
2002-03-31 15:28:51 +00:00
|
|
|
<para>
|
2003-01-09 14:15:37 +00:00
|
|
|
You can link two pads with:
|
2002-03-31 15:28:51 +00:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
2001-01-06 02:35:17 +00:00
|
|
|
GstPad *srcpad, *sinkpad;
|
|
|
|
|
|
|
|
srcpad = gst_element_get_pad (element1, "src");
|
|
|
|
sinpad = gst_element_get_pad (element2, "sink");
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
// link them
|
|
|
|
gst_pad_link (srcpad, sinkpad);
|
2001-01-06 02:35:17 +00:00
|
|
|
....
|
2003-01-09 14:15:37 +00:00
|
|
|
// and unlink them
|
|
|
|
gst_pad_unlink (srcpad, sinkpad);
|
2001-01-06 02:35:17 +00:00
|
|
|
|
2002-03-31 15:28:51 +00:00
|
|
|
</programlisting>
|
|
|
|
<para>
|
2003-01-09 14:15:37 +00:00
|
|
|
A convenient shortcut for the above code is done with the gst_element_link_pads ()
|
2002-03-31 15:28:51 +00:00
|
|
|
function:
|
|
|
|
</para>
|
2001-01-06 02:35:17 +00:00
|
|
|
<programlisting>
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
// link them
|
|
|
|
gst_element_link_pads (element1, "src", element2, "sink");
|
2001-01-06 02:35:17 +00:00
|
|
|
....
|
2003-01-09 14:15:37 +00:00
|
|
|
// and unlink them
|
|
|
|
gst_element_unlink_pads (element1, "src", element2, "sink");
|
2002-04-07 23:32:16 +00:00
|
|
|
|
|
|
|
</programlisting>
|
|
|
|
<para>
|
|
|
|
An even more convenient shortcut for single-source, single-sink elements is the
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_element_link () function:
|
2002-04-07 23:32:16 +00:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
// link them
|
|
|
|
gst_element_link (element1, element2);
|
2002-04-07 23:32:16 +00:00
|
|
|
....
|
2003-01-09 14:15:37 +00:00
|
|
|
// and unlink them
|
|
|
|
gst_element_unlink (element1, element2);
|
2002-04-07 23:32:16 +00:00
|
|
|
|
|
|
|
</programlisting>
|
|
|
|
<para>
|
2003-01-09 14:15:37 +00:00
|
|
|
If you have more than one element to link, the gst_element_link_many () function takes
|
2002-04-07 23:32:16 +00:00
|
|
|
a NULL-terminated list of elements:
|
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
// link them
|
|
|
|
gst_element_link_many (element1, element2, element3, element4, NULL);
|
2002-04-07 23:32:16 +00:00
|
|
|
....
|
2003-01-09 14:15:37 +00:00
|
|
|
// and unlink them
|
|
|
|
gst_element_unlink_many (element1, element2, element3, element4, NULL);
|
2001-01-06 02:35:17 +00:00
|
|
|
|
2002-03-31 15:28:51 +00:00
|
|
|
</programlisting>
|
|
|
|
<para>
|
2003-01-09 14:15:37 +00:00
|
|
|
You can query if a pad is linked with GST_PAD_IS_CONNECTED (pad).
|
2002-03-31 15:28:51 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2003-01-09 14:15:37 +00:00
|
|
|
To query for the <classname>GstPad</classname> a pad is linked to, use
|
2002-09-14 14:13:34 +00:00
|
|
|
gst_pad_get_peer (pad).
|
2002-03-31 15:28:51 +00:00
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
|
|
|
<sect1 id="sec-conn-filtered">
|
2003-01-09 14:15:37 +00:00
|
|
|
<title>Making filtered links</title>
|
2002-03-31 15:28:51 +00:00
|
|
|
<para>
|
2003-01-09 14:15:37 +00:00
|
|
|
You can also force a specific media type on the link by using gst_pad_link_filtered ()
|
|
|
|
and gst_element_link_filtered (). FIXME link to caps documentation.
|
2002-03-31 15:28:51 +00:00
|
|
|
</para>
|
|
|
|
</sect1>
|
2001-01-06 02:35:17 +00:00
|
|
|
|
2000-08-16 21:38:57 +00:00
|
|
|
</chapter>
|