zoukankan      html  css  js  c++  java
  • openmax component类的继承关系

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

    };

  • 相关阅读:
    【算法学习笔记】27.动态规划 解题报告 SJTU OJ 1254 传手绢
    【算法学习笔记】26.扫描维护法 解题报告 SJTU OJ 1133 数星星
    【算法学习笔记】25.贪心法 均分纸牌问题的分析
    【算法学习笔记】24.记忆化搜索 解题报告 SJTU OJ 1002 二哥种花生
    【算法学习笔记】23.动态规划 解题报告 SJTU OJ 1280 整装待发
    【算法学习笔记】22.算法设计初步 二分查找 上下界判断
    【算法学习笔记】21.算法设计初步 求第k个数 划分法 快排法
    【算法学习笔记】20.算法设计初步 归并排序 求逆序数
    【算法学习笔记】19.算法设计初步 最大子列和问题的几种方法
    【算法学习笔记】18.暴力求解法06 隐式图搜索2 八数码问题 未启发
  • 原文地址:https://www.cnblogs.com/nsnow/p/3808267.html
Copyright © 2011-2022 走看看