OpenMAX/IL: OMX IL 学习笔记【1】- 接口与头文件

来源:互联网 发布:lol徐老师淘宝店多少 编辑:程序博客网 时间:2024/05/17 03:50
 1.  OpenMAX IL 层的接口定义是由若干个头文件的形式给出的,在头文件中定义了一些结构体和需要开发者实现的接口函数,包括:
  • OMX_Types.h:OpenMax Il的数据类型定义
  • OMX_Core.h:OpenMax IL核心的API
  • OMX_Component.h:OpenMax IL 组件相关的 API
  • OMX_Audio.h:音频相关的常量和数据结构
  • OMX_IVCommon.h:图像和视频公共的常量和数据结构
  • OMX_Image.h:图像相关的常量和数据结构
  • OMX_Video.h:视频相关的常量和数据结构
  • OMX_Other.h:其他数据结构(包括A/V 同步)
  • OMX_Index.h:OpenMax IL定义的数据结构索引
  • OMX_ContentPipe.h:内容的管道定义 
  提示:OpenMax标准只有头文件,没有标准的库,设置没有定义函数接口。对于实现者,需要实现的主要是包含函数指针的结构体

2.  在OMX_Core.h中定义了Core的API函数,应用程序通过它可以进行初始化、处理handle等操作,具体内容如下:
  OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Init(void);         // 初始化OMX Core,且应该是OMX中第一个被调用的函数;  OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Deinit(void);        // 反初始化OMX Core,且应该是OMX中最后一个被;  OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_ComponentNameEnum(       // 列出系统中所有可用component的名称;                                   OMX_OUT OMX_STRING cComponentName,                                   OMX_IN  OMX_U32 nNameLength,                                   OMX_IN  OMX_U32 nIndex);  OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_GetHandle(    // 根据名称查找component,并调用component的方法来实例化component;                                   OMX_OUT OMX_HANDLETYPE* pHandle,                                    OMX_IN  OMX_STRING cComponentName,                                   OMX_IN  OMX_PTR pAppData,                                   OMX_IN  OMX_CALLBACKTYPE* pCallBacks);  OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_FreeHandle(                                   OMX_IN  OMX_HANDLETYPE hComponent);  OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_SetupTunnel(         // 在两个component之间建立tunnel连接                                   OMX_IN  OMX_HANDLETYPE hOutput,                                   OMX_IN  OMX_U32 nPortOutput,                                   OMX_IN  OMX_HANDLETYPE hInput,                                   OMX_IN  OMX_U32 nPortInput);  OMX_API OMX_ERRORTYPE   OMX_GetContentPipe(                                   OMX_OUT OMX_HANDLETYPE *hPipe,                                   OMX_IN OMX_STRING szURI);  OMX_API OMX_ERRORTYPE OMX_GetComponentsOfRole (                                    OMX_IN      OMX_STRING role,                                   OMX_INOUT   OMX_U32 *pNumComps,                                   OMX_INOUT   OMX_U8  **compNames);  OMX_API OMX_ERRORTYPE OMX_GetRolesOfComponent (                                    OMX_IN      OMX_STRING compName,                                    OMX_INOUT   OMX_U32 *pNumRoles,                                   OMX_OUT     OMX_U8 **roles);

  当应用程序需要使用某个component的功能时,其首先需要调用OMX_Init()来对OMX Core进行初始化,然后通过OMX_GetHandle()来实例化component,取得相应的handle。handle实际上是一个指向component对象的void类型指针,其在OMX_Type.h中定义如下,
  typedef void* OMX_HANDLETYPE;
OMX_SetupTunnel()用来在两个component之间建立tunnel连接。

