vp9-rtc: Fix to Q clamp in adjust_q_cbr
authorMarco Paniconi <marpan@google.com>
Mon, 25 Feb 2019 03:02:14 +0000 (19:02 -0800)
committerMarco Paniconi <marpan@google.com>
Mon, 25 Feb 2019 03:09:38 +0000 (19:09 -0800)
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

index e342250..9540e21 100644 (file)
@@ -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);