diff options
-rwxr-xr-x | build/make/configure.sh | 2 | ||||
-rw-r--r-- | vp9/common/vp9_onyxc_int.h | 6 | ||||
-rw-r--r-- | vp9/decoder/vp9_decodframe.c | 204 | ||||
-rw-r--r-- | vp9/decoder/vp9_dequantize.c | 24 | ||||
-rw-r--r-- | vp9/decoder/vp9_dequantize.h | 26 | ||||
-rw-r--r-- | vp9/decoder/vp9_detokenize.c | 30 | ||||
-rw-r--r-- | vp9/decoder/vp9_detokenize.h | 14 | ||||
-rw-r--r-- | vp9/encoder/vp9_bitstream.c | 111 | ||||
-rw-r--r-- | vp9/encoder/vp9_quantize.c | 96 |
9 files changed, 232 insertions, 281 deletions
diff --git a/build/make/configure.sh b/build/make/configure.sh index 1a78f272b..c62d5f61c 100755 --- a/build/make/configure.sh +++ b/build/make/configure.sh @@ -1049,7 +1049,7 @@ EOF tune_cflags="-march=" setup_gnu_toolchain #for 32 bit x86 builds, -O3 did not turn on this flag - enabled optimizations && check_add_cflags -fomit-frame-pointer + enabled optimizations && disabled gprof && check_add_cflags -fomit-frame-pointer ;; vs*) # When building with Microsoft Visual Studio the assembler is diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h index 43c629065..6f928f5e0 100644 --- a/vp9/common/vp9_onyxc_int.h +++ b/vp9/common/vp9_onyxc_int.h @@ -40,6 +40,8 @@ void vp9_initialize_common(void); #define NUM_REF_FRAMES 3 #define NUM_REF_FRAMES_LG2 2 +#define ALLOWED_REFS_PER_FRAME 3 + // 1 scratch frame for the new frame, 3 for scaled references on the encoder // TODO(jkoleszar): These 3 extra references could probably come from the // normal reference pool. @@ -167,8 +169,8 @@ typedef enum { typedef struct VP9Common { struct vpx_internal_error_info error; - DECLARE_ALIGNED(16, int16_t, Y1dequant[QINDEX_RANGE][16]); - DECLARE_ALIGNED(16, int16_t, UVdequant[QINDEX_RANGE][16]); + DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][16]); + DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][16]); int width; int height; 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); } diff --git a/vp9/decoder/vp9_dequantize.c b/vp9/decoder/vp9_dequantize.c index c0d1e2adb..1539ee7d1 100644 --- a/vp9/decoder/vp9_dequantize.c +++ b/vp9/decoder/vp9_dequantize.c @@ -79,10 +79,10 @@ void vp9_add_constant_residual_32x32_c(const int16_t diff, const uint8_t *pred, add_constant_residual(diff, pred, pitch, dest, stride, 32, 32); } -void vp9_ht_dequant_idct_add_c(TX_TYPE tx_type, int16_t *input, - const int16_t *dq, - uint8_t *pred, uint8_t *dest, - int pitch, int stride, int eob) { +void vp9_dequant_iht_add_c(TX_TYPE tx_type, int16_t *input, + const int16_t *dq, + uint8_t *pred, uint8_t *dest, + int pitch, int stride, int eob) { int i; DECLARE_ALIGNED_ARRAY(16, int16_t, output, 16); @@ -94,10 +94,10 @@ void vp9_ht_dequant_idct_add_c(TX_TYPE tx_type, int16_t *input, vp9_add_residual_4x4(output, pred, pitch, dest, stride); } -void vp9_ht_dequant_idct_add_8x8_c(TX_TYPE tx_type, int16_t *input, - const int16_t *dq, - uint8_t *pred, uint8_t *dest, - int pitch, int stride, int eob) { +void vp9_dequant_iht_add_8x8_c(TX_TYPE tx_type, int16_t *input, + const int16_t *dq, + uint8_t *pred, uint8_t *dest, + int pitch, int stride, int eob) { DECLARE_ALIGNED_ARRAY(16, int16_t, output, 64); if (eob == 0) { @@ -253,10 +253,10 @@ void vp9_dequant_idct_add_8x8_c(int16_t *input, const int16_t *dq, } } -void vp9_ht_dequant_idct_add_16x16_c(TX_TYPE tx_type, int16_t *input, - const int16_t *dq, uint8_t *pred, - uint8_t *dest, int pitch, int stride, - int eob) { +void vp9_dequant_iht_add_16x16_c(TX_TYPE tx_type, int16_t *input, + const int16_t *dq, uint8_t *pred, + uint8_t *dest, int pitch, int stride, + int eob) { DECLARE_ALIGNED_ARRAY(16, int16_t, output, 256); if (eob == 0) { diff --git a/vp9/decoder/vp9_dequantize.h b/vp9/decoder/vp9_dequantize.h index bb72bb294..da9e2b72f 100644 --- a/vp9/decoder/vp9_dequantize.h +++ b/vp9/decoder/vp9_dequantize.h @@ -44,18 +44,18 @@ void vp9_dequant_idct_add_uv_block_lossless_c(int16_t *q, const int16_t *dq, int stride, uint16_t *eobs); -void vp9_ht_dequant_idct_add_c(TX_TYPE tx_type, int16_t *input, const int16_t *dq, - unsigned char *pred, unsigned char *dest, - int pitch, int stride, int eob); - -void vp9_ht_dequant_idct_add_8x8_c(TX_TYPE tx_type, int16_t *input, - const int16_t *dq, unsigned char *pred, - unsigned char *dest, int pitch, int stride, - int eob); - -void vp9_ht_dequant_idct_add_16x16_c(TX_TYPE tx_type, int16_t *input, - const int16_t *dq, unsigned char *pred, - unsigned char *dest, - int pitch, int stride, int eob); +void vp9_dequant_iht_add_c(TX_TYPE tx_type, int16_t *input, const int16_t *dq, + unsigned char *pred, unsigned char *dest, + int pitch, int stride, int eob); + +void vp9_dequant_iht_add_8x8_c(TX_TYPE tx_type, int16_t *input, + const int16_t *dq, unsigned char *pred, + unsigned char *dest, int pitch, int stride, + int eob); + +void vp9_dequant_iht_add_16x16_c(TX_TYPE tx_type, int16_t *input, + const int16_t *dq, unsigned char *pred, + unsigned char *dest, + int pitch, int stride, int eob); #endif // VP9_DECODER_VP9_DEQUANTIZE_H_ diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c index 9077fcde1..f9e9da9bc 100644 --- a/vp9/decoder/vp9_detokenize.c +++ b/vp9/decoder/vp9_detokenize.c @@ -401,26 +401,26 @@ static INLINE int block_idx_4x4(MACROBLOCKD* const xd, int block_size_b, static INLINE int decode_block_plane(VP9D_COMP* const pbi, MACROBLOCKD* const xd, BOOL_DECODER* const bc, - BLOCK_SIZE_LG2 block_size, + int 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; + const int block_size_b = block_size; + const int 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; + const int 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 + const int 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; @@ -477,22 +477,12 @@ static INLINE int decode_blocks(VP9D_COMP* const pbi, 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) { - return decode_blocks(pbi, xd, bc, BLOCK_64X64_LG2); -} - -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); -} - -int vp9_decode_mb_tokens(VP9D_COMP* const pbi, +int vp9_decode_tokens(VP9D_COMP* const pbi, MACROBLOCKD* const xd, - BOOL_DECODER* const bc) { - return decode_blocks(pbi, xd, bc, BLOCK_16X16_LG2); + BOOL_DECODER* const bc, + BLOCK_SIZE_TYPE bsize) { + const int bwl = mb_width_log2(bsize) + 2, bhl = mb_height_log2(bsize) + 2; + return decode_blocks(pbi, xd, bc, bwl + bhl); } #if CONFIG_NEWBINTRAMODES diff --git a/vp9/decoder/vp9_detokenize.h b/vp9/decoder/vp9_detokenize.h index 97de72b9a..e0c29686f 100644 --- a/vp9/decoder/vp9_detokenize.h +++ b/vp9/decoder/vp9_detokenize.h @@ -14,16 +14,10 @@ #include "vp9/decoder/vp9_onyxd_int.h" -int vp9_decode_mb_tokens(VP9D_COMP* const, MACROBLOCKD* const, - BOOL_DECODER* const); - -int vp9_decode_sb_tokens(VP9D_COMP* const pbi, - MACROBLOCKD* const xd, - BOOL_DECODER* const bc); - -int vp9_decode_sb64_tokens(VP9D_COMP* const pbi, - MACROBLOCKD* const xd, - BOOL_DECODER* const bc); +int vp9_decode_tokens(VP9D_COMP* const pbi, + MACROBLOCKD* const xd, + BOOL_DECODER* const bc, + BLOCK_SIZE_TYPE bsize); int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx, MACROBLOCKD* const xd, BOOL_DECODER* const bc); diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index d12f39dff..7fc33c00c 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -8,6 +8,9 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include <assert.h> +#include <stdio.h> +#include <limits.h> #include "vp9/common/vp9_header.h" #include "vp9/encoder/vp9_encodemv.h" @@ -17,9 +20,6 @@ #include "vp9/common/vp9_tile_common.h" #include "vp9/encoder/vp9_mcomp.h" #include "vp9/common/vp9_systemdependent.h" -#include <assert.h> -#include <stdio.h> -#include <limits.h> #include "vp9/common/vp9_pragmas.h" #include "vpx/vpx_encoder.h" #include "vpx_mem/vpx_mem.h" @@ -479,7 +479,7 @@ static void pack_mb_tokens(vp9_writer* const bc, do { const int bb = (v >> --n) & 1; - encode_bool(bc, bb, pp[i >> 1]); + vp9_write(bc, bb, pp[i >> 1]); i = vp9_coef_tree[i + bb]; } while (n); @@ -495,12 +495,12 @@ static void pack_mb_tokens(vp9_writer* const bc, do { const int bb = (v >> --n) & 1; - encode_bool(bc, bb, pp[i >> 1]); + vp9_write(bc, bb, pp[i >> 1]); i = b->tree[i + bb]; } while (n); } - encode_bool(bc, e & 1, 128); + vp9_write_bit(bc, e & 1); } ++p; } @@ -2262,17 +2262,13 @@ static void put_delta_q(vp9_writer *bc, int delta_q) { if (delta_q != 0) { vp9_write_bit(bc, 1); vp9_write_literal(bc, abs(delta_q), 4); - - if (delta_q < 0) - vp9_write_bit(bc, 1); - else - vp9_write_bit(bc, 0); - } else + vp9_write_bit(bc, delta_q < 0); + } else { vp9_write_bit(bc, 0); + } } static void decide_kf_ymode_entropy(VP9_COMP *cpi) { - int mode_cost[MB_MODE_COUNT]; int cost; int bestcost = INT_MAX; @@ -2307,9 +2303,8 @@ static void segment_reference_frames(VP9_COMP *cpi) { MACROBLOCKD *const xd = &cpi->mb.e_mbd; for (i = 0; i < oci->mb_rows; i++) { - for (j = 0; j < oci->mb_cols; j++, mb_index++) { + for (j = 0; j < oci->mb_cols; j++, mb_index++) ref[mi[mb_index].mbmi.segment_id] |= (1 << mi[mb_index].mbmi.ref_frame); - } mb_index++; } for (i = 0; i < MAX_MB_SEGMENTS; i++) { @@ -2410,11 +2405,10 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest, // Send the tree probabilities used to decode unpredicted // macro-block segments for (i = 0; i < MB_FEATURE_TREE_PROBS; i++) { - int data = xd->mb_segment_tree_probs[i]; - - if (data != 255) { + const int prob = xd->mb_segment_tree_probs[i]; + if (prob != 255) { vp9_write_bit(&header_bc, 1); - vp9_write_literal(&header_bc, data, 8); + vp9_write_literal(&header_bc, prob, 8); } else { vp9_write_bit(&header_bc, 0); } @@ -2424,11 +2418,10 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest, vp9_write_bit(&header_bc, (pc->temporal_update) ? 1 : 0); if (pc->temporal_update) { for (i = 0; i < PREDICTION_PROBS; i++) { - int data = pc->segment_pred_probs[i]; - - if (data != 255) { + const int prob = pc->segment_pred_probs[i]; + if (prob != 255) { vp9_write_bit(&header_bc, 1); - vp9_write_literal(&header_bc, data, 8); + vp9_write_literal(&header_bc, prob, 8); } else { vp9_write_bit(&header_bc, 0); } @@ -2441,15 +2434,14 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest, // segment_reference_frames(cpi); if (xd->update_mb_segmentation_data) { - signed char Data; - vp9_write_bit(&header_bc, (xd->mb_segment_abs_delta) ? 1 : 0); // For each segments id... for (i = 0; i < MAX_MB_SEGMENTS; i++) { // For each segmentation codable feature... for (j = 0; j < SEG_LVL_MAX; j++) { - Data = vp9_get_segdata(xd, i, j); + const int8_t data = vp9_get_segdata(xd, i, j); + const int data_max = vp9_seg_feature_data_max(j); // If the feature is enabled... if (vp9_segfeature_active(xd, i, j)) { @@ -2458,23 +2450,20 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest, // Is the segment data signed.. if (vp9_is_segfeature_signed(j)) { // Encode the relevant feature data - if (Data < 0) { - Data = - Data; - vp9_encode_unsigned_max(&header_bc, Data, - vp9_seg_feature_data_max(j)); + if (data < 0) { + vp9_encode_unsigned_max(&header_bc, -data, data_max); vp9_write_bit(&header_bc, 1); } else { - vp9_encode_unsigned_max(&header_bc, Data, - vp9_seg_feature_data_max(j)); + vp9_encode_unsigned_max(&header_bc, data, data_max); vp9_write_bit(&header_bc, 0); } + } else { + // Unsigned data element so no sign bit needed + vp9_encode_unsigned_max(&header_bc, data, data_max); } - // Unsigned data element so no sign bit needed - else - vp9_encode_unsigned_max(&header_bc, Data, - vp9_seg_feature_data_max(j)); - } else + } else { vp9_write_bit(&header_bc, 0); + } } } } @@ -2560,28 +2549,24 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest, if (xd->mode_ref_lf_delta_enabled) { // Do the deltas need to be updated - int send_update = xd->mode_ref_lf_delta_update; - - vp9_write_bit(&header_bc, send_update); - if (send_update) { - int Data; - + vp9_write_bit(&header_bc, xd->mode_ref_lf_delta_update); + if (xd->mode_ref_lf_delta_update) { // Send update for (i = 0; i < MAX_REF_LF_DELTAS; i++) { - Data = xd->ref_lf_deltas[i]; + const int delta = xd->ref_lf_deltas[i]; // Frame level data - if (xd->ref_lf_deltas[i] != xd->last_ref_lf_deltas[i]) { - xd->last_ref_lf_deltas[i] = xd->ref_lf_deltas[i]; + if (delta != xd->last_ref_lf_deltas[i]) { + xd->last_ref_lf_deltas[i] = delta; vp9_write_bit(&header_bc, 1); - if (Data > 0) { - vp9_write_literal(&header_bc, (Data & 0x3F), 6); - vp9_write_bit(&header_bc, 0); // sign + if (delta > 0) { + vp9_write_literal(&header_bc, delta & 0x3F, 6); + vp9_write_bit(&header_bc, 0); // sign } else { - Data = -Data; - vp9_write_literal(&header_bc, (Data & 0x3F), 6); - vp9_write_bit(&header_bc, 1); // sign + assert(delta < 0); + vp9_write_literal(&header_bc, (-delta) & 0x3F, 6); + vp9_write_bit(&header_bc, 1); // sign } } else { vp9_write_bit(&header_bc, 0); @@ -2590,19 +2575,19 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest, // Send update for (i = 0; i < MAX_MODE_LF_DELTAS; i++) { - Data = xd->mode_lf_deltas[i]; + const int delta = xd->mode_lf_deltas[i]; - if (xd->mode_lf_deltas[i] != xd->last_mode_lf_deltas[i]) { - xd->last_mode_lf_deltas[i] = xd->mode_lf_deltas[i]; + if (delta != xd->last_mode_lf_deltas[i]) { + xd->last_mode_lf_deltas[i] = delta; vp9_write_bit(&header_bc, 1); - if (Data > 0) { - vp9_write_literal(&header_bc, (Data & 0x3F), 6); - vp9_write_bit(&header_bc, 0); // sign + if (delta > 0) { + vp9_write_literal(&header_bc, delta & 0x3F, 6); + vp9_write_bit(&header_bc, 0); // sign } else { - Data = -Data; - vp9_write_literal(&header_bc, (Data & 0x3F), 6); - vp9_write_bit(&header_bc, 1); // sign + assert(delta < 0); + vp9_write_literal(&header_bc, (-delta) & 0x3F, 6); + vp9_write_bit(&header_bc, 1); // sign } } else { vp9_write_bit(&header_bc, 0); @@ -2867,9 +2852,9 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest, const int use_compound_pred = (comp_pred_mode != SINGLE_PREDICTION_ONLY); const int use_hybrid_pred = (comp_pred_mode == HYBRID_PREDICTION); - vp9_write(&header_bc, use_compound_pred, 128); + vp9_write_bit(&header_bc, use_compound_pred); if (use_compound_pred) { - vp9_write(&header_bc, use_hybrid_pred, 128); + vp9_write_bit(&header_bc, use_hybrid_pred); if (use_hybrid_pred) { for (i = 0; i < COMP_PRED_CONTEXTS; i++) { pc->prob_comppred[i] = get_binary_prob(cpi->single_pred_count[i], diff --git a/vp9/encoder/vp9_quantize.c b/vp9/encoder/vp9_quantize.c index 7a8b2519b..cb6cca0af 100644 --- a/vp9/encoder/vp9_quantize.c +++ b/vp9/encoder/vp9_quantize.c @@ -626,14 +626,14 @@ void vp9_init_quantizer(VP9_COMP *cpi) { invert_quant(cpi->Y1quant[q] + 0, cpi->Y1quant_shift[q] + 0, quant_val); cpi->Y1zbin[q][0] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7); cpi->Y1round[q][0] = (qrounding_factor * quant_val) >> 7; - cpi->common.Y1dequant[q][0] = quant_val; + cpi->common.y_dequant[q][0] = quant_val; cpi->zrun_zbin_boost_y1[q][0] = (quant_val * zbin_boost[0]) >> 7; quant_val = vp9_dc_uv_quant(q, cpi->common.uvdc_delta_q); invert_quant(cpi->UVquant[q] + 0, cpi->UVquant_shift[q] + 0, quant_val); cpi->UVzbin[q][0] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7); cpi->UVround[q][0] = (qrounding_factor * quant_val) >> 7; - cpi->common.UVdequant[q][0] = quant_val; + cpi->common.uv_dequant[q][0] = quant_val; cpi->zrun_zbin_boost_uv[q][0] = (quant_val * zbin_boost[0]) >> 7; // all the 4x4 ac values =; @@ -644,7 +644,7 @@ void vp9_init_quantizer(VP9_COMP *cpi) { invert_quant(cpi->Y1quant[q] + rc, cpi->Y1quant_shift[q] + rc, quant_val); cpi->Y1zbin[q][rc] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7); cpi->Y1round[q][rc] = (qrounding_factor * quant_val) >> 7; - cpi->common.Y1dequant[q][rc] = quant_val; + cpi->common.y_dequant[q][rc] = quant_val; cpi->zrun_zbin_boost_y1[q][i] = ROUND_POWER_OF_TWO(quant_val * zbin_boost[i], 7); @@ -652,7 +652,7 @@ void vp9_init_quantizer(VP9_COMP *cpi) { invert_quant(cpi->UVquant[q] + rc, cpi->UVquant_shift[q] + rc, quant_val); cpi->UVzbin[q][rc] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7); cpi->UVround[q][rc] = (qrounding_factor * quant_val) >> 7; - cpi->common.UVdequant[q][rc] = quant_val; + cpi->common.uv_dequant[q][rc] = quant_val; cpi->zrun_zbin_boost_uv[q][i] = ROUND_POWER_OF_TWO(quant_val * zbin_boost[i], 7); } @@ -661,40 +661,39 @@ void vp9_init_quantizer(VP9_COMP *cpi) { void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) { int i; - int QIndex; + int qindex; MACROBLOCKD *xd = &x->e_mbd; int zbin_extra; int segment_id = xd->mode_info_context->mbmi.segment_id; // Select the baseline MB Q index allowing for any segment level change. if (vp9_segfeature_active(xd, segment_id, SEG_LVL_ALT_Q)) { - // Abs Value - if (xd->mb_segment_abs_delta == SEGMENT_ABSDATA) - QIndex = vp9_get_segdata(xd, segment_id, SEG_LVL_ALT_Q); - - // Delta Value - else { - QIndex = cpi->common.base_qindex + - vp9_get_segdata(xd, segment_id, SEG_LVL_ALT_Q); + if (xd->mb_segment_abs_delta == SEGMENT_ABSDATA) { + // Abs Value + qindex = vp9_get_segdata(xd, segment_id, SEG_LVL_ALT_Q); + } else { + // Delta Value + qindex = cpi->common.base_qindex + + vp9_get_segdata(xd, segment_id, SEG_LVL_ALT_Q); // Clamp to valid range - QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0; + qindex = clamp(qindex, 0, MAXQ); } - } else - QIndex = cpi->common.base_qindex; + } else { + qindex = cpi->common.base_qindex; + } // Y - zbin_extra = (cpi->common.Y1dequant[QIndex][1] * - (cpi->zbin_mode_boost + - x->act_zbin_adj)) >> 7; + zbin_extra = (cpi->common.y_dequant[qindex][1] * + (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; for (i = 0; i < 16; i++) { - x->block[i].quant = cpi->Y1quant[QIndex]; - x->block[i].quant_shift = cpi->Y1quant_shift[QIndex]; - x->block[i].zbin = cpi->Y1zbin[QIndex]; - x->block[i].round = cpi->Y1round[QIndex]; - x->e_mbd.block[i].dequant = cpi->common.Y1dequant[QIndex]; - x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_y1[QIndex]; + x->block[i].quant = cpi->Y1quant[qindex]; + x->block[i].quant_shift = cpi->Y1quant_shift[qindex]; + x->block[i].zbin = cpi->Y1zbin[qindex]; + x->block[i].round = cpi->Y1round[qindex]; + x->e_mbd.block[i].dequant = cpi->common.y_dequant[qindex]; + x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_y1[qindex]; x->block[i].zbin_extra = (int16_t)zbin_extra; // Segment skip feature. @@ -703,49 +702,40 @@ void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) { } // UV - zbin_extra = (cpi->common.UVdequant[QIndex][1] * - (cpi->zbin_mode_boost + - x->act_zbin_adj)) >> 7; + zbin_extra = (cpi->common.uv_dequant[qindex][1] * + (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; for (i = 16; i < 24; i++) { - x->block[i].quant = cpi->UVquant[QIndex]; - x->block[i].quant_shift = cpi->UVquant_shift[QIndex]; - x->block[i].zbin = cpi->UVzbin[QIndex]; - x->block[i].round = cpi->UVround[QIndex]; - x->e_mbd.block[i].dequant = cpi->common.UVdequant[QIndex]; - x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_uv[QIndex]; + x->block[i].quant = cpi->UVquant[qindex]; + x->block[i].quant_shift = cpi->UVquant_shift[qindex]; + x->block[i].zbin = cpi->UVzbin[qindex]; + x->block[i].round = cpi->UVround[qindex]; + x->e_mbd.block[i].dequant = cpi->common.uv_dequant[qindex]; + x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_uv[qindex]; x->block[i].zbin_extra = (int16_t)zbin_extra; // Segment skip feature. x->block[i].skip_block = - vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP); + vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP); } /* save this macroblock QIndex for vp9_update_zbin_extra() */ - x->e_mbd.q_index = QIndex; + x->e_mbd.q_index = qindex; } void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) { int i; - int QIndex = x->e_mbd.q_index; - int zbin_extra; - - // Y - zbin_extra = (cpi->common.Y1dequant[QIndex][1] * - (cpi->zbin_mode_boost + - x->act_zbin_adj)) >> 7; - for (i = 0; i < 16; i++) { - x->block[i].zbin_extra = (int16_t)zbin_extra; - } + const int qindex = x->e_mbd.q_index; + const int y_zbin_extra = (cpi->common.y_dequant[qindex][1] * + (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; + const int uv_zbin_extra = (cpi->common.uv_dequant[qindex][1] * + (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; - // UV - zbin_extra = (cpi->common.UVdequant[QIndex][1] * - (cpi->zbin_mode_boost + - x->act_zbin_adj)) >> 7; + for (i = 0; i < 16; i++) + x->block[i].zbin_extra = (int16_t)y_zbin_extra; - for (i = 16; i < 24; i++) { - x->block[i].zbin_extra = (int16_t)zbin_extra; - } + for (i = 16; i < 24; i++) + x->block[i].zbin_extra = (int16_t)uv_zbin_extra; } void vp9_frame_init_quantizer(VP9_COMP *cpi) { |