diff options
28 files changed, 356 insertions, 330 deletions
diff --git a/test/acm_random.h b/test/acm_random.h index 514894eda..84c6c7529 100644 --- a/test/acm_random.h +++ b/test/acm_random.h @@ -35,6 +35,13 @@ class ACMRandom { return (rand() >> 8) & 0xff; } + uint8_t Rand8Extremes(void) { + // Returns a random value near 0 or near 255, to better exercise + // saturation behavior. + const uint8_t r = Rand8(); + return r < 128 ? r << 4 : r >> 4; + } + int PseudoUniform(int range) { return (rand() >> 8) % range; } diff --git a/test/convolve_test.cc b/test/convolve_test.cc index 35065a41f..a8139cbd3 100644 --- a/test/convolve_test.cc +++ b/test/convolve_test.cc @@ -66,7 +66,7 @@ static void filter_block2d_8_c(const uint8_t *src_ptr, // support. const int kInterp_Extend = 4; const unsigned int intermediate_height = - (kInterp_Extend - 1) + output_height + kInterp_Extend; + (kInterp_Extend - 1) + output_height + kInterp_Extend; /* Size of intermediate_buffer is max_intermediate_height * filter_max_width, * where max_intermediate_height = (kInterp_Extend - 1) + filter_max_height @@ -75,7 +75,7 @@ static void filter_block2d_8_c(const uint8_t *src_ptr, * = 23 * and filter_max_width = 16 */ - uint8_t intermediate_buffer[23 * 16]; + uint8_t intermediate_buffer[71 * 64]; const int intermediate_next_stride = 1 - intermediate_height * output_width; // Horizontal pass (src -> transposed intermediate). @@ -158,13 +158,13 @@ static void filter_average_block2d_8_c(const uint8_t *src_ptr, unsigned int dst_stride, unsigned int output_width, unsigned int output_height) { - uint8_t tmp[16*16]; + uint8_t tmp[64*64]; - assert(output_width <= 16); - assert(output_height <= 16); - filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp, 16, + assert(output_width <= 64); + assert(output_height <= 64); + filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp, 64, output_width, output_height); - block2d_average_c(tmp, 16, dst_ptr, dst_stride, + block2d_average_c(tmp, 64, dst_ptr, dst_stride, output_width, output_height); } @@ -188,10 +188,10 @@ class ConvolveTest : public PARAMS(int, int, const ConvolveFunctions*) { protected: static const int kDataAlignment = 16; - static const int kOuterBlockSize = 32; + static const int kOuterBlockSize = 128; static const int kInputStride = kOuterBlockSize; static const int kOutputStride = kOuterBlockSize; - static const int kMaxDimension = 16; + static const int kMaxDimension = 64; int Width() const { return GET_PARAM(0); } int Height() const { return GET_PARAM(1); } @@ -221,7 +221,7 @@ class ConvolveTest : public PARAMS(int, int, const ConvolveFunctions*) { ::libvpx_test::ACMRandom prng; for (int i = 0; i < kOuterBlockSize * kOuterBlockSize; ++i) - input_[i] = prng.Rand8(); + input_[i] = prng.Rand8Extremes(); } void CheckGuardBlocks() { @@ -308,6 +308,29 @@ const int16_t (*kTestFilterList[])[8] = { vp9_sub_pel_filters_8s, vp9_sub_pel_filters_8lp }; +const int kNumFilterBanks = sizeof(kTestFilterList) / + sizeof(kTestFilterList[0]); +const int kNumFilters = 16; + +TEST(ConvolveTest, FiltersWontSaturateWhenAddedPairwise) { + for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) { + const int16_t (*filters)[8] = kTestFilterList[filter_bank]; + for (int i = 0; i < kNumFilters; i++) { + const int p0 = filters[i][0] + filters[i][1]; + const int p1 = filters[i][2] + filters[i][3]; + const int p2 = filters[i][4] + filters[i][5]; + const int p3 = filters[i][6] + filters[i][7]; + EXPECT_LE(p0, 128); + EXPECT_LE(p1, 128); + EXPECT_LE(p2, 128); + EXPECT_LE(p3, 128); + EXPECT_LE(p0 + p3, 128); + EXPECT_LE(p0 + p3 + p1, 128); + EXPECT_LE(p0 + p3 + p1 + p2, 128); + EXPECT_EQ(p0 + p1 + p2 + p3, 128); + } + } +} const int16_t kInvalidFilter[8] = { 0 }; @@ -316,12 +339,9 @@ TEST_P(ConvolveTest, MatchesReferenceSubpixelFilter) { uint8_t* const out = output(); uint8_t ref[kOutputStride * kMaxDimension]; - const int kNumFilterBanks = sizeof(kTestFilterList) / - sizeof(kTestFilterList[0]); for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) { const int16_t (*filters)[8] = kTestFilterList[filter_bank]; - const int kNumFilters = 16; for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) { for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) { @@ -368,7 +388,7 @@ TEST_P(ConvolveTest, MatchesReferenceAveragingSubpixelFilter) { ::libvpx_test::ACMRandom prng; for (int y = 0; y < Height(); ++y) { for (int x = 0; x < Width(); ++x) { - const uint8_t r = prng.Rand8(); + const uint8_t r = prng.Rand8Extremes(); out[y * kOutputStride + x] = r; ref[y * kOutputStride + x] = r; @@ -440,16 +460,17 @@ DECLARE_ALIGNED(256, const int16_t, kChangeFilters[16][8]) = { TEST_P(ConvolveTest, ChangeFilterWorks) { uint8_t* const in = input(); uint8_t* const out = output(); + const int kPixelSelected = 4; REGISTER_STATE_CHECK(UUT_->h8_(in, kInputStride, out, kOutputStride, kChangeFilters[8], 17, kChangeFilters[4], 16, Width(), Height())); for (int x = 0; x < Width(); ++x) { - if (x < 8) - ASSERT_EQ(in[4], out[x]) << "x == " << x; - else - ASSERT_EQ(in[12], out[x]) << "x == " << x; + const int kQ4StepAdjust = x >> 4; + const int kFilterPeriodAdjust = (x >> 3) << 3; + const int ref_x = kQ4StepAdjust + kFilterPeriodAdjust + kPixelSelected; + ASSERT_EQ(in[ref_x], out[x]) << "x == " << x; } REGISTER_STATE_CHECK(UUT_->v8_(in, kInputStride, out, kOutputStride, @@ -457,10 +478,10 @@ TEST_P(ConvolveTest, ChangeFilterWorks) { Width(), Height())); for (int y = 0; y < Height(); ++y) { - if (y < 8) - ASSERT_EQ(in[4 * kInputStride], out[y * kOutputStride]) << "y == " << y; - else - ASSERT_EQ(in[12 * kInputStride], out[y * kOutputStride]) << "y == " << y; + const int kQ4StepAdjust = y >> 4; + const int kFilterPeriodAdjust = (y >> 3) << 3; + const int ref_y = kQ4StepAdjust + kFilterPeriodAdjust + kPixelSelected; + ASSERT_EQ(in[ref_y * kInputStride], out[y * kInputStride]) << "y == " << y; } REGISTER_STATE_CHECK(UUT_->hv8_(in, kInputStride, out, kOutputStride, @@ -468,9 +489,13 @@ TEST_P(ConvolveTest, ChangeFilterWorks) { Width(), Height())); for (int y = 0; y < Height(); ++y) { + const int kQ4StepAdjustY = y >> 4; + const int kFilterPeriodAdjustY = (y >> 3) << 3; + const int ref_y = kQ4StepAdjustY + kFilterPeriodAdjustY + kPixelSelected; for (int x = 0; x < Width(); ++x) { - const int ref_x = x < 8 ? 4 : 12; - const int ref_y = y < 8 ? 4 : 12; + const int kQ4StepAdjustX = x >> 4; + const int kFilterPeriodAdjustX = (x >> 3) << 3; + const int ref_x = kQ4StepAdjustX + kFilterPeriodAdjustX + kPixelSelected; ASSERT_EQ(in[ref_y * kInputStride + ref_x], out[y * kOutputStride + x]) << "x == " << x << ", y == " << y; @@ -489,9 +514,17 @@ const ConvolveFunctions convolve8_c( INSTANTIATE_TEST_CASE_P(C, ConvolveTest, ::testing::Values( make_tuple(4, 4, &convolve8_c), make_tuple(8, 4, &convolve8_c), + make_tuple(4, 8, &convolve8_c), make_tuple(8, 8, &convolve8_c), make_tuple(16, 8, &convolve8_c), - make_tuple(16, 16, &convolve8_c))); + make_tuple(8, 16, &convolve8_c), + make_tuple(16, 16, &convolve8_c), + make_tuple(32, 16, &convolve8_c), + make_tuple(16, 32, &convolve8_c), + make_tuple(32, 32, &convolve8_c), + make_tuple(64, 32, &convolve8_c), + make_tuple(32, 64, &convolve8_c), + make_tuple(64, 64, &convolve8_c))); } #if HAVE_SSSE3 @@ -503,7 +536,15 @@ const ConvolveFunctions convolve8_ssse3( INSTANTIATE_TEST_CASE_P(SSSE3, ConvolveTest, ::testing::Values( make_tuple(4, 4, &convolve8_ssse3), make_tuple(8, 4, &convolve8_ssse3), + make_tuple(4, 8, &convolve8_ssse3), make_tuple(8, 8, &convolve8_ssse3), make_tuple(16, 8, &convolve8_ssse3), - make_tuple(16, 16, &convolve8_ssse3))); + make_tuple(8, 16, &convolve8_ssse3), + make_tuple(16, 16, &convolve8_ssse3), + make_tuple(32, 16, &convolve8_ssse3), + make_tuple(16, 32, &convolve8_ssse3), + make_tuple(32, 32, &convolve8_ssse3), + make_tuple(64, 32, &convolve8_ssse3), + make_tuple(32, 64, &convolve8_ssse3), + make_tuple(64, 64, &convolve8_ssse3))); #endif diff --git a/vp9/common/vp9_alloccommon.c b/vp9/common/vp9_alloccommon.c index 0628a88b7..e142362b2 100644 --- a/vp9/common/vp9_alloccommon.c +++ b/vp9/common/vp9_alloccommon.c @@ -85,7 +85,7 @@ int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) { oci->new_fb_idx = NUM_YV12_BUFFERS - 1; oci->fb_idx_ref_cnt[oci->new_fb_idx] = 1; - for (i = 0; i < 3; i++) + for (i = 0; i < ALLOWED_REFS_PER_FRAME; i++) oci->active_ref_idx[i] = i; for (i = 0; i < NUM_REF_FRAMES; i++) { diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h index 9525a0e14..7eb9f8e86 100644 --- a/vp9/common/vp9_blockd.h +++ b/vp9/common/vp9_blockd.h @@ -26,6 +26,10 @@ #define MB_FEATURE_TREE_PROBS 3 #define PREDICTION_PROBS 3 +#define DEFAULT_PRED_PROB_0 120 +#define DEFAULT_PRED_PROB_1 80 +#define DEFAULT_PRED_PROB_2 40 + #define MBSKIP_CONTEXTS 3 #define MAX_MB_SEGMENTS 4 @@ -51,8 +55,10 @@ typedef struct { ENTROPY_CONTEXT v[2]; } ENTROPY_CONTEXT_PLANES; -#define VP9_COMBINEENTROPYCONTEXTS(Dest, A, B) \ - Dest = ((A)!=0) + ((B)!=0); +static INLINE int combine_entropy_contexts(ENTROPY_CONTEXT a, + ENTROPY_CONTEXT b) { + return (a != 0) + (b != 0); +} typedef enum { KEY_FRAME = 0, diff --git a/vp9/common/vp9_convolve.c b/vp9/common/vp9_convolve.c index 3ab8bec7a..a27ca6f5d 100644 --- a/vp9/common/vp9_convolve.c +++ b/vp9/common/vp9_convolve.c @@ -331,14 +331,14 @@ static void convolve_c(const uint8_t *src, int src_stride, const int16_t *filter_y, int y_step_q4, int w, int h, int taps) { /* Fixed size intermediate buffer places limits on parameters. - * Maximum intermediate_height is 39, for y_step_q4 == 32, - * h == 16, taps == 8. + * Maximum intermediate_height is 135, for y_step_q4 == 32, + * h == 64, taps == 8. */ - uint8_t temp[16 * 39]; + uint8_t temp[64 * 135]; int intermediate_height = ((h * y_step_q4) >> 4) + taps - 1; - assert(w <= 16); - assert(h <= 16); + assert(w <= 64); + assert(h <= 64); assert(taps <= 8); assert(y_step_q4 <= 32); @@ -346,10 +346,10 @@ static void convolve_c(const uint8_t *src, int src_stride, intermediate_height = h; convolve_horiz_c(src - src_stride * (taps / 2 - 1), src_stride, - temp, 16, + temp, 64, filter_x, x_step_q4, filter_y, y_step_q4, w, intermediate_height, taps); - convolve_vert_c(temp + 16 * (taps / 2 - 1), 16, dst, dst_stride, + convolve_vert_c(temp + 64 * (taps / 2 - 1), 64, dst, dst_stride, filter_x, x_step_q4, filter_y, y_step_q4, w, h, taps); } @@ -360,14 +360,14 @@ static void convolve_avg_c(const uint8_t *src, int src_stride, const int16_t *filter_y, int y_step_q4, int w, int h, int taps) { /* Fixed size intermediate buffer places limits on parameters. - * Maximum intermediate_height is 39, for y_step_q4 == 32, - * h == 16, taps == 8. + * Maximum intermediate_height is 135, for y_step_q4 == 32, + * h == 64, taps == 8. */ - uint8_t temp[16 * 39]; + uint8_t temp[64 * 135]; int intermediate_height = ((h * y_step_q4) >> 4) + taps - 1; - assert(w <= 16); - assert(h <= 16); + assert(w <= 64); + assert(h <= 64); assert(taps <= 8); assert(y_step_q4 <= 32); @@ -375,10 +375,10 @@ static void convolve_avg_c(const uint8_t *src, int src_stride, intermediate_height = h; convolve_horiz_c(src - src_stride * (taps / 2 - 1), src_stride, - temp, 16, + temp, 64, filter_x, x_step_q4, filter_y, y_step_q4, w, intermediate_height, taps); - convolve_avg_vert_c(temp + 16 * (taps / 2 - 1), 16, dst, dst_stride, + convolve_avg_vert_c(temp + 64 * (taps / 2 - 1), 64, dst, dst_stride, filter_x, x_step_q4, filter_y, y_step_q4, w, h, taps); } @@ -563,16 +563,16 @@ void vp9_convolve8_avg_c(const uint8_t *src, int src_stride, const int16_t *filter_y, int y_step_q4, int w, int h) { /* Fixed size intermediate buffer places limits on parameters. */ - DECLARE_ALIGNED_ARRAY(16, uint8_t, temp, 16 * 16); - assert(w <= 16); - assert(h <= 16); + DECLARE_ALIGNED_ARRAY(16, uint8_t, temp, 64 * 64); + assert(w <= 64); + assert(h <= 64); vp9_convolve8(src, src_stride, - temp, 16, + temp, 64, filter_x, x_step_q4, filter_y, y_step_q4, w, h); - vp9_convolve_avg(temp, 16, + vp9_convolve_avg(temp, 64, dst, dst_stride, NULL, 0, /* These unused parameter should be removed! */ NULL, 0, /* These unused parameter should be removed! */ diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c index 865034913..0db2de6ee 100644 --- a/vp9/common/vp9_entropymode.c +++ b/vp9/common/vp9_entropymode.c @@ -364,9 +364,9 @@ void vp9_init_mbmode_probs(VP9_COMMON *x) { #if CONFIG_COMP_INTERINTRA_PRED x->fc.interintra_prob = VP9_DEF_INTERINTRA_PROB; #endif - x->ref_pred_probs[0] = 120; - x->ref_pred_probs[1] = 80; - x->ref_pred_probs[2] = 40; + x->ref_pred_probs[0] = DEFAULT_PRED_PROB_0; + x->ref_pred_probs[1] = DEFAULT_PRED_PROB_1; + x->ref_pred_probs[2] = DEFAULT_PRED_PROB_2; } diff --git a/vp9/common/vp9_entropymv.c b/vp9/common/vp9_entropymv.c index fe3667725..0a81015cb 100644 --- a/vp9/common/vp9_entropymv.c +++ b/vp9/common/vp9_entropymv.c @@ -87,12 +87,12 @@ const nmv_context vp9_default_nmv_context = { }, }; -MV_JOINT_TYPE vp9_get_mv_joint(MV mv) { - if (mv.row == 0 && mv.col == 0) +MV_JOINT_TYPE vp9_get_mv_joint(const MV *mv) { + if (mv->row == 0 && mv->col == 0) return MV_JOINT_ZERO; - else if (mv.row == 0 && mv.col != 0) + else if (mv->row == 0 && mv->col != 0) return MV_JOINT_HNZVZ; - else if (mv.row != 0 && mv.col == 0) + else if (mv->row != 0 && mv->col == 0) return MV_JOINT_HZVNZ; else return MV_JOINT_HNZVNZ; @@ -209,13 +209,13 @@ static void counts_to_context(nmv_component_counts *mvcomp, int usehp) { void vp9_increment_nmv(const MV *mv, const MV *ref, nmv_context_counts *mvctx, int usehp) { - const MV_JOINT_TYPE type = vp9_get_mv_joint(*mv); - mvctx->joints[type]++; + const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); + mvctx->joints[j]++; usehp = usehp && vp9_use_nmv_hp(ref); - if (mv_joint_vertical(type)) + if (mv_joint_vertical(j)) increment_nmv_component_count(mv->row, &mvctx->comps[0], 1, usehp); - if (mv_joint_horizontal(type)) + if (mv_joint_horizontal(j)) increment_nmv_component_count(mv->col, &mvctx->comps[1], 1, usehp); } diff --git a/vp9/common/vp9_entropymv.h b/vp9/common/vp9_entropymv.h index 715b5bb2b..de1bd4383 100644 --- a/vp9/common/vp9_entropymv.h +++ b/vp9/common/vp9_entropymv.h @@ -105,7 +105,7 @@ typedef struct { nmv_component comps[2]; } nmv_context; -MV_JOINT_TYPE vp9_get_mv_joint(MV mv); +MV_JOINT_TYPE vp9_get_mv_joint(const MV *mv); MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset); int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset); diff --git a/vp9/common/vp9_findnearmv.h b/vp9/common/vp9_findnearmv.h index 72b6128c1..a31893b27 100644 --- a/vp9/common/vp9_findnearmv.h +++ b/vp9/common/vp9_findnearmv.h @@ -74,11 +74,9 @@ static int clamp_mv2(int_mv *mv, const MACROBLOCKD *xd) { return mv_clampped; } -static unsigned int check_mv_bounds(int_mv *mv, - int mb_to_left_edge, - int mb_to_right_edge, - int mb_to_top_edge, - int mb_to_bottom_edge) { +static int check_mv_bounds(int_mv *mv, + int mb_to_left_edge, int mb_to_right_edge, + int mb_to_top_edge, int mb_to_bottom_edge) { return mv->as_mv.col < mb_to_left_edge || mv->as_mv.col > mb_to_right_edge || mv->as_mv.row < mb_to_top_edge || diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h index 66698f71a..13ec8657f 100644 --- a/vp9/common/vp9_onyxc_int.h +++ b/vp9/common/vp9_onyxc_int.h @@ -231,9 +231,9 @@ typedef struct VP9Common { int base_qindex; int last_kf_gf_q; /* Q used on the last GF or KF */ - int y1dc_delta_q; - int uvdc_delta_q; - int uvac_delta_q; + int y_dc_delta_q; + int uv_dc_delta_q; + int uv_ac_delta_q; unsigned int frames_since_golden; unsigned int frames_till_alt_ref_frame; diff --git a/vp9/common/x86/vp9_asm_stubs.c b/vp9/common/x86/vp9_asm_stubs.c index 6d3bb021a..310f8ed24 100644 --- a/vp9/common/x86/vp9_asm_stubs.c +++ b/vp9/common/x86/vp9_asm_stubs.c @@ -278,11 +278,9 @@ void vp9_convolve8_ssse3(const uint8_t *src, int src_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h) { - DECLARE_ALIGNED_ARRAY(16, unsigned char, fdata2, 16*23); + DECLARE_ALIGNED_ARRAY(16, unsigned char, fdata2, 16*71); - // check w/h due to fixed size fdata2 array - assert(w <= 16); - assert(h <= 16); + assert(h <= 64); if (x_step_q4 == 16 && y_step_q4 == 16 && filter_x[3] != 128 && filter_y[3] != 128) { @@ -324,11 +322,9 @@ void vp9_convolve8_avg_ssse3(const uint8_t *src, int src_stride, const int16_t *filter_x, int x_step_q4, const int16_t *filter_y, int y_step_q4, int w, int h) { - DECLARE_ALIGNED_ARRAY(16, unsigned char, fdata2, 16*23); + DECLARE_ALIGNED_ARRAY(16, unsigned char, fdata2, 16*71); - // check w/h due to fixed size fdata2 array - assert(w <= 16); - assert(h <= 16); + assert(h <= 64); if (x_step_q4 == 16 && y_step_q4 == 16 && filter_x[3] != 128 && filter_y[3] != 128) { diff --git a/vp9/common/x86/vp9_subpixel_8t_ssse3.asm b/vp9/common/x86/vp9_subpixel_8t_ssse3.asm index 32f00e289..bbf9888ca 100644 --- a/vp9/common/x86/vp9_subpixel_8t_ssse3.asm +++ b/vp9/common/x86/vp9_subpixel_8t_ssse3.asm @@ -81,10 +81,10 @@ pmaddubsw xmm4, k4k5 pmaddubsw xmm6, k6k7 + paddsw xmm0, xmm6 paddsw xmm0, xmm2 - paddsw xmm0, krd - paddsw xmm4, xmm6 paddsw xmm0, xmm4 + paddsw xmm0, krd psraw xmm0, 7 packuswb xmm0, xmm0 @@ -165,10 +165,10 @@ pmaddubsw xmm4, k4k5 pmaddubsw xmm6, k6k7 + paddsw xmm0, xmm6 paddsw xmm0, xmm2 - paddsw xmm0, krd - paddsw xmm4, xmm6 paddsw xmm0, xmm4 + paddsw xmm0, krd psraw xmm0, 7 packuswb xmm0, xmm0 @@ -250,10 +250,10 @@ pmaddubsw xmm4, k4k5 pmaddubsw xmm6, k6k7 + paddsw xmm0, xmm6 paddsw xmm0, xmm2 - paddsw xmm0, krd - paddsw xmm4, xmm6 paddsw xmm0, xmm4 + paddsw xmm0, krd psraw xmm0, 7 packuswb xmm0, xmm0 @@ -285,10 +285,10 @@ pmaddubsw xmm4, k4k5 pmaddubsw xmm6, k6k7 + paddsw xmm0, xmm6 paddsw xmm0, xmm2 - paddsw xmm4, xmm6 - paddsw xmm0, krd paddsw xmm0, xmm4 + paddsw xmm0, krd psraw xmm0, 7 packuswb xmm0, xmm0 diff --git a/vp9/decoder/vp9_dboolhuff.c b/vp9/decoder/vp9_dboolhuff.c index dcd591642..390a68475 100644 --- a/vp9/decoder/vp9_dboolhuff.c +++ b/vp9/decoder/vp9_dboolhuff.c @@ -55,66 +55,3 @@ void vp9_reader_fill(BOOL_DECODER *br) { br->count = count; } - -static int get_unsigned_bits(unsigned int num_values) { - int cat = 0; - if (num_values <= 1) - return 0; - num_values--; - while (num_values > 0) { - cat++; - num_values >>= 1; - } - return cat; -} - -int vp9_inv_recenter_nonneg(int v, int m) { - if (v > (m << 1)) - return v; - else if ((v & 1) == 0) - return (v >> 1) + m; - else - return m - ((v + 1) >> 1); -} - -int vp9_decode_uniform(BOOL_DECODER *br, int n) { - int v; - const int l = get_unsigned_bits(n); - const int m = (1 << l) - n; - if (!l) - return 0; - - v = vp9_read_literal(br, l - 1); - return v < m ? v : (v << 1) - m + vp9_read_bit(br); -} - -int vp9_decode_term_subexp(BOOL_DECODER *br, int k, int num_syms) { - int i = 0, mk = 0, word; - while (1) { - const int b = i ? k + i - 1 : k; - const int a = 1 << b; - if (num_syms <= mk + 3 * a) { - word = vp9_decode_uniform(br, num_syms - mk) + mk; - break; - } else { - if (vp9_read_bit(br)) { - i++; - mk += a; - } else { - word = vp9_read_literal(br, b) + mk; - break; - } - } - } - return word; -} - -int vp9_decode_unsigned_max(BOOL_DECODER *br, int max) { - int data = 0, bit = 0, lmax = max; - - while (lmax) { - data |= vp9_read_bit(br) << bit++; - lmax >>= 1; - } - return data > max ? max : data; -} diff --git a/vp9/decoder/vp9_dboolhuff.h b/vp9/decoder/vp9_dboolhuff.h index 10b7a1af3..dab330c02 100644 --- a/vp9/decoder/vp9_dboolhuff.h +++ b/vp9/decoder/vp9_dboolhuff.h @@ -41,10 +41,6 @@ int vp9_start_decode(BOOL_DECODER *br, const uint8_t *buffer, size_t size); void vp9_reader_fill(BOOL_DECODER *br); -int vp9_decode_uniform(BOOL_DECODER *br, int n); -int vp9_decode_term_subexp(BOOL_DECODER *br, int k, int num_syms); -int vp9_inv_recenter_nonneg(int v, int m); - static INLINE const uint8_t *vp9_reader_find_end(BOOL_DECODER *br) { // Find the end of the coded buffer while (br->count > CHAR_BIT && br->count < VP9_BD_VALUE_SIZE) { @@ -123,6 +119,4 @@ static int bool_error(BOOL_DECODER *br) { return br->count > VP9_BD_VALUE_SIZE && br->count < VP9_LOTS_OF_BITS; } -int vp9_decode_unsigned_max(BOOL_DECODER *br, int max); - #endif // VP9_DECODER_VP9_DBOOLHUFF_H_ diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index aaa9b2ef0..6478a8ebc 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -85,19 +85,17 @@ static void read_mb_segid(vp9_reader *r, MB_MODE_INFO *mi, MACROBLOCKD *xd) { // This function reads the current macro block's segnent id from the bitstream // It should only be called if a segment map update is indicated. -static void read_mb_segid_except(VP9_COMMON *cm, - vp9_reader *r, MB_MODE_INFO *mi, - MACROBLOCKD *xd, int mb_row, int mb_col) { +static int read_mb_segid_except(vp9_reader *r, + VP9_COMMON *cm, MACROBLOCKD *xd, + int mb_row, int mb_col) { const int mb_index = mb_row * cm->mb_cols + mb_col; const int pred_seg_id = vp9_get_pred_mb_segid(cm, xd, mb_index); const vp9_prob *const p = xd->mb_segment_tree_probs; const vp9_prob prob = xd->mb_segment_mispred_tree_probs[pred_seg_id]; - if (xd->segmentation_enabled && xd->update_mb_segmentation_map) { - mi->segment_id = vp9_read(r, prob) - ? 2 + (pred_seg_id < 2 ? vp9_read(r, p[2]) : (pred_seg_id == 2)) - : (pred_seg_id >= 2 ? vp9_read(r, p[1]) : (pred_seg_id == 0)); - } + return vp9_read(r, prob) + ? 2 + (pred_seg_id < 2 ? vp9_read(r, p[2]) : (pred_seg_id == 2)) + : (pred_seg_id >= 2 ? vp9_read(r, p[1]) : (pred_seg_id == 0)); } #if CONFIG_NEW_MVREF @@ -269,7 +267,7 @@ static void read_nmv(vp9_reader *r, MV *mv, const MV *ref, static void read_nmv_fp(vp9_reader *r, MV *mv, const MV *ref, const nmv_context *mvctx, int usehp) { - const MV_JOINT_TYPE j = vp9_get_mv_joint(*mv); + const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); usehp = usehp && vp9_use_nmv_hp(ref); if (mv_joint_vertical(j)) mv->row = read_nmv_component_fp(r, mv->row, ref->row, &mvctx->comps[0], @@ -334,7 +332,7 @@ static void read_nmvprobs(vp9_reader *r, nmv_context *mvctx, // Read the referncence frame static MV_REFERENCE_FRAME read_ref_frame(VP9D_COMP *pbi, vp9_reader *r, - unsigned char segment_id) { + int segment_id) { MV_REFERENCE_FRAME ref_frame; VP9_COMMON *const cm = &pbi->common; MACROBLOCKD *const xd = &pbi->mb; @@ -439,7 +437,7 @@ static MB_PREDICTION_MODE read_mv_ref(vp9_reader *r, const vp9_prob *p) { return (MB_PREDICTION_MODE) treed_read(r, vp9_mv_ref_tree, p); } -static B_PREDICTION_MODE sub_mv_ref(vp9_reader *r, const vp9_prob *p) { +static B_PREDICTION_MODE read_sub_mv_ref(vp9_reader *r, const vp9_prob *p) { return (B_PREDICTION_MODE) treed_read(r, vp9_sub_mv_ref_tree, p); } @@ -538,9 +536,9 @@ static void read_mb_segment_id(VP9D_COMP *pbi, vp9_reader *r) { VP9_COMMON *const cm = &pbi->common; MACROBLOCKD *const xd = &pbi->mb; - MODE_INFO *mi = xd->mode_info_context; - MB_MODE_INFO *mbmi = &mi->mbmi; - int mb_index = mb_row * cm->mb_cols + mb_col; + MODE_INFO *const mi = xd->mode_info_context; + MB_MODE_INFO *const mbmi = &mi->mbmi; + const int mb_index = mb_row * cm->mb_cols + mb_col; if (xd->segmentation_enabled) { if (xd->update_mb_segmentation_map) { @@ -557,13 +555,10 @@ static void read_mb_segment_id(VP9D_COMP *pbi, vp9_set_pred_flag(xd, PRED_SEG_ID, seg_pred_flag); // If the value is flagged as correctly predicted - // then use the predicted value - if (seg_pred_flag) { - mbmi->segment_id = vp9_get_pred_mb_segid(cm, xd, mb_index); - } else { - // Decode it explicitly - read_mb_segid_except(cm, r, mbmi, xd, mb_row, mb_col); - } + // then use the predicted value, otherwise decode it explicitly + mbmi->segment_id = seg_pred_flag ? + vp9_get_pred_mb_segid(cm, xd, mb_index) : + read_mb_segid_except(r, cm, xd, mb_row, mb_col); } else { // Normal unpredicted coding mode read_mb_segid(r, mbmi, xd); @@ -623,8 +618,9 @@ static INLINE void assign_and_clamp_mv(int_mv *dst, const int_mv *src, mb_to_bottom_edge); } -static INLINE void process_mv(vp9_reader *r, MV *mv, MV *ref, - nmv_context *nmvc, nmv_context_counts *mvctx, +static INLINE void process_mv(vp9_reader *r, MV *mv, const MV *ref, + const nmv_context *nmvc, + nmv_context_counts *mvctx, int usehp) { read_nmv(r, mv, ref, nmvc); read_nmv_fp(r, mv, ref, nmvc, usehp); @@ -650,7 +646,8 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, const int mis = cm->mode_info_stride; MACROBLOCKD *const xd = &pbi->mb; - int_mv *const mv = &mbmi->mv[0]; + int_mv *const mv0 = &mbmi->mv[0]; + int_mv *const mv1 = &mbmi->mv[1]; const int bw = 1 << mb_width_log2(mi->mbmi.sb_type); const int bh = 1 << mb_height_log2(mi->mbmi.sb_type); @@ -881,7 +878,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, second_abovemv.as_int = above_block_second_mv(mi, k, mis); } mv_contz = vp9_mv_cont(&leftmv, &abovemv); - blockmode = sub_mv_ref(r, cm->fc.sub_mv_ref_prob[mv_contz]); + blockmode = read_sub_mv_ref(r, cm->fc.sub_mv_ref_prob[mv_contz]); cm->fc.sub_mv_ref_counts[mv_contz][blockmode - LEFT4X4]++; switch (blockmode) { @@ -947,7 +944,7 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, Must do it here because ensuing subsets can refer back to us via "left" or "above". */ unsigned int fill_count = mbsplit_fill_count[s]; - const unsigned char *fill_offset = + const uint8_t *fill_offset = &mbsplit_fill_offset[s][j * fill_count]; do { @@ -961,56 +958,56 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, } while (++j < num_p); } - mv->as_int = mi->bmi[15].as_mv[0].as_int; - mbmi->mv[1].as_int = mi->bmi[15].as_mv[1].as_int; + mv0->as_int = mi->bmi[15].as_mv[0].as_int; + mv1->as_int = mi->bmi[15].as_mv[1].as_int; break; /* done with SPLITMV */ case NEARMV: // Clip "next_nearest" so that it does not extend to far out of image - assign_and_clamp_mv(mv, &nearby, mb_to_left_edge, - mb_to_right_edge, - mb_to_top_edge, - mb_to_bottom_edge); + assign_and_clamp_mv(mv0, &nearby, mb_to_left_edge, + mb_to_right_edge, + mb_to_top_edge, + mb_to_bottom_edge); if (mbmi->second_ref_frame > 0) - assign_and_clamp_mv(&mbmi->mv[1], &nearby_second, mb_to_left_edge, - mb_to_right_edge, - mb_to_top_edge, - mb_to_bottom_edge); + assign_and_clamp_mv(mv1, &nearby_second, mb_to_left_edge, + mb_to_right_edge, + mb_to_top_edge, + mb_to_bottom_edge); break; case NEARESTMV: // Clip "next_nearest" so that it does not extend to far out of image - assign_and_clamp_mv(mv, &nearest, mb_to_left_edge, - mb_to_right_edge, - mb_to_top_edge, - mb_to_bottom_edge); + assign_and_clamp_mv(mv0, &nearest, mb_to_left_edge, + mb_to_right_edge, + mb_to_top_edge, + mb_to_bottom_edge); if (mbmi->second_ref_frame > 0) - assign_and_clamp_mv(&mbmi->mv[1], &nearest_second, mb_to_left_edge, - mb_to_right_edge, - mb_to_top_edge, - mb_to_bottom_edge); + assign_and_clamp_mv(mv1, &nearest_second, mb_to_left_edge, + mb_to_right_edge, + mb_to_top_edge, + mb_to_bottom_edge); break; case ZEROMV: - mv->as_int = 0; + mv0->as_int = 0; if (mbmi->second_ref_frame > 0) - mbmi->mv[1].as_int = 0; + mv1->as_int = 0; break; case NEWMV: - process_mv(r, &mv->as_mv, &best_mv.as_mv, nmvc, &cm->fc.NMVcount, + process_mv(r, &mv0->as_mv, &best_mv.as_mv, nmvc, &cm->fc.NMVcount, xd->allow_high_precision_mv); - mbmi->need_to_clamp_mvs = check_mv_bounds(mv, + mbmi->need_to_clamp_mvs = check_mv_bounds(mv0, mb_to_left_edge, mb_to_right_edge, mb_to_top_edge, mb_to_bottom_edge); if (mbmi->second_ref_frame > 0) { - process_mv(r, &mbmi->mv[1].as_mv, &best_mv_second.as_mv, nmvc, + process_mv(r, &mv1->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], + mbmi->need_to_clamp_secondmv = check_mv_bounds(mv1, mb_to_left_edge, mb_to_right_edge, mb_to_top_edge, @@ -1024,8 +1021,8 @@ static void read_mb_modes_mv(VP9D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, #endif } } else { - /* required for left and above block mv */ - mbmi->mv[0].as_int = 0; + // required for left and above block mv + mv0->as_int = 0; if (mbmi->sb_type) { mbmi->mode = read_sb_ymode(r, cm->fc.sb_ymode_prob); diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c index 20d4f19c0..4af921872 100644 --- a/vp9/decoder/vp9_decodframe.c +++ b/vp9/decoder/vp9_decodframe.c @@ -65,6 +65,69 @@ static TXFM_MODE read_txfm_mode(vp9_reader *r) { return mode; } +static int get_unsigned_bits(unsigned int num_values) { + int cat = 0; + if (num_values <= 1) + return 0; + num_values--; + while (num_values > 0) { + cat++; + num_values >>= 1; + } + return cat; +} + +static int inv_recenter_nonneg(int v, int m) { + if (v > (m << 1)) + return v; + else if ((v & 1) == 0) + return (v >> 1) + m; + else + return m - ((v + 1) >> 1); +} + +static int decode_uniform(BOOL_DECODER *br, int n) { + int v; + const int l = get_unsigned_bits(n); + const int m = (1 << l) - n; + if (!l) + return 0; + + v = vp9_read_literal(br, l - 1); + return v < m ? v : (v << 1) - m + vp9_read_bit(br); +} + +static int decode_term_subexp(BOOL_DECODER *br, int k, int num_syms) { + int i = 0, mk = 0, word; + while (1) { + const int b = i ? k + i - 1 : k; + const int a = 1 << b; + if (num_syms <= mk + 3 * a) { + word = decode_uniform(br, num_syms - mk) + mk; + break; + } else { + if (vp9_read_bit(br)) { + i++; + mk += a; + } else { + word = vp9_read_literal(br, b) + mk; + break; + } + } + } + return word; +} + +static int decode_unsigned_max(BOOL_DECODER *br, int max) { + int data = 0, bit = 0, lmax = max; + + while (lmax) { + data |= vp9_read_bit(br) << bit++; + lmax >>= 1; + } + return data > max ? max : data; +} + static int merge_index(int v, int n, int modulus) { int max1 = (n - 1 - modulus / 2) / modulus + 1; if (v < max1) v = v * modulus + modulus / 2; @@ -85,14 +148,14 @@ static int inv_remap_prob(int v, int m) { v = merge_index(v, n - 1, modulus); if ((m << 1) <= n) { - return vp9_inv_recenter_nonneg(v + 1, m); + return inv_recenter_nonneg(v + 1, m); } else { - return n - 1 - vp9_inv_recenter_nonneg(v + 1, n - 1 - m); + return n - 1 - inv_recenter_nonneg(v + 1, n - 1 - m); } } static vp9_prob read_prob_diff_update(vp9_reader *const bc, int oldp) { - int delp = vp9_decode_term_subexp(bc, SUBEXP_PARAM, 255); + int delp = decode_term_subexp(bc, SUBEXP_PARAM, 255); return (vp9_prob)inv_remap_prob(delp, oldp); } @@ -102,15 +165,15 @@ void vp9_init_de_quantizer(VP9D_COMP *pbi) { VP9_COMMON *const pc = &pbi->common; for (q = 0; q < QINDEX_RANGE; 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); + pc->y_dequant[q][0] = (int16_t)vp9_dc_quant(q, pc->y_dc_delta_q); + pc->uv_dequant[q][0] = (int16_t)vp9_dc_uv_quant(q, pc->uv_dc_delta_q); /* all the ac values =; */ for (i = 1; i < 16; i++) { const int rc = vp9_default_zig_zag1d_4x4[i]; 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); + pc->uv_dequant[q][rc] = (int16_t)vp9_ac_uv_quant(q, pc->uv_ac_delta_q); } } } @@ -868,16 +931,18 @@ static void decode_modes_sb(VP9D_COMP *pbi, int mb_row, int mb_col, } /* Decode a row of Superblocks (4x4 region of MBs) */ -static void decode_sb_row(VP9D_COMP *pbi, int mb_row, vp9_reader* r) { +static void decode_tile(VP9D_COMP *pbi, vp9_reader* r) { VP9_COMMON *const pc = &pbi->common; - int mb_col; - - // For a SB there are 2 left contexts, each pertaining to a MB row within - vpx_memset(pc->left_context, 0, sizeof(pc->left_context)); - - for (mb_col = pc->cur_tile_mb_col_start; - mb_col < pc->cur_tile_mb_col_end; mb_col += 4) { - decode_modes_sb(pbi, mb_row, mb_col, r, BLOCK_SIZE_SB64X64); + int mb_row, mb_col; + + for (mb_row = pc->cur_tile_mb_row_start; + mb_row < pc->cur_tile_mb_row_end; mb_row += 4) { + // For a SB there are 2 left contexts, each pertaining to a MB row within + vpx_memset(pc->left_context, 0, sizeof(pc->left_context)); + for (mb_col = pc->cur_tile_mb_col_start; + mb_col < pc->cur_tile_mb_col_end; mb_col += 4) { + decode_modes_sb(pbi, mb_row, mb_col, r, BLOCK_SIZE_SB64X64); + } } } @@ -1132,7 +1197,7 @@ static void setup_segmentation(VP9_COMMON *pc, MACROBLOCKD *xd, vp9_reader *r) { const int feature_enabled = vp9_read_bit(r); if (feature_enabled) { vp9_enable_segfeature(xd, i, j); - data = vp9_decode_unsigned_max(r, vp9_seg_feature_data_max(j)); + data = decode_unsigned_max(r, vp9_seg_feature_data_max(j)); if (vp9_is_segfeature_signed(j)) data = vp9_read_and_apply_sign(r, data); } @@ -1148,9 +1213,9 @@ static void setup_pred_probs(VP9_COMMON *pc, vp9_reader *r) { // reference frame if (pc->frame_type == KEY_FRAME) { // Set the prediction probabilities to defaults - pc->ref_pred_probs[0] = 120; - pc->ref_pred_probs[1] = 80; - pc->ref_pred_probs[2] = 40; + pc->ref_pred_probs[0] = DEFAULT_PRED_PROB_0; + pc->ref_pred_probs[1] = DEFAULT_PRED_PROB_1; + pc->ref_pred_probs[2] = DEFAULT_PRED_PROB_2; } else { int i; for (i = 0; i < PREDICTION_PROBS; ++i) @@ -1203,9 +1268,9 @@ static void setup_quantization(VP9D_COMP *pbi, vp9_reader *r) { 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)) + if (get_delta_q(r, &pc->y_dc_delta_q) | + get_delta_q(r, &pc->uv_dc_delta_q) | + get_delta_q(r, &pc->uv_ac_delta_q)) vp9_init_de_quantizer(pbi); mb_init_dequantizer(pbi, &pbi->mb); // MB level dequantizer setup @@ -1215,8 +1280,17 @@ static const uint8_t *read_frame_size(VP9_COMMON *const pc, const uint8_t *data, const uint8_t *data_end, int *width, int *height) { if (data + 4 < data_end) { - *width = read_le16(data); - *height = read_le16(data + 2); + const int w = read_le16(data); + const int h = read_le16(data + 2); + if (w <= 0) + vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, + "Invalid frame width"); + + if (h <= 0) + vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, + "Invalid frame height"); + *width = w; + *height = h; data += 4; } else { vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, @@ -1242,14 +1316,6 @@ static const uint8_t *setup_frame_size(VP9D_COMP *pbi, int scaling_active, data = read_frame_size(pc, data, data_end, &width, &height); if (pc->width != width || pc->height != height) { - if (width <= 0) - vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, - "Invalid frame width"); - - if (height <= 0) - vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, - "Invalid frame height"); - if (!pbi->initial_width || !pbi->initial_height) { if (vp9_alloc_frame_buffers(pc, width, height)) vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, @@ -1342,7 +1408,6 @@ static void decode_tiles(VP9D_COMP *pbi, const uint8_t *data_ptr = data + first_partition_size; int tile_row, tile_col, delta_log2_tiles; - int mb_row; vp9_get_tile_n_bits(pc, &pc->log2_tile_columns, &delta_log2_tiles); while (delta_log2_tiles--) { @@ -1388,13 +1453,7 @@ static void decode_tiles(VP9D_COMP *pbi, for (tile_col = n_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], residual_bc); - - // 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, mb_row, residual_bc); - } - + decode_tile(pbi, residual_bc); if (tile_row == pc->tile_rows - 1 && tile_col == n_cols - 1) bc_bak = *residual_bc; } @@ -1411,14 +1470,8 @@ static void decode_tiles(VP9D_COMP *pbi, has_more = tile_col < pc->tile_columns - 1 || tile_row < pc->tile_rows - 1; - // Setup decoder setup_token_decoder(pbi, data_ptr + (has_more ? 4 : 0), residual_bc); - - // 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, mb_row, residual_bc); - } + decode_tile(pbi, residual_bc); if (has_more) { const int size = read_le32(data_ptr); diff --git a/vp9/decoder/vp9_detokenize.c b/vp9/decoder/vp9_detokenize.c index 2679be4bc..b3a6927c2 100644 --- a/vp9/decoder/vp9_detokenize.c +++ b/vp9/decoder/vp9_detokenize.c @@ -72,7 +72,7 @@ DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]); #if CONFIG_CODE_NONZEROCOUNT #define WRITE_COEF_CONTINUE(val, token) \ { \ - qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(br, val); \ + qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(r, val); \ INCREMENT_COUNT(token); \ c++; \ nzc++; \ @@ -81,7 +81,7 @@ DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]); #else #define WRITE_COEF_CONTINUE(val, token) \ { \ - qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(br, val); \ + qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(r, val); \ INCREMENT_COUNT(token); \ c++; \ continue; \ @@ -90,12 +90,12 @@ DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]); #define ADJUST_COEF(prob, bits_count) \ do { \ - if (vp9_read(br, prob)) \ + if (vp9_read(r, prob)) \ val += 1 << bits_count; \ } while (0); static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd, - BOOL_DECODER* const br, int block_idx, + vp9_reader *r, int block_idx, PLANE_TYPE type, int seg_eob, int16_t *qcoeff_ptr, TX_SIZE txfm_size) { ENTROPY_CONTEXT* const A0 = (ENTROPY_CONTEXT *) xd->above_context; @@ -251,7 +251,7 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd, break; } - VP9_COMBINEENTROPYCONTEXTS(pt, above_ec, left_ec); + pt = combine_entropy_contexts(above_ec, left_ec); nb = vp9_get_coef_neighbors_handle(scan, &pad); while (1) { @@ -270,7 +270,7 @@ static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd, #if CONFIG_CODE_NONZEROCOUNT if (!nzc_used) #endif - if (!vp9_read(br, prob[EOB_CONTEXT_NODE])) + if (!vp9_read(r, prob[EOB_CONTEXT_NODE])) break; SKIP_START: if (c >= seg_eob) @@ -281,29 +281,29 @@ SKIP_START: // decode zero node only if there are zeros left if (!nzc_used || seg_eob - nzc_expected - c + nzc > 0) #endif - if (!vp9_read(br, prob[ZERO_CONTEXT_NODE])) { + if (!vp9_read(r, prob[ZERO_CONTEXT_NODE])) { INCREMENT_COUNT(ZERO_TOKEN); ++c; prob = coef_probs[type][ref][get_coef_band(scan, txfm_size, c)][pt]; goto SKIP_START; } // ONE_CONTEXT_NODE_0_ - if (!vp9_read(br, prob[ONE_CONTEXT_NODE])) { + if (!vp9_read(r, prob[ONE_CONTEXT_NODE])) { WRITE_COEF_CONTINUE(1, ONE_TOKEN); } // LOW_VAL_CONTEXT_NODE_0_ - if (!vp9_read(br, prob[LOW_VAL_CONTEXT_NODE])) { - if (!vp9_read(br, prob[TWO_CONTEXT_NODE])) { + if (!vp9_read(r, prob[LOW_VAL_CONTEXT_NODE])) { + if (!vp9_read(r, prob[TWO_CONTEXT_NODE])) { WRITE_COEF_CONTINUE(2, TWO_TOKEN); } - if (!vp9_read(br, prob[THREE_CONTEXT_NODE])) { + if (!vp9_read(r, prob[THREE_CONTEXT_NODE])) { WRITE_COEF_CONTINUE(3, THREE_TOKEN); } WRITE_COEF_CONTINUE(4, FOUR_TOKEN); } // HIGH_LOW_CONTEXT_NODE_0_ - if (!vp9_read(br, prob[HIGH_LOW_CONTEXT_NODE])) { - if (!vp9_read(br, prob[CAT_ONE_CONTEXT_NODE])) { + if (!vp9_read(r, prob[HIGH_LOW_CONTEXT_NODE])) { + if (!vp9_read(r, prob[CAT_ONE_CONTEXT_NODE])) { val = CAT1_MIN_VAL; ADJUST_COEF(CAT1_PROB0, 0); WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY1); @@ -314,8 +314,8 @@ SKIP_START: WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY2); } // CAT_THREEFOUR_CONTEXT_NODE_0_ - if (!vp9_read(br, prob[CAT_THREEFOUR_CONTEXT_NODE])) { - if (!vp9_read(br, prob[CAT_THREE_CONTEXT_NODE])) { + if (!vp9_read(r, prob[CAT_THREEFOUR_CONTEXT_NODE])) { + if (!vp9_read(r, prob[CAT_THREE_CONTEXT_NODE])) { val = CAT3_MIN_VAL; ADJUST_COEF(CAT3_PROB2, 2); ADJUST_COEF(CAT3_PROB1, 1); @@ -330,7 +330,7 @@ SKIP_START: WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY4); } // CAT_FIVE_CONTEXT_NODE_0_: - if (!vp9_read(br, prob[CAT_FIVE_CONTEXT_NODE])) { + if (!vp9_read(r, prob[CAT_FIVE_CONTEXT_NODE])) { val = CAT5_MIN_VAL; ADJUST_COEF(CAT5_PROB4, 4); ADJUST_COEF(CAT5_PROB3, 3); @@ -341,7 +341,7 @@ SKIP_START: } val = 0; while (*cat6) { - val = (val << 1) | vp9_read(br, *cat6++); + val = (val << 1) | vp9_read(r, *cat6++); } val += CAT6_MIN_VAL; WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY6); @@ -398,7 +398,7 @@ static int get_eob(MACROBLOCKD* const xd, int segment_id, int eob_max) { struct decode_block_args { VP9D_COMP *pbi; MACROBLOCKD *xd; - BOOL_DECODER *bc; + vp9_reader *r; int *eobtotal; }; static void decode_block(int plane, int block, @@ -416,7 +416,7 @@ static void decode_block(int plane, int block, const int seg_eob = get_eob(arg->xd, segment_id, 16 << ss_txfrm_size); int16_t* const qcoeff_base = arg->xd->plane[plane].qcoeff; - const int eob = decode_coefs(arg->pbi, arg->xd, arg->bc, old_block_idx, + const int eob = decode_coefs(arg->pbi, arg->xd, arg->r, old_block_idx, arg->xd->plane[plane].plane_type, seg_eob, BLOCK_OFFSET(qcoeff_base, block, 16), ss_tx_size); @@ -427,20 +427,20 @@ static void decode_block(int plane, int block, int vp9_decode_tokens(VP9D_COMP* const pbi, MACROBLOCKD* const xd, - BOOL_DECODER* const bc, + vp9_reader *r, BLOCK_SIZE_TYPE bsize) { int eobtotal = 0; - struct decode_block_args args = {pbi, xd, bc, &eobtotal}; + struct decode_block_args args = {pbi, xd, r, &eobtotal}; foreach_transformed_block(xd, bsize, decode_block, &args); return eobtotal; } #if CONFIG_NEWBINTRAMODES static int decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd, - BOOL_DECODER* const bc, + vp9_reader *r, PLANE_TYPE type, int i, int seg_eob) { const struct plane_block_idx pb_idx = plane_block_idx(16, i); - const int c = decode_coefs(dx, xd, bc, i, type, seg_eob, + const int c = decode_coefs(dx, xd, r, i, type, seg_eob, BLOCK_OFFSET(xd->plane[pb_idx.plane].qcoeff, pb_idx.block, 16), TX_4X4); xd->plane[pb_idx.plane].eobs[pb_idx.block] = c; return c; @@ -448,31 +448,31 @@ static int decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd, static int decode_mb_tokens_4x4_uv(VP9D_COMP* const dx, MACROBLOCKD* const xd, - BOOL_DECODER* const bc, + vp9_reader *r, int seg_eob) { int i, eobtotal = 0; // chroma blocks for (i = 16; i < 24; i++) - eobtotal += decode_coefs_4x4(dx, xd, bc, PLANE_TYPE_UV, i, seg_eob); + eobtotal += decode_coefs_4x4(dx, xd, r, PLANE_TYPE_UV, i, seg_eob); return eobtotal; } int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx, MACROBLOCKD* const xd, - BOOL_DECODER* const bc) { + vp9_reader *r) { const int segment_id = xd->mode_info_context->mbmi.segment_id; const int seg_eob = get_eob(xd, segment_id, 16); - return decode_mb_tokens_4x4_uv(dx, xd, bc, seg_eob); + return decode_mb_tokens_4x4_uv(dx, xd, r, seg_eob); } int vp9_decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd, - BOOL_DECODER* const bc, + vp9_reader *r, PLANE_TYPE type, int i) { const int segment_id = xd->mode_info_context->mbmi.segment_id; const int seg_eob = get_eob(xd, segment_id, 16); - return decode_coefs_4x4(dx, xd, bc, type, i, seg_eob); + return decode_coefs_4x4(dx, xd, r, type, i, seg_eob); } #endif diff --git a/vp9/decoder/vp9_detokenize.h b/vp9/decoder/vp9_detokenize.h index e0c29686f..74352a323 100644 --- a/vp9/decoder/vp9_detokenize.h +++ b/vp9/decoder/vp9_detokenize.h @@ -16,14 +16,14 @@ int vp9_decode_tokens(VP9D_COMP* const pbi, MACROBLOCKD* const xd, - BOOL_DECODER* const bc, + vp9_reader *r, BLOCK_SIZE_TYPE bsize); int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx, MACROBLOCKD* const xd, - BOOL_DECODER* const bc); + vp9_reader *r); #if CONFIG_NEWBINTRAMODES int vp9_decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd, - BOOL_DECODER* const bc, + vp9_reader *r, PLANE_TYPE type, int i); #endif diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 8a644d556..bcfbd6094 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -2623,9 +2623,9 @@ void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest, vp9_write_literal(&header_bc, pc->base_qindex, QINDEX_BITS); // Transmit Dc, Second order and Uv quantizer delta information - put_delta_q(&header_bc, pc->y1dc_delta_q); - put_delta_q(&header_bc, pc->uvdc_delta_q); - put_delta_q(&header_bc, pc->uvac_delta_q); + put_delta_q(&header_bc, pc->y_dc_delta_q); + put_delta_q(&header_bc, pc->uv_dc_delta_q); + put_delta_q(&header_bc, pc->uv_ac_delta_q); // When there is a key frame all reference buffers are updated using the new key frame if (pc->frame_type != KEY_FRAME) { diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 8db2796db..5f29c2770 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -1456,14 +1456,14 @@ static void encode_frame_internal(VP9_COMP *cpi) { #endif cpi->mb.e_mbd.lossless = (cm->base_qindex == 0 && - cm->y1dc_delta_q == 0 && - cm->uvdc_delta_q == 0 && - cm->uvac_delta_q == 0); + cm->y_dc_delta_q == 0 && + cm->uv_dc_delta_q == 0 && + cm->uv_ac_delta_q == 0); switch_lossless_mode(cpi, cpi->mb.e_mbd.lossless); vp9_frame_init_quantizer(cpi); - vp9_initialize_rd_consts(cpi, cm->base_qindex + cm->y1dc_delta_q); + vp9_initialize_rd_consts(cpi, cm->base_qindex + cm->y_dc_delta_q); vp9_initialize_me_consts(cpi, cm->base_qindex); if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { diff --git a/vp9/encoder/vp9_encodemb.c b/vp9/encoder/vp9_encodemb.c index e786532a1..dbbde31d2 100644 --- a/vp9/encoder/vp9_encodemb.c +++ b/vp9/encoder/vp9_encodemb.c @@ -574,7 +574,7 @@ static void optimize_b(VP9_COMMON *const cm, /* Now pick the best path through the whole trellis. */ band = get_coef_band(scan, tx_size, i + 1); - VP9_COMBINEENTROPYCONTEXTS(pt, *a, *l); + pt = combine_entropy_contexts(*a, *l); rate0 = tokens[next][0].rate; rate1 = tokens[next][1].rate; error0 = tokens[next][0].error; diff --git a/vp9/encoder/vp9_encodemv.c b/vp9/encoder/vp9_encodemv.c index 7c0b3ddeb..553c69790 100644 --- a/vp9/encoder/vp9_encodemv.c +++ b/vp9/encoder/vp9_encodemv.c @@ -556,30 +556,27 @@ void vp9_write_nmv_probs(VP9_COMP* const cpi, int usehp, vp9_writer* const bc) { } } -void vp9_encode_nmv(vp9_writer* const bc, const MV* const mv, +void vp9_encode_nmv(vp9_writer* w, const MV* const mv, const MV* const ref, const nmv_context* const mvctx) { - MV_JOINT_TYPE j = vp9_get_mv_joint(*mv); - write_token(bc, vp9_mv_joint_tree, mvctx->joints, - vp9_mv_joint_encodings + j); - if (mv_joint_vertical(j)) { - encode_nmv_component(bc, mv->row, ref->col, &mvctx->comps[0]); - } - if (mv_joint_horizontal(j)) { - encode_nmv_component(bc, mv->col, ref->col, &mvctx->comps[1]); - } + const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); + write_token(w, vp9_mv_joint_tree, mvctx->joints, vp9_mv_joint_encodings + j); + if (mv_joint_vertical(j)) + encode_nmv_component(w, mv->row, ref->col, &mvctx->comps[0]); + + if (mv_joint_horizontal(j)) + encode_nmv_component(w, mv->col, ref->col, &mvctx->comps[1]); } void vp9_encode_nmv_fp(vp9_writer* const bc, const MV* const mv, const MV* const ref, const nmv_context* const mvctx, int usehp) { - MV_JOINT_TYPE j = vp9_get_mv_joint(*mv); + const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); usehp = usehp && vp9_use_nmv_hp(ref); - if (mv_joint_vertical(j)) { + if (mv_joint_vertical(j)) encode_nmv_component_fp(bc, mv->row, ref->row, &mvctx->comps[0], usehp); - } - if (mv_joint_horizontal(j)) { + + if (mv_joint_horizontal(j)) encode_nmv_component_fp(bc, mv->col, ref->col, &mvctx->comps[1], usehp); - } } void vp9_build_nmv_cost_table(int *mvjoint, diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 04ef55513..bb6ba7056 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -505,7 +505,7 @@ void vp9_first_pass(VP9_COMP *cpi) { // if ( 0 ) { vp9_init_mv_probs(cm); - vp9_initialize_rd_consts(cpi, cm->base_qindex + cm->y1dc_delta_q); + vp9_initialize_rd_consts(cpi, cm->base_qindex + cm->y_dc_delta_q); } // for each macroblock row in image diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index 1649ccade..caba2ea85 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -56,8 +56,9 @@ int vp9_mv_bit_cost(int_mv *mv, int_mv *ref, int *mvjcost, int *mvcost[2], MV v; v.row = mv->as_mv.row - ref->as_mv.row; v.col = mv->as_mv.col - ref->as_mv.col; - return ((mvjcost[vp9_get_mv_joint(v)] + - mvcost[0][v.row] + mvcost[1][v.col]) * weight) >> 7; + return ((mvjcost[vp9_get_mv_joint(&v)] + + mvcost[0][v.row] + + mvcost[1][v.col]) * weight) >> 7; } static int mv_err_cost(int_mv *mv, int_mv *ref, int *mvjcost, int *mvcost[2], @@ -66,9 +67,9 @@ static int mv_err_cost(int_mv *mv, int_mv *ref, int *mvjcost, int *mvcost[2], MV v; v.row = mv->as_mv.row - ref->as_mv.row; v.col = mv->as_mv.col - ref->as_mv.col; - return ((mvjcost[vp9_get_mv_joint(v)] + - mvcost[0][v.row] + mvcost[1][v.col]) * - error_per_bit + 4096) >> 13; + return ROUND_POWER_OF_TWO((mvjcost[vp9_get_mv_joint(&v)] + + mvcost[0][v.row] + + mvcost[1][v.col]) * error_per_bit, 13); } return 0; } @@ -79,10 +80,9 @@ static int mvsad_err_cost(int_mv *mv, int_mv *ref, int *mvjsadcost, MV v; v.row = mv->as_mv.row - ref->as_mv.row; v.col = mv->as_mv.col - ref->as_mv.col; - - return ROUND_POWER_OF_TWO((mvjsadcost[vp9_get_mv_joint(v)] + - mvsadcost[0][v.row] + mvsadcost[1][v.col]) * - error_per_bit, 8); + return ROUND_POWER_OF_TWO((mvjsadcost[vp9_get_mv_joint(&v)] + + mvsadcost[0][v.row] + + mvsadcost[1][v.col]) * error_per_bit, 8); } return 0; } diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index dc02f146e..9997e188c 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -3974,13 +3974,13 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags, cm->frame_type = INTER_FRAME; cm->frame_flags = *frame_flags; - /* Reset the frame pointers to the current frame size */ + // Reset the frame pointers to the current frame size vp8_yv12_realloc_frame_buffer(&cm->yv12_fb[cm->new_fb_idx], cm->width, cm->height, VP9BORDERINPIXELS); - /* Calculate scaling factors for each of the 3 available references */ - for (i = 0; i < 3; ++i) { + // Calculate scaling factors for each of the 3 available references + for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i) { if (cm->active_ref_idx[i] >= NUM_YV12_BUFFERS) { memset(&cm->active_ref_scale[i], 0, sizeof(cm->active_ref_scale[i])); continue; diff --git a/vp9/encoder/vp9_quantize.c b/vp9/encoder/vp9_quantize.c index 1401bd64e..80d984965 100644 --- a/vp9/encoder/vp9_quantize.c +++ b/vp9/encoder/vp9_quantize.c @@ -542,14 +542,14 @@ void vp9_init_quantizer(VP9_COMP *cpi) { qrounding_factor = 64; } // dc values - quant_val = vp9_dc_quant(q, cpi->common.y1dc_delta_q); + quant_val = vp9_dc_quant(q, cpi->common.y_dc_delta_q); 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.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); + quant_val = vp9_dc_uv_quant(q, cpi->common.uv_dc_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; @@ -568,7 +568,7 @@ void vp9_init_quantizer(VP9_COMP *cpi) { cpi->zrun_zbin_boost_y1[q][i] = ROUND_POWER_OF_TWO(quant_val * zbin_boost[i], 7); - quant_val = vp9_ac_uv_quant(q, cpi->common.uvac_delta_q); + quant_val = vp9_ac_uv_quant(q, cpi->common.uv_ac_delta_q); 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; @@ -677,9 +677,9 @@ void vp9_set_quantizer(struct VP9_COMP *cpi, int Q) { // if any of the delta_q values are changing update flag will // have to be set. - cm->y1dc_delta_q = 0; - cm->uvdc_delta_q = 0; - cm->uvac_delta_q = 0; + cm->y_dc_delta_q = 0; + cm->uv_dc_delta_q = 0; + cm->uv_ac_delta_q = 0; // quantizer has to be reinitialized if any delta_q changes. // As there are not any here for now this is inactive code. diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 73c126912..900f889fc 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -496,7 +496,7 @@ static INLINE int cost_coeffs(VP9_COMMON *const cm, MACROBLOCK *mb, } assert(eob <= seg_eob); - VP9_COMBINEENTROPYCONTEXTS(pt, a_ec, l_ec); + pt = combine_entropy_contexts(a_ec, l_ec); nb = vp9_get_coef_neighbors_handle(scan, &pad); default_eob = seg_eob; @@ -3358,7 +3358,7 @@ static void rd_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, int_mv seg_mvs[NB_PARTITIONINGS][16 /* n_blocks */][MAX_REF_FRAMES - 1]; int intra_cost_penalty = 20 * vp9_dc_quant(cpi->common.base_qindex, - cpi->common.y1dc_delta_q); + cpi->common.y_dc_delta_q); struct scale_factors scale_factor[4]; diff --git a/vp9/encoder/vp9_tokenize.c b/vp9/encoder/vp9_tokenize.c index e38add602..b68ef5d23 100644 --- a/vp9/encoder/vp9_tokenize.c +++ b/vp9/encoder/vp9_tokenize.c @@ -287,7 +287,7 @@ static void tokenize_b(VP9_COMP *cpi, break; } - VP9_COMBINEENTROPYCONTEXTS(pt, a_ec, l_ec); + pt = combine_entropy_contexts(a_ec, l_ec); nb = vp9_get_coef_neighbors_handle(scan, &pad); default_eob = seg_eob; @@ -807,7 +807,7 @@ static void stuff_b(VP9_COMP *cpi, #if CONFIG_CODE_NONZEROCOUNT if (!nzc_used) { #endif - VP9_COMBINEENTROPYCONTEXTS(pt, a_ec, l_ec); + pt = combine_entropy_contexts(a_ec, l_ec); band = 0; t->Token = DCT_EOB_TOKEN; t->context_tree = probs[type][ref][band][pt]; |