Commit 9620bcd5 authored by David Barker's avatar David Barker Committed by Debargha Mukherjee

Re-enable av1_nmv_ctx() when ext-inter is enabled

Currently, mbmi->ref_mv_idx can be set to a nonzero value
on the encoder side if mbmi->mode is one of NEARMV, NEWMV,
NEAR_NEARMV, or NEW_NEWMV. But it can only be nonzero on the
decoder side if the mode is NEARMV or NEWMV. Hence av1_nmv_ctx
has previously been disabled when ext-inter is enabled, to
prevent a mismatch due to this.

This patch changes the encoder behaviour to match the decoder
behaviour.

Change-Id: Icfe41fb72e76731ae373fe8c6065f5e003f6414f
parent 008ea46a
......@@ -391,10 +391,6 @@ 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 CONFIG_EXT_INTER
return 0;
#endif
if (ref_mv_stack[ref_mv_idx].weight >= REF_CAT_LEVEL && ref_mv_count > 0)
return ref_mv_stack[ref_mv_idx].pred_diff[ref];
......
......@@ -1721,6 +1721,10 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const MODE_INFO *mi,
#if CONFIG_REF_MV
if (mode == NEARMV || mode == NEWMV)
write_drl_idx(cm, mbmi, mbmi_ext, w);
#if CONFIG_EXT_INTER
else
assert(mbmi->ref_mv_idx == 0);
#endif
#endif
}
}
......
......@@ -2203,39 +2203,39 @@ static void update_stats(const AV1_COMMON *const cm, ThreadData *td, int mi_row,
has_second_ref(mbmi),
#endif // CONFIG_EXT_INTER
mode_ctx);
#if CONFIG_EXT_INTER
}
#endif // CONFIG_EXT_INTER
if (mode == NEWMV) {
uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
int idx;
if (mode == NEWMV) {
uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
int idx;
for (idx = 0; idx < 2; ++idx) {
if (mbmi_ext->ref_mv_count[ref_frame_type] > idx + 1) {
uint8_t drl_ctx =
av1_drl_ctx(mbmi_ext->ref_mv_stack[ref_frame_type], idx);
++counts->drl_mode[drl_ctx][mbmi->ref_mv_idx != idx];
for (idx = 0; idx < 2; ++idx) {
if (mbmi_ext->ref_mv_count[ref_frame_type] > idx + 1) {
uint8_t drl_ctx =
av1_drl_ctx(mbmi_ext->ref_mv_stack[ref_frame_type], idx);
++counts->drl_mode[drl_ctx][mbmi->ref_mv_idx != idx];
if (mbmi->ref_mv_idx == idx) break;
}
if (mbmi->ref_mv_idx == idx) break;
}
}
}
if (mode == NEARMV) {
uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
int idx;
if (mode == NEARMV) {
uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
int idx;
for (idx = 1; idx < 3; ++idx) {
if (mbmi_ext->ref_mv_count[ref_frame_type] > idx + 1) {
uint8_t drl_ctx =
av1_drl_ctx(mbmi_ext->ref_mv_stack[ref_frame_type], idx);
++counts->drl_mode[drl_ctx][mbmi->ref_mv_idx != idx - 1];
for (idx = 1; idx < 3; ++idx) {
if (mbmi_ext->ref_mv_count[ref_frame_type] > idx + 1) {
uint8_t drl_ctx =
av1_drl_ctx(mbmi_ext->ref_mv_stack[ref_frame_type], idx);
++counts->drl_mode[drl_ctx][mbmi->ref_mv_idx != idx - 1];
if (mbmi->ref_mv_idx == idx - 1) break;
}
if (mbmi->ref_mv_idx == idx - 1) break;
}
}
#if CONFIG_EXT_INTER
}
#endif // CONFIG_EXT_INTER
#else
#if CONFIG_EXT_INTER
if (is_inter_compound_mode(mode))
......
......@@ -10489,18 +10489,11 @@ void av1_rd_pick_inter_mode_sb(const AV1_COMP *cpi, TileDataEnc *tile_data,
}
#if CONFIG_REF_MV
// TODO(jingning): This needs some refactoring to improve code quality
// and reduce redundant steps.
#if CONFIG_EXT_INTER
if (((mbmi->mode == NEARMV || mbmi->mode == NEAR_NEARMV) &&
mbmi_ext->ref_mv_count[ref_frame_type] > 2) ||
((mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV) &&
mbmi_ext->ref_mv_count[ref_frame_type] > 1)) {
#else
// TODO(jingning): This needs some refactoring to improve code quality
// and reduce redundant steps.
if ((mbmi->mode == NEARMV &&
mbmi_ext->ref_mv_count[ref_frame_type] > 2) ||
(mbmi->mode == NEWMV && mbmi_ext->ref_mv_count[ref_frame_type] > 1)) {
#endif // CONFIG_EXT_INTER
int_mv backup_mv = frame_mv[NEARMV][ref_frame];
MB_MODE_INFO backup_mbmi = *mbmi;
int backup_skip = x->skip;
......@@ -11322,6 +11315,13 @@ PALETTE_EXIT:
#endif // CONFIG_REF_MV
}
// Make sure that the ref_mv_idx is only nonzero when we're
// using a mode which can support ref_mv_idx
if (best_mbmode.ref_mv_idx != 0 &&
!(best_mbmode.mode == NEARMV || best_mbmode.mode == NEWMV)) {
best_mbmode.ref_mv_idx = 0;
}
#if CONFIG_REF_MV
{
int8_t ref_frame_type = av1_ref_frame_type(best_mbmode.ref_frame);
......
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