Commit e9b15e2b authored by Zoe Liu's avatar Zoe Liu

Add encoder support to ALTREF2

This CL adds the use of ALTREF2_FRAME to both single / comp reference
prediction at the encoder side. In particular, the encoder keeps the
distant altref as ALTREF, and uses the internal extra altrefs to
refresh ALTREF2.

Compared with the baseline (ext_tx and global_motion disabled simply
for speed concern):
(a) lowres: avg_psnr -0.395% ovr_psnr -0.393% ssim -0.329%
(b) midres: avg_psnr -0.419% ovr_psnr -0.431% ssim -0.444%
(c) AWCY High Latency:
   PSNR | PSNR Cb | PSNR Cr | PSNR HVS |    SSIM | MS SSIM | CIEDE 2000
-0.6661 | -0.5988 | -0.6669 |  -0.6993 | -0.6988 | -0.7303 | -0.6051
(d) AWCY Low Latency:
  PSNR | PSNR Cb | PSNR Cr | PSNR HVS |   SSIM | MS SSIM | CIEDE 2000
0.0720 | -0.0505 |  0.1501 |   0.0670 | 0.0842 |  0.0517 |     0.0158

TODO list:
(1) To have altref2 incorporated with ext-comp-refs;
(2) To have altref2 fully work with new-multisymbol;
(3) To re-collect the initial default probs/cdfs;
(4) To tune the encoder gf group structure design for altref2.

