Commit fec59886 authored by Jingning Han's avatar Jingning Han

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
parent 03c01bc3
......@@ -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;
......
......@@ -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];
......
......@@ -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) {
......
......@@ -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
......
......@@ -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),
......
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