shithub: libvpx

Download patch

ref: 9482a0bf10773358bff7bc10c413eea780f97ab1
parent: 98e132bde099c760289ba1dc8b1ae06183ec611d
author: Dmitry Kovalev <dkovalev@google.com>
date: Tue Jul 16 10:47:15 EDT 2013

Cleaning up tile code.

Removing tile_rows and tile_columns from VP9Common, removing redundant
constants MIN_TILE_WIDTH and MAX_TILE_WIDTH, changing signature of
vp9_get_tile_n_bits.

Change-Id: I8ff3104a38179b2c6900df965c144c1d6f602267

--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -254,9 +254,8 @@
   int error_resilient_mode;
   int frame_parallel_decoding_mode;
 
-  int tile_columns, log2_tile_columns;
+  int log2_tile_cols, log2_tile_rows;
   int cur_tile_mi_col_start, cur_tile_mi_col_end, cur_tile_col_idx;
-  int tile_rows, log2_tile_rows;
   int cur_tile_mi_row_start, cur_tile_mi_row_end, cur_tile_row_idx;
 } VP9_COMMON;
 
--- a/vp9/common/vp9_tile_common.c
+++ b/vp9/common/vp9_tile_common.c
@@ -10,18 +10,15 @@
 
 #include "vp9/common/vp9_tile_common.h"
 
-#define MIN_TILE_WIDTH 256
-#define MAX_TILE_WIDTH 4096
-#define MIN_TILE_WIDTH_SBS (MIN_TILE_WIDTH >> 6)
-#define MAX_TILE_WIDTH_SBS (MAX_TILE_WIDTH >> 6)
+#define MIN_TILE_WIDTH_B64 4
+#define MAX_TILE_WIDTH_B64 64
 
 static int to_sbs(n_mis) {
   return mi_cols_aligned_to_sb(n_mis) >> LOG2_MI_BLOCK_SIZE;
 }
 
