Tile groups: ensure each tile in a TG has a length.

This ensures TGs can be decoded even if the whole
frame has not been received and the frame length
is not known.

Change-Id: If24837fcc3b5c46554751be792e91100de73e8d6
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 4e6afb0..a5c95bd 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -1254,7 +1254,6 @@
 
   for (r = 0; r < tile_rows; ++r) {
     for (c = 0; c < tile_cols; ++c, ++tc) {
-      const int is_last = (r == tile_rows - 1) && (c == tile_cols - 1);
       TileBuffer *const buf = &tile_buffers[r][c];
       hdr_offset = (tc && tc == first_tile_in_tg) ? hdr_size : 0;
 
@@ -1269,9 +1268,8 @@
       }
       first_tile_in_tg += tc == first_tile_in_tg ? pbi->tg_size : 0;
       data += hdr_offset;
-      get_tile_buffer(data_end, pbi->common.tile_sz_mag, is_last,
-                      &pbi->common.error, &data, pbi->decrypt_cb,
-                      pbi->decrypt_state, buf);
+      get_tile_buffer(data_end, pbi->common.tile_sz_mag, 0, &pbi->common.error,
+                      &data, pbi->decrypt_cb, pbi->decrypt_state, buf);
     }
   }
 #else
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 952db61..2734a5d 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -1812,11 +1812,13 @@
   for (tile_row = 0; tile_row < tile_rows; tile_row++) {
     for (tile_col = 0; tile_col < tile_cols; tile_col++) {
       const int tile_idx = tile_row * tile_cols + tile_col;
-      const int is_last_tile = tile_idx == tile_rows * tile_cols - 1;
       unsigned int tile_size;
       TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col];
-
-#if CONFIG_TILE_GROUPS
+#if !CONFIG_TILE_GROUPS
+      const int is_last_tile = tile_idx == tile_rows * tile_cols - 1;
+#else
+      // All tiles in a tile group have a length
+      const int is_last_tile = 0;
       if (tile_count >= tg_size) {
         // Copy uncompressed header
         memcpy(data_ptr + total_size, data_ptr,