From eec3def7c5f8ae558e096615801d6afc7e779b29 Mon Sep 17 00:00:00 2001
From: Paul Wilkins <paulwilkins@google.com>
Date: Wed, 16 Oct 2013 10:59:55 +0100
Subject: [PATCH] Modified no memory rate control.

This 2-pass rate control setting allocates bits based
on first pass stats to each kf group, gf group and individual
frame but does not correct the bits left and allocation after
each frame.

In other words it recommends a bit allocation for each frame
but does not try and correct any over or under spend on a
frame over the remainder of the clip. This reduces the accuracy
of rate control in terms of hitting an average bitrate but prevents
problems that may arise because early frames either use to many
or too few bits. This mode is currently more inclined to undershoot
than overshoot (particularly at higher data rates).

Also minor changes to rate of adaption when recode loop is not
enabled.

This mode is currently enabled by default for VBR.
It gives the following % performance gains.

derf +0.467, +1.072
yt 2.962, 2.645
stdhd 1.682, 1.595,
yt-hd 2.3, 2.174

Change-Id: I3c84a9bf8884e5b345698ff0e19187f792c2f3a0
---
 vp9/encoder/vp9_onyx_if.c  | 7 +++++--
 vp9/encoder/vp9_onyx_int.h | 2 +-
 vp9/encoder/vp9_ratectrl.c | 4 ++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c
index ffd34c90aa..a8a7ba6f19 100644
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -1743,7 +1743,7 @@ VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
   vp9_zero(cpi->y_uv_mode_count);
 
 #ifdef MODE_TEST_HIT_STATS
-  vp9_zero(cpi->mode_test_hits)
+  vp9_zero(cpi->mode_test_hits);
 #endif
 
   return (VP9_PTR) cpi;
@@ -3295,8 +3295,9 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
   cpi->total_byte_count += (*size);
   cpi->projected_frame_size = (*size) << 3;
 
+  // Post encode loop adjustment of Q prediction.
   if (!active_worst_qchanged)
-    vp9_update_rate_correction_factors(cpi, 2);
+    vp9_update_rate_correction_factors(cpi, (cpi->sf.recode_loop) ? 2 : 0);
 
   cpi->last_q[cm->frame_type] = cm->base_qindex;
 
@@ -3371,6 +3372,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
 
   cpi->buffer_level = cpi->bits_off_target;
 
+#ifndef DISABLE_RC_LONG_TERM_MEM
   // Update bits left to the kf and gf groups to account for overshoot or
   // undershoot on these frames
   if (cm->frame_type == KEY_FRAME) {
@@ -3384,6 +3386,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
 
     cpi->twopass.gf_group_bits = MAX(cpi->twopass.gf_group_bits, 0);
   }
+#endif
 
 #if 0
   output_frame_level_debug_stats(cpi);
diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h
index 2e5c7bc7e6..7187884100 100644
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -33,8 +33,8 @@
 #if CONFIG_ONESHOTQ
 #define ONE_SHOT_Q_ESTIMATE 0
 #define STRICT_ONE_SHOT_Q 0
-#define DISABLE_RC_LONG_TERM_MEM 0
 #endif
+#define DISABLE_RC_LONG_TERM_MEM 0
 
 // #define MODE_TEST_HIT_STATS
 
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c
index 224d1e4f31..0aa3a6893e 100644
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -288,7 +288,7 @@ void vp9_update_rate_correction_factors(VP9_COMP *cpi, int damp_var) {
   if (correction_factor > 102) {
     // We are not already at the worst allowable quality
     correction_factor =
-        (int)(100.5 + ((correction_factor - 100) * adjustment_limit));
+        (int)(100 + ((correction_factor - 100) * adjustment_limit));
     rate_correction_factor =
         ((rate_correction_factor * correction_factor) / 100);
 
@@ -298,7 +298,7 @@ void vp9_update_rate_correction_factors(VP9_COMP *cpi, int damp_var) {
   } else if (correction_factor < 99) {
     // We are not already at the best allowable quality
     correction_factor =
-        (int)(100.5 - ((100 - correction_factor) * adjustment_limit));
+        (int)(100 - ((100 - correction_factor) * adjustment_limit));
     rate_correction_factor =
         ((rate_correction_factor * correction_factor) / 100);
 
-- 
GitLab