Control flow of the OMX codec component under Android4.2.2 stagefright

Source: Internet
Author: User

This article is the source of their own reading a bit summary, transfer Please specify the source thank you.

Welcome to communicate with you. qq:1037701636 Email:[email protected]

Android source version version:4.2.2; Hardware platform Full Chi A31

The reason why this piece of content is extracted separately is that it has a certain level, the structure is unified, the API function design needs to implement the interface unique to OMX architecture.

1. In the A31 OMX plugin and codec component of the Stagefright multimedia architecture in the previous post Android4.2.2, we mentioned that, with the binder architecture, after creating an actual codec node on the MPS thread, we get a node: node_id. As shown below, a OMXCODEC structure on the MPs side is created as a local codec, based on the associated node information.

.....            Sp<omxcodec> codec = new Omxcodec (                    OMX, node, quirks, flags,                    Createencoder, mime, componentname,                    source, NativeWindow);//Create a local Omxcodec decoder, node becomes the key for subsequent operations IOMX::NODE_ID//OMX the master            Observer->setcodec ( codec);//The decoder is given to observer            err = CODEC->CONFIGURECODEC (meta);//The local decoder is configured according to the data source ...

In the CONFIGURECODEC configuration of this decoder, we can see some control operations on the previously allocated decoder nodes. Let's take one of its function calls as an example to perform a layer-by-layer analysis of the control flow:

Setvideooutputformat (mmime, meta);//Set Video output format
Momx->getparameter (Mnode, omx_indexparamportdefinition, &def, sizeof (DEF))

Here we see that MOMX is an anonymous Bpomx object that was obtained when Awesomeplayer was created. The final implementation of the OMX object in Mediaplayerservice is to implement GetParameter.

Operation under the 2.OMX object.

status_t omx::getparameter (        node_id node, omx_indextype index,        void *params, size_t size) {    return Findinstance (node)->getparameter (            index, params, size);}

Findinstance (node) is here to obtain an instance of a Omxnodeinstance object that was previously registered, based on this node_id:

Omxnodeinstance *omx::findinstance (node_id node) {    Mutex::autolock autolock (mLock);    ssize_t index = mnodeidtoinstance.indexofkey (node);    Return Index < 0? NULL:mNodeIDToInstance.valueAt (index);}

Finally, it becomes the following call:

status_t omxnodeinstance::setparameter (        omx_indextype index, const void *params, size_t size) {    Mutex:: Autolock Autolock (mLock);    Omx_errortype err = Omx_setparameter (            mhandle, index, const_cast<void *> (params));    return Statusfromomxerror (ERR);}

The realization of 3.OMX_XXX

#define Omx_getparameter (                                           hcomponent,                                                 nparamindex,                                                componentparameterstructure)                            ((omx_ componenttype*) hcomponent)->getparameter (                 hcomponent,                                                 nparamindex,                                                componentparameterstructure) /    * Macro End */

Omx_setparameter, such as macro function is the core of Omx_core, but also the original openomx in the OMX il layer embodiment. To see the type of Mhandle, as a member variable of a Omxnodeinstance object, he maintains a handle to the underlying codec component library that was returned by Makecomponentinstance. This looks like a OMX node instance, a handle that operates on the lowest-level decoding component. You can see that the handle is converted to Omx_componenttype type. To see its structure type:

