Sunday 30 January 2011

Analyse Xingmux Plugin

xingmux adds a Xing header to MP3 files. This contains information about the duration and size
of the file and a seek table and is very useful for getting an almost correct duration and better
seeking on VBR MP3 files.

This element will remove any existing Xing, LAME or VBRI headers from the beginning of the file.

Pad templates and the element details are registered with the plugin during the gst_xing_mux_base_init()

GStreamer uses a type system to ensure that the data passed between elements is in a recognized format

pad templates are registered during the gst_xing_mux_base_init () function. Pads are created from these
templates in the gst_xing_mux_init () function using gst_pad_new_from_template (). The
template can be retrieved from the element class using gst_element_class_get_pad_template()

method 1 and 2 are doing the same, but what's the difference?


1.
GstElementClass *klass = GST_ELEMENT_CLASS (xingmux_class);
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,"sink"), "sink");
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,"src"), "src");

2.
gst_pad_new_from_static_template (&gst_xing_mux_sink_template, "sink");
gst_pad_new_from_static_template (&gst_xing_mux_src_template, "src");

xingmux has a sinkpad and a srcpad, it supports mpeg version 1 audio, layer 1 to 3,
any channel at any samplerate


85 static GstStaticPadTemplate gst_xing_mux_sink_template =                                                                  
86 GST_STATIC_PAD_TEMPLATE ("sink",                                                                                          
87     GST_PAD_SINK,                                                                                                         
88     GST_PAD_ALWAYS,                                                                                                       
89     GST_STATIC_CAPS ("audio/mpeg, "                                                                                       
90         "mpegversion = (int) 1, " "layer = (int) [ 1, 3 ]")); 

initialise the class only once during the gst_xing_mux_class_init()
(specifying what signals, arguments and virtual functions the class has and setting up global state)

The primary and most important way of controlling how an element behaves, is through GObject
properties. GObject properties are defined in the _class_init () function.

gst_xing_mux_init()


  • initialize the new element
  • instantiate pads and add them to element
  • set pad calback functions
  • initialize instance structure

    gst_pad_set_setcaps_function()is called during caps negotiation,
    This is the process where the linked pads decide on the streamtype that will transfer

    Caps negotiation is the process where elements configure themselves and each other for streaming a
    particular media format over their pads.

    between them, here using
    gst_pad_set_setcaps_function (xing->sinkpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_setcaps));

    If at all possible, your element should derive from one of the new base classes (Pre-made base classes).
    If you use a base class, you will rarely have to handle state changes yourself. All you have to do is
    override the base class’s start() and stop() virtual functions (might be called differently depending on the
    base class) and the base class will take care of everything for you.

    Do not g_assert for unhandled state changes; this is taken care of by the GstElement base class.

Test Pipeline:gst-launch-0.10 filesrc location=test.mp3 ! xingmux ! filesink location=test2.mp3

additional: function plugin_init() register the element when the plugin is loaded, is in the source file plugin.c under the same folder gst-plugins-ugly/gst/mpegaudioparse

No comments:

Post a Comment