1 <chapter id="cha-elements">
2 <title>GstElement</title>
4 The most important object in <application>GStreamer</application> for the
5 application programmer is the <classname>GstElement</classname> object.
8 <sect1 id="sec-elements-design">
9 <title>What is a GstElement</title>
11 <classname>GstElement</classname> is the basic building block for the
12 media pipeline. All the different components you are going to use are
13 derived from <classname>GstElement</classname>. This means that a
14 lot of functions you are going to use operate on objects of this class.
17 Elements, from the perspective of GStreamer, are viewed as "black boxes"
18 with a number of different aspects. One of these aspects is the presence
19 of "pads", or link points. This terminology arises from soldering;
20 pads are where wires can be attached.
23 <sect2 id="sec-elements-src">
24 <title>Source elements</title>
26 Source elements generate data for use by a pipeline, for example
27 reading from disk or from a sound card.
30 Below you see how we will visualize the element.
31 We always draw a source pad to the right of the element.
33 <figure float="1" id="sec-element-srcimg">
34 <title>Visualisation of a source element</title>
37 <imagedata fileref="images/src-element.&magic;" format="&MAGIC;" />
42 Source elements do not accept data, they only generate data. You can
43 see this in the figure because it only has a source pad. A source
44 pad can only generate data.
48 <sect2 id="sec-elements-filter">
49 <title>Filters and codecs</title>
51 Filter elements both have input and output pads. They operate on
52 data they receive in their sink pads and produce data on their source
53 pads. For example, MPEG decoders and volume filters would fall into
57 Elements are not constrained as to the number of pads they might have;
58 for example, a video mixer might have two input pads (the images of
59 the two different video streams) and one output pad.
61 <figure float="1" id="sec-element-filterimg">
62 <title>Visualisation of a filter element</title>
65 <imagedata fileref="images/filter-element.&magic;" format="&MAGIC;" />
70 The above figure shows the visualisation of a filter element.
71 This element has one sink (input) pad and one source (output) pad.
72 Sink pads are drawn on the left of the element.
74 <figure float="1" id="sec-element-multifilterimg">
75 <title>Visualisation of a filter element with
76 more than one output pad</title>
79 <imagedata fileref="images/filter-element-multi.&magic;"
85 The above figure shows the visualisation of a filter element with
86 more than one output pad. An example of such a filter is the AVI
87 splitter (demultiplexer). This element will parse the input data and
88 extract the audio and video data. Most of these filters dynamically
89 send out a signal when a new pad is created so that the application
90 programmer can link an arbitrary element to the newly created pad.
94 <sect2 id="sec-elements-sink">
95 <title>Sink elements</title>
97 Sink elements are terminal points in a media pipeline. They accept
98 data but do not produce anything. Disk writing, soundcard playback,
99 and video output would all be implemented by sink elements.
101 <figure float="1" id="sec-element-sinkimg">
102 <title>Visualisation of a sink element</title>
105 <imagedata fileref="images/sink-element.&magic;" format="&MAGIC;" />
111 <sect1 id="sec-elements-create">
112 <title>Creating a GstElement</title>
114 A <classname>GstElement</classname> object is created from
115 a factory. To create an element, you have to get access to a
116 <classname>GstElementFactory</classname> object using a unique
120 The following code example is used to get a factory that can be used
121 to create the 'mad' element, an mp3 decoder.
124 GstElementFactory *factory;
126 factory = gst_element_factory_find ("mad");
129 Once you have the handle to the element factory, you can create a
130 real element with the following code fragment:
135 element = gst_element_factory_create (factory, "decoder");
138 <function>gst_element_factory_create</function> will use the element
139 factory to create an element with the given name. The name of the
140 element is something you can use later on to look up the element in
141 a bin, for example. You can pass <symbol>NULL</symbol> as the name
142 argument to get a unique, default name.
145 A simple shortcut exists for creating an element from a factory. The
146 following example creates an element named "decoder" from the element
147 factory named "mad". This convenience function is most widely used to
153 element = gst_element_factory_make ("mad", "decoder");
156 When you don't need the element anymore, you need to unref it, as shown in the following
163 gst_element_unref (element);
166 <sect1 id="sec-elements-properties">
167 <title>GstElement properties</title>
169 A <classname>GstElement</classname> can have several properties
170 which are implemented using standard <classname>GObject</classname>
171 properties. The usual <classname>GObject</classname> methods to query,
172 set and get property values and <classname>GParamSpecs</classname>
173 are therefore supported.
176 Every <classname>GstElement</classname> inherits at least
177 one property of its parent <classname>GstObject</classname>:
178 the "name" property. This is the name you provide to the
179 functions <function>gst_element_factory_make</function> or
180 <function>gst_element_factory_create</function>. You can get and set
181 this property using the functions
182 <function>gst_object_set_name</function>
183 and <function>gst_object_get_name</function> or use the
184 <classname>GObject</classname> property mechanism as shown below.
188 GValue value = { 0, }; /* initialize the GValue for g_object_get() */
190 element = gst_element_factory_make ("mad", "decoder");
191 g_object_set (G_OBJECT (element), "name", "mydecoder", NULL);
194 g_value_init (&value, G_TYPE_STRING);
195 g_object_get_property (G_OBJECT (element), "name", &value);
199 Most plugins provide additional properties to provide more information
200 about their configuration or to configure the element.
201 <command>gst-inspect</command> is a useful tool to query the properties
202 of a particular element, it will also use property introspection to give
203 a short explanation about the function of the property and about the
204 parameter types and ranges it supports.
207 For more information about <classname>GObject</classname>
208 properties we recommend you read the <ulink
209 url="http://developer.gnome.org/doc/API/2.0/gobject/index.html"
210 type="http">GObject manual</ulink>.
214 <sect1 id="sec-elements-signals">
215 <title>GstElement signals</title>
217 A <classname>GstElement</classname> also provides various
218 <classname>GObject</classname> signals that can be used as a flexible
223 <sect1 id="sec-elements-factories">
224 <title>More about GstElementFactory</title>
226 We talk some more about the GstElementFactory object.
229 <sect2 id="sec-elements-factories-details">
230 <title>Getting information about an element using the factory details</title>
235 <sect2 id="sec-elements-factories-padtemplates">
236 <title>Finding out what pads an element can contain</title>
241 <sect2 id="sec-elements-factories-query">
242 <title>Different ways of querying the factories</title>