Add arf_boost factor to GOP sructure

No coding stats change.

Change-Id: Ia263e6d0432efc44e03cf6da93416f924e7584ef
diff --git a/av1/encoder/firstpass.h b/av1/encoder/firstpass.h
index 4a3a2f9..87b1344 100644
--- a/av1/encoder/firstpass.h
+++ b/av1/encoder/firstpass.h
@@ -124,6 +124,7 @@
   // TODO(jingning): Unify the data structure used here after the new control
   // mechanism is in place.
   int layer_depth[MAX_STATIC_GF_GROUP_LENGTH];
+  int arf_boost[MAX_STATIC_GF_GROUP_LENGTH];
   // This is currently only populated for AOM_Q mode
   unsigned char q_val[MAX_STATIC_GF_GROUP_LENGTH];
   int bit_allocation[MAX_STATIC_GF_GROUP_LENGTH];
diff --git a/av1/encoder/gop_structure.c b/av1/encoder/gop_structure.c
index eb4f3a8..1cc676d 100644
--- a/av1/encoder/gop_structure.c
+++ b/av1/encoder/gop_structure.c
@@ -26,9 +26,9 @@
 #include "av1/encoder/gop_structure.h"
 
 // Set parameters for frames between 'start' and 'end' (excluding both).
-static void set_multi_layer_params(GF_GROUP *const gf_group, int start, int end,
-                                   int *frame_ind, int arf_ind, int level,
-                                   int layer_depth) {
+static void set_multi_layer_params(AV1_COMP *cpi, GF_GROUP *const gf_group,
+                                   int start, int end, int *frame_ind,
+                                   int arf_ind, int level, int layer_depth) {
   assert(level >= MIN_PYRAMID_LVL);
   const int num_frames_to_process = end - start - 1;
   assert(num_frames_to_process >= 0);
@@ -46,6 +46,7 @@
       gf_group->frame_disp_idx[*frame_ind] = start;
       gf_group->pyramid_level[*frame_ind] = MIN_PYRAMID_LVL;
       gf_group->layer_depth[*frame_ind] = MAX_ARF_LAYERS;
+      gf_group->arf_boost[*frame_ind] = NORMAL_BOOST;
       ++gf_group->pyramid_lvl_nodes[MIN_PYRAMID_LVL];
       ++(*frame_ind);
     }
@@ -61,11 +62,13 @@
     gf_group->frame_disp_idx[*frame_ind] = m;
     gf_group->pyramid_level[*frame_ind] = level;
     gf_group->layer_depth[*frame_ind] = layer_depth;
+    gf_group->arf_boost[*frame_ind] =
+        av1_calc_arf_boost(cpi, m, end - m, m - start);
     ++gf_group->pyramid_lvl_nodes[level];
     ++(*frame_ind);
 
     // Frames displayed before this internal ARF.
-    set_multi_layer_params(gf_group, start, m, frame_ind, 1, level - 1,
+    set_multi_layer_params(cpi, gf_group, start, m, frame_ind, 1, level - 1,
                            layer_depth + 1);
 
     // Overlay for internal ARF.
@@ -75,17 +78,18 @@
     gf_group->arf_update_idx[*frame_ind] = 1;
     gf_group->frame_disp_idx[*frame_ind] = m;
     gf_group->pyramid_level[*frame_ind] = MIN_PYRAMID_LVL;
+    gf_group->arf_boost[*frame_ind] = 0;
     gf_group->layer_depth[*frame_ind] = layer_depth;
     ++(*frame_ind);
 
     // Frames displayed after this internal ARF.
-    set_multi_layer_params(gf_group, m, end, frame_ind, arf_ind, level - 1,
+    set_multi_layer_params(cpi, gf_group, m, end, frame_ind, arf_ind, level - 1,
                            layer_depth + 1);
   }
 }
 
 static int construct_multi_layer_gf_structure(
-    GF_GROUP *const gf_group, int gf_interval, int pyr_height,
+    AV1_COMP *cpi, GF_GROUP *const gf_group, int gf_interval, int pyr_height,
     FRAME_UPDATE_TYPE first_frame_update_type) {
   gf_group->pyramid_height = pyr_height;
   av1_zero_array(gf_group->pyramid_lvl_nodes, MAX_PYRAMID_LVL);
@@ -116,6 +120,7 @@
     gf_group->frame_disp_idx[frame_index] = gf_interval;
     gf_group->pyramid_level[frame_index] = gf_group->pyramid_height;
     gf_group->layer_depth[frame_index] = 1;
+    gf_group->arf_boost[frame_index] = cpi->rc.gfu_boost;
     ++frame_index;
   }
 
@@ -123,8 +128,8 @@
   const int next_height =
       use_altref ? gf_group->pyramid_height - 1 : gf_group->pyramid_height;
   assert(next_height >= MIN_PYRAMID_LVL);
-  set_multi_layer_params(gf_group, 0, gf_interval, &frame_index, 0, next_height,
-                         use_altref + 1);
+  set_multi_layer_params(cpi, gf_group, 0, gf_interval, &frame_index, 0,
+                         next_height, use_altref + 1);
   return frame_index;
 }
 
