Move count buffers from stack to heap

This fixes the stack overflow issue on MSVC build.

Change-Id: Icb0a78e5992a097d2192979ec2432546eaa452dd
diff --git a/vp10/encoder/bitstream.c b/vp10/encoder/bitstream.c
index a7f8162..4f8e89c 100644
--- a/vp10/encoder/bitstream.c
+++ b/vp10/encoder/bitstream.c
@@ -2291,10 +2291,6 @@
   unsigned int eob_counts_copy[TX_SIZES][PLANE_TYPES][REF_TYPES]
                               [COEF_BANDS][COEFF_CONTEXTS];
   int i;
-  vp10_coeff_count coef_counts[COEF_PROBS_BUFS][TX_SIZES][PLANE_TYPES];
-  unsigned int eob_counts[COEF_PROBS_BUFS][TX_SIZES][PLANE_TYPES]
-                         [REF_TYPES][COEF_BANDS][COEFF_CONTEXTS];
-  vp10_coeff_stats branch_ct[COEF_PROBS_BUFS][TX_SIZES][PLANE_TYPES];
   vp10_coeff_probs_model dummy_frame_coef_probs[PLANE_TYPES];
 
   if (cm->do_subframe_update &&
@@ -2302,7 +2298,9 @@
     vp10_copy(cpi->common.fc->coef_probs,
               subframe_stats->enc_starting_coef_probs);
     for (i = 0; i <= cpi->common.coef_probs_update_idx; ++i) {
-      get_coef_counts_diff(cpi, i, coef_counts[i], eob_counts[i]);
+      get_coef_counts_diff(cpi, i,
+                           cpi->wholeframe_stats.coef_counts_buf[i],
+                           cpi->wholeframe_stats.eob_counts_buf[i]);
     }
   }
 #endif  // CONFIG_ENTROPY
@@ -2326,16 +2324,17 @@
                                 frame_coef_probs);
         for (i = 0; i <= cpi->common.coef_probs_update_idx; ++i) {
           vp10_copy(cpi->common.counts.eob_branch[tx_size],
-                    eob_counts[i][tx_size]);
+                    cpi->wholeframe_stats.eob_counts_buf[i][tx_size]);
           vp10_copy(cpi->td.rd_counts.coef_counts[tx_size],
-                    coef_counts[i][tx_size]);
-          build_tree_distribution(cpi, tx_size, branch_ct[i][tx_size],
+                    cpi->wholeframe_stats.coef_counts_buf[i][tx_size]);
+          build_tree_distribution(cpi, tx_size,
+                                  cpi->branch_ct_buf[i][tx_size],
                                   dummy_frame_coef_probs);
         }
         vp10_copy(cpi->common.counts.eob_branch[tx_size], eob_counts_copy);
         vp10_copy(cpi->td.rd_counts.coef_counts[tx_size], coef_counts_copy);
 
-        update_coef_probs_subframe(w, cpi, tx_size, branch_ct,
+        update_coef_probs_subframe(w, cpi, tx_size, cpi->branch_ct_buf,
                                    frame_coef_probs);
 #if CONFIG_ANS
         update = 1;
diff --git a/vp10/encoder/encoder.h b/vp10/encoder/encoder.h
index 93f274d..67ebe6d 100644
--- a/vp10/encoder/encoder.h
+++ b/vp10/encoder/encoder.h
@@ -580,6 +580,9 @@
   VP9LfSync lf_row_sync;
 #if CONFIG_ENTROPY
   SUBFRAME_STATS subframe_stats;
+  // TODO(yaowu): minimize the size of count buffers
+  SUBFRAME_STATS wholeframe_stats;
+  vp10_coeff_stats branch_ct_buf[COEF_PROBS_BUFS][TX_SIZES][PLANE_TYPES];
 #endif  // CONFIG_ENTROPY
 #if CONFIG_ANS
   struct BufAnsCoder buf_ans;