From fec5988657cfb810072d657dd545c20036ba9fa1 Mon Sep 17 00:00:00 2001 From: Jingning Han Date: Fri, 19 Feb 2016 11:53:24 -0800 Subject: [PATCH] Unify motion vector cost system This commit unifies the motion vector cost buffers for full pixel and sub-pixel motion search. The new motion vector coding system provides 0.5% coding gains for 720p and above sequences and 0.2% for lower resolution sets. Change-Id: I927ec81eadc39d11a3c12b375221a1ddd2e8bf24 --- vp10/encoder/block.h | 4 ++-- vp10/encoder/encoder.c | 4 +++- vp10/encoder/mcomp.c | 10 ++++++++++ vp10/encoder/rd.c | 4 ++++ vp10/encoder/temporal_filter.c | 7 +++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/vp10/encoder/block.h b/vp10/encoder/block.h index aa9139398..0c3e48fea 100644 --- a/vp10/encoder/block.h +++ b/vp10/encoder/block.h @@ -113,15 +113,15 @@ struct macroblock { int *nmvcost[NMV_CONTEXTS][2]; int *nmvcost_hp[NMV_CONTEXTS][2]; int **mv_cost_stack[NMV_CONTEXTS]; + int *nmvjointsadcost; #else int nmvjointcost[MV_JOINTS]; int *nmvcost[2]; int *nmvcost_hp[2]; + int nmvjointsadcost[MV_JOINTS]; #endif int **mvcost; - - int nmvjointsadcost[MV_JOINTS]; int *nmvsadcost[2]; int *nmvsadcost_hp[2]; int **mvsadcost; diff --git a/vp10/encoder/encoder.c b/vp10/encoder/encoder.c index 1ecd668ee..cadd53b53 100644 --- a/vp10/encoder/encoder.c +++ b/vp10/encoder/encoder.c @@ -1627,12 +1627,14 @@ void vp10_change_config(struct VP10_COMP *cpi, const VP10EncoderConfig *oxcf) { #endif #define log2f(x) (log (x) / (float) M_LOG2_E) +#if !CONFIG_REF_MV static void cal_nmvjointsadcost(int *mvjointsadcost) { mvjointsadcost[0] = 600; mvjointsadcost[1] = 300; mvjointsadcost[2] = 300; mvjointsadcost[3] = 300; } +#endif static void cal_nmvsadcosts(int *mvsadcost[2]) { int i = 1; @@ -1794,7 +1796,6 @@ VP10_COMP *vp10_create_compressor(VP10EncoderConfig *oxcf, cpi->first_time_stamp_ever = INT64_MAX; - cal_nmvjointsadcost(cpi->td.mb.nmvjointsadcost); #if CONFIG_REF_MV for (i = 0; i < NMV_CONTEXTS; ++i) { cpi->td.mb.nmvcost[i][0] = &cpi->nmv_costs[i][0][MV_MAX]; @@ -1803,6 +1804,7 @@ VP10_COMP *vp10_create_compressor(VP10EncoderConfig *oxcf, cpi->td.mb.nmvcost_hp[i][1] = &cpi->nmv_costs_hp[i][1][MV_MAX]; } #else + cal_nmvjointsadcost(cpi->td.mb.nmvjointsadcost); cpi->td.mb.nmvcost[0] = &cpi->nmvcosts[0][MV_MAX]; cpi->td.mb.nmvcost[1] = &cpi->nmvcosts[1][MV_MAX]; cpi->td.mb.nmvcost_hp[0] = &cpi->nmvcosts_hp[0][MV_MAX]; diff --git a/vp10/encoder/mcomp.c b/vp10/encoder/mcomp.c index dd19e029f..6e3b06ab9 100644 --- a/vp10/encoder/mcomp.c +++ b/vp10/encoder/mcomp.c @@ -97,12 +97,22 @@ static int mv_err_cost(const MV *mv, const MV *ref, const int *mvjcost, static int mvsad_err_cost(const MACROBLOCK *x, const MV *mv, const MV *ref, int sad_per_bit) { +#if CONFIG_REF_MV + const MV diff = { (mv->row - ref->row) << 3, + (mv->col - ref->col) << 3 }; + return ROUND_POWER_OF_TWO( + (unsigned)mv_cost(&diff, x->nmvjointsadcost, x->mvsadcost) * + sad_per_bit, + VP9_PROB_COST_SHIFT); +#else const MV diff = { mv->row - ref->row, mv->col - ref->col }; + return ROUND_POWER_OF_TWO( (unsigned)mv_cost(&diff, x->nmvjointsadcost, x->nmvsadcost) * sad_per_bit, VP9_PROB_COST_SHIFT); +#endif } void vp10_init_dsmotion_compensation(search_site_config *cfg, int stride) { diff --git a/vp10/encoder/rd.c b/vp10/encoder/rd.c index 77fc16228..299b7612b 100644 --- a/vp10/encoder/rd.c +++ b/vp10/encoder/rd.c @@ -338,6 +338,8 @@ void vp10_set_mvcost(MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame) { mbmi_ext->ref_mv_stack[ref_frame]); x->mvcost = x->mv_cost_stack[nmv_ctx]; x->nmvjointcost = x->nmv_vec_cost[nmv_ctx]; + x->mvsadcost = x->mvcost; + x->nmvjointsadcost = x->nmvjointcost; } #endif @@ -382,6 +384,8 @@ void vp10_initialize_rd_consts(VP10_COMP *cpi) { } x->mvcost = x->mv_cost_stack[0]; x->nmvjointcost = x->nmv_vec_cost[0]; + x->mvsadcost = x->mvcost; + x->nmvjointsadcost = x->nmvjointcost; #else vp10_build_nmv_cost_table(x->nmvjointcost, cm->allow_high_precision_mv ? x->nmvcost_hp diff --git a/vp10/encoder/temporal_filter.c b/vp10/encoder/temporal_filter.c index 035b66abf..afe555d5a 100644 --- a/vp10/encoder/temporal_filter.c +++ b/vp10/encoder/temporal_filter.c @@ -293,6 +293,13 @@ static int temporal_filter_find_matching_mb_c(VP10_COMP *cpi, step_param = mv_sf->reduce_first_step_size; step_param = VPXMIN(step_param, MAX_MVSEARCH_STEPS - 2); +#if CONFIG_REF_MV + x->mvcost = x->mv_cost_stack[0]; + x->nmvjointcost = x->nmv_vec_cost[0]; + x->mvsadcost = x->mvcost; + x->nmvjointsadcost = x->nmvjointcost; +#endif + // Ignore mv costing by sending NULL pointer instead of cost arrays vp10_hex_search(x, &best_ref_mv1_full, step_param, sadpb, 1, cond_cost_list(cpi, cost_list), -- 2.40.0