织梦CMS - 轻松建站从此开始!

罗索

当前位置: 主页>嵌入式开发>Android>

openmax component类的继承关系

落鹤生 发布于 2012-10-11 09:37 点击:次 
向OpenCORE里继承一个新的codec时,需要用到OpenMAX接口规范对该codec进行封装,即要定义一个用于封装的类(wrapper),实现OpenMAX规定的集中核心方法(omx core methods)。
TAG:

向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文件中。看给类的注释:

  1. /** 
  2.  * User base class for execution objects. 
  3.  * OsclActiveObject defines an execution object without any timer. 
  4.  * This AO can be used across threads, i.e. the request 
  5.  * can be activated in one thread and completed in another. 
  6.  */ 

即该类是用于执行(或运行)对象的用户基础类,该运行对象没有计时器。 这个正在运行的对象(AO)可以在多个线程间被使用,如在一个线程中的请求可以在另一个线程中完成。
OsclActiveObject类又继承自两个类:HeapBase和PVActiveBase类,其中类HeapBase是用于基础的堆操作,如分配、释放内存等。类PVActiveBase主要是跟线程相关的(PV Scheduler internal AO base class)。
OsclActiveObject类主要是定义了对象运行的相关操作,如优先级、对象状态等。
【2】OmxComponentBase类
其中一些接口涉及到proxy(代理??),不知道具体什么差别!!!

  1. /** Component entry points declarations without proxy interface*/ 
  2. …… 
  3. /** Component entry points declarations with proxy interface*/ 
  4. …… 

接着是最重要的部分,

  1. /*NON STATIC COUNTERPARTS OF STATIC MEMBER API'S */ 
  2.         //Pure virtual functions, definition to be written in derived class 
  3.         /* 
  4.           纯虚函数,具体实现在派生的类中。 
  5.         */ 
  6.         virtual OMX_ERRORTYPE GetParameter( 
  7.             OMX_IN  OMX_HANDLETYPE hComponent, 
  8.             OMX_IN  OMX_INDEXTYPE nParamIndex, 
  9.             OMX_INOUT OMX_PTR ComponentParameterStructure) = 0; 
  10.         virtual OMX_ERRORTYPE SetParameter( 
  11.             OMX_IN  OMX_HANDLETYPE hComponent, 
  12.             OMX_IN  OMX_INDEXTYPE nParamIndex, 
  13.             OMX_IN  OMX_PTR ComponentParameterStructure) = 0; 
  14.         virtual OSCL_IMPORT_REF OMX_ERRORTYPE GetConfig( 
  15.             OMX_IN  OMX_HANDLETYPE hComponent, 
  16.             OMX_IN  OMX_INDEXTYPE nIndex, 
  17.             OMX_INOUT OMX_PTR pComponentConfigStructure); 
  18. //Making Setconfig as virtual function to be implemented in respective component class 
  19. // 在各个派生的component中各自实现该函数 
  20.         virtual OSCL_IMPORT_REF OMX_ERRORTYPE SetConfig( 
  21.             OMX_IN  OMX_HANDLETYPE hComponent, 
  22.             OMX_IN  OMX_INDEXTYPE nIndex, 
  23.             OMX_IN  OMX_PTR pComponentConfigStructure); 
  24. …… 
  25.  
  26. /*OTHER PROCESSING FUNCTIONS */ 
  27. //Pure virtual function called from base, must have a definition in derived components 
  28. //virtual void Decode() = 0; 
  29. /* 
  30.           纯虚函数,必须在派生的类中实现。 
  31.            --> OmxComponentAudio --> omx_audio_xxx 
  32.            --> OmxComponentVideo --> omx_video_xxx 
  33.            
  34. 该函数不是在OmxComponentAudio/OmxComponentVideo中实现,而是在最
  35. 终的派生类的实现,不同的编解码器其实现过程是不一样的。 
  36.         */ 
  37.         virtual void ProcessData() = 0; 
  38. …… 
  39.       /* 
  40.          需要在派生的类(最终的component)中实现!! 
  41.       */ 
  42.         virtual OMX_ERRORTYPE ComponentInit() = 0; 
  43.         virtual OMX_ERRORTYPE ComponentDeInit() = 0; 
  44. …… 

