Commit 705544c2 authored by Debargha Mukherjee's avatar Debargha Mukherjee

Refines the recode loop

Uses number of 4x4 blocks using global motion as metric to
decide whether to recode or not.

Improves performance a little.
lowres: -0.658%

Change-Id: I6b1913b7bd31d7a25ca8ca5c75c9b6bb87151a78
parent fd873807
......@@ -4129,18 +4129,19 @@ static void write_global_motion(AV1_COMP *cpi, aom_writer *w) {
// With ref-mv, clearing unused global motion models here is
// unsafe, and we need to rely on the recode loop to do it
// instead. See av1_find_mv_refs for details.
if (!cpi->global_motion_used[frame]) {
if (!cpi->global_motion_used[frame][0]) {
set_default_gmparams(&cm->global_motion[frame]);
}
#endif
write_global_motion_params(&cm->global_motion[frame],
cm->fc->global_motion_types_prob, w);
/*
printf("Frame %d/%d: Enc Ref %d (used %d): %d %d %d %d\n",
printf("Frame %d/%d: Enc Ref %d (used %d/%d): %d %d %d %d\n",
cm->current_video_frame, cm->show_frame, frame,
cpi->global_motion_used[frame], cm->global_motion[frame].wmmat[0],
cm->global_motion[frame].wmmat[1], cm->global_motion[frame].wmmat[2],
cm->global_motion[frame].wmmat[3]);
cpi->global_motion_used[frame][0], cpi->global_motion_used[frame][1],
cm->global_motion[frame].wmmat[0], cm->global_motion[frame].wmmat[1],
cm->global_motion[frame].wmmat[2],
cm->global_motion[frame].wmmat[3]);
*/
}
}
......
......@@ -1003,11 +1003,19 @@ static void update_filter_type_count(FRAME_COUNTS *counts,
}
#endif
#if CONFIG_GLOBAL_MOTION
static void update_global_motion_used(PREDICTION_MODE mode,
static void update_global_motion_used(PREDICTION_MODE mode, BLOCK_SIZE bsize,
const MB_MODE_INFO *mbmi, AV1_COMP *cpi) {
if (mode == ZEROMV) {
++cpi->global_motion_used[mbmi->ref_frame[0]];
if (has_second_ref(mbmi)) ++cpi->global_motion_used[mbmi->ref_frame[1]];
const int num_4x4s = bsize >= BLOCK_8X8
? num_4x4_blocks_wide_lookup[bsize] *
num_4x4_blocks_high_lookup[bsize]
: 1;
++cpi->global_motion_used[mbmi->ref_frame[0]][0];
cpi->global_motion_used[mbmi->ref_frame[0]][1] += num_4x4s;
if (has_second_ref(mbmi)) {
++cpi->global_motion_used[mbmi->ref_frame[1]][0];
cpi->global_motion_used[mbmi->ref_frame[1]][1] += num_4x4s;
}
}
}
#endif // CONFIG_GLOBAL_MOTION
......@@ -1165,7 +1173,7 @@ static void update_state(const AV1_COMP *const cpi, ThreadData *td,
if (bsize >= BLOCK_8X8) {
// TODO(sarahparker): global motion stats need to be handled per-tile
// to be compatible with tile-based threading.
update_global_motion_used(mbmi->mode, mbmi, (AV1_COMP *)cpi);
update_global_motion_used(mbmi->mode, bsize, mbmi, (AV1_COMP *)cpi);
} else {
const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
......@@ -1173,7 +1181,7 @@ static void update_state(const AV1_COMP *const cpi, ThreadData *td,
for (idy = 0; idy < 2; idy += num_4x4_h) {
for (idx = 0; idx < 2; idx += num_4x4_w) {
const int j = idy * 2 + idx;
update_global_motion_used(mi->bmi[j].as_mode, mbmi,
update_global_motion_used(mi->bmi[j].as_mode, bsize, mbmi,
(AV1_COMP *)cpi);
}
}
......@@ -1338,7 +1346,7 @@ static void update_state_supertx(const AV1_COMP *const cpi, ThreadData *td,
if (bsize >= BLOCK_8X8) {
// TODO(sarahparker): global motion stats need to be handled per-tile
// to be compatible with tile-based threading.
update_global_motion_used(mbmi->mode, mbmi, (AV1_COMP *)cpi);
update_global_motion_used(mbmi->mode, bsize, mbmi, (AV1_COMP *)cpi);
} else {
const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize];
const int num_4x4_h = num_4x4_blocks_high_lookup[bsize];
......@@ -1346,7 +1354,7 @@ static void update_state_supertx(const AV1_COMP *const cpi, ThreadData *td,
for (idy = 0; idy < 2; idy += num_4x4_h) {
for (idx = 0; idx < 2; idx += num_4x4_w) {
const int j = idy * 2 + idx;
update_global_motion_used(mi->bmi[j].as_mode, mbmi,
update_global_motion_used(mi->bmi[j].as_mode, bsize, mbmi,
(AV1_COMP *)cpi);
}
}
......
......@@ -2885,18 +2885,19 @@ static int scale_down(AV1_COMP *cpi, int q) {
#if CONFIG_GLOBAL_MOTION
static int recode_loop_test_global_motion(AV1_COMP *cpi) {
static const int min_blocks[TRANS_TYPES] = { 0, 2, 4, 6, 8 };
static const int min_blocks[TRANS_TYPES] = { 0, 60, 120, 180, 240 };
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_blocks[cm->global_motion[i].wmtype]) {
cpi->global_motion_used[i][1] <
min_blocks[cm->global_motion[i].wmtype]) {
set_default_gmparams(&cm->global_motion[i]);
#if CONFIG_REF_MV
recode = 1;
#else
recode |= (cpi->global_motion_used[i] > 0);
recode |= (cpi->global_motion_used[i][1] > 0);
#endif
}
}
......
......@@ -632,7 +632,9 @@ typedef struct AV1_COMP {
int arf_map[MAX_EXT_ARFS + 1];
#endif // CONFIG_EXT_REFS
#if CONFIG_GLOBAL_MOTION
int global_motion_used[TOTAL_REFS_PER_FRAME];
// Stores number of prediction blocks using global motion and the
// number of 4x4 blocks using it per reference frame.
int global_motion_used[TOTAL_REFS_PER_FRAME][2];
int global_motion_search_done;
#endif
#if CONFIG_REFERENCE_BUFFER
......
......@@ -4404,7 +4404,7 @@ static int GLOBAL_MOTION_RATE(const AV1_COMP *const cpi, int ref) {
};
const WarpedMotionParams *gm = &cpi->common.global_motion[(ref)];
assert(gm->wmtype < GLOBAL_TRANS_TYPES);
if (cpi->global_motion_used[ref] >= gm_amortization_blks[gm->wmtype]) {
if (cpi->global_motion_used[ref][0] >= gm_amortization_blks[gm->wmtype]) {
return 0;
} else {
const int cost = (gm_params_cost[gm->wmtype] << AV1_PROB_COST_SHIFT) +
......
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