write_tile_info: gather writing of tile_size_bytes

the retains the behavior of non-large_scale_tile in writing the bits
without tiles present

Change-Id: Id140a6a6aa81aebea46daf022133306c75bc1810
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 74662a6..65e4604 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -2318,6 +2318,7 @@
 #endif
 
 static void write_tile_info(const AV1_COMMON *const cm,
+                            struct aom_write_bit_buffer *saved_wb,
                             struct aom_write_bit_buffer *wb) {
   if (cm->large_scale_tile) {
     const int tile_width =
@@ -2378,10 +2379,20 @@
 #endif  // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
 #endif  // CONFIG_LOOPFILTERING_ACROSS_TILES
 
-#if CONFIG_TILE_INFO_FIRST
-  // write the tile length code  (Always 4 bytes for now)
+  *saved_wb = *wb;
+  if (cm->large_scale_tile) {
+    if (cm->tile_rows * cm->tile_cols > 1) {
+      // Note that the last item in the uncompressed header is the data
+      // describing tile configuration.
+      // Number of bytes in tile column size - 1
+      aom_wb_write_literal(wb, 0, 2);
+      // Number of bytes in tile size - 1
+      aom_wb_write_literal(wb, 0, 2);
+    }
+    return;
+  }
+  // Number of bytes in tile size - 1
   aom_wb_write_literal(wb, 3, 2);
-#endif
 }
 
 #if USE_GF16_MULTI_LAYER
@@ -3217,9 +3228,8 @@
   aom_wb_write_literal(wb, cm->frame_context_idx, FRAME_CONTEXTS_LOG2);
 #endif
 #if CONFIG_TILE_INFO_FIRST
-  (void)saved_wb;
-  write_tile_info(cm, wb);
-#endif
+  write_tile_info(cm, saved_wb, wb);
+#endif  // CONFIG_TILE_INFO_FIRST
   encode_quantization(cm, wb);
   encode_segmentation(cm, xd, wb);
   {
@@ -3308,19 +3318,7 @@
 #endif
 
 #if !CONFIG_TILE_INFO_FIRST
-  write_tile_info(cm, wb);
-
-  *saved_wb = *wb;
-  // Write tile size magnitudes
-  if (cm->tile_rows * cm->tile_cols > 1 && cm->large_scale_tile) {
-    // Note that the last item in the uncompressed header is the data
-    // describing tile configuration.
-    // Number of bytes in tile column size - 1
-    aom_wb_write_literal(wb, 0, 2);
-
-    // Number of bytes in tile size - 1
-    aom_wb_write_literal(wb, 0, 2);
-  }
+  write_tile_info(cm, saved_wb, wb);
 #endif  // !CONFIG_TILE_INFO_FIRST
 }
 
@@ -3577,11 +3575,6 @@
     return total_size;
   }
 
-#if !CONFIG_TILE_INFO_FIRST
-  // write the tile length code  (Always 4 bytes for now)
-  if (!cm->large_scale_tile) aom_wb_write_literal(&wb, 3, 2);
-#endif
-
   uncompressed_hdr_size = aom_wb_bytes_written(&wb);
   total_size = uncompressed_hdr_size;
   return total_size;