就将计就计

就将计就计

0个粉丝

3

问答

0

专栏

0

资料

就将计就计  发布于  2025-05-23 15:42:10
采纳率 0%
3个问答
380

hi3516cv610 用户插入图片用于视频信号丢失时的显示

 

功能:hi3516cv610 用户插入图片用于视频信号丢失时的显示
问题:
[it66021_vio]-1893: hi_mpi_vi_set_pipe_user_pic failed!0xa010800c!
[it66021_vio]-1909: hi_mpi_vi_enable_pipe_user_pic failed!0xa010800c!
0xa010800c OT_ERR_VI_NOT_SUPPORT 操作不支持

代码:```c
static hi_s32 it66021_vio(void)
{
hi_s32 ret;
hi_vb_cfg vb_cfg;

/*************************************
Step 1: init vb
*************************************/
hi_u32 blk_size;
hi_pic_buf_attr pic_buf_attr;

(hi_void)memset_s(&vb_cfg, sizeof(hi_vb_cfg), 0, sizeof(hi_vb_cfg));

vb_cfg.max_pool_cnt = 3; /* 3: max vb pool */
pic_buf_attr.width = HDMIIN_WIDTH_IN;
pic_buf_attr.height = HDMIIN_HEIGHT_IN;
pic_buf_attr.pixel_format = HI_PIXEL_FORMAT_YVU_SEMIPLANAR_420;
pic_buf_attr.bit_width = HI_DATA_BIT_WIDTH_8;
pic_buf_attr.compress_mode = HI_COMPRESS_MODE_NONE;
pic_buf_attr.align = HI_DEFAULT_ALIGN;
blk_size = hi_common_get_pic_buf_size(&pic_buf_attr);
vb_cfg.common_pool[0].blk_size = blk_size;
vb_cfg.common_pool[0].blk_cnt = 3;

pic_buf_attr.compress_mode = HI_COMPRESS_MODE_NONE;
blk_size = hi_common_get_pic_buf_size(&pic_buf_attr);
vb_cfg.common_pool[1].blk_size = blk_size;
vb_cfg.common_pool[1].blk_cnt = 3;

pic_buf_attr.width = HDMIIN_WIDTH_IN;
pic_buf_attr.height = HDMIIN_HEIGHT_IN;
blk_size = hi_common_get_pic_buf_size(&pic_buf_attr);
vb_cfg.common_pool[2].blk_size = blk_size;
vb_cfg.common_pool[2].blk_cnt = 2;

hi_mpi_sys_exit();
hi_mpi_vb_exit();

ret = hi_mpi_vb_set_cfg(&vb_cfg);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vb_set_conf failed!");
    return HI_FAILURE;
}

ret = hi_mpi_vb_init();
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vb_init failed with 0x%x!", ret);
    return HI_FAILURE;
}

ret = hi_mpi_sys_init();
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_sys_init failed with 0x%x!", ret);
    hi_mpi_vb_exit();
    return HI_FAILURE;
}

if (ret != HI_SUCCESS) {
    log_printf(4,"system init failed with 0x%x!", ret);
    goto exit_sys;
}

ret = hi_mpi_audio_exit();
ret = hi_mpi_audio_init();
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_audio_init failed!");
     goto exit_sys;
}
ret = hi_mpi_aenc_aac_init();
if (ret != HI_SUCCESS)
{
    log_printf(4, "hi_mpi_aenc_aac_init with 0x%x!", ret);
}

/*************************************
Step 2: init vi
*************************************/
hi_vi_dev vi_dev = 1;
hi_s32 vi_pipe = 0;

ot_vi_vpss_mode vi_vpss_mode;
//vi_vpss_mode.mode[0] = OT_VI_ONLINE_VPSS_ONLINE;
//vi_vpss_mode.mode[0] = OT_VI_OFFLINE_VPSS_OFFLINE;
vi_vpss_mode.mode[0] = OT_VI_ONLINE_VPSS_OFFLINE;
vi_vpss_mode.mode[1] = OT_VI_OFFLINE_VPSS_OFFLINE;
vi_vpss_mode.mode[2] = OT_VI_OFFLINE_VPSS_OFFLINE;
vi_vpss_mode.mode[3] = OT_VI_OFFLINE_VPSS_OFFLINE;
ret = hi_mpi_sys_set_vi_vpss_mode(&vi_vpss_mode);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vi_set_dev_attr failed 0x%x", ret);
    goto exit_sys;
}

ret = hi_mpi_sys_set_vi_aiisp_mode(0, HI_VI_AIISP_MODE_DEFAULT); /* only pipe0 can set aiisp other mode */
if (ret != HI_SUCCESS) {
    sample_print("set vi video mode failed!\n");
    return HI_FAILURE;
}

hi_vi_dev_attr vi_dev_attr =
{
    .intf_mode = OT_VI_INTF_MODE_BT1120,
    .work_mode = OT_VI_WORK_MODE_MULTIPLEX_1,
    //.component_mask = {0x00FF0000, 0xFF000000},
    .component_mask = {0xFF000000, 0x00FF0000},
    .scan_mode = OT_VI_SCAN_PROGRESSIVE,
    .ad_chn_id = {-1, -1, -1, -1},
    .data_seq = OT_VI_DATA_SEQ_UVUV,
    //.data_seq = OT_VI_DATA_SEQ_VUVU,
    .sync_cfg = {
        .vsync = OT_VI_VSYNC_PULSE,
        .vsync_neg = OT_VI_VSYNC_NEG_LOW,
        .hsync = OT_VI_HSYNC_VALID_SIG,
        .hsync_neg = OT_VI_HSYNC_NEG_HIGH,
        .vsync_valid = OT_VI_VSYNC_VALID_SIG,
        .vsync_valid_neg = OT_VI_VSYNC_VALID_NEG_HIGH,

        .timing_blank = {
        /* hsync_hfb hsync_act hsync_hhb */
        0, 0, 0,
        /* vsync0_vhb vsync0_act vsync0_hhb */
        0, 0, 0,
        /* vsync1_vhb vsync1_act vsync1_hhb */
        0, 0, 0
        }
    },
    .data_type = OT_VI_DATA_TYPE_YUV,
    //.data_reverse = TD_FALSE,
    .data_reverse = TD_TRUE,
    .in_size = {HDMIIN_WIDTH_IN, HDMIIN_HEIGHT_IN},
    .data_rate = OT_DATA_RATE_X1,
};

ret = hi_mpi_vi_set_dev_attr(vi_dev, &vi_dev_attr);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vi_set_dev_attr failed 0x%x", ret);
    goto exit_sys;
}

ret = hi_mpi_vi_enable_dev(vi_dev);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vi_enable_dev failed 0x%x", ret);
    goto exit_sys;
}

ret = hi_mpi_vi_bind(vi_dev, vi_pipe);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vi_bind failed 0x%x", ret);
    goto exit_vi_0;
}

ot_vi_pipe_attr vi_bt1120_pipe_attr = {
    .pipe_bypass_mode = OT_VI_PIPE_BYPASS_NONE,
    .isp_bypass = TD_TRUE,
    .size = {HDMIIN_WIDTH_IN, HDMIIN_HEIGHT_IN},
    .pixel_format = OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420,
    .compress_mode = OT_COMPRESS_MODE_NONE,
    .frame_rate_ctrl = {-1, -1},
};
ret = hi_mpi_vi_create_pipe(vi_pipe, &vi_bt1120_pipe_attr);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vi_create_pipe failed 0x%x", ret);
    goto exit_vi_0;
}

ret =  hi_mpi_vi_start_pipe(vi_pipe);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vi_set_chn_attr failed 0x%x", ret);
    goto exit_vi_0;
}
sleep(1);
ot_vi_chn_attr vi_chn_attr = {
    .size = {HDMIIN_WIDTH_IN, HDMIIN_HEIGHT_IN},
    .pixel_format = HI_PIXEL_FORMAT_YVU_SEMIPLANAR_420,
    .dynamic_range = OT_DYNAMIC_RANGE_SDR8,
    .video_format = OT_VIDEO_FORMAT_LINEAR,
    .compress_mode = OT_COMPRESS_MODE_NONE,
    .mirror_en = TD_FALSE,
    .flip_en = TD_FALSE,
    .depth = 1,
    .frame_rate_ctrl = {-1, -1},
};

hi_s32 vi_chn = 0;
ret = hi_mpi_vi_set_chn_attr(vi_pipe, vi_chn, &vi_chn_attr);
if (ret != HI_SUCCESS) {
    log_printf(4,"vi set chn(%d) attr failed with 0x%x!", vi_chn, ret);
    goto exit_vi_0;
}

ret = hi_mpi_vi_enable_chn(vi_pipe, vi_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"vi enable chn(%d) failed with 0x%x!", vi_chn, ret);
    goto exit_vi_0;
}
// hi_video_frame_info frame_info;

/*************************************
Step 3: init vpss
*************************************/
hi_vpss_grp grp = 0;
hi_vpss_grp_attr grp_attr = { 0 };
hi_vpss_chn vpss_chn = 0;
hi_vpss_chn_attr chn_attr[HI_VPSS_MAX_PHYS_CHN_NUM] = { 0 };

// grp_attr.nr_en = HI_FALSE;
grp_attr.ie_en = HI_FALSE;
grp_attr.dci_en = HI_FALSE;
// grp_attr.nr_attr.compress_mode = HI_COMPRESS_MODE_FRAME;
grp_attr.dei_mode = HI_VPSS_DEI_MODE_OFF;
grp_attr.pixel_format = SAMPLE_PIXEL_FORMAT;
grp_attr.frame_rate.src_frame_rate = TS_SRC_VIDEO_FRAMERATE;
grp_attr.frame_rate.dst_frame_rate = TS_DST_VIDEO_FRAMERATE;
grp_attr.max_width = HDMIIN_WIDTH_IN;
grp_attr.max_height = HDMIIN_HEIGHT_IN;

chn_attr[vpss_chn].chn_mode = HI_VPSS_CHN_MODE_USER;
chn_attr[vpss_chn].width = HDMIIN_WIDTH_IN;
chn_attr[vpss_chn].height = HDMIIN_HEIGHT_IN;
chn_attr[vpss_chn].pixel_format = HI_PIXEL_FORMAT_YVU_SEMIPLANAR_420;
chn_attr[vpss_chn].frame_rate.src_frame_rate = TS_SRC_VIDEO_FRAMERATE;
chn_attr[vpss_chn].frame_rate.dst_frame_rate = TS_DST_VIDEO_FRAMERATE;

chn_attr[vpss_chn].border_en = HI_FALSE;
chn_attr[vpss_chn].border_attr.color = COLOR_RGB_BLACK;
chn_attr[vpss_chn].border_attr.top_width = 2; /* 2 : border top width */
chn_attr[vpss_chn].border_attr.bottom_width = 2; /* 2 : border bottom width */
chn_attr[vpss_chn].border_attr.left_width = 2; /* 2 : border left width */
chn_attr[vpss_chn].border_attr.right_width = 2; /* 2 : border right width */

ret = hi_mpi_vpss_create_grp(grp, &grp_attr);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vpss_create_grp(grp:%d) failed with %#x!", grp, ret);
    goto exit_vi_1;
}

ret = hi_mpi_vpss_start_grp(grp);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vpss_start_grp failed with %#x", ret);
    goto exit_vpss_0;
}

ret = hi_mpi_vpss_set_chn_attr(grp, vpss_chn, &chn_attr[vpss_chn]);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vpss_set_chn_attr failed with %#x", ret);
    goto exit_vpss_0;
}

ret = hi_mpi_vpss_enable_chn(grp, vpss_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vpss_enable_chn failed with %#x", ret);
    goto exit_vpss_1;
}

hi_mpp_chn src_chn;
hi_mpp_chn dest_chn;
src_chn.mod_id = HI_ID_VI;
src_chn.dev_id = 0;
src_chn.chn_id = vi_chn;

dest_chn.mod_id = HI_ID_VPSS;
dest_chn.dev_id = grp;
dest_chn.chn_id = 0;

ret = hi_mpi_sys_bind(&src_chn, &dest_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_sys_bind failed with %#x", ret);
    goto exit_vpss_2;
}

{
hi_s32 ret;
hi_3dnr_attr nr_attr;
sample_vi_user_pic_type user_pic_type;
sample_vi_user_frame_info user_frame_info = {0};

// for (user_pic_type = VI_USER_PIC_FRAME; user_pic_type <= VI_USER_PIC_BGCOLOR; user_pic_type++) 
{
    ret = sample_common_vi_load_user_pic(vi_pipe, VI_USER_PIC_BGCOLOR, &user_frame_info);
    if (ret != HI_SUCCESS) {
        sample_print("load user pic failed!\n");
        return;
    }

    ret = hi_mpi_vi_set_pipe_user_pic(vi_pipe, &user_frame_info.frame_info);
    if (ret != HI_SUCCESS) {
        sample_print("hi_mpi_vi_set_pipe_user_pic failed!%#x!\n",ret);
    }

    ret = hi_mpi_vi_get_pipe_3dnr_attr(vi_pipe, &nr_attr);
    if (ret != HI_SUCCESS) {
        sample_print("vi pipe(%d) get 3dnr_attr failed!\n", vi_pipe);
    }
    nr_attr.enable = HI_FALSE;
    ret = hi_mpi_vi_set_pipe_3dnr_attr(vi_pipe, &nr_attr);
    if (ret != HI_SUCCESS) {
        sample_print("vi pipe(%d) set 3dnr_attr failed!\n", vi_pipe);
    }

    // sample_print_pause("press enter key to enable user pic!\n");
    ret = hi_mpi_vi_enable_pipe_user_pic(vi_pipe);
    if (ret != HI_SUCCESS) {
        sample_print("hi_mpi_vi_enable_pipe_user_pic failed!%#x!\n",ret);
    }

    // sample_print_pause("press enter key to disable user pic!\n");
    // ret = hi_mpi_vi_disable_pipe_user_pic(vi_pipe);
    // if (ret != HI_SUCCESS) {
    //     sample_print("hi_mpi_vi_disable_pipe_user_pic failed!\n");
    // }

    // nr_attr.enable = HI_TRUE;
    // ret = hi_mpi_vi_set_pipe_3dnr_attr(vi_pipe, &nr_attr);
    // if (ret != HI_SUCCESS) {
    //     sample_print("vi pipe(%d) set 3dnr_attr failed!\n", vi_pipe);
    // }

    // sleep(1);
    // sample_common_vi_unload_user_pic(&user_frame_info);
}

}

/*************************************
Step 4: init venc
*************************************/
hi_venc_gop_mode gop_mode    = HI_VENC_GOP_MODE_NORMAL_P;
hi_venc_gop_attr gop_attr    = {0};
hi_venc_chn venc_chn         = 0;
hi_u32 profile                = 0;
hi_payload_type type        = HI_PT_H264;//HI_PT_H265;
if (TS_DST_VIDEO_CODECID == PSI_STREAM_H265)
    type = HI_PT_H265;
hi_size venc_size            = {0};
hi_venc_h265_cbr h265_cbr    = {0};
hi_venc_h264_cbr h264_cbr    = {0};
hi_u32 frame_rate            = TS_DST_VIDEO_FRAMERATE;
hi_venc_chn_attr venc_chn_attr = {0};
hi_venc_start_param start_param;

venc_size.width             = HDMIIN_WIDTH_OUT;
venc_size.height             = HDMIIN_HEIGHT_OUT;

gop_attr.gop_mode = gop_mode;
gop_attr.normal_p.ip_qp_delta = 2; /* 2 is a number */

h265_cbr.gop = TS_DST_VIDEO_GOP;
h265_cbr.stats_time = 1;     /* stream rate statics time(s) */
h265_cbr.src_frame_rate = frame_rate; /* input (vi) frame rate */
h265_cbr.dst_frame_rate = frame_rate; /* target frame rate */
h265_cbr.bit_rate = TS_DST_VIDEO_BIT_RATE;

h264_cbr.gop = TS_DST_VIDEO_GOP;
h264_cbr.stats_time = 1;
h264_cbr.src_frame_rate =  frame_rate;//frame_rate;
h264_cbr.dst_frame_rate = frame_rate;//frame_rate;
h264_cbr.bit_rate =TS_DST_VIDEO_BIT_RATE;

venc_chn_attr.venc_attr.type = type;
venc_chn_attr.venc_attr.max_pic_width = venc_size.width;
venc_chn_attr.venc_attr.max_pic_height = venc_size.height;
venc_chn_attr.venc_attr.pic_width = venc_size.width;   /* the picture width */
venc_chn_attr.venc_attr.pic_height = venc_size.height; /* the picture height */
venc_chn_attr.venc_attr.buf_size = HI_ALIGN_UP(venc_size.width * venc_size.height * 3 / 4, 64); /*  3  4 64 is a number */
venc_chn_attr.venc_attr.profile = profile;
venc_chn_attr.venc_attr.is_by_frame = HI_TRUE; /* get stream mode is slice mode or frame mode? */
if (TS_DST_VIDEO_CODECID == PSI_STREAM_H264)
{
    venc_chn_attr.venc_attr.h264_attr.frame_buf_ratio = 100; // SAMPLE_FRAME_BUF_RATIO_MIN;
    venc_chn_attr.venc_attr.h264_attr.rcn_ref_share_buf_en = HI_TRUE;
    venc_chn_attr.rc_attr.rc_mode = HI_VENC_RC_MODE_H264_CBR;
    if(TS_DST_VIDEO_QUALITY == 2 )
        venc_chn_attr.rc_attr.rc_mode = HI_VENC_RC_MODE_H264_VBR;
    venc_chn_attr.rc_attr.h264_cbr = h264_cbr;
    type        = HI_PT_H264;
}

if (TS_DST_VIDEO_CODECID == PSI_STREAM_H265)
{
    venc_chn_attr.venc_attr.h265_attr.frame_buf_ratio = SAMPLE_FRAME_BUF_RATIO_MIN;
    venc_chn_attr.venc_attr.h265_attr.rcn_ref_share_buf_en = HI_TRUE;
    venc_chn_attr.rc_attr.rc_mode = HI_VENC_RC_MODE_H265_CBR;
    if(TS_DST_VIDEO_QUALITY == 2 )
        venc_chn_attr.rc_attr.rc_mode = HI_VENC_RC_MODE_H265_VBR;
    venc_chn_attr.rc_attr.h265_cbr = h265_cbr;
    type        = HI_PT_H265;
}
venc_chn_attr.venc_attr.type = type;
venc_chn_attr.gop_attr = gop_attr;

if ((ret = hi_mpi_venc_create_chn(venc_chn, &venc_chn_attr)) != HI_SUCCESS) {
    log_printf(4,"hi_mpi_venc_create_chn [%d] failed with %#x! ", venc_chn, ret);
    goto EXIT_VENC_H265_STOP;
}

if ((ret = venc_close_reencode(venc_chn)) != HI_SUCCESS) {
    log_printf(4,"venc_close_reencode [%d] failed with %#x! ", venc_chn, ret);
    goto EXIT_VENC_H265_STOP;
}

start_param.recv_pic_num = -1;
if ((ret = hi_mpi_venc_start_chn(venc_chn, &start_param)) != HI_SUCCESS) {
    log_printf(4,"hi_mpi_venc_start_recv_pic failed with%#x! ", ret);
    goto EXIT_VENC_H265_STOP;
}

src_chn.mod_id = HI_ID_VPSS;
src_chn.dev_id = grp;
src_chn.chn_id = vpss_chn;

dest_chn.mod_id = HI_ID_VENC;
dest_chn.dev_id = 0;
dest_chn.chn_id = venc_chn;

ret = hi_mpi_sys_bind(&src_chn, &dest_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"sample_comm_vpss_bind_venc failed for %#x!", ret);
    goto EXIT_VENC_H265_STOP;
}

log_printf(2,”hi_mpi_venc complete”);

/*************************************
Step 5: init audio
*************************************/
hi_ai_chn ai_chn = 0;
hi_audio_dev ai_dev = 0;
hi_aio_attr ai_attr = {0};
if (TS_HDMI_AUDIO_INPUT_TYPE == 0)
{
    // HDMI
    ai_attr.sample_rate = TS_HDMI_AUDIO_SAMPLE_RATE;
    ai_attr.bit_width = HI_AUDIO_BIT_WIDTH_16;
    ai_attr.work_mode = HI_AIO_MODE_I2S_SLAVE;
    ai_attr.snd_mode = TS_HDMI_AUDIO_SND_MODE;
    ai_attr.expand_flag = 0;
    ai_attr.frame_num = 30; /* 30:frame num */
    ai_attr.point_num_per_frame = 1024;
    ai_attr.chn_cnt = 2; /* 2:chn cnt */
    ai_attr.clk_share = 0;
    ai_attr.i2s_type = HI_AIO_I2STYPE_EXTERN;
}
else
{
    // 3.5mm耳机
    ai_attr.sample_rate = TS_HDMI_AUDIO_SAMPLE_RATE;
    ai_attr.bit_width = HI_AUDIO_BIT_WIDTH_16;
    ai_attr.work_mode = HI_AIO_MODE_I2S_MASTER;
    ai_attr.snd_mode = TS_HDMI_AUDIO_SND_MODE;
    ai_attr.expand_flag = 0;
    ai_attr.frame_num = SAMPLE_AUDIO_AI_USER_FRAME_DEPTH;
    ai_attr.point_num_per_frame = HI_AACLC_SAMPLES_PER_FRAME;
    ai_attr.chn_cnt = 2; /* 2:chn cnt */
    ai_attr.clk_share = 1;
    ai_attr.i2s_type = HI_AIO_I2STYPE_INNERCODEC;
}
// hi_mpi_ai_get_pub_attr(hi_audio_dev ai_dev, hi_aio_attr *attr);
ret = hi_mpi_ai_set_pub_attr(ai_dev, &ai_attr);
if (ret) {
    log_printf(4,"hi_mpi_ai_set_pub_attr(%d) failed with %#x", ai_dev, ret);
    goto exit_vo_6;
}

ret = hi_mpi_ai_enable(ai_dev);
if (ret) {
    log_printf(4,"hi_mpi_ai_enable(%d) failed with %#x", ai_dev, ret);
    goto exit_vo_6;
}

ret = hi_mpi_ai_enable_chn(ai_dev, ai_chn);
if (ret) {
    log_printf(4,"hi_mpi_ai_enable_chn(%d,%d) failed with %#x", ai_dev, ai_chn, ret);
    goto exit_aio_0;
}
if (TS_HDMI_AUDIO_INPUT_TYPE == 1)
{//3.5mm耳机
    hi_usleep(100);
    inner_codec_cfg_audio(TS_HDMI_AUDIO_SAMPLE_RATE); //HI_AUDIO_SAMPLE_RATE_32000
    hi_mpi_ai_set_track_mode(ai_dev,OT_AUDIO_TRACK_EXCHANGE);
}

log_printf(2,”hi_mpi_ai complete”);

hi_aenc_chn ae_chn = 0;
hi_aenc_chn_attr aenc_attr;
hi_aenc_attr_aac aenc_aac;

aenc_attr.type = HI_PT_AAC;
aenc_attr.buf_size = 30; /* 30:size */
aenc_attr.point_num_per_frame = 1024;

aenc_attr.value = &aenc_aac;
aenc_aac.aac_type = HI_AAC_TYPE_AACLC;
aenc_aac.bit_rate = TS_HDMI_AUDIO_BIT_RATE;
aenc_aac.bit_width = HI_AUDIO_BIT_WIDTH_16;
aenc_aac.sample_rate = TS_HDMI_AUDIO_SAMPLE_RATE;
aenc_aac.snd_mode = TS_HDMI_AUDIO_SND_MODE;
aenc_aac.transport_type = HI_AAC_TRANSPORT_TYPE_ADTS;
aenc_aac.band_width = 0;

/* create aenc chn */
ret = hi_mpi_aenc_create_chn(ae_chn, &aenc_attr);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_aenc_create_chn(%d) failed with %#x!", ae_chn, ret);
    goto exit_aio_3;
}
log_printf(2,"hi_mpi_ai enc complete 1");

src_chn.mod_id = HI_ID_AI;
src_chn.chn_id = ai_chn;
src_chn.dev_id = ai_dev;
dest_chn.mod_id = HI_ID_AENC;
dest_chn.dev_id = 0;
dest_chn.chn_id = ae_chn;

ret = hi_mpi_sys_bind(&src_chn, &dest_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_sys_bind failed with %#x!", ret);
    goto exit_aio_4;
}

log_printf(2,”hi_mpi_ai enc complete”);

g_media_start = 1;
pthread_create(&g_media_threadid, NULL, media_get_stream_proc, NULL);
// sleep(4);
pthread_create(&g_st_OSD_read_Thread, NULL, SAMPLE_RGN_VencOSdDynamicRead, NULL);
pthread_create(&g_st_OSD_Thread, NULL, SAMPLE_RGN_VencOSdDynamicDisplay, NULL);

//log_printf(2,"please choose mode, press 'q' to exit this sample.");
//             // sample_region_venc_overlay();
//log_printf(2,"\tq) quit");
char ch;
while(1)
{
    ch = getchar();
    if(10 == ch)
    {
        continue;
    }

    getchar();

    if(('Q' == ch)||('q' == ch))
    {
        break;
    }
    else
    {
        //log_printf(2,"preview mode invaild! please try again.");
        sleep(10);
        // continue;
    }

}

g_media_start = 0;
pthread_join(g_media_threadid, 0);

exit_aio_4:
src_chn.mod_id = HI_ID_AI;
src_chn.dev_id = ai_dev;
src_chn.chn_id = ai_chn;
dest_chn.mod_id = HI_ID_AENC;
dest_chn.dev_id = 0;
dest_chn.chn_id = ae_chn;

 ret = hi_mpi_sys_unbind(&src_chn, &dest_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_sys_unbind failed with %#x!", ret);
    goto exit_aio_3;
}

ret = hi_mpi_aenc_destroy_chn(ae_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_aenc_destroy_chn(%d) failed with %#x!", ae_chn, ret);
}

exit_aio_3:

ret = hi_mpi_ai_disable_chn(ai_dev, ai_chn);
if (ret) {
    log_printf(4,"hi_mpi_ai_disable_chn(%d,%d) failed with %#x", ai_dev, ai_chn, ret);
}

exit_aio_0:
ret = hi_mpi_ai_disable(ai_dev);
if (ret) {
log_printf(4,”hi_mpi_ai_disable(%d) failed with %#x”, ai_dev, ret);
}

src_chn.mod_id = HI_ID_VPSS;
src_chn.dev_id = grp;
src_chn.chn_id = vpss_chn;

dest_chn.mod_id = HI_ID_VENC;
dest_chn.dev_id = 0;
dest_chn.chn_id = venc_chn;

ret = hi_mpi_sys_unbind(&src_chn, &dest_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_sys_unbind failed with %#x", ret);
}

EXIT_VENC_H265_STOP:
ret = hi_mpi_venc_stop_chn(venc_chn);
if (ret != HI_SUCCESS) {
log_printf(4,”hi_mpi_venc_stop_chn vechn[%d] failed with %#x!”, venc_chn, ret);
}

/* distroy venc channel */
ret = hi_mpi_venc_destroy_chn(venc_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_venc_destroy_chn vechn[%d] failed with %#x!", venc_chn, ret);
    return HI_FAILURE;
}

exit_vo_6:

exit_vpss_2:
src_chn.mod_id = HI_ID_VI;
src_chn.dev_id = 0;
src_chn.chn_id = vi_chn;

dest_chn.mod_id = HI_ID_VPSS;
dest_chn.dev_id = grp;
dest_chn.chn_id = 0;

ret = hi_mpi_sys_unbind(&src_chn, &dest_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_sys_unbind failed with %#x", ret);
}

ret = hi_mpi_vpss_disable_chn(grp, vpss_chn);
if (ret != HI_SUCCESS) {
    log_printf(4,"hi_mpi_vpss_disable_chn failed with %#x", ret);
}

exit_vpss_1:
ret = hi_mpi_vpss_stop_grp(grp);
if (ret != HI_SUCCESS) {
log_printf(4,”hi_mpi_vpss_stop_grp failed with %#x”, ret);
}

exit_vpss_0:
ret = hi_mpi_vpss_destroy_grp(grp);
if (ret != HI_SUCCESS) {
log_printf(4,”hi_mpi_vpss_destroy_grp failed with %#x”, ret);
}
exit_vi_1:
// ret = hi_mpi_vi_disable_chn(vi_chn);
// if (ret != HI_SUCCESS) {
// log_printf(2,”hi_mpi_vi_disable_chn failed 0x%x”, ret);
// }
exit_vi_0:
// ret = hi_mpi_vi_disable_dev(vi_dev);
// if (ret != HI_SUCCESS) {
// log_printf(2,”hi_mpi_vi_disable_dev failed 0x%x”, ret);
// }
exit_sys:
hi_mpi_aenc_aac_deinit();

hi_mpi_sys_exit();
hi_mpi_vb_exit_mod_common_pool(HI_VB_UID_VDEC);
hi_mpi_vb_exit();
return ret;

}
```

