ref: 3b47e059086e8e9c1e39daf2a6950d4a79a853b5
parent: 1bea58e4a8bbe3b63dd726563db0e2569b63057b
parent: 6b00202f1ba30f3546d6e6f277ec396cf45a76d0
author: James Zern <[email protected]>
date: Tue Oct 29 13:34:56 EDT 2013
Merge "vp9/decode: add get_tile()"
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -823,6 +823,27 @@
cm->log2_tile_rows += vp9_rb_read_bit(rb);
}
+// Reads the next tile returning its size and adjusting '*data' accordingly
+// based on 'is_last'.
+static size_t get_tile(const uint8_t *const data_end,
+ int is_last,
+ struct vpx_internal_error_info *error_info,
+ const uint8_t **data) {
+ size_t size;
+
+ if (!is_last) {
+ if (!read_is_valid(*data, 4, data_end))
+ vpx_internal_error(error_info, VPX_CODEC_CORRUPT_FRAME,
+ "Truncated packet or corrupt tile length");
+
+ size = read_be32(*data);
+ *data += 4;
+ } else {
+ size = data_end - *data;
+ }
+ return size;
+}
+
static const uint8_t *decode_tiles(VP9D_COMP *pbi, const uint8_t *data) {
vp9_reader residual_bc;
@@ -848,21 +869,16 @@
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
+ // pre-initialize the offsets, we're going to decode in inverse order
data_ptr2[0][0] = data;
for (tile_row = 0; tile_row < tile_rows; tile_row++) {
- if (tile_row) {
- 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 = 0; tile_col < tile_cols; tile_col++) {
+ const int last_tile =
+ tile_row == tile_rows - 1 && tile_col == tile_cols - 1;
+ const size_t size = get_tile(data_end, last_tile, &cm->error, &data);
+ data_ptr2[tile_row][tile_col] = data;
+ data += size;
}
-
- 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] =
- data_ptr2[tile_row][tile_col - 1] + size;
- }
}
for (tile_row = 0; tile_row < tile_rows; tile_row++) {
@@ -881,26 +897,14 @@
}
residual_bc = bc_bak;
} else {
- int has_more;
-
for (tile_row = 0; tile_row < tile_rows; tile_row++) {
for (tile_col = 0; tile_col < tile_cols; tile_col++) {
+ const int last_tile =
+ tile_row == tile_rows - 1 && tile_col == tile_cols - 1;
+ const size_t size = get_tile(data_end, last_tile, &cm->error, &data);
TileInfo tile;
- size_t size;
vp9_tile_init(&tile, cm, tile_row, tile_col);
-
- has_more = tile_col < tile_cols - 1 || tile_row < tile_rows - 1;
- if (has_more) {
- if (!read_is_valid(data, 4, data_end))
- vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
- "Truncated packet or corrupt tile length");
-
- size = read_be32(data);
- data += 4;
- } else {
- size = data_end - data;
- }
setup_token_decoder(data, data_end, size, &cm->error, &residual_bc);
setup_tile_context(pbi, xd, tile_col);