typedef struct omx_componenttype{    omx_u32 nSize;    Omx_versiontype nversion;    Omx_componentnametype Ecompname;    Omx_ptr pcomponentprivate;    Omx_errortype (*getparameter) (            omx_in  omx_handletype hcomponent,             omx_in  omx_indextype NIndex,            omx_in  Omx_ptr componentparameterstructure), .........

This handle is obtained when the decoder node was created before, through the name of the decoder that needs to be created, through the OMX plugin library, and then into the libomxcore.so (OMX IL intrinsic structure) call Omx_ GetHandle to get the corresponding component name under the Platform decoding Library libomxvdec.so, or libomxvenc.so, and so on. This handle is initialized with the following completion:

void* Aw_omx_create_component_wrapper (omx_ptr obj_ptr) {aw_omx_component *pthis = (aw_omx_component *) obj_ptr;// Omx_vdec Object omx_componenttype* component = & (PTHIS-&GT;M_CMP);//Initialize m_cmp memset (&pthis->m_cmp,0,sizeo    F (omx_componenttype));    component->nsize = sizeof (Omx_componenttype);    Component->nversion.nversion = omx_spec_version;    component->papplicationprivate = 0; Component->pcomponentprivate = obj_ptr;//holds omx_vdec This object component->allocatebuffer = &aw_omx_component    _allocate_buffer;    Component->freebuffer = &aw_omx_component_free_buffer;    Component->getparameter = &aw_omx_component_get_parameter;    Component->setparameter = &aw_omx_component_set_parameter;    Component->sendcommand = &aw_omx_component_send_command;    Component->fillthisbuffer = &aw_omx_component_fill_this_buffer; Component->emptythisbuffer = &aW_omx_component_empty_this_buffer;    Component->getstate = &aw_omx_component_get_state;    Component->getcomponentversion = &aw_omx_component_get_version;    Component->getconfig = &aw_omx_component_get_config;    Component->setconfig = &aw_omx_component_set_config;    Component->getextensionindex = &aw_omx_component_get_extension_index;    Component->componenttunnelrequest = &aw_omx_component_tunnel_request;    Component->usebuffer = &aw_omx_component_use_buffer;    Component->setcallbacks = &aw_omx_component_set_callbacks;    Component->useeglimage = &aw_omx_component_use_EGL_image;    Component->componentroleenum = &aw_omx_component_role_enum;    Component->componentdeinit = &aw_omx_component_deinit; return (void *) component;

With the above assignment, we focus on this component->pcomponentprivate = Obj_ptr, which maintains the decoder instance of the hardware platform into the handle structure, because the final operation must be back to the bottom of the decoder control. This is what OMX il architecture gives developers the convenience and planning. With this we can conclude that the following files are needed to connect to the lower-level codecs:

Xxx_omx_core.c and omx_core_cmp.c Two source files to complete. The former provides an upward interface for creating a codec instance, which provides for example the implementation of the Xxx_omx_component_api interface described above, while the actual implementation is called a codec-related API to handle:

Omx_errortype aw_omx_component_get_parameter (omx_in omx_handletype     hcomp,                                             omx_in omx_indextype ParamIndex,                                             omx_inout omx_ptr     paramdata) {omx_errortype Eret = omx_errorbadparameter;aw_omx_component *pThis = (hComp)? (Aw_omx_component *) (((Omx_componenttype *) hcomp)->pcomponentprivate): Null;debug_print ("Omxcore:aw_omx_component_get_parameter%x ,%x,%d\n ", (unsigned) Hcomp, (unsigned) paramdata,paramindex); if (pThis) {Eret = Pthis->get_parameter (Hcomp, Paramindex,paramdata);} return Eret;}

Here the Pthis technology is currently the bottom of the control entry for the decoder component. That is, the so-called Aw_omx_component derived class object. That is to say that our own to build the codec needs real aw_omx_component of the relevant interface functions, you can see here our most basic decoder component is the implementation of these functions, speed up the customization of a new component type, the following are the definition and implementation of several interfaces:

Omx_errortype  omx_vdec::set_parameter (omx_in omx_handletype hcomp, omx_in omx_indextype paramIndex,  OMX_IN Omx_ptr paramdata)
Omx_errortype  omx_vdec::get_parameter (omx_in omx_handletype hcomp,                                       omx_in omx_indextype  ParamIndex,                                       omx_inout omx_ptr     paramdata)

Here we go. From Omxcodec to the lowest-level codec component control, hierarchical, interface specification brings us the rapid development, we need to do the core is to implement the relevant business in its own codec components, and this and its own hardware platform is close.

4. Summarize what you need to do to create a new codec component belonging to the Stagefright OMX

The core work we have to do is the design of the two library files, libomxcore.so and libomxvdec.so. But they all need to comply with OMX's protocol.


Analyzed so many control flow, also already has the so-called Omxcodec, then the following main content will be the data flow processing.






Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.