Last active
October 13, 2018 08:59
-
-
Save chertov/92ab93c07bbaf062ae7e58c83c36d320 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <sys/ioctl.h> | |
#include <sys/poll.h> | |
#include <sys/time.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
#include <pthread.h> | |
#include <math.h> | |
#include <unistd.h> | |
#include <signal.h> | |
#include "hi_common.h" | |
#include "hi_comm_sys.h" | |
#include "hi_comm_vb.h" | |
#include "hi_comm_isp.h" | |
#include "hi_comm_vi.h" | |
#include "hi_comm_vo.h" | |
#include "hi_comm_venc.h" | |
#include "hi_comm_vpss.h" | |
#include "hi_comm_vdec.h" | |
#include "hi_comm_region.h" | |
#include "hi_comm_adec.h" | |
#include "hi_comm_aenc.h" | |
#include "hi_comm_ai.h" | |
#include "hi_comm_ao.h" | |
#include "hi_comm_aio.h" | |
#include "hi_defines.h" | |
#include "mpi_sys.h" | |
#include "mpi_vb.h" | |
#include "mpi_vi.h" | |
#include "mpi_vo.h" | |
#include "mpi_venc.h" | |
#include "mpi_vpss.h" | |
#include "mpi_vdec.h" | |
#include "mpi_region.h" | |
#include "mpi_adec.h" | |
#include "mpi_aenc.h" | |
#include "mpi_ai.h" | |
#include "mpi_ao.h" | |
#include "mpi_isp.h" | |
#include "mpi_ive.h" | |
#include "mpi_ae.h" | |
#include "mpi_awb.h" | |
#include "mpi_af.h" | |
#include "hi_vreg.h" | |
#include "hi_sns_ctrl.h" | |
#include "hi_mipi.h" | |
#define FNLOG(func) func | |
#define CALLFN(func) func | |
HI_VOID* Test_ISP_Run(HI_VOID *param) { | |
ISP_DEV isp_dev = 0; | |
HI_S32 s32Ret = FNLOG(HI_MPI_ISP_Run)(isp_dev); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_ISP_Run faild with %#x!\n", s32Ret); | |
} | |
return HI_NULL; | |
} | |
int main(int argc, char *argv[]) { | |
// init_fnlog("log_s.txt", "log_ss.txt"); | |
FNLOG(HI_MPI_SYS_Exit)(); | |
FNLOG(HI_MPI_VB_Exit)(); | |
VB_CONF_S vb_conf; | |
memset(&vb_conf,0,sizeof(VB_CONF_S)); | |
vb_conf.u32MaxPoolCnt = 128; | |
vb_conf.astCommPool[0].u32BlkSize = 3159360; | |
vb_conf.astCommPool[0].u32BlkCnt = 10; | |
HI_S32 s32Ret = FNLOG(HI_MPI_VB_SetConf)(&vb_conf); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VB_SetConf faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
VB_SUPPLEMENT_CONF_S supplement_conf; | |
memset(&supplement_conf, 0, sizeof(VB_SUPPLEMENT_CONF_S)); | |
supplement_conf.u32SupplementConf = 1; | |
s32Ret = FNLOG(HI_MPI_VB_SetSupplementConf)(&supplement_conf); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VB_SetSupplementConf faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VB_Init)(); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VB_Init faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
MPP_SYS_CONF_S sys_conf; | |
memset(&sys_conf,0,sizeof(MPP_SYS_CONF_S)); | |
sys_conf.u32AlignWidth = 64; | |
s32Ret = FNLOG(HI_MPI_SYS_SetConf)(&sys_conf); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_SYS_SetConf faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_SYS_Init)(); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_SYS_Init faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
/* mipi reset unrest */ | |
HI_S32 fd = open("/dev/hi_mipi", O_RDWR); | |
if (fd < 0) { | |
printf("warning: open hi_mipi dev failed\n"); | |
return EXIT_FAILURE; | |
} | |
combo_dev_attr_t MIPI_CMOS3V3_ATTR = { .input_mode = INPUT_MODE_CMOS_33V, { } }; | |
if (ioctl(fd, _IOW('m', 0x01, combo_dev_attr_t), &MIPI_CMOS3V3_ATTR)) { | |
printf("set mipi attr failed\n"); | |
close(fd); | |
return EXIT_FAILURE; | |
} | |
close(fd); | |
CALLFN("sensor_register_callback"); | |
sensor_register_callback(); | |
ISP_DEV isp_dev = 0; | |
ALG_LIB_S lib; | |
memset(&lib,0,sizeof(ALG_LIB_S)); | |
lib.s32Id = 0; | |
strcpy(lib.acLibName, "hisi_ae_lib\0 "); | |
s32Ret = FNLOG(HI_MPI_AE_Register)(isp_dev, &lib); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_AE_Register faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
lib.s32Id = 0; | |
strcpy(lib.acLibName, "hisi_awb_lib\0 "); | |
s32Ret = FNLOG(HI_MPI_AWB_Register)(isp_dev, &lib); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_AWB_Register faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
lib.s32Id = 0; | |
strcpy(lib.acLibName, "hisi_af_lib\0 "); | |
s32Ret = FNLOG(HI_MPI_AF_Register)(isp_dev, &lib); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_AF_Register faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_ISP_MemInit)(isp_dev); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_ISP_MemInit faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
ISP_WDR_MODE_S wdr_mode; | |
memset(&wdr_mode,0,sizeof(ISP_WDR_MODE_S)); | |
wdr_mode.enWDRMode = WDR_MODE_NONE; | |
s32Ret = FNLOG(HI_MPI_ISP_SetWDRMode)(isp_dev, &wdr_mode); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_ISP_SetWDRMode faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
ISP_PUB_ATTR_S pub_attr; | |
memset(&pub_attr,0,sizeof(ISP_PUB_ATTR_S)); | |
pub_attr.enBayer = BAYER_RGGB; | |
pub_attr.f32FrameRate = 30.0; | |
pub_attr.stWndRect.s32X = 200; | |
pub_attr.stWndRect.s32Y = 20; | |
pub_attr.stWndRect.u32Width = 1920; | |
pub_attr.stWndRect.u32Height = 1080; | |
s32Ret = FNLOG(HI_MPI_ISP_SetPubAttr)(isp_dev, &pub_attr); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_ISP_SetPubAttr faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_ISP_Init)(isp_dev); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_ISP_Init faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
pthread_t gs_IspPid = 0; | |
if (0 != pthread_create(&gs_IspPid, 0, (void* (*)(void*))Test_ISP_Run, NULL)) { | |
printf("%s: create isp running thread failed!\n", __FUNCTION__); return EXIT_FAILURE; | |
} | |
usleep(1000); | |
VI_DEV vi_dev = 0; | |
VI_DEV_ATTR_S vi_dev_attr; | |
memset(&vi_dev_attr,0,sizeof(VI_DEV_ATTR_S)); | |
vi_dev_attr.enIntfMode = VI_MODE_DIGITAL_CAMERA; | |
vi_dev_attr.enWorkMode = VI_WORK_MODE_1Multiplex; | |
vi_dev_attr.au32CompMask[0] = 268369920; | |
vi_dev_attr.au32CompMask[1] = 0x0; | |
vi_dev_attr.enScanMode = VI_SCAN_PROGRESSIVE; | |
vi_dev_attr.s32AdChnId[0] = -1; | |
vi_dev_attr.s32AdChnId[1] = -1; | |
vi_dev_attr.s32AdChnId[2] = -1; | |
vi_dev_attr.s32AdChnId[3] = -1; | |
vi_dev_attr.stDevRect.s32X = 0; | |
vi_dev_attr.stDevRect.s32Y = 0; | |
vi_dev_attr.stDevRect.u32Width = 1920; | |
vi_dev_attr.stDevRect.u32Height = 1080; | |
vi_dev_attr.enDataSeq = VI_INPUT_DATA_YUYV; | |
vi_dev_attr.stSynCfg.enVsync = VI_VSYNC_PULSE; | |
vi_dev_attr.stSynCfg.enVsyncNeg = VI_VSYNC_NEG_HIGH; | |
vi_dev_attr.stSynCfg.enHsync = VI_HSYNC_VALID_SINGNAL; | |
vi_dev_attr.stSynCfg.enHsyncNeg = VI_HSYNC_NEG_HIGH; | |
vi_dev_attr.stSynCfg.enVsyncValid = VI_VSYNC_VALID_SINGAL; | |
vi_dev_attr.stSynCfg.enVsyncValidNeg = VI_VSYNC_VALID_NEG_HIGH; | |
vi_dev_attr.stSynCfg.stTimingBlank.u32HsyncHfb = 0; | |
vi_dev_attr.stSynCfg.stTimingBlank.u32HsyncAct = 1920; | |
vi_dev_attr.stSynCfg.stTimingBlank.u32HsyncHbb = 0; | |
vi_dev_attr.stSynCfg.stTimingBlank.u32VsyncVfb = 0; | |
vi_dev_attr.stSynCfg.stTimingBlank.u32VsyncVact = 1080; | |
vi_dev_attr.stSynCfg.stTimingBlank.u32VsyncVbb = 0; | |
vi_dev_attr.stSynCfg.stTimingBlank.u32VsyncVbfb = 0; | |
vi_dev_attr.stSynCfg.stTimingBlank.u32VsyncVbact = 0; | |
vi_dev_attr.stSynCfg.stTimingBlank.u32VsyncVbbb = 0; | |
vi_dev_attr.enDataPath = VI_PATH_ISP; | |
vi_dev_attr.enInputDataType = VI_DATA_TYPE_RGB; | |
vi_dev_attr.bDataRev = HI_FALSE; | |
vi_dev_attr.stDevRect.s32X = 200; | |
vi_dev_attr.stDevRect.s32Y = 20; | |
vi_dev_attr.stDevRect.u32Width = 1920; | |
vi_dev_attr.stDevRect.u32Height = 1080; | |
s32Ret = FNLOG(HI_MPI_VI_SetDevAttr)(vi_dev, &vi_dev_attr); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VI_SetDevAttr faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
// ISP_WDR_MODE_S wdr_mode; | |
// memset(&wdr_mode,0,sizeof(ISP_WDR_MODE_S)); | |
// wdr_mode.enWDRMode = WDR_MODE_NONE; | |
s32Ret = FNLOG(HI_MPI_ISP_GetWDRMode)(isp_dev, &wdr_mode); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_ISP_GetWDRMode faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
// TODO | |
VI_WDR_ATTR_S wdr_addr; | |
memset(&wdr_mode,0,sizeof(ISP_WDR_MODE_S)); | |
wdr_addr.enWDRMode = WDR_MODE_NONE; | |
wdr_addr.bCompress = HI_FALSE; | |
s32Ret = FNLOG(HI_MPI_VI_SetWDRAttr)(vi_dev, &wdr_addr); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VI_SetWDRAttr faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VI_EnableDev)(vi_dev); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VI_EnableDev faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
VI_CHN vi_chn; | |
VI_CHN_ATTR_S chn_attr; | |
memset(&chn_attr,0,sizeof(VI_CHN_ATTR_S)); | |
chn_attr.stCapRect.s32X = 0; | |
chn_attr.stCapRect.s32Y = 0; | |
chn_attr.stCapRect.u32Width = 1920; | |
chn_attr.stCapRect.u32Height = 1080; | |
chn_attr.stDestSize.u32Width = 1920; | |
chn_attr.stDestSize.u32Height = 1080; | |
chn_attr.enCapSel = VI_CAPSEL_BOTH; | |
chn_attr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; | |
chn_attr.bMirror = HI_FALSE; | |
chn_attr.bFlip = HI_FALSE; | |
chn_attr.s32SrcFrameRate = -1; | |
chn_attr.s32DstFrameRate = -1; | |
chn_attr.enCompressMode = COMPRESS_MODE_NONE; | |
s32Ret = FNLOG(HI_MPI_VI_SetChnAttr)(vi_chn, &chn_attr); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VI_SetChnAttr faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VI_EnableChn)(vi_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VI_EnableChn faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
VPSS_GRP vpss_grp = 0; | |
VPSS_GRP_ATTR_S vpss_grp_attr; | |
memset(&vpss_grp_attr,0,sizeof(VPSS_GRP_ATTR_S)); | |
vpss_grp_attr.u32MaxW = 1920; | |
vpss_grp_attr.u32MaxH = 1080; | |
vpss_grp_attr.enPixFmt = PIXEL_FORMAT_YUV_SEMIPLANAR_420; | |
vpss_grp_attr.bIeEn = HI_FALSE; | |
vpss_grp_attr.bDciEn = HI_FALSE; | |
vpss_grp_attr.bNrEn = HI_TRUE; | |
vpss_grp_attr.bHistEn = HI_FALSE; | |
vpss_grp_attr.enDieMode = VPSS_DIE_MODE_NODIE; | |
s32Ret = FNLOG(HI_MPI_VPSS_CreateGrp)(vpss_grp, &vpss_grp_attr); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_CreateGrp faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
VPSS_NR_PARAM_U nr_param; | |
memset(&nr_param,0,sizeof(VPSS_NR_PARAM_U)); | |
s32Ret = FNLOG(HI_MPI_VPSS_GetNRParam)(vpss_grp, &nr_param); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_GetNRParam faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
nr_param.stNRParam_V1.s32YPKStr = 0; | |
nr_param.stNRParam_V1.s32YSFStr = 100; | |
nr_param.stNRParam_V1.s32YTFStr = 64; | |
nr_param.stNRParam_V1.s32TFStrMax = 12; | |
nr_param.stNRParam_V1.s32TFStrMov = 0; | |
nr_param.stNRParam_V1.s32YSmthStr = 0; | |
nr_param.stNRParam_V1.s32YSmthRat = 16; | |
nr_param.stNRParam_V1.s32YSFStrDlt = 0; | |
nr_param.stNRParam_V1.s32YSFStrDl = 0; | |
nr_param.stNRParam_V1.s32YTFStrDlt = 0; | |
nr_param.stNRParam_V1.s32YTFStrDl = 0; | |
nr_param.stNRParam_V1.s32YSFBriRat = 24; | |
nr_param.stNRParam_V1.s32CSFStr = 32; | |
nr_param.stNRParam_V1.s32CTFstr = 0; | |
nr_param.stNRParam_V1.s32YTFMdWin = 1; | |
s32Ret = FNLOG(HI_MPI_VPSS_SetNRParam)(vpss_grp, &nr_param); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_SetNRParam faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VPSS_StartGrp)(vpss_grp); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_StartGrp faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
MPP_CHN_S src_chn; | |
src_chn.enModId = HI_ID_VIU; | |
src_chn.s32DevId = 0; | |
src_chn.s32ChnId = 0; | |
MPP_CHN_S dest_chn; | |
dest_chn.enModId = HI_ID_VPSS; | |
dest_chn.s32DevId = 0; | |
dest_chn.s32ChnId = 0; | |
s32Ret = FNLOG(HI_MPI_SYS_Bind)(&src_chn, &dest_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_SYS_Bind faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
VPSS_CHN vpss_chn = 0; | |
VPSS_CHN_ATTR_S vpss_chn_attr; | |
memset(&vpss_chn_attr,0,sizeof(VPSS_CHN_ATTR_S)); | |
vpss_chn_attr.bSpEn = HI_FALSE; | |
vpss_chn_attr.bBorderEn = HI_FALSE; | |
vpss_chn_attr.bMirror = HI_FALSE; | |
vpss_chn_attr.bFlip = HI_FALSE; | |
vpss_chn_attr.s32SrcFrameRate = -1; | |
vpss_chn_attr.s32DstFrameRate = -1; | |
vpss_chn_attr.stBorder.u32TopWidth = 0; | |
vpss_chn_attr.stBorder.u32BottomWidth = 0; | |
vpss_chn_attr.stBorder.u32LeftWidth = 0; | |
vpss_chn_attr.stBorder.u32RightWidth = 0; | |
vpss_chn_attr.stBorder.u32Color = 0; | |
s32Ret = FNLOG(HI_MPI_VPSS_SetChnAttr)(vpss_grp, vpss_chn, &vpss_chn_attr); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_SetChnAttr faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
VPSS_CHN_MODE_S vpss_chn_mode; | |
vpss_chn_mode.enChnMode = VPSS_CHN_MODE_USER; | |
vpss_chn_mode.u32Width = 1920; | |
vpss_chn_mode.u32Height = 1080; | |
vpss_chn_mode.bDouble = HI_FALSE; | |
vpss_chn_mode.enPixelFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; | |
vpss_chn_mode.enCompressMode = COMPRESS_MODE_NONE; | |
s32Ret = FNLOG(HI_MPI_VPSS_SetChnMode)(vpss_grp, vpss_chn, &vpss_chn_mode); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_SetChnMode faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VPSS_EnableChn)(vpss_grp, vpss_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_EnableChn faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
ISP_DCF_INFO_S isp_dcf; | |
memset(&isp_dcf,0,sizeof(ISP_DCF_INFO_S)); | |
s32Ret = FNLOG(HI_MPI_ISP_GetDCFInfo)(&isp_dcf); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_ISP_GetDCFInfo faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
memset(&isp_dcf,0,sizeof(ISP_DCF_INFO_S)); | |
memcpy(isp_dcf.au8ImageDescription,"Thumbnail test",strlen("Thumbnail test")); //description: Thumbnail test | |
memcpy(isp_dcf.au8Make,"Hisilicon",strlen("Hisilicon")); //manufacturer: Hisilicon | |
memcpy(isp_dcf.au8Model,"Hisilicon IP Camera",strlen("Hisilicon IP Camera")); //model number: Hisilicon IP Camera | |
memcpy(isp_dcf.au8Software,"v.1.1.0",strlen("v.1.1.0")); //firmware version: v.1.1.0 | |
isp_dcf.u16ISOSpeedRatings = 500; | |
isp_dcf.u32FNumber = 65551; | |
isp_dcf.u32MaxApertureValue = 65537; | |
isp_dcf.u32ExposureTime = 65540; | |
isp_dcf.u32ExposureBiasValue = 5; | |
isp_dcf.u8ExposureProgram = 1; | |
isp_dcf.u8MeteringMode = 1; | |
isp_dcf.u8LightSource = 1; | |
isp_dcf.u32FocalLength = 6553601; | |
isp_dcf.u8SceneType = 0; | |
isp_dcf.u8CustomRendered = 0; | |
isp_dcf.u8ExposureMode = 0; | |
isp_dcf.u8WhiteBalance = 1; | |
isp_dcf.u8FocalLengthIn35mmFilm = 1; | |
isp_dcf.u8SceneCaptureType = 1; | |
isp_dcf.u8GainControl = 1; | |
isp_dcf.u8Contrast = 5; | |
isp_dcf.u8Saturation = 1; | |
isp_dcf.u8Sharpness = 5; | |
s32Ret = FNLOG(HI_MPI_ISP_SetDCFInfo)(&isp_dcf); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_ISP_SetDCFInfo faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
VENC_ATTR_JPEG_S jpeg_attr; | |
memset(&jpeg_attr, 0, sizeof(VENC_ATTR_JPEG_S)); | |
jpeg_attr.u32MaxPicWidth = 1920; | |
jpeg_attr.u32MaxPicHeight = 1080; | |
jpeg_attr.u32BufSize = (((1920+15)>>4)<<4) * (((1080+15)>>4)<<4); | |
jpeg_attr.bByFrame = HI_TRUE; | |
jpeg_attr.u32PicWidth = 1920; | |
jpeg_attr.u32PicHeight = 1080; | |
jpeg_attr.bSupportDCF = HI_TRUE; | |
VENC_ATTR_S ve_attr; | |
memset(&ve_attr, 0, sizeof(VENC_ATTR_S)); | |
ve_attr.enType = PT_JPEG; | |
ve_attr.stAttrJpeg = jpeg_attr; | |
VENC_RC_ATTR_S rc_attr; | |
memset(&rc_attr, 0, sizeof(VENC_RC_ATTR_S)); | |
VENC_CHN venc_chn = 0; | |
VENC_CHN_ATTR_S venc_chn_attr; | |
memset(&venc_chn_attr, 0, sizeof(VENC_CHN_ATTR_S)); | |
venc_chn_attr.stVeAttr = ve_attr; | |
venc_chn_attr.stRcAttr = rc_attr; | |
s32Ret = FNLOG(HI_MPI_VENC_CreateChn)(venc_chn, &venc_chn_attr); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VENC_CreateChn faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
{ | |
MPP_CHN_S src_chn; | |
src_chn.enModId = HI_ID_VPSS; | |
src_chn.s32DevId = 0; | |
src_chn.s32ChnId = 0; | |
MPP_CHN_S dest_chn; | |
dest_chn.enModId = HI_ID_VENC; | |
dest_chn.s32DevId = 0; | |
dest_chn.s32ChnId = 0; | |
s32Ret = FNLOG(HI_MPI_SYS_Bind)(&src_chn, &dest_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_SYS_Bind faild with %#x!\n", s32Ret); | |
return HI_FAILURE; | |
} | |
} | |
VENC_RECV_PIC_PARAM_S recv_param; | |
recv_param.s32RecvPicNum = 1; | |
s32Ret = FNLOG(HI_MPI_VENC_StartRecvPicEx)(venc_chn, &recv_param); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VENC_StartRecvPicEx faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
HI_S32 s32VencFd = FNLOG(HI_MPI_VENC_GetFd)(venc_chn); | |
if (s32VencFd < 0) { | |
printf("HI_MPI_VENC_GetFd faild with%#x!\n", s32VencFd); | |
return HI_FAILURE; | |
} | |
fd_set read_fds; | |
FD_ZERO(&read_fds); | |
FD_SET(s32VencFd, &read_fds); | |
struct timeval TimeoutVal; | |
TimeoutVal.tv_sec = 2; | |
TimeoutVal.tv_usec = 0; | |
s32Ret = select(s32VencFd+1, &read_fds, NULL, NULL, &TimeoutVal); | |
if (s32Ret < 0) { | |
printf("snap select failed!\n"); | |
return EXIT_FAILURE; | |
} | |
if (0 == s32Ret) { | |
printf("snap time out!\n"); | |
return EXIT_FAILURE; | |
} | |
if (!FD_ISSET(s32VencFd, &read_fds)) { | |
printf("can't read snapshot!\n"); | |
return EXIT_FAILURE; | |
} | |
VENC_CHN_STAT_S stat; | |
memset(&stat, 0, sizeof(VENC_CHN_STAT_S)); | |
s32Ret = FNLOG(HI_MPI_VENC_Query)(venc_chn, &stat); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VENC_Query faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
VENC_STREAM_S stream; | |
stream.pstPack = (VENC_PACK_S*)malloc(sizeof(VENC_PACK_S) * stat.u32CurPacks); | |
stream.u32PackCount = stat.u32CurPacks; | |
stream.u32Seq = 0; | |
stream.stJpegInfo.u32PicBytesNum = 0; | |
stream.stJpegInfo.u32Qfactor = 0; | |
stream.stJpegInfo.u32UpdateAttrCnt = 0; | |
s32Ret = FNLOG(HI_MPI_VENC_GetStream)(venc_chn, &stream, -1); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VENC_GetStream faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
FILE *fpJpegFile = fopen("/tmp/svenc.jpg", "wb"); | |
for (HI_U32 i = 0; i < stream.u32PackCount; i++) | |
{ | |
VENC_PACK_S* pstData = &stream.pstPack[i]; | |
fwrite(pstData->pu8Addr+pstData->u32Offset, pstData->u32Len-pstData->u32Offset, 1, fpJpegFile); | |
fflush(fpJpegFile); | |
} | |
fclose(fpJpegFile); | |
s32Ret = FNLOG(HI_MPI_VENC_ReleaseStream)(venc_chn, &stream); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VENC_ReleaseStream faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VENC_StopRecvPic)(venc_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VENC_StopRecvPic faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
{ | |
MPP_CHN_S src_chn; | |
src_chn.enModId = HI_ID_VPSS; | |
src_chn.s32DevId = 0; | |
src_chn.s32ChnId = 0; | |
MPP_CHN_S dest_chn; | |
dest_chn.enModId = HI_ID_VENC; | |
dest_chn.s32DevId = 0; | |
dest_chn.s32ChnId = 0; | |
s32Ret = FNLOG(HI_MPI_SYS_UnBind)(&src_chn, &dest_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_SYS_UnBind faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
} | |
s32Ret = FNLOG(HI_MPI_VENC_StopRecvPic)(venc_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VENC_StopRecvPic faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VENC_DestroyChn)(venc_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VENC_DestroyChn faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VPSS_DisableChn)(vpss_grp, vpss_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_DisableChn faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
{ | |
MPP_CHN_S src_chn; | |
src_chn.enModId = HI_ID_VIU; | |
src_chn.s32DevId = 0; | |
src_chn.s32ChnId = 0; | |
MPP_CHN_S dest_chn; | |
dest_chn.enModId = HI_ID_VPSS; | |
dest_chn.s32DevId = 0; | |
dest_chn.s32ChnId = 0; | |
s32Ret = FNLOG(HI_MPI_SYS_UnBind)(&src_chn, &dest_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_SYS_UnBind faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
} | |
s32Ret = FNLOG(HI_MPI_VPSS_StopGrp)(vpss_grp); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_StopGrp faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VPSS_DestroyGrp)(vpss_grp); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VPSS_DestroyGrp faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VI_DisableChn)(vi_chn); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VI_DisableChn faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VI_DisableDev)(vi_dev); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VI_DisableDev faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
lib.s32Id = 0; | |
strcpy(lib.acLibName, "hisi_af_lib\0 "); | |
s32Ret = FNLOG(HI_MPI_AF_UnRegister)(isp_dev, & lib); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_AF_UnRegister faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
lib.s32Id = 0; | |
strcpy(lib.acLibName, "hisi_awb_lib\0 "); | |
s32Ret = FNLOG(HI_MPI_AWB_UnRegister)(isp_dev, & lib); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_AWB_UnRegister faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
lib.s32Id = 0; | |
strcpy(lib.acLibName, "hisi_ae_lib\0 "); | |
s32Ret = FNLOG(HI_MPI_AE_UnRegister)(isp_dev, & lib); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_AE_UnRegister faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
sensor_unregister_callback(); | |
s32Ret = FNLOG(HI_MPI_SYS_Exit)(); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_SYS_Exit faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
s32Ret = FNLOG(HI_MPI_VB_Exit)(); | |
if (HI_SUCCESS != s32Ret) { | |
printf("HI_MPI_VB_Exit faild with %#x!\n", s32Ret); return EXIT_FAILURE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment