Commit c23ad632 authored by Imdad Sardharwalla's avatar Imdad Sardharwalla Committed by Peter de Rivaz

Fix inconsistent use of ref_mv_idx.

"+ 1" has been added in a few locations to match the indices for the
context for the CDFs and the motion vectors.

Suggested fix (of removing +1s entirely) can then be implemented
without further affecting the overall behaviour of the encoder and
decoder.

BUG=aomedia:858

Change-Id: I650a618d3fda1d27bd3550d25ad1ac52e4365061
parent b260f44f
......@@ -280,7 +280,8 @@ static INLINE uint8_t av1_get_pred_diff_ctx(const int_mv pred_mv,
static INLINE int av1_nmv_ctx(const uint8_t ref_mv_count,
const CANDIDATE_MV *ref_mv_stack, int ref,
int ref_mv_idx) {
if (ref_mv_stack[ref_mv_idx].weight >= REF_CAT_LEVEL && ref_mv_count > 0)
if (ref_mv_stack[ref_mv_idx].weight >= REF_CAT_LEVEL &&
ref_mv_idx < ref_mv_count)
return ref_mv_stack[ref_mv_idx].pred_diff[ref];
return 0;
......
......@@ -1711,8 +1711,9 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
}
case NEAR_NEWMV: {
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);
int nmv_ctx =
av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], 1,
mbmi->ref_mv_idx + 1);
nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
mv[0].as_int = near_mv[0].as_int;
read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, allow_hp);
......@@ -1723,8 +1724,9 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd,
}
case NEW_NEARMV: {
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);
int nmv_ctx =
av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], 0,
mbmi->ref_mv_idx + 1);
nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx];
read_mv(r, &mv[0].as_mv, &ref_mv[0].as_mv, nmvc, allow_hp);
assert(is_compound);
......
......@@ -1453,18 +1453,18 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const int mi_row,
}
} else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) {
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);
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 + (mode == NEAR_NEWMV ? 1 : 0));
nmv_context *nmvc = &ec_ctx->nmvc[nmv_ctx];
av1_encode_mv(cpi, w, &mbmi->mv[1].as_mv,
&mbmi_ext->ref_mvs[mbmi->ref_frame[1]][0].as_mv, nmvc,
allow_hp);
} else if (mode == NEW_NEARESTMV || mode == NEW_NEARMV) {
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);
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 + (mode == NEW_NEARMV ? 1 : 0));
nmv_context *nmvc = &ec_ctx->nmvc[nmv_ctx];
av1_encode_mv(cpi, w, &mbmi->mv[0].as_mv,
&mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0].as_mv, nmvc,
......
......@@ -5980,7 +5980,9 @@ static void joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
best_mv->col >>= 3;
best_mv->row >>= 3;
av1_set_mvcost(x, refs[id], id, mbmi->ref_mv_idx);
av1_set_mvcost(
x, refs[id], id,
mbmi->ref_mv_idx + (have_nearmv_in_inter_mode(mbmi->mode) ? 1 : 0));
// Small-range full-pixel motion search.
bestsme = av1_refining_search_8p_c(x, sadpb, search_range,
......@@ -6039,7 +6041,9 @@ static void joint_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
xd->plane[i].pre[ref] = backup_yv12[ref][i];
}
av1_set_mvcost(x, refs[ref], ref, mbmi->ref_mv_idx);
av1_set_mvcost(
x, refs[ref], ref,
mbmi->ref_mv_idx + (have_nearmv_in_inter_mode(mbmi->mode) ? 1 : 0));
*rate_mv += av1_mv_bit_cost(&frame_mv[refs[ref]].as_mv,
&x->mbmi_ext->ref_mvs[refs[ref]][0].as_mv,
......@@ -6351,7 +6355,9 @@ static void single_motion_search(const AV1_COMP *const cpi, MACROBLOCK *x,
av1_set_mv_search_range(&x->mv_limits, &ref_mv);
av1_set_mvcost(x, ref, ref_idx, mbmi->ref_mv_idx);
av1_set_mvcost(
x, ref, ref_idx,
mbmi->ref_mv_idx + (have_nearmv_in_inter_mode(mbmi->mode) ? 1 : 0));
// Work out the size of the first step in the mv step search.
// 0 here is maximum length first step. 1 is AOMMAX >> 1 etc.
......@@ -6680,7 +6686,9 @@ static void compound_single_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
best_mv->col >>= 3;
best_mv->row >>= 3;
av1_set_mvcost(x, ref, ref_idx, mbmi->ref_mv_idx);
av1_set_mvcost(
x, ref, ref_idx,
mbmi->ref_mv_idx + (have_nearmv_in_inter_mode(mbmi->mode) ? 1 : 0));
// Small-range full-pixel motion search.
bestsme = av1_refining_search_8p_c(x, sadpb, search_range,
......@@ -6732,7 +6740,9 @@ static void compound_single_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
xd->plane[i].pre[ref_idx] = backup_yv12[i];
}
av1_set_mvcost(x, ref, ref_idx, mbmi->ref_mv_idx);
av1_set_mvcost(
x, ref, ref_idx,
mbmi->ref_mv_idx + (have_nearmv_in_inter_mode(mbmi->mode) ? 1 : 0));
*rate_mv += av1_mv_bit_cost(this_mv, &ref_mv.as_mv, x->nmvjointcost,
x->mvcost, MV_COST_WEIGHT);
}
......@@ -7399,7 +7409,8 @@ static int64_t handle_newmv(const AV1_COMP *const cpi, MACROBLOCK *const x,
compound_single_motion_search_interinter(
cpi, x, bsize, frame_mv, mi_row, mi_col, NULL, 0, rate_mv, 0, 1);
} else {
av1_set_mvcost(x, refs[1], 1, mbmi->ref_mv_idx);
av1_set_mvcost(x, refs[1], 1,
mbmi->ref_mv_idx + (this_mode == NEAR_NEWMV ? 1 : 0));
*rate_mv = av1_mv_bit_cost(&frame_mv[refs[1]].as_mv,
&mbmi_ext->ref_mvs[refs[1]][0].as_mv,
x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
......@@ -7413,7 +7424,8 @@ static int64_t handle_newmv(const AV1_COMP *const cpi, MACROBLOCK *const x,
compound_single_motion_search_interinter(
cpi, x, bsize, frame_mv, mi_row, mi_col, NULL, 0, rate_mv, 0, 0);
} else {
av1_set_mvcost(x, refs[0], 0, mbmi->ref_mv_idx);
av1_set_mvcost(x, refs[0], 0,
mbmi->ref_mv_idx + (this_mode == NEW_NEARMV ? 1 : 0));
*rate_mv = av1_mv_bit_cost(&frame_mv[refs[0]].as_mv,
&mbmi_ext->ref_mvs[refs[0]][0].as_mv,
x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
......
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