Fix a bug when CONFIG_REALTIME_ONLY=1

When CONFIG_REALTIMIE_ONLY=1 and mode=REALTIME, then force lag_in_frames
to be 0 when we set up num_lap_buffers. After this bug fix, we can make
the threshold in the unit test BasicRateTargetingVBRLagRealtime to be
more strict.

Change-Id: I5e08d8214ffb758379c73328d26694206d6e02b6
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 36df963..e4e77c9 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -1388,6 +1388,8 @@
 
   // Set Group of frames configuration.
 #if CONFIG_REALTIME_ONLY
+  // When CONFIG_REALTIMIE_ONLY=1 and mode=REALTIME, then force lag_in_frames
+  // = 0.
   gf_cfg->lag_in_frames = (oxcf->mode == REALTIME)
                               ? 0
                               : clamp(cfg->g_lag_in_frames, 0, MAX_LAG_BUFFERS);
@@ -3055,10 +3057,16 @@
       set_encoder_config(&priv->oxcf, &priv->cfg, &priv->extra_cfg);
       if (priv->oxcf.pass == AOM_RC_ONE_PASS) {
         // Enable look ahead.
-        *num_lap_buffers =
-            AOMMIN((int)priv->cfg.g_lag_in_frames,
-                   AOMMIN(MAX_LAP_BUFFERS, priv->oxcf.kf_cfg.key_freq_max +
-                                               SCENE_CUT_KEY_TEST_INTERVAL));
+        *num_lap_buffers = AOMMIN(
+#if CONFIG_REALTIME_ONLY
+            // When CONFIG_REALTIMIE_ONLY=1 and mode=REALTIME, then force
+            // lag_in_frames = 0.
+            (priv->oxcf.mode == REALTIME) ? 0 : (int)priv->cfg.g_lag_in_frames,
+#else
+            (int)priv->cfg.g_lag_in_frames,
+#endif
+            AOMMIN(MAX_LAP_BUFFERS, priv->oxcf.kf_cfg.key_freq_max +
+                                        SCENE_CUT_KEY_TEST_INTERVAL));
         if ((int)priv->cfg.g_lag_in_frames - (*num_lap_buffers) >=
             LAP_LAG_IN_FRAMES) {
           lap_lag_in_frames = LAP_LAG_IN_FRAMES;
diff --git a/test/datarate_test.cc b/test/datarate_test.cc
index d886c2a..0969e9f 100644
--- a/test/datarate_test.cc
+++ b/test/datarate_test.cc
@@ -377,7 +377,7 @@
     // With CONFIG_REALTIME_ONLY=1, lag_in_frames is set to 0, and along with
     // other factors in that configuration the threshold needs to be lowered
     // after commit 2fed9c389d.
-    ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.65)
+    ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.8)
         << " The datarate for the file is lower than target by too much!";
 #else
     ASSERT_GE(effective_datarate_, cfg_.rc_target_bitrate * 0.85)