summaryrefslogtreecommitdiff
path: root/vp9/encoder
diff options
context:
space:
mode:
authorDmitry Kovalev <dkovalev@google.com>2014-01-31 17:33:40 -0800
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2014-01-31 17:33:40 -0800
commitc2ca97caafc89e52f0083326753ed461abc7bd62 (patch)
treee47195e9fd45ac1b62679a671bfb400df87f3466 /vp9/encoder
parent389344945e699b532ab70bea9de340dacdd03b33 (diff)
parent6c98df29e4157b3508cf506e9056a7129439ef92 (diff)
downloadlibvpx-c2ca97caafc89e52f0083326753ed461abc7bd62.tar
libvpx-c2ca97caafc89e52f0083326753ed461abc7bd62.tar.gz
libvpx-c2ca97caafc89e52f0083326753ed461abc7bd62.tar.bz2
libvpx-c2ca97caafc89e52f0083326753ed461abc7bd62.zip
Merge "Cleaning up motion compensation code."
Diffstat (limited to 'vp9/encoder')
-rw-r--r--vp9/encoder/vp9_mcomp.c187
-rw-r--r--vp9/encoder/vp9_mcomp.h4
2 files changed, 74 insertions, 117 deletions
diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c
index d48daceca..4c4ac5dfa 100644
--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -511,7 +511,7 @@ static INLINE int check_point(const MACROBLOCK *x, const MV *mv) {
// 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,
@@ -523,14 +523,14 @@ static int vp9_pattern_search(MACROBLOCK *x,
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;
@@ -539,14 +539,11 @@ static int vp9_pattern_search(MACROBLOCK *x,
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;
@@ -686,17 +683,15 @@ static int vp9_pattern_search(MACROBLOCK *x,
// 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)) {
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
@@ -707,8 +702,8 @@ static int vp9_pattern_search(MACROBLOCK *x,
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
@@ -861,11 +856,11 @@ int vp9_square_search(MACROBLOCK *x,
#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;
@@ -879,9 +874,9 @@ int vp9_full_range_search_c(MACROBLOCK *x, MV *ref_mv, MV *best_mv,
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;
@@ -893,9 +888,6 @@ int vp9_full_range_search_c(MACROBLOCK *x, MV *ref_mv, MV *best_mv,
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;
@@ -980,18 +972,18 @@ int vp9_full_range_search_c(MACROBLOCK *x, MV *ref_mv, MV *best_mv,
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,
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;
@@ -1007,14 +999,11 @@ int vp9_diamond_search_sad_c(MACROBLOCK *x,
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;
@@ -1121,7 +1110,7 @@ int vp9_diamond_search_sad_c(MACROBLOCK *x,
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,
@@ -1129,7 +1118,7 @@ int vp9_diamond_search_sadx4(MACROBLOCK *x,
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;
@@ -1151,14 +1140,11 @@ int vp9_diamond_search_sadx4(MACROBLOCK *x,
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;
@@ -1368,7 +1354,7 @@ int vp9_full_pixel_diamond(VP9_COMP *cpi, MACROBLOCK *x,
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],
@@ -1378,7 +1364,6 @@ int vp9_full_search_sad_c(MACROBLOCK *x, MV *ref_mv,
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;
@@ -1386,20 +1371,18 @@ int vp9_full_search_sad_c(MACROBLOCK *x, MV *ref_mv,
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;
@@ -1410,13 +1393,6 @@ int vp9_full_search_sad_c(MACROBLOCK *x, MV *ref_mv,
+ 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;
@@ -1452,7 +1428,7 @@ int vp9_full_search_sad_c(MACROBLOCK *x, MV *ref_mv,
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) {
@@ -1461,7 +1437,6 @@ int vp9_full_search_sadx3(MACROBLOCK *x, MV *ref_mv,
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;
@@ -1469,20 +1444,20 @@ int vp9_full_search_sadx3(MACROBLOCK *x, MV *ref_mv,
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;
@@ -1493,13 +1468,6 @@ int vp9_full_search_sadx3(MACROBLOCK *x, MV *ref_mv,
+ 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;
@@ -1565,7 +1533,7 @@ int vp9_full_search_sadx3(MACROBLOCK *x, MV *ref_mv,
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],
@@ -1575,7 +1543,6 @@ int vp9_full_search_sadx8(MACROBLOCK *x, MV *ref_mv,
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;
@@ -1583,22 +1550,22 @@ int vp9_full_search_sadx8(MACROBLOCK *x, MV *ref_mv,
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;
@@ -1609,13 +1576,6 @@ int vp9_full_search_sadx8(MACROBLOCK *x, MV *ref_mv,
+ 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;
@@ -1792,24 +1752,20 @@ int vp9_refining_search_sadx4(const MACROBLOCK *x,
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,
@@ -1824,11 +1780,12 @@ int vp9_refining_search_sadx4(const MACROBLOCK *x,
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);
@@ -1855,8 +1812,8 @@ int vp9_refining_search_sadx4(const MACROBLOCK *x,
(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);
diff --git a/vp9/encoder/vp9_mcomp.h b/vp9/encoder/vp9_mcomp.h
index 5cd9fd170..c3a8be212 100644
--- a/vp9/encoder/vp9_mcomp.h
+++ b/vp9/encoder/vp9_mcomp.h
@@ -106,7 +106,7 @@ typedef int (fractional_mv_step_comp_fp) (
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],
@@ -119,7 +119,7 @@ typedef int (*vp9_refining_search_fn_t)(const MACROBLOCK *x,
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,