Merge opt-ref-mv experimental flag
The opt-ref-mv experiment has been adopted by the AOM working
group and cleared by TAPAS.
Change-Id: Ibb2f97f239eca82476fc078b3d56d6d67af99bce
diff --git a/av1/common/entropymode.c b/av1/common/entropymode.c
index ae8dab0..889a5dc 100644
--- a/av1/common/entropymode.c
+++ b/av1/common/entropymode.c
@@ -35,7 +35,6 @@
{ AOM_CDF2(128 * 134) },
};
-#if CONFIG_OPT_REF_MV
static const aom_cdf_prob
default_inter_compound_mode_cdf[INTER_MODE_CONTEXTS][CDF_SIZE(
INTER_COMPOUND_MODES)] = {
@@ -55,19 +54,6 @@
{ AOM_CDF8(11407, 16588, 19365, 21657, 22748, 23629, 28912) },
{ AOM_CDF8(10681, 18953, 20791, 22468, 23935, 25024, 28506) }
};
-#else
-static const aom_cdf_prob
- default_inter_compound_mode_cdf[INTER_MODE_CONTEXTS][CDF_SIZE(
- INTER_COMPOUND_MODES)] = {
- { AOM_CDF8(19712, 28229, 30892, 31437, 31712, 32135, 32360) },
- { AOM_CDF8(9600, 24804, 29268, 30323, 30802, 31726, 32177) },
- { AOM_CDF8(896, 22434, 27015, 29026, 29753, 31114, 31597) },
- { AOM_CDF8(1024, 15904, 22127, 25421, 26864, 28996, 30001) },
- { AOM_CDF8(512, 11222, 17217, 21445, 23473, 26133, 27550) },
- { AOM_CDF8(2944, 13313, 17214, 20751, 23211, 25500, 26992) },
- { AOM_CDF8(3456, 9067, 14069, 16907, 18817, 21214, 23139) }
- };
-#endif
static const aom_cdf_prob
default_compound_type_cdf[BLOCK_SIZES_ALL][CDF_SIZE(COMPOUND_TYPES - 1)] = {
diff --git a/av1/common/enums.h b/av1/common/enums.h
index 1019428..438088c 100644
--- a/av1/common/enums.h
+++ b/av1/common/enums.h
@@ -528,12 +528,8 @@
#define GLOBALMV_CTX_MASK ((1 << (REFMV_OFFSET - GLOBALMV_OFFSET)) - 1)
#define REFMV_CTX_MASK ((1 << (8 - REFMV_OFFSET)) - 1)
-#if CONFIG_OPT_REF_MV
#define COMP_NEWMV_CTXS 5
#define INTER_MODE_CONTEXTS 15
-#else
-#define INTER_MODE_CONTEXTS 7
-#endif
#define DELTA_Q_SMALL 3
#define DELTA_Q_PROBS (DELTA_Q_SMALL)
diff --git a/av1/common/mvref_common.c b/av1/common/mvref_common.c
index dffc7a5..9c90991 100644
--- a/av1/common/mvref_common.c
+++ b/av1/common/mvref_common.c
@@ -120,15 +120,9 @@
get_sub_block_pred_mv(candidate_mi, ref, col), this_refmv);
ref_mv_stack[index].weight = weight * len;
++(*refmv_count);
-
-#if !CONFIG_OPT_REF_MV
- if (candidate->mode == NEWMV) ++*newmv_count;
-#endif
}
-#if CONFIG_OPT_REF_MV
if (have_newmv_in_inter_mode(candidate->mode)) ++*newmv_count;
++*ref_match_count;
-#endif
}
}
} else {
@@ -169,15 +163,9 @@
get_sub_block_pred_mv(candidate_mi, 1, col), this_refmv[1]);
ref_mv_stack[index].weight = weight * len;
++(*refmv_count);
-
-#if !CONFIG_OPT_REF_MV
- if (candidate->mode == NEW_NEWMV) ++*newmv_count;
-#endif
}
-#if CONFIG_OPT_REF_MV
if (have_newmv_in_inter_mode(candidate->mode)) ++*newmv_count;
++*ref_match_count;
-#endif
}
}
}
@@ -447,17 +435,10 @@
lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv);
#endif
-#if CONFIG_OPT_REF_MV
if (blk_row == 0 && blk_col == 0)
if (abs(this_refmv.as_mv.row - gm_mv_candidates[0].as_mv.row) >= 16 ||
abs(this_refmv.as_mv.col - gm_mv_candidates[0].as_mv.col) >= 16)
mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET);
-#else
- if (blk_row == 0 && blk_col == 0)
- if (abs(this_refmv.as_mv.row) >= 16 ||
- abs(this_refmv.as_mv.col) >= 16)
- mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET);
-#endif
for (idx = 0; idx < refmv_count[rf[0]]; ++idx)
if (this_refmv.as_int == ref_mv_stack[idx].this_mv.as_int) break;
@@ -518,21 +499,12 @@
lower_mv_precision(&comp_refmv.as_mv, cm->allow_high_precision_mv);
#endif
-#if CONFIG_OPT_REF_MV
if (blk_row == 0 && blk_col == 0)
if (abs(this_refmv.as_mv.row - gm_mv_candidates[0].as_mv.row) >= 16 ||
abs(this_refmv.as_mv.col - gm_mv_candidates[0].as_mv.col) >= 16 ||
abs(comp_refmv.as_mv.row - gm_mv_candidates[1].as_mv.row) >= 16 ||
abs(comp_refmv.as_mv.col - gm_mv_candidates[1].as_mv.col) >= 16)
mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET);
-#else
- if (blk_row == 0 && blk_col == 0)
- if (abs(this_refmv.as_mv.row) >= 16 ||
- abs(this_refmv.as_mv.col) >= 16 ||
- abs(comp_refmv.as_mv.row) >= 16 ||
- abs(comp_refmv.as_mv.col) >= 16)
- mode_context[ref_frame] |= (1 << GLOBALMV_OFFSET);
-#endif
for (idx = 0; idx < refmv_count[ref_frame]; ++idx)
if (this_refmv.as_int == ref_mv_stack[idx].this_mv.as_int &&
@@ -605,20 +577,20 @@
// Find valid maximum row/col offset.
if (xd->up_available) {
max_row_offset = -(MVREF_ROWS << 1) + row_adj;
-#if CONFIG_OPT_REF_MV
+
if (xd->n8_h < mi_size_high[BLOCK_8X8])
max_row_offset = -(2 << 1) + row_adj;
-#endif
+
max_row_offset =
find_valid_row_offset(tile, mi_row, cm->mi_rows, cm, max_row_offset);
}
if (xd->left_available) {
max_col_offset = -(MVREF_COLS << 1) + col_adj;
-#if CONFIG_OPT_REF_MV
+
if (xd->n8_w < mi_size_wide[BLOCK_8X8])
max_col_offset = -(2 << 1) + col_adj;
-#endif
+
max_col_offset = find_valid_col_offset(tile, mi_col, max_col_offset);
}
@@ -762,41 +734,22 @@
ref_match_count[ref_frame] =
(row_match_count[ref_frame] > 0) + (col_match_count[ref_frame] > 0);
-#if CONFIG_OPT_REF_MV
- switch (nearest_match[ref_frame])
-#else
- switch (nearest_refmv_count[ref_frame])
-#endif
- {
- case 0: mode_context[ref_frame] |= 0;
-#if CONFIG_OPT_REF_MV
+ switch (nearest_match[ref_frame]) {
+ case 0:
+ mode_context[ref_frame] |= 0;
if (ref_match_count[ref_frame] >= 1) mode_context[ref_frame] |= 1;
if (ref_match_count[ref_frame] == 1)
mode_context[ref_frame] |= (1 << REFMV_OFFSET);
else if (ref_match_count[ref_frame] >= 2)
mode_context[ref_frame] |= (2 << REFMV_OFFSET);
-#else
- if (refmv_count[ref_frame] >= 1) mode_context[ref_frame] |= 1;
- if (refmv_count[ref_frame] == 1)
- mode_context[ref_frame] |= (1 << REFMV_OFFSET);
- else if (refmv_count[ref_frame] >= 2)
- mode_context[ref_frame] |= (2 << REFMV_OFFSET);
-#endif
break;
- case 1: mode_context[ref_frame] |= (newmv_count[ref_frame] > 0) ? 2 : 3;
-#if CONFIG_OPT_REF_MV
+ case 1:
+ mode_context[ref_frame] |= (newmv_count[ref_frame] > 0) ? 2 : 3;
if (ref_match_count[ref_frame] == 1)
mode_context[ref_frame] |= (3 << REFMV_OFFSET);
else if (ref_match_count[ref_frame] >= 2)
mode_context[ref_frame] |= (4 << REFMV_OFFSET);
-#else
- if (refmv_count[ref_frame] == 1)
- mode_context[ref_frame] |= (3 << REFMV_OFFSET);
- else if (refmv_count[ref_frame] >= 2)
- mode_context[ref_frame] |= (4 << REFMV_OFFSET);
-#endif
break;
-
case 2:
default:
if (newmv_count[ref_frame] >= 1)
@@ -840,7 +793,6 @@
}
if (rf[1] > NONE_FRAME) {
-#if CONFIG_OPT_REF_MV
// TODO(jingning, yunqing): Refactor and consolidate the compound and
// single reference frame modes. Reduce unnecessary redundancy.
if (refmv_count[ref_frame] < 2) {
@@ -953,7 +905,6 @@
}
assert(refmv_count[ref_frame] >= 2);
-#endif
for (int idx = 0; idx < refmv_count[ref_frame]; ++idx) {
clamp_mv_ref(&ref_mv_stack[ref_frame][idx].this_mv.as_mv,
@@ -962,7 +913,6 @@
xd->n8_w << MI_SIZE_LOG2, xd->n8_h << MI_SIZE_LOG2, xd);
}
} else {
-#if CONFIG_OPT_REF_MV
// Handle single reference frame extension
int mi_width = AOMMIN(mi_size_wide[BLOCK_64X64], xd->n8_w);
mi_width = AOMMIN(mi_width, cm->mi_cols - mi_col);
@@ -1040,7 +990,6 @@
for (int idx = refmv_count[ref_frame]; idx < MAX_MV_REF_CANDIDATES; ++idx)
mv_ref_list[rf[0]][idx].as_int = gm_mv_candidates[0].as_int;
-#endif
for (int idx = 0; idx < refmv_count[ref_frame]; ++idx) {
clamp_mv_ref(&ref_mv_stack[ref_frame][idx].this_mv.as_mv,
@@ -1205,23 +1154,6 @@
zeromv1,
#endif // USE_CUR_GM_REFMV
mi_row, mi_col, mode_context, compound_search);
-#if !CONFIG_OPT_REF_MV
- zeromv1[0].as_int = zeromv[0].as_int;
- zeromv1[1].as_int = 0;
- setup_ref_mv_list(cm, xd, rf[0], ref_mv_count, ref_mv_stack, mv_ref_list,
-#if USE_CUR_GM_REFMV
- zeromv1,
-#endif // USE_CUR_GM_REFMV
- mi_row, mi_col, mode_context, compound_search);
-
- zeromv1[0].as_int = zeromv[1].as_int;
- zeromv1[1].as_int = 0;
- setup_ref_mv_list(cm, xd, rf[1], ref_mv_count, ref_mv_stack, mv_ref_list,
-#if USE_CUR_GM_REFMV
- zeromv1,
-#endif // USE_CUR_GM_REFMV
- mi_row, mi_col, mode_context, compound_search);
-#endif
} else {
setup_ref_mv_list(cm, xd, ref_frame, ref_mv_count, ref_mv_stack,
mv_ref_list,
@@ -1231,25 +1163,9 @@
mi_row, mi_col, mode_context, compound_search);
}
-#if !CONFIG_OPT_REF_MV
- if (compound_search) {
- find_mv_refs_idx(cm, xd, mi, rf[0], mv_ref_list[rf[0]], mi_row, mi_col,
- sync, data, compound_mode_context, zeromv[0],
- ref_mv_count[rf[0]]);
- find_mv_refs_idx(cm, xd, mi, rf[1], mv_ref_list[rf[1]], mi_row, mi_col,
- sync, data, compound_mode_context, zeromv[1],
- ref_mv_count[rf[1]]);
- } else {
- if (ref_frame <= ALTREF_FRAME)
- find_mv_refs_idx(cm, xd, mi, ref_frame, mv_ref_list[rf[0]], mi_row,
- mi_col, sync, data, compound_mode_context, zeromv[0],
- ref_mv_count[ref_frame]);
- }
-#else
(void)compound_mode_context;
(void)data;
(void)sync;
-#endif
}
void av1_find_best_ref_mvs(int allow_hp, int_mv *mvlist, int_mv *nearest_mv,
diff --git a/av1/common/mvref_common.h b/av1/common/mvref_common.h
index 91f44a6..b9c8abf 100644
--- a/av1/common/mvref_common.h
+++ b/av1/common/mvref_common.h
@@ -20,11 +20,7 @@
#define MVREF_NEIGHBOURS 9
#define MVREF_ROWS 3
-#if CONFIG_OPT_REF_MV
#define MVREF_COLS 3
-#else
-#define MVREF_COLS 4
-#endif
// Set the upper limit of the motion vector component magnitude.
// This would make a motion vector fit in 26 bits. Plus 3 bits for the
@@ -293,9 +289,7 @@
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_OPT_REF_MV
return 0;
-#endif
if (ref_mv_idx < ref_mv_count &&
ref_mv_stack[ref_mv_idx].weight >= REF_CAT_LEVEL)
@@ -373,7 +367,6 @@
const int16_t *const mode_context, const MV_REFERENCE_FRAME *const rf) {
const int8_t ref_frame = av1_ref_frame_type(rf);
-#if CONFIG_OPT_REF_MV
if (rf[1] <= INTRA_FRAME) return mode_context[ref_frame];
const int16_t newmv_ctx = mode_context[ref_frame] & NEWMV_CTX_MASK;
@@ -382,9 +375,6 @@
const int16_t comp_ctx = (refmv_ctx >> 1) * COMP_NEWMV_CTXS +
AOMMIN(newmv_ctx, COMP_NEWMV_CTXS - 1);
return comp_ctx;
-#else
- return mode_context[ref_frame];
-#endif
}
static INLINE uint8_t av1_drl_ctx(const CANDIDATE_MV *ref_mv_stack,
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 63ae357..df8de05 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1446,14 +1446,7 @@
int mode_ctx = 0;
-#if CONFIG_OPT_REF_MV
mode_ctx = av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame);
-#else
- if (is_compound)
- mode_ctx = compound_inter_mode_ctx[mbmi->ref_frame[0]];
- else
- mode_ctx = av1_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame);
-#endif
mbmi->ref_mv_idx = 0;
if (mbmi->skip_mode) {
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 8c5073a..af9f6f4 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -1096,16 +1096,8 @@
write_ref_frames(cm, xd, w);
-#if CONFIG_OPT_REF_MV
mode_ctx =
av1_mode_context_analyzer(mbmi_ext->mode_context, mbmi->ref_frame);
-#else
- if (is_compound)
- mode_ctx = mbmi_ext->compound_mode_context[mbmi->ref_frame[0]];
- else
- mode_ctx =
- av1_mode_context_analyzer(mbmi_ext->mode_context, mbmi->ref_frame);
-#endif
// If segment skip is not enabled code the mode.
if (!segfeature_active(seg, segment_id, SEG_LVL_SKIP)) {
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 9ca9013..80b2e10 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1265,7 +1265,6 @@
int16_t mode_ctx;
const PREDICTION_MODE mode = mbmi->mode;
-#if CONFIG_OPT_REF_MV
mode_ctx =
av1_mode_context_analyzer(mbmi_ext->mode_context, mbmi->ref_frame);
if (has_second_ref(mbmi)) {
@@ -1276,20 +1275,6 @@
} else {
update_inter_mode_stats(fc, counts, mode, mode_ctx, allow_update_cdf);
}
-#else
- if (has_second_ref(mbmi)) {
- mode_ctx = mbmi_ext->compound_mode_context[mbmi->ref_frame[0]];
- ++counts->inter_compound_mode[mode_ctx][INTER_COMPOUND_OFFSET(mode)];
- if (allow_update_cdf) {
- update_cdf(fc->inter_compound_mode_cdf[mode_ctx],
- INTER_COMPOUND_OFFSET(mode), INTER_COMPOUND_MODES);
- }
- } else {
- mode_ctx =
- av1_mode_context_analyzer(mbmi_ext->mode_context, mbmi->ref_frame);
- update_inter_mode_stats(fc, counts, mode, mode_ctx, allow_update_cdf);
- }
-#endif
int mode_allowed = (mbmi->mode == NEWMV);
mode_allowed |= (mbmi->mode == NEW_NEWMV);
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index a259438..60b5af6 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -5179,11 +5179,7 @@
this_mode == GLOBAL_GLOBALMV) &&
frame_mv[this_mode][ref_frames[0]].as_int == zeromv[0].as_int &&
frame_mv[this_mode][ref_frames[1]].as_int == zeromv[1].as_int) {
-#if CONFIG_OPT_REF_MV
int16_t rfc = av1_mode_context_analyzer(mode_context, ref_frames);
-#else
- int16_t rfc = compound_mode_context[ref_frames[0]];
-#endif
int c2 = cost_mv_ref(x, NEAREST_NEARESTMV, rfc);
int c3 = cost_mv_ref(x, GLOBAL_GLOBALMV, rfc);
int c5 = cost_mv_ref(x, NEAR_NEARMV, rfc);
@@ -7371,15 +7367,7 @@
mbmi->compound_idx = 1;
if (mbmi->ref_frame[1] == INTRA_FRAME) mbmi->ref_frame[1] = NONE_FRAME;
-#if CONFIG_OPT_REF_MV
mode_ctx = av1_mode_context_analyzer(mbmi_ext->mode_context, mbmi->ref_frame);
-#else
- if (is_comp_pred)
- mode_ctx = mbmi_ext->compound_mode_context[refs[0]];
- else
- mode_ctx =
- av1_mode_context_analyzer(mbmi_ext->mode_context, mbmi->ref_frame);
-#endif
memset(tmp_buf_, 0, sizeof(tmp_buf_));
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH)