Move tot_q and ni_frames to PRIMARY_RATE_CONTROL

Moved tot_q and ni_frames from RATE_CONTROL to
PRIMARY_RATE_CONTROL to facilitate FPMT.

Change-Id: I9836ecd438233ac02294bd4dcb8ad76e5c5376dd
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index bd1a263..ca13f14 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -318,6 +318,9 @@
   p_rc->baseline_gf_interval = (min_gf_interval + max_gf_interval) / 2;
   p_rc->this_key_frame_forced = 0;
   p_rc->next_key_frame_forced = 0;
+  p_rc->ni_frames = 0;
+
+  p_rc->tot_q = 0.0;
 
   if (oxcf->target_seq_level_idx[0] < SEQ_LEVELS) {
     worst_allowed_q = 255;
@@ -355,9 +358,6 @@
   rc->frames_till_gf_update_due = 0;
   rc->ni_av_qi = rc_cfg->worst_allowed_q;
   rc->ni_tot_qi = 0;
-  rc->ni_frames = 0;
-
-  rc->tot_q = 0.0;
   rc->avg_q = av1_convert_qindex_to_q(rc_cfg->worst_allowed_q,
                                       oxcf->tool_cfg.bit_depth);
 
@@ -2106,13 +2106,13 @@
       rc->last_q[INTER_FRAME] = qindex;
       p_rc->avg_frame_qindex[INTER_FRAME] = ROUND_POWER_OF_TWO(
           3 * p_rc->avg_frame_qindex[INTER_FRAME] + qindex, 2);
-      rc->ni_frames++;
-      rc->tot_q += av1_convert_qindex_to_q(qindex, cm->seq_params->bit_depth);
-      rc->avg_q = rc->tot_q / rc->ni_frames;
+      p_rc->ni_frames++;
+      p_rc->tot_q += av1_convert_qindex_to_q(qindex, cm->seq_params->bit_depth);
+      rc->avg_q = p_rc->tot_q / p_rc->ni_frames;
       // Calculate the average Q for normal inter frames (not key or GFU
       // frames).
       rc->ni_tot_qi += qindex;
-      rc->ni_av_qi = rc->ni_tot_qi / rc->ni_frames;
+      rc->ni_av_qi = rc->ni_tot_qi / p_rc->ni_frames;
     }
   }
   // Keep record of last boosted (KF/GF/ARF) Q value.
diff --git a/av1/encoder/ratectrl.h b/av1/encoder/ratectrl.h
index 72166ee..45c6ff3 100644
--- a/av1/encoder/ratectrl.h
+++ b/av1/encoder/ratectrl.h
@@ -201,8 +201,6 @@
 
   int ni_av_qi;
   int ni_tot_qi;
-  int ni_frames;
-  double tot_q;
   double avg_q;
 
   int64_t buffer_level;
@@ -354,6 +352,10 @@
   int enable_scenecut_detection;
 
   int use_arf_in_this_kf_group;
+
+  int ni_frames;
+
+  double tot_q;
   /*!\endcond */
 
   /*!
diff --git a/av1/encoder/svc_layercontext.c b/av1/encoder/svc_layercontext.c
index 7d4d445..f74af68 100644
--- a/av1/encoder/svc_layercontext.c
+++ b/av1/encoder/svc_layercontext.c
@@ -41,9 +41,9 @@
       lrc->ni_av_qi = oxcf->rc_cfg.worst_allowed_q;
       lrc->total_actual_bits = 0;
       lrc->ni_tot_qi = 0;
-      lrc->tot_q = 0.0;
+      lp_rc->tot_q = 0.0;
       lrc->avg_q = 0.0;
-      lrc->ni_frames = 0;
+      lp_rc->ni_frames = 0;
       lrc->decimation_count = 0;
       lrc->decimation_factor = 0;
       lrc->worst_quality = av1_quantizer_to_qindex(lc->max_q);