From bead2e8fb455ae770379f9ac1a21553db7765889 Mon Sep 17 00:00:00 2001 From: Deb Mukherjee Date: Fri, 7 Mar 2014 17:15:09 -0800 Subject: [PATCH] Support for a fast diamond search Adds a fast diamond search which is about 5% faster than FAST_HEX with only a 0.1% drop in psnr when turned on for both speeds 5 and 7. This search is turned on for speed 7. Change-Id: I497630aa88a5148926086bb3038e7975e5f4eb98 --- vp9/encoder/vp9_mcomp.c | 14 ++++++++++++++ vp9/encoder/vp9_mcomp.h | 1 + vp9/encoder/vp9_onyx_if.c | 2 +- vp9/encoder/vp9_onyx_int.h | 3 ++- vp9/encoder/vp9_pickmode.c | 7 ++++++- vp9/encoder/vp9_rdopt.c | 9 ++++++++- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index 158bb6849..3ff4a672d 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -884,6 +884,20 @@ int vp9_fast_hex_search(const MACROBLOCK *x, center_mv, best_mv); } +int vp9_fast_dia_search(const MACROBLOCK *x, + MV *ref_mv, + int search_param, + int sad_per_bit, + int do_init_search, + const vp9_variance_fn_ptr_t *vfp, + int use_mvcost, + const MV *center_mv, + MV *best_mv) { + return vp9_bigdia_search(x, ref_mv, MAX(MAX_MVSEARCH_STEPS - 2, search_param), + sad_per_bit, do_init_search, vfp, use_mvcost, + center_mv, best_mv); +} + #undef CHECK_BETTER int vp9_full_range_search_c(const MACROBLOCK *x, MV *ref_mv, MV *best_mv, diff --git a/vp9/encoder/vp9_mcomp.h b/vp9/encoder/vp9_mcomp.h index 39360f1b4..e1e149e5f 100644 --- a/vp9/encoder/vp9_mcomp.h +++ b/vp9/encoder/vp9_mcomp.h @@ -76,6 +76,7 @@ integer_mv_pattern_search_fn vp9_hex_search; integer_mv_pattern_search_fn vp9_bigdia_search; integer_mv_pattern_search_fn vp9_square_search; integer_mv_pattern_search_fn vp9_fast_hex_search; +integer_mv_pattern_search_fn vp9_fast_dia_search; typedef int (fractional_mv_step_fp) ( const MACROBLOCK *x, diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index 61881d8ae..318e7168f 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -872,7 +872,7 @@ static void set_rt_speed_feature(VP9_COMMON *cm, if (speed >= 7) { sf->partition_search_type = VAR_BASED_FIXED_PARTITION; sf->use_nonrd_pick_mode = 1; - sf->search_method = FAST_HEX; + sf->search_method = FAST_DIAMOND; } if (speed >= 8) { int i; diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index a8e7b69e2..4ee035b37 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -137,7 +137,8 @@ typedef enum { HEX = 2, BIGDIA = 3, SQUARE = 4, - FAST_HEX = 5 + FAST_HEX = 5, + FAST_DIAMOND = 6 } SEARCH_METHODS; typedef enum { diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index 92409a179..9ece4593d 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -86,7 +86,12 @@ static int full_pixel_motion_search(VP9_COMP *cpi, MACROBLOCK *x, mvp_full.col >>= 3; mvp_full.row >>= 3; - if (cpi->sf.search_method == FAST_HEX) { + if (cpi->sf.search_method == FAST_DIAMOND) { + // NOTE: this returns SAD + vp9_fast_dia_search(x, &mvp_full, step_param, sadpb, 0, + &cpi->fn_ptr[bsize], 1, + &ref_mv, &tmp_mv->as_mv); + } else if (cpi->sf.search_method == FAST_HEX) { // NOTE: this returns SAD vp9_fast_hex_search(x, &mvp_full, step_param, sadpb, 0, &cpi->fn_ptr[bsize], 1, diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 7b14fdd63..4be4c50d1 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -2457,7 +2457,14 @@ static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, // Further step/diamond searches as necessary further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; - if (cpi->sf.search_method == FAST_HEX) { + if (cpi->sf.search_method == FAST_DIAMOND) { + bestsme = vp9_fast_dia_search(x, &mvp_full, step_param, sadpb, 0, + &cpi->fn_ptr[bsize], 1, + &ref_mv, &tmp_mv->as_mv); + if (bestsme < INT_MAX) + bestsme = vp9_get_mvpred_var(x, &tmp_mv->as_mv, &ref_mv, + &cpi->fn_ptr[bsize], 1); + } else if (cpi->sf.search_method == FAST_HEX) { bestsme = vp9_fast_hex_search(x, &mvp_full, step_param, sadpb, 0, &cpi->fn_ptr[bsize], 1, &ref_mv, &tmp_mv->as_mv); -- 2.40.0