Commit 21b67229 authored by Hui Su's avatar Hui Su

Remove prob table entries and counters for new mv

Change-Id: Ifa2cdc2d2230dfa11396ee3e547653180f96b795
parent 9eabd691
......@@ -409,13 +409,9 @@ typedef struct FRAME_COUNTS {
unsigned int skip_mode[SKIP_MODE_CONTEXTS][2];
#endif // CONFIG_EXT_SKIP
unsigned int skip[SKIP_CONTEXTS][2];
nmv_context_counts mv[NMV_CONTEXTS];
#if CONFIG_JNT_COMP
unsigned int compound_index[COMP_INDEX_CONTEXTS][2];
#endif // CONFIG_JNT_COMP
#if CONFIG_INTRABC
nmv_context_counts dv;
#endif
unsigned int delta_q[DELTA_Q_PROBS][2];
#if CONFIG_EXT_DELTA_Q
#if CONFIG_LOOPFILTER_LEVEL
......
......@@ -42,27 +42,18 @@ const aom_tree_index av1_mv_fp_tree[TREE_SIZE(MV_FP_SIZE)] = { -0, 2, -1,
4, -2, -3 };
static const nmv_context default_nmv_context = {
{ 32, 64, 96 }, // joints
{ AOM_CDF4(4096, 11264, 19328) }, // joints_cdf
{ {
// Vertical component
128, // sign
{ 224, 144, 192, 168, 192, 176, 192, 198, 198, 245 }, // class
{ AOM_CDF11(28672, 30976, 31858, 32320, 32551, 32656, 32740, 32757,
32762, 32767) }, // class_cdf
{ 216 }, // class0
{ 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits
{ { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp
{ 64, 96, 64 }, // fp
32762, 32767) }, // class_cdf // fp
{ { AOM_CDF4(16384, 24576, 26624) },
{ AOM_CDF4(12288, 21248, 24128) } }, // class0_fp_cdf
{ AOM_CDF4(8192, 17408, 21248) }, // fp_cdf
160, // class0_hp bit
128, // hp
{ AOM_CDF2(128 * 128) },
{ AOM_CDF2(160 * 128) },
{ AOM_CDF2(128 * 128) },
{ AOM_CDF2(216 * 128) },
{ AOM_CDF2(128 * 128) }, // sign_cdf
{ AOM_CDF2(160 * 128) }, // class0_hp_cdf
{ AOM_CDF2(128 * 128) }, // hp_cdf
{ AOM_CDF2(216 * 128) }, // class0_cdf
{ { AOM_CDF2(128 * 136) },
{ AOM_CDF2(128 * 140) },
{ AOM_CDF2(128 * 148) },
......@@ -76,23 +67,15 @@ static const nmv_context default_nmv_context = {
},
{
// Horizontal component
128, // sign
{ 216, 128, 176, 160, 176, 176, 192, 198, 198, 208 }, // class
{ AOM_CDF11(28672, 30976, 31858, 32320, 32551, 32656, 32740, 32757,
32762, 32767) }, // class_cdf
{ 208 }, // class0
{ 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits
{ { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp
{ 64, 96, 64 }, // fp
32762, 32767) }, // class_cdf // fp
{ { AOM_CDF4(16384, 24576, 26624) },
{ AOM_CDF4(12288, 21248, 24128) } }, // class0_fp_cdf
{ AOM_CDF4(8192, 17408, 21248) }, // fp_cdf
160, // class0_hp bit
128, // hp
{ AOM_CDF2(128 * 128) },
{ AOM_CDF2(160 * 128) },
{ AOM_CDF2(128 * 128) },
{ AOM_CDF2(216 * 128) },
{ AOM_CDF2(128 * 128) }, // sign_cdf
{ AOM_CDF2(160 * 128) }, // class0_hp_cdf
{ AOM_CDF2(128 * 128) }, // hp_cdf
{ AOM_CDF2(216 * 128) }, // class0_cdf
{ { AOM_CDF2(128 * 136) },
{ AOM_CDF2(128 * 140) },
{ AOM_CDF2(128 * 148) },
......@@ -161,97 +144,6 @@ MV_CLASS_TYPE av1_get_mv_class(int z, int *offset) {
return c;
}
static void inc_mv_component(int v, nmv_component_counts *comp_counts, int incr,
MvSubpelPrecision precision) {
int s, z, c, o, d, e, f;
assert(v != 0); /* should not be zero */
s = v < 0;
comp_counts->sign[s] += incr;
z = (s ? -v : v) - 1; /* magnitude - 1 */
c = av1_get_mv_class(z, &o);
comp_counts->classes[c] += incr;
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) {
comp_counts->class0[d] += incr;
#if CONFIG_INTRABC || CONFIG_AMVR
if (precision > MV_SUBPEL_NONE)
#endif
comp_counts->class0_fp[d][f] += incr;
if (precision > MV_SUBPEL_LOW_PRECISION) comp_counts->class0_hp[e] += incr;
} else {
int i;
int b = c + CLASS0_BITS - 1; // number of bits
for (i = 0; i < b; ++i) comp_counts->bits[i][((d >> i) & 1)] += incr;
#if CONFIG_INTRABC || CONFIG_AMVR
if (precision > MV_SUBPEL_NONE)
#endif
comp_counts->fp[f] += incr;
if (precision > MV_SUBPEL_LOW_PRECISION) comp_counts->hp[e] += incr;
}
}
void av1_inc_mv(const MV *mv, nmv_context_counts *counts,
MvSubpelPrecision precision) {
if (counts != NULL) {
const MV_JOINT_TYPE j = av1_get_mv_joint(mv);
++counts->joints[j];
if (mv_joint_vertical(j))
inc_mv_component(mv->row, &counts->comps[0], 1, precision);
if (mv_joint_horizontal(j))
inc_mv_component(mv->col, &counts->comps[1], 1, precision);
}
}
void av1_adapt_mv_probs(AV1_COMMON *cm, int allow_hp) {
int i, j;
int idx;
for (idx = 0; idx < NMV_CONTEXTS; ++idx) {
nmv_context *nmvc = &cm->fc->nmvc[idx];
const nmv_context *pre_nmvc = &cm->pre_fc->nmvc[idx];
const nmv_context_counts *counts = &cm->counts.mv[idx];
aom_tree_merge_probs(av1_mv_joint_tree, pre_nmvc->joints, counts->joints,
nmvc->joints);
for (i = 0; i < 2; ++i) {
nmv_component *comp = &nmvc->comps[i];
const nmv_component *pre_comp = &pre_nmvc->comps[i];
const nmv_component_counts *c = &counts->comps[i];
comp->sign = av1_mode_mv_merge_probs(pre_comp->sign, c->sign);
aom_tree_merge_probs(av1_mv_class_tree, pre_comp->classes, c->classes,
comp->classes);
aom_tree_merge_probs(av1_mv_class0_tree, pre_comp->class0, c->class0,
comp->class0);
for (j = 0; j < MV_OFFSET_BITS; ++j)
comp->bits[j] = av1_mode_mv_merge_probs(pre_comp->bits[j], c->bits[j]);
#if CONFIG_AMVR
if (cm->cur_frame_force_integer_mv == 0) {
#endif
for (j = 0; j < CLASS0_SIZE; ++j)
aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->class0_fp[j],
c->class0_fp[j], comp->class0_fp[j]);
aom_tree_merge_probs(av1_mv_fp_tree, pre_comp->fp, c->fp, comp->fp);
if (allow_hp) {
comp->class0_hp =
av1_mode_mv_merge_probs(pre_comp->class0_hp, c->class0_hp);
comp->hp = av1_mode_mv_merge_probs(pre_comp->hp, c->hp);
}
#if CONFIG_AMVR
}
#endif
}
}
}
void av1_init_mv_probs(AV1_COMMON *cm) {
int i;
for (i = 0; i < NMV_CONTEXTS; ++i) {
......
......@@ -26,8 +26,6 @@ struct AV1Common;
void av1_init_mv_probs(struct AV1Common *cm);
void av1_adapt_mv_probs(struct AV1Common *cm, int usehp);
#define MV_UPDATE_PROB 252
/* Symbols for coding which components are zero jointly */
......@@ -83,17 +81,9 @@ extern const aom_tree_index av1_mv_class0_tree[];
extern const aom_tree_index av1_mv_fp_tree[];
typedef struct {
aom_prob sign;
aom_prob classes[MV_CLASSES - 1];
aom_cdf_prob classes_cdf[CDF_SIZE(MV_CLASSES)];
aom_prob class0[CLASS0_SIZE - 1];
aom_prob bits[MV_OFFSET_BITS];
aom_prob class0_fp[CLASS0_SIZE][MV_FP_SIZE - 1];
aom_prob fp[MV_FP_SIZE - 1];
aom_cdf_prob class0_fp_cdf[CLASS0_SIZE][CDF_SIZE(MV_FP_SIZE)];
aom_cdf_prob fp_cdf[CDF_SIZE(MV_FP_SIZE)];
aom_prob class0_hp;
aom_prob hp;
aom_cdf_prob sign_cdf[CDF_SIZE(2)];
aom_cdf_prob class0_hp_cdf[CDF_SIZE(2)];
aom_cdf_prob hp_cdf[CDF_SIZE(2)];
......@@ -102,7 +92,6 @@ typedef struct {
} nmv_component;
typedef struct {
aom_prob joints[MV_JOINTS - 1];
aom_cdf_prob joints_cdf[CDF_SIZE(MV_JOINTS)];
nmv_component comps[2];
} nmv_context;
......@@ -117,22 +106,6 @@ static INLINE MV_JOINT_TYPE av1_get_mv_joint(const MV *mv) {
MV_CLASS_TYPE av1_get_mv_class(int z, int *offset);
typedef struct {
unsigned int sign[2];
unsigned int classes[MV_CLASSES];
unsigned int class0[CLASS0_SIZE];
unsigned int bits[MV_OFFSET_BITS][2];
unsigned int class0_fp[CLASS0_SIZE][MV_FP_SIZE];
unsigned int fp[MV_FP_SIZE];
unsigned int class0_hp[2];
unsigned int hp[2];
} nmv_component_counts;
typedef struct {
unsigned int joints[MV_JOINTS];
nmv_component_counts comps[2];
} nmv_context_counts;
typedef enum {
#if CONFIG_INTRABC || CONFIG_AMVR
MV_SUBPEL_NONE = -1,
......@@ -141,9 +114,6 @@ typedef enum {
MV_SUBPEL_HIGH_PRECISION,
} MvSubpelPrecision;
void av1_inc_mv(const MV *mv, nmv_context_counts *mvctx,
MvSubpelPrecision precision);
#ifdef __cplusplus
} // extern "C"
#endif
......
......@@ -3327,10 +3327,6 @@ static void debug_check_frame_counts(const AV1_COMMON *const cm) {
assert(!memcmp(cm->counts.comp_bwdref, zero_counts.comp_bwdref,
sizeof(cm->counts.comp_bwdref)));
assert(!memcmp(cm->counts.skip, zero_counts.skip, sizeof(cm->counts.skip)));
assert(
!memcmp(&cm->counts.mv[0], &zero_counts.mv[0], sizeof(cm->counts.mv[0])));
assert(
!memcmp(&cm->counts.mv[1], &zero_counts.mv[1], sizeof(cm->counts.mv[0])));
}
#endif // NDEBUG
......
......@@ -945,8 +945,7 @@ void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd,
#if CONFIG_INTRABC
static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
nmv_context *ctx, nmv_context_counts *counts,
MvSubpelPrecision precision);
nmv_context *ctx, MvSubpelPrecision precision);
static INLINE int is_mv_valid(const MV *mv);
......@@ -955,10 +954,7 @@ static INLINE int assign_dv(AV1_COMMON *cm, MACROBLOCKD *xd, int_mv *mv,
BLOCK_SIZE bsize, aom_reader *r) {
FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
(void)cm;
FRAME_COUNTS *counts = xd->counts;
nmv_context_counts *const dv_counts = counts ? &counts->dv : NULL;
read_mv(r, &mv->as_mv, &ref_mv->as_mv, &ec_ctx->ndvc, dv_counts,
MV_SUBPEL_NONE);
read_mv(r, &mv->as_mv, &ref_mv->as_mv, &ec_ctx->ndvc, MV_SUBPEL_NONE);
// DV should not have sub-pel.
assert((mv->as_mv.col & 7) == 0);
assert((mv->as_mv.row & 7) == 0);
......@@ -1222,8 +1218,7 @@ static int read_mv_component(aom_reader *r, nmv_component *mvcomp,
}
static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
nmv_context *ctx, nmv_context_counts *counts,
MvSubpelPrecision precision) {
nmv_context *ctx, MvSubpelPrecision precision) {
MV_JOINT_TYPE joint_type;
MV diff = { 0, 0 };
joint_type =
......@@ -1243,8 +1238,6 @@ static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref,
#endif // CONFIG_INTRABC || CONFIG_AMVR
precision > MV_SUBPEL_LOW_PRECISION);
av1_inc_mv(&diff, counts, precision);
mv->row = ref->row + diff.row;
mv->col = ref->col + diff.col;
}
......@@ -1634,16 +1627,13 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
#endif
switch (mode) {
case NEWMV: {
FRAME_COUNTS *counts = xd->counts;
for (i = 0; i < 1 + is_compound; ++i) {
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
int nmv_ctx =
av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
mbmi->ref_mv_idx);
nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
nmv_context_counts *const mv_counts =
counts ? &counts->mv[nmv_ctx] : NULL;
read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp);
read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, allow_hp);
ret = ret && is_mv_valid(&mv[i].as_mv);
pred_mv[i].as_int = ref_mv[i].as_int;
......@@ -1692,7 +1682,6 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
break;
}
case NEW_NEWMV: {
FRAME_COUNTS *counts = xd->counts;
assert(is_compound);
for (i = 0; i < 2; ++i) {
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
......@@ -1700,9 +1689,7 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], i,
mbmi->ref_mv_idx);
nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
nmv_context_counts *const mv_counts =
counts ? &counts->mv[nmv_ctx] : NULL;
read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, mv_counts, allow_hp);
read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, allow_hp);
ret = ret && is_mv_valid(&mv[i].as_mv);
}
break;
......@@ -1720,57 +1707,45 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
break;
}
case NEW_NEARESTMV: {
FRAME_COUNTS *counts = xd->counts;
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
nmv_context_counts *const mv_counts =
counts ? &counts->mv[nmv_ctx] : NULL;
read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, allow_hp);
assert(is_compound);
ret = ret && is_mv_valid(&mv[0].as_mv);
mv[1].as_int = nearest_mv[1].as_int;
break;
}
case NEAREST_NEWMV: {
FRAME_COUNTS *counts = xd->counts;
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx);
nmv_context_counts *const mv_counts =
counts ? &counts->mv[nmv_ctx] : NULL;
nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
mv[0].as_int = nearest_mv[0].as_int;
read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp);
read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, allow_hp);
assert(is_compound);
ret = ret && is_mv_valid(&mv[1].as_mv);
break;
}
case NEAR_NEWMV: {
FRAME_COUNTS *counts = xd->counts;
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
xd->ref_mv_stack[rf_type], 1, mbmi->ref_mv_idx);
nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
nmv_context_counts *const mv_counts =
counts ? &counts->mv[nmv_ctx] : NULL;
mv[0].as_int = near_mv[0].as_int;
read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, mv_counts, allow_hp);
read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, allow_hp);
assert(is_compound);
ret = ret && is_mv_valid(&mv[1].as_mv);
break;
}
case NEW_NEARMV: {
FRAME_COUNTS *counts = xd->counts;
int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame);
int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type],
xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx);
nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
nmv_context_counts *const mv_counts =
counts ? &counts->mv[nmv_ctx] : NULL;
read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp);
read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, allow_hp);
assert(is_compound);
ret = ret && is_mv_valid(&mv[0].as_mv);
mv[1].as_int = near_mv[1].as_int;
......
......@@ -602,7 +602,6 @@ static void update_state(const AV1_COMP *const cpi, TileDataEnc *tile_data,
#endif
if (!frame_is_intra_only(cm)) {
if (is_inter_block(mbmi)) {
av1_update_mv_count(td);
if (bsize >= BLOCK_8X8) {
// TODO(sarahparker): global motion stats need to be handled per-tile
// to be compatible with tile-based threading.
......
......@@ -187,82 +187,3 @@ void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2],
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
}
} 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
}
}
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_AMVR
MvSubpelPrecision precision = 1;
if (xd->cur_frame_force_integer_mv) {
precision = MV_SUBPEL_NONE;
}
#endif
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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment