Commit b98a702d authored by Debargha Mukherjee's avatar Debargha Mukherjee

Add recode loop test for global motion usage

Adds a feature to recode if global motion is used for a reference but
has very few blocks in the frame actually using it.

lowres improves to -0.512% on average.

Change-Id: I61a36770e1b7103b9a27706909443c3f14ee4e42
parent fa2865b5
...@@ -4014,12 +4014,10 @@ static void write_global_motion(AV1_COMP *cpi, aom_writer *w) { ...@@ -4014,12 +4014,10 @@ static void write_global_motion(AV1_COMP *cpi, aom_writer *w) {
write_global_motion_params(&cm->global_motion[frame], write_global_motion_params(&cm->global_motion[frame],
cm->fc->global_motion_types_prob, w); cm->fc->global_motion_types_prob, w);
/* /*
printf("Enc Ref %d [%d/%d] (used %d): %d %d %d %d\n", printf("Frame %d/%d: Enc Ref %d (used %d): %d %d %d %d\n",
frame, cm->current_video_frame, cm->show_frame, cm->current_video_frame, cm->show_frame, frame,
cpi->global_motion_used[frame], cpi->global_motion_used[frame], cm->global_motion[frame].wmmat[0],
cm->global_motion[frame].wmmat[0], cm->global_motion[frame].wmmat[1], cm->global_motion[frame].wmmat[2],
cm->global_motion[frame].wmmat[1],
cm->global_motion[frame].wmmat[2],
cm->global_motion[frame].wmmat[3]); cm->global_motion[frame].wmmat[3]);
*/ */
} }
......
...@@ -4785,10 +4785,8 @@ static void encode_frame_internal(AV1_COMP *cpi) { ...@@ -4785,10 +4785,8 @@ static void encode_frame_internal(AV1_COMP *cpi) {
#if CONFIG_GLOBAL_MOTION #if CONFIG_GLOBAL_MOTION
av1_zero(cpi->global_motion_used); av1_zero(cpi->global_motion_used);
for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { if (cpi->common.frame_type == INTER_FRAME && cpi->Source &&
set_default_gmparams(&cm->global_motion[i]); !cpi->global_motion_search_done) {
}
if (cpi->common.frame_type == INTER_FRAME && cpi->Source) {
YV12_BUFFER_CONFIG *ref_buf; YV12_BUFFER_CONFIG *ref_buf;
int frame; int frame;
double erroradvantage = 0; double erroradvantage = 0;
...@@ -4831,6 +4829,7 @@ static void encode_frame_internal(AV1_COMP *cpi) { ...@@ -4831,6 +4829,7 @@ static void encode_frame_internal(AV1_COMP *cpi) {
aom_clear_system_state(); aom_clear_system_state();
} }
} }
cpi->global_motion_search_done = 1;
} }
#endif // CONFIG_GLOBAL_MOTION #endif // CONFIG_GLOBAL_MOTION
......
...@@ -330,10 +330,10 @@ int av1_optimize_b(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, int block, ...@@ -330,10 +330,10 @@ int av1_optimize_b(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, int block,
: tokens[i][1].dqc; : tokens[i][1].dqc;
if (sz) tokens[i][1].dqc = -tokens[i][1].dqc; if (sz) tokens[i][1].dqc = -tokens[i][1].dqc;
#else #else
// The 32x32 transform coefficient uses half quantization step size. // The 32x32 transform coefficient uses half quantization step size.
// Account for the rounding difference in the dequantized coefficeint // Account for the rounding difference in the dequantized coefficeint
// value when the quantization index is dropped from an even number // value when the quantization index is dropped from an even number
// to an odd number. // to an odd number.
#if CONFIG_AOM_QM #if CONFIG_AOM_QM
tran_low_t offset = dqv >> shift; tran_low_t offset = dqv >> shift;
......
...@@ -2878,6 +2878,23 @@ static int scale_down(AV1_COMP *cpi, int q) { ...@@ -2878,6 +2878,23 @@ static int scale_down(AV1_COMP *cpi, int q) {
return scale; return scale;
} }
#if CONFIG_GLOBAL_MOTION
#define MIN_GLOBAL_MOTION_BLKS 4
static int recode_loop_test_global_motion(AV1_COMP *cpi) {
int i;
int recode = 0;
AV1_COMMON *const cm = &cpi->common;
for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
if (cm->global_motion[i].wmtype != IDENTITY &&
cpi->global_motion_used[i] < MIN_GLOBAL_MOTION_BLKS) {
set_default_gmparams(&cm->global_motion[i]);
recode |= (cpi->global_motion_used[i] > 0);
}
}
return recode;
}
#endif // CONFIG_GLOBAL_MOTION
// Function to test for conditions that indicate we should loop // Function to test for conditions that indicate we should loop
// back and recode a frame. // back and recode a frame.
static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q, static int recode_loop_test(AV1_COMP *cpi, int high_limit, int low_limit, int q,
...@@ -3699,6 +3716,13 @@ static void set_mv_search_params(AV1_COMP *cpi) { ...@@ -3699,6 +3716,13 @@ static void set_mv_search_params(AV1_COMP *cpi) {
} }
static void set_size_independent_vars(AV1_COMP *cpi) { static void set_size_independent_vars(AV1_COMP *cpi) {
#if CONFIG_GLOBAL_MOTION
int i;
for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
set_default_gmparams(&cpi->common.global_motion[i]);
}
cpi->global_motion_search_done = 0;
#endif // CONFIG_GLOBAL_MOTION
av1_set_speed_features_framesize_independent(cpi); av1_set_speed_features_framesize_independent(cpi);
av1_set_rd_speed_thresholds(cpi); av1_set_rd_speed_thresholds(cpi);
av1_set_rd_speed_thresholds_sub8x8(cpi); av1_set_rd_speed_thresholds_sub8x8(cpi);
...@@ -4211,6 +4235,12 @@ static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size, ...@@ -4211,6 +4235,12 @@ static void encode_with_recode_loop(AV1_COMP *cpi, size_t *size,
rc->projected_frame_size < rc->max_frame_bandwidth) rc->projected_frame_size < rc->max_frame_bandwidth)
loop = 0; loop = 0;
#if CONFIG_GLOBAL_MOTION
if (recode_loop_test_global_motion(cpi)) {
loop = 1;
}
#endif // CONFIG_GLOBAL_MOTION
if (loop) { if (loop) {
++loop_count; ++loop_count;
++loop_at_this_size; ++loop_at_this_size;
......
...@@ -625,6 +625,7 @@ typedef struct AV1_COMP { ...@@ -625,6 +625,7 @@ typedef struct AV1_COMP {
#endif // CONFIG_EXT_REFS #endif // CONFIG_EXT_REFS
#if CONFIG_GLOBAL_MOTION #if CONFIG_GLOBAL_MOTION
int global_motion_used[TOTAL_REFS_PER_FRAME]; int global_motion_used[TOTAL_REFS_PER_FRAME];
int global_motion_search_done;
#endif #endif
#if CONFIG_REFERENCE_BUFFER #if CONFIG_REFERENCE_BUFFER
SequenceHeader seq_params; SequenceHeader seq_params;
......
...@@ -4330,6 +4330,9 @@ static int cost_mv_ref(const AV1_COMP *const cpi, PREDICTION_MODE mode, ...@@ -4330,6 +4330,9 @@ static int cost_mv_ref(const AV1_COMP *const cpi, PREDICTION_MODE mode,
} }
#if CONFIG_GLOBAL_MOTION #if CONFIG_GLOBAL_MOTION
#define GLOBAL_MOTION_COST_AMORTIZATION_BLKS 8
#if GLOBAL_MOTION_COST_AMORTIZATION_BLKS > 0
static int get_gmbitcost(const WarpedMotionParams *gm, const aom_prob *probs) { static int get_gmbitcost(const WarpedMotionParams *gm, const aom_prob *probs) {
int gmtype_cost[TRANS_TYPES]; int gmtype_cost[TRANS_TYPES];
int bits; int bits;
...@@ -4354,9 +4357,6 @@ static int get_gmbitcost(const WarpedMotionParams *gm, const aom_prob *probs) { ...@@ -4354,9 +4357,6 @@ static int get_gmbitcost(const WarpedMotionParams *gm, const aom_prob *probs) {
return bits ? (bits << AV1_PROB_COST_SHIFT) + gmtype_cost[type] : 0; return bits ? (bits << AV1_PROB_COST_SHIFT) + gmtype_cost[type] : 0;
} }
#define GLOBAL_MOTION_COST_AMORTIZATION_BLKS 8
#if GLOBAL_MOTION_COST_AMORTIZATION_BLKS > 0
#define GLOBAL_MOTION_RATE(ref) \ #define GLOBAL_MOTION_RATE(ref) \
(cpi->global_motion_used[ref] >= GLOBAL_MOTION_COST_AMORTIZATION_BLKS \ (cpi->global_motion_used[ref] >= GLOBAL_MOTION_COST_AMORTIZATION_BLKS \
? 0 \ ? 0 \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment