Add a runtime flag to enable bit accounting.

By default, when building with --enable-accounting the bit accounting
 code will collect statistics for every frame while decoding.
Collecting statistics can slow down decode time and we would eventually
 like to enable the CONFIG_ACCOUNTING flag by default.
This patch adds a runtime flag so that bit accounting statistics are
 only collected when actually needed.

Change-Id: I25d9eaf26ea132d61ace95b952872158c9ac29e7
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 2e6e744..861ba21 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -2774,7 +2774,9 @@
     pbi->allocated_tiles = n_tiles;
   }
 #if CONFIG_ACCOUNTING
-  aom_accounting_reset(&pbi->accounting);
+  if (pbi->acct_enabled) {
+    aom_accounting_reset(&pbi->accounting);
+  }
 #endif
   // Load all tile information into tile_data.
   for (tile_row = tile_rows_start; tile_row < tile_rows_end; ++tile_row) {
@@ -2799,7 +2801,11 @@
                           &td->bit_reader, pbi->decrypt_cb, pbi->decrypt_state);
 #endif
 #if CONFIG_ACCOUNTING
-      tile_data->bit_reader.accounting = &pbi->accounting;
+      if (pbi->acct_enabled) {
+        tile_data->bit_reader.accounting = &pbi->accounting;
+      } else {
+        tile_data->bit_reader.accounting = NULL;
+      }
 #endif
       av1_init_macroblockd(cm, &td->xd, td->dqcoeff);
 #if CONFIG_PALETTE
@@ -2820,8 +2826,10 @@
       const int col = inv_col_order ? tile_cols - 1 - tile_col : tile_col;
       TileData *const td = pbi->tile_data + tile_cols * row + col;
 #if CONFIG_ACCOUNTING
-      tile_data->bit_reader.accounting->last_tell_frac =
-          aom_reader_tell_frac(&tile_data->bit_reader);
+      if (pbi->acct_enabled) {
+        tile_data->bit_reader.accounting->last_tell_frac =
+            aom_reader_tell_frac(&tile_data->bit_reader);
+      }
 #endif
 
       av1_tile_set_col(&tile_info, cm, col);
diff --git a/av1/decoder/decoder.c b/av1/decoder/decoder.c
index 9952650..dea9d36 100644
--- a/av1/decoder/decoder.c
+++ b/av1/decoder/decoder.c
@@ -127,6 +127,7 @@
   av1_loop_restoration_precal();
 #endif  // CONFIG_LOOP_RESTORATION
 #if CONFIG_ACCOUNTING
+  pbi->acct_enabled = 1;
   aom_accounting_init(&pbi->accounting);
 #endif
 
diff --git a/av1/decoder/decoder.h b/av1/decoder/decoder.h
index 7575260..fd68d13 100644
--- a/av1/decoder/decoder.h
+++ b/av1/decoder/decoder.h
@@ -104,6 +104,7 @@
   int dec_tile_row, dec_tile_col;
 #endif  // CONFIG_EXT_TILE
 #if CONFIG_ACCOUNTING
+  int acct_enabled;
   Accounting accounting;
 #endif