- static RK_S32 test_vi_bind_venc_loop(TEST_VI_CTX_S *ctx) {
- MPP_CHN_S stSrcChn, stDestChn[TEST_VENC_MAX];
- RK_S32 loopCount = 0;
- void *pData = RK_NULL;
- RK_S32 s32Ret = RK_FAILURE;
- RK_U32 i;
- RK_U32 u32DstCount = ((ctx->enMode == TEST_VI_MODE_BIND_VENC_MULTI) ? 2 : 1);
- /* vi init */
- // 0. get dev config status
- s32Ret = RK_MPI_VI_GetDevAttr(ctx->devId, &ctx->stDevAttr);
- if (s32Ret == RK_ERR_VI_NOT_CONFIG) {
- // 0-1.config dev
- s32Ret = RK_MPI_VI_SetDevAttr(ctx->devId, &ctx->stDevAttr);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("RK_MPI_VI_SetDevAttr %x", s32Ret);
- goto __FAILED1;
- }
- } else {
- RK_LOGE("RK_MPI_VI_SetDevAttr already");
- }
- // 1.get dev enable status
- s32Ret = RK_MPI_VI_GetDevIsEnable(ctx->devId);
- if (s32Ret != RK_SUCCESS) {
- // 1-2.enable dev
- s32Ret = RK_MPI_VI_EnableDev(ctx->devId);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("RK_MPI_VI_EnableDev %x", s32Ret);
- goto __FAILED1;
- }
- // 1-3.bind dev/pipe
- ctx->stBindPipe.u32Num = ctx->pipeId;
- ctx->stBindPipe.PipeId[0] = ctx->pipeId;
- s32Ret = RK_MPI_VI_SetDevBindPipe(ctx->devId, &ctx->stBindPipe);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("RK_MPI_VI_SetDevBindPipe %x", s32Ret);
- goto __FAILED2;
- }
- } else {
- RK_LOGE("RK_MPI_VI_EnableDev already");
- }
- // 2.config channel
- ctx->stChnAttr.stSize.u32Width = ctx->width;
- ctx->stChnAttr.stSize.u32Height = ctx->height;
- s32Ret = RK_MPI_VI_SetChnAttr(ctx->pipeId, ctx->channelId, &ctx->stChnAttr);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("RK_MPI_VI_SetChnAttr %x", s32Ret);
- goto __FAILED2;
- }
- // 3.enable channel
- s32Ret = RK_MPI_VI_EnableChn(ctx->pipeId, ctx->channelId);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("RK_MPI_VI_EnableChn %x", s32Ret);
- goto __FAILED2;
- }
- // 4.save debug file
- if (ctx->stDebugFile.bCfg) {
- s32Ret = RK_MPI_VI_ChnSaveFile(ctx->pipeId, ctx->channelId, &ctx->stDebugFile);
- RK_LOGD("RK_MPI_VI_ChnSaveFile %x", s32Ret);
- }
- /* venc */
- for (i = 0; i < u32DstCount; i++) {
- // venc init and create
- init_venc_cfg(ctx, i, RK_VIDEO_ID_AVC);
- s32Ret = create_venc(ctx, ctx->stVencCfg[i].s32ChnId);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("create %d ch venc failed", ctx->stVencCfg[i].s32ChnId);
- return s32Ret;
- }
- // bind vi to venc
- stSrcChn.enModId = RK_ID_VI;
- stSrcChn.s32DevId = ctx->devId;
- stSrcChn.s32ChnId = ctx->channelId;
- stDestChn[i].enModId = RK_ID_VENC;
- stDestChn[i].s32DevId = i;
- stDestChn[i].s32ChnId = ctx->stVencCfg[i].s32ChnId;
- s32Ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn[i]);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("create %d ch venc failed", ctx->stVencCfg[i].s32ChnId);
- goto __FAILED2;
- }
- ctx->stFrame[i].pstPack = reinterpret_cast(malloc(sizeof(VENC_PACK_S)));
- #if TEST_WITH_FD
- ctx->stVencCfg[i].selectFd = RK_MPI_VENC_GetFd(ctx->stVencCfg[i].s32ChnId);
- RK_LOGE("venc chn:%d, ctx->selectFd:%d ", ctx->stVencCfg[i].s32ChnId, ctx->stVencCfg[i].selectFd);
- #endif
- }
- // 不断地把码流写到pData中
- while (loopCount < ctx->loopCountSet) {
- for (i = 0; i < u32DstCount; i++) {
- #if TEST_WITH_FD
- test_vi_poll_event(-1, ctx->stVencCfg[i].selectFd);
- #endif
- s32Ret = RK_MPI_VENC_GetStream(ctx->stVencCfg[i].s32ChnId, &ctx->stFrame[i], -1); //获得编码码流
- if (s32Ret == RK_SUCCESS) {
- if (ctx->stVencCfg[i].bOutDebugCfg) {
- pData = RK_MPI_MB_Handle2VirAddr(ctx->stFrame[i].pstPack->pMbBlk);
- fwrite(pData, 1, ctx->stFrame[i].pstPack->u32Len, ctx->stVencCfg[i].fp);
- fflush(ctx->stVencCfg[i].fp);
- }
- RK_LOGE("chn:%d, loopCount:%d wd:%dn", i, loopCount, ctx->stFrame[i].pstPack->u32Len);
- s32Ret = RK_MPI_VENC_ReleaseStream(ctx->stVencCfg[i].s32ChnId, &ctx->stFrame[i]);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("RK_MPI_VENC_ReleaseStream fail %x", s32Ret);
- }
- loopCount++;
- } else {
- RK_LOGE("RK_MPI_VI_GetChnFrame fail %x", s32Ret);
- }
- }
- usleep(10*1000); // 写一次之后线程挂起10ms
- }
- for (i = 0; i < u32DstCount; i++) {
- s32Ret = RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn[i]);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("RK_MPI_SYS_UnBind fail %x", s32Ret);
- }
- }
- // 5. disable one chn
- s32Ret = RK_MPI_VI_DisableChn(ctx->pipeId, ctx->channelId);
- RK_LOGE("RK_MPI_VI_DisableChn %x", s32Ret);
- for (i = 0; i < u32DstCount; i++) {
- s32Ret = RK_MPI_VENC_StopRecvFrame(ctx->stVencCfg[i].s32ChnId);
- if (s32Ret != RK_SUCCESS) {
- return s32Ret;
- }
- RK_LOGE("destroy enc chn:%d", ctx->stVencCfg[i].s32ChnId);
- s32Ret = RK_MPI_VENC_DestroyChn(ctx->stVencCfg[i].s32ChnId);
- if (s32Ret != RK_SUCCESS) {
- RK_LOGE("RK_MPI_VDEC_DestroyChn fail %x", s32Ret);
- }
- }
- // 6.disable dev(will diabled all chn)
- __FAILED2:
- s32Ret = RK_MPI_VI_DisableDev(ctx->devId);
- RK_LOGE("RK_MPI_VI_DisableDev %x", s32Ret);
- __FAILED1:
- for (i = 0; i < u32DstCount; i++) {
- if (ctx->stFrame[i].pstPack)
- free(ctx->stFrame[i].pstPack);
- if (ctx->stVencCfg[i].fp)
- fclose(ctx->stVencCfg[i].fp);
- }
- return s32Ret;
- }
复制代码
这个是官方提供的vi+venc的功能模块 bind之后 查看日志发现while循环被固定成了0.1s 但是调了想到的所有参数都没用
|
|
2022-11-1 09:04:06
评论
举报
|
|
|