OMX_Init()
沒有什麼好說的,初始化函數,一定要運行的.
OMX_GetHandle
得到某一個組件的句柄
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_GetHandle(
OMX_OUT OMX_HANDLETYPE* pHandle,
OMX_IN OMX_STRING cComponentName,
OMX_IN OMX_PTR pAppData,
OMX_IN OMX_CALLBACKTYPE* pCallBacks);
OMX_GetExtensionIndex
除了標準OMX_INDEXTYPE中定義的以外,返回用戶自定義的一些參數(第二個參數)對應的index(第三個參數,用在OMX_SetParameter...裏面),用來configur或者parameter.
這些參數往往被定義在用戶特殊的extension interface裏面
#define OMX_GetExtensionIndex( /
hComponent, /
cParameterName, /
pIndexType) /
((OMX_COMPONENTTYPE*)hComponent)->GetExtensionIndex( /
hComponent, /
cParameterName, /
pIndexType) /* Macro End */
OMX_SetParameter
設定某個參數對應的值
#define OMX_SetParameter( /
hComponent, /
nParamIndex, /
pComponentParameterStructure) /
((OMX_COMPONENTTYPE*)hComponent)->SetParameter( /
hComponent, /
nParamIndex, /
pComponentParameterStructure) /* Macro End */
OMX_SetConfig
設定某個config值
#define OMX_SetConfig( /
hComponent, /
nConfigIndex, /
pComponentConfigStructure) /
((OMX_COMPONENTTYPE*)hComponent)->SetConfig( /
hComponent, /
nConfigIndex, /
pComponentConfigStructure) /* Macro End */
注意有時候,需要先停止某個組件(的某些端口),才能設置config 成功
OMX_SendCommand
一般的命令有:
OMX_CommandStateSet 、OMX_CommandFlush、OMX_CommandPortDisable" 、 "OMX_CommandPortEnable、CommandMarkBuffer
#define OMX_SendCommand( /
hComponent, /
Cmd, /
nParam, /
pCmdData) /
((OMX_COMPONENTTYPE*)hComponent)->SendCommand( /
hComponent, /
Cmd, /
nParam, /
pCmdData) /* Macro End */
例子:OMXSAFE(OMX_SendCommand(vrenderer, OMX_CommandPortEnable, 1, 0)); // 停下1對應的端口
OMX_SetupTunnel
將兩個組件連接起來,實際會引起調用每個組件的ComponentTunnelRequest
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_SetupTunnel(
OMX_IN OMX_HANDLETYPE hOutput,
OMX_IN OMX_U32 nPortOutput,
OMX_IN OMX_HANDLETYPE hInput,
OMX_IN OMX_U32 nPortInput);
例子:
OMXSAFE(OMX_SetupTunnel(reader, 0, vdecoder, 0)); // reader的0端口爲出,vdecoder的0端口爲入,連接成一個Tunnel
準備好後,就可以設置OMX_StateExecuting,來讓這個流程活動起來了。
再以後,就可以通過OMX_StateIdle 來停下。
OMX_GetState
#define OMX_GetState( /
hComponent, /
pState) /
((OMX_COMPONENTTYPE*)hComponent)->GetState( /
hComponent, /
pState) /* Macro End */
一些新補充:
1:
OMX_PARAM_PORTDEFINITIONTYPE decOutputPortDef;
INIT_PARAM(decOutputPortDef);
decOutputPortDef.nPortIndex = 0;
err = OMX_GetParameter(pCtx->hReaderComp,
OMX_IndexParamPortDefinition,
&decOutputPortDef); // 利用IndexParamPortDefinition來得到組件的輸出端口的屬性
videoWidth = decOutputPortDef.format.video.nFrameWidth;
videoHeight = decOutputPortDef.format.video.nFrameHeight;
2:OMX_BUFFERHEADERTYPE *pOmxBufferHeader ;
// tell decoder output port that it will be using our buffer
err = OMX_UseBuffer(hDecodeComp,
&pOmxBufferHeader, //out
OMX_DECODE_OUTPUT_PORT,
NULL,
outSize,
(NvU8*)pOut);
將分配好的pOut指針和他的大小outSize,配成一個OMX_BUF, 並給pOmxBufferHeader,這樣就通過OMX_UseBuffer,來得到一個以後能給他用的Buffer,指針用我們分配的。
3:
OMXErr = OMX_FillThisBuffer(hDecodeComp, pOmxBufferHeader);
讓hDecodeComp將pOmxBufferHeader的數據準備好(就是輸出數據),pOmxBufferHeader就是通過UseBuffer來組裝的。
通過nFilledLen,可以得到具體數據填充情況。
如果OMX_FillThisBuffer是異步函數的話,那真正的返回是要靠:Callback_FillBufferDone 來設置真正數據ready信號
4: