openmax component类的继承关系

向OpenCORE里继承一个新的codec时,需要用到OpenMAX接口规范对该codec进行封装,即要定义一个用于封装的类(wrapper),实现OpenMAX规定的集中核心方法(omx core methods)。若该codec是一个音频解码器,则该类继承OmxComponentAudio类;若是视频解码器,则继承OmxComponentVideo类。而OmxComponentAudio和OmxComponentVideo类都是继承了OmxComponentBase类;OmxComponentBase类又继承自OsclActiveObject类。

为了深入点理解每OMX Component每个接口(core methods)具体要实现些什么功能,我们逐一深入这些相关的类的定义中。

【1】OsclActiveObject类

该类的定义在.../opencore/oscl/oscl/osclproc/src/oscl_scheduler_ao.h文件中。看给类的注释:

/**

 * User base class for execution objects.

 * OsclActiveObject defines an execution object without any timer.

 * This AO can be used across threads, i.e. the request

 * can be activated in one thread and completed in another.

 */

即该类是用于执行(或运行)对象的用户基础类,该运行对象没有计时器。 这个正在运行的对象(AO)可以在多个线程间被使用,如在一个线程中的请求可以在另一个线程中完成。

OsclActiveObject类又继承自两个类:HeapBase和PVActiveBase类,其中类HeapBase是用于基础的堆操作,如分配、释放内存等。类PVActiveBase主要是跟线程相关的(PV Scheduler internal AO base class)。

OsclActiveObject类主要是定义了对象运行的相关操作,如优先级、对象状态等。

【2】OmxComponentBase类

其中一些接口涉及到proxy(代理??),不知道具体什么差别!!!

/** Component entry points declarations without proxy interface*/

……

/** Component entry points declarations with proxy interface*/

……

接着是最重要的部分,

        /*NON STATIC COUNTERPARTS OF STATIC MEMBER API'S */

        //Pure virtual functions, definition to be written in derived class

        /*

          纯虚函数,具体实现在派生的类中。

        */

        virtual OMX_ERRORTYPE GetParameter(

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nParamIndex,

            OMX_INOUT OMX_PTR ComponentParameterStructure) = 0;

        virtual OMX_ERRORTYPE SetParameter(

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nParamIndex,

            OMX_IN  OMX_PTR ComponentParameterStructure) = 0;

        virtual OSCL_IMPORT_REF OMX_ERRORTYPE GetConfig(

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nIndex,

            OMX_INOUT OMX_PTR pComponentConfigStructure);

        //Making Setconfig as virtual function to be implemented in respective component class

// 在各个派生的component中各自实现该函数

        virtual OSCL_IMPORT_REF OMX_ERRORTYPE SetConfig(

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nIndex,

            OMX_IN  OMX_PTR pComponentConfigStructure);

……

        /*OTHER PROCESSING FUNCTIONS */

        //Pure virtual function called from base, must have a definition in derived components

        //virtual void Decode() = 0;

        /*

          纯虚函数,必须在派生的类中实现。

           --> OmxComponentAudio --> omx_audio_xxx

           --> OmxComponentVideo --> omx_video_xxx

           

            该函数不是在OmxComponentAudio/OmxComponentVideo中实现,

而是在最终的派生类的实现,不同的编解码器其实现过程是不一样的。

        */

        virtual void ProcessData() = 0;

……

      /*

         需要在派生的类(最终的component)中实现!!

      */

        virtual OMX_ERRORTYPE ComponentInit() = 0;

        virtual OMX_ERRORTYPE ComponentDeInit() = 0;

……

这些接口是每一个OMX component都必须实现的函数(core methods),其中最重要的5种方法:

(1) ComponentInit()

(2) ComponentDeinit()

(3) GetParameter()

(4) SetParameter()

(5) ProcessData()

【3】OmxComponentAudio类

每个音频解码器组件都必须继承的类,其中GetParameter()和SetParameter()方法在该类中实现,其余方法在最终派生的component类中实现。

class OmxComponentAudio : public OmxComponentBase

{

    public:

        OSCL_IMPORT_REF OmxComponentAudio();

        OSCL_IMPORT_REF virtual ~OmxComponentAudio();

        OSCL_IMPORT_REF OMX_ERRORTYPE GetParameter(

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nParamIndex,

            OMX_INOUT OMX_PTR ComponentParameterStructure);

        OSCL_IMPORT_REF OMX_ERRORTYPE SetParameter(

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nParamIndex,

            OMX_IN  OMX_PTR ComponentParameterStructure);

        virtual void UpdateAACPlusFlag(OMX_BOOL aAacPlusFlag)

        {

            OSCL_UNUSED_ARG(aAacPlusFlag);

        }

        OSCL_IMPORT_REF virtual void CalculateBufferParameters(OMX_U32 PortIndex);

};

注意:

由OmxComponentBase类继承来的其他虚函数,如ComponentInit(), ComponentDeinit(), ProcessData()等在这还没有具体实现。

