二、Omx架构:
二、Omx 使用:
1、initialize.
OMX_Init();
2. get componenthandle.
OMX_GetHandle();
For example:
OMX_CALLBACKTYPE videodeccallbacks = {
.EventHandler =videodecEventHandler,
.EmptyBufferDone =videodecEmptyBufferDone,
.FillBufferDone =videodecFillBufferDone
};
/*getting video decoder handle*/
OMX_GetHandle(&videodechandle, "OMX.vender.video_decoder.h264",NULL, &videodeccallbacks);
/*getting color converter component handle*/
OMX_GetHandle(&colorconv_handle, "OMX.ven.video_colorconv.ffmpeg",NULL, &colorconv_callbacks);
/** getting sink componenthandle */
OMX_GetHandle(&fbdev_sink_handle,"OMX.ven.fbdev.fbdev_sink", NULL, &fbdev_sink_callbacks);
3. set up the tunnelbetween the components.
OMX_SetupTunnel( OMX_HANDLETYPE hOutput, OMX_U32 nPortOutput, OMX_HANDLETYPE hInput, OMX_U32 nPortInput) ;
For example:
OMX_SetupTunnel(videodechandle,1, colorconv_handle, 0);
OMX_SetupTunnel(colorconv_handle,1, fbdev_sink_handle, 0);
videodecà Colorconvàfbdev_sink
4.control components.
Thereare two type of communication control:
1)send command.
a. OMX_CommandStateSet /**< Change the component state */
b. OMX_CommandFlush, /**< Flush the data queue(s) of acomponent */
c. OMX_CommandPortDisable, /**< Disable a porton a component. */
d. OMX_CommandPortEnable, /**< Enable a port on a component. */
2)Send data.
a. OMX_CommandMarkBuffer, /**< Mark a component/buffer forobservation */
5. components stateMachine.
OMX_StateIdle, /**< component initializationhas been completed successfully and the component is ready to to start. */
OMX_StateExecuting, /**< component has accepted the startcommand and is processing data (if data is available) */
OMX_StatePause, /**< component has received pausecommand */
OMX_StateWaitForResources,/**< component is waiting for resources, either after preemption or before itgets the resources requested. See specification for complete details. */
For example:
OMX_SendCommand(videodechandle,OMX_CommandStateSet, OMX_StateExecuting, NULL);
6. buffer control.
/*will send a buffer full of datato an input port of a component. The buffer will be emptied by the component andreturned to the application via the EmptyBufferDone call back*/
OMX_EmptyThisBuffer()
/*will send an empty buffer to anoutput port of a component. The bufferwill be filled by the component and returned to the application via theFillBufferDone call back*/
OMX_FillThisBuffer();
/* will request that thecomponent use a buffer (and allocate its own buffer header) already allocated
by another component, or by the IL Client*/
OMX_UseBuffer();
/*will request that the componentallocate a new buffer and buffer header.*/
OMX_AllocateBuffer();
/*will release a buffer headerfrom the component which was allocated using either OMX_AllocateBuffer orOMX_UseBuffer.*/
OMX_FreeBuffer();
For example:
OMX_EmptyThisBuffer(videodechandle,pInBuffer1);
OMX_FillThisBuffer(videodechandle,pOutBuffer1);
7. data flow betweendifferent component.
For example: decoder àcolorConv
/*set pOutBuffer1 to the decodercompoment output buffer*/
OMX_FillThisBuffer(videodechandle,pOutBuffer1);
/*read the compressed data fromfile to pInBuffer1*/
fread(pInBuffer1->pBuffer,1, buffer_in_size, fd);
/*put the pInBuffer1 to thedecoder component input buffer, began to decoder the data*/
OMX_EmptyThisBuffer(videodechandle,pInBuffer1);
/*will trigger this callback whendecoder decode one frame */
videodecFillBufferDone(OMX_OUTOMX_BUFFERHEADERTYPE* pBuffer){
/*we will put the decoded frameto the color converter component input buffer */
pInBufferColorConv1->pBuffer== pBuffer->pBuffer;
pInBufferColorConv1->nFilledLen= pBuffer->nFilledLen;
OMX_EmptyThisBuffer(appPriv->colorconv_handle,pInBufferColorConv1);
}
二、编写omx component:
Component 需从source,filter或者sinkcomponent 派生,然后可以添加特有的属性和方法。
遵循openMax IL 规范,必须重写的函数:
omx_h264dec_component_Constructor();
omx_h264dec_component_SetParameter();
omx_h264dec_component_GetParameter();
必须实现的函数:
omx_videodec_base_component_BufferMgmtCallback();
组件的功能和其定义的端口类型密切相关,通常情况下:
只有一个输出端口的,为Source组件;
只有一个输入端口的,为Sink组件;
有多个输入端口,一个输出端口的为Mux组件;
有一个输入端口,多个输出端口的为DeMux组件;
输入输出端口各一个组件的为中间处理环节,这是最常见的组件。