海思媒体处理平台VI视频输入模块
[Hi3516A||Vi视频输入||海思媒体处理平台]
文章目录
VI模块的概念
Vi是海思媒体处理平台的视频输入模块,负责捕获视频图像,可对其进行剪切、缩放等处理,并输出多路不同分辨率的图像数据.
VI模块的功能、作用、内部单元工作流程
硬件单元功能框图
Hi3516A/Hi3518EV200/Hi3519V200 VI硬件单元功能框图.
VI可通过ITU-R BT656/601/1120 接口或 Digital Camera接口、 MIPI Rx(含 MIPI 接口、 LVDS 接口和 HISPI 接口)接收视频数据。
Vi还可以对接收到的原始视频图像数据进行裁剪(Crop)等处理,并实现一路原始视频图像输入,输出一路视频图像功能.
我们使用的是海思样例的SENSOR类型PANASONIC_MN34220_SUBLVDS_1080P_30FPS(传感器为松下的MN34220,采用SubLVDS的信号传输技术,使用1080P的分辨率,30帧率).
__MIPI__和__LVDS__的概念:
MIPI:移动产业处理器接口(Mobile Industry Processor Interface 简称MIPI)是为移动应用处理器制定的开放标准和一个规范。
LVDS:Low Voltage Differential Signaling,是一种低压差分信号技术接口。它是为克服以TTL电平方式传输宽带高码率数据时功耗大、EMI电磁干扰大等缺点而研制的一种数字视频信号传输方式,SubLVDS则是LVDS的发展.
VI内部单元工作流程
摄像机通过镜头(lens)聚焦光线,将光信号投射到 sensor 的感光区域,sensor经过光电转换,将 Bayer 格式的原始图像送给 ISP(Image Signal Processing 图像信号处理) 经过算法处理,输出 RGB 空间域的图像给后端的视频采集单元。在这个过程中,ISP 通过运行在其上的 firmware 对 lens 和 sensor 进行相应控制,进而完成自动光圈、自动曝光、自动白平衡等功能。其中,firmware 的运转靠视频采集单元的中断驱动。
ISP控制结构:
VIU视频采集单元
VIU视频采集单元负责接收ISP传过来的视频图像,经过视频输入设备Dev0的加工,通过物理通道Chn0发送给接收者,也可通过扩展通道,进行缩放后发送出去.
视频输入设备Dev0:
Hi3516A/Hi3518EV200/Hi3519V100 芯片只有一个 VI 设备,即 Dev0。 Dev0 支持BT.656、 BT.601、 DC、 MIPI Rx(MIPI、 LVDS、 HISPI 接口)输入。 Dev0 不支持非连续 pixel clock 时序。
视频物理通道Chn0:
Hi3516A/Hi3518EV200/Hi3519V100 VI 硬件单元仅包含 1 个 VI 视频物理通道,即Chn0。不存在次通道,但支持扩展通道。
视频扩展通道ext_ChnN:
扩展通道是物理通道的扩展,主要实现缩放功能,其数据来源于物理通道,Hi3516A/Hi3518EV200/Hi3519V100 最多支持 16 个扩展通道。
参阅Api实现VI
下面程序是初始化Vi后直接绑定Vi到Venc编码的例子,没有写清理工作,已测试可以运行,可供参考.
main.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <pthread.h>
#include <string.h>
#include <fcntl.h>
#include "My_Head.h"
static pthread_t gs_IspPid;
static HI_S32 gs_s32SnapCnt = 0;
HI_VOID WB_VENC_HandleSig(HI_S32 signo)
{
if(SIGINT == signo || SIGTERM == signo)
{
LOG_D("Interrupt Happen! exit\n");
}
exit(HI_FAILURE);
}
HI_S32 WB_MPI_SYS_Init()
{
LOG_D("******************************************\n");
LOG_D("step 1: Mpi System Init\n");
LOG_D("******************************************\n");
HI_S32 s32Ret;
VB_CONF_S struVbConf;
MPP_SYS_CONF_S struSysConf = {0};
memset(&struVbConf, 0, sizeof(VB_CONF_S));
//memcpy(&struVbConf, &VB_SYS_CONF_BASE, sizeof(struVbConf));
struVbConf.u32MaxPoolCnt = 128;
struVbConf.astCommPool[0].u32BlkSize = 3159360;
struVbConf.astCommPool[0].u32BlkCnt = 12;
HI_MPI_SYS_Exit();
HI_MPI_VB_Exit();
s32Ret = HI_MPI_VB_SetConf(&struVbConf);
if(HI_SUCCESS != s32Ret)
{
LOG_E("SetConf failed!\n");
return s32Ret;
}
s32Ret = HI_MPI_VB_Init();
if(HI_SUCCESS != s32Ret)
{
LOG_E("Vb Init failed!\n");
return s32Ret;
}
struSysConf.u32AlignWidth = 64;
/*set config of mpp system*/
s32Ret = HI_MPI_SYS_SetConf(&struSysConf);
if(HI_SUCCESS != s32Ret)
{
LOG_E("Set mpp sys config failed!\n");
return s32Ret;
}
/*init system*/
s32Ret = HI_MPI_SYS_Init();
if(HI_SUCCESS != s32Ret)
{
LOG_E("Mpi sys init failed!\n");
return s32Ret;
}
LOG_D("******************************************\n");
LOG_D("Mpi Sys Init Success\n");
LOG_D("******************************************\n");
return HI_SUCCESS;
/**/
}
HI_S32 WB_MIPI_Init()
{
HI_S32 fd;
combo_dev_attr_t* pstcomboDevAttr = NULL;
fd = open("/dev/hi_mipi", O_RDWR);
if( fd < 0)
{
LOG_W("open hi_mipi dev failed\n");
return -1;
}
pstcomboDevAttr = &SUBLVDS_4lane_SENSOR_MN34220_12BIT_1080_NOWDR_ATTR;
if (ioctl(fd, _IOW(HI_MIPI_IOC_MAGIC, 0x01, combo_dev_attr_t), pstcomboDevAttr))
{
LOG_E("set mipi attr failed\n");
close(fd);
return HI_FAILURE;
}
close(fd);
return HI_SUCCESS;
}
HI_S32 WB_Mpp_Vi_Init(HI_VOID)
{
LOG_D("******************************************\n");
LOG_D("step 2: Init vi dev and chn to capture\n");
LOG_D("******************************************\n");
HI_S32 s32Ret;
VI_DEV ViDev = 0;
VI_CHN ViChn = 0;
VI_DEV_ATTR_S stViDevAttr;
VI_CHN_ATTR_S stChnAttr;
ISP_WDR_MODE_S stWdrMode;
memset(&stViDevAttr, 0, sizeof(stViDevAttr));
memcpy(&stViDevAttr, &DEV_ATTR_LVDS_BASE, sizeof(stViDevAttr));
stViDevAttr.stDevRect.s32X = 0;
stViDevAttr.stDevRect.s32Y = 20;
stViDevAttr.stDevRect.u32Width = 1920;
stViDevAttr.stDevRect.u32Height = 1080;
/*
LOG_D("----%d\n",stViDevAttr.enIntfMode);
LOG_D("----%d\n",stViDevAttr.enWorkMode);
LOG_D("----%d\n",stViDevAttr.au32CompMask[0]);
LOG_D("----%d\n",stViDevAttr.au32CompMask[1]);
LOG_D("----%d\n",stViDevAttr.enScanMode);
LOG_D("----%d\n",stViDevAttr.enDataSeq);
LOG_D("----%d\n",stViDevAttr.enDataPath);
LOG_D("----%d\n",stViDevAttr.enInputDataType);
LOG_D("----%d\n",stViDevAttr.stDevRect.s32X);
LOG_D("----%d\n",stViDevAttr.stDevRect.s32Y);
LOG_D("----%d\n",stViDevAttr.stDevRect.u32Width);
LOG_D("----%d\n",stViDevAttr.stDevRect.u32Height);
LOG_D("----%d\n",stViDevAttr.bDataRev);
*/
s32Ret = HI_MPI_VI_SetDevAttr(ViDev, &stViDevAttr);
if (s32Ret != HI_SUCCESS)
{
LOG_E("Set dev attributes failed with error code %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_ISP_GetWDRMode(0, &stWdrMode);
if (s32Ret != HI_SUCCESS)
{
LOG_E("HI_MPI_ISP_GetWDRMode failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
if (stWdrMode.enWDRMode) //wdr mode
{
VI_WDR_ATTR_S stWdrAttr;
stWdrAttr.enWDRMode = stWdrMode.enWDRMode;
stWdrAttr.bCompress = HI_FALSE;
s32Ret = HI_MPI_VI_SetWDRAttr(0, &stWdrAttr);
if (s32Ret)
{
LOG_E("HI_MPI_VI_SetWDRAttr failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
}
s32Ret = HI_MPI_VI_EnableDev(ViDev);
if (s32Ret != HI_SUCCESS)
{
LOG_E("Enable dev failed with error code %#x!\n", s32Ret);
return HI_FAILURE;
}
stChnAttr.stCapRect.s32X = 0;
stChnAttr.stCapRect.s32Y = 0;
stChnAttr.stCapRect.u32Width = 1920;
stChnAttr.stCapRect.u32Height = 1080;
stChnAttr.stDestSize.u32Width = 1920;
stChnAttr.stDestSize.u32Height = 1080;
stChnAttr.enCapSel = VI_CAPSEL_BOTH;
stChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
stChnAttr.bMirror = HI_FALSE;
stChnAttr.bFlip = HI_FALSE;
stChnAttr.s32SrcFrameRate = -1;
stChnAttr.s32DstFrameRate = -1;
stChnAttr.enCompressMode = COMPRESS_MODE_NONE;
/*
LOG_D("----%d\n",stChnAttr.stCapRect.s32X);
LOG_D("----%d\n",stChnAttr.stCapRect.s32Y);
LOG_D("----%d\n",stChnAttr.stCapRect.u32Width);
LOG_D("----%d\n",stChnAttr.stCapRect.u32Height);
LOG_D("----%d\n",stChnAttr.stDestSize.u32Width );
LOG_D("----%d\n",stChnAttr.stDestSize.u32Height );
LOG_D("----%d\n",stChnAttr.enCapSel);
LOG_D("----%d\n",stChnAttr.enPixFormat);
LOG_D("----%d\n",stChnAttr.bMirror);
LOG_D("----%d\n",stChnAttr.bFlip);
LOG_D("----%d\n",stChnAttr.s32SrcFrameRate);
LOG_D("----%d\n",stChnAttr.s32DstFrameRate);
LOG_D("----%d\n",stChnAttr. enCompressMode);
*/
s32Ret = HI_MPI_VI_SetChnAttr(ViChn,&stChnAttr);
if (s32Ret != HI_SUCCESS)
{
LOG_E("Set chn attributes failed with error code %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VI_EnableChn(ViChn);
if (s32Ret != HI_SUCCESS)
{
LOG_E("Enable chn failed with error code %#x!\n", s32Ret);
return HI_FAILURE;
}
LOG_D("******************************************\n");
LOG_D("now, vi is capturing images\n");
LOG_D("******************************************\n");
return HI_SUCCESS;
/* now, vi is capturing images, you can do something else ... */
/*s32Ret = HI_MPI_VI_DisableChn(ViChn);
if (s32Ret != HI_SUCCESS)
{
LOG_D("Disable chn failed with error code %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VI_DisableDev(ViDev);
if (s32Ret != HI_SUCCESS)
{
LOG_D("Disable dev failed with error code %#x!\n", s32Ret);
return HI_FAILURE;
}*/
}
HI_S32 WB_MPI_VENC_Init()
{
LOG_D("******************************************\n");
LOG_D("step 3: Create Venc Chn\n");
LOG_D("******************************************\n");
HI_S32 s32Ret;
VI_CHN ViChn = 0;
VENC_CHN VencChn = 0;
VENC_ATTR_JPEG_S stJpegAttr;
VENC_CHN_ATTR_S stVencChnAttr;
MPP_CHN_S stSrcChn, stDestChn;
stVencChnAttr.stVeAttr.enType = PT_JPEG;
stJpegAttr.u32PicWidth = 1920;
stJpegAttr.u32PicHeight = 1080;
stJpegAttr.u32MaxPicWidth = 1920;
stJpegAttr.u32MaxPicHeight = 1080;
stJpegAttr.u32BufSize = 1920*1080*2;
stJpegAttr.bByFrame = HI_TRUE;
stJpegAttr.bSupportDCF = HI_FALSE;
memcpy(&stVencChnAttr.stVeAttr.stAttrJpeg, &stJpegAttr, sizeof(VENC_ATTR_JPEG_S));
s32Ret = HI_MPI_VENC_CreateChn(VencChn, &stVencChnAttr);
if(HI_SUCCESS != s32Ret)
{
LOG_E("Hi Mpi Venc CreateChn Failed with %#x!\n", s32Ret);
return s32Ret;
}
LOG_D("******************************************\n");
LOG_D("step 4: Start Recv Venc Pictures\n");
LOG_D("******************************************\n");
//s32Ret = HI_MPI_VENC_StartRecvPic(VencChn);
//if(HI_SUCCESS != s32Ret)
//{
// LOG_E("Hi Mpi Venc Start Recv Failed with %#x!\n", s32Ret);
// return s32Ret;
//}
stSrcChn.enModId = HI_ID_VIU;
stSrcChn.s32DevId = 0;
stSrcChn.s32ChnId = ViChn;
stDestChn.enModId = HI_ID_VENC;
stDestChn.s32DevId = 0;
stDestChn.s32ChnId = 0;
s32Ret = HI_MPI_SYS_Bind(&stSrcChn, &stDestChn);
return HI_SUCCESS;
}
HI_S32 WB_VENC_SaveJpeg(FILE* pFile, VENC_STREAM_S* pstVencStream)
{
VENC_PACK_S* pstData;
HI_U32 i;
for(i = 0; i < pstVencStream->u32PackCount; i++)
{
pstData = &pstVencStream->pstPack[i];
fwrite(pstData->pu8Addr + pstData->u32Offset, pstData->u32Len - pstData->u32Offset, 1, pFile);
fflush(pFile);
}
return HI_SUCCESS;
}
HI_S32 WB_Venc_SaveSnap(VENC_STREAM_S* pstVencStream)
{
char acFile[FILE_NAME_LEN] = {0};
FILE* pFile;
HI_S32 s32Ret;
snprintf(acFile, FILE_NAME_LEN, "Mysnap.jpg" );
pFile = fopen(acFile, "wb");
if(pFile == NULL)
{
LOG_E("open file error");
return HI_FAILURE;
}
s32Ret = WB_VENC_SaveJpeg(pFile, pstVencStream);
if(HI_SUCCESS != s32Ret)
{
LOG_E("save snap picture failed!\n");
return HI_FAILURE;
}
fclose(pFile);
gs_s32SnapCnt++;
return HI_SUCCESS;
}
HI_S32 WB_VENC_GetVencSnapProc(VENC_CHN VencChn)
{
LOG_D("******************************************\n");
LOG_D("step 5: Get Venc Snap Start\n");
LOG_D("******************************************\n");
sleep(2);
HI_S32 s32Ret;
//HI_S32 s32Cnt = 0;
HI_S32 s32VencFd;
fd_set read_fds;
struct timeval timeout;
VENC_STREAM_S stVencStream;
VENC_CHN_STAT_S stVencChnStat;
VENC_RECV_PIC_PARAM_S stRecvParam;
//HI_CHAR aszFileName[VENC_MAX_CHN_NUM][64];
//char szFilePostfix[10];
stRecvParam.s32RecvPicNum = 1;
s32Ret = HI_MPI_VENC_StartRecvPicEx(VencChn, &stRecvParam);
if(HI_SUCCESS != s32Ret)
{
LOG_E("HI_MPI_VENC_StartRecvPic faild with%#x!\n", s32Ret);
}
s32VencFd = HI_MPI_VENC_GetFd(VencChn);
if(s32VencFd < 0)
{
LOG_E("HI_MPI Venc GetFd failed with %#x!\n", s32VencFd);
return -1;
}
FD_ZERO(&read_fds);
FD_SET(s32VencFd, &read_fds);
timeout.tv_sec = 2;
timeout.tv_usec = 0;
LOG_D(" Venc GetFd is %d\n", s32VencFd);
s32Ret = select(s32VencFd +1, &read_fds, NULL, NULL, &timeout);
if(s32Ret < 0)
{
LOG_E("snap select failed!\n");
}
else if (s32Ret == 0)
{
LOG_E("Get Venc Stream time out !\n");
return s32Ret;
}
else
{
if(FD_ISSET(s32VencFd, &read_fds))
{
s32Ret = HI_MPI_VENC_Query(VencChn, &stVencChnStat);
if(HI_SUCCESS != s32Ret)
{
LOG_E("Mpi Venc Query failed with %#x!\n", s32Ret);
return s32Ret;
}
if(0 == stVencChnStat.u32CurPacks)
{
LOG_E("NOTE: Current Frame is NULL!\n");
return HI_SUCCESS;
}
stVencStream.pstPack = (VENC_PACK_S* )malloc(sizeof(VENC_PACK_S) * stVencChnStat.u32CurPacks);
if(NULL == stVencStream.pstPack)
{
LOG_E("malloc memory failed!\n");
return s32Ret;
}
stVencStream.u32PackCount = stVencChnStat.u32CurPacks;
s32Ret = HI_MPI_VENC_GetStream(VencChn, &stVencStream, -1);
if(HI_SUCCESS != s32Ret)
{
LOG_E("Hi Mpi Venc GetStream failed with %#x!\n", s32Ret);
free(stVencStream.pstPack);
stVencStream.pstPack = NULL;
return s32Ret;
}
s32Ret = WB_Venc_SaveSnap(&stVencStream);
if(HI_SUCCESS != s32Ret)
{
LOG_E("Venc SaveSnap failed with %#x!\n", s32Ret);
free(stVencStream.pstPack);
stVencStream.pstPack = NULL;
return s32Ret;
}
s32Ret = HI_MPI_VENC_ReleaseStream(VencChn, &stVencStream);
if(s32Ret)
{
LOG_E("Release Stream failed with %#x!\n",s32Ret);
free(stVencStream.pstPack);
stVencStream.pstPack = NULL;
return s32Ret;
}
free(stVencStream.pstPack);
stVencStream.pstPack = NULL;
}
}
s32Ret = HI_MPI_VENC_StopRecvPic(VencChn);
if (s32Ret != HI_SUCCESS)
{
LOG_E("MPI VENC StopRecvPic failed with %#x!\n", s32Ret);
return s32Ret;
}
return HI_SUCCESS;
}
void* WB_Isp_Run_Proc(void* arg)
{
ISP_DEV IspDev = 0;
HI_MPI_ISP_Run(IspDev);
return HI_NULL;
}
HI_S32 WB_VENC_ISP_Init()
{
ISP_DEV IspDev = 0;
HI_S32 s32Ret;
ISP_PUB_ATTR_S stPubAttr;
ALG_LIB_S stLib;
s32Ret = sensor_set_inifile_path("configs/");
if(s32Ret != HI_SUCCESS)
{
LOG_E("set cmos iniparser file path failed with %#x!\n", s32Ret);
return s32Ret;
}
s32Ret = sensor_register_callback();
if(s32Ret != HI_SUCCESS)
{
LOG_E("sensor_register_callback failed with %#x!\n", s32Ret);
return s32Ret;
}
stLib.s32Id = 0;
strcpy(stLib.acLibName, HI_AE_LIB_NAME);
s32Ret = HI_MPI_AE_Register(IspDev, &stLib);
if(s32Ret != HI_SUCCESS)
{
LOG_E("HI_MPI_AE_Register failed!\n");
return s32Ret;
}
stLib.s32Id = 0;
strcpy(stLib.acLibName, HI_AWB_LIB_NAME);
s32Ret = HI_MPI_AWB_Register(IspDev, &stLib);
if(s32Ret != HI_SUCCESS)
{
LOG_E("HI_MPI_AWB Register failed!\n");
return s32Ret;
}
stLib.s32Id = 0;
strcpy(stLib.acLibName, HI_AF_LIB_NAME);
s32Ret = HI_MPI_AF_Register(IspDev, &stLib);
if (s32Ret != HI_SUCCESS)
{
LOG_E("HI_MPI_AF Register failed!\n");
return s32Ret;
}
s32Ret = HI_MPI_ISP_MemInit(IspDev);
if(s32Ret != HI_SUCCESS)
{
LOG_E("HI Mpi Isp Init failed!\n");
return s32Ret;
}
ISP_WDR_MODE_S stWdrMode;
stWdrMode.enWDRMode = WDR_MODE_NONE;
s32Ret = HI_MPI_ISP_SetWDRMode(0, &stWdrMode);
if(HI_SUCCESS != s32Ret)
{
LOG_E("start ISP WDR failed!\n");
return s32Ret;
}
switch(SENSOR_TYPE)
{
case APTINA_9M034_DC_720P_30FPS:
LOG_E("Wrong Sensor Type\n");
break;
case PANASONIC_MN34220_SUBLVDS_1080P_30FPS:
stPubAttr.enBayer = BAYER_GRBG;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 0;
stPubAttr.stWndRect.s32Y = 0;
stPubAttr.stWndRect.u32Width = 1920;
stPubAttr.stWndRect.u32Height = 1080;
break;
}
s32Ret = HI_MPI_ISP_SetPubAttr(IspDev, &stPubAttr);
if(s32Ret != HI_SUCCESS)
{
LOG_E("Mpi Isp SetPubAttr failed with %#x!\n", s32Ret);
return s32Ret;
}
s32Ret = HI_MPI_ISP_Init(IspDev);
if(s32Ret != HI_SUCCESS)
{
LOG_E("Mpi ISP Init failed!\n");
}
if( 0 != pthread_create(&gs_IspPid, 0, (void * (*)(void *))WB_Isp_Run_Proc, NULL))
{
LOG_E("Create Isp Run thread failed!\n");
return HI_FAILURE;
}
return HI_SUCCESS;
}
int main(int argc,char *argv[])
{
HI_S32 s32Ret;
signal(SIGINT, WB_VENC_HandleSig);
signal(SIGTERM, WB_VENC_HandleSig);
s32Ret = WB_MPI_SYS_Init();
if(HI_SUCCESS != s32Ret)
{
LOG_E("Mpi sys init failed!\n");
exit(-1);
}
LOG_D("******************************************\n");
LOG_D("step 1~2: WB_MIPI_Init start\n");
LOG_D("******************************************\n");
s32Ret = WB_MIPI_Init();
if(HI_SUCCESS != s32Ret)
{
LOG_E("MIPI init failed!\n");
exit(-1);
}
LOG_D("******************************************\n");
LOG_D("step 1~2: WB_ISP_Init start\n");
LOG_D("******************************************\n");
s32Ret = WB_VENC_ISP_Init();
if(HI_SUCCESS != s32Ret)
{
LOG_E("ISP init failed!\n");
exit(-1);
}
s32Ret = WB_Mpp_Vi_Init();
if(HI_SUCCESS != s32Ret)
{
LOG_E("Mpi vi init failed!\n");
exit(-1);
}
s32Ret = WB_MPI_VENC_Init();
if(HI_SUCCESS != s32Ret)
{
LOG_E("Mpi venc init failed!\n");
exit(-1);
}
s32Ret = WB_VENC_GetVencSnapProc(0);
if(s32Ret != HI_SUCCESS)
{
LOG_E("GetVencSnapProc is Failed!\n");
return HI_FAILURE;
}
getchar();
exit(s32Ret);
}
My_Head.h
//#include <sys/time.h>
#include "hi_comm_venc.h"
#include "hi_type.h"
#include "hi_comm_vi.h"
#include "hi_comm_video.h"
#include "hi_comm_vb.h"
#include "hi_comm_sys.h"
#include "hi_mipi.h"
#include "hi_comm_3a.h"
#include "hi_comm_isp.h"
#include "hi_ae_comm.h"
#include "hi_sns_ctrl.h"
#include "hi_af_comm.h"
#include "hi_awb_comm.h"
#include "mpi_venc.h"
#include "mpi_sys.h"
#include "mpi_isp.h"
#include "mpi_af.h"
#include "mpi_vb.h"
#include "mpi_vi.h"
#include "mpi_ae.h"
#include "mpi_awb.h"
#include "sys/ioctl.h"
#define FILE_NAME_LEN 128
#define TRUE 1
#define FALSE 0
#define TAG "TEST"
#define DEBUG TRUE
/*
#define TIMEPRINT \
do{\
struct timeval now;\
struct tm* ptime = NULL;\
suseconds_t mstime;\
\
gettimeofday(&now, NULL);\
ptime = gmtime(&now.tv_sec);\
mstime = now.tv_usec/10000;\
\
printf("%d-%d-%d-%d-%d-%d:%02d ", 1900 + ptime->tm_year, 1 + ptime->tm_mon, ptime->tm_mday, ptime->tm_hour, ptime->tm_min, ptime->tm_sec, mstime);\
}while(0)
*/
#define TIMEPRINT
#if DEBUG
#define LOG_D(...) \
do{\
TIMEPRINT\
printf("D/%s ",TAG);\
printf("(%s, %d): ", __FILE__,__LINE__);\
printf(__VA_ARGS__);\
}while(0)
#else
#define LOG_D(...) printf(__VA_ARGS__)
#endif
#if DEBUG
#define LOG_W(...) \
do{\
TIMEPRINT\
printf("W/%s ",TAG);\
printf("(%s, %d): ", __FILE__,__LINE__);\
printf(__VA_ARGS__);\
}while(0)
#else
#define LOG_W(...) printf(__VA_ARGS__)
#endif
#if DEBUG
#define LOG_E(...) \
do{\
TIMEPRINT\
printf("E/%s ",TAG);\
printf("(%s, %d): ", __FILE__,__LINE__);\
printf(__VA_ARGS__);\
}while(0)
#else
#define LOG_E(...) printf(__VA_ARGS__)
#endif
#if DEBUG
#define LOG_B(...) \
do{\
TIMEPRINT\
printf("B/%s ",TAG);\
printf("(%s, %d):", __FILE__,__LINE__);\
printf(__VA_ARGS__);\
getchar();\
}while(0)
#else
#define LOG_B(...) \
do{\
printf("Break Here!\n");\
printf(__VA_ARGS__);\
getchar();\
}while(0)
#endif
typedef enum wb_vi_mode_e
{
APTINA_AR0130_DC_720P_30FPS = 0,
APTINA_9M034_DC_720P_30FPS,
SAMPLE_VI_MODE_1_D1,
SAMPLE_VI_MODE_BT1120_1080I,
SAMPLE_VI_MODE_BT1120_720P,
SAMPLE_VI_MODE_BT1120_1080P,
PANASONIC_MN34220_SUBLVDS_1080P_30FPS,
PANASONIC_MN34220_SUBLVDS_720P_120FPS,
SONY_IMX178_LVDS_1080P_30FPS,
SONY_IMX185_MIPI_1080P_30FPS,
PANASONIC_MN34220_MIPI_1080P_30FPS,
PANASONIC_MN34220_MIPI_720P_120FPS,
SONY_IMX178_LVDS_5M_30FPS,
SONY_IMX117_LVDS_1080P_30FPS,
SONY_IMX117_LVDS_720P_30FPS,
SONY_IMX123_LVDS_QXGA_30FPS,
APTINA_AR0230_HISPI_1080P_30FPS,
APTINA_AR0237_HISPI_1080P_30FPS,
APTINA_AR0330_MIPI_1080P_30FPS,
APTINA_AR0330_MIPI_1536P_25FPS,
APTINA_AR0330_MIPI_1296P_25FPS,
OMNIVISION_OV4689_MIPI_4M_30FPS,
OMNIVISION_OV4689_MIPI_1080P_30FPS,
OMNIVISION_OV5658_MIPI_5M_30FPS,
}Vi_Mode_E;
typedef struct VENC_GETSTREAMPARA_S
{
HI_BOOL bTreadStart;
HI_S32 s32Cnt;
}Venc_GetStreamPara_S;
VI_DEV_ATTR_S DEV_ATTR_LVDS_BASE =
{
/* interface mode */
VI_MODE_LVDS,
/* multiplex mode */
VI_WORK_MODE_1Multiplex,
/* r_mask g_mask b_mask*/
{0xFFF00000, 0x0},
/* progessive or interleaving */
VI_SCAN_PROGRESSIVE,
/*AdChnId*/
{ -1, -1, -1, -1},
/*enDataSeq, only support yuv*/
VI_INPUT_DATA_YUYV,
/* synchronization information */
{
/*port_vsync port_vsync_neg port_hsync port_hsync_neg */
VI_VSYNC_PULSE, VI_VSYNC_NEG_LOW, VI_HSYNC_VALID_SINGNAL, VI_HSYNC_NEG_HIGH, VI_VSYNC_VALID_SINGAL, VI_VSYNC_VALID_NEG_HIGH,
/*hsync_hfb hsync_act hsync_hhb*/
{
0, 1280, 0,
/*vsync0_vhb vsync0_act vsync0_hhb*/
0, 720, 0,
/*vsync1_vhb vsync1_act vsync1_hhb*/
0, 0, 0
}
},
/* use interior ISP */
VI_PATH_ISP,
/* input data type */
VI_DATA_TYPE_RGB,
/* bRever */
HI_FALSE,
/* DEV CROP */
{0, 0, 1920, 1080}
};
//VB_CONF_S VB_SYS_CONF_BASE =
//{
/*Max Pool count*/
// 128,
/*Vb Pool Stru*/
// {
/*BlkSize*/
// 3159360,
/* BlkCnt */
// 20
/*acMmzName*/
// }
//};
combo_dev_attr_t MIPI_4lane_SENSOR_MN34220_MIPI_12BIT_ATTR =
{
.input_mode = INPUT_MODE_MIPI,
{
.mipi_attr =
{
RAW_DATA_12BIT,
{0, 1, 2, 3, -1, -1, -1, -1}
}
}
};
combo_dev_attr_t SUBLVDS_4lane_SENSOR_MN34220_12BIT_1080_NOWDR_ATTR =
{
/* input mode */
.input_mode = INPUT_MODE_SUBLVDS,
{
.lvds_attr = {
.img_size = {1920, 1080},
HI_WDR_MODE_NONE,
LVDS_SYNC_MODE_SOL,
RAW_DATA_12BIT,
LVDS_ENDIAN_BIG,
LVDS_ENDIAN_BIG,
.lane_id = {0, 2, -1, -1, 1, 3, -1, -1},
.sync_code = {
{ {0x002, 0x003, 0x000, 0x001}, //PHY0_lane0
{0x202, 0x203, 0x200, 0x201},
{0x102, 0x103, 0x100, 0x101},
{0x302, 0x303, 0x300, 0x301}
},
{ {0x006, 0x007, 0x004, 0x005}, //PHY0_lane1
{0x206, 0x207, 0x204, 0x205},
{0x106, 0x107, 0x104, 0x105},
{0x306, 0x307, 0x304, 0x305}
},
{ {0x00a, 0x00b, 0x008, 0x009}, //PHY0_lane2
{0x20a, 0x20b, 0x208, 0x209},
{0x10a, 0x10b, 0x108, 0x109},
{0x30a, 0x30b, 0x308, 0x309}
},
{ {0x00a, 0x00b, 0x008, 0x009}, //PHY0_lane3 INPUT_MODE_LVDS
{0x20a, 0x20b, 0x208, 0x209},
{0x10a, 0x10b, 0x108, 0x109},
{0x30a, 0x30b, 0x308, 0x309}
},
{ {0x012, 0x013, 0x010, 0x011},//PHY1_lane0
{0x212, 0x213, 0x210, 0x211},
{0x112, 0x113, 0x110, 0x111},
{0x312, 0x313, 0x310, 0x311}
},
{ {0x016, 0x017, 0x014, 0x015}, //PHY1_lane1
{0x216, 0x217, 0x214, 0x215},
{0x116, 0x117, 0x114, 0x115},
{0x316, 0x317, 0x314, 0x315}
},
{ {0x01a, 0x01b, 0x018, 0x019}, //PHY1_lane2
{0x21a, 0x21b, 0x218, 0x219},
{0x11a, 0x11b, 0x118, 0x119},
{0x31a, 0x31b, 0x318, 0x319}
},
{ {0x01a, 0x01b, 0x018, 0x019}, //PHY1_lane3
{0x21a, 0x21b, 0x218, 0x219},
{0x11a, 0x11b, 0x118, 0x119},
{0x31a, 0x31b, 0x318, 0x319}
}
}
}
}
};
Makefile
#
#
#
#
SRC := $(wildcard *.c)
OBJ := $(SRC:%.c=%.o)
TARGET := sample
#CC :=gcc
CC := arm-hisiv300-linux-gcc
CFLAGS := -g -Wall -ldl -DSENSOR_TYPE=PANASONIC_MN34220_SUBLVDS_1080P_30FPS
CFLAGS += -I../include/
CFLAGS += -Dhi3516a -DHICHIP=0x3516A100 -DISP_V2 -DHI_MIPI_ENABLE -DHI_ACODEC_TYPE_INNER -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -ffunction-sections -mno-unaligned-access -fno-aggressive-loop-optimizations
MPILIB := ../lib/libmpi.a
ISPLIB := ../lib/libisp.a ../lib/lib_hiae.a
SENSORLIB := ../lib/libsns_mn34220.a
AUDIO_LIBS :=../lib/libupvqe.a ../lib/libdnvqe.a ../lib/libVoiceEngine.a
OTHERLIB := ../lib/lib_hiawb.a ../lib/lib_hidefog.a ../lib/lib_hiaf.a
all: $(OBJ) $(TARGET)
$(TARGET):
@echo "SRC is " $(SRC)
@echo "OBJ is " $(OBJ)
@echo "TARGET is " $(TARGET)
$(CC) $(CFLAGS) $(OBJ) -lpthread -lm -o $(TARGET) $(ISPLIB) $(MPILIB) $(SENSORLIB) $(OTHERLIB) $(AUDIO_LIBS)
.PHONY: clean target
clean:
rm -rf $(OBJ) $(TARGET)
target:
#@source /etc/profile
rm -rf $(OBJ) $(TARGET)
make
测试: ./sample
通过其他设置接口增加功能
我们已经实现了最简化的VI视频采集了,接着可以在此基础上通过其他设置接口进行更复杂功能的设计如HI_MPI_VI_SetExtChnCrop()进行裁剪、HI_MPI_VI_SetLDCAttr()设置 VI 镜头畸变校正(LDC)属性、HI_MPI_VI_SetCSCAttr()调节图像的亮度、色调、对比度、饱和度等等。
至此本文关于海思VI模块的学习就结束了,学习中会遇到很多音视频方面的东西,像隔行扫描制式,YUV颜色图像编码方法等等,这些还没有做详细的解释,如果有机会再追加写一篇关于这些音视频方面的知识。