Group Two pass related config in AV1EncoderConfig

This CL groups the two-pass related configuration parameters in
AV1EncoderConfig into a new struct TwoPassCfg, and adds relevant
documentation.

BUG=aomedia:2701

Change-Id: I5e0b085c4daa28f256b99d2a0963c800f1b6bf76
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 682c452..10c9bcc 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -722,6 +722,8 @@
 
   DecoderModelCfg *const dec_model_cfg = &oxcf->dec_model_cfg;
 
+  TwoPassCfg *const two_pass_cfg = &oxcf->two_pass_cfg;
+
   const int is_vbr = cfg->rc_end_usage == AOM_VBR;
   oxcf->profile = cfg->g_profile;
   oxcf->max_threads = (int)cfg->g_threads;
@@ -841,9 +843,11 @@
 
   oxcf->drop_frames_water_mark = cfg->rc_dropframe_thresh;
 
-  oxcf->two_pass_vbrbias = cfg->rc_2pass_vbr_bias_pct;
-  oxcf->two_pass_vbrmin_section = cfg->rc_2pass_vbr_minsection_pct;
-  oxcf->two_pass_vbrmax_section = cfg->rc_2pass_vbr_maxsection_pct;
+  // Set two-pass configuration.
+  two_pass_cfg->vbrbias = cfg->rc_2pass_vbr_bias_pct;
+  two_pass_cfg->vbrmin_section = cfg->rc_2pass_vbr_minsection_pct;
+  two_pass_cfg->vbrmax_section = cfg->rc_2pass_vbr_maxsection_pct;
+  two_pass_cfg->stats_in = cfg->rc_twopass_stats_in;
 
   // Set Key frame configuration.
   kf_cfg->fwd_kf_enabled = cfg->fwd_kf_enabled;
@@ -861,8 +865,6 @@
   oxcf->noise_sensitivity = extra_cfg->noise_sensitivity;
   oxcf->sharpness = extra_cfg->sharpness;
 
-  oxcf->two_pass_stats_in = cfg->rc_twopass_stats_in;
-
   oxcf->color_primaries = extra_cfg->color_primaries;
   oxcf->transfer_characteristics = extra_cfg->transfer_characteristics;
   oxcf->matrix_coefficients = extra_cfg->matrix_coefficients;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index b843118..a69f9eb 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -1232,12 +1232,13 @@
 #if !CONFIG_REALTIME_ONLY
   if (is_stat_consumption_stage(cpi)) {
     const size_t packet_sz = sizeof(FIRSTPASS_STATS);
-    const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz);
+    const int packets = (int)(oxcf->two_pass_cfg.stats_in.sz / packet_sz);
 
     if (!cpi->lap_enabled) {
       /*Re-initialize to stats buffer, populated by application in the case of
        * two pass*/
-      cpi->twopass.stats_buf_ctx->stats_in_start = oxcf->two_pass_stats_in.buf;
+      cpi->twopass.stats_buf_ctx->stats_in_start =
+          oxcf->two_pass_cfg.stats_in.buf;
       cpi->twopass.stats_in = cpi->twopass.stats_buf_ctx->stats_in_start;
       cpi->twopass.stats_buf_ctx->stats_in_end =
           &cpi->twopass.stats_buf_ctx->stats_in_start[packets - 1];
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index ddd8118..28e545c 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -462,6 +462,25 @@
   bool timing_info_present;
 } DecoderModelCfg;
 
+typedef struct {
+  // stats_in buffer contains all of the stats packets produced in the first
+  // pass, concatenated.
+  aom_fixed_buf_t stats_in;
+
+  // TWO PASS DATARATE CONTROL OPTIONS.
+  // Indicates the bias (expressed on a scale of 0 to 100) for determining
+  // target size for the current frame. The value 0 indicates the optimal CBR
+  // mode value should be used, and 100 indicates the optimal VBR mode value
+  // should be used.
+  int vbrbias;
+  // Indicates the minimum bitrate to be used for a single GOP as a percentage
+  // of the target bitrate.
+  int vbrmin_section;
+  // Indicates the maximum bitrate to be used for a single GOP as a percentage
+  // of the target bitrate.
+  int vbrmax_section;
+} TwoPassCfg;
+
 typedef struct AV1EncoderConfig {
   BITSTREAM_PROFILE profile;
   aom_bit_depth_t bit_depth;     // Codec bit-depth.
@@ -538,9 +557,8 @@
   int frame_periodic_boost;
 
   // two pass datarate control
-  int two_pass_vbrbias;  // two pass datarate control tweaks
-  int two_pass_vbrmin_section;
-  int two_pass_vbrmax_section;
+  TwoPassCfg two_pass_cfg;
+
   // END DATARATE CONTROL OPTIONS
   // ----------------------------------------------------------------
 
@@ -573,8 +591,6 @@
 
   int max_threads;
 
-  aom_fixed_buf_t two_pass_stats_in;
-
   aom_tune_metric tuning;
   const char *vmaf_model_path;
   aom_tune_content content;
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index 89fcc89..712e00c 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -65,7 +65,7 @@
   double modified_error =
       av_err * pow(this_frame->coded_error * this_frame->weight /
                        DOUBLE_DIVIDE_CHECK(av_err),
-                   oxcf->two_pass_vbrbias / 100.0);
+                   oxcf->two_pass_cfg.vbrbias / 100.0);
 
   // Correction for active area. Frames with a reduced active area
   // (eg due to formatting bars) have a higher error per mb for the
@@ -146,7 +146,7 @@
 static int frame_max_bits(const RATE_CONTROL *rc,
                           const AV1EncoderConfig *oxcf) {
   int64_t max_bits = ((int64_t)rc->avg_frame_bandwidth *
-                      (int64_t)oxcf->two_pass_vbrmax_section) /
+                      (int64_t)oxcf->two_pass_cfg.vbrmax_section) /
                      100;
   if (max_bits < 0)
     max_bits = 0;
@@ -2800,9 +2800,9 @@
     const FIRSTPASS_STATS *s = twopass->stats_in;
     double modified_error_total = 0.0;
     twopass->modified_error_min =
-        (avg_error * oxcf->two_pass_vbrmin_section) / 100;
+        (avg_error * oxcf->two_pass_cfg.vbrmin_section) / 100;
     twopass->modified_error_max =
-        (avg_error * oxcf->two_pass_vbrmax_section) / 100;
+        (avg_error * oxcf->two_pass_cfg.vbrmax_section) / 100;
     while (s < twopass->stats_buf_ctx->stats_in_end) {
       modified_error_total +=
           calculate_modified_err(frame_info, twopass, oxcf, s);
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index fc43690..11db0e5 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -1837,7 +1837,7 @@
 
   rc->avg_frame_bandwidth = (int)(oxcf->target_bandwidth / cpi->framerate);
   rc->min_frame_bandwidth =
-      (int)(rc->avg_frame_bandwidth * oxcf->two_pass_vbrmin_section / 100);
+      (int)(rc->avg_frame_bandwidth * oxcf->two_pass_cfg.vbrmin_section / 100);
 
   rc->min_frame_bandwidth =
       AOMMAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS);
@@ -1849,9 +1849,9 @@
   // a very high rate is given on the command line or the the rate cannnot
   // be acheived because of a user specificed max q (e.g. when the user
   // specifies lossless encode.
-  vbr_max_bits =
-      (int)(((int64_t)rc->avg_frame_bandwidth * oxcf->two_pass_vbrmax_section) /
-            100);
+  vbr_max_bits = (int)(((int64_t)rc->avg_frame_bandwidth *
+                        oxcf->two_pass_cfg.vbrmax_section) /
+                       100);
   rc->max_frame_bandwidth =
       AOMMAX(AOMMAX((MBs * MAX_MB_RATE), MAXRATE_1080P), vbr_max_bits);