轉(zhuǎn)載請(qǐng)注明:http://www.reibang.com/p/0cb16c896c36
以RK3399為例
相關(guān)數(shù)據(jù)結(jié)構(gòu):
OMX::allocateNode -> new OMXNodeInstance
-> OMXMaster::makeComponentInstance -> 從名稱(chēng)插件map中查到名字對(duì)應(yīng)的插件 OMXPluginBase *plugin = mPluginByComponentName.valueAt(index) -> plugin->makeComponentInstance
-> RKOMXPlugin::makeComponentInstance 如果用到了插件libstagefrighthw.so
->對(duì)Vector<RKOMXCore*> mCores循環(huán) mCores存著編碼器和解碼器各一
-> 調(diào)用core->mGetHandle句柄
-> Rockchip_OMX_Core: RKOMX_GetHandle(pHandle, cComponentName, pAppData, pCallBacks)
創(chuàng)建ROCKCHIP_OMX_COMPONENT *loadComponent 對(duì)象,
loadComponent->libName = "libomxvpu_enc.so", loadComponent->componentName = "rk.omx_enc"
-> Rockchip_OMX_Component_Register: Rockchip_OMX_ComponentLoad(loadComponent)
-> dlopen(libomxvpu_enc.so) -> dlsym("Rockchip_OMX_ComponentConstructor") 對(duì)應(yīng)代碼位于hardware_rockchip\omx_il\component\video\enc
-> Rkvpu_OMX_Venc: Rockchip_OMX_ComponentConstructor
-> Rockchip_OMX_Basecomponent: Rockchip_OMX_BaseComponent_Constructor(OMX_HANDLETYPE hComponent)
->構(gòu)建變量ROCKCHIP_OMX_BASECOMPONENT *pRockchipComponent, pOMXComponent->pComponentPrivate=pRockchipComponent
->創(chuàng)建互斥量:Rockchip_OSAL_SemaphoreCreate(&pRockchipComponent->msgSemaphoreHandle),
Rockchip_OSAL_MutexCreate(&pRockchipComponent->compMutex),
Rockchip_OSAL_SignalCreate(&pRockchipComponent->abendStateEvent)
->Rockchip_OSAL_QueueCreate(&pRockchipComponent->messageQ, MAX_QUEUE_ELEMENTS);創(chuàng)建消息隊(duì)列
-> Rockchip_OSAL_ThreadCreate(&pRockchipComponent->hMessageHandler, Rockchip_OMX_MessageHandlerThread, pOMXComponent); 創(chuàng)建消息處理線(xiàn)程Rockchip_OMX_MessageHandlerThread
-> 設(shè)置幾個(gè)函數(shù)指針
pOMXComponent->GetComponentVersion = &Rockchip_OMX_GetComponentVersion;
pOMXComponent->SendCommand = &Rockchip_OMX_SendCommand; //用于給消息隊(duì)列發(fā)送指令
pOMXComponent->GetState = &Rockchip_OMX_GetState;
pOMXComponent->SetCallbacks = &Rockchip_OMX_SetCallbacks;
pOMXComponent->UseEGLImage = &Rockchip_OMX_UseEGLImage;
->>>>>>Rockchip_OMX_Basecomponent: Rockchip_OMX_BaseComponent_Constructor end
->Rockchip_OMX_Baseport: Rockchip_OMX_Port_Constructor(pOMXComponent)
-> pRockchipComponent = (ROCKCHIP_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate
-> 設(shè)置版本號(hào)恢着,port數(shù)量為ALL_PORT_NUM = 2染乌, INPUT_PORT_INDEX = 1
INIT_SET_SIZE_VERSION(&pRockchipComponent->portParam, OMX_PORT_PARAM_TYPE);
pRockchipComponent->portParam.nPorts = ALL_PORT_NUM;
pRockchipComponent->portParam.nStartPortNumber = INPUT_PORT_INDEX;
pRockchipPort = Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_BASEPORT) * ALL_PORT_NUM);
-> 構(gòu)建input port: pRockchipInputPort
pRockchipComponent->pRockchipPort = pRockchipPort; 利用中間變量創(chuàng)建兩個(gè)隊(duì)列
pRockchipInputPort = &pRockchipPort[INPUT_PORT_INDEX];
Rockchip_OSAL_QueueCreate(&pRockchipInputPort->bufferQ, MAX_QUEUE_ELEMENTS);
Rockchip_OSAL_QueueCreate(&pRockchipInputPort->securebufferQ, MAX_QUEUE_ELEMENTS);
pRockchipInputPort->extendBufferHeader = Rockchip_OSAL_Malloc(sizeof(ROCKCHIP_OMX_BUFFERHEADERTYPE) * MAX_BUFFER_NUM);
...
-> 構(gòu)建output buffer : pRockchipOutputPort
-> 給返回參數(shù)設(shè)置函數(shù)指針
pOMXComponent->EmptyThisBuffer = &Rockchip_OMX_EmptyThisBuffer;
pOMXComponent->FillThisBuffer = &Rockchip_OMX_FillThisBuffer;
->>>>>> Rockchip_OMX_Baseport: Rockchip_OMX_Port_Constructor end
->構(gòu)建對(duì)象 RKVPU_OMX_VIDEOENC_COMPONENT *pVideoEnc
->pVideoEnc->hSharedMemory 這個(gè)字段存著"/dev/ion" 這個(gè)文件的句柄
->設(shè)置 pRockchipComponent 的各種版本信息
pRockchipComponent->hComponentHandle = pVideoEnc(把上一步的共享內(nèi)存句柄賦值到這里)
pRockchipComponent->bMultiThreadProcess = OMX_TRUE;
pRockchipComponent->codecType = HW_VIDEO_ENC_CODEC;
-> 設(shè)置pVideoEnc的信息
pVideoEnc->bFirstFrame = OMX_TRUE;
pVideoEnc->bFirstInput = OMX_TRUE;
pVideoEnc->bFirstOutput = OMX_TRUE;
pVideoEnc->configChange = OMX_FALSE;
pVideoEnc->bStoreMetaData = OMX_FALSE;
pVideoEnc->bPrependSpsPpsToIdr = OMX_FALSE;
pVideoEnc->bRkWFD = OMX_FALSE;
pVideoEnc->quantization.nQpI = 4; // I frame quantization parameter
pVideoEnc->quantization.nQpP = 5; // P frame quantization parameter
pVideoEnc->quantization.nQpB = 5; // B frame quantization parameter
//add by xlm for use mpp or vpuapi
pVideoEnc->bIsUseMpp = OMX_FALSE;
pVideoEnc->bIsNewVpu = OMX_TRUE;
-> 初始化input port: pRockchipComponent->pRockchipPort[INPUT_PORT_INDEX]
一堆賦值操作
-> 初始化output port: pRockchipComponent->pRockchipPort[OUTPUT_PORT_INDEX]
一堆賦值操作
-> pOMXComponent 設(shè)置一堆函數(shù)指針
pOMXComponent->UseBuffer = &Rkvpu_OMX_UseBuffer;
pOMXComponent->AllocateBuffer = &Rkvpu_OMX_AllocateBuffer;
pOMXComponent->FreeBuffer = &Rkvpu_OMX_FreeBuffer;
pOMXComponent->ComponentTunnelRequest = &Rkvpu_OMX_ComponentTunnelRequest;
pOMXComponent->GetParameter = &Rkvpu_OMX_GetParameter;
pOMXComponent->SetParameter = &Rkvpu_OMX_SetParameter;
pOMXComponent->GetConfig = &Rkvpu_OMX_GetConfig;
pOMXComponent->SetConfig = &Rkvpu_OMX_SetConfig;
pOMXComponent->GetExtensionIndex = &Rkvpu_OMX_GetExtensionIndex;
pOMXComponent->ComponentRoleEnum = &Rkvpu_OMX_ComponentRoleEnum;
pOMXComponent->ComponentDeInit = &Rockchip_OMX_ComponentDeInit;
-> pRockchipComponent設(shè)置一堆函數(shù)指針
pRockchipComponent->rockchip_codec_componentInit = &Rkvpu_Enc_ComponentInit;
pRockchipComponent->rockchip_codec_componentTerminate = &Rkvpu_Enc_Terminate;
pRockchipComponent->rockchip_AllocateTunnelBuffer = &Rkvpu_OMX_AllocateTunnelBuffer;
pRockchipComponent->rockchip_FreeTunnelBuffer = &Rkvpu_OMX_FreeTunnelBuffer;
pRockchipComponent->rockchip_BufferProcessCreate = &Rkvpu_OMX_BufferProcess_Create; //注意這個(gè)函數(shù)指針,會(huì)啟動(dòng)兩個(gè)線(xiàn)程
pRockchipComponent->rockchip_BufferProcessTerminate = &Rkvpu_OMX_BufferProcess_Terminate;
pRockchipComponent->rockchip_BufferFlush = &Rkvpu_OMX_BufferFlush;
-> 為pVideoEnc中的AVCComponent數(shù)組設(shè)置參數(shù),????這里比較可疑,沒(méi)有生效
INIT_SET_SIZE_VERSION(&pVideoEnc->AVCComponent[i], OMX_VIDEO_PARAM_AVCTYPE);
pVideoEnc->AVCComponent[i].nPortIndex = i;
pVideoEnc->AVCComponent[i].eProfile = OMX_VIDEO_AVCProfileBaseline;
pVideoEnc->AVCComponent[i].eLevel = OMX_VIDEO_AVCLevel31;
pVideoEnc->AVCComponent[i].nPFrames = 20;
pVideoEnc->codecId = OMX_VIDEO_CodingAVC;
pRockchipPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
->設(shè)置狀態(tài)機(jī): pRockchipComponent->currentState = OMX_StateLoaded;
->>>>>>Rkvpu_OMX_Venc: Rockchip_OMX_ComponentConstructor end
->>>>>>Rockchip_OMX_Component_Register: Rockchip_OMX_ComponentLoad(loadComponent) end
rockchip_component 就是調(diào)用者傳進(jìn)的參數(shù)loadComponent
rockchip_component->libHandle = libHandle;
rockchip_component->pOMXComponent = pOMXComponent;
rockchip_component->rkversion = OMX_COMPILE_INFO;
-> loadComponent->pOMXComponent->SetCallbacks(loadComponent->pOMXComponent, pCallBacks, pAppData)
這里會(huì)設(shè)置一個(gè)回調(diào),回調(diào)函數(shù)是從OMX中創(chuàng)建的 OMXNodeInstance 對(duì)象的 kCallbacks
->>>>>> Rockchip_OMX_Core: RKOMX_GetHandle(pHandle, cComponentName, pAppData, pCallBacks) end
返回給調(diào)用者的 pHandle = loadComponent->pOMXComponent
-> 構(gòu)建 RKOMXComponent comp
comp.mComponent = *component //這里的component就是上一步RKOMX_GetHandle的參數(shù)pHandle
comp.mCore = mCores[i];
-> mComponents.push_back(comp); 把組件加入隊(duì)列
->>>> 循環(huán)結(jié)束
->>>> RKOMXPlugin::makeComponentInstance結(jié)束
-> instance->setHandle(handle) // instance是OMXNodeInstance對(duì)象绩卤,
這里把上面創(chuàng)建的OMX_COMPONENTTYPE *handle給賦值到OMXNodeInstance:mHandle
->>>> OMX::allocateNode結(jié)束