Commit 3ac2093f authored by Zoe Liu's avatar Zoe Liu Committed by Yaowu Xu
Browse files

Enable altref2 by default and merge it into ext-refs

Change-Id: Ie67266538db41c6aa7d79a5c270c26c021583c48
parent 492c7957
......@@ -51,8 +51,7 @@ struct loopfilter {
uint8_t mode_ref_delta_update;
// 0 = Intra, Last, Last2+Last3(CONFIG_EXT_REFS),
// GF, BRF(CONFIG_EXT_REFS),
// ARF2(CONFIG_EXT_REFS+CONFIG_ALTREF2), ARF
// GF, BRF(CONFIG_EXT_REFS), ARF2(CONFIG_EXT_REFS), ARF
int8_t ref_deltas[TOTAL_REFS_PER_FRAME];
int8_t last_ref_deltas[TOTAL_REFS_PER_FRAME];
......
......@@ -1413,20 +1413,12 @@ static const aom_prob default_comp_ref_p[REF_CONTEXTS][FWD_REFS - 1] = {
};
static const aom_prob default_comp_bwdref_p[REF_CONTEXTS][BWD_REFS - 1] = {
#if CONFIG_ALTREF2
// TODO(zoeliu): ALTREF2 to work with NEW_MULTISYMBOL.
{ 50, 50 },
{ 130, 130 },
{ 210, 210 },
{ 128, 128 },
{ 128, 128 }
#else // !CONFIG_ALTREF2
#if !CONFIG_EXT_COMP_REFS
{ 16 }, { 74 }, { 142 }, { 170 }, { 247 }
#else // CONFIG_EXT_COMP_REFS
{ 7 }, { 56 }, { 29 }, { 230 }, { 220 }
#endif // CONFIG_EXT_COMP_REFS
#endif // CONFIG_ALTREF2
};
#if CONFIG_NEW_MULTISYMBOL
......@@ -1469,19 +1461,16 @@ static const aom_cdf_prob
static const aom_cdf_prob
default_comp_bwdref_cdf[REF_CONTEXTS][BWD_REFS - 1][CDF_SIZE(2)] = {
#if !CONFIG_EXT_COMP_REFS
{ { AOM_ICDF(16 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(74 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(142 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(170 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(247 * 128), AOM_ICDF(32768), 0 } }
#else // CONFIG_EXT_COMP_REFS
{ { AOM_ICDF(7 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(56 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(29 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(230 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(220 * 128), AOM_ICDF(32768), 0 } }
#endif // !CONFIG_EXT_COMP_REFS
{ { AOM_ICDF(50 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(50 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(130 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(130 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(210 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(210 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(128 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(128 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(128 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(128 * 128), AOM_ICDF(32768), 0 } }
};
#endif // CONFIG_NEW_MULTISYMBOL
......@@ -1504,28 +1493,12 @@ static const aom_cdf_prob
static const aom_prob default_single_ref_p[REF_CONTEXTS][SINGLE_REFS - 1] = {
#if CONFIG_EXT_REFS
#if CONFIG_ALTREF2
// TODO(zoeliu): ALTREF2 to work with NEW_MULTISYMBOL.
{ 33, 50, 16, 16, 16, 50 },
{ 77, 130, 74, 74, 74, 130 },
{ 142, 210, 142, 142, 142, 210 },
{ 172, 128, 170, 170, 170, 128 },
{ 238, 128, 247, 247, 247, 128 }
#else // !CONFIG_ALTREF2
#if !CONFIG_EXT_COMP_REFS
{ 33, 16, 16, 16, 16 },
{ 77, 74, 74, 74, 74 },
{ 142, 142, 142, 142, 142 },
{ 172, 170, 170, 170, 170 },
{ 238, 247, 247, 247, 247 }
#else // CONFIG_EXT_COMP_REFS
{ 36, 2, 28, 58, 9 },
{ 64, 22, 60, 122, 40 },
{ 153, 69, 126, 179, 71 },
{ 128, 174, 189, 216, 101 },
{ 233, 252, 228, 246, 200 }
#endif // !CONFIG_EXT_COMP_REFS
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
{ 31, 25 }, { 72, 80 }, { 147, 148 }, { 197, 191 }, { 235, 247 },
#endif // CONFIG_EXT_REFS
......@@ -1535,59 +1508,36 @@ static const aom_prob default_single_ref_p[REF_CONTEXTS][SINGLE_REFS - 1] = {
static const aom_cdf_prob
default_single_ref_cdf[REF_CONTEXTS][SINGLE_REFS - 1][CDF_SIZE(2)] = {
#if CONFIG_EXT_REFS
#if !CONFIG_EXT_COMP_REFS
{ { AOM_ICDF(33 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(50 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(16 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(16 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(16 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(16 * 128), AOM_ICDF(32768), 0 } },
{ AOM_ICDF(50 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(77 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(130 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(74 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(74 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(74 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(74 * 128), AOM_ICDF(32768), 0 } },
{ AOM_ICDF(130 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(142 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(210 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(142 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(142 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(142 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(142 * 128), AOM_ICDF(32768), 0 } },
{ AOM_ICDF(210 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(172 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(128 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(170 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(170 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(170 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(170 * 128), AOM_ICDF(32768), 0 } },
{ AOM_ICDF(128 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(238 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(128 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(247 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(247 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(247 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(247 * 128), AOM_ICDF(32768), 0 } }
#else // CONFIG_EXT_COMP_REFS
{ { AOM_ICDF(36 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(2 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(28 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(58 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(9 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(64 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(22 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(60 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(122 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(40 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(153 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(69 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(126 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(179 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(71 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(128 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(174 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(189 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(216 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(101 * 128), AOM_ICDF(32768), 0 } },
{ { AOM_ICDF(233 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(252 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(228 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(246 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(200 * 128), AOM_ICDF(32768), 0 } }
#endif // !CONFIG_EXT_COMP_REFS
{ AOM_ICDF(128 * 128), AOM_ICDF(32768), 0 } }
#else // !CONFIG_EXT_REFS
{ { AOM_ICDF(31 * 128), AOM_ICDF(32768), 0 },
{ AOM_ICDF(25 * 128), AOM_ICDF(32768), 0 } },
......@@ -5430,9 +5380,9 @@ static void set_default_lf_deltas(struct loopfilter *lf) {
lf->ref_deltas[BWDREF_FRAME] = lf->ref_deltas[LAST_FRAME];
#endif // CONFIG_EXT_REFS
lf->ref_deltas[GOLDEN_FRAME] = -1;
#if CONFIG_ALTREF2
#if CONFIG_EXT_REFS
lf->ref_deltas[ALTREF2_FRAME] = -1;
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
lf->ref_deltas[ALTREF_FRAME] = -1;
lf->mode_deltas[0] = 0;
......
......@@ -325,14 +325,9 @@ typedef enum {
AOM_LAST3_FLAG = 1 << 2,
AOM_GOLD_FLAG = 1 << 3,
AOM_BWD_FLAG = 1 << 4,
#if CONFIG_ALTREF2
AOM_ALT2_FLAG = 1 << 5,
AOM_ALT_FLAG = 1 << 6,
AOM_REFFRAME_ALL = (1 << 7) - 1
#else // !CONFIG_ALTREF2
AOM_ALT_FLAG = 1 << 5,
AOM_REFFRAME_ALL = (1 << 6) - 1
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
AOM_GOLD_FLAG = 1 << 1,
AOM_ALT_FLAG = 1 << 2,
......@@ -631,14 +626,8 @@ typedef uint8_t TXFM_CONTEXT;
#define LAST3_FRAME 3
#define GOLDEN_FRAME 4
#define BWDREF_FRAME 5
#if CONFIG_ALTREF2
#define ALTREF2_FRAME 6
#define ALTREF_FRAME 7
#else // !CONFIG_ALTREF2
#define ALTREF_FRAME 6
#endif // CONFIG_ALTREF2
#define LAST_REF_FRAMES (LAST3_FRAME - LAST_FRAME + 1)
#else // !CONFIG_EXT_REFS
#define GOLDEN_FRAME 2
......
......@@ -302,10 +302,8 @@ static MV_REFERENCE_FRAME ref_frame_map[COMP_REFS][2] = {
{ LAST_FRAME, BWDREF_FRAME }, { LAST2_FRAME, BWDREF_FRAME },
{ LAST3_FRAME, BWDREF_FRAME }, { GOLDEN_FRAME, BWDREF_FRAME },
#if CONFIG_ALTREF2
{ LAST_FRAME, ALTREF2_FRAME }, { LAST2_FRAME, ALTREF2_FRAME },
{ LAST3_FRAME, ALTREF2_FRAME }, { GOLDEN_FRAME, ALTREF2_FRAME },
#endif // CONFIG_ALTREF2
{ LAST_FRAME, ALTREF_FRAME }, { LAST2_FRAME, ALTREF_FRAME },
{ LAST3_FRAME, ALTREF_FRAME }, { GOLDEN_FRAME, ALTREF_FRAME }
......
......@@ -611,9 +611,7 @@ static INLINE void ensure_mv_buffer(RefCntBuffer *buf, AV1_COMMON *cm) {
#define LAST3_IS_VALID(cm) ((cm)->frame_refs[LAST3_FRAME - 1].is_valid)
#define GOLDEN_IS_VALID(cm) ((cm)->frame_refs[GOLDEN_FRAME - 1].is_valid)
#define BWDREF_IS_VALID(cm) ((cm)->frame_refs[BWDREF_FRAME - 1].is_valid)
#if CONFIG_ALTREF2
#define ALTREF2_IS_VALID(cm) ((cm)->frame_refs[ALTREF2_FRAME - 1].is_valid)
#endif // CONFIG_ALTREF2
#define ALTREF_IS_VALID(cm) ((cm)->frame_refs[ALTREF_FRAME - 1].is_valid)
#define L_OR_L2(cm) (LAST_IS_VALID(cm) || LAST2_IS_VALID(cm))
......@@ -624,10 +622,8 @@ static INLINE void ensure_mv_buffer(RefCntBuffer *buf, AV1_COMMON *cm) {
#define L3_OR_G(cm) (LAST3_IS_VALID(cm) || GOLDEN_IS_VALID(cm))
#define L3_AND_G(cm) (LAST3_IS_VALID(cm) && GOLDEN_IS_VALID(cm))
#if CONFIG_ALTREF2
#define BWD_OR_ALT2(cm) (BWDREF_IS_VALID(cm) || ALTREF2_IS_VALID(cm))
#define BWD_AND_ALT2(cm) (BWDREF_IS_VALID(cm) && ALTREF2_IS_VALID(cm))
#endif // CONFIG_ALTREF2
#define BWD_OR_ALT(cm) (BWDREF_IS_VALID(cm) || ALTREF_IS_VALID(cm))
#define BWD_AND_ALT(cm) (BWDREF_IS_VALID(cm) && ALTREF_IS_VALID(cm))
#endif // CONFIG_VAR_REFS
......
......@@ -885,8 +885,6 @@ int av1_get_pred_context_comp_ref_p2(const AV1_COMMON *cm,
return pred_context;
}
#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) {
......@@ -987,132 +985,6 @@ int av1_get_pred_context_comp_bwdref_p1(const AV1_COMMON *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) {
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;
// Note:
// 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
// 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 // CONFIG_ONE_SIDED_COMPOUND
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);
if (above_intra && left_intra) { // intra/intra (2)
pred_context = 2;
} else if (above_intra || left_intra) { // intra/inter
const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
if (!has_second_ref(edge_mbmi)) // single pred (1/3)
pred_context = 1 + 2 * (edge_mbmi->ref_frame[0] != cm->comp_bwd_ref[1]);
else // comp pred (1/3)
pred_context =
1 +
2 * (edge_mbmi->ref_frame[bwd_ref_sign_idx] != cm->comp_bwd_ref[1]);
} else { // inter/inter
const int l_comp = has_second_ref(left_mbmi);
const int a_comp = has_second_ref(above_mbmi);
const MV_REFERENCE_FRAME l_brf =
l_comp ? left_mbmi->ref_frame[bwd_ref_sign_idx] : NONE_FRAME;
const MV_REFERENCE_FRAME a_brf =
a_comp ? above_mbmi->ref_frame[bwd_ref_sign_idx] : NONE_FRAME;
const MV_REFERENCE_FRAME l_frf =
!l_comp ? left_mbmi->ref_frame[0]
: left_mbmi->ref_frame[fwd_ref_sign_idx];
const MV_REFERENCE_FRAME a_frf =
!a_comp ? above_mbmi->ref_frame[0]
: above_mbmi->ref_frame[fwd_ref_sign_idx];
if (l_comp && a_comp) { // comp/comp
if (l_brf == a_brf && l_brf == cm->comp_bwd_ref[1]) {
pred_context = 0;
} else if (l_brf == cm->comp_bwd_ref[1] ||
a_brf == cm->comp_bwd_ref[1]) {
pred_context = 1;
} else {
// 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
if (l_frf == a_frf && l_frf == cm->comp_bwd_ref[1]) {
pred_context = 0;
} else if (l_frf == cm->comp_bwd_ref[1] ||
a_frf == cm->comp_bwd_ref[1]) {
pred_context = 1;
} 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
assert((l_comp && !a_comp) || (!l_comp && a_comp));
if ((l_comp && l_brf == cm->comp_bwd_ref[1] &&
a_frf == cm->comp_bwd_ref[1]) ||
(a_comp && a_brf == cm->comp_bwd_ref[1] &&
l_frf == cm->comp_bwd_ref[1])) {
pred_context = 1;
} else if ((l_comp && l_brf == cm->comp_bwd_ref[1]) ||
(a_comp && a_brf == cm->comp_bwd_ref[1]) ||
(!l_comp && l_frf == cm->comp_bwd_ref[1]) ||
(!a_comp && a_frf == cm->comp_bwd_ref[1])) {
pred_context = 2;
} else {
pred_context = 4;
}
}
}
} 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)) {
pred_context = 2;
} else {
if (has_second_ref(edge_mbmi)) {
pred_context =
4 * (edge_mbmi->ref_frame[bwd_ref_sign_idx] != cm->comp_bwd_ref[1]);
} else {
pred_context = 3 * (edge_mbmi->ref_frame[0] != cm->comp_bwd_ref[1]);
}
}
} else { // no edges available (2)
pred_context = 2;
}
assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
return pred_context;
}
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
// Returns a context number for the given MB prediction signal
......@@ -1268,96 +1140,7 @@ int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
// 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;
const int has_above = xd->up_available;
const int has_left = xd->left_available;
// Note:
// 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 (has_above && has_left) { // 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 or inter/intra
const MB_MODE_INFO *edge_mbmi = above_intra ? left_mbmi : above_mbmi;
if (!has_second_ref(edge_mbmi)) { // single
if (!CHECK_BACKWARD_REFS(edge_mbmi->ref_frame[0]))
pred_context = 3;
else
pred_context = 4 * (edge_mbmi->ref_frame[0] == BWDREF_FRAME);
} else { // comp
pred_context = 1 +
2 * (edge_mbmi->ref_frame[0] == BWDREF_FRAME ||
edge_mbmi->ref_frame[1] == BWDREF_FRAME);
}
} else { // inter/inter
const int above_has_second = has_second_ref(above_mbmi);
const int left_has_second = has_second_ref(left_mbmi);
const MV_REFERENCE_FRAME above0 = above_mbmi->ref_frame[0];
const MV_REFERENCE_FRAME above1 = above_mbmi->ref_frame[1];
const MV_REFERENCE_FRAME left0 = left_mbmi->ref_frame[0];
const MV_REFERENCE_FRAME left1 = left_mbmi->ref_frame[1];
if (above_has_second && left_has_second) { // comp/comp
if (above0 == left0 && above1 == left1)
pred_context =
3 * (above0 == BWDREF_FRAME || above1 == BWDREF_FRAME ||
left0 == BWDREF_FRAME || left1 == BWDREF_FRAME);
else
pred_context = 2;
} else if (above_has_second || left_has_second) { // single/comp
const MV_REFERENCE_FRAME rfs = !above_has_second ? above0 : left0;
const MV_REFERENCE_FRAME crf1 = above_has_second ? above0 : left0;
const MV_REFERENCE_FRAME crf2 = above_has_second ? above1 : left1;
if (rfs == BWDREF_FRAME)
pred_context = 3 + (crf1 == BWDREF_FRAME || crf2 == BWDREF_FRAME);
else if (rfs == ALTREF_FRAME)
pred_context = (crf1 == BWDREF_FRAME || crf2 == BWDREF_FRAME);
else
pred_context = 1 + 2 * (crf1 == BWDREF_FRAME || crf2 == BWDREF_FRAME);
} else { // single/single
if (!CHECK_BACKWARD_REFS(above0) && !CHECK_BACKWARD_REFS(left0)) {
pred_context = 2 + (above0 == left0);
} else if (!CHECK_BACKWARD_REFS(above0) ||
!CHECK_BACKWARD_REFS(left0)) {
const MV_REFERENCE_FRAME edge0 =
!CHECK_BACKWARD_REFS(above0) ? left0 : above0;
pred_context = 4 * (edge0 == BWDREF_FRAME);
} else {
pred_context =
2 * (above0 == BWDREF_FRAME) + 2 * (left0 == BWDREF_FRAME);
}
}
}
} else if (has_above || has_left) { // one edge available
const MB_MODE_INFO *edge_mbmi = has_above ? above_mbmi : left_mbmi;
if (!is_inter_block(edge_mbmi) ||
(!CHECK_BACKWARD_REFS(edge_mbmi->ref_frame[0]) &&
!has_second_ref(edge_mbmi)))
pred_context = 2;
else if (!has_second_ref(edge_mbmi)) // single
pred_context = 4 * (edge_mbmi->ref_frame[0] == BWDREF_FRAME);
else // comp
pred_context = 3 * (edge_mbmi->ref_frame[0] == BWDREF_FRAME ||
edge_mbmi->ref_frame[1] == BWDREF_FRAME);
} else { // no edges available (2)
pred_context = 2;
}
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
......@@ -1638,13 +1421,11 @@ int av1_get_pred_context_single_ref_p5(const MACROBLOCKD *xd) {
return pred_context;
}
#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
......
......@@ -243,17 +243,22 @@ static INLINE aom_prob av1_get_pred_prob_comp_bwdref_p(const AV1_COMMON *cm,
return cm->fc->comp_bwdref_prob[pred_context][0];
}
#if CONFIG_ALTREF2
// TODO(zoeliu): ALTREF2 to work with NEW_MULTISYMBOL
int av1_get_pred_context_comp_bwdref_p1(const AV1_COMMON *cm,
const MACROBLOCKD *xd);
#if CONFIG_NEW_MULTISYMBOL
static INLINE aom_cdf_prob *av1_get_pred_cdf_comp_bwdref_p1(
const AV1_COMMON *cm, const MACROBLOCKD *xd) {
const int pred_context = av1_get_pred_context_comp_bwdref_p1(cm, xd);
return xd->tile_ctx->comp_bwdref_cdf[pred_context][1];
}
#endif // CONFIG_NEW_MULTISYMBOL
static INLINE aom_prob av1_get_pred_prob_comp_bwdref_p1(const AV1_COMMON *cm,
const MACROBLOCKD *xd) {
const int pred_context = av1_get_pred_context_comp_bwdref_p1(cm, xd);
return cm->fc->comp_bwdref_prob[pred_context][1];
}
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd);
......@@ -292,14 +297,12 @@ static INLINE aom_prob av1_get_pred_prob_single_ref_p5(const AV1_COMMON *cm,
return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p5(xd)][4];
}
#if CONFIG_ALTREF2
int av1_get_pred_context_single_ref_p6(const MACROBLOCKD *xd);
static INLINE aom_prob av1_get_pred_prob_single_ref_p6(const AV1_COMMON *cm,
const MACROBLOCKD *xd) {
return cm->fc->single_ref_prob[av1_get_pred_context_single_ref_p6(xd)][5];
}
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
#if CONFIG_NEW_MULTISYMBOL
......@@ -334,6 +337,12 @@ static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p5(
return xd->tile_ctx
->single_ref_cdf[av1_get_pred_context_single_ref_p5(xd)][4];
}
static INLINE aom_cdf_prob *av1_get_pred_cdf_single_ref_p6(
const AV1_COMMON *cm, const MACROBLOCKD *xd) {
(void)cm;
return xd->tile_ctx
->single_ref_cdf[av1_get_pred_context_single_ref_p6(xd)][5];
}
#endif // CONFIG_EXT_REFS
#endif // CONFIG_NEW_MULTISYMBOL
......
......@@ -115,12 +115,8 @@ static void setup_compound_reference_mode(AV1_COMMON *cm) {
cm->comp_fwd_ref[3] = GOLDEN_FRAME;
cm->comp_bwd_ref[0] = BWDREF_FRAME;
#if CONFIG_ALTREF2
cm->comp_bwd_ref[1] = ALTREF2_FRAME;
cm->comp_bwd_ref[2] = ALTREF_FRAME;
#else // !CONFIG_ALTREF2
cm->comp_bwd_ref[1] = ALTREF_FRAME;
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
if (cm->ref_frame_sign_bias[LAST_FRAME] ==
cm->ref_frame_sign_bias[GOLDEN_FRAME]) {
......
......@@ -1525,12 +1525,8 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
const int ctx_bwd = av1_get_pred_context_comp_bwdref_p(cm, xd);
#if CONFIG_VAR_REFS
int bit_bwd;
// Test need to explicitly code (BWD/ALT2) vs (ALT) branch node in tree
#if CONFIG_ALTREF2
// Test need to explicitly code (BWD/ALT2) vs (ALT) branch node in tree
const int bit_bwd_uncertain = BWD_OR_ALT2(cm) && ALTREF_IS_VALID(cm);
#else // !CONFIG_ALTREF2
const int bit_bwd_uncertain = BWD_AND_ALT(cm);
#endif // CONFIG_ALTREF2
if (bit_bwd_uncertain)
bit_bwd = READ_REF_BIT(comp_bwdref_p);
else
......@@ -1539,7 +1535,6 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
const int bit_bwd = READ_REF_BIT(comp_bwdref_p);
#endif // CONFIG_VAR_REFS
if (counts) ++counts->comp_bwdref[ctx_bwd][0][bit_bwd];
#if CONFIG_ALTREF2
if (!bit_bwd) {
const int ctx1_bwd = av1_get_pred_context_comp_bwdref_p1(cm, xd);
#if CONFIG_VAR_REFS
......@@ -1556,9 +1551,6 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
} else {
ref_frame[idx] = cm->comp_bwd_ref[2];
}
#else // !CONFIG_ALTREF2
ref_frame[idx] = cm->comp_bwd_ref[bit_bwd];
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
ref_frame[!idx] = cm->comp_var_ref[bit];
ref_frame[idx] = cm->comp_fixed_ref;
......@@ -1568,7 +1560,6 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
const int ctx0 = av1_get_pred_context_single_ref_p1(xd);
#if CONFIG_VAR_REFS
int bit0;
#if CONFIG_ALTREF2
// Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT2,ALT) branch node
// in tree