rtc: Fix to avg_frame_low_motion in cyclic refresh

The avg_frame_low_motion should be updated every
frame if the aq_mode=CR feature is enabled.
In current code the metric was not updated when
the cyclic refresh was dynamically disabled within
the stream (because of the cm->seg_enabled check).
This can lead to the refresh not being re-enabled
when the motion content goes low.

Also adjust the threshold for disabling CR.

Only affects a few high motion clips on rtc set.
For low bitrates low resoln on speed 6/7:
2.3/3.6% gain for pixel3 clip, 0.5/0.47% gain for
still_bright, and 0.0/0.33% loss for street.

Change-Id: I0e33861c98f29e109c2e755932f0b8ac87598bc8
diff --git a/av1/encoder/aq_cyclicrefresh.c b/av1/encoder/aq_cyclicrefresh.c
index 854adbb..49221a6 100644
--- a/av1/encoder/aq_cyclicrefresh.c
+++ b/av1/encoder/aq_cyclicrefresh.c
@@ -218,12 +218,15 @@
     for (int mi_col = 0; mi_col < cm->mi_cols; mi_col++) {
       MB_MODE_INFO **mi = cm->mi_grid_base + mi_row * cm->mi_stride + mi_col;
       MV mv = mi[0]->mv[0].as_mv;
-      int map_index = mi_row * cm->mi_cols + mi_col;
-      if (cyclic_refresh_segment_id(seg_map[map_index]) == CR_SEGMENT_ID_BOOST1)
-        cr->actual_num_seg1_blocks++;
-      else if (cyclic_refresh_segment_id(seg_map[map_index]) ==
-               CR_SEGMENT_ID_BOOST2)
-        cr->actual_num_seg2_blocks++;
+      if (cm->seg.enabled) {
+        int map_index = mi_row * cm->mi_cols + mi_col;
+        if (cyclic_refresh_segment_id(seg_map[map_index]) ==
+            CR_SEGMENT_ID_BOOST1)
+          cr->actual_num_seg1_blocks++;
+        else if (cyclic_refresh_segment_id(seg_map[map_index]) ==
+                 CR_SEGMENT_ID_BOOST2)
+          cr->actual_num_seg2_blocks++;
+      }
       // Accumulate low_content_frame.
       if (is_inter_block(mi[0]) && abs(mv.row) < 16 && abs(mv.col) < 16)
         cr->cnt_zeromv++;
@@ -343,7 +346,7 @@
       rc->avg_frame_qindex[INTER_FRAME] < qp_thresh ||
       (rc->frames_since_key > 20 &&
        rc->avg_frame_qindex[INTER_FRAME] > qp_max_thresh) ||
-      (cr->avg_frame_low_motion < 20 && rc->frames_since_key > 40)) {
+      (cr->avg_frame_low_motion < 45 && rc->frames_since_key > 40)) {
     cr->apply_cyclic_refresh = 0;
     return;
   }
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 562ce0b..48ee8be 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -5208,8 +5208,7 @@
   } while (loop);
 
   // Update some stats from cyclic refresh.
-  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled &&
-      !frame_is_intra_only(cm))
+  if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && !frame_is_intra_only(cm))
     av1_cyclic_refresh_postencode(cpi);
 
   return AOM_CODEC_OK;