轉(zhuǎn)載請(qǐng)注明:http://www.reibang.com/p/55104d5935b2
RK3399
ACodec::LoadedState::onStart
-> mCodec->mOMXNode->sendCommand(OMX_CommandStateSet, OMX_StateIdle);
-> OMX_SendCommand(mHandle, cmd, param, NULL); //mHandle 是 makeComponentInstance 中創(chuàng)建的對(duì)象
-> 通過(guò)函數(shù)指針調(diào)用 Rockchip_OMX_Basecomponent: Rockchip_OMX_SendCommand //根據(jù)命令來(lái)決定汰现,命令為OMX_CommandStateSet
-> Rockchip_StateSet(pRockchipComponent, nParam);
-> Rockchip_OMX_CommandQueue(pRockchipComponent, Cmd, nParam, pCmdData) //把命令加入消息隊(duì)列
-> Rockchip_OMX_MessageHandlerThread 是消息處理線程眼坏,內(nèi)部循環(huán)處理消息隊(duì)列中的消息
-> 因?yàn)閏md = OMX_CommandStateSet坚嗜,所以調(diào)用 Rockchip_OMX_ComponentStateSet
-> pRockchipComponent->rockchip_codec_componentInit(pOMXComponent); //Rkvpu_OMX_Venc.c
->調(diào)用函數(shù)指針 Rkvpu_Enc_ComponentInit
-> omx_open_vpuenc_context(RKVPU_OMX_VIDEOENC_COMPONENT *pVideoEnc)
-> 對(duì)參數(shù)pVideoEnc進(jìn)行賦值
pVideoEnc->rkapi_hdl = dlopen("libvpu.so")
pVideoEnc->rkvpu_open_cxt = (OMX_S32 (*)(VpuCodecContext_t **ctx))dlsym(pVideoEnc->rkapi_hdl, "vpu_open_context");
pVideoEnc->bIsNewVpu = OMX_TRUE;
pVideoEnc->rkvpu_close_cxt = (OMX_S32 (*)(VpuCodecContext_t **ctx))dlsym(pVideoEnc->rkapi_hdl, "vpu_close_context");
->>>> omx_open_vpuenc_context end
-> 對(duì) pVideoEnc的一些屬性進(jìn)行賦值
-> 構(gòu)建 p_vpu_ctx 進(jìn)行賦值
p_vpu_ctx = (VpuCodecContext_t *)Rockchip_OSAL_Malloc(sizeof(VpuCodecContext_t));
p_vpu_ctx->codecType = CODEC_ENCODER;
p_vpu_ctx->videoCoding = codecId;
p_vpu_ctx->width = pVideoEnc->bCurrent_width;
p_vpu_ctx->height = pVideoEnc->bCurrent_height;
-> pVideoEnc->rkvpu_open_cxt(&p_vpu_ctx);
調(diào)用libvpu.so中的函數(shù),對(duì)一些變量進(jìn)行賦值
if (p_vpu_ctx->extra_cfg.reserved[0] == 1) {
omx_info("use vpuapi."); //根據(jù)log查知是走的這個(gè)分支
pVideoEnc->bIsUseMpp = OMX_FALSE;
} else {
omx_info("use mpp.");
pVideoEnc->bIsUseMpp = OMX_TRUE;
}
-> Rkvpu_Enc_GetEncParams(pOMXComponent,&EncParam)
這里根據(jù)pOMXComponent中存儲(chǔ)的pVideoEnc去給EncParam賦值脏榆,編碼器的各種屬性,寬高拓春,碼率鸠匀,幀率等
EncParam = (EncParameter_t*)p_vpu_ctx->private_data;
如下為實(shí)例log:
ROCKCHIP_VIDEO_ENC: Rkvpu_Enc_GetEncParams(1549): encode params init settings:
ROCKCHIP_VIDEO_ENC: width = 1920
ROCKCHIP_VIDEO_ENC: height = 1080
ROCKCHIP_VIDEO_ENC: bitRate = 2621440
ROCKCHIP_VIDEO_ENC: framerate = 30
ROCKCHIP_VIDEO_ENC: format = 10
ROCKCHIP_VIDEO_ENC: enableCabac = 0,
ROCKCHIP_VIDEO_ENC: cabacInitIdc = 0,
ROCKCHIP_VIDEO_ENC: intraPicRate = 29,
ROCKCHIP_VIDEO_ENC: profileIdc = 66,
ROCKCHIP_VIDEO_ENC: levelIdc = 31,
ROCKCHIP_VIDEO_ENC: rc_mode = 1,
ROCKCHIP_VIDEO_ENC:
ROCKCHIP_VIDEO_ENC: Rkvpu_Enc_GetEncParams(1551): OUT
-> p_vpu_ctx->init(p_vpu_ctx, NULL, 0)
這個(gè)init函數(shù)分析可能是在pVideoEnc->rkvpu_open_cxt(&p_vpu_ctx) 時(shí),
由rkvpu_open_cxt這個(gè)函數(shù)賦值的函數(shù)指針椿争,可能在libvpu.so中
-> Rockchip_OSAL_RGA_Process: rga_dev_open(&pVideoEnc->rga_ctx)
-> open("/dev/rga", O_RDWR, 0)
這里判斷USE_DRM怕膛,兩個(gè)分支都需要打開(kāi)這個(gè)節(jié)點(diǎn),暫不深究 秦踪?褐捻?掸茅?
-> 將構(gòu)建的 p_vpu_ctx 保存到 pVideoEnc->vpu_ctx
pVideoEnc->bRgb2yuvFlag = OMX_FALSE;
pVideoEnc->bPixel_format = -1;
pVideoEnc->vpu_ctx = p_vpu_ctx;
->>>>rockchip_codec_componentInit end
-> pRockchipComponent->rockchip_BufferProcessCreate(pOMXComponent);
-> 調(diào)用函數(shù)指針 Rkvpu_OMX_Venc: Rkvpu_OMX_BufferProcess_Create
-> 創(chuàng)建output線程 Rockchip_OSAL_ThreadCreate(&pVideoEnc->hOutputThread, Rkvpu_OMX_OutputProcessThread, pOMXComponent);
-> 創(chuàng)建input線程 Rockchip_OSAL_ThreadCreate(&pVideoEnc->hInputThread, Rkvpu_OMX_InputProcessThread, pOMXComponent);
->>> Rkvpu_OMX_BufferProcess_Create end
->>> Rockchip_OMX_MessageHandlerThread 本次消息處理完畢
->>>> Rockchip_StateSet end
->>>> OMX_SendCommand end