-static void vp9_get_tile_offsets(VP9_COMMON *cm, int *min_tile_off,
-                                 int *max_tile_off, int tile_idx,
-                                 int log2_n_tiles, int n_mis) {
+static void vp9_get_tile_offsets(int *min_tile_off, int *max_tile_off,
+                                 int tile_idx, int log2_n_tiles, int n_mis) {
   const int n_sbs = to_sbs(n_mis);
   const int sb_off1 =  (tile_idx      * n_sbs) >> log2_n_tiles;
   const int sb_off2 = ((tile_idx + 1) * n_sbs) >> log2_n_tiles;
@@ -32,26 +29,24 @@
 
 void vp9_get_tile_col_offsets(VP9_COMMON *cm, int tile_col_idx) {
   cm->cur_tile_col_idx = tile_col_idx;
-  vp9_get_tile_offsets(cm, &cm->cur_tile_mi_col_start,
-                       &cm->cur_tile_mi_col_end, tile_col_idx,
-                       cm->log2_tile_columns, cm->mi_cols);
+  vp9_get_tile_offsets(&cm->cur_tile_mi_col_start, &cm->cur_tile_mi_col_end,
+                       tile_col_idx, cm->log2_tile_cols, cm->mi_cols);
 }
 
 void vp9_get_tile_row_offsets(VP9_COMMON *cm, int tile_row_idx) {
   cm->cur_tile_row_idx = tile_row_idx;
-  vp9_get_tile_offsets(cm, &cm->cur_tile_mi_row_start,
-                       &cm->cur_tile_mi_row_end, tile_row_idx,
-                       cm->log2_tile_rows, cm->mi_rows);
+  vp9_get_tile_offsets(&cm->cur_tile_mi_row_start, &cm->cur_tile_mi_row_end,
+                       tile_row_idx, cm->log2_tile_rows, cm->mi_rows);
 }
 
 
-void vp9_get_tile_n_bits(VP9_COMMON *cm, int *min_log2_n_tiles_ptr,
-                         int *delta_log2_n_tiles) {
-  const int sb_cols = to_sbs(cm->mi_cols);
+void vp9_get_tile_n_bits(int mi_cols,
+                         int *min_log2_tile_cols, int *max_log2_tile_cols) {
+  const int sb_cols = to_sbs(mi_cols);
   int min_log2_n_tiles, max_log2_n_tiles;
 
   for (max_log2_n_tiles = 0;
-       (sb_cols >> max_log2_n_tiles) >= MIN_TILE_WIDTH_SBS;
+       (sb_cols >> max_log2_n_tiles) >= MIN_TILE_WIDTH_B64;
        max_log2_n_tiles++) {}
   max_log2_n_tiles--;
   if (max_log2_n_tiles <  0)
@@ -58,10 +53,11 @@
     max_log2_n_tiles = 0;
 
   for (min_log2_n_tiles = 0;
-       (MAX_TILE_WIDTH_SBS << min_log2_n_tiles) < sb_cols;
+       (MAX_TILE_WIDTH_B64 << min_log2_n_tiles) < sb_cols;
        min_log2_n_tiles++) {}
 
-  assert(max_log2_n_tiles >= min_log2_n_tiles);
-  *min_log2_n_tiles_ptr = min_log2_n_tiles;
-  *delta_log2_n_tiles = max_log2_n_tiles - min_log2_n_tiles;
+  assert(min_log2_n_tiles <= max_log2_n_tiles);
+
+  *min_log2_tile_cols = min_log2_n_tiles;
+  *max_log2_tile_cols = max_log2_n_tiles;
 }
--- a/vp9/common/vp9_tile_common.h
+++ b/vp9/common/vp9_tile_common.h
@@ -17,7 +17,7 @@
 
 void vp9_get_tile_row_offsets(VP9_COMMON *cm, int tile_row_idx);
 
-void vp9_get_tile_n_bits(VP9_COMMON *cm, int *min_log2_n_tiles,
-                         int *delta_log2_n_tiles);
+void vp9_get_tile_n_bits(int mi_cols,
+                         int *min_log2_tile_cols, int *max_log2_tile_cols);
 
 #endif  // VP9_COMMON_VP9_TILE_COMMON_H_
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -632,23 +632,19 @@
 }
 
 static void setup_tile_info(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
-  int delta_log2_tiles;
+  int min_log2_tile_cols, max_log2_tile_cols, max_ones;
+  vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
 
-  vp9_get_tile_n_bits(cm, &cm->log2_tile_columns, &delta_log2_tiles);
-  while (delta_log2_tiles--) {
-    if (vp9_rb_read_bit(rb)) {
-      cm->log2_tile_columns++;
-    } else {
-      break;
-    }
-  }
+  // columns
+  max_ones = max_log2_tile_cols - min_log2_tile_cols;
+  cm->log2_tile_cols = min_log2_tile_cols;
+  while (max_ones-- && vp9_rb_read_bit(rb))
+    cm->log2_tile_cols++;
 
+  // rows
   cm->log2_tile_rows = vp9_rb_read_bit(rb);
   if (cm->log2_tile_rows)
     cm->log2_tile_rows += vp9_rb_read_bit(rb);
-
-  cm->tile_columns = 1 << cm->log2_tile_columns;
-  cm->tile_rows    = 1 << cm->log2_tile_rows;
 }
 
 static void decode_tiles(VP9D_COMP *pbi,
@@ -659,6 +655,8 @@
   const uint8_t *data_ptr = data + first_partition_size;
   const uint8_t *const data_end = pbi->source + pbi->source_sz;
   const int aligned_mi_cols = mi_cols_aligned_to_sb(pc->mi_cols);
+  const int tile_cols = 1 << pc->log2_tile_cols;
+  const int tile_rows = 1 << pc->log2_tile_rows;
   int tile_row, tile_col;
 
   // Note: this memset assumes above_context[0], [1] and [2]
@@ -670,20 +668,19 @@
              sizeof(PARTITION_CONTEXT) * aligned_mi_cols);
 
   if (pbi->oxcf.inv_tile_order) {
-    const int n_cols = pc->tile_columns;
     const uint8_t *data_ptr2[4][1 << 6];
     vp9_reader bc_bak = {0};
 
     // pre-initialize the offsets, we're going to read in inverse order
     data_ptr2[0][0] = data_ptr;
-    for (tile_row = 0; tile_row < pc->tile_rows; tile_row++) {
+    for (tile_row = 0; tile_row < tile_rows; tile_row++) {
       if (tile_row) {
-        const int size = read_be32(data_ptr2[tile_row - 1][n_cols - 1]);
-        data_ptr2[tile_row - 1][n_cols - 1] += 4;
-        data_ptr2[tile_row][0] = data_ptr2[tile_row - 1][n_cols - 1] + size;
+        const int size = read_be32(data_ptr2[tile_row - 1][tile_cols - 1]);
+        data_ptr2[tile_row - 1][tile_cols - 1] += 4;
+        data_ptr2[tile_row][0] = data_ptr2[tile_row - 1][tile_cols - 1] + size;
       }
 
-      for (tile_col = 1; tile_col < n_cols; tile_col++) {
+      for (tile_col = 1; tile_col < tile_cols; tile_col++) {
         const int size = read_be32(data_ptr2[tile_row][tile_col - 1]);
         data_ptr2[tile_row][tile_col - 1] += 4;
         data_ptr2[tile_row][tile_col] =
@@ -691,15 +688,15 @@
       }
     }
 
-    for (tile_row = 0; tile_row < pc->tile_rows; tile_row++) {
+    for (tile_row = 0; tile_row < tile_rows; tile_row++) {
       vp9_get_tile_row_offsets(pc, tile_row);
-      for (tile_col = n_cols - 1; tile_col >= 0; tile_col--) {
+      for (tile_col = tile_cols - 1; tile_col >= 0; tile_col--) {
         vp9_get_tile_col_offsets(pc, tile_col);
         setup_token_decoder(pbi, data_ptr2[tile_row][tile_col],
                             data_end - data_ptr2[tile_row][tile_col],
                             residual_bc);
         decode_tile(pbi, residual_bc);
-        if (tile_row == pc->tile_rows - 1 && tile_col == n_cols - 1)
+        if (tile_row == tile_rows - 1 && tile_col == tile_cols - 1)
           bc_bak = *residual_bc;
       }
     }
@@ -707,15 +704,14 @@
   } else {
     int has_more;
 
-    for (tile_row = 0; tile_row < pc->tile_rows; tile_row++) {
+    for (tile_row = 0; tile_row < tile_rows; tile_row++) {
       vp9_get_tile_row_offsets(pc, tile_row);
-      for (tile_col = 0; tile_col < pc->tile_columns; tile_col++) {
+      for (tile_col = 0; tile_col < tile_cols; tile_col++) {
         size_t size;
 
         vp9_get_tile_col_offsets(pc, tile_col);
 
-        has_more = tile_col < pc->tile_columns - 1 ||
-                   tile_row < pc->tile_rows - 1;
+        has_more = tile_col < tile_cols - 1 || tile_row < tile_rows - 1;
         if (has_more) {
           if (!read_is_valid(data_ptr, 4, data_end))
             vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -1136,18 +1136,18 @@
 }
 
 static void write_tile_info(VP9_COMMON *cm, struct vp9_write_bit_buffer *wb) {
-  int min_log2_tiles, delta_log2_tiles, n_tile_bits, n;
-  vp9_get_tile_n_bits(cm, &min_log2_tiles, &delta_log2_tiles);
-  n_tile_bits = cm->log2_tile_columns - min_log2_tiles;
-  for (n = 0; n < delta_log2_tiles; n++) {
-    if (n_tile_bits--) {
-      vp9_wb_write_bit(wb, 1);
-    } else {
-      vp9_wb_write_bit(wb, 0);
-      break;
-    }
-  }
+  int min_log2_tile_cols, max_log2_tile_cols, ones;
+  vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
 
+  // columns
+  ones = cm->log2_tile_cols - min_log2_tile_cols;
+  while (ones--)
+    vp9_wb_write_bit(wb, 1);
+
+  if (cm->log2_tile_cols < max_log2_tile_cols)
+    vp9_wb_write_bit(wb, 0);
+
+  // rows
   vp9_wb_write_bit(wb, cm->log2_tile_rows != 0);
   if (cm->log2_tile_rows != 0)
     vp9_wb_write_bit(wb, cm->log2_tile_rows != 1);
@@ -1195,28 +1195,30 @@
   int tile_row, tile_col;
   TOKENEXTRA *tok[4][1 << 6], *tok_end;
   size_t total_size = 0;
+  const int tile_cols = 1 << cm->log2_tile_cols;
+  const int tile_rows = 1 << cm->log2_tile_rows;
 
   vpx_memset(cm->above_seg_context, 0, sizeof(PARTITION_CONTEXT) *
              mi_cols_aligned_to_sb(cm->mi_cols));
 
   tok[0][0] = cpi->tok;
-  for (tile_row = 0; tile_row < cm->tile_rows; tile_row++) {
+  for (tile_row = 0; tile_row < tile_rows; tile_row++) {
     if (tile_row)
-      tok[tile_row][0] = tok[tile_row - 1][cm->tile_columns - 1] +
-                         cpi->tok_count[tile_row - 1][cm->tile_columns - 1];
+      tok[tile_row][0] = tok[tile_row - 1][tile_cols - 1] +
+                         cpi->tok_count[tile_row - 1][tile_cols - 1];
 
-    for (tile_col = 1; tile_col < cm->tile_columns; tile_col++)
+    for (tile_col = 1; tile_col < tile_cols; tile_col++)
       tok[tile_row][tile_col] = tok[tile_row][tile_col - 1] +
                                 cpi->tok_count[tile_row][tile_col - 1];
   }
 
-  for (tile_row = 0; tile_row < cm->tile_rows; tile_row++) {
+  for (tile_row = 0; tile_row < tile_rows; tile_row++) {
     vp9_get_tile_row_offsets(cm, tile_row);
-    for (tile_col = 0; tile_col < cm->tile_columns; tile_col++) {
+    for (tile_col = 0; tile_col < tile_cols; tile_col++) {
       vp9_get_tile_col_offsets(cm, tile_col);
       tok_end = tok[tile_row][tile_col] + cpi->tok_count[tile_row][tile_col];
 
-      if (tile_col < cm->tile_columns - 1 || tile_row < cm->tile_rows - 1)
+      if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1)
         vp9_start_encode(&residual_bc, data_ptr + total_size + 4);
       else
         vp9_start_encode(&residual_bc, data_ptr + total_size);
@@ -1224,7 +1226,7 @@
       write_modes(cpi, &residual_bc, &tok[tile_row][tile_col], tok_end);
       assert(tok[tile_row][tile_col] == tok_end);
       vp9_stop_encode(&residual_bc);
-      if (tile_col < cm->tile_columns - 1 || tile_row < cm->tile_rows - 1) {
+      if (tile_col < tile_cols - 1 || tile_row < tile_rows - 1) {
         // size of this tile
         write_be32(data_ptr + total_size, residual_bc.pos);
         total_size += 4;
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -1839,22 +1839,23 @@
       // Take tiles into account and give start/end MB
       int tile_col, tile_row;
       TOKENEXTRA *tp = cpi->tok;
+      const int tile_cols = 1 << cm->log2_tile_cols;
+      const int tile_rows = 1 << cm->log2_tile_rows;
 
-      for (tile_row = 0; tile_row < cm->tile_rows; tile_row++) {
+      for (tile_row = 0; tile_row < tile_rows; tile_row++) {
         vp9_get_tile_row_offsets(cm, tile_row);
 
-        for (tile_col = 0; tile_col < cm->tile_columns; tile_col++) {
+        for (tile_col = 0; tile_col < tile_cols; tile_col++) {
           TOKENEXTRA *tp_old = tp;
 
           // For each row of SBs in the frame
           vp9_get_tile_col_offsets(cm, tile_col);
           for (mi_row = cm->cur_tile_mi_row_start;
-              mi_row < cm->cur_tile_mi_row_end; mi_row += 8)
+               mi_row < cm->cur_tile_mi_row_end; mi_row += 8)
             encode_sb_row(cpi, mi_row, &tp, &totalrate);
 
           cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old);
-          assert(tp - cpi->tok <=
-                 get_token_alloc(cm->mb_rows, cm->mb_cols));
+          assert(tp - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols));
         }
       }
     }
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -1068,19 +1068,13 @@
 
 static void set_tile_limits(VP9_COMP *cpi) {
   VP9_COMMON *const cm = &cpi->common;
-  int min_log2_tiles, max_log2_tiles;
 
-  cm->log2_tile_columns = cpi->oxcf.tile_columns;
-  cm->log2_tile_rows = cpi->oxcf.tile_rows;
+  int min_log2_tile_cols, max_log2_tile_cols;
+  vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
 
-  vp9_get_tile_n_bits(cm, &min_log2_tiles, &max_log2_tiles);
-  max_log2_tiles += min_log2_tiles;
-
-  cm->log2_tile_columns = clamp(cm->log2_tile_columns,
-                                min_log2_tiles, max_log2_tiles);
-
-  cm->tile_columns = 1 << cm->log2_tile_columns;
-  cm->tile_rows = 1 << cm->log2_tile_rows;
+  cm->log2_tile_cols = clamp(cpi->oxcf.tile_columns,
+                             min_log2_tile_cols, max_log2_tile_cols);
+  cm->log2_tile_rows = cpi->oxcf.tile_rows;
 }
 
 static void init_config(VP9_PTR ptr, VP9_CONFIG *oxcf) {
--- a/vp9/encoder/vp9_segmentation.c
+++ b/vp9/encoder/vp9_segmentation.c
@@ -216,8 +216,7 @@
   int no_pred_cost;
   int t_pred_cost = INT_MAX;
 
-  int i;
-  int tile_col, mi_row, mi_col;
+  int i, tile_col, mi_row, mi_col;
 
   int temporal_predictor_count[PREDICTION_PROBS][2];
   int no_pred_segcounts[MAX_MB_SEGMENTS];
@@ -241,18 +240,16 @@
 
   // First of all generate stats regarding how well the last segment map
   // predicts this one
-  for (tile_col = 0; tile_col < cm->tile_columns; tile_col++) {
+  for (tile_col = 0; tile_col < 1 << cm->log2_tile_cols; tile_col++) {
     vp9_get_tile_col_offsets(cm, tile_col);
     mi_ptr = cm->mi + cm->cur_tile_mi_col_start;
     for (mi_row = 0; mi_row < cm->mi_rows;
          mi_row += 8, mi_ptr += 8 * mis) {
       mi = mi_ptr;
-      for (mi_col = cm->cur_tile_mi_col_start;
-           mi_col < cm->cur_tile_mi_col_end;
-           mi_col += 8, mi += 8) {
+      for (mi_col = cm->cur_tile_mi_col_start; mi_col < cm->cur_tile_mi_col_end;
+           mi_col += 8, mi += 8)
         count_segs_sb(cpi, mi, no_pred_segcounts, temporal_predictor_count,
                       t_unpred_seg_counts, mi_row, mi_col, BLOCK_SIZE_SB64X64);
-      }
     }
   }