/****************************************************************************** * function : 1D1 User send pictures for H264 encode ******************************************************************************/ HI_S32 SAMPLE_VENC_1D1_USER_SEND_PICTURES(HI_VOID) { VB_CONF_S stVbConf; VENC_GRP VencGrp = 0; VENC_CHN VencChn = 0; PIC_SIZE_E enSize = PIC_D1; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize; SIZE_S stSize; VB_POOL hPool = VB_INVALID_POOLID; FILE *pfp_img = HI_NULL; HI_U32 u32PicLStride = 0; HI_U32 u32PicCStride = 0; HI_U32 u32LumaSize = 0; HI_U32 u32ChrmSize = 0; HI_U32 u32Cnt = 0; HI_U32 u32ChnCnt = 1; /****************************************** step 1: init variable ******************************************/ memset(&stVbConf,0,sizeof(VB_CONF_S)); u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\ enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.u32MaxPoolCnt = 128; /*ddr0 video buffer*/ stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = 10; memset(stVbConf.astCommPool[0].acMmzName,0, sizeof(stVbConf.astCommPool[0].acMmzName)); /****************************************** step 2: mpp system init. ******************************************/ s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("system init failed with %d!\n", s32Ret); goto END_VENC_USER_0; } /****************************************** step 3: open yuv file ******************************************/ if (pfp_img != HI_NULL) { fclose(pfp_img); pfp_img = HI_NULL; } pfp_img = fopen(SAMPLE_YUV_D1_FILEPATH, "rb" ); if (pfp_img == HI_NULL) { SAMPLE_PRT("Open yuv file failed!Check if the file %s exit\n",SAMPLE_YUV_D1_FILEPATH); goto END_VENC_USER_0; } /****************************************** step 4: create private pool on ddr0 ******************************************/ hPool = HI_MPI_VB_CreatePool( u32BlkSize, 10,NULL ); if (hPool == VB_INVALID_POOLID) { SAMPLE_PRT("HI_MPI_VB_CreatePool failed! \n"); goto END_VENC_USER_1; } /****************************************** step 5: encode process ******************************************/ s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n"); goto END_VENC_USER_2; } s32Ret = SAMPLE_COMM_VENC_Start(VencGrp, VencChn, PT_H264, gs_enNorm, enSize, SAMPLE_RC_CBR); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start snap failed!\n"); goto END_VENC_USER_2; } /****************************************** step 6: stream venc process -- get stream, then save it to file. ******************************************/ s32Ret = SAMPLE_COMM_VENC_StartGetStream(u32ChnCnt); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("StartGetStream failed!\n"); goto END_VENC_USER_3; } u32PicLStride = CEILING_2_POWER(stSize.u32Width, SAMPLE_SYS_ALIGN_WIDTH); u32PicCStride = CEILING_2_POWER(stSize.u32Width, SAMPLE_SYS_ALIGN_WIDTH); u32LumaSize = (u32PicLStride * stSize.u32Height); u32ChrmSize = (u32PicCStride * stSize.u32Height) >> 2; while(0 == feof(pfp_img)) { SAMPLE_MEMBUF_S stMem = {0}; VIDEO_FRAME_INFO_S stFrmInfo; stMem.hPool = hPool; u32Cnt ++; while((stMem.hBlock = HI_MPI_VB_GetBlock(stMem.hPool, u32BlkSize,NULL)) == VB_INVALID_HANDLE) { ; } stMem.u32PhyAddr = HI_MPI_VB_Handle2PhysAddr(stMem.hBlock); stMem.pVirAddr = (HI_U8 *) HI_MPI_SYS_Mmap( stMem.u32PhyAddr, u32BlkSize ); if(stMem.pVirAddr == NULL) { SAMPLE_PRT("Mem dev may not open\n"); goto END_VENC_USER_4; } memset(&stFrmInfo.stVFrame, 0, sizeof(VIDEO_FRAME_S)); stFrmInfo.stVFrame.u32PhyAddr[0] = stMem.u32PhyAddr; stFrmInfo.stVFrame.u32PhyAddr[1] = stFrmInfo.stVFrame.u32PhyAddr[0] + u32LumaSize; stFrmInfo.stVFrame.u32PhyAddr[2] = stFrmInfo.stVFrame.u32PhyAddr[1] + u32ChrmSize; stFrmInfo.stVFrame.pVirAddr[0] = stMem.pVirAddr; stFrmInfo.stVFrame.pVirAddr[1] = (HI_U8 *) stFrmInfo.stVFrame.pVirAddr[0] + u32LumaSize; stFrmInfo.stVFrame.pVirAddr[2] = (HI_U8 *) stFrmInfo.stVFrame.pVirAddr[1] + u32ChrmSize; stFrmInfo.stVFrame.u32Width = stSize.u32Width; stFrmInfo.stVFrame.u32Height = stSize.u32Height; stFrmInfo.stVFrame.u32Stride[0] = u32PicLStride; stFrmInfo.stVFrame.u32Stride[1] = u32PicLStride; stFrmInfo.stVFrame.u32Stride[2] = u32PicLStride; stFrmInfo.stVFrame.u64pts = (u32Cnt * 40); stFrmInfo.stVFrame.u32TimeRef = (u32Cnt * 2); /* Different channsel with different picture sequence */ SAMPLE_COMM_VENC_ReadOneFrame( pfp_img, stFrmInfo.stVFrame.pVirAddr[0], stFrmInfo.stVFrame.pVirAddr[1], stFrmInfo.stVFrame.pVirAddr[2], stFrmInfo.stVFrame.u32Width, stFrmInfo.stVFrame.u32Height, stFrmInfo.stVFrame.u32Stride[0], stFrmInfo.stVFrame.u32Stride[1] >> 1 ); SAMPLE_COMM_VENC_PlanToSemi( stFrmInfo.stVFrame.pVirAddr[0], stFrmInfo.stVFrame.u32Stride[0], stFrmInfo.stVFrame.pVirAddr[1], stFrmInfo.stVFrame.u32Stride[1], stFrmInfo.stVFrame.pVirAddr[2], stFrmInfo.stVFrame.u32Stride[1], stFrmInfo.stVFrame.u32Width, stFrmInfo.stVFrame.u32Height ); stFrmInfo.stVFrame.enPixelFormat = SAMPLE_PIXEL_FORMAT; stFrmInfo.stVFrame.u32Field = VIDEO_FIELD_FRAME; stMem.u32PoolId = HI_MPI_VB_Handle2PoolId( stMem.hBlock ); stFrmInfo.u32PoolId = stMem.u32PoolId; s32Ret = HI_MPI_VENC_SendFrame(VencGrp, &stFrmInfo); HI_MPI_SYS_Munmap( stMem.pVirAddr, u32BlkSize ); HI_MPI_VB_ReleaseBlock(stMem.hBlock); } /****************************************** step 7: exit process ******************************************/ END_VENC_USER_4: SAMPLE_COMM_VENC_StopGetStream(); END_VENC_USER_3: s32Ret = SAMPLE_COMM_VENC_Stop(VencGrp,VencChn);; if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Stop encode failed!\n"); goto END_VENC_USER_2; } END_VENC_USER_2: //before destroy private pool,must stop venc HI_MPI_VB_DestroyPool( hPool ); END_VENC_USER_1: //close the yuv file fclose( pfp_img ); pfp_img = HI_NULL; END_VENC_USER_0: //system exit SAMPLE_COMM_SYS_Exit(); return s32Ret; }
/****************************************************************************** * function : calculate VB Block size of picture. ******************************************************************************/ HI_U32 SAMPLE_COMM_SYS_CalcPicVbBlkSize(VIDEO_NORM_E enNorm, PIC_SIZE_E enPicSize, PIXEL_FORMAT_E enPixFmt, HI_U32 u32AlignWidth) { HI_S32 s32Ret = HI_FAILURE; SIZE_S stSize; s32Ret = SAMPLE_COMM_SYS_GetPicSize(enNorm, enPicSize, &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("get picture size[%d] failed!\n", enPicSize); return HI_FAILURE; } if (PIXEL_FORMAT_YUV_SEMIPLANAR_422 != enPixFmt && PIXEL_FORMAT_YUV_SEMIPLANAR_420 != enPixFmt) { SAMPLE_PRT("pixel format[%d] input failed!\n", enPixFmt); return HI_FAILURE; } if (16!=u32AlignWidth && 32!=u32AlignWidth && 64!=u32AlignWidth) { SAMPLE_PRT("system align width[%d] input failed!\n",\ u32AlignWidth); return HI_FAILURE; } //SAMPLE_PRT("w:%d, u32AlignWidth:%d\n", CEILING_2_POWER(stSize.u32Width,u32AlignWidth), u32AlignWidth); return (CEILING_2_POWER(stSize.u32Width, u32AlignWidth) * \ CEILING_2_POWER(stSize.u32Height,u32AlignWidth) * \ ((PIXEL_FORMAT_YUV_SEMIPLANAR_422 == enPixFmt)?2:1.5)); }
void ipcam_media_sys_ctrl_init_media_system(IpcamMediaSysCtrl *self) { VB_CONF_S stVbConf; MPP_SYS_CONF_S stSysConf = {0}; HI_S32 s32Ret = HI_FAILURE; memset(&stVbConf, 0, sizeof(VB_CONF_S)); stVbConf.u32MaxPoolCnt = VB_MAX_POOLS; stVbConf.astCommPool[0].u32BlkSize = (CEILING_2_POWER(IMAGE_MAX_WIDTH, SYS_ALIGN_WIDTH) * \ CEILING_2_POWER(IMAGE_MAX_HEIGHT, SYS_ALIGN_WIDTH) * \ 2); stVbConf.astCommPool[0].u32BlkCnt = 12; memset(stVbConf.astCommPool[0].acMmzName, 0, sizeof(stVbConf.astCommPool[0].acMmzName)); HI_MPI_SYS_Exit(); HI_MPI_VB_Exit(); s32Ret = HI_MPI_VB_SetConf(&stVbConf); if (HI_SUCCESS != s32Ret) { g_critical("HI_MPI_VB_SetConf failed with %#x!\n", s32Ret); return; } s32Ret = HI_MPI_VB_Init(); if (HI_SUCCESS != s32Ret) { g_critical("HI_MPI_VB_Init failed with %#x!\n", s32Ret); return; } stSysConf.u32AlignWidth = SYS_ALIGN_WIDTH; s32Ret = HI_MPI_SYS_SetConf(&stSysConf); if (HI_SUCCESS != s32Ret) { g_critical("HI_MPI_SYS_SetConf failed with %#x!\n", s32Ret); return; } s32Ret = HI_MPI_SYS_Init(); if (HI_SUCCESS != s32Ret) { g_critical("HI_MPI_SYS_Init failed with %#x!\n", s32Ret); return; } }
/****************************************************************************** * function : calculate VB Block size of Histogram. ******************************************************************************/ HI_U32 SAMPLE_COMM_SYS_CalcHistVbBlkSize(VIDEO_NORM_E enNorm, PIC_SIZE_E enPicSize, SIZE_S *pstHistBlkSize, HI_U32 u32AlignWidth) { HI_S32 s32Ret; SIZE_S stPicSize; s32Ret = SAMPLE_COMM_SYS_GetPicSize(enNorm, enPicSize, &stPicSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("get picture size[%d] failed!\n", enPicSize); return HI_FAILURE; } SAMPLE_PRT("stPicSize.u32Width%d,pstHistBlkSize->u32Width%d\n,stPicSize.u32Height%d,pstHistBlkSize->u32Height%d\n", stPicSize.u32Width,pstHistBlkSize->u32Width, stPicSize.u32Height,pstHistBlkSize->u32Height ); return (CEILING_2_POWER(44, u32AlignWidth)*CEILING_2_POWER(44, u32AlignWidth)*16*4); return HI_SUCCESS; }
/****************************************************************************** * function : VI: DC(720P); VO: SD0(CVBS). Embeded isp, phychn channel preview. ******************************************************************************/ HI_S32 SAMPLE_VIO_720P_PreView(SAMPLE_VI_CONFIG_S* pstViConfig) { HI_U32 u32ViChnCnt = 2; VB_CONF_S stVbConf; VO_DEV VoDev = SAMPLE_VO_DEV_DSD0;; VO_CHN VoChn = 0; VI_CHN ViChn = 0; VO_PUB_ATTR_S stVoPubAttr; SAMPLE_VO_MODE_E enVoMode = VO_MODE_1MUX; PIC_SIZE_E enPicSize = g_enPicSize; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize; SIZE_S stSize; ROTATE_E enRotate = ROTATE_NONE; /****************************************** step 1: init global variable ******************************************/ gs_u32ViFrmRate = (VIDEO_ENCODING_MODE_PAL == gs_enNorm)? 25: 30; memset(&stVbConf,0,sizeof(VB_CONF_S)); u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm, enPicSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.u32MaxPoolCnt = 128; /*ddr0 video buffer*/ stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = u32ViChnCnt * 8; /****************************************** step 2: start vpss and vi bind vpss (subchn needn't bind vpss in this mode) ******************************************/ s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enPicSize, &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n"); goto END_720P_1; } if(pstViConfig) { enRotate = pstViConfig->enRotate; if(ROTATE_90 == enRotate || ROTATE_270 == enRotate) { u32BlkSize = (CEILING_2_POWER(stSize.u32Width, SAMPLE_SYS_ALIGN_WIDTH) * \ CEILING_2_POWER(stSize.u32Height,SAMPLE_SYS_ALIGN_WIDTH) * \ ((PIXEL_FORMAT_YUV_SEMIPLANAR_422 == SAMPLE_PIXEL_FORMAT) ? 2 : 1.5)); stVbConf.astCommPool[1].u32BlkSize = u32BlkSize; stVbConf.astCommPool[1].u32BlkCnt = 8; } } /****************************************** step 3: mpp system init. ******************************************/ s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("system init failed with %d!\n", s32Ret); goto END_720P_0; } /****************************************** step 4: start vi dev & chn to capture ******************************************/ s32Ret = SAMPLE_COMM_VI_StartVi(pstViConfig); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("start vi failed!\n"); goto END_720P_0; } /****************************************** step 5: start VO SD0 (bind * vi ) ******************************************/ stVoPubAttr.enIntfType = g_enVoIntfType; if(VO_INTF_BT1120 == g_enVoIntfType) { stVoPubAttr.enIntfSync = VO_OUTPUT_720P50; gs_u32ViFrmRate = 50; } else { stVoPubAttr.enIntfSync = VO_OUTPUT_PAL; } stVoPubAttr.u32BgColor = 0x000000ff; /* In HD, this item should be set to HI_FALSE */ stVoPubAttr.bDoubleFrame = HI_FALSE; s32Ret = SAMPLE_COMM_VO_StartDevLayer(VoDev, &stVoPubAttr, gs_u32ViFrmRate); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_VO_StartDevLayer failed!\n"); goto END_720P_1; } s32Ret = SAMPLE_COMM_VO_StartChn(VoDev, &stVoPubAttr, enVoMode); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_VO_StartChn failed!\n"); goto END_720P_2; } s32Ret = SAMPLE_COMM_VO_BindVi(VoDev, VoChn, ViChn); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_VO_BindVi(vo:%d)-(vichn:%d) failed with %#x!\n", VoDev, VoChn, s32Ret); goto END_720P_3; } VI_PAUSE(); /****************************************** step 6: exit process ******************************************/ END_720P_3: SAMPLE_COMM_VO_UnBindVi(VoDev,VoChn); SAMPLE_COMM_VO_StopChn(VoDev, enVoMode); END_720P_2: SAMPLE_COMM_VO_StopDevLayer(VoDev); END_720P_1: SAMPLE_COMM_VI_StopVi(pstViConfig); END_720P_0: SAMPLE_COMM_SYS_Exit(); return s32Ret; }