Stagefright的編解碼功能是利用OpenMAX框架,而且用的還是OpenCORE之OMX的實作,我們 來看一下Stagefright和OMX是如何運作的。(1) OMX_InitOMXClient mClient;AwesomePlayer::AwesomePlayer(){ mClient.connect();}status_t OMXClient::connect(){ mOMX = service->getOMX();}sp<IOMX> MediaPlayerService::getOMX(){ mOMX = new OMX;}OMX::OMX() : mMaster(new OMXMaster)OMXMaster::OMXMaster(){ addPlugin(new OMXPVCodecsPlugin);}OMXPVCodecsPlugin::OMXPVCodecsPlugin(){ OMX_MasterInit();}OMX_ERRORTYPE OMX_MasterInit() <-- under OpenCORE{ return OMX_Init();}(2) OMX_SendCommandOMXCodec::function_name(){ mOMX->sendCommand(mNode, OMX_CommandStateSet, OMX_StateIdle);}status_t OMX::sendCommand(node, cmd, param){ return findInstance(node)->sendCommand(cmd, param);}status_t OMXNodeInstance::sendCommand(cmd, param){ OMX_SendCommand(mHandle, cmd, param, NULL);}(3) 其他作用在 OMX 元件的指令其他 作用在OMX元件的指令也和OMX_SendCommand的call path一樣,請見下表:
OMXCodecOMXOMXNodeInstance useBufferuseBuffer (OMX_UseBuffer) getParametergetParameter (OMX_GetParameter) fillBufferfillBuffer (OMX_FillThisBuffer) emptyBufferemptyBuffer (OMX_EmptyThisBuffer)
(4) Callback FunctionsOMX_CALLBACKTYPE OMXNodeInstance::kCallbacks ={ &OnEvent, <--------------- omx_message::EVENT &OnEmptyBufferDone, <----- omx_message::EMPTY_BUFFER_DONE &OnFillBufferDone <------- omx_message::FILL_BUFFER_DONE}