@@ -318,7 +323,7 @@
       key_frame ? KF_UPDATE
                 : rc->source_alt_ref_active ? OVERLAY_UPDATE : GF_UPDATE;
   gf_group->size = construct_multi_layer_gf_structure(
-      gf_group, rc->baseline_gf_interval, get_pyramid_height(cpi),
+      cpi, gf_group, rc->baseline_gf_interval, get_pyramid_height(cpi),
       first_frame_update_type);
 
   set_gop_ref_frame_map(gf_group);
diff --git a/av1/encoder/gop_structure.h b/av1/encoder/gop_structure.h
index d9d5ae7..3a77396 100644
--- a/av1/encoder/gop_structure.h
+++ b/av1/encoder/gop_structure.h
@@ -22,6 +22,9 @@
 struct AV1_COMP;
 struct EncodeFrameParams;
 
+#define MIN_ARF_GF_BOOST 240
+#define NORMAL_BOOST 100
+
 // Set up the Group-Of-Pictures structure for this GF_GROUP.  This involves
 // deciding where to place the various FRAME_UPDATE_TYPEs in the group.  It does
 // this primarily by setting the contents of
@@ -29,6 +32,7 @@
 void av1_gop_setup_structure(
     struct AV1_COMP *cpi, const struct EncodeFrameParams *const frame_params);
 
+int av1_calc_arf_boost(AV1_COMP *cpi, int offset, int f_frames, int b_frames);
 #ifdef __cplusplus
 }  // extern "C"
 #endif
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index c85d919..8d229c3 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -418,11 +418,9 @@
 }
 
 #define GF_MAX_BOOST 90.0
-#define MIN_ARF_GF_BOOST 240
 #define MIN_DECAY_FACTOR 0.01
 
-static int calc_arf_boost(AV1_COMP *cpi, int offset, int f_frames,
-                          int b_frames) {
+int av1_calc_arf_boost(AV1_COMP *cpi, int offset, int f_frames, int b_frames) {
   TWO_PASS *const twopass = &cpi->twopass;
   int i;
   double boost_score = 0.0;
@@ -1092,12 +1090,13 @@
                                    : AOMMAX(0, rc->frames_to_key - i);
 
     // Calculate the boost for alt ref.
-    rc->gfu_boost = calc_arf_boost(cpi, alt_offset, forward_frames, (i - 1));
+    rc->gfu_boost =
+        av1_calc_arf_boost(cpi, alt_offset, forward_frames, (i - 1));
     rc->source_alt_ref_pending = 1;
   } else {
     reset_fpf_position(twopass, start_pos);
     rc->gfu_boost =
-        AOMMIN(MAX_GF_BOOST, calc_arf_boost(cpi, alt_offset, (i - 1), 0));
+        AOMMIN(MAX_GF_BOOST, av1_calc_arf_boost(cpi, alt_offset, (i - 1), 0));
     rc->source_alt_ref_pending = 0;
   }