static void video_DisplayD1(int nVoDev, int nChn, unsigned char bDisplay) { static int s_nDispViDev = -1; static int s_nDispViChn = -1; VI_CHN_ATTR_S stViChnAttr; if(bDisplay){ int i = 0; for(i = 0; i < MAX_CAM_CH; ++i){ DVR_ASSERT(HI_MPI_VO_ChnHide(nVoDev, i)); } } if(bDisplay){ static int s_nLastFull = -1; // prevent to bind twice if(-1 == s_nLastFull || nChn != s_nLastFull){ int fd = open(VIDEO_DEV, O_RDWR); VIDEO_TRACE("%s fd = %d", __func__, fd); if(fd > 0){ // set ad configuration video_preview_t stPreview = {0}; stPreview.chn = nChn; // switch to this channel @ ad ioctl(fd, VIDEO_DRV_SET_LIVE_CHN, &stPreview); close(fd); fd = -1; } } // unbind last full channel first if(!(-1 == s_nDispViDev && -1 == s_nDispViChn)){ DVR_ASSERT(HI_MPI_VI_UnBindOutput(s_nDispViDev, s_nDispViChn, nVoDev, MAX_CAM_CH)); } // bind to d1 special live connect s_nDispViDev = 2; s_nDispViChn = 0; DVR_ASSERT(HI_MPI_VO_ClearChnBuffer(nVoDev, MAX_CAM_CH, HI_TRUE)); if(s_stVideo.nLossStat & (1<<nChn)){ DVR_ASSERT(HI_MPI_VO_SENDFRAME(nVoDev, MAX_CAM_CH, VIDEO_GetUserPic(nChn))); }else{ DVR_ASSERT(HI_MPI_VI_GetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); VI_D1_ATTR_CONF(&stViChnAttr); DVR_ASSERT(HI_MPI_VI_SetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); DVR_ASSERT(HI_MPI_VI_BindOutput(s_nDispViDev, s_nDispViChn, nVoDev, MAX_CAM_CH)); } usleep(40000); DVR_ASSERT(HI_MPI_VO_ChnShow(nVoDev, MAX_CAM_CH)); video_CheckDigitalZoomD1(nChn); }else{ if(!(-1 == s_nDispViDev && -1 == s_nDispViChn)){ DVR_ASSERT(HI_MPI_VO_ChnHide(nVoDev, MAX_CAM_CH)); // printf("unbind output (%d,%d) to (%d,%d)", s_nDispViDev, s_nDispViChn, nVoDev, MAX_CAM_CH); DVR_ASSERT(HI_MPI_VI_UnBindOutput(s_nDispViDev, s_nDispViChn, nVoDev, MAX_CAM_CH)); DVR_ASSERT(HI_MPI_VI_GetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); VI_CIF_ATTR_CONF(&stViChnAttr); DVR_ASSERT(HI_MPI_VI_SetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); s_nDispViDev = -1; s_nDispViChn = -1; } } }
static void video_DisplayD1(int nVoDev, int nChn, unsigned char bDisplay) { static int s_nDispViDev = -1; static int s_nDispViChn = -1; static int s_nDispVoChn = -1; VI_CHN_ATTR_S stViChnAttr; // input reset // dont try to change input the original setting of d1 channel if(bDisplay){ if(!(-1 == s_nDispViDev && -1 == s_nDispViChn)){ if(s_nDispVoChn >= MAX_D1_CNT){ DVR_ASSERT(HI_MPI_VI_GetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); VI_CIF_ATTR_CONF(&stViChnAttr); DVR_ASSERT(HI_MPI_VI_SetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); } DVR_ASSERT(HI_MPI_VO_SetChnField(nVoDev, nChn, VO_FIELD_BOTTOM)); } if(nChn >= MAX_D1_CNT){ if(0 == VIMAP_Get(nChn, &s_nDispViDev, &s_nDispViChn)){ DVR_ASSERT(HI_MPI_VI_GetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); VI_D1_ATTR_CONF(&stViChnAttr); DVR_ASSERT(HI_MPI_VI_SetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); s_nDispVoChn = nChn; } } DVR_ASSERT(HI_MPI_VO_SetChnField(nVoDev, nChn, VO_FIELD_BOTH)); }else{ if(!(-1 == s_nDispViDev && -1 == s_nDispViChn)){ if(nChn >= MAX_D1_CNT){ // reset field setting DVR_ASSERT(HI_MPI_VI_GetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); VI_CIF_ATTR_CONF(&stViChnAttr); DVR_ASSERT(HI_MPI_VI_SetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); s_nDispViDev = -1; s_nDispViChn = -1; } s_nDispVoChn = -1; } DVR_ASSERT(HI_MPI_VO_SetChnField(nVoDev, nChn, VO_FIELD_BOTTOM)); } }
HI_S32 SAMPLE_COMM_VI_ChangeMixCap(VI_CHN ViChn,HI_BOOL bMixCap,HI_U32 FrameRate) { VI_CHN_ATTR_S stChnAttr,stChnMinorAttr; HI_S32 S32Ret = HI_SUCCESS; S32Ret = HI_MPI_VI_GetChnAttr(ViChn, &stChnAttr); if(HI_SUCCESS!= S32Ret) { SAMPLE_PRT( "HI_MPI_VI_GetChnAttr failed"); } if(HI_TRUE == bMixCap) { memcpy(&stChnMinorAttr, &stChnAttr, sizeof(VI_CHN_ATTR_S)); stChnMinorAttr.stDestSize.u32Width = D1_WIDTH / 2; stChnAttr.s32FrameRate = FrameRate; S32Ret = HI_MPI_VI_SetChnAttr(ViChn, &stChnAttr); if (HI_SUCCESS != S32Ret) { SAMPLE_PRT("call HI_MPI_VI_SetChnAttr failed with %#x\n", S32Ret); return HI_FAILURE; } S32Ret = HI_MPI_VI_SetChnMinorAttr(ViChn, &stChnMinorAttr); if (HI_SUCCESS != S32Ret) { SAMPLE_PRT("call HI_MPI_VI_SetChnMinorAttr failed with %#x\n", S32Ret); return HI_FAILURE; } } else { stChnAttr.s32FrameRate = stChnAttr.s32SrcFrameRate; S32Ret = HI_MPI_VI_SetChnAttr(ViChn, &stChnAttr); if (HI_SUCCESS != S32Ret) { SAMPLE_PRT("call HI_MPI_VI_SetChnAttr failed with %#x\n", S32Ret); return HI_FAILURE; } } return HI_SUCCESS; }
HI_S32 SAMPLE_COMM_VI_ChangeDestSize(VI_CHN ViChn, HI_U32 u32Width, HI_U32 u32Height) { VI_CHN_ATTR_S stChnAttr; HI_S32 S32Ret = HI_SUCCESS; S32Ret = HI_MPI_VI_GetChnAttr(ViChn, &stChnAttr); if(HI_SUCCESS!= S32Ret) { SAMPLE_PRT( "HI_MPI_VI_GetChnAttr failed\n"); } stChnAttr.stDestSize.u32Width = u32Width; stChnAttr.stDestSize.u32Height = u32Height; S32Ret = HI_MPI_VI_SetChnAttr(ViChn, &stChnAttr); if(HI_SUCCESS!= S32Ret) { SAMPLE_PRT( "HI_MPI_VI_SetChnAttr failed\n"); } return HI_SUCCESS; }
static void video_DisplayD1(int nVoDev, int nChn, unsigned char bDisplay) { int i = 0, ii = 0; static int s_nDispViDev = -1; static int s_nDispViChn = -1; VI_CHN_ATTR_S stViChnAttr; if(bDisplay){ for(i = 0; i < VIDEO_GetMaxDiv(); ++i){ DVR_ASSERT(HI_MPI_VO_ChnHide(nVoDev, i)); } } if(bDisplay){ // unbind last full channel first if(!(-1 == s_nDispViDev && -1 == s_nDispViChn)){ DVR_ASSERT(HI_MPI_VI_UnBindOutput(s_nDispViDev, s_nDispViChn, nVoDev, SPECIAL_D1_CH)); } DVR_ASSERT(HI_MPI_VO_ClearChnBuffer(nVoDev, SPECIAL_D1_CH, HI_TRUE)); if(nChn < 16){ int fd = open(VIDEO_DEV, O_RDWR); if(fd > 0){ // set ad configuration video_preview_t stPreview = {0}; stPreview.chn = nChn; // switch to this channel @ ad ioctl(fd, VIDEO_DRV_SET_LIVE_CHN, &stPreview); close(fd); fd = -1; } // redefine device s_nDispViDev = 1; s_nDispViChn = 0; }else if(nChn < 24){ // reset field to both not downscale if(0 == VIMAP_Get(nChn, &s_nDispViDev, &s_nDispViChn)){ } }else{ ; } if(s_stVideo.nLossStat & (1<<nChn)){ // VIDEO_TRACE("Send User Pic"); DVR_ASSERT(HI_MPI_VO_SENDFRAME(nVoDev, SPECIAL_D1_CH, VIDEO_GetUserPic(nChn))); }else{ DVR_ASSERT(HI_MPI_VI_GetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); VI_D1_ATTR_CONF(&stViChnAttr); DVR_ASSERT(HI_MPI_VI_SetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); DVR_ASSERT(HI_MPI_VI_BindOutput(s_nDispViDev, s_nDispViChn, nVoDev, SPECIAL_D1_CH)); usleep(40000); } DVR_ASSERT(HI_MPI_VO_ChnShow(nVoDev, SPECIAL_D1_CH)); }else{ if(!(-1 == s_nDispViDev && -1 == s_nDispViChn)){ DVR_ASSERT(HI_MPI_VI_GetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); VI_CIF_ATTR_CONF(&stViChnAttr); DVR_ASSERT(HI_MPI_VI_SetChnAttr(s_nDispViDev, s_nDispViChn, &stViChnAttr)); DVR_ASSERT(HI_MPI_VI_UnBindOutput(s_nDispViDev, s_nDispViChn, nVoDev, SPECIAL_D1_CH)); DVR_ASSERT(HI_MPI_VO_ChnHide(nVoDev, SPECIAL_D1_CH)); if(nVoDev > 0){ s_nDispViDev = -1; s_nDispViChn = -1; } } } }
/****************************************************************************** * 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; }