/* * Copyright (c) 2020, Alliance for Open Media. All rights reserved. * * 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.
*/
// Find good enough match. // TODO(yunqing): Separate single-ref mode and comp mode stats for fast // search. int best = INT_MAX; int match = -1; for (int j = 0; j < interp_filter_stats_idx; ++j) { const INTERPOLATION_FILTER_STATS *st = &interp_filter_stats[j]; constint mv_diff = is_interp_filter_good_match(st, mbmi, skip_level); // Exact match is found. if (mv_diff == 0) {
match = j; break;
} elseif (mv_diff < best && mv_diff <= thr[skip_level - 1][is_comp]) {
best = mv_diff;
match = j;
}
}
if (match != -1) {
mbmi->interp_filters = interp_filter_stats[match].filters; return match;
} return -1; // no match result found
}
// When skip_txfm pred is equal to default_interp_skip_flags, // skip both luma and chroma MC. // For mono-chrome images: // num_planes = 1 and cpi->default_interp_skip_flags = 1, // skip_pred = 1: skip both luma and chroma // skip_pred = 0: Evaluate luma and as num_planes=1, // skip chroma evaluation int tmp_skip_pred =
(skip_pred == interp_search_flags->default_interp_skip_flags)
? INTERP_SKIP_LUMA_SKIP_CHROMA
: skip_pred;
switch (tmp_skip_pred) { case INTERP_EVAL_LUMA_EVAL_CHROMA: // skip_pred = 0: Evaluate both luma and chroma. // Luma MC
interp_model_rd_eval(x, cpi, bsize, orig_dst, AOM_PLANE_Y, AOM_PLANE_Y,
&this_rd_stats_luma, 0);
this_rd_stats = this_rd_stats_luma; #if CONFIG_COLLECT_RD_STATS == 3
RD_STATS rd_stats_y;
av1_pick_recursive_tx_size_type_yrd(cpi, x, &rd_stats_y, bsize,
INT64_MAX);
PrintPredictionUnitStats(cpi, tile_data, x, &rd_stats_y, bsize); #endif// CONFIG_COLLECT_RD_STATS == 3
AOM_FALLTHROUGH_INTENDED; case INTERP_SKIP_LUMA_EVAL_CHROMA: // skip_pred = 1: skip luma evaluation (retain previous best luma stats) // and do chroma evaluation. for (int plane = 1; plane < num_planes; ++plane) {
int64_t tmp_rd =
RDCOST(x->rdmult, tmp_rs + this_rd_stats.rate, this_rd_stats.dist); if (tmp_rd >= *rd) {
mbmi->interp_filters = last_best; return 0;
}
interp_model_rd_eval(x, cpi, bsize, orig_dst, plane, plane,
&this_rd_stats, 0);
} break; case INTERP_SKIP_LUMA_SKIP_CHROMA: // both luma and chroma evaluation is skipped
this_rd_stats = *rd_stats; break; case INTERP_EVAL_INVALID: default: assert(0); return 0;
}
int64_t tmp_rd =
RDCOST(x->rdmult, tmp_rs + this_rd_stats.rate, this_rd_stats.dist);
if (tmp_rd < *rd) {
*rd = tmp_rd;
*switchable_rate = tmp_rs; if (skip_pred != interp_search_flags->default_interp_skip_flags) { if (skip_pred == INTERP_EVAL_LUMA_EVAL_CHROMA) { // Overwrite the data as current filter is the best one
*rd_stats_luma = this_rd_stats_luma;
*rd_stats = this_rd_stats; // As luma MC data is computed, no need to recompute after the search
x->recalc_luma_mc_data = 0;
} elseif (skip_pred == INTERP_SKIP_LUMA_EVAL_CHROMA) { // As luma MC data is not computed, update of luma data can be skipped
*rd_stats = this_rd_stats; // As luma MC data is not recomputed and current filter is the best, // indicate the possibility of recomputing MC data // If current buffer contains valid MC data, toggle to indicate that // luma MC data needs to be recomputed
x->recalc_luma_mc_data ^= 1;
}
swap_dst_buf(xd, dst_bufs, num_planes);
} return 1;
}
mbmi->interp_filters = last_best; return 0;
}
// If no filter are set to be evaluated, return from function if (allow_interp_mask == 0x0) return best_filt_type; // For block width or height is 4, skip the pred evaluation of SHARP_SHARP
tmp_skip_pred = is_w4_or_h4
? cpi->interp_search_flags.default_interp_skip_flags
: skip_pred;
// Loop over the all filter types and evaluate for only allowed filter types for (int filt_type = SHARP_SHARP; filt_type >= REG_REG; --filt_type) { constint is_filter_allowed =
get_interp_filter_allowed_mask(allow_interp_mask, filt_type); if (is_filter_allowed) if (interpolation_filter_rd(x, cpi, tile_data, bsize, orig_dst, rd,
rd_stats_y, rd_stats, switchable_rate,
dst_bufs, filt_type, switchable_ctx,
tmp_skip_pred))
best_filt_type = filt_type;
tmp_skip_pred = skip_pred;
} return best_filt_type;
}
if (cpi->sf.interp_sf.adaptive_interp_filter_search == 2) { const FRAME_UPDATE_TYPE update_type =
get_frame_update_type(&cpi->ppi->gf_group, cpi->gf_frame_index); constint ctx0 = av1_get_pred_context_switchable_interp(xd, 0); constint ctx1 = av1_get_pred_context_switchable_interp(xd, 1); int use_actual_frame_probs = 1; constint *switchable_interp_p0; constint *switchable_interp_p1; #if CONFIG_FPMT_TEST
use_actual_frame_probs =
(cpi->ppi->fpmt_unit_test_cfg == PARALLEL_SIMULATION_ENCODE) ? 0 : 1; if (!use_actual_frame_probs) {
switchable_interp_p0 = (int *)cpi->ppi->temp_frame_probs
.switchable_interp_probs[update_type][ctx0];
switchable_interp_p1 = (int *)cpi->ppi->temp_frame_probs
.switchable_interp_probs[update_type][ctx1];
} #endif if (use_actual_frame_probs) {
switchable_interp_p0 =
cpi->ppi->frame_probs.switchable_interp_probs[update_type][ctx0];
switchable_interp_p1 =
cpi->ppi->frame_probs.switchable_interp_probs[update_type][ctx1];
} staticconstint thr[7] = { 0, 8, 8, 8, 8, 0, 8 }; constint thresh = thr[update_type]; for (i = 0; i < SWITCHABLE_FILTERS; i++) { // For non-dual case, the 2 dir's prob should be identical.
assert(switchable_interp_p0[i] == switchable_interp_p1[i]); if (switchable_interp_p0[i] < thresh &&
switchable_interp_p1[i] < thresh) {
DUAL_FILTER_TYPE filt_type = i + SWITCHABLE_FILTERS * i;
reset_interp_filter_allowed_mask(&interp_filter_search_mask, filt_type);
}
}
}
// Regular filter evaluation should have been done and hence the same should // be the winner
assert(x->e_mbd.mi[0]->interp_filters.as_int == filter_sets[0].as_int); if ((skip_hor & skip_ver) != interp_search_flags->default_interp_skip_flags) {
INTERP_PRED_TYPE pred_filter_type = INTERP_HORZ_NEQ_VERT_NEQ;
int_interpfilters af = av1_broadcast_interp_filter(INTERP_INVALID);
int_interpfilters lf = af;
pred_filter_type = is_pred_filter_search_allowed(cpi, xd, bsize, &af, &lf); if (pred_filter_type) {
assert(af.as_filters.x_filter != INTERP_INVALID); int filter_idx = SWITCHABLE * af.as_filters.x_filter; // This assert tells that (filter_x == filter_y) for non-dual filter case
assert(filter_sets[filter_idx].as_filters.x_filter ==
filter_sets[filter_idx].as_filters.y_filter); if (cpi->sf.interp_sf.adaptive_interp_filter_search &&
!(get_interp_filter_allowed_mask(interp_filter_search_mask,
filter_idx))) { return;
} if (filter_idx) {
interpolation_filter_rd(x, cpi, tile_data, bsize, orig_dst, rd,
rd_stats_y, rd_stats, switchable_rate, dst_bufs,
filter_idx, switchable_ctx,
(skip_hor & skip_ver));
} return;
}
} // Reuse regular filter's modeled rd data for sharp filter for following // cases // 1) When bsize is 4x4 // 2) When block width is 4 (i.e. 4x8/4x16 blocks) and MV in vertical // direction is full-pel // 3) When block height is 4 (i.e. 8x4/16x4 blocks) and MV in horizontal // direction is full-pel // TODO(any): Optimize cases 2 and 3 further if luma MV in relavant direction // alone is full-pel
// REG_REG filter type is evaluated beforehand, hence skip it
set_interp_filter_allowed_mask(&allowed_interp_mask, SHARP_SHARP);
set_interp_filter_allowed_mask(&allowed_interp_mask, SMOOTH_SMOOTH); if (cpi->sf.interp_sf.adaptive_interp_filter_search)
allowed_interp_mask &= interp_filter_search_mask;
find_best_interp_rd_facade(x, cpi, tile_data, bsize, orig_dst, rd,
rd_stats_y, rd_stats, switchable_rate, dst_bufs,
switchable_ctx, skip_pred, allowed_interp_mask,
1);
} else { int skip_pred = (skip_hor & skip_ver); for (i = (SWITCHABLE_FILTERS + 1); i < DUAL_FILTER_SET_SIZE;
i += (SWITCHABLE_FILTERS + 1)) { // This assert tells that (filter_x == filter_y) for non-dual filter case
assert(filter_sets[i].as_filters.x_filter ==
filter_sets[i].as_filters.y_filter); if (cpi->sf.interp_sf.adaptive_interp_filter_search &&
!(get_interp_filter_allowed_mask(interp_filter_search_mask, i))) { continue;
}
interpolation_filter_rd(x, cpi, tile_data, bsize, orig_dst, rd,
rd_stats_y, rd_stats, switchable_rate, dst_bufs,
i, switchable_ctx, skip_pred); // In first iteration, smooth filter is evaluated. If smooth filter // (which is less sharper) is the winner among regular and smooth filters, // sharp filter evaluation is skipped // TODO(any): Refine this gating based on modelled rd only (i.e., by not // accounting switchable filter rate) if (cpi->sf.interp_sf.skip_sharp_interp_filter_search &&
skip_pred != interp_search_flags->default_interp_skip_flags) { if (mbmi->interp_filters.as_int == filter_sets[SMOOTH_SMOOTH].as_int) break;
}
}
}
}
staticinlinevoid calc_interp_skip_pred_flag(MACROBLOCK *const x, const AV1_COMP *const cpi, int *skip_hor, int *skip_ver) { const AV1_COMMON *cm = &cpi->common;
MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *const mbmi = xd->mi[0]; constint num_planes = av1_num_planes(cm); constint is_compound = has_second_ref(mbmi);
assert(is_intrabc_block(mbmi) == 0); for (int ref = 0; ref < 1 + is_compound; ++ref) { conststruct scale_factors *const sf =
get_ref_scale_factors_const(cm, mbmi->ref_frame[ref]); // TODO(any): Refine skip flag calculation considering scaling if (av1_is_scaled(sf)) {
*skip_hor = 0;
*skip_ver = 0; break;
} const MV mv = mbmi->mv[ref].as_mv; int skip_hor_plane = 0; int skip_ver_plane = 0; for (int plane_idx = 0; plane_idx < AOMMAX(1, (num_planes - 1));
++plane_idx) { struct macroblockd_plane *const pd = &xd->plane[plane_idx]; constint bw = pd->width; constint bh = pd->height; const MV mv_q4 = clamp_mv_to_umv_border_sb(
xd, &mv, bw, bh, pd->subsampling_x, pd->subsampling_y); constint sub_x = (mv_q4.col & SUBPEL_MASK) << SCALE_EXTRA_BITS; constint sub_y = (mv_q4.row & SUBPEL_MASK) << SCALE_EXTRA_BITS;
skip_hor_plane |= ((sub_x == 0) << plane_idx);
skip_ver_plane |= ((sub_y == 0) << plane_idx);
}
*skip_hor &= skip_hor_plane;
*skip_ver &= skip_ver_plane; // It is not valid that "luma MV is sub-pel, whereas chroma MV is not"
assert(*skip_hor != 2);
assert(*skip_ver != 2);
} // When compond prediction type is compound segment wedge, luma MC and chroma // MC need to go hand in hand as mask generated during luma MC is reuired for // chroma MC. If skip_hor = 0 and skip_ver = 1, mask used for chroma MC during // vertical filter decision may be incorrect as temporary MC evaluation // overwrites the mask. Make skip_ver as 0 for this case so that mask is // populated during luma MC if (is_compound && mbmi->compound_idx == 1 &&
mbmi->interinter_comp.type == COMPOUND_DIFFWTD) {
assert(mbmi->comp_group_idx == 1); if (*skip_hor == 0 && *skip_ver == 1) *skip_ver = 0;
}
}
/*!\brief AV1 interpolation filter search * * \ingroup inter_mode_search * * \param[in] cpi Top-level encoder structure. * \param[in] tile_data Pointer to struct holding adaptive * data/contexts/models for the tile during * encoding. * \param[in] x Pointer to struc holding all the data for * the current macroblock. * \param[in] bsize Current block size. * \param[in] tmp_dst A temporary prediction buffer to hold a * computed prediction. * \param[in,out] orig_dst A prediction buffer to hold a computed * prediction. This will eventually hold the * final prediction, and the tmp_dst info will * be copied here. * \param[in,out] rd The RD cost associated with the selected * interpolation filter parameters. * \param[in,out] switchable_rate The rate associated with using a SWITCHABLE * filter mode. * \param[in,out] skip_build_pred Indicates whether or not to build the inter * predictor. If this is 0, the inter predictor * has already been built and thus we can avoid * repeating computation. * \param[in] args HandleInterModeArgs struct holding * miscellaneous arguments for inter mode * search. See the documentation for this * struct for a description of each member. * \param[in] ref_best_rd Best RD found so far for this block. * It is used for early termination of this * search if the RD exceeds this value. * * \return Returns INT64_MAX if the filter parameters are invalid and the * current motion mode being tested should be skipped. It returns 0 if the * parameter search is a success.
*/
int64_t av1_interpolation_filter_search(
MACROBLOCK *const x, const AV1_COMP *const cpi, const TileDataEnc *tile_data, BLOCK_SIZE bsize, const BUFFER_SET *const tmp_dst, const BUFFER_SET *const orig_dst,
int64_t *const rd, int *const switchable_rate, int *skip_build_pred,
HandleInterModeArgs *args, int64_t ref_best_rd) { const AV1_COMMON *cm = &cpi->common; const InterpSearchFlags *interp_search_flags = &cpi->interp_search_flags; constint num_planes = av1_num_planes(cm);
MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *const mbmi = xd->mi[0]; constint need_search = av1_is_interp_needed(xd); constint ref_frame = xd->mi[0]->ref_frame[0];
RD_STATS rd_stats_luma, rd_stats;
// Initialization of rd_stats structures with default values
av1_init_rd_stats(&rd_stats_luma);
av1_init_rd_stats(&rd_stats);
int match_found_idx = -1; const InterpFilter assign_filter = cm->features.interp_filter;
// Do MC evaluation for default filter_type. // Luma MC
interp_model_rd_eval(x, cpi, bsize, orig_dst, AOM_PLANE_Y, AOM_PLANE_Y,
&rd_stats_luma, *skip_build_pred);
x->recalc_luma_mc_data = 0; // skip_flag=xx (in binary form) // Setting 0th flag corresonds to skipping luma MC and setting 1st bt // corresponds to skipping chroma MC skip_flag=0 corresponds to "Don't skip // luma and chroma MC" Skip flag=1 corresponds to "Skip Luma MC only" // Skip_flag=2 is not a valid case // skip_flag=3 corresponds to "Skip both luma and chroma MC" int skip_hor = interp_search_flags->default_interp_skip_flags; int skip_ver = interp_search_flags->default_interp_skip_flags;
calc_interp_skip_pred_flag(x, cpi, &skip_hor, &skip_ver);
// do interp_filter search
restore_dst_buf(xd, *tmp_dst, num_planes); const BUFFER_SET *dst_bufs[2] = { tmp_dst, orig_dst }; // Evaluate dual interp filters if (cm->seq_params->enable_dual_filter) { if (cpi->sf.interp_sf.use_fast_interpolation_filter_search) {
fast_dual_interp_filter_rd(x, cpi, tile_data, bsize, orig_dst, rd,
&rd_stats_luma, &rd_stats, switchable_rate,
dst_bufs, switchable_ctx, skip_hor, skip_ver);
} else { // Use full interpolation filter search
uint16_t allowed_interp_mask = ALLOW_ALL_INTERP_FILT_MASK; // REG_REG filter type is evaluated beforehand, so loop is repeated over // REG_SMOOTH to SHARP_SHARP for full interpolation filter search
reset_interp_filter_allowed_mask(&allowed_interp_mask, REG_REG);
find_best_interp_rd_facade(x, cpi, tile_data, bsize, orig_dst, rd,
&rd_stats_luma, &rd_stats, switchable_rate,
dst_bufs, switchable_ctx,
(skip_hor & skip_ver), allowed_interp_mask, 0);
}
} else { // Evaluate non-dual interp filters
find_best_non_dual_interp_filter(
x, cpi, tile_data, bsize, orig_dst, rd, &rd_stats_luma, &rd_stats,
switchable_rate, dst_bufs, switchable_ctx, skip_ver, skip_hor);
}
swap_dst_buf(xd, dst_bufs, num_planes); // Recompute final MC data if required if (x->recalc_luma_mc_data == 1) { // Recomputing final luma MC data is required only if the same was skipped // in either of the directions Condition below is necessary, but not // sufficient
assert((skip_hor == 1) || (skip_ver == 1)); constint mi_row = xd->mi_row; constint mi_col = xd->mi_col;
av1_enc_build_inter_predictor(cm, xd, mi_row, mi_col, orig_dst, bsize,
AOM_PLANE_Y, AOM_PLANE_Y);
}
x->pred_sse[ref_frame] = (unsignedint)(rd_stats_luma.sse >> 4);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.