Old structure misc cleanup.

- Remove cpi->num_ext_arfs
- Add size to GF_GROUP
- Rename 'extra ARF' to 'internal ARF' in various places, and related
cleanup.
- Remove unused arrays and macros.
- Remove stale comments.

BUG=aomedia:2346

Change-Id: Ia716c2195d4d7dc465e1e30389e8da30d0addf88
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index d65a4a7..e9d6ee7 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -40,7 +40,7 @@
   // cpi->rc.is_$Source_Type to make this function as it is in the comment?
 
   cpi->rc.is_src_frame_alt_ref = 0;
-  cpi->rc.is_src_frame_ext_arf = 0;
+  cpi->rc.is_src_frame_internal_arf = 0;
 
   switch (type) {
     case KF_UPDATE:
@@ -96,7 +96,7 @@
       frame_params->refresh_alt_ref_frame = 0;
 
       cpi->rc.is_src_frame_alt_ref = 1;
-      cpi->rc.is_src_frame_ext_arf = 1;
+      cpi->rc.is_src_frame_internal_arf = 1;
       break;
 
     case INTNL_ARF_UPDATE:
@@ -328,7 +328,7 @@
       cpi->ext_use_primary_ref_none)
     return REGULAR_FRAME;
   else if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE)
-    return EXT_ARF_FRAME;
+    return INTERNAL_ARF_FRAME;
   else if (frame_params->refresh_alt_ref_frame)
     return ARF_FRAME;
   else if (cpi->rc.is_src_frame_alt_ref)
@@ -456,37 +456,35 @@
   cpi->last_end_time_stamp_seen = source->ts_end;
 }
 
