From 74985f88ee3bd26dcf346fa5f44cc304fcfffba1 Mon Sep 17 00:00:00 2001 From: Jung Zhao Date: Tue, 14 Mar 2017 16:35:04 +0800 Subject: [PATCH] [rc]: fix first gop ratecontrol working bad bug since have little data to estimate qp, qp of frame in first gop is nearly hor-line. now we add a re-encode mechanism to avoid this bug. re-encode frame if it meets all the conditions below: 1. gop is the first gop 2. type is p frame 3. target_bis is larger than 1.5 * real_bits and the qp_init will decrese 3 when re-encode. TODO: maybe use sse to calculate a proper value instead of 3 or add a much more suitable condition to start this re-encode process. Change-Id: I2bea5dd31a3f0348a23b40650b2e11bce32ca2db Signed-off-by: Jung Zhao Signed-off-by: Lin Kesheng --- mpp/hal/rkenc/h264e/hal_h264e_rkv.c | 19 +++++++++++++++++++ mpp/hal/vpu/jpegd/hal_jpegd_vdpu1.c | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mpp/hal/rkenc/h264e/hal_h264e_rkv.c b/mpp/hal/rkenc/h264e/hal_h264e_rkv.c index 578e1a85..4d5db2ec 100644 --- a/mpp/hal/rkenc/h264e/hal_h264e_rkv.c +++ b/mpp/hal/rkenc/h264e/hal_h264e_rkv.c @@ -3250,6 +3250,7 @@ MPP_RET hal_h264e_rkv_wait(void *hal, HalTaskInfo *task) h264e_feedback *fb = &ctx->feedback; HalEncTask *enc_task = &task->enc; MppEncPrepCfg *prep = &ctx->cfg->prep; + MppEncRcCfg *rcfg = &ctx->cfg->rc; H264eHwCfg *hw_cfg = &ctx->hw_cfg; RK_S32 num_mb = MPP_ALIGN(prep->width, 16) * MPP_ALIGN(prep->height, 16) / 16 / 16; /* for dumping ratecontrol message */ @@ -3313,6 +3314,24 @@ MPP_RET hal_h264e_rkv_wait(void *hal, HalTaskInfo *task) if (ctx->frame_cnt == 1) { h264e_rkv_resend(ctx, 0); + h264e_rkv_set_feedback(fb, reg_out); + } else if ((RK_S32)ctx->frame_cnt < rcfg->fps_out_num / rcfg->fps_out_denorm && + rc_syn->type == INTER_P_FRAME && + rc_syn->bit_target > fb->out_strm_size * 8 * 1.5) { + /* re-encode frame if it meets all the conditions below: + * 1. gop is the first gop + * 2. type is p frame + * 3. target_bits is larger than 1.5 * real_bits + * and the qp_init will decrease 3 when re-encode. + * + * TODO: maybe use sse to calculate a proper value instead of 3 + * or add a much more suitable condition to start this re-encode + * process. + */ + RK_S32 new_qp = fb->qp_sum / num_mb - 3; + fb->qp_sum = new_qp * num_mb; + + h264e_rkv_resend(ctx, 1); h264e_rkv_set_feedback(fb, reg_out); } diff --git a/mpp/hal/vpu/jpegd/hal_jpegd_vdpu1.c b/mpp/hal/vpu/jpegd/hal_jpegd_vdpu1.c index 11b5554c..d0716029 100644 --- a/mpp/hal/vpu/jpegd/hal_jpegd_vdpu1.c +++ b/mpp/hal/vpu/jpegd/hal_jpegd_vdpu1.c @@ -633,7 +633,7 @@ jpegd_set_post_processor(JpegHalContext *pCtx, JpegSyntaxParam *pSyntax) } else { if (outWidth * outHeight > 0x400000) { JPEGD_ERROR_LOG - ("out offset big than 22bit iommu map may be error"); + ("out offset big than 22bit iommu map may be error"); } else { post->reg67_pp_out_ch_base = (phy_addr | ((outWidth * outHeight) << 10)); @@ -873,7 +873,7 @@ static MPP_RET jpegd_gen_regs(JpegHalContext *ctx, JpegSyntaxParam *syntax) do { /* loop until decoding control should return for user */ if (pSyntax->ppInstance != NULL) { - /* if pp enabled ==> set pp control */ + /* if pp enabled ==> set pp control */ pSyntax->ppControl.usePipeline = 1; }