Flatten nmv context model
The nmv context model dependency on the reconstructed mvs has been
deprecated. This commit converts the nmv context model to scalar
case.
Change-Id: I27f45b9d16b0e4ebdde10abd17dba873ccf6b138
diff --git a/av1/common/entropy.c b/av1/common/entropy.c
index 608e101..7f8c8cb 100644
--- a/av1/common/entropy.c
+++ b/av1/common/entropy.c
@@ -638,20 +638,17 @@
assert(num_tiles == 1);
- int j;
- for (j = 0; j < NMV_CONTEXTS; ++j) {
- AVERAGE_TILE_CDFS(nmvc[j].joints_cdf)
+ AVERAGE_TILE_CDFS(nmvc.joints_cdf)
- for (k = 0; k < 2; ++k) {
- AVERAGE_TILE_CDFS(nmvc[j].comps[k].classes_cdf)
- AVERAGE_TILE_CDFS(nmvc[j].comps[k].class0_fp_cdf)
- AVERAGE_TILE_CDFS(nmvc[j].comps[k].fp_cdf)
- AVERAGE_TILE_CDFS(nmvc[j].comps[k].sign_cdf)
- AVERAGE_TILE_CDFS(nmvc[j].comps[k].hp_cdf)
- AVERAGE_TILE_CDFS(nmvc[j].comps[k].class0_hp_cdf)
- AVERAGE_TILE_CDFS(nmvc[j].comps[k].class0_cdf)
- AVERAGE_TILE_CDFS(nmvc[j].comps[k].bits_cdf)
- }
+ for (k = 0; k < 2; ++k) {
+ AVERAGE_TILE_CDFS(nmvc.comps[k].classes_cdf)
+ AVERAGE_TILE_CDFS(nmvc.comps[k].class0_fp_cdf)
+ AVERAGE_TILE_CDFS(nmvc.comps[k].fp_cdf)
+ AVERAGE_TILE_CDFS(nmvc.comps[k].sign_cdf)
+ AVERAGE_TILE_CDFS(nmvc.comps[k].hp_cdf)
+ AVERAGE_TILE_CDFS(nmvc.comps[k].class0_hp_cdf)
+ AVERAGE_TILE_CDFS(nmvc.comps[k].class0_cdf)
+ AVERAGE_TILE_CDFS(nmvc.comps[k].bits_cdf)
}
}
diff --git a/av1/common/entropymode.h b/av1/common/entropymode.h
index 831e9fa..65c7894 100644
--- a/av1/common/entropymode.h
+++ b/av1/common/entropymode.h
@@ -135,7 +135,7 @@
aom_cdf_prob skip_mode_cdfs[SKIP_CONTEXTS][CDF_SIZE(2)];
aom_cdf_prob skip_cdfs[SKIP_CONTEXTS][CDF_SIZE(2)];
aom_cdf_prob intra_inter_cdf[INTRA_INTER_CONTEXTS][CDF_SIZE(2)];
- nmv_context nmvc[NMV_CONTEXTS];
+ nmv_context nmvc;
nmv_context ndvc;
aom_cdf_prob intrabc_cdf[CDF_SIZE(2)];
int initialized;
diff --git a/av1/common/entropymv.c b/av1/common/entropymv.c
index 292ab75..d9c8f70 100644
--- a/av1/common/entropymv.c
+++ b/av1/common/entropymv.c
@@ -119,10 +119,7 @@
}
void av1_init_mv_probs(AV1_COMMON *cm) {
- int i;
- for (i = 0; i < NMV_CONTEXTS; ++i) {
- // NB: this sets CDFs too
- cm->fc->nmvc[i] = default_nmv_context;
- }
+ // NB: this sets CDFs too
+ cm->fc->nmvc = default_nmv_context;
cm->fc->ndvc = default_nmv_context;
}
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 87e139f..0a9d298 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1193,7 +1193,7 @@
switch (mode) {
case NEWMV: {
for (int i = 0; i < 1 + is_compound; ++i) {
- nmv_context *const nmvc = &ec_ctx->nmvc[0];
+ nmv_context *const nmvc = &ec_ctx->nmvc;
read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, allow_hp);
ret = ret && is_mv_valid(&mv[i].as_mv);
@@ -1245,7 +1245,7 @@
case NEW_NEWMV: {
assert(is_compound);
for (int i = 0; i < 2; ++i) {
- nmv_context *const nmvc = &ec_ctx->nmvc[0];
+ nmv_context *const nmvc = &ec_ctx->nmvc;
read_mv(r, &mv[i].as_mv, &ref_mv[i].as_mv, nmvc, allow_hp);
ret = ret && is_mv_valid(&mv[i].as_mv);
}
@@ -1264,7 +1264,7 @@
break;
}
case NEW_NEARESTMV: {
- nmv_context *const nmvc = &ec_ctx->nmvc[0];
+ nmv_context *const nmvc = &ec_ctx->nmvc;
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);
@@ -1272,7 +1272,7 @@
break;
}
case NEAREST_NEWMV: {
- nmv_context *const nmvc = &ec_ctx->nmvc[0];
+ nmv_context *const nmvc = &ec_ctx->nmvc;
mv[0].as_int = nearest_mv[0].as_int;
read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, allow_hp);
assert(is_compound);
@@ -1280,7 +1280,7 @@
break;
}
case NEAR_NEWMV: {
- nmv_context *const nmvc = &ec_ctx->nmvc[0];
+ nmv_context *const nmvc = &ec_ctx->nmvc;
mv[0].as_int = near_mv[0].as_int;
read_mv(r, &mv[1].as_mv, &ref_mv[1].as_mv, nmvc, allow_hp);
assert(is_compound);
@@ -1289,7 +1289,7 @@
break;
}
case NEW_NEARMV: {
- nmv_context *const nmvc = &ec_ctx->nmvc[0];
+ nmv_context *const nmvc = &ec_ctx->nmvc;
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);
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 9d9e176..d34a9ab 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -1115,18 +1115,18 @@
if (mode == NEWMV || mode == NEW_NEWMV) {
int_mv ref_mv;
for (ref = 0; ref < 1 + is_compound; ++ref) {
- nmv_context *nmvc = &ec_ctx->nmvc[0];
+ nmv_context *nmvc = &ec_ctx->nmvc;
ref_mv = mbmi_ext->ref_mvs[mbmi->ref_frame[ref]][0];
av1_encode_mv(cpi, w, &mbmi->mv[ref].as_mv, &ref_mv.as_mv, nmvc,
allow_hp);
}
} else if (mode == NEAREST_NEWMV || mode == NEAR_NEWMV) {
- nmv_context *nmvc = &ec_ctx->nmvc[0];
+ nmv_context *nmvc = &ec_ctx->nmvc;
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) {
- nmv_context *nmvc = &ec_ctx->nmvc[0];
+ nmv_context *nmvc = &ec_ctx->nmvc;
av1_encode_mv(cpi, w, &mbmi->mv[0].as_mv,
&mbmi_ext->ref_mvs[mbmi->ref_frame[0]][0].as_mv, nmvc,
allow_hp);
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index f7e7b98..26a827b 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -205,10 +205,10 @@
int pred_mv_sad[TOTAL_REFS_PER_FRAME];
int *nmvjointcost;
- int nmv_vec_cost[NMV_CONTEXTS][MV_JOINTS];
- int *nmvcost[NMV_CONTEXTS][2];
- int *nmvcost_hp[NMV_CONTEXTS][2];
- int **mv_cost_stack[NMV_CONTEXTS];
+ int nmv_vec_cost[MV_JOINTS];
+ int *nmvcost[2];
+ int *nmvcost_hp[2];
+ int **mv_cost_stack;
int **mvcost;
int32_t *wsrc_buf;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 9f7f6e4..0005390 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -264,10 +264,8 @@
cpi->common.allow_high_precision_mv = allow_high_precision_mv;
const int copy_hp = cpi->common.allow_high_precision_mv;
#endif
- int *(*src)[2] = copy_hp ? mb->nmvcost_hp : mb->nmvcost;
- for (int i = 0; i < NMV_CONTEXTS; ++i) {
- mb->mv_cost_stack[i] = src[i];
- }
+ int *(*src)[2] = copy_hp ? &mb->nmvcost_hp : &mb->nmvcost;
+ mb->mv_cost_stack = *src;
}
static BLOCK_SIZE select_sb_size(const AV1_COMP *const cpi) {
@@ -560,17 +558,14 @@
static void save_coding_context(AV1_COMP *cpi) {
CODING_CONTEXT *const cc = &cpi->coding_context;
AV1_COMMON *cm = &cpi->common;
- int i;
// Stores a snapshot of key state variables which can subsequently be
// restored with a call to av1_restore_coding_context. These functions are
// intended for use in a re-code loop in av1_compress_frame where the
// quantizer value is adjusted between loop iterations.
- for (i = 0; i < NMV_CONTEXTS; ++i) {
- av1_copy(cc->nmv_vec_cost[i], cpi->td.mb.nmv_vec_cost[i]);
- av1_copy(cc->nmv_costs, cpi->nmv_costs);
- av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp);
- }
+ av1_copy(cc->nmv_vec_cost, cpi->td.mb.nmv_vec_cost);
+ av1_copy(cc->nmv_costs, cpi->nmv_costs);
+ av1_copy(cc->nmv_costs_hp, cpi->nmv_costs_hp);
av1_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas);
av1_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas);
@@ -581,15 +576,12 @@
static void restore_coding_context(AV1_COMP *cpi) {
CODING_CONTEXT *const cc = &cpi->coding_context;
AV1_COMMON *cm = &cpi->common;
- int i;
// Restore key state variables to the snapshot state stored in the
// previous call to av1_save_coding_context.
- for (i = 0; i < NMV_CONTEXTS; ++i) {
- av1_copy(cpi->td.mb.nmv_vec_cost[i], cc->nmv_vec_cost[i]);
- av1_copy(cpi->nmv_costs, cc->nmv_costs);
- av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp);
- }
+ av1_copy(cpi->td.mb.nmv_vec_cost, cc->nmv_vec_cost);
+ av1_copy(cpi->nmv_costs, cc->nmv_costs);
+ av1_copy(cpi->nmv_costs_hp, cc->nmv_costs_hp);
av1_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas);
av1_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas);
@@ -2623,10 +2615,8 @@
realloc_segmentation_maps(cpi);
- for (i = 0; i < NMV_CONTEXTS; ++i) {
- memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs));
- memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp));
- }
+ memset(cpi->nmv_costs, 0, sizeof(cpi->nmv_costs));
+ memset(cpi->nmv_costs_hp, 0, sizeof(cpi->nmv_costs_hp));
for (i = 0; i < (sizeof(cpi->mbgraph_stats) / sizeof(cpi->mbgraph_stats[0]));
i++) {
@@ -2690,12 +2680,10 @@
cpi->first_time_stamp_ever = INT64_MAX;
- for (i = 0; i < NMV_CONTEXTS; ++i) {
- cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX];
- cpi->td.mb.nmvcost[i][1] = &cpi->nmv_costs[i][1][MV_MAX];
- cpi->td.mb.nmvcost_hp[i][0] = &cpi->nmv_costs_hp[i][0][MV_MAX];
- cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX];
- }
+ cpi->td.mb.nmvcost[0] = &cpi->nmv_costs[0][MV_MAX];
+ cpi->td.mb.nmvcost[1] = &cpi->nmv_costs[1][MV_MAX];
+ cpi->td.mb.nmvcost_hp[0] = &cpi->nmv_costs_hp[0][MV_MAX];
+ cpi->td.mb.nmvcost_hp[1] = &cpi->nmv_costs_hp[1][MV_MAX];
#ifdef OUTPUT_YUV_SKINMAP
yuv_skinmap_file = fopen("skinmap.yuv", "ab");
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index d8f7fd9..9158909 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -47,9 +47,9 @@
#endif
typedef struct {
- int nmv_vec_cost[NMV_CONTEXTS][MV_JOINTS];
- int nmv_costs[NMV_CONTEXTS][2][MV_VALS];
- int nmv_costs_hp[NMV_CONTEXTS][2][MV_VALS];
+ int nmv_vec_cost[MV_JOINTS];
+ int nmv_costs[2][MV_VALS];
+ int nmv_costs_hp[2][MV_VALS];
// 0 = Intra, Last, GF, ARF
int8_t last_ref_lf_deltas[TOTAL_REFS_PER_FRAME];
@@ -449,8 +449,8 @@
int gmtype_cost[TRANS_TYPES];
int gmparams_cost[TOTAL_REFS_PER_FRAME];
- int nmv_costs[NMV_CONTEXTS][2][MV_VALS];
- int nmv_costs_hp[NMV_CONTEXTS][2][MV_VALS];
+ int nmv_costs[2][MV_VALS];
+ int nmv_costs_hp[2][MV_VALS];
int64_t last_time_stamp_seen;
int64_t last_end_time_stamp_seen;
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c
index 81ea460..eea5995 100644
--- a/av1/encoder/rd.c
+++ b/av1/encoder/rd.c
@@ -445,8 +445,8 @@
void av1_set_mvcost(MACROBLOCK *x, int ref, int ref_mv_idx) {
(void)ref;
(void)ref_mv_idx;
- x->mvcost = x->mv_cost_stack[0];
- x->nmvjointcost = x->nmv_vec_cost[0];
+ x->mvcost = x->mv_cost_stack;
+ x->nmvjointcost = x->nmv_vec_cost;
}
void av1_fill_coeff_costs(MACROBLOCK *x, FRAME_CONTEXT *fc,
@@ -549,7 +549,6 @@
AV1_COMMON *const cm = &cpi->common;
MACROBLOCK *const x = &cpi->td.mb;
RD_OPT *const rd = &cpi->rd;
- int nmv_ctx;
aom_clear_system_state();
@@ -559,29 +558,25 @@
set_block_thresholds(cm, rd);
- for (nmv_ctx = 0; nmv_ctx < NMV_CONTEXTS; ++nmv_ctx) {
#if CONFIG_AMVR
- if (cm->cur_frame_force_integer_mv) {
- av1_build_nmv_cost_table(x->nmv_vec_cost[nmv_ctx], x->nmvcost[nmv_ctx],
- &cm->fc->nmvc[nmv_ctx], MV_SUBPEL_NONE);
- } else {
- av1_build_nmv_cost_table(
- x->nmv_vec_cost[nmv_ctx],
- cm->allow_high_precision_mv ? x->nmvcost_hp[nmv_ctx]
- : x->nmvcost[nmv_ctx],
- &cm->fc->nmvc[nmv_ctx], cm->allow_high_precision_mv);
- }
-
-#else
+ if (cm->cur_frame_force_integer_mv) {
+ av1_build_nmv_cost_table(x->nmv_vec_cost, x->nmvcost, &cm->fc->nmvc,
+ MV_SUBPEL_NONE);
+ } else {
av1_build_nmv_cost_table(
- x->nmv_vec_cost[nmv_ctx],
- cm->allow_high_precision_mv ? x->nmvcost_hp[nmv_ctx]
- : x->nmvcost[nmv_ctx],
- &cm->fc->nmvc[nmv_ctx], cm->allow_high_precision_mv);
-#endif
+ x->nmv_vec_cost,
+ cm->allow_high_precision_mv ? x->nmvcost_hp : x->nmvcost, &cm->fc->nmvc,
+ cm->allow_high_precision_mv);
}
- x->mvcost = x->mv_cost_stack[0];
- x->nmvjointcost = x->nmv_vec_cost[0];
+#else
+ av1_build_nmv_cost_table(x->nmv_vec_cost[nmv_ctx],
+ cm->allow_high_precision_mv ? x->nmvcost_hp[nmv_ctx]
+ : x->nmvcost[nmv_ctx],
+ &cm->fc->nmvc[nmv_ctx], cm->allow_high_precision_mv);
+#endif
+
+ x->mvcost = x->mv_cost_stack;
+ x->nmvjointcost = x->nmv_vec_cost;
if (frame_is_intra_only(cm) && cm->allow_screen_content_tools &&
cpi->oxcf.pass != 1) {
diff --git a/av1/encoder/temporal_filter.c b/av1/encoder/temporal_filter.c
index 1b828b7..1fc96b2 100644
--- a/av1/encoder/temporal_filter.c
+++ b/av1/encoder/temporal_filter.c
@@ -244,8 +244,8 @@
av1_set_mv_search_range(&x->mv_limits, &best_ref_mv1);
- x->mvcost = x->mv_cost_stack[0];
- x->nmvjointcost = x->nmv_vec_cost[0];
+ x->mvcost = x->mv_cost_stack;
+ x->nmvjointcost = x->nmv_vec_cost;
// Use mv costing from x->mvcost directly
av1_hex_search(x, &best_ref_mv1_full, step_param, sadpb, 1,