2015-08-06 05:00:31 +03:00
|
|
|
/*
|
2016-09-02 22:04:54 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2015-08-06 05:00:31 +03:00
|
|
|
*
|
2016-09-02 22:04:54 +03:00
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
2015-08-06 05:00:31 +03:00
|
|
|
*/
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
#include "av1/common/mvref_common.h"
|
2016-09-09 00:48:15 +03:00
|
|
|
#if CONFIG_WARPED_MOTION
|
|
|
|
#include "av1/common/warped_motion.h"
|
|
|
|
#endif // CONFIG_WARPED_MOTION
|
2015-08-06 05:00:31 +03:00
|
|
|
|
2016-08-12 04:55:00 +03:00
|
|
|
static uint8_t add_ref_mv_candidate(
|
|
|
|
const MODE_INFO *const candidate_mi, const MB_MODE_INFO *const candidate,
|
|
|
|
const MV_REFERENCE_FRAME rf[2], uint8_t *refmv_count,
|
|
|
|
CANDIDATE_MV *ref_mv_stack, const int use_hp, int len, int block, int col) {
|
2015-12-12 09:39:40 +03:00
|
|
|
int index = 0, ref;
|
|
|
|
int newmv_count = 0;
|
2016-12-14 22:05:10 +03:00
|
|
|
#if CONFIG_CB4X4
|
|
|
|
const int unify_bsize = 1;
|
|
|
|
#else
|
|
|
|
const int unify_bsize = 0;
|
|
|
|
#endif
|
2015-12-12 09:39:40 +03:00
|
|
|
|
2017-01-21 02:03:11 +03:00
|
|
|
if (rf[1] == NONE_FRAME) {
|
2015-12-12 09:39:40 +03:00
|
|
|
// single reference frame
|
|
|
|
for (ref = 0; ref < 2; ++ref) {
|
|
|
|
if (candidate->ref_frame[ref] == rf[0]) {
|
2016-08-12 04:55:00 +03:00
|
|
|
int_mv this_refmv = get_sub_block_mv(candidate_mi, ref, col, block);
|
2016-03-03 07:09:54 +03:00
|
|
|
lower_mv_precision(&this_refmv.as_mv, use_hp);
|
|
|
|
|
2015-12-12 09:39:40 +03:00
|
|
|
for (index = 0; index < *refmv_count; ++index)
|
2016-08-12 04:55:00 +03:00
|
|
|
if (ref_mv_stack[index].this_mv.as_int == this_refmv.as_int) break;
|
2015-11-23 23:05:48 +03:00
|
|
|
|
2016-09-27 20:13:33 +03:00
|
|
|
if (index < *refmv_count) ref_mv_stack[index].weight += 2 * len;
|
2015-11-23 23:05:48 +03:00
|
|
|
|
2015-12-12 09:39:40 +03:00
|
|
|
// Add a new item to the list.
|
|
|
|
if (index == *refmv_count) {
|
|
|
|
ref_mv_stack[index].this_mv = this_refmv;
|
2016-11-18 22:01:48 +03:00
|
|
|
ref_mv_stack[index].pred_diff[0] = av1_get_pred_diff_ctx(
|
|
|
|
get_sub_block_pred_mv(candidate_mi, ref, col, block), this_refmv);
|
2016-09-27 20:13:33 +03:00
|
|
|
ref_mv_stack[index].weight = 2 * len;
|
2015-12-12 09:39:40 +03:00
|
|
|
++(*refmv_count);
|
2015-11-23 23:05:48 +03:00
|
|
|
|
2017-03-18 03:42:05 +03:00
|
|
|
if (candidate->mode == NEWMV) ++newmv_count;
|
2015-12-12 09:39:40 +03:00
|
|
|
}
|
|
|
|
|
2016-12-14 22:05:10 +03:00
|
|
|
if (candidate_mi->mbmi.sb_type < BLOCK_8X8 && block >= 0 &&
|
|
|
|
!unify_bsize) {
|
2015-12-12 09:39:40 +03:00
|
|
|
int alt_block = 3 - block;
|
2016-08-12 04:55:00 +03:00
|
|
|
this_refmv = get_sub_block_mv(candidate_mi, ref, col, alt_block);
|
2016-04-14 04:05:45 +03:00
|
|
|
lower_mv_precision(&this_refmv.as_mv, use_hp);
|
|
|
|
|
2015-11-23 23:05:48 +03:00
|
|
|
for (index = 0; index < *refmv_count; ++index)
|
2016-08-12 04:55:00 +03:00
|
|
|
if (ref_mv_stack[index].this_mv.as_int == this_refmv.as_int) break;
|
2015-11-23 23:05:48 +03:00
|
|
|
|
2016-09-27 20:13:33 +03:00
|
|
|
if (index < *refmv_count) ref_mv_stack[index].weight += len;
|
2015-11-23 23:05:48 +03:00
|
|
|
|
|
|
|
// Add a new item to the list.
|
|
|
|
if (index == *refmv_count) {
|
|
|
|
ref_mv_stack[index].this_mv = this_refmv;
|
2016-11-18 22:01:48 +03:00
|
|
|
ref_mv_stack[index].pred_diff[0] = av1_get_pred_diff_ctx(
|
|
|
|
get_sub_block_pred_mv(candidate_mi, ref, col, alt_block),
|
|
|
|
this_refmv);
|
2016-09-27 20:13:33 +03:00
|
|
|
ref_mv_stack[index].weight = len;
|
2015-11-23 23:05:48 +03:00
|
|
|
++(*refmv_count);
|
2015-12-02 21:59:01 +03:00
|
|
|
|
2017-03-18 03:42:05 +03:00
|
|
|
if (candidate->mode == NEWMV) ++newmv_count;
|
2015-11-23 23:05:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-12 09:39:40 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// compound reference frame
|
2016-08-12 04:55:00 +03:00
|
|
|
if (candidate->ref_frame[0] == rf[0] && candidate->ref_frame[1] == rf[1]) {
|
2016-05-06 04:31:59 +03:00
|
|
|
int_mv this_refmv[2];
|
2015-12-12 09:39:40 +03:00
|
|
|
|
2016-05-06 04:31:59 +03:00
|
|
|
for (ref = 0; ref < 2; ++ref) {
|
|
|
|
this_refmv[ref] = get_sub_block_mv(candidate_mi, ref, col, block);
|
2016-04-14 04:05:45 +03:00
|
|
|
lower_mv_precision(&this_refmv[ref].as_mv, use_hp);
|
2016-05-06 04:31:59 +03:00
|
|
|
}
|
2016-04-14 04:05:45 +03:00
|
|
|
|
2015-12-12 09:39:40 +03:00
|
|
|
for (index = 0; index < *refmv_count; ++index)
|
|
|
|
if ((ref_mv_stack[index].this_mv.as_int == this_refmv[0].as_int) &&
|
|
|
|
(ref_mv_stack[index].comp_mv.as_int == this_refmv[1].as_int))
|
|
|
|
break;
|
|
|
|
|
2016-09-27 20:13:33 +03:00
|
|
|
if (index < *refmv_count) ref_mv_stack[index].weight += 2 * len;
|
2015-12-12 09:39:40 +03:00
|
|
|
|
|
|
|
// Add a new item to the list.
|
|
|
|
if (index == *refmv_count) {
|
|
|
|
ref_mv_stack[index].this_mv = this_refmv[0];
|
|
|
|
ref_mv_stack[index].comp_mv = this_refmv[1];
|
2016-11-18 22:01:48 +03:00
|
|
|
ref_mv_stack[index].pred_diff[0] = av1_get_pred_diff_ctx(
|
|
|
|
get_sub_block_pred_mv(candidate_mi, 0, col, block), this_refmv[0]);
|
|
|
|
ref_mv_stack[index].pred_diff[1] = av1_get_pred_diff_ctx(
|
|
|
|
get_sub_block_pred_mv(candidate_mi, 1, col, block), this_refmv[1]);
|
2016-09-27 20:13:33 +03:00
|
|
|
ref_mv_stack[index].weight = 2 * len;
|
2015-12-12 09:39:40 +03:00
|
|
|
++(*refmv_count);
|
|
|
|
|
2016-01-20 03:45:45 +03:00
|
|
|
#if CONFIG_EXT_INTER
|
|
|
|
if (candidate->mode == NEW_NEWMV)
|
|
|
|
#else
|
2015-12-12 09:39:40 +03:00
|
|
|
if (candidate->mode == NEWMV)
|
2016-01-20 03:45:45 +03:00
|
|
|
#endif // CONFIG_EXT_INTER
|
2015-12-12 09:39:40 +03:00
|
|
|
++newmv_count;
|
|
|
|
}
|
|
|
|
|
2016-12-14 22:05:10 +03:00
|
|
|
if (candidate_mi->mbmi.sb_type < BLOCK_8X8 && block >= 0 &&
|
|
|
|
!unify_bsize) {
|
2015-12-12 09:39:40 +03:00
|
|
|
int alt_block = 3 - block;
|
|
|
|
this_refmv[0] = get_sub_block_mv(candidate_mi, 0, col, alt_block);
|
|
|
|
this_refmv[1] = get_sub_block_mv(candidate_mi, 1, col, alt_block);
|
|
|
|
|
2016-04-14 04:05:45 +03:00
|
|
|
for (ref = 0; ref < 2; ++ref)
|
|
|
|
lower_mv_precision(&this_refmv[ref].as_mv, use_hp);
|
|
|
|
|
2015-12-12 09:39:40 +03:00
|
|
|
for (index = 0; index < *refmv_count; ++index)
|
|
|
|
if (ref_mv_stack[index].this_mv.as_int == this_refmv[0].as_int &&
|
|
|
|
ref_mv_stack[index].comp_mv.as_int == this_refmv[1].as_int)
|
|
|
|
break;
|
|
|
|
|
2016-09-27 20:13:33 +03:00
|
|
|
if (index < *refmv_count) ref_mv_stack[index].weight += len;
|
2015-12-12 09:39:40 +03:00
|
|
|
|
|
|
|
// Add a new item to the list.
|
|
|
|
if (index == *refmv_count) {
|
|
|
|
ref_mv_stack[index].this_mv = this_refmv[0];
|
|
|
|
ref_mv_stack[index].comp_mv = this_refmv[1];
|
2016-11-18 22:01:48 +03:00
|
|
|
ref_mv_stack[index].pred_diff[0] = av1_get_pred_diff_ctx(
|
|
|
|
get_sub_block_pred_mv(candidate_mi, 0, col, block),
|
|
|
|
this_refmv[0]);
|
|
|
|
ref_mv_stack[index].pred_diff[0] = av1_get_pred_diff_ctx(
|
|
|
|
get_sub_block_pred_mv(candidate_mi, 1, col, block),
|
|
|
|
this_refmv[1]);
|
2016-09-27 20:13:33 +03:00
|
|
|
ref_mv_stack[index].weight = len;
|
2015-12-12 09:39:40 +03:00
|
|
|
++(*refmv_count);
|
|
|
|
|
2016-01-20 03:45:45 +03:00
|
|
|
#if CONFIG_EXT_INTER
|
|
|
|
if (candidate->mode == NEW_NEWMV)
|
|
|
|
#else
|
2015-12-12 09:39:40 +03:00
|
|
|
if (candidate->mode == NEWMV)
|
2016-01-20 03:45:45 +03:00
|
|
|
#endif // CONFIG_EXT_INTER
|
2015-12-12 09:39:40 +03:00
|
|
|
++newmv_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newmv_count;
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static uint8_t scan_row_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd,
|
2015-12-12 09:39:40 +03:00
|
|
|
const int mi_row, const int mi_col, int block,
|
2016-08-12 04:55:00 +03:00
|
|
|
const MV_REFERENCE_FRAME rf[2], int row_offset,
|
|
|
|
CANDIDATE_MV *ref_mv_stack, uint8_t *refmv_count) {
|
2015-12-12 09:39:40 +03:00
|
|
|
const TileInfo *const tile = &xd->tile;
|
|
|
|
int i;
|
|
|
|
uint8_t newmv_count = 0;
|
2016-12-09 23:37:28 +03:00
|
|
|
#if CONFIG_CB4X4
|
2016-12-17 01:52:45 +03:00
|
|
|
const int bsize = xd->mi[0]->mbmi.sb_type;
|
|
|
|
const int mi_offset =
|
|
|
|
bsize < BLOCK_8X8 ? mi_size_wide[BLOCK_4X4] : mi_size_wide[BLOCK_8X8];
|
2016-12-09 23:37:28 +03:00
|
|
|
// TODO(jingning): Revisit this part after cb4x4 is stable.
|
2016-12-17 01:52:45 +03:00
|
|
|
if (bsize >= BLOCK_8X8) row_offset *= 2;
|
|
|
|
#else
|
|
|
|
const int mi_offset = mi_size_wide[BLOCK_8X8];
|
2016-12-09 23:37:28 +03:00
|
|
|
#endif
|
2015-12-12 09:39:40 +03:00
|
|
|
|
|
|
|
for (i = 0; i < xd->n8_w && *refmv_count < MAX_REF_MV_STACK_SIZE;) {
|
|
|
|
POSITION mi_pos;
|
2016-12-09 23:37:28 +03:00
|
|
|
#if CONFIG_CB4X4
|
|
|
|
const int use_step_16 = (xd->n8_w >= 16);
|
|
|
|
#else
|
2016-09-30 19:10:26 +03:00
|
|
|
const int use_step_16 = (xd->n8_w >= 8);
|
2016-12-09 23:37:28 +03:00
|
|
|
#endif
|
2016-09-30 19:10:26 +03:00
|
|
|
|
2015-12-12 09:39:40 +03:00
|
|
|
mi_pos.row = row_offset;
|
|
|
|
mi_pos.col = i;
|
2017-03-08 04:48:52 +03:00
|
|
|
if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos)) {
|
2015-12-12 09:39:40 +03:00
|
|
|
const MODE_INFO *const candidate_mi =
|
|
|
|
xd->mi[mi_pos.row * xd->mi_stride + mi_pos.col];
|
|
|
|
const MB_MODE_INFO *const candidate = &candidate_mi->mbmi;
|
2016-12-07 01:48:09 +03:00
|
|
|
int len = AOMMIN(xd->n8_w, mi_size_wide[candidate->sb_type]);
|
2016-12-13 22:29:23 +03:00
|
|
|
if (use_step_16) len = AOMMAX(mi_size_wide[BLOCK_16X16], len);
|
2016-08-12 04:55:00 +03:00
|
|
|
newmv_count += add_ref_mv_candidate(
|
|
|
|
candidate_mi, candidate, rf, refmv_count, ref_mv_stack,
|
|
|
|
cm->allow_high_precision_mv, len, block, mi_pos.col);
|
2015-11-23 23:05:48 +03:00
|
|
|
i += len;
|
|
|
|
} else {
|
2016-09-30 19:10:26 +03:00
|
|
|
if (use_step_16)
|
2016-12-09 23:37:28 +03:00
|
|
|
i += (mi_offset << 1);
|
2016-09-30 19:10:26 +03:00
|
|
|
else
|
2016-12-09 23:37:28 +03:00
|
|
|
i += mi_offset;
|
2015-11-23 23:05:48 +03:00
|
|
|
}
|
|
|
|
}
|
2015-12-02 21:59:01 +03:00
|
|
|
|
|
|
|
return newmv_count;
|
2015-11-23 23:05:48 +03:00
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static uint8_t scan_col_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd,
|
2015-12-02 21:59:01 +03:00
|
|
|
const int mi_row, const int mi_col, int block,
|
2016-08-12 04:55:00 +03:00
|
|
|
const MV_REFERENCE_FRAME rf[2], int col_offset,
|
|
|
|
CANDIDATE_MV *ref_mv_stack, uint8_t *refmv_count) {
|
2015-11-23 23:05:48 +03:00
|
|
|
const TileInfo *const tile = &xd->tile;
|
|
|
|
int i;
|
2015-12-02 21:59:01 +03:00
|
|
|
uint8_t newmv_count = 0;
|
2016-12-09 23:37:28 +03:00
|
|
|
#if CONFIG_CB4X4
|
2016-12-17 01:52:45 +03:00
|
|
|
const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
|
|
|
|
const int mi_offset =
|
|
|
|
(bsize < BLOCK_8X8) ? mi_size_high[BLOCK_4X4] : mi_size_high[BLOCK_8X8];
|
|
|
|
if (bsize >= BLOCK_8X8) col_offset *= 2;
|
|
|
|
#else
|
|
|
|
const int mi_offset = mi_size_wide[BLOCK_8X8];
|
2016-12-09 23:37:28 +03:00
|
|
|
#endif
|
2015-11-23 23:05:48 +03:00
|
|
|
|
|
|
|
for (i = 0; i < xd->n8_h && *refmv_count < MAX_REF_MV_STACK_SIZE;) {
|
|
|
|
POSITION mi_pos;
|
2016-12-09 23:37:28 +03:00
|
|
|
#if CONFIG_CB4X4
|
|
|
|
const int use_step_16 = (xd->n8_h >= 16);
|
|
|
|
#else
|
2016-09-30 19:10:26 +03:00
|
|
|
const int use_step_16 = (xd->n8_h >= 8);
|
2016-12-09 23:37:28 +03:00
|
|
|
#endif
|
2016-09-30 19:10:26 +03:00
|
|
|
|
2015-11-23 23:05:48 +03:00
|
|
|
mi_pos.row = i;
|
|
|
|
mi_pos.col = col_offset;
|
2017-03-08 04:48:52 +03:00
|
|
|
if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos)) {
|
2015-11-23 23:05:48 +03:00
|
|
|
const MODE_INFO *const candidate_mi =
|
|
|
|
xd->mi[mi_pos.row * xd->mi_stride + mi_pos.col];
|
|
|
|
const MB_MODE_INFO *const candidate = &candidate_mi->mbmi;
|
2016-12-07 01:48:09 +03:00
|
|
|
int len = AOMMIN(xd->n8_h, mi_size_high[candidate->sb_type]);
|
2016-12-13 22:29:23 +03:00
|
|
|
if (use_step_16) len = AOMMAX(mi_size_high[BLOCK_16X16], len);
|
2016-08-12 04:55:00 +03:00
|
|
|
newmv_count += add_ref_mv_candidate(
|
|
|
|
candidate_mi, candidate, rf, refmv_count, ref_mv_stack,
|
|
|
|
cm->allow_high_precision_mv, len, block, mi_pos.col);
|
2015-11-23 23:05:48 +03:00
|
|
|
i += len;
|
|
|
|
} else {
|
2016-09-30 19:10:26 +03:00
|
|
|
if (use_step_16)
|
2016-12-09 23:37:28 +03:00
|
|
|
i += (mi_offset << 1);
|
2016-09-30 19:10:26 +03:00
|
|
|
else
|
2016-12-09 23:37:28 +03:00
|
|
|
i += mi_offset;
|
2015-11-23 23:05:48 +03:00
|
|
|
}
|
|
|
|
}
|
2015-12-02 21:59:01 +03:00
|
|
|
|
|
|
|
return newmv_count;
|
2015-11-23 23:05:48 +03:00
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static uint8_t scan_blk_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd,
|
2015-12-02 21:59:01 +03:00
|
|
|
const int mi_row, const int mi_col, int block,
|
2016-08-12 04:55:00 +03:00
|
|
|
const MV_REFERENCE_FRAME rf[2], int row_offset,
|
|
|
|
int col_offset, CANDIDATE_MV *ref_mv_stack,
|
2015-12-02 21:59:01 +03:00
|
|
|
uint8_t *refmv_count) {
|
2015-11-23 23:05:48 +03:00
|
|
|
const TileInfo *const tile = &xd->tile;
|
|
|
|
POSITION mi_pos;
|
2015-12-02 21:59:01 +03:00
|
|
|
uint8_t newmv_count = 0;
|
2015-11-23 23:05:48 +03:00
|
|
|
|
|
|
|
mi_pos.row = row_offset;
|
|
|
|
mi_pos.col = col_offset;
|
|
|
|
|
2017-03-08 04:48:52 +03:00
|
|
|
if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos) &&
|
2017-01-18 01:01:52 +03:00
|
|
|
*refmv_count < MAX_REF_MV_STACK_SIZE) {
|
2015-11-23 23:05:48 +03:00
|
|
|
const MODE_INFO *const candidate_mi =
|
|
|
|
xd->mi[mi_pos.row * xd->mi_stride + mi_pos.col];
|
|
|
|
const MB_MODE_INFO *const candidate = &candidate_mi->mbmi;
|
2016-12-09 23:37:28 +03:00
|
|
|
const int len = mi_size_wide[BLOCK_8X8];
|
2015-11-24 20:01:19 +03:00
|
|
|
|
2016-08-12 04:55:00 +03:00
|
|
|
newmv_count += add_ref_mv_candidate(
|
|
|
|
candidate_mi, candidate, rf, refmv_count, ref_mv_stack,
|
|
|
|
cm->allow_high_precision_mv, len, block, mi_pos.col);
|
2015-11-23 23:05:48 +03:00
|
|
|
} // Analyze a single 8x8 block motion information.
|
2016-09-27 22:55:32 +03:00
|
|
|
|
2015-12-02 21:59:01 +03:00
|
|
|
return newmv_count;
|
2015-11-23 23:05:48 +03:00
|
|
|
}
|
|
|
|
|
2016-08-12 04:55:00 +03:00
|
|
|
static int has_top_right(const MACROBLOCKD *xd, int mi_row, int mi_col,
|
|
|
|
int bs) {
|
2016-11-18 02:17:25 +03:00
|
|
|
const int mask_row = mi_row & MAX_MIB_MASK;
|
|
|
|
const int mask_col = mi_col & MAX_MIB_MASK;
|
|
|
|
|
2016-03-17 19:50:28 +03:00
|
|
|
// In a split partition all apart from the bottom right has a top right
|
2016-11-18 02:17:25 +03:00
|
|
|
int has_tr = !((mask_row & bs) && (mask_col & bs));
|
2015-12-02 03:26:06 +03:00
|
|
|
|
2016-03-07 16:46:39 +03:00
|
|
|
// bs > 0 and bs is a power of 2
|
|
|
|
assert(bs > 0 && !(bs & (bs - 1)));
|
2015-12-02 03:26:06 +03:00
|
|
|
|
2016-03-07 16:46:39 +03:00
|
|
|
// For each 4x4 group of blocks, when the bottom right is decoded the blocks
|
|
|
|
// to the right have not been decoded therefore the bottom right does
|
|
|
|
// not have a top right
|
2016-03-24 14:20:25 +03:00
|
|
|
while (bs < MAX_MIB_SIZE) {
|
2016-11-18 02:17:25 +03:00
|
|
|
if (mask_col & bs) {
|
|
|
|
if ((mask_col & (2 * bs)) && (mask_row & (2 * bs))) {
|
2015-12-02 03:26:06 +03:00
|
|
|
has_tr = 0;
|
2016-03-07 16:46:39 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bs <<= 1;
|
|
|
|
}
|
2015-12-02 03:26:06 +03:00
|
|
|
|
2016-03-07 16:46:39 +03:00
|
|
|
// The left hand of two vertical rectangles always has a top right (as the
|
2016-03-17 19:50:28 +03:00
|
|
|
// block above will have been decoded)
|
2015-12-08 02:54:59 +03:00
|
|
|
if (xd->n8_w < xd->n8_h)
|
2016-08-12 04:55:00 +03:00
|
|
|
if (!xd->is_sec_rect) has_tr = 1;
|
2015-12-02 03:26:06 +03:00
|
|
|
|
2016-03-17 19:50:28 +03:00
|
|
|
// The bottom of two horizontal rectangles never has a top right (as the block
|
|
|
|
// to the right won't have been decoded)
|
2015-12-08 02:54:59 +03:00
|
|
|
if (xd->n8_w > xd->n8_h)
|
2016-08-12 04:55:00 +03:00
|
|
|
if (xd->is_sec_rect) has_tr = 0;
|
2015-12-08 02:54:59 +03:00
|
|
|
|
2016-03-17 19:50:28 +03:00
|
|
|
#if CONFIG_EXT_PARTITION_TYPES
|
|
|
|
// The bottom left square of a Vertical A does not have a top right as it is
|
|
|
|
// decoded before the right hand rectangle of the partition
|
|
|
|
if (xd->mi[0]->mbmi.partition == PARTITION_VERT_A)
|
2016-11-18 02:17:25 +03:00
|
|
|
if ((mask_row & bs) && !(mask_col & bs)) has_tr = 0;
|
2016-03-17 19:50:28 +03:00
|
|
|
#endif // CONFIG_EXT_PARTITION_TYPES
|
|
|
|
|
2015-12-02 03:26:06 +03:00
|
|
|
return has_tr;
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:29:34 +03:00
|
|
|
static int add_col_ref_mv(const AV1_COMMON *cm,
|
|
|
|
const MV_REF *prev_frame_mvs_base,
|
|
|
|
const MACROBLOCKD *xd, int mi_row, int mi_col,
|
|
|
|
MV_REFERENCE_FRAME ref_frame, int blk_row,
|
|
|
|
int blk_col, uint8_t *refmv_count,
|
|
|
|
CANDIDATE_MV *ref_mv_stack, int16_t *mode_context) {
|
|
|
|
const MV_REF *prev_frame_mvs =
|
|
|
|
prev_frame_mvs_base + blk_row * cm->mi_cols + blk_col;
|
|
|
|
POSITION mi_pos;
|
|
|
|
int ref, idx;
|
|
|
|
int coll_blk_count = 0;
|
2016-12-09 23:37:28 +03:00
|
|
|
const int weight_unit = mi_size_wide[BLOCK_8X8];
|
2016-09-27 20:29:34 +03:00
|
|
|
|
2017-02-17 12:49:03 +03:00
|
|
|
#if CONFIG_MV_COMPRESS
|
|
|
|
mi_pos.row = (mi_row & 0x01) ? blk_row : blk_row + 1;
|
|
|
|
mi_pos.col = (mi_col & 0x01) ? blk_col : blk_col + 1;
|
|
|
|
#else
|
2016-09-27 20:29:34 +03:00
|
|
|
mi_pos.row = blk_row;
|
|
|
|
mi_pos.col = blk_col;
|
2017-02-17 12:49:03 +03:00
|
|
|
#endif
|
2016-09-27 20:29:34 +03:00
|
|
|
|
2017-03-08 04:48:52 +03:00
|
|
|
if (!is_inside(&xd->tile, mi_col, mi_row, cm->mi_rows, cm, &mi_pos))
|
2017-01-18 01:01:52 +03:00
|
|
|
return coll_blk_count;
|
2016-09-27 20:29:34 +03:00
|
|
|
for (ref = 0; ref < 2; ++ref) {
|
|
|
|
if (prev_frame_mvs->ref_frame[ref] == ref_frame) {
|
|
|
|
int_mv this_refmv = prev_frame_mvs->mv[ref];
|
|
|
|
lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv);
|
|
|
|
|
|
|
|
if (abs(this_refmv.as_mv.row) >= 16 || abs(this_refmv.as_mv.col) >= 16)
|
|
|
|
mode_context[ref_frame] |= (1 << ZEROMV_OFFSET);
|
|
|
|
|
|
|
|
for (idx = 0; idx < *refmv_count; ++idx)
|
|
|
|
if (this_refmv.as_int == ref_mv_stack[idx].this_mv.as_int) break;
|
|
|
|
|
2016-12-09 23:37:28 +03:00
|
|
|
if (idx < *refmv_count) ref_mv_stack[idx].weight += 2 * weight_unit;
|
2016-09-27 20:29:34 +03:00
|
|
|
|
|
|
|
if (idx == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) {
|
|
|
|
ref_mv_stack[idx].this_mv.as_int = this_refmv.as_int;
|
2016-11-18 22:01:48 +03:00
|
|
|
ref_mv_stack[idx].pred_diff[0] =
|
|
|
|
av1_get_pred_diff_ctx(prev_frame_mvs->pred_mv[ref], this_refmv);
|
2016-12-09 23:37:28 +03:00
|
|
|
ref_mv_stack[idx].weight = 2 * weight_unit;
|
2016-09-27 20:29:34 +03:00
|
|
|
++(*refmv_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
++coll_blk_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return coll_blk_count;
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
static void setup_ref_mv_list(const AV1_COMMON *cm, const MACROBLOCKD *xd,
|
2015-11-24 04:33:38 +03:00
|
|
|
MV_REFERENCE_FRAME ref_frame,
|
2016-08-12 04:55:00 +03:00
|
|
|
uint8_t *refmv_count, CANDIDATE_MV *ref_mv_stack,
|
|
|
|
int_mv *mv_ref_list, int block, int mi_row,
|
|
|
|
int mi_col, int16_t *mode_context) {
|
2015-11-24 02:05:18 +03:00
|
|
|
int idx, nearest_refmv_count = 0;
|
2015-12-02 21:59:01 +03:00
|
|
|
uint8_t newmv_count = 0;
|
2015-11-23 23:05:48 +03:00
|
|
|
CANDIDATE_MV tmp_mv;
|
|
|
|
int len, nr_len;
|
|
|
|
|
2017-02-17 12:49:03 +03:00
|
|
|
#if CONFIG_MV_COMPRESS
|
|
|
|
const MV_REF *const prev_frame_mvs_base =
|
|
|
|
cm->use_prev_frame_mvs
|
|
|
|
? cm->prev_frame->mvs + (((mi_row >> 1) << 1) + 1) * cm->mi_cols +
|
|
|
|
((mi_col >> 1) << 1) + 1
|
|
|
|
: NULL;
|
|
|
|
#else
|
2016-08-12 04:55:00 +03:00
|
|
|
const MV_REF *const prev_frame_mvs_base =
|
|
|
|
cm->use_prev_frame_mvs
|
|
|
|
? cm->prev_frame->mvs + mi_row * cm->mi_cols + mi_col
|
|
|
|
: NULL;
|
2017-02-17 12:49:03 +03:00
|
|
|
#endif
|
2015-12-02 03:26:06 +03:00
|
|
|
|
2016-09-27 20:29:34 +03:00
|
|
|
const int bs = AOMMAX(xd->n8_w, xd->n8_h);
|
|
|
|
const int has_tr = has_top_right(xd, mi_row, mi_col, bs);
|
2015-12-12 09:39:40 +03:00
|
|
|
MV_REFERENCE_FRAME rf[2];
|
|
|
|
|
2016-09-27 20:29:34 +03:00
|
|
|
av1_set_ref_frame(rf, ref_frame);
|
2015-12-05 02:18:17 +03:00
|
|
|
mode_context[ref_frame] = 0;
|
2015-11-24 02:05:18 +03:00
|
|
|
*refmv_count = 0;
|
2015-11-23 23:05:48 +03:00
|
|
|
|
|
|
|
// Scan the first above row mode info.
|
2016-09-27 20:29:34 +03:00
|
|
|
newmv_count += scan_row_mbmi(cm, xd, mi_row, mi_col, block, rf, -1,
|
|
|
|
ref_mv_stack, refmv_count);
|
2015-11-23 23:05:48 +03:00
|
|
|
// Scan the first left column mode info.
|
2016-08-12 04:55:00 +03:00
|
|
|
newmv_count += scan_col_mbmi(cm, xd, mi_row, mi_col, block, rf, -1,
|
|
|
|
ref_mv_stack, refmv_count);
|
2015-11-23 23:05:48 +03:00
|
|
|
|
2015-12-02 03:26:06 +03:00
|
|
|
// Check top-right boundary
|
|
|
|
if (has_tr)
|
2016-10-29 00:19:12 +03:00
|
|
|
newmv_count += scan_blk_mbmi(cm, xd, mi_row, mi_col, block, rf, -1,
|
|
|
|
xd->n8_w, ref_mv_stack, refmv_count);
|
2015-12-02 03:26:06 +03:00
|
|
|
|
2015-11-24 02:05:18 +03:00
|
|
|
nearest_refmv_count = *refmv_count;
|
2015-11-23 23:05:48 +03:00
|
|
|
|
2016-09-27 20:29:34 +03:00
|
|
|
for (idx = 0; idx < nearest_refmv_count; ++idx)
|
2016-01-22 05:07:31 +03:00
|
|
|
ref_mv_stack[idx].weight += REF_CAT_LEVEL;
|
2016-12-15 00:40:54 +03:00
|
|
|
#if CONFIG_TEMPMV_SIGNALING
|
|
|
|
if (cm->use_prev_frame_mvs && rf[1] == NONE_FRAME) {
|
|
|
|
#else
|
2016-08-12 04:55:00 +03:00
|
|
|
if (prev_frame_mvs_base && cm->show_frame && cm->last_show_frame &&
|
2017-01-21 02:03:11 +03:00
|
|
|
rf[1] == NONE_FRAME) {
|
2016-12-15 00:40:54 +03:00
|
|
|
#endif
|
2015-12-02 21:59:01 +03:00
|
|
|
int blk_row, blk_col;
|
2016-09-27 20:29:34 +03:00
|
|
|
int coll_blk_count = 0;
|
2016-12-17 01:52:45 +03:00
|
|
|
#if CONFIG_CB4X4
|
|
|
|
const int mi_step = (xd->n8_w == 1 || xd->n8_h == 1)
|
|
|
|
? mi_size_wide[BLOCK_8X8]
|
|
|
|
: mi_size_wide[BLOCK_16X16];
|
|
|
|
#else
|
2016-12-09 23:37:28 +03:00
|
|
|
const int mi_step = mi_size_wide[BLOCK_16X16];
|
2016-12-17 01:52:45 +03:00
|
|
|
#endif
|
2017-01-31 01:39:28 +03:00
|
|
|
|
|
|
|
#if CONFIG_TPL_MV
|
|
|
|
int tpl_sample_pos[5][2] = { { -1, xd->n8_w },
|
|
|
|
{ 0, xd->n8_w },
|
|
|
|
{ xd->n8_h, xd->n8_w },
|
|
|
|
{ xd->n8_h, 0 },
|
|
|
|
{ xd->n8_h, -1 } };
|
|
|
|
int i;
|
|
|
|
#endif
|
|
|
|
|
2016-12-09 23:37:28 +03:00
|
|
|
for (blk_row = 0; blk_row < xd->n8_h; blk_row += mi_step) {
|
|
|
|
for (blk_col = 0; blk_col < xd->n8_w; blk_col += mi_step) {
|
2016-09-27 20:29:34 +03:00
|
|
|
coll_blk_count += add_col_ref_mv(
|
|
|
|
cm, prev_frame_mvs_base, xd, mi_row, mi_col, ref_frame, blk_row,
|
|
|
|
blk_col, refmv_count, ref_mv_stack, mode_context);
|
2015-12-02 03:26:06 +03:00
|
|
|
}
|
|
|
|
}
|
2017-01-31 01:39:28 +03:00
|
|
|
|
|
|
|
#if CONFIG_TPL_MV
|
|
|
|
for (i = 0; i < 5; ++i) {
|
|
|
|
blk_row = tpl_sample_pos[i][0];
|
|
|
|
blk_col = tpl_sample_pos[i][1];
|
|
|
|
coll_blk_count += add_col_ref_mv(cm, prev_frame_mvs_base, xd, mi_row,
|
|
|
|
mi_col, ref_frame, blk_row, blk_col,
|
|
|
|
refmv_count, ref_mv_stack, mode_context);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-09-27 20:29:34 +03:00
|
|
|
if (coll_blk_count == 0) mode_context[ref_frame] |= (1 << ZEROMV_OFFSET);
|
|
|
|
} else {
|
2015-12-02 21:59:01 +03:00
|
|
|
mode_context[ref_frame] |= (1 << ZEROMV_OFFSET);
|
2016-09-27 20:29:34 +03:00
|
|
|
}
|
2015-11-23 23:05:48 +03:00
|
|
|
|
2016-11-21 09:34:12 +03:00
|
|
|
// Scan the second outer area.
|
2016-10-17 09:06:35 +03:00
|
|
|
scan_blk_mbmi(cm, xd, mi_row, mi_col, block, rf, -1, -1, ref_mv_stack,
|
|
|
|
refmv_count);
|
|
|
|
for (idx = 2; idx <= 3; ++idx) {
|
|
|
|
scan_row_mbmi(cm, xd, mi_row, mi_col, block, rf, -idx, ref_mv_stack,
|
|
|
|
refmv_count);
|
|
|
|
scan_col_mbmi(cm, xd, mi_row, mi_col, block, rf, -idx, ref_mv_stack,
|
|
|
|
refmv_count);
|
|
|
|
}
|
|
|
|
scan_col_mbmi(cm, xd, mi_row, mi_col, block, rf, -4, ref_mv_stack,
|
|
|
|
refmv_count);
|
2015-11-23 23:05:48 +03:00
|
|
|
|
2015-12-05 02:18:17 +03:00
|
|
|
switch (nearest_refmv_count) {
|
|
|
|
case 0:
|
|
|
|
mode_context[ref_frame] |= 0;
|
2016-08-12 04:55:00 +03:00
|
|
|
if (*refmv_count >= 1) mode_context[ref_frame] |= 1;
|
2015-12-05 02:18:17 +03:00
|
|
|
|
|
|
|
if (*refmv_count == 1)
|
|
|
|
mode_context[ref_frame] |= (1 << REFMV_OFFSET);
|
|
|
|
else if (*refmv_count >= 2)
|
|
|
|
mode_context[ref_frame] |= (2 << REFMV_OFFSET);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
mode_context[ref_frame] |= (newmv_count > 0) ? 2 : 3;
|
|
|
|
|
|
|
|
if (*refmv_count == 1)
|
|
|
|
mode_context[ref_frame] |= (3 << REFMV_OFFSET);
|
|
|
|
else if (*refmv_count >= 2)
|
|
|
|
mode_context[ref_frame] |= (4 << REFMV_OFFSET);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
default:
|
|
|
|
if (newmv_count >= 2)
|
|
|
|
mode_context[ref_frame] |= 4;
|
|
|
|
else if (newmv_count == 1)
|
|
|
|
mode_context[ref_frame] |= 5;
|
|
|
|
else
|
|
|
|
mode_context[ref_frame] |= 6;
|
|
|
|
|
|
|
|
mode_context[ref_frame] |= (5 << REFMV_OFFSET);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-23 23:05:48 +03:00
|
|
|
// Rank the likelihood and assign nearest and near mvs.
|
|
|
|
len = nearest_refmv_count;
|
|
|
|
while (len > 0) {
|
|
|
|
nr_len = 0;
|
|
|
|
for (idx = 1; idx < len; ++idx) {
|
|
|
|
if (ref_mv_stack[idx - 1].weight < ref_mv_stack[idx].weight) {
|
|
|
|
tmp_mv = ref_mv_stack[idx - 1];
|
|
|
|
ref_mv_stack[idx - 1] = ref_mv_stack[idx];
|
|
|
|
ref_mv_stack[idx] = tmp_mv;
|
|
|
|
nr_len = idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len = nr_len;
|
|
|
|
}
|
|
|
|
|
2015-11-24 02:05:18 +03:00
|
|
|
len = *refmv_count;
|
2015-11-23 23:05:48 +03:00
|
|
|
while (len > nearest_refmv_count) {
|
|
|
|
nr_len = nearest_refmv_count;
|
|
|
|
for (idx = nearest_refmv_count + 1; idx < len; ++idx) {
|
|
|
|
if (ref_mv_stack[idx - 1].weight < ref_mv_stack[idx].weight) {
|
|
|
|
tmp_mv = ref_mv_stack[idx - 1];
|
|
|
|
ref_mv_stack[idx - 1] = ref_mv_stack[idx];
|
|
|
|
ref_mv_stack[idx] = tmp_mv;
|
|
|
|
nr_len = idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len = nr_len;
|
|
|
|
}
|
|
|
|
|
2017-01-21 02:03:11 +03:00
|
|
|
if (rf[1] > NONE_FRAME) {
|
2016-01-13 02:06:59 +03:00
|
|
|
for (idx = 0; idx < *refmv_count; ++idx) {
|
2016-12-07 20:55:21 +03:00
|
|
|
clamp_mv_ref(&ref_mv_stack[idx].this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
|
|
|
|
xd->n8_h << MI_SIZE_LOG2, xd);
|
|
|
|
clamp_mv_ref(&ref_mv_stack[idx].comp_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
|
|
|
|
xd->n8_h << MI_SIZE_LOG2, xd);
|
2016-01-13 02:06:59 +03:00
|
|
|
}
|
|
|
|
} else {
|
2016-08-31 00:01:10 +03:00
|
|
|
for (idx = 0; idx < AOMMIN(MAX_MV_REF_CANDIDATES, *refmv_count); ++idx) {
|
2016-01-13 02:06:59 +03:00
|
|
|
mv_ref_list[idx].as_int = ref_mv_stack[idx].this_mv.as_int;
|
2016-12-07 20:55:21 +03:00
|
|
|
clamp_mv_ref(&mv_ref_list[idx].as_mv, xd->n8_w << MI_SIZE_LOG2,
|
|
|
|
xd->n8_h << MI_SIZE_LOG2, xd);
|
2016-01-13 02:06:59 +03:00
|
|
|
}
|
2015-11-23 23:05:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-06 05:00:31 +03:00
|
|
|
// This function searches the neighbourhood of a given MB/SB
|
|
|
|
// to try and find candidate reference vectors.
|
2016-08-31 00:01:10 +03:00
|
|
|
static void find_mv_refs_idx(const AV1_COMMON *cm, const MACROBLOCKD *xd,
|
2015-08-06 05:00:31 +03:00
|
|
|
MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
|
2016-08-12 04:55:00 +03:00
|
|
|
int_mv *mv_ref_list, int block, int mi_row,
|
|
|
|
int mi_col, find_mv_refs_sync sync,
|
2016-12-01 20:04:16 +03:00
|
|
|
void *const data, int16_t *mode_context,
|
|
|
|
int_mv zeromv) {
|
2015-08-06 05:00:31 +03:00
|
|
|
const int *ref_sign_bias = cm->ref_frame_sign_bias;
|
|
|
|
int i, refmv_count = 0;
|
|
|
|
int different_ref_found = 0;
|
|
|
|
int context_counter = 0;
|
2017-02-17 12:49:03 +03:00
|
|
|
#if CONFIG_MV_COMPRESS
|
|
|
|
const TileInfo *const tile_ = &xd->tile;
|
|
|
|
int mi_row_end = tile_->mi_row_end;
|
|
|
|
int mi_col_end = tile_->mi_col_end;
|
|
|
|
const MV_REF *const prev_frame_mvs =
|
|
|
|
cm->use_prev_frame_mvs
|
|
|
|
? cm->prev_frame->mvs +
|
|
|
|
AOMMIN(((mi_row >> 1) << 1) + 1 + (((xd->n8_h - 1) >> 1) << 1),
|
|
|
|
mi_row_end - 1) *
|
|
|
|
cm->mi_cols +
|
|
|
|
AOMMIN(((mi_col >> 1) << 1) + 1 + (((xd->n8_w - 1) >> 1) << 1),
|
|
|
|
mi_col_end - 1)
|
|
|
|
: NULL;
|
|
|
|
#else
|
2016-08-12 04:55:00 +03:00
|
|
|
const MV_REF *const prev_frame_mvs =
|
|
|
|
cm->use_prev_frame_mvs
|
|
|
|
? cm->prev_frame->mvs + mi_row * cm->mi_cols + mi_col
|
|
|
|
: NULL;
|
2017-05-11 19:36:10 +03:00
|
|
|
#endif
|
|
|
|
#if CONFIG_INTRABC
|
|
|
|
assert(IMPLIES(ref_frame == INTRA_FRAME, cm->use_prev_frame_mvs == 0));
|
2017-02-17 12:49:03 +03:00
|
|
|
#endif
|
2015-08-06 05:00:31 +03:00
|
|
|
const TileInfo *const tile = &xd->tile;
|
2016-12-09 23:37:28 +03:00
|
|
|
const BLOCK_SIZE bsize = mi->mbmi.sb_type;
|
|
|
|
const int bw = block_size_wide[AOMMAX(bsize, BLOCK_8X8)];
|
|
|
|
const int bh = block_size_high[AOMMAX(bsize, BLOCK_8X8)];
|
2016-10-17 09:06:35 +03:00
|
|
|
POSITION mv_ref_search[MVREF_NEIGHBOURS];
|
2016-12-09 23:37:28 +03:00
|
|
|
const int num_8x8_blocks_wide = num_8x8_blocks_wide_lookup[bsize];
|
|
|
|
const int num_8x8_blocks_high = num_8x8_blocks_high_lookup[bsize];
|
2016-10-17 09:06:35 +03:00
|
|
|
mv_ref_search[0].row = num_8x8_blocks_high - 1;
|
|
|
|
mv_ref_search[0].col = -1;
|
|
|
|
mv_ref_search[1].row = -1;
|
|
|
|
mv_ref_search[1].col = num_8x8_blocks_wide - 1;
|
|
|
|
mv_ref_search[2].row = -1;
|
|
|
|
mv_ref_search[2].col = (num_8x8_blocks_wide - 1) >> 1;
|
|
|
|
mv_ref_search[3].row = (num_8x8_blocks_high - 1) >> 1;
|
|
|
|
mv_ref_search[3].col = -1;
|
|
|
|
mv_ref_search[4].row = -1;
|
|
|
|
mv_ref_search[4].col = -1;
|
2017-01-26 19:50:48 +03:00
|
|
|
#if CONFIG_EXT_PARTITION_TYPES
|
|
|
|
if (num_8x8_blocks_wide == num_8x8_blocks_high) {
|
|
|
|
mv_ref_search[5].row = -1;
|
|
|
|
mv_ref_search[5].col = 0;
|
|
|
|
mv_ref_search[6].row = 0;
|
|
|
|
mv_ref_search[6].col = -1;
|
|
|
|
} else {
|
|
|
|
mv_ref_search[5].row = -1;
|
|
|
|
mv_ref_search[5].col = num_8x8_blocks_wide;
|
|
|
|
mv_ref_search[6].row = num_8x8_blocks_high;
|
|
|
|
mv_ref_search[6].col = -1;
|
|
|
|
}
|
|
|
|
#else
|
2016-10-17 09:06:35 +03:00
|
|
|
mv_ref_search[5].row = -1;
|
|
|
|
mv_ref_search[5].col = num_8x8_blocks_wide;
|
|
|
|
mv_ref_search[6].row = num_8x8_blocks_high;
|
|
|
|
mv_ref_search[6].col = -1;
|
2017-01-26 19:50:48 +03:00
|
|
|
#endif // CONFIG_EXT_PARTITION_TYPES
|
2016-10-17 09:06:35 +03:00
|
|
|
mv_ref_search[7].row = -1;
|
|
|
|
mv_ref_search[7].col = -3;
|
|
|
|
mv_ref_search[8].row = num_8x8_blocks_high - 1;
|
|
|
|
mv_ref_search[8].col = -3;
|
2016-12-09 23:37:28 +03:00
|
|
|
|
|
|
|
#if CONFIG_CB4X4
|
|
|
|
for (i = 0; i < MVREF_NEIGHBOURS; ++i) {
|
|
|
|
mv_ref_search[i].row *= 2;
|
|
|
|
mv_ref_search[i].col *= 2;
|
|
|
|
}
|
|
|
|
#endif // CONFIG_CB4X4
|
2015-08-06 05:00:31 +03:00
|
|
|
|
|
|
|
// The nearest 2 blocks are treated differently
|
|
|
|
// if the size < 8x8 we get the mv from the bmi substructure,
|
|
|
|
// and we also need to keep a mode count.
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
const POSITION *const mv_ref = &mv_ref_search[i];
|
2017-03-08 04:48:52 +03:00
|
|
|
if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, mv_ref)) {
|
2016-08-12 04:55:00 +03:00
|
|
|
const MODE_INFO *const candidate_mi =
|
|
|
|
xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
|
2015-08-06 05:00:31 +03:00
|
|
|
const MB_MODE_INFO *const candidate = &candidate_mi->mbmi;
|
|
|
|
// Keep counts for entropy encoding.
|
|
|
|
context_counter += mode_2_counter[candidate->mode];
|
|
|
|
different_ref_found = 1;
|
|
|
|
|
|
|
|
if (candidate->ref_frame[0] == ref_frame)
|
|
|
|
ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block),
|
2015-10-20 20:31:40 +03:00
|
|
|
refmv_count, mv_ref_list, bw, bh, xd, Done);
|
2015-08-06 05:00:31 +03:00
|
|
|
else if (candidate->ref_frame[1] == ref_frame)
|
|
|
|
ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block),
|
2015-10-20 20:31:40 +03:00
|
|
|
refmv_count, mv_ref_list, bw, bh, xd, Done);
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the rest of the neighbors in much the same way
|
|
|
|
// as before except we don't need to keep track of sub blocks or
|
|
|
|
// mode counts.
|
|
|
|
for (; i < MVREF_NEIGHBOURS; ++i) {
|
|
|
|
const POSITION *const mv_ref = &mv_ref_search[i];
|
2017-03-08 04:48:52 +03:00
|
|
|
if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, mv_ref)) {
|
2016-08-12 04:55:00 +03:00
|
|
|
const MB_MODE_INFO *const candidate =
|
2016-12-14 20:30:03 +03:00
|
|
|
!xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]
|
|
|
|
? NULL
|
|
|
|
: &xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]->mbmi;
|
2016-10-31 18:55:27 +03:00
|
|
|
if (candidate == NULL) continue;
|
2016-12-07 23:01:35 +03:00
|
|
|
if ((mi_row % MAX_MIB_SIZE) + mv_ref->row >= MAX_MIB_SIZE ||
|
|
|
|
(mi_col % MAX_MIB_SIZE) + mv_ref->col >= MAX_MIB_SIZE)
|
2016-10-17 09:06:35 +03:00
|
|
|
continue;
|
2015-08-06 05:00:31 +03:00
|
|
|
different_ref_found = 1;
|
|
|
|
|
|
|
|
if (candidate->ref_frame[0] == ref_frame)
|
2016-08-12 04:55:00 +03:00
|
|
|
ADD_MV_REF_LIST(candidate->mv[0], refmv_count, mv_ref_list, bw, bh, xd,
|
|
|
|
Done);
|
2015-08-06 05:00:31 +03:00
|
|
|
else if (candidate->ref_frame[1] == ref_frame)
|
2016-08-12 04:55:00 +03:00
|
|
|
ADD_MV_REF_LIST(candidate->mv[1], refmv_count, mv_ref_list, bw, bh, xd,
|
|
|
|
Done);
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 04:55:00 +03:00
|
|
|
// TODO(hkuang): Remove this sync after fixing pthread_cond_broadcast
|
|
|
|
// on windows platform. The sync here is unncessary if use_perv_frame_mvs
|
|
|
|
// is 0. But after removing it, there will be hang in the unit test on windows
|
|
|
|
// due to several threads waiting for a thread's signal.
|
2015-08-06 05:00:31 +03:00
|
|
|
#if defined(_WIN32) && !HAVE_PTHREAD_H
|
2016-08-12 04:55:00 +03:00
|
|
|
if (cm->frame_parallel_decode && sync != NULL) {
|
|
|
|
sync(data, mi_row);
|
|
|
|
}
|
2015-08-06 05:00:31 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Check the last frame's mode and mv info.
|
|
|
|
if (cm->use_prev_frame_mvs) {
|
|
|
|
// Synchronize here for frame parallel decode if sync function is provided.
|
|
|
|
if (cm->frame_parallel_decode && sync != NULL) {
|
|
|
|
sync(data, mi_row);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prev_frame_mvs->ref_frame[0] == ref_frame) {
|
2016-08-12 04:55:00 +03:00
|
|
|
ADD_MV_REF_LIST(prev_frame_mvs->mv[0], refmv_count, mv_ref_list, bw, bh,
|
|
|
|
xd, Done);
|
2015-08-06 05:00:31 +03:00
|
|
|
} else if (prev_frame_mvs->ref_frame[1] == ref_frame) {
|
2016-08-12 04:55:00 +03:00
|
|
|
ADD_MV_REF_LIST(prev_frame_mvs->mv[1], refmv_count, mv_ref_list, bw, bh,
|
|
|
|
xd, Done);
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since we couldn't find 2 mvs from the same reference frame
|
|
|
|
// go back through the neighbors and find motion vectors from
|
|
|
|
// different reference frames.
|
|
|
|
if (different_ref_found) {
|
|
|
|
for (i = 0; i < MVREF_NEIGHBOURS; ++i) {
|
|
|
|
const POSITION *mv_ref = &mv_ref_search[i];
|
2017-03-08 04:48:52 +03:00
|
|
|
if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, mv_ref)) {
|
2016-08-12 04:55:00 +03:00
|
|
|
const MB_MODE_INFO *const candidate =
|
2016-12-14 20:30:03 +03:00
|
|
|
!xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]
|
|
|
|
? NULL
|
|
|
|
: &xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]->mbmi;
|
2016-10-31 18:55:27 +03:00
|
|
|
if (candidate == NULL) continue;
|
2016-12-07 23:01:35 +03:00
|
|
|
if ((mi_row % MAX_MIB_SIZE) + mv_ref->row >= MAX_MIB_SIZE ||
|
|
|
|
(mi_col % MAX_MIB_SIZE) + mv_ref->col >= MAX_MIB_SIZE)
|
2016-10-17 09:06:35 +03:00
|
|
|
continue;
|
2015-08-06 05:00:31 +03:00
|
|
|
|
|
|
|
// If the candidate is INTRA we don't want to consider its mv.
|
|
|
|
IF_DIFF_REF_FRAME_ADD_MV(candidate, ref_frame, ref_sign_bias,
|
2015-10-20 20:31:40 +03:00
|
|
|
refmv_count, mv_ref_list, bw, bh, xd, Done);
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since we still don't have a candidate we'll try the last frame.
|
|
|
|
if (cm->use_prev_frame_mvs) {
|
|
|
|
if (prev_frame_mvs->ref_frame[0] != ref_frame &&
|
|
|
|
prev_frame_mvs->ref_frame[0] > INTRA_FRAME) {
|
|
|
|
int_mv mv = prev_frame_mvs->mv[0];
|
|
|
|
if (ref_sign_bias[prev_frame_mvs->ref_frame[0]] !=
|
|
|
|
ref_sign_bias[ref_frame]) {
|
|
|
|
mv.as_mv.row *= -1;
|
|
|
|
mv.as_mv.col *= -1;
|
|
|
|
}
|
2015-10-20 20:31:40 +03:00
|
|
|
ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, bw, bh, xd, Done);
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (prev_frame_mvs->ref_frame[1] > INTRA_FRAME &&
|
2015-09-08 21:35:24 +03:00
|
|
|
prev_frame_mvs->ref_frame[1] != ref_frame) {
|
2015-08-06 05:00:31 +03:00
|
|
|
int_mv mv = prev_frame_mvs->mv[1];
|
|
|
|
if (ref_sign_bias[prev_frame_mvs->ref_frame[1]] !=
|
|
|
|
ref_sign_bias[ref_frame]) {
|
|
|
|
mv.as_mv.row *= -1;
|
|
|
|
mv.as_mv.col *= -1;
|
|
|
|
}
|
2015-10-20 20:31:40 +03:00
|
|
|
ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, bw, bh, xd, Done);
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 00:42:59 +03:00
|
|
|
Done:
|
|
|
|
if (mode_context)
|
|
|
|
mode_context[ref_frame] = counter_to_context[context_counter];
|
2015-10-20 20:31:40 +03:00
|
|
|
for (i = refmv_count; i < MAX_MV_REF_CANDIDATES; ++i)
|
2016-12-01 20:04:16 +03:00
|
|
|
mv_ref_list[i].as_int = zeromv.as_int;
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
|
2016-01-08 02:13:52 +03:00
|
|
|
#if CONFIG_EXT_INTER
|
|
|
|
// This function keeps a mode count for a given MB/SB
|
2017-03-08 04:48:52 +03:00
|
|
|
void av1_update_mv_context(const AV1_COMMON *cm, const MACROBLOCKD *xd,
|
|
|
|
MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
|
|
|
|
int_mv *mv_ref_list, int block, int mi_row,
|
|
|
|
int mi_col, int16_t *mode_context) {
|
2016-01-08 02:13:52 +03:00
|
|
|
int i, refmv_count = 0;
|
|
|
|
int context_counter = 0;
|
2017-01-24 04:12:48 +03:00
|
|
|
const int bw = block_size_wide[mi->mbmi.sb_type];
|
|
|
|
const int bh = block_size_high[mi->mbmi.sb_type];
|
2016-01-08 02:13:52 +03:00
|
|
|
const TileInfo *const tile = &xd->tile;
|
2017-05-12 20:18:39 +03:00
|
|
|
POSITION mv_ref_search[2];
|
2017-01-24 04:12:48 +03:00
|
|
|
const int num_8x8_blocks_wide = mi_size_wide[mi->mbmi.sb_type];
|
|
|
|
const int num_8x8_blocks_high = mi_size_high[mi->mbmi.sb_type];
|
2017-05-12 20:18:39 +03:00
|
|
|
|
2016-11-18 04:42:20 +03:00
|
|
|
mv_ref_search[0].row = num_8x8_blocks_high - 1;
|
|
|
|
mv_ref_search[0].col = -1;
|
|
|
|
mv_ref_search[1].row = -1;
|
|
|
|
mv_ref_search[1].col = num_8x8_blocks_wide - 1;
|
2016-01-08 02:13:52 +03:00
|
|
|
|
|
|
|
// Blank the reference vector list
|
|
|
|
memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES);
|
|
|
|
|
|
|
|
// The nearest 2 blocks are examined only.
|
|
|
|
// If the size < 8x8, we get the mv from the bmi substructure;
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
const POSITION *const mv_ref = &mv_ref_search[i];
|
2017-03-08 04:48:52 +03:00
|
|
|
if (is_inside(tile, mi_col, mi_row, cm->mi_rows, cm, mv_ref)) {
|
2016-01-08 02:13:52 +03:00
|
|
|
const MODE_INFO *const candidate_mi =
|
|
|
|
xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
|
|
|
|
const MB_MODE_INFO *const candidate = &candidate_mi->mbmi;
|
|
|
|
|
|
|
|
// Keep counts for entropy encoding.
|
|
|
|
context_counter += mode_2_counter[candidate->mode];
|
|
|
|
|
|
|
|
if (candidate->ref_frame[0] == ref_frame) {
|
|
|
|
ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block),
|
|
|
|
refmv_count, mv_ref_list, bw, bh, xd, Done);
|
|
|
|
} else if (candidate->ref_frame[1] == ref_frame) {
|
|
|
|
ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block),
|
|
|
|
refmv_count, mv_ref_list, bw, bh, xd, Done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 04:55:00 +03:00
|
|
|
Done:
|
2016-01-08 02:13:52 +03:00
|
|
|
|
|
|
|
if (mode_context)
|
|
|
|
mode_context[ref_frame] = counter_to_context[context_counter];
|
|
|
|
}
|
|
|
|
#endif // CONFIG_EXT_INTER
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
void av1_find_mv_refs(const AV1_COMMON *cm, const MACROBLOCKD *xd,
|
|
|
|
MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
|
|
|
|
uint8_t *ref_mv_count, CANDIDATE_MV *ref_mv_stack,
|
2016-01-20 03:45:45 +03:00
|
|
|
#if CONFIG_EXT_INTER
|
2016-08-31 00:01:10 +03:00
|
|
|
int16_t *compound_mode_context,
|
2016-01-20 03:45:45 +03:00
|
|
|
#endif // CONFIG_EXT_INTER
|
2016-08-31 00:01:10 +03:00
|
|
|
int_mv *mv_ref_list, int mi_row, int mi_col,
|
|
|
|
find_mv_refs_sync sync, void *const data,
|
|
|
|
int16_t *mode_context) {
|
2016-12-01 20:04:16 +03:00
|
|
|
int_mv zeromv[2];
|
2017-05-03 07:54:41 +03:00
|
|
|
#if CONFIG_GLOBAL_MOTION
|
|
|
|
BLOCK_SIZE bsize = mi->mbmi.sb_type;
|
|
|
|
#endif // CONFIG_GLOBAL_MOTION
|
2016-12-01 20:04:16 +03:00
|
|
|
int idx, all_zero = 1;
|
|
|
|
#if CONFIG_GLOBAL_MOTION
|
|
|
|
MV_REFERENCE_FRAME rf[2];
|
2017-05-03 07:54:41 +03:00
|
|
|
#endif // CONFIG_GLOBAL_MOTION
|
2017-04-27 10:52:34 +03:00
|
|
|
|
2016-01-08 02:13:52 +03:00
|
|
|
#if CONFIG_EXT_INTER
|
2017-03-08 04:48:52 +03:00
|
|
|
av1_update_mv_context(cm, xd, mi, ref_frame, mv_ref_list, -1, mi_row, mi_col,
|
2016-08-31 00:01:10 +03:00
|
|
|
compound_mode_context);
|
2016-09-27 22:55:32 +03:00
|
|
|
#endif // CONFIG_EXT_INTER
|
2016-12-01 20:04:16 +03:00
|
|
|
|
|
|
|
#if CONFIG_GLOBAL_MOTION
|
2017-06-14 22:32:35 +03:00
|
|
|
if (!CONFIG_INTRABC || ref_frame != INTRA_FRAME) {
|
|
|
|
av1_set_ref_frame(rf, ref_frame);
|
|
|
|
zeromv[0].as_int = gm_get_motion_vector(&cm->global_motion[rf[0]],
|
|
|
|
cm->allow_high_precision_mv, bsize,
|
|
|
|
mi_col, mi_row, 0)
|
|
|
|
.as_int;
|
|
|
|
zeromv[1].as_int = (rf[1] != NONE_FRAME)
|
|
|
|
? gm_get_motion_vector(&cm->global_motion[rf[1]],
|
|
|
|
cm->allow_high_precision_mv,
|
|
|
|
bsize, mi_col, mi_row, 0)
|
|
|
|
.as_int
|
|
|
|
: 0;
|
|
|
|
} else {
|
|
|
|
zeromv[0].as_int = zeromv[1].as_int = 0;
|
|
|
|
}
|
2016-12-01 20:04:16 +03:00
|
|
|
#else
|
|
|
|
zeromv[0].as_int = zeromv[1].as_int = 0;
|
2017-02-03 14:07:56 +03:00
|
|
|
#endif // CONFIG_GLOBAL_MOTION
|
2016-12-01 20:04:16 +03:00
|
|
|
|
2016-09-27 22:55:32 +03:00
|
|
|
if (ref_frame <= ALTREF_FRAME)
|
2016-12-01 20:04:16 +03:00
|
|
|
find_mv_refs_idx(cm, xd, mi, ref_frame, mv_ref_list, -1, mi_row, mi_col,
|
|
|
|
sync, data, mode_context, zeromv[0]);
|
2015-11-23 23:05:48 +03:00
|
|
|
|
2016-08-12 04:55:00 +03:00
|
|
|
setup_ref_mv_list(cm, xd, ref_frame, ref_mv_count, ref_mv_stack, mv_ref_list,
|
|
|
|
-1, mi_row, mi_col, mode_context);
|
2016-12-01 20:04:16 +03:00
|
|
|
/* Note: If global motion is enabled, then we want to set the ALL_ZERO flag
|
|
|
|
iff all of the MVs we could generate with NEARMV/NEARESTMV are equivalent
|
|
|
|
to the global motion vector.
|
|
|
|
Note: For the following to work properly, the encoder can't throw away
|
|
|
|
any global motion models after calling this function, even if they are
|
|
|
|
unused. Instead we rely on the recode loop: If any non-IDENTITY model
|
|
|
|
is unused, the whole frame will be re-encoded without it.
|
|
|
|
The problem is that, otherwise, we can end up in the following situation:
|
|
|
|
* Encoder has a global motion model with nonzero translational part,
|
|
|
|
and all candidate MVs are zero. So the ALL_ZERO flag is unset.
|
|
|
|
* Encoder throws away global motion because it is never used.
|
|
|
|
* Decoder sees that there is no global motion and all candidate MVs are
|
|
|
|
zero, so sets the ALL_ZERO flag.
|
|
|
|
* This leads to an encode/decode mismatch.
|
|
|
|
*/
|
2016-09-27 22:55:32 +03:00
|
|
|
if (*ref_mv_count >= 2) {
|
|
|
|
for (idx = 0; idx < AOMMIN(3, *ref_mv_count); ++idx) {
|
2016-12-01 20:04:16 +03:00
|
|
|
if (ref_mv_stack[idx].this_mv.as_int != zeromv[0].as_int) all_zero = 0;
|
2016-09-27 22:55:32 +03:00
|
|
|
if (ref_frame > ALTREF_FRAME)
|
2016-12-01 20:04:16 +03:00
|
|
|
if (ref_mv_stack[idx].comp_mv.as_int != zeromv[1].as_int) all_zero = 0;
|
2016-09-27 22:55:32 +03:00
|
|
|
}
|
|
|
|
} else if (ref_frame <= ALTREF_FRAME) {
|
|
|
|
for (idx = 0; idx < MAX_MV_REF_CANDIDATES; ++idx)
|
2016-12-01 20:04:16 +03:00
|
|
|
if (mv_ref_list[idx].as_int != zeromv[0].as_int) all_zero = 0;
|
2016-09-27 22:55:32 +03:00
|
|
|
}
|
2015-12-08 02:54:59 +03:00
|
|
|
|
2016-08-12 04:55:00 +03:00
|
|
|
if (all_zero) mode_context[ref_frame] |= (1 << ALL_ZERO_FLAG_OFFSET);
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
void av1_find_best_ref_mvs(int allow_hp, int_mv *mvlist, int_mv *nearest_mv,
|
|
|
|
int_mv *near_mv) {
|
2015-08-06 05:00:31 +03:00
|
|
|
int i;
|
|
|
|
// Make sure all the candidates are properly clamped etc
|
|
|
|
for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) {
|
|
|
|
lower_mv_precision(&mvlist[i].as_mv, allow_hp);
|
|
|
|
}
|
|
|
|
*nearest_mv = mvlist[0];
|
|
|
|
*near_mv = mvlist[1];
|
|
|
|
}
|
|
|
|
|
2016-10-14 03:27:51 +03:00
|
|
|
void av1_append_sub8x8_mvs_for_idx(const AV1_COMMON *cm, MACROBLOCKD *xd,
|
|
|
|
int block, int ref, int mi_row, int mi_col,
|
2016-08-31 00:01:10 +03:00
|
|
|
CANDIDATE_MV *ref_mv_stack,
|
|
|
|
uint8_t *ref_mv_count,
|
2016-01-08 02:13:52 +03:00
|
|
|
#if CONFIG_EXT_INTER
|
2016-08-31 00:01:10 +03:00
|
|
|
int_mv *mv_list,
|
2016-01-08 02:13:52 +03:00
|
|
|
#endif // CONFIG_EXT_INTER
|
2016-08-31 00:01:10 +03:00
|
|
|
int_mv *nearest_mv, int_mv *near_mv) {
|
2016-01-08 02:13:52 +03:00
|
|
|
#if !CONFIG_EXT_INTER
|
2015-08-06 05:00:31 +03:00
|
|
|
int_mv mv_list[MAX_MV_REF_CANDIDATES];
|
2016-01-08 02:13:52 +03:00
|
|
|
#endif // !CONFIG_EXT_INTER
|
2015-08-06 05:00:31 +03:00
|
|
|
MODE_INFO *const mi = xd->mi[0];
|
|
|
|
b_mode_info *bmi = mi->bmi;
|
|
|
|
int n;
|
2016-12-01 20:04:16 +03:00
|
|
|
int_mv zeromv;
|
2015-11-24 20:01:19 +03:00
|
|
|
CANDIDATE_MV tmp_mv;
|
2016-03-15 01:04:58 +03:00
|
|
|
uint8_t idx;
|
2015-11-24 20:01:19 +03:00
|
|
|
uint8_t above_count = 0, left_count = 0;
|
2017-01-21 02:03:11 +03:00
|
|
|
MV_REFERENCE_FRAME rf[2] = { mi->mbmi.ref_frame[ref], NONE_FRAME };
|
2016-03-15 01:04:58 +03:00
|
|
|
*ref_mv_count = 0;
|
2015-08-06 05:00:31 +03:00
|
|
|
|
|
|
|
assert(MAX_MV_REF_CANDIDATES == 2);
|
|
|
|
|
2016-12-01 20:04:16 +03:00
|
|
|
#if CONFIG_GLOBAL_MOTION
|
|
|
|
zeromv.as_int =
|
2017-02-20 17:44:40 +03:00
|
|
|
gm_get_motion_vector(&cm->global_motion[ref], cm->allow_high_precision_mv,
|
2017-03-02 23:23:45 +03:00
|
|
|
mi->mbmi.sb_type, mi_col, mi_row, block)
|
2016-12-01 20:04:16 +03:00
|
|
|
.as_int;
|
|
|
|
#else
|
|
|
|
zeromv.as_int = 0;
|
|
|
|
#endif
|
2016-08-12 04:55:00 +03:00
|
|
|
find_mv_refs_idx(cm, xd, mi, mi->mbmi.ref_frame[ref], mv_list, block, mi_row,
|
2016-12-01 20:04:16 +03:00
|
|
|
mi_col, NULL, NULL, NULL, zeromv);
|
2015-08-06 05:00:31 +03:00
|
|
|
|
2016-08-12 04:55:00 +03:00
|
|
|
scan_blk_mbmi(cm, xd, mi_row, mi_col, block, rf, -1, 0, ref_mv_stack,
|
|
|
|
ref_mv_count);
|
2016-03-15 01:04:58 +03:00
|
|
|
above_count = *ref_mv_count;
|
2015-11-24 20:01:19 +03:00
|
|
|
|
2016-08-12 04:55:00 +03:00
|
|
|
scan_blk_mbmi(cm, xd, mi_row, mi_col, block, rf, 0, -1, ref_mv_stack,
|
|
|
|
ref_mv_count);
|
2016-03-15 01:04:58 +03:00
|
|
|
left_count = *ref_mv_count - above_count;
|
2015-11-24 20:01:19 +03:00
|
|
|
|
|
|
|
if (above_count > 1 && left_count > 0) {
|
|
|
|
tmp_mv = ref_mv_stack[1];
|
|
|
|
ref_mv_stack[1] = ref_mv_stack[above_count];
|
|
|
|
ref_mv_stack[above_count] = tmp_mv;
|
|
|
|
}
|
|
|
|
|
2016-03-21 22:55:24 +03:00
|
|
|
for (idx = 0; idx < *ref_mv_count; ++idx)
|
2016-12-07 20:55:21 +03:00
|
|
|
clamp_mv_ref(&ref_mv_stack[idx].this_mv.as_mv, xd->n8_w << MI_SIZE_LOG2,
|
|
|
|
xd->n8_h << MI_SIZE_LOG2, xd);
|
2016-03-21 22:55:24 +03:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
for (idx = 0; idx < AOMMIN(MAX_MV_REF_CANDIDATES, *ref_mv_count); ++idx)
|
2016-03-21 22:55:24 +03:00
|
|
|
mv_list[idx].as_int = ref_mv_stack[idx].this_mv.as_int;
|
2015-11-24 20:01:19 +03:00
|
|
|
|
2015-08-06 05:00:31 +03:00
|
|
|
near_mv->as_int = 0;
|
|
|
|
switch (block) {
|
|
|
|
case 0:
|
|
|
|
nearest_mv->as_int = mv_list[0].as_int;
|
|
|
|
near_mv->as_int = mv_list[1].as_int;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
nearest_mv->as_int = bmi[0].as_mv[ref].as_int;
|
|
|
|
for (n = 0; n < MAX_MV_REF_CANDIDATES; ++n)
|
|
|
|
if (nearest_mv->as_int != mv_list[n].as_int) {
|
|
|
|
near_mv->as_int = mv_list[n].as_int;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3: {
|
|
|
|
int_mv candidates[2 + MAX_MV_REF_CANDIDATES];
|
|
|
|
candidates[0] = bmi[1].as_mv[ref];
|
|
|
|
candidates[1] = bmi[0].as_mv[ref];
|
|
|
|
candidates[2] = mv_list[0];
|
|
|
|
candidates[3] = mv_list[1];
|
|
|
|
|
|
|
|
nearest_mv->as_int = bmi[2].as_mv[ref].as_int;
|
|
|
|
for (n = 0; n < 2 + MAX_MV_REF_CANDIDATES; ++n)
|
|
|
|
if (nearest_mv->as_int != candidates[n].as_int) {
|
|
|
|
near_mv->as_int = candidates[n].as_int;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-08-12 04:55:00 +03:00
|
|
|
default: assert(0 && "Invalid block index.");
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-09 00:48:15 +03:00
|
|
|
|
|
|
|
#if CONFIG_WARPED_MOTION
|
2017-04-05 01:50:12 +03:00
|
|
|
void calc_projection_samples(MB_MODE_INFO *const mbmi, int x, int y,
|
|
|
|
int *pts_inref) {
|
|
|
|
pts_inref[0] = (x * 8) + mbmi->mv[0].as_mv.col;
|
|
|
|
pts_inref[1] = (y * 8) + mbmi->mv[0].as_mv.row;
|
2017-01-13 11:52:23 +03:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:50:56 +03:00
|
|
|
// Note: Samples returned are at 1/8-pel precision
|
2016-09-09 00:48:15 +03:00
|
|
|
int findSamples(const AV1_COMMON *cm, MACROBLOCKD *xd, int mi_row, int mi_col,
|
2017-02-26 19:50:56 +03:00
|
|
|
int *pts, int *pts_inref) {
|
2016-09-09 00:48:15 +03:00
|
|
|
MB_MODE_INFO *const mbmi0 = &(xd->mi[0]->mbmi);
|
|
|
|
int ref_frame = mbmi0->ref_frame[0];
|
|
|
|
int up_available = xd->up_available;
|
|
|
|
int left_available = xd->left_available;
|
|
|
|
int i, mi_step, np = 0;
|
2017-01-30 22:22:32 +03:00
|
|
|
int global_offset_c = mi_col * MI_SIZE;
|
|
|
|
int global_offset_r = mi_row * MI_SIZE;
|
2016-09-09 00:48:15 +03:00
|
|
|
|
|
|
|
// scan the above row
|
|
|
|
if (up_available) {
|
|
|
|
for (i = 0; i < AOMMIN(xd->n8_w, cm->mi_cols - mi_col); i += mi_step) {
|
|
|
|
int mi_row_offset = -1;
|
|
|
|
int mi_col_offset = i;
|
|
|
|
|
|
|
|
MODE_INFO *mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride];
|
|
|
|
MB_MODE_INFO *mbmi = &mi->mbmi;
|
|
|
|
|
2017-01-30 22:22:32 +03:00
|
|
|
mi_step = AOMMIN(xd->n8_w, mi_size_wide[mbmi->sb_type]);
|
2016-09-09 00:48:15 +03:00
|
|
|
|
2017-01-21 02:03:11 +03:00
|
|
|
if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) {
|
2016-12-01 20:04:16 +03:00
|
|
|
int bw = block_size_wide[mbmi->sb_type];
|
|
|
|
int bh = block_size_high[mbmi->sb_type];
|
2017-01-30 22:22:32 +03:00
|
|
|
int cr_offset = -AOMMAX(bh, MI_SIZE) / 2 - 1;
|
|
|
|
int cc_offset = i * MI_SIZE + AOMMAX(bw, MI_SIZE) / 2 - 1;
|
Use 1 sample per neighbor for local warping model estimation
Only 1 sample needs to be collected. Max of 8 neighbors are
used.
In LS estimation, the projection samples (sx, sy)->(dx, dy) are
intentionally smoothed by assuming 3 shifted versions
(sx, sy+n)->(dx, dy+n), (sx+n, sy)->(dx+n, dy), (sx+n,
sy+n)->(dx+n, dy+n) also contribute to the estimation.
For example, instead of using A[0] = sx^2, we use the sum of
squares of source x of four points, A[0] += 4sx^2+4*n*sx+n^2.
But computational cost wise, it does not add much overhead. Coding
gain is mostly same as the old version. If no smoothing is added,
will lose 0.3% on lowres.
Change-Id: I04be32cffa525f7dc8ee583c0bf211d7bdc6e609
2017-03-31 22:24:42 +03:00
|
|
|
int x = cc_offset + global_offset_c;
|
|
|
|
int y = cr_offset + global_offset_r;
|
2016-09-09 00:48:15 +03:00
|
|
|
|
Use 1 sample per neighbor for local warping model estimation
Only 1 sample needs to be collected. Max of 8 neighbors are
used.
In LS estimation, the projection samples (sx, sy)->(dx, dy) are
intentionally smoothed by assuming 3 shifted versions
(sx, sy+n)->(dx, dy+n), (sx+n, sy)->(dx+n, dy), (sx+n,
sy+n)->(dx+n, dy+n) also contribute to the estimation.
For example, instead of using A[0] = sx^2, we use the sum of
squares of source x of four points, A[0] += 4sx^2+4*n*sx+n^2.
But computational cost wise, it does not add much overhead. Coding
gain is mostly same as the old version. If no smoothing is added,
will lose 0.3% on lowres.
Change-Id: I04be32cffa525f7dc8ee583c0bf211d7bdc6e609
2017-03-31 22:24:42 +03:00
|
|
|
pts[0] = (x * 8);
|
|
|
|
pts[1] = (y * 8);
|
2017-04-05 01:50:12 +03:00
|
|
|
calc_projection_samples(mbmi, x, y, pts_inref);
|
Use 1 sample per neighbor for local warping model estimation
Only 1 sample needs to be collected. Max of 8 neighbors are
used.
In LS estimation, the projection samples (sx, sy)->(dx, dy) are
intentionally smoothed by assuming 3 shifted versions
(sx, sy+n)->(dx, dy+n), (sx+n, sy)->(dx+n, dy), (sx+n,
sy+n)->(dx+n, dy+n) also contribute to the estimation.
For example, instead of using A[0] = sx^2, we use the sum of
squares of source x of four points, A[0] += 4sx^2+4*n*sx+n^2.
But computational cost wise, it does not add much overhead. Coding
gain is mostly same as the old version. If no smoothing is added,
will lose 0.3% on lowres.
Change-Id: I04be32cffa525f7dc8ee583c0bf211d7bdc6e609
2017-03-31 22:24:42 +03:00
|
|
|
pts += 2;
|
|
|
|
pts_inref += 2;
|
|
|
|
np++;
|
|
|
|
if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX;
|
2016-09-09 00:48:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-27 02:23:35 +03:00
|
|
|
assert(2 * np <= SAMPLES_ARRAY_SIZE);
|
2016-09-09 00:48:15 +03:00
|
|
|
|
|
|
|
// scan the left column
|
|
|
|
if (left_available) {
|
|
|
|
for (i = 0; i < AOMMIN(xd->n8_h, cm->mi_rows - mi_row); i += mi_step) {
|
|
|
|
int mi_row_offset = i;
|
|
|
|
int mi_col_offset = -1;
|
|
|
|
|
|
|
|
MODE_INFO *mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride];
|
|
|
|
MB_MODE_INFO *mbmi = &mi->mbmi;
|
|
|
|
|
2017-01-30 22:22:32 +03:00
|
|
|
mi_step = AOMMIN(xd->n8_h, mi_size_high[mbmi->sb_type]);
|
2016-09-09 00:48:15 +03:00
|
|
|
|
2017-01-21 02:03:11 +03:00
|
|
|
if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) {
|
2016-12-01 20:04:16 +03:00
|
|
|
int bw = block_size_wide[mbmi->sb_type];
|
|
|
|
int bh = block_size_high[mbmi->sb_type];
|
2017-01-30 22:22:32 +03:00
|
|
|
int cr_offset = i * MI_SIZE + AOMMAX(bh, MI_SIZE) / 2 - 1;
|
|
|
|
int cc_offset = -AOMMAX(bw, MI_SIZE) / 2 - 1;
|
Use 1 sample per neighbor for local warping model estimation
Only 1 sample needs to be collected. Max of 8 neighbors are
used.
In LS estimation, the projection samples (sx, sy)->(dx, dy) are
intentionally smoothed by assuming 3 shifted versions
(sx, sy+n)->(dx, dy+n), (sx+n, sy)->(dx+n, dy), (sx+n,
sy+n)->(dx+n, dy+n) also contribute to the estimation.
For example, instead of using A[0] = sx^2, we use the sum of
squares of source x of four points, A[0] += 4sx^2+4*n*sx+n^2.
But computational cost wise, it does not add much overhead. Coding
gain is mostly same as the old version. If no smoothing is added,
will lose 0.3% on lowres.
Change-Id: I04be32cffa525f7dc8ee583c0bf211d7bdc6e609
2017-03-31 22:24:42 +03:00
|
|
|
int x = cc_offset + global_offset_c;
|
|
|
|
int y = cr_offset + global_offset_r;
|
2016-09-09 00:48:15 +03:00
|
|
|
|
Use 1 sample per neighbor for local warping model estimation
Only 1 sample needs to be collected. Max of 8 neighbors are
used.
In LS estimation, the projection samples (sx, sy)->(dx, dy) are
intentionally smoothed by assuming 3 shifted versions
(sx, sy+n)->(dx, dy+n), (sx+n, sy)->(dx+n, dy), (sx+n,
sy+n)->(dx+n, dy+n) also contribute to the estimation.
For example, instead of using A[0] = sx^2, we use the sum of
squares of source x of four points, A[0] += 4sx^2+4*n*sx+n^2.
But computational cost wise, it does not add much overhead. Coding
gain is mostly same as the old version. If no smoothing is added,
will lose 0.3% on lowres.
Change-Id: I04be32cffa525f7dc8ee583c0bf211d7bdc6e609
2017-03-31 22:24:42 +03:00
|
|
|
pts[0] = (x * 8);
|
|
|
|
pts[1] = (y * 8);
|
2017-04-05 01:50:12 +03:00
|
|
|
calc_projection_samples(mbmi, x, y, pts_inref);
|
Use 1 sample per neighbor for local warping model estimation
Only 1 sample needs to be collected. Max of 8 neighbors are
used.
In LS estimation, the projection samples (sx, sy)->(dx, dy) are
intentionally smoothed by assuming 3 shifted versions
(sx, sy+n)->(dx, dy+n), (sx+n, sy)->(dx+n, dy), (sx+n,
sy+n)->(dx+n, dy+n) also contribute to the estimation.
For example, instead of using A[0] = sx^2, we use the sum of
squares of source x of four points, A[0] += 4sx^2+4*n*sx+n^2.
But computational cost wise, it does not add much overhead. Coding
gain is mostly same as the old version. If no smoothing is added,
will lose 0.3% on lowres.
Change-Id: I04be32cffa525f7dc8ee583c0bf211d7bdc6e609
2017-03-31 22:24:42 +03:00
|
|
|
pts += 2;
|
|
|
|
pts_inref += 2;
|
|
|
|
np++;
|
|
|
|
if (np >= LEAST_SQUARES_SAMPLES_MAX) return LEAST_SQUARES_SAMPLES_MAX;
|
2016-09-09 00:48:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-27 02:23:35 +03:00
|
|
|
assert(2 * np <= SAMPLES_ARRAY_SIZE);
|
2016-09-09 00:48:15 +03:00
|
|
|
|
|
|
|
if (left_available && up_available) {
|
|
|
|
int mi_row_offset = -1;
|
|
|
|
int mi_col_offset = -1;
|
|
|
|
|
|
|
|
MODE_INFO *mi = xd->mi[mi_col_offset + mi_row_offset * xd->mi_stride];
|
|
|
|
MB_MODE_INFO *mbmi = &mi->mbmi;
|
|
|
|
|
2017-01-21 02:03:11 +03:00
|
|
|
if (mbmi->ref_frame[0] == ref_frame && mbmi->ref_frame[1] == NONE_FRAME) {
|
2016-12-01 20:04:16 +03:00
|
|
|
int bw = block_size_wide[mbmi->sb_type];
|
|
|
|
int bh = block_size_high[mbmi->sb_type];
|
2017-01-30 22:22:32 +03:00
|
|
|
int cr_offset = -AOMMAX(bh, MI_SIZE) / 2 - 1;
|
|
|
|
int cc_offset = -AOMMAX(bw, MI_SIZE) / 2 - 1;
|
Use 1 sample per neighbor for local warping model estimation
Only 1 sample needs to be collected. Max of 8 neighbors are
used.
In LS estimation, the projection samples (sx, sy)->(dx, dy) are
intentionally smoothed by assuming 3 shifted versions
(sx, sy+n)->(dx, dy+n), (sx+n, sy)->(dx+n, dy), (sx+n,
sy+n)->(dx+n, dy+n) also contribute to the estimation.
For example, instead of using A[0] = sx^2, we use the sum of
squares of source x of four points, A[0] += 4sx^2+4*n*sx+n^2.
But computational cost wise, it does not add much overhead. Coding
gain is mostly same as the old version. If no smoothing is added,
will lose 0.3% on lowres.
Change-Id: I04be32cffa525f7dc8ee583c0bf211d7bdc6e609
2017-03-31 22:24:42 +03:00
|
|
|
int x = cc_offset + global_offset_c;
|
|
|
|
int y = cr_offset + global_offset_r;
|
2016-09-09 00:48:15 +03:00
|
|
|
|
Use 1 sample per neighbor for local warping model estimation
Only 1 sample needs to be collected. Max of 8 neighbors are
used.
In LS estimation, the projection samples (sx, sy)->(dx, dy) are
intentionally smoothed by assuming 3 shifted versions
(sx, sy+n)->(dx, dy+n), (sx+n, sy)->(dx+n, dy), (sx+n,
sy+n)->(dx+n, dy+n) also contribute to the estimation.
For example, instead of using A[0] = sx^2, we use the sum of
squares of source x of four points, A[0] += 4sx^2+4*n*sx+n^2.
But computational cost wise, it does not add much overhead. Coding
gain is mostly same as the old version. If no smoothing is added,
will lose 0.3% on lowres.
Change-Id: I04be32cffa525f7dc8ee583c0bf211d7bdc6e609
2017-03-31 22:24:42 +03:00
|
|
|
pts[0] = (x * 8);
|
|
|
|
pts[1] = (y * 8);
|
2017-04-05 01:50:12 +03:00
|
|
|
calc_projection_samples(mbmi, x, y, pts_inref);
|
Use 1 sample per neighbor for local warping model estimation
Only 1 sample needs to be collected. Max of 8 neighbors are
used.
In LS estimation, the projection samples (sx, sy)->(dx, dy) are
intentionally smoothed by assuming 3 shifted versions
(sx, sy+n)->(dx, dy+n), (sx+n, sy)->(dx+n, dy), (sx+n,
sy+n)->(dx+n, dy+n) also contribute to the estimation.
For example, instead of using A[0] = sx^2, we use the sum of
squares of source x of four points, A[0] += 4sx^2+4*n*sx+n^2.
But computational cost wise, it does not add much overhead. Coding
gain is mostly same as the old version. If no smoothing is added,
will lose 0.3% on lowres.
Change-Id: I04be32cffa525f7dc8ee583c0bf211d7bdc6e609
2017-03-31 22:24:42 +03:00
|
|
|
np++;
|
2016-09-09 00:48:15 +03:00
|
|
|
}
|
|
|
|
}
|
2017-01-27 02:23:35 +03:00
|
|
|
assert(2 * np <= SAMPLES_ARRAY_SIZE);
|
2016-09-09 00:48:15 +03:00
|
|
|
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
#endif // CONFIG_WARPED_MOTION
|