Elements
The most important object in GStreamer for the
application programmer is the GstElement object.
What is an element ?
An element is the basic building block for the media pipeline.
All the different high-level components you are going to use are
derived from GstElement. This means that a
lot of functions you are going to use operate on objects of this class.
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" (see ), or link points. This terminology arises from soldering;
pads are where wires can be attached.
Types of elementsSource elements
Source elements generate data for use by a pipeline, for example
reading from disk or from a sound card.
shows how we will visualise
a source element.
We always draw a source pad to the right of the element.
Source elements do not accept data, they only generate data. You can
see this in the figure because it only has a source pad. A source
pad can only generate data.
Filters and codecs
Filter elements have both input and output pads. They operate on
data they receive in their sink pads and produce data on their source
pads. For example, MPEG decoders and volume filters would fall into
this category.
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.
shows how we will visualise
a filter element.
This element has one sink (input) pad and one source (output) pad.
Sink pads are drawn on the left of the element.
shows the visualisation of a filter element with
more than one output pad. An example of such a filter is the AVI
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 link an arbitrary element to the newly created pad.
Sink elements
Sink elements are end 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.
shows a sink element.
Creating a GstElement
A GstElement object is created from
a factory. To create an element, you have to get access to a
GstElementFactory object using a unique
factory name.
The following code example is used to get a factory that can be used
to create the 'mad' element, an mp3 decoder.
GstElementFactory *factory;
factory = gst_element_factory_find ("mad");
Once you have the handle to the element factory, you can create a
real element with the following code fragment:
GstElement *element;
element = gst_element_factory_create (factory, "decoder");
gst_element_factory_create 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 NULL as the name
argument to get a unique, default name.
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.
GstElement *element;
element = gst_element_factory_make ("mad", "decoder");
When you don't need the element anymore, you need to unref it, as shown in the following
example.
GstElement *element;
...
gst_element_unref (element);
GstElement properties
A GstElement can have several properties
which are implemented using standard GObject
properties. The usual GObject methods to query,
set and get property values and GParamSpecs
are therefore supported.
Every GstElement inherits at least
one property of its parent GstObject:
the "name" property. This is the name you provide to the
functions gst_element_factory_make or
gst_element_factory_create. You can get and set
this property using the functions
gst_object_set_name
and gst_object_get_name or use the
GObject property mechanism as shown below.
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);
...
Most plugins provide additional properties to provide more information
about their configuration or to configure the element.
gst-inspect is a useful tool to query the properties
of a particular element, it will also use property introspection to give
a short explanation about the function of the property and about the
parameter types and ranges it supports.
For more information about GObject
properties we recommend you read the GObject manual and an introduction to
The Glib Object system.
GstElement signals
A GstElement also provides various
GObject signals that can be used as a flexible
callback mechanism.
More about GstElementFactory
We talk some more about the GstElementFactory object.
Getting information about an element using the factory detailsFinding out what pads an element can containDifferent ways of querying the factories