Commit 3dfba994 authored by David Barker's avatar David Barker Committed by Debargha Mukherjee

Harmonize ext-inter and ref-mv

This changes the behavior of the ext-inter compound modes
as follows:
* NEAREST_NEARESTMV, NEAR_NEARMV, NEW_NEWMV, ZERO_ZEROMV
  work the same as the corresponding compound modes without
  ext-inter
* NEAREST_NEWMV and NEW_NEARESTMV keep their current behavior,
  which is to use the first ref-mv candidate pair for their
  particular reference frames
* NEAR_NEWMV and NEW_NEARMV select between the second, third,
  and fourth candidate pairs.
* NEAREST_NEARMV and NEAR_NEARESTMV use the first candidate
  pair for the NEAREST component and the second, third, or
  fourth candidate pair for the NEAR component.

Also do some minor refactoring and fix compile errors
with --enable-ext-inter --disable-ref-mv

Change-Id: If0d2a60559083b7c1189909d426b705af42d2d0e
parent d13c24a5
......@@ -192,6 +192,11 @@ static INLINE PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) {
return lut[mode];
}
static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) {
return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAREST_NEARMV ||
mode == NEAR_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV);
}
static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) {
return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAREST_NEWMV ||
mode == NEW_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV);
......@@ -210,6 +215,10 @@ static INLINE int is_masked_compound_type(COMPOUND_TYPE type) {
}
#else
static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) {
return (mode == NEARMV);
}
static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) {
return (mode == NEWMV);
}
......
......@@ -253,11 +253,7 @@ static void read_drl_idx(const AV1_COMMON *cm, MACROBLOCKD *xd,
}
}
#if CONFIG_EXT_INTER
if (mbmi->mode == NEARMV || mbmi->mode == NEAR_NEARMV) {
#else
if (mbmi->mode == NEARMV) {
#endif
if (have_nearmv_in_inter_mode(mbmi->mode)) {
int idx;
// Offset the NEARESTMV mode.
// TODO(jingning): Unify the two syntax decoding loops after the NEARESTMV
......@@ -1773,8 +1769,8 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
mbmi->mode = read_inter_mode(ec_ctx, xd, r, mode_ctx);
#if CONFIG_REF_MV
#if CONFIG_EXT_INTER
if (mbmi->mode == NEARMV || mbmi->mode == NEAR_NEARMV ||
mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV)
if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV ||
have_nearmv_in_inter_mode(mbmi->mode))
#else
if (mbmi->mode == NEARMV || mbmi->mode == NEWMV)
#endif
......@@ -1837,14 +1833,12 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
#if CONFIG_EXT_INTER
if (xd->ref_mv_count[ref_frame_type] > 1) {
int ref_mv_idx = 1 + mbmi->ref_mv_idx;
if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEAR_NEARESTMV ||
mbmi->mode == NEAR_NEARMV) {
if (compound_ref0_mode(mbmi->mode) == NEARMV) {
nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
lower_mv_precision(&nearmv[0].as_mv, allow_hp);
}
if (mbmi->mode == NEW_NEARMV || mbmi->mode == NEAREST_NEARMV ||
mbmi->mode == NEAR_NEARMV) {
if (compound_ref1_mode(mbmi->mode) == NEARMV) {
nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
lower_mv_precision(&nearmv[1].as_mv, allow_hp);
}
......@@ -1976,25 +1970,60 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
ref_mv[1] = nearestmv[1];
#if CONFIG_EXT_INTER
if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV) {
#else
if (mbmi->mode == NEWMV) {
if (is_compound) {
#if CONFIG_REF_MV
int ref_mv_idx = mbmi->ref_mv_idx;
// Special case: NEAR_NEWMV and NEW_NEARMV modes use
// 1 + mbmi->ref_mv_idx (like NEARMV) instead of
// mbmi->ref_mv_idx (like NEWMV)
if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV)
ref_mv_idx = 1 + mbmi->ref_mv_idx;
#endif
for (ref = 0; ref < 1 + is_compound; ++ref) {
if (compound_ref0_mode(mbmi->mode) == NEWMV) {
#if CONFIG_REF_MV
uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
if (xd->ref_mv_count[ref_frame_type] > 1) {
ref_mv[ref] =
(ref == 0)
? xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx].this_mv
: xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx].comp_mv;
ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
clamp_mv_ref(&ref_mv[ref].as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
}
#endif
nearestmv[ref] = ref_mv[ref];
nearestmv[0] = ref_mv[0];
}
if (compound_ref1_mode(mbmi->mode) == NEWMV) {
#if CONFIG_REF_MV
uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
if (xd->ref_mv_count[ref_frame_type] > 1) {
ref_mv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
clamp_mv_ref(&ref_mv[ref].as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
}
#endif
nearestmv[1] = ref_mv[1];
}
} else {
#endif // CONFIG_EXT_INTER
if (mbmi->mode == NEWMV) {
for (ref = 0; ref < 1 + is_compound; ++ref) {
#if CONFIG_REF_MV
uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame);
if (xd->ref_mv_count[ref_frame_type] > 1) {
ref_mv[ref] =
(ref == 0)
? xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx].this_mv
: xd->ref_mv_stack[ref_frame_type][mbmi->ref_mv_idx]
.comp_mv;
clamp_mv_ref(&ref_mv[ref].as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
}
#endif
nearestmv[ref] = ref_mv[ref];
}
}
#if CONFIG_EXT_INTER
}
#endif // CONFIG_EXT_INTER
int mv_corrupted_flag =
!assign_mv(cm, xd, mbmi->mode, mbmi->ref_frame, 0, mbmi->mv, ref_mv,
......
......@@ -318,11 +318,7 @@ static void write_drl_idx(const AV1_COMMON *cm, const MB_MODE_INFO *mbmi,
return;
}
#if CONFIG_EXT_INTER
if (mbmi->mode == NEARMV || mbmi->mode == NEAR_NEARMV) {
#else
if (mbmi->mode == NEARMV) {
#endif
if (have_nearmv_in_inter_mode(mbmi->mode)) {
int idx;
// TODO(jingning): Temporary solution to compensate the NEARESTMV offset.
for (idx = 1; idx < 3; ++idx) {
......@@ -1825,8 +1821,8 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const int mi_row,
#if CONFIG_REF_MV
#if CONFIG_EXT_INTER
if (mode == NEARMV || mode == NEAR_NEARMV || mode == NEWMV ||
mode == NEW_NEWMV)
if (mode == NEWMV || mode == NEW_NEWMV ||
have_nearmv_in_inter_mode(mode))
#else
if (mode == NEARMV || mode == NEWMV)
#endif
......
......@@ -1100,25 +1100,52 @@ static void update_state(const AV1_COMP *const cpi, ThreadData *td,
#if CONFIG_REF_MV
rf_type = av1_ref_frame_type(mbmi->ref_frame);
if (x->mbmi_ext->ref_mv_count[rf_type] > 1 &&
(mbmi->sb_type >= BLOCK_8X8 || unify_bsize) &&
(mbmi->sb_type >= BLOCK_8X8 || unify_bsize)) {
#if CONFIG_EXT_INTER
if (has_second_ref(mbmi)) {
int ref_mv_idx = mbmi->ref_mv_idx;
// Special case: NEAR_NEWMV and NEW_NEARMV modes use 1 + mbmi->ref_mv_idx
// (like NEARMV) instead
if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV)
ref_mv_idx = 1 + mbmi->ref_mv_idx;
if (compound_ref0_mode(mbmi->mode) == NEWMV) {
int_mv this_mv = x->mbmi_ext->ref_mv_stack[rf_type][ref_mv_idx].this_mv;
clamp_mv_ref(&this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
x->mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0] = this_mv;
mbmi->pred_mv[0] = this_mv;
mi->mbmi.pred_mv[0] = this_mv;
}
if (compound_ref1_mode(mbmi->mode) == NEWMV) {
int_mv this_mv = x->mbmi_ext->ref_mv_stack[rf_type][ref_mv_idx].comp_mv;
clamp_mv_ref(&this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
x->mbmi_ext->ref_mvs[mbmi->ref_frame[1]][0] = this_mv;
mbmi->pred_mv[1] = this_mv;
mi->mbmi.pred_mv[1] = this_mv;
}
} else {
#endif // CONFIG_EXT_INTER
if (mbmi->mode == NEWMV) {
for (i = 0; i < 1 + has_second_ref(mbmi); ++i) {
int_mv this_mv =
(i == 0)
? x->mbmi_ext->ref_mv_stack[rf_type][mbmi->ref_mv_idx].this_mv
: x->mbmi_ext->ref_mv_stack[rf_type][mbmi->ref_mv_idx]
.comp_mv;
clamp_mv_ref(&this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
x->mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0] = this_mv;
mbmi->pred_mv[i] = this_mv;
mi->mbmi.pred_mv[i] = this_mv;
}
}
#if CONFIG_EXT_INTER
(mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV)) {
#else
mbmi->mode == NEWMV) {
#endif
for (i = 0; i < 1 + has_second_ref(mbmi); ++i) {
int_mv this_mv =
(i == 0)
? x->mbmi_ext->ref_mv_stack[rf_type][mbmi->ref_mv_idx].this_mv
: x->mbmi_ext->ref_mv_stack[rf_type][mbmi->ref_mv_idx].comp_mv;
clamp_mv_ref(&this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
x->mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0] = this_mv;
mbmi->pred_mv[i] = this_mv;
mi->mbmi.pred_mv[i] = this_mv;
}
}
#endif
}
#endif // CONFIG_REF_MV
// If segmentation in use
if (seg->enabled) {
......@@ -1289,6 +1316,7 @@ static void update_state_supertx(const AV1_COMP *const cpi, ThreadData *td,
const int mi_height = mi_size_high[bsize];
const int x_mis = AOMMIN(mi_width, cm->mi_cols - mi_col);
const int y_mis = AOMMIN(mi_height, cm->mi_rows - mi_row);
const int unify_bsize = CONFIG_CB4X4;
MV_REF *const frame_mvs = cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
int w, h;
......@@ -1308,27 +1336,52 @@ static void update_state_supertx(const AV1_COMP *const cpi, ThreadData *td,
#if CONFIG_REF_MV
rf_type = av1_ref_frame_type(mbmi->ref_frame);
if (x->mbmi_ext->ref_mv_count[rf_type] > 1 &&
#if !CONFIG_CB4X4
mbmi->sb_type >= BLOCK_8X8 &&
#endif // !CONFIG_CB4X4
(mbmi->sb_type >= BLOCK_8X8 || unify_bsize)) {
#if CONFIG_EXT_INTER
if (has_second_ref(mbmi)) {
int ref_mv_idx = mbmi->ref_mv_idx;
// Special case: NEAR_NEWMV and NEW_NEARMV modes use 1 + mbmi->ref_mv_idx
// (like NEARMV) instead
if (mbmi->mode == NEAR_NEWMV || mbmi->mode == NEW_NEARMV)
ref_mv_idx = 1 + mbmi->ref_mv_idx;
if (compound_ref0_mode(mbmi->mode) == NEWMV) {
int_mv this_mv = x->mbmi_ext->ref_mv_stack[rf_type][ref_mv_idx].this_mv;
clamp_mv_ref(&this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
x->mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0] = this_mv;
mbmi->pred_mv[0] = this_mv;
mi->mbmi.pred_mv[0] = this_mv;
}
if (compound_ref1_mode(mbmi->mode) == NEWMV) {
int_mv this_mv = x->mbmi_ext->ref_mv_stack[rf_type][ref_mv_idx].comp_mv;
clamp_mv_ref(&this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
x->mbmi_ext->ref_mvs[mbmi->ref_frame[1]][0] = this_mv;
mbmi->pred_mv[1] = this_mv;
mi->mbmi.pred_mv[1] = this_mv;
}
} else {
#endif // CONFIG_EXT_INTER
if (mbmi->mode == NEWMV) {
for (i = 0; i < 1 + has_second_ref(mbmi); ++i) {
int_mv this_mv =
(i == 0)
? x->mbmi_ext->ref_mv_stack[rf_type][mbmi->ref_mv_idx].this_mv
: x->mbmi_ext->ref_mv_stack[rf_type][mbmi->ref_mv_idx]
.comp_mv;
clamp_mv_ref(&this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
x->mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0] = this_mv;
mbmi->pred_mv[i] = this_mv;
mi->mbmi.pred_mv[i] = this_mv;
}
}
#if CONFIG_EXT_INTER
(mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV)) {
#else
mbmi->mode == NEWMV) {
#endif
for (i = 0; i < 1 + has_second_ref(mbmi); ++i) {
int_mv this_mv =
(i == 0)
? x->mbmi_ext->ref_mv_stack[rf_type][mbmi->ref_mv_idx].this_mv
: x->mbmi_ext->ref_mv_stack[rf_type][mbmi->ref_mv_idx].comp_mv;
clamp_mv_ref(&this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
xd->n8_h << MI_SIZE_LOG2, xd);
lower_mv_precision(&this_mv.as_mv, cm->allow_high_precision_mv);
x->mbmi_ext->ref_mvs[mbmi->ref_frame[i]][0] = this_mv;
mbmi->pred_mv[i] = this_mv;
}
}
#endif
}
#endif // CONFIG_REF_MV
// If segmentation in use
if (seg->enabled) {
......@@ -2236,7 +2289,7 @@ static void update_stats(const AV1_COMMON *const cm, ThreadData *td, int mi_row,
}
#if CONFIG_EXT_INTER
if (mbmi->mode == NEARMV || mbmi->mode == NEAR_NEARMV) {
if (have_nearmv_in_inter_mode(mbmi->mode)) {
#else
if (mbmi->mode == NEARMV) {
#endif
......
This diff is collapsed.
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