Code refactoring in adapt-scan

Change-Id: Ie20bd0b05bbf3128933f10787aade7b63c98b52a
diff --git a/av1/common/entropy.c b/av1/common/entropy.c
index a1730a6..70b4acb 100644
--- a/av1/common/entropy.c
+++ b/av1/common/entropy.c
@@ -5584,10 +5584,6 @@
   TX_SIZE tx_size;
   unsigned int count_sat, update_factor;
 
-#if CONFIG_ADAPT_SCAN
-  TX_TYPE tx_type;
-#endif
-
   if (!frame_is_intra_only(cm) && cm->last_frame_type == KEY_FRAME) {
     update_factor = COEF_MAX_UPDATE_FACTOR_AFTER_KEY; /* adapt quickly */
     count_sat = COEF_COUNT_SAT_AFTER_KEY;
@@ -5601,25 +5597,6 @@
 
   for (tx_size = 0; tx_size < TX_SIZES; tx_size++)
     adapt_coef_probs(cm, tx_size, count_sat, update_factor);
-
-#if CONFIG_SUBFRAME_PROB_UPDATE
-  if (cm->partial_prob_update == 0)
-#endif  // CONFIG_SUBFRAME_PROB_UPDATE
-  {
-#if CONFIG_ADAPT_SCAN
-    for (tx_size = 0; tx_size < TX_SIZES_ALL; ++tx_size) {
-#if !(CONFIG_VAR_TX || CONFIG_RECT_TX)
-      if (tx_size >= TX_SIZES) continue;
-#else
-      if (tx_size > TX_32X16) continue;
-#endif  // !(CONFIG_VAR_TX || CONFIG_RECT_TX)
-      for (tx_type = DCT_DCT; tx_type < TX_TYPES; ++tx_type) {
-        av1_update_scan_prob(cm, tx_size, tx_type, ADAPT_SCAN_UPDATE_RATE_16);
-        av1_update_scan_order_facade(cm, tx_size, tx_type);
-      }
-    }
-#endif  // CONFIG_ADAPT_SCAN
-  }
 }
 
 #if CONFIG_SUBFRAME_PROB_UPDATE
diff --git a/av1/common/scan.c b/av1/common/scan.c
index 4e5f906..9a09056 100644
--- a/av1/common/scan.c
+++ b/av1/common/scan.c
@@ -6600,8 +6600,8 @@
   }
 }
 
-void av1_update_scan_prob(AV1_COMMON *cm, TX_SIZE tx_size, TX_TYPE tx_type,
-                          int rate_16) {
+static void update_scan_prob(AV1_COMMON *cm, TX_SIZE tx_size, TX_TYPE tx_type,
+                             int rate_16) {
   FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx];
   uint32_t *prev_non_zero_prob = get_non_zero_prob(pre_fc, tx_size, tx_type);
   uint32_t *non_zero_prob = get_non_zero_prob(cm->fc, tx_size, tx_type);
@@ -6757,8 +6757,8 @@
   }
 }
 
-void av1_update_scan_order_facade(AV1_COMMON *cm, TX_SIZE tx_size,
-                                  TX_TYPE tx_type) {
+static void update_scan_order_facade(AV1_COMMON *cm, TX_SIZE tx_size,
+                                     TX_TYPE tx_type) {
   int16_t sort_order[COEFF_IDX_SIZE];
   uint32_t *non_zero_prob = get_non_zero_prob(cm->fc, tx_size, tx_type);
   int16_t *scan = get_adapt_scan(cm->fc, tx_size, tx_type);
@@ -6787,11 +6787,27 @@
       for (i = 0; i < tx2d_size; ++i) {
         non_zero_prob[i] = (1 << 16) / 2;  // init non_zero_prob to 0.5
       }
-      av1_update_scan_order_facade(cm, tx_size, tx_type);
+      update_scan_order_facade(cm, tx_size, tx_type);
       sc->scan = get_adapt_scan(cm->fc, tx_size, tx_type);
       sc->iscan = get_adapt_iscan(cm->fc, tx_size, tx_type);
       sc->neighbors = get_adapt_nb(cm->fc, tx_size, tx_type);
     }
   }
 }
+
+void av1_adapt_scan_order(AV1_COMMON *cm) {
+  TX_SIZE tx_size;
+  for (tx_size = 0; tx_size < TX_SIZES_ALL; ++tx_size) {
+#if !(CONFIG_VAR_TX || CONFIG_RECT_TX)
+    if (tx_size >= TX_SIZES) continue;
+#else
+    if (tx_size > TX_32X16) continue;
+#endif  // !(CONFIG_VAR_TX || CONFIG_RECT_TX)
+    TX_TYPE tx_type;
+    for (tx_type = DCT_DCT; tx_type < TX_TYPES; ++tx_type) {
+      update_scan_prob(cm, tx_size, tx_type, ADAPT_SCAN_UPDATE_RATE_16);
+      update_scan_order_facade(cm, tx_size, tx_type);
+    }
+  }
+}
 #endif  // CONFIG_ADAPT_SCAN
diff --git a/av1/common/scan.h b/av1/common/scan.h
index c726d4d..e1bf7d4 100644
--- a/av1/common/scan.h
+++ b/av1/common/scan.h
@@ -30,8 +30,6 @@
 extern const SCAN_ORDER av1_inter_scan_orders[TX_SIZES_ALL][TX_TYPES];
 
 #if CONFIG_ADAPT_SCAN
-void av1_update_scan_prob(AV1_COMMON *cm, TX_SIZE tx_size, TX_TYPE tx_type,
-                          int rate_16);
 void av1_update_scan_count_facade(AV1_COMMON *cm, FRAME_COUNTS *counts,
                                   TX_SIZE tx_size, TX_TYPE tx_type,
                                   const tran_low_t *dqcoeffs, int max_scan);
@@ -55,9 +53,8 @@
 // neighbors[] accordingly.
 void av1_update_neighbors(int tx_size, const int16_t *scan,
                           const int16_t *iscan, int16_t *neighbors);
-void av1_update_scan_order_facade(AV1_COMMON *cm, TX_SIZE tx_size,
-                                  TX_TYPE tx_type);
 void av1_init_scan_order(AV1_COMMON *cm);
+void av1_adapt_scan_order(AV1_COMMON *cm);
 #endif
 
 static INLINE int get_coef_context(const int16_t *neighbors,