ref: 941fe20336d051a5b79623c110c7eb86b81467d1
parent: c37d012ada8e985adcfecbb4591d276f7e427eb0
parent: 6554333b59cf773983c7cacbd832d754f75139e8
author: Alex Converse <[email protected]>
date: Tue Aug 9 13:12:50 EDT 2016
Merge "Refactor mv limits."
--- a/vp9/encoder/vp9_block.h
+++ b/vp9/encoder/vp9_block.h
@@ -52,6 +52,13 @@
uint8_t mode_context[MAX_REF_FRAMES];
} MB_MODE_INFO_EXT;
+typedef struct {
+ int col_min;
+ int col_max;
+ int row_min;
+ int row_max;
+} MvLimits;
+
typedef struct macroblock MACROBLOCK;
struct macroblock {
struct macroblock_plane plane[MAX_MB_PLANE];
@@ -103,10 +110,7 @@
// These define limits to motion vector components to prevent them
// from extending outside the UMV borders
- int mv_col_min;
- int mv_col_max;
- int mv_row_min;
- int mv_row_max;
+ MvLimits mv_limits;
// Notes transform blocks where no coefficents are coded.
// Set during mode selection. Read during block encoding.
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -184,6 +184,7 @@
const int mi_width = num_8x8_blocks_wide_lookup[bsize];
const int mi_height = num_8x8_blocks_high_lookup[bsize];
const struct segmentation *const seg = &cm->seg;
+ MvLimits *const mv_limits = &x->mv_limits;
set_skip_context(xd, mi_row, mi_col);
@@ -196,10 +197,10 @@
// Set up limit values for MV components.
// Mv beyond the range do not produce new/different prediction block.
- x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND);
- x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND);
- x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND;
- x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND;
+ mv_limits->row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND);
+ mv_limits->col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND);
+ mv_limits->row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND;
+ mv_limits->col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND;
// Set up distance of MB to edge of frame in 1/8th pel units.
assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1)));
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -805,8 +805,9 @@
// Set up limit values for motion vectors to prevent them extending
// outside the UMV borders.
- x->mv_row_min = -((mb_row * 16) + BORDER_MV_PIXELS_B16);
- x->mv_row_max = ((cm->mb_rows - 1 - mb_row) * 16) + BORDER_MV_PIXELS_B16;
+ x->mv_limits.row_min = -((mb_row * 16) + BORDER_MV_PIXELS_B16);
+ x->mv_limits.row_max =
+ ((cm->mb_rows - 1 - mb_row) * 16) + BORDER_MV_PIXELS_B16;
for (mb_col = 0; mb_col < cm->mb_cols; ++mb_col) {
int this_error;
@@ -929,8 +930,9 @@
// Set up limit values for motion vectors to prevent them extending
// outside the UMV borders.
- x->mv_col_min = -((mb_col * 16) + BORDER_MV_PIXELS_B16);
- x->mv_col_max = ((cm->mb_cols - 1 - mb_col) * 16) + BORDER_MV_PIXELS_B16;
+ x->mv_limits.col_min = -((mb_col * 16) + BORDER_MV_PIXELS_B16);
+ x->mv_limits.col_max =
+ ((cm->mb_cols - 1 - mb_col) * 16) + BORDER_MV_PIXELS_B16;
// Other than for the first frame do a motion search.
if ((lc == NULL && cm->current_video_frame > 0) ||
--- a/vp9/encoder/vp9_mbgraph.c
+++ b/vp9/encoder/vp9_mbgraph.c
@@ -30,11 +30,7 @@
MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv;
const SEARCH_METHODS old_search_method = mv_sf->search_method;
const vp9_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[BLOCK_16X16];
-
- const int tmp_col_min = x->mv_col_min;
- const int tmp_col_max = x->mv_col_max;
- const int tmp_row_min = x->mv_row_min;
- const int tmp_row_max = x->mv_row_max;
+ const MvLimits tmp_mv_limits = x->mv_limits;
MV ref_full;
int cost_list[5];
@@ -42,7 +38,7 @@
int step_param = mv_sf->reduce_first_step_size;
step_param = VPXMIN(step_param, MAX_MVSEARCH_STEPS - 2);
- vp9_set_mv_search_range(x, ref_mv);
+ vp9_set_mv_search_range(&x->mv_limits, ref_mv);
ref_full.col = ref_mv->col >> 3;
ref_full.row = ref_mv->row >> 3;
@@ -71,10 +67,7 @@
vp9_build_inter_predictors_sby(xd, mb_row, mb_col, BLOCK_16X16);
/* restore UMV window */
- x->mv_col_min = tmp_col_min;
- x->mv_col_max = tmp_col_max;
- x->mv_row_min = tmp_row_min;
- x->mv_row_max = tmp_row_max;
+ x->mv_limits = tmp_mv_limits;
return vpx_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride,
xd->plane[0].dst.buf, xd->plane[0].dst.stride);
@@ -233,8 +226,8 @@
vp9_zero(mi_local);
// Set up limit values for motion vectors to prevent them extending outside
// the UMV borders.
- x->mv_row_min = -BORDER_MV_PIXELS_B16;
- x->mv_row_max = (cm->mb_rows - 1) * 8 + BORDER_MV_PIXELS_B16;
+ x->mv_limits.row_min = -BORDER_MV_PIXELS_B16;
+ x->mv_limits.row_max = (cm->mb_rows - 1) * 8 + BORDER_MV_PIXELS_B16;
// Signal to vp9_predict_intra_block() that above is not available
xd->above_mi = NULL;
@@ -254,8 +247,8 @@
// Set up limit values for motion vectors to prevent them extending outside
// the UMV borders.
- x->mv_col_min = -BORDER_MV_PIXELS_B16;
- x->mv_col_max = (cm->mb_cols - 1) * 8 + BORDER_MV_PIXELS_B16;
+ x->mv_limits.col_min = -BORDER_MV_PIXELS_B16;
+ x->mv_limits.col_max = (cm->mb_cols - 1) * 8 + BORDER_MV_PIXELS_B16;
// Signal to vp9_predict_intra_block() that left is not available
xd->left_mi = NULL;
@@ -274,8 +267,8 @@
mb_y_in_offset += 16;
gld_y_in_offset += 16;
arf_y_in_offset += 16;
- x->mv_col_min -= 16;
- x->mv_col_max -= 16;
+ x->mv_limits.col_min -= 16;
+ x->mv_limits.col_max -= 16;
}
// Signal to vp9_predict_intra_block() that above is available
@@ -284,8 +277,8 @@
mb_y_offset += buf->y_stride * 16;
gld_y_offset += golden_ref->y_stride * 16;
if (alt_ref) arf_y_offset += alt_ref->y_stride * 16;
- x->mv_row_min -= 16;
- x->mv_row_max -= 16;
+ x->mv_limits.row_min -= 16;
+ x->mv_limits.row_max -= 16;
offset += cm->mb_cols;
}
}
--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -33,7 +33,7 @@
return &buf->buf[mv->row * buf->stride + mv->col];
}
-void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv) {
+void vp9_set_mv_search_range(MvLimits *mv_limits, const MV *mv) {
int col_min = (mv->col >> 3) - MAX_FULL_PEL_VAL + (mv->col & 7 ? 1 : 0);
int row_min = (mv->row >> 3) - MAX_FULL_PEL_VAL + (mv->row & 7 ? 1 : 0);
int col_max = (mv->col >> 3) + MAX_FULL_PEL_VAL;
@@ -46,10 +46,10 @@
// Get intersection of UMV window and valid MV window to reduce # of checks
// in diamond search.
- if (x->mv_col_min < col_min) x->mv_col_min = col_min;
- if (x->mv_col_max > col_max) x->mv_col_max = col_max;
- if (x->mv_row_min < row_min) x->mv_row_min = row_min;
- if (x->mv_row_max > row_max) x->mv_row_max = row_max;
+ if (mv_limits->col_min < col_min) mv_limits->col_min = col_min;
+ if (mv_limits->col_max > col_max) mv_limits->col_max = col_max;
+ if (mv_limits->row_min < row_min) mv_limits->row_min = row_min;
+ if (mv_limits->row_max > row_max) mv_limits->row_max = row_max;
}
int vp9_init_search_range(int size) {
@@ -273,34 +273,34 @@
} \
}
-#define SETUP_SUBPEL_SEARCH \
- const uint8_t *const z = x->plane[0].src.buf; \
- const int src_stride = x->plane[0].src.stride; \
- const MACROBLOCKD *xd = &x->e_mbd; \
- unsigned int besterr = INT_MAX; \
- unsigned int sse; \
- unsigned int whichdir; \
- int thismse; \
- const unsigned int halfiters = iters_per_step; \
- const unsigned int quarteriters = iters_per_step; \
- const unsigned int eighthiters = iters_per_step; \
- const int y_stride = xd->plane[0].pre[0].stride; \
- const int offset = bestmv->row * y_stride + bestmv->col; \
- const uint8_t *const y = xd->plane[0].pre[0].buf; \
- \
- int rr = ref_mv->row; \
- int rc = ref_mv->col; \
- int br = bestmv->row * 8; \
- int bc = bestmv->col * 8; \
- int hstep = 4; \
- const int minc = VPXMAX(x->mv_col_min * 8, ref_mv->col - MV_MAX); \
- const int maxc = VPXMIN(x->mv_col_max * 8, ref_mv->col + MV_MAX); \
- const int minr = VPXMAX(x->mv_row_min * 8, ref_mv->row - MV_MAX); \
- const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX); \
- int tr = br; \
- int tc = bc; \
- \
- bestmv->row *= 8; \
+#define SETUP_SUBPEL_SEARCH \
+ const uint8_t *const z = x->plane[0].src.buf; \
+ const int src_stride = x->plane[0].src.stride; \
+ const MACROBLOCKD *xd = &x->e_mbd; \
+ unsigned int besterr = INT_MAX; \
+ unsigned int sse; \
+ unsigned int whichdir; \
+ int thismse; \
+ const unsigned int halfiters = iters_per_step; \
+ const unsigned int quarteriters = iters_per_step; \
+ const unsigned int eighthiters = iters_per_step; \
+ const int y_stride = xd->plane[0].pre[0].stride; \
+ const int offset = bestmv->row * y_stride + bestmv->col; \
+ const uint8_t *const y = xd->plane[0].pre[0].buf; \
+ \
+ int rr = ref_mv->row; \
+ int rc = ref_mv->col; \
+ int br = bestmv->row * 8; \
+ int bc = bestmv->col * 8; \
+ int hstep = 4; \
+ const int minc = VPXMAX(x->mv_limits.col_min * 8, ref_mv->col - MV_MAX); \
+ const int maxc = VPXMIN(x->mv_limits.col_max * 8, ref_mv->col + MV_MAX); \
+ const int minr = VPXMAX(x->mv_limits.row_min * 8, ref_mv->row - MV_MAX); \
+ const int maxr = VPXMIN(x->mv_limits.row_max * 8, ref_mv->row + MV_MAX); \
+ int tr = br; \
+ int tc = bc; \
+ \
+ bestmv->row *= 8; \
bestmv->col *= 8;
static unsigned int setup_center_error(
@@ -659,10 +659,10 @@
int bc = bestmv->col * 8;
int hstep = 4;
int iter, round = 3 - forced_stop;
- const int minc = VPXMAX(x->mv_col_min * 8, ref_mv->col - MV_MAX);
- const int maxc = VPXMIN(x->mv_col_max * 8, ref_mv->col + MV_MAX);
- const int minr = VPXMAX(x->mv_row_min * 8, ref_mv->row - MV_MAX);
- const int maxr = VPXMIN(x->mv_row_max * 8, ref_mv->row + MV_MAX);
+ const int minc = VPXMAX(x->mv_limits.col_min * 8, ref_mv->col - MV_MAX);
+ const int maxc = VPXMIN(x->mv_limits.col_max * 8, ref_mv->col + MV_MAX);
+ const int minr = VPXMAX(x->mv_limits.row_min * 8, ref_mv->row - MV_MAX);
+ const int maxr = VPXMIN(x->mv_limits.row_max * 8, ref_mv->row + MV_MAX);
int tr = br;
int tc = bc;
const MV *search_step = search_step_table;
@@ -779,15 +779,17 @@
#undef MVC
#undef CHECK_BETTER
-static INLINE int check_bounds(const MACROBLOCK *x, int row, int col,
+static INLINE int check_bounds(const MvLimits *mv_limits, int row, int col,
int range) {
- return ((row - range) >= x->mv_row_min) & ((row + range) <= x->mv_row_max) &
- ((col - range) >= x->mv_col_min) & ((col + range) <= x->mv_col_max);
+ return ((row - range) >= mv_limits->row_min) &
+ ((row + range) <= mv_limits->row_max) &
+ ((col - range) >= mv_limits->col_min) &
+ ((col + range) <= mv_limits->col_max);
}
-static INLINE int is_mv_in(const MACROBLOCK *x, const MV *mv) {
- return (mv->col >= x->mv_col_min) && (mv->col <= x->mv_col_max) &&
- (mv->row >= x->mv_row_min) && (mv->row <= x->mv_row_max);
+static INLINE int is_mv_in(const MvLimits *mv_limits, const MV *mv) {
+ return (mv->col >= mv_limits->col_min) && (mv->col <= mv_limits->col_max) &&
+ (mv->row >= mv_limits->row_min) && (mv->row <= mv_limits->row_max);
}
#define CHECK_BETTER \
@@ -827,7 +829,7 @@
fn_ptr->vf(what->buf, what->stride, get_buf_from_mv(in_what, &this_mv),
in_what->stride, &sse) +
mvsad_err_cost(x, &this_mv, &fcenter_mv, sadpb);
- if (check_bounds(x, br, bc, 1)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1)) {
for (i = 0; i < 4; i++) {
const MV this_mv = { br + neighbors[i].row, bc + neighbors[i].col };
cost_list[i + 1] = fn_ptr->vf(what->buf, what->stride,
@@ -839,7 +841,7 @@
} else {
for (i = 0; i < 4; i++) {
const MV this_mv = { br + neighbors[i].row, bc + neighbors[i].col };
- if (!is_mv_in(x, &this_mv))
+ if (!is_mv_in(&x->mv_limits, &this_mv))
cost_list[i + 1] = INT_MAX;
else
cost_list[i + 1] = fn_ptr->vf(what->buf, what->stride,
@@ -876,7 +878,8 @@
const MV fcenter_mv = { center_mv->row >> 3, center_mv->col >> 3 };
int best_init_s = search_param_to_steps[search_param];
// 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);
+ clamp_mv(ref_mv, x->mv_limits.col_min, x->mv_limits.col_max,
+ x->mv_limits.row_min, x->mv_limits.row_max);
br = ref_mv->row;
bc = ref_mv->col;
@@ -893,7 +896,7 @@
best_init_s = -1;
for (t = 0; t <= s; ++t) {
int best_site = -1;
- if (check_bounds(x, br, bc, 1 << t)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1 << t)) {
for (i = 0; i < num_candidates[t]; i++) {
const MV this_mv = { br + candidates[t][i].row,
bc + candidates[t][i].col };
@@ -906,7 +909,7 @@
for (i = 0; i < num_candidates[t]; i++) {
const MV this_mv = { br + candidates[t][i].row,
bc + candidates[t][i].col };
- if (!is_mv_in(x, &this_mv)) continue;
+ if (!is_mv_in(&x->mv_limits, &this_mv)) continue;
thissad =
vfp->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &this_mv), in_what->stride);
@@ -935,7 +938,7 @@
do {
// No need to search all 6 points the 1st time if initial search was used
if (!do_init_search || s != best_init_s) {
- if (check_bounds(x, br, bc, 1 << s)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1 << s)) {
for (i = 0; i < num_candidates[s]; i++) {
const MV this_mv = { br + candidates[s][i].row,
bc + candidates[s][i].col };
@@ -948,7 +951,7 @@
for (i = 0; i < num_candidates[s]; i++) {
const MV this_mv = { br + candidates[s][i].row,
bc + candidates[s][i].col };
- if (!is_mv_in(x, &this_mv)) continue;
+ if (!is_mv_in(&x->mv_limits, &this_mv)) continue;
thissad =
vfp->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &this_mv), in_what->stride);
@@ -972,7 +975,7 @@
next_chkpts_indices[1] = k;
next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1;
- if (check_bounds(x, br, bc, 1 << s)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1 << s)) {
for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
const MV this_mv = {
br + candidates[s][next_chkpts_indices[i]].row,
@@ -989,7 +992,7 @@
br + candidates[s][next_chkpts_indices[i]].row,
bc + candidates[s][next_chkpts_indices[i]].col
};
- if (!is_mv_in(x, &this_mv)) continue;
+ if (!is_mv_in(&x->mv_limits, &this_mv)) continue;
thissad =
vfp->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &this_mv), in_what->stride);
@@ -1045,7 +1048,8 @@
const MV fcenter_mv = { center_mv->row >> 3, center_mv->col >> 3 };
int best_init_s = search_param_to_steps[search_param];
// 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);
+ clamp_mv(ref_mv, x->mv_limits.col_min, x->mv_limits.col_max,
+ x->mv_limits.row_min, x->mv_limits.row_max);
br = ref_mv->row;
bc = ref_mv->col;
if (cost_list != NULL) {
@@ -1066,7 +1070,7 @@
best_init_s = -1;
for (t = 0; t <= s; ++t) {
int best_site = -1;
- if (check_bounds(x, br, bc, 1 << t)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1 << t)) {
for (i = 0; i < num_candidates[t]; i++) {
const MV this_mv = { br + candidates[t][i].row,
bc + candidates[t][i].col };
@@ -1079,7 +1083,7 @@
for (i = 0; i < num_candidates[t]; i++) {
const MV this_mv = { br + candidates[t][i].row,
bc + candidates[t][i].col };
- if (!is_mv_in(x, &this_mv)) continue;
+ if (!is_mv_in(&x->mv_limits, &this_mv)) continue;
thissad =
vfp->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &this_mv), in_what->stride);
@@ -1108,7 +1112,7 @@
for (; s >= do_sad; s--) {
if (!do_init_search || s != best_init_s) {
- if (check_bounds(x, br, bc, 1 << s)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1 << s)) {
for (i = 0; i < num_candidates[s]; i++) {
const MV this_mv = { br + candidates[s][i].row,
bc + candidates[s][i].col };
@@ -1121,7 +1125,7 @@
for (i = 0; i < num_candidates[s]; i++) {
const MV this_mv = { br + candidates[s][i].row,
bc + candidates[s][i].col };
- if (!is_mv_in(x, &this_mv)) continue;
+ if (!is_mv_in(&x->mv_limits, &this_mv)) continue;
thissad =
vfp->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &this_mv), in_what->stride);
@@ -1145,7 +1149,7 @@
next_chkpts_indices[1] = k;
next_chkpts_indices[2] = (k == num_candidates[s] - 1) ? 0 : k + 1;
- if (check_bounds(x, br, bc, 1 << s)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1 << s)) {
for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
const MV this_mv = {
br + candidates[s][next_chkpts_indices[i]].row,
@@ -1162,7 +1166,7 @@
br + candidates[s][next_chkpts_indices[i]].row,
bc + candidates[s][next_chkpts_indices[i]].col
};
- if (!is_mv_in(x, &this_mv)) continue;
+ if (!is_mv_in(&x->mv_limits, &this_mv)) continue;
thissad =
vfp->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &this_mv), in_what->stride);
@@ -1182,7 +1186,7 @@
if (s == 0) {
cost_list[0] = bestsad;
if (!do_init_search || s != best_init_s) {
- if (check_bounds(x, br, bc, 1 << s)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1 << s)) {
for (i = 0; i < num_candidates[s]; i++) {
const MV this_mv = { br + candidates[s][i].row,
bc + candidates[s][i].col };
@@ -1195,7 +1199,7 @@
for (i = 0; i < num_candidates[s]; i++) {
const MV this_mv = { br + candidates[s][i].row,
bc + candidates[s][i].col };
- if (!is_mv_in(x, &this_mv)) continue;
+ if (!is_mv_in(&x->mv_limits, &this_mv)) continue;
cost_list[i + 1] = thissad =
vfp->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &this_mv), in_what->stride);
@@ -1219,7 +1223,7 @@
cost_list[((k + 2) % 4) + 1] = cost_list[0];
cost_list[0] = bestsad;
- if (check_bounds(x, br, bc, 1 << s)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1 << s)) {
for (i = 0; i < PATTERN_CANDIDATES_REF; i++) {
const MV this_mv = {
br + candidates[s][next_chkpts_indices[i]].row,
@@ -1236,7 +1240,7 @@
br + candidates[s][next_chkpts_indices[i]].row,
bc + candidates[s][next_chkpts_indices[i]].col
};
- if (!is_mv_in(x, &this_mv)) {
+ if (!is_mv_in(&x->mv_limits, &this_mv)) {
cost_list[next_chkpts_indices[i] + 1] = INT_MAX;
continue;
}
@@ -1266,7 +1270,7 @@
static const MV neighbors[4] = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } };
if (cost_list[0] == INT_MAX) {
cost_list[0] = bestsad;
- if (check_bounds(x, br, bc, 1)) {
+ if (check_bounds(&x->mv_limits, br, bc, 1)) {
for (i = 0; i < 4; i++) {
const MV this_mv = { br + neighbors[i].row, bc + neighbors[i].col };
cost_list[i + 1] =
@@ -1276,7 +1280,7 @@
} else {
for (i = 0; i < 4; i++) {
const MV this_mv = { br + neighbors[i].row, bc + neighbors[i].col };
- if (!is_mv_in(x, &this_mv))
+ if (!is_mv_in(&x->mv_limits, &this_mv))
cost_list[i + 1] = INT_MAX;
else
cost_list[i + 1] =
@@ -1499,17 +1503,17 @@
assert(step >= 1);
- clamp_mv(&fcenter_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min,
- x->mv_row_max);
+ clamp_mv(&fcenter_mv, x->mv_limits.col_min, x->mv_limits.col_max,
+ x->mv_limits.row_min, x->mv_limits.row_max);
*best_mv = fcenter_mv;
best_sad =
fn_ptr->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &fcenter_mv), in_what->stride) +
mvsad_err_cost(x, &fcenter_mv, ref_mv, sad_per_bit);
- start_row = VPXMAX(-range, x->mv_row_min - fcenter_mv.row);
- start_col = VPXMAX(-range, x->mv_col_min - fcenter_mv.col);
- end_row = VPXMIN(range, x->mv_row_max - fcenter_mv.row);
- end_col = VPXMIN(range, x->mv_col_max - fcenter_mv.col);
+ start_row = VPXMAX(-range, x->mv_limits.row_min - fcenter_mv.row);
+ start_col = VPXMAX(-range, x->mv_limits.col_min - fcenter_mv.col);
+ end_row = VPXMIN(range, x->mv_limits.row_max - fcenter_mv.row);
+ end_col = VPXMIN(range, x->mv_limits.col_max - fcenter_mv.col);
for (r = start_row; r <= end_row; r += step) {
for (c = start_col; c <= end_col; c += col_step) {
@@ -1602,7 +1606,8 @@
const int tot_steps = cfg->total_steps - search_param;
const MV fcenter_mv = { center_mv->row >> 3, center_mv->col >> 3 };
- clamp_mv(ref_mv, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
+ clamp_mv(ref_mv, x->mv_limits.col_min, x->mv_limits.col_max,
+ x->mv_limits.row_min, x->mv_limits.row_max);
ref_row = ref_mv->row;
ref_col = ref_mv->col;
*num00 = 0;
@@ -1624,10 +1629,10 @@
// All_in is true if every one of the points we are checking are within
// the bounds of the image.
- all_in &= ((best_mv->row + ss_mv[i].row) > x->mv_row_min);
- all_in &= ((best_mv->row + ss_mv[i + 1].row) < x->mv_row_max);
- all_in &= ((best_mv->col + ss_mv[i + 2].col) > x->mv_col_min);
- all_in &= ((best_mv->col + ss_mv[i + 3].col) < x->mv_col_max);
+ all_in &= ((best_mv->row + ss_mv[i].row) > x->mv_limits.row_min);
+ all_in &= ((best_mv->row + ss_mv[i + 1].row) < x->mv_limits.row_max);
+ all_in &= ((best_mv->col + ss_mv[i + 2].col) > x->mv_limits.col_min);
+ all_in &= ((best_mv->col + ss_mv[i + 3].col) < x->mv_limits.col_max);
// If all the pixels are within the bounds we don't check whether the
// search point is valid in this loop, otherwise we check each point
@@ -1662,7 +1667,7 @@
const MV this_mv = { best_mv->row + ss_mv[i].row,
best_mv->col + ss_mv[i].col };
- if (is_mv_in(x, &this_mv)) {
+ if (is_mv_in(&x->mv_limits, &this_mv)) {
const uint8_t *const check_here = ss_os[i] + best_address;
unsigned int thissad =
fn_ptr->sdf(what, what_stride, check_here, in_what_stride);
@@ -1687,7 +1692,7 @@
while (1) {
const MV this_mv = { best_mv->row + ss_mv[best_site].row,
best_mv->col + ss_mv[best_site].col };
- if (is_mv_in(x, &this_mv)) {
+ if (is_mv_in(&x->mv_limits, &this_mv)) {
const uint8_t *const check_here = ss_os[best_site] + best_address;
unsigned int thissad =
fn_ptr->sdf(what, what_stride, check_here, in_what_stride);
@@ -2044,10 +2049,10 @@
const MACROBLOCKD *const xd = &x->e_mbd;
const struct buf_2d *const what = &x->plane[0].src;
const struct buf_2d *const in_what = &xd->plane[0].pre[0];
- const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min);
- const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max);
- const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min);
- const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max);
+ const int row_min = VPXMAX(ref_mv->row - distance, x->mv_limits.row_min);
+ const int row_max = VPXMIN(ref_mv->row + distance, x->mv_limits.row_max);
+ const int col_min = VPXMAX(ref_mv->col - distance, x->mv_limits.col_min);
+ const int col_max = VPXMIN(ref_mv->col + distance, x->mv_limits.col_max);
const MV fcenter_mv = { center_mv->row >> 3, center_mv->col >> 3 };
int best_sad =
fn_ptr->sdf(what->buf, what->stride, get_buf_from_mv(in_what, ref_mv),
@@ -2079,10 +2084,10 @@
const MACROBLOCKD *const xd = &x->e_mbd;
const struct buf_2d *const what = &x->plane[0].src;
const struct buf_2d *const in_what = &xd->plane[0].pre[0];
- const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min);
- const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max);
- const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min);
- const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max);
+ const int row_min = VPXMAX(ref_mv->row - distance, x->mv_limits.row_min);
+ const int row_max = VPXMIN(ref_mv->row + distance, x->mv_limits.row_max);
+ const int col_min = VPXMAX(ref_mv->col - distance, x->mv_limits.col_min);
+ const int col_max = VPXMIN(ref_mv->col + distance, x->mv_limits.col_max);
const MV fcenter_mv = { center_mv->row >> 3, center_mv->col >> 3 };
unsigned int best_sad =
fn_ptr->sdf(what->buf, what->stride, get_buf_from_mv(in_what, ref_mv),
@@ -2145,10 +2150,10 @@
const MACROBLOCKD *const xd = &x->e_mbd;
const struct buf_2d *const what = &x->plane[0].src;
const struct buf_2d *const in_what = &xd->plane[0].pre[0];
- const int row_min = VPXMAX(ref_mv->row - distance, x->mv_row_min);
- const int row_max = VPXMIN(ref_mv->row + distance, x->mv_row_max);
- const int col_min = VPXMAX(ref_mv->col - distance, x->mv_col_min);
- const int col_max = VPXMIN(ref_mv->col + distance, x->mv_col_max);
+ const int row_min = VPXMAX(ref_mv->row - distance, x->mv_limits.row_min);
+ const int row_max = VPXMIN(ref_mv->row + distance, x->mv_limits.row_max);
+ const int col_min = VPXMAX(ref_mv->col - distance, x->mv_limits.col_min);
+ const int col_max = VPXMIN(ref_mv->col + distance, x->mv_limits.col_max);
const MV fcenter_mv = { center_mv->row >> 3, center_mv->col >> 3 };
unsigned int best_sad =
fn_ptr->sdf(what->buf, what->stride, get_buf_from_mv(in_what, ref_mv),
@@ -2244,10 +2249,10 @@
for (i = 0; i < search_range; i++) {
int best_site = -1;
- const int all_in = ((ref_mv->row - 1) > x->mv_row_min) &
- ((ref_mv->row + 1) < x->mv_row_max) &
- ((ref_mv->col - 1) > x->mv_col_min) &
- ((ref_mv->col + 1) < x->mv_col_max);
+ const int all_in = ((ref_mv->row - 1) > x->mv_limits.row_min) &
+ ((ref_mv->row + 1) < x->mv_limits.row_max) &
+ ((ref_mv->col - 1) > x->mv_limits.col_min) &
+ ((ref_mv->col + 1) < x->mv_limits.col_max);
if (all_in) {
unsigned int sads[4];
@@ -2273,7 +2278,7 @@
const MV mv = { ref_mv->row + neighbors[j].row,
ref_mv->col + neighbors[j].col };
- if (is_mv_in(x, &mv)) {
+ if (is_mv_in(&x->mv_limits, &mv)) {
unsigned int sad =
fn_ptr->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &mv), in_what->stride);
@@ -2325,7 +2330,7 @@
const MV mv = { ref_mv->row + neighbors[j].row,
ref_mv->col + neighbors[j].col };
- if (is_mv_in(x, &mv)) {
+ if (is_mv_in(&x->mv_limits, &mv)) {
unsigned int sad =
fn_ptr->sdaf(what->buf, what->stride, get_buf_from_mv(in_what, &mv),
in_what->stride, second_pred);
--- a/vp9/encoder/vp9_mcomp.h
+++ b/vp9/encoder/vp9_mcomp.h
@@ -41,7 +41,7 @@
void vp9_init_dsmotion_compensation(search_site_config *cfg, int stride);
void vp9_init3smotion_compensation(search_site_config *cfg, int stride);
-void vp9_set_mv_search_range(MACROBLOCK *x, const MV *mv);
+void vp9_set_mv_search_range(MvLimits *mv_limits, const MV *mv);
int vp9_mv_bit_cost(const MV *mv, const MV *ref, const int *mvjcost,
int *mvcost[2], int weight);
--- a/vp9/encoder/vp9_pickmode.c
+++ b/vp9/encoder/vp9_pickmode.c
@@ -155,10 +155,7 @@
MV center_mv;
uint32_t dis;
int rate_mode;
- const int tmp_col_min = x->mv_col_min;
- const int tmp_col_max = x->mv_col_max;
- const int tmp_row_min = x->mv_row_min;
- const int tmp_row_max = x->mv_row_max;
+ const MvLimits tmp_mv_limits = x->mv_limits;
int rv = 0;
int cost_list[5];
const YV12_BUFFER_CONFIG *scaled_ref_frame =
@@ -171,7 +168,7 @@
for (i = 0; i < MAX_MB_PLANE; i++) backup_yv12[i] = xd->plane[i].pre[0];
vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL);
}
- vp9_set_mv_search_range(x, &ref_mv);
+ vp9_set_mv_search_range(&x->mv_limits, &ref_mv);
assert(x->mv_best_ref_index[ref] <= 2);
if (x->mv_best_ref_index[ref] < 2)
@@ -191,10 +188,7 @@
cond_cost_list(cpi, cost_list), ¢er_mv,
&tmp_mv->as_mv, INT_MAX, 0);
- x->mv_col_min = tmp_col_min;
- x->mv_col_max = tmp_col_max;
- x->mv_row_min = tmp_row_min;
- x->mv_row_max = tmp_row_max;
+ x->mv_limits = tmp_mv_limits;
// calculate the bit cost on motion vector
mvp_full.row = tmp_mv->as_mv.row * 8;
@@ -2182,10 +2176,7 @@
MV mvp_full;
MV tmp_mv;
int cost_list[5];
- const int tmp_col_min = x->mv_col_min;
- const int tmp_col_max = x->mv_col_max;
- const int tmp_row_min = x->mv_row_min;
- const int tmp_row_max = x->mv_row_max;
+ const MvLimits tmp_mv_limits = x->mv_limits;
uint32_t dummy_dist;
if (i == 0) {
@@ -2196,7 +2187,8 @@
mvp_full.col = xd->mi[0]->bmi[0].as_mv[0].as_mv.col >> 3;
}
- vp9_set_mv_search_range(x, &mbmi_ext->ref_mvs[0]->as_mv);
+ vp9_set_mv_search_range(&x->mv_limits,
+ &mbmi_ext->ref_mvs[0]->as_mv);
vp9_full_pixel_search(cpi, x, bsize, &mvp_full, step_param,
x->sadperbit4, cond_cost_list(cpi, cost_list),
@@ -2203,10 +2195,7 @@
&mbmi_ext->ref_mvs[ref_frame][0].as_mv,
&tmp_mv, INT_MAX, 0);
- x->mv_col_min = tmp_col_min;
- x->mv_col_max = tmp_col_max;
- x->mv_row_min = tmp_row_min;
- x->mv_row_max = tmp_row_max;
+ x->mv_limits = tmp_mv_limits;
// calculate the bit cost on motion vector
mvp_full.row = tmp_mv.row * 8;
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -1626,9 +1626,11 @@
int mvthresh;
} BEST_SEG_INFO;
-static INLINE int mv_check_bounds(const MACROBLOCK *x, const MV *mv) {
- return (mv->row >> 3) < x->mv_row_min || (mv->row >> 3) > x->mv_row_max ||
- (mv->col >> 3) < x->mv_col_min || (mv->col >> 3) > x->mv_col_max;
+static INLINE int mv_check_bounds(const MvLimits *mv_limits, const MV *mv) {
+ return (mv->row >> 3) < mv_limits->row_min ||
+ (mv->row >> 3) > mv_limits->row_max ||
+ (mv->col >> 3) < mv_limits->col_min ||
+ (mv->col >> 3) > mv_limits->col_max;
}
static INLINE void mi_buf_shift(MACROBLOCK *x, int i) {
@@ -1765,10 +1767,7 @@
MV tmp_mv;
int search_range = 3;
- int tmp_col_min = x->mv_col_min;
- int tmp_col_max = x->mv_col_max;
- int tmp_row_min = x->mv_row_min;
- int tmp_row_max = x->mv_row_max;
+ const MvLimits tmp_mv_limits = x->mv_limits;
int id = ite % 2; // Even iterations search in the first reference frame,
// odd iterations search in the second. The predictor
// found for the 'other' reference frame is factored in.
@@ -1801,7 +1800,7 @@
// Do compound motion search on the current reference frame.
if (id) xd->plane[0].pre[0] = ref_yv12[id];
- vp9_set_mv_search_range(x, &ref_mv[id].as_mv);
+ vp9_set_mv_search_range(&x->mv_limits, &ref_mv[id].as_mv);
// Use the mv result from the single mode as mv predictor.
tmp_mv = frame_mv[refs[id]].as_mv;
@@ -1817,10 +1816,7 @@
bestsme = vp9_get_mvpred_av_var(x, &tmp_mv, &ref_mv[id].as_mv,
second_pred, &cpi->fn_ptr[bsize], 1);
- x->mv_col_min = tmp_col_min;
- x->mv_col_max = tmp_col_max;
- x->mv_row_min = tmp_row_min;
- x->mv_row_max = tmp_row_max;
+ x->mv_limits = tmp_mv_limits;
if (bestsme < UINT_MAX) {
uint32_t dis; /* TODO: use dis in distortion calculation later. */
@@ -1958,10 +1954,7 @@
MV mvp_full;
int max_mv;
int cost_list[5];
- int tmp_col_min = x->mv_col_min;
- int tmp_col_max = x->mv_col_max;
- int tmp_row_min = x->mv_row_min;
- int tmp_row_max = x->mv_row_max;
+ const MvLimits tmp_mv_limits = x->mv_limits;
/* Is the best so far sufficiently good that we cant justify doing
* and new motion search. */
@@ -2002,7 +1995,7 @@
// adjust src pointer for this block
mi_buf_shift(x, i);
- vp9_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv);
+ vp9_set_mv_search_range(&x->mv_limits, &bsi->ref_mv[0]->as_mv);
bestsme = vp9_full_pixel_search(
cpi, x, bsize, &mvp_full, step_param, sadpb,
@@ -2009,10 +2002,7 @@
sf->mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL,
&bsi->ref_mv[0]->as_mv, new_mv, INT_MAX, 1);
- x->mv_col_min = tmp_col_min;
- x->mv_col_max = tmp_col_max;
- x->mv_row_min = tmp_row_min;
- x->mv_row_max = tmp_row_max;
+ x->mv_limits = tmp_mv_limits;
if (bestsme < UINT_MAX) {
uint32_t distortion;
@@ -2073,8 +2063,9 @@
}
// Trap vectors that reach beyond the UMV borders
- if (mv_check_bounds(x, &mode_mv[this_mode][0].as_mv) ||
- (has_second_rf && mv_check_bounds(x, &mode_mv[this_mode][1].as_mv)))
+ if (mv_check_bounds(&x->mv_limits, &mode_mv[this_mode][0].as_mv) ||
+ (has_second_rf &&
+ mv_check_bounds(&x->mv_limits, &mode_mv[this_mode][1].as_mv)))
continue;
if (filter_idx > 0) {
@@ -2335,11 +2326,7 @@
MV mvp_full;
int ref = mi->ref_frame[0];
MV ref_mv = x->mbmi_ext->ref_mvs[ref][0].as_mv;
-
- int tmp_col_min = x->mv_col_min;
- int tmp_col_max = x->mv_col_max;
- int tmp_row_min = x->mv_row_min;
- int tmp_row_max = x->mv_row_max;
+ const MvLimits tmp_mv_limits = x->mv_limits;
int cost_list[5];
const YV12_BUFFER_CONFIG *scaled_ref_frame =
@@ -2360,7 +2347,7 @@
vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL);
}
- vp9_set_mv_search_range(x, &ref_mv);
+ vp9_set_mv_search_range(&x->mv_limits, &ref_mv);
// Work out the size of the first step in the mv step search.
// 0 here is maximum length first step. 1 is VPXMAX >> 1 etc.
@@ -2418,10 +2405,7 @@
cond_cost_list(cpi, cost_list), &ref_mv,
&tmp_mv->as_mv, INT_MAX, 1);
- x->mv_col_min = tmp_col_min;
- x->mv_col_max = tmp_col_max;
- x->mv_row_min = tmp_row_min;
- x->mv_row_max = tmp_row_max;
+ x->mv_limits = tmp_mv_limits;
if (bestsme < INT_MAX) {
uint32_t dis; /* TODO: use dis in distortion calculation later. */
@@ -2594,7 +2578,7 @@
// Clip "next_nearest" so that it does not extend to far out of image
if (this_mode != NEWMV) clamp_mv2(&cur_mv[i].as_mv, xd);
- if (mv_check_bounds(x, &cur_mv[i].as_mv)) return INT64_MAX;
+ if (mv_check_bounds(&x->mv_limits, &cur_mv[i].as_mv)) return INT64_MAX;
mi->mv[i].as_int = cur_mv[i].as_int;
}
--- a/vp9/encoder/vp9_temporal_filter.c
+++ b/vp9/encoder/vp9_temporal_filter.c
@@ -316,8 +316,9 @@
// 8 - VP9_INTERP_EXTEND.
// To keep the mv in play for both Y and UV planes the max that it
// can be on a border is therefore 16 - (2*VP9_INTERP_EXTEND+1).
- cpi->td.mb.mv_row_min = -((mb_row * 16) + (17 - 2 * VP9_INTERP_EXTEND));
- cpi->td.mb.mv_row_max =
+ cpi->td.mb.mv_limits.row_min =
+ -((mb_row * 16) + (17 - 2 * VP9_INTERP_EXTEND));
+ cpi->td.mb.mv_limits.row_max =
((mb_rows - 1 - mb_row) * 16) + (17 - 2 * VP9_INTERP_EXTEND);
for (mb_col = 0; mb_col < mb_cols; mb_col++) {
@@ -327,8 +328,9 @@
memset(accumulator, 0, 16 * 16 * 3 * sizeof(accumulator[0]));
memset(count, 0, 16 * 16 * 3 * sizeof(count[0]));
- cpi->td.mb.mv_col_min = -((mb_col * 16) + (17 - 2 * VP9_INTERP_EXTEND));
- cpi->td.mb.mv_col_max =
+ cpi->td.mb.mv_limits.col_min =
+ -((mb_col * 16) + (17 - 2 * VP9_INTERP_EXTEND));
+ cpi->td.mb.mv_limits.col_max =
((mb_cols - 1 - mb_col) * 16) + (17 - 2 * VP9_INTERP_EXTEND);
for (frame = 0; frame < frame_count; frame++) {
--- a/vp9/encoder/x86/vp9_diamond_search_sad_avx.c
+++ b/vp9/encoder/x86/vp9_diamond_search_sad_avx.c
@@ -75,9 +75,9 @@
MV *best_mv, int search_param, int sad_per_bit,
int *num00, const vp9_variance_fn_ptr_t *fn_ptr,
const MV *center_mv) {
- const int_mv maxmv = pack_int_mv(x->mv_row_max, x->mv_col_max);
+ const int_mv maxmv = pack_int_mv(x->mv_limits.row_max, x->mv_limits.col_max);
const __m128i v_max_mv_w = _mm_set1_epi32(maxmv.as_int);
- const int_mv minmv = pack_int_mv(x->mv_row_min, x->mv_col_min);
+ const int_mv minmv = pack_int_mv(x->mv_limits.row_min, x->mv_limits.col_min);
const __m128i v_min_mv_w = _mm_set1_epi32(minmv.as_int);
const __m128i v_spb_d = _mm_set1_epi32(sad_per_bit);