summaryrefslogtreecommitdiff
path: root/vp9
diff options
context:
space:
mode:
Diffstat (limited to 'vp9')
-rw-r--r--vp9/common/vp9_blockd.h11
-rw-r--r--vp9/common/vp9_findnearmv.h15
-rw-r--r--vp9/common/vp9_mbpitch.c8
-rw-r--r--vp9/decoder/vp9_decodemv.c15
-rw-r--r--vp9/decoder/vp9_decodframe.c205
-rw-r--r--vp9/decoder/vp9_detokenize.c283
-rw-r--r--vp9/encoder/vp9_rdopt.c6
7 files changed, 191 insertions, 352 deletions
diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h
index d0c77077e..d372325a6 100644
--- a/vp9/common/vp9_blockd.h
+++ b/vp9/common/vp9_blockd.h
@@ -237,6 +237,14 @@ static INLINE int mb_height_log2(BLOCK_SIZE_TYPE sb_type) {
}
}
+typedef enum {
+ BLOCK_4X4_LG2 = 0,
+ BLOCK_8X8_LG2 = 2,
+ BLOCK_16X16_LG2 = 4,
+ BLOCK_32X32_LG2 = 6,
+ BLOCK_64X64_LG2 = 8
+} BLOCK_SIZE_LG2;
+
typedef struct {
MB_PREDICTION_MODE mode, uv_mode;
#if CONFIG_COMP_INTERINTRA_PRED
@@ -321,6 +329,9 @@ struct mb_plane {
DECLARE_ALIGNED(16, int16_t, qcoeff[64 * 64]);
DECLARE_ALIGNED(16, int16_t, dqcoeff[64 * 64]);
DECLARE_ALIGNED(16, uint16_t, eobs[256]);
+ PLANE_TYPE plane_type;
+ int subsampling_x;
+ int subsampling_y;
};
#define BLOCK_OFFSET(x, i, n) ((x) + (i) * (n))
diff --git a/vp9/common/vp9_findnearmv.h b/vp9/common/vp9_findnearmv.h
index 6887b044f..1c96f0ad0 100644
--- a/vp9/common/vp9_findnearmv.h
+++ b/vp9/common/vp9_findnearmv.h
@@ -17,8 +17,8 @@
#include "vp9/common/vp9_treecoder.h"
#include "vp9/common/vp9_onyxc_int.h"
-#define LEFT_TOP_MARGIN (16 << 3)
-#define RIGHT_BOTTOM_MARGIN (16 << 3)
+#define LEFT_TOP_MARGIN ((VP9BORDERINPIXELS - VP9_INTERP_EXTEND) << 3)
+#define RIGHT_BOTTOM_MARGIN ((VP9BORDERINPIXELS - VP9_INTERP_EXTEND) << 3)
/* check a list of motion vectors by sad score using a number rows of pixels
* above and a number cols of pixels in the left to select the one with best
@@ -43,7 +43,7 @@ static void mv_bias(int refmb_ref_frame_sign_bias, int refframe,
mvp->as_mv = xmv;
}
-
+// TODO(jingning): this mv clamping function should be block size dependent.
static void clamp_mv(int_mv *mv,
int mb_to_left_edge,
int mb_to_right_edge,
@@ -59,12 +59,19 @@ static void clamp_mv(int_mv *mv,
mb_to_bottom_edge : mv->as_mv.row;
}
-static void clamp_mv2(int_mv *mv, const MACROBLOCKD *xd) {
+static int clamp_mv2(int_mv *mv, const MACROBLOCKD *xd) {
+ int_mv tmp_mv;
+ int mv_clampped = 0;
+ tmp_mv.as_int = mv->as_int;
clamp_mv(mv,
xd->mb_to_left_edge - LEFT_TOP_MARGIN,
xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN,
xd->mb_to_top_edge - LEFT_TOP_MARGIN,
xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN);
+ if (tmp_mv.as_int != mv->as_int)
+ mv_clampped = 1;
+
+ return mv_clampped;
}
static unsigned int check_mv_bounds(int_mv *mv,
diff --git a/vp9/common/vp9_mbpitch.c b/vp9/common/vp9_mbpitch.c
index b357c9ac9..aba950e9a 100644
--- a/vp9/common/vp9_mbpitch.c
+++ b/vp9/common/vp9_mbpitch.c
@@ -70,7 +70,7 @@ static void setup_macroblock(MACROBLOCKD *mb, BLOCKSET bs) {
}
void vp9_setup_block_dptrs(MACROBLOCKD *mb) {
- int r, c;
+ int r, c, i;
BLOCKD *blockd = mb->block;
for (r = 0; r < 4; r++) {
@@ -99,6 +99,12 @@ void vp9_setup_block_dptrs(MACROBLOCKD *mb) {
blockd[to].predictor = &mb->predictor[from];
}
}
+
+ for (i = 0; i < MAX_MB_PLANE; i++) {
+ mb->plane[i].plane_type = i ? PLANE_TYPE_UV : PLANE_TYPE_Y_WITH_DC;
+ mb->plane[i].subsampling_x = !!i;
+ mb->plane[i].subsampling_y = !!i;
+ }
}
void vp9_build_block_doffsets(MACROBLOCKD *mb) {
diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c
index e033a2435..f081e7174 100644
--- a/vp9/decoder/vp9_decodemv.c
+++ b/vp9/decoder/vp9_decodemv.c
@@ -1026,11 +1026,6 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
case NEWMV:
process_mv(bc, &mv->as_mv, &best_mv.as_mv, nmvc, &cm->fc.NMVcount,
xd->allow_high_precision_mv);
-
- // Don't need to check this on NEARMV and NEARESTMV modes
- // since those modes clamp the MV. The NEWMV mode does not,
- // so signal to the prediction stage whether special
- // handling may be required.
mbmi->need_to_clamp_mvs = check_mv_bounds(mv,
mb_to_left_edge,
mb_to_right_edge,
@@ -1040,11 +1035,11 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
if (mbmi->second_ref_frame > 0) {
process_mv(bc, &mbmi->mv[1].as_mv, &best_mv_second.as_mv, nmvc,
&cm->fc.NMVcount, xd->allow_high_precision_mv);
- mbmi->need_to_clamp_secondmv |= check_mv_bounds(&mbmi->mv[1],
- mb_to_left_edge,
- mb_to_right_edge,
- mb_to_top_edge,
- mb_to_bottom_edge);
+ mbmi->need_to_clamp_secondmv = check_mv_bounds(&mbmi->mv[1],
+ mb_to_left_edge,
+ mb_to_right_edge,
+ mb_to_top_edge,
+ mb_to_bottom_edge);
}
break;
default:
diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c
index 9ad060fe5..965310e7d 100644
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -53,8 +53,8 @@ static int read_le32(const uint8_t *p) {
}
// len == 0 is not allowed
-static int read_is_valid(const unsigned char *start, size_t len,
- const unsigned char *end) {
+static int read_is_valid(const uint8_t *start, size_t len,
+ const uint8_t *end) {
return start + len > start && start + len <= end;
}
@@ -227,23 +227,6 @@ static void skip_recon_mb(VP9D_COMP *pbi, MACROBLOCKD *xd,
static void decode_16x16(VP9D_COMP *pbi, MACROBLOCKD *xd,
BOOL_DECODER* const bc) {
const TX_TYPE tx_type = get_tx_type_16x16(xd, 0);
-#if 0 // def DEC_DEBUG
- if (dec_debug) {
- int i;
- printf("\n");
- printf("qcoeff 16x16\n");
- for (i = 0; i < 400; i++) {
- printf("%3d ", xd->qcoeff[i]);
- if (i % 16 == 15) printf("\n");
- }
- printf("\n");
- printf("predictor\n");
- for (i = 0; i < 400; i++) {
- printf("%3d ", xd->predictor[i]);
- if (i % 16 == 15) printf("\n");
- }
- }
-#endif
if (tx_type != DCT_DCT) {
vp9_ht_dequant_idct_add_16x16_c(tx_type, xd->plane[0].qcoeff,
xd->block[0].dequant, xd->predictor,
@@ -266,21 +249,11 @@ static void decode_16x16(VP9D_COMP *pbi, MACROBLOCKD *xd,
static void decode_8x8(VP9D_COMP *pbi, MACROBLOCKD *xd,
BOOL_DECODER* const bc) {
- // First do Y
+ const MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
+ // luma
// if the first one is DCT_DCT assume all the rest are as well
TX_TYPE tx_type = get_tx_type_8x8(xd, 0);
-#if 0 // def DEC_DEBUG
- if (dec_debug) {
- int i;
- printf("\n");
- printf("qcoeff 8x8\n");
- for (i = 0; i < 384; i++) {
- printf("%3d ", xd->qcoeff[i]);
- if (i % 16 == 15) printf("\n");
- }
- }
-#endif
- if (tx_type != DCT_DCT || xd->mode_info_context->mbmi.mode == I8X8_PRED) {
+ if (tx_type != DCT_DCT || mode == I8X8_PRED) {
int i;
for (i = 0; i < 4; i++) {
int ib = vp9_i8x8_block[i];
@@ -291,7 +264,7 @@ static void decode_8x8(VP9D_COMP *pbi, MACROBLOCKD *xd,
uint8_t *dst = *(xd->block[ib].base_dst) + xd->block[ib].dst;
int stride = xd->dst.y_stride;
BLOCKD *b = &xd->block[ib];
- if (xd->mode_info_context->mbmi.mode == I8X8_PRED) {
+ if (mode == I8X8_PRED) {
int i8x8mode = b->bmi.as_mode.first;
vp9_intra8x8_predict(xd, b, i8x8mode, b->predictor);
}
@@ -313,8 +286,8 @@ static void decode_8x8(VP9D_COMP *pbi, MACROBLOCKD *xd,
xd);
}
- // Now do UV
- if (xd->mode_info_context->mbmi.mode == I8X8_PRED) {
+ // chroma
+ if (mode == I8X8_PRED) {
int i;
for (i = 0; i < 4; i++) {
int ib = vp9_i8x8_block[i];
@@ -335,7 +308,7 @@ static void decode_8x8(VP9D_COMP *pbi, MACROBLOCKD *xd,
*(b->base_dst) + b->dst, 8, b->dst_stride,
xd->plane[2].eobs[i]);
}
- } else if (xd->mode_info_context->mbmi.mode == SPLITMV) {
+ } else if (mode == SPLITMV) {
xd->itxm_add_uv_block(xd->plane[1].qcoeff, xd->block[16].dequant,
xd->predictor + 16 * 16, xd->dst.u_buffer,
xd->dst.uv_stride, xd->plane[1].eobs);
@@ -351,35 +324,13 @@ static void decode_8x8(VP9D_COMP *pbi, MACROBLOCKD *xd,
xd->predictor + 16 * 16 + 64, xd->dst.v_buffer, 8,
xd->dst.uv_stride, xd->plane[2].eobs[0]);
}
-#if 0 // def DEC_DEBUG
- if (dec_debug) {
- int i;
- printf("\n");
- printf("predictor\n");
- for (i = 0; i < 384; i++) {
- printf("%3d ", xd->predictor[i]);
- if (i % 16 == 15) printf("\n");
- }
- }
-#endif
}
static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd,
BOOL_DECODER* const bc) {
TX_TYPE tx_type;
int i = 0;
- MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
-#if 0 // def DEC_DEBUG
- if (dec_debug) {
- int i;
- printf("\n");
- printf("predictor\n");
- for (i = 0; i < 384; i++) {
- printf("%3d ", xd->predictor[i]);
- if (i % 16 == 15) printf("\n");
- }
- }
-#endif
+ const MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
if (mode == I8X8_PRED) {
for (i = 0; i < 4; i++) {
int ib = vp9_i8x8_block[i];
@@ -468,23 +419,6 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd,
xd->predictor + 16 * 16 + 64, xd->dst.v_buffer,
xd->dst.uv_stride, xd->plane[2].eobs);
} else {
-#if 0 // def DEC_DEBUG
- if (dec_debug) {
- int i;
- printf("\n");
- printf("qcoeff 4x4\n");
- for (i = 0; i < 400; i++) {
- printf("%3d ", xd->qcoeff[i]);
- if (i % 16 == 15) printf("\n");
- }
- printf("\n");
- printf("predictor\n");
- for (i = 0; i < 400; i++) {
- printf("%3d ", xd->predictor[i]);
- if (i % 16 == 15) printf("\n");
- }
- }
-#endif
for (i = 0; i < 16; i++) {
BLOCKD *b = &xd->block[i];
tx_type = get_tx_type_4x4(xd, i);
@@ -990,6 +924,8 @@ static void set_refs(VP9D_COMP *pbi, int block_size, int mb_row, int mb_col) {
// Select the appropriate reference frame for this MB
const int second_fb_idx = cm->active_ref_idx[mbmi->second_ref_frame - 1];
const YV12_BUFFER_CONFIG *second_cfg = &cm->yv12_fb[second_fb_idx];
+ xd->scale_factor[1] = cm->active_ref_scale[mbmi->second_ref_frame - 1];
+ xd->scale_factor_uv[1] = cm->active_ref_scale[mbmi->second_ref_frame - 1];
setup_pred_block(&xd->second_pre, second_cfg, mb_row, mb_col,
&xd->scale_factor[1], &xd->scale_factor_uv[1]);
xd->corrupted |= second_cfg->corrupted;
@@ -998,9 +934,9 @@ static void set_refs(VP9D_COMP *pbi, int block_size, int mb_row, int mb_col) {
}
/* Decode a row of Superblocks (2x2 region of MBs) */
-static void decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc,
- int mb_row, MACROBLOCKD *xd,
- BOOL_DECODER* const bc) {
+static void decode_sb_row(VP9D_COMP *pbi, int mb_row, vp9_reader* r) {
+ VP9_COMMON *const pc = &pbi->common;
+ MACROBLOCKD *const xd = &pbi->mb;
int mb_col;
// For a SB there are 2 left contexts, each pertaining to a MB row within
@@ -1008,72 +944,52 @@ static void decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc,
for (mb_col = pc->cur_tile_mb_col_start;
mb_col < pc->cur_tile_mb_col_end; mb_col += 4) {
- if (vp9_read(bc, pc->prob_sb64_coded)) {
-#ifdef DEC_DEBUG
- dec_debug = (pc->current_video_frame == 11 && pc->show_frame &&
- mb_row == 8 && mb_col == 0);
- if (dec_debug)
- printf("Debug Decode SB64\n");
-#endif
+ if (vp9_read(r, pc->prob_sb64_coded)) {
+ // SB64 decoding
set_offsets(pbi, 64, mb_row, mb_col);
- vp9_decode_mb_mode_mv(pbi, xd, mb_row, mb_col, bc);
+ vp9_decode_mb_mode_mv(pbi, xd, mb_row, mb_col, r);
set_refs(pbi, 64, mb_row, mb_col);
- decode_sb64(pbi, xd, mb_row, mb_col, bc);
- xd->corrupted |= bool_error(bc);
+ decode_sb64(pbi, xd, mb_row, mb_col, r);
+ xd->corrupted |= bool_error(r);
} else {
+ // not SB64
int j;
-
for (j = 0; j < 4; j++) {
- const int x_idx_sb = (j & 1) << 1, y_idx_sb = j & 2;
+ const int x_idx_sb = mb_col + 2 * (j % 2);
+ const int y_idx_sb = mb_row + 2 * (j / 2);
- if (mb_row + y_idx_sb >= pc->mb_rows ||
- mb_col + x_idx_sb >= pc->mb_cols) {
- // MB lies outside frame, skip on to next
- continue;
- }
+ if (y_idx_sb >= pc->mb_rows || x_idx_sb >= pc->mb_cols)
+ continue; // MB lies outside frame, skip on to next
xd->sb_index = j;
- if (vp9_read(bc, pc->prob_sb32_coded)) {
-#ifdef DEC_DEBUG
- dec_debug = (pc->current_video_frame == 11 && pc->show_frame &&
- mb_row + y_idx_sb == 8 && mb_col + x_idx_sb == 0);
- if (dec_debug)
- printf("Debug Decode SB32\n");
-#endif
- set_offsets(pbi, 32, mb_row + y_idx_sb, mb_col + x_idx_sb);
- vp9_decode_mb_mode_mv(pbi,
- xd, mb_row + y_idx_sb, mb_col + x_idx_sb, bc);
- set_refs(pbi, 32, mb_row + y_idx_sb, mb_col + x_idx_sb);
- decode_sb32(pbi, xd, mb_row + y_idx_sb, mb_col + x_idx_sb, bc);
- xd->corrupted |= bool_error(bc);
+ if (vp9_read(r, pc->prob_sb32_coded)) {
+ // SB32 decoding
+ set_offsets(pbi, 32, y_idx_sb, x_idx_sb);
+ vp9_decode_mb_mode_mv(pbi, xd, y_idx_sb, x_idx_sb, r);
+ set_refs(pbi, 32, y_idx_sb, x_idx_sb);
+ decode_sb32(pbi, xd, y_idx_sb, x_idx_sb, r);
+ xd->corrupted |= bool_error(r);
} else {
- int i;
-
+ // not SB32
// Process the 4 MBs within the SB in the order:
// top-left, top-right, bottom-left, bottom-right
+ int i;
for (i = 0; i < 4; i++) {
- const int x_idx = x_idx_sb + (i & 1), y_idx = y_idx_sb + (i >> 1);
+ const int x_idx_mb = x_idx_sb + (i % 2);
+ const int y_idx_mb = y_idx_sb + (i / 2);
- if (mb_row + y_idx >= pc->mb_rows ||
- mb_col + x_idx >= pc->mb_cols) {
- // MB lies outside frame, skip on to next
- continue;
- }
-#ifdef DEC_DEBUG
- dec_debug = (pc->current_video_frame == 11 && pc->show_frame &&
- mb_row + y_idx == 8 && mb_col + x_idx == 0);
- if (dec_debug)
- printf("Debug Decode MB\n");
-#endif
+ if (y_idx_mb >= pc->mb_rows || x_idx_mb >= pc->mb_cols)
+ continue; // MB lies outside frame, skip on to next
- set_offsets(pbi, 16, mb_row + y_idx, mb_col + x_idx);
xd->mb_index = i;
- vp9_decode_mb_mode_mv(pbi, xd, mb_row + y_idx, mb_col + x_idx, bc);
- set_refs(pbi, 16, mb_row + y_idx, mb_col + x_idx);
- decode_mb(pbi, xd, mb_row + y_idx, mb_col + x_idx, bc);
- xd->corrupted |= bool_error(bc);
+ // MB decoding
+ set_offsets(pbi, 16, y_idx_mb, x_idx_mb);
+ vp9_decode_mb_mode_mv(pbi, xd, y_idx_mb, x_idx_mb, r);
+ set_refs(pbi, 16, y_idx_mb, x_idx_mb);
+ decode_mb(pbi, xd, y_idx_mb, x_idx_mb, r);
+ xd->corrupted |= bool_error(r);
}
}
}
@@ -1083,25 +999,21 @@ static void decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc,
static void setup_token_decoder(VP9D_COMP *pbi,
- const unsigned char *cx_data,
- BOOL_DECODER* const bool_decoder) {
+ const uint8_t *data,
+ vp9_reader *r) {
VP9_COMMON *pc = &pbi->common;
- const uint8_t *user_data_end = pbi->source + pbi->source_sz;
- const uint8_t *partition = cx_data;
- ptrdiff_t bytes_left = user_data_end - partition;
- ptrdiff_t partition_size = bytes_left;
+ const uint8_t *data_end = pbi->source + pbi->source_sz;
+ const size_t partition_size = data_end - data;
// Validate the calculated partition length. If the buffer
// described by the partition can't be fully read, then restrict
// it to the portion that can be (for EC mode) or throw an error.
- if (!read_is_valid(partition, partition_size, user_data_end)) {
+ if (!read_is_valid(data, partition_size, data_end))
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
"Truncated packet or corrupt partition "
"%d length", 1);
- }
- if (vp9_start_decode(bool_decoder,
- partition, (unsigned int)partition_size))
+ if (vp9_start_decode(r, data, partition_size))
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate bool decoder %d", 1);
}
@@ -1533,7 +1445,6 @@ static void decode_tiles(VP9D_COMP *pbi,
const uint8_t *data, int first_partition_size,
BOOL_DECODER *header_bc, BOOL_DECODER *residual_bc) {
VP9_COMMON *const pc = &pbi->common;
- MACROBLOCKD *const xd = &pbi->mb;
const uint8_t *data_ptr = data + first_partition_size;
int tile_row, tile_col, delta_log2_tiles;
@@ -1587,7 +1498,7 @@ static void decode_tiles(VP9D_COMP *pbi,
// Decode a row of superblocks
for (mb_row = pc->cur_tile_mb_row_start;
mb_row < pc->cur_tile_mb_row_end; mb_row += 4) {
- decode_sb_row(pbi, pc, mb_row, xd, residual_bc);
+ decode_sb_row(pbi, mb_row, residual_bc);
}
if (tile_row == pc->tile_rows - 1 && tile_col == n_cols - 1)
@@ -1612,7 +1523,7 @@ static void decode_tiles(VP9D_COMP *pbi,
// Decode a row of superblocks
for (mb_row = pc->cur_tile_mb_row_start;
mb_row < pc->cur_tile_mb_row_end; mb_row += 4) {
- decode_sb_row(pbi, pc, mb_row, xd, residual_bc);
+ decode_sb_row(pbi, mb_row, residual_bc);
}
if (has_more) {
@@ -1630,7 +1541,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
MACROBLOCKD *const xd = &pbi->mb;
const uint8_t *data = pbi->source;
const uint8_t *data_end = data + pbi->source_sz;
- ptrdiff_t first_partition_length_in_bytes = 0;
+ size_t first_partition_size = 0;
int i, corrupt_tokens = 0;
// printf("Decoding frame %d\n", pc->current_video_frame);
@@ -1647,9 +1558,9 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
pc->version = (data[0] >> 1) & 7;
pc->show_frame = (data[0] >> 4) & 1;
scaling_active = (data[0] >> 5) & 1;
- first_partition_length_in_bytes = read_le16(data + 1);
+ first_partition_size = read_le16(data + 1);
- if (!read_is_valid(data, first_partition_length_in_bytes, data_end))
+ if (!read_is_valid(data, first_partition_size, data_end))
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
"Truncated packet or corrupt partition 0 length");
@@ -1683,8 +1594,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
pc->width, pc->height,
VP9BORDERINPIXELS);
- if (vp9_start_decode(&header_bc, data,
- (unsigned int)first_partition_length_in_bytes))
+ if (vp9_start_decode(&header_bc, data, first_partition_size))
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate bool decoder 0");
@@ -1858,8 +1768,7 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
vp9_decode_mode_mvs_init(pbi, &header_bc);
- decode_tiles(pbi, data, first_partition_length_in_bytes,
- &header_bc, &residual_bc);
+ decode_tiles(pbi, data, first_partition_size, &header_bc, &residual_bc);
corrupt_tokens |= xd->corrupted;
// keep track of the last coded dimensions
diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c
index a4ada2b7e..9077fcde1 100644
--- a/vp9/decoder/vp9_detokenize.c
+++ b/vp9/decoder/vp9_detokenize.c
@@ -380,182 +380,122 @@ static int get_eob(MACROBLOCKD* const xd, int segment_id, int eob_max) {
return vp9_get_segdata(xd, segment_id, SEG_LVL_SKIP) ? 0 : eob_max;
}
-static INLINE int decode_sb(VP9D_COMP* const pbi,
- MACROBLOCKD* const xd,
- BOOL_DECODER* const bc,
- int offset, int count, int inc,
- int eob_max, TX_SIZE tx_size) {
- const int segment_id = xd->mode_info_context->mbmi.segment_id;
- const int seg_eob = get_eob(xd, segment_id, eob_max);
+/* TODO(jkoleszar): Probably best to remove instances that require this,
+ * as the data likely becomes per-plane and stored in the per-plane structures.
+ * This is a stub to work with the existing code.
+ */
+static INLINE int block_idx_4x4(MACROBLOCKD* const xd, int block_size_b,
+ int plane, int i) {
+ const int luma_blocks = 1 << block_size_b;
+ assert(xd->plane[0].subsampling_x == 0);
+ assert(xd->plane[0].subsampling_y == 0);
+ assert(xd->plane[1].subsampling_x == 1);
+ assert(xd->plane[1].subsampling_y == 1);
+ assert(xd->plane[2].subsampling_x == 1);
+ assert(xd->plane[2].subsampling_y == 1);
+ return plane == 0 ? i :
+ plane == 1 ? luma_blocks + i :
+ luma_blocks * 5 / 4 + i;
+}
+
+static INLINE int decode_block_plane(VP9D_COMP* const pbi,
+ MACROBLOCKD* const xd,
+ BOOL_DECODER* const bc,
+ BLOCK_SIZE_LG2 block_size,
+ int segment_id,
+ int plane,
+ int is_split) {
+ // block and transform sizes, in number of 4x4 blocks log 2 ("*_b")
+ // 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8
+ const TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
+ const BLOCK_SIZE_LG2 block_size_b = block_size;
+ const BLOCK_SIZE_LG2 txfrm_size_b = tx_size * 2;
+
+ // subsampled size of the block
+ const int ss_sum = xd->plane[plane].subsampling_x +
+ xd->plane[plane].subsampling_y;
+ const BLOCK_SIZE_LG2 ss_block_size = block_size_b - ss_sum;
+
+ // size of the transform to use. scale the transform down if it's larger
+ // than the size of the subsampled data, or forced externally by the mb mode.
+ const int ss_max = MAX(xd->plane[plane].subsampling_x,
+ xd->plane[plane].subsampling_y);
+ const BLOCK_SIZE_LG2 ss_txfrm_size = txfrm_size_b > ss_block_size || is_split
+ ? txfrm_size_b - ss_max * 2
+ : txfrm_size_b;
+ const TX_SIZE ss_tx_size = ss_txfrm_size / 2;
+
+ // TODO(jkoleszar): 1 may not be correct here with larger chroma planes.
+ const int inc = is_split ? 1 : (1 << ss_txfrm_size);
+
+ // find the maximum eob for this transform size, adjusted by segment
+ const int seg_eob = get_eob(xd, segment_id, 16 << ss_txfrm_size);
+
int i, eobtotal = 0;
- assert(count == offset * 3 / 2);
+ assert(txfrm_size_b <= block_size_b);
+ assert(ss_txfrm_size <= ss_block_size);
- // luma blocks
- for (i = 0; i < offset; i += inc) {
- const int c = decode_coefs(pbi, xd, bc, i, PLANE_TYPE_Y_WITH_DC, seg_eob,
- BLOCK_OFFSET(xd->plane[0].qcoeff, i, 16),
- tx_size);
- xd->plane[0].eobs[i] = c;
- eobtotal += c;
- }
+ // step through the block by the size of the transform in use.
+ for (i = 0; i < (1 << ss_block_size); i += inc) {
+ const int block_idx = block_idx_4x4(xd, block_size_b, plane, i);
- // chroma blocks
- for (i = offset; i < offset * 5 / 4; i += inc) {
- const int b = i - offset;
- const int c = decode_coefs(pbi, xd, bc, i, PLANE_TYPE_UV, seg_eob,
- BLOCK_OFFSET(xd->plane[1].qcoeff, b, 16),
- tx_size);
- xd->plane[1].eobs[b] = c;
+ const int c = decode_coefs(pbi, xd, bc, block_idx,
+ xd->plane[plane].plane_type, seg_eob,
+ BLOCK_OFFSET(xd->plane[plane].qcoeff, i, 16),
+ ss_tx_size);
+ xd->plane[plane].eobs[i] = c;
eobtotal += c;
}
- for (i = offset * 5 / 4; i < count; i += inc) {
- const int b = i - offset * 5 / 4;
- const int c = decode_coefs(pbi, xd, bc, i, PLANE_TYPE_UV, seg_eob,
- BLOCK_OFFSET(xd->plane[2].qcoeff, b, 16),
- tx_size);
- xd->plane[2].eobs[b] = c;
- eobtotal += c;
- }
-
return eobtotal;
}
-int vp9_decode_sb_tokens(VP9D_COMP* const pbi,
- MACROBLOCKD* const xd,
- BOOL_DECODER* const bc) {
- switch (xd->mode_info_context->mbmi.txfm_size) {
- case TX_32X32: {
- // 32x32 luma block
- const int segment_id = xd->mode_info_context->mbmi.segment_id;
- int eobtotal = 0, seg_eob;
- int c = decode_coefs(pbi, xd, bc, 0, PLANE_TYPE_Y_WITH_DC,
- get_eob(xd, segment_id, 1024),
- xd->plane[0].qcoeff, TX_32X32);
- xd->plane[0].eobs[0] = c;
- eobtotal += c;
-
- // 16x16 chroma blocks
- seg_eob = get_eob(xd, segment_id, 256);
-
- c = decode_coefs(pbi, xd, bc, 64, PLANE_TYPE_UV, seg_eob,
- xd->plane[1].qcoeff, TX_16X16);
- xd->plane[1].eobs[0] = c;
- eobtotal += c;
- c = decode_coefs(pbi, xd, bc, 80, PLANE_TYPE_UV, seg_eob,
- xd->plane[2].qcoeff, TX_16X16);
- xd->plane[2].eobs[0] = c;
- eobtotal += c;
- return eobtotal;
- }
- case TX_16X16:
- return decode_sb(pbi, xd, bc, 64, 96, 16, 16 * 16, TX_16X16);
- case TX_8X8:
- return decode_sb(pbi, xd, bc, 64, 96, 4, 8 * 8, TX_8X8);
- case TX_4X4:
- return decode_sb(pbi, xd, bc, 64, 96, 1, 4 * 4, TX_4X4);
- default:
- assert(0);
- return 0;
+static INLINE int decode_blocks_helper(VP9D_COMP* const pbi,
+ MACROBLOCKD* const xd,
+ BOOL_DECODER* const bc,
+ int block_size,
+ int is_split_chroma) {
+ const int segment_id = xd->mode_info_context->mbmi.segment_id;
+ int plane, eobtotal = 0;
+
+ for (plane = 0; plane < MAX_MB_PLANE; plane++) {
+ const int is_split = is_split_chroma &&
+ xd->plane[plane].plane_type == PLANE_TYPE_UV;
+ eobtotal += decode_block_plane(pbi, xd, bc, block_size, segment_id,
+ plane, is_split);
}
+ return eobtotal;
+}
+
+static INLINE int decode_blocks(VP9D_COMP* const pbi,
+ MACROBLOCKD* const xd,
+ BOOL_DECODER* const bc,
+ int block_size) {
+ const MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
+ const TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
+ return decode_blocks_helper(pbi, xd, bc, block_size,
+ tx_size == TX_8X8 && (mode == I8X8_PRED || mode == SPLITMV));
}
int vp9_decode_sb64_tokens(VP9D_COMP* const pbi,
MACROBLOCKD* const xd,
BOOL_DECODER* const bc) {
- switch (xd->mode_info_context->mbmi.txfm_size) {
- case TX_32X32:
- return decode_sb(pbi, xd, bc, 256, 384, 64, 32 * 32, TX_32X32);
- case TX_16X16:
- return decode_sb(pbi, xd, bc, 256, 384, 16, 16 * 16, TX_16X16);
- case TX_8X8:
- return decode_sb(pbi, xd, bc, 256, 384, 4, 8 * 8, TX_8X8);
- case TX_4X4:
- return decode_sb(pbi, xd, bc, 256, 384, 1, 4 * 4, TX_4X4);
- default:
- assert(0);
- return 0;
- }
+ return decode_blocks(pbi, xd, bc, BLOCK_64X64_LG2);
}
-static int vp9_decode_mb_tokens_16x16(VP9D_COMP* const pbi,
- MACROBLOCKD* const xd,
- BOOL_DECODER* const bc) {
- const int segment_id = xd->mode_info_context->mbmi.segment_id;
- int eobtotal = 0, seg_eob;
-
- // Luma block
- int c = decode_coefs(pbi, xd, bc, 0, PLANE_TYPE_Y_WITH_DC,
- get_eob(xd, segment_id, 256),
- xd->plane[0].qcoeff, TX_16X16);
- xd->plane[0].eobs[0] = c;
- eobtotal += c;
-
- // 8x8 chroma blocks
- seg_eob = get_eob(xd, segment_id, 64);
-
- c = decode_coefs(pbi, xd, bc, 16, PLANE_TYPE_UV,
- seg_eob, xd->plane[1].qcoeff, TX_8X8);
- xd->plane[1].eobs[0] = c;
- eobtotal += c;
- c = decode_coefs(pbi, xd, bc, 20, PLANE_TYPE_UV,
- seg_eob, xd->plane[2].qcoeff, TX_8X8);
- xd->plane[2].eobs[0] = c;
- eobtotal += c;
- return eobtotal;
+int vp9_decode_sb_tokens(VP9D_COMP* const pbi,
+ MACROBLOCKD* const xd,
+ BOOL_DECODER* const bc) {
+ return decode_blocks(pbi, xd, bc, BLOCK_32X32_LG2);
}
-static int vp9_decode_mb_tokens_8x8(VP9D_COMP* const pbi,
- MACROBLOCKD* const xd,
- BOOL_DECODER* const bc) {
- int i, eobtotal = 0;
- const int segment_id = xd->mode_info_context->mbmi.segment_id;
-
- // luma blocks
- int seg_eob = get_eob(xd, segment_id, 64);
- for (i = 0; i < 16; i += 4) {
- const int c = decode_coefs(pbi, xd, bc, i, PLANE_TYPE_Y_WITH_DC, seg_eob,
- BLOCK_OFFSET(xd->plane[0].qcoeff, i, 16),
- TX_8X8);
- xd->plane[0].eobs[i] = c;
- eobtotal += c;
- }
-
- // chroma blocks
- if (xd->mode_info_context->mbmi.mode == I8X8_PRED ||
- xd->mode_info_context->mbmi.mode == SPLITMV) {
- // use 4x4 transform for U, V components in I8X8/splitmv prediction mode
- seg_eob = get_eob(xd, segment_id, 16);
- for (i = 16; i < 20; i++) {
- const int c = decode_coefs(pbi, xd, bc, i, PLANE_TYPE_UV, seg_eob,
- BLOCK_OFFSET(xd->plane[1].qcoeff, i - 16, 16),
- TX_4X4);
- xd->plane[1].eobs[i - 16] = c;
- eobtotal += c;
- }
- for (i = 20; i < 24; i++) {
- const int c = decode_coefs(pbi, xd, bc, i, PLANE_TYPE_UV, seg_eob,
- BLOCK_OFFSET(xd->plane[2].qcoeff, i - 20, 16),
- TX_4X4);
- xd->plane[2].eobs[i - 20] = c;
- eobtotal += c;
- }
- } else {
- int c;
-
- c = decode_coefs(pbi, xd, bc, 16, PLANE_TYPE_UV, seg_eob,
- xd->plane[1].qcoeff, TX_8X8);
- xd->plane[1].eobs[0] = c;
- eobtotal += c;
- c = decode_coefs(pbi, xd, bc, 20, PLANE_TYPE_UV, seg_eob,
- xd->plane[2].qcoeff, TX_8X8);
- xd->plane[2].eobs[0] = c;
- eobtotal += c;
- }
-
- return eobtotal;
+int vp9_decode_mb_tokens(VP9D_COMP* const pbi,
+ MACROBLOCKD* const xd,
+ BOOL_DECODER* const bc) {
+ return decode_blocks(pbi, xd, bc, BLOCK_16X16_LG2);
}
+#if CONFIG_NEWBINTRAMODES
static int decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd,
BOOL_DECODER* const bc,
PLANE_TYPE type, int i, int seg_eob) {
@@ -588,39 +528,6 @@ int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx,
return decode_mb_tokens_4x4_uv(dx, xd, bc, seg_eob);
}
-static int vp9_decode_mb_tokens_4x4(VP9D_COMP* const dx,
- MACROBLOCKD* const xd,
- BOOL_DECODER* const bc) {
- int i, eobtotal = 0;
- const int segment_id = xd->mode_info_context->mbmi.segment_id;
- const int seg_eob = get_eob(xd, segment_id, 16);
-
- // luma blocks
- for (i = 0; i < 16; ++i)
- eobtotal += decode_coefs_4x4(dx, xd, bc, PLANE_TYPE_Y_WITH_DC, i, seg_eob);
-
- // chroma blocks
- eobtotal += decode_mb_tokens_4x4_uv(dx, xd, bc, seg_eob);
-
- return eobtotal;
-}
-
-int vp9_decode_mb_tokens(VP9D_COMP* const dx,
- MACROBLOCKD* const xd,
- BOOL_DECODER* const bc) {
- const TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
- switch (tx_size) {
- case TX_16X16:
- return vp9_decode_mb_tokens_16x16(dx, xd, bc);
- case TX_8X8:
- return vp9_decode_mb_tokens_8x8(dx, xd, bc);
- default:
- assert(tx_size == TX_4X4);
- return vp9_decode_mb_tokens_4x4(dx, xd, bc);
- }
-}
-
-#if CONFIG_NEWBINTRAMODES
int vp9_decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd,
BOOL_DECODER* const bc,
PLANE_TYPE type, int i) {
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index 566fb60ef..4df117088 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -3711,7 +3711,11 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
for (i = 0; i < num_refs; ++i) {
cur_mv[i] = frame_mv[this_mode][refs[i]];
// Clip "next_nearest" so that it does not extend to far out of image
- clamp_mv2(&cur_mv[i], xd);
+ if (this_mode == NEWMV)
+ assert(!clamp_mv2(&cur_mv[i], xd));
+ else
+ clamp_mv2(&cur_mv[i], xd);
+
if (mv_check_bounds(x, &cur_mv[i]))
return INT64_MAX;
mbmi->mv[i].as_int = cur_mv[i].as_int;