-// Returns 0 if this is not an alt ref else the offset of the source frame
-// used as the arf midpoint.
+// If this is an alt-ref, returns the offset of the source frame used
+// as the arf midpoint. Otherwise, returns 0.
 static int get_arf_src_index(AV1_COMP *cpi) {
   RATE_CONTROL *const rc = &cpi->rc;
   int arf_src_index = 0;
-  if (is_altref_enabled(cpi)) {
-    if (cpi->oxcf.pass == 2) {
-      const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-      if (gf_group->update_type[gf_group->index] == ARF_UPDATE) {
-        arf_src_index = gf_group->arf_src_offset[gf_group->index];
-      }
-    } else if (rc->source_alt_ref_pending) {
-      arf_src_index = rc->frames_till_gf_update_due;
+  if (cpi->oxcf.pass == 2) {
+    const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
+    if (gf_group->update_type[gf_group->index] == ARF_UPDATE) {
+      assert(is_altref_enabled(cpi));
+      arf_src_index = gf_group->arf_src_offset[gf_group->index];
     }
+  } else if (rc->source_alt_ref_pending) {
+    arf_src_index = rc->frames_till_gf_update_due;
   }
   return arf_src_index;
 }
 
-// Returns 0 if this is not an alt ref else the offset of the source frame
-// used as the arf midpoint.
-static int get_arf2_src_index(AV1_COMP *cpi) {
-  int arf2_src_index = 0;
-  if (is_altref_enabled(cpi) && cpi->num_extra_arfs) {
-    if (cpi->oxcf.pass == 2) {
-      const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
-      if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) {
-        arf2_src_index = gf_group->arf_src_offset[gf_group->index];
-      }
+// If this is an internal alt-ref, returns the offset of the source frame used
+// as the internal arf midpoint. Otherwise, returns 0.
+static int get_internal_arf_src_index(AV1_COMP *cpi) {
+  int internal_arf_src_index = 0;
+  if (cpi->oxcf.pass == 2) {
+    const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
+    if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) {
+      assert(is_altref_enabled(cpi) && cpi->internal_altref_allowed);
+      internal_arf_src_index = gf_group->arf_src_offset[gf_group->index];
     }
   }
-  return arf2_src_index;
+  return internal_arf_src_index;
 }
 
 // Called if this frame is an ARF or ARF2. Also handles forward-keyframes
@@ -549,7 +547,7 @@
   return 0;  // Never reached
 }
 
-// Check if we should encode an ARF, ARF2 or BRF.  If not, try a LAST
+// Check if we should encode an ARF or internal ARF.  If not, try a LAST
 // Do some setup associated with the chosen source
 // temporal_filtered, flush, and frame_update_type are outputs.
 // Return the frame source, or NULL if we couldn't find one
@@ -575,8 +573,8 @@
     *frame_update_type = ARF_UPDATE;
   }
 
-  // Should we encode an arf2 frame (mutually exclusive to ARF)
-  arf_src_index = get_arf2_src_index(cpi);
+  // Should we encode an internal Alt-ref frame (mutually exclusive to ARF)
+  arf_src_index = get_internal_arf_src_index(cpi);
   if (arf_src_index &&
       is_forced_keyframe_pending(cpi->lookahead, arf_src_index)) {
     arf_src_index = 0;
@@ -753,7 +751,7 @@
     return;
   }
 
-  // Initialise the new reference map as a copy of the old one.
+  // Initialize the new reference map as a copy of the old one.
   int new_map[REF_FRAMES];
   memcpy(new_map, cm->remapped_ref_idx, sizeof(new_map));
 
@@ -770,30 +768,18 @@
   //   then point the LAST_FRAME reference at it.  The old LAST_FRAME becomes
   //   LAST2_FRAME and the old LAST2_FRAME becomes LAST3_FRAME.  The old
   //   LAST3_FRAME is re-used somewhere else.
-  // * With the old, flat, GOP structure (cpi->new_bwdref_update_rule == 0):
-  //   * When we code an internal-ARF or BRF it just refreshes the ALTREF2 or
-  //     BWDREF buffer respectively and we don't reassign anything.
-  //   * When we code an INTNL_OVERLAY we refresh the ALTREF2 buffer which then
-  //     gets pushed into the last-frame FIFO.  LAST3 gets pushed out of the
-  //     last-frame FIFO and becomes the new ALTREF2 for later use.
-  //   * Every LAST_BIPRED is followed by a show_existing_frame of the following
-  //     BWDREF.  The show_existing doesn't update the ref-map so the
-  //     LAST_BIPRED updates the ref-map for both the LAST_BIPRED (which just
-  //     acts like a LAST_FRAME) and for the BWDREF (which pushes the BWDREF
-  //     into the last-frame FIFO).
-  // * With the new, pyramid, GOP structure (cpi->new_bwdref_update_rule == 1):
-  //   * BWDREF, ALTREF2, and EXTREF act like a stack structure, so we can
-  //     "push" and "pop" internal alt-ref frames through the three references.
-  //   * When we code a BRF or internal-ARF (they work the same in this
-  //     structure) we push it onto the bwdref stack.  Because we have a finite
-  //     number of buffers, we actually refresh EXTREF, the bottom of the stack,
-  //     and rotate the three references to make EXTREF the top.
-  //   * When we code an INTNL_OVERLAY we refresh BWDREF, then pop it off of the
-  //     bwdref stack and push it into the last-frame FIFO.  The old LAST3
-  //     buffer gets pushed out of the last-frame FIFO and becomes the new
-  //     EXTREF, bottom of the bwdref stack.
-  //   * LAST_BIPRED just acts like a LAST_FRAME.  The BWDREF will have an
-  //     INTNL_OVERLAY and so can do its own ref map update.
+  // * BWDREF, ALTREF2, and EXTREF act like a stack structure, so we can
+  //   "push" and "pop" internal alt-ref frames through the three references.
+  // * When we code a BRF or internal-ARF (they work the same in this
+  //   structure) we push it onto the bwdref stack.  Because we have a finite
+  //   number of buffers, we actually refresh EXTREF, the bottom of the stack,
+  //   and rotate the three references to make EXTREF the top.
+  // * When we code an INTNL_OVERLAY we refresh BWDREF, then pop it off of the
+  //   bwdref stack and push it into the last-frame FIFO.  The old LAST3
+  //   buffer gets pushed out of the last-frame FIFO and becomes the new
+  //   EXTREF, bottom of the bwdref stack.
+  // * LAST_BIPRED just acts like a LAST_FRAME.  The BWDREF will have an
+  //   INTNL_OVERLAY and so can do its own ref map update.
   //
   // Note that this function runs *after* a frame has been coded, so it does not
   // affect reference assignment of the current frame, it only affects future
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 449d418..6c0278e 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -4916,7 +4916,7 @@
   if (frame_is_intra_only(&cpi->common)) {
     return INTRA_FRAME;
   } else if ((cpi->rc.is_src_frame_alt_ref && cpi->refresh_golden_frame) ||
-             cpi->rc.is_src_frame_ext_arf) {
+             cpi->rc.is_src_frame_internal_arf) {
     // We will not update the golden frame with an internal overlay frame
     return ALTREF_FRAME;
   } else if (cpi->refresh_golden_frame || cpi->refresh_alt2_ref_frame ||
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 483fb5a..e971271 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -65,18 +65,12 @@
 } CODING_CONTEXT;
 
 enum {
-  // regular inter frame
-  REGULAR_FRAME = 0,
-  // alternate reference frame
-  ARF_FRAME = 1,
-  // overlay frame
-  OVERLAY_FRAME = 2,
-  // golden frame
-  GLD_FRAME = 3,
-  // backward reference frame
-  BRF_FRAME = 4,
-  // extra alternate reference frame
-  EXT_ARF_FRAME = 5,
+  REGULAR_FRAME,       // regular inter frame
+  ARF_FRAME,           // alternate reference frame
+  OVERLAY_FRAME,       // overlay frame
+  GLD_FRAME,           // golden frame
+  BRF_FRAME,           // backward reference frame
+  INTERNAL_ARF_FRAME,  // internal alternate reference frame
   FRAME_CONTEXT_INDEXES
 } UENUM1BYTE(FRAME_CONTEXT_INDEX);
 
@@ -714,6 +708,9 @@
 }
 #endif
 
