Commit 5f11e915 authored by Zoe Liu's avatar Zoe Liu

JNT_COMP: Simplify logic on inter-inter comp modes

This patch simplies the checking criteria for the two groups of
compound modes. It also makes the encoder side cdf update inside the
RD loop consistent with that in the bitstream.

Experimental results on Google test sets (30 frames of lowres and
midres) confirm this patch obtains identical coding performance.

Change-Id: I170eea91f7d2be2170df544cfc2c692b09aa82d6
parent 46ae3de1
......@@ -2196,23 +2196,21 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
#if CONFIG_JNT_COMP
// init
mbmi->comp_group_idx = 1;
mbmi->comp_group_idx = 0;
mbmi->compound_idx = 1;
mbmi->interinter_compound_type = COMPOUND_AVERAGE;
// read idx to indicate current compound inter prediction mode group
int masked_compound_used = is_any_masked_compound_used(bsize);
masked_compound_used = masked_compound_used && cm->allow_masked_compound;
if (has_second_ref(mbmi)) {
// Read idx to indicate current compound inter prediction mode group
const int masked_compound_used =
is_any_masked_compound_used(bsize) && cm->allow_masked_compound;
if (masked_compound_used) {
const int ctx_comp_group_idx = get_comp_group_idx_context(xd);
mbmi->comp_group_idx = aom_read_symbol(
r, ec_ctx->comp_group_idx_cdf[ctx_comp_group_idx], 2, ACCT_STR);
if (xd->counts)
++xd->counts->comp_group_idx[ctx_comp_group_idx][mbmi->comp_group_idx];
} else {
mbmi->comp_group_idx = 0;
}
if (mbmi->comp_group_idx == 0) {
......@@ -2222,44 +2220,33 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
if (xd->counts)
++xd->counts->compound_index[comp_index_ctx][mbmi->compound_idx];
if (mbmi->compound_idx) mbmi->interinter_compound_type = COMPOUND_AVERAGE;
} else {
assert(cm->reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
mbmi->motion_mode == SIMPLE_TRANSLATION);
assert(masked_compound_used);
// compound_segment, wedge
mbmi->interinter_compound_type = COMPOUND_AVERAGE;
if (cm->reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
mbmi->motion_mode == SIMPLE_TRANSLATION
#if CONFIG_EXT_SKIP
&& !mbmi->skip_mode
#endif // CONFIG_EXT_SKIP
) {
if (is_any_masked_compound_used(bsize)) {
if (cm->allow_masked_compound) {
if (is_interinter_compound_used(COMPOUND_WEDGE, bsize))
mbmi->interinter_compound_type =
1 + aom_read_symbol(r, ec_ctx->compound_type_cdf[bsize],
COMPOUND_TYPES - 1, ACCT_STR);
else
mbmi->interinter_compound_type = COMPOUND_SEG;
if (mbmi->interinter_compound_type == COMPOUND_WEDGE) {
assert(is_interinter_compound_used(COMPOUND_WEDGE, bsize));
mbmi->wedge_index =
aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR);
mbmi->wedge_sign = aom_read_bit(r, ACCT_STR);
}
if (mbmi->interinter_compound_type == COMPOUND_SEG) {
mbmi->mask_type =
aom_read_literal(r, MAX_SEG_MASK_BITS, ACCT_STR);
}
}
}
if (is_interinter_compound_used(COMPOUND_WEDGE, bsize))
mbmi->interinter_compound_type =
1 + aom_read_symbol(r, ec_ctx->compound_type_cdf[bsize],
COMPOUND_TYPES - 1, ACCT_STR);
else
mbmi->interinter_compound_type = COMPOUND_SEG;
if (xd->counts)
xd->counts->compound_interinter[bsize]
[mbmi->interinter_compound_type - 1]++;
if (mbmi->interinter_compound_type == COMPOUND_WEDGE) {
assert(is_interinter_compound_used(COMPOUND_WEDGE, bsize));
mbmi->wedge_index =
aom_read_literal(r, get_wedge_bits_lookup(bsize), ACCT_STR);
mbmi->wedge_sign = aom_read_bit(r, ACCT_STR);
} else {
assert(mbmi->interinter_compound_type == COMPOUND_SEG);
mbmi->mask_type = aom_read_literal(r, MAX_SEG_MASK_BITS, ACCT_STR);
}
if (xd->counts)
xd->counts
->compound_interinter[bsize][mbmi->interinter_compound_type - 1]++;
}
}
#else // CONFIG_JNT_COMP
......
......@@ -1460,16 +1460,16 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const int mi_row,
// First write idx to indicate current compound inter prediction mode group
// Group A (0): jnt_comp, compound_average
// Group B (1): interintra, compound_segment, wedge
int masked_compound_used = is_any_masked_compound_used(bsize);
masked_compound_used = masked_compound_used && cm->allow_masked_compound;
if (has_second_ref(mbmi)) {
if (masked_compound_used) {
assert(mbmi->comp_group_idx == 0);
const int masked_compound_used =
is_any_masked_compound_used(bsize) && cm->allow_masked_compound;
if (masked_compound_used) {
const int ctx_comp_group_idx = get_comp_group_idx_context(xd);
aom_write_symbol(w, mbmi->comp_group_idx,
ec_ctx->comp_group_idx_cdf[ctx_comp_group_idx], 2);
} else {
assert(mbmi->comp_group_idx == 0);
}
if (mbmi->comp_group_idx == 0) {
......@@ -1480,27 +1480,26 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const int mi_row,
aom_write_symbol(w, mbmi->compound_idx,
ec_ctx->compound_index_cdf[comp_index_ctx], 2);
} else {
assert(cpi->common.reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
mbmi->motion_mode == SIMPLE_TRANSLATION);
assert(masked_compound_used);
// compound_segment, wedge
assert(mbmi->interinter_compound_type == COMPOUND_WEDGE ||
mbmi->interinter_compound_type == COMPOUND_SEG);
// compound_segment, wedge
if (cpi->common.reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
mbmi->motion_mode == SIMPLE_TRANSLATION &&
is_any_masked_compound_used(bsize) && cm->allow_masked_compound) {
if (is_interinter_compound_used(COMPOUND_WEDGE, bsize))
aom_write_symbol(w, mbmi->interinter_compound_type - 1,
ec_ctx->compound_type_cdf[bsize],
COMPOUND_TYPES - 1);
if (is_interinter_compound_used(COMPOUND_WEDGE, bsize) &&
mbmi->interinter_compound_type == COMPOUND_WEDGE) {
aom_write_literal(w, mbmi->wedge_index,
get_wedge_bits_lookup(bsize));
aom_write_bit(w, mbmi->wedge_sign);
}
if (mbmi->interinter_compound_type == COMPOUND_SEG) {
aom_write_literal(w, mbmi->mask_type, MAX_SEG_MASK_BITS);
}
if (is_interinter_compound_used(COMPOUND_WEDGE, bsize))
aom_write_symbol(w, mbmi->interinter_compound_type - 1,
ec_ctx->compound_type_cdf[bsize],
COMPOUND_TYPES - 1);
if (mbmi->interinter_compound_type == COMPOUND_WEDGE) {
assert(is_interinter_compound_used(COMPOUND_WEDGE, bsize));
aom_write_literal(w, mbmi->wedge_index, get_wedge_bits_lookup(bsize));
aom_write_bit(w, mbmi->wedge_sign);
} else {
assert(mbmi->interinter_compound_type == COMPOUND_SEG);
aom_write_literal(w, mbmi->mask_type, MAX_SEG_MASK_BITS);
}
}
}
......
......@@ -1125,7 +1125,7 @@ static void update_stats(const AV1_COMMON *const cm, TileDataEnc *tile_data,
else
// This flag is also updated for 4x4 blocks
rdc->single_ref_used_flag = 1;
if (is_comp_ref_allowed(mbmi->sb_type)) {
if (is_comp_ref_allowed(bsize)) {
counts->comp_inter[av1_get_reference_mode_context(cm, xd)]
[has_second_ref(mbmi)]++;
if (allow_update_cdf)
......@@ -1237,31 +1237,39 @@ static void update_stats(const AV1_COMMON *const cm, TileDataEnc *tile_data,
if (mbmi->mode == NEARESTMV) wm_ctx = 2;
}
counts->motion_mode[wm_ctx][mbmi->sb_type][mbmi->motion_mode]++;
counts->motion_mode[wm_ctx][bsize][mbmi->motion_mode]++;
if (allow_update_cdf)
update_cdf(fc->motion_mode_cdf[wm_ctx][mbmi->sb_type],
mbmi->motion_mode, MOTION_MODES);
update_cdf(fc->motion_mode_cdf[wm_ctx][bsize], mbmi->motion_mode,
MOTION_MODES);
#else
counts->motion_mode[mbmi->sb_type][mbmi->motion_mode]++;
counts->motion_mode[bsize][mbmi->motion_mode]++;
if (allow_update_cdf)
update_cdf(fc->motion_mode_cdf[mbmi->sb_type], mbmi->motion_mode,
update_cdf(fc->motion_mode_cdf[bsize], mbmi->motion_mode,
MOTION_MODES);
#endif // CONFIG_EXT_WARPED_MOTION
} else if (motion_allowed == OBMC_CAUSAL) {
counts->obmc[mbmi->sb_type][mbmi->motion_mode == OBMC_CAUSAL]++;
counts->obmc[bsize][mbmi->motion_mode == OBMC_CAUSAL]++;
if (allow_update_cdf)
update_cdf(fc->obmc_cdf[mbmi->sb_type],
mbmi->motion_mode == OBMC_CAUSAL, 2);
update_cdf(fc->obmc_cdf[bsize], mbmi->motion_mode == OBMC_CAUSAL,
2);
}
}
#if CONFIG_JNT_COMP
if (has_second_ref(mbmi)) {
const int comp_group_idx_ctx = get_comp_group_idx_context(xd);
++counts->comp_group_idx[comp_group_idx_ctx][mbmi->comp_group_idx];
if (allow_update_cdf)
update_cdf(fc->comp_group_idx_cdf[comp_group_idx_ctx],
mbmi->comp_group_idx, 2);
assert(cm->reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
mbmi->motion_mode == SIMPLE_TRANSLATION);
const int masked_compound_used =
is_any_masked_compound_used(bsize) && cm->allow_masked_compound;
if (masked_compound_used) {
const int comp_group_idx_ctx = get_comp_group_idx_context(xd);
++counts->comp_group_idx[comp_group_idx_ctx][mbmi->comp_group_idx];
if (allow_update_cdf)
update_cdf(fc->comp_group_idx_cdf[comp_group_idx_ctx],
mbmi->comp_group_idx, 2);
}
if (mbmi->comp_group_idx == 0) {
const int comp_index_ctx = get_comp_index_context(cm, xd);
......@@ -1269,23 +1277,19 @@ static void update_stats(const AV1_COMMON *const cm, TileDataEnc *tile_data,
if (allow_update_cdf)
update_cdf(fc->compound_index_cdf[comp_index_ctx],
mbmi->compound_idx, 2);
}
}
if (cm->reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) && mbmi->comp_group_idx &&
mbmi->motion_mode == SIMPLE_TRANSLATION) {
if (is_interinter_compound_used(COMPOUND_WEDGE, bsize)) {
counts->compound_interinter[bsize]
[mbmi->interinter_compound_type - 1]++;
if (allow_update_cdf)
update_cdf(fc->compound_type_cdf[bsize],
mbmi->interinter_compound_type - 1,
COMPOUND_TYPES - 1);
} else {
assert(masked_compound_used);
if (is_interinter_compound_used(COMPOUND_WEDGE, bsize)) {
counts->compound_interinter[bsize]
[mbmi->interinter_compound_type - 1]++;
if (allow_update_cdf)
update_cdf(fc->compound_type_cdf[bsize],
mbmi->interinter_compound_type - 1,
COMPOUND_TYPES - 1);
}
}
}
#else // CONFIG_JNT_COMP
if (cm->reference_mode != SINGLE_REFERENCE &&
is_inter_compound_mode(mbmi->mode) &&
mbmi->motion_mode == SIMPLE_TRANSLATION) {
......
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