From 68569dee1416593955c1570d638b3d9250b33012 Mon Sep 17 00:00:00 2001 From: trav90 Date: Mon, 15 Oct 2018 21:45:30 -0500 Subject: Import aom library This is the reference implementation for the Alliance for Open Media's av1 video code. The commit used was 4d668d7feb1f8abd809d1bca0418570a7f142a36. --- third_party/aom/av1/encoder/encodemv.c | 497 +++++++++++++++++++++++++++++++++ 1 file changed, 497 insertions(+) create mode 100644 third_party/aom/av1/encoder/encodemv.c (limited to 'third_party/aom/av1/encoder/encodemv.c') diff --git a/third_party/aom/av1/encoder/encodemv.c b/third_party/aom/av1/encoder/encodemv.c new file mode 100644 index 000000000..a2a53f840 --- /dev/null +++ b/third_party/aom/av1/encoder/encodemv.c @@ -0,0 +1,497 @@ +/* + * Copyright (c) 2016, Alliance for Open Media. All rights reserved + * + * This source code is subject to the terms of the BSD 2 Clause License and + * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License + * was not distributed with this source code in the LICENSE file, you can + * obtain it at www.aomedia.org/license/software. If the Alliance for Open + * Media Patent License 1.0 was not distributed with this source code in the + * PATENTS file, you can obtain it at www.aomedia.org/license/patent. + */ + +#include + +#include "av1/common/common.h" +#include "av1/common/entropymode.h" + +#include "av1/encoder/cost.h" +#include "av1/encoder/encodemv.h" +#include "av1/encoder/subexp.h" + +#include "aom_dsp/aom_dsp_common.h" + +static struct av1_token mv_joint_encodings[MV_JOINTS]; +static struct av1_token mv_class_encodings[MV_CLASSES]; +static struct av1_token mv_fp_encodings[MV_FP_SIZE]; + +void av1_entropy_mv_init(void) { + av1_tokens_from_tree(mv_joint_encodings, av1_mv_joint_tree); + av1_tokens_from_tree(mv_class_encodings, av1_mv_class_tree); + av1_tokens_from_tree(mv_fp_encodings, av1_mv_fp_tree); +} + +static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, + int usehp) { + int offset; + const int sign = comp < 0; + const int mag = sign ? -comp : comp; + const int mv_class = av1_get_mv_class(mag - 1, &offset); + const int d = offset >> 3; // int mv data + const int fr = (offset >> 1) & 3; // fractional mv data + const int hp = offset & 1; // high precision mv data + + assert(comp != 0); + + // Sign + aom_write(w, sign, mvcomp->sign); + +// Class +#if CONFIG_EC_MULTISYMBOL + aom_write_symbol(w, mv_class, mvcomp->class_cdf, MV_CLASSES); +#else + av1_write_token(w, av1_mv_class_tree, mvcomp->classes, + &mv_class_encodings[mv_class]); +#endif + + // Integer bits + if (mv_class == MV_CLASS_0) { + aom_write(w, d, mvcomp->class0[0]); + } else { + int i; + const int n = mv_class + CLASS0_BITS - 1; // number of bits + for (i = 0; i < n; ++i) aom_write(w, (d >> i) & 1, mvcomp->bits[i]); + } + +// Fractional bits +#if CONFIG_EC_MULTISYMBOL + aom_write_symbol( + w, fr, mv_class == MV_CLASS_0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf, + MV_FP_SIZE); +#else + av1_write_token(w, av1_mv_fp_tree, + mv_class == MV_CLASS_0 ? mvcomp->class0_fp[d] : mvcomp->fp, + &mv_fp_encodings[fr]); +#endif + + // High precision bit + if (usehp) + aom_write(w, hp, mv_class == MV_CLASS_0 ? mvcomp->class0_hp : mvcomp->hp); +} + +static void build_nmv_component_cost_table(int *mvcost, + const nmv_component *const mvcomp, + int usehp) { + int i, v; + int sign_cost[2], class_cost[MV_CLASSES], class0_cost[CLASS0_SIZE]; + int bits_cost[MV_OFFSET_BITS][2]; + int class0_fp_cost[CLASS0_SIZE][MV_FP_SIZE], fp_cost[MV_FP_SIZE]; + int class0_hp_cost[2], hp_cost[2]; + + sign_cost[0] = av1_cost_zero(mvcomp->sign); + sign_cost[1] = av1_cost_one(mvcomp->sign); + av1_cost_tokens(class_cost, mvcomp->classes, av1_mv_class_tree); + av1_cost_tokens(class0_cost, mvcomp->class0, av1_mv_class0_tree); + for (i = 0; i < MV_OFFSET_BITS; ++i) { + bits_cost[i][0] = av1_cost_zero(mvcomp->bits[i]); + bits_cost[i][1] = av1_cost_one(mvcomp->bits[i]); + } + + for (i = 0; i < CLASS0_SIZE; ++i) + av1_cost_tokens(class0_fp_cost[i], mvcomp->class0_fp[i], av1_mv_fp_tree); + av1_cost_tokens(fp_cost, mvcomp->fp, av1_mv_fp_tree); + + if (usehp) { + class0_hp_cost[0] = av1_cost_zero(mvcomp->class0_hp); + class0_hp_cost[1] = av1_cost_one(mvcomp->class0_hp); + hp_cost[0] = av1_cost_zero(mvcomp->hp); + hp_cost[1] = av1_cost_one(mvcomp->hp); + } + mvcost[0] = 0; + for (v = 1; v <= MV_MAX; ++v) { + int z, c, o, d, e, f, cost = 0; + z = v - 1; + c = av1_get_mv_class(z, &o); + cost += class_cost[c]; + d = (o >> 3); /* int mv data */ + f = (o >> 1) & 3; /* fractional pel mv data */ + e = (o & 1); /* high precision mv data */ + if (c == MV_CLASS_0) { + cost += class0_cost[d]; + } else { + const int b = c + CLASS0_BITS - 1; /* number of bits */ + for (i = 0; i < b; ++i) cost += bits_cost[i][((d >> i) & 1)]; + } + if (c == MV_CLASS_0) { + cost += class0_fp_cost[d][f]; + } else { + cost += fp_cost[f]; + } + if (usehp) { + if (c == MV_CLASS_0) { + cost += class0_hp_cost[e]; + } else { + cost += hp_cost[e]; + } + } + mvcost[v] = cost + sign_cost[0]; + mvcost[-v] = cost + sign_cost[1]; + } +} + +static void update_mv(aom_writer *w, const unsigned int ct[2], aom_prob *cur_p, + aom_prob upd_p) { + (void)upd_p; +#if CONFIG_TILE_GROUPS + // Just use the default maximum number of tile groups to avoid passing in the + // actual + // number + av1_cond_prob_diff_update(w, cur_p, ct, DEFAULT_MAX_NUM_TG); +#else + av1_cond_prob_diff_update(w, cur_p, ct, 1); +#endif +} + +#if !CONFIG_EC_ADAPT +static void write_mv_update(const aom_tree_index *tree, + aom_prob probs[/*n - 1*/], + const unsigned int counts[/*n - 1*/], int n, + aom_writer *w) { + int i; + unsigned int branch_ct[32][2]; + + // Assuming max number of probabilities <= 32 + assert(n <= 32); + + av1_tree_probs_from_distribution(tree, branch_ct, counts); + for (i = 0; i < n - 1; ++i) + update_mv(w, branch_ct[i], &probs[i], MV_UPDATE_PROB); +} +#endif + +void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w, + nmv_context_counts *const nmv_counts) { + int i; +#if CONFIG_REF_MV + int nmv_ctx = 0; + for (nmv_ctx = 0; nmv_ctx < NMV_CONTEXTS; ++nmv_ctx) { + nmv_context *const mvc = &cm->fc->nmvc[nmv_ctx]; + nmv_context_counts *const counts = &nmv_counts[nmv_ctx]; +#if !CONFIG_EC_ADAPT + write_mv_update(av1_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS, + w); + + for (i = 0; i < 2; ++i) { + int j; + nmv_component *comp = &mvc->comps[i]; + nmv_component_counts *comp_counts = &counts->comps[i]; + + update_mv(w, comp_counts->sign, &comp->sign, MV_UPDATE_PROB); + write_mv_update(av1_mv_class_tree, comp->classes, comp_counts->classes, + MV_CLASSES, w); + write_mv_update(av1_mv_class0_tree, comp->class0, comp_counts->class0, + CLASS0_SIZE, w); + for (j = 0; j < MV_OFFSET_BITS; ++j) + update_mv(w, comp_counts->bits[j], &comp->bits[j], MV_UPDATE_PROB); + } + + for (i = 0; i < 2; ++i) { + int j; + for (j = 0; j < CLASS0_SIZE; ++j) + write_mv_update(av1_mv_fp_tree, mvc->comps[i].class0_fp[j], + counts->comps[i].class0_fp[j], MV_FP_SIZE, w); + + write_mv_update(av1_mv_fp_tree, mvc->comps[i].fp, counts->comps[i].fp, + MV_FP_SIZE, w); + } +#endif + + if (usehp) { + for (i = 0; i < 2; ++i) { + update_mv(w, counts->comps[i].class0_hp, &mvc->comps[i].class0_hp, + MV_UPDATE_PROB); + update_mv(w, counts->comps[i].hp, &mvc->comps[i].hp, MV_UPDATE_PROB); + } + } + } +#else + nmv_context *const mvc = &cm->fc->nmvc; + nmv_context_counts *const counts = nmv_counts; + +#if !CONFIG_EC_ADAPT + write_mv_update(av1_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS, w); + + for (i = 0; i < 2; ++i) { + int j; + nmv_component *comp = &mvc->comps[i]; + nmv_component_counts *comp_counts = &counts->comps[i]; + + update_mv(w, comp_counts->sign, &comp->sign, MV_UPDATE_PROB); + write_mv_update(av1_mv_class_tree, comp->classes, comp_counts->classes, + MV_CLASSES, w); + write_mv_update(av1_mv_class0_tree, comp->class0, comp_counts->class0, + CLASS0_SIZE, w); + for (j = 0; j < MV_OFFSET_BITS; ++j) + update_mv(w, comp_counts->bits[j], &comp->bits[j], MV_UPDATE_PROB); + } + + for (i = 0; i < 2; ++i) { + int j; + for (j = 0; j < CLASS0_SIZE; ++j) { + write_mv_update(av1_mv_fp_tree, mvc->comps[i].class0_fp[j], + counts->comps[i].class0_fp[j], MV_FP_SIZE, w); + } + write_mv_update(av1_mv_fp_tree, mvc->comps[i].fp, counts->comps[i].fp, + MV_FP_SIZE, w); + } +#endif // !CONFIG_EC_ADAPT + + if (usehp) { + for (i = 0; i < 2; ++i) { + update_mv(w, counts->comps[i].class0_hp, &mvc->comps[i].class0_hp, + MV_UPDATE_PROB); + update_mv(w, counts->comps[i].hp, &mvc->comps[i].hp, MV_UPDATE_PROB); + } + } +#endif +} + +void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, const MV *mv, const MV *ref, + nmv_context *mvctx, int usehp) { + const MV diff = { mv->row - ref->row, mv->col - ref->col }; + const MV_JOINT_TYPE j = av1_get_mv_joint(&diff); +#if CONFIG_EC_MULTISYMBOL + aom_write_symbol(w, j, mvctx->joint_cdf, MV_JOINTS); +#else + av1_write_token(w, av1_mv_joint_tree, mvctx->joints, &mv_joint_encodings[j]); +#endif + if (mv_joint_vertical(j)) + encode_mv_component(w, diff.row, &mvctx->comps[0], usehp); + + if (mv_joint_horizontal(j)) + encode_mv_component(w, diff.col, &mvctx->comps[1], usehp); + + // If auto_mv_step_size is enabled then keep track of the largest + // motion vector component used. + if (cpi->sf.mv.auto_mv_step_size) { + unsigned int maxv = AOMMAX(abs(mv->row), abs(mv->col)) >> 3; + cpi->max_mv_magnitude = AOMMAX(maxv, cpi->max_mv_magnitude); + } +} + +#if CONFIG_INTRABC +void av1_encode_dv(aom_writer *w, const MV *mv, const MV *ref, + nmv_context *mvctx) { + const MV diff = { mv->row - ref->row, mv->col - ref->col }; + const MV_JOINT_TYPE j = av1_get_mv_joint(&diff); + +#if CONFIG_EC_MULTISYMBOL + aom_write_symbol(w, j, mvctx->joint_cdf, MV_JOINTS); +#else + av1_write_token(w, av1_mv_joint_tree, mvctx->joints, &mv_joint_encodings[j]); +#endif + if (mv_joint_vertical(j)) + encode_mv_component(w, diff.row, &mvctx->comps[0], 0); + + if (mv_joint_horizontal(j)) + encode_mv_component(w, diff.col, &mvctx->comps[1], 0); +} +#endif // CONFIG_INTRABC + +void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2], + const nmv_context *ctx, int usehp) { + av1_cost_tokens(mvjoint, ctx->joints, av1_mv_joint_tree); + build_nmv_component_cost_table(mvcost[0], &ctx->comps[0], usehp); + build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], usehp); +} + +#if CONFIG_EXT_INTER +static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, + const int_mv mvs[2], +#if CONFIG_REF_MV + const int_mv pred_mvs[2], +#endif + nmv_context_counts *nmv_counts) { + int i; + PREDICTION_MODE mode = mbmi->mode; +#if !CONFIG_REF_MV + nmv_context_counts *counts = nmv_counts; +#endif + + if (mode == NEWMV || mode == NEW_NEWMV) { + for (i = 0; i < 1 + has_second_ref(mbmi); ++i) { + const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0].as_mv; + const MV diff = { mvs[i].as_mv.row - ref->row, + mvs[i].as_mv.col - ref->col }; +#if CONFIG_REF_MV + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = + av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], + mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); + nmv_context_counts *counts = &nmv_counts[nmv_ctx]; + (void)pred_mvs; +#endif + av1_inc_mv(&diff, counts, 1); + } + } else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) { + const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[1]][0].as_mv; + const MV diff = { mvs[1].as_mv.row - ref->row, + mvs[1].as_mv.col - ref->col }; +#if CONFIG_REF_MV + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = + av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], + mbmi_ext->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); + nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#endif + av1_inc_mv(&diff, counts, 1); + } else if (mode == NEW_NEARESTMV || mode == NEW_NEARMV) { + const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0].as_mv; + const MV diff = { mvs[0].as_mv.row - ref->row, + mvs[0].as_mv.col - ref->col }; +#if CONFIG_REF_MV + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = + av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], + mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); + nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#endif + av1_inc_mv(&diff, counts, 1); + } +} + +static void inc_mvs_sub8x8(const MODE_INFO *mi, int block, const int_mv mvs[2], +#if CONFIG_REF_MV + const MB_MODE_INFO_EXT *mbmi_ext, +#endif + nmv_context_counts *nmv_counts) { + int i; + PREDICTION_MODE mode = mi->bmi[block].as_mode; +#if CONFIG_REF_MV + const MB_MODE_INFO *mbmi = &mi->mbmi; +#else + nmv_context_counts *counts = nmv_counts; +#endif + + if (mode == NEWMV || mode == NEW_NEWMV) { + for (i = 0; i < 1 + has_second_ref(&mi->mbmi); ++i) { + const MV *ref = &mi->bmi[block].ref_mv[i].as_mv; + const MV diff = { mvs[i].as_mv.row - ref->row, + mvs[i].as_mv.col - ref->col }; +#if CONFIG_REF_MV + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = + av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], + mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); + nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#endif + av1_inc_mv(&diff, counts, 1); + } + } else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) { + const MV *ref = &mi->bmi[block].ref_mv[1].as_mv; + const MV diff = { mvs[1].as_mv.row - ref->row, + mvs[1].as_mv.col - ref->col }; +#if CONFIG_REF_MV + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = + av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], + mbmi_ext->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); + nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#endif + av1_inc_mv(&diff, counts, 1); + } else if (mode == NEW_NEARESTMV || mode == NEW_NEARMV) { + const MV *ref = &mi->bmi[block].ref_mv[0].as_mv; + const MV diff = { mvs[0].as_mv.row - ref->row, + mvs[0].as_mv.col - ref->col }; +#if CONFIG_REF_MV + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = + av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], + mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); + nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#endif + av1_inc_mv(&diff, counts, 1); + } +} +#else +static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, + const int_mv mvs[2], +#if CONFIG_REF_MV + const int_mv pred_mvs[2], +#endif + nmv_context_counts *nmv_counts) { + int i; +#if !CONFIG_REF_MV + nmv_context_counts *counts = nmv_counts; +#endif + + for (i = 0; i < 1 + has_second_ref(mbmi); ++i) { +#if CONFIG_REF_MV + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = + av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], + mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); + nmv_context_counts *counts = &nmv_counts[nmv_ctx]; + const MV *ref = &pred_mvs[i].as_mv; +#else + const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0].as_mv; +#endif + const MV diff = { mvs[i].as_mv.row - ref->row, + mvs[i].as_mv.col - ref->col }; + av1_inc_mv(&diff, counts, 1); + } +} +#endif // CONFIG_EXT_INTER + +void av1_update_mv_count(ThreadData *td) { + const MACROBLOCKD *xd = &td->mb.e_mbd; + const MODE_INFO *mi = xd->mi[0]; + const MB_MODE_INFO *const mbmi = &mi->mbmi; + const MB_MODE_INFO_EXT *mbmi_ext = td->mb.mbmi_ext; +#if CONFIG_CB4X4 + const int unify_bsize = 1; +#else + const int unify_bsize = 0; +#endif + + if (mbmi->sb_type < BLOCK_8X8 && !unify_bsize) { + const int num_4x4_w = num_4x4_blocks_wide_lookup[mbmi->sb_type]; + const int num_4x4_h = num_4x4_blocks_high_lookup[mbmi->sb_type]; + int idx, idy; + + for (idy = 0; idy < 2; idy += num_4x4_h) { + for (idx = 0; idx < 2; idx += num_4x4_w) { + const int i = idy * 2 + idx; + +#if CONFIG_EXT_INTER + if (have_newmv_in_inter_mode(mi->bmi[i].as_mode)) + inc_mvs_sub8x8(mi, i, mi->bmi[i].as_mv, +#if CONFIG_REF_MV + mbmi_ext, td->counts->mv); +#else + &td->counts->mv); +#endif +#else + if (mi->bmi[i].as_mode == NEWMV) + inc_mvs(mbmi, mbmi_ext, mi->bmi[i].as_mv, +#if CONFIG_REF_MV + mi->bmi[i].pred_mv, td->counts->mv); +#else + &td->counts->mv); +#endif +#endif // CONFIG_EXT_INTER + } + } + } else { +#if CONFIG_EXT_INTER + if (have_newmv_in_inter_mode(mbmi->mode)) +#else + if (mbmi->mode == NEWMV) +#endif // CONFIG_EXT_INTER + inc_mvs(mbmi, mbmi_ext, mbmi->mv, +#if CONFIG_REF_MV + mbmi->pred_mv, td->counts->mv); +#else + &td->counts->mv); +#endif + } +} -- cgit v1.2.3 From df9477dfa60ebb5d31bc142e58ce46535c17abce Mon Sep 17 00:00:00 2001 From: trav90 Date: Wed, 17 Oct 2018 05:59:08 -0500 Subject: Update aom to slightly newer commit ID --- third_party/aom/av1/encoder/encodemv.c | 124 +++------------------------------ 1 file changed, 8 insertions(+), 116 deletions(-) (limited to 'third_party/aom/av1/encoder/encodemv.c') diff --git a/third_party/aom/av1/encoder/encodemv.c b/third_party/aom/av1/encoder/encodemv.c index a2a53f840..eb0ff88c4 100644 --- a/third_party/aom/av1/encoder/encodemv.c +++ b/third_party/aom/av1/encoder/encodemv.c @@ -45,13 +45,8 @@ static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, // Sign aom_write(w, sign, mvcomp->sign); -// Class -#if CONFIG_EC_MULTISYMBOL + // Class aom_write_symbol(w, mv_class, mvcomp->class_cdf, MV_CLASSES); -#else - av1_write_token(w, av1_mv_class_tree, mvcomp->classes, - &mv_class_encodings[mv_class]); -#endif // Integer bits if (mv_class == MV_CLASS_0) { @@ -62,16 +57,10 @@ static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, for (i = 0; i < n; ++i) aom_write(w, (d >> i) & 1, mvcomp->bits[i]); } -// Fractional bits -#if CONFIG_EC_MULTISYMBOL + // Fractional bits aom_write_symbol( w, fr, mv_class == MV_CLASS_0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf, MV_FP_SIZE); -#else - av1_write_token(w, av1_mv_fp_tree, - mv_class == MV_CLASS_0 ? mvcomp->class0_fp[d] : mvcomp->fp, - &mv_fp_encodings[fr]); -#endif // High precision bit if (usehp) @@ -171,7 +160,6 @@ static void write_mv_update(const aom_tree_index *tree, void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w, nmv_context_counts *const nmv_counts) { int i; -#if CONFIG_REF_MV int nmv_ctx = 0; for (nmv_ctx = 0; nmv_ctx < NMV_CONTEXTS; ++nmv_ctx) { nmv_context *const mvc = &cm->fc->nmvc[nmv_ctx]; @@ -213,57 +201,13 @@ void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w, } } } -#else - nmv_context *const mvc = &cm->fc->nmvc; - nmv_context_counts *const counts = nmv_counts; - -#if !CONFIG_EC_ADAPT - write_mv_update(av1_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS, w); - - for (i = 0; i < 2; ++i) { - int j; - nmv_component *comp = &mvc->comps[i]; - nmv_component_counts *comp_counts = &counts->comps[i]; - - update_mv(w, comp_counts->sign, &comp->sign, MV_UPDATE_PROB); - write_mv_update(av1_mv_class_tree, comp->classes, comp_counts->classes, - MV_CLASSES, w); - write_mv_update(av1_mv_class0_tree, comp->class0, comp_counts->class0, - CLASS0_SIZE, w); - for (j = 0; j < MV_OFFSET_BITS; ++j) - update_mv(w, comp_counts->bits[j], &comp->bits[j], MV_UPDATE_PROB); - } - - for (i = 0; i < 2; ++i) { - int j; - for (j = 0; j < CLASS0_SIZE; ++j) { - write_mv_update(av1_mv_fp_tree, mvc->comps[i].class0_fp[j], - counts->comps[i].class0_fp[j], MV_FP_SIZE, w); - } - write_mv_update(av1_mv_fp_tree, mvc->comps[i].fp, counts->comps[i].fp, - MV_FP_SIZE, w); - } -#endif // !CONFIG_EC_ADAPT - - if (usehp) { - for (i = 0; i < 2; ++i) { - update_mv(w, counts->comps[i].class0_hp, &mvc->comps[i].class0_hp, - MV_UPDATE_PROB); - update_mv(w, counts->comps[i].hp, &mvc->comps[i].hp, MV_UPDATE_PROB); - } - } -#endif } void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, const MV *mv, const MV *ref, nmv_context *mvctx, int usehp) { const MV diff = { mv->row - ref->row, mv->col - ref->col }; const MV_JOINT_TYPE j = av1_get_mv_joint(&diff); -#if CONFIG_EC_MULTISYMBOL aom_write_symbol(w, j, mvctx->joint_cdf, MV_JOINTS); -#else - av1_write_token(w, av1_mv_joint_tree, mvctx->joints, &mv_joint_encodings[j]); -#endif if (mv_joint_vertical(j)) encode_mv_component(w, diff.row, &mvctx->comps[0], usehp); @@ -284,11 +228,7 @@ void av1_encode_dv(aom_writer *w, const MV *mv, const MV *ref, const MV diff = { mv->row - ref->row, mv->col - ref->col }; const MV_JOINT_TYPE j = av1_get_mv_joint(&diff); -#if CONFIG_EC_MULTISYMBOL aom_write_symbol(w, j, mvctx->joint_cdf, MV_JOINTS); -#else - av1_write_token(w, av1_mv_joint_tree, mvctx->joints, &mv_joint_encodings[j]); -#endif if (mv_joint_vertical(j)) encode_mv_component(w, diff.row, &mvctx->comps[0], 0); @@ -306,135 +246,101 @@ void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2], #if CONFIG_EXT_INTER static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, - const int_mv mvs[2], -#if CONFIG_REF_MV - const int_mv pred_mvs[2], -#endif + const int_mv mvs[2], const int_mv pred_mvs[2], nmv_context_counts *nmv_counts) { int i; PREDICTION_MODE mode = mbmi->mode; -#if !CONFIG_REF_MV - nmv_context_counts *counts = nmv_counts; -#endif if (mode == NEWMV || mode == NEW_NEWMV) { for (i = 0; i < 1 + has_second_ref(mbmi); ++i) { const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0].as_mv; const MV diff = { mvs[i].as_mv.row - ref->row, mvs[i].as_mv.col - ref->col }; -#if CONFIG_REF_MV int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; (void)pred_mvs; -#endif av1_inc_mv(&diff, counts, 1); } } else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) { const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[1]][0].as_mv; const MV diff = { mvs[1].as_mv.row - ref->row, mvs[1].as_mv.col - ref->col }; -#if CONFIG_REF_MV int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#endif av1_inc_mv(&diff, counts, 1); } else if (mode == NEW_NEARESTMV || mode == NEW_NEARMV) { const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0].as_mv; const MV diff = { mvs[0].as_mv.row - ref->row, mvs[0].as_mv.col - ref->col }; -#if CONFIG_REF_MV int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#endif av1_inc_mv(&diff, counts, 1); } } static void inc_mvs_sub8x8(const MODE_INFO *mi, int block, const int_mv mvs[2], -#if CONFIG_REF_MV const MB_MODE_INFO_EXT *mbmi_ext, -#endif nmv_context_counts *nmv_counts) { int i; PREDICTION_MODE mode = mi->bmi[block].as_mode; -#if CONFIG_REF_MV const MB_MODE_INFO *mbmi = &mi->mbmi; -#else - nmv_context_counts *counts = nmv_counts; -#endif if (mode == NEWMV || mode == NEW_NEWMV) { for (i = 0; i < 1 + has_second_ref(&mi->mbmi); ++i) { const MV *ref = &mi->bmi[block].ref_mv[i].as_mv; const MV diff = { mvs[i].as_mv.row - ref->row, mvs[i].as_mv.col - ref->col }; -#if CONFIG_REF_MV int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#endif av1_inc_mv(&diff, counts, 1); } } else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) { const MV *ref = &mi->bmi[block].ref_mv[1].as_mv; const MV diff = { mvs[1].as_mv.row - ref->row, mvs[1].as_mv.col - ref->col }; -#if CONFIG_REF_MV int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#endif av1_inc_mv(&diff, counts, 1); } else if (mode == NEW_NEARESTMV || mode == NEW_NEARMV) { const MV *ref = &mi->bmi[block].ref_mv[0].as_mv; const MV diff = { mvs[0].as_mv.row - ref->row, mvs[0].as_mv.col - ref->col }; -#if CONFIG_REF_MV int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#endif av1_inc_mv(&diff, counts, 1); } } #else static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, - const int_mv mvs[2], -#if CONFIG_REF_MV - const int_mv pred_mvs[2], -#endif + const int_mv mvs[2], const int_mv pred_mvs[2], nmv_context_counts *nmv_counts) { int i; -#if !CONFIG_REF_MV - nmv_context_counts *counts = nmv_counts; -#endif for (i = 0; i < 1 + has_second_ref(mbmi); ++i) { -#if CONFIG_REF_MV int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); int nmv_ctx = av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; const MV *ref = &pred_mvs[i].as_mv; -#else - const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0].as_mv; -#endif const MV diff = { mvs[i].as_mv.row - ref->row, mvs[i].as_mv.col - ref->col }; av1_inc_mv(&diff, counts, 1); @@ -464,20 +370,11 @@ void av1_update_mv_count(ThreadData *td) { #if CONFIG_EXT_INTER if (have_newmv_in_inter_mode(mi->bmi[i].as_mode)) - inc_mvs_sub8x8(mi, i, mi->bmi[i].as_mv, -#if CONFIG_REF_MV - mbmi_ext, td->counts->mv); -#else - &td->counts->mv); -#endif + inc_mvs_sub8x8(mi, i, mi->bmi[i].as_mv, mbmi_ext, td->counts->mv); #else if (mi->bmi[i].as_mode == NEWMV) - inc_mvs(mbmi, mbmi_ext, mi->bmi[i].as_mv, -#if CONFIG_REF_MV - mi->bmi[i].pred_mv, td->counts->mv); -#else - &td->counts->mv); -#endif + inc_mvs(mbmi, mbmi_ext, mi->bmi[i].as_mv, mi->bmi[i].pred_mv, + td->counts->mv); #endif // CONFIG_EXT_INTER } } @@ -487,11 +384,6 @@ void av1_update_mv_count(ThreadData *td) { #else if (mbmi->mode == NEWMV) #endif // CONFIG_EXT_INTER - inc_mvs(mbmi, mbmi_ext, mbmi->mv, -#if CONFIG_REF_MV - mbmi->pred_mv, td->counts->mv); -#else - &td->counts->mv); -#endif + inc_mvs(mbmi, mbmi_ext, mbmi->mv, mbmi->pred_mv, td->counts->mv); } } -- cgit v1.2.3 From 7369c7d7a5eed32963d8af37658286617919f91c Mon Sep 17 00:00:00 2001 From: trav90 Date: Thu, 18 Oct 2018 06:04:57 -0500 Subject: Update aom to commit id f5bdeac22930ff4c6b219be49c843db35970b918 --- third_party/aom/av1/encoder/encodemv.c | 143 ++++++++++++++++----------------- 1 file changed, 71 insertions(+), 72 deletions(-) (limited to 'third_party/aom/av1/encoder/encodemv.c') diff --git a/third_party/aom/av1/encoder/encodemv.c b/third_party/aom/av1/encoder/encodemv.c index eb0ff88c4..fd61fe6b2 100644 --- a/third_party/aom/av1/encoder/encodemv.c +++ b/third_party/aom/av1/encoder/encodemv.c @@ -31,7 +31,7 @@ void av1_entropy_mv_init(void) { } static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, - int usehp) { + MvSubpelPrecision precision) { int offset; const int sign = comp < 0; const int mag = sign ? -comp : comp; @@ -42,34 +42,53 @@ static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, assert(comp != 0); - // Sign +// Sign +#if CONFIG_NEW_MULTISYMBOL + aom_write_bit(w, sign); +#else aom_write(w, sign, mvcomp->sign); +#endif // Class aom_write_symbol(w, mv_class, mvcomp->class_cdf, MV_CLASSES); // Integer bits if (mv_class == MV_CLASS_0) { +#if CONFIG_NEW_MULTISYMBOL + aom_write_symbol(w, d, mvcomp->class0_cdf, CLASS0_SIZE); +#else aom_write(w, d, mvcomp->class0[0]); +#endif } else { int i; const int n = mv_class + CLASS0_BITS - 1; // number of bits for (i = 0; i < n; ++i) aom_write(w, (d >> i) & 1, mvcomp->bits[i]); } - // Fractional bits - aom_write_symbol( - w, fr, mv_class == MV_CLASS_0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf, - MV_FP_SIZE); +// Fractional bits +#if CONFIG_INTRABC + if (precision > MV_SUBPEL_NONE) +#endif // CONFIG_INTRABC + { + aom_write_symbol(w, fr, mv_class == MV_CLASS_0 ? mvcomp->class0_fp_cdf[d] + : mvcomp->fp_cdf, + MV_FP_SIZE); + } // High precision bit - if (usehp) + if (precision > MV_SUBPEL_LOW_PRECISION) +#if CONFIG_NEW_MULTISYMBOL + aom_write_symbol( + w, hp, mv_class == MV_CLASS_0 ? mvcomp->class0_hp_cdf : mvcomp->hp_cdf, + 2); +#else aom_write(w, hp, mv_class == MV_CLASS_0 ? mvcomp->class0_hp : mvcomp->hp); +#endif } static void build_nmv_component_cost_table(int *mvcost, const nmv_component *const mvcomp, - int usehp) { + MvSubpelPrecision precision) { int i, v; int sign_cost[2], class_cost[MV_CLASSES], class0_cost[CLASS0_SIZE]; int bits_cost[MV_OFFSET_BITS][2]; @@ -89,7 +108,7 @@ static void build_nmv_component_cost_table(int *mvcost, av1_cost_tokens(class0_fp_cost[i], mvcomp->class0_fp[i], av1_mv_fp_tree); av1_cost_tokens(fp_cost, mvcomp->fp, av1_mv_fp_tree); - if (usehp) { + if (precision > MV_SUBPEL_LOW_PRECISION) { class0_hp_cost[0] = av1_cost_zero(mvcomp->class0_hp); class0_hp_cost[1] = av1_cost_one(mvcomp->class0_hp); hp_cost[0] = av1_cost_zero(mvcomp->hp); @@ -110,16 +129,21 @@ static void build_nmv_component_cost_table(int *mvcost, const int b = c + CLASS0_BITS - 1; /* number of bits */ for (i = 0; i < b; ++i) cost += bits_cost[i][((d >> i) & 1)]; } - if (c == MV_CLASS_0) { - cost += class0_fp_cost[d][f]; - } else { - cost += fp_cost[f]; - } - if (usehp) { +#if CONFIG_INTRABC + if (precision > MV_SUBPEL_NONE) +#endif // CONFIG_INTRABC + { if (c == MV_CLASS_0) { - cost += class0_hp_cost[e]; + cost += class0_fp_cost[d][f]; } else { - cost += hp_cost[e]; + cost += fp_cost[f]; + } + if (precision > MV_SUBPEL_LOW_PRECISION) { + if (c == MV_CLASS_0) { + cost += class0_hp_cost[e]; + } else { + cost += hp_cost[e]; + } } } mvcost[v] = cost + sign_cost[0]; @@ -127,36 +151,16 @@ static void build_nmv_component_cost_table(int *mvcost, } } +#if !CONFIG_NEW_MULTISYMBOL static void update_mv(aom_writer *w, const unsigned int ct[2], aom_prob *cur_p, aom_prob upd_p) { (void)upd_p; -#if CONFIG_TILE_GROUPS // Just use the default maximum number of tile groups to avoid passing in the // actual // number av1_cond_prob_diff_update(w, cur_p, ct, DEFAULT_MAX_NUM_TG); -#else - av1_cond_prob_diff_update(w, cur_p, ct, 1); -#endif } -#if !CONFIG_EC_ADAPT -static void write_mv_update(const aom_tree_index *tree, - aom_prob probs[/*n - 1*/], - const unsigned int counts[/*n - 1*/], int n, - aom_writer *w) { - int i; - unsigned int branch_ct[32][2]; - - // Assuming max number of probabilities <= 32 - assert(n <= 32); - - av1_tree_probs_from_distribution(tree, branch_ct, counts); - for (i = 0; i < n - 1; ++i) - update_mv(w, branch_ct[i], &probs[i], MV_UPDATE_PROB); -} -#endif - void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w, nmv_context_counts *const nmv_counts) { int i; @@ -164,34 +168,6 @@ void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w, for (nmv_ctx = 0; nmv_ctx < NMV_CONTEXTS; ++nmv_ctx) { nmv_context *const mvc = &cm->fc->nmvc[nmv_ctx]; nmv_context_counts *const counts = &nmv_counts[nmv_ctx]; -#if !CONFIG_EC_ADAPT - write_mv_update(av1_mv_joint_tree, mvc->joints, counts->joints, MV_JOINTS, - w); - - for (i = 0; i < 2; ++i) { - int j; - nmv_component *comp = &mvc->comps[i]; - nmv_component_counts *comp_counts = &counts->comps[i]; - - update_mv(w, comp_counts->sign, &comp->sign, MV_UPDATE_PROB); - write_mv_update(av1_mv_class_tree, comp->classes, comp_counts->classes, - MV_CLASSES, w); - write_mv_update(av1_mv_class0_tree, comp->class0, comp_counts->class0, - CLASS0_SIZE, w); - for (j = 0; j < MV_OFFSET_BITS; ++j) - update_mv(w, comp_counts->bits[j], &comp->bits[j], MV_UPDATE_PROB); - } - - for (i = 0; i < 2; ++i) { - int j; - for (j = 0; j < CLASS0_SIZE; ++j) - write_mv_update(av1_mv_fp_tree, mvc->comps[i].class0_fp[j], - counts->comps[i].class0_fp[j], MV_FP_SIZE, w); - - write_mv_update(av1_mv_fp_tree, mvc->comps[i].fp, counts->comps[i].fp, - MV_FP_SIZE, w); - } -#endif if (usehp) { for (i = 0; i < 2; ++i) { @@ -202,6 +178,7 @@ void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w, } } } +#endif void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, const MV *mv, const MV *ref, nmv_context *mvctx, int usehp) { @@ -230,18 +207,19 @@ void av1_encode_dv(aom_writer *w, const MV *mv, const MV *ref, aom_write_symbol(w, j, mvctx->joint_cdf, MV_JOINTS); if (mv_joint_vertical(j)) - encode_mv_component(w, diff.row, &mvctx->comps[0], 0); + encode_mv_component(w, diff.row, &mvctx->comps[0], MV_SUBPEL_NONE); if (mv_joint_horizontal(j)) - encode_mv_component(w, diff.col, &mvctx->comps[1], 0); + encode_mv_component(w, diff.col, &mvctx->comps[1], MV_SUBPEL_NONE); } #endif // CONFIG_INTRABC void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2], - const nmv_context *ctx, int usehp) { + const nmv_context *ctx, + MvSubpelPrecision precision) { av1_cost_tokens(mvjoint, ctx->joints, av1_mv_joint_tree); - build_nmv_component_cost_table(mvcost[0], &ctx->comps[0], usehp); - build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], usehp); + build_nmv_component_cost_table(mvcost[0], &ctx->comps[0], precision); + build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], precision); } #if CONFIG_EXT_INTER @@ -284,6 +262,27 @@ static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; av1_inc_mv(&diff, counts, 1); +#if CONFIG_COMPOUND_SINGLEREF + } else { + assert( // mode == SR_NEAREST_NEWMV || + mode == SR_NEAR_NEWMV || mode == SR_ZERO_NEWMV || mode == SR_NEW_NEWMV); + const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0].as_mv; + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = + av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], + mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); + nmv_context_counts *counts = &nmv_counts[nmv_ctx]; + (void)pred_mvs; + MV diff; + if (mode == SR_NEW_NEWMV) { + diff.row = mvs[0].as_mv.row - ref->row; + diff.col = mvs[0].as_mv.col - ref->col; + av1_inc_mv(&diff, counts, 1); + } + diff.row = mvs[1].as_mv.row - ref->row; + diff.col = mvs[1].as_mv.col - ref->col; + av1_inc_mv(&diff, counts, 1); +#endif // CONFIG_COMPOUND_SINGLEREF } } @@ -328,7 +327,7 @@ static void inc_mvs_sub8x8(const MODE_INFO *mi, int block, const int_mv mvs[2], av1_inc_mv(&diff, counts, 1); } } -#else +#else // !CONFIG_EXT_INTER static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, const int_mv mvs[2], const int_mv pred_mvs[2], nmv_context_counts *nmv_counts) { -- cgit v1.2.3 From ec910d81405c736a4490383a250299a7837c2e64 Mon Sep 17 00:00:00 2001 From: trav90 Date: Thu, 18 Oct 2018 21:53:44 -0500 Subject: Update aom to commit id e87fb2378f01103d5d6e477a4ef6892dc714e614 --- third_party/aom/av1/encoder/encodemv.c | 115 ++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 39 deletions(-) (limited to 'third_party/aom/av1/encoder/encodemv.c') diff --git a/third_party/aom/av1/encoder/encodemv.c b/third_party/aom/av1/encoder/encodemv.c index fd61fe6b2..f8a546999 100644 --- a/third_party/aom/av1/encoder/encodemv.c +++ b/third_party/aom/av1/encoder/encodemv.c @@ -62,17 +62,22 @@ static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, } else { int i; const int n = mv_class + CLASS0_BITS - 1; // number of bits +#if CONFIG_NEW_MULTISYMBOL + for (i = 0; i < n; ++i) + aom_write_symbol(w, (d >> i) & 1, mvcomp->bits_cdf[(i + 1) / 2], 2); +#else for (i = 0; i < n; ++i) aom_write(w, (d >> i) & 1, mvcomp->bits[i]); +#endif } - // Fractional bits -#if CONFIG_INTRABC +#if CONFIG_INTRABC || CONFIG_AMVR if (precision > MV_SUBPEL_NONE) -#endif // CONFIG_INTRABC +#endif // CONFIG_INTRABC || CONFIG_AMVR { - aom_write_symbol(w, fr, mv_class == MV_CLASS_0 ? mvcomp->class0_fp_cdf[d] - : mvcomp->fp_cdf, - MV_FP_SIZE); + aom_write_symbol( + w, fr, + mv_class == MV_CLASS_0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf, + MV_FP_SIZE); } // High precision bit @@ -129,9 +134,9 @@ static void build_nmv_component_cost_table(int *mvcost, const int b = c + CLASS0_BITS - 1; /* number of bits */ for (i = 0; i < b; ++i) cost += bits_cost[i][((d >> i) & 1)]; } -#if CONFIG_INTRABC +#if CONFIG_INTRABC || CONFIG_AMVR if (precision > MV_SUBPEL_NONE) -#endif // CONFIG_INTRABC +#endif // CONFIG_INTRABC || CONFIG_AMVR { if (c == MV_CLASS_0) { cost += class0_fp_cost[d][f]; @@ -165,6 +170,11 @@ void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w, nmv_context_counts *const nmv_counts) { int i; int nmv_ctx = 0; +#if CONFIG_AMVR + if (cm->cur_frame_mv_precision_level) { + return; + } +#endif for (nmv_ctx = 0; nmv_ctx < NMV_CONTEXTS; ++nmv_ctx) { nmv_context *const mvc = &cm->fc->nmvc[nmv_ctx]; nmv_context_counts *const counts = &nmv_counts[nmv_ctx]; @@ -184,6 +194,11 @@ void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, const MV *mv, const MV *ref, nmv_context *mvctx, int usehp) { const MV diff = { mv->row - ref->row, mv->col - ref->col }; const MV_JOINT_TYPE j = av1_get_mv_joint(&diff); +#if CONFIG_AMVR + if (cpi->common.cur_frame_mv_precision_level) { + usehp = MV_SUBPEL_NONE; + } +#endif aom_write_symbol(w, j, mvctx->joint_cdf, MV_JOINTS); if (mv_joint_vertical(j)) encode_mv_component(w, diff.row, &mvctx->comps[0], usehp); @@ -222,10 +237,14 @@ void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2], build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], precision); } -#if CONFIG_EXT_INTER static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, const int_mv mvs[2], const int_mv pred_mvs[2], - nmv_context_counts *nmv_counts) { + nmv_context_counts *nmv_counts +#if CONFIG_AMVR + , + MvSubpelPrecision precision +#endif + ) { int i; PREDICTION_MODE mode = mbmi->mode; @@ -240,7 +259,11 @@ static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; (void)pred_mvs; +#if CONFIG_AMVR + av1_inc_mv(&diff, counts, precision); +#else av1_inc_mv(&diff, counts, 1); +#endif } } else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) { const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[1]][0].as_mv; @@ -251,7 +274,11 @@ static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#if CONFIG_AMVR + av1_inc_mv(&diff, counts, precision); +#else av1_inc_mv(&diff, counts, 1); +#endif } else if (mode == NEW_NEARESTMV || mode == NEW_NEARMV) { const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0].as_mv; const MV diff = { mvs[0].as_mv.row - ref->row, @@ -261,7 +288,11 @@ static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#if CONFIG_AMVR + av1_inc_mv(&diff, counts, precision); +#else av1_inc_mv(&diff, counts, 1); +#endif #if CONFIG_COMPOUND_SINGLEREF } else { assert( // mode == SR_NEAREST_NEWMV || @@ -288,7 +319,12 @@ static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, static void inc_mvs_sub8x8(const MODE_INFO *mi, int block, const int_mv mvs[2], const MB_MODE_INFO_EXT *mbmi_ext, - nmv_context_counts *nmv_counts) { + nmv_context_counts *nmv_counts +#if CONFIG_AMVR + , + MvSubpelPrecision precision +#endif + ) { int i; PREDICTION_MODE mode = mi->bmi[block].as_mode; const MB_MODE_INFO *mbmi = &mi->mbmi; @@ -303,7 +339,11 @@ static void inc_mvs_sub8x8(const MODE_INFO *mi, int block, const int_mv mvs[2], av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#if CONFIG_AMVR + av1_inc_mv(&diff, counts, precision); +#else av1_inc_mv(&diff, counts, 1); +#endif } } else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) { const MV *ref = &mi->bmi[block].ref_mv[1].as_mv; @@ -314,7 +354,11 @@ static void inc_mvs_sub8x8(const MODE_INFO *mi, int block, const int_mv mvs[2], av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#if CONFIG_AMVR + av1_inc_mv(&diff, counts, precision); +#else av1_inc_mv(&diff, counts, 1); +#endif } else if (mode == NEW_NEARESTMV || mode == NEW_NEARMV) { const MV *ref = &mi->bmi[block].ref_mv[0].as_mv; const MV diff = { mvs[0].as_mv.row - ref->row, @@ -324,28 +368,13 @@ static void inc_mvs_sub8x8(const MODE_INFO *mi, int block, const int_mv mvs[2], av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); nmv_context_counts *counts = &nmv_counts[nmv_ctx]; +#if CONFIG_AMVR + av1_inc_mv(&diff, counts, precision); +#else av1_inc_mv(&diff, counts, 1); +#endif } } -#else // !CONFIG_EXT_INTER -static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, - const int_mv mvs[2], const int_mv pred_mvs[2], - nmv_context_counts *nmv_counts) { - int i; - - for (i = 0; i < 1 + has_second_ref(mbmi); ++i) { - int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); - int nmv_ctx = - av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], - mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); - nmv_context_counts *counts = &nmv_counts[nmv_ctx]; - const MV *ref = &pred_mvs[i].as_mv; - const MV diff = { mvs[i].as_mv.row - ref->row, - mvs[i].as_mv.col - ref->col }; - av1_inc_mv(&diff, counts, 1); - } -} -#endif // CONFIG_EXT_INTER void av1_update_mv_count(ThreadData *td) { const MACROBLOCKD *xd = &td->mb.e_mbd; @@ -357,6 +386,12 @@ void av1_update_mv_count(ThreadData *td) { #else const int unify_bsize = 0; #endif +#if CONFIG_AMVR + MvSubpelPrecision precision = 1; + if (xd->cur_frame_mv_precision_level) { + precision = MV_SUBPEL_NONE; + } +#endif if (mbmi->sb_type < BLOCK_8X8 && !unify_bsize) { const int num_4x4_w = num_4x4_blocks_wide_lookup[mbmi->sb_type]; @@ -367,22 +402,24 @@ void av1_update_mv_count(ThreadData *td) { for (idx = 0; idx < 2; idx += num_4x4_w) { const int i = idy * 2 + idx; -#if CONFIG_EXT_INTER if (have_newmv_in_inter_mode(mi->bmi[i].as_mode)) - inc_mvs_sub8x8(mi, i, mi->bmi[i].as_mv, mbmi_ext, td->counts->mv); + +#if CONFIG_AMVR + inc_mvs_sub8x8(mi, i, mi->bmi[i].as_mv, mbmi_ext, td->counts->mv, + precision); #else - if (mi->bmi[i].as_mode == NEWMV) - inc_mvs(mbmi, mbmi_ext, mi->bmi[i].as_mv, mi->bmi[i].pred_mv, - td->counts->mv); -#endif // CONFIG_EXT_INTER + inc_mvs_sub8x8(mi, i, mi->bmi[i].as_mv, mbmi_ext, td->counts->mv); +#endif } } } else { -#if CONFIG_EXT_INTER if (have_newmv_in_inter_mode(mbmi->mode)) + +#if CONFIG_AMVR + inc_mvs(mbmi, mbmi_ext, mbmi->mv, mbmi->pred_mv, td->counts->mv, + precision); #else - if (mbmi->mode == NEWMV) -#endif // CONFIG_EXT_INTER inc_mvs(mbmi, mbmi_ext, mbmi->mv, mbmi->pred_mv, td->counts->mv); +#endif } } -- cgit v1.2.3 From bbcc64772580c8a979288791afa02d30bc476d2e Mon Sep 17 00:00:00 2001 From: trav90 Date: Fri, 19 Oct 2018 21:52:15 -0500 Subject: Update aom to v1.0.0 Update aom to commit id d14c5bb4f336ef1842046089849dee4a301fbbf0. --- third_party/aom/av1/encoder/encodemv.c | 336 +++++++-------------------------- 1 file changed, 66 insertions(+), 270 deletions(-) (limited to 'third_party/aom/av1/encoder/encodemv.c') diff --git a/third_party/aom/av1/encoder/encodemv.c b/third_party/aom/av1/encoder/encodemv.c index f8a546999..944e2c53d 100644 --- a/third_party/aom/av1/encoder/encodemv.c +++ b/third_party/aom/av1/encoder/encodemv.c @@ -16,20 +16,9 @@ #include "av1/encoder/cost.h" #include "av1/encoder/encodemv.h" -#include "av1/encoder/subexp.h" #include "aom_dsp/aom_dsp_common.h" -static struct av1_token mv_joint_encodings[MV_JOINTS]; -static struct av1_token mv_class_encodings[MV_CLASSES]; -static struct av1_token mv_fp_encodings[MV_FP_SIZE]; - -void av1_entropy_mv_init(void) { - av1_tokens_from_tree(mv_joint_encodings, av1_mv_joint_tree); - av1_tokens_from_tree(mv_class_encodings, av1_mv_class_tree); - av1_tokens_from_tree(mv_fp_encodings, av1_mv_fp_tree); -} - static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, MvSubpelPrecision precision) { int offset; @@ -42,38 +31,23 @@ static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, assert(comp != 0); -// Sign -#if CONFIG_NEW_MULTISYMBOL - aom_write_bit(w, sign); -#else - aom_write(w, sign, mvcomp->sign); -#endif + // Sign + aom_write_symbol(w, sign, mvcomp->sign_cdf, 2); // Class - aom_write_symbol(w, mv_class, mvcomp->class_cdf, MV_CLASSES); + aom_write_symbol(w, mv_class, mvcomp->classes_cdf, MV_CLASSES); // Integer bits if (mv_class == MV_CLASS_0) { -#if CONFIG_NEW_MULTISYMBOL aom_write_symbol(w, d, mvcomp->class0_cdf, CLASS0_SIZE); -#else - aom_write(w, d, mvcomp->class0[0]); -#endif } else { int i; const int n = mv_class + CLASS0_BITS - 1; // number of bits -#if CONFIG_NEW_MULTISYMBOL for (i = 0; i < n; ++i) - aom_write_symbol(w, (d >> i) & 1, mvcomp->bits_cdf[(i + 1) / 2], 2); -#else - for (i = 0; i < n; ++i) aom_write(w, (d >> i) & 1, mvcomp->bits[i]); -#endif + aom_write_symbol(w, (d >> i) & 1, mvcomp->bits_cdf[i], 2); } -// Fractional bits -#if CONFIG_INTRABC || CONFIG_AMVR - if (precision > MV_SUBPEL_NONE) -#endif // CONFIG_INTRABC || CONFIG_AMVR - { + // Fractional bits + if (precision > MV_SUBPEL_NONE) { aom_write_symbol( w, fr, mv_class == MV_CLASS_0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf, @@ -82,13 +56,9 @@ static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, // High precision bit if (precision > MV_SUBPEL_LOW_PRECISION) -#if CONFIG_NEW_MULTISYMBOL aom_write_symbol( w, hp, mv_class == MV_CLASS_0 ? mvcomp->class0_hp_cdf : mvcomp->hp_cdf, 2); -#else - aom_write(w, hp, mv_class == MV_CLASS_0 ? mvcomp->class0_hp : mvcomp->hp); -#endif } static void build_nmv_component_cost_table(int *mvcost, @@ -100,24 +70,20 @@ static void build_nmv_component_cost_table(int *mvcost, int class0_fp_cost[CLASS0_SIZE][MV_FP_SIZE], fp_cost[MV_FP_SIZE]; int class0_hp_cost[2], hp_cost[2]; - sign_cost[0] = av1_cost_zero(mvcomp->sign); - sign_cost[1] = av1_cost_one(mvcomp->sign); - av1_cost_tokens(class_cost, mvcomp->classes, av1_mv_class_tree); - av1_cost_tokens(class0_cost, mvcomp->class0, av1_mv_class0_tree); + av1_cost_tokens_from_cdf(sign_cost, mvcomp->sign_cdf, NULL); + av1_cost_tokens_from_cdf(class_cost, mvcomp->classes_cdf, NULL); + av1_cost_tokens_from_cdf(class0_cost, mvcomp->class0_cdf, NULL); for (i = 0; i < MV_OFFSET_BITS; ++i) { - bits_cost[i][0] = av1_cost_zero(mvcomp->bits[i]); - bits_cost[i][1] = av1_cost_one(mvcomp->bits[i]); + av1_cost_tokens_from_cdf(bits_cost[i], mvcomp->bits_cdf[i], NULL); } for (i = 0; i < CLASS0_SIZE; ++i) - av1_cost_tokens(class0_fp_cost[i], mvcomp->class0_fp[i], av1_mv_fp_tree); - av1_cost_tokens(fp_cost, mvcomp->fp, av1_mv_fp_tree); + av1_cost_tokens_from_cdf(class0_fp_cost[i], mvcomp->class0_fp_cdf[i], NULL); + av1_cost_tokens_from_cdf(fp_cost, mvcomp->fp_cdf, NULL); if (precision > MV_SUBPEL_LOW_PRECISION) { - class0_hp_cost[0] = av1_cost_zero(mvcomp->class0_hp); - class0_hp_cost[1] = av1_cost_one(mvcomp->class0_hp); - hp_cost[0] = av1_cost_zero(mvcomp->hp); - hp_cost[1] = av1_cost_one(mvcomp->hp); + av1_cost_tokens_from_cdf(class0_hp_cost, mvcomp->class0_hp_cdf, NULL); + av1_cost_tokens_from_cdf(hp_cost, mvcomp->hp_cdf, NULL); } mvcost[0] = 0; for (v = 1; v <= MV_MAX; ++v) { @@ -134,10 +100,7 @@ static void build_nmv_component_cost_table(int *mvcost, const int b = c + CLASS0_BITS - 1; /* number of bits */ for (i = 0; i < b; ++i) cost += bits_cost[i][((d >> i) & 1)]; } -#if CONFIG_INTRABC || CONFIG_AMVR - if (precision > MV_SUBPEL_NONE) -#endif // CONFIG_INTRABC || CONFIG_AMVR - { + if (precision > MV_SUBPEL_NONE) { if (c == MV_CLASS_0) { cost += class0_fp_cost[d][f]; } else { @@ -156,50 +119,14 @@ static void build_nmv_component_cost_table(int *mvcost, } } -#if !CONFIG_NEW_MULTISYMBOL -static void update_mv(aom_writer *w, const unsigned int ct[2], aom_prob *cur_p, - aom_prob upd_p) { - (void)upd_p; - // Just use the default maximum number of tile groups to avoid passing in the - // actual - // number - av1_cond_prob_diff_update(w, cur_p, ct, DEFAULT_MAX_NUM_TG); -} - -void av1_write_nmv_probs(AV1_COMMON *cm, int usehp, aom_writer *w, - nmv_context_counts *const nmv_counts) { - int i; - int nmv_ctx = 0; -#if CONFIG_AMVR - if (cm->cur_frame_mv_precision_level) { - return; - } -#endif - for (nmv_ctx = 0; nmv_ctx < NMV_CONTEXTS; ++nmv_ctx) { - nmv_context *const mvc = &cm->fc->nmvc[nmv_ctx]; - nmv_context_counts *const counts = &nmv_counts[nmv_ctx]; - - if (usehp) { - for (i = 0; i < 2; ++i) { - update_mv(w, counts->comps[i].class0_hp, &mvc->comps[i].class0_hp, - MV_UPDATE_PROB); - update_mv(w, counts->comps[i].hp, &mvc->comps[i].hp, MV_UPDATE_PROB); - } - } - } -} -#endif - void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, const MV *mv, const MV *ref, nmv_context *mvctx, int usehp) { const MV diff = { mv->row - ref->row, mv->col - ref->col }; const MV_JOINT_TYPE j = av1_get_mv_joint(&diff); -#if CONFIG_AMVR - if (cpi->common.cur_frame_mv_precision_level) { + if (cpi->common.cur_frame_force_integer_mv) { usehp = MV_SUBPEL_NONE; } -#endif - aom_write_symbol(w, j, mvctx->joint_cdf, MV_JOINTS); + aom_write_symbol(w, j, mvctx->joints_cdf, MV_JOINTS); if (mv_joint_vertical(j)) encode_mv_component(w, diff.row, &mvctx->comps[0], usehp); @@ -214,212 +141,81 @@ void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, const MV *mv, const MV *ref, } } -#if CONFIG_INTRABC void av1_encode_dv(aom_writer *w, const MV *mv, const MV *ref, nmv_context *mvctx) { + // DV and ref DV should not have sub-pel. + assert((mv->col & 7) == 0); + assert((mv->row & 7) == 0); + assert((ref->col & 7) == 0); + assert((ref->row & 7) == 0); const MV diff = { mv->row - ref->row, mv->col - ref->col }; const MV_JOINT_TYPE j = av1_get_mv_joint(&diff); - aom_write_symbol(w, j, mvctx->joint_cdf, MV_JOINTS); + aom_write_symbol(w, j, mvctx->joints_cdf, MV_JOINTS); if (mv_joint_vertical(j)) encode_mv_component(w, diff.row, &mvctx->comps[0], MV_SUBPEL_NONE); if (mv_joint_horizontal(j)) encode_mv_component(w, diff.col, &mvctx->comps[1], MV_SUBPEL_NONE); } -#endif // CONFIG_INTRABC void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2], const nmv_context *ctx, MvSubpelPrecision precision) { - av1_cost_tokens(mvjoint, ctx->joints, av1_mv_joint_tree); + av1_cost_tokens_from_cdf(mvjoint, ctx->joints_cdf, NULL); build_nmv_component_cost_table(mvcost[0], &ctx->comps[0], precision); build_nmv_component_cost_table(mvcost[1], &ctx->comps[1], precision); } -static void inc_mvs(const MB_MODE_INFO *mbmi, const MB_MODE_INFO_EXT *mbmi_ext, - const int_mv mvs[2], const int_mv pred_mvs[2], - nmv_context_counts *nmv_counts -#if CONFIG_AMVR - , - MvSubpelPrecision precision -#endif - ) { - int i; - PREDICTION_MODE mode = mbmi->mode; - - if (mode == NEWMV || mode == NEW_NEWMV) { - for (i = 0; i < 1 + has_second_ref(mbmi); ++i) { - const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0].as_mv; - const MV diff = { mvs[i].as_mv.row - ref->row, - mvs[i].as_mv.col - ref->col }; - int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); - int nmv_ctx = - av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], - mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); - nmv_context_counts *counts = &nmv_counts[nmv_ctx]; - (void)pred_mvs; -#if CONFIG_AMVR - av1_inc_mv(&diff, counts, precision); -#else - av1_inc_mv(&diff, counts, 1); -#endif +int_mv av1_get_ref_mv_from_stack(int ref_idx, + const MV_REFERENCE_FRAME *ref_frame, + int ref_mv_idx, + const MB_MODE_INFO_EXT *mbmi_ext) { + const int8_t ref_frame_type = av1_ref_frame_type(ref_frame); + const CANDIDATE_MV *curr_ref_mv_stack = + mbmi_ext->ref_mv_stack[ref_frame_type]; + int_mv ref_mv; + ref_mv.as_int = INVALID_MV; + + if (ref_frame[1] > INTRA_FRAME) { + if (ref_idx == 0) { + ref_mv = curr_ref_mv_stack[ref_mv_idx].this_mv; + } else { + assert(ref_idx == 1); + ref_mv = curr_ref_mv_stack[ref_mv_idx].comp_mv; } - } else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) { - const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[1]][0].as_mv; - const MV diff = { mvs[1].as_mv.row - ref->row, - mvs[1].as_mv.col - ref->col }; - int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); - int nmv_ctx = - av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], - mbmi_ext->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); - nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#if CONFIG_AMVR - av1_inc_mv(&diff, counts, precision); -#else - av1_inc_mv(&diff, counts, 1); -#endif - } else if (mode == NEW_NEARESTMV || mode == NEW_NEARMV) { - const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0].as_mv; - const MV diff = { mvs[0].as_mv.row - ref->row, - mvs[0].as_mv.col - ref->col }; - int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); - int nmv_ctx = - av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], - mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); - nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#if CONFIG_AMVR - av1_inc_mv(&diff, counts, precision); -#else - av1_inc_mv(&diff, counts, 1); -#endif -#if CONFIG_COMPOUND_SINGLEREF } else { - assert( // mode == SR_NEAREST_NEWMV || - mode == SR_NEAR_NEWMV || mode == SR_ZERO_NEWMV || mode == SR_NEW_NEWMV); - const MV *ref = &mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0].as_mv; - int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); - int nmv_ctx = - av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], - mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); - nmv_context_counts *counts = &nmv_counts[nmv_ctx]; - (void)pred_mvs; - MV diff; - if (mode == SR_NEW_NEWMV) { - diff.row = mvs[0].as_mv.row - ref->row; - diff.col = mvs[0].as_mv.col - ref->col; - av1_inc_mv(&diff, counts, 1); + assert(ref_idx == 0); + if (ref_mv_idx < mbmi_ext->ref_mv_count[ref_frame_type]) { + ref_mv = curr_ref_mv_stack[ref_mv_idx].this_mv; + } else { + ref_mv = mbmi_ext->global_mvs[ref_frame_type]; } - diff.row = mvs[1].as_mv.row - ref->row; - diff.col = mvs[1].as_mv.col - ref->col; - av1_inc_mv(&diff, counts, 1); -#endif // CONFIG_COMPOUND_SINGLEREF } + return ref_mv; } -static void inc_mvs_sub8x8(const MODE_INFO *mi, int block, const int_mv mvs[2], - const MB_MODE_INFO_EXT *mbmi_ext, - nmv_context_counts *nmv_counts -#if CONFIG_AMVR - , - MvSubpelPrecision precision -#endif - ) { - int i; - PREDICTION_MODE mode = mi->bmi[block].as_mode; - const MB_MODE_INFO *mbmi = &mi->mbmi; - - if (mode == NEWMV || mode == NEW_NEWMV) { - for (i = 0; i < 1 + has_second_ref(&mi->mbmi); ++i) { - const MV *ref = &mi->bmi[block].ref_mv[i].as_mv; - const MV diff = { mvs[i].as_mv.row - ref->row, - mvs[i].as_mv.col - ref->col }; - int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); - int nmv_ctx = - av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], - mbmi_ext->ref_mv_stack[rf_type], i, mbmi->ref_mv_idx); - nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#if CONFIG_AMVR - av1_inc_mv(&diff, counts, precision); -#else - av1_inc_mv(&diff, counts, 1); -#endif - } - } else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) { - const MV *ref = &mi->bmi[block].ref_mv[1].as_mv; - const MV diff = { mvs[1].as_mv.row - ref->row, - mvs[1].as_mv.col - ref->col }; - int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); - int nmv_ctx = - av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], - mbmi_ext->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx); - nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#if CONFIG_AMVR - av1_inc_mv(&diff, counts, precision); -#else - av1_inc_mv(&diff, counts, 1); -#endif - } else if (mode == NEW_NEARESTMV || mode == NEW_NEARMV) { - const MV *ref = &mi->bmi[block].ref_mv[0].as_mv; - const MV diff = { mvs[0].as_mv.row - ref->row, - mvs[0].as_mv.col - ref->col }; - int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); - int nmv_ctx = - av1_nmv_ctx(mbmi_ext->ref_mv_count[rf_type], - mbmi_ext->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); - nmv_context_counts *counts = &nmv_counts[nmv_ctx]; -#if CONFIG_AMVR - av1_inc_mv(&diff, counts, precision); -#else - av1_inc_mv(&diff, counts, 1); -#endif +int_mv av1_get_ref_mv(const MACROBLOCK *x, int ref_idx) { + const MACROBLOCKD *xd = &x->e_mbd; + const MB_MODE_INFO *mbmi = xd->mi[0]; + int ref_mv_idx = mbmi->ref_mv_idx; + if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV) { + assert(has_second_ref(mbmi)); + ref_mv_idx += 1; } + return av1_get_ref_mv_from_stack(ref_idx, mbmi->ref_frame, ref_mv_idx, + x->mbmi_ext); } -void av1_update_mv_count(ThreadData *td) { - const MACROBLOCKD *xd = &td->mb.e_mbd; - const MODE_INFO *mi = xd->mi[0]; - const MB_MODE_INFO *const mbmi = &mi->mbmi; - const MB_MODE_INFO_EXT *mbmi_ext = td->mb.mbmi_ext; -#if CONFIG_CB4X4 - const int unify_bsize = 1; -#else - const int unify_bsize = 0; -#endif -#if CONFIG_AMVR - MvSubpelPrecision precision = 1; - if (xd->cur_frame_mv_precision_level) { - precision = MV_SUBPEL_NONE; - } -#endif - - if (mbmi->sb_type < BLOCK_8X8 && !unify_bsize) { - const int num_4x4_w = num_4x4_blocks_wide_lookup[mbmi->sb_type]; - const int num_4x4_h = num_4x4_blocks_high_lookup[mbmi->sb_type]; - int idx, idy; - - for (idy = 0; idy < 2; idy += num_4x4_h) { - for (idx = 0; idx < 2; idx += num_4x4_w) { - const int i = idy * 2 + idx; - - if (have_newmv_in_inter_mode(mi->bmi[i].as_mode)) - -#if CONFIG_AMVR - inc_mvs_sub8x8(mi, i, mi->bmi[i].as_mv, mbmi_ext, td->counts->mv, - precision); -#else - inc_mvs_sub8x8(mi, i, mi->bmi[i].as_mv, mbmi_ext, td->counts->mv); -#endif - } - } - } else { - if (have_newmv_in_inter_mode(mbmi->mode)) - -#if CONFIG_AMVR - inc_mvs(mbmi, mbmi_ext, mbmi->mv, mbmi->pred_mv, td->counts->mv, - precision); -#else - inc_mvs(mbmi, mbmi_ext, mbmi->mv, mbmi->pred_mv, td->counts->mv); -#endif - } +void av1_find_best_ref_mvs_from_stack(int allow_hp, + const MB_MODE_INFO_EXT *mbmi_ext, + MV_REFERENCE_FRAME ref_frame, + int_mv *nearest_mv, int_mv *near_mv, + int is_integer) { + const int ref_idx = 0; + MV_REFERENCE_FRAME ref_frames[2] = { ref_frame, NONE_FRAME }; + *nearest_mv = av1_get_ref_mv_from_stack(ref_idx, ref_frames, 0, mbmi_ext); + lower_mv_precision(&nearest_mv->as_mv, allow_hp, is_integer); + *near_mv = av1_get_ref_mv_from_stack(ref_idx, ref_frames, 1, mbmi_ext); + lower_mv_precision(&near_mv->as_mv, allow_hp, is_integer); } -- cgit v1.2.3 From d2499ead93dc4298c0882fe98902acb1b5209f99 Mon Sep 17 00:00:00 2001 From: trav90 Date: Fri, 19 Oct 2018 23:05:00 -0500 Subject: Update libaom to commit ID 1e227d41f0616de9548a673a83a21ef990b62591 --- third_party/aom/av1/encoder/encodemv.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'third_party/aom/av1/encoder/encodemv.c') diff --git a/third_party/aom/av1/encoder/encodemv.c b/third_party/aom/av1/encoder/encodemv.c index 944e2c53d..42eb5abf6 100644 --- a/third_party/aom/av1/encoder/encodemv.c +++ b/third_party/aom/av1/encoder/encodemv.c @@ -18,19 +18,37 @@ #include "av1/encoder/encodemv.h" #include "aom_dsp/aom_dsp_common.h" +#include "aom_ports/bitops.h" + +static INLINE int mv_class_base(MV_CLASS_TYPE c) { + return c ? CLASS0_SIZE << (c + 2) : 0; +} + +// If n != 0, returns the floor of log base 2 of n. If n == 0, returns 0. +static INLINE uint8_t log_in_base_2(unsigned int n) { + // get_msb() is only valid when n != 0. + return n == 0 ? 0 : get_msb(n); +} + +static INLINE MV_CLASS_TYPE get_mv_class(int z, int *offset) { + const MV_CLASS_TYPE c = (z >= CLASS0_SIZE * 4096) + ? MV_CLASS_10 + : (MV_CLASS_TYPE)log_in_base_2(z >> 3); + if (offset) *offset = z - mv_class_base(c); + return c; +} static void encode_mv_component(aom_writer *w, int comp, nmv_component *mvcomp, MvSubpelPrecision precision) { + assert(comp != 0); int offset; const int sign = comp < 0; const int mag = sign ? -comp : comp; - const int mv_class = av1_get_mv_class(mag - 1, &offset); + const int mv_class = get_mv_class(mag - 1, &offset); const int d = offset >> 3; // int mv data const int fr = (offset >> 1) & 3; // fractional mv data const int hp = offset & 1; // high precision mv data - assert(comp != 0); - // Sign aom_write_symbol(w, sign, mvcomp->sign_cdf, 2); @@ -89,7 +107,7 @@ static void build_nmv_component_cost_table(int *mvcost, for (v = 1; v <= MV_MAX; ++v) { int z, c, o, d, e, f, cost = 0; z = v - 1; - c = av1_get_mv_class(z, &o); + c = get_mv_class(z, &o); cost += class_cost[c]; d = (o >> 3); /* int mv data */ f = (o >> 1) & 3; /* fractional pel mv data */ -- cgit v1.2.3