Move members common to 1 and 2 pass from TWO_PASS struct

This is necessary to merge 1 and 2 pass paths and add pyramid
structure to 1 pass.

Change-Id: Iccd3811575bd3014d7034fd7515010dc24c09743
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 6378bc0..fe57bef 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -179,7 +179,7 @@
   // originally encoded.
   if (!cpi->common.show_existing_frame || cpi->rc.is_src_frame_alt_ref ||
       cpi->common.current_frame.frame_type == KEY_FRAME) {
-    ++cpi->twopass.gf_group.index;
+    ++cpi->gf_group.index;
   }
 }
 #endif
@@ -194,7 +194,7 @@
 
 // Get update type of the current frame.
 static INLINE FRAME_UPDATE_TYPE get_frame_update_type(const AV1_COMP *cpi) {
-  const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
+  const GF_GROUP *const gf_group = &cpi->gf_group;
   if (gf_group->size == 0) {
     // Special case 1: happens at the first frame of a video.
     return KF_UPDATE;
@@ -227,7 +227,7 @@
 // av1_get_second_pass_params().
 static void check_show_existing_frame(AV1_COMP *const cpi,
                                       EncodeFrameParams *const frame_params) {
-  const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
+  const GF_GROUP *const gf_group = &cpi->gf_group;
   assert(gf_group->index <= gf_group->size);
   AV1_COMMON *const cm = &cpi->common;
   if (cm->show_existing_frame == 1) {
@@ -500,7 +500,7 @@
   RATE_CONTROL *const rc = &cpi->rc;
   int arf_src_index = 0;
   if (cpi->oxcf.pass == 2) {
-    const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
+    const GF_GROUP *const gf_group = &cpi->gf_group;
     if (get_frame_update_type(cpi) == ARF_UPDATE) {
       assert(is_altref_enabled(cpi));
       arf_src_index = gf_group->arf_src_offset[gf_group->index];
@@ -516,7 +516,7 @@
 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;
+    const GF_GROUP *const gf_group = &cpi->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];
@@ -551,7 +551,7 @@
     // When arf_src_index == rc->frames_to_key, it indicates a fwd_kf
     if (!arf2 && arf_src_index == rc->frames_to_key) {
       // Skip temporal filtering and mark as intra_only if we have a fwd_kf
-      const int which_arf = get_arf_update_idx(&cpi->twopass.gf_group);
+      const int which_arf = get_arf_update_idx(&cpi->gf_group);
       cpi->is_arf_filter_off[which_arf] = 1;
       cpi->no_show_kf = 1;
     } else {
@@ -1146,8 +1146,7 @@
 
     frame_params.primary_ref_frame =
         choose_primary_ref_frame(cpi, &frame_params);
-    frame_params.order_offset =
-        get_order_offset(&cpi->twopass.gf_group, &frame_params);
+    frame_params.order_offset = get_order_offset(&cpi->gf_group, &frame_params);
 
     frame_params.refresh_frame_flags =
         get_refresh_frame_flags(cpi, &frame_params, frame_update_type);
@@ -1178,7 +1177,7 @@
     cm->min_qmlevel = cpi->oxcf.qm_minlevel;
     cm->max_qmlevel = cpi->oxcf.qm_maxlevel;
     if (oxcf->pass == 2) {
-      if (cpi->twopass.gf_group.index == 1 && cpi->oxcf.enable_tpl_model) {
+      if (cpi->gf_group.index == 1 && cpi->oxcf.enable_tpl_model) {
         av1_configure_buffer_updates(cpi, &frame_params, frame_update_type, 0);
         av1_set_frame_size(cpi, cm->width, cm->height);
         av1_tpl_setup_stats(cpi, &frame_input, 0);
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 331ce0f..4ac4b4d 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -3345,10 +3345,9 @@
 #if !CONFIG_REALTIME_ONLY
 static int get_rdmult_delta(AV1_COMP *cpi, BLOCK_SIZE bsize, int analysis_type,
                             int mi_row, int mi_col, int orig_rdmult) {
-  assert(IMPLIES(cpi->twopass.gf_group.size > 0,
-                 cpi->twopass.gf_group.index < cpi->twopass.gf_group.size));
-  const int tpl_idx =
-      cpi->twopass.gf_group.frame_disp_idx[cpi->twopass.gf_group.index];
+  assert(IMPLIES(cpi->gf_group.size > 0,
+                 cpi->gf_group.index < cpi->gf_group.size));
+  const int tpl_idx = cpi->gf_group.frame_disp_idx[cpi->gf_group.index];
   TplDepFrame *tpl_frame = &cpi->tpl_stats[tpl_idx];
   TplDepStats *tpl_stats = tpl_frame->tpl_stats_ptr;
   int tpl_stride = tpl_frame->stride;
@@ -3362,7 +3361,7 @@
 
   if (!is_frame_tpl_eligible(cpi)) return orig_rdmult;
 
-  if (cpi->twopass.gf_group.index >= MAX_LAG_BUFFERS) return orig_rdmult;
+  if (cpi->gf_group.index >= MAX_LAG_BUFFERS) return orig_rdmult;
 
   int64_t mc_count = 0, mc_saved = 0;
   int mi_count = 0;
@@ -3420,10 +3419,9 @@
                                       int analysis_type, int mi_row,
                                       int mi_col) {
   AV1_COMMON *const cm = &cpi->common;
-  assert(IMPLIES(cpi->twopass.gf_group.size > 0,
-                 cpi->twopass.gf_group.index < cpi->twopass.gf_group.size));
-  const int tpl_idx =
-      cpi->twopass.gf_group.frame_disp_idx[cpi->twopass.gf_group.index];
+  assert(IMPLIES(cpi->gf_group.size > 0,
+                 cpi->gf_group.index < cpi->gf_group.size));
+  const int tpl_idx = cpi->gf_group.frame_disp_idx[cpi->gf_group.index];
   TplDepFrame *tpl_frame = &cpi->tpl_stats[tpl_idx];
   TplDepStats *tpl_stats = tpl_frame->tpl_stats_ptr;
   int tpl_stride = tpl_frame->stride;
@@ -3442,7 +3440,7 @@
 
   if (!is_frame_tpl_eligible(cpi)) return cm->base_qindex;
 
-  if (cpi->twopass.gf_group.index >= MAX_LAG_BUFFERS) return cm->base_qindex;
+  if (cpi->gf_group.index >= MAX_LAG_BUFFERS) return cm->base_qindex;
 
   int64_t mc_count = 0, mc_saved = 0;
   int mi_count = 0;
@@ -3480,7 +3478,7 @@
   }
   offset = (7 * av1_get_deltaq_offset(cpi, cm->base_qindex, beta)) / 8;
   // printf("[%d/%d]: beta %g offset %d\n", pyr_lev_from_top,
-  //        cpi->twopass.gf_group.pyramid_height, beta, offset);
+  //        cpi->gf_group.pyramid_height, beta, offset);
 
   aom_clear_system_state();
 
@@ -3762,12 +3760,12 @@
     return;
   }
 
-  assert(IMPLIES(cpi->twopass.gf_group.size > 0,
-                 cpi->twopass.gf_group.index < cpi->twopass.gf_group.size));
-  const int gf_group_index = cpi->twopass.gf_group.index;
+  assert(IMPLIES(cpi->gf_group.size > 0,
+                 cpi->gf_group.index < cpi->gf_group.size));
+  const int gf_group_index = cpi->gf_group.index;
   if (cpi->oxcf.enable_tpl_model && cpi->oxcf.aq_mode == NO_AQ &&
       cpi->oxcf.deltaq_mode == NO_DELTA_Q && gf_group_index > 0 &&
-      cpi->twopass.gf_group.update_type[gf_group_index] == ARF_UPDATE) {
+      cpi->gf_group.update_type[gf_group_index] == ARF_UPDATE) {
     const int dr =
         get_rdmult_delta(cpi, sb_size, 0, mi_row, mi_col, orig_rdmult);
     x->rdmult = dr;
@@ -4862,7 +4860,7 @@
   av1_setup_frame_sign_bias(cm);
 
 #if CHECK_PRECOMPUTED_REF_FRAME_MAP
-  GF_GROUP *gf_group = &cpi->twopass.gf_group;
+  GF_GROUP *gf_group = &cpi->gf_group;
   // TODO(yuec): The check is disabled on OVERLAY frames for now, because info
   // in cpi->gf_group has been refreshed for the next GOP when the check is
   // performed for OVERLAY frames. Since we have not support inter-GOP ref
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 619e349..6d909e4 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3555,12 +3555,11 @@
 }
 
 static void process_tpl_stats_frame(AV1_COMP *cpi) {
+  const GF_GROUP *const gf_group = &cpi->gf_group;
   AV1_COMMON *const cm = &cpi->common;
 
-  assert(IMPLIES(cpi->twopass.gf_group.size > 0,
-                 cpi->twopass.gf_group.index < cpi->twopass.gf_group.size));
-  const int tpl_idx =
-      cpi->twopass.gf_group.frame_disp_idx[cpi->twopass.gf_group.index];
+  assert(IMPLIES(gf_group->size > 0, gf_group->index < gf_group->size));
+  const int tpl_idx = gf_group->frame_disp_idx[gf_group->index];
   TplDepFrame *tpl_frame = &cpi->tpl_stats[tpl_idx];
   TplDepStats *tpl_stats = tpl_frame->tpl_stats_ptr;
 
@@ -4685,11 +4684,11 @@
       "show_frame=%d, show_existing_frame=%d, source_alt_ref_active=%d, "
       "refresh_alt_ref_frame=%d, "
       "y_stride=%4d, uv_stride=%4d, cm->width=%4d, cm->height=%4d\n\n",
-      current_frame->frame_number, cpi->twopass.gf_group.index,
-      cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index],
-      current_frame->order_hint, cm->show_frame, cm->show_existing_frame,
-      cpi->rc.source_alt_ref_active, cpi->refresh_alt_ref_frame,
-      recon_buf->y_stride, recon_buf->uv_stride, cm->width, cm->height);
+      current_frame->frame_number, cpi->gf_group.index,
+      cpi->gf_group.update_type[cpi->gf_group.index], current_frame->order_hint,
+      cm->show_frame, cm->show_existing_frame, cpi->rc.source_alt_ref_active,
+      cpi->refresh_alt_ref_frame, recon_buf->y_stride, recon_buf->uv_stride,
+      cm->width, cm->height);
 #if 0
   int ref_frame;
   printf("get_ref_frame_map_idx: [");
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 7f4165c..0aa1bac 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -863,6 +863,8 @@
 
   TWO_PASS twopass;
 
+  GF_GROUP gf_group;
+
   YV12_BUFFER_CONFIG alt_ref_buffer;
 
 #if CONFIG_INTERNAL_STATS
@@ -1336,12 +1338,12 @@
 }
 
 static INLINE int is_frame_arf_and_tpl_eligible(AV1_COMP *const cpi) {
+  GF_GROUP *const gf_group = &cpi->gf_group;
   const int max_pyr_level_fromtop_deltaq = 0;
   const int pyr_lev_from_top =
-      cpi->twopass.gf_group.pyramid_height -
-      cpi->twopass.gf_group.pyramid_level[cpi->twopass.gf_group.index];
+      gf_group->pyramid_height - gf_group->pyramid_level[cpi->gf_group.index];
   if (pyr_lev_from_top > max_pyr_level_fromtop_deltaq ||
-      cpi->twopass.gf_group.pyramid_height <= max_pyr_level_fromtop_deltaq + 1)
+      gf_group->pyramid_height <= max_pyr_level_fromtop_deltaq + 1)
     return 0;
   else
     return 1;
diff --git a/av1/encoder/firstpass.h b/av1/encoder/firstpass.h
index 3fb4296..c23c60f 100644
--- a/av1/encoder/firstpass.h
+++ b/av1/encoder/firstpass.h
@@ -171,13 +171,9 @@
 
   int kf_zeromotion_pct;
   int last_kfgroup_zeromotion_pct;
-  int active_worst_quality;
-  int baseline_active_worst_quality;
   int extend_minq;
   int extend_maxq;
   int extend_minq_fast;
-
-  GF_GROUP gf_group;
 } TWO_PASS;
 
 struct AV1_COMP;
diff --git a/av1/encoder/gop_structure.c b/av1/encoder/gop_structure.c
index a1bc709..2432218 100644
--- a/av1/encoder/gop_structure.c
+++ b/av1/encoder/gop_structure.c
@@ -302,8 +302,7 @@
 void av1_gop_setup_structure(AV1_COMP *cpi,
                              const EncodeFrameParams *const frame_params) {
   RATE_CONTROL *const rc = &cpi->rc;
-  TWO_PASS *const twopass = &cpi->twopass;
-  GF_GROUP *const gf_group = &twopass->gf_group;
+  GF_GROUP *const gf_group = &cpi->gf_group;
   const int key_frame = (frame_params->frame_type == KEY_FRAME);
   const FRAME_UPDATE_TYPE first_frame_update_type =
       key_frame ? KF_UPDATE
diff --git a/av1/encoder/partition_strategy.h b/av1/encoder/partition_strategy.h
index aa8a9f6..810ee4c 100644
--- a/av1/encoder/partition_strategy.h
+++ b/av1/encoder/partition_strategy.h
@@ -192,16 +192,14 @@
 static INLINE int use_auto_max_partition(AV1_COMP *const cpi,
                                          BLOCK_SIZE sb_size, int mi_row,
                                          int mi_col) {
-  assert(IMPLIES(cpi->twopass.gf_group.size > 0,
-                 cpi->twopass.gf_group.index < cpi->twopass.gf_group.size));
+  assert(IMPLIES(cpi->gf_group.size > 0,
+                 cpi->gf_group.index < cpi->gf_group.size));
   AV1_COMMON *const cm = &cpi->common;
   return !frame_is_intra_only(cm) &&
          cpi->sf.auto_max_partition_based_on_simple_motion != NOT_IN_USE &&
          sb_size == BLOCK_128X128 && is_full_sb(cm, mi_row, mi_col, sb_size) &&
-         cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index] !=
-             OVERLAY_UPDATE &&
-         cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index] !=
-             INTNL_OVERLAY_UPDATE;
+         cpi->gf_group.update_type[cpi->gf_group.index] != OVERLAY_UPDATE &&
+         cpi->gf_group.update_type[cpi->gf_group.index] != INTNL_OVERLAY_UPDATE;
 }
 
 #endif  // AOM_AV1_ENCODER_PARTITION_STRATEGY_H_
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index 7d2e402..9919cb3 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -576,7 +576,7 @@
   RATE_CONTROL *const rc = &cpi->rc;
   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
   TWO_PASS *const twopass = &cpi->twopass;
-  GF_GROUP *const gf_group = &twopass->gf_group;
+  GF_GROUP *const gf_group = &cpi->gf_group;
   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;
@@ -732,7 +732,7 @@
 
 void av1_assign_q_and_bounds_q_mode(AV1_COMP *cpi) {
   AV1_COMMON *const cm = &cpi->common;
-  GF_GROUP *const gf_group = &cpi->twopass.gf_group;
+  GF_GROUP *const gf_group = &cpi->gf_group;
   const int width = cm->width;
   const int height = cm->height;
   RATE_CONTROL *const rc = &cpi->rc;
@@ -822,7 +822,7 @@
   // Reset the GF group data structures unless this is a key
   // frame in which case it will already have been done.
   if (!is_intra_only) {
-    av1_zero(twopass->gf_group);
+    av1_zero(cpi->gf_group);
   }
 
   aom_clear_system_state();
@@ -1157,8 +1157,7 @@
     tmp_q = get_twopass_worst_quality(
         cpi, group_av_err, (group_av_skip_pct + group_av_inactive_zone),
         vbr_group_bits_per_frame, twopass->kfgroup_inter_fraction * rc_factor);
-    twopass->active_worst_quality =
-        AOMMAX(tmp_q, twopass->active_worst_quality >> 1);
+    rc->active_worst_quality = AOMMAX(tmp_q, rc->active_worst_quality >> 1);
   }
 #endif
 
@@ -1337,7 +1336,7 @@
   int i, j;
   RATE_CONTROL *const rc = &cpi->rc;
   TWO_PASS *const twopass = &cpi->twopass;
-  GF_GROUP *const gf_group = &twopass->gf_group;
+  GF_GROUP *const gf_group = &cpi->gf_group;
   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
   const FIRSTPASS_STATS first_frame = *this_frame;
   const FIRSTPASS_STATS *const start_position = twopass->stats_in;
@@ -1614,7 +1613,7 @@
   CurrentFrame *const current_frame = &cm->current_frame;
   RATE_CONTROL *const rc = &cpi->rc;
   TWO_PASS *const twopass = &cpi->twopass;
-  GF_GROUP *const gf_group = &twopass->gf_group;
+  GF_GROUP *const gf_group = &cpi->gf_group;
   int frames_left;
   FIRSTPASS_STATS this_frame;
 
@@ -1656,7 +1655,7 @@
   aom_clear_system_state();
 
   if (cpi->oxcf.rc_mode == AOM_Q) {
-    twopass->active_worst_quality = cpi->oxcf.cq_level;
+    rc->active_worst_quality = cpi->oxcf.cq_level;
   } else if (current_frame->frame_number == 0) {
     // Special case code for first frame.
     const int section_target_bandwidth =
@@ -1673,8 +1672,7 @@
         cpi, section_error, section_intra_skip + section_inactive_zone,
         section_target_bandwidth, DEFAULT_GRP_WEIGHT);
 
-    twopass->active_worst_quality = tmp_q;
-    twopass->baseline_active_worst_quality = tmp_q;
+    rc->active_worst_quality = tmp_q;
     rc->ni_av_qi = tmp_q;
     rc->last_q[INTER_FRAME] = tmp_q;
     rc->avg_q = av1_convert_qindex_to_q(tmp_q, cm->seq_params.bit_depth);
@@ -1851,8 +1849,7 @@
 
   // If the rate control is drifting consider adjustment to min or maxq.
   if ((cpi->oxcf.rc_mode != AOM_Q) && !cpi->rc.is_src_frame_alt_ref) {
-    const int maxq_adj_limit =
-        rc->worst_quality - twopass->active_worst_quality;
+    const int maxq_adj_limit = rc->worst_quality - rc->active_worst_quality;
     const int minq_adj_limit =
         (cpi->oxcf.rc_mode == AOM_CQ ? MINQ_ADJ_LIMIT_CQ : MINQ_ADJ_LIMIT);
 
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index 4d93341..cfeb6aa 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -373,8 +373,7 @@
   if (cpi->common.current_frame.frame_type == KEY_FRAME) {
     rcf = rc->rate_correction_factors[KF_STD];
   } else if (cpi->oxcf.pass == 2) {
-    const RATE_FACTOR_LEVEL rf_lvl =
-        get_rate_factor_level(&cpi->twopass.gf_group);
+    const RATE_FACTOR_LEVEL rf_lvl = get_rate_factor_level(&cpi->gf_group);
     rcf = rc->rate_correction_factors[rf_lvl];
   } else {
     if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
@@ -400,8 +399,7 @@
   if (cpi->common.current_frame.frame_type == KEY_FRAME) {
     rc->rate_correction_factors[KF_STD] = factor;
   } else if (cpi->oxcf.pass == 2) {
-    const RATE_FACTOR_LEVEL rf_lvl =
-        get_rate_factor_level(&cpi->twopass.gf_group);
+    const RATE_FACTOR_LEVEL rf_lvl = get_rate_factor_level(&cpi->gf_group);
     rc->rate_correction_factors[rf_lvl] = factor;
   } else {
     if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
@@ -807,7 +805,7 @@
 }
 
 static int gf_group_pyramid_level(const AV1_COMP *cpi) {
-  const GF_GROUP *gf_group = &cpi->twopass.gf_group;
+  const GF_GROUP *gf_group = &cpi->gf_group;
   int this_height = gf_group->pyramid_level[gf_group->index];
   return this_height;
 }
@@ -995,8 +993,7 @@
 };
 
 int av1_frame_type_qdelta(const AV1_COMP *cpi, int q) {
-  const RATE_FACTOR_LEVEL rf_lvl =
-      get_rate_factor_level(&cpi->twopass.gf_group);
+  const RATE_FACTOR_LEVEL rf_lvl = get_rate_factor_level(&cpi->gf_group);
   const FRAME_TYPE frame_type = (rf_lvl == KF_STD) ? KEY_FRAME : INTER_FRAME;
   return av1_compute_qdelta_by_rate(&cpi->rc, frame_type, q,
                                     rate_factor_deltas[rf_lvl],
@@ -1212,12 +1209,12 @@
                                              int gf_index) {
   const AV1_COMMON *const cm = &cpi->common;
   const RATE_CONTROL *const rc = &cpi->rc;
-  const GF_GROUP *gf_group = &cpi->twopass.gf_group;
+  const GF_GROUP *gf_group = &cpi->gf_group;
   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
   const int cq_level = get_active_cq_level(rc, oxcf, frame_is_intra_only(cm),
                                            cm->superres_scale_denominator);
   int active_best_quality = 0;
-  int active_worst_quality = cpi->twopass.active_worst_quality;
+  int active_worst_quality = rc->active_worst_quality;
   int q;
   const int bit_depth = cm->seq_params.bit_depth;
 
@@ -1306,11 +1303,11 @@
   const AV1_COMMON *const cm = &cpi->common;
   const RATE_CONTROL *const rc = &cpi->rc;
   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
-  const GF_GROUP *gf_group = &cpi->twopass.gf_group;
+  const GF_GROUP *gf_group = &cpi->gf_group;
   const int cq_level = get_active_cq_level(rc, oxcf, frame_is_intra_only(cm),
                                            cm->superres_scale_denominator);
   int active_best_quality = 0;
-  int active_worst_quality = cpi->twopass.active_worst_quality;
+  int active_worst_quality = rc->active_worst_quality;
   int q;
   int *inter_minq;
   const int bit_depth = cm->seq_params.bit_depth;
@@ -1443,7 +1440,7 @@
   } else {
     assert(cpi->oxcf.pass == 2 && "invalid encode pass");
 
-    GF_GROUP *gf_group = &cpi->twopass.gf_group;
+    GF_GROUP *gf_group = &cpi->gf_group;
     int arf_q = -1;  // Initialize to invalid value, for sanity check later.
 
     q = rc_pick_q_and_bounds_two_pass(cpi, width, height, bottom_index,
@@ -1504,8 +1501,7 @@
 
 static void update_golden_frame_stats(AV1_COMP *cpi) {
   RATE_CONTROL *const rc = &cpi->rc;
-  const TWO_PASS *const twopass = &cpi->twopass;
-  const GF_GROUP *const gf_group = &twopass->gf_group;
+  const GF_GROUP *const gf_group = &cpi->gf_group;
   const int is_intrnl_arf =
       cpi->oxcf.pass == 2
           ? gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE
@@ -1526,7 +1522,7 @@
     // active flag. In multi arf group case, if the index is not 0 then
     // we are overlaying a mid group arf so should not reset the flag.
     if (cpi->oxcf.pass == 2) {
-      if (!rc->source_alt_ref_pending && (cpi->twopass.gf_group.index == 0))
+      if (!rc->source_alt_ref_pending && (cpi->gf_group.index == 0))
         rc->source_alt_ref_active = 0;
     } else if (!rc->source_alt_ref_pending) {
       rc->source_alt_ref_active = 0;
@@ -1540,8 +1536,7 @@
   const AV1_COMMON *const cm = &cpi->common;
   const CurrentFrame *const current_frame = &cm->current_frame;
   RATE_CONTROL *const rc = &cpi->rc;
-  const TWO_PASS *const twopass = &cpi->twopass;
-  const GF_GROUP *const gf_group = &twopass->gf_group;
+  const GF_GROUP *const gf_group = &cpi->gf_group;
   const int is_intrnl_arf =
       cpi->oxcf.pass == 2
           ? gf_group->update_type[gf_group->index] == INTNL_ARF_UPDATE
diff --git a/av1/encoder/ratectrl.h b/av1/encoder/ratectrl.h
index d67a401..3b3a8cd 100644
--- a/av1/encoder/ratectrl.h
+++ b/av1/encoder/ratectrl.h
@@ -142,6 +142,7 @@
   float_t arf_boost_factor;
   // Q index used for ALT frame
   int arf_q;
+  int active_worst_quality;
 } RATE_CONTROL;
 
 struct AV1_COMP;
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index e172507..e4a0c54 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -366,7 +366,7 @@
   int64_t rdmult = av1_compute_rd_mult_based_on_qindex(cpi, qindex);
   if (cpi->oxcf.pass == 2 &&
       (cpi->common.current_frame.frame_type != KEY_FRAME)) {
-    const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
+    const GF_GROUP *const gf_group = &cpi->gf_group;
     const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index];
     const int boost_index = AOMMIN(15, (cpi->rc.gfu_boost / 100));
 
@@ -415,7 +415,7 @@
 
   if (cpi->oxcf.pass == 2 &&
       (cpi->common.current_frame.frame_type != KEY_FRAME)) {
-    const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
+    const GF_GROUP *const gf_group = &cpi->gf_group;
     const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index];
     const int boost_index = AOMMIN(15, (cpi->rc.gfu_boost / 100));
 
diff --git a/av1/encoder/temporal_filter.c b/av1/encoder/temporal_filter.c
index 9135750..54127bc 100644
--- a/av1/encoder/temporal_filter.c
+++ b/av1/encoder/temporal_filter.c
@@ -1247,7 +1247,7 @@
   struct scale_factors sf;
 
   YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS] = { NULL };
-  const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
+  const GF_GROUP *const gf_group = &cpi->gf_group;
   int rdmult = 0;
 
   // Apply context specific adjustments to the arnr filter parameters.
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index 4bb5004..2461e80 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -108,7 +108,7 @@
                             TX_SIZE tx_size, YV12_BUFFER_CONFIG *ref_frame[],
                             uint8_t *predictor, TplDepStats *tpl_stats) {
   AV1_COMMON *cm = &cpi->common;
-  const GF_GROUP *gf_group = &cpi->twopass.gf_group;
+  const GF_GROUP *gf_group = &cpi->gf_group;
 
   const int bw = 4 << mi_size_wide_log2[bsize];
   const int bh = 4 << mi_size_high_log2[bsize];
@@ -264,7 +264,7 @@
   if (frame_idx) {
     const int idx = gf_group->ref_frame_gop_idx[frame_idx][best_rf_idx];
     tpl_stats->ref_frame_index = idx;
-    tpl_stats->ref_disp_frame_index = cpi->twopass.gf_group.frame_disp_idx[idx];
+    tpl_stats->ref_disp_frame_index = gf_group->frame_disp_idx[idx];
     tpl_stats->mv.as_int = best_mv.as_int;
   }
 }
@@ -416,7 +416,7 @@
   } else if (frame_idx == 1) {
     return frame_input ? frame_input->source : NULL;
   } else {
-    const GF_GROUP *gf_group = &cpi->twopass.gf_group;
+    const GF_GROUP *gf_group = &cpi->gf_group;
     const int frame_disp_idx = gf_group->frame_disp_idx[frame_idx];
     struct lookahead_entry *buf = av1_lookahead_peek(
         cpi->lookahead, frame_disp_idx - cpi->num_gf_group_show_frames);
@@ -426,7 +426,7 @@
 
 static void mc_flow_dispenser(AV1_COMP *cpi, YV12_BUFFER_CONFIG **gf_picture,
                               int frame_idx) {
-  const GF_GROUP *gf_group = &cpi->twopass.gf_group;
+  const GF_GROUP *gf_group = &cpi->gf_group;
   if (frame_idx == gf_group->size) return;
   int tpl_idx = gf_group->frame_disp_idx[frame_idx];
   TplDepFrame *tpl_frame = &cpi->tpl_stats[tpl_idx];
@@ -692,7 +692,7 @@
                          const EncodeFrameInput *const frame_input,
                          int is_for_kf) {
   YV12_BUFFER_CONFIG *gf_picture[MAX_LENGTH_TPL_FRAME_STATS];
-  GF_GROUP *gf_group = &cpi->twopass.gf_group;
+  GF_GROUP *gf_group = &cpi->gf_group;
 
   init_gop_frames_for_tpl(cpi, gf_picture, gf_group, &cpi->tpl_gf_group_frames,
                           frame_input, is_for_kf);
@@ -911,9 +911,9 @@
 #error "Invalid block size for tpl model"
 #endif  // MC_FLOW_BSIZE == 64
 
-  const GF_GROUP *gf_group = &cpi->twopass.gf_group;
+  const GF_GROUP *gf_group = &cpi->gf_group;
   assert(IMPLIES(gf_group->size > 0, gf_group->index < gf_group->size));
-  const int tpl_cur_idx = cpi->twopass.gf_group.frame_disp_idx[gf_group->index];
+  const int tpl_cur_idx = gf_group->frame_disp_idx[gf_group->index];
   TplDepFrame *tpl_frame = &cpi->tpl_stats[tpl_cur_idx];
   memset(
       tpl_frame->tpl_stats_ptr, 0,
@@ -921,7 +921,7 @@
   tpl_frame->is_valid = 0;
   int tpl_used_mask[MAX_LENGTH_TPL_FRAME_STATS] = { 0 };
   for (int idx = gf_group->index + 1; idx < cpi->tpl_gf_group_frames; ++idx) {
-    const int tpl_future_idx = cpi->twopass.gf_group.frame_disp_idx[idx];
+    const int tpl_future_idx = gf_group->frame_disp_idx[idx];
 
     if (gf_group->update_type[idx] == OVERLAY_UPDATE ||
         gf_group->update_type[idx] == INTNL_OVERLAY_UPDATE)
@@ -931,7 +931,7 @@
 
     for (int ridx = 0; ridx < INTER_REFS_PER_FRAME; ++ridx) {
       const int ref_idx = gf_group->ref_frame_gop_idx[idx][ridx];
-      const int tpl_ref_idx = cpi->twopass.gf_group.frame_disp_idx[ref_idx];
+      const int tpl_ref_idx = gf_group->frame_disp_idx[ref_idx];
       if (tpl_ref_idx == tpl_cur_idx) {
         // Do tpl stats computation between current buffer and the one at
         // gf_group index given by idx (and with disp index given by