海思3516的开箱测试代码>>>>开发板测评-海思hi3518e开发教程

有小伙伴说, 直接跑官方的代码跑不起来, 这里以vio代码为例, 说说怎么从源码编译海思的应用.

首先环境是单摄GC2053, 接CSI1, 如下图:

海思3516的开箱测试代码>>>>开发板测评-海思hi3518e开发教程

在sdk里面找到

hi3516sdk/smp/a7_linux/mpp/sample/Makefile.param

修改摄像头为你的摄像头型号, 比如GC2053

SENSOR0_TYPE ?= GALAXYCORE_GC2053_MIPI_2M_30FPS_10BIT SENSOR1_TYPE ?= GALAXYCORE_GC2053_MIPI_2M_30FPS_10BIT

修改

hi3516sdk/smp/a7_linux/mpp/sample/common/sample_comm_vi.c

文件, 修改下面的变量值

/***************************************************************************** * function : init mipi *****************************************************************************/ HI_S32 SAMPLE_COMM_VI_StartMIPI(SAMPLE_VI_CONFIG_S *pstViConfig) { HI_S32 s32Ret = HI_SUCCESS; lane_divide_mode_t lane_divide_mode = LANE_DIVIDE_MODE_0; if (!pstViConfig) { SAMPLE_PRT(“%s: null ptr\n”, __FUNCTION__); return HI_FAILURE; } // 加入这一行 lane_divide_mode = LANE_DIVIDE_MODE_1; SAMPLE_PRT(“lane_divide_mode:%d \n”, lane_divide_mode); // lane_divide_mode = SAMPLE_COMM_VI_GetMipiLaneDivideMode(pstViConfig); s32Ret = SAMPLE_COMM_VI_SetMipiHsMode(lane_divide_mode); if (HI_SUCCESS != s32Ret) {
<

在sample文件夹中建一个子文件夹, 名字无所谓, 然后建一个c文件

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <pthread.h> #include <signal.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/ioctl.h> #include “sample_comm.h” HI_VOID SAMPLE_VIO_MsgInit(HI_VOID) { } HI_VOID SAMPLE_VIO_MsgExit(HI_VOID) { } void SAMPLE_VIO_HandleSig(HI_S32 signo) { signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); if (SIGINT == signo || SIGTERM == signo) { SAMPLE_COMM_VENC_StopGetStream(); SAMPLE_COMM_All_ISP_Stop(); SAMPLE_COMM_VO_HdmiStop(); SAMPLE_COMM_SYS_Exit(); SAMPLE_PRT(“\033[0;31mprogram termination abnormally!\033[0;39m\n”); } exit(-1); } HI_S32 SAMPLE_VIO_ViOnlineVpssOnlineRoute(HI_U32 u32VoIntfType) { HI_S32 s32Ret = HI_SUCCESS; HI_S32 s32ViCnt = 1; VI_DEV ViDev = 1; VI_PIPE ViPipe = 0; VI_CHN ViChn = 0; HI_S32 s32WorkSnsId = 0; SAMPLE_VI_CONFIG_S stViConfig; SIZE_S stSize; VB_CONFIG_S stVbConf; PIC_SIZE_E enPicSize; HI_U32 u32BlkSize; VO_CHN VoChn = 0; SAMPLE_VO_CONFIG_S stVoConfig; WDR_MODE_E enWDRMode = WDR_MODE_NONE; DYNAMIC_RANGE_E enDynamicRange = DYNAMIC_RANGE_SDR8; PIXEL_FORMAT_E enPixFormat = PIXEL_FORMAT_YVU_SEMIPLANAR_420; VIDEO_FORMAT_E enVideoFormat = VIDEO_FORMAT_LINEAR; COMPRESS_MODE_E enCompressMode = COMPRESS_MODE_NONE; VI_VPSS_MODE_E enMastPipeMode = VI_ONLINE_VPSS_ONLINE; VPSS_GRP VpssGrp = 0; VPSS_GRP_ATTR_S stVpssGrpAttr; VPSS_CHN VpssChn = VPSS_CHN0; HI_BOOL abChnEnable[VPSS_MAX_PHY_CHN_NUM] = {0}; VPSS_CHN_ATTR_S astVpssChnAttr[VPSS_MAX_PHY_CHN_NUM]; VENC_CHN VencChn[1] = {0}; PAYLOAD_TYPE_E enType = PT_H265; SAMPLE_RC_E enRcMode = SAMPLE_RC_CBR; HI_U32 u32Profile = 0; HI_BOOL bRcnRefShareBuf = HI_FALSE; VENC_GOP_ATTR_S stGopAttr; /*config vi*/ SAMPLE_COMM_VI_GetSensorInfo(&stViConfig); SAMPLE_PRT(“ViDev:%d, ViPipe:%d, ViChn:%d, s32WorkSnsId:%d”, ViDev, ViPipe, ViChn, s32WorkSnsId); stViConfig.s32WorkingViNum = s32ViCnt; stViConfig.as32WorkingViId[0] = 0; stViConfig.astViInfo[s32WorkSnsId].stSnsInfo.MipiDev = ViDev; stViConfig.astViInfo[s32WorkSnsId].stSnsInfo.s32BusId = 1; stViConfig.astViInfo[s32WorkSnsId].stDevInfo.ViDev = ViDev; stViConfig.astViInfo[s32WorkSnsId].stDevInfo.enWDRMode = enWDRMode; stViConfig.astViInfo[s32WorkSnsId].stPipeInfo.enMastPipeMode = enMastPipeMode; stViConfig.astViInfo[s32WorkSnsId].stPipeInfo.aPipe[0] = ViPipe; stViConfig.astViInfo[s32WorkSnsId].stPipeInfo.aPipe[1] = -1; stViConfig.astViInfo[s32WorkSnsId].stPipeInfo.aPipe[2] = -1; stViConfig.astViInfo[s32WorkSnsId].stPipeInfo.aPipe[3] = -1; stViConfig.astViInfo[s32WorkSnsId].stChnInfo.ViChn = ViChn; stViConfig.astViInfo[s32WorkSnsId].stChnInfo.enPixFormat = enPixFormat; stViConfig.astViInfo[s32WorkSnsId].stChnInfo.enDynamicRange = enDynamicRange; stViConfig.astViInfo[s32WorkSnsId].stChnInfo.enVideoFormat = enVideoFormat; stViConfig.astViInfo[s32WorkSnsId].stChnInfo.enCompressMode = enCompressMode; /*get picture size*/ s32Ret = SAMPLE_COMM_VI_GetSizeBySensor(stViConfig.astViInfo[s32WorkSnsId].stSnsInfo.enSnsType, &enPicSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“get picture size by sensor failed!\n”); return s32Ret; } s32Ret = SAMPLE_COMM_SYS_GetPicSize(enPicSize, &stSize); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“get picture size failed!\n”); return s32Ret; } /*config vb*/ memset_s(&stVbConf, sizeof(VB_CONFIG_S), 0, sizeof(VB_CONFIG_S)); stVbConf.u32MaxPoolCnt = 2; u32BlkSize = COMMON_GetPicBufferSize(stSize.u32Width, stSize.u32Height, SAMPLE_PIXEL_FORMAT, DATA_BITWIDTH_8, COMPRESS_MODE_SEG, DEFAULT_ALIGN); stVbConf.astCommPool[0].u64BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = 10; u32BlkSize = VI_GetRawBufferSize(stSize.u32Width, stSize.u32Height, PIXEL_FORMAT_RGB_BAYER_16BPP, COMPRESS_MODE_NONE, DEFAULT_ALIGN); stVbConf.astCommPool[1].u64BlkSize = u32BlkSize; stVbConf.astCommPool[1].u32BlkCnt = 4; s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“system init failed with %d!\n”, s32Ret); return s32Ret; } /*start vi*/ s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“start vi failed.s32Ret:0x%x !\n”, s32Ret); goto EXIT; } /*config vpss*/ memset_s(&stVpssGrpAttr, sizeof(VPSS_GRP_ATTR_S), 0, sizeof(VPSS_GRP_ATTR_S)); stVpssGrpAttr.stFrameRate.s32SrcFrameRate = -1; stVpssGrpAttr.stFrameRate.s32DstFrameRate = -1; stVpssGrpAttr.enDynamicRange = DYNAMIC_RANGE_SDR8; stVpssGrpAttr.enPixelFormat = enPixFormat; stVpssGrpAttr.u32MaxW = stSize.u32Width; stVpssGrpAttr.u32MaxH = stSize.u32Height; stVpssGrpAttr.bNrEn = HI_TRUE; stVpssGrpAttr.stNrAttr.enCompressMode = COMPRESS_MODE_FRAME; stVpssGrpAttr.stNrAttr.enNrMotionMode = NR_MOTION_MODE_NORMAL; astVpssChnAttr[VpssChn].u32Width = stSize.u32Width; astVpssChnAttr[VpssChn].u32Height = stSize.u32Height; astVpssChnAttr[VpssChn].enChnMode = VPSS_CHN_MODE_USER; astVpssChnAttr[VpssChn].enCompressMode = enCompressMode; astVpssChnAttr[VpssChn].enDynamicRange = enDynamicRange; astVpssChnAttr[VpssChn].enVideoFormat = enVideoFormat; astVpssChnAttr[VpssChn].enPixelFormat = enPixFormat; astVpssChnAttr[VpssChn].stFrameRate.s32SrcFrameRate = 30; astVpssChnAttr[VpssChn].stFrameRate.s32DstFrameRate = 30; astVpssChnAttr[VpssChn].u32Depth = 0; astVpssChnAttr[VpssChn].bMirror = HI_FALSE; astVpssChnAttr[VpssChn].bFlip = HI_FALSE; astVpssChnAttr[VpssChn].stAspectRatio.enMode = ASPECT_RATIO_NONE; /*start vpss*/ abChnEnable[0] = HI_TRUE; s32Ret = SAMPLE_COMM_VPSS_Start(VpssGrp, abChnEnable, &stVpssGrpAttr, astVpssChnAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“start vpss group failed. s32Ret: 0x%x !\n”, s32Ret); goto EXIT1; } /*config venc */ stGopAttr.enGopMode = VENC_GOPMODE_SMARTP; stGopAttr.stSmartP.s32BgQpDelta = 7; stGopAttr.stSmartP.s32ViQpDelta = 2; stGopAttr.stSmartP.u32BgInterval = 1200; s32Ret = SAMPLE_COMM_VENC_Start(VencChn[0], enType, enPicSize, enRcMode, u32Profile, bRcnRefShareBuf, &stGopAttr); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“start venc failed. s32Ret: 0x%x !\n”, s32Ret); goto EXIT2; } s32Ret = SAMPLE_COMM_VPSS_Bind_VENC(VpssGrp, VpssChn, VencChn[0]); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“Venc bind Vpss failed. s32Ret: 0x%x !n”, s32Ret); goto EXIT3; } /*config vo*/ SAMPLE_COMM_VO_GetDefConfig(&stVoConfig); stVoConfig.enDstDynamicRange = enDynamicRange; if (1 == u32VoIntfType) { stVoConfig.enVoIntfType = VO_INTF_BT1120; stVoConfig.enIntfSync = VO_OUTPUT_1080P25; } else { stVoConfig.enVoIntfType = VO_INTF_HDMI; } stVoConfig.enPicSize = enPicSize; /*start vo*/ s32Ret = SAMPLE_COMM_VO_StartVO(&stVoConfig); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“start vo failed. s32Ret: 0x%x !\n”, s32Ret); goto EXIT4; } /*vpss bind vo*/ s32Ret = SAMPLE_COMM_VPSS_Bind_VO(VpssGrp, VpssChn, stVoConfig.VoDev, VoChn); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“vo bind vpss failed. s32Ret: 0x%x !\n”, s32Ret); goto EXIT5; } s32Ret = SAMPLE_COMM_VENC_StartGetStream(VencChn, sizeof(VencChn) / sizeof(VENC_CHN)); if (HI_SUCCESS != s32Ret) { SAMPLE_PRT(“Get venc stream failed!\n”); goto EXIT6; } PAUSE(); SAMPLE_COMM_VENC_StopGetStream(); EXIT6: SAMPLE_COMM_VPSS_UnBind_VO(VpssGrp, VpssChn, stVoConfig.VoDev, VoChn); EXIT5: SAMPLE_COMM_VO_StopVO(&stVoConfig); EXIT4: SAMPLE_COMM_VPSS_UnBind_VENC(VpssGrp, VpssChn, VencChn[0]); EXIT3: SAMPLE_COMM_VENC_Stop(VencChn[0]); EXIT2: SAMPLE_COMM_VPSS_Stop(VpssGrp, abChnEnable); EXIT1: SAMPLE_COMM_VI_StopVi(&stViConfig); EXIT: SAMPLE_COMM_SYS_Exit(); return s32Ret; } int main(void) { HI_U32 u32VoIntfType = 0; HI_U32 u32ChipId; HI_MPI_SYS_GetChipId(&u32ChipId); if (HI3516C_V500 == u32ChipId) { u32VoIntfType = 1; } else { u32VoIntfType = 0; } SAMPLE_VIO_ViOnlineVpssOnlineRoute(0); }
<

在同一个文件夹下面加入Makefile编译文件

# Hisilicon Hi35xx sample Makefile include ../Makefile.param SMP_SRCS := $(wildcard *.c) TARGET := $(SMP_SRCS:%.c=%) TARGET_PATH := $(PWD) # compile linux or HuaweiLite include $(PWD)/../$(ARM_ARCH)_$(OSTYPE).mak

然后就make一下, 把生成的可执行文件复制到你板子上就可以跑起来了, 同时会在同一个目录生成h.265的码流.

串口看到的log应该差不多这样:

/sd/vio_demo # ./my_vio_csi1 [SAMPLE_VIO_ViOnlineVpssOnlineRoute]-80: ViDev:1, ViPipe:0, ViChn:0, s32WorkSnsId:0[SAMPLE_COMM_VI_StartVi]-3577: SAMPLE_COMM_VI_StartMIPI [SAMPLE_COMM_VI_StartMIPI]-2050: lane_divide_mode:1 [SAMPLE_COMM_VI_StartMIPI]-2062: SAMPLE_COMM_VI_EnableMipiClock [SAMPLE_COMM_VI_EnableMipiClock]-1521: s32WorkingViNum: 1 [SAMPLE_COMM_VI_EnableMipiClock]-1525: i: 0 [SAMPLE_COMM_VI_EnableMipiClock]-1528: s32ViNum: 0 [SAMPLE_COMM_VI_EnableMipiClock]-1534: devno: 1 [SAMPLE_COMM_VI_EnableMipiClock]-1538: MIPI_ENABLE_CLOCK:1 [SAMPLE_COMM_VI_StartMIPI]-2071: SAMPLE_COMM_VI_ResetMipi [SAMPLE_COMM_VI_StartMIPI]-2081: SAMPLE_COMM_VI_EnableSensorClock [SAMPLE_COMM_VI_StartMIPI]-2091: SAMPLE_COMM_VI_ResetSensor [SAMPLE_COMM_VI_SetMipiAttr]-2000: ============= MipiDev 1, SetMipiAttr enWDRMode: 0 [SAMPLE_COMM_VI_StartVi]-3585: SAMPLE_COMM_VI_SetParam GC2053_SENSOR_1080P_30FPS_LINEAR_MODE === Galaxycore GC2053_1080P_30FPS_10BIT_LINE_Init_OK!=== GC2053 init succuss! [SAMPLE_COMM_ISP_Thread]-526: ISP Dev 0 running ! [SAMPLE_COMM_VO_StartChn]-540: u32Width:1920, u32Height:1080, u32Square:1 —————press Enter key to exit!————— [SAMPLE_COMM_VENC_GetVencStreamProc]-1985: s32ChnTotal:1 [SAMPLE_COMM_VENC_GetVencStreamProc]-2032: VencFd i:0 fd:16

免责声明:文章内容来自互联网,本站不对其真实性负责,也不承担任何法律责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:海思3516的开箱测试代码>>>>开发板测评-海思hi3518e开发教程 https://www.yhzz.com.cn/a/9626.html

上一篇 2023-04-20
下一篇 2023-04-20

相关推荐

联系云恒

在线留言: 我要留言
客服热线:400-600-0310
工作时间:周一至周六,08:30-17:30,节假日休息。