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);