From a90b35eb0178479d560e7fa0f10d5741e4c0923c Mon Sep 17 00:00:00 2001 From: Harish Mahendrakar Date: Thu, 22 Jul 2021 10:00:41 -0700 Subject: [PATCH] avcenc: Make a separate call to encode header This makes avcenc to be in sync with c2 plugin Bug: 242103842 Test: avcenc -c enc.cfg Change-Id: Ia19f8fc6d3a824a29206e3214d4c8145479ecc70 --- test/encoder/main.c | 62 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/test/encoder/main.c b/test/encoder/main.c index 471d630..b39d5cb 100644 --- a/test/encoder/main.c +++ b/test/encoder/main.c @@ -1836,6 +1836,59 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) } } + /*****************************************************************************/ + /* Video control Set in Encode header mode */ + /*****************************************************************************/ + set_enc_mode(ps_app_ctxt, -1, -1, IVE_ENC_MODE_HEADER); + + // Encode header + memset(&ih264e_video_encode_ip, 0, sizeof(ih264e_video_encode_ip)); + memset(&ih264e_video_encode_op, 0, sizeof(ih264e_video_encode_op)); + + ps_video_encode_ip->u4_size = sizeof(ih264e_video_encode_ip_t); + ps_video_encode_op->u4_size = sizeof(ih264e_video_encode_op_t); + + ps_inp_raw_buf->apv_bufs[0] = NULL; + ps_inp_raw_buf->apv_bufs[1] = NULL; + ps_inp_raw_buf->apv_bufs[2] = NULL; + + ps_video_encode_ip->e_cmd = IVE_CMD_VIDEO_ENCODE; + ps_video_encode_ip->pv_bufs = NULL; + ps_video_encode_ip->pv_mb_info = NULL; + ps_video_encode_ip->pv_pic_info = NULL; + ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type; + ps_video_encode_ip->u4_is_last = 0; + ps_video_encode_ip->u4_mb_info_type = ps_app_ctxt->u4_mb_info_type; + ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type; + ps_video_encode_ip->s_out_buf.pv_buf = ps_app_ctxt->as_output_buf[0].pu1_buf; + ps_video_encode_ip->s_out_buf.u4_bytes = 0; + ps_video_encode_ip->s_out_buf.u4_bufsize = ps_app_ctxt->as_output_buf[0].u4_buf_size; + ps_video_encode_ip->u4_timestamp_high = 0; + ps_video_encode_ip->u4_timestamp_low = 0; + + status = ih264e_api_function(ps_enc, &ih264e_video_encode_ip, &ih264e_video_encode_op); + if(IV_SUCCESS != status) + { + printf("Encode Header failed = 0x%x\n", ih264e_video_encode_op.s_ive_op.u4_error_code); + return; + } + + if(1 == ps_video_encode_op->output_present) + { + status = write_output(ps_app_ctxt->fp_op, (UWORD8 *) ps_video_encode_op->s_out_buf.pv_buf, + ps_video_encode_op->s_out_buf.u4_bytes); + if(IV_SUCCESS != status) + { + printf("Error: Unable to write to output file\n"); + return; + } + } + + /*****************************************************************************/ + /* Video control Set in Encode picture mode */ + /*****************************************************************************/ + set_enc_mode(ps_app_ctxt, -1, -1, IVE_ENC_MODE_PICTURE); + GETTIME(&ps_app_ctxt->enc_start_time); ps_app_ctxt->enc_last_time = ps_app_ctxt->enc_start_time; @@ -1920,6 +1973,9 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) exit(0); } + memset(&ih264e_video_encode_ip, 0, sizeof(ih264e_video_encode_ip)); + memset(&ih264e_video_encode_op, 0, sizeof(ih264e_video_encode_op)); + ps_video_encode_ip->u4_size = sizeof(ih264e_video_encode_ip_t); ps_video_encode_op->u4_size = sizeof(ih264e_video_encode_op_t); @@ -2078,7 +2134,6 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) ps_video_encode_ip->u4_is_last = is_last; ps_video_encode_ip->u4_mb_info_type = ps_app_ctxt->u4_mb_info_type; ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type;; - ps_video_encode_op->s_out_buf.pv_buf= NULL; ps_video_encode_ip->u4_timestamp_high = u4_timestamp_high; ps_video_encode_ip->u4_timestamp_low = u4_timestamp_low; @@ -2807,11 +2862,6 @@ int main(int argc, char *argv[]) /*****************************************************************************/ set_profile_params(&s_app_ctxt, 0, 0); - /*****************************************************************************/ - /* Video control Set in Encode header mode */ - /*****************************************************************************/ - set_enc_mode(&s_app_ctxt, 0, 0, IVE_ENC_MODE_PICTURE); - /*****************************************************************************/ /* Video usability information */ /*****************************************************************************/