ref: 6c98df29e4157b3508cf506e9056a7129439ef92
parent: 63fb34c9bc6114c6ab8b4250177ff6197edacf25
author: Dmitry Kovalev <dkovalev@google.com>
date: Thu Jan 23 12:15:30 EST 2014
Cleaning up motion compensation code. Change-Id: I74cf028e8c732cd0dbc070326152d3085b824a80
--- a/vp9/common/vp9_rtcd_defs.sh
+++ b/vp9/common/vp9_rtcd_defs.sh
@@ -737,7 +737,7 @@
#
# Motion search
#
-prototype int vp9_full_search_sad "struct macroblock *x, struct mv *ref_mv, int sad_per_bit, int distance, struct vp9_variance_vtable *fn_ptr, DEC_MVCOSTS, const struct mv *center_mv, int n"
+prototype int vp9_full_search_sad "const struct macroblock *x, struct mv *ref_mv, int sad_per_bit, int distance, struct vp9_variance_vtable *fn_ptr, DEC_MVCOSTS, const struct mv *center_mv, int n"
specialize vp9_full_search_sad sse3 sse4_1
vp9_full_search_sad_sse3=vp9_full_search_sadx3
vp9_full_search_sad_sse4_1=vp9_full_search_sadx8
@@ -746,11 +746,11 @@
specialize vp9_refining_search_sad sse3
vp9_refining_search_sad_sse3=vp9_refining_search_sadx4
-prototype int vp9_diamond_search_sad "struct macroblock *x, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, struct vp9_variance_vtable *fn_ptr, DEC_MVCOSTS, const struct mv *center_mv"
+prototype int vp9_diamond_search_sad "const struct macroblock *x, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, struct vp9_variance_vtable *fn_ptr, DEC_MVCOSTS, const struct mv *center_mv"
specialize vp9_diamond_search_sad sse3
vp9_diamond_search_sad_sse3=vp9_diamond_search_sadx4
-prototype int vp9_full_range_search "struct macroblock *x, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, struct vp9_variance_vtable *fn_ptr, DEC_MVCOSTS, const struct mv *center_mv"
+prototype int vp9_full_range_search "const struct macroblock *x, struct mv *ref_mv, struct mv *best_mv, int search_param, int sad_per_bit, int *num00, struct vp9_variance_vtable *fn_ptr, DEC_MVCOSTS, const struct mv *center_mv"
specialize vp9_full_range_search
prototype void vp9_temporal_filter_apply "uint8_t *frame1, unsigned int stride, uint8_t *frame2, unsigned int block_size, int strength, int filter_weight, unsigned int *accumulator, uint16_t *count"
--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -517,7 +517,7 @@
// Each scale can have a different number of candidates and shape of
// candidates as indicated in the num_candidates and candidates arrays
// passed into this function
-static int vp9_pattern_search(MACROBLOCK *x,
+static int vp9_pattern_search(const MACROBLOCK *x,
MV *ref_mv,
int search_param,
int sad_per_bit,
@@ -529,14 +529,14 @@
const int num_candidates[MAX_PATTERN_SCALES],
const MV candidates[MAX_PATTERN_SCALES]
[MAX_PATTERN_CANDIDATES]) {- const MACROBLOCKD* const xd = &x->e_mbd;
+ const MACROBLOCKD *const xd = &x->e_mbd;
static const int search_param_to_steps[MAX_MVSEARCH_STEPS] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
};
int i, j, s, t;
- uint8_t *what = x->plane[0].src.buf;
- int what_stride = x->plane[0].src.stride;
- int in_what_stride = xd->plane[0].pre[0].stride;
+ const uint8_t *what = x->plane[0].src.buf;
+ const int what_stride = x->plane[0].src.stride;
+ const int in_what_stride = xd->plane[0].pre[0].stride;
int br, bc;
MV this_mv;
int bestsad = INT_MAX;
@@ -545,14 +545,11 @@
uint8_t *this_offset;
int k = -1;
int best_site = -1;
- MV fcenter_mv;
+ MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};int best_init_s = search_param_to_steps[search_param];
- int *mvjsadcost = x->nmvjointsadcost;
+ const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};- fcenter_mv.row = center_mv->row >> 3;
- fcenter_mv.col = center_mv->col >> 3;
-
// adjust ref_mv to make sure it is within MV range
clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
br = ref_mv->row;
@@ -692,9 +689,7 @@
// Check 4 1-away neighbors if do_refine is true.
// For most well-designed schemes do_refine will not be necessary.
if (do_refine) {- static const MV neighbors[4] = {- {0, -1}, { -1, 0}, {1, 0}, {0, 1},- };
+ static const MV neighbors[4] = { {0, -1}, { -1, 0}, {1, 0}, {0, 1} }; for (j = 0; j < 16; j++) {best_site = -1;
if (check_bounds(x, br, bc, 1)) {@@ -701,8 +696,8 @@
for (i = 0; i < 4; i++) {this_mv.row = br + neighbors[i].row;
this_mv.col = bc + neighbors[i].col;
- this_offset = base_offset + (this_mv.row * (in_what_stride)) +
- this_mv.col;
+ this_offset = base_offset + this_mv.row * in_what_stride +
+ this_mv.col;
thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
bestsad);
CHECK_BETTER
@@ -713,8 +708,8 @@
this_mv.col = bc + neighbors[i].col;
if (check_point(x, &this_mv))
continue;
- this_offset = base_offset + (this_mv.row * (in_what_stride)) +
- this_mv.col;
+ this_offset = base_offset + this_mv.row * in_what_stride +
+ this_mv.col;
thissad = vfp->sdf(what, what_stride, this_offset, in_what_stride,
bestsad);
CHECK_BETTER
@@ -867,11 +862,11 @@
#undef CHECK_BETTER
-int vp9_full_range_search_c(MACROBLOCK *x, MV *ref_mv, MV *best_mv,
+int vp9_full_range_search_c(const MACROBLOCK *x, MV *ref_mv, MV *best_mv,
int search_param, int sad_per_bit, int *num00,
vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
int *mvcost[2], const MV *center_mv) {- const MACROBLOCKD* const xd = &x->e_mbd;
+ const MACROBLOCKD *const xd = &x->e_mbd;
uint8_t *what = x->plane[0].src.buf;
int what_stride = x->plane[0].src.stride;
uint8_t *in_what;
@@ -885,9 +880,9 @@
uint8_t *check_here;
int thissad;
- MV fcenter_mv;
+ const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};- int *mvjsadcost = x->nmvjointsadcost;
+ const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};int tr, tc;
@@ -899,9 +894,6 @@
int start_row, end_row;
int i;
- fcenter_mv.row = center_mv->row >> 3;
- fcenter_mv.col = center_mv->col >> 3;
-
clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
ref_row = ref_mv->row;
ref_col = ref_mv->col;
@@ -986,7 +978,7 @@
mvjcost, mvcost, x->errorperbit);
}
-int vp9_diamond_search_sad_c(MACROBLOCK *x,
+int vp9_diamond_search_sad_c(const MACROBLOCK *x,
MV *ref_mv, MV *best_mv,
int search_param, int sad_per_bit, int *num00,
vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
@@ -993,11 +985,11 @@
int *mvcost[2], const MV *center_mv) {int i, j, step;
- const MACROBLOCKD* const xd = &x->e_mbd;
- uint8_t *what = x->plane[0].src.buf;
- int what_stride = x->plane[0].src.stride;
+ const MACROBLOCKD *const xd = &x->e_mbd;
+ const uint8_t *what = x->plane[0].src.buf;
+ const int what_stride = x->plane[0].src.stride;
uint8_t *in_what;
- int in_what_stride = xd->plane[0].pre[0].stride;
+ const int in_what_stride = xd->plane[0].pre[0].stride;
uint8_t *best_address;
int tot_steps;
@@ -1013,14 +1005,11 @@
uint8_t *check_here;
int thissad;
- MV fcenter_mv;
+ MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};- int *mvjsadcost = x->nmvjointsadcost;
+ const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};- fcenter_mv.row = center_mv->row >> 3;
- fcenter_mv.col = center_mv->col >> 3;
-
clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
ref_row = ref_mv->row;
ref_col = ref_mv->col;
@@ -1127,7 +1116,7 @@
mvjcost, mvcost, x->errorperbit);
}
-int vp9_diamond_search_sadx4(MACROBLOCK *x,
+int vp9_diamond_search_sadx4(const MACROBLOCK *x,
MV *ref_mv, MV *best_mv, int search_param,
int sad_per_bit, int *num00,
vp9_variance_fn_ptr_t *fn_ptr,
@@ -1135,7 +1124,7 @@
const MV *center_mv) {int i, j, step;
- const MACROBLOCKD* const xd = &x->e_mbd;
+ const MACROBLOCKD *const xd = &x->e_mbd;
uint8_t *what = x->plane[0].src.buf;
int what_stride = x->plane[0].src.stride;
uint8_t *in_what;
@@ -1157,14 +1146,11 @@
uint8_t *check_here;
unsigned int thissad;
- MV fcenter_mv;
+ const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};- int *mvjsadcost = x->nmvjointsadcost;
+ const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};- fcenter_mv.row = center_mv->row >> 3;
- fcenter_mv.col = center_mv->col >> 3;
-
clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
ref_row = ref_mv->row;
ref_col = ref_mv->col;
@@ -1374,7 +1360,7 @@
return bestsme;
}
-int vp9_full_search_sad_c(MACROBLOCK *x, MV *ref_mv,
+int vp9_full_search_sad_c(const MACROBLOCK *x, MV *ref_mv,
int sad_per_bit, int distance,
vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
int *mvcost[2],
@@ -1384,7 +1370,6 @@
const int what_stride = x->plane[0].src.stride;
const uint8_t *const in_what = xd->plane[0].pre[0].buf;
const int in_what_stride = xd->plane[0].pre[0].stride;
- const uint8_t *bestaddress;
MV *best_mv = &x->e_mbd.mi_8x8[0]->bmi[n].as_mv[0].as_mv;
MV this_mv;
int bestsad = INT_MAX;
@@ -1392,20 +1377,18 @@
int thissad;
int ref_row = ref_mv->row;
int ref_col = ref_mv->col;
- int row_min = ref_row - distance;
- int row_max = ref_row + distance;
- int col_min = ref_col - distance;
- int col_max = ref_col + distance;
- MV fcenter_mv;
-
- int *mvjsadcost = x->nmvjointsadcost;
+ // Apply further limits to prevent us looking using vectors that stretch
+ // beyond the UMV border
+ const int row_min = MAX(ref_row - distance, x->mv_row_min);
+ const int row_max = MIN(ref_row + distance, x->mv_row_max);
+ const int col_min = MAX(ref_col - distance, x->mv_col_min);
+ const int col_max = MIN(ref_col + distance, x->mv_col_max);
+ const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};+ const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};- fcenter_mv.row = center_mv->row >> 3;
- fcenter_mv.col = center_mv->col >> 3;
-
// Work out the mid point for the search
- bestaddress = &in_what[ref_row * in_what_stride + ref_col];
+ const uint8_t *bestaddress = &in_what[ref_row * in_what_stride + ref_col];
best_mv->row = ref_row;
best_mv->col = ref_col;
@@ -1416,13 +1399,6 @@
+ mvsad_err_cost(best_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit);
- // Apply further limits to prevent us looking using vectors that stretch
- // beyond the UMV border
- col_min = MAX(col_min, x->mv_col_min);
- col_max = MIN(col_max, x->mv_col_max);
- row_min = MAX(row_min, x->mv_row_min);
- row_max = MIN(row_max, x->mv_row_max);
-
for (r = row_min; r < row_max; r++) {const uint8_t *check_here = &in_what[r * in_what_stride + col_min];
this_mv.row = r;
@@ -1458,7 +1434,7 @@
return INT_MAX;
}
-int vp9_full_search_sadx3(MACROBLOCK *x, MV *ref_mv,
+int vp9_full_search_sadx3(const MACROBLOCK *x, MV *ref_mv,
int sad_per_bit, int distance,
vp9_variance_fn_ptr_t *fn_ptr, int *mvjcost,
int *mvcost[2], const MV *center_mv, int n) {@@ -1467,7 +1443,6 @@
const int what_stride = x->plane[0].src.stride;
const uint8_t *const in_what = xd->plane[0].pre[0].buf;
const int in_what_stride = xd->plane[0].pre[0].stride;
- const uint8_t *bestaddress;
MV *best_mv = &x->e_mbd.mi_8x8[0]->bmi[n].as_mv[0].as_mv;
MV this_mv;
unsigned int bestsad = INT_MAX;
@@ -1475,20 +1450,20 @@
unsigned int thissad;
int ref_row = ref_mv->row;
int ref_col = ref_mv->col;
- int row_min = ref_row - distance;
- int row_max = ref_row + distance;
- int col_min = ref_col - distance;
- int col_max = ref_col + distance;
+
+ // Apply further limits to prevent us looking using vectors that stretch
+ // beyond the UMV border
+ const int row_min = MAX(ref_row - distance, x->mv_row_min);
+ const int row_max = MIN(ref_row + distance, x->mv_row_max);
+ const int col_min = MAX(ref_col - distance, x->mv_col_min);
+ const int col_max = MIN(ref_col + distance, x->mv_col_max);
unsigned int sad_array[3];
- MV fcenter_mv;
- int *mvjsadcost = x->nmvjointsadcost;
+ const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};+ const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};- fcenter_mv.row = center_mv->row >> 3;
- fcenter_mv.col = center_mv->col >> 3;
-
// Work out the mid point for the search
- bestaddress = &in_what[ref_row * in_what_stride + ref_col];
+ const uint8_t *bestaddress = &in_what[ref_row * in_what_stride + ref_col];
best_mv->row = ref_row;
best_mv->col = ref_col;
@@ -1499,13 +1474,6 @@
+ mvsad_err_cost(best_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit);
- // Apply further limits to prevent us looking using vectors that stretch
- // beyond the UMV border
- col_min = MAX(col_min, x->mv_col_min);
- col_max = MIN(col_max, x->mv_col_max);
- row_min = MAX(row_min, x->mv_row_min);
- row_max = MIN(row_max, x->mv_row_max);
-
for (r = row_min; r < row_max; r++) {const uint8_t *check_here = &in_what[r * in_what_stride + col_min];
this_mv.row = r;
@@ -1571,7 +1539,7 @@
return INT_MAX;
}
-int vp9_full_search_sadx8(MACROBLOCK *x, MV *ref_mv,
+int vp9_full_search_sadx8(const MACROBLOCK *x, MV *ref_mv,
int sad_per_bit, int distance,
vp9_variance_fn_ptr_t *fn_ptr,
int *mvjcost, int *mvcost[2],
@@ -1581,7 +1549,6 @@
const int what_stride = x->plane[0].src.stride;
const uint8_t *const in_what = xd->plane[0].pre[0].buf;
const int in_what_stride = xd->plane[0].pre[0].stride;
- const uint8_t *bestaddress;
MV *best_mv = &x->e_mbd.mi_8x8[0]->bmi[n].as_mv[0].as_mv;
MV this_mv;
unsigned int bestsad = INT_MAX;
@@ -1589,22 +1556,22 @@
unsigned int thissad;
int ref_row = ref_mv->row;
int ref_col = ref_mv->col;
- int row_min = ref_row - distance;
- int row_max = ref_row + distance;
- int col_min = ref_col - distance;
- int col_max = ref_col + distance;
+
+ // Apply further limits to prevent us looking using vectors that stretch
+ // beyond the UMV border
+ const int row_min = MAX(ref_row - distance, x->mv_row_min);
+ const int row_max = MIN(ref_row + distance, x->mv_row_max);
+ const int col_min = MAX(ref_col - distance, x->mv_col_min);
+ const int col_max = MIN(ref_col + distance, x->mv_col_max);
DECLARE_ALIGNED_ARRAY(16, uint32_t, sad_array8, 8);
unsigned int sad_array[3];
- MV fcenter_mv;
+ const MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};- int *mvjsadcost = x->nmvjointsadcost;
+ const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};- fcenter_mv.row = center_mv->row >> 3;
- fcenter_mv.col = center_mv->col >> 3;
-
// Work out the mid point for the search
- bestaddress = &in_what[ref_row * in_what_stride + ref_col];
+ const uint8_t *bestaddress = &in_what[ref_row * in_what_stride + ref_col];
best_mv->row = ref_row;
best_mv->col = ref_col;
@@ -1615,13 +1582,6 @@
+ mvsad_err_cost(best_mv, &fcenter_mv,
mvjsadcost, mvsadcost, sad_per_bit);
- // Apply further limits to prevent us looking using vectors that stretch
- // beyond the UMV border
- col_min = MAX(col_min, x->mv_col_min);
- col_max = MIN(col_max, x->mv_col_max);
- row_min = MAX(row_min, x->mv_row_min);
- row_max = MIN(row_max, x->mv_row_max);
-
for (r = row_min; r < row_max; r++) {const uint8_t *check_here = &in_what[r * in_what_stride + col_min];
this_mv.row = r;
@@ -1798,24 +1758,20 @@
int i, j;
int this_row_offset, this_col_offset;
- int what_stride = x->plane[0].src.stride;
- int in_what_stride = xd->plane[0].pre[0].stride;
- uint8_t *what = x->plane[0].src.buf;
- uint8_t *best_address = xd->plane[0].pre[0].buf +
+ const int what_stride = x->plane[0].src.stride;
+ const int in_what_stride = xd->plane[0].pre[0].stride;
+ const uint8_t *what = x->plane[0].src.buf;
+ const uint8_t *best_address = xd->plane[0].pre[0].buf +
(ref_mv->row * xd->plane[0].pre[0].stride) +
ref_mv->col;
- uint8_t *check_here;
unsigned int thissad;
MV this_mv;
unsigned int bestsad = INT_MAX;
- MV fcenter_mv;
+ MV fcenter_mv = {center_mv->row >> 3, center_mv->col >> 3};const int *mvjsadcost = x->nmvjointsadcost;
int *mvsadcost[2] = {x->nmvsadcost[0], x->nmvsadcost[1]};- fcenter_mv.row = center_mv->row >> 3;
- fcenter_mv.col = center_mv->col >> 3;
-
bestsad = fn_ptr->sdf(what, what_stride, best_address,
in_what_stride, 0x7fffffff) +
mvsad_err_cost(ref_mv, &fcenter_mv,
@@ -1830,11 +1786,12 @@
if (all_in) {unsigned int sad_array[4];
- unsigned char const *block_offset[4];
- block_offset[0] = best_address - in_what_stride;
- block_offset[1] = best_address - 1;
- block_offset[2] = best_address + 1;
- block_offset[3] = best_address + in_what_stride;
+ uint8_t const *block_offset[4] = {+ best_address - in_what_stride,
+ best_address - 1,
+ best_address + 1,
+ best_address + in_what_stride
+ };
fn_ptr->sdx4df(what, what_stride, block_offset, in_what_stride,
sad_array);
@@ -1861,8 +1818,8 @@
(this_col_offset < x->mv_col_max) &&
(this_row_offset > x->mv_row_min) &&
(this_row_offset < x->mv_row_max)) {- check_here = (neighbors[j].row) * in_what_stride + neighbors[j].col +
- best_address;
+ const uint8_t *check_here = neighbors[j].row * in_what_stride +
+ neighbors[j].col + best_address;
thissad = fn_ptr->sdf(what, what_stride, check_here, in_what_stride,
bestsad);
--- a/vp9/encoder/vp9_mcomp.h
+++ b/vp9/encoder/vp9_mcomp.h
@@ -102,7 +102,7 @@
extern fractional_mv_step_comp_fp vp9_find_best_sub_pixel_comp_tree;
-typedef int (*vp9_full_search_fn_t)(MACROBLOCK *x,
+typedef int (*vp9_full_search_fn_t)(const MACROBLOCK *x,
MV *ref_mv, int sad_per_bit,
int distance, vp9_variance_fn_ptr_t *fn_ptr,
int *mvjcost, int *mvcost[2],
@@ -115,7 +115,7 @@
int *mvjcost, int *mvcost[2],
const MV *center_mv);
-typedef int (*vp9_diamond_search_fn_t)(MACROBLOCK *x,
+typedef int (*vp9_diamond_search_fn_t)(const MACROBLOCK *x,
MV *ref_mv, MV *best_mv,
int search_param, int sad_per_bit,
int *num00,
--
⑨