OpenMAX IL接口/头文件

OpenMAX IL接口/头文件

  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标准只有头文件,没有标准的库,设置没有定义函数接口。对于实现者,需要实现的主要是包含函数指针的结构体

    1. 在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连接。

  1. 在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;  
  1. 在OMX_Component.h文件中定义了OMX_COMPONENTTYPE类型数据结构,OMX IL 用它来描述一个component,其中包含了可供调用的函数方法。OMX_PORTDOMAINTYPE 音频类型,视频类型,图像类型,其他类型是OpenMax IL层此所定义的四种端口的类型。
    端口具体内容的定义使用OMX_PARAM_PORTDEFINITIONTYPE类来表示。
typedef enum OMX_DIRTYPE  // OMX_Types.h
{
    OMX_DirInput,              /**< Port is an input port */
    OMX_DirOutput,             /**< Port is an output port */
    OMX_DirMax = 0x7FFFFFFF
} OMX_DIRTYPE;

/** @ingroup comp */
typedef enum OMX_PORTDOMAINTYPE { 
    OMX_PortDomainAudio, 
    OMX_PortDomainVideo, 
    OMX_PortDomainImage, 
    OMX_PortDomainOther,
    OMX_PortDomainKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */ 
    OMX_PortDomainVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
    OMX_PortDomainMax = 0x7ffffff
} OMX_PORTDOMAINTYPE;


/** @ingroup comp */
typedef struct OMX_PARAM_PORTDEFINITIONTYPE {
    OMX_U32 nSize;                 /**< Size of the structure in bytes */
    OMX_VERSIONTYPE nVersion;      /**< OMX specification version information */
    OMX_U32 nPortIndex;            /**< Port number the structure applies to */
    OMX_DIRTYPE eDir;              /**< Direction (input or output) of this port */
    OMX_U32 nBufferCountActual;    /**< The actual number of buffers allocated on this port */
    OMX_U32 nBufferCountMin;       /**< The minimum number of buffers this port requires */
    OMX_U32 nBufferSize;           /**< Size, in bytes, for buffers to be used for this channel */
    OMX_BOOL bEnabled;             /**< Ports default to enabled and are enabled/disabled by
                                        OMX_CommandPortEnable/OMX_CommandPortDisable.
                                        When disabled a port is unpopulated. A disabled port
                                        is not populated with buffers on a transition to IDLE. */
    OMX_BOOL bPopulated;           /**< Port is populated with all of its buffers as indicated by
                                        nBufferCountActual. A disabled port is always unpopulated. 
                                        An enabled port is populated on a transition to OMX_StateIdle
                                        and unpopulated on a transition to loaded. */
    OMX_PORTDOMAINTYPE eDomain;    /**< Domain of the port. Determines the contents of metadata below. */
    union {
        OMX_AUDIO_PORTDEFINITIONTYPE audio;
        OMX_VIDEO_PORTDEFINITIONTYPE video;
        OMX_IMAGE_PORTDEFINITIONTYPE image;
        OMX_OTHER_PORTDEFINITIONTYPE other;
    } format;
    OMX_BOOL bBuffersContiguous;
    OMX_U32 nBufferAlignment;
} OMX_PARAM_PORTDEFINITIONTYPE;

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等宏,它们的实际内容为空,只是为了标记参数的方向是输入还是输出。
5、OMX_Core.h中定义的枚举类型OMX_STATETYPE命令表示OpenMax的状态机,OpenMax组件的状态机可以由外部的命令改变,也可以由内部发生的情况改变

typedef enum OMX_STATETYPE
{
    OMX_StateInvalid,      /**< component has detected that it's internal data 
                                structures are corrupted to the point that
                                it cannot determine it's state properly */
    OMX_StateLoaded,      /**< component has been loaded but has not completed
                                initialization.  The OMX_SetParameter macro
                                and the OMX_GetParameter macro are the only 
                                valid macros allowed to be sent to the 
                                component in this state. */
    OMX_StateIdle,        /**< component initialization has been completed
                                successfully and the component is ready to
                                to start. */
    OMX_StateExecuting,   /**< component has accepted the start command and
                                is processing data (if data is available) */
    OMX_StatePause,       /**< component has received pause command */
    OMX_StateWaitForResources, /**< component is waiting for resources, either after 
                                preemption or before it gets the resources requested.
                                See specification for complete details. */
    OMX_StateKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */ 
    OMX_StateVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
    OMX_StateMax = 0X7FFFFFFF
} OMX_STATETYPE;
OMX_Core.h中定义的枚举类型OMX_COMMANDTYPE表示对组件的命令类型
/** The OMX_COMMANDTYPE enumeration is used to specify the action in the
 *  OMX_SendCommand macro.  
 *  @ingroup core
 */
typedef enum OMX_COMMANDTYPE
{
    OMX_CommandStateSet,    /**< Change the component state */
    OMX_CommandFlush,       /**< Flush the data queue(s) of a component */
    OMX_CommandPortDisable, /**< Disable a port on a component. */
    OMX_CommandPortEnable,  /**< Enable a port on a component. */
    OMX_CommandMarkBuffer,  /**< Mark a component/buffer for observation */
    OMX_CommandKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */ 
    OMX_CommandVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
    OMX_CommandMax = 0X7FFFFFFF
} OMX_COMMANDTYPE;

6、OpenMax适配层的接口在frameworks/base/include/media/目录中的IOMX.h文件定义

