/****************************************************************************** * 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 : 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; }
/****************************************************************************** * function : VI: DC(720P); VO: SD0(CVBS). Embeded isp, one ExtChn preview. ******************************************************************************/ HI_S32 SAMPLE_VIO_720P_LDC_Preview(SAMPLE_VI_CONFIG_S* pstViConfig) { HI_U32 u32ViChnCnt = 3; 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; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize; SIZE_S stSize; VI_LDC_ATTR_S stLDCAttr; PIC_SIZE_E enPicSize = g_enPicSize; /****************************************** 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: 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 3: 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; } stLDCAttr.bEnable = HI_TRUE; stLDCAttr.stAttr.enViewType = LDC_VIEW_TYPE_CROP; //LDC_VIEW_TYPE_CROP; LDC_VIEW_TYPE_ALL stLDCAttr.stAttr.s32CenterXOffset = 0; stLDCAttr.stAttr.s32CenterYOffset = 0; stLDCAttr.stAttr.s32Ratio = 255; HI_MPI_VI_SetLDCAttr(ViChn, &stLDCAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_SetLDCAttr failed!\n"); goto END_720P_1; } /****************************************** step 4: 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; } /****************************************** step 5: start VO SD0 (bind * vi ) ******************************************/ stVoPubAttr.enIntfType = g_enVoIntfType; if(VO_INTF_BT1120 == g_enVoIntfType) { stVoPubAttr.enIntfSync = VO_OUTPUT_720P50; } 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; } printf("press 'q' key to exit, other key to disable LDC!");; while(1) { char ch = getchar(); char ch1 = getchar(); if('q' == ch || 'q' == ch1) break; stLDCAttr.bEnable = !stLDCAttr.bEnable; HI_MPI_VI_SetLDCAttr(ViChn, &stLDCAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_SetLDCAttr failed!\n"); break; } if(stLDCAttr.bEnable) { printf("press 'q' key to exit, other key to disable LDC!\n"); } else { printf("press 'q' key to exit, other key to enable LDC!\n"); } } /****************************************** 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: s32Ret = HI_MPI_VI_DisableChn(ViChn); SAMPLE_COMM_VI_StopVi(pstViConfig); END_720P_0: SAMPLE_COMM_SYS_Exit(); return s32Ret; }
/****************************************************************************** * function : VI: DC(720P); VO: SD0(CVBS). Embeded isp, one ExtChn preview. ******************************************************************************/ HI_S32 SAMPLE_VIO_720P_Extchn_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; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize; SIZE_S stSize; VI_EXT_CHN_ATTR_S stExtChnAttr; VI_CHN ExtChn = 1; PIC_SIZE_E enPicSize = g_enPicSize; /****************************************** 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; u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm, PIC_D1, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.astCommPool[1].u32BlkSize = u32BlkSize; stVbConf.astCommPool[1].u32BlkCnt = 8; /****************************************** 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_720P_0; } /****************************************** step 3: 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; } stExtChnAttr.enPixFormat = SAMPLE_PIXEL_FORMAT; stExtChnAttr.s32BindChn = ViChn; stExtChnAttr.stDestSize.u32Width = 720; stExtChnAttr.stDestSize.u32Height = 576; stExtChnAttr.s32FrameRate = -1; stExtChnAttr.s32SrcFrameRate = -1; s32Ret = HI_MPI_VI_SetExtChnAttr(ExtChn, &stExtChnAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_SetExtChnAttr failed!\n"); goto END_720P_0; } s32Ret = HI_MPI_VI_EnableChn(ExtChn); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_EnableChn failed!\n"); goto END_720P_0; } /****************************************** step 4: 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; } /****************************************** step 5: start VO SD0 (bind * vi ) ******************************************/ stVoPubAttr.enIntfType = g_enVoIntfType; if(VO_INTF_BT1120 == g_enVoIntfType) { stVoPubAttr.enIntfSync = VO_OUTPUT_720P50; } 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, ExtChn); 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: s32Ret = HI_MPI_VI_DisableChn(ExtChn); SAMPLE_COMM_VI_StopVi(pstViConfig); END_720P_0: SAMPLE_COMM_SYS_Exit(); return s32Ret; }
int main(int argc, char const *argv[]) { VI_EXT_CHN_ATTR_S stExtChnAttr; VB_BLK hBlock; VB_POOL hPool = VB_INVALID_POOLID; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize, u32DstBlkSize; VIDEO_FRAME_INFO_S FrameInfo; IVE_HANDLE IveHandle; IVE_SRC_IMAGE_S stSrc; IVE_DST_IMAGE_S stDst; IVE_CSC_CTRL_S stCscCtrl; HI_BOOL bInstant = HI_TRUE; HI_BOOL bFinish; IplImage *iplImage; FILE *fp,*fp2; int k=1; #if 0 memset(&stVbConf, 0, sizeof(VB_CONF_S)); stVbConf.u32MaxPoolCnt = 128; SAMPLE_COMM_VI_GetSizeBySensor(&enSize); u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm, enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = 12; s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf); if (HI_SUCCESS != s32Ret) { printf("system init failed with err code %#x!\n", s32Ret ); } stViConfig.enViMode = SENSOR_TYPE; stViConfig.enRotate = ROTATE_NONE; stViConfig.enNorm = VIDEO_ENCODING_MODE_AUTO; stViConfig.enViChnSet = VI_CHN_SET_NORMAL; s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig); if (HI_SUCCESS != s32Ret) { printf("start vi failed with err code %#x!\n", s32Ret); // goto END_1; } #endif iplImage = cvCreateImageHeader(cvSize(WIDTH,HEIGHT), IPL_DEPTH_8U, 3); stExtChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; stExtChnAttr.s32BindChn = ViChn; stExtChnAttr.stDestSize.u32Width = WIDTH; stExtChnAttr.stDestSize.u32Height = HEIGHT; stExtChnAttr.s32DstFrameRate = -1; stExtChnAttr.s32SrcFrameRate = -1; stExtChnAttr.enCompressMode = COMPRESS_MODE_NONE; HI_MPI_VI_DisableChn(ExtChn); s32Ret = HI_MPI_VI_SetExtChnAttr(ExtChn, &stExtChnAttr); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_SetExtChnAttr failed with err code %#x\n", s32Ret); return -1; } s32Ret = HI_MPI_VI_SetFrameDepth(ExtChn, 1); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_SetFrameDepth failed with err code %#x\n", s32Ret); return -1; } stSrc.enType = IVE_IMAGE_TYPE_YUV420SP; //stDst.enType = IVE_IMAGE_TYPE_U8C3_PLANAR; stDst.enType = IVE_IMAGE_TYPE_U8C3_PACKAGE; stCscCtrl.enMode = IVE_CSC_MODE_PIC_BT709_YUV2RGB; #if 1 s32Ret = HI_MPI_VI_EnableChn(ExtChn); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_EnableChn failed with err code %#x\n", s32Ret); return -1; } #endif printf("begin\n"); det_t *pdet = det_open("bd_detect_trace.config"); while(k) { s32Ret = HI_MPI_VI_GetFrame(ExtChn, &FrameInfo, -1); if(HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_GetFrame failed with err code %#x!\n",s32Ret); } printf("get frame!\n"); u32DstBlkSize = FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height * 3; s32Ret = HI_MPI_SYS_MmzAlloc_Cached(&stDst.u32PhyAddr[0],(void**) &stDst.pu8VirAddr[0], "user", HI_NULL, u32DstBlkSize); HI_MPI_SYS_MmzFlushCache(stDst.u32PhyAddr[0], (void *)stDst.pu8VirAddr[0], u32DstBlkSize); #if 0 stDst.u32PhyAddr[1] = stDst.u32PhyAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stDst.u32PhyAddr[2] = stDst.u32PhyAddr[1] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stDst.pu8VirAddr[0] = (HI_U8*) HI_MPI_SYS_Mmap(stDst.u32PhyAddr[0], u32DstBlkSize); stDst.pu8VirAddr[1] = stDst.pu8VirAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stDst.pu8VirAddr[2] = stDst.pu8VirAddr[1] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stDst.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0]; stDst.u16Stride[1] = FrameInfo.stVFrame.u32Stride[0]; stDst.u16Stride[2] = FrameInfo.stVFrame.u32Stride[0]; stDst.u16Width = FrameInfo.stVFrame.u32Width; stDst.u16Height = FrameInfo.stVFrame.u32Height; #endif #if 1 stDst.pu8VirAddr[0] = (HI_U8*) HI_MPI_SYS_Mmap(stDst.u32PhyAddr[0], u32DstBlkSize); stDst.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0]; stDst.u16Width = FrameInfo.stVFrame.u32Width; stDst.u16Height = FrameInfo.stVFrame.u32Height; #endif stSrc.u32PhyAddr[0] = FrameInfo.stVFrame.u32PhyAddr[0]; stSrc.u32PhyAddr[1] = FrameInfo.stVFrame.u32PhyAddr[1]; stSrc.u32PhyAddr[2] = FrameInfo.stVFrame.u32PhyAddr[2]; stSrc.pu8VirAddr[0] = (HI_U8*)HI_MPI_SYS_Mmap(FrameInfo.stVFrame.u32PhyAddr[0], u32DstBlkSize / 2); stSrc.pu8VirAddr[1] = stSrc.pu8VirAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stSrc.pu8VirAddr[2] = stSrc.pu8VirAddr[1] + 1; stSrc.u16Stride[1] = FrameInfo.stVFrame.u32Stride[0]; stSrc.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0]; stSrc.u16Stride[2] = 0; stSrc.u16Width = FrameInfo.stVFrame.u32Width; stSrc.u16Height = FrameInfo.stVFrame.u32Height; #if 0 for(k = 0; k < 720 * 576 * 3 / 2;k++) *(stSrc.pu8VirAddr[0] + k) = 130; k = 0; #endif s32Ret = HI_MPI_IVE_CSC(&IveHandle, &stSrc, &stDst, &stCscCtrl, bInstant); if(s32Ret != HI_SUCCESS) { printf("HI_MPI_IVE_CSC failed with error code %#x\n",s32Ret); continue; } s32Ret = HI_MPI_IVE_Query(IveHandle, &bFinish, HI_TRUE); if(s32Ret != HI_SUCCESS) { printf("HI_MPI_IVE_Query failed with error code %#x\n",s32Ret); continue; } #if 0 fp = fopen("image.rgb","wb"); fwrite(stDst.pu8VirAddr[0], WIDTH * HEIGHT * 3, 1, fp); fclose(fp); fp2 = fopen("image2.yuv","wb"); fwrite(stSrc.pu8VirAddr[0], WIDTH * HEIGHT * 3 / 2, 1, fp2); fclose(fp2); #endif //printf("u16Width:%d,u16Height:%d\n",stDst.u16Width,stDst.u16Height); //printf("widthStep:%d\n",iplImage->widthStep); //cvSetData(iplImage, stDst.pu8VirAddr[0], iplImage->widthStep); //cvSaveImage("saveImage.jpg",iplImage); char *str = det_detect(pdet, HEIGHT, WIDTH, (char *)stDst.pu8VirAddr[0]); printf("%s\n",str); HI_MPI_SYS_Munmap(stDst.pu8VirAddr[0], u32DstBlkSize); HI_MPI_SYS_Munmap(stSrc.pu8VirAddr[0], u32DstBlkSize / 2); HI_MPI_SYS_MmzFree(stDst.u32PhyAddr[0], NULL); HI_MPI_VI_ReleaseFrame(ExtChn, &FrameInfo); } det_close(pdet); }
/****************************************************************************** * function : Start BT1120 720P vi/vo/venc ******************************************************************************/ HI_S32 SAMPLE_COMM_IVE_BT1120_720P_PreView(SAMPLE_IVE_VI_VO_CONFIG_S *pstViVoConfig, HI_BOOL bOpenVi,HI_BOOL bOpenViExt,HI_BOOL bOpenVo,HI_BOOL bOpenVenc,HI_BOOL bOpenVpss,HI_U32 u32VpssChnNum) { HI_U32 u32ViChnCnt = 1; VB_CONF_S stVbConf; VO_DEV VoDev = SAMPLE_VO_DEV_DSD0; VI_CHN ViChn = 0; VI_CHN ViExtChn = 1; VO_PUB_ATTR_S stVoPubAttr; SAMPLE_VO_MODE_E enVoMode = VO_MODE_1MUX; PIC_SIZE_E enPicSize = pstViVoConfig->enPicSize; VI_EXT_CHN_ATTR_S stExtChnAttr; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize; SIZE_S stSize; VO_LAYER VoLayer = 0; VO_VIDEO_LAYER_ATTR_S stLayerAttr; SAMPLE_VI_CONFIG_S *pstViConfig = &(pstViVoConfig->stViConfig); VENC_CHN VencChn = 0; HI_U32 u32ViDepth = 4; VI_CHN_ATTR_S stChnAttr; HI_U32 u32VpssGrpCnt = 1; VPSS_CHN aVpssChn[2] = {VPSS_CHN0, VPSS_CHN3}; VPSS_GRP_ATTR_S stVpssGrpAttr; SIZE_S astSize[2]; memset(&stVbConf,0,sizeof(VB_CONF_S)); u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(pstViVoConfig->enNorm, enPicSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.u32MaxPoolCnt = 64; /*ddr0 video buffer*/ stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = u32ViChnCnt * 3; if ((HI_TRUE == bOpenViExt) || (HI_TRUE == bOpenVpss)) { u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(pstViVoConfig->enNorm,PIC_CIF, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.astCommPool[1].u32BlkSize = u32BlkSize; stVbConf.astCommPool[1].u32BlkCnt = 3; } // mpp system init. s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_Init fail,Error(%#x)\n", s32Ret); goto END_720P_0; } if (HI_TRUE == bOpenVi) { s32Ret = SAMPLE_COMM_VI_StartVi(pstViConfig); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_VI_StartVi fail,Error(%#x)\n",s32Ret); goto END_720P_0; } s32Ret = HI_MPI_VI_SetFrameDepth(ViChn,u32ViDepth); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_SetFrameDepth fail,ViChn(%d),Error(%#x)\n",ViChn,s32Ret); goto END_720P_1; } s32Ret = HI_MPI_VI_GetChnAttr(ViChn,&stChnAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_GetChnAttr fail,ViChn(%d),Error(%#x)\n",ViChn,s32Ret); goto END_720P_1; } //Set Vi frame rate,because vi from BT1120 is 720P@30 stChnAttr.s32SrcFrameRate = 3; stChnAttr.s32DstFrameRate = 1; s32Ret = HI_MPI_VI_SetChnAttr(ViChn,&stChnAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_SetChnAttr,ViChn(%d),Error(%#x)\n",ViChn,s32Ret); goto END_720P_1; } } //Open vi ext chn if (HI_TRUE == bOpenViExt) { stExtChnAttr.enPixFormat = SAMPLE_PIXEL_FORMAT; stExtChnAttr.s32BindChn = ViChn; stExtChnAttr.stDestSize.u32Width = 352; stExtChnAttr.stDestSize.u32Height = 288; stExtChnAttr.s32DstFrameRate = -1; stExtChnAttr.s32SrcFrameRate = -1; stExtChnAttr.enCompressMode = COMPRESS_MODE_NONE; s32Ret = HI_MPI_VI_SetExtChnAttr(ViExtChn, &stExtChnAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_SetExtChnAttr fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret); goto END_720P_1; } s32Ret = HI_MPI_VI_EnableChn(ViExtChn); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_EnableChn fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret); goto END_720P_1; } s32Ret = HI_MPI_VI_SetFrameDepth(ViExtChn,u32ViDepth); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("HI_MPI_VI_SetFrameDepth fail,ViChn(%d),Error(%#x)\n",ViExtChn,s32Ret); goto END_720P_1; } } //Open vo if (HI_TRUE == bOpenVo) { s32Ret = SAMPLE_COMM_SYS_GetPicSize(pstViVoConfig->enNorm, enPicSize, &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize fail,Error(%#x)\n",s32Ret); goto END_720P_2; } stVoPubAttr.enIntfType = pstViVoConfig->enVoIntfType; //hi3518e Vo only suppurt pal //if(VO_INTF_BT1120 == pstViVoConfig->enVoIntfType) //{ // stVoPubAttr.enIntfSync = /*VO_OUTPUT_720P60*/VO_OUTPUT_1080P30; //} // if(SAMPLE_VI_MODE_BT1120_1080P == pstViVoConfig->stViConfig.enViMode) // { // stVoPubAttr.enIntfSync = VO_OUTPUT_1080P30; // } //else if(SAMPLE_VI_MODE_BT1120_720P == pstViVoConfig->stViConfig.enViMode) // { // stVoPubAttr.enIntfSync = VO_OUTPUT_720P60; // } // else { stVoPubAttr.enIntfSync = VO_OUTPUT_PAL; } stVoPubAttr.u32BgColor = 0x000000ff; /* In HD, this item should be set to HI_FALSE */ s32Ret = SAMPLE_COMM_VO_StartDev(VoDev, &stVoPubAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_VO_StartDevLayer fail,VoDev(%d),Error(%#x)!\n",VoDev,s32Ret); goto END_720P_2; } stLayerAttr.bClusterMode = HI_FALSE; stLayerAttr.bDoubleFrame = HI_FALSE; stLayerAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; memcpy(&stLayerAttr.stImageSize,&stSize,sizeof(stSize)); stLayerAttr.u32DispFrmRt = 60 ; stLayerAttr.stDispRect.s32X = 0; stLayerAttr.stDispRect.s32Y = 0; if((stVoPubAttr.enIntfSync == VO_OUTPUT_720P60) || (stVoPubAttr.enIntfSync == VO_OUTPUT_1080P30)) { stLayerAttr.stDispRect.u32Width = stSize.u32Width; stLayerAttr.stDispRect.u32Height = stSize.u32Height; } else if(stVoPubAttr.enIntfSync == VO_OUTPUT_PAL) { stLayerAttr.stDispRect.u32Width = 720; stLayerAttr.stDispRect.u32Height = 576; } s32Ret = SAMPLE_COMM_VO_StartLayer(VoLayer, &stLayerAttr, HI_TRUE); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_VO_StartLayer fail,VoLayer(%d),Error(%#x)\n",VoLayer,s32Ret); goto END_720P_3; } s32Ret = SAMPLE_COMM_VO_StartChn(VoDev, enVoMode); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_VO_StartChn fail,VoDev(%d),Error(%#x)\n",VoDev,s32Ret); goto END_720P_4; } } if (HI_TRUE == bOpenVenc) { s32Ret = SAMPLE_COMM_VENC_Start(VencChn, PT_H264, pstViVoConfig->enNorm, enPicSize, SAMPLE_RC_CBR,0); if(s32Ret != HI_SUCCESS) { SAMPLE_PRT("SAMPLE_COMM_VENC_Start fail,VencChn(%d),Error(%#x)\n",VencChn,s32Ret); goto END_720P_5; } s32Ret = SAMPLE_COMM_VENC_StartGetStream(1); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_VENC_StartGetStream fail,Error(%#x)\n",s32Ret); goto END_720P_6; } } if (HI_TRUE == bOpenVpss) { s32Ret = SAMPLE_COMM_SYS_GetPicSize(pstViVoConfig->enNorm, enPicSize, &astSize[0]); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize fail,Error(%#x)\n",s32Ret); goto END_720P_6; } astSize[1].u32Width = 352; astSize[1].u32Height = 288; SAMPLE_COMM_IVE_VpssGrpAttr(u32VpssGrpCnt, &stVpssGrpAttr, &stSize); s32Ret = SAMPLE_COMM_IVE_VpssStart(u32VpssGrpCnt, astSize, aVpssChn, u32VpssChnNum, &stVpssGrpAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_IVE_VpssStart fail,Error(%#x)\n",s32Ret); goto END_720P_6; } } return s32Ret; //END_720P_7: //if (HI_TRUE == bOpenVpss) //{ // SAMPLE_COMM_IVE_StopVpss(u32VpssGrpCnt,u32VpssChnNum); //} END_720P_6: if (HI_TRUE == bOpenVenc) { SAMPLE_COMM_VENC_Stop(VencChn); } END_720P_5: if (HI_TRUE == bOpenVo) { SAMPLE_COMM_VO_StopChn(VoDev, enVoMode); } END_720P_4: if (HI_TRUE == bOpenVo) { SAMPLE_COMM_VO_StopLayer(VoLayer); } END_720P_3: if (HI_TRUE == bOpenVo) { SAMPLE_COMM_VO_StopDev(VoDev); } END_720P_2: if(HI_TRUE == bOpenViExt) { (HI_VOID)HI_MPI_VI_DisableChn(ViExtChn); } END_720P_1: if (HI_TRUE == bOpenVi) { SAMPLE_COMM_VI_StopVi(pstViConfig); } END_720P_0: SAMPLE_COMM_SYS_Exit(); return s32Ret; }
/****************************************************************************** * function : 16*Cif SNAP ******************************************************************************/ HI_S32 SAMPLE_VENC_8_Cif_Snap(HI_VOID) { SAMPLE_VI_MODE_E enViMode = SAMPLE_VI_MODE_8_2Cif; HI_U32 u32ViChnCnt = 8; HI_S32 s32VpssGrpCnt = 8; PIC_SIZE_E enSize = PIC_2CIF; VB_CONF_S stVbConf; VPSS_GRP VpssGrp; VPSS_GRP_ATTR_S stGrpAttr; VENC_GRP VencGrp; VENC_CHN VencChn; HI_S32 i; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize; SIZE_S stSize; /****************************************** 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; /* video buffer*/ stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = u32ViChnCnt * 6; memset(stVbConf.astCommPool[0].acMmzName,0, sizeof(stVbConf.astCommPool[0].acMmzName)); /* hist buf*/ stVbConf.astCommPool[1].u32BlkSize = (196*4); stVbConf.astCommPool[1].u32BlkCnt = u32ViChnCnt * 6; memset(stVbConf.astCommPool[1].acMmzName,0, sizeof(stVbConf.astCommPool[1].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_SNAP_0; } /****************************************** step 3: start vi dev & chn to capture ******************************************/ s32Ret = SAMPLE_COMM_VI_Start(enViMode, gs_enNorm); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("start vi failed!\n"); goto END_VENC_SNAP_0; } /****************************************** step 4: start vpss and vi bind vpss ******************************************/ s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n"); goto END_VENC_SNAP_0; } stGrpAttr.u32MaxW = stSize.u32Width; stGrpAttr.u32MaxH = stSize.u32Height; stGrpAttr.bDrEn = HI_FALSE; stGrpAttr.bDbEn = HI_FALSE; stGrpAttr.bIeEn = HI_TRUE; stGrpAttr.bNrEn = HI_TRUE; stGrpAttr.bHistEn = HI_TRUE; stGrpAttr.enDieMode = VPSS_DIE_MODE_AUTO; stGrpAttr.enPixFmt = SAMPLE_PIXEL_FORMAT; s32Ret = SAMPLE_COMM_VPSS_Start(s32VpssGrpCnt, &stSize, VPSS_MAX_CHN_NUM,NULL); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Vpss failed!\n"); goto END_VENC_SNAP_1; } s32Ret = SAMPLE_COMM_VI_BindVpss(enViMode); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Vi bind Vpss failed!\n"); goto END_VENC_SNAP_2; } /****************************************** step 5: snap process ******************************************/ VencGrp = 0; VencChn = 0; /*snap Cif pic*/ s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, PIC_CIF, &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n"); goto END_VENC_SNAP_0; } s32Ret = SAMPLE_COMM_VENC_SnapStart(VencGrp, VencChn, &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start snap failed!\n"); goto END_VENC_SNAP_3; } for (i=0; i<u32ViChnCnt; i++) { /*** main frame **/ VpssGrp = i; s32Ret = SAMPLE_COMM_VENC_SnapProcess(VencGrp, VencChn, VpssGrp, VPSS_PRE0_CHN); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("snap process failed!\n"); goto END_VENC_SNAP_4; } printf("snap chn %d ok!\n", i); sleep(1); } /****************************************** step 8: exit process ******************************************/ printf("snap over!\n"); END_VENC_SNAP_4: s32Ret = SAMPLE_COMM_VENC_SnapStop(VencGrp, VencChn); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Stop snap failed!\n"); goto END_VENC_SNAP_3; } END_VENC_SNAP_3: SAMPLE_COMM_VI_UnBindVpss(enViMode); END_VENC_SNAP_2: //vpss stop SAMPLE_COMM_VPSS_Stop(s32VpssGrpCnt, VPSS_MAX_CHN_NUM); END_VENC_SNAP_1: //vi stop SAMPLE_COMM_VI_Stop(enViMode); END_VENC_SNAP_0: //system exit SAMPLE_COMM_SYS_Exit(); return s32Ret; }
/****************************************************************************** * function : 4D1 H264 encode ******************************************************************************/ HI_S32 SAMPLE_VENC_4D1_H264(HI_VOID) { SAMPLE_VI_MODE_E enViMode = SAMPLE_VI_MODE_4_D1; HI_U32 u32ViChnCnt = 4; HI_S32 s32VpssGrpCnt = 4; PAYLOAD_TYPE_E enPayLoad[2]= {PT_H264, PT_H264}; PIC_SIZE_E enSize[2] = {PIC_D1, PIC_CIF}; VB_CONF_S stVbConf; VPSS_GRP VpssGrp; VPSS_CHN VpssChn; VPSS_GRP_ATTR_S stGrpAttr; VENC_GRP VencGrp; VENC_CHN VencChn; SAMPLE_RC_E enRcMode; HI_S32 i; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize; HI_CHAR ch; SIZE_S stSize; /****************************************** step 1: init variable ******************************************/ memset(&stVbConf,0,sizeof(VB_CONF_S)); u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm,\ PIC_D1, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.u32MaxPoolCnt = 128; stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = u32ViChnCnt * 6; memset(stVbConf.astCommPool[0].acMmzName,0, sizeof(stVbConf.astCommPool[0].acMmzName)); /* hist buf*/ stVbConf.astCommPool[1].u32BlkSize = (196*4); stVbConf.astCommPool[1].u32BlkCnt = u32ViChnCnt * 6; memset(stVbConf.astCommPool[1].acMmzName,0, sizeof(stVbConf.astCommPool[1].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_8D1_0; } /****************************************** step 3: start vi dev & chn to capture ******************************************/ s32Ret = SAMPLE_COMM_VI_Start(enViMode, gs_enNorm); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("start vi failed!\n"); goto END_VENC_8D1_0; } /****************************************** step 4: start vpss and vi bind vpss ******************************************/ s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, PIC_D1, &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n"); goto END_VENC_8D1_0; } stGrpAttr.u32MaxW = stSize.u32Width; stGrpAttr.u32MaxH = stSize.u32Height; stGrpAttr.bDrEn = HI_FALSE; stGrpAttr.bDbEn = HI_FALSE; stGrpAttr.bIeEn = HI_TRUE; stGrpAttr.bNrEn = HI_TRUE; stGrpAttr.bHistEn = HI_TRUE; stGrpAttr.enDieMode = VPSS_DIE_MODE_AUTO; stGrpAttr.enPixFmt = SAMPLE_PIXEL_FORMAT; s32Ret = SAMPLE_COMM_VPSS_Start(s32VpssGrpCnt, &stSize, VPSS_MAX_CHN_NUM,NULL); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Vpss failed!\n"); goto END_VENC_8D1_1; } s32Ret = SAMPLE_COMM_VI_BindVpss(enViMode); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Vi bind Vpss failed!\n"); goto END_VENC_8D1_2; } /****************************************** step 5: select rc mode ******************************************/ while(1) { printf("please choose rc mode:\n"); printf("\t0) CBR\n"); printf("\t1) VBR\n"); printf("\t2) FIXQP\n"); ch = getchar(); getchar(); if ('0' == ch) { enRcMode = SAMPLE_RC_CBR; break; } else if ('1' == ch) { enRcMode = SAMPLE_RC_VBR; break; } else if ('2' == ch) { enRcMode = SAMPLE_RC_FIXQP; break; } else { printf("rc mode invaild! please try again.\n"); continue; } } /****************************************** step 5: start stream venc (big + little) ******************************************/ for (i=0; i<u32ViChnCnt; i++) { /*** main stream **/ VencGrp = i*2; VencChn = i*2; VpssGrp = i; s32Ret = SAMPLE_COMM_VENC_Start(VencGrp, VencChn, enPayLoad[0],\ gs_enNorm, enSize[0], enRcMode); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_8D1_2; } s32Ret = SAMPLE_COMM_VENC_BindVpss(VencGrp, VpssGrp, VPSS_BSTR_CHN); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_8D1_3; } /*** Sub stream **/ VencGrp ++; VencChn ++; s32Ret = SAMPLE_COMM_VENC_Start(VencGrp, VencChn, enPayLoad[1], \ gs_enNorm, enSize[1], enRcMode); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_8D1_3; } s32Ret = SAMPLE_COMM_VENC_BindVpss(VencChn, VpssGrp, VPSS_PRE0_CHN); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_8D1_3; } } /****************************************** step 6: stream venc process -- get stream, then save it to file. ******************************************/ s32Ret = SAMPLE_COMM_VENC_StartGetStream(u32ViChnCnt*2); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT("Start Venc failed!\n"); goto END_VENC_8D1_3; } printf("please press twice ENTER to exit this sample\n"); getchar(); getchar(); /****************************************** step 7: exit process ******************************************/ SAMPLE_COMM_VENC_StopGetStream(); END_VENC_8D1_3: for (i=0; i<u32ViChnCnt*2; i++) { VencGrp = i; VencChn = i; VpssGrp = i/2; VpssChn = (VpssGrp%2)?VPSS_PRE0_CHN:VPSS_BSTR_CHN; SAMPLE_COMM_VENC_UnBindVpss(VencGrp, VpssGrp, VpssChn); SAMPLE_COMM_VENC_Stop(VencGrp,VencChn); } SAMPLE_COMM_VI_UnBindVpss(enViMode); END_VENC_8D1_2: //vpss stop SAMPLE_COMM_VPSS_Stop(s32VpssGrpCnt, VPSS_MAX_CHN_NUM); END_VENC_8D1_1: //vi stop SAMPLE_COMM_VI_Stop(enViMode); END_VENC_8D1_0: //system exit SAMPLE_COMM_SYS_Exit(); return s32Ret; }
int main(int argc, char const *argv[]) { PAYLOAD_TYPE_E enPayLoad = PT_H264; VB_CONF_S stVbConf; SAMPLE_VI_CONFIG_S stViConfig; VPSS_GRP_ATTR_S stVpssGrpAttr; VPSS_CHN_ATTR_S stVpssChnAttr; VPSS_CHN_MODE_S stVpssChnMode; VI_EXT_CHN_ATTR_S stExtChnAttr; SAMPLE_RC_E enRcMode = SAMPLE_RC_CBR; HI_S32 s32ChnNum = 1; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize; SIZE_S stSize; int sockfd, SendSockfd; struct sockaddr_in SendServaddr; pthread_t sendvideotid, AnalyzePictid, snaptid, accepttid; int ret; MPP_CHN_S stSrcChn; MPP_CHN_S stDestChn; memset(&stVbConf, 0 , sizeof(VB_CONF_S)); stVbConf.u32MaxPoolCnt = 128; u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm, enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = 10; // u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm, // PIC_QVGA, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); // stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; // stVbConf.astCommPool[0].u32BlkCnt = 10; //初始化系统 printf("-----------------------V0.01-----------------------\n"); s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf); if (HI_SUCCESS != s32Ret) { printf("system init failed with err code %#x!\n", s32Ret ); } stViConfig.enViMode = SENSOR_TYPE; //stViConfig.enViMode = SONY_IMX122_DC_1080P_30FPS; stViConfig.enRotate = ROTATE_NONE; stViConfig.enNorm = VIDEO_ENCODING_MODE_AUTO; stViConfig.enViChnSet = VI_CHN_SET_NORMAL; //配置并启动VI s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig); if (HI_SUCCESS != s32Ret) { printf("start vi failed with err code %#x!\n", s32Ret); goto END_1; } stExtChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; stExtChnAttr.s32BindChn = ViChn; stExtChnAttr.stDestSize.u32Width = WIDTH; stExtChnAttr.stDestSize.u32Height = HEIGHT; stExtChnAttr.s32FrameRate = -1; stExtChnAttr.s32SrcFrameRate = -1; s32Ret = HI_MPI_VI_SetExtChnAttr(ExtChn, &stExtChnAttr); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_SetExtChnAttr failed with err code %#x\n", s32Ret); return -1; } s32Ret = HI_MPI_VI_SetFrameDepth(1, 5); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_SetFrameDepth failed with err code %#x\n", s32Ret); return -1; } s32Ret = HI_MPI_VI_EnableChn(ExtChn); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_EnableChn failed with err code %#x\n", s32Ret); return -1; } stExtChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; stExtChnAttr.s32BindChn = ViChn; stExtChnAttr.stDestSize.u32Width = WIDTH; stExtChnAttr.stDestSize.u32Height = HEIGHT; stExtChnAttr.s32FrameRate = -1; stExtChnAttr.s32SrcFrameRate = -1; s32Ret = HI_MPI_VI_SetExtChnAttr(SnapExtChn, &stExtChnAttr); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_SetExtChnAttr failed with err code %#x\n", s32Ret); return -1; } s32Ret = HI_MPI_VI_EnableChn(SnapExtChn); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_EnableChn failed with err code %#x\n", s32Ret); return -1; } #if 1 s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize); if (HI_SUCCESS != s32Ret) { printf("SAMPLE_COMM_SYS_GetPicSize failed with err code %#x!\n", s32Ret); goto END_2; } //配置并启动VPSS组 stVpssGrpAttr.u32MaxW = stSize.u32Width; stVpssGrpAttr.u32MaxH = stSize.u32Height; stVpssGrpAttr.bDrEn = HI_FALSE; stVpssGrpAttr.bDbEn = HI_FALSE; stVpssGrpAttr.bIeEn = HI_TRUE; stVpssGrpAttr.bNrEn = HI_TRUE; stVpssGrpAttr.bHistEn = HI_TRUE; stVpssGrpAttr.enDieMode = VPSS_DIE_MODE_AUTO; stVpssGrpAttr.enPixFmt = SAMPLE_PIXEL_FORMAT; s32Ret = SAMPLE_COMM_VPSS_StartGroup(VpssGrp, &stVpssGrpAttr); if (HI_SUCCESS != s32Ret) { printf("SAMPLE_COMM_VPSS_StartGroup failed with err code %#x!\n", s32Ret); goto END_3; } //绑定VI和VPSS s32Ret = SAMPLE_COMM_VI_BindVpss(stViConfig.enViMode); if (HI_SUCCESS != s32Ret) { printf("SAMPLE_COMM_vi_BindVpss failed with err code %#x\n", s32Ret); goto END_4; } //配置并启动VPSS通道 memset(&stVpssChnAttr, 0, sizeof(stVpssChnAttr)); stVpssChnAttr.bFrameEn = HI_FALSE; stVpssChnAttr.bSpEn = HI_TRUE; stVpssChnMode.enChnMode = VPSS_CHN_MODE_USER; stVpssChnMode.bDouble = HI_FALSE; stVpssChnMode.enPixelFormat = SAMPLE_PIXEL_FORMAT; stVpssChnMode.u32Width = 1920; stVpssChnMode.u32Height = 1080; s32Ret = SAMPLE_COMM_VPSS_EnableChn(VpssGrp, VpssChn, &stVpssChnAttr, &stVpssChnMode, HI_NULL); if (HI_SUCCESS != s32Ret) { printf("SAMPLE_COMM_VPSS_EnableChn failed with err code %#x\n", s32Ret); goto END_5; } #if 0 s32Ret = SAMPLE_COMM_VENC_BindVpss(SnapVencGrp, VpssGrp, VpssChn); if (HI_SUCCESS != s32Ret) { printf("SAMPLE_COMM_VENC_BindVpss failed with err code %#x\n", s32Ret); } gs_enNorm = PIC_D1; s32Ret = SAMPLE_COMM_SYS_GetPicSize(gs_enNorm, enSize, &stSize); if (HI_SUCCESS != s32Ret) { printf("SAMPLE_COMM_SYS_GetPicSize failed with err code %#x\n", s32Ret); } #endif #endif stSrcChn.enModId = HI_ID_VIU; stSrcChn.s32DevId = 0; stSrcChn.s32ChnId = SnapExtChn; stDestChn.enModId = HI_ID_GROUP; stDestChn.s32DevId = SnapVencGrp; stDestChn.s32ChnId = 0; s32Ret = HI_MPI_SYS_Bind(&stSrcChn, &stDestChn); if (s32Ret != HI_SUCCESS) { SAMPLE_PRT("failed with %#x!\n", s32Ret); //return HI_FAILURE; } stSize.u32Width = 720; stSize.u32Height = 576; //printf("%d,%d\n",stSize.u32Width,stSize.u32Height); s32Ret = SAMPLE_COMM_VENC_SnapStart(SnapVencGrp, SnapVencChn, &stSize); if (HI_SUCCESS != s32Ret) { printf("SAMPLE_COMM_VENC_SnapStart failed with err code %#x\n", s32Ret); } #if 1 #if 0 //创建发送视频流socket //SendSockfd = socket(AF_INET, SOCK_STREAM, 0); SendSockfd = socket(AF_INET, SOCK_DGRAM, 0); if (SendSockfd == -1) { perror("send socket error"); exit(0); } memset(&SendServaddr, 0, sizeof(SendServaddr)); SendServaddr.sin_family = AF_INET; //SendServaddr.sin_addr.s_addr = htonl(INADDR_ANY); SendServaddr.sin_addr.s_addr = inet_addr("10.1.2.60"); SendServaddr.sin_port = htons(6666); #endif #if 0 if (bind(SendSockfd, (struct sockaddr *)&SendServaddr, sizeof(SendServaddr)) == -1) { perror("send bind error"); exit(0); } if (listen(SendSockfd, 10) == -1) { perror("send listen error"); exit(0); } #endif #if 0 //ret = pthread_create(&sendvideotid, 0, (HI_VOID*)SendVideoStream, SendSockfd); ret = pthread_create(&sendvideotid, 0, (HI_VOID*)SendVideoStream, 0); if (ret != 0) { perror("create SendVideoStream error"); exit(0); } printf("create SendVideoStream thread successfully!\n"); #endif #endif ret = pthread_create(&AnalyzePictid, 0, (HI_VOID*)AnalyzePic, NULL); if (ret != 0) { perror("create AnalyzePic error"); exit(0); } ret = pthread_create(&snaptid, 0, (HI_VOID*)SnapPic, NULL); if (ret != 0) { perror("create SnapPic error"); exit(0); } ret = pthread_create(&accepttid, 0, (HI_VOID*)accept_thread, NULL); if (ret != 0) { perror("create accept_thread error"); exit(0); } while (1) { sleep(10); } END_5: SAMPLE_COMM_VPSS_DisableChn(VpssGrp, VpssChn); END_4: SAMPLE_COMM_VI_UnBindVpss(stViConfig.enViMode); END_3: SAMPLE_COMM_VPSS_StopGroup(VpssGrp); END_2: SAMPLE_COMM_VI_StopVi(&stViConfig); END_1: SAMPLE_COMM_SYS_Exit(); close(SendSockfd); pthread_join(sendvideotid, NULL); return 0; }