Change-Id: I6ad63fd65afa903d3bba20acdb68e3b67acf7fdf
parent da4d8b9c
......@@ -1590,12 +1590,22 @@ 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
if ((L_OR_L2(cm) || L3_OR_G(cm)) &&
(BWD_OR_ALT2(cm) || ALTREF_IS_VALID(cm)))
bit0 = READ_REF_BIT(single_ref_p1);
else
bit0 = (BWD_OR_ALT2(cm) || ALTREF_IS_VALID(cm));
#else // !CONFIG_ALTREF2
// Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT) branch node in
// tree
if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm))
bit0 = READ_REF_BIT(single_ref_p1);
else
bit0 = BWD_OR_ALT(cm);
#endif // CONFIG_ALTREF2
#else // !CONFIG_VAR_REFS
const int bit0 = READ_REF_BIT(single_ref_p1);
#endif // CONFIG_VAR_REFS
......@@ -1605,10 +1615,11 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
const int ctx1 = av1_get_pred_context_single_ref_p2(xd);
#if CONFIG_VAR_REFS
int bit1;
// 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 bit1_uncertain = BWD_OR_ALT2(cm) && ALTREF_IS_VALID(cm);
#else // !CONFIG_ALTREF2
// Test need to explicitly code (BWD) vs (ALT) branch node in tree
const int bit1_uncertain = BWD_AND_ALT(cm);
#endif // CONFIG_ALTREF2
if (bit1_uncertain)
......
......@@ -1153,6 +1153,29 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd,
#endif // CONFIG_VAR_REFS
}
#if CONFIG_ALTREF2
#if CONFIG_VAR_REFS
// Test need to explicitly code (BWD,ALT2) vs (ALT) branch node in tree
if (BWD_OR_ALT2(cm) && ALTREF_IS_VALID(cm)) {
#endif // CONFIG_VAR_REFS
const int bit_bwd = mbmi->ref_frame[1] == ALTREF_FRAME;
WRITE_REF_BIT(bit_bwd, comp_bwdref_p);
if (!bit_bwd) {
#if CONFIG_VAR_REFS
// Test need to explicitly code (BWD,ALT2) vs (ALT) branch node in
// tree
if (BWD_AND_ALT2(cm))
#endif // CONFIG_VAR_REFS
WRITE_REF_BIT(mbmi->ref_frame[1] == ALTREF2_FRAME, comp_bwdref_p1);
}
#if CONFIG_VAR_REFS
}
#endif // CONFIG_VAR_REFS
#else // !CONFIG_ALTREF2
#if CONFIG_VAR_REFS
// Test need to explicitly code (BWD) vs (ALT) branch node in tree
if (BWD_AND_ALT(cm)) {
......@@ -1163,22 +1186,50 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd,
}
#endif // CONFIG_VAR_REFS
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
const int bit = mbmi->ref_frame[0] == GOLDEN_FRAME;
WRITE_REF_BIT(bit, comp_ref_p);
#endif // CONFIG_EXT_REFS
} else {
#if CONFIG_EXT_REFS
const int bit0 = (mbmi->ref_frame[0] == ALTREF_FRAME ||
mbmi->ref_frame[0] == BWDREF_FRAME);
const int bit0 = (mbmi->ref_frame[0] <= ALTREF_FRAME &&
mbmi->ref_frame[0] >= BWDREF_FRAME);
#if CONFIG_VAR_REFS
#if CONFIG_ALTREF2
// Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT2,ALT) branch node
// in tree
if ((L_OR_L2(cm) || L3_OR_G(cm)) &&
(BWD_OR_ALT2(cm) || ALTREF_IS_VALID(cm)))
#else // !CONFIG_ALTREF2
// Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT) branch node in
// tree
if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm))
#endif // CONFIG_ALTREF2
#endif // CONFIG_VAR_REFS
WRITE_REF_BIT(bit0, single_ref_p1);
if (bit0) {
#if CONFIG_ALTREF2
#if CONFIG_VAR_REFS
// Test need to explicitly code (BWD,ALT2) vs (ALT) branch node in tree
if (BWD_OR_ALT2(cm) && ALTREF_IS_VALID(cm)) {
#endif // CONFIG_VAR_REFS
const int bit1 = mbmi->ref_frame[0] == ALTREF_FRAME;
WRITE_REF_BIT(bit1, single_ref_p2);
if (!bit1) {
#if CONFIG_VAR_REFS
// Test need to explicitly code (BWD) vs (ALT2) branch node in tree
if (BWD_AND_ALT2(cm))
#endif // CONFIG_VAR_REFS
WRITE_REF_BIT(mbmi->ref_frame[0] == ALTREF2_FRAME, single_ref_p6);
}
#if CONFIG_VAR_REFS
}
#endif // CONFIG_VAR_REFS
#else // !CONFIG_ALTREF2
#if CONFIG_VAR_REFS
// Test need to explicitly code (BWD) vs (ALT) branch node in tree
if (BWD_AND_ALT(cm)) {
......@@ -1188,6 +1239,7 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd,
#if CONFIG_VAR_REFS
}
#endif // CONFIG_VAR_REFS
#endif // CONFIG_ALTREF2
} else {
const int bit2 = (mbmi->ref_frame[0] == LAST3_FRAME ||
mbmi->ref_frame[0] == GOLDEN_FRAME);
......@@ -3638,13 +3690,19 @@ static int get_refresh_mask(AV1_COMP *cpi) {
// LAST3_FRAME.
refresh_mask |=
(cpi->refresh_last_frame << cpi->lst_fb_idxes[LAST_REF_FRAMES - 1]);
#if CONFIG_ALTREF2
refresh_mask |= (cpi->refresh_bwd_ref_frame << cpi->bwd_fb_idx);
refresh_mask |= (cpi->refresh_alt2_ref_frame << cpi->alt2_fb_idx);
#else // !CONFIG_ALTREF2
if (cpi->rc.is_bwd_ref_frame && cpi->num_extra_arfs) {
// We have swapped the virtual indices
refresh_mask |= (cpi->refresh_bwd_ref_frame << cpi->arf_map[0]);
} else {
refresh_mask |= (cpi->refresh_bwd_ref_frame << cpi->bwd_fb_idx);
}
#else
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
refresh_mask |= (cpi->refresh_last_frame << cpi->lst_fb_idx);
#endif // CONFIG_EXT_REFS
......@@ -3662,9 +3720,13 @@ static int get_refresh_mask(AV1_COMP *cpi) {
return refresh_mask | (cpi->refresh_golden_frame << cpi->alt_fb_idx);
} else {
#if CONFIG_EXT_REFS
#if CONFIG_ALTREF2
const int arf_idx = cpi->alt_fb_idx;
#else // !CONFIG_ALTREF2
const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
int arf_idx = cpi->arf_map[gf_group->arf_update_idx[gf_group->index]];
#else
const int arf_idx = cpi->arf_map[gf_group->arf_update_idx[gf_group->index]];
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
int arf_idx = cpi->alt_fb_idx;
if ((cpi->oxcf.pass == 2) && cpi->multi_arf_allowed) {
const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
......
......@@ -1491,6 +1491,9 @@ static void rd_pick_sb_modes(const AV1_COMP *const cpi, TileDataEnc *tile_data,
if ((rd_cost->rate != INT_MAX) && (aq_mode == COMPLEXITY_AQ) &&
(bsize >= BLOCK_16X16) &&
(cm->frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame ||
#if CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt2_ref_frame ||
#endif // CONFIG_EXT_REFS && CONFIG_ALTREF2
(cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref))) {
av1_caq_select_segment(cpi, x, bsize, mi_row, mi_col, rd_cost->rate);
}
......@@ -1664,6 +1667,11 @@ static void update_stats(const AV1_COMMON *const cm, ThreadData *td, int mi_row,
counts->comp_bwdref[av1_get_pred_context_comp_bwdref_p(cm, xd)][0]
[ref1 == ALTREF_FRAME]++;
#if CONFIG_ALTREF2
if (ref1 != ALTREF_FRAME)
counts->comp_bwdref[av1_get_pred_context_comp_bwdref_p1(cm, xd)]
[1][ref1 == ALTREF2_FRAME]++;
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
counts->comp_ref[av1_get_pred_context_comp_ref_p(cm, xd)][0]
[ref0 == GOLDEN_FRAME]++;
......@@ -1673,12 +1681,18 @@ static void update_stats(const AV1_COMMON *const cm, ThreadData *td, int mi_row,
#endif // CONFIG_EXT_COMP_REFS
} else {
#if CONFIG_EXT_REFS
const int bit = (ref0 == ALTREF_FRAME || ref0 == BWDREF_FRAME);
const int bit = (ref0 >= BWDREF_FRAME);
counts->single_ref[av1_get_pred_context_single_ref_p1(xd)][0][bit]++;
if (bit) {
assert(ref0 <= ALTREF_FRAME);
counts->single_ref[av1_get_pred_context_single_ref_p2(xd)][1]
[ref0 != BWDREF_FRAME]++;
[ref0 == ALTREF_FRAME]++;
#if CONFIG_ALTREF2
if (ref0 != ALTREF_FRAME)
counts->single_ref[av1_get_pred_context_single_ref_p6(xd)][5]
[ref0 == ALTREF2_FRAME]++;
#endif // CONFIG_ALTREF2
} else {
const int bit1 = !(ref0 == LAST2_FRAME || ref0 == LAST_FRAME);
counts
......@@ -4671,6 +4685,9 @@ static int check_dual_ref_flags(AV1_COMP *cpi) {
#if CONFIG_EXT_REFS
!!(ref_flags & AOM_LAST2_FLAG) + !!(ref_flags & AOM_LAST3_FLAG) +
!!(ref_flags & AOM_BWD_FLAG) +
#if CONFIG_ALTREF2
!!(ref_flags & AOM_ALT2_FLAG) +
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
!!(ref_flags & AOM_ALT_FLAG)) >= 2;
}
......@@ -4702,7 +4719,11 @@ static MV_REFERENCE_FRAME get_frame_type(const AV1_COMP *cpi) {
else if (cpi->rc.is_src_frame_alt_ref && cpi->refresh_golden_frame)
#endif
return ALTREF_FRAME;
else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)
else if (cpi->refresh_golden_frame ||
#if CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt2_ref_frame ||
#endif // CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt_ref_frame)
return GOLDEN_FRAME;
else
// TODO(zoeliu): To investigate whether a frame_type other than
......@@ -5389,8 +5410,13 @@ void av1_encode_frame(AV1_COMP *cpi) {
cm->comp_fwd_ref[2] = LAST3_FRAME;
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;
#else
#endif // CONFIG_ALTREF2
#else // CONFIG_EXT_REFS
cm->comp_fixed_ref = ALTREF_FRAME;
cm->comp_var_ref[0] = LAST_FRAME;
cm->comp_var_ref[1] = GOLDEN_FRAME;
......
This diff is collapsed.
......@@ -107,8 +107,11 @@ typedef enum {
FRAMEFLAGS_GOLDEN = 1 << 1,
#if CONFIG_EXT_REFS
FRAMEFLAGS_BWDREF = 1 << 2,
#if CONFIG_ALTREF2
// TODO(zoeliu): To determine whether a frame flag is needed for ALTREF2_FRAME
#endif // CONFIG_ALTREF2
FRAMEFLAGS_ALTREF = 1 << 3,
#else
#else // !CONFIG_EXT_REFS
FRAMEFLAGS_ALTREF = 1 << 2,
#endif // CONFIG_EXT_REFS
} FRAMETYPE_FLAGS;
......@@ -407,8 +410,11 @@ typedef struct AV1_COMP {
#endif // CONFIG_EXT_REFS
int gld_fb_idx;
#if CONFIG_EXT_REFS
int bwd_fb_idx; // BWD_REF_FRAME
#endif // CONFIG_EXT_REFS
int bwd_fb_idx; // BWDREF_FRAME
#if CONFIG_ALTREF2
int alt2_fb_idx; // ALTREF2_FRAME
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
int alt_fb_idx;
int last_show_frame_buf_idx; // last show frame buffer index
......@@ -417,6 +423,9 @@ typedef struct AV1_COMP {
int refresh_golden_frame;
#if CONFIG_EXT_REFS
int refresh_bwd_ref_frame;
#if CONFIG_ALTREF2
int refresh_alt2_ref_frame;
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
int refresh_alt_ref_frame;
......@@ -667,6 +676,10 @@ static INLINE int get_ref_frame_map_idx(const AV1_COMP *cpi,
#if CONFIG_EXT_REFS
else if (ref_frame == BWDREF_FRAME)
return cpi->bwd_fb_idx;
#if CONFIG_ALTREF2
else if (ref_frame == ALTREF2_FRAME)
return cpi->alt2_fb_idx;
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
else
return cpi->alt_fb_idx;
......
This diff is collapsed.
......@@ -101,8 +101,13 @@ typedef enum {
LAST_BIPRED_UPDATE = 6, // Last Bi-predictive Frame
BIPRED_UPDATE = 7, // Bi-predictive Frame, but not the last one
INTNL_OVERLAY_UPDATE = 8, // Internal Overlay Frame
#if CONFIG_ALTREF2
INTNL_ARF_UPDATE = 9, // Internal Altref Frame (candidate for ALTREF2)
FRAME_UPDATE_TYPES = 10
#else // !CONFIG_ALTREF2
FRAME_UPDATE_TYPES = 9
#else
#endif // CONFIG_ALTREF2
#else // !CONFIG_EXT_REFS
FRAME_UPDATE_TYPES = 5
#endif // CONFIG_EXT_REFS
} FRAME_UPDATE_TYPE;
......
......@@ -579,8 +579,11 @@ static int calc_active_worst_quality_one_pass_vbr(const AV1_COMP *cpi) {
active_worst_quality =
curr_frame == 0 ? rc->worst_quality : rc->last_q[KEY_FRAME] * 2;
} else {
if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
if (!rc->is_src_frame_alt_ref && (cpi->refresh_golden_frame ||
#if CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt2_ref_frame ||
#endif // CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt_ref_frame)) {
active_worst_quality = curr_frame == 1 ? rc->last_q[KEY_FRAME] * 5 / 4
: rc->last_q[INTER_FRAME];
} else {
......@@ -1005,8 +1008,11 @@ static int rc_pick_q_and_bounds_two_pass(const AV1_COMP *cpi, int *bottom_index,
active_best_quality +=
av1_compute_qdelta(rc, q_val, q_val * q_adj_factor, cm->bit_depth);
}
} else if (!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
} else if (!rc->is_src_frame_alt_ref && (cpi->refresh_golden_frame ||
#if CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt2_ref_frame ||
#endif // CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt_ref_frame)) {
// Use the lower of active_worst_quality and recent
// average Q as basis for GF/ARF best Q limit unless last frame was
// a key frame.
......@@ -1026,7 +1032,11 @@ static int rc_pick_q_and_bounds_two_pass(const AV1_COMP *cpi, int *bottom_index,
active_best_quality = active_best_quality * 15 / 16;
} else if (oxcf->rc_mode == AOM_Q) {
#if CONFIG_EXT_REFS && CONFIG_ALTREF2
if (!cpi->refresh_alt_ref_frame && !cpi->refresh_alt2_ref_frame) {
#else
if (!cpi->refresh_alt_ref_frame) {
#endif // CONFIG_EXT_REFS && CONFIG_ALTREF2
active_best_quality = cq_level;
} else {
active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth);
......@@ -1058,8 +1068,11 @@ static int rc_pick_q_and_bounds_two_pass(const AV1_COMP *cpi, int *bottom_index,
if ((cpi->oxcf.rc_mode != AOM_Q) &&
(cpi->twopass.gf_zeromotion_pct < VLOW_MOTION_THRESHOLD)) {
if (frame_is_intra_only(cm) ||
(!rc->is_src_frame_alt_ref &&
(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) {
(!rc->is_src_frame_alt_ref && (cpi->refresh_golden_frame ||
#if CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt2_ref_frame ||
#endif // CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt_ref_frame))) {
active_best_quality -=
(cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast);
active_worst_quality += (cpi->twopass.extend_maxq / 2);
......@@ -1194,7 +1207,7 @@ static void update_golden_frame_stats(AV1_COMP *cpi) {
// only the virtual indices for the reference frame will be
// updated and cpi->refresh_golden_frame will still be zero.
if (cpi->refresh_golden_frame || rc->is_src_frame_alt_ref) {
#else
#else // !CONFIG_EXT_REFS
// Update the Golden frame usage counts.
if (cpi->refresh_golden_frame) {
#endif // CONFIG_EXT_REFS
......@@ -1219,7 +1232,11 @@ static void update_golden_frame_stats(AV1_COMP *cpi) {
// Decrement count down till next gf
if (rc->frames_till_gf_update_due > 0) rc->frames_till_gf_update_due--;
#if CONFIG_EXT_REFS && CONFIG_ALTREF2
} else if (!cpi->refresh_alt_ref_frame && !cpi->refresh_alt2_ref_frame) {
#else
} else if (!cpi->refresh_alt_ref_frame) {
#endif // CONFIG_EXT_REFS && CONFIG_ALTREF2
// Decrement count down till next gf
if (rc->frames_till_gf_update_due > 0) rc->frames_till_gf_update_due--;
......@@ -1249,7 +1266,11 @@ void av1_rc_postencode_update(AV1_COMP *cpi, uint64_t bytes_used) {
ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2);
} else {
if (!rc->is_src_frame_alt_ref &&
!(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
!(cpi->refresh_golden_frame ||
#if CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt2_ref_frame ||
#endif // CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt_ref_frame)) {
rc->last_q[INTER_FRAME] = qindex;
rc->avg_frame_qindex[INTER_FRAME] =
ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2);
......@@ -1271,6 +1292,9 @@ void av1_rc_postencode_update(AV1_COMP *cpi, uint64_t bytes_used) {
if ((qindex < rc->last_boosted_qindex) || (cm->frame_type == KEY_FRAME) ||
(!rc->constrained_gf_group &&
(cpi->refresh_alt_ref_frame ||
#if CONFIG_EXT_REFS && CONFIG_ALTREF2
cpi->refresh_alt2_ref_frame ||
#endif // CONFIG_EXT_REFS && CONFIG_ALTREF2
(cpi->refresh_golden_frame && !rc->is_src_frame_alt_ref)))) {
rc->last_boosted_qindex = qindex;
}
......@@ -1294,6 +1318,8 @@ void av1_rc_postencode_update(AV1_COMP *cpi, uint64_t bytes_used) {
// Actual bits spent
rc->total_actual_bits += rc->projected_frame_size;
#if CONFIG_EXT_REFS
// TODO(zoeliu): To investigate whether we should treat BWDREF_FRAME
// differently here for rc->avg_frame_bandwidth.
rc->total_target_bits +=
(cm->show_frame || rc->is_bwd_ref_frame) ? rc->avg_frame_bandwidth : 0;
#else
......@@ -1313,6 +1339,8 @@ void av1_rc_postencode_update(AV1_COMP *cpi, uint64_t bytes_used) {
if (cm->frame_type == KEY_FRAME) rc->frames_since_key = 0;
#if CONFIG_EXT_REFS
// TODO(zoeliu): To investigate whether we should treat BWDREF_FRAME
// differently here for rc->avg_frame_bandwidth.
if (cm->show_frame || rc->is_bwd_ref_frame) {
#else
if (cm->show_frame) {
......
......@@ -311,7 +311,11 @@ static const int rd_frame_type_factor[FRAME_UPDATE_TYPES] = {
// TODO(weitinglin): We should investigate if the values should be the same
// as the value used by OVERLAY frame
,
144
144 // INTNL_OVERLAY_UPDATE
#if CONFIG_ALTREF2
,
128 // INTNL_ARF_UPDATE
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
};
......@@ -959,6 +963,9 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_NEARESTL2] = 300;
rd->thresh_mult[THR_NEARESTL3] = 300;
rd->thresh_mult[THR_NEARESTB] = 300;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_NEARESTA2] = 300;
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_NEARESTA] = 300;
rd->thresh_mult[THR_NEARESTG] = 300;
......@@ -968,6 +975,9 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_NEARESTL2] = 0;
rd->thresh_mult[THR_NEARESTL3] = 0;
rd->thresh_mult[THR_NEARESTB] = 0;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_NEARESTA2] = 0;
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_NEARESTA] = 0;
rd->thresh_mult[THR_NEARESTG] = 0;
......@@ -980,6 +990,9 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_NEWL2] += 1000;
rd->thresh_mult[THR_NEWL3] += 1000;
rd->thresh_mult[THR_NEWB] += 1000;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_NEWA2] = 1000;
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_NEWA] += 1000;
rd->thresh_mult[THR_NEWG] += 1000;
......@@ -989,6 +1002,9 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_NEARL2] += 1000;
rd->thresh_mult[THR_NEARL3] += 1000;
rd->thresh_mult[THR_NEARB] += 1000;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_NEARA2] = 1000;
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_NEARA] += 1000;
rd->thresh_mult[THR_NEARG] += 1000;
......@@ -998,6 +1014,9 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_ZEROL2] += 2000;
rd->thresh_mult[THR_ZEROL3] += 2000;
rd->thresh_mult[THR_ZEROB] += 2000;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_ZEROA2] = 2000;
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_ZEROG] += 2000;
rd->thresh_mult[THR_ZEROA] += 2000;
......@@ -1065,6 +1084,12 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_COMP_NEAREST_NEARESTL2B] += 1000;
rd->thresh_mult[THR_COMP_NEAREST_NEARESTL3B] += 1000;
rd->thresh_mult[THR_COMP_NEAREST_NEARESTGB] += 1000;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_COMP_NEAREST_NEARESTLA2] += 1000;
rd->thresh_mult[THR_COMP_NEAREST_NEARESTL2A2] += 1000;
rd->thresh_mult[THR_COMP_NEAREST_NEARESTL3A2] += 1000;
rd->thresh_mult[THR_COMP_NEAREST_NEARESTGA2] += 1000;
#endif // CONFIG_ALTREF2
#if CONFIG_EXT_COMP_REFS
rd->thresh_mult[THR_COMP_NEAREST_NEARESTLL2] += 1000;
......@@ -1087,6 +1112,13 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_COMP_NEARESTL2B] += 1000;
rd->thresh_mult[THR_COMP_NEARESTL3B] += 1000;
rd->thresh_mult[THR_COMP_NEARESTGB] += 1000;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_COMP_NEARESTLA2] += 1000;
rd->thresh_mult[THR_COMP_NEARESTL2A2] += 1000;
rd->thresh_mult[THR_COMP_NEARESTL3A2] += 1000;
rd->thresh_mult[THR_COMP_NEARESTGA2] += 1000;
#endif // CONFIG_ALTREF2
#if CONFIG_EXT_COMP_REFS
rd->thresh_mult[THR_COMP_NEARESTLL2] += 1000;
rd->thresh_mult[THR_COMP_NEARESTLL3] += 1000;
......@@ -1166,6 +1198,40 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_COMP_NEW_NEWGB] += 2000;
rd->thresh_mult[THR_COMP_ZERO_ZEROGB] += 2500;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_COMP_NEAR_NEARLA2] += 1200;
rd->thresh_mult[THR_COMP_NEAREST_NEWLA2] += 1500;
rd->thresh_mult[THR_COMP_NEW_NEARESTLA2] += 1500;
rd->thresh_mult[THR_COMP_NEAR_NEWLA2] += 1700;
rd->thresh_mult[THR_COMP_NEW_NEARLA2] += 1700;
rd->thresh_mult[THR_COMP_NEW_NEWLA2] += 2000;
rd->thresh_mult[THR_COMP_ZERO_ZEROLA2] += 2500;
rd->thresh_mult[THR_COMP_NEAR_NEARL2A2] += 1200;
rd->thresh_mult[THR_COMP_NEAREST_NEWL2A2] += 1500;
rd->thresh_mult[THR_COMP_NEW_NEARESTL2A2] += 1500;
rd->thresh_mult[THR_COMP_NEAR_NEWL2A2] += 1700;
rd->thresh_mult[THR_COMP_NEW_NEARL2A2] += 1700;
rd->thresh_mult[THR_COMP_NEW_NEWL2A2] += 2000;
rd->thresh_mult[THR_COMP_ZERO_ZEROL2A2] += 2500;
rd->thresh_mult[THR_COMP_NEAR_NEARL3A2] += 1200;
rd->thresh_mult[THR_COMP_NEAREST_NEWL3A2] += 1500;
rd->thresh_mult[THR_COMP_NEW_NEARESTL3A2] += 1500;
rd->thresh_mult[THR_COMP_NEAR_NEWL3A2] += 1700;
rd->thresh_mult[THR_COMP_NEW_NEARL3A2] += 1700;
rd->thresh_mult[THR_COMP_NEW_NEWL3A2] += 2000;
rd->thresh_mult[THR_COMP_ZERO_ZEROL3A2] += 2500;
rd->thresh_mult[THR_COMP_NEAR_NEARGA2] += 1200;
rd->thresh_mult[THR_COMP_NEAREST_NEWGA2] += 1500;
rd->thresh_mult[THR_COMP_NEW_NEARESTGA2] += 1500;
rd->thresh_mult[THR_COMP_NEAR_NEWGA2] += 1700;
rd->thresh_mult[THR_COMP_NEW_NEARGA2] += 1700;
rd->thresh_mult[THR_COMP_NEW_NEWGA2] += 2000;
rd->thresh_mult[THR_COMP_ZERO_ZEROGA2] += 2500;
#endif // CONFIG_ALTREF2
#if CONFIG_EXT_COMP_REFS
rd->thresh_mult[THR_COMP_NEAR_NEARLL2] += 1200;
rd->thresh_mult[THR_COMP_NEAREST_NEWLL2] += 1500;
......@@ -1224,6 +1290,17 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_COMP_NEARGB] += 1500;
rd->thresh_mult[THR_COMP_NEWGB] += 2000;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_COMP_NEARLA2] += 1500;
rd->thresh_mult[THR_COMP_NEWLA2] += 2000;
rd->thresh_mult[THR_COMP_NEARL2A2] += 1500;
rd->thresh_mult[THR_COMP_NEWL2A2] += 2000;
rd->thresh_mult[THR_COMP_NEARL3A2] += 1500;
rd->thresh_mult[THR_COMP_NEWL3A2] += 2000;
rd->thresh_mult[THR_COMP_NEARGA2] += 1500;
rd->thresh_mult[THR_COMP_NEWGA2] += 2000;
#endif // CONFIG_ALTREF2
#if CONFIG_EXT_COMP_REFS
rd->thresh_mult[THR_COMP_NEARLL2] += 1500;
rd->thresh_mult[THR_COMP_NEWLL2] += 2000;
......@@ -1249,6 +1326,13 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_COMP_ZEROL3B] += 2500;
rd->thresh_mult[THR_COMP_ZEROGB] += 2500;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_COMP_ZEROLA2] += 2500;
rd->thresh_mult[THR_COMP_ZEROL2A2] += 2500;
rd->thresh_mult[THR_COMP_ZEROL3A2] += 2500;
rd->thresh_mult[THR_COMP_ZEROGA2] += 2500;
#endif // CONFIG_ALTREF2
#if CONFIG_EXT_COMP_REFS
rd->thresh_mult[THR_COMP_ZEROLL2] += 2500;
rd->thresh_mult[THR_COMP_ZEROLL3] += 2500;
......@@ -1296,6 +1380,13 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_COMP_INTERINTRA_NEARESTB] += 1500;
rd->thresh_mult[THR_COMP_INTERINTRA_NEARB] += 1500;
rd->thresh_mult[THR_COMP_INTERINTRA_NEWB] += 2000;
#if CONFIG_ALTREF2
rd->thresh_mult[THR_COMP_INTERINTRA_ZEROA2] += 1500;
rd->thresh_mult[THR_COMP_INTERINTRA_NEARESTA2] += 1500;
rd->thresh_mult[THR_COMP_INTERINTRA_NEARA2] += 1500;
rd->thresh_mult[THR_COMP_INTERINTRA_NEWA2] += 2000;
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_INTERINTRA_ZEROA] += 1500;
......@@ -1312,18 +1403,27 @@ void av1_set_rd_speed_thresholds_sub8x8(AV1_COMP *cpi) {
2500,
2500,
2500,
#if CONFIG_ALTREF2
2500,
#endif // CONFIG_ALTREF2
2500,
2500,
4500,
4500,
4500,
4500,
4500,
4500,
4500,
4500,
#if CONFIG_ALTREF2
4500,
4500,
4500,
4500,
#endif // CONFIG_ALTREF2
2500
#else
#else // !CONFIG_EXT_REFS
2500,
2500,
2500,
......
......@@ -45,12 +45,6 @@ extern "C" {
#define INVALID_MV 0x80008000
#if CONFIG_EXT_REFS
#define MAX_REFS 15
#else
#define MAX_REFS 6
#endif // CONFIG_EXT_REFS
#define RD_THRESH_MAX_FACT 64
#define RD_THRESH_INC 1
......@@ -62,6 +56,9 @@ typedef enum {
THR_NEARESTL2,
THR_NEARESTL3,
THR_NEARESTB,
#if CONFIG_ALTREF2
THR_NEARESTA2,
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
THR_NEARESTA,
THR_NEARESTG,
......@@ -73,6 +70,9 @@ typedef enum {
THR_NEWL2,
THR_NEWL3,
THR_NEWB,
#if CONFIG_ALTREF2
THR_NEWA2,
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
THR_NEWA,
THR_NEWG,
......@@ -82,6 +82,9 @@ typedef enum {
THR_NEARL2,
THR_NEARL3,
THR_NEARB,
#if CONFIG_ALTREF2
THR_NEARA2,
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
THR_NEARA,
THR_NEARG,
......@@ -91,9 +94,12 @@ typedef enum {
THR_ZEROL2,
THR_ZEROL3,
THR_ZEROB,
#if CONFIG_ALTREF2
THR_ZEROA2,
#endif // CONFIG_ALTREF2
#endif // CONFIG_EXT_REFS
THR_ZEROG,
THR_ZEROA,
THR_ZEROG,
#if CONFIG_EXT_INTER
......@@ -156,6 +162,12 @@ typedef enum {
THR_COMP_NEAREST_NEARESTL2B,
THR_COMP_NEAREST_NEARESTL3B,
THR_COMP_NEAREST_NEARESTGB,
#if CONFIG_ALTREF2
THR_COMP_NEAREST_NEARESTLA2,
THR_COMP_NEAREST_NEARESTL2A2,
THR_COMP_NEAREST_NEARESTL3A2,
THR_COMP_NEAREST_NEARESTGA2,
#endif // CONFIG_ALTREF2
#if CONFIG_EXT_COMP_REFS
THR_COMP_NEAREST_NEARESTLL2,
THR_COMP_NEAREST_NEARESTLL3,
......@@ -177,6 +189,12 @@ typedef enum {
THR_COMP_NEARESTL2B,
THR_COMP_NEARESTL3B,
THR_COMP_NEARESTGB,
#if CONFIG_ALTREF2
THR_COMP_NEARESTLA2,
THR_COMP_NEARESTL2A2,
THR_COMP_NEARESTL3A2,
THR_COMP_NEARESTGA2,
#endif // CONFIG_ALTREF2
#if CONFIG_EXT_COMP_REFS
THR_COMP_NEARESTLL2,
THR_COMP_NEARESTLL3,
......@@ -266,6 +284,40 @@ typedef enum {
THR_COMP_NEW_NEWGB,
THR_COMP_ZERO_ZEROGB,
#if CONFIG_ALTREF2
THR_COMP_NEAR_NEARLA2,
THR_COMP_NEW_NEARESTLA2,
THR_COMP_NEAREST_NEWLA2,
THR_COMP_NEW_NEARLA2,
THR_COMP_NEAR_NEWLA2,
THR_COMP_NEW_NEWLA2,
THR_COMP_ZERO_ZEROLA2,
THR_COMP_NEAR_NEARL2A2,
THR_COMP_NEW_NEARESTL2A2,
THR_COMP_NEAREST_NEWL2A2,
THR_COMP_NEW_NEARL2A2,
THR_COMP_NEAR_NEWL2A2,
THR_COMP_NEW_NEWL2A2,
THR_COMP_ZERO_ZEROL2A2,
THR_COMP_NEAR_NEARL3A2,
THR_COMP_NEW_NEARESTL3A2,
THR_COMP_NEAREST_NEWL3A2,
THR_COMP_NEW_NEARL3A2,
THR_COMP_NEAR_NEWL3A2,
THR_COMP_NEW_NEWL3A2,
THR_COMP_ZERO_ZEROL3A2,
THR_COMP_NEAR_NEARGA2,
THR_COMP_NEW_NEARESTGA2,
THR_COMP_NEAREST_NEWGA2,
THR_COMP_NEW_NEARGA2,
THR_COMP_NEAR_NEWGA2,
THR_COMP_NEW_NEWGA2,
THR_COMP_ZERO_ZEROGA2,
#endif // CONFIG_ALTREF2
#if CONFIG_EXT_COMP_REFS
THR_COMP_NEAR_NEARLL2,