这些接口是每一个OMX component都必须实现的函数(core methods),其中最重要的5种方法:
(1) ComponentInit()
(2) ComponentDeinit()
(3) GetParameter()
(4) SetParameter()
(5) ProcessData()

【3】OmxComponentAudio类

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

  1. class OmxComponentAudio : public OmxComponentBase 
  2.     public
  3.         OSCL_IMPORT_REF OmxComponentAudio(); 
  4.         OSCL_IMPORT_REF virtual ~OmxComponentAudio(); 
  5.         OSCL_IMPORT_REF OMX_ERRORTYPE GetParameter( 
  6.             OMX_IN  OMX_HANDLETYPE hComponent, 
  7.             OMX_IN  OMX_INDEXTYPE nParamIndex, 
  8.             OMX_INOUT OMX_PTR ComponentParameterStructure); 
  9.         OSCL_IMPORT_REF OMX_ERRORTYPE SetParameter( 
  10.             OMX_IN  OMX_HANDLETYPE hComponent, 
  11.             OMX_IN  OMX_INDEXTYPE nParamIndex, 
  12.             OMX_IN  OMX_PTR ComponentParameterStructure); 
  13.  
  14.         virtual void UpdateAACPlusFlag(OMX_BOOL aAacPlusFlag) 
  15.         { 
  16.             OSCL_UNUSED_ARG(aAacPlusFlag); 
  17.         } 
  18.         OSCL_IMPORT_REF virtual void CalculateBufferParameters(OMX_U32 PortIndex); 
  19. }; 

注意:
由OmxComponentBase类继承来的其他虚函数,如ComponentInit(), ComponentDeinit(), ProcessData()等在这还没有具体实现。
【进一步分析GetParameter()和SetParameter()函数!!!!】
【4】OmxComponentVideo类

  1. /************************* 
  2.  VIDEO BASE CLASS ROUTINES 
  3.  *************************/ 
  4. class OmxComponentVideo : public OmxComponentBase 
  5.     public
  6.         OSCL_IMPORT_REF OmxComponentVideo(); 
  7.         OSCL_IMPORT_REF virtual ~OmxComponentVideo(); 
  8.         OSCL_IMPORT_REF OMX_ERRORTYPE GetParameter( 
  9.             OMX_IN  OMX_HANDLETYPE hComponent, 
  10.             OMX_IN  OMX_INDEXTYPE nParamIndex, 
  11.             OMX_INOUT OMX_PTR ComponentParameterStructure); 
  12.         OSCL_IMPORT_REF OMX_ERRORTYPE SetParameter( 
  13.             OMX_IN  OMX_HANDLETYPE hComponent, 
  14.             OMX_IN  OMX_INDEXTYPE nParamIndex, 
  15.             OMX_IN  OMX_PTR ComponentParameterStructure); 
  16.         OSCL_IMPORT_REF virtual void CalculateBufferParameters(OMX_U32 PortIndex); 
  17. }; 

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

