From a2c289bbce03a90b04da7bf3f52a46fbe54aff68 Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Fri, 11 Sep 2020 15:10:15 +0800 Subject: [PATCH] [mpp_enc_ref]: Add st_cfg repeat value check 1. When repeat in st_cfg is negative set it to zero. 2. Do not insert non-reference frame when smart oop vi_len less than 2. Change-Id: Icdf2be21fbbe0a919f7c3006d9c1dde5dfc5ffcb Signed-off-by: Herman Chen --- mpp/base/mpp_enc_ref.cpp | 6 ++++++ utils/mpi_enc_utils.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/mpp/base/mpp_enc_ref.cpp b/mpp/base/mpp_enc_ref.cpp index 69f74eaa..46d0f989 100644 --- a/mpp/base/mpp_enc_ref.cpp +++ b/mpp/base/mpp_enc_ref.cpp @@ -269,6 +269,12 @@ MPP_RET mpp_enc_ref_cfg_check(MppEncRefCfg ref) ready = 0; } + if (cfg->repeat < 0) { + mpp_err_f("ref cfg %p st cfg %d with negative repeat %d set to zero\n", + ref, pos, cfg->repeat); + cfg->repeat = 0; + } + /* constrain on head and tail frame */ if (pos == 0 || (pos == st_cfg_cnt - 1)) { if (cfg->is_non_ref) { diff --git a/utils/mpi_enc_utils.c b/utils/mpi_enc_utils.c index 5db008e8..bc8fc5b9 100644 --- a/utils/mpi_enc_utils.c +++ b/utils/mpi_enc_utils.c @@ -542,6 +542,7 @@ MPP_RET mpi_enc_gen_smart_gop_ref_cfg(MppEncRefCfg ref, RK_S32 gop_len, RK_S32 v MppEncRefStFrmCfg st_ref[16]; RK_S32 lt_cnt = 1; RK_S32 st_cnt = 8; + RK_S32 pos = 0; MPP_RET ret = MPP_OK; memset(<_ref, 0, sizeof(lt_ref)); @@ -559,26 +560,31 @@ MPP_RET mpi_enc_gen_smart_gop_ref_cfg(MppEncRefCfg ref, RK_S32 gop_len, RK_S32 v ret = mpp_enc_ref_cfg_add_lt_cfg(ref, 1, lt_ref); /* st 0 layer 0 - ref */ - st_ref[0].is_non_ref = 0; - st_ref[0].temporal_id = 0; - st_ref[0].ref_mode = REF_TO_PREV_INTRA; - st_ref[0].ref_arg = 0; - st_ref[0].repeat = 0; + st_ref[pos].is_non_ref = 0; + st_ref[pos].temporal_id = 0; + st_ref[pos].ref_mode = REF_TO_PREV_INTRA; + st_ref[pos].ref_arg = 0; + st_ref[pos].repeat = 0; + pos++; - /* st 1 layer 3 - non-ref */ - st_ref[1].is_non_ref = 0; - st_ref[1].temporal_id = 1; - st_ref[1].ref_mode = REF_TO_PREV_REF_FRM; - st_ref[1].ref_arg = 0; - st_ref[1].repeat = vi_len - 2; + /* st 1 layer 1 - non-ref */ + if (vi_len > 1) { + st_ref[pos].is_non_ref = 0; + st_ref[pos].temporal_id = 1; + st_ref[pos].ref_mode = REF_TO_PREV_REF_FRM; + st_ref[pos].ref_arg = 0; + st_ref[pos].repeat = vi_len - 2; + pos++; + } - st_ref[2].is_non_ref = 0; - st_ref[2].temporal_id = 0; - st_ref[2].ref_mode = REF_TO_PREV_INTRA; - st_ref[2].ref_arg = 0; - st_ref[2].repeat = 0; + st_ref[pos].is_non_ref = 0; + st_ref[pos].temporal_id = 0; + st_ref[pos].ref_mode = REF_TO_PREV_INTRA; + st_ref[pos].ref_arg = 0; + st_ref[pos].repeat = 0; + pos++; - ret = mpp_enc_ref_cfg_add_st_cfg(ref, 3, st_ref); + ret = mpp_enc_ref_cfg_add_st_cfg(ref, pos, st_ref); /* check and get dpb size */ ret = mpp_enc_ref_cfg_check(ref);