📄 avcommon.c
字号:
#include <stdlib.h>#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/ioctl.h>#include <tw2834.h>/*please select the header file, according to the D/A or A/D device*/#include <adv7171.h>#include "avcommon.h"HI_S32 ADconfig (HI_S32 mode, HI_S32 normal){ HI_S32 fd; HI_S32 val; HI_S32 hiRet; /*step 1: Open the A/D device, and config it. Default is TW2834*/ fd = open("/dev/misc/tw2834dev",O_RDWR); /*step 2: config thd A/D devide normal(PAL/NTSC)*/ if ((mode != QVGA) && (mode != VGA) && (mode != SXGA)) { printf("set the normal: %d\n", normal); ioctl(fd, TW2834_SETNORM, &normal); } else { printf("please config AD by yourself\n"); } /*step 3: config VI mode(D1/CIF......)*/ switch (mode) { case CIF: { val = 0; printf("set 4cif.\n"); hiRet = ioctl(fd,TW2834_SET_4CIF,&val); break; } case HD1: { val = 0; printf("set half d1.\n"); hiRet = ioctl(fd,TW2834_SET_2HALF_D1,&val); break; } case D1: { val = 0; printf("set d1,channel:%d\n", val); hiRet = ioctl(fd,TW2834_SET_1D1,&val); break; } case MD1: { val = 0; printf("set 4 d1.\n"); hiRet = ioctl(fd,TW2834_SET_4D1,&val); break; } default: { printf ("config the mode of AD by yourself\n"); hiRet = HI_FAILURE; break; } } return hiRet;}HI_S32 ViPubConfig(HI_U16 mode, HI_U16 normal, VENC_FORMAT_E format){ VENC_INIT_S venc_init; VI_ATTR_S struPubAttr; HI_S32 hiRet; HI_U16 i; /*step 1: Open video encoder*/ venc_init.enVencType = format; venc_init.reserved = 0; hiRet = HI_VENC_Open(&venc_init); if ( hiRet != HI_SUCCESS ) { return hiRet; } /*step 2: Overlay must be close ,before VI pulic attribute is configed*/ for (i = 0; i < 4; i++ ) { HI_VI_DisableOverlay(i); } /*step 3: VI chnnel must be disable, before VI public attribute is configed*/ for (i = 0; i < 4; i++ ) { HI_VI_DisableVIChn(i); } /*step 4: VI must be disable, before VI public attribute is configed*/ hiRet = HI_VI_DisableVI(); if (hiRet != HI_SUCCESS ) { printf("disable VI attribute failed:%x !\n",hiRet); return hiRet ; } /*step 5: config public attribute for different mode*/ struPubAttr.enMaster = VIDEO_CONTROL_MODE_SLAVER; if (normal == NTSC) { struPubAttr.enInputNorm = VIDEO_ENCODING_MODE_NTSC; } else { struPubAttr.enInputNorm = VIDEO_ENCODING_MODE_PAL; } struPubAttr.enInputMode = VI_MODE_BT656 ; struPubAttr.u32CapSel = VI_CAP_BOTH; struPubAttr.u32Bufsize = 10 * 1024 * 1024; struPubAttr.bDownScaling = HI_FALSE; switch (mode) { case QCIF: struPubAttr.bDownScaling = HI_FALSE; struPubAttr.u32InputOption = VI_IA_L24; break; case CIF: struPubAttr.bDownScaling = HI_FALSE; struPubAttr.u32InputOption = VI_IA_L24; break; case HD1: struPubAttr.bDownScaling = HI_FALSE; struPubAttr.u32InputOption = VI_IA_L12; break; case D1: struPubAttr.bDownScaling = HI_FALSE; struPubAttr.u32InputOption = VI_IA_L11; break; case MD1: struPubAttr.bDownScaling = HI_FALSE; struPubAttr.u32InputOption = VI_IA_S14; break; case QVGA: struPubAttr.enInputMode = VI_MODE_DIGITAL_CAMERA; struPubAttr.u32CapSel = VI_CAP_FRAME; struPubAttr.bDownScaling = HI_FALSE; struPubAttr.u32InputOption = VI_ID_L11; break; case VGA: struPubAttr.enInputMode = VI_MODE_DIGITAL_CAMERA; struPubAttr.u32CapSel = VI_CAP_FRAME; struPubAttr.bDownScaling = HI_FALSE; struPubAttr.u32InputOption = VI_ID_L12; break; case SXGA: struPubAttr.enInputMode = VI_MODE_DIGITAL_CAMERA; struPubAttr.u32CapSel = VI_CAP_FRAME; struPubAttr.bDownScaling = HI_FALSE; struPubAttr.u32InputOption = VI_ID_L13; break; default: printf ("invalid mode\n"); break; } if (HI_VI_SetPublicAttr(&struPubAttr)) { printf("set VI attribute failed !\n"); return HI_FAILURE; } /*step 6: enable VI public attribute*/ if (HI_VI_EnableVI()) { printf("enable vi failed!\n"); return HI_FAILURE; } return HI_SUCCESS;}HI_S32 ViChnConfig(HI_U16 mode, HI_U16 normal, VI_CHN vi_chn ){ VI_CH_ATTR_S struVichAttr; struVichAttr.u32StartX = 0; struVichAttr.u32StartY = 0; if (normal == NTSC) { switch (mode) { case QCIF: struVichAttr.u32Width = 176; struVichAttr.u32Height = 128; struVichAttr.u32CapSel = (vi_chn >= 2)?VI_CAP_BOTTOM : VI_CAP_TOP; break; case CIF: struVichAttr.u32Width = 352; struVichAttr.u32Height = 240; struVichAttr.u32CapSel = (vi_chn > 1)?VI_CAP_BOTTOM : VI_CAP_TOP;; break; case HD1: struVichAttr.u32Width = 720; struVichAttr.u32Height = 240; struVichAttr.u32CapSel = (vi_chn > 0)?VI_CAP_BOTTOM : VI_CAP_TOP; break; case D1: struVichAttr.u32Width = 720; struVichAttr.u32Height = 240; struVichAttr.u32CapSel = VI_CAP_BOTH; break; case MD1: struVichAttr.u32Width = 720; struVichAttr.u32Height = 240; struVichAttr.u32CapSel = VI_CAP_BOTH; break; case QVGA: struVichAttr.u32Width = 320; struVichAttr.u32Height = 240; struVichAttr.u32CapSel = VI_CAP_FRAME; break; case VGA: struVichAttr.u32Width = 640; struVichAttr.u32Height = 480; struVichAttr.u32CapSel = VI_CAP_FRAME; break; case SXGA: struVichAttr.u32Width = 1280; struVichAttr.u32Height = 1024; struVichAttr.u32CapSel = VI_CAP_FRAME; break; default: printf ("invalid mode\n"); break; } } else { switch (mode) { case QCIF: struVichAttr.u32Width = 176; struVichAttr.u32Height = 144; struVichAttr.u32CapSel = (vi_chn >= 2)?VI_CAP_BOTTOM : VI_CAP_TOP; break; case CIF: struVichAttr.u32Width = 352; struVichAttr.u32Height = 288; struVichAttr.u32CapSel = (vi_chn > 1)?VI_CAP_BOTTOM : VI_CAP_TOP;; break; case HD1: struVichAttr.u32Width = 720; struVichAttr.u32Height = 288; struVichAttr.u32CapSel = (vi_chn > 0)?VI_CAP_BOTTOM : VI_CAP_TOP; break; case D1: struVichAttr.u32Width = 720; struVichAttr.u32Height = 288; struVichAttr.u32CapSel = VI_CAP_BOTH; break; case MD1: struVichAttr.u32Width = 720; struVichAttr.u32Height = 288; struVichAttr.u32CapSel = VI_CAP_BOTH; break; case QVGA: struVichAttr.u32Width = 320; struVichAttr.u32Height = 240; struVichAttr.u32CapSel = VI_CAP_FRAME; break; case VGA: struVichAttr.u32Width = 640; struVichAttr.u32Height = 480; struVichAttr.u32CapSel = VI_CAP_FRAME; break; case SXGA: struVichAttr.u32Width = 1280; struVichAttr.u32Height = 1024; struVichAttr.u32CapSel = VI_CAP_FRAME; break; default: printf ("invalid mode\n"); break; } } /*step 1: disable VI channel*/ if (HI_VI_DisableVIChn(vi_chn)) { printf("disable VI CHN %u failed!\n",vi_chn); return HI_FAILURE; }; /*step 2: set VI channel attribute*/ if (HI_VI_SetCHAttr(vi_chn, &struVichAttr)) { printf("Set VI CHN %u failed!\n",vi_chn); return HI_FAILURE; } /*step 3: enable VI channel attribute*/ if (HI_VI_EnableVIChn(vi_chn)) { printf("enable vi chn %u failed!\n", vi_chn); return HI_FAILURE; } return HI_SUCCESS;}HI_S32 DAconfig (HI_S32 normal){ HI_S32 fd; HI_S32 hiRet; /*step 1: Open the D/A device, and config it. Default is ADV7171*/ fd = open("/dev/misc/adv7171",O_RDWR); if (fd == -1) { printf ("open device failed\n"); return HI_FAILURE; } if ((normal != NTSC) && (normal != PAL)) { printf ("The normal to set is wrong\n"); return HI_FAILURE; } /*step 2: config the norma for D/A device*/ hiRet = ioctl(fd, ENCODER_SET_NORM, normal); if (HI_SUCCESS != hiRet) { printf ("config D/A failed\n"); return HI_FAILURE; } return HI_SUCCESS; }HI_S32 VoPubConfig (HI_U16 normal){ HI_VO_Init(); VO_PUBLIC_ATTR_S struPubAttr; if ( HI_VO_GetPublicAttr (&struPubAttr) != HI_SUCCESS) { printf("HI_VO_GetPublicAttr error"); return HI_FAILURE; } struPubAttr.enable = HI_TRUE; /* TV mode */ struPubAttr.display_mode = VO_MODE_BT656; struPubAttr.tv_config.enMaster = VIDEO_CONTROL_MODE_MASTER; struPubAttr.tv_config.compose_mode = normal; struPubAttr.tv_config.seriatim_mode = HI_TRUE; struPubAttr.bOutputScale = HI_TRUE; struPubAttr.background_color = 0x00ff00; /* blue */ struPubAttr.vo_chn_img_num = 4; struPubAttr.pip_buf_num = 4; /*steop 0: config public attribute for VO*/ if ( HI_VO_SetPublicAttr (&struPubAttr) != HI_SUCCESS) { printf("set VO attribute failed !\n"); return HI_FAILURE; } return HI_SUCCESS;}HI_S32 VoChnConfig (HI_U16 normal, VI_CHN voChn){ VO_CHN_ATTR_S struChnAttr ; if ( HI_VO_GetChnAttr (voChn, &struChnAttr)!= HI_SUCCESS) { printf("Set VO CHN: %d attribute failed !", voChn); } struChnAttr.enable = HI_TRUE; struChnAttr.rectangle.x = 0; struChnAttr.rectangle.y = 0; struChnAttr.rectangle.width = 720; if(normal == PAL) struChnAttr.rectangle.height = 576; else struChnAttr.rectangle.height = 480; struChnAttr.zoom_enable = HI_TRUE; /*steop 0: config channel attribute for VO*/ if ( HI_VO_SetChnAttr (voChn, &struChnAttr)!= HI_SUCCESS) { printf("Set VI CHN %u failed!\n", voChn); } return HI_SUCCESS;}/* Set the AD's sample rate */HI_VOID SetADSampleRate(HI_U32 sample){ HI_S32 fd; HI_U32 tmp; /* We use TLV320 as audio AD */ fd = open("/dev/misc/tlv320",O_NONBLOCK); if (fd < 0) { perror("tlv320"); exit(1); } tmp = sample; ioctl(fd, SET_TLV_SAMPLERATE,&tmp); close(fd);}/* Set the AI's sample rate */HI_S32 SetAiSampleRate(AI_CHN ai_chnid, AUDIO_SAMPLE_RATE_E enSample){ AUDIO_CH_ATTR_S strAttr; HI_S32 s32Ret; s32Ret = HI_AENC_GetAIAttr(ai_chnid, &strAttr); ASSERT_RETURN((HI_SUCCESS == s32Ret), s32Ret); strAttr.enSampleRate = enSample; s32Ret = HI_AENC_SetAIAttr(ai_chnid, &strAttr); ASSERT_RETURN((HI_SUCCESS == s32Ret), s32Ret); return HI_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -