Stagefright之二
——与Openmax一起工作
Stagefright的编解码功能是利用Openmax框架,而且用的还是Opencore的OMX组件,我们来看一下Stagefright和OMX是如何工作的。
(1) OMX_Init
OMXClient mClient; ……AwesomePlayer.cpp
AwesomePlayer::AwesomePlayer()
{
CHECK_EQ(mClient.connect(), OK);
}
status_t OMXClient::connect() ……OMXClient.cpp
{
mOMX = service->getOMX();
}
sp<IOMX> MediaPlayerService::getOMX() ……MediaPlayerService.cpp
{
mOMX = new OMX;
}
OMX::OMX() : mMaster(new OMXMaster) ……OMX.cpp
OMXMaster::OMXMaster() ……OMXMaster.cpp
{
addPlugin(new OMXPVCodecsPlugin);
}
OMXPVCodecsPlugin::OMXPVCodecsPlugin() ……OMXPVCodecsPlugin.cpp
{
OMX_MasterInit();
}
OMX_ERRORTYPE OMX_MasterInit() <-- under Opencore ……Pv_omxcore.cpp
(gingerbread 下,已移除Opencore代码)
{
return OMX_Init();
}
(2) OMX_SendCommand
OMXCodec::function_name() ……OMXCodec.cpp
{
mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);
}
status_t OMX::sendCommand(node, cmd, param) ……OMX.cpp
{
return findInstance(node)->sendCommand(cmd, param);
}
status_t OMXNodeInstance::sendCommand(cmd, param) ……OMXNodeInstance.cpp
{
OMX_SendCommand(mHandle, cmd, param, NULL);
}
****OMX_Core.h****
#define OMX_SendCommand( \
hComponent, \
Cmd, \
nParam, \
pCmdData) \
((OMX_COMPONENTTYPE*)hComponent)->SendCommand( \
hComponent, \
Cmd, \
nParam, \
pCmdData) /* Macro End */
(3) 其它作用在 OMX组件的指令
其它指令也和OMX_SendCommand的call path一样,请见下表:
OMXCodec | OMX | OMXNodeInstance |
| useBuffer | useBuffer (OMX_UseBuffer) |
| getParameter | getParameter (OMX_GetParameter) |
| fillBuffer | fillBuffer (OMX_FillThisBuffer) |
| emptyBuffer | emptyBuffer (OMX_EmptyThisBuffer) |
(4) Callback Functions
OMX_CALLBACKTYPE OMXNodeInstance::kCallbacks =
{
&OnEvent, <--------------- omx_message::EVENT
&OnEmptyBufferDone, <----- omx_message::EMPTY_BUFFER_DONE
&OnFillBufferDone <------- omx_message::FILL_BUFFER_DONE
}