static void video_InputInit() { int i = 0, ii = 0; // init sdk { int nDev = 0; int nChnCnt = 0; VI_PUB_ATTR_S stViDevAttr; VI_CHN_ATTR_S stViChnAttr; int const vi_fps = (VIDEO_IS_PAL() ? 25 : 30); // vi0 1-4 ch cif input 4d1 // vi2 5-8 ch d1 input 4d1 // device attributes stViDevAttr.enInputMode = VI_MODE_BT656; stViDevAttr.enWorkMode = VI_WORK_MODE_4D1; stViDevAttr.enViNorm = (VIDEO_IS_PAL() ? VIDEO_ENCODING_MODE_PAL : VIDEO_ENCODING_MODE_NTSC); // channel attributes stViChnAttr.stCapRect.s32Y = 0; stViChnAttr.stCapRect.u32Height = (VIDEO_IS_PAL() ? 288 : 240); stViChnAttr.bHighPri = HI_FALSE; stViChnAttr.bChromaResample = HI_FALSE; stViChnAttr.enViPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; VI_CIF_ATTR_CONF(&stViChnAttr); for(ii = 0; ii < MAX_CAM_CH; ii += 4) { if(VIMAP_Get(ii, &nDev, NULL) < 0) { continue; } DVR_ASSERT(HI_MPI_VI_Disable(nDev)); DVR_ASSERT(HI_MPI_VI_SetPubAttr(nDev, &stViDevAttr)); DVR_ASSERT(HI_MPI_VI_Enable(nDev)); for(i = 0; i < 4; ++i) { if(nChnCnt++ < MAX_D1_CNT){ VI_D1_ATTR_CONF(&stViChnAttr); }else{ VI_CIF_ATTR_CONF(&stViChnAttr); } DVR_ASSERT(HI_MPI_VI_SetChnAttr(nDev, i, &stViChnAttr)); DVR_ASSERT(HI_MPI_VI_EnableChn(nDev, i)); DVR_ASSERT(HI_MPI_VI_SetSrcFrameRate(nDev, i, vi_fps)); DVR_ASSERT(HI_MPI_VI_SetFrameRate(nDev, i, vi_fps)); } } } }
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_InputInit() { // int i = 0; // init sdk { VI_PUB_ATTR_S stViDevAttr; VI_CHN_ATTR_S stViChnAttr; // vi0 1-16 ch cif input 1d1 // vi2 1-16 ch d1 input mutex d1 live //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// // vi0 stViDevAttr.enInputMode = VI_MODE_BT656; stViDevAttr.enWorkMode = VI_WORK_MODE_1D1; stViDevAttr.enViNorm = (VIDEO_IS_PAL() ? VIDEO_ENCODING_MODE_PAL : VIDEO_ENCODING_MODE_NTSC); // channel attribute stViChnAttr.stCapRect.s32X = 0; stViChnAttr.stCapRect.s32Y = 0; stViChnAttr.stCapRect.u32Width = VI_CIF_WIDTH; stViChnAttr.stCapRect.u32Height = 8 * VI_CIF_HEIGHT + 7 * 2; // half field height combo frame stViChnAttr.bChromaResample = HI_FALSE; stViChnAttr.enCapSel = VI_CAPSEL_BOTH; stViChnAttr.bDownScale = HI_FALSE; stViChnAttr.bHighPri = HI_FALSE; stViChnAttr.enViPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; DVR_ASSERT(HI_MPI_VI_Disable(0)); DVR_ASSERT(HI_MPI_VI_SetPubAttr(0, &stViDevAttr)); DVR_ASSERT(HI_MPI_VI_Enable(0)); DVR_ASSERT(HI_MPI_VI_SetChnAttr(0, 0, &stViChnAttr)); DVR_ASSERT(HI_MPI_VI_EnableChn(0, 0)); DVR_ASSERT(HI_MPI_VI_SetSrcFrameRate(0, 0, MAX_CIF_LIVE_FPS)); DVR_ASSERT(HI_MPI_VI_SetFrameRate(0, 0, MAX_CIF_LIVE_FPS)); //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// // vi2 must be d1 stViChnAttr.enCapSel = VI_CAPSEL_BOTH; stViChnAttr.bDownScale = HI_FALSE; stViChnAttr.stCapRect.s32Y = 0; stViChnAttr.stCapRect.u32Height = VIDEO_IS_PAL() ? 288 : 240; stViChnAttr.bChromaResample = HI_FALSE; stViChnAttr.bHighPri = HI_FALSE; VI_CIF_ATTR_CONF(&stViChnAttr); // vi2 DVR_ASSERT(HI_MPI_VI_Disable(2)); DVR_ASSERT(HI_MPI_VI_SetPubAttr(2, &stViDevAttr)); DVR_ASSERT(HI_MPI_VI_Enable(2)); DVR_ASSERT(HI_MPI_VI_SetChnAttr(2, 0, &stViChnAttr)); DVR_ASSERT(HI_MPI_VI_EnableChn(2, 0)); DVR_ASSERT(HI_MPI_VI_SetSrcFrameRate(2, 0, MAX_D1_LIVE_FPS)); DVR_ASSERT(HI_MPI_VI_SetFrameRate(2, 0, MAX_D1_LIVE_FPS)); } }
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)); } }
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; } } } }