Android: How to integrate a decoder to multimedia framework

In Android SF framework, the codecs are registered through media_codecs.xml. In standard android distribution, an example media_codecs.xml can be found here. All audio-visual components are registered as OMX components.

1. Codec Registration

To register your video decoder, you would have to add a new entry under <Decoders> list. To ensure that your codec is always picked up, please ensure that your codec is listed as the first entry for the specific MIME type. An example entry for a H.264 decoder could be as below.

    <MediaCodec name="OMX.ABC.XYZ.H264.DECODER" type="video/avc" >
        <Quirk name="requires-allocate-on-input-ports" />
        <Quirk name="requires-allocate-on-output-ports" />
    <MediaCodec name="" type="video/avc" />


a.OMX.ABC.XYZ.H264.Decoder is the name of your component

b. video/avc is the MIME type of your component. In this example, it denotes a AVC / H.264 video decoder.

c.The next 2 statements denote the quirks or special requirements of your components. In the given example, requires-allocate-on-input-ports indicates to the Stagefright framework that the component prefers to allocate the buffers on all it’s input ports. Similarly, the other quirk is informing that the component will also prefer to allocate on it’s output ports. For a list of supported quirks in the system, you could refer to the function OMXCodec::getComponentQuirks in OMXCodec.cpp file. These quirks translate into flags which are then read by the framework to create and initialize the components.

In the example illustration, it is shown that your OMX component is registered prior to the default Google implemented video decoder.

NOTE: If you trying this on an end device, you will have to ensure that this entry is reflected in the final media_codecs.xml file.

2. OMX Core Registration

To create your component and ensure that the correct factory method is invoked, you may have to register your OMX Core with the Stagefright framework.

To register a new core, you will have to create a new library named which will be located at /system/lib in your end system. This library will have to expose a createOMXPlugin symbol which will be looked by dlsym.

The registration of the OMX core is thus: OMXMaster invokes addVendorPlugin which internally invokes addPlugin(""). In addPlugin, the createOMXPlugin will be looked up using which the other function pointers for makeComponentInstance, destroyComponentInstance etc are initialized.

Once the OMX core is initialized, you are ready to run your own your component within the android framework. The reference for OMXMaster can be found here.

With these changes, your video decoder is integrated into the android stagefright framework.

Leave a Comment