Simplify Linux multimedia development with GStreamer
Source: Internet
Author: User
Article Title: Use GStreamer to simplify Linux multimedia development. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
GStreamer is a programming framework used to build streaming media applications in the GNOME desktop environment. Its goal is to simplify the development of audio/video applications, currently, it can be used to process multimedia data in various formats such as MP3, Ogg, MPEG1, MPEG2, AVI, and Quicktime.
I. Basic Concepts
GStreamer, as the streaming media application framework recommended by GNOME desktop environment, adopts the architecture based on plug-ins and pipelines, all functional modules in the framework are implemented as pluggable components and can be conveniently installed on any pipeline as needed, since all plug-ins use the MPs queue mechanism for unified data exchange, it is easy to use existing plug-ins to "Assemble" a functional multimedia application.
1.1 component Processing
For programmers who need to apply the GStreamer framework, the ststelement is a concept that must be understood, because it is the basic component of the pipeline and the basis of all available components in the framework, it is no wonder that most of the functions in the GStreamer framework involve operations on the ststelement object. From GStreamer's point of view, the ststelement can be described as a black box with specific attributes. It interacts with the outside world through a link point, present your own features or functions to the rest of the framework.
GStreamer further subdivided the stststelement into the following categories based on their respective functional differences:
-The Source Element Data Source Element only has the output end. It can only be used to generate data for pipeline consumption, but cannot process the data. An example of a typical data source component is an audio capture unit, which reads the original audio data from the sound card and then serves as a data source for other modules.
-Filter Element: the Filter Element has both input and output ends. It obtains data from the input end and passes the data to the output end after special processing. An example of a typical filter element is an audio encoding unit. It first obtains audio data from the outside, and then encodes it according to a specific compression algorithm, finally, the encoded result is provided to other modules.
-The Sink Element receiver has only the input end. It can only consume data and is the terminal of the entire media pipeline. An example of a typical Receiver component is the audio playback unit, which writes the received data to the sound card. This is usually the last step in audio processing.
It will help you better understand the differences between data source components, Filter components and receiver components, and it is not difficult to see how they work together to form a pipeline:
It should be noted that the specific form of filter elements is very flexible, GStreamer does not strictly specify the number of input and output, in fact they can be one or more. Is the basic structure of an AVI separator. It can separate the input data into separate Audio Information and video information. The filter element used to implement this function obviously only has one input, however, two outputs are required.
The only way to create a GstElement object in an application is to use the factory object GstElementFactory. The GStreamer framework provides various types of ststelementfactory objects, which are differentiated by specific factory names. For example, the following code obtains a factory object named mad through the stst_element_factory_find () function, which can then be used to create the corresponding MP3 decoder component:
Maid factory * factory; factory = maid ("mad ");
After the factory object is obtained successfully, you can use the maid () function to create a specific ststelement object. The function has two parameters called, namely, the factory object to be used, and the name of the component to be created. The component name can be obtained through a query, or a NULL pointer can be passed in to generate the default component of the factory object. The following code demonstrates how to use the obtained factory object to create an MP3 decoder component named decoder:
Stststelement * element; element = maid (factory, "decoder ");
When the created GstElement is no longer used, you must call the gst_element_unref () function to release the memory resources it occupies:
Ststst_element_unref (element );
GStreamer uses the same mechanism as GObject to manage properties, including query, set, and get. All stststelement objects need to inherit the most basic attribute name (name) from their parent object, because it is like the stst_element_factory_make () and ststst_element_factory_create () such functions use the name attribute when creating factory objects and component objects. by calling the stst_object_set_name () and stst_object_get_name () functions, you can set and read the name attribute of the ststelement object.
1.2 liner handling
Pad is another basic concept introduced by the GStreamer framework. It refers to the connection channel between elements and the outside. For a specific component in the framework, the media type it can process is exposed to other components through the pad. After the ststelement object is created, you can use the stst_element_get_pad () method to obtain the specified pad of the component. For example, the following code returns the pad named src in the element:
Maid * srcpad; srcpad = maid (element, "src ");
If necessary, you can use the maid function to query all the pads in the specified component. For example, the following code outputs the names of all pads in the element:
GList * pads; pads = maid (element); while (pads) {maid * pad = maid (pads-> data); g_print ("pad name is: % sn ", ststst_pad_get_name (pad); pads = g_list_next (pads );}
Like the component, the name of the pad can be dynamically set or read. This is done by calling the functions ststst_pad_get_name () and ststst_pad_set_name. The pads of all components can be subdivided into two types: the input liner and the output liner. The input liner can only receive data but cannot generate data, while the output liner is the opposite, data can only be generated but cannot be received. The type of the specified liner can be obtained using the function stst_pad_get_direction. All the cushions in the GStreamer framework must be attached to a certain component. The component to which the specified liner belongs can be obtained by calling the maid () function. The return value of this function is a pointer to the ststelement. To some extent, the liner can be seen as the spokesperson of the component because it is responsible for describing the capabilities of the component to the outside world. The GStreamer framework provides a unified mechanism to allow the liner to describe the capabilities of the component, which is achieved through the data structure _ stststcaps:
Struct _ maid {gchar * name;/* the name of this caps */guint16 id;/* type id (major type) */guint refcount; /* caps are refcounted */ststprops * properties;/* properties for this capability */ststcaps * next;/* caps can be chained together */};
The following describes the capabilities of the mad component. It is not difficult to see that the component actually contains two pads, sink and src, and each pad carries specific function information. The sink pad is the input end of the mad component. It can accept media data of the MIME type audio/mp3, and has three attributes: layer, bitrate, and framed. A pad named src is the output end of the mad component. It is responsible for generating media data of the MIME type audio/raw. It also has multiple attributes such as format, depth, rate, and channels.
To be precise, each liner in the GStreamer framework may correspond to multiple capability descriptions, which can be obtained through the function stst_pad_get_caps. For example, the following code outputs the names and MIME types that can be described in the pad:
GstCaps * caps; caps = gst_pad_get_caps (pad); g_print ("pad name is: % sn", gst_pad_get_name (pad); while (caps) {g_print ("Capability name is % s, MIME type is % sn", stst_caps_get_name (cap), ststst_caps_get_mime (cap); caps = caps-> next ;}
1.3 Cabinet
The bin is a container component in the GStreamer framework. It is usually used to hold other component objects, but because it is also a ststelement object, therefore, it can also be used to accommodate other cabinet objects. The cabinet can be used to combine multiple components to be processed into one logical component. As you do not need to operate the components in the cabinet one by one, therefore, it is easy to use it to construct more complex pipelines. Another advantage of using the cabinet in the GStreamer framework is that it will try to optimize the data stream, which is very attractive for multimedia applications.
The typical structure of the Cabinet in the GStreamer framework is described:
There are two main types of cabinets used in GStreamer applications:
-The GstPipeline pipe is the most commonly used container. For a GStreamer application, the top-level Cabinet must be a pipe.
-The role of the ststthread thread is to provide synchronization processing capabilities. This type of cabinet is generally used if the GStreamer application requires strict audio/video synchronization.
The GStreamer framework provides two methods to create a cabinet: A factory method and a specific function. Lower
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service