class IOMX : public IInterface {
public:
    DECLARE_META_INTERFACE(OMX);
   typedef void *buffer_id;
    typedef void *node_id;
   // Given the calling process' pid, returns true iff
    // the implementation of the OMX interface lives in the same
    // process.
    virtual bool livesLocally(pid_t pid) = 0;
   struct ComponentInfo {
        String8 mName;
        List<String8> mRoles;
    };
    virtual status_t listNodes(List<ComponentInfo> *list) = 0;
   virtual status_t allocateNode(
            const char *name, const sp<IOMXObserver> &observer,
            node_id *node) = 0;
   virtual status_t freeNode(node_id node) = 0;
   virtual status_t sendCommand(
            node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
   virtual status_t getParameter(
            node_id node, OMX_INDEXTYPE index,
            void *params, size_t size) = 0;
    virtual status_t setParameter(
            node_id node, OMX_INDEXTYPE index,
            const void *params, size_t size) = 0;
    virtual status_t getConfig(
            node_id node, OMX_INDEXTYPE index,
            void *params, size_t size) = 0;
    virtual status_t setConfig(
            node_id node, OMX_INDEXTYPE index,
            const void *params, size_t size) = 0;
     virtual status_t getState(
            node_id node, OMX_STATETYPE* state) = 0;
     virtual status_t storeMetaDataInBuffers(
            node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
     virtual status_t enableGraphicBuffers(
            node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
     virtual status_t getGraphicBufferUsage(
            node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
     virtual status_t useBuffer(
            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
            buffer_id *buffer) = 0;
    virtual status_t useGraphicBuffer(
            node_id node, OMX_U32 port_index,
            const sp<GraphicBuffer> &graphicBuffer, buffer_id *buffer) = 0;
    // This API clearly only makes sense if the caller lives in the
    // same process as the callee, i.e. is the media_server, as the
    // returned "buffer_data" pointer is just that, a pointer into local
    // address space.
    virtual status_t allocateBuffer(
            node_id node, OMX_U32 port_index, size_t size,
            buffer_id *buffer, void **buffer_data) = 0;
     virtual status_t allocateBufferWithBackup(
            node_id node, OMX_U32 port_index, const sp<IMemory> &params,
            buffer_id *buffer) = 0;
     virtual status_t freeBuffer(
            node_id node, OMX_U32 port_index, buffer_id buffer) = 0;
     virtual status_t fillBuffer(node_id node, buffer_id buffer) = 0;
     virtual status_t emptyBuffer(
            node_id node,
            buffer_id buffer,
            OMX_U32 range_offset, OMX_U32 range_length,
            OMX_U32 flags, OMX_TICKS timestamp) = 0;
     virtual status_t getExtensionIndex(
            node_id node,
            const char *parameter_name,
            OMX_INDEXTYPE *index) = 0;
};
struct omx_message {
    enum {
        EVENT,
        EMPTY_BUFFER_DONE,
        FILL_BUFFER_DONE,
    } type;
    IOMX::node_id node;
    union {
        // if type == EVENT
        struct {
            OMX_EVENTTYPE event;
            OMX_U32 data1;
            OMX_U32 data2;
        } event_data;
        // if type == EMPTY_BUFFER_DONE
        struct {
            IOMX::buffer_id buffer;
        } buffer_data;
        // if type == FILL_BUFFER_DONE
        struct {
            IOMX::buffer_id buffer;
            OMX_U32 range_offset;
            OMX_U32 range_length;
            OMX_U32 flags;
            OMX_TICKS timestamp;
            OMX_PTR platform_private;
            OMX_PTR data_ptr;
        } extended_buffer_data;
    } u;
};
class IOMXObserver : public IInterface {
public:
    DECLARE_META_INTERFACE(OMXObserver);
    virtual void onMessage(const omx_message &msg) = 0;
};
class BnOMX : public BnInterface<IOMX> {
public:
    virtual status_t onTransact(
            uint32_t code, const Parcel &data, Parcel *reply,
            uint32_t flags = 0);
};
class BnOMXObserver : public BnInterface<IOMXObserver> {
public:
    virtual status_t onTransact(
            uint32_t code, const Parcel &data, Parcel *reply,
            uint32_t flags = 0);
};
struct CodecProfileLevel {
    OMX_U32 mProfile;
    OMX_U32 mLevel;
};
}  // namespace android

IOMX表示的是OpenMax的一个组件,根据Android的Binder IPC机制,BnOMX继承IOMX,实现者需要继承实现BnOMX。
1、IOMX类中,除了和标准的OpenMax的GetParameter,SetParameter,GetConfig,SetConfig,SendCommand,UseBuffer,AllocateBuffer,FreeBuffer,FillThisBuffer和EmptyThisBuffer等接口之外,
2、还包含了创造渲染器的接口createRenderer(),创建的接口为IOMXRenderer类型。
3、IOMX中只有第一个createRenderer()函数是纯虚函数,第二个的createRenderer()函数和createRendererFromJavaSurface()通过调用第一个createRenderer()函数实现。
4、在IOMX.h文件中,另有表示观察器类的IOMXObserver,这个类表示OpenMax的观察者,其中只包含一个onMessage()函数,其参数为omx_message接口体,其中包含Event事件类型、FillThisBuffer完成和EmptyThisBuffer完成几种类型。
OpenMax的适配层是OpenMAX IL层至上的封装层,在Android系统中被StageFright调用,也可以被其他部分调用

IOMXRenderer类表示一个OpenMax的渲染器

class IOMXRenderer : public IInterface {
   DECLARE_META_INTERFACE(OMXRenderer);
   virtual  void  render(IOMX:buffer_id buffer) = 0;
};

IOMXRenderer只包含了一个render接口,其参数类型IOMX::buffer_id实际上是void*,根据不同渲染器使用不同的类型。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值