我来回答
回答6个
时间排序
认可量排序

UncleRoderick

59个粉丝

16

问答

4

专栏

20

资料

UncleRoderick 2025-05-23 15:55:48
认可0

VI要改成离线模式
vi_vpss_mode.mode[0] = OT_VI_OFFLINE_VPSS_OFFLINE

就将计就计
就将计就计   回复   UncleRoderick  2025-05-23 16:06:08
0

2025-05-23 16:05:14.953 E [it66021] [1255-it66021] it66021.c:1769 it66021_vio | hi_mpi_vi_create_pipe failed 0xa0108007
0xa0108007 OT_ERR_VI_ILLEGAL_PARAM 视频输入参数设置无效

UncleRoderick
UncleRoderick   回复   就将计就计  2025-05-23 16:19:50
0

cat /dev/logmpp看看报错信息,有啥报错解啥报错

就将计就计
就将计就计   回复   UncleRoderick  2025-05-23 16:22:50
0
<3>[    vi] [func]:vi_drv_pipe_check_pixel_format [line]:1565 [info]:vi_pipe(0) do not support SP420/SP422/YUV400 in offline mode!
<3>[    vi] [func]:vi_pipe_check_destroyed_sema_down [line]:457 [info]:pipe(1) unexisted!
<3>[    vi] [func]:vi_stop_capture_frame [line]:423 [info]:pipe0 wait timeout 120 ms!
<3>[    vi] [func]:vi_stop_capture_frame [line]:423 [info]:pipe0 wait timeout 120 ms!
<3>[    vi] [func]:vi_stop_capture_frame [line]:423 [info]:pipe0 wait timeout 1000 ms!
<3>[   sys] [Func]:sys_print_support_valid_mode_message [Line]:839 [Info]:invalid VI-VPSS mode mode[1] 0 should be 1
<3>[   sys] [Func]:sys_drv_check_vi_vpss_mode [Line]:940 [Info]:Now pipe0_mode is OT_VI_OFFLINE_VPSS_ONLINE
<3>[    vi] [func]:vi_drv_pipe_check_pixel_format [line]:1565 [info]:vi_pipe(0) do not support SP420/SP422/YUV400 in offline mode!
<3>[    vi] [func]:vi_pipe_check_destroyed_sema_down [line]:457 [info]:pipe(0) unexisted!
<3>[    vi] [func]:vi_drv_pipe_check_pixel_format [line]:1565 [info]:vi_pipe(0) do not support SP420/SP422/YUV400 in offline mode!
<3>[    vi] [func]:vi_drv_pipe_check_pixel_format [line]:1565 [info]:vi_pipe(0) do not support SP420/SP422/YUV400 in offline mode!
UncleRoderick
UncleRoderick   回复   就将计就计  2025-05-23 16:25:53
0

