For programmers, one of the most important concepts in GStreamer is the Gstelement object. This object is the base block for building a media pipeline. All upper layer (high-level) parts originate from the Gstelement object. Any decoder encoder, splitter, video/audio output part is actually a Gstelement object.
For programmers, element is like a black box. You enter data at one end of the element, element processes the data, and the data is output from the other end of the element. To take a decoding element, you enter some data that has a specific encoding, and the element outputs the corresponding decoded data.
Source elements: Generates data for pipelines, such as reading data from a disk or a sound card. The source component does not receive data and produces only data.
Like Filter elements: with both input and output pads, they manipulate the data obtained from the input pads and then supply the data to the output pads. such as filters (filters), converters (convertors), shunts (demuxers), Rectifiers (muxers)
RECV elements: The receive element is the end of the media pipeline that receives data but does not produce any data. Writing disks, playing sound with sound, and video output are all implemented by the receiving element.
Create a Gstelement object: The simplest way to create an element is through the function gst_element_factory_make (), and you need to use Gst_object_unref () to dereference it when you no longer need a component.
The following example shows the creation of a component named source through a Fakesrc factory object. The program checks to see if the component was created successfully. After the check is complete, the program destroys the component.
#include <gst/gst.h>
int main (int argc,
Char *argv[])
{
Gstelement *element;
/* Init GStreamer */
Gst_init (&ARGC, &ARGV);
/* Create element */
element = Gst_element_factory_make ("fakesrc", "source");
if (!element) {
G_print ("Failed to create element of type ' fakesrc ' \ n");
return-1;
}
printf ("Successful to make element...\n");
Gst_object_unref (Gst_object (Element));
printf ("Destory the element...\n");
return 0;
}
Gst_element_factory_make is actually a combination of the Gst_element_factory_find () and the Gst_element_factory_create () two functions.
Gst_element_factory_find (): Get a unique factory object Gstelementfactory object
Gst_element_factory_create (): Uses the element factory and creates an element object based on the given name.
#include <gst/gst.h>
int main (int argc,
Char *argv[])
{
Gstelementfactory *factory;
Gstelement * ELEMENT;
/* Init GStreamer */
Gst_init (&ARGC, &ARGV);
/* Create element, method #2 */
Factory = Gst_element_factory_find ("fakesrc");
if (!factory) {
G_print ("Failed to find factory of type ' fakesrc ' \ n");
return-1;
}
element = Gst_element_factory_create (factory, "source");
if (!element) {
G_print ("Failed to create element, even though its factory exists!\n");
return-1;
}
Gst_object_unref (Gst_object (Element));
return 0;
}
Most of the properties of Gstelement are implemented by standard GObject objects. The GObject method can be used to query, set, and get the value of the Gstelement property. The same gparamspecs is also supported.
Each gstelement inherits at least one "name" attribute from its base class Gstobject. The name attribute will be used in the function gst_element_factory_make () or function gst_element_factory_create ().
You can set this property through the function Gst_object_set_name and get the name attribute of an object by Gst_object_get_name. You can also use the following method to get the name attribute of an object.
#include <gst/gst.h>
int main (int argc, char *argv[])
{
Gstelement *element;
Gchar *name;
/* Init GStreamer */
Gst_init (&ARGC, &ARGV);
/* Create element */
element = Gst_element_factory_make ("fakesrc", "source");
/* Get name */
G_object_get (G_object (Element), "name", &name, NULL);
G_print ("The name of the element is '%s '. \ n", name);
G_free (name);
Gst_object_unref (Gst_object (Element));
return 0;
}
OpenWrt GStreamer Example Learning Note (two. Element of GStreamer)