summaryrefslogtreecommitdiff
path: root/vp9/decoder/vp9_decodframe.c
diff options
context:
space:
mode:
Diffstat (limited to 'vp9/decoder/vp9_decodframe.c')
-rw-r--r--vp9/decoder/vp9_decodframe.c204
1 files changed, 97 insertions, 107 deletions
diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c
index 965310e7d..214c72b85 100644
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -102,15 +102,15 @@ void vp9_init_de_quantizer(VP9D_COMP *pbi) {
VP9_COMMON *const pc = &pbi->common;
for (q = 0; q < QINDEX_RANGE; q++) {
- pc->Y1dequant[q][0] = (int16_t)vp9_dc_quant(q, pc->y1dc_delta_q);
- pc->UVdequant[q][0] = (int16_t)vp9_dc_uv_quant(q, pc->uvdc_delta_q);
+ pc->y_dequant[q][0] = (int16_t)vp9_dc_quant(q, pc->y1dc_delta_q);
+ pc->uv_dequant[q][0] = (int16_t)vp9_dc_uv_quant(q, pc->uvdc_delta_q);
/* all the ac values =; */
for (i = 1; i < 16; i++) {
const int rc = vp9_default_zig_zag1d_4x4[i];
- pc->Y1dequant[q][rc] = (int16_t)vp9_ac_yquant(q);
- pc->UVdequant[q][rc] = (int16_t)vp9_ac_uv_quant(q, pc->uvac_delta_q);
+ pc->y_dequant[q][rc] = (int16_t)vp9_ac_yquant(q);
+ pc->uv_dequant[q][rc] = (int16_t)vp9_ac_uv_quant(q, pc->uvac_delta_q);
}
}
}
@@ -118,11 +118,10 @@ void vp9_init_de_quantizer(VP9D_COMP *pbi) {
static int get_qindex(MACROBLOCKD *mb, int segment_id, int base_qindex) {
// Set the Q baseline allowing for any segment level adjustment
if (vp9_segfeature_active(mb, segment_id, SEG_LVL_ALT_Q)) {
- if (mb->mb_segment_abs_delta == SEGMENT_ABSDATA)
- return vp9_get_segdata(mb, segment_id, SEG_LVL_ALT_Q); // Abs Value
- else
- return clamp(base_qindex + vp9_get_segdata(mb, segment_id, SEG_LVL_ALT_Q),
- 0, MAXQ); // Delta Value
+ const int data = vp9_get_segdata(mb, segment_id, SEG_LVL_ALT_Q);
+ return mb->mb_segment_abs_delta == SEGMENT_ABSDATA ?
+ data : // Abs value
+ clamp(base_qindex + data, 0, MAXQ); // Delta value
} else {
return base_qindex;
}
@@ -137,10 +136,10 @@ static void mb_init_dequantizer(VP9D_COMP *pbi, MACROBLOCKD *mb) {
mb->q_index = qindex;
for (i = 0; i < 16; i++)
- mb->block[i].dequant = pc->Y1dequant[qindex];
+ mb->block[i].dequant = pc->y_dequant[qindex];
for (i = 16; i < 24; i++)
- mb->block[i].dequant = pc->UVdequant[qindex];
+ mb->block[i].dequant = pc->uv_dequant[qindex];
if (mb->lossless) {
assert(qindex == 0);
@@ -228,10 +227,10 @@ 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 (tx_type != DCT_DCT) {
- vp9_ht_dequant_idct_add_16x16_c(tx_type, xd->plane[0].qcoeff,
- xd->block[0].dequant, xd->predictor,
- xd->dst.y_buffer, 16, xd->dst.y_stride,
- xd->plane[0].eobs[0]);
+ vp9_dequant_iht_add_16x16_c(tx_type, xd->plane[0].qcoeff,
+ xd->block[0].dequant, xd->predictor,
+ xd->dst.y_buffer, 16, xd->dst.y_stride,
+ xd->plane[0].eobs[0]);
} else {
vp9_dequant_idct_add_16x16(xd->plane[0].qcoeff, xd->block[0].dequant,
xd->predictor, xd->dst.y_buffer,
@@ -242,7 +241,7 @@ static void decode_16x16(VP9D_COMP *pbi, MACROBLOCKD *xd,
xd->predictor + 16 * 16, xd->dst.u_buffer, 8,
xd->dst.uv_stride, xd->plane[1].eobs[0]);
- vp9_dequant_idct_add_8x8(xd->plane[2].qcoeff, xd->block[16].dequant,
+ vp9_dequant_idct_add_8x8(xd->plane[2].qcoeff, xd->block[20].dequant,
xd->predictor + 16 * 16 + 64, xd->dst.v_buffer, 8,
xd->dst.uv_stride, xd->plane[2].eobs[0]);
}
@@ -270,8 +269,8 @@ static void decode_8x8(VP9D_COMP *pbi, MACROBLOCKD *xd,
}
tx_type = get_tx_type_8x8(xd, ib);
if (tx_type != DCT_DCT) {
- vp9_ht_dequant_idct_add_8x8_c(tx_type, q, dq, pre, dst, 16, stride,
- xd->plane[0].eobs[idx]);
+ vp9_dequant_iht_add_8x8_c(tx_type, q, dq, pre, dst, 16, stride,
+ xd->plane[0].eobs[idx]);
} else {
vp9_dequant_idct_add_8x8_c(q, dq, pre, dst, 16, stride,
xd->plane[0].eobs[idx]);
@@ -343,7 +342,7 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd,
b = &xd->block[ib + iblock[j]];
tx_type = get_tx_type_4x4(xd, ib + iblock[j]);
if (tx_type != DCT_DCT) {
- vp9_ht_dequant_idct_add_c(tx_type,
+ vp9_dequant_iht_add_c(tx_type,
BLOCK_OFFSET(xd->plane[0].qcoeff, ib + iblock[j], 16),
b->dequant, b->predictor,
*(b->base_dst) + b->dst, 16,
@@ -382,11 +381,11 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd,
vp9_intra4x4_predict(xd, b, b_mode, b->predictor);
tx_type = get_tx_type_4x4(xd, i);
if (tx_type != DCT_DCT) {
- vp9_ht_dequant_idct_add_c(tx_type,
- BLOCK_OFFSET(xd->plane[0].qcoeff, i, 16),
- b->dequant, b->predictor,
- *(b->base_dst) + b->dst, 16, b->dst_stride,
- xd->plane[0].eobs[i]);
+ vp9_dequant_iht_add_c(tx_type,
+ BLOCK_OFFSET(xd->plane[0].qcoeff, i, 16),
+ b->dequant, b->predictor,
+ *(b->base_dst) + b->dst, 16, b->dst_stride,
+ xd->plane[0].eobs[i]);
} else {
xd->itxm_add(BLOCK_OFFSET(xd->plane[0].qcoeff, i, 16),
b->dequant, b->predictor,
@@ -423,11 +422,11 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd,
BLOCKD *b = &xd->block[i];
tx_type = get_tx_type_4x4(xd, i);
if (tx_type != DCT_DCT) {
- vp9_ht_dequant_idct_add_c(tx_type,
- BLOCK_OFFSET(xd->plane[0].qcoeff, i, 16),
- b->dequant, b->predictor,
- *(b->base_dst) + b->dst, 16,
- b->dst_stride, xd->plane[0].eobs[i]);
+ vp9_dequant_iht_add_c(tx_type,
+ BLOCK_OFFSET(xd->plane[0].qcoeff, i, 16),
+ b->dequant, b->predictor,
+ *(b->base_dst) + b->dst, 16,
+ b->dst_stride, xd->plane[0].eobs[i]);
} else {
xd->itxm_add(BLOCK_OFFSET(xd->plane[0].qcoeff, i, 16),
b->dequant, b->predictor,
@@ -464,13 +463,13 @@ static void decode_sb_16x16(MACROBLOCKD *mb, int y_size) {
mb->dst.y_stride, mb->dst.y_stride,
mb->plane[0].eobs[n * 16]);
} else {
- vp9_ht_dequant_idct_add_16x16_c(tx_type,
- BLOCK_OFFSET(mb->plane[0].qcoeff, n, 256),
- mb->block[0].dequant,
- mb->dst.y_buffer + y_offset,
- mb->dst.y_buffer + y_offset,
- mb->dst.y_stride, mb->dst.y_stride,
- mb->plane[0].eobs[n * 16]);
+ vp9_dequant_iht_add_16x16_c(tx_type,
+ BLOCK_OFFSET(mb->plane[0].qcoeff, n, 256),
+ mb->block[0].dequant,
+ mb->dst.y_buffer + y_offset,
+ mb->dst.y_buffer + y_offset,
+ mb->dst.y_stride, mb->dst.y_stride,
+ mb->plane[0].eobs[n * 16]);
}
}
@@ -514,13 +513,13 @@ static INLINE void decode_sb_8x8(MACROBLOCKD *xd, int y_size) {
xd->dst.y_stride, xd->dst.y_stride,
xd->plane[0].eobs[n * 4]);
} else {
- vp9_ht_dequant_idct_add_8x8_c(tx_type,
- BLOCK_OFFSET(xd->plane[0].qcoeff, n, 64),
- xd->block[0].dequant,
- xd->dst.y_buffer + y_offset,
- xd->dst.y_buffer + y_offset,
- xd->dst.y_stride, xd->dst.y_stride,
- xd->plane[0].eobs[n * 4]);
+ vp9_dequant_iht_add_8x8_c(tx_type,
+ BLOCK_OFFSET(xd->plane[0].qcoeff, n, 64),
+ xd->block[0].dequant,
+ xd->dst.y_buffer + y_offset,
+ xd->dst.y_buffer + y_offset,
+ xd->dst.y_stride, xd->dst.y_stride,
+ xd->plane[0].eobs[n * 4]);
}
}
@@ -564,14 +563,14 @@ static void decode_sb_4x4(MACROBLOCKD *xd, int y_size) {
xd->dst.y_stride, xd->dst.y_stride,
xd->plane[0].eobs[n]);
} else {
- vp9_ht_dequant_idct_add_c(tx_type,
- BLOCK_OFFSET(xd->plane[0].qcoeff, n, 16),
- xd->block[0].dequant,
- xd->dst.y_buffer + y_offset,
- xd->dst.y_buffer + y_offset,
- xd->dst.y_stride,
- xd->dst.y_stride,
- xd->plane[0].eobs[n]);
+ vp9_dequant_iht_add_c(tx_type,
+ BLOCK_OFFSET(xd->plane[0].qcoeff, n, 16),
+ xd->block[0].dequant,
+ xd->dst.y_buffer + y_offset,
+ xd->dst.y_buffer + y_offset,
+ xd->dst.y_stride,
+ xd->dst.y_stride,
+ xd->plane[0].eobs[n]);
}
}
@@ -626,7 +625,7 @@ static void decode_sb64(VP9D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col,
}
// dequantization and idct
- eobtotal = vp9_decode_sb64_tokens(pbi, xd, bc);
+ eobtotal = vp9_decode_tokens(pbi, xd, bc, BLOCK_SIZE_SB64X64);
if (eobtotal == 0) { // skip loopfilter
for (n = 0; n < 16; n++) {
const int x_idx = n & 3, y_idx = n >> 2;
@@ -705,7 +704,7 @@ static void decode_sb32(VP9D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col,
}
// dequantization and idct
- eobtotal = vp9_decode_sb_tokens(pbi, xd, bc);
+ eobtotal = vp9_decode_tokens(pbi, xd, bc, BLOCK_SIZE_SB32X32);
if (eobtotal == 0) { // skip loopfilter
mi->mbmi.mb_skip_coeff = 1;
if (mb_col + 1 < pc->mb_cols)
@@ -767,7 +766,7 @@ static void decode_mb(VP9D_COMP *pbi, MACROBLOCKD *xd,
#if CONFIG_NEWBINTRAMODES
if (mode != B_PRED)
#endif
- eobtotal = vp9_decode_mb_tokens(pbi, xd, bc);
+ eobtotal = vp9_decode_tokens(pbi, xd, bc, BLOCK_SIZE_MB16X16);
}
//mode = xd->mode_info_context->mbmi.mode;
@@ -878,31 +877,26 @@ static void set_offsets(VP9D_COMP *pbi, int block_size,
int mb_row, int mb_col) {
VP9_COMMON *const cm = &pbi->common;
MACROBLOCKD *const xd = &pbi->mb;
- const int mis = cm->mode_info_stride;
- const int idx = mis * mb_row + mb_col;
- const int dst_fb_idx = cm->new_fb_idx;
- const int recon_y_stride = cm->yv12_fb[dst_fb_idx].y_stride;
- const int recon_uv_stride = cm->yv12_fb[dst_fb_idx].uv_stride;
- const int recon_yoffset = mb_row * 16 * recon_y_stride + 16 * mb_col;
- const int recon_uvoffset = mb_row * 8 * recon_uv_stride + 8 * mb_col;
-
- xd->mode_info_context = cm->mi + idx;
- xd->mode_info_context->mbmi.sb_type = block_size >> 5;
- xd->prev_mode_info_context = cm->prev_mi + idx;
- xd->above_context = cm->above_context + mb_col;
- xd->left_context = cm->left_context + (mb_row & 3);
- // Distance of Mb to the various image edges.
- // These are specified to 8th pel as they are always compared to
- // values that are in 1/8th pel units
- block_size >>= 4; // in mb units
+ const int mb_idx = mb_row * cm->mode_info_stride + mb_col;
+ const YV12_BUFFER_CONFIG *dst_fb = &cm->yv12_fb[cm->new_fb_idx];
+ const int recon_yoffset = (16 * mb_row) * dst_fb->y_stride + (16 * mb_col);
+ const int recon_uvoffset = (8 * mb_row) * dst_fb->uv_stride + (8 * mb_col);
- set_mb_row(cm, xd, mb_row, block_size);
- set_mb_col(cm, xd, mb_col, block_size);
+ xd->mode_info_context = cm->mi + mb_idx;
+ xd->mode_info_context->mbmi.sb_type = (BLOCK_SIZE_TYPE)(block_size / 32);
+ xd->prev_mode_info_context = cm->prev_mi + mb_idx;
+ xd->above_context = cm->above_context + mb_col;
+ xd->left_context = cm->left_context + mb_row % 4;
+
+ // Distance of Mb to the various image edges. These are specified to 8th pel
+ // as they are always compared to values that are in 1/8th pel units
+ set_mb_row(cm, xd, mb_row, block_size / 16);
+ set_mb_col(cm, xd, mb_col, block_size / 16);
- xd->dst.y_buffer = cm->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
- xd->dst.u_buffer = cm->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
- xd->dst.v_buffer = cm->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;
+ xd->dst.y_buffer = dst_fb->y_buffer + recon_yoffset;
+ xd->dst.u_buffer = dst_fb->u_buffer + recon_uvoffset;
+ xd->dst.v_buffer = dst_fb->v_buffer + recon_uvoffset;
}
static void set_refs(VP9D_COMP *pbi, int block_size, int mb_row, int mb_col) {
@@ -1319,6 +1313,19 @@ static void setup_loopfilter(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) {
}
}
+static void setup_quantization(VP9D_COMP *pbi, vp9_reader *r) {
+ // Read the default quantizers
+ VP9_COMMON *const pc = &pbi->common;
+
+ pc->base_qindex = vp9_read_literal(r, QINDEX_BITS);
+ if (get_delta_q(r, &pc->y1dc_delta_q) |
+ get_delta_q(r, &pc->uvdc_delta_q) |
+ get_delta_q(r, &pc->uvac_delta_q))
+ vp9_init_de_quantizer(pbi);
+
+ mb_init_dequantizer(pbi, &pbi->mb); // MB level dequantizer setup
+}
+
static const uint8_t *read_frame_size(VP9_COMMON *const pc, const uint8_t *data,
const uint8_t *data_end,
int *width, int *height) {
@@ -1621,36 +1628,20 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
// Dummy read for now
vp9_read_literal(&header_bc, 2);
- // Read the default quantizers.
- {
- int q_update = 0;
- pc->base_qindex = vp9_read_literal(&header_bc, QINDEX_BITS);
-
- // AC 1st order Q = default
- q_update = get_delta_q(&header_bc, &pc->y1dc_delta_q) |
- get_delta_q(&header_bc, &pc->uvdc_delta_q) |
- get_delta_q(&header_bc, &pc->uvac_delta_q);
-
- if (q_update)
- vp9_init_de_quantizer(pbi);
-
- // MB level dequantizer setup
- mb_init_dequantizer(pbi, &pbi->mb);
- }
+ setup_quantization(pbi, &header_bc);
// Determine if the golden frame or ARF buffer should be updated and how.
// For all non key frames the GF and ARF refresh flags and sign bias
// flags must be set explicitly.
if (pc->frame_type == KEY_FRAME) {
- pc->active_ref_idx[0] = pc->new_fb_idx;
- pc->active_ref_idx[1] = pc->new_fb_idx;
- pc->active_ref_idx[2] = pc->new_fb_idx;
+ for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i)
+ pc->active_ref_idx[i] = pc->new_fb_idx;
} else {
// Should the GF or ARF be updated from the current frame
pbi->refresh_frame_flags = vp9_read_literal(&header_bc, NUM_REF_FRAMES);
// Select active reference frames
- for (i = 0; i < 3; i++) {
+ for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i) {
int ref_frame_num = vp9_read_literal(&header_bc, NUM_REF_FRAMES_LG2);
pc->active_ref_idx[i] = pc->ref_frame_map[ref_frame_num];
}
@@ -1670,19 +1661,18 @@ int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
pc->use_interintra = vp9_read_bit(&header_bc);
#endif
- /* Calculate scaling factors for each of the 3 available references */
- for (i = 0; i < 3; ++i) {
- if (pc->active_ref_idx[i] >= NUM_YV12_BUFFERS) {
- memset(&pc->active_ref_scale[i], 0, sizeof(pc->active_ref_scale[i]));
- continue;
- }
-
- vp9_setup_scale_factors_for_frame(&pc->active_ref_scale[i],
- &pc->yv12_fb[pc->active_ref_idx[i]],
- pc->width, pc->height);
+ // Calculate scaling factors for each of the 3 available references
+ for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i) {
+ const int idx = pc->active_ref_idx[i];
+ struct scale_factors *sf = &pc->active_ref_scale[i];
+ if (idx >= NUM_YV12_BUFFERS)
+ memset(sf, 0, sizeof(*sf));
+ else
+ vp9_setup_scale_factors_for_frame(sf, &pc->yv12_fb[idx],
+ pc->width, pc->height);
}
- // To enable choice of different interploation filters
+ // To enable choice of different interpolation filters
vp9_setup_interp_filters(xd, pc->mcomp_filter_type, pc);
}