ref: 129e6fe52463d192f6b48f7d42ac4a3a93c61f3b
parent: 6b191dc40219f5e74f2d2c616c9a69b13a479372
parent: 6f8861e293a5f376568a1468d1c9eba524ae7e8a
author: Angie Chiang <angiebird@google.com>
date: Tue Oct 2 21:05:21 EDT 2018
Merge changes I66b35ef7,Ic9ed6ed6,Ie5818689 * changes: Add mv_dist/mv_cost to TplDepStats Change interface of motion_compensated_prediction Separate lambda from nb_mvs_inconsistency()
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -5475,11 +5475,20 @@
}
#endif
+#if CONFIG_NON_GREEDY_MV
uint32_t motion_compensated_prediction(VP9_COMP *cpi, ThreadData *td,
int frame_idx, uint8_t *cur_frame_buf,
uint8_t *ref_frame_buf, int stride,
- MV *mv, BLOCK_SIZE bsize, int mi_row,
- int mi_col) {
+ BLOCK_SIZE bsize, int mi_row, int mi_col,
+ TplDepStats *tpl_stats, int rf_idx) {
+ MV *mv = &tpl_stats->mv_arr[rf_idx].as_mv;
+#else // CONFIG_NON_GREEDY_MV
+uint32_t motion_compensated_prediction(VP9_COMP *cpi, ThreadData *td,
+ int frame_idx, uint8_t *cur_frame_buf,
+ uint8_t *ref_frame_buf, int stride,
+ BLOCK_SIZE bsize, int mi_row, int mi_col,
+ MV *mv) {
+#endif // CONFIG_NON_GREEDY_MV
MACROBLOCK *const x = &td->mb;
MACROBLOCKD *const xd = &x->e_mbd;
MV_SPEED_FEATURES *const mv_sf = &cpi->sf.mv;
@@ -5521,7 +5530,8 @@
prepare_nb_full_mvs(&cpi->tpl_stats[frame_idx], mi_row, mi_col, nb_full_mvs);
vp9_full_pixel_diamond_new(cpi, x, &best_ref_mv1_full, step_param, lambda,
MAX_MVSEARCH_STEPS - 1 - step_param, 1,
- &cpi->fn_ptr[bsize], nb_full_mvs, mv);
+ &cpi->fn_ptr[bsize], nb_full_mvs, tpl_stats,
+ rf_idx);
#else
(void)frame_idx;
(void)mi_row;
@@ -5604,6 +5614,8 @@
#if CONFIG_NON_GREEDY_MV
int rf_idx;
for (rf_idx = 0; rf_idx < 3; ++rf_idx) {
+ tpl_ptr->mv_dist[rf_idx] = src_stats->mv_dist[rf_idx];
+ tpl_ptr->mv_cost[rf_idx] = src_stats->mv_cost[rf_idx];
tpl_ptr->inter_cost_arr[rf_idx] = src_stats->inter_cost;
tpl_ptr->recon_error_arr[rf_idx] = src_stats->recon_error_arr[rf_idx];
tpl_ptr->sse_arr[rf_idx] = src_stats->sse_arr[rf_idx];
@@ -5836,10 +5848,18 @@
continue;
}
+#if CONFIG_NON_GREEDY_MV
motion_compensated_prediction(
cpi, td, frame_idx, xd->cur_buf->y_buffer + mb_y_offset,
- ref_frame[rf_idx]->y_buffer + mb_y_offset, xd->cur_buf->y_stride,
- &mv.as_mv, bsize, mi_row, mi_col);
+ ref_frame[rf_idx]->y_buffer + mb_y_offset, xd->cur_buf->y_stride, bsize,
+ mi_row, mi_col, tpl_stats, rf_idx);
+ mv.as_int = tpl_stats->mv_arr[rf_idx].as_int;
+#else
+ motion_compensated_prediction(
+ cpi, td, frame_idx, xd->cur_buf->y_buffer + mb_y_offset,
+ ref_frame[rf_idx]->y_buffer + mb_y_offset, xd->cur_buf->y_stride, bsize,
+ mi_row, mi_col, &mv.as_mv);
+#endif
// TODO(jingning): Not yet support high bit-depth in the next three
// steps.
@@ -5877,7 +5897,6 @@
#if CONFIG_NON_GREEDY_MV
tpl_stats->inter_cost_arr[rf_idx] = inter_cost;
- tpl_stats->mv_arr[rf_idx].as_int = mv.as_int;
get_quantize_error(x, 0, coeff, qcoeff, dqcoeff, tx_size,
&tpl_stats->recon_error_arr[rf_idx],
&tpl_stats->sse_arr[rf_idx]);
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -292,6 +292,8 @@
#if CONFIG_NON_GREEDY_MV
int ready;
+ double mv_dist[3];
+ double mv_cost[3];
int64_t inter_cost_arr[3];
int64_t recon_error_arr[3];
int64_t sse_arr[3];
--- a/vp9/encoder/vp9_mcomp.c
+++ b/vp9/encoder/vp9_mcomp.c
@@ -1578,8 +1578,7 @@
}
#if CONFIG_NON_GREEDY_MV
-static double nb_mvs_inconsistency(const MV *mv, const int_mv *nb_mvs,
- double lambda) {
+static double nb_mvs_inconsistency(const MV *mv, const int_mv *nb_mvs) {
int i;
double best_cost = -1;
vpx_clear_system_state();
@@ -1600,7 +1599,7 @@
if (best_cost < 0) {
return 0;
} else {
- return best_cost * lambda;
+ return best_cost;
}
}
@@ -1607,6 +1606,7 @@
double vp9_diamond_search_sad_new(const MACROBLOCK *x,
const search_site_config *cfg,
const MV *init_full_mv, MV *best_full_mv,
+ double *best_mv_dist, double *best_mv_cost,
int search_param, double lambda, int *num00,
const vp9_variance_fn_ptr_t *fn_ptr,
const int_mv *nb_full_mvs) {
@@ -1645,8 +1645,9 @@
best_address = in_what;
// Check the starting position
- bestsad = fn_ptr->sdf(what, what_stride, in_what, in_what_stride) +
- nb_mvs_inconsistency(best_full_mv, nb_full_mvs, lambda);
+ *best_mv_dist = fn_ptr->sdf(what, what_stride, in_what, in_what_stride);
+ *best_mv_cost = nb_mvs_inconsistency(best_full_mv, nb_full_mvs);
+ bestsad = (*best_mv_dist) + lambda * (*best_mv_cost);
i = 0;
@@ -1675,15 +1676,16 @@
sad_array);
for (t = 0; t < 4; t++, i++) {
- if (sad_array[t] < bestsad) {
- const MV this_mv = { best_full_mv->row + ss_mv[i].row,
- best_full_mv->col + ss_mv[i].col };
- double thissad = sad_array[t] + nb_mvs_inconsistency(
- &this_mv, nb_full_mvs, lambda);
- if (thissad < bestsad) {
- bestsad = thissad;
- best_site = i;
- }
+ const MV this_mv = { best_full_mv->row + ss_mv[i].row,
+ best_full_mv->col + ss_mv[i].col };
+ const double mv_dist = sad_array[t];
+ const double mv_cost = nb_mvs_inconsistency(&this_mv, nb_full_mvs);
+ double thissad = mv_dist + lambda * mv_cost;
+ if (thissad < bestsad) {
+ bestsad = thissad;
+ *best_mv_dist = mv_dist;
+ *best_mv_cost = mv_cost;
+ best_site = i;
}
}
}
@@ -1695,15 +1697,15 @@
if (is_mv_in(&x->mv_limits, &this_mv)) {
const uint8_t *const check_here = ss_os[i] + best_address;
- double thissad =
+ const double mv_dist =
fn_ptr->sdf(what, what_stride, check_here, in_what_stride);
-
+ const double mv_cost = nb_mvs_inconsistency(&this_mv, nb_full_mvs);
+ double thissad = mv_dist + lambda * mv_cost;
if (thissad < bestsad) {
- thissad += nb_mvs_inconsistency(&this_mv, nb_full_mvs, lambda);
- if (thissad < bestsad) {
- bestsad = thissad;
- best_site = i;
- }
+ bestsad = thissad;
+ *best_mv_dist = mv_dist;
+ *best_mv_cost = mv_cost;
+ best_site = i;
}
}
i++;
@@ -2085,15 +2087,22 @@
MV *mvp_full, int step_param, double lambda,
int further_steps, int do_refine,
const vp9_variance_fn_ptr_t *fn_ptr,
- const int_mv *nb_full_mvs, MV *dst_mv) {
+ const int_mv *nb_full_mvs,
+ TplDepStats *tpl_stats, int rf_idx) {
+ MV *dst_mv = &tpl_stats->mv_arr[rf_idx].as_mv;
MV temp_mv;
int n, num00 = 0;
double thissme;
- double bestsme =
- vp9_diamond_search_sad_new(x, &cpi->ss_cfg, mvp_full, &temp_mv,
- step_param, lambda, &n, fn_ptr, nb_full_mvs);
+ double mv_dist;
+ double mv_cost;
+ double bestsme;
vpx_clear_system_state();
+ bestsme = vp9_diamond_search_sad_new(x, &cpi->ss_cfg, mvp_full, &temp_mv,
+ &mv_dist, &mv_cost, step_param, lambda,
+ &n, fn_ptr, nb_full_mvs);
*dst_mv = temp_mv;
+ tpl_stats->mv_dist[rf_idx] = mv_dist;
+ tpl_stats->mv_cost[rf_idx] = mv_cost;
// If there won't be more n-step search, check to see if refining search is
// needed.
@@ -2105,8 +2114,8 @@
num00--;
} else {
thissme = vp9_diamond_search_sad_new(x, &cpi->ss_cfg, mvp_full, &temp_mv,
- step_param + n, lambda, &num00,
- fn_ptr, nb_full_mvs);
+ &mv_dist, &mv_cost, step_param + n,
+ lambda, &num00, fn_ptr, nb_full_mvs);
// check to see if refining search is needed.
if (num00 > further_steps - n) do_refine = 0;
@@ -2113,6 +2122,8 @@
if (thissme < bestsme) {
bestsme = thissme;
*dst_mv = temp_mv;
+ tpl_stats->mv_dist[rf_idx] = mv_dist;
+ tpl_stats->mv_cost[rf_idx] = mv_cost;
}
}
}
@@ -2121,11 +2132,14 @@
if (do_refine) {
const int search_range = 8;
MV best_mv = *dst_mv;
- thissme = vp9_refining_search_sad_new(x, &best_mv, lambda, search_range,
- fn_ptr, nb_full_mvs);
+ thissme =
+ vp9_refining_search_sad_new(x, &best_mv, &mv_dist, &mv_cost, lambda,
+ search_range, fn_ptr, nb_full_mvs);
if (thissme < bestsme) {
bestsme = thissme;
*dst_mv = best_mv;
+ tpl_stats->mv_dist[rf_idx] = mv_dist;
+ tpl_stats->mv_cost[rf_idx] = mv_cost;
}
}
return bestsme;
@@ -2257,6 +2271,7 @@
#if CONFIG_NON_GREEDY_MV
double vp9_refining_search_sad_new(const MACROBLOCK *x, MV *best_full_mv,
+ double *best_mv_dist, double *best_mv_cost,
double lambda, int search_range,
const vp9_variance_fn_ptr_t *fn_ptr,
const int_mv *nb_full_mvs) {
@@ -2265,11 +2280,13 @@
const struct buf_2d *const what = &x->plane[0].src;
const struct buf_2d *const in_what = &xd->plane[0].pre[0];
const uint8_t *best_address = get_buf_from_mv(in_what, best_full_mv);
- double best_sad =
- fn_ptr->sdf(what->buf, what->stride, best_address, in_what->stride) +
- nb_mvs_inconsistency(best_full_mv, nb_full_mvs, lambda);
+ double best_sad;
int i, j;
vpx_clear_system_state();
+ *best_mv_dist =
+ fn_ptr->sdf(what->buf, what->stride, best_address, in_what->stride);
+ *best_mv_cost = nb_mvs_inconsistency(best_full_mv, nb_full_mvs);
+ best_sad = (*best_mv_dist) + lambda * (*best_mv_cost);
for (i = 0; i < search_range; i++) {
int best_site = -1;
@@ -2287,16 +2304,16 @@
fn_ptr->sdx4df(what->buf, what->stride, positions, in_what->stride, sads);
for (j = 0; j < 4; ++j) {
- double thissad = sads[j];
- if (sads[j] < best_sad) {
- const MV mv = { best_full_mv->row + neighbors[j].row,
- best_full_mv->col + neighbors[j].col };
-
- thissad += nb_mvs_inconsistency(&mv, nb_full_mvs, lambda);
- if (thissad < best_sad) {
- best_sad = thissad;
- best_site = j;
- }
+ const MV mv = { best_full_mv->row + neighbors[j].row,
+ best_full_mv->col + neighbors[j].col };
+ const double mv_dist = sads[j];
+ const double mv_cost = nb_mvs_inconsistency(&mv, nb_full_mvs);
+ const double thissad = mv_dist + lambda * mv_cost;
+ if (thissad < best_sad) {
+ best_sad = thissad;
+ *best_mv_dist = mv_dist;
+ *best_mv_cost = mv_cost;
+ best_site = j;
}
}
} else {
@@ -2305,15 +2322,16 @@
best_full_mv->col + neighbors[j].col };
if (is_mv_in(&x->mv_limits, &mv)) {
- double thissad =
+ const double mv_dist =
fn_ptr->sdf(what->buf, what->stride,
get_buf_from_mv(in_what, &mv), in_what->stride);
+ const double mv_cost = nb_mvs_inconsistency(&mv, nb_full_mvs);
+ const double thissad = mv_dist + lambda * mv_cost;
if (thissad < best_sad) {
- thissad += nb_mvs_inconsistency(&mv, nb_full_mvs, lambda);
- if (thissad < best_sad) {
- best_sad = thissad;
- best_site = j;
- }
+ best_sad = thissad;
+ *best_mv_dist = mv_dist;
+ *best_mv_cost = mv_cost;
+ best_site = j;
}
}
}
--- a/vp9/encoder/vp9_mcomp.h
+++ b/vp9/encoder/vp9_mcomp.h
@@ -121,7 +121,9 @@
#if CONFIG_NON_GREEDY_MV
#define NB_MVS_NUM 4
+struct TplDepStats;
double vp9_refining_search_sad_new(const MACROBLOCK *x, MV *best_full_mv,
+ double *best_mv_dist, double *best_mv_cost,
double lambda, int search_range,
const vp9_variance_fn_ptr_t *fn_ptr,
const int_mv *nb_full_mvs);
@@ -130,7 +132,8 @@
MV *mvp_full, int step_param, double lambda,
int further_steps, int do_refine,
const vp9_variance_fn_ptr_t *fn_ptr,
- const int_mv *nb_full_mvs, MV *dst_mv);
+ const int_mv *nb_full_mvs,
+ struct TplDepStats *tpl_stats, int rf_idx);
#endif // CONFIG_NON_GREEDY_MV
#ifdef __cplusplus
} // extern "C"