首页专栏详情
打赏
海思3516的开箱测试代码>>>>开发板测评
海思3516的开箱测试代码>>>>开发板测评
易百纳技术社区 Marc 2022-11-03 09:27:26

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

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

在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




声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。

821
收藏
点赞
打赏
给作者打赏,鼓励他抓紧创作吧~
评论
0个
内容存在敏感词
相关专栏
打赏作者
易百纳技术社区
Marc
您的支持将鼓励我继续创作!
打赏金额:
¥1 易百纳技术社区
¥5 易百纳技术社区
¥10 易百纳技术社区
¥50 易百纳技术社区
¥100 易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区 微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
Loading...
易百纳技术社区
确定要删除此文章、专栏、评论吗?
确定
取消
易百纳技术社区
易百纳技术社区
在专栏模块发布专栏,可获得其他E友的打赏
易百纳技术社区
回答悬赏问答,被题主采纳后即可获得悬赏金
易百纳技术社区
在上传资料时,有价值的资料可设置为付费资源
易百纳技术社区
达到一定金额,收益即可提现~
收益也可用来充值ebc,下载资料、兑换礼品更容易
易百纳技术社区
活动规则
  • 1.周任务为周期性任务,每周周一00:00刷新,上周完成的任务不会累计到本周,本周需要从头开始任务,当前任务完成后才可以完成下一个任务
  • 2.发布的专栏与资料需要与平台的板块有相关性,禁止注水,专栏/资料任务以审核通过的篇数为准
  • 3.任务完成后,现金奖励直接打款到微信账户;EBC/收益将自动发放到个人账户,可前往“我的钱包”查看;其他奖励请联系客服兑换
  • 4.每周最后三个任务将会有以下奖品掉落:社区热卖开发板、小米音响、视频年度会员、京东卡、华为手机等等
易百纳技术社区
升级提醒
易百纳技术社区

恭喜您由入门

社区送出礼品一份

请填写您的收件地址,礼品将在3个工作日寄出

易百纳技术社区