【5】OpenmaxMp3AO类

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

  1. /* 
  2. 按照openmax接口规范,对mp3 codec进行封装!! 
  3. */ 
  4. class OpenmaxMp3AO : public OmxComponentAudio 
  5.     public
  6.         OpenmaxMp3AO(); 
  7.         ~OpenmaxMp3AO(); 
  8.         OMX_ERRORTYPE ConstructComponent(OMX_PTR pAppData, OMX_PTR pProxy); 
  9.         OMX_ERRORTYPE DestroyComponent(); 
  10.         OMX_ERRORTYPE ComponentInit(); // 继承自OmxComponentAudio 
  11.         OMX_ERRORTYPE ComponentDeInit(); // 继承自OmxComponentAudio 
  12.         void ProcessData(); // 继承自OmxComponentAudio 
  13.         void SyncWithInputTimestamp(); // 继承自OmxComponentAudio 
  14.         void ProcessInBufferFlag(); // 继承自OmxComponentBase 
  15.         void ResetComponent(); // 继承自OmxComponentBase 
  16.         OMX_ERRORTYPE GetConfig( // 覆盖掉OmxComponentAudio中的实现 
  17.             OMX_IN  OMX_HANDLETYPE hComponent, 
  18.             OMX_IN  OMX_INDEXTYPE nIndex, 
  19.             OMX_INOUT OMX_PTR pComponentConfigStructure); 
  20.  
  21.     private
  22.         void CheckForSilenceInsertion(); 
  23.         void DoSilenceInsertion(); 
  24.         Mp3Decoder*      ipMp3Dec; // 看具体实现!!! 
  25.         Mp3TimeStampCalc iCurrentFrameTS; 
  26. }; 

【6】OpenmaxAvcAO类

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

  1. class OpenmaxAvcAO : public OmxComponentVideo 
  2.     public
  3.         OpenmaxAvcAO(); 
  4.         ~OpenmaxAvcAO(); 
  5.         OMX_ERRORTYPE ConstructComponent(OMX_PTR pAppData, OMX_PTR pProxy); 
  6.         OMX_ERRORTYPE DestroyComponent(); 
  7.         OMX_ERRORTYPE ComponentInit(); 
  8.         OMX_ERRORTYPE ComponentDeInit(); 
  9.         void ComponentBufferMgmtWithoutMarker(); 
  10.         OMX_BOOL ParseFullAVCFramesIntoNALs(OMX_BUFFERHEADERTYPE* aInputBuffer); 
  11.         void ProcessData(); 
  12.         void DecodeWithoutMarker(); 
  13.         void DecodeWithMarker(); 
  14.         void ResetComponent(); 
  15.         void ReleaseReferenceBuffers(); 
  16.         OMX_ERRORTYPE GetConfig( // 覆盖继承类中的实现 
  17.             OMX_IN  OMX_HANDLETYPE hComponent, 
  18.             OMX_IN  OMX_INDEXTYPE nIndex, 
  19.             OMX_INOUT OMX_PTR pComponentConfigStructure); 
  20.         OMX_BOOL DetectStartCodeLength(OMX_U8* aBitstream, 
  21.                                        OMX_U8** aNalUnit, 
  22.                                        OMX_U32 aBufSize, 
  23.                                        OMX_U32* aSCSize); 
  24. // ipOutputBuffer is fed to the decoder which may keep it as a reference 
  25. // The decoder "spits" out another output buffer for rendering 
  26.         OMX_BUFFERHEADERTYPE *ipOutputBufferForRendering; 
  27.  
  28.     private
  29.         AvcDecoder_OMX* ipAvcDec; 
  30.         OMX_BOOL        iDecodeReturn; 
  31.         OMX_BOOL        iFlushOutputStatus; 
  32. // variables for "frame" mode i.e. iOMXComponentNeedsFullAVCFrames is turned on 
  33.         OMX_U32 iNALSizeArray[MAX_NAL_PER_FRAME];
  34. // 100 should be more than enough NALs per frame 
  35.         OMX_U32 iNALStartCodeSizeArray[MAX_NAL_PER_FRAME];
  36. // 100 should be more than enough NALs per frame 
  37.         OMX_U32 iCurrNAL; 
  38.         OMX_U32 iNumNALs; 
  39.         OMX_U32 iNALOffset; 
  40.         OMX_U32 iSizeOfNALSize; 
  41. }; 

 

(yuyin86)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201210/16310.html]
本文出处:CSDN博客 作者:yuyin86 原文
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容