// Exhuastive motion search around a given centre position with a given
// step size.
-static int exhuastive_mesh_search(const MACROBLOCK *x,
+static int exhuastive_mesh_search(MACROBLOCK *x,
MV *ref_mv, MV *best_mv,
int range, int step, int sad_per_bit,
const vp10_variance_fn_ptr_t *fn_ptr,
sad += mvsad_err_cost(x, &mv, ref_mv, sad_per_bit);
if (sad < best_sad) {
best_sad = sad;
+ x->second_best_mv.as_mv = *best_mv;
*best_mv = mv;
}
}
mvsad_err_cost(x, &mv, ref_mv, sad_per_bit);
if (sad < best_sad) {
best_sad = sad;
+ x->second_best_mv.as_mv = *best_mv;
*best_mv = mv;
}
}
sad += mvsad_err_cost(x, &mv, ref_mv, sad_per_bit);
if (sad < best_sad) {
best_sad = sad;
+ x->second_best_mv.as_mv = *best_mv;
*best_mv = mv;
}
}
return best_sad;
}
-int vp10_diamond_search_sad_c(const MACROBLOCK *x,
+int vp10_diamond_search_sad_c(MACROBLOCK *x,
const search_site_config *cfg,
MV *ref_mv, MV *best_mv, int search_param,
int sad_per_bit, int *num00,
}
}
if (best_site != last_site) {
+ x->second_best_mv.as_mv = *best_mv;
best_mv->row += ss[best_site].mv.row;
best_mv->col += ss[best_site].mv.col;
best_address += ss[best_site].offset;
return best_sad;
}
-int vp10_refining_search_sad(const MACROBLOCK *x,
- MV *ref_mv, int error_per_bit,
- int search_range,
- const vp10_variance_fn_ptr_t *fn_ptr,
- const MV *center_mv) {
+int vp10_refining_search_sad(MACROBLOCK *x,
+ MV *ref_mv, int error_per_bit,
+ int search_range,
+ const vp10_variance_fn_ptr_t *fn_ptr,
+ const MV *center_mv) {
const MACROBLOCKD *const xd = &x->e_mbd;
const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}};
const struct buf_2d *const what = &x->plane[0].src;
if (best_site == -1) {
break;
} else {
+ x->second_best_mv.as_mv = *ref_mv;
ref_mv->row += neighbors[best_site].row;
ref_mv->col += neighbors[best_site].col;
best_address = get_buf_from_mv(in_what, ref_mv);
vp10_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv);
+ x->best_mv.as_int = x->second_best_mv.as_int = INVALID_MV;
+
#if CONFIG_REF_MV
vp10_set_mvcost(x, mbmi->ref_frame[0]);
#endif
if (bestsme < INT_MAX) {
int distortion;
if (cpi->sf.use_upsampled_references) {
+ int best_mv_var;
+ const int try_second =
+ x->second_best_mv.as_int != INVALID_MV &&
+ x->second_best_mv.as_int != x->best_mv.as_int;
const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
// Use up-sampled reference frames.
&pd->pre[0].buf[(vp10_raster_block_offset(BLOCK_8X8, i,
pd->pre[0].stride)) << 3];
- cpi->find_fractional_mv_step(
- x, &bsi->ref_mv[0]->as_mv,
- cm->allow_high_precision_mv,
- x->errorperbit, &cpi->fn_ptr[bsize],
- cpi->sf.mv.subpel_force_stop,
- cpi->sf.mv.subpel_iters_per_step,
- cond_cost_list(cpi, cost_list),
- x->nmvjointcost, x->mvcost,
- &distortion,
- &x->pred_sse[mbmi->ref_frame[0]],
- NULL, pw, ph, 1);
+ best_mv_var =
+ cpi->find_fractional_mv_step(x, &bsi->ref_mv[0]->as_mv,
+ cm->allow_high_precision_mv,
+ x->errorperbit,
+ &cpi->fn_ptr[bsize],
+ cpi->sf.mv.subpel_force_stop,
+ cpi->sf.mv.subpel_iters_per_step,
+ cond_cost_list(cpi, cost_list),
+ x->nmvjointcost, x->mvcost,
+ &distortion,
+ &x->pred_sse[mbmi->ref_frame[0]],
+ NULL, pw, ph, 1);
+
+ if (try_second) {
+ int this_var;
+ MV best_mv = x->best_mv.as_mv;
+ const MV ref_mv = bsi->ref_mv[0]->as_mv;
+ 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);
+
+ x->best_mv = x->second_best_mv;
+ if (x->best_mv.as_mv.row * 8 <= maxr &&
+ x->best_mv.as_mv.row * 8 >= minr &&
+ x->best_mv.as_mv.col * 8 <= maxc &&
+ x->best_mv.as_mv.col * 8 >= minc) {
+ this_var =
+ cpi->find_fractional_mv_step(x, &bsi->ref_mv[0]->as_mv,
+ cm->allow_high_precision_mv,
+ x->errorperbit,
+ &cpi->fn_ptr[bsize],
+ cpi->sf.mv.subpel_force_stop,
+ cpi->
+ sf.mv.subpel_iters_per_step,
+ cond_cost_list(cpi,
+ cost_list),
+ x->nmvjointcost, x->mvcost,
+ &distortion,
+ &x->pred_sse[mbmi->
+ ref_frame[0]],
+ NULL, pw, ph, 1);
+ if (this_var < best_mv_var) best_mv = x->best_mv.as_mv;
+ x->best_mv.as_mv = best_mv;
+ }
+ }
// Restore the reference frames.
pd->pre[0] = backup_pred;
mvp_full.col >>= 3;
mvp_full.row >>= 3;
+ x->best_mv.as_int = x->second_best_mv.as_int = INVALID_MV;
+
bestsme = vp10_full_pixel_search(cpi, x, bsize, &mvp_full, step_param, sadpb,
cond_cost_list(cpi, cost_list),
&ref_mv, INT_MAX, 1);
if (bestsme < INT_MAX) {
int dis; /* TODO: use dis in distortion calculation later. */
if (cpi->sf.use_upsampled_references) {
+ int best_mv_var;
+ const int try_second =
+ x->second_best_mv.as_int != INVALID_MV &&
+ x->second_best_mv.as_int != x->best_mv.as_int;
const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
// Use up-sampled reference frames.
upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
NULL, pd->subsampling_x, pd->subsampling_y);
- bestsme = cpi->find_fractional_mv_step(x, &ref_mv,
- cm->allow_high_precision_mv,
- x->errorperbit,
- &cpi->fn_ptr[bsize],
- cpi->sf.mv.subpel_force_stop,
- cpi->sf.mv.subpel_iters_per_step,
- cond_cost_list(cpi, cost_list),
- x->nmvjointcost, x->mvcost,
- &dis, &x->pred_sse[ref], NULL,
- pw, ph, 1);
+ best_mv_var =
+ cpi->find_fractional_mv_step(x, &ref_mv,
+ cm->allow_high_precision_mv,
+ x->errorperbit,
+ &cpi->fn_ptr[bsize],
+ cpi->sf.mv.subpel_force_stop,
+ cpi->sf.mv.subpel_iters_per_step,
+ cond_cost_list(cpi, cost_list),
+ x->nmvjointcost, x->mvcost,
+ &dis, &x->pred_sse[ref], NULL,
+ pw, ph, 1);
+
+ if (try_second) {
+ 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 this_var;
+ MV best_mv = x->best_mv.as_mv;
+
+ x->best_mv = x->second_best_mv;
+ if (x->best_mv.as_mv.row * 8 <= maxr &&
+ x->best_mv.as_mv.row * 8 >= minr &&
+ x->best_mv.as_mv.col * 8 <= maxc &&
+ x->best_mv.as_mv.col * 8 >= minc) {
+ this_var =
+ cpi->find_fractional_mv_step(x, &ref_mv,
+ cm->allow_high_precision_mv,
+ x->errorperbit,
+ &cpi->fn_ptr[bsize],
+ cpi->sf.mv.subpel_force_stop,
+ cpi->sf.mv.subpel_iters_per_step,
+ cond_cost_list(cpi, cost_list),
+ x->nmvjointcost, x->mvcost,
+ &dis, &x->pred_sse[ref], NULL,
+ pw, ph, 1);
+ if (this_var < best_mv_var) best_mv = x->best_mv.as_mv;
+ x->best_mv.as_mv = best_mv;
+ }
+ }
// Restore the reference frames.
pd->pre[ref_idx] = backup_pred;