3.  在OMX_Core.h中还定义了数据类型OMX_BUFFERHEADERTYPE,其对象存放在buffer内用来描述该buffer的特性。具体内容及各字段注释如下:
typedef struct OMX_BUFFERHEADERTYPE{    OMX_U32 nSize;              /**< size of the structure in bytes */    OMX_VERSIONTYPE nVersion;   /**< OMX specification version information */    OMX_U8* pBuffer;            /**< Pointer to actual block of memory                                                    that is acting as the buffer */    OMX_U32 nAllocLen;          /**< size of the buffer allocated, in bytes */    OMX_U32 nFilledLen;         /**< number of bytes currently in the                                                       buffer */    OMX_U32 nOffset;             /**< start offset of valid data in bytes from                                                      the start of the buffer */    OMX_PTR pAppPrivate;        /**< pointer to any data the application                                                        wants to associate with this buffer */    OMX_PTR pPlatformPrivate;   /**< pointer to any data the platform                                                          wants to associate with this buffer */     OMX_PTR pInputPortPrivate;  /**< pointer to any data the input port                                                          wants to associate with this buffer */    OMX_PTR pOutputPortPrivate; /**< pointer to any data the output port                                                            wants to associate with this buffer */    OMX_HANDLETYPE hMarkTargetComponent; /**< The component that will generate a                                                                                     mark event upon processing this buffer. */    OMX_PTR pMarkData;          /**< Application specific data associated with                                      the mark sent on a mark event to disambiguate                                      this mark from others. */    OMX_U32 nTickCount;         /**< Optional entry that the component and                                     application can update with a tick count                                     when they access the component.  This                                     value should be in microseconds.  Since                                     this is a value relative to an arbitrary                                     starting point, this value cannot be used                                      to determine absolute time.  This is an                                     optional entry and not all components                                     will update it.*/ OMX_TICKS nTimeStamp;          /**< Timestamp corresponding to the sample                                      starting at the first logical sample                                      boundary in the buffer. Timestamps of                                      successive samples within the buffer may                                     be inferred by adding the duration of the                                      of the preceding buffer to the timestamp                                     of the preceding buffer.*/  OMX_U32     nFlags;           /**< buffer specific flags */  OMX_U32 nOutputPortIndex;     /**< The index of the output port (if any) using                                                            this buffer */  OMX_U32 nInputPortIndex;      /**< The index of the input port (if any) using                                                         this buffer */} OMX_BUFFERHEADERTYPE;


4.  在OMX_Component.h文件中定义了OMX_COMPONENTTYPE类型数据结构,OMX IL 用它来描述一个component,其中包含了可供调用的函数方法。
typedef struct OMX_COMPONENTTYPE{    OMX_U32 nSize;     OMX_VERSIONTYPE nVersion;    OMX_PTR pComponentPrivate;    OMX_PTR pApplicationPrivate;     OMX_ERRORTYPE (*GetComponentVersion)(            OMX_IN  OMX_HANDLETYPE hComponent,            OMX_OUT OMX_STRING pComponentName,            OMX_OUT OMX_VERSIONTYPE* pComponentVersion,            OMX_OUT OMX_VERSIONTYPE* pSpecVersion,            OMX_OUT OMX_UUIDTYPE* pComponentUUID);    OMX_ERRORTYPE (*SendCommand)(            OMX_IN  OMX_HANDLETYPE hComponent,            OMX_IN  OMX_COMMANDTYPE Cmd,            OMX_IN  OMX_U32 nParam1,            OMX_IN  OMX_PTR pCmdData);    OMX_ERRORTYPE (*GetParameter)(            OMX_IN  OMX_HANDLETYPE hComponent,             OMX_IN  OMX_INDEXTYPE nParamIndex,              OMX_INOUT OMX_PTR pComponentParameterStructure);    OMX_ERRORTYPE (*SetParameter)(            OMX_IN  OMX_HANDLETYPE hComponent,             OMX_IN  OMX_INDEXTYPE nIndex,            OMX_IN  OMX_PTR pComponentParameterStructure);  OMX_ERRORTYPE (*GetConfig)(            OMX_IN  OMX_HANDLETYPE hComponent,            OMX_IN  OMX_INDEXTYPE nIndex,             OMX_INOUT OMX_PTR pComponentConfigStructure);    OMX_ERRORTYPE (*SetConfig)(            OMX_IN  OMX_HANDLETYPE hComponent,            OMX_IN  OMX_INDEXTYPE nIndex,             OMX_IN  OMX_PTR pComponentConfigStructure);    OMX_ERRORTYPE (*GetExtensionIndex)(            OMX_IN  OMX_HANDLETYPE hComponent,            OMX_IN  OMX_STRING cParameterName,            OMX_OUT OMX_INDEXTYPE* pIndexType);    OMX_ERRORTYPE (*GetState)(            OMX_IN  OMX_HANDLETYPE hComponent,            OMX_OUT OMX_STATETYPE* pState);    OMX_ERRORTYPE (*ComponentTunnelRequest)(            OMX_IN  OMX_HANDLETYPE hComp,            OMX_IN  OMX_U32 nPort,            OMX_IN  OMX_HANDLETYPE hTunneledComp,            OMX_IN  OMX_U32 nTunneledPort,            OMX_INOUT  OMX_TUNNELSETUPTYPE* pTunnelSetup);     OMX_ERRORTYPE (*UseBuffer)(            OMX_IN OMX_HANDLETYPE hComponent,            OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,            OMX_IN OMX_U32 nPortIndex,            OMX_IN OMX_PTR pAppPrivate,            OMX_IN OMX_U32 nSizeBytes,            OMX_IN OMX_U8* pBuffer);    OMX_ERRORTYPE (*AllocateBuffer)(            OMX_IN OMX_HANDLETYPE hComponent,            OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer,            OMX_IN OMX_U32 nPortIndex,            OMX_IN OMX_PTR pAppPrivate,            OMX_IN OMX_U32 nSizeBytes);    OMX_ERRORTYPE (*FreeBuffer)(            OMX_IN  OMX_HANDLETYPE hComponent,            OMX_IN  OMX_U32 nPortIndex,            OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);    OMX_ERRORTYPE (*FillThisBuffer)(            OMX_IN  OMX_HANDLETYPE hComponent,            OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);    OMX_ERRORTYPE (*SetCallbacks)(            OMX_IN  OMX_HANDLETYPE hComponent,            OMX_IN  OMX_CALLBACKTYPE* pCallbacks,             OMX_IN  OMX_PTR pAppData);    OMX_ERRORTYPE (*ComponentDeInit)(            OMX_IN  OMX_HANDLETYPE hComponent);    OMX_ERRORTYPE (*UseEGLImage)(            OMX_IN OMX_HANDLETYPE hComponent,            OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,            OMX_IN OMX_U32 nPortIndex,            OMX_IN OMX_PTR pAppPrivate,            OMX_IN void* eglImage);    OMX_ERRORTYPE (*ComponentRoleEnum)(            OMX_IN OMX_HANDLETYPE hComponent,            OMX_OUT OMX_U8 *cRole,            OMX_IN OMX_U32 nIndex);} OMX_COMPONENTTYPE;

EmptyThisBuffer和FillThisBuffer是驱动组件运行的基本的机制,前者表示让组件消耗缓冲区,表示对应组件输入的内容;后者表示让组件填充缓冲区,表示对应组件输出的内容。

UseBuffer,AllocateBuffer,FreeBuffer为和端口相关的缓冲区管理函数,对于组件的端口有些可以自己分配缓冲区,有些可以使用外部的缓冲区,因此有不同的接口对其进行操作。

SendCommand表示向组件发送控制类的命令。

GetParameter,SetParameter,GetConfig,SetConfig几个接口用于辅助的参数和配置的设置和获取。

ComponentTunnelRequest用于组件之间的隧道化连接,其中需要制定两个组件及其相连的端口。

ComponentDeInit用于组件的反初始化。

提示:OpenMax函数的参数中,经常包含OMX_IN和OMX_OUT等宏,它们的实际内容为空,只是为了标记参数的方向是输入还是输出。


0 0
原创粉丝点击