这是代码,入口是那个__SAMPLE_VENC_NORMALP_CLASSIC()
/******************************************************************************
A simple program of Hisilicon Hi35xx video encode implementation.
Copyright (C), 2018, Hisilicon Tech. Co., Ltd.
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include "mpi_vpss.h"
#include "sample_comm.h"
#include "sample_venc.h"
#include "hicamera.h"
#include "histream.h"
#include "uvc_venc_glue.h"
#include "log.h"
#include "config_svc.h"
#include "sample_yuv.h"
#define PIC_SIZE PIC_3840x2160
#define v4l2_fourcc(a, b, c, d) \
((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */
#define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y', 'U', '1', '2') /* 16 YUV 4:2:0 */
#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG */
#define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */
static SAMPLE_VI_CONFIG_S g_stViConfig;
static HI_U32 g_u32SupplementConfig = HI_FALSE;
static PIC_SIZE_E g_enSize = PIC_SIZE;
static HI_S32 g_s32ChnNum;
static HI_U8 __started = 0;
extern encoder_property __encoder_property;
extern HI_S32 __SAMPLE_StartGetYUV(HI_S32 s32VpssGrp, HI_S32 s32VpssChn);
extern HI_S32 __SAMPLE_StopGetYUV(HI_VOID);
typedef struct param{
HI_BOOL bThreadStart;
HI_S32 s32VpssGrp;
HI_S32 s32VpssChn;
HI_S32 vencChn;
}PARAM;
static PARAM param1;
static pthread_t g_threadid;
static HI_S32 __SAMPLE_VENC_VPSS_Init(VPSS_GRP VpssGrp, HI_BOOL *pabChnEnable, DYNAMIC_RANGE_E enDynamicRange,
PIXEL_FORMAT_E enPixelFormat, SIZE_S stSize[], SAMPLE_SNS_TYPE_E enSnsType)
{
HI_S32 i;
HI_S32 s32Ret;
PIC_SIZE_E enSnsSize;
SIZE_S stSnsSize;
VPSS_GRP_ATTR_S stVpssGrpAttr = {0};
VPSS_CHN_ATTR_S stVpssChnAttr[VPSS_MAX_PHY_CHN_NUM];
s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(enSnsType, &enSnsSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_VI_GetSizeBySensor failed!\n");
return s32Ret;
}
s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSnsSize, &stSnsSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
return s32Ret;
}
stVpssGrpAttr.enDynamicRange = enDynamicRange;
stVpssGrpAttr.enPixelFormat = enPixelFormat;
stVpssGrpAttr.u32MaxW = stSnsSize.u32Width;
stVpssGrpAttr.u32MaxH = stSnsSize.u32Height;
stVpssGrpAttr.stFrameRate.s32SrcFrameRate = -1;
stVpssGrpAttr.stFrameRate.s32DstFrameRate = -1;
stVpssGrpAttr.bNrEn = HI_TRUE;
for (i = 0; i < VPSS_MAX_PHY_CHN_NUM; ++i)
{
if (HI_TRUE == pabChnEnable[i])
{
stVpssChnAttr[i].u32Width = stSize[i].u32Width;
stVpssChnAttr[i].u32Height = stSize[i].u32Height;
stVpssChnAttr[i].enChnMode = VPSS_CHN_MODE_USER;
stVpssChnAttr[i].enCompressMode = COMPRESS_MODE_NONE;
stVpssChnAttr[i].enDynamicRange = enDynamicRange;
stVpssChnAttr[i].enPixelFormat = enPixelFormat;
stVpssChnAttr[i].stFrameRate.s32SrcFrameRate = -1;
stVpssChnAttr[i].stFrameRate.s32DstFrameRate = -1;
stVpssChnAttr[i].u32Depth = 0;
stVpssChnAttr[i].bMirror = HI_FALSE;
stVpssChnAttr[i].bFlip = HI_FALSE;
stVpssChnAttr[i].enVideoFormat = VIDEO_FORMAT_LINEAR;
stVpssChnAttr[i].stAspectRatio.enMode = ASPECT_RATIO_NONE;
}
}
s32Ret = SAMPLE_COMM_VPSS_Start(VpssGrp, pabChnEnable, &stVpssGrpAttr, stVpssChnAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("start VPSS fail for %#x!\n", s32Ret);
}
return s32Ret;
}
static HI_S32 __SAMPLE_VENC_CheckSensor(SAMPLE_SNS_TYPE_E enSnsType, SIZE_S stSize)
{
HI_S32 s32Ret;
SIZE_S stSnsSize;
PIC_SIZE_E enSnsSize;
s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(enSnsType, &enSnsSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_VI_GetSizeBySensor failed!\n");
return s32Ret;
}
s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSnsSize, &stSnsSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
return s32Ret;
}
if ((stSnsSize.u32Width < stSize.u32Width) || (stSnsSize.u32Height < stSize.u32Height))
{
SAMPLE_PRT("Sensor size is (%d,%d), but encode chnl is (%d,%d)!\n",
stSnsSize.u32Width, stSnsSize.u32Height, stSize.u32Width, stSize.u32Height);
return HI_FAILURE;
}
return HI_SUCCESS;
}
static HI_S32 __SAMPLE_VENC_SYS_Init(HI_U32 u32SupplementConfig, SAMPLE_SNS_TYPE_E enSnsType)
{
HI_S32 s32Ret;
HI_U64 u64BlkSize;
VB_CONFIG_S stVbConf;
PIC_SIZE_E enSnsSize;
SIZE_S stSnsSize;
memset(&stVbConf, 0, sizeof(VB_CONFIG_S));
//通过sensor型号,跟ensize[0]赋值
s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(enSnsType, &enSnsSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_VI_GetSizeBySensor failed!\n");
return s32Ret;
}
//通过ensize[0] PIC_1080P,获取图片的分辨率
s32Ret = SAMPLE_COMM_SYS_GetPicSize(enSnsSize, &stSnsSize);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
return s32Ret;
}
//申请视频缓存池
u64BlkSize = COMMON_GetPicBufferSize(stSnsSize.u32Width, stSnsSize.u32Height, PIXEL_FORMAT_YVU_SEMIPLANAR_422, DATA_BITWIDTH_8, COMPRESS_MODE_SEG, DEFAULT_ALIGN);
stVbConf.astCommPool[0].u64BlkSize = u64BlkSize;
stVbConf.astCommPool[0].u32BlkCnt = 15;
u64BlkSize = COMMON_GetPicBufferSize(1920, 1080, PIXEL_FORMAT_YVU_SEMIPLANAR_422, DATA_BITWIDTH_8, COMPRESS_MODE_SEG, DEFAULT_ALIGN);
stVbConf.astCommPool[1].u64BlkSize = u64BlkSize;
stVbConf.astCommPool[1].u32BlkCnt = 15;
stVbConf.u32MaxPoolCnt = 2;//定义缓冲池最大个数
if (0 == u32SupplementConfig)
{
s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf);
}
else
{
s32Ret = SAMPLE_COMM_SYS_InitWithVbSupplement(&stVbConf, u32SupplementConfig);
}
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
return s32Ret;
}
return HI_SUCCESS;
}
static HI_S32 __SAMPLE_VENC_VI_Init(SAMPLE_VI_CONFIG_S *pstViConfig, HI_BOOL bLowDelay, HI_U32 u32SupplementConfig)
{
HI_S32 s32Ret;
SAMPLE_SNS_TYPE_E enSnsType;
ISP_CTRL_PARAM_S stIspCtrlParam;
HI_U32 u32FrameRate;
enSnsType = pstViConfig->astViInfo[0].stSnsInfo.enSnsType;
pstViConfig->as32WorkingViId[0] = 0;
pstViConfig->astViInfo[0].stSnsInfo.MipiDev = SAMPLE_COMM_VI_GetComboDevBySensor(pstViConfig->astViInfo[0].stSnsInfo.enSnsType, 0);
pstViConfig->astViInfo[0].stDevInfo.enWDRMode = WDR_MODE_NONE;//不支持宽动态
if (HI_TRUE == bLowDelay)
{
pstViConfig->astViInfo[0].stPipeInfo.enMastPipeMode = VI_ONLINE_VPSS_ONLINE;
}
else
{
pstViConfig->astViInfo[0].stPipeInfo.enMastPipeMode = VI_OFFLINE_VPSS_OFFLINE;
}
pstViConfig->astViInfo[0].stPipeInfo.aPipe[1] = -1;
pstViConfig->astViInfo[0].stPipeInfo.aPipe[2] = -1;
pstViConfig->astViInfo[0].stPipeInfo.aPipe[3] = -1;
pstViConfig->astViInfo[0].stChnInfo.enVideoFormat = VIDEO_FORMAT_LINEAR;
pstViConfig->astViInfo[0].stChnInfo.enCompressMode = COMPRESS_MODE_SEG;
s32Ret = SAMPLE_COMM_VI_SetParam(pstViConfig);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("SAMPLE_COMM_VI_SetParam failed with %d!\n", s32Ret);
return s32Ret;
}
SAMPLE_COMM_VI_GetFrameRateBySensor(enSnsType, &u32FrameRate);
s32Ret = HI_MPI_ISP_GetCtrlParam(pstViConfig->astViInfo[0].stPipeInfo.aPipe[0], &stIspCtrlParam);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_ISP_GetCtrlParam failed with %d!\n", s32Ret);
return s32Ret;
}
stIspCtrlParam.u32StatIntvl = u32FrameRate / 30;
s32Ret = HI_MPI_ISP_SetCtrlParam(pstViConfig->astViInfo[0].stPipeInfo.aPipe[0], &stIspCtrlParam);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("HI_MPI_ISP_SetCtrlParam failed with %d!\n", s32Ret);
return s32Ret;
}
s32Ret = SAMPLE_COMM_VI_StartVi(pstViConfig);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_COMM_SYS_Exit();
SAMPLE_PRT("SAMPLE_COMM_VI_StartVi failed with %d!\n", s32Ret);
return s32Ret;
}
#if 1
{
VI_CHN_ATTR_S stChnAttr;
s32Ret = HI_MPI_VI_GetChnAttr(0, 0, &stChnAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("get vi chn attr err:0x%x\n", s32Ret);
goto FAILED_EXIT;
}
stChnAttr.enPixelFormat = __SAMPLE_COMM_VENC_FORMAT();
s32Ret = HI_MPI_VI_SetChnAttr(0, 0, &stChnAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
goto FAILED_EXIT;
}
}
#endif
return HI_SUCCESS;
FAILED_EXIT:
SAMPLE_COMM_VI_StopVi(&g_stViConfig);
SAMPLE_COMM_SYS_Exit();
return s32Ret;
}
HI_S32 __stop_loop(HI_VOID)
{
if (HI_TRUE == param1.bThreadStart)
{
param1.bThreadStart = HI_FALSE;
pthread_join(g_threadid, HI_NULL);
}
return HI_SUCCESS;
}
HI_VOID* __loop_func(HI_VOID *p)
{
HI_S32 s32Ret = HI_FAILURE;
HI_S32 s32MilliSec = 200;
HI_BOOL bSendToVgs = HI_FALSE;
VGS_TASK_ATTR_S stTask;
PARAM *pstPara = (PARAM*)p;
HI_U32 u32Width = 0;
HI_U32 u32Height = 0;
HI_U32 u32Align = 32;
PIXEL_FORMAT_E enPixelFormat;
DATA_BITWIDTH_E enBitWidth;
COMPRESS_MODE_E enCmpMode;
VB_CAL_CONFIG_S stCalConfig;
VB_POOL_CONFIG_S stVbPoolCfg;
VIDEO_FRAME_INFO_S frameinfo;
VPSS_GRP Grp1 = pstPara->s32VpssGrp; /* VpssGrp */
VPSS_CHN Chn1 = pstPara->s32VpssChn; /* VpssChn */
VPSS_CHN_ATTR_S stChnAttr1;
HI_S32 VencChn = pstPara->vencChn;
#if (1 == UVC_SAVE_FILE)
HI_CHAR szYuvName[128];
#endif
if (HI_MPI_VPSS_GetChnAttr(Grp1, Chn1, &stChnAttr1) != HI_SUCCESS)
{
printf("HI_MPI_VPSS_GetChnAttr 1 failed!\n");
return HI_NULL;
}
stChnAttr1.u32Depth = 2;
if (HI_MPI_VPSS_SetChnAttr(Grp1, Chn1, &stChnAttr1) != HI_SUCCESS)
{
printf("HI_MPI_VPSS_SetChnAttr 1 failed!\n");
return HI_NULL;
}
#if (1 == UVC_SAVE_FILE)
snprintf(szYuvName, 128, "output/vpss_grp%d_chn%d_%dx%d_%s.yuv", Grp1, Chn1,
stChnAttr1.u32Width, stChnAttr1.u32Height, "P420");
g_pfd = fopen(szYuvName, "wb");
if (HI_NULL == g_pfd)
{
printf("open file %s err!\n", szYuvName);
return HI_NULL;
}
#endif
/* get frame first */
while (pstPara[0].bThreadStart)
{
printf("trhead\n");
if ((s32Ret = HI_MPI_VPSS_GetChnFrame(Grp1, Chn1, &frameinfo, s32MilliSec)) != HI_SUCCESS)
{
printf("Get frame from VPSS 1 fail(0x%x)!\n", s32Ret);
return HI_NULL;
}
s32Ret = HI_MPI_VENC_SendFrame(VencChn, &frameinfo, 50);
if(s32Ret != 0)
{
printf("HI_MPI_VENC_SendFrame failed %x\n",s32Ret);
return ;
}
/* release frame after using */
s32Ret = HI_MPI_VPSS_ReleaseChnFrame(Grp1, Chn1, &frameinfo);
if (s32Ret != HI_SUCCESS)
{
printf("HI_MPI_VPSS_ReleaseChnFrame failed!\n");
return HI_NULL;
}
}
}
/******************************************************************************
* function : H.264@4K@30fps
******************************************************************************/
static HI_S32 __SAMPLE_VENC_NORMALP_CLASSIC(HI_VOID)
{
HI_S32 s32Ret = HI_FAILURE;
SIZE_S stSize[2];
HI_S32 s32ChnNum = 1;
VENC_CHN VencChn[2] = {0, 1};
HI_U32 u32Profile = 0;
PAYLOAD_TYPE_E enPayLoad = PT_H264;/*枚举类型、数组、1路码流的编码类型 */
VENC_GOP_MODE_E enGopMode = VENC_GOPMODE_NORMALP;
VENC_GOP_ATTR_S stGopAttr;
SAMPLE_RC_E enRcMode = SAMPLE_RC_CBR; /* 恒定比特率方式进行编码 */
HI_BOOL bRcnRefShareBuf = HI_TRUE;
VPSS_GRP VpssGrp = 0;
VPSS_CHN VpssChn = 1;
HI_BOOL abChnEnable[4] = {0, 1, 0, 0};
PIXEL_FORMAT_E enPixFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420;
set_user_config_format(&enPayLoad, &g_enSize, &s32ChnNum);
if (V4L2_PIX_FMT_YUYV == __encoder_property.format)
{
enPixFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_422;
}
s32Ret = SAMPLE_COMM_SYS_GetPicSize(g_enSize, &stSize[VpssChn]);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("SAMPLE_COMM_SYS_GetPicSize failed!\n");
return s32Ret;
}
SAMPLE_COMM_VI_GetSensorInfo(&g_stViConfig);
if (SAMPLE_SNS_TYPE_BUTT == g_stViConfig.astViInfo[0].stSnsInfo.enSnsType)
{
SAMPLE_PRT("Not set SENSOR%d_TYPE !\n", 0);
return HI_FAILURE;
}
//验证sensor与传进来的wh是否一致
s32Ret = __SAMPLE_VENC_CheckSensor(g_stViConfig.astViInfo[0].stSnsInfo.enSnsType, stSize[VpssChn]);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("Check Sensor err!\n");
return HI_FAILURE;
}
/******************************************
start SYS VI VPSS
******************************************/
g_stViConfig.s32WorkingViNum = 1;
g_stViConfig.astViInfo[0].stDevInfo.ViDev = 0;
g_stViConfig.astViInfo[0].stPipeInfo.aPipe[0] = 0;
g_stViConfig.astViInfo[0].stChnInfo.ViChn = 0;
g_stViConfig.astViInfo[0].stChnInfo.enDynamicRange = DYNAMIC_RANGE_SDR8;
g_stViConfig.astViInfo[0].stChnInfo.enPixFormat = enPixFormat;
s32Ret = __SAMPLE_VENC_VI_Init(&g_stViConfig, HI_FALSE, g_u32SupplementConfig);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("Init VI err for %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = __SAMPLE_VENC_VPSS_Init(VpssGrp, abChnEnable, DYNAMIC_RANGE_SDR8, enPixFormat,
stSize, g_stViConfig.astViInfo[0].stSnsInfo.enSnsType);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("Init VPSS err for %#x!\n", s32Ret);
goto EXIT_VI_STOP;
}
s32Ret = SAMPLE_COMM_VI_Bind_VPSS(0, 0, VpssGrp[0]);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("VI Bind VPSS 1 err for %#x!\n", s32Ret);
goto EXIT_VPSS_STOP;
}
if (__encoder_property.format != V4L2_PIX_FMT_YUYV && __encoder_property.format != V4L2_PIX_FMT_YUV420)
{
enRcMode = SAMPLE_RC_CBR;
if (enPayLoad == PT_H264)
{
enRcMode = SAMPLE_RC_AVBR;
}
/******************************************
start stream venc
******************************************/
s32Ret = SAMPLE_COMM_VENC_GetGopAttr(enGopMode, &stGopAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Venc Get GopAttr for %#x!\n", s32Ret);
goto EXIT_VI_VPSS_UNBIND;
}
if (VENC_GOPMODE_BIPREDB == enGopMode)
{
SAMPLE_PRT("BIPREDB and ADVSMARTP not support lowdelay!\n");
goto EXIT_VI_VPSS_UNBIND;
}
s32Ret = SAMPLE_COMM_VENC_Start(VencChn[0], enPayLoad, g_enSize, enRcMode, u32Profile, bRcnRefShareBuf, &stGopAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Venc Start failed for %#x!\n", s32Ret);
goto EXIT_VI_VPSS_UNBIND;
}
param1.bThreadStart = HI_TRUE;
param1.s32VpssChn = VpssChn;
param1.s32VpssGrp = VpssGrp;
param1.vencChn = VencChn[0];
pthread_create(&g_threadid, HI_NULL,__loop_func , (HI_VOID *)¶m1);
// s32Ret = SAMPLE_COMM_VPSS_Bind_VENC(VpssGrp, VpssChn, VencChn[0]);
// if (HI_SUCCESS != s32Ret)
// {
// SAMPLE_PRT("Venc Get GopAttr failed for %#x!\n", s32Ret);
// goto EXIT_VENC_STOP;
// }
/******************************************
stream save process
******************************************/
g_s32ChnNum = s32ChnNum;
s32Ret = __SAMPLE_COMM_VENC_StartGetStream(VencChn, s32ChnNum);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start Venc failed!\n");
goto EXIT_VPSS_VENC_UNBIND;
}
}
else
{
s32Ret = __SAMPLE_StartGetYUV(VpssGrp, VpssChn);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Start get YUV failed!\n");
goto EXIT_VI_VPSS_UNBIND;
}
}
return s32Ret;
EXIT_VPSS_VENC_UNBIND:
// SAMPLE_COMM_VPSS_UnBind_VENC(VpssGrp, VpssChn, VencChn[0]);
EXIT_VENC_STOP:
SAMPLE_COMM_VENC_Stop(VencChn[0]);
EXIT_VI_VPSS_UNBIND:
SAMPLE_COMM_VI_UnBind_VPSS(0, 0, VpssGrp[0]);
EXIT_VPSS_STOP:
SAMPLE_COMM_VPSS_Stop(VpssGrp, abChnEnable);
EXIT_VI_STOP:
SAMPLE_COMM_VI_StopVi(&g_stViConfig);
SAMPLE_COMM_SYS_Exit();
return s32Ret;
}
/*******************************************************
* Processing Unit Operation Functions
*******************************************************/
static uint16_t _venc_brightness_get(HI_VOID)
{
ISP_CSC_ATTR_S stCSCAttr;
HI_MPI_ISP_GetCSCAttr(0, &stCSCAttr);
return (uint16_t)stCSCAttr.u8Luma;
}
static uint16_t _venc_contrast_get(HI_VOID)
{
ISP_CSC_ATTR_S stCSCAttr;
HI_MPI_ISP_GetCSCAttr(0, &stCSCAttr);
return (uint16_t)stCSCAttr.u8Contr;
}
static uint16_t _venc_hue_get(HI_VOID)
{
ISP_CSC_ATTR_S stCSCAttr;
HI_MPI_ISP_GetCSCAttr(0, &stCSCAttr);
return (uint16_t)stCSCAttr.u8Hue;
}
static uint8_t _venc_power_line_frequency_get(HI_VOID)
{
ISP_EXPOSURE_ATTR_S stExpAttr;
HI_MPI_ISP_GetExposureAttr(0, &stExpAttr);
if (stExpAttr.stAuto.stAntiflicker.u8Frequency != 50 &&
stExpAttr.stAuto.stAntiflicker.u8Frequency != 60)
{
return 0;
}
return (stExpAttr.stAuto.stAntiflicker.u8Frequency == 50) ? 0x1 : 0x2;
}
static uint16_t _venc_saturation_get(HI_VOID)
{
ISP_CSC_ATTR_S stCSCAttr;
HI_MPI_ISP_GetCSCAttr(0, &stCSCAttr);
return (uint16_t)stCSCAttr.u8Satu;
}
static uint8_t _venc_white_balance_temperature_auto_get(HI_VOID)
{
ISP_WB_ATTR_S stWBAttr;
HI_MPI_ISP_GetWBAttr(0, &stWBAttr);
return (stWBAttr.enOpType == OP_TYPE_AUTO) ? 0x1 : 0x0;
}
static uint16_t _venc_white_balance_temperature_get(HI_VOID)
{
ISP_WB_INFO_S stWBInfo;
HI_MPI_ISP_QueryWBInfo(0, &stWBInfo);
return (uint16_t)stWBInfo.u16ColorTemp;
}
static HI_VOID _venc_brightness_set(uint16_t v)
{
ISP_CSC_ATTR_S stCSCAttr;
HI_MPI_ISP_GetCSCAttr(0, &stCSCAttr);
stCSCAttr.u8Luma = v;
HI_MPI_ISP_SetCSCAttr(0, &stCSCAttr);
}
static HI_VOID _venc_contrast_set(uint16_t v)
{
ISP_CSC_ATTR_S stCSCAttr;
HI_MPI_ISP_GetCSCAttr(0, &stCSCAttr);
stCSCAttr.u8Contr = v;
HI_MPI_ISP_SetCSCAttr(0, &stCSCAttr);
}
static HI_VOID _venc_hue_set(uint16_t v)
{
ISP_CSC_ATTR_S stCSCAttr;
HI_MPI_ISP_GetCSCAttr(0, &stCSCAttr);
stCSCAttr.u8Hue = v;
HI_MPI_ISP_SetCSCAttr(0, &stCSCAttr);
}
static HI_VOID _venc_power_line_frequency_set(uint8_t v)
{
HI_S32 s32Ret;
ISP_EXPOSURE_ATTR_S stExpAttr;
HI_MPI_ISP_GetExposureAttr(0, &stExpAttr);
if (0 == v)
{
stExpAttr.stAuto.stAntiflicker.bEnable = HI_FALSE;
}
else if (1 == v)
{
stExpAttr.stAuto.stAntiflicker.bEnable = HI_TRUE;
stExpAttr.stAuto.stAntiflicker.u8Frequency = 50;
}
else if (2 == v)
{
stExpAttr.stAuto.stAntiflicker.bEnable = HI_TRUE;
stExpAttr.stAuto.stAntiflicker.u8Frequency = 60;
}
s32Ret = HI_MPI_ISP_SetExposureAttr(0, &stExpAttr);
if (s32Ret != HI_SUCCESS)
{
RLOG("HI_MPI_ISP_SetExposureAttr err 0x%x\n", s32Ret);
}
}
static HI_VOID _venc_saturation_set(uint16_t v)
{
ISP_CSC_ATTR_S stCSCAttr;
HI_MPI_ISP_GetCSCAttr(0, &stCSCAttr);
stCSCAttr.u8Satu = v;
HI_MPI_ISP_SetCSCAttr(0, &stCSCAttr);
}
static HI_VOID _venc_white_balance_temperature_auto_set(uint8_t v)
{
ISP_WB_ATTR_S stWBAttr;
HI_MPI_ISP_GetWBAttr(0, &stWBAttr);
stWBAttr.enOpType = (v == 1) ? OP_TYPE_AUTO : OP_TYPE_MANUAL;
HI_MPI_ISP_SetWBAttr(0, &stWBAttr);
}
static HI_VOID _venc_white_balance_temperature_set(uint16_t v)
{
ISP_WB_INFO_S stWBInfo;
ISP_WB_ATTR_S stWBAttr;
HI_U16 u16ColorTemp;
HI_U16 u16AWBGain[4];
HI_MPI_ISP_QueryWBInfo(0, &stWBInfo);
HI_MPI_ISP_GetWBAttr(0, &stWBAttr);
u16ColorTemp = v;
HI_MPI_ISP_CalGainByTemp(0, &stWBAttr, u16ColorTemp, 0, u16AWBGain);
stWBAttr.enOpType = OP_TYPE_MANUAL;
memcpy(&stWBAttr.stManual, u16AWBGain, sizeof(stWBAttr.stManual));
HI_MPI_ISP_SetWBAttr(0, &stWBAttr);
}
/* Processing Unit Operation Functions End */
/*******************************************************
* Input Terminal Operation Functions
*******************************************************/
static uint8_t _venc_exposure_auto_mode_get(HI_VOID)
{
ISP_EXPOSURE_ATTR_S stExpAttr;
HI_MPI_ISP_GetExposureAttr(0, &stExpAttr);
return (stExpAttr.enOpType == OP_TYPE_AUTO) ? 0x02 : 0x04;
}
static uint32_t _venc_exposure_ansolute_time_get(HI_VOID)
{
ISP_EXPOSURE_ATTR_S stExpAttr;
HI_MPI_ISP_GetExposureAttr(0, &stExpAttr);
return stExpAttr.stManual.u32ExpTime;
}
static HI_VOID _venc_exposure_auto_mode_set(uint8_t v)
{
ISP_EXPOSURE_ATTR_S stExpAttr;
HI_MPI_ISP_GetExposureAttr(0, &stExpAttr);
stExpAttr.enOpType = (v == 4) ? OP_TYPE_MANUAL : OP_TYPE_AUTO;
HI_MPI_ISP_SetExposureAttr(0, &stExpAttr);
}
static HI_VOID _venc_exposure_ansolute_time_set(uint32_t v)
{
ISP_EXPOSURE_ATTR_S stExpAttr;
HI_MPI_ISP_GetExposureAttr(0, &stExpAttr);
stExpAttr.stManual.u32ExpTime = v * 100;
stExpAttr.stManual.enExpTimeOpType = OP_TYPE_MANUAL;
HI_MPI_ISP_SetExposureAttr(0, &stExpAttr);
}
/* Input Terminal Operation Functions End */
/*******************************************************
* Stream Control Operation Functions
*******************************************************/
static HI_S32 sample_venc_set_idr(HI_VOID)
{
return HI_MPI_VENC_RequestIDR(1, HI_TRUE);
}
static HI_S32 sample_venc_init(HI_VOID)
{
HI_S32 s32Ret = HI_FAILURE;
SAMPLE_SNS_TYPE_E enSnsType = SENSOR0_TYPE;//显示近红外 修改这里SENSOR1_TYPE
if(g_sns_type[0] != SAMPLE_SNS_TYPE_BUTT )
enSnsType = g_sns_type[0];
s32Ret = __SAMPLE_VENC_SYS_Init(g_u32SupplementConfig, enSnsType);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("Init SYS err for %#x!\n", s32Ret);
return s32Ret;
}
return 0;
}
static HI_S32 sample_venc_startup(HI_VOID)
{
HI_S32 ret = HI_FAILURE;
__started = 1;
ret = __SAMPLE_VENC_NORMALP_CLASSIC();
HI_MPI_VENC_RequestIDR(0, HI_TRUE);
return ret;
}
static HI_S32 sample_venc_shutdown(HI_VOID)
{
HI_S32 VpssGrp = 0;
HI_S32 VpssChn = 1;
HI_S32 VencChn = 0;
HI_BOOL abChnEnable[4] = {0, 1, 0, 0};
if ((!__started))
{
return 0;
}
if (__encoder_property.format != V4L2_PIX_FMT_YUYV && __encoder_property.format != V4L2_PIX_FMT_YUV420)
{
__stop_loop();
__SAMPLE_COMM_VENC_StopGetStream();
// SAMPLE_COMM_VPSS_UnBind_VENC(VpssGrp, VpssChn, VencChn);
SAMPLE_COMM_VENC_Stop(VencChn);
}
else
{
__SAMPLE_StopGetYUV();
}
SAMPLE_COMM_VI_UnBind_VPSS(0, 0, VpssGrp);
SAMPLE_COMM_VPSS_Stop(VpssGrp, abChnEnable);
SAMPLE_COMM_VI_StopVi(&g_stViConfig);
__started = 0;
return HI_SUCCESS;
}
static HI_S32 sample_venc_set_property(encoder_property *p)
{
__encoder_property = *p;
set_yuv_property();
return 0;
}
/* Stream Control Operation Functions End */
static struct processing_unit_ops venc_pu_ops = {
.brightness_get = _venc_brightness_get,
.contrast_get = _venc_contrast_get,
.hue_get = _venc_hue_get,
.power_line_frequency_get = _venc_power_line_frequency_get,
.saturation_get = _venc_saturation_get,
.white_balance_temperature_auto_get = _venc_white_balance_temperature_auto_get,
.white_balance_temperature_get = _venc_white_balance_temperature_get,
.brightness_set = _venc_brightness_set,
.contrast_set = _venc_contrast_set,
.hue_set = _venc_hue_set,
.power_line_frequency_set = _venc_power_line_frequency_set,
.saturation_set = _venc_saturation_set,
.white_balance_temperature_auto_set = _venc_white_balance_temperature_auto_set,
.white_balance_temperature_set = _venc_white_balance_temperature_set,
};
static struct input_terminal_ops venc_it_ops = {
.exposure_ansolute_time_get = _venc_exposure_ansolute_time_get,
.exposure_auto_mode_get = _venc_exposure_auto_mode_get,
.exposure_ansolute_time_set = _venc_exposure_ansolute_time_set,
.exposure_auto_mode_set = _venc_exposure_auto_mode_set,
};
static struct stream_control_ops venc_sc_ops = {
.init = sample_venc_init,
.startup = sample_venc_startup,
.shutdown = sample_venc_shutdown,
.set_idr = sample_venc_set_idr,
.set_property = sample_venc_set_property,
};
HI_VOID sample_venc_config(HI_VOID)
{
printf("\n@@@@@ HiUVC App Sample @@@@@\n\n");
histream_register_mpi_ops(&venc_sc_ops, &venc_pu_ops, &venc_it_ops, HI_NULL);
}