2004-01-28 15:08:17 +00:00
|
|
|
<chapter id="chapter-autoplug">
|
2001-05-02 23:46:27 +00:00
|
|
|
<title>Autoplugging</title>
|
|
|
|
<para>
|
|
|
|
<application>GStreamer</application> provides an API to automatically
|
2002-04-07 23:32:16 +00:00
|
|
|
construct complex pipelines based on source and destination capabilities.
|
|
|
|
This feature is very useful if you want to convert type X to type Y but
|
2001-05-02 23:46:27 +00:00
|
|
|
don't care about the plugins needed to accomplish this task. The
|
2003-01-24 18:08:39 +00:00
|
|
|
autoplugger will consult the plugin repository, select and link the
|
2001-05-02 23:46:27 +00:00
|
|
|
elements needed for the conversion.
|
|
|
|
</para>
|
|
|
|
<para>
|
2002-09-08 21:17:16 +00:00
|
|
|
The autoplugger API is implemented in an abstract class. Autoplugger
|
|
|
|
implementations reside in plugins and are therefore optional and can be
|
|
|
|
optimized for a specific task. Two types of autopluggers exist: renderer
|
2002-09-14 14:13:34 +00:00
|
|
|
ones and non-renderer ones. The renderer autopluggers will not have any
|
|
|
|
source pads while the non-renderer ones do. The renderer autopluggers are
|
2002-09-08 21:17:16 +00:00
|
|
|
mainly used for media playback while the non renderer ones are used for
|
|
|
|
arbitrary format conversion.
|
2001-05-02 23:46:27 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect1>
|
|
|
|
<title>Using autoplugging</title>
|
|
|
|
<para>
|
2002-04-11 20:35:18 +00:00
|
|
|
You first need to create a suitable autoplugger with gst_autoplug_factory_make().
|
2001-05-02 23:46:27 +00:00
|
|
|
The name of the autoplugger must be one of the registered autopluggers..
|
|
|
|
</para>
|
|
|
|
<para>
|
2002-04-11 20:35:18 +00:00
|
|
|
A list of all available autopluggers can be obtained with gst_autoplug_factory_get_list().
|
2001-05-02 23:46:27 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-09-14 14:13:34 +00:00
|
|
|
If the autoplugger supports the RENDERER API, use the
|
2003-01-24 18:08:39 +00:00
|
|
|
gst_autoplug_to_renderers() function to create a bin that links
|
2002-09-14 14:13:34 +00:00
|
|
|
the source caps to the specified render elements. You can then add
|
|
|
|
the bin to a pipeline and run it.
|
2001-05-02 23:46:27 +00:00
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
|
|
GstAutoplug *autoplug;
|
|
|
|
GstElement *element;
|
|
|
|
GstElement *sink;
|
|
|
|
|
|
|
|
/* create a static autoplugger */
|
2002-04-11 20:35:18 +00:00
|
|
|
autoplug = gst_autoplug_factory_make ("staticrender");
|
2001-05-02 23:46:27 +00:00
|
|
|
|
|
|
|
/* create an osssink */
|
2002-04-11 20:35:18 +00:00
|
|
|
sink = gst_element_factory_make ("osssink", "our_sink");
|
2001-05-02 23:46:27 +00:00
|
|
|
|
|
|
|
/* create an element that can play audio/mp3 through osssink */
|
|
|
|
element = gst_autoplug_to_renderers (autoplug,
|
|
|
|
gst_caps_new (
|
|
|
|
"sink_audio_caps",
|
|
|
|
"audio/mp3",
|
|
|
|
NULL
|
|
|
|
),
|
|
|
|
sink,
|
|
|
|
NULL);
|
|
|
|
|
2003-01-24 18:08:39 +00:00
|
|
|
/* add the element to a bin and link the sink pad */
|
2001-05-02 23:46:27 +00:00
|
|
|
...
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
<para>
|
2002-09-08 21:17:16 +00:00
|
|
|
If the autoplugger supports the CAPS API, use the gst_autoplug_to_caps()
|
2003-01-24 18:08:39 +00:00
|
|
|
function to link the source caps to the destination caps. The created
|
2002-09-14 14:13:34 +00:00
|
|
|
bin will have source and sink pads compatible with the provided caps.
|
2001-05-02 23:46:27 +00:00
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
|
|
|
|
GstAutoplug *autoplug;
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
/* create a static autoplugger */
|
2002-04-11 20:35:18 +00:00
|
|
|
autoplug = gst_autoplug_factory_make ("static");
|
2001-05-02 23:46:27 +00:00
|
|
|
|
|
|
|
/* create an element that converts audio/mp3 to audio/raw */
|
|
|
|
element = gst_autoplug_to_caps (autoplug,
|
|
|
|
gst_caps_new (
|
|
|
|
"sink_audio_caps",
|
|
|
|
"audio/mp3",
|
|
|
|
NULL
|
|
|
|
),
|
|
|
|
gst_caps_new (
|
|
|
|
"src_audio_caps",
|
|
|
|
"audio/raw",
|
|
|
|
NULL
|
|
|
|
),
|
|
|
|
NULL);
|
|
|
|
|
2003-01-24 18:08:39 +00:00
|
|
|
/* add the element to a bin and link the src/sink pads */
|
2001-05-02 23:46:27 +00:00
|
|
|
...
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</sect1>
|
2004-01-28 15:08:17 +00:00
|
|
|
<sect1 id="section-autoplug-cache">
|
2001-07-07 14:17:22 +00:00
|
|
|
<title>Using the <classname>GstAutoplugCache</classname> element</title>
|
2001-05-02 23:46:27 +00:00
|
|
|
<para>
|
2001-07-07 14:17:22 +00:00
|
|
|
The <classname>GstAutoplugCache</classname> element is used to cache the
|
2003-10-09 12:42:49 +00:00
|
|
|
media stream when performing typedetection. As we have seen in
|
2004-01-28 15:08:17 +00:00
|
|
|
<xref linkend="chapter-typedetection"/>, the typefind function consumes a
|
2003-10-09 12:42:49 +00:00
|
|
|
buffer to determine its media type. After we have set up the pipeline
|
2001-07-07 14:17:22 +00:00
|
|
|
to play the media stream we should be able to 'replay' the previous buffer(s).
|
2003-10-09 12:42:49 +00:00
|
|
|
This is what the autoplugcache is used for.
|
2001-07-07 14:17:22 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The basic usage pattern for the autoplugcache in combination with the typefind
|
|
|
|
element is like this:
|
|
|
|
<orderedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-01-24 18:08:39 +00:00
|
|
|
Add the autoplugcache element to a bin and link the sink pad
|
2002-09-14 14:13:34 +00:00
|
|
|
to the source pad of an element with unknown caps.
|
2001-07-07 14:17:22 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-01-24 18:08:39 +00:00
|
|
|
Link the source pad of the autoplugcache to the sink pad of
|
2002-09-14 14:13:34 +00:00
|
|
|
the typefind element.
|
2001-07-07 14:17:22 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-09-14 14:13:34 +00:00
|
|
|
Iterate the pipeline until the typefind element has found a type.
|
2001-07-07 14:17:22 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-09-08 21:17:16 +00:00
|
|
|
Remove the typefind element and add the plugins needed to play
|
2002-09-14 14:13:34 +00:00
|
|
|
back the discovered media type to the autoplugcache source pad.
|
2001-07-07 14:17:22 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Reset the cache to start playback of the cached data. Connect to the
|
|
|
|
"cache_empty" signal.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
In the cache_empty signal callback function, remove the autoplugcache and
|
2003-01-24 18:08:39 +00:00
|
|
|
relink the pads.
|
2001-07-07 14:17:22 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</orderedlist>
|
|
|
|
</para>
|
|
|
|
<para>
|
2002-04-07 23:32:16 +00:00
|
|
|
In the next chapter we will create a new version of our helloworld example using the
|
2001-07-07 14:17:22 +00:00
|
|
|
autoplugger, the autoplugcache and the typefind element.
|
2001-05-02 23:46:27 +00:00
|
|
|
</para>
|
|
|
|
</sect1>
|
2004-01-28 15:08:17 +00:00
|
|
|
<sect1 id="section-autoplugging-spider">
|
2002-04-07 23:32:16 +00:00
|
|
|
<title>Another approach to autoplugging</title>
|
|
|
|
<para>
|
2002-09-08 21:17:16 +00:00
|
|
|
The autoplug API is interesting, but often impractical. It is static;
|
2003-10-09 12:42:49 +00:00
|
|
|
it cannot deal with dynamic pipelines. An element that will
|
|
|
|
automatically figure out and decode the type is more useful.
|
|
|
|
Enter the spider.
|
2002-04-07 23:32:16 +00:00
|
|
|
</para>
|
|
|
|
<sect2>
|
|
|
|
<title>The spider element</title>
|
|
|
|
<para>
|
|
|
|
The spider element is a generalized autoplugging element. At this point (April 2002), it's
|
|
|
|
the best we've got; it can be inserted anywhere within a pipeline to perform caps
|
|
|
|
conversion, if possible. Consider the following gst-launch line:
|
|
|
|
<programlisting>
|
|
|
|
$ gst-launch filesrc location=my.mp3 ! spider ! osssink
|
|
|
|
</programlisting>
|
|
|
|
The spider will detect the type of the stream, autoplug it to the osssink's caps, and play
|
|
|
|
the pipeline. It's neat.
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
<sect2>
|
|
|
|
<title>Spider features</title>
|
|
|
|
<para>
|
|
|
|
<orderedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Automatically typefinds the incoming stream.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2002-09-14 14:13:34 +00:00
|
|
|
Has request pads on the source side. This means that it can
|
|
|
|
autoplug one source stream into many sink streams. For example,
|
|
|
|
an MPEG1 system stream can have audio as well as video; that
|
|
|
|
pipeline would be represented in gst-launch syntax as
|
2002-09-08 21:17:16 +00:00
|
|
|
|
2002-04-07 23:32:16 +00:00
|
|
|
<programlisting>
|
|
|
|
$ gst-launch filesrc location=my.mpeg1 ! spider ! { queue ! osssink } spider.src_%d!
|
|
|
|
{ queue ! xvideosink }
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</orderedlist>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
</sect1>
|
2001-05-02 23:46:27 +00:00
|
|
|
</chapter>
|