Commit 9c1e2f92 authored by Zoe Liu's avatar Zoe Liu
Browse files

Add the use of new reference frames at encoder in EXT_REFS

In the experiment of EXT_REFS, add the use of the 3 extra reference
frames, including the 2 forward reference frames LAST2 and LAST3, and
the one backward reference frame BWDREF, for the encoding.

For lowres, EXT_REFS achieves following bitrate saving on overall PSNR
compared against baseline:
Avg: -4.581  BDRate: -4.358

Change-Id: Ib15b65681c39892ddfce5e4107598c0a22317ccd
parent da35bc93
...@@ -903,11 +903,16 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, ...@@ -903,11 +903,16 @@ static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
// TODO(jzern) the checks related to cpi's validity should be treated as a // TODO(jzern) the checks related to cpi's validity should be treated as a
// failure condition, encoder setup is done fully in init() currently. // failure condition, encoder setup is done fully in init() currently.
if (res == AOM_CODEC_OK && cpi != NULL) { if (res == AOM_CODEC_OK && cpi != NULL) {
#if CONFIG_EXT_REFS
data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) *
ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) * get_image_bps(img);
#else
// There's no codec control for multiple alt-refs so check the encoder // There's no codec control for multiple alt-refs so check the encoder
// instance for its status to determine the compressed data size. // instance for its status to determine the compressed data size.
data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) * data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) *
ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) * get_image_bps(img) / 8 * ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) * get_image_bps(img) / 8 *
(cpi->multi_arf_allowed ? 8 : 2); (cpi->multi_arf_allowed ? 8 : 2);
#endif // CONFIG_EXT_REFS
if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize; if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize;
if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) { if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) {
ctx->cx_data_sz = data_sz; ctx->cx_data_sz = data_sz;
......
...@@ -508,12 +508,9 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd, ...@@ -508,12 +508,9 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
if (mode == COMPOUND_REFERENCE) { if (mode == COMPOUND_REFERENCE) {
#if CONFIG_EXT_REFS #if CONFIG_EXT_REFS
const int idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]]; const int idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]];
// Read forward references.
const int ctx_fwd = av1_get_pred_context_comp_fwdref_p(cm, xd); const int ctx_fwd = av1_get_pred_context_comp_fwdref_p(cm, xd);
const int bit_fwd = aom_read(r, fc->comp_fwdref_prob[ctx_fwd][0]); const int bit_fwd = aom_read(r, fc->comp_fwdref_prob[ctx_fwd][0]);
const int ctx_bwd = av1_get_pred_context_comp_bwdref_p(cm, xd);
const int bit_bwd = aom_read(r, fc->comp_bwdref_prob[ctx_bwd][0]);
// Decode forward references.
if (counts) ++counts->comp_fwdref[ctx_fwd][0][bit_fwd]; if (counts) ++counts->comp_fwdref[ctx_fwd][0][bit_fwd];
if (!bit_fwd) { if (!bit_fwd) {
const int ctx_fwd1 = av1_get_pred_context_comp_fwdref_p1(cm, xd); const int ctx_fwd1 = av1_get_pred_context_comp_fwdref_p1(cm, xd);
...@@ -526,15 +523,17 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd, ...@@ -526,15 +523,17 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
if (counts) ++counts->comp_fwdref[ctx_fwd2][2][bit_fwd2]; if (counts) ++counts->comp_fwdref[ctx_fwd2][2][bit_fwd2];
ref_frame[!idx] = cm->comp_fwd_ref[bit_fwd2 ? 3 : 2]; ref_frame[!idx] = cm->comp_fwd_ref[bit_fwd2 ? 3 : 2];
} }
// Read backward references.
// Decode backward references. {
if (counts) ++counts->comp_bwdref[ctx_bwd][0][bit_bwd]; const int ctx_bwd = av1_get_pred_context_comp_bwdref_p(cm, xd);
ref_frame[idx] = cm->comp_bwd_ref[bit_bwd]; const int bit_bwd = aom_read(r, fc->comp_bwdref_prob[ctx_bwd][0]);
if (counts) ++counts->comp_bwdref[ctx_bwd][0][bit_bwd];
ref_frame[idx] = cm->comp_bwd_ref[bit_bwd];
}
#else #else
const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
const int ctx = av1_get_pred_context_comp_ref_p(cm, xd); const int ctx = av1_get_pred_context_comp_ref_p(cm, xd);
const int bit = aom_read(r, fc->comp_ref_prob[ctx]); const int bit = aom_read(r, fc->comp_ref_prob[ctx]);
if (counts) ++counts->comp_ref[ctx][bit]; if (counts) ++counts->comp_ref[ctx][bit];
ref_frame[idx] = cm->comp_fixed_ref; ref_frame[idx] = cm->comp_fixed_ref;
ref_frame[!idx] = cm->comp_var_ref[bit]; ref_frame[!idx] = cm->comp_var_ref[bit];
...@@ -553,16 +552,16 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd, ...@@ -553,16 +552,16 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd,
const int ctx2 = av1_get_pred_context_single_ref_p3(xd); const int ctx2 = av1_get_pred_context_single_ref_p3(xd);
const int bit2 = aom_read(r, fc->single_ref_prob[ctx2][2]); const int bit2 = aom_read(r, fc->single_ref_prob[ctx2][2]);
if (counts) ++counts->single_ref[ctx2][2][bit2]; if (counts) ++counts->single_ref[ctx2][2][bit2];
if (bit2) { if (!bit2) {
const int ctx4 = av1_get_pred_context_single_ref_p5(xd);
const int bit4 = aom_read(r, fc->single_ref_prob[ctx4][4]);
if (counts) ++counts->single_ref[ctx4][4][bit4];
ref_frame[0] = bit4 ? GOLDEN_FRAME : LAST3_FRAME;
} else {
const int ctx3 = av1_get_pred_context_single_ref_p4(xd); const int ctx3 = av1_get_pred_context_single_ref_p4(xd);
const int bit3 = aom_read(r, fc->single_ref_prob[ctx3][3]); const int bit3 = aom_read(r, fc->single_ref_prob[ctx3][3]);
if (counts) ++counts->single_ref[ctx3][3][bit3]; if (counts) ++counts->single_ref[ctx3][3][bit3];
ref_frame[0] = bit3 ? LAST2_FRAME : LAST_FRAME; ref_frame[0] = bit3 ? LAST2_FRAME : LAST_FRAME;
} else {
const int ctx4 = av1_get_pred_context_single_ref_p5(xd);
const int bit4 = aom_read(r, fc->single_ref_prob[ctx4][4]);
if (counts) ++counts->single_ref[ctx4][4][bit4];
ref_frame[0] = bit4 ? GOLDEN_FRAME : LAST3_FRAME;
} }
} }
#else #else
......
...@@ -414,6 +414,8 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -414,6 +414,8 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd,
const int bit_fwd = (mbmi->ref_frame[0] == GOLDEN_FRAME || const int bit_fwd = (mbmi->ref_frame[0] == GOLDEN_FRAME ||
mbmi->ref_frame[0] == LAST3_FRAME); mbmi->ref_frame[0] == LAST3_FRAME);
const int bit_bwd = mbmi->ref_frame[1] == ALTREF_FRAME; const int bit_bwd = mbmi->ref_frame[1] == ALTREF_FRAME;
// Write forward references.
aom_write(w, bit_fwd, av1_get_pred_prob_comp_fwdref_p(cm, xd)); aom_write(w, bit_fwd, av1_get_pred_prob_comp_fwdref_p(cm, xd));
if (!bit_fwd) { if (!bit_fwd) {
const int bit1_fwd = mbmi->ref_frame[0] == LAST_FRAME; const int bit1_fwd = mbmi->ref_frame[0] == LAST_FRAME;
...@@ -422,6 +424,7 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -422,6 +424,7 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd,
const int bit2_fwd = mbmi->ref_frame[0] == GOLDEN_FRAME; const int bit2_fwd = mbmi->ref_frame[0] == GOLDEN_FRAME;
aom_write(w, bit2_fwd, av1_get_pred_prob_comp_fwdref_p2(cm, xd)); aom_write(w, bit2_fwd, av1_get_pred_prob_comp_fwdref_p2(cm, xd));
} }
// Write forward references.
aom_write(w, bit_bwd, av1_get_pred_prob_comp_bwdref_p(cm, xd)); aom_write(w, bit_bwd, av1_get_pred_prob_comp_bwdref_p(cm, xd));
#else #else
aom_write(w, mbmi->ref_frame[0] == GOLDEN_FRAME, aom_write(w, mbmi->ref_frame[0] == GOLDEN_FRAME,
...@@ -432,7 +435,6 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -432,7 +435,6 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd,
const int bit0 = (mbmi->ref_frame[0] == ALTREF_FRAME || const int bit0 = (mbmi->ref_frame[0] == ALTREF_FRAME ||
mbmi->ref_frame[0] == BWDREF_FRAME); mbmi->ref_frame[0] == BWDREF_FRAME);
aom_write(w, bit0, av1_get_pred_prob_single_ref_p1(cm, xd)); aom_write(w, bit0, av1_get_pred_prob_single_ref_p1(cm, xd));
if (bit0) { if (bit0) {
const int bit1 = mbmi->ref_frame[0] == ALTREF_FRAME; const int bit1 = mbmi->ref_frame[0] == ALTREF_FRAME;
aom_write(w, bit1, av1_get_pred_prob_single_ref_p2(cm, xd)); aom_write(w, bit1, av1_get_pred_prob_single_ref_p2(cm, xd));
...@@ -440,7 +442,6 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -440,7 +442,6 @@ static void write_ref_frames(const AV1_COMMON *cm, const MACROBLOCKD *xd,
const int bit2 = (mbmi->ref_frame[0] == LAST3_FRAME || const int bit2 = (mbmi->ref_frame[0] == LAST3_FRAME ||
mbmi->ref_frame[0] == GOLDEN_FRAME); mbmi->ref_frame[0] == GOLDEN_FRAME);
aom_write(w, bit2, av1_get_pred_prob_single_ref_p3(cm, xd)); aom_write(w, bit2, av1_get_pred_prob_single_ref_p3(cm, xd));
if (!bit2) { if (!bit2) {
const int bit3 = mbmi->ref_frame[0] != LAST_FRAME; const int bit3 = mbmi->ref_frame[0] != LAST_FRAME;
aom_write(w, bit3, av1_get_pred_prob_single_ref_p4(cm, xd)); aom_write(w, bit3, av1_get_pred_prob_single_ref_p4(cm, xd));
......
...@@ -151,8 +151,13 @@ void av1_init_me_luts(void) { ...@@ -151,8 +151,13 @@ void av1_init_me_luts(void) {
static const int rd_boost_factor[16] = { 64, 32, 32, 32, 24, 16, 12, 12, static const int rd_boost_factor[16] = { 64, 32, 32, 32, 24, 16, 12, 12,
8, 8, 4, 4, 2, 2, 1, 0 }; 8, 8, 4, 4, 2, 2, 1, 0 };
static const int rd_frame_type_factor[FRAME_UPDATE_TYPES] = { 128, 144, 128, static const int rd_frame_type_factor[FRAME_UPDATE_TYPES] = {
128, 144 }; 128, 144, 128, 128, 144,
#if CONFIG_EXT_REFS
// TODO(zoeliu): To adjust further following factor values.
128, 128, 128
#endif // CONFIG_EXT_REFS
};
int av1_compute_rd_mult(const AV1_COMP *cpi, int qindex) { int av1_compute_rd_mult(const AV1_COMP *cpi, int qindex) {
const int64_t q = av1_dc_quant(qindex, 0, cpi->common.bit_depth); const int64_t q = av1_dc_quant(qindex, 0, cpi->common.bit_depth);
...@@ -608,10 +613,20 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) { ...@@ -608,10 +613,20 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
if (sf->adaptive_rd_thresh) { if (sf->adaptive_rd_thresh) {
rd->thresh_mult[THR_NEARESTMV] = 300; rd->thresh_mult[THR_NEARESTMV] = 300;
#if CONFIG_EXT_REFS
rd->thresh_mult[THR_NEARESTL2] = 300;
rd->thresh_mult[THR_NEARESTL3] = 300;
rd->thresh_mult[THR_NEARESTB] = 300;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_NEARESTG] = 300; rd->thresh_mult[THR_NEARESTG] = 300;
rd->thresh_mult[THR_NEARESTA] = 300; rd->thresh_mult[THR_NEARESTA] = 300;
} else { } else {
rd->thresh_mult[THR_NEARESTMV] = 0; rd->thresh_mult[THR_NEARESTMV] = 0;
#if CONFIG_EXT_REFS
rd->thresh_mult[THR_NEARESTL2] = 0;
rd->thresh_mult[THR_NEARESTL3] = 0;
rd->thresh_mult[THR_NEARESTB] = 0;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_NEARESTG] = 0; rd->thresh_mult[THR_NEARESTG] = 0;
rd->thresh_mult[THR_NEARESTA] = 0; rd->thresh_mult[THR_NEARESTA] = 0;
} }
...@@ -619,28 +634,83 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) { ...@@ -619,28 +634,83 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
rd->thresh_mult[THR_DC] += 1000; rd->thresh_mult[THR_DC] += 1000;
rd->thresh_mult[THR_NEWMV] += 1000; rd->thresh_mult[THR_NEWMV] += 1000;
#if CONFIG_EXT_REFS
rd->thresh_mult[THR_NEWL2] += 1000;
rd->thresh_mult[THR_NEWL3] += 1000;
rd->thresh_mult[THR_NEWB] += 1000;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_NEWA] += 1000; rd->thresh_mult[THR_NEWA] += 1000;
rd->thresh_mult[THR_NEWG] += 1000; rd->thresh_mult[THR_NEWG] += 1000;
rd->thresh_mult[THR_NEARMV] += 1000; rd->thresh_mult[THR_NEARMV] += 1000;
#if CONFIG_EXT_REFS
rd->thresh_mult[THR_NEARL2] += 1000;
rd->thresh_mult[THR_NEARL3] += 1000;
rd->thresh_mult[THR_NEARB] += 1000;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_NEARA] += 1000; rd->thresh_mult[THR_NEARA] += 1000;
rd->thresh_mult[THR_COMP_NEARESTLA] += 1000; rd->thresh_mult[THR_NEARG] += 1000;
rd->thresh_mult[THR_COMP_NEARESTGA] += 1000;
rd->thresh_mult[THR_ZEROMV] += 2000;
#if CONFIG_EXT_REFS
rd->thresh_mult[THR_ZEROL2] += 2000;
rd->thresh_mult[THR_ZEROL3] += 2000;
rd->thresh_mult[THR_ZEROB] += 2000;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_ZEROG] += 2000;
rd->thresh_mult[THR_ZEROA] += 2000;
rd->thresh_mult[THR_TM] += 1000; rd->thresh_mult[THR_TM] += 1000;
rd->thresh_mult[THR_COMP_NEARESTLA] += 1000;
#if CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_NEARESTL2A] += 1000;
rd->thresh_mult[THR_COMP_NEARESTL3A] += 1000;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_NEARESTGA] += 1000;
#if CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_NEARESTLB] += 1000;
rd->thresh_mult[THR_COMP_NEARESTL2B] += 1000;
rd->thresh_mult[THR_COMP_NEARESTL3B] += 1000;
rd->thresh_mult[THR_COMP_NEARESTGB] += 1000;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_NEARLA] += 1500; rd->thresh_mult[THR_COMP_NEARLA] += 1500;
rd->thresh_mult[THR_COMP_NEWLA] += 2000; rd->thresh_mult[THR_COMP_NEWLA] += 2000;
rd->thresh_mult[THR_NEARG] += 1000; #if CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_NEARL2A] += 1500;
rd->thresh_mult[THR_COMP_NEWL2A] += 2000;
rd->thresh_mult[THR_COMP_NEARL3A] += 1500;
rd->thresh_mult[THR_COMP_NEWL3A] += 2000;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_NEARGA] += 1500; rd->thresh_mult[THR_COMP_NEARGA] += 1500;
rd->thresh_mult[THR_COMP_NEWGA] += 2000; rd->thresh_mult[THR_COMP_NEWGA] += 2000;
rd->thresh_mult[THR_ZEROMV] += 2000; #if CONFIG_EXT_REFS
rd->thresh_mult[THR_ZEROG] += 2000; rd->thresh_mult[THR_COMP_NEARLB] += 1500;
rd->thresh_mult[THR_ZEROA] += 2000; rd->thresh_mult[THR_COMP_NEWLB] += 2000;
rd->thresh_mult[THR_COMP_NEARL2B] += 1500;
rd->thresh_mult[THR_COMP_NEWL2B] += 2000;
rd->thresh_mult[THR_COMP_NEARL3B] += 1500;
rd->thresh_mult[THR_COMP_NEWL3B] += 2000;
rd->thresh_mult[THR_COMP_NEARGB] += 1500;
rd->thresh_mult[THR_COMP_NEWGB] += 2000;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_ZEROLA] += 2500; rd->thresh_mult[THR_COMP_ZEROLA] += 2500;
#if CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_ZEROL2A] += 2500;
rd->thresh_mult[THR_COMP_ZEROL3A] += 2500;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_ZEROGA] += 2500; rd->thresh_mult[THR_COMP_ZEROGA] += 2500;
#if CONFIG_EXT_REFS
rd->thresh_mult[THR_COMP_ZEROLB] += 2500;
rd->thresh_mult[THR_COMP_ZEROL2B] += 2500;
rd->thresh_mult[THR_COMP_ZEROL3B] += 2500;
rd->thresh_mult[THR_COMP_ZEROGB] += 2500;
#endif // CONFIG_EXT_REFS
rd->thresh_mult[THR_H_PRED] += 2000; rd->thresh_mult[THR_H_PRED] += 2000;
rd->thresh_mult[THR_V_PRED] += 2000; rd->thresh_mult[THR_V_PRED] += 2000;
rd->thresh_mult[THR_D45_PRED] += 2500; rd->thresh_mult[THR_D45_PRED] += 2500;
...@@ -653,8 +723,15 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) { ...@@ -653,8 +723,15 @@ void av1_set_rd_speed_thresholds(AV1_COMP *cpi) {
void av1_set_rd_speed_thresholds_sub8x8(AV1_COMP *cpi) { void av1_set_rd_speed_thresholds_sub8x8(AV1_COMP *cpi) {
static const int thresh_mult[2][MAX_REFS] = { static const int thresh_mult[2][MAX_REFS] = {
#if CONFIG_EXT_REFS
{ 2500, 2500, 2500, 2500, 2500, 2500, 4500, 4500, 4500, 4500, 4500, 4500,
4500, 4500, 2500 },
{ 2000, 2000, 2000, 2000, 2000, 2000, 4000, 4000, 4000, 4000, 4000, 4000,
4000, 4000, 2000 }
#else
{ 2500, 2500, 2500, 4500, 4500, 2500 }, { 2500, 2500, 2500, 4500, 4500, 2500 },
{ 2000, 2000, 2000, 4000, 4000, 2000 } { 2000, 2000, 2000, 4000, 4000, 2000 }
#endif // CONFIG_EXT_REFS
}; };
RD_OPT *const rd = &cpi->rd; RD_OPT *const rd = &cpi->rd;
const int idx = cpi->oxcf.mode == BEST; const int idx = cpi->oxcf.mode == BEST;
......
...@@ -36,8 +36,13 @@ extern "C" { ...@@ -36,8 +36,13 @@ extern "C" {
#define INVALID_MV 0x80008000 #define INVALID_MV 0x80008000
#if CONFIG_EXT_REFS
#define MAX_MODES 66
#define MAX_REFS 15
#else
#define MAX_MODES 30 #define MAX_MODES 30
#define MAX_REFS 6 #define MAX_REFS 6
#endif // CONFIG_EXT_REFS
#define RD_THRESH_MAX_FACT 64 #define RD_THRESH_MAX_FACT 64
#define RD_THRESH_INC 1 #define RD_THRESH_INC 1
...@@ -46,35 +51,92 @@ extern "C" { ...@@ -46,35 +51,92 @@ extern "C" {
// const MODE_DEFINITION av1_mode_order[MAX_MODES] used in the rd code. // const MODE_DEFINITION av1_mode_order[MAX_MODES] used in the rd code.
typedef enum { typedef enum {
THR_NEARESTMV, THR_NEARESTMV,
#if CONFIG_EXT_REFS
THR_NEARESTL2,
THR_NEARESTL3,
THR_NEARESTB,
#endif // CONFIG_EXT_REFS
THR_NEARESTA, THR_NEARESTA,
THR_NEARESTG, THR_NEARESTG,
THR_DC, THR_DC,
THR_NEWMV, THR_NEWMV,
#if CONFIG_EXT_REFS
THR_NEWL2,
THR_NEWL3,
THR_NEWB,
#endif // CONFIG_EXT_REFS
THR_NEWA, THR_NEWA,
THR_NEWG, THR_NEWG,
THR_NEARMV, THR_NEARMV,
#if CONFIG_EXT_REFS
THR_NEARL2,
THR_NEARL3,
THR_NEARB,
#endif // CONFIG_EXT_REFS
THR_NEARA, THR_NEARA,
THR_NEARG, THR_NEARG,
THR_ZEROMV, THR_ZEROMV,
#if CONFIG_EXT_REFS
THR_ZEROL2,
THR_ZEROL3,
THR_ZEROB,
#endif // CONFIG_EXT_REFS
THR_ZEROG, THR_ZEROG,
THR_ZEROA, THR_ZEROA,
THR_COMP_NEARESTLA, THR_COMP_NEARESTLA,
#if CONFIG_EXT_REFS
THR_COMP_NEARESTL2A,
THR_COMP_NEARESTL3A,
#endif // CONFIG_EXT_REFS
THR_COMP_NEARESTGA, THR_COMP_NEARESTGA,
#if CONFIG_EXT_REFS
THR_COMP_NEARESTLB,
THR_COMP_NEARESTL2B,
THR_COMP_NEARESTL3B,
THR_COMP_NEARESTGB,
#endif // CONFIG_EXT_REFS
THR_TM, THR_TM,
THR_COMP_NEARLA, THR_COMP_NEARLA,
THR_COMP_NEWLA, THR_COMP_NEWLA,
#if CONFIG_EXT_REFS
THR_COMP_NEARL2A,
THR_COMP_NEWL2A,
THR_COMP_NEARL3A,
THR_COMP_NEWL3A,
#endif // CONFIG_EXT_REFS
THR_COMP_NEARGA, THR_COMP_NEARGA,
THR_COMP_NEWGA, THR_COMP_NEWGA,
#if CONFIG_EXT_REFS
THR_COMP_NEARLB,
THR_COMP_NEWLB,
THR_COMP_NEARL2B,
THR_COMP_NEWL2B,
THR_COMP_NEARL3B,
THR_COMP_NEWL3B,
THR_COMP_NEARGB,
THR_COMP_NEWGB,
#endif // CONFIG_EXT_REFS
THR_COMP_ZEROLA, THR_COMP_ZEROLA,
#if CONFIG_EXT_REFS
THR_COMP_ZEROL2A,
THR_COMP_ZEROL3A,
#endif // CONFIG_EXT_REFS
THR_COMP_ZEROGA, THR_COMP_ZEROGA,
#if CONFIG_EXT_REFS
THR_COMP_ZEROLB,
THR_COMP_ZEROL2B,
THR_COMP_ZEROL3B,
THR_COMP_ZEROGB,
#endif // CONFIG_EXT_REFS
THR_H_PRED, THR_H_PRED,
THR_V_PRED, THR_V_PRED,
...@@ -88,10 +150,27 @@ typedef enum { ...@@ -88,10 +150,27 @@ typedef enum {
typedef enum { typedef enum {
THR_LAST, THR_LAST,
#if CONFIG_EXT_REFS
THR_LAST2,
THR_LAST3,
#endif // CONFIG_EXT_REFS
THR_GOLD, THR_GOLD,
#if CONFIG_EXT_REFS
THR_BWDR,
#endif // CONFIG_EXT_REFS
THR_ALTR, THR_ALTR,
THR_COMP_LA, THR_COMP_LA,
#if CONFIG_EXT_REFS
THR_COMP_L2A,
THR_COMP_L3A,
#endif // CONFIG_EXT_REFS
THR_COMP_GA, THR_COMP_GA,
#if CONFIG_EXT_REFS
THR_COMP_LB,
THR_COMP_L2B,
THR_COMP_L3B,
THR_COMP_GB,
#endif // CONFIG_EXT_REFS
THR_INTRA, THR_INTRA,
} THR_MODES_SUB8X8; } THR_MODES_SUB8X8;
......
...@@ -44,14 +44,43 @@ ...@@ -44,14 +44,43 @@
#include "av1/encoder/rd.h" #include "av1/encoder/rd.h"
#include "av1/encoder/rdopt.h" #include "av1/encoder/rdopt.h"
#if CONFIG_EXT_REFS
#define LAST_FRAME_MODE_MASK \
((1 << INTRA_FRAME) | (1 << LAST2_FRAME) | (1 << LAST3_FRAME) | \
(1 << GOLDEN_FRAME) | (1 << BWDREF_FRAME) | (1 << ALTREF_FRAME)) // NOLINT
#define LAST2_FRAME_MODE_MASK \
((1 << INTRA_FRAME) | (1 << LAST_FRAME) | (1 << LAST3_FRAME) | \
(1 << GOLDEN_FRAME) | (1 << BWDREF_FRAME) | (1 << ALTREF_FRAME)) // NOLINT
#define LAST3_FRAME_MODE_MASK \
((1 << INTRA_FRAME) | (1 << LAST_FRAME) | (1 << LAST2_FRAME) | \
(1 << GOLDEN_FRAME) | (1 << BWDREF_FRAME) | (1 << ALTREF_FRAME)) // NOLINT
#define GOLDEN_FRAME_MODE_MASK \
((1 << INTRA_FRAME) | (1 << LAST_FRAME) | (1 << LAST2_FRAME) | \
(1 << LAST3_FRAME) | (1 << BWDREF_FRAME) | (1 << ALTREF_FRAME)) // NOLINT
#define BWDREF_FRAME_MODE_MASK \
((1 << INTRA_FRAME) | (1 << LAST_FRAME) | (1 << LAST2_FRAME) | \
(1 << LAST3_FRAME) | (1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME)) // NOLINT
#define ALTREF_FRAME_MODE_MASK \
((1 << INTRA_FRAME) | (1 << LAST_FRAME) | (1 << LAST2_FRAME) | \
(1 << LAST3_FRAME) | (1 << GOLDEN_FRAME) | (1 << BWDREF_FRAME)) // NOLINT
#else
#define LAST_FRAME_MODE_MASK \ #define LAST_FRAME_MODE_MASK \
((1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME) | (1 << INTRA_FRAME)) ((1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME) | (1 << INTRA_FRAME))
#define GOLDEN_FRAME_MODE_MASK \ #define GOLDEN_FRAME_MODE_MASK \
((1 << LAST_FRAME) | (1 << ALTREF_FRAME) | (1 << INTRA_FRAME)) ((1 << LAST_FRAME) | (1 << ALTREF_FRAME) | (1 << INTRA_FRAME))
#define ALT_REF_MODE_MASK \ #define ALTREF_FRAME_MODE_MASK \
((1 << LAST_FRAME) | (1 << GOLDEN_FRAME) | (1 << INTRA_FRAME)) ((1 << LAST_FRAME) | (1 << GOLDEN_FRAME) | (1 << INTRA_FRAME))
#endif // CONFIG_EXT_REFS
#if CONFIG_EXT_REFS
#define SECOND_REF_FRAME_MASK ((1 << ALTREF_FRAME) | (1 << BWDREF_FRAME) | 0x01)
#else
#define SECOND_REF_FRAME_MASK ((1 << ALTREF_FRAME) | 0x01) #define SECOND_REF_FRAME_MASK ((1 << ALTREF_FRAME) | 0x01)
#endif // CONFIG_EXT_REFS
#define MIN_EARLY_TERM_INDEX 3 #define MIN_EARLY_TERM_INDEX 3
#define NEW_MV_DISCOUNT_FACTOR 8 #define NEW_MV_DISCOUNT_FACTOR 8
...@@ -83,35 +112,94 @@ struct rdcost_block_args { ...@@ -83,35 +112,94 @@ struct rdcost_block_args {
#define LAST_NEW_MV_INDEX 6 #define LAST_NEW_MV_INDEX 6
static const MODE_DEFINITION av1_mode_order[MAX_MODES] = { static const MODE_DEFINITION av1_mode_order[MAX_MODES] = {
{ NEARESTMV, { LAST_FRAME, NONE } }, { NEARESTMV, { LAST_FRAME, NONE } },
#if CONFIG_EXT_REFS
{ NEARESTMV, { LAST2_FRAME, NONE } },
{ NEARESTMV, { LAST3_FRAME, NONE } },
{ NEARESTMV, { BWDREF_FRAME, NONE } },
#endif // CONFIG_EXT_REFS
{ NEARESTMV, { ALTREF_FRAME, NONE } }, { NEARESTMV, { ALTREF_FRAME, NONE } },
{ NEARESTMV, { GOLDEN_FRAME, NONE } }, { NEARESTMV, { GOLDEN_FRAME, NONE } },
{ DC_PRED, { INTRA_FRAME, NONE } }, { DC_PRED, { INTRA_FRAME, NONE } },
{ NEWMV, { LAST_FRAME, NONE } }, { NEWMV, { LAST_FRAME, NONE } },
#if CONFIG_EXT_REFS
{ NEWMV, { LAST2_FRAME, NONE } },
{ NEWMV, { LAST3_FRAME, NONE } },
{ NEWMV, { BWDREF_FRAME, NONE } },
#endif // CONFIG_EXT_REFS
{ NEWMV, { ALTREF_FRAME, NONE } }, { NEWMV, { ALTREF_FRAME, NONE } },
{ NEWMV, { GOLDEN_FRAME, NONE } }, { NEWMV, { GOLDEN_FRAME, NONE } },
{ NEARMV, { LAST_FRAME, NONE } }, { NEARMV, { LAST_FRAME, NONE } },
#if CONFIG_EXT_REFS
{ NEARMV, { LAST2_FRAME, NONE } },
{ NEARMV, { LAST3_FRAME, NONE } },
{ NEARMV, { BWDREF_FRAME, NONE } },
#endif // CONFIG_EXT_REFS
{ NEARMV, { ALTREF_FRAME, NONE } }, { NEARMV, { ALTREF_FRAME, NONE } },