【进一步分析GetParameter()和SetParameter()函数!!!!】

【4】OmxComponentVideo类

/*************************

 VIDEO BASE CLASS ROUTINES

 *************************/

class OmxComponentVideo : public OmxComponentBase

{

    public:

        OSCL_IMPORT_REF OmxComponentVideo();

        OSCL_IMPORT_REF virtual ~OmxComponentVideo();

        OSCL_IMPORT_REF OMX_ERRORTYPE GetParameter(

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nParamIndex,

            OMX_INOUT OMX_PTR ComponentParameterStructure);

        OSCL_IMPORT_REF OMX_ERRORTYPE SetParameter(

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nParamIndex,

            OMX_IN  OMX_PTR ComponentParameterStructure);

        OSCL_IMPORT_REF virtual void CalculateBufferParameters(OMX_U32 PortIndex);

};

在OmxComponentVideo类中也是把从OmxComponentBase类中继承来的虚函数GetParameter()和SetParameter()函数做了实现。

【5】OpenmaxMp3AO类

该类是对MP3解码器按照openmax接口规范进行封装的类,以便作为一个音频解码的component集成进opencore框架中。

/*

按照openmax接口规范,对mp3 codec进行封装!!

*/

class OpenmaxMp3AO : public OmxComponentAudio

{

    public:

        OpenmaxMp3AO();

        ~OpenmaxMp3AO();

        OMX_ERRORTYPE ConstructComponent(OMX_PTR pAppData, OMX_PTR pProxy);

        OMX_ERRORTYPE DestroyComponent();

        OMX_ERRORTYPE ComponentInit(); // 继承自OmxComponentAudio

        OMX_ERRORTYPE ComponentDeInit(); // 继承自OmxComponentAudio

        void ProcessData(); // 继承自OmxComponentAudio

        void SyncWithInputTimestamp(); // 继承自OmxComponentAudio

        void ProcessInBufferFlag(); // 继承自OmxComponentBase

        void ResetComponent(); // 继承自OmxComponentBase

        OMX_ERRORTYPE GetConfig( // 覆盖掉OmxComponentAudio中的实现

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nIndex,

            OMX_INOUT OMX_PTR pComponentConfigStructure);

    private:

        void CheckForSilenceInsertion();

        void DoSilenceInsertion();

        Mp3Decoder*      ipMp3Dec; // 看具体实现!!!

        Mp3TimeStampCalc iCurrentFrameTS;

};

【6】OpenmaxAvcAO类

该类是对H264解码器按照openmax接口规范进行封装的类,以便作为一个视频解码的component集成进opencore框架中。

class OpenmaxAvcAO : public OmxComponentVideo

{

    public:

        OpenmaxAvcAO();

        ~OpenmaxAvcAO();

        OMX_ERRORTYPE ConstructComponent(OMX_PTR pAppData, OMX_PTR pProxy);

        OMX_ERRORTYPE DestroyComponent();

        OMX_ERRORTYPE ComponentInit();

        OMX_ERRORTYPE ComponentDeInit();

        void ComponentBufferMgmtWithoutMarker();

        OMX_BOOL ParseFullAVCFramesIntoNALs(OMX_BUFFERHEADERTYPE* aInputBuffer);

        void ProcessData();

        void DecodeWithoutMarker();

        void DecodeWithMarker();

        void ResetComponent();

        void ReleaseReferenceBuffers();

        OMX_ERRORTYPE GetConfig( // 覆盖继承类中的实现

            OMX_IN  OMX_HANDLETYPE hComponent,

            OMX_IN  OMX_INDEXTYPE nIndex,

            OMX_INOUT OMX_PTR pComponentConfigStructure);

        OMX_BOOL DetectStartCodeLength(OMX_U8* aBitstream,

                                       OMX_U8** aNalUnit,

                                       OMX_U32 aBufSize,

                                       OMX_U32* aSCSize);

        // ipOutputBuffer is fed to the decoder which may keep it as a reference

        // The decoder "spits" out another output buffer for rendering

        OMX_BUFFERHEADERTYPE *ipOutputBufferForRendering;

    private:

        AvcDecoder_OMX* ipAvcDec;

        OMX_BOOL        iDecodeReturn;

        OMX_BOOL        iFlushOutputStatus;

        // variables for "frame" mode i.e. iOMXComponentNeedsFullAVCFrames is turned on

        OMX_U32 iNALSizeArray[MAX_NAL_PER_FRAME]; // 100 should be more than enough NALs per frame

        OMX_U32 iNALStartCodeSizeArray[MAX_NAL_PER_FRAME]; // 100 should be more than enough NALs per frame

        OMX_U32 iCurrNAL;

        OMX_U32 iNumNALs;

        OMX_U32 iNALOffset;

        OMX_U32 iSizeOfNALSize;

};


http://blog.chinaunix.net/u/33029/showart_2241526.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值