[rk_mpi_cmd]: Add max_reenc_cnt for reencode flow

When max_reenc_cnt is zero the reencode flow is disabled.

Change-Id: Iba600b37bb5ab6e4f720b652d59abfae36f9e52f
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2020-05-14 15:33:46 +08:00
parent 85f9662150
commit 0b4532c6d5
15 changed files with 29 additions and 23 deletions

View File

@@ -158,7 +158,7 @@ typedef enum MppEncRcCfgChange_e {
MPP_ENC_RC_CFG_CHANGE_FPS_IN = (1 << 5), /* change on fps in flex / numerator / denorminator */
MPP_ENC_RC_CFG_CHANGE_FPS_OUT = (1 << 6), /* change on fps out flex / numerator / denorminator */
MPP_ENC_RC_CFG_CHANGE_GOP = (1 << 7),
MPP_ENC_RC_CFG_CHANGE_SKIP_CNT = (1 << 8),
MPP_ENC_RC_CFG_CHANGE_MAX_REENC = (1 << 8),
MPP_ENC_RC_CFG_CHANGE_ALL = (0xFFFFFFFF),
} MppEncRcCfgChange;
@@ -270,10 +270,11 @@ typedef struct MppEncRcCfg_t {
RK_S32 gop;
/*
* skip_cnt - max continuous frame skip count
* 0 - frame skip is not allow
* max_reenc_times - max reencode time for one frame
* 0 - reencode is not allowed
* 1~3 max reencode time is limited to 3
*/
RK_S32 skip_cnt;
RK_U32 max_reenc_times;
/*
* stat_times - the time of bitrate statistics

View File

@@ -162,6 +162,7 @@ static const char *cfg_func_names[] = {
ENTRY(rc, fps_out_num, S32, RK_S32, MPP_ENC_RC_CFG_CHANGE_FPS_OUT, rc, fps_out_num) \
ENTRY(rc, fps_out_denorm, S32, RK_S32, MPP_ENC_RC_CFG_CHANGE_FPS_OUT, rc, fps_out_denorm) \
ENTRY(rc, gop, S32, RK_S32, MPP_ENC_RC_CFG_CHANGE_GOP, rc, gop) \
ENTRY(rc, max_reenc_times,U32, RK_U32, MPP_ENC_RC_CFG_CHANGE_MAX_REENC, rc, max_reenc_times) \
/* prep config */ \
ENTRY(prep, width, S32, RK_S32, MPP_ENC_PREP_CFG_CHANGE_INPUT, prep, width) \
ENTRY(prep, height, S32, RK_S32, MPP_ENC_PREP_CFG_CHANGE_INPUT, prep, height) \

View File

@@ -39,7 +39,7 @@
/* ascii 32 is ' ', char after space is valid data */
#define MAX_NEXT (128 - 32)
#define DEFAULT_NODE_COUNT 800
#define DEFAULT_NODE_COUNT 900
#define DEFAULT_INFO_COUNT 80
/* spatial optimized tire tree */

View File

@@ -99,7 +99,7 @@ static MPP_RET h264e_init(void *ctx, EncImplCfg *ctrl_cfg)
rc_cfg->fps_out_num = 30;
rc_cfg->fps_out_denorm = 1;
rc_cfg->gop = 60;
rc_cfg->skip_cnt = 0;
rc_cfg->max_reenc_times = 1;
p->cfg = ctrl_cfg->cfg;
p->set = ctrl_cfg->set;

View File

@@ -135,7 +135,7 @@ static void init_h264e_cfg_set(MppEncCfgSet *cfg)
rc_cfg->fps_out_num = 30;
rc_cfg->fps_out_denorm = 1;
rc_cfg->gop = 60;
rc_cfg->skip_cnt = 0;
rc_cfg->max_reenc_times = 1;
}
static void h264e_add_syntax(H264eCtx *ctx, H264eSyntaxType type, void *p)
@@ -286,8 +286,8 @@ static MPP_RET h264e_proc_rc_cfg(MppEncRcCfg *dst, MppEncRcCfg *src)
if (change & MPP_ENC_RC_CFG_CHANGE_GOP)
dst->gop = src->gop;
if (change & MPP_ENC_RC_CFG_CHANGE_SKIP_CNT)
dst->skip_cnt = src->skip_cnt;
if (change & MPP_ENC_RC_CFG_CHANGE_MAX_REENC)
dst->max_reenc_times = src->max_reenc_times;
// parameter checking
if (dst->rc_mode >= MPP_ENC_RC_MODE_BUTT) {

View File

@@ -151,7 +151,7 @@ static MPP_RET h265e_init(void *ctx, EncImplCfg *ctrlCfg)
rc_cfg->fps_out_num = 30;
rc_cfg->fps_out_denorm = 1;
rc_cfg->gop = 60;
rc_cfg->skip_cnt = 0;
rc_cfg->max_reenc_times = 1;
INIT_LIST_HEAD(&p->rc_list);
@@ -467,6 +467,7 @@ static MPP_RET h265e_proc_h265_cfg(MppEncH265Cfg *dst, MppEncH265Cfg *src)
dst->max_i_qp = src->max_i_qp;
dst->min_i_qp = src->min_i_qp;
}
/*
* NOTE: use OR here for avoiding overwrite on multiple config
* When next encoding is trigger the change flag will be clear

View File

@@ -168,8 +168,8 @@ static MPP_RET jpege_proc_rc_cfg(MppEncRcCfg *dst, MppEncRcCfg *src)
dst->fps_out_denorm = src->fps_out_denorm;
}
if (change & MPP_ENC_RC_CFG_CHANGE_GOP)
dst->gop = src->gop;
if (change & MPP_ENC_RC_CFG_CHANGE_MAX_REENC)
dst->max_reenc_times = src->max_reenc_times;
// parameter checking
if (dst->rc_mode >= MPP_ENC_RC_MODE_BUTT) {

View File

@@ -102,7 +102,7 @@ MPP_RET vp8e_init(void *ctx, EncImplCfg *ctrl_cfg)
rc_cfg->fps_out_num = 30;
rc_cfg->fps_out_denorm = 1;
rc_cfg->gop = 60;
rc_cfg->skip_cnt = 0;
rc_cfg->max_reenc_times = 1;
p->rc = mpp_calloc(Vp8eRc, 1);

View File

@@ -801,8 +801,8 @@ void mpp_enc_update_rc_cfg(MppEncRcCfg *dst, MppEncRcCfg *src)
if (change & MPP_ENC_RC_CFG_CHANGE_GOP)
dst->gop = src->gop;
if (change & MPP_ENC_RC_CFG_CHANGE_SKIP_CNT)
dst->skip_cnt = src->skip_cnt;
if (change & MPP_ENC_RC_CFG_CHANGE_MAX_REENC)
dst->max_reenc_times = src->max_reenc_times;
/*
* NOTE: use OR here for avoiding overwrite on multiple config

View File

@@ -487,7 +487,7 @@ static void set_rc_cfg(RcCfg *cfg, MppEncCfgSet *cfg_set)
cfg->layer_bit_prop[3] = 0;
}
cfg->max_reencode_times = 1;
cfg->max_reencode_times = rc->max_reenc_times;
mpp_log("mode %s bps [%d:%d:%d] fps %s [%d/%d] -> %s [%d/%d] gop i [%d] v [%d]\n",
name_of_rc_mode[cfg->mode],
@@ -798,11 +798,14 @@ void *mpp_enc_thread(void *data)
enc_dbg_detail("task %d rc frame end\n", frm->seq_idx);
RUN_ENC_RC_FUNC(rc_frm_end, enc->rc_ctx, rc_task, mpp, ret);
if (frm->reencode) {
if (frm->reencode_times < rc_cfg->max_reenc_times && frm->reencode) {
enc_dbg_reenc("reencode time %d\n", frm->reencode_times);
hal_task->length -= hal_task->hw_length;
hal_task->hw_length = 0;
goto TASK_REENCODE;
} else {
frm->reencode = 0;
frm->reencode_times = 0;
}
enc_dbg_detail("task %d enc update hal\n", frm->seq_idx);

View File

@@ -1254,7 +1254,7 @@ static MPP_RET vepu22_check_rc_cfg_change(HalH265eCtx* ctx, MppEncRcCfg* set)
set->fps_in_num, set->fps_in_denorm);
hal_h265e_dbg_input("fps_out_num = %d,fps_out_denorm = %d\n",
set->fps_out_num, set->fps_out_denorm);
hal_h265e_dbg_input("gop = %d,skip_cnt = %d\n", set->gop, set->skip_cnt);
hal_h265e_dbg_input("gop = %d, max_reenc_cnt = %d\n", set->gop, set->max_reenc_times);
if (!ctx->init) {
set->change = MPP_ENC_RC_CFG_CHANGE_ALL;
ctx->option |= H265E_SET_RC_CFG;
@@ -1285,7 +1285,7 @@ static MPP_RET vepu22_set_rc_cfg(HalH265eCtx* ctx)
rc->fps_in_num, rc->fps_in_denorm);
hal_h265e_dbg_input("fps_out_num = %d,fps_out_denorm = %d\n",
rc->fps_out_num, rc->fps_out_denorm);
hal_h265e_dbg_input("gop = %d,skip_cnt = %d\n", rc->gop, rc->skip_cnt);
hal_h265e_dbg_input("gop = %d, max_reenc_cnt = %d\n", rc->gop, rc->max_reenc_times);
/* the first time to set rc cfg*/
if (change & MPP_ENC_RC_CFG_CHANGE_FPS_OUT) {

View File

@@ -408,7 +408,7 @@ MPP_RET test_mpp_setup(MpiEncTestData *p)
rc_cfg->fps_out_denorm = 1;
rc_cfg->gop = p->gop;
rc_cfg->skip_cnt = 0;
rc_cfg->max_reenc_times = 1;
mpp_log("mpi_enc_test bps %d fps %d gop %d\n",
rc_cfg->bps_target, rc_cfg->fps_out_num, rc_cfg->gop);

View File

@@ -312,7 +312,7 @@ MPP_RET test_mpp_setup_legacy(MpiEncTestData *p)
rc_cfg->fps_out_denorm = p->fps_out_den;
rc_cfg->gop = p->gop;
rc_cfg->skip_cnt = 0;
rc_cfg->max_reenc_times = 1;
mpp_log("mpi_enc_test bps %d fps %d gop %d\n",
rc_cfg->bps_target, rc_cfg->fps_out_num, rc_cfg->gop);

View File

@@ -557,7 +557,7 @@ static MPP_RET mpi_rc_enc_init(MpiRc2TestCtx *ctx)
rc_cfg->fps_in_flex = 0;
rc_cfg->fps_out_flex = 0;
rc_cfg->gop = 60;
rc_cfg->skip_cnt = 0;
rc_cfg->max_reenc_times = 1;
ret = enc_mpi->control(*enc_ctx, MPP_ENC_SET_RC_CFG, rc_cfg);
if (ret) {

View File

@@ -594,7 +594,7 @@ static MPP_RET mpi_rc_codec(MpiRcTestCtx *ctx)
rc_cfg->fps_in_flex = 0;
rc_cfg->fps_out_flex = 0;
rc_cfg->gop = fps;
rc_cfg->skip_cnt = 0;
rc_cfg->max_reenc_times = 1;
ret = enc_mpi->control(enc_ctx, MPP_ENC_SET_RC_CFG, rc_cfg);
if (ret) {