Create function for checks related to first pass

Moved  the check for first pass into a inline
function is_stat_generation_stage()

Change-Id: Ic0d34c7654840ff8f5dfbaf7153fe90af9ac9dd7
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 4b5a68c..5d5c89e 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -104,7 +104,7 @@
   }
 
   if (cpi->ext_refresh_frame_flags_pending &&
-      (cpi->oxcf.pass == 0 || cpi->oxcf.pass == 2)) {
+      (!is_stat_generation_stage(cpi))) {
     frame_params->refresh_last_frame = cpi->ext_refresh_last_frame;
     frame_params->refresh_golden_frame = cpi->ext_refresh_golden_frame;
     frame_params->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame;
@@ -974,7 +974,7 @@
     *temporal_filtered = 1;
   }
 
-  if (oxcf->lag_in_frames > 0 && oxcf->pass != 1 &&
+  if (oxcf->lag_in_frames > 0 && !is_stat_generation_stage(cpi) &&
       frame_params->frame_type == KEY_FRAME && frame_params->show_frame) {
     av1_configure_buffer_updates(cpi, frame_params, KEY_FRAME, 0);
     av1_set_frame_size(cpi, cm->width, cm->height);
@@ -1124,7 +1124,7 @@
   if (oxcf->pass == 0 && oxcf->rc_mode != AOM_Q)
     cpi->oxcf.gf_max_pyr_height = USE_ALTREF_FOR_ONE_PASS;
 
-  if (oxcf->pass == 0 || oxcf->pass == 2) {
+  if (!is_stat_generation_stage(cpi)) {
     // If this is a forward keyframe, mark as a show_existing_frame
     if (cpi->oxcf.fwd_kf_enabled && (gf_group->index == gf_group->size) &&
         gf_group->update_type[1] == ARF_UPDATE && cpi->rc.frames_to_key == 0) {
@@ -1208,7 +1208,7 @@
 #else
   if (oxcf->pass == 0 && oxcf->mode == REALTIME && oxcf->lag_in_frames == 0)
     av1_get_one_pass_rt_params(cpi, &frame_params, *frame_flags);
-  else if (oxcf->pass != 1)
+  else if (!is_stat_generation_stage(cpi))
     av1_get_second_pass_params(cpi, &frame_params, *frame_flags);
 #endif
   FRAME_UPDATE_TYPE frame_update_type = get_frame_update_type(gf_group);
@@ -1233,7 +1233,7 @@
   // Work out some encoding parameters specific to the pass:
   if (cpi->oxcf.pass == 0 && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
     av1_cyclic_refresh_update_parameters(cpi);
-  } else if (oxcf->pass == 1) {
+  } else if (is_stat_generation_stage(cpi)) {
     cpi->td.mb.e_mbd.lossless[0] = is_lossless_requested(&cpi->oxcf);
     const int kf_requested = (cm->current_frame.frame_number == 0 ||
                               (*frame_flags & FRAMEFLAGS_KEY));
@@ -1253,7 +1253,7 @@
 #endif
   }
 
-  if (oxcf->pass == 0 || oxcf->pass == 2) set_ext_overrides(cpi, &frame_params);
+  if (!is_stat_generation_stage(cpi)) set_ext_overrides(cpi, &frame_params);
 
   // Shown keyframes and S frames refresh all reference buffers
   const int force_refresh_all =
@@ -1264,7 +1264,7 @@
   av1_configure_buffer_updates(cpi, &frame_params, frame_update_type,
                                force_refresh_all);
 
-  if (oxcf->pass == 0 || oxcf->pass == 2) {
+  if (!is_stat_generation_stage(cpi)) {
     if (!cpi->ext_refresh_frame_flags_pending) {
       av1_get_ref_frames(cpi, &cpi->ref_buffer_stack);
     } else if (cpi->svc.external_ref_frame_config) {
@@ -1308,7 +1308,7 @@
     cm->min_qmlevel = cpi->oxcf.qm_minlevel;
     cm->max_qmlevel = cpi->oxcf.qm_maxlevel;
 #if !CONFIG_REALTIME_ONLY
-    if (oxcf->lag_in_frames > 0 && oxcf->pass != 1) {
+    if (oxcf->lag_in_frames > 0 && !is_stat_generation_stage(cpi)) {
       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);
@@ -1332,9 +1332,10 @@
     return AOM_CODEC_ERROR;
   }
 #endif  // CONFIG_REALTIME_ONLY
-  if (oxcf->pass != 1) cpi->num_gf_group_show_frames += frame_params.show_frame;
+  if (!is_stat_generation_stage(cpi))
+    cpi->num_gf_group_show_frames += frame_params.show_frame;
 
-  if (oxcf->pass == 0 || oxcf->pass == 2) {
+  if (!is_stat_generation_stage(cpi)) {
     // First pass doesn't modify reference buffer assignment or produce frame
     // flags
     update_frame_flags(cpi, frame_flags);
@@ -1347,7 +1348,7 @@
   }
 
 #if !CONFIG_REALTIME_ONLY
-  if (oxcf->pass != 1) {
+  if (!is_stat_generation_stage(cpi)) {
 #if TXCOEFF_COST_TIMER
     cm->cum_txcoeff_cost_timer += cm->txcoeff_cost_timer;
     fprintf(stderr,
@@ -1360,7 +1361,7 @@
   }
 #endif  // !CONFIG_REALTIME_ONLY
 
-  if (oxcf->pass != 1) {
+  if (!is_stat_generation_stage(cpi)) {
     update_fb_of_context_type(cpi, &frame_params, cpi->fb_of_context_type);
     set_additional_frame_flags(cm, frame_flags);
     update_rc_counts(cpi);
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 4a02ea1..aa05d8d 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -5092,7 +5092,7 @@
 
   cm->allow_intrabc &= (cpi->oxcf.enable_intrabc);
 
-  if (cpi->oxcf.pass != 1 && av1_use_hash_me(cpi) &&
+  if (!is_stat_generation_stage(cpi) && av1_use_hash_me(cpi) &&
       !cpi->sf.use_nonrd_pick_mode) {
     // add to hash table
     const int pic_width = cpi->source->y_crop_width;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index a69c22d..37d14a4 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -2959,7 +2959,7 @@
 #endif
 
 #if !CONFIG_REALTIME_ONLY
-  if (oxcf->pass == 1) {
+  if (is_stat_generation_stage(cpi)) {
     av1_init_first_pass(cpi);
   } else if (oxcf->pass == 2) {
     const size_t packet_sz = sizeof(FIRSTPASS_STATS);
@@ -3312,7 +3312,7 @@
 
   if (cm->current_frame.frame_number > 0) {
 #if CONFIG_ENTROPY_STATS
-    if (cpi->oxcf.pass != 1) {
+    if (!is_stat_generation_stage(cpi)) {
       fprintf(stderr, "Writing counts.stt\n");
       FILE *f = fopen("counts.stt", "wb");
       fwrite(&aggregate_fc, sizeof(aggregate_fc), 1, f);
@@ -3322,7 +3322,7 @@
 #if CONFIG_INTERNAL_STATS
     aom_clear_system_state();
 
-    if (cpi->oxcf.pass != 1) {
+    if (!is_stat_generation_stage(cpi)) {
       char headings[512] = { 0 };
       char results[512] = { 0 };
       FILE *f = fopen("opsnr.stt", "a");
@@ -3393,13 +3393,13 @@
     }
 #endif  // CONFIG_INTERNAL_STATS
 #if CONFIG_SPEED_STATS
-    if (cpi->oxcf.pass != 1) {
+    if (!is_stat_generation_stage(cpi)) {
       fprintf(stdout, "tx_search_count = %d\n", cpi->tx_search_count);
     }
 #endif  // CONFIG_SPEED_STATS
 
 #if CONFIG_COLLECT_PARTITION_STATS == 2
-    if (cpi->oxcf.pass != 1) {
+    if (!is_stat_generation_stage(cpi)) {
       av1_print_partition_stats(&cpi->partition_stats);
     }
 #endif
@@ -4229,7 +4229,7 @@
   // Choose an arbitrary random number
   static unsigned int seed = 56789;
   const AV1EncoderConfig *oxcf = &cpi->oxcf;
-  if (oxcf->pass == 1) return SCALE_NUMERATOR;
+  if (is_stat_generation_stage(cpi)) return SCALE_NUMERATOR;
   uint8_t new_denom = SCALE_NUMERATOR;
 
   if (cpi->common.seq_params.reduced_still_picture_hdr) return SCALE_NUMERATOR;
@@ -4343,7 +4343,7 @@
   // Choose an arbitrary random number
   static unsigned int seed = 34567;
   const AV1EncoderConfig *oxcf = &cpi->oxcf;
-  if (oxcf->pass == 1) return SCALE_NUMERATOR;
+  if (is_stat_generation_stage(cpi)) return SCALE_NUMERATOR;
   uint8_t new_denom = SCALE_NUMERATOR;
 
   // Make sure that superres mode of the frame is consistent with the
@@ -4494,7 +4494,7 @@
     rsz.resize_height = cpi->common.height;
     return rsz;
   }
-  if (oxcf->pass == 1) return rsz;
+  if (is_stat_generation_stage(cpi)) return rsz;
   if (cpi->resize_pending_width && cpi->resize_pending_height) {
     rsz.resize_width = cpi->resize_pending_width;
     rsz.resize_height = cpi->resize_pending_height;
@@ -5895,8 +5895,8 @@
   }
 
   // Work out whether to force_integer_mv this frame
-  if (oxcf->pass != 1 && cpi->common.allow_screen_content_tools &&
-      !frame_is_intra_only(cm)) {
+  if (!is_stat_generation_stage(cpi) &&
+      cpi->common.allow_screen_content_tools && !frame_is_intra_only(cm)) {
     if (cpi->common.seq_params.force_integer_mv == 2) {
       // Adaptive mode: see what previous frame encoded did
       if (cpi->unscaled_last_source != NULL) {
@@ -5919,7 +5919,7 @@
          "Hash-me is leaking memory!");
 #endif
 
-  if (cpi->oxcf.pass != 1 && cpi->need_to_clear_prev_hash_table) {
+  if (!is_stat_generation_stage(cpi) && cpi->need_to_clear_prev_hash_table) {
     av1_hash_table_clear_all(cpi->previous_hash_table);
     cpi->need_to_clear_prev_hash_table = 0;
   }
@@ -6125,7 +6125,7 @@
   // Store encoded frame's hash table for in_integer_mv() next time.
   // Beware! If we don't update previous_hash_table here we will leak the
   // items stored in cur_frame's hash_table!
-  if (oxcf->pass != 1 && av1_use_hash_me(cpi)) {
+  if (!is_stat_generation_stage(cpi) && av1_use_hash_me(cpi)) {
     cpi->previous_hash_table = &cm->cur_frame->hash_table;
     cpi->need_to_clear_prev_hash_table = 1;
   }
@@ -6192,7 +6192,7 @@
         (1 << (cm->seq_params.order_hint_info.order_hint_bits_minus_1 + 1));
   }
 
-  if (cpi->oxcf.pass == 1) {
+  if (is_stat_generation_stage(cpi)) {
 #if !CONFIG_REALTIME_ONLY
     av1_first_pass(cpi, frame_input->ts_duration);
 #endif
@@ -6463,12 +6463,13 @@
   cpi->time_compress_data += aom_usec_timer_elapsed(&cmptimer);
 #endif  // CONFIG_INTERNAL_STATS
   if (cpi->b_calculate_psnr) {
-    if (cm->show_existing_frame || (oxcf->pass != 1 && cm->show_frame)) {
+    if (cm->show_existing_frame ||
+        (!is_stat_generation_stage(cpi) && cm->show_frame)) {
       generate_psnr_packet(cpi);
     }
   }
 
-  if (cpi->keep_level_stats && oxcf->pass != 1) {
+  if (cpi->keep_level_stats && !is_stat_generation_stage(cpi)) {
     // Initialize level info. at the beginning of each sequence.
     if (cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) {
       av1_init_level_info(cpi);
@@ -6477,12 +6478,12 @@
   }
 
 #if CONFIG_INTERNAL_STATS
-  if (oxcf->pass != 1) {
+  if (!is_stat_generation_stage(cpi)) {
     compute_internal_stats(cpi, (int)(*size));
   }
 #endif  // CONFIG_INTERNAL_STATS
 #if CONFIG_SPEED_STATS
-  if (cpi->oxcf.pass != 1 && !cm->show_existing_frame) {
+  if (!is_stat_generation_stage(cpi) && !cm->show_existing_frame) {
     cpi->tx_search_count += cpi->td.mb.tx_search_count;
     cpi->td.mb.tx_search_count = 0;
   }
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index dfaf33b..8fd07ce 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -1358,6 +1358,11 @@
   return cpi->oxcf.lag_in_frames >= ALT_MIN_LAG && cpi->oxcf.enable_auto_arf;
 }
 
+// Check if statistics generation stage
+static INLINE int is_stat_generation_stage(const AV1_COMP *const cpi) {
+  return (cpi->oxcf.pass == 1);
+}
+
 // TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf
 
 static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd,
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 392189a..27d8b22 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -618,13 +618,13 @@
                       cm->allow_high_precision_mv, x);
 
   if (frame_is_intra_only(cm) && cm->allow_screen_content_tools &&
-      cpi->oxcf.pass != 1) {
+      !is_stat_generation_stage(cpi)) {
     int *dvcost[2] = { &cpi->dv_cost[0][MV_MAX], &cpi->dv_cost[1][MV_MAX] };
     av1_build_nmv_cost_table(cpi->dv_joint_cost, dvcost, &cm->fc->ndvc,
                              MV_SUBPEL_NONE);
   }
 
-  if (cpi->oxcf.pass != 1) {
+  if (!is_stat_generation_stage(cpi)) {
     for (int i = 0; i < TRANS_TYPES; ++i)
       // IDENTITY: 1 bit
       // TRANSLATION: 3 bits
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index e4df066..90521fd 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -992,7 +992,7 @@
 
   // Slow quant, dct and trellis not worthwhile for first pass
   // so make sure they are always turned off.
-  if (oxcf->pass == 1) sf->optimize_coefficients = NO_TRELLIS_OPT;
+  if (is_stat_generation_stage(cpi)) sf->optimize_coefficients = NO_TRELLIS_OPT;
 
   // No recode or trellis for 1 pass.
   if (oxcf->pass == 0) sf->recode_loop = DISALLOW_RECODE;