2000-08-16 21:38:57 +00:00
|
|
|
<chapter id="cha-elements">
|
|
|
|
<title>GstElement</title>
|
|
|
|
<para>
|
2001-05-02 23:46:27 +00:00
|
|
|
The most important object in <application>GStreamer</application> for the
|
|
|
|
application programmer is the <classname>GstElement</classname> object.
|
2000-08-16 21:38:57 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect1 id="sec-elements-design">
|
|
|
|
<title>What is a GstElement</title>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
<classname>GstElement</classname> is the basic building block for the
|
|
|
|
media pipeline. All the different components you are going to use are
|
|
|
|
derived from <classname>GstElement</classname>. This means that a
|
|
|
|
lot of functions you are going to use operate on objects of this class.
|
2000-08-16 21:38:57 +00:00
|
|
|
</para>
|
2002-09-06 15:53:06 +00:00
|
|
|
<para>
|
|
|
|
Elements, from the perspective of GStreamer, are viewed as "black boxes"
|
|
|
|
with a number of different aspects. One of these aspects is the presence
|
|
|
|
of "pads", or connection points. This terminology arises from soldering;
|
|
|
|
pads are where wires can be attached.
|
2000-08-16 21:38:57 +00:00
|
|
|
</para>
|
2001-01-04 23:35:50 +00:00
|
|
|
|
2000-08-16 21:38:57 +00:00
|
|
|
<sect2 id="sec-elements-src">
|
2002-04-07 23:32:16 +00:00
|
|
|
<title>Source elements</title>
|
2000-08-16 21:38:57 +00:00
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
Source elements generate data for use by a pipeline, for example
|
|
|
|
reading from disk or from a sound card.
|
2000-08-16 21:38:57 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2001-01-04 23:35:50 +00:00
|
|
|
Below you see how we will visualize the element.
|
2000-08-16 21:38:57 +00:00
|
|
|
We always draw a src pad to the right of the element.
|
|
|
|
</para>
|
|
|
|
<figure float="1" id="sec-element-srcimg">
|
2001-01-04 23:35:50 +00:00
|
|
|
<title>Visualisation of a source element</title>
|
2001-12-13 15:24:00 +00:00
|
|
|
<mediaobject>
|
|
|
|
<imageobject>
|
2001-12-15 23:13:04 +00:00
|
|
|
<imagedata fileref="images/src-element.&magic;" format="&magic;" />
|
2001-12-13 15:24:00 +00:00
|
|
|
</imageobject>
|
|
|
|
</mediaobject>
|
2000-08-16 21:38:57 +00:00
|
|
|
</figure>
|
|
|
|
<para>
|
2002-09-08 21:17:16 +00:00
|
|
|
Source elements do not accept data, they only generate data. You can
|
|
|
|
see this in the figure because it only has a src pad. A src pad can
|
|
|
|
only generate data.
|
2000-08-16 21:38:57 +00:00
|
|
|
</para>
|
|
|
|
</sect2>
|
2001-01-04 23:35:50 +00:00
|
|
|
|
2000-08-16 21:38:57 +00:00
|
|
|
<sect2 id="sec-elements-filter">
|
2002-04-07 23:32:16 +00:00
|
|
|
<title>Filters and codecs</title>
|
2000-08-16 21:38:57 +00:00
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
Filter elements both have input and output pads. They operate on
|
|
|
|
data they receive in their sink pads and produce data on their src
|
|
|
|
pads. For example, MPEG decoders and volume filters would fall into
|
|
|
|
this category.
|
2002-04-07 23:32:16 +00:00
|
|
|
</para>
|
2000-08-16 21:38:57 +00:00
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
Elements are not constrained as to the number of pads they might have;
|
|
|
|
for example, a video mixer might have two input pads (the images of
|
|
|
|
the two different video streams) and one output pad.
|
2002-04-07 23:32:16 +00:00
|
|
|
</para>
|
2000-08-16 21:38:57 +00:00
|
|
|
<figure float="1" id="sec-element-filterimg">
|
2001-01-04 23:35:50 +00:00
|
|
|
<title>Visualisation of a filter element</title>
|
2001-12-13 15:24:00 +00:00
|
|
|
<mediaobject>
|
|
|
|
<imageobject>
|
2001-12-15 23:13:04 +00:00
|
|
|
<imagedata fileref="images/filter-element.&magic;" format="&magic;" />
|
2001-12-13 15:24:00 +00:00
|
|
|
</imageobject>
|
|
|
|
</mediaobject>
|
2000-08-16 21:38:57 +00:00
|
|
|
</figure>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
The above figure shows the visualisation of a filter element.
|
|
|
|
This element has one sink (input) pad and one src (output) pad.
|
|
|
|
Sink pads are drawn on the left of the element.
|
2000-08-16 21:38:57 +00:00
|
|
|
</para>
|
|
|
|
<figure float="1" id="sec-element-multifilterimg">
|
2001-01-04 23:35:50 +00:00
|
|
|
<title>Visualisation of a filter element with
|
2000-08-16 21:38:57 +00:00
|
|
|
more than one output pad</title>
|
2001-12-13 15:24:00 +00:00
|
|
|
<mediaobject>
|
|
|
|
<imageobject>
|
2002-09-06 15:53:06 +00:00
|
|
|
<imagedata fileref="images/filter-element-multi.&magic;"
|
|
|
|
format="&magic;" />
|
2001-12-13 15:24:00 +00:00
|
|
|
</imageobject>
|
|
|
|
</mediaobject>
|
2000-08-16 21:38:57 +00:00
|
|
|
</figure>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
The above figure shows the visualisation of a filter element with
|
|
|
|
more than one output pad. An example of such a filter is the AVI
|
|
|
|
splitter (demultiplexer). This element will parse the input data and
|
|
|
|
extract the audio and video data. Most of these filters dynamically
|
|
|
|
send out a signal when a new pad is created so that the application
|
|
|
|
programmer can connect an arbitrary element to the newly created pad.
|
2002-04-07 23:32:16 +00:00
|
|
|
</para>
|
2000-08-16 21:38:57 +00:00
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2 id="sec-elements-sink">
|
2002-04-07 23:32:16 +00:00
|
|
|
<title>Sink elements</title>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
Sink elements are terminal points in a media pipeline. They accept
|
|
|
|
data but do not produce anything. Disk writing, soundcard playback,
|
|
|
|
and video output would all be implemented by sink elements.
|
2002-04-07 23:32:16 +00:00
|
|
|
</para>
|
2000-08-16 21:38:57 +00:00
|
|
|
<figure float="1" id="sec-element-sinkimg">
|
2001-01-04 23:35:50 +00:00
|
|
|
<title>Visualisation of a sink element</title>
|
2001-12-13 15:24:00 +00:00
|
|
|
<mediaobject>
|
|
|
|
<imageobject>
|
2001-12-15 23:13:04 +00:00
|
|
|
<imagedata fileref="images/sink-element.&magic;" format="&magic;" />
|
2001-12-13 15:24:00 +00:00
|
|
|
</imageobject>
|
|
|
|
</mediaobject>
|
2000-08-16 21:38:57 +00:00
|
|
|
</figure>
|
|
|
|
</sect2>
|
|
|
|
</sect1>
|
2001-01-06 02:35:17 +00:00
|
|
|
<sect1 id="sec-elements-create">
|
|
|
|
<title>Creating a GstElement</title>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
A <classname>GstElement</classname> object is created from
|
|
|
|
a factory. To create an element, you have to get access to a
|
|
|
|
<classname>GstElementFactory</classname> object using a unique
|
|
|
|
factory name.
|
2001-01-06 02:35:17 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
The following code example is used to get a factory that can be used
|
|
|
|
to create the 'mad' element, an mp3 decoder.
|
2001-01-06 02:35:17 +00:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
factory = gst_element_factory_find ("mad");
|
2001-01-06 02:35:17 +00:00
|
|
|
</programlisting>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
Once you have the handle to the element factory, you can create a
|
|
|
|
real element with the following code fragment:
|
2001-01-06 02:35:17 +00:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
GstElement *element;
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
element = gst_element_factory_create (factory, "decoder");
|
2001-01-06 02:35:17 +00:00
|
|
|
</programlisting>
|
2002-04-07 23:32:16 +00:00
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
<function>gst_element_factory_create</function> will use the element
|
|
|
|
factory to create an element with the given name. The name of the
|
|
|
|
element is something you can use later on to look up the element in
|
|
|
|
a bin, for example. You can pass <symbol>NULL</symbol> as the name
|
|
|
|
argument to get a unique, default name.
|
2002-04-07 23:32:16 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
A simple shortcut exists for creating an element from a factory. The
|
|
|
|
following example creates an element named "decoder" from the element
|
|
|
|
factory named "mad". This convenience function is most widely used to
|
|
|
|
create an element.
|
2002-04-07 23:32:16 +00:00
|
|
|
</para>
|
2001-01-06 02:35:17 +00:00
|
|
|
<programlisting>
|
|
|
|
GstElement *element;
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
element = gst_element_factory_make ("mad", "decoder");
|
2001-01-06 02:35:17 +00:00
|
|
|
</programlisting>
|
|
|
|
<para>
|
2002-07-24 19:46:42 +00:00
|
|
|
When you don't need the element anymore, you need to unref it, as shown in the following
|
|
|
|
example.
|
2001-01-06 02:35:17 +00:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
...
|
2002-07-24 19:46:42 +00:00
|
|
|
gst_element_unref (element);
|
2001-01-06 02:35:17 +00:00
|
|
|
</programlisting>
|
|
|
|
</sect1>
|
2002-07-24 19:46:42 +00:00
|
|
|
<sect1 id="sec-elements-properties">
|
|
|
|
<title>GstElement properties</title>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
A <classname>GstElement</classname> can have several properties
|
|
|
|
which are implemented using standard <classname>GObject</classname>
|
|
|
|
properties. The usual <classname>GObject</classname> methods to query,
|
|
|
|
set and get property values and <classname>GParamSpecs</classname>
|
|
|
|
are therefore supported.
|
2002-07-24 19:46:42 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
Every <classname>GstElement</classname> inherits at least
|
|
|
|
one property of its parent <classname>GstObject</classname>:
|
|
|
|
the "name" property. This is the name you provide to the
|
|
|
|
functions <function>gst_element_factory_make</function> or
|
|
|
|
<function>gst_element_factory_create</function>. You can get and set
|
|
|
|
this property using the functions
|
|
|
|
<function>gst_object_set_name</function>
|
|
|
|
and <function>gst_object_get_name</function> or use the
|
|
|
|
<classname>GObject</classname> property mechanism as shown below.
|
2002-07-24 19:46:42 +00:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
GstElement *element;
|
|
|
|
GValue value = { 0, }; /* initialize the GValue for g_object_get() */
|
|
|
|
|
|
|
|
element = gst_element_factory_make ("mad", "decoder");
|
|
|
|
g_object_set (G_OBJECT (element), "name", "mydecoder", NULL);
|
|
|
|
...
|
|
|
|
|
|
|
|
g_value_init (&value, G_TYPE_STRING);
|
|
|
|
g_object_get_property (G_OBJECT (element), "name", &value);
|
|
|
|
...
|
|
|
|
</programlisting>
|
|
|
|
<para>
|
|
|
|
Most plugins provide additional properties to provide more information
|
|
|
|
about their configuration or to configure the element.
|
|
|
|
<command>gst-inspect</command> is a useful tool to query the properties
|
2002-09-06 15:53:06 +00:00
|
|
|
of a particular element, it will also use property introspection to give
|
2002-07-24 19:46:42 +00:00
|
|
|
a short explanation about the function of the property and about the
|
|
|
|
parameter types and ranges it supports.
|
|
|
|
</para>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
For more information about <classname>GObject</classname>
|
|
|
|
properties we recommend you read the <ulink
|
|
|
|
url="http://developer.gnome.org/doc/API/2.0/gobject/index.html"
|
|
|
|
type="http">GObject manual</ulink>.
|
2002-07-24 19:46:42 +00:00
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
|
|
|
<sect1 id="sec-elements-signals">
|
|
|
|
<title>GstElement signals</title>
|
|
|
|
<para>
|
2002-09-06 15:53:06 +00:00
|
|
|
A <classname>GstElement</classname> also provides various
|
|
|
|
<classname>GObject</classname> signals that can be used as a flexible
|
2002-07-24 19:46:42 +00:00
|
|
|
callback mechanism.
|
|
|
|
</para>
|
|
|
|
</sect1>
|
|
|
|
|
|
|
|
<sect1 id="sec-elements-factories">
|
|
|
|
<title>More about GstElementFactory</title>
|
|
|
|
<para>
|
|
|
|
We talk some more about the GstElementFactory object.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect2 id="sec-elements-factories-details">
|
|
|
|
<title>Getting information about an element using the factory details</title>
|
|
|
|
<para>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2 id="sec-elements-factories-padtemplates">
|
|
|
|
<title>Finding out what pads an element can contain</title>
|
|
|
|
<para>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2 id="sec-elements-factories-query">
|
|
|
|
<title>Different ways of querying the factories</title>
|
|
|
|
<para>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
</sect1>
|
2000-08-16 21:38:57 +00:00
|
|
|
</chapter>
|