summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vp9/encoder/vp9_aq_cyclicrefresh.c7
-rw-r--r--vp9/encoder/vp9_aq_cyclicrefresh.h2
-rw-r--r--vp9/encoder/vp9_ratectrl.c44
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;
}