PIPE0离线模式不支持YUV,换一个PIPE1

就将计就计
就将计就计   回复   UncleRoderick  2025-05-23 16:58:38
0

不报错了,打开视频是空的,大佬帮忙看一下


static hi_s32 it66021_vio(void)
{
    hi_s32 ret;
    hi_vb_cfg vb_cfg;

    /*************************************
    Step 1: init vb
    *************************************/
    hi_u32 blk_size;
    hi_pic_buf_attr pic_buf_attr;

    (hi_void)memset_s(&vb_cfg, sizeof(hi_vb_cfg), 0, sizeof(hi_vb_cfg));

    vb_cfg.max_pool_cnt = 3; /* 3: max vb pool */
    pic_buf_attr.width = HDMIIN_WIDTH_IN;
    pic_buf_attr.height = HDMIIN_HEIGHT_IN;
    pic_buf_attr.pixel_format = HI_PIXEL_FORMAT_YVU_SEMIPLANAR_420;
    pic_buf_attr.bit_width = HI_DATA_BIT_WIDTH_8;
    pic_buf_attr.compress_mode = HI_COMPRESS_MODE_NONE;
    pic_buf_attr.align = HI_DEFAULT_ALIGN;
    blk_size = hi_common_get_pic_buf_size(&pic_buf_attr);
    vb_cfg.common_pool[0].blk_size = blk_size;
    vb_cfg.common_pool[0].blk_cnt = 3;

    pic_buf_attr.compress_mode = HI_COMPRESS_MODE_NONE;
    blk_size = hi_common_get_pic_buf_size(&pic_buf_attr);
    vb_cfg.common_pool[1].blk_size = blk_size;
    vb_cfg.common_pool[1].blk_cnt = 3;

    pic_buf_attr.width = HDMIIN_WIDTH_IN;
    pic_buf_attr.height = HDMIIN_HEIGHT_IN;
    blk_size = hi_common_get_pic_buf_size(&pic_buf_attr);
    vb_cfg.common_pool[2].blk_size = blk_size;
    vb_cfg.common_pool[2].blk_cnt = 2;

    hi_mpi_sys_exit();
    hi_mpi_vb_exit();

    ret = hi_mpi_vb_set_cfg(&vb_cfg);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vb_set_conf failed!");
        return HI_FAILURE;
    }

    ret = hi_mpi_vb_init();
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vb_init failed with 0x%x!", ret);
        return HI_FAILURE;
    }

    ret = hi_mpi_sys_init();
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_sys_init failed with 0x%x!", ret);
        hi_mpi_vb_exit();
        return HI_FAILURE;
    }

    if (ret != HI_SUCCESS) {
        log_printf(4,"system init failed with 0x%x!", ret);
        goto exit_sys;
    }

    ret = hi_mpi_audio_exit();
    ret = hi_mpi_audio_init();
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_audio_init failed!");
         goto exit_sys;
    }
    ret = hi_mpi_aenc_aac_init();
    if (ret != HI_SUCCESS)
    {
        log_printf(4, "hi_mpi_aenc_aac_init with 0x%x!", ret);
    }

    /*************************************
    Step 2: init vi
    *************************************/
    hi_vi_dev vi_dev = 1;
    hi_s32 vi_pipe = 1;

    ot_vi_vpss_mode vi_vpss_mode;
    //vi_vpss_mode.mode[0] = OT_VI_ONLINE_VPSS_ONLINE;
    //vi_vpss_mode.mode[0] = OT_VI_OFFLINE_VPSS_OFFLINE;
    vi_vpss_mode.mode[0] = OT_VI_ONLINE_VPSS_OFFLINE;
    vi_vpss_mode.mode[1] = OT_VI_OFFLINE_VPSS_OFFLINE;
    vi_vpss_mode.mode[2] = OT_VI_OFFLINE_VPSS_OFFLINE;
    vi_vpss_mode.mode[3] = OT_VI_OFFLINE_VPSS_OFFLINE;
    ret = hi_mpi_sys_set_vi_vpss_mode(&vi_vpss_mode);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vi_set_dev_attr failed 0x%x", ret);
        goto exit_sys;
    }

    ret = hi_mpi_sys_set_vi_aiisp_mode(0, HI_VI_AIISP_MODE_DEFAULT); /* only pipe0 can set aiisp other mode */
    if (ret != HI_SUCCESS) {
        sample_print("set vi video mode failed!\n");
        return HI_FAILURE;
    }

    hi_vi_dev_attr vi_dev_attr =
    {
        .intf_mode = OT_VI_INTF_MODE_BT1120,
        .work_mode = OT_VI_WORK_MODE_MULTIPLEX_1,
        //.component_mask = {0x00FF0000, 0xFF000000},
        .component_mask = {0xFF000000, 0x00FF0000},
        .scan_mode = OT_VI_SCAN_PROGRESSIVE,
        .ad_chn_id = {-1, -1, -1, -1},
        .data_seq = OT_VI_DATA_SEQ_UVUV,
        //.data_seq = OT_VI_DATA_SEQ_VUVU,
        .sync_cfg = {
            .vsync = OT_VI_VSYNC_PULSE,
            .vsync_neg = OT_VI_VSYNC_NEG_LOW,
            .hsync = OT_VI_HSYNC_VALID_SIG,
            .hsync_neg = OT_VI_HSYNC_NEG_HIGH,
            .vsync_valid = OT_VI_VSYNC_VALID_SIG,
            .vsync_valid_neg = OT_VI_VSYNC_VALID_NEG_HIGH,

            .timing_blank = {
            /* hsync_hfb hsync_act hsync_hhb */
            0, 0, 0,
            /* vsync0_vhb vsync0_act vsync0_hhb */
            0, 0, 0,
            /* vsync1_vhb vsync1_act vsync1_hhb */
            0, 0, 0
            }
        },
        .data_type = OT_VI_DATA_TYPE_YUV,
        //.data_reverse = TD_FALSE,
        .data_reverse = TD_TRUE,
        .in_size = {HDMIIN_WIDTH_IN, HDMIIN_HEIGHT_IN},
        .data_rate = OT_DATA_RATE_X1,
    };

    ret = hi_mpi_vi_set_dev_attr(vi_dev, &vi_dev_attr);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vi_set_dev_attr failed 0x%x", ret);
        goto exit_sys;
    }

    ret = hi_mpi_vi_enable_dev(vi_dev);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vi_enable_dev failed 0x%x", ret);
        goto exit_sys;
    }

    ret = hi_mpi_vi_bind(vi_dev, vi_pipe);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vi_bind failed 0x%x", ret);
        goto exit_vi_0;
    }

    ot_vi_pipe_attr vi_bt1120_pipe_attr = {
        .pipe_bypass_mode = OT_VI_PIPE_BYPASS_NONE,
        .isp_bypass = TD_TRUE,
        .size = {HDMIIN_WIDTH_IN, HDMIIN_HEIGHT_IN},
        .pixel_format = OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420,
        .compress_mode = OT_COMPRESS_MODE_NONE,
        .frame_rate_ctrl = {-1, -1},
    };
    ret = hi_mpi_vi_create_pipe(vi_pipe, &vi_bt1120_pipe_attr);//hi_vi_pipe_attr
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vi_create_pipe failed 0x%x", ret);
        goto exit_vi_0;
    }

    ret =  hi_mpi_vi_start_pipe(vi_pipe);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vi_set_chn_attr failed 0x%x", ret);
        goto exit_vi_0;
    }
    sleep(1);
    ot_vi_chn_attr vi_chn_attr = {
        .size = {HDMIIN_WIDTH_IN, HDMIIN_HEIGHT_IN},
        .pixel_format = HI_PIXEL_FORMAT_YVU_SEMIPLANAR_420,
        .dynamic_range = OT_DYNAMIC_RANGE_SDR8,
        .video_format = OT_VIDEO_FORMAT_LINEAR,
        .compress_mode = OT_COMPRESS_MODE_NONE,
        .mirror_en = TD_FALSE,
        .flip_en = TD_FALSE,
        .depth = 1,
        .frame_rate_ctrl = {-1, -1},
    };

    hi_s32 vi_chn = 0;
    ret = hi_mpi_vi_set_chn_attr(vi_pipe, vi_chn, &vi_chn_attr);
    if (ret != HI_SUCCESS) {
        log_printf(4,"vi set chn(%d) attr failed with 0x%x!", vi_chn, ret);
        goto exit_vi_0;
    }

    ret = hi_mpi_vi_enable_chn(vi_pipe, vi_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"vi enable chn(%d) failed with 0x%x!", vi_chn, ret);
        goto exit_vi_0;
    }
    // hi_video_frame_info frame_info;

    /*************************************
    Step 3: init vpss
    *************************************/
    hi_vpss_grp grp = 0;
    hi_vpss_grp_attr grp_attr = { 0 };
    hi_vpss_chn vpss_chn = 0;
    hi_vpss_chn_attr chn_attr[HI_VPSS_MAX_PHYS_CHN_NUM] = { 0 };

 //   grp_attr.nr_en = HI_FALSE;
    grp_attr.ie_en = HI_FALSE;
    grp_attr.dci_en = HI_FALSE;
 //   grp_attr.nr_attr.compress_mode = HI_COMPRESS_MODE_FRAME;
    grp_attr.dei_mode = HI_VPSS_DEI_MODE_OFF;
    grp_attr.pixel_format = SAMPLE_PIXEL_FORMAT;
    grp_attr.frame_rate.src_frame_rate = TS_SRC_VIDEO_FRAMERATE;
    grp_attr.frame_rate.dst_frame_rate = TS_DST_VIDEO_FRAMERATE;
    grp_attr.max_width = HDMIIN_WIDTH_IN;
    grp_attr.max_height = HDMIIN_HEIGHT_IN;

    chn_attr[vpss_chn].chn_mode = HI_VPSS_CHN_MODE_USER;
    chn_attr[vpss_chn].width = HDMIIN_WIDTH_IN;
    chn_attr[vpss_chn].height = HDMIIN_HEIGHT_IN;
    chn_attr[vpss_chn].pixel_format = HI_PIXEL_FORMAT_YVU_SEMIPLANAR_420;
    chn_attr[vpss_chn].frame_rate.src_frame_rate = TS_SRC_VIDEO_FRAMERATE;
    chn_attr[vpss_chn].frame_rate.dst_frame_rate = TS_DST_VIDEO_FRAMERATE;

    chn_attr[vpss_chn].border_en = HI_FALSE;
    chn_attr[vpss_chn].border_attr.color = COLOR_RGB_BLACK;
    chn_attr[vpss_chn].border_attr.top_width = 2; /* 2 : border top width */
    chn_attr[vpss_chn].border_attr.bottom_width = 2; /* 2 : border bottom width */
    chn_attr[vpss_chn].border_attr.left_width = 2; /* 2 : border left width */
    chn_attr[vpss_chn].border_attr.right_width = 2; /* 2 : border right width */

    ret = hi_mpi_vpss_create_grp(grp, &grp_attr);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vpss_create_grp(grp:%d) failed with %#x!", grp, ret);
        goto exit_vi_1;
    }

    ret = hi_mpi_vpss_start_grp(grp);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vpss_start_grp failed with %#x", ret);
        goto exit_vpss_0;
    }

    ret = hi_mpi_vpss_set_chn_attr(grp, vpss_chn, &chn_attr[vpss_chn]);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vpss_set_chn_attr failed with %#x", ret);
        goto exit_vpss_0;
    }

    ret = hi_mpi_vpss_enable_chn(grp, vpss_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vpss_enable_chn failed with %#x", ret);
        goto exit_vpss_1;
    }

    hi_mpp_chn src_chn;
    hi_mpp_chn dest_chn;
    src_chn.mod_id = HI_ID_VI;
    src_chn.dev_id = 0;
    src_chn.chn_id = vi_chn;

    dest_chn.mod_id = HI_ID_VPSS;
    dest_chn.dev_id = grp;
    dest_chn.chn_id = 0;

    ret = hi_mpi_sys_bind(&src_chn, &dest_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_sys_bind failed with %#x", ret);
        goto exit_vpss_2;
    }
{
    hi_s32 ret;
    hi_3dnr_attr nr_attr;
    sample_vi_user_pic_type user_pic_type;
    sample_vi_user_frame_info user_frame_info = {0};

    // for (user_pic_type = VI_USER_PIC_FRAME; user_pic_type <= VI_USER_PIC_BGCOLOR; user_pic_type++) 
    {
        ret = sample_common_vi_load_user_pic(vi_pipe, VI_USER_PIC_FRAME, &user_frame_info);
        if (ret != HI_SUCCESS) {
            sample_print("load user pic failed!\n");
            return;
        }

        ret = hi_mpi_vi_set_pipe_user_pic(vi_pipe, &user_frame_info.frame_info);
        if (ret != HI_SUCCESS) {
            sample_print("hi_mpi_vi_set_pipe_user_pic failed!%#x!\n",ret);
        }

        ret = hi_mpi_vi_get_pipe_3dnr_attr(vi_pipe, &nr_attr);
        if (ret != HI_SUCCESS) {
            sample_print("vi pipe(%d) get 3dnr_attr failed!\n", vi_pipe);
        }
        nr_attr.enable = HI_FALSE;
        ret = hi_mpi_vi_set_pipe_3dnr_attr(vi_pipe, &nr_attr);
        if (ret != HI_SUCCESS) {
            sample_print("vi pipe(%d) set 3dnr_attr failed!\n", vi_pipe);
        }

        // sample_print_pause("press enter key to enable user pic!\n");
        ret = hi_mpi_vi_enable_pipe_user_pic(vi_pipe);
        if (ret != HI_SUCCESS) {
            sample_print("hi_mpi_vi_enable_pipe_user_pic failed!%#x!\n",ret);
        }

        // sample_print_pause("press enter key to disable user pic!\n");
        // ret = hi_mpi_vi_disable_pipe_user_pic(vi_pipe);
        // if (ret != HI_SUCCESS) {
        //     sample_print("hi_mpi_vi_disable_pipe_user_pic failed!\n");
        // }

        // nr_attr.enable = HI_TRUE;
        // ret = hi_mpi_vi_set_pipe_3dnr_attr(vi_pipe, &nr_attr);
        // if (ret != HI_SUCCESS) {
        //     sample_print("vi pipe(%d) set 3dnr_attr failed!\n", vi_pipe);
        // }

        // sleep(1);
        // sample_common_vi_unload_user_pic(&user_frame_info);
    }
}

    /*************************************
    Step 4: init venc
    *************************************/
    hi_venc_gop_mode gop_mode    = HI_VENC_GOP_MODE_NORMAL_P;
    hi_venc_gop_attr gop_attr    = {0};
    hi_venc_chn venc_chn         = 0;
    hi_u32 profile                = 0;
    hi_payload_type type        = HI_PT_H264;//HI_PT_H265;
    if (TS_DST_VIDEO_CODECID == PSI_STREAM_H265)
        type = HI_PT_H265;
    hi_size venc_size            = {0};
    hi_venc_h265_cbr h265_cbr    = {0};
    hi_venc_h264_cbr h264_cbr    = {0};
    hi_u32 frame_rate            = TS_DST_VIDEO_FRAMERATE;
    hi_venc_chn_attr venc_chn_attr = {0};
    hi_venc_start_param start_param;

    venc_size.width             = HDMIIN_WIDTH_OUT;
    venc_size.height             = HDMIIN_HEIGHT_OUT;

    gop_attr.gop_mode = gop_mode;
    gop_attr.normal_p.ip_qp_delta = 2; /* 2 is a number */

    h265_cbr.gop = TS_DST_VIDEO_GOP;
    h265_cbr.stats_time = 1;     /* stream rate statics time(s) */
    h265_cbr.src_frame_rate = frame_rate; /* input (vi) frame rate */
    h265_cbr.dst_frame_rate = frame_rate; /* target frame rate */
    h265_cbr.bit_rate = TS_DST_VIDEO_BIT_RATE;

    h264_cbr.gop = TS_DST_VIDEO_GOP;
    h264_cbr.stats_time = 1;
    h264_cbr.src_frame_rate =  frame_rate;//frame_rate;
    h264_cbr.dst_frame_rate = frame_rate;//frame_rate;
    h264_cbr.bit_rate =TS_DST_VIDEO_BIT_RATE;

    venc_chn_attr.venc_attr.type = type;
    venc_chn_attr.venc_attr.max_pic_width = venc_size.width;
    venc_chn_attr.venc_attr.max_pic_height = venc_size.height;
    venc_chn_attr.venc_attr.pic_width = venc_size.width;   /* the picture width */
    venc_chn_attr.venc_attr.pic_height = venc_size.height; /* the picture height */
    venc_chn_attr.venc_attr.buf_size = HI_ALIGN_UP(venc_size.width * venc_size.height * 3 / 4, 64); /*  3  4 64 is a number */
    venc_chn_attr.venc_attr.profile = profile;
    venc_chn_attr.venc_attr.is_by_frame = HI_TRUE; /* get stream mode is slice mode or frame mode? */
    if (TS_DST_VIDEO_CODECID == PSI_STREAM_H264)
    {
        venc_chn_attr.venc_attr.h264_attr.frame_buf_ratio = 100; // SAMPLE_FRAME_BUF_RATIO_MIN;
        venc_chn_attr.venc_attr.h264_attr.rcn_ref_share_buf_en = HI_TRUE;
        venc_chn_attr.rc_attr.rc_mode = HI_VENC_RC_MODE_H264_CBR;
        if(TS_DST_VIDEO_QUALITY == 2 )
            venc_chn_attr.rc_attr.rc_mode = HI_VENC_RC_MODE_H264_VBR;
        venc_chn_attr.rc_attr.h264_cbr = h264_cbr;
        type        = HI_PT_H264;
    }

    if (TS_DST_VIDEO_CODECID == PSI_STREAM_H265)
    {
        venc_chn_attr.venc_attr.h265_attr.frame_buf_ratio = SAMPLE_FRAME_BUF_RATIO_MIN;
        venc_chn_attr.venc_attr.h265_attr.rcn_ref_share_buf_en = HI_TRUE;
        venc_chn_attr.rc_attr.rc_mode = HI_VENC_RC_MODE_H265_CBR;
        if(TS_DST_VIDEO_QUALITY == 2 )
            venc_chn_attr.rc_attr.rc_mode = HI_VENC_RC_MODE_H265_VBR;
        venc_chn_attr.rc_attr.h265_cbr = h265_cbr;
        type        = HI_PT_H265;
    }
    venc_chn_attr.venc_attr.type = type;
    venc_chn_attr.gop_attr = gop_attr;

    if ((ret = hi_mpi_venc_create_chn(venc_chn, &venc_chn_attr)) != HI_SUCCESS) {
        log_printf(4,"hi_mpi_venc_create_chn [%d] failed with %#x! ", venc_chn, ret);
        goto EXIT_VENC_H265_STOP;
    }

    if ((ret = venc_close_reencode(venc_chn)) != HI_SUCCESS) {
        log_printf(4,"venc_close_reencode [%d] failed with %#x! ", venc_chn, ret);
        goto EXIT_VENC_H265_STOP;
    }

    start_param.recv_pic_num = -1;
    if ((ret = hi_mpi_venc_start_chn(venc_chn, &start_param)) != HI_SUCCESS) {
        log_printf(4,"hi_mpi_venc_start_recv_pic failed with%#x! ", ret);
        goto EXIT_VENC_H265_STOP;
    }

    src_chn.mod_id = HI_ID_VPSS;
    src_chn.dev_id = grp;
    src_chn.chn_id = vpss_chn;

    dest_chn.mod_id = HI_ID_VENC;
    dest_chn.dev_id = 0;
    dest_chn.chn_id = venc_chn;

    ret = hi_mpi_sys_bind(&src_chn, &dest_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"sample_comm_vpss_bind_venc failed for %#x!", ret);
        goto EXIT_VENC_H265_STOP;
    }

   log_printf(2,"hi_mpi_venc complete");

    /*************************************
    Step 5: init audio
    *************************************/
    hi_ai_chn ai_chn = 0;
    hi_audio_dev ai_dev = 0;
    hi_aio_attr ai_attr = {0};
    if (TS_HDMI_AUDIO_INPUT_TYPE == 0)
    {
        // HDMI
        ai_attr.sample_rate = TS_HDMI_AUDIO_SAMPLE_RATE;
        ai_attr.bit_width = HI_AUDIO_BIT_WIDTH_16;
        ai_attr.work_mode = HI_AIO_MODE_I2S_SLAVE;
        ai_attr.snd_mode = TS_HDMI_AUDIO_SND_MODE;
        ai_attr.expand_flag = 0;
        ai_attr.frame_num = 30; /* 30:frame num */
        ai_attr.point_num_per_frame = 1024;
        ai_attr.chn_cnt = 2; /* 2:chn cnt */
        ai_attr.clk_share = 0;
        ai_attr.i2s_type = HI_AIO_I2STYPE_EXTERN;
    }
    else
    {
        // 3.5mm耳机
        ai_attr.sample_rate = TS_HDMI_AUDIO_SAMPLE_RATE;
        ai_attr.bit_width = HI_AUDIO_BIT_WIDTH_16;
        ai_attr.work_mode = HI_AIO_MODE_I2S_MASTER;
        ai_attr.snd_mode = TS_HDMI_AUDIO_SND_MODE;
        ai_attr.expand_flag = 0;
        ai_attr.frame_num = SAMPLE_AUDIO_AI_USER_FRAME_DEPTH;
        ai_attr.point_num_per_frame = HI_AACLC_SAMPLES_PER_FRAME;
        ai_attr.chn_cnt = 2; /* 2:chn cnt */
        ai_attr.clk_share = 1;
        ai_attr.i2s_type = HI_AIO_I2STYPE_INNERCODEC;
    }
    // hi_mpi_ai_get_pub_attr(hi_audio_dev ai_dev, hi_aio_attr *attr);
    ret = hi_mpi_ai_set_pub_attr(ai_dev, &ai_attr);
    if (ret) {
        log_printf(4,"hi_mpi_ai_set_pub_attr(%d) failed with %#x", ai_dev, ret);
        goto exit_vo_6;
    }

    ret = hi_mpi_ai_enable(ai_dev);
    if (ret) {
        log_printf(4,"hi_mpi_ai_enable(%d) failed with %#x", ai_dev, ret);
        goto exit_vo_6;
    }

    ret = hi_mpi_ai_enable_chn(ai_dev, ai_chn);
    if (ret) {
        log_printf(4,"hi_mpi_ai_enable_chn(%d,%d) failed with %#x", ai_dev, ai_chn, ret);
        goto exit_aio_0;
    }
    if (TS_HDMI_AUDIO_INPUT_TYPE == 1)
    {//3.5mm耳机
        hi_usleep(100);
        inner_codec_cfg_audio(TS_HDMI_AUDIO_SAMPLE_RATE); //HI_AUDIO_SAMPLE_RATE_32000
        hi_mpi_ai_set_track_mode(ai_dev,OT_AUDIO_TRACK_EXCHANGE);
    }

   log_printf(2,"hi_mpi_ai complete");

    hi_aenc_chn ae_chn = 0;
    hi_aenc_chn_attr aenc_attr;
    hi_aenc_attr_aac aenc_aac;

    aenc_attr.type = HI_PT_AAC;
    aenc_attr.buf_size = 30; /* 30:size */
    aenc_attr.point_num_per_frame = 1024;

    aenc_attr.value = &aenc_aac;
    aenc_aac.aac_type = HI_AAC_TYPE_AACLC;
    aenc_aac.bit_rate = TS_HDMI_AUDIO_BIT_RATE;
    aenc_aac.bit_width = HI_AUDIO_BIT_WIDTH_16;
    aenc_aac.sample_rate = TS_HDMI_AUDIO_SAMPLE_RATE;
    aenc_aac.snd_mode = TS_HDMI_AUDIO_SND_MODE;
    aenc_aac.transport_type = HI_AAC_TRANSPORT_TYPE_ADTS;
    aenc_aac.band_width = 0;

    /* create aenc chn */
    ret = hi_mpi_aenc_create_chn(ae_chn, &aenc_attr);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_aenc_create_chn(%d) failed with %#x!", ae_chn, ret);
        goto exit_aio_3;
    }
    log_printf(2,"hi_mpi_ai enc complete 1");

    src_chn.mod_id = HI_ID_AI;
    src_chn.chn_id = ai_chn;
    src_chn.dev_id = ai_dev;
    dest_chn.mod_id = HI_ID_AENC;
    dest_chn.dev_id = 0;
    dest_chn.chn_id = ae_chn;

    ret = hi_mpi_sys_bind(&src_chn, &dest_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_sys_bind failed with %#x!", ret);
        goto exit_aio_4;
    }

   log_printf(2,"hi_mpi_ai enc complete");


    g_media_start = 1;
    pthread_create(&g_media_threadid, NULL, media_get_stream_proc, NULL);
    // sleep(4);
    pthread_create(&g_st_OSD_read_Thread, NULL, SAMPLE_RGN_VencOSdDynamicRead, NULL);
    pthread_create(&g_st_OSD_Thread, NULL, SAMPLE_RGN_VencOSdDynamicDisplay, NULL);

    //log_printf(2,"please choose mode, press 'q' to exit this sample.");
    //             // sample_region_venc_overlay();
    //log_printf(2,"\tq) quit");
    char ch;
    while(1)
    {
        ch = getchar();
        if(10 == ch)
        {
            continue;
        }

        getchar();

        if(('Q' == ch)||('q' == ch))
        {
            break;
        }
        else
        {
            //log_printf(2,"preview mode invaild! please try again.");
            sleep(10);
            // continue;
        }

    }

    g_media_start = 0;
    pthread_join(g_media_threadid, 0);

 exit_aio_4:
    src_chn.mod_id = HI_ID_AI;
    src_chn.dev_id = ai_dev;
    src_chn.chn_id = ai_chn;
    dest_chn.mod_id = HI_ID_AENC;
    dest_chn.dev_id = 0;
    dest_chn.chn_id = ae_chn;

     ret = hi_mpi_sys_unbind(&src_chn, &dest_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_sys_unbind failed with %#x!", ret);
        goto exit_aio_3;
    }

    ret = hi_mpi_aenc_destroy_chn(ae_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_aenc_destroy_chn(%d) failed with %#x!", ae_chn, ret);
    }

 exit_aio_3:

    ret = hi_mpi_ai_disable_chn(ai_dev, ai_chn);
    if (ret) {
        log_printf(4,"hi_mpi_ai_disable_chn(%d,%d) failed with %#x", ai_dev, ai_chn, ret);
    }

 exit_aio_0:
    ret = hi_mpi_ai_disable(ai_dev);
    if (ret) {
        log_printf(4,"hi_mpi_ai_disable(%d) failed with %#x", ai_dev, ret);
    }

    src_chn.mod_id = HI_ID_VPSS;
    src_chn.dev_id = grp;
    src_chn.chn_id = vpss_chn;

    dest_chn.mod_id = HI_ID_VENC;
    dest_chn.dev_id = 0;
    dest_chn.chn_id = venc_chn;

    ret = hi_mpi_sys_unbind(&src_chn, &dest_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_sys_unbind failed with %#x", ret);
    }

