diff options
author | Marco Paniconi <marpan@google.com> | 2018-05-30 13:55:28 -0700 |
---|---|---|
committer | Marco Paniconi <marpan@google.com> | 2018-05-30 14:58:48 -0700 |
commit | d7a80012a06f67ee0130864b1f89e394778a1f02 (patch) | |
tree | 07447cbd706156a2d2fdac358977c0b14f5ffec7 /vp9 | |
parent | 7f7782bebdcb43708bda2f88e4ae21e4319bdf29 (diff) | |
download | libvpx-d7a80012a06f67ee0130864b1f89e394778a1f02.tar libvpx-d7a80012a06f67ee0130864b1f89e394778a1f02.tar.gz libvpx-d7a80012a06f67ee0130864b1f89e394778a1f02.tar.bz2 libvpx-d7a80012a06f67ee0130864b1f89e394778a1f02.zip |
vp9: Refactor code for q adjustment in CBR mode.
Move the adjustment code to separate function.
Change-Id: I876b246a5c26095f262bb9a19f03d1f17077225d
Diffstat (limited to 'vp9')
-rw-r--r-- | vp9/encoder/vp9_aq_cyclicrefresh.c | 7 | ||||
-rw-r--r-- | vp9/encoder/vp9_aq_cyclicrefresh.h | 2 | ||||
-rw-r--r-- | vp9/encoder/vp9_ratectrl.c | 44 |
3 files changed, 29 insertions, 24 deletions
diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.c b/vp9/encoder/vp9_aq_cyclicrefresh.c index 3aaec2e29..3b4fee7cf 100644 --- a/vp9/encoder/vp9_aq_cyclicrefresh.c +++ b/vp9/encoder/vp9_aq_cyclicrefresh.c @@ -599,10 +599,11 @@ void vp9_cyclic_refresh_reset_resize(VP9_COMP *const cpi) { cpi->refresh_alt_ref_frame = 1; } -void vp9_cyclic_refresh_limit_q(CYCLIC_REFRESH *const cr, int prev_q, int *q) { +void vp9_cyclic_refresh_limit_q(const VP9_COMP *cpi, int *q) { + CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; // For now apply hard limit to frame-level decrease in q, if the cyclic // refresh is active (percent_refresh > 0). - if (cr->percent_refresh > 0 && prev_q - *q > 8) { - *q = prev_q - 8; + if (cr->percent_refresh > 0 && cpi->rc.q_1_frame - *q > 8) { + *q = cpi->rc.q_1_frame - 8; } } diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.h b/vp9/encoder/vp9_aq_cyclicrefresh.h index ce72fcb33..f59f193f6 100644 --- a/vp9/encoder/vp9_aq_cyclicrefresh.h +++ b/vp9/encoder/vp9_aq_cyclicrefresh.h @@ -139,7 +139,7 @@ static INLINE int cyclic_refresh_segment_id(int segment_id) { return CR_SEGMENT_ID_BASE; } -void vp9_cyclic_refresh_limit_q(CYCLIC_REFRESH *const cr, int prev_q, int *q); +void vp9_cyclic_refresh_limit_q(const struct VP9_COMP *cpi, int *q); #ifdef __cplusplus } // extern "C" diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index 2b2f17bc0..70b3a7ab6 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -554,6 +554,28 @@ int vp9_rc_drop_frame(VP9_COMP *cpi) { return 0; } +static int adjust_q_cbr(const VP9_COMP *cpi, int q) { + // This makes sure q is between oscillating Qs to prevent resonance. + if (!cpi->rc.reset_high_source_sad && + (!cpi->oxcf.gf_cbr_boost_pct || + !(cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame)) && + (cpi->rc.rc_1_frame * cpi->rc.rc_2_frame == -1) && + cpi->rc.q_1_frame != cpi->rc.q_2_frame) { + int qclamp = clamp(q, VPXMIN(cpi->rc.q_1_frame, cpi->rc.q_2_frame), + VPXMAX(cpi->rc.q_1_frame, cpi->rc.q_2_frame)); + // If the previous frame had overshoot and the current q needs to increase + // above the clamped value, reduce the clamp for faster reaction to + // overshoot. + if (cpi->rc.rc_1_frame == -1 && q > qclamp) + q = (q + qclamp) >> 1; + else + q = qclamp; + } + if (cpi->oxcf.content == VP9E_CONTENT_SCREEN) + vp9_cyclic_refresh_limit_q(cpi, &q); + return q; +} + static double get_rate_correction_factor(const VP9_COMP *cpi) { const RATE_CONTROL *const rc = &cpi->rc; double rcf; @@ -713,26 +735,8 @@ int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame, } while (++i <= active_worst_quality); // Adjustment to q for CBR mode. - if (cpi->oxcf.rc_mode == VPX_CBR) { - // This makes sure q is between oscillating Qs to prevent resonance. - if (!cpi->rc.reset_high_source_sad && - (!cpi->oxcf.gf_cbr_boost_pct || - !(cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame)) && - (cpi->rc.rc_1_frame * cpi->rc.rc_2_frame == -1) && - cpi->rc.q_1_frame != cpi->rc.q_2_frame) { - int qclamp = clamp(q, VPXMIN(cpi->rc.q_1_frame, cpi->rc.q_2_frame), - VPXMAX(cpi->rc.q_1_frame, cpi->rc.q_2_frame)); - // If the previous frame had overshoot and the current q needs to increase - // above the clamped value, reduce the clamp for faster reaction to - // overshoot. - if (cpi->rc.rc_1_frame == -1 && q > qclamp) - q = (q + qclamp) >> 1; - else - q = qclamp; - } - if (cpi->oxcf.content == VP9E_CONTENT_SCREEN) - vp9_cyclic_refresh_limit_q(cr, cpi->rc.q_1_frame, &q); - } + if (cpi->oxcf.rc_mode == VPX_CBR) return adjust_q_cbr(cpi, q); + return q; } |