android OMX相关3:OMX命令发送处理流程

转载请注明:https://www.jianshu.com/p/55104d5935b2

RK3399

ACodec::LoadedState::onStart
-> mCodec->mOMXNode->sendCommand(OMX_CommandStateSet, OMX_StateIdle);
-> OMX_SendCommand(mHandle, cmd, param, NULL);    //mHandle 是 makeComponentInstance 中创建的对象
-> 通过函数指针调用  Rockchip_OMX_Basecomponent: Rockchip_OMX_SendCommand //根据命令来决定,命令为OMX_CommandStateSet
    -> Rockchip_StateSet(pRockchipComponent, nParam);
    -> Rockchip_OMX_CommandQueue(pRockchipComponent, Cmd, nParam, pCmdData) //把命令加入消息队列
        -> Rockchip_OMX_MessageHandlerThread 是消息处理线程,内部循环处理消息队列中的消息
        -> 因为cmd = OMX_CommandStateSet,所以调用  Rockchip_OMX_ComponentStateSet
        -> pRockchipComponent->rockchip_codec_componentInit(pOMXComponent); //Rkvpu_OMX_Venc.c
            ->调用函数指针 Rkvpu_Enc_ComponentInit
                -> omx_open_vpuenc_context(RKVPU_OMX_VIDEOENC_COMPONENT *pVideoEnc)
                -> 对参数pVideoEnc进行赋值
                    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
            -> 对 pVideoEnc的一些属性进行赋值
            -> 构建 p_vpu_ctx 进行赋值
                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); 
                调用libvpu.so中的函数,对一些变量进行赋值
                if (p_vpu_ctx->extra_cfg.reserved[0] == 1) {
                    omx_info("use vpuapi."); //根据log查知是走的这个分支
                    pVideoEnc->bIsUseMpp = OMX_FALSE;
                } else {
                    omx_info("use mpp.");
                    pVideoEnc->bIsUseMpp = OMX_TRUE;
                }
            -> Rkvpu_Enc_GetEncParams(pOMXComponent,&EncParam)
                这里根据pOMXComponent中存储的pVideoEnc去给EncParam赋值,编码器的各种属性,宽高,码率,帧率等
                EncParam = (EncParameter_t*)p_vpu_ctx->private_data;
                如下为实例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)
                这个init函数分析可能是在pVideoEnc->rkvpu_open_cxt(&p_vpu_ctx) 时,
                由rkvpu_open_cxt这个函数赋值的函数指针,可能在libvpu.so中
            -> Rockchip_OSAL_RGA_Process: rga_dev_open(&pVideoEnc->rga_ctx) 
                ->  open("/dev/rga", O_RDWR, 0) 
                    这里判断USE_DRM,两个分支都需要打开这个节点,暂不深究 ???
            -> 将构建的 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);
        -> 调用函数指针 Rkvpu_OMX_Venc: Rkvpu_OMX_BufferProcess_Create
        -> 创建output线程  Rockchip_OSAL_ThreadCreate(&pVideoEnc->hOutputThread, Rkvpu_OMX_OutputProcessThread, pOMXComponent);
        -> 创建input线程  Rockchip_OSAL_ThreadCreate(&pVideoEnc->hInputThread, Rkvpu_OMX_InputProcessThread, pOMXComponent);
        ->>> Rkvpu_OMX_BufferProcess_Create end
        ->>> Rockchip_OMX_MessageHandlerThread 本次消息处理完毕
    ->>>> Rockchip_StateSet end
->>>> OMX_SendCommand  end

你可能感兴趣的:(android OMX相关3:OMX命令发送处理流程)