Make adapt-scan support multi-thread encoding

This commit makes the adaptive scan order system support multi-
thread encoding. It fixes unit test failure issue associated with
AV1/AVxEncoderThreadTest.EncoderResultTest/0.

BUG=aomedia:353

Change-Id: I61cbf9531c8deab97fb3bb17428d0b2a63cf309a
diff --git a/av1/common/scan.c b/av1/common/scan.c
index 894ffec..4e5f906 100644
--- a/av1/common/scan.c
+++ b/av1/common/scan.c
@@ -6629,13 +6629,13 @@
   }
 }
 
-void av1_update_scan_count_facade(AV1_COMMON *cm, TX_SIZE tx_size,
-                                  TX_TYPE tx_type, const tran_low_t *dqcoeffs,
-                                  int max_scan) {
+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) {
   int16_t *scan = get_adapt_scan(cm->fc, tx_size, tx_type);
-  uint32_t *non_zero_count = get_non_zero_counts(&cm->counts, tx_size, tx_type);
+  uint32_t *non_zero_count = get_non_zero_counts(counts, tx_size, tx_type);
   update_scan_count(scan, max_scan, dqcoeffs, non_zero_count);
-  ++cm->counts.txb_count[tx_size][tx_type];
+  ++counts->txb_count[tx_size][tx_type];
 }
 
 static int cmp_prob(const void *a, const void *b) {
diff --git a/av1/common/scan.h b/av1/common/scan.h
index 9047359..c726d4d 100644
--- a/av1/common/scan.h
+++ b/av1/common/scan.h
@@ -32,9 +32,9 @@
 #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, TX_SIZE tx_size,
-                                  TX_TYPE tx_type, const tran_low_t *dqcoeffs,
-                                  int max_scan);
+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);
 
 // embed r + c and coeff_idx info with nonzero probabilities. When sorting the
 // nonzero probabilities, if there is a tie, the coefficient with smaller r + c
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 651be21..b646965 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -522,7 +522,8 @@
         av1_decode_block_tokens(xd, plane, scan_order, col, row, tx_size,
                                 tx_type, &max_scan_line, r, mbmi->segment_id);
 #if CONFIG_ADAPT_SCAN
-    av1_update_scan_count_facade(cm, tx_size, tx_type, pd->dqcoeff, eob);
+    av1_update_scan_count_facade(cm, xd->counts, tx_size, tx_type, pd->dqcoeff,
+                                 eob);
 #endif
     if (eob)
       inverse_transform_block(xd, plane, tx_type, tx_size, dst, pd->dst.stride,
@@ -562,7 +563,8 @@
         av1_decode_block_tokens(xd, plane, sc, blk_col, blk_row, plane_tx_size,
                                 tx_type, &max_scan_line, r, mbmi->segment_id);
 #if CONFIG_ADAPT_SCAN
-    av1_update_scan_count_facade(cm, tx_size, tx_type, pd->dqcoeff, eob);
+    av1_update_scan_count_facade(cm, xd->counts, tx_size, tx_type, pd->dqcoeff,
+                                 eob);
 #endif
     inverse_transform_block(xd, plane, tx_type, plane_tx_size,
                             &pd->dst.buf[(blk_row * pd->dst.stride + blk_col)
@@ -615,7 +617,8 @@
   uint8_t *dst =
       &pd->dst.buf[(row * pd->dst.stride + col) << tx_size_wide_log2[0]];
 #if CONFIG_ADAPT_SCAN
-  av1_update_scan_count_facade(cm, tx_size, tx_type, pd->dqcoeff, eob);
+  av1_update_scan_count_facade(cm, xd->counts, tx_size, tx_type, pd->dqcoeff,
+                               eob);
 #endif
   if (eob)
     inverse_transform_block(xd, plane, tx_type, tx_size, dst, pd->dst.stride,
diff --git a/av1/encoder/tokenize.c b/av1/encoder/tokenize.c
index 1d427bd..549815f 100644
--- a/av1/encoder/tokenize.c
+++ b/av1/encoder/tokenize.c
@@ -589,7 +589,8 @@
   // av1_update_scan_count_facade(). The update behavior should be the same
   // because av1_update_scan_count_facade() only cares if coefficients are zero
   // or not.
-  av1_update_scan_count_facade((AV1_COMMON *)cm, tx_size, tx_type, qcoeff, c);
+  av1_update_scan_count_facade((AV1_COMMON *)cm, td->counts, tx_size, tx_type,
+                               qcoeff, c);
 #endif
 
   av1_set_contexts(xd, pd, plane, tx_size, c > 0, blk_col, blk_row);