summaryrefslogtreecommitdiff
path: root/third_party/aom/av1/common/pred_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/aom/av1/common/pred_common.c')
-rw-r--r--third_party/aom/av1/common/pred_common.c475
1 files changed, 415 insertions, 60 deletions
diff --git a/third_party/aom/av1/common/pred_common.c b/third_party/aom/av1/common/pred_common.c
index 51c343d19a..0417a67f8e 100644
--- a/third_party/aom/av1/common/pred_common.c
+++ b/third_party/aom/av1/common/pred_common.c
@@ -223,27 +223,34 @@ int av1_get_intra_inter_context(const MACROBLOCKD *xd) {
// The compound/single mode info data structure has one element border above and
// to the left of the entries corresponding to real macroblocks.
// The prediction flags in these dummy entries are initialized to 0.
-// 0 - single/single
-// 1 - single/--, --/single, --/--
-// 2 - single/comp, comp/single
-// 3 - comp/comp, comp/--, --/comp
int av1_get_inter_mode_context(const MACROBLOCKD *xd) {
const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
const int has_above = xd->up_available;
const int has_left = xd->left_available;
- if (has_above && has_left) { // both edges available (0/2/3)
- const int above_inter_comp_mode = is_inter_compound_mode(above_mbmi->mode);
- const int left_inter_comp_mode = is_inter_compound_mode(left_mbmi->mode);
- return (above_inter_comp_mode && left_inter_comp_mode)
- ? 3
- : (above_inter_comp_mode || left_inter_comp_mode) * 2;
- } else if (has_above || has_left) { // one edge available (1/3)
+ if (has_above && has_left) { // both edges available
+ const int above_inter_comp_mode =
+ is_inter_anyref_comp_mode(above_mbmi->mode);
+ const int left_inter_comp_mode = is_inter_anyref_comp_mode(left_mbmi->mode);
+ if (above_inter_comp_mode && left_inter_comp_mode)
+ return 0;
+ else if (above_inter_comp_mode || left_inter_comp_mode)
+ return 1;
+ else if (!is_inter_block(above_mbmi) && !is_inter_block(left_mbmi))
+ return 2;
+ else
+ return 3;
+ } else if (has_above || has_left) { // one edge available
const MB_MODE_INFO *const edge_mbmi = has_above ? above_mbmi : left_mbmi;
- return is_inter_compound_mode(edge_mbmi->mode) ? 3 : 1;
- } else { // no edge available (1)
- return 1;
+ if (is_inter_anyref_comp_mode(edge_mbmi->mode))
+ return 1;
+ else if (!is_inter_block(edge_mbmi))
+ return 2;
+ else
+ return 3;
+ } else { // no edge available
+ return 2;
}
}
#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
@@ -256,6 +263,9 @@ int av1_get_inter_mode_context(const MACROBLOCKD *xd) {
#define IS_BACKWARD_REF_FRAME(ref_frame) ((ref_frame) == cm->comp_fixed_ref)
#endif // CONFIG_EXT_REFS
+#define CHECK_GOLDEN_OR_LAST3(ref_frame) \
+ (((ref_frame) == GOLDEN_FRAME) || ((ref_frame) == LAST3_FRAME))
+
int av1_get_reference_mode_context(const AV1_COMMON *cm,
const MACROBLOCKD *xd) {
int ctx;
@@ -303,6 +313,247 @@ int av1_get_reference_mode_context(const AV1_COMMON *cm,
return ctx;
}
+#if CONFIG_EXT_COMP_REFS
+#define CHECK_BWDREF_OR_ALTREF(ref_frame) \
+ ((ref_frame) == BWDREF_FRAME || (ref_frame) == ALTREF_FRAME)
+// TODO(zoeliu): To try on the design of 3 contexts, instead of 5:
+// COMP_REF_TYPE_CONTEXTS = 3
+int av1_get_comp_reference_type_context(const MACROBLOCKD *xd) {
+ int pred_context;
+ const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
+ const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
+ const int above_in_image = xd->up_available;
+ const int left_in_image = xd->left_available;
+
+ if (above_in_image && left_in_image) { // both edges available
+ const int above_intra = !is_inter_block(above_mbmi);
+ const int left_intra = !is_inter_block(left_mbmi);
+
+ if (above_intra && left_intra) { // intra/intra
+ pred_context = 2;
+ } else if (above_intra || left_intra) { // intra/inter
+ const MB_MODE_INFO *inter_mbmi = above_intra ? left_mbmi : above_mbmi;
+
+ if (!has_second_ref(inter_mbmi)) // single pred
+ pred_context = 2;
+ else // comp pred
+ pred_context = 1 + 2 * has_uni_comp_refs(inter_mbmi);
+ } else { // inter/inter
+ const int a_sg = !has_second_ref(above_mbmi);
+ const int l_sg = !has_second_ref(left_mbmi);
+ const MV_REFERENCE_FRAME frfa = above_mbmi->ref_frame[0];
+ const MV_REFERENCE_FRAME frfl = left_mbmi->ref_frame[0];
+
+ if (a_sg && l_sg) { // single/single
+ pred_context = 1 +
+ 2 * (!(CHECK_BWDREF_OR_ALTREF(frfa) ^
+ CHECK_BWDREF_OR_ALTREF(frfl)));
+ } else if (l_sg || a_sg) { // single/comp
+ const int uni_rfc =
+ a_sg ? has_uni_comp_refs(left_mbmi) : has_uni_comp_refs(above_mbmi);
+
+ if (!uni_rfc) // comp bidir
+ pred_context = 1;
+ else // comp unidir
+ pred_context = 3 + (!(CHECK_BWDREF_OR_ALTREF(frfa) ^
+ CHECK_BWDREF_OR_ALTREF(frfl)));
+ } else { // comp/comp
+ const int a_uni_rfc = has_uni_comp_refs(above_mbmi);
+ const int l_uni_rfc = has_uni_comp_refs(left_mbmi);
+
+ if (!a_uni_rfc && !l_uni_rfc) // bidir/bidir
+ pred_context = 0;
+ else if (!a_uni_rfc || !l_uni_rfc) // unidir/bidir
+ pred_context = 2;
+ else // unidir/unidir
+ pred_context =
+ 3 + (!((frfa == BWDREF_FRAME) ^ (frfl == BWDREF_FRAME)));
+ }
+ }
+ } else if (above_in_image || left_in_image) { // one edge available
+ const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
+
+ if (!is_inter_block(edge_mbmi)) { // intra
+ pred_context = 2;
+ } else { // inter
+ if (!has_second_ref(edge_mbmi)) // single pred
+ pred_context = 2;
+ else // comp pred
+ pred_context = 4 * has_uni_comp_refs(edge_mbmi);
+ }
+ } else { // no edges available
+ pred_context = 2;
+ }
+
+ assert(pred_context >= 0 && pred_context < COMP_REF_TYPE_CONTEXTS);
+ return pred_context;
+}
+
+// Returns a context number for the given MB prediction signal
+//
+// Signal the uni-directional compound reference frame pair as either
+// (BWDREF, ALTREF), or (LAST, LAST2) / (LAST, LAST3) / (LAST, GOLDEN),
+// conditioning on the pair is known as uni-directional.
+//
+// 3 contexts: Voting is used to compare the count of forward references with
+// that of backward references from the spatial neighbors.
+int av1_get_pred_context_uni_comp_ref_p(const MACROBLOCKD *xd) {
+ int pred_context;
+ const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
+ const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
+ const int above_in_image = xd->up_available;
+ const int left_in_image = xd->left_available;
+
+ // Count of forward references (L, L2, L3, or G)
+ int frf_count = 0;
+ // Count of backward references (B or A)
+ int brf_count = 0;
+
+ if (above_in_image && is_inter_block(above_mbmi)) {
+ if (above_mbmi->ref_frame[0] <= GOLDEN_FRAME)
+ ++frf_count;
+ else
+ ++brf_count;
+ if (has_second_ref(above_mbmi)) {
+ if (above_mbmi->ref_frame[1] <= GOLDEN_FRAME)
+ ++frf_count;
+ else
+ ++brf_count;
+ }
+ }
+
+ if (left_in_image && is_inter_block(left_mbmi)) {
+ if (left_mbmi->ref_frame[0] <= GOLDEN_FRAME)
+ ++frf_count;
+ else
+ ++brf_count;
+ if (has_second_ref(left_mbmi)) {
+ if (left_mbmi->ref_frame[1] <= GOLDEN_FRAME)
+ ++frf_count;
+ else
+ ++brf_count;
+ }
+ }
+
+ pred_context =
+ (frf_count == brf_count) ? 1 : ((frf_count < brf_count) ? 0 : 2);
+
+ assert(pred_context >= 0 && pred_context < UNI_COMP_REF_CONTEXTS);
+ return pred_context;
+}
+
+// Returns a context number for the given MB prediction signal
+//
+// Signal the uni-directional compound reference frame pair as
+// either (LAST, LAST2), or (LAST, LAST3) / (LAST, GOLDEN),
+// conditioning on the pair is known as one of the above three.
+//
+// 3 contexts: Voting is used to compare the count of LAST2_FRAME with the
+// total count of LAST3/GOLDEN from the spatial neighbors.
+int av1_get_pred_context_uni_comp_ref_p1(const MACROBLOCKD *xd) {
+ int pred_context;
+ const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
+ const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
+ const int above_in_image = xd->up_available;
+ const int left_in_image = xd->left_available;
+
+ // Count of LAST2
+ int last2_count = 0;
+ // Count of LAST3 or GOLDEN
+ int last3_or_gld_count = 0;
+
+ if (above_in_image && is_inter_block(above_mbmi)) {
+ last2_count = (above_mbmi->ref_frame[0] == LAST2_FRAME) ? last2_count + 1
+ : last2_count;
+ last3_or_gld_count = CHECK_GOLDEN_OR_LAST3(above_mbmi->ref_frame[0])
+ ? last3_or_gld_count + 1
+ : last3_or_gld_count;
+ if (has_second_ref(above_mbmi)) {
+ last2_count = (above_mbmi->ref_frame[1] == LAST2_FRAME) ? last2_count + 1
+ : last2_count;
+ last3_or_gld_count = CHECK_GOLDEN_OR_LAST3(above_mbmi->ref_frame[1])
+ ? last3_or_gld_count + 1
+ : last3_or_gld_count;
+ }
+ }
+
+ if (left_in_image && is_inter_block(left_mbmi)) {
+ last2_count = (left_mbmi->ref_frame[0] == LAST2_FRAME) ? last2_count + 1
+ : last2_count;
+ last3_or_gld_count = CHECK_GOLDEN_OR_LAST3(left_mbmi->ref_frame[0])
+ ? last3_or_gld_count + 1
+ : last3_or_gld_count;
+ if (has_second_ref(left_mbmi)) {
+ last2_count = (left_mbmi->ref_frame[1] == LAST2_FRAME) ? last2_count + 1
+ : last2_count;
+ last3_or_gld_count = CHECK_GOLDEN_OR_LAST3(left_mbmi->ref_frame[1])
+ ? last3_or_gld_count + 1
+ : last3_or_gld_count;
+ }
+ }
+
+ pred_context = (last2_count == last3_or_gld_count)
+ ? 1
+ : ((last2_count < last3_or_gld_count) ? 0 : 2);
+
+ assert(pred_context >= 0 && pred_context < UNI_COMP_REF_CONTEXTS);
+ return pred_context;
+}
+
+// Returns a context number for the given MB prediction signal
+//
+// Signal the uni-directional compound reference frame pair as
+// either (LAST, LAST3) or (LAST, GOLDEN),
+// conditioning on the pair is known as one of the above two.
+//
+// 3 contexts: Voting is used to compare the count of LAST3_FRAME with the
+// total count of GOLDEN_FRAME from the spatial neighbors.
+int av1_get_pred_context_uni_comp_ref_p2(const MACROBLOCKD *xd) {
+ int pred_context;
+ const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
+ const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
+ const int above_in_image = xd->up_available;
+ const int left_in_image = xd->left_available;
+
+ // Count of LAST3
+ int last3_count = 0;
+ // Count of GOLDEN
+ int gld_count = 0;
+
+ if (above_in_image && is_inter_block(above_mbmi)) {
+ last3_count = (above_mbmi->ref_frame[0] == LAST3_FRAME) ? last3_count + 1
+ : last3_count;
+ gld_count =
+ (above_mbmi->ref_frame[0] == GOLDEN_FRAME) ? gld_count + 1 : gld_count;
+ if (has_second_ref(above_mbmi)) {
+ last3_count = (above_mbmi->ref_frame[1] == LAST3_FRAME) ? last3_count + 1
+ : last3_count;
+ gld_count = (above_mbmi->ref_frame[1] == GOLDEN_FRAME) ? gld_count + 1
+ : gld_count;
+ }
+ }
+
+ if (left_in_image && is_inter_block(left_mbmi)) {
+ last3_count = (left_mbmi->ref_frame[0] == LAST3_FRAME) ? last3_count + 1
+ : last3_count;
+ gld_count =
+ (left_mbmi->ref_frame[0] == GOLDEN_FRAME) ? gld_count + 1 : gld_count;
+ if (has_second_ref(left_mbmi)) {
+ last3_count = (left_mbmi->ref_frame[1] == LAST3_FRAME) ? last3_count + 1
+ : last3_count;
+ gld_count =
+ (left_mbmi->ref_frame[1] == GOLDEN_FRAME) ? gld_count + 1 : gld_count;
+ }
+ }
+
+ pred_context =
+ (last3_count == gld_count) ? 1 : ((last3_count < gld_count) ? 0 : 2);
+
+ assert(pred_context >= 0 && pred_context < UNI_COMP_REF_CONTEXTS);
+ return pred_context;
+}
+#endif // CONFIG_EXT_COMP_REFS
+
#if CONFIG_EXT_REFS
// TODO(zoeliu): Future work will be conducted to optimize the context design
@@ -311,22 +562,14 @@ int av1_get_reference_mode_context(const AV1_COMMON *cm,
#define CHECK_LAST_OR_LAST2(ref_frame) \
((ref_frame == LAST_FRAME) || (ref_frame == LAST2_FRAME))
-#define CHECK_GOLDEN_OR_LAST3(ref_frame) \
- ((ref_frame == GOLDEN_FRAME) || (ref_frame == LAST3_FRAME))
-
// Returns a context number for the given MB prediction signal
// Signal the first reference frame for a compound mode be either
// GOLDEN/LAST3, or LAST/LAST2.
//
// NOTE(zoeliu): The probability of ref_frame[0] is either
// GOLDEN_FRAME or LAST3_FRAME.
-#if CONFIG_ONE_SIDED_COMPOUND
-int av1_get_pred_context_comp_ref_p(UNUSED const AV1_COMMON *cm,
- const MACROBLOCKD *xd) {
-#else
int av1_get_pred_context_comp_ref_p(const AV1_COMMON *cm,
const MACROBLOCKD *xd) {
-#endif
int pred_context;
const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
@@ -337,14 +580,16 @@ int av1_get_pred_context_comp_ref_p(const AV1_COMMON *cm,
// The mode info data structure has a one element border above and to the
// left of the entries correpsonding to real macroblocks.
// The prediction flags in these dummy entries are initialised to 0.
-#if CONFIG_ONE_SIDED_COMPOUND // No change to bitstream
+#if CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS // No change to bitstream
// Code seems to assume that signbias of cm->comp_bwd_ref[0] is always 1
const int bwd_ref_sign_idx = 1;
#else
const int bwd_ref_sign_idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]];
-#endif
+#endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS
const int fwd_ref_sign_idx = !bwd_ref_sign_idx;
+ (void)cm;
+
if (above_in_image && left_in_image) { // both edges available
const int above_intra = !is_inter_block(above_mbmi);
const int left_intra = !is_inter_block(left_mbmi);
@@ -396,8 +641,11 @@ int av1_get_pred_context_comp_ref_p(const AV1_COMMON *cm,
if ((CHECK_LAST_OR_LAST2(frfa) && CHECK_LAST_OR_LAST2(frfl))) {
pred_context = 4;
} else {
- // NOTE(zoeliu): Following assert may be removed once confirmed.
+// NOTE(zoeliu): Following assert may be removed once confirmed.
+#if !USE_UNI_COMP_REFS
+ // TODO(zoeliu): To further study the UNIDIR scenario
assert(CHECK_GOLDEN_OR_LAST3(frfa) || CHECK_GOLDEN_OR_LAST3(frfl));
+#endif // !USE_UNI_COMP_REFS
pred_context = 2;
}
}
@@ -430,13 +678,8 @@ int av1_get_pred_context_comp_ref_p(const AV1_COMMON *cm,
//
// NOTE(zoeliu): The probability of ref_frame[0] is LAST_FRAME,
// conditioning on it is either LAST_FRAME or LAST2_FRAME.
-#if CONFIG_ONE_SIDED_COMPOUND
-int av1_get_pred_context_comp_ref_p1(UNUSED const AV1_COMMON *cm,
- const MACROBLOCKD *xd) {
-#else
int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm,
const MACROBLOCKD *xd) {
-#endif
int pred_context;
const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
@@ -447,14 +690,16 @@ int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm,
// The mode info data structure has a one element border above and to the
// left of the entries correpsonding to real macroblocks.
// The prediction flags in these dummy entries are initialised to 0.
-#if CONFIG_ONE_SIDED_COMPOUND // No change to bitstream
+#if CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS // No change to bitstream
// Code seems to assume that signbias of cm->comp_bwd_ref[0] is always 1
const int bwd_ref_sign_idx = 1;
#else
const int bwd_ref_sign_idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]];
-#endif
+#endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS
const int fwd_ref_sign_idx = !bwd_ref_sign_idx;
+ (void)cm;
+
if (above_in_image && left_in_image) { // both edges available
const int above_intra = !is_inter_block(above_mbmi);
const int left_intra = !is_inter_block(left_mbmi);
@@ -541,13 +786,8 @@ int av1_get_pred_context_comp_ref_p1(const AV1_COMMON *cm,
//
// NOTE(zoeliu): The probability of ref_frame[0] is GOLDEN_FRAME,
// conditioning on it is either GOLDEN or LAST3.
-#if CONFIG_ONE_SIDED_COMPOUND
-int av1_get_pred_context_comp_ref_p2(UNUSED const AV1_COMMON *cm,
- const MACROBLOCKD *xd) {
-#else
int av1_get_pred_context_comp_ref_p2(const AV1_COMMON *cm,
const MACROBLOCKD *xd) {
-#endif
int pred_context;
const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
@@ -558,14 +798,16 @@ int av1_get_pred_context_comp_ref_p2(const AV1_COMMON *cm,
// The mode info data structure has a one element border above and to the
// left of the entries correpsonding to real macroblocks.
// The prediction flags in these dummy entries are initialised to 0.
-#if CONFIG_ONE_SIDED_COMPOUND // No change to bitstream
+#if CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS // No change to bitstream
// Code seems to assume that signbias of cm->comp_bwd_ref[0] is always 1
const int bwd_ref_sign_idx = 1;
#else
const int bwd_ref_sign_idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]];
-#endif
+#endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS
const int fwd_ref_sign_idx = !bwd_ref_sign_idx;
+ (void)cm;
+
if (above_in_image && left_in_image) { // both edges available
const int above_intra = !is_inter_block(above_mbmi);
const int left_intra = !is_inter_block(left_mbmi);
@@ -645,14 +887,113 @@ int av1_get_pred_context_comp_ref_p2(const AV1_COMMON *cm,
return pred_context;
}
-// Returns a context number for the given MB prediction signal
-#if CONFIG_ONE_SIDED_COMPOUND
-int av1_get_pred_context_comp_bwdref_p(UNUSED const AV1_COMMON *cm,
+#if CONFIG_ALTREF2
+
+// Obtain contexts to signal a reference frame be either BWDREF/ALTREF2, or
+// ALTREF.
+int av1_get_pred_context_brfarf2_or_arf(const MACROBLOCKD *xd) {
+ const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
+ const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
+ const int above_in_image = xd->up_available;
+ const int left_in_image = xd->left_available;
+
+ // Counts of BWDREF, ALTREF2, or ALTREF frames (B, A2, or A)
+ int bwdref_counts[ALTREF_FRAME - BWDREF_FRAME + 1] = { 0 };
+
+ if (above_in_image && is_inter_block(above_mbmi)) {
+ if (above_mbmi->ref_frame[0] >= BWDREF_FRAME)
+ ++bwdref_counts[above_mbmi->ref_frame[0] - BWDREF_FRAME];
+ if (has_second_ref(above_mbmi)) {
+ if (above_mbmi->ref_frame[1] >= BWDREF_FRAME)
+ ++bwdref_counts[above_mbmi->ref_frame[1] - BWDREF_FRAME];
+ }
+ }
+
+ if (left_in_image && is_inter_block(left_mbmi)) {
+ if (left_mbmi->ref_frame[0] >= BWDREF_FRAME)
+ ++bwdref_counts[left_mbmi->ref_frame[0] - BWDREF_FRAME];
+ if (has_second_ref(left_mbmi)) {
+ if (left_mbmi->ref_frame[1] >= BWDREF_FRAME)
+ ++bwdref_counts[left_mbmi->ref_frame[1] - BWDREF_FRAME];
+ }
+ }
+
+ const int brfarf2_count = bwdref_counts[BWDREF_FRAME - BWDREF_FRAME] +
+ bwdref_counts[ALTREF2_FRAME - BWDREF_FRAME];
+ const int arf_count = bwdref_counts[ALTREF_FRAME - BWDREF_FRAME];
+ const int pred_context =
+ (brfarf2_count == arf_count) ? 1 : ((brfarf2_count < arf_count) ? 0 : 2);
+
+ assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
+ return pred_context;
+}
+
+// Obtain contexts to signal a reference frame be either BWDREF or ALTREF2.
+int av1_get_pred_context_brf_or_arf2(const MACROBLOCKD *xd) {
+ const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
+ const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
+ const int above_in_image = xd->up_available;
+ const int left_in_image = xd->left_available;
+
+ // Count of BWDREF frames (B)
+ int brf_count = 0;
+ // Count of ALTREF2 frames (A2)
+ int arf2_count = 0;
+
+ if (above_in_image && is_inter_block(above_mbmi)) {
+ if (above_mbmi->ref_frame[0] == BWDREF_FRAME)
+ ++brf_count;
+ else if (above_mbmi->ref_frame[0] == ALTREF2_FRAME)
+ ++arf2_count;
+ if (has_second_ref(above_mbmi)) {
+ if (above_mbmi->ref_frame[1] == BWDREF_FRAME)
+ ++brf_count;
+ else if (above_mbmi->ref_frame[1] == ALTREF2_FRAME)
+ ++arf2_count;
+ }
+ }
+
+ if (left_in_image && is_inter_block(left_mbmi)) {
+ if (left_mbmi->ref_frame[0] == BWDREF_FRAME)
+ ++brf_count;
+ else if (left_mbmi->ref_frame[0] == ALTREF2_FRAME)
+ ++arf2_count;
+ if (has_second_ref(left_mbmi)) {
+ if (left_mbmi->ref_frame[1] == BWDREF_FRAME)
+ ++brf_count;
+ else if (left_mbmi->ref_frame[1] == ALTREF2_FRAME)
+ ++arf2_count;
+ }
+ }
+
+ const int pred_context =
+ (brf_count == arf2_count) ? 1 : ((brf_count < arf2_count) ? 0 : 2);
+
+ assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
+ return pred_context;
+}
+
+// Signal the 2nd reference frame for a compound mode be either
+// ALTREF, or ALTREF2/BWDREF.
+int av1_get_pred_context_comp_bwdref_p(const AV1_COMMON *cm,
const MACROBLOCKD *xd) {
-#else
+ (void)cm;
+ return av1_get_pred_context_brfarf2_or_arf(xd);
+}
+
+// Signal the 2nd reference frame for a compound mode be either
+// ALTREF2 or BWDREF.
+int av1_get_pred_context_comp_bwdref_p1(const AV1_COMMON *cm,
+ const MACROBLOCKD *xd) {
+ (void)cm;
+ return av1_get_pred_context_brf_or_arf2(xd);
+}
+
+#else // !CONFIG_ALTREF2
+
+// Returns a context number for the given MB prediction signal
int av1_get_pred_context_comp_bwdref_p(const AV1_COMMON *cm,
const MACROBLOCKD *xd) {
-#endif
int pred_context;
const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
@@ -663,14 +1004,16 @@ int av1_get_pred_context_comp_bwdref_p(const AV1_COMMON *cm,
// The mode info data structure has a one element border above and to the
// left of the entries corresponding to real macroblocks.
// The prediction flags in these dummy entries are initialized to 0.
-#if CONFIG_ONE_SIDED_COMPOUND // No change to bitstream
+#if CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS // No change to bitstream
// Code seems to assume that signbias of cm->comp_bwd_ref[0] is always 1
const int bwd_ref_sign_idx = 1;
#else
const int bwd_ref_sign_idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]];
-#endif
+#endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS
const int fwd_ref_sign_idx = !bwd_ref_sign_idx;
+ (void)cm;
+
if (above_in_image && left_in_image) { // both edges available
const int above_intra = !is_inter_block(above_mbmi);
const int left_intra = !is_inter_block(left_mbmi);
@@ -709,8 +1052,11 @@ int av1_get_pred_context_comp_bwdref_p(const AV1_COMMON *cm,
a_brf == cm->comp_bwd_ref[1]) {
pred_context = 1;
} else {
- // NOTE: Backward ref should be either BWDREF or ALTREF.
+// NOTE: Backward ref should be either BWDREF or ALTREF.
+#if !USE_UNI_COMP_REFS
+ // TODO(zoeliu): To further study the UNIDIR scenario
assert(l_brf == a_brf && l_brf != cm->comp_bwd_ref[1]);
+#endif // !USE_UNI_COMP_REFS
pred_context = 3;
}
} else if (!l_comp && !a_comp) { // single/single
@@ -722,8 +1068,11 @@ int av1_get_pred_context_comp_bwdref_p(const AV1_COMMON *cm,
} else if (l_frf == a_frf) {
pred_context = 3;
} else {
+#if !USE_UNI_COMP_REFS
+ // TODO(zoeliu): To further study the UNIDIR scenario
assert(l_frf != a_frf && l_frf != cm->comp_bwd_ref[1] &&
a_frf != cm->comp_bwd_ref[1]);
+#endif // !USE_UNI_COMP_REFS
pred_context = 4;
}
} else { // comp/single
@@ -764,8 +1113,9 @@ int av1_get_pred_context_comp_bwdref_p(const AV1_COMMON *cm,
return pred_context;
}
+#endif // CONFIG_ALTREF2
-#else // CONFIG_EXT_REFS
+#else // !CONFIG_EXT_REFS
// Returns a context number for the given MB prediction signal
int av1_get_pred_context_comp_ref_p(const AV1_COMMON *cm,
@@ -854,10 +1204,8 @@ int av1_get_pred_context_comp_ref_p(const AV1_COMMON *cm,
#if CONFIG_EXT_REFS
-// For the bit to signal whether the single reference is a ALTREF_FRAME
-// or a BWDREF_FRAME.
-//
-// NOTE(zoeliu): The probability of ref_frame[0] is ALTREF/BWDREF.
+// For the bit to signal whether the single reference is a forward reference
+// frame or a backward reference frame.
int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
int pred_context;
const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
@@ -919,11 +1267,12 @@ int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
}
// For the bit to signal whether the single reference is ALTREF_FRAME or
-// BWDREF_FRAME, knowing that it shall be either of these 2 choices.
-//
-// NOTE(zoeliu): The probability of ref_frame[0] is ALTREF_FRAME, conditioning
-// on it is either ALTREF_FRAME/BWDREF_FRAME.
+// non-ALTREF backward reference frame, knowing that it shall be either of
+// these 2 choices.
int av1_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) {
+#if CONFIG_ALTREF2
+ return av1_get_pred_context_brfarf2_or_arf(xd);
+#else // !CONFIG_ALTREF2
int pred_context;
const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
@@ -1010,13 +1359,11 @@ int av1_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) {
assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
return pred_context;
+#endif // CONFIG_ALTREF2
}
// For the bit to signal whether the single reference is LAST3/GOLDEN or
// LAST2/LAST, knowing that it shall be either of these 2 choices.
-//
-// NOTE(zoeliu): The probability of ref_frame[0] is LAST3/GOLDEN, conditioning
-// on it is either LAST3/GOLDEN/LAST2/LAST.
int av1_get_pred_context_single_ref_p3(const MACROBLOCKD *xd) {
int pred_context;
const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
@@ -1293,7 +1640,15 @@ int av1_get_pred_context_single_ref_p5(const MACROBLOCKD *xd) {
return pred_context;
}
-#else // CONFIG_EXT_REFS
+#if CONFIG_ALTREF2
+// For the bit to signal whether the single reference is ALTREF2_FRAME or
+// BWDREF_FRAME, knowing that it shall be either of these 2 choices.
+int av1_get_pred_context_single_ref_p6(const MACROBLOCKD *xd) {
+ return av1_get_pred_context_brf_or_arf2(xd);
+}
+#endif // CONFIG_ALTREF2
+
+#else // !CONFIG_EXT_REFS
int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
int pred_context;