海思媒体处理平台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);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
- 393
- 394
- 395
- 396
- 397
- 398
- 399
- 400
- 401
- 402
- 403
- 404
- 405
- 406
- 407
- 408
- 409
- 410
- 411
- 412
- 413
- 414
- 415
- 416
- 417
- 418
- 419
- 420
- 421
- 422
- 423
- 424
- 425
- 426
- 427
- 428
- 429
- 430
- 431
- 432
- 433
- 434
- 435
- 436
- 437
- 438
- 439
- 440
- 441
- 442
- 443
- 444
- 445
- 446
- 447
- 448
- 449
- 450
- 451
- 452
- 453
- 454
- 455
- 456
- 457
- 458
- 459
- 460
- 461
- 462
- 463
- 464
- 465
- 466
- 467
- 468
- 469
- 470
- 471
- 472
- 473
- 474
- 475
- 476
- 477
- 478
- 479
- 480
- 481
- 482
- 483
- 484
- 485
- 486
- 487
- 488
- 489
- 490
- 491
- 492
- 493
- 494
- 495
- 496
- 497
- 498
- 499
- 500
- 501
- 502
- 503
- 504
- 505
- 506
- 507
- 508
- 509
- 510
- 511
- 512
- 513
- 514
- 515
- 516
- 517
- 518
- 519
- 520
- 521
- 522
- 523
- 524
- 525
- 526
- 527
- 528
- 529
- 530
- 531
- 532
- 533
- 534
- 535
- 536
- 537
- 538
- 539
- 540
- 541
- 542
- 543
- 544
- 545
- 546
- 547
- 548
- 549
- 550
- 551
- 552
- 553
- 554
- 555
- 556
- 557
- 558
- 559
- 560
- 561
- 562
- 563
- 564
- 565
- 566
- 567
- 568
- 569
- 570
- 571
- 572
- 573
- 574
- 575
- 576
- 577
- 578
- 579
- 580
- 581
- 582
- 583
- 584
- 585
- 586
- 587
- 588
- 589
- 590
- 591
- 592
- 593
- 594
- 595
- 596
- 597
- 598
- 599
- 600
- 601
- 602
- 603
- 604
- 605
- 606
- 607
- 608
- 609
- 610
- 611
- 612
- 613
- 614
- 615
- 616
- 617
- 618
- 619
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}
}
}
}
}
};
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
测试: ./sample
通过其他设置接口增加功能
我们已经实现了最简化的VI视频采集了,接着可以在此基础上通过其他设置接口进行更复杂功能的设计如HI_MPI_VI_SetExtChnCrop()进行裁剪、HI_MPI_VI_SetLDCAttr()设置 VI 镜头畸变校正(LDC)属性、HI_MPI_VI_SetCSCAttr()调节图像的亮度、色调、对比度、饱和度等等。
至此本文关于海思VI模块的学习就结束了,学习中会遇到很多音视频方面的东西,像隔行扫描制式,YUV颜色图像编码方法等等,这些还没有做详细的解释,如果有机会再追加写一篇关于这些音视频方面的知识。
- 分享
- 举报

-
浏览量:5556次2020-07-31 11:54:44
-
浏览量:3523次2020-07-10 16:39:10
-
浏览量:1945次2023-11-07 15:38:56
-
浏览量:3660次2020-07-30 11:57:30
-
浏览量:3521次2020-08-03 11:10:18
-
浏览量:1980次2024-01-25 16:21:59
-
浏览量:3784次2020-07-27 15:12:15
-
浏览量:3146次2020-07-27 15:26:51
-
浏览量:3762次2020-08-05 20:36:22
-
浏览量:2924次2020-08-04 20:12:26
-
2023-06-12 14:35:32
-
浏览量:3238次2018-09-04 15:41:09
-
2024-01-11 15:44:19
-
浏览量:2453次2020-08-04 20:26:22
-
浏览量:3531次2020-08-25 18:13:09
-
浏览量:1699次2020-08-04 20:27:54
-
浏览量:2575次2020-06-19 15:39:47
-
浏览量:2641次2020-06-12 19:39:57
-
2024-12-22 11:22:24
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖

一休摸鱼






举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明