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 int video_DigitalZoom(int nChn, int nRatioX, int nRatioY, int nRatioW, int nRatioH, unsigned char bLive) { int i, ii; VO_ZOOM_ATTR_S stBaseZoom; if(bLive){ int x, y, w, h; video_GetZoom(nChn, &stBaseZoom, NULL); x = stBaseZoom.stZoomRect.s32X; y = stBaseZoom.stZoomRect.s32Y; w = stBaseZoom.stZoomRect.u32Width; h = stBaseZoom.stZoomRect.u32Height; if(!s_stVideo.abDigitalZoom[nChn]){ if(0 == nRatioX && 0 == nRatioY && 1000 == nRatioW && 1000 == nRatioH){ // needless to zoom return 0; } s_stVideo.astDigitalZoomRatio[nChn].nRatioX = nRatioX; s_stVideo.astDigitalZoomRatio[nChn].nRatioY = nRatioY; s_stVideo.astDigitalZoomRatio[nChn].nRatioW = nRatioW; s_stVideo.astDigitalZoomRatio[nChn].nRatioH = nRatioH; stBaseZoom.stZoomRect.s32X = x + (nRatioX * w / 1000); stBaseZoom.stZoomRect.s32Y = y + (nRatioY * h / 1000); stBaseZoom.stZoomRect.u32Width = nRatioW * w / 1000; stBaseZoom.stZoomRect.u32Height = nRatioH * h / 1000; stBaseZoom.stZoomRect.s32X &= ~0xf; // aligned 16 pixels stBaseZoom.stZoomRect.s32Y &= ~0xf; // aligned 16 pixels stBaseZoom.stZoomRect.u32Width &= ~1; stBaseZoom.stZoomRect.u32Height &= ~1; VIDEO_TRACE("ch=%d zoom [%d,%d,%d,%d]", ii, stBaseZoom.stZoomRect.s32X,stBaseZoom.stZoomRect.s32Y, stBaseZoom.stZoomRect.u32Width, stBaseZoom.stZoomRect.u32Height); for(i = 0; i < sizeof(VO_DEV_ID)/sizeof(VO_DEV_ID[0]); ++i){ DVR_ASSERT(HI_MPI_VO_SetZoomInWindow(VO_DEV_ID[i], nChn, &stBaseZoom)); } if(1 == s_stVideo.nCurDivi && nChn == s_stVideo.nCurPage){ video_CheckDigitalZoomD1(nChn); } s_stVideo.abDigitalZoom[nChn] = TRUE; }else{ // all zeroes is recover memset(&s_stVideo.astDigitalZoomRatio[nChn], 0, sizeof(s_stVideo.astDigitalZoomRatio[nChn])); s_stVideo.abDigitalZoom[nChn] = FALSE; for(i = 0; i < sizeof(VO_DEV_ID)/sizeof(VO_DEV_ID[0]); ++i){ DVR_ASSERT(HI_MPI_VO_SetZoomInWindow(VO_DEV_ID[i], nChn, &stBaseZoom)); video_CheckDigitalZoomD1(nChn); } } }else{ // return 0; VO_ZOOM_RATIO_S stZoomRatio = {0}; if(!s_stVideo.abDigitalZoom[nChn]){ if(0 == nRatioX && 0 == nRatioY && 1000 == nRatioW && 1000 == nRatioH){ // needless to zoom return 0; } s_stVideo.astDigitalZoomRatio[nChn].nRatioX = stZoomRatio.u32XRatio = nRatioX; s_stVideo.astDigitalZoomRatio[nChn].nRatioY = stZoomRatio.u32YRatio = nRatioY; s_stVideo.astDigitalZoomRatio[nChn].nRatioW = stZoomRatio.u32WRatio = nRatioW; s_stVideo.astDigitalZoomRatio[nChn].nRatioH = stZoomRatio.u32HRatio = nRatioH; for(i = 0; i < sizeof(VO_DEV_ID)/sizeof(VO_DEV_ID[0]); ++i){ DVR_ASSERT(HI_MPI_VO_SetZoomInRatio(VO_DEV_ID[i], nChn, &stZoomRatio)); } s_stVideo.abDigitalZoom[nChn] = TRUE; }else{ // all zeroes is recover memset(&stZoomRatio, 0, sizeof(stZoomRatio)); for(i = 0; i < sizeof(VO_DEV_ID)/sizeof(VO_DEV_ID[0]); ++i){ DVR_ASSERT(HI_MPI_VO_SetZoomInRatio(VO_DEV_ID[i], nChn, &stZoomRatio)); } memset(&s_stVideo.astDigitalZoomRatio[nChn], 0, sizeof(s_stVideo.astDigitalZoomRatio[nChn])); s_stVideo.abDigitalZoom[nChn] = FALSE; } } return 0; }
static void video_OutputInit() { int i = 0, ii = 0; int const nMaxFps = MAX_D1_CNT ? MAX_D1_LIVE_FPS : MAX_CIF_LIVE_FPS; VO_VIDEO_LAYER_ATTR_S stVgaLayerAttr; VO_VIDEO_LAYER_ATTR_S stCvbsLayerAttr; // vga output { VGA_RESOLUTION const enRes = g_pstSysEnv->GetVGAResolution(g_pstSysEnv); stVgaLayerAttr.stImageSize.u32Width = VO_ORIGIN_WIDTH; stVgaLayerAttr.stImageSize.u32Height = VO_ORIGIN_HEIGHT; stVgaLayerAttr.stDispRect.s32X = 0; stVgaLayerAttr.stDispRect.s32Y = 0; switch(enRes) { case VGA_800x600: stVgaLayerAttr.stDispRect.u32Width = 800; stVgaLayerAttr.stDispRect.u32Height = 600; break; default: case VGA_1024x768: stVgaLayerAttr.stDispRect.u32Width = 1024; stVgaLayerAttr.stDispRect.u32Height = 768; break; case VGA_1280x1024: stVgaLayerAttr.stDispRect.u32Width = 1280; stVgaLayerAttr.stDispRect.u32Height = 1024; break; case VGA_1366x768: stVgaLayerAttr.stDispRect.u32Width = 1366; stVgaLayerAttr.stDispRect.u32Height = 768; break; case VGA_1440x900: stVgaLayerAttr.stDispRect.u32Width = 1440; stVgaLayerAttr.stDispRect.u32Height = 900; break; } stVgaLayerAttr.u32DispFrmRt = nMaxFps; stVgaLayerAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; stVgaLayerAttr.s32PiPChn = VO_DEFAULT_CHN; } // cvbs { stCvbsLayerAttr.stImageSize.u32Width = VO_ORIGIN_WIDTH; stCvbsLayerAttr.stImageSize.u32Height = VO_ORIGIN_HEIGHT; stCvbsLayerAttr.stDispRect.s32X = 0; stCvbsLayerAttr.stDispRect.s32Y = 0; stCvbsLayerAttr.stDispRect.u32Width = VO_ORIGIN_WIDTH; stCvbsLayerAttr.stDispRect.u32Height = VO_ORIGIN_HEIGHT; stCvbsLayerAttr.u32DispFrmRt = nMaxFps; stCvbsLayerAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; stCvbsLayerAttr.s32PiPChn = VO_DEFAULT_CHN; } { // configuration active const VO_VIDEO_LAYER_ATTR_S astVideoLayerAttr[] = {stVgaLayerAttr, stCvbsLayerAttr}; video_ScreenInit(); for(i = 0; i < sizeof(VO_DEV_ID) / sizeof(VO_DEV_ID[0]); ++i){ //DVR_ASSERT(HI_MPI_VO_SetDispBufLen(nDev, MAX_CAM_CH)); DVR_ASSERT(HI_MPI_VO_SetVideoLayerAttr(VO_DEV_ID[i], &astVideoLayerAttr[i])); DVR_ASSERT(HI_MPI_VO_EnableVideoLayer(VO_DEV_ID[i])); // setup division video_Division(VO_DEV_ID[i], s_stVideo.nScrWidth[i], s_stVideo.nScrHeight[i], VIDEO_GetMaxDiv(), 0, FALSE); // 1 - 16 digital zoom // 17 - 20 bind directly // 21 - 24 bind directly VO_DISPLAY_FIELD_E enDisplayField; // enable vo channel for(ii = 0; ii < VIDEO_GetMaxDiv() + 1; ++ii){ if(ii < 16){ // for vi0 1-16 // digital zoom VO_ZOOM_ATTR_S stZoomAttr; memset(&stZoomAttr, 0, sizeof(stZoomAttr)); stZoomAttr.enField = VIDEO_FIELD_FRAME; stZoomAttr.stZoomRect.u32Width = VI_CIF_WIDTH; stZoomAttr.stZoomRect.u32Height = VI_CIF_HEIGHT; stZoomAttr.stZoomRect.s32X = 0; stZoomAttr.stZoomRect.s32Y = (ii % 8) * (stZoomAttr.stZoomRect.u32Height + 2); VIDEO_TRACE("ch=%d zoom [%d,%d,%d,%d]", ii, stZoomAttr.stZoomRect.s32X, stZoomAttr.stZoomRect.s32Y, stZoomAttr.stZoomRect.u32Width, stZoomAttr.stZoomRect.u32Height); DVR_ASSERT(HI_MPI_VO_SetZoomInWindow(VO_DEV_ID[i], ii, &stZoomAttr)); enDisplayField = (ii >= 8) ? VO_FIELD_TOP : VO_FIELD_BOTTOM; }else if(ii < 20){ // for vi2 ch1-4 enDisplayField = VO_FIELD_BOTTOM; }else if(ii < 24){ // for vi3 ch1-4 enDisplayField = VO_FIELD_BOTTOM; }else if(24 == ii){ enDisplayField = VO_FIELD_BOTH; }else if(25 == ii){ // for ch1-16 d1 live enDisplayField = VO_FIELD_BOTH; } DVR_ASSERT(HI_MPI_VO_SetChnField(VO_DEV_ID[i], ii, enDisplayField)); DVR_ASSERT(HI_MPI_VO_EnableChn(VO_DEV_ID[i], ii)); if(ii < MAX_CAM_CH){ video_BindOutput(VO_DEV_ID[i], ii, TRUE); }else if(ii < SPECIAL_D1_CH){ DVR_ASSERT(HI_MPI_VO_SENDFRAME(VO_DEV_ID[i], ii, s_pstLogoPic)); } } } } s_stVideo.bOutput = TRUE; }