EXIT_VENC_H265_STOP:
    ret = hi_mpi_venc_stop_chn(venc_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_venc_stop_chn vechn[%d] failed with %#x!", venc_chn, ret);
    }

    /* distroy venc channel */
    ret = hi_mpi_venc_destroy_chn(venc_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_venc_destroy_chn vechn[%d] failed with %#x!", venc_chn, ret);
        return HI_FAILURE;
    }
exit_vo_6:

exit_vpss_2:
    src_chn.mod_id = HI_ID_VI;
    src_chn.dev_id = 0;
    src_chn.chn_id = vi_chn;

    dest_chn.mod_id = HI_ID_VPSS;
    dest_chn.dev_id = grp;
    dest_chn.chn_id = 0;

    ret = hi_mpi_sys_unbind(&src_chn, &dest_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_sys_unbind failed with %#x", ret);
    }

    ret = hi_mpi_vpss_disable_chn(grp, vpss_chn);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vpss_disable_chn failed with %#x", ret);
    }

exit_vpss_1:
    ret = hi_mpi_vpss_stop_grp(grp);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vpss_stop_grp failed with %#x", ret);
    }

exit_vpss_0:
    ret = hi_mpi_vpss_destroy_grp(grp);
    if (ret != HI_SUCCESS) {
        log_printf(4,"hi_mpi_vpss_destroy_grp failed with %#x", ret);
    }
exit_vi_1:
    // ret = hi_mpi_vi_disable_chn(vi_chn);
    // if (ret != HI_SUCCESS) {
    //    log_printf(2,"hi_mpi_vi_disable_chn failed 0x%x", ret);
    // }
exit_vi_0:
    // ret = hi_mpi_vi_disable_dev(vi_dev);
    // if (ret != HI_SUCCESS) {
    //     log_printf(2,"hi_mpi_vi_disable_dev failed 0x%x", ret);
    // }
exit_sys:
    hi_mpi_aenc_aac_deinit();

    hi_mpi_sys_exit();
    hi_mpi_vb_exit_mod_common_pool(HI_VB_UID_VDEC);
    hi_mpi_vb_exit();
    return ret;
}
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区