From 892c855313fa068067299001a3d0c9bbe2b68c4f Mon Sep 17 00:00:00 2001 From: Marco Paniconi Date: Sun, 24 Feb 2019 19:02:14 -0800 Subject: [PATCH] vp9-rtc: Fix to Q clamp in adjust_q_cbr For CBR mode: clamp the Q to worst/best quality in adjust_q_cbr(). Under certain conditions, when the worst/best quality is suddenly changed by a large amount mid-stream, the Q adjustment from the final Q from adjust_q_cbr may not respect the worst/best qualiy limits. Change-Id: I3776129325d89882d422b22e6247d44660dd90ac --- vp9/encoder/vp9_ratectrl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index e3422509d..9540e218b 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -668,7 +668,7 @@ static int adjust_q_cbr(const VP9_COMP *cpi, int q) { } if (cpi->oxcf.content == VP9E_CONTENT_SCREEN) vp9_cyclic_refresh_limit_q(cpi, &q); - return q; + return VPXMAX(VPXMIN(q, cpi->rc.worst_quality), cpi->rc.best_quality); } static double get_rate_correction_factor(const VP9_COMP *cpi) { @@ -1076,6 +1076,7 @@ static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi, q = *top_index; } } + assert(*top_index <= rc->worst_quality && *top_index >= rc->best_quality); assert(*bottom_index <= rc->worst_quality && *bottom_index >= rc->best_quality); -- 2.40.0