ref: 302698fb120477aedb1c6db199b19c9177e14828
parent: 97dbee00dd5e8f1ab5fdcf3c222413355e6404ef
author: Deb Mukherjee <[email protected]>
date: Fri Jul 12 05:52:24 EDT 2013
Reworked the auto_mv_step_size speed feature This patch modifies the auto_mv_step_size speed feature to use a combination of the maximum magnitude mv from the last inter frame, and the maximum magnitude mv for the two reference mvs with the same reference. For arf frames, the max mav step for the resolution is used. The bounds therefore are slightly tighter. The feature is made a speed 1 feature. Rebased. Results (when this feature is turned on over speed 0): derfraw300: -0.046% psnr, about 5+% speedup (tested on football: goes from 4m30.760s to 4m17.410s). Change-Id: If492797a61b0b4b3e58c0b8f86afb880165fc9f6
--- a/vp9/encoder/vp9_block.h
+++ b/vp9/encoder/vp9_block.h
@@ -96,6 +96,7 @@
signed int act_zbin_adj;
int mv_best_ref_index[MAX_REF_FRAMES];
+ unsigned int max_mv_context[MAX_REF_FRAMES];
int nmvjointcost[MV_JOINTS];
int nmvcosts[2][MV_VALS];
--- a/vp9/encoder/vp9_encodemv.c
+++ b/vp9/encoder/vp9_encodemv.c
@@ -486,11 +486,11 @@
if (mv_joint_horizontal(j))
encode_mv_component(w, diff.col, &mvctx->comps[1], usehp);
- // If auto_mv_step_size is enabled and it is an arf/non shown frame
- // then keep track of the largest motion vector component used.
- if (cpi->sf.auto_mv_step_size && !cpi->common.show_frame) {
- cpi->max_mv_magnitude = MAX((MAX(abs(mv->row), abs(mv->col)) >> 3),
- cpi->max_mv_magnitude);
+ // If auto_mv_step_size is enabled then keep track of the largest
+ // motion vector component used.
+ if (!cpi->dummy_packing && cpi->sf.auto_mv_step_size) {
+ unsigned int maxv = MAX(abs(mv->row), abs(mv->col)) >> 3;
+ cpi->max_mv_magnitude = MAX(maxv, cpi->max_mv_magnitude);
}
}
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -680,12 +680,6 @@
cpi->mode_chosen_counts[i] = 0;
}
- // Initialize cpi->max_mv_magnitude if appropriate.
- if ((cpi->common.frame_type == KEY_FRAME) || cpi->common.intra_only ||
- (cpi->common.show_frame == 0)) {
- cpi->max_mv_magnitude = 0;
- }
-
// best quality defaults
sf->RD = 1;
sf->search_method = NSTEP;
@@ -747,7 +741,6 @@
#else
sf->static_segmentation = 0;
#endif
- sf->auto_mv_step_size = 1;
sf->use_avoid_tested_higherror = 1;
sf->adaptive_rd_thresh = 1;
sf->last_chroma_intra_mode = TM_PRED;
@@ -772,6 +765,7 @@
sf->last_chroma_intra_mode = H_PRED;
sf->use_rd_breakout = 1;
sf->skip_encode_sb = 1;
+ sf->auto_mv_step_size = 1;
}
if (speed == 2) {
sf->adjust_thresholds_by_speed = 1;
@@ -798,6 +792,7 @@
sf->using_small_partition_info = 1;
sf->disable_splitmv =
(MIN(cpi->common.width, cpi->common.height) >= 720)? 1 : 0;
+ sf->auto_mv_step_size = 1;
}
if (speed == 3) {
sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
@@ -814,6 +809,7 @@
sf->use_rd_breakout = 1;
sf->skip_encode_sb = 1;
sf->disable_splitmv = 1;
+ sf->auto_mv_step_size = 1;
}
if (speed == 4) {
sf->comp_inter_joint_search_thresh = BLOCK_SIZE_TYPES;
@@ -830,6 +826,7 @@
FLAG_SKIP_COMP_REFMISMATCH;
sf->use_rd_breakout = 1;
sf->optimize_coefficients = 0;
+ sf->auto_mv_step_size = 1;
// sf->reduce_first_step_size = 1;
// sf->reference_masking = 1;
@@ -2489,6 +2486,7 @@
int undershoot_seen = 0;
SPEED_FEATURES *sf = &cpi->sf;
+ unsigned int max_mv_def = MIN(cpi->common.width, cpi->common.height);
#if RESET_FOREACH_FILTER
int q_low0;
int q_high0;
@@ -2561,6 +2559,24 @@
// Set default state for segment based loop filter update flags
xd->mode_ref_lf_delta_update = 0;
+ // Initialize cpi->mv_step_param to default based on max resolution
+ cpi->mv_step_param = vp9_init_search_range(cpi, max_mv_def);
+ // Initialize cpi->max_mv_magnitude and cpi->mv_step_param if appropriate.
+ if (sf->auto_mv_step_size) {
+ if ((cpi->common.frame_type == KEY_FRAME) || cpi->common.intra_only) {
+ // initialize max_mv_magnitude for use in the first INTER frame
+ // after a key/intra-only frame
+ cpi->max_mv_magnitude = max_mv_def;
+ } else {
+ if (cm->show_frame)
+ // allow mv_steps to correspond to twice the max mv magnitude found
+ // in the previous frame, capped by the default max_mv_magnitude based
+ // on resolution
+ cpi->mv_step_param = vp9_init_search_range(
+ cpi, MIN(max_mv_def, 2 * cpi->max_mv_magnitude));
+ cpi->max_mv_magnitude = 0;
+ }
+ }
// Set various flags etc to special state if it is a key frame
if (cm->frame_type == KEY_FRAME) {
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -505,6 +505,7 @@
int error_bins[1024];
unsigned int max_mv_magnitude;
+ int mv_step_param;
// Data used for real time conferencing mode to help determine if it would be good to update the gf
int inter_zz_count;
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -1940,9 +1940,24 @@
if (i == 2)
bsi->mvp.as_int =
x->e_mbd.mode_info_context->bmi[i - 2].as_mv[0].as_int;
- step_param = 2;
}
}
+ if (cpi->sf.auto_mv_step_size && cpi->common.show_frame) {
+ // Take wtd average of the step_params based on the last frame's
+ // max mv magnitude and the best ref mvs of the current block for
+ // the given reference.
+ if (i == 0)
+ step_param = (vp9_init_search_range(
+ cpi, x->max_mv_context[mbmi->ref_frame[0]]) +
+ cpi->mv_step_param) >> 1;
+ else
+ step_param = (vp9_init_search_range(
+ cpi, MAX(abs(bsi->mvp.as_mv.row),
+ abs(bsi->mvp.as_mv.col)) >> 3) +
+ cpi->mv_step_param) >> 1;
+ } else {
+ step_param = cpi->mv_step_param;
+ }
further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
@@ -2163,6 +2178,7 @@
int best_index = 0;
int best_sad = INT_MAX;
int this_sad = INT_MAX;
+ unsigned int max_mv = 0;
uint8_t *src_y_ptr = x->plane[0].src.buf;
uint8_t *ref_y_ptr;
@@ -2172,6 +2188,8 @@
for (i = 0; i < MAX_MV_REF_CANDIDATES; i++) {
this_mv.as_int = mbmi->ref_mvs[ref_frame][i].as_int;
+ max_mv = MAX(max_mv,
+ MAX(abs(this_mv.as_mv.row), abs(this_mv.as_mv.col)) >> 3);
// The list is at an end if we see 0 for a second time.
if (!this_mv.as_int && zero_seen)
break;
@@ -2195,6 +2213,7 @@
// Note the index of the mv that worked best in the reference list.
x->mv_best_ref_index[ref_frame] = best_index;
+ x->max_mv_context[ref_frame] = max_mv;
}
static void estimate_ref_frame_costs(VP9_COMP *cpi, int segment_id,
@@ -2441,12 +2460,14 @@
// Work out the size of the first step in the mv step search.
// 0 here is maximum length first step. 1 is MAX >> 1 etc.
if (cpi->sf.auto_mv_step_size && cpi->common.show_frame) {
- step_param = vp9_init_search_range(cpi, cpi->max_mv_magnitude);
+ // Take wtd average of the step_params based on the last frame's
+ // max mv magnitude and that based on the best ref mvs of the current
+ // block for the given reference.
+ step_param = (vp9_init_search_range(cpi, x->max_mv_context[ref]) +
+ cpi->mv_step_param) >> 1;
} else {
- step_param = vp9_init_search_range(
- cpi, MIN(cpi->common.width, cpi->common.height));
+ step_param = cpi->mv_step_param;
}
-
// mvp_full.as_int = ref_mv[0].as_int;
mvp_full.as_int =
mbmi->ref_mvs[ref][x->mv_best_ref_index[ref]].as_int;