Commit 97d6a37e authored by Yunqing Wang's avatar Yunqing Wang

Find warped reference MV

While finding the reference MV for a block, if one neighbouring block's
motion mode is warped motion mode, instead of directly adding that
block's MV to the candidate MV list, we use that neighbouring block's
warped motion parameters to compute a MV for the center point of the
current block, and then add that MV to the candidate MV list.

Borg test result:
             avg_psnr ovr_psnr ssim
cam_lowres:  -0.507   -0.514  -0.685
lowres:      -0.114   -0.122  -0.180

The change is added under ext_warped_motion config flag.

Change-Id: I3ce6290a1fd512b613eab5d7620c8bcb08f189a6
parent 63ce36fc
......@@ -37,10 +37,6 @@ typedef struct mv32 {
int32_t col;
} MV32;
#if CONFIG_WARPED_MOTION
#define WARPED_MOTION_SORT_SAMPLES 1
#endif // CONFIG_WARPED_MOTION
#if CONFIG_GLOBAL_MOTION || CONFIG_WARPED_MOTION
// Bits of precision used for the model
#define WARPEDMODEL_PREC_BITS 16
......
This diff is collapsed.
......@@ -433,14 +433,14 @@ void av1_update_mv_context(const AV1_COMMON *cm, const MACROBLOCKD *xd,
int mi_col, int16_t *mode_context);
#if CONFIG_WARPED_MOTION
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
int sortSamples(int *pts_mv, MV *mv, int *pts, int *pts_inref, int len);
int findSamples(const AV1_COMMON *cm, MACROBLOCKD *xd, int mi_row, int mi_col,
int *pts, int *pts_inref, int *pts_mv);
#else
int findSamples(const AV1_COMMON *cm, MACROBLOCKD *xd, int mi_row, int mi_col,
int *pts, int *pts_inref);
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
#endif // CONFIG_WARPED_MOTION
#if CONFIG_INTRABC
......
......@@ -29,13 +29,14 @@
#define LEAST_SQUARES_SAMPLES_MAX_BITS 3
#define LEAST_SQUARES_SAMPLES_MAX (1 << LEAST_SQUARES_SAMPLES_MAX_BITS)
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
// Search 1 row on the top and 1 column on the left, 1 upper-left block,
// 1 upper-right block.
#define SAMPLES_ARRAY_SIZE ((MAX_MIB_SIZE * 2 + 2) * 2)
#define SCALING_FCT 3
#else
#define SAMPLES_ARRAY_SIZE (LEAST_SQUARES_SAMPLES_MAX * 2)
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
#define DEFAULT_WMTYPE AFFINE
#endif // CONFIG_WARPED_MOTION
......
......@@ -2339,9 +2339,9 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
int16_t mode_ctx = 0;
#if CONFIG_WARPED_MOTION
int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE];
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
int pts_mv[SAMPLES_ARRAY_SIZE];
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
#endif // CONFIG_WARPED_MOTION
FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
......@@ -2804,12 +2804,12 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
mbmi->motion_mode = SIMPLE_TRANSLATION;
#if CONFIG_WARPED_MOTION
if (mbmi->sb_type >= BLOCK_8X8 && !has_second_ref(mbmi))
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
mbmi->num_proj_ref[0] =
findSamples(cm, xd, mi_row, mi_col, pts, pts_inref, pts_mv);
#else
mbmi->num_proj_ref[0] = findSamples(cm, xd, mi_row, mi_col, pts, pts_inref);
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
#endif // CONFIG_WARPED_MOTION
#if CONFIG_MOTION_VAR
av1_count_overlappable_neighbors(cm, xd, mi_row, mi_col);
......@@ -2832,11 +2832,11 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
if (mbmi->motion_mode == WARPED_CAUSAL) {
mbmi->wm_params[0].wmtype = DEFAULT_WMTYPE;
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
if (mbmi->num_proj_ref[0] > 1)
mbmi->num_proj_ref[0] = sortSamples(pts_mv, &mbmi->mv[0].as_mv, pts,
pts_inref, mbmi->num_proj_ref[0]);
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
if (find_projection(mbmi->num_proj_ref[0], pts, pts_inref, bsize,
mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col,
......
......@@ -886,7 +886,7 @@ unsigned int av1_compute_motion_cost(const AV1_COMP *cpi, MACROBLOCK *const x,
}
// Refine MV in a small range
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
unsigned int av1_refine_warped_mv(const AV1_COMP *cpi, MACROBLOCK *const x,
BLOCK_SIZE bsize, int mi_row, int mi_col,
int *pts0, int *pts_inref0, int *pts_mv0,
......@@ -895,7 +895,7 @@ unsigned int av1_refine_warped_mv(const AV1_COMP *cpi, MACROBLOCK *const x,
unsigned int av1_refine_warped_mv(const AV1_COMP *cpi, MACROBLOCK *const x,
BLOCK_SIZE bsize, int mi_row, int mi_col,
int *pts, int *pts_inref) {
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
const AV1_COMMON *const cm = &cpi->common;
MACROBLOCKD *xd = &x->e_mbd;
MODE_INFO *mi = xd->mi[0];
......@@ -908,9 +908,9 @@ unsigned int av1_refine_warped_mv(const AV1_COMP *cpi, MACROBLOCK *const x,
int16_t *tr = &mbmi->mv[0].as_mv.row;
int16_t *tc = &mbmi->mv[0].as_mv.col;
WarpedMotionParams best_wm_params = mbmi->wm_params[0];
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
int best_num_proj_ref = mbmi->num_proj_ref[0];
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
unsigned int bestmse;
int minc, maxc, minr, maxr;
const int start = cm->allow_high_precision_mv ? 0 : 4;
......@@ -937,7 +937,7 @@ unsigned int av1_refine_warped_mv(const AV1_COMP *cpi, MACROBLOCK *const x,
if (*tc >= minc && *tc <= maxc && *tr >= minr && *tr <= maxr) {
MV this_mv = { *tr, *tc };
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE];
memcpy(pts, pts0, total_samples * 2 * sizeof(*pts0));
......@@ -945,7 +945,7 @@ unsigned int av1_refine_warped_mv(const AV1_COMP *cpi, MACROBLOCK *const x,
if (total_samples > 1)
mbmi->num_proj_ref[0] =
sortSamples(pts_mv0, &this_mv, pts, pts_inref, total_samples);
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
if (!find_projection(mbmi->num_proj_ref[0], pts, pts_inref, bsize, *tr,
*tc, &mbmi->wm_params[0], mi_row, mi_col)) {
......@@ -955,9 +955,9 @@ unsigned int av1_refine_warped_mv(const AV1_COMP *cpi, MACROBLOCK *const x,
if (thismse < bestmse) {
best_idx = idx;
best_wm_params = mbmi->wm_params[0];
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
best_num_proj_ref = mbmi->num_proj_ref[0];
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
bestmse = thismse;
}
}
......@@ -975,9 +975,9 @@ unsigned int av1_refine_warped_mv(const AV1_COMP *cpi, MACROBLOCK *const x,
*tr = br;
*tc = bc;
mbmi->wm_params[0] = best_wm_params;
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
mbmi->num_proj_ref[0] = best_num_proj_ref;
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
return bestmse;
}
#endif // CONFIG_WARPED_MOTION
......
......@@ -157,7 +157,7 @@ int av1_find_best_obmc_sub_pixel_tree_up(
unsigned int av1_compute_motion_cost(const struct AV1_COMP *cpi,
MACROBLOCK *const x, BLOCK_SIZE bsize,
int mi_row, int mi_col, const MV *this_mv);
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
unsigned int av1_refine_warped_mv(const struct AV1_COMP *cpi,
MACROBLOCK *const x, BLOCK_SIZE bsize,
int mi_row, int mi_col, int *pts0,
......@@ -168,7 +168,7 @@ unsigned int av1_refine_warped_mv(const struct AV1_COMP *cpi,
MACROBLOCK *const x, BLOCK_SIZE bsize,
int mi_row, int mi_col, int *pts,
int *pts_inref);
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
#endif // CONFIG_WARPED_MOTION
#endif // AV1_ENCODER_MCOMP_H_
......@@ -8771,13 +8771,13 @@ static int64_t motion_mode_rd(
#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
#if CONFIG_WARPED_MOTION
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
int pts0[SAMPLES_ARRAY_SIZE], pts_inref0[SAMPLES_ARRAY_SIZE];
int pts_mv0[SAMPLES_ARRAY_SIZE];
int total_samples;
#else
int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE];
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
#endif // CONFIG_WARPED_MOTION
#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
......@@ -8787,13 +8787,13 @@ static int64_t motion_mode_rd(
if (cm->interp_filter == SWITCHABLE) rd_stats->rate += rs;
#if CONFIG_WARPED_MOTION
aom_clear_system_state();
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
mbmi->num_proj_ref[0] =
findSamples(cm, xd, mi_row, mi_col, pts0, pts_inref0, pts_mv0);
total_samples = mbmi->num_proj_ref[0];
#else
mbmi->num_proj_ref[0] = findSamples(cm, xd, mi_row, mi_col, pts, pts_inref);
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
best_bmc_mbmi->num_proj_ref[0] = mbmi->num_proj_ref[0];
#endif // CONFIG_WARPED_MOTION
#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
......@@ -8865,16 +8865,16 @@ static int64_t motion_mode_rd(
#if CONFIG_WARPED_MOTION
if (mbmi->motion_mode == WARPED_CAUSAL) {
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE];
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
*mbmi = *best_bmc_mbmi;
mbmi->motion_mode = WARPED_CAUSAL;
mbmi->wm_params[0].wmtype = DEFAULT_WMTYPE;
mbmi->interp_filters = av1_broadcast_interp_filter(
av1_unswitchable_filter(cm->interp_filter));
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
memcpy(pts, pts0, total_samples * 2 * sizeof(*pts0));
memcpy(pts_inref, pts_inref0, total_samples * 2 * sizeof(*pts_inref0));
// Rank the samples by motion vector difference
......@@ -8883,7 +8883,7 @@ static int64_t motion_mode_rd(
pts_inref, mbmi->num_proj_ref[0]);
best_bmc_mbmi->num_proj_ref[0] = mbmi->num_proj_ref[0];
}
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
if (!find_projection(mbmi->num_proj_ref[0], pts, pts_inref, bsize,
mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col,
......@@ -8893,7 +8893,7 @@ static int64_t motion_mode_rd(
int tmp_rate_mv = 0;
const int_mv mv0 = mbmi->mv[0];
WarpedMotionParams wm_params0 = mbmi->wm_params[0];
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
int num_proj_ref0 = mbmi->num_proj_ref[0];
// Refine MV in a small range.
......@@ -8902,7 +8902,7 @@ static int64_t motion_mode_rd(
#else
// Refine MV in a small range.
av1_refine_warped_mv(cpi, x, bsize, mi_row, mi_col, pts, pts_inref);
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
// Keep the refined MV and WM parameters.
if (mv0.as_int != mbmi->mv[0].as_int) {
......@@ -8922,9 +8922,9 @@ static int64_t motion_mode_rd(
refs[0])) {
tmp_rate_mv = AOMMAX((tmp_rate_mv / NEW_MV_DISCOUNT_FACTOR), 1);
}
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
best_bmc_mbmi->num_proj_ref[0] = mbmi->num_proj_ref[0];
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
tmp_rate2 = rate2_bmc_nocoeff - rate_mv_bmc + tmp_rate_mv;
#if CONFIG_DUAL_FILTER
mbmi->interp_filters =
......@@ -8934,9 +8934,9 @@ static int64_t motion_mode_rd(
// Restore the old MV and WM parameters.
mbmi->mv[0] = mv0;
mbmi->wm_params[0] = wm_params0;
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
mbmi->num_proj_ref[0] = num_proj_ref0;
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
}
}
......@@ -12234,7 +12234,7 @@ void av1_rd_pick_inter_mode_sb_seg_skip(const AV1_COMP *cpi,
#if CONFIG_WARPED_MOTION
if (is_motion_variation_allowed_bsize(bsize) && !has_second_ref(mbmi)) {
int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE];
#if WARPED_MOTION_SORT_SAMPLES
#if CONFIG_EXT_WARPED_MOTION
int pts_mv[SAMPLES_ARRAY_SIZE];
mbmi->num_proj_ref[0] =
findSamples(cm, xd, mi_row, mi_col, pts, pts_inref, pts_mv);
......@@ -12244,7 +12244,7 @@ void av1_rd_pick_inter_mode_sb_seg_skip(const AV1_COMP *cpi,
pts_inref, mbmi->num_proj_ref[0]);
#else
mbmi->num_proj_ref[0] = findSamples(cm, xd, mi_row, mi_col, pts, pts_inref);
#endif // WARPED_MOTION_SORT_SAMPLES
#endif // CONFIG_EXT_WARPED_MOTION
}
#endif
......
......@@ -145,6 +145,7 @@ set(CONFIG_EXT_REFS 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_EXT_SKIP 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_EXT_TILE 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_EXT_TX 1 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_EXT_WARPED_MOTION 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_FILTER_INTRA 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_FP_MB_STATS 0 CACHE NUMBER "AV1 experiment flag.")
set(CONFIG_FRAME_MARKER 0 CACHE NUMBER "AV1 experiment flag.")
......
......@@ -352,6 +352,7 @@ EXPERIMENT_LIST="
lpf_sb
opt_ref_mv
tmv
ext_warped_motion
restrict_compressed_hdr
horzonly_frame_superres
"
......@@ -591,6 +592,7 @@ post_process_cmdline() {
enabled ext_skip && enable_feature frame_marker
enabled ext_skip && enable_feature ext_refs
enabled horzonly_frame_superres && enable_feature frame_superres
enabled ext_warped_motion && enable_feature warped_motion
if enabled rawbits && enabled ans; then
log_echo "rawbits requires not ans, so disabling rawbits"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment