From 6581817991801224d5016c86115daf79e74bad85 Mon Sep 17 00:00:00 2001 From: Marco Paniconi Date: Tue, 5 Feb 2019 10:54:28 -0800 Subject: [PATCH] vp8: Limit Q change for screen content CBR mode Add last_q[] to layer context, and add limit on Q change from previous layer/frame. For now put hard limit of 12 for decrease. For 1 pass CBR sreen content mode. Change-Id: Ifb972c9b6831440c80b1cb07a054c577ece930ec --- vp8/encoder/onyx_if.c | 4 ++++ vp8/encoder/onyx_int.h | 1 + vp8/encoder/ratectrl.c | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index 07be0d989..a30821ac1 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -218,6 +218,8 @@ static void save_layer_context(VP8_COMP *cpi) { lc->frames_since_last_drop_overshoot = cpi->frames_since_last_drop_overshoot; lc->force_maxqp = cpi->force_maxqp; lc->last_frame_percent_intra = cpi->last_frame_percent_intra; + lc->last_q[0] = cpi->last_q[0]; + lc->last_q[1] = cpi->last_q[1]; memcpy(lc->count_mb_ref_frame_usage, cpi->mb.count_mb_ref_frame_usage, sizeof(cpi->mb.count_mb_ref_frame_usage)); @@ -255,6 +257,8 @@ static void restore_layer_context(VP8_COMP *cpi, const int layer) { cpi->frames_since_last_drop_overshoot = lc->frames_since_last_drop_overshoot; cpi->force_maxqp = lc->force_maxqp; cpi->last_frame_percent_intra = lc->last_frame_percent_intra; + cpi->last_q[0] = lc->last_q[0]; + cpi->last_q[1] = lc->last_q[1]; memcpy(cpi->mb.count_mb_ref_frame_usage, lc->count_mb_ref_frame_usage, sizeof(cpi->mb.count_mb_ref_frame_usage)); diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index 5189d4338..a4e3f2f79 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -257,6 +257,7 @@ typedef struct { int count_mb_ref_frame_usage[MAX_REF_FRAMES]; + int last_q[2]; } LAYER_CONTEXT; typedef struct VP8_COMP { diff --git a/vp8/encoder/ratectrl.c b/vp8/encoder/ratectrl.c index d7badeb5a..dbd76edad 100644 --- a/vp8/encoder/ratectrl.c +++ b/vp8/encoder/ratectrl.c @@ -1125,6 +1125,14 @@ void vp8_update_rate_correction_factors(VP8_COMP *cpi, int damp_var) { } } +static int limit_q_cbr_inter(int last_q, int current_q) { + int limit_down = 12; + if (last_q - current_q > limit_down) + return (last_q - limit_down); + else + return current_q; +} + int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame) { int Q = cpi->active_worst_quality; @@ -1264,6 +1272,12 @@ int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame) { } } + // Limit decrease in Q for 1 pass CBR screen content mode. + if (cpi->common.frame_type != KEY_FRAME && cpi->pass == 0 && + cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER && + cpi->oxcf.screen_content_mode) + Q = limit_q_cbr_inter(cpi->last_q[1], Q); + return Q; } -- 2.40.0