+// The maximum number of internal ARFs except ALTREF_FRAME
+#define MAX_INTERNAL_ARFS (REF_FRAMES - BWDREF_FRAME - 1)
+
 typedef struct AV1_COMP {
   QUANTS quants;
   ThreadData td;
@@ -940,12 +937,9 @@
   AVxWorker *workers;
   struct EncWorkerData *tile_thr_data;
   int existing_fb_idx_to_show;
-  int is_arf_filter_off[MAX_EXT_ARFS + 1];
-  int num_extra_arfs;
-  int arf_pos_in_gf[MAX_EXT_ARFS + 1];
-  int arf_pos_for_ovrly[MAX_EXT_ARFS + 1];
+  int is_arf_filter_off[MAX_INTERNAL_ARFS + 1];
   int global_motion_search_done;
-  int extra_arf_allowed;
+  int internal_altref_allowed;
   // A flag to indicate if intrabc is ever used in current frame.
   int intrabc_used;
   int dv_cost[2][MV_VALS];
diff --git a/av1/encoder/firstpass.h b/av1/encoder/firstpass.h
index b8f2501..e898314 100644
--- a/av1/encoder/firstpass.h
+++ b/av1/encoder/firstpass.h
@@ -23,15 +23,6 @@
 
 #define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x)-0.000001 : (x) + 0.000001)
 
-// Length of the bi-predictive frame group (BFG)
-// NOTE: Currently each BFG contains one backward ref (BWF) frame plus a certain
-//       number of bi-predictive frames.
-#define BFG_INTERVAL 2
-// The maximum number of extra ALTREF's except ALTREF_FRAME
-#define MAX_EXT_ARFS (REF_FRAMES - BWDREF_FRAME - 1)
-
-#define MIN_EXT_ARF_INTERVAL 4
-
 #define MIN_ZERO_MOTION 0.95
 #define MAX_SR_CODED_ERROR 40
 #define MAX_RAW_ERR_VAR 2000
@@ -95,6 +86,7 @@
   unsigned char pyramid_height;
   unsigned char pyramid_lvl_nodes[MAX_PYRAMID_LVL];
   int bit_allocation[MAX_STATIC_GF_GROUP_LENGTH + 1];
+  int size;
 } GF_GROUP;
 
 typedef struct {
@@ -149,25 +141,6 @@
 
 void av1_twopass_zero_stats(FIRSTPASS_STATS *section);
 
-static INLINE int get_number_of_extra_arfs(int interval, int arf_pending,
-                                           int max_pyr_height) {
-  // Max extra (internal) alt-refs allowed based on interval.
-  int extra_arfs_from_interval = 0;
-  if (arf_pending && MAX_EXT_ARFS > 0) {
-    extra_arfs_from_interval =
-        (interval >= MIN_EXT_ARF_INTERVAL * (MAX_EXT_ARFS + 1))
-            ? MAX_EXT_ARFS
-            : (interval >= MIN_EXT_ARF_INTERVAL * MAX_EXT_ARFS)
-                  ? MAX_EXT_ARFS - 1
-                  : 0;
-  }
-  // Max extra (internal) alt-refs allowed based on max pyramid height.
-  const int ext_arfs_from_max_height = AOMMAX(max_pyr_height - 1, 0);
-
-  // Finally, min of the two above is our actual max allowance.
-  return AOMMIN(extra_arfs_from_interval, ext_arfs_from_max_height);
-}
-
 #ifdef __cplusplus
 }  // extern "C"
 #endif
diff --git a/av1/encoder/gop_structure.c b/av1/encoder/gop_structure.c
index 32155df..73cb0ed 100644
--- a/av1/encoder/gop_structure.c
+++ b/av1/encoder/gop_structure.c
@@ -116,8 +116,7 @@
 
 #define CHECK_GF_PARAMETER 0
 #if CHECK_GF_PARAMETER
-void check_frame_params(GF_GROUP *const gf_group, int gf_interval,
-                        int frame_nums) {
+void check_frame_params(GF_GROUP *const gf_group, int gf_interval) {
   static const char *update_type_strings[FRAME_UPDATE_TYPES] = {
     "KF_UPDATE",       "LF_UPDATE",      "GF_UPDATE",
     "ARF_UPDATE",      "OVERLAY_UPDATE", "INTNL_OVERLAY_UPDATE",
@@ -126,7 +125,7 @@
   FILE *fid = fopen("GF_PARAMS.txt", "a");
 
   fprintf(fid, "\ngf_interval = {%d}\n", gf_interval);
-  for (int i = 0; i <= frame_nums; ++i) {
+  for (int i = 0; i <= gf_group->size; ++i) {
     fprintf(fid, "#%2d : %s %d %d %d %d\n", i,
             update_type_strings[gf_group->update_type[i]],
             gf_group->arf_src_offset[i], gf_group->arf_pos_in_gf[i],
@@ -158,7 +157,7 @@
     return MIN_PYRAMID_LVL;
   }
   assert(cpi->oxcf.gf_max_pyr_height > MIN_PYRAMID_LVL);
-  if (!cpi->extra_arf_allowed) {
+  if (!cpi->internal_altref_allowed) {
     assert(MIN_PYRAMID_LVL + 1 <= cpi->oxcf.gf_max_pyr_height);
     return MIN_PYRAMID_LVL + 1;
   }
@@ -175,27 +174,19 @@
   const FRAME_UPDATE_TYPE first_frame_update_type =
       key_frame ? KF_UPDATE
                 : rc->source_alt_ref_active ? OVERLAY_UPDATE : GF_UPDATE;
-  const int gf_update_frames = construct_multi_layer_gf_structure(
+  gf_group->size = construct_multi_layer_gf_structure(
       gf_group, rc->baseline_gf_interval, get_pyramid_height(cpi),
       first_frame_update_type);
 
-  // Count extra arfs.
-  cpi->num_extra_arfs = 0;
-  for (int frame_index = 0; frame_index < gf_update_frames; ++frame_index) {
-    if (gf_group->update_type[frame_index] == INTNL_ARF_UPDATE) {
-      ++cpi->num_extra_arfs;
-    }
-  }
-
   // We need to configure the frame at the end of the sequence + 1 that
   // will be the start frame for the next group. Otherwise prior to the
   // call to av1_get_second_pass_params(), the data will be undefined.
-  gf_group->update_type[gf_update_frames] =
+  gf_group->update_type[gf_group->size] =
       (rc->source_alt_ref_pending) ? OVERLAY_UPDATE : GF_UPDATE;
-  gf_group->arf_update_idx[gf_update_frames] = 0;
-  gf_group->arf_pos_in_gf[gf_update_frames] = 0;
+  gf_group->arf_update_idx[gf_group->size] = 0;
+  gf_group->arf_pos_in_gf[gf_group->size] = 0;
 
 #if CHECK_GF_PARAMETER
-  check_frame_params(gf_group, rc->baseline_gf_interval, gf_update_frames);
+  check_frame_params(gf_group, rc->baseline_gf_interval);
 #endif
 }
diff --git a/av1/encoder/gop_structure.h b/av1/encoder/gop_structure.h
index 79be636..d9d5ae7 100644
--- a/av1/encoder/gop_structure.h
+++ b/av1/encoder/gop_structure.h
@@ -23,9 +23,9 @@
 struct EncodeFrameParams;
 
 // Set up the Group-Of-Pictures structure for this GF_GROUP.  This involves
-// deciding where to place the various FRAME_UPDATE_TYPEs (e.g. ARF, BRF,
-// OVERLAY, LAST) in the group.  It does this primarily by setting the contents
-// of cpi->twopass.gf_group.update_type[].
+// deciding where to place the various FRAME_UPDATE_TYPEs in the group.  It does
+// this primarily by setting the contents of
+// cpi->twopass.gf_group.update_type[].
 void av1_gop_setup_structure(
     struct AV1_COMP *cpi, const struct EncodeFrameParams *const frame_params);
 
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index 0cbb60c..bdcd20a 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -576,18 +576,23 @@
   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
   TWO_PASS *const twopass = &cpi->twopass;
   GF_GROUP *const gf_group = &twopass->gf_group;
-  int i;
-  int frame_index = 0;
-  const int key_frame = frame_params->frame_type == KEY_FRAME;
+  const int key_frame = (frame_params->frame_type == KEY_FRAME);
   const int max_bits = frame_max_bits(&cpi->rc, &cpi->oxcf);
   int64_t total_group_bits = gf_group_bits;
-  int ext_arf_boost[MAX_EXT_ARFS];
 
-  av1_zero_array(ext_arf_boost, MAX_EXT_ARFS);
+  // Check if GF group has any internal arfs.
+  int has_internal_arfs = 0;
+  for (int i = 0; i < gf_group->size; ++i) {
+    if (gf_group->update_type[i] == INTNL_ARF_UPDATE) {
+      has_internal_arfs = 1;
+      break;
+    }
+  }
 
   // For key frames the frame target rate is already set and it
   // is also the golden frame.
   // === [frame_index == 0] ===
+  int frame_index = 0;
   if (!key_frame) {
     if (rc->source_alt_ref_active)
       gf_group->bit_allocation[frame_index] = 0;
@@ -612,11 +617,12 @@
 
     ++frame_index;
 
-    // Skip all the extra-ARF's right after ARF at the starting segment of
+    // Skip all the internal ARFs right after ARF at the starting segment of
     // the current GF group.
-    if (cpi->num_extra_arfs) {
-      while (gf_group->update_type[frame_index] == INTNL_ARF_UPDATE)
+    if (has_internal_arfs) {
+      while (gf_group->update_type[frame_index] == INTNL_ARF_UPDATE) {
         ++frame_index;
+      }
     }
   }
 
@@ -628,7 +634,7 @@
   // overlay frame or golden frame.
   const int normal_frames = rc->baseline_gf_interval - 1;
 
-  for (i = 0; i < normal_frames; ++i) {
+  for (int i = 0; i < normal_frames; ++i) {
     FIRSTPASS_STATS frame_stats;
     if (EOF == input_stats(twopass, &frame_stats)) break;
 
@@ -653,7 +659,7 @@
     } else {
       assert(gf_group->update_type[frame_index] == LF_UPDATE);
       gf_group->bit_allocation[frame_index] = target_frame_size;
-      if (cpi->num_extra_arfs > 0) {
+      if (has_internal_arfs) {
         const int this_budget_reduction =
             (int)(target_frame_size * LEAF_REDUCTION_FACTOR);
         gf_group->bit_allocation[frame_index] -= this_budget_reduction;
@@ -663,20 +669,20 @@
 
     ++frame_index;
 
-    // Skip all the extra-ARF's.
-    if (cpi->num_extra_arfs) {
+    // Skip all the internal ARFs.
+    if (has_internal_arfs) {
       while (gf_group->update_type[frame_index] == INTNL_ARF_UPDATE)
         ++frame_index;
     }
   }
 
   if (budget_reduced_from_leaf_level > 0) {
-    assert(cpi->num_extra_arfs > 0);
+    assert(has_internal_arfs);
     // Restore.
     frame_index = tmp_frame_index;
 
     // Re-distribute this extra budget to overlay frames in the group.
-    for (i = 0; i < normal_frames; ++i) {
+    for (int i = 0; i < normal_frames; ++i) {
       if (gf_group->update_type[frame_index] == INTNL_OVERLAY_UPDATE) {
         assert(gf_group->pyramid_height <= MAX_PYRAMID_LVL &&
                "non-valid height for a pyramid structure");
@@ -692,10 +698,11 @@
       }
       ++frame_index;
 
-      // Skip all the extra-ARF's.
-      if (cpi->num_extra_arfs) {
-        while (gf_group->update_type[frame_index] == INTNL_ARF_UPDATE)
+      // Skip all the internal ARFs.
+      if (has_internal_arfs) {
+        while (gf_group->update_type[frame_index] == INTNL_ARF_UPDATE) {
           ++frame_index;
+        }
       }
     }
   }
@@ -766,7 +773,7 @@
                             frame_params->frame_type == INTRA_ONLY_FRAME;
   const int arf_active_or_kf = is_intra_only || rc->source_alt_ref_active;
 
-  cpi->extra_arf_allowed = (oxcf->gf_max_pyr_height > 1);
+  cpi->internal_altref_allowed = (oxcf->gf_max_pyr_height > 1);
 
   // Reset the GF group data structures unless this is a key
   // frame in which case it will already have been done.
@@ -893,17 +900,16 @@
 
   if (non_zero_stdev_count) avg_raw_err_stdev /= non_zero_stdev_count;
 
-  // Disable extra altrefs and backward refs for "still" gf group:
+  // Disable internal ARFs for "still" gf groups.
   //   zero_motion_accumulator: minimum percentage of (0,0) motion;
   //   avg_sr_coded_error:      average of the SSE per pixel of each frame;
   //   avg_raw_err_stdev:       average of the standard deviation of (0,0)
   //                            motion error per block of each frame.
-  const int disable_bwd_extarf =
-      (zero_motion_accumulator > MIN_ZERO_MOTION &&
-       avg_sr_coded_error / num_mbs < MAX_SR_CODED_ERROR &&
-       avg_raw_err_stdev < MAX_RAW_ERR_VAR);
-
-  if (disable_bwd_extarf) cpi->extra_arf_allowed = 0;
+  if (zero_motion_accumulator > MIN_ZERO_MOTION &&
+      avg_sr_coded_error / num_mbs < MAX_SR_CODED_ERROR &&
+      avg_raw_err_stdev < MAX_RAW_ERR_VAR) {
+    cpi->internal_altref_allowed = 0;
+  }
 
   const int use_alt_ref =
       !is_almost_static(zero_motion_accumulator, twopass->kf_zeromotion_pct) &&
@@ -919,7 +925,7 @@
   // work well for certain other cases.
   const int allow_gf_length_reduction =
       ((cpi->oxcf.rc_mode == AOM_Q && cpi->oxcf.cq_level <= 128) ||
-       cpi->extra_arf_allowed == 0) &&
+       !cpi->internal_altref_allowed) &&
       !is_lossless_requested(&cpi->oxcf);
 
   if (allow_gf_length_reduction && use_alt_ref) {
@@ -998,23 +1004,6 @@
     }
   }
 
-  if (!cpi->extra_arf_allowed) {
-    cpi->num_extra_arfs = 0;
-  } else {
-    // Calculate 'num_extra_arfs' (internal alt-refs) that we are allowed.
-    // Note: When new pyramid structure is used through
-    // 'define_pyramid_gf_group_structure()' function, this value is
-    // overridden.
-    if (rc->baseline_gf_interval == MIN_GF_INTERVAL &&
-        rc->source_alt_ref_pending) {
-      cpi->num_extra_arfs = 1;
-    } else {
-      cpi->num_extra_arfs = get_number_of_extra_arfs(rc->baseline_gf_interval,
-                                                     rc->source_alt_ref_pending,
-                                                     oxcf->gf_max_pyr_height);
-    }
-  }
-
   rc->frames_till_gf_update_due = rc->baseline_gf_interval;
 
   // Reset the file position.
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index b149991..861c737 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -1340,7 +1340,7 @@
   //                   updated and cpi->refresh_golden_frame will still be zero.
   if (cpi->refresh_golden_frame || rc->is_src_frame_alt_ref) {
     // We will not use internal overlay frames to replace the golden frame
-    if (!rc->is_src_frame_ext_arf) {
+    if (!rc->is_src_frame_internal_arf) {
       // this frame refreshes means next frames don't unless specified by user
       rc->frames_since_golden = 0;
     }
diff --git a/av1/encoder/ratectrl.h b/av1/encoder/ratectrl.h
index 2cf0ea8..1cd5994 100644
--- a/av1/encoder/ratectrl.h
+++ b/av1/encoder/ratectrl.h
@@ -89,7 +89,7 @@
   int source_alt_ref_pending;
   int source_alt_ref_active;
   int is_src_frame_alt_ref;
-  int is_src_frame_ext_arf;
+  int is_src_frame_internal_arf;
   int sframe_due;
 
   int avg_frame_bandwidth;  // Average frame size target for clip
diff --git a/av1/encoder/temporal_filter.c b/av1/encoder/temporal_filter.c
index 5f22ce7..ba883d7 100644
--- a/av1/encoder/temporal_filter.c
+++ b/av1/encoder/temporal_filter.c
@@ -1253,9 +1253,8 @@
   // Apply context specific adjustments to the arnr filter parameters.
   if (gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE) {
     // TODO(weitinglin): Currently, we enforce the filtering strength on
-    //                   extra ARFs' to be zeros. We should investigate in which
-    //                   case it is more beneficial to use non-zero strength
-    //                   filtering.
+    // internal ARFs to be zeros. We should investigate in which case it is more
+    // beneficial to use non-zero strength filtering.
     strength = 0;
     frames_to_blur = 1;
   } else {