/* * 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.
*/
// Allow more mesh searches for screen content type on the ARF. staticint use_fine_search_interval(const AV1_COMP *const cpi) { return cpi->is_screen_content_type &&
cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == ARF_UPDATE &&
cpi->oxcf.speed <= 2;
}
// Iterate through the tpl and collect the mvs to be used as candidates staticinlinevoid get_mv_candidate_from_tpl(const AV1_COMP *const cpi, const MACROBLOCK *x,
BLOCK_SIZE bsize, int ref,
cand_mv_t *cand, int *cand_count, int *total_cand_weight) { const SuperBlockEnc *sb_enc = &x->sb_enc; if (!sb_enc->tpl_data_count) { return;
}
if (scaled_ref_frame) { // Swap out the reference frame for a version that's been scaled to // match the resolution of the current frame, allowing the existing // full-pixel motion search code to be used without additional // modifications. for (int i = 0; i < num_planes; i++) {
backup_yv12[i] = xd->plane[i].pre[ref_idx];
}
av1_setup_pre_planes(xd, ref_idx, scaled_ref_frame, mi_row, mi_col, NULL,
num_planes);
}
// Work out the size of the first step in the mv step search. // 0 here is maximum length first step. 1 is AOMMAX >> 1 etc. int step_param; if (cpi->sf.mv_sf.auto_mv_step_size && cm->show_frame) { // Take the weighted average of the step_params based on the last frame's // max mv magnitude and that based on the best ref mvs of the current // block for the given reference.
step_param = (av1_init_search_range(x->max_mv_context[ref]) +
mv_search_params->mv_step_param) /
2;
} else {
step_param = mv_search_params->mv_step_param;
}
// cand stores start_mv and all possible MVs in a SB.
cand_mv_t cand[MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB + 1];
av1_zero(cand);
cand[0].fmv.as_fullmv = start_mv; int cnt = 1; int total_weight = 0;
constint cand_cnt = AOMMIN(2, cnt); // TODO(any): Test the speed feature for OBMC_CAUSAL mode. if (cpi->sf.mv_sf.skip_fullpel_search_using_startmv &&
mbmi->motion_mode == SIMPLE_TRANSLATION) { constint stack_size = args->start_mv_cnt; for (int cand_idx = 0; cand_idx < cand_cnt; cand_idx++) {
int_mv *fmv_cand = &cand[cand_idx].fmv; int skip_cand_mv = 0;
// Check difference between mvs in the stack and candidate mv. for (int stack_idx = 0; stack_idx < stack_size; stack_idx++) { const uint8_t this_ref_mv_idx = args->ref_mv_idx_stack[stack_idx]; const FULLPEL_MV *fmv_stack = &args->start_mv_stack[stack_idx]; constint this_newmv_valid =
args->single_newmv_valid[this_ref_mv_idx][ref]; constint row_diff = abs(fmv_stack->row - fmv_cand->as_fullmv.row); constint col_diff = abs(fmv_stack->col - fmv_cand->as_fullmv.col);
if (!this_newmv_valid) continue;
if (cpi->sf.mv_sf.skip_fullpel_search_using_startmv >= 2) { // Prunes the current start_mv candidate, if the absolute mv // difference of both row and column are <= 1. if (row_diff <= 1 && col_diff <= 1) {
skip_cand_mv = 1; break;
}
} elseif (cpi->sf.mv_sf.skip_fullpel_search_using_startmv >= 1) { // Prunes the current start_mv candidate, if the sum of the absolute // mv difference of row and column is <= 1. if (row_diff + col_diff <= 1) {
skip_cand_mv = 1; break;
}
}
} if (skip_cand_mv) { // Ensure atleast one full-pel motion search is not pruned.
assert(mbmi->ref_mv_idx != 0); // Mark the candidate mv as invalid so that motion search gets skipped.
cand[cand_idx].fmv.as_int = INVALID_MV;
} else { // Store start_mv candidate and corresponding ref_mv_idx of full-pel // search in the mv stack (except last ref_mv_idx). if (mbmi->ref_mv_idx != MAX_REF_MV_SEARCH - 1) {
assert(args->start_mv_cnt < (MAX_REF_MV_SEARCH - 1) * 2);
args->start_mv_stack[args->start_mv_cnt] = fmv_cand->as_fullmv;
args->ref_mv_idx_stack[args->start_mv_cnt] = mbmi->ref_mv_idx;
args->start_mv_cnt++;
}
}
}
}
// Hot fix for asan complaints when resize mode is on. When resize mode is on, // the stride of the reference frame can be different from indicated by // MotionVectorSearchParams::search_site_cfg. When this happens, we need to // readjust the stride. const MV_SPEED_FEATURES *mv_sf = &cpi->sf.mv_sf; const SEARCH_METHODS search_method =
av1_get_default_mv_search_method(x, mv_sf, bsize); const search_site_config *src_search_site_cfg =
av1_get_search_site_config(cpi, x, search_method);
// Further reduce the search range. if (search_range < INT_MAX) { const search_site_config *search_site_cfg =
&src_search_site_cfg[search_method_lookup[search_method]]; // Max step_param is search_site_cfg->num_search_steps. if (search_range < 1) {
step_param = search_site_cfg->num_search_steps;
} else { while (search_site_cfg->radius[search_site_cfg->num_search_steps -
step_param - 1] > (search_range << 1) &&
search_site_cfg->num_search_steps - step_param - 1 > 0)
step_param++;
}
}
// Allow more mesh searches for screen content type on the ARF. constint fine_search_interval = use_fine_search_interval(cpi);
FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
switch (mbmi->motion_mode) { case SIMPLE_TRANSLATION: { // Perform a search with the top 2 candidates int sum_weight = 0; for (int m = 0; m < cand_cnt; m++) {
int_mv smv = cand[m].fmv;
FULLPEL_MV this_best_mv, this_second_best_mv;
FULLPEL_MV_STATS this_mv_stats;
if (scaled_ref_frame) { // Swap back the original buffers for subpel motion search. for (int i = 0; i < num_planes; i++) {
xd->plane[i].pre[ref_idx] = backup_yv12[i];
}
}
// Terminate search with the current ref_idx based on fullpel mv, rate cost, // and other know cost. if (cpi->sf.inter_sf.skip_newmv_in_drl >= 2 &&
mbmi->motion_mode == SIMPLE_TRANSLATION &&
best_mv->as_int != INVALID_MV) {
int_mv this_mv;
this_mv.as_mv = get_mv_from_fullmv(&best_mv->as_fullmv); constint ref_mv_idx = mbmi->ref_mv_idx; constint this_mv_rate =
av1_mv_bit_cost(&this_mv.as_mv, &ref_mv, mv_costs->nmv_joint_cost,
mv_costs->mv_cost_stack, MV_COST_WEIGHT);
mode_info[ref_mv_idx].full_search_mv.as_int = this_mv.as_int;
mode_info[ref_mv_idx].full_mv_rate = this_mv_rate;
mode_info[ref_mv_idx].full_mv_bestsme = bestsme;
for (int prev_ref_idx = 0; prev_ref_idx < ref_mv_idx; ++prev_ref_idx) { // Check if the motion search result same as previous results if (this_mv.as_int == mode_info[prev_ref_idx].full_search_mv.as_int) { // Compare the rate cost constint prev_rate_cost = mode_info[prev_ref_idx].full_mv_rate +
mode_info[prev_ref_idx].drl_cost; constint this_rate_cost =
this_mv_rate + mode_info[ref_mv_idx].drl_cost;
if (prev_rate_cost <= this_rate_cost) { // If the current rate_cost is worse than the previous rate_cost, then // we terminate the search. Since av1_single_motion_search is only // called by handle_new_mv in SIMPLE_TRANSLATION mode, we set the // best_mv to INVALID mv to signal that we wish to terminate search // for the current mode.
best_mv->as_int = INVALID_MV; return;
}
}
// Terminate the evaluation of current ref_mv_idx based on bestsme and // drl_cost. constint psme = mode_info[prev_ref_idx].full_mv_bestsme; if (psme == INT_MAX) continue; constint thr =
cpi->sf.inter_sf.skip_newmv_in_drl == 3 ? (psme + (psme >> 2)) : psme; if (cpi->sf.inter_sf.skip_newmv_in_drl >= 3 &&
mode_info[ref_mv_idx].full_mv_bestsme > thr &&
mode_info[prev_ref_idx].drl_cost < mode_info[ref_mv_idx].drl_cost) {
best_mv->as_int = INVALID_MV; return;
}
}
}
if (cpi->common.features.cur_frame_force_integer_mv) {
convert_fullmv_to_mv(best_mv);
}
constint use_fractional_mv =
bestsme < INT_MAX && cpi->common.features.cur_frame_force_integer_mv == 0; int best_mv_rate = 0; int mv_rate_calculated = 0; if (use_fractional_mv) {
int_mv fractional_ms_list[3];
av1_set_fractional_mv(fractional_ms_list); int dis; /* TODO: use dis in distortion calculation later. */
if (!mv_sf->disable_second_mv) { // If cpi->sf.mv_sf.disable_second_mv is 0, use actual rd cost // to choose the better MV.
mbmi->mv[0].as_mv = this_best_mv;
av1_enc_build_inter_predictor(cm, xd, mi_row, mi_col, &orig_dst,
bsize, 0, 0);
av1_subtract_plane(x, bsize, 0);
RD_STATS tmp_rd_stats;
av1_init_rd_stats(&tmp_rd_stats);
av1_estimate_txfm_yrd(cpi, x, &tmp_rd_stats, INT64_MAX, bsize,
max_txsize_rect_lookup[bsize]); int tmp_mv_rate = av1_mv_bit_cost(
&this_best_mv, &ref_mv, mv_costs->nmv_joint_cost,
mv_costs->mv_cost_stack, MV_COST_WEIGHT);
int64_t tmp_rd =
RDCOST(x->rdmult, tmp_rd_stats.rate + tmp_mv_rate,
tmp_rd_stats.dist); if (tmp_rd < rd) {
best_mv->as_mv = this_best_mv;
x->pred_sse[ref] = sse;
}
} else { // If cpi->sf.mv_sf.disable_second_mv = 1, use var to decide the // best MV. if (this_var < best_mv_var) {
best_mv->as_mv = this_best_mv;
x->pred_sse[ref] = sse;
}
}
}
}
} else {
mv_search_params->find_fractional_mv_step(
xd, cm, &ms_params, subpel_start_mv, &best_mv_stats,
&best_mv->as_mv, &dis, &x->pred_sse[ref], NULL);
} break; case OBMC_CAUSAL:
av1_find_best_obmc_sub_pixel_tree_up(
xd, cm, &ms_params, subpel_start_mv, NULL, &best_mv->as_mv, &dis,
&x->pred_sse[ref], NULL); break; default: assert(0 && "Invalid motion mode!\n");
}
// Terminate search with the current ref_idx based on subpel mv and rate // cost. if (cpi->sf.inter_sf.skip_newmv_in_drl >= 1 && args != NULL &&
mbmi->motion_mode == SIMPLE_TRANSLATION &&
best_mv->as_int != INVALID_MV) { constint ref_mv_idx = mbmi->ref_mv_idx;
best_mv_rate =
av1_mv_bit_cost(&best_mv->as_mv, &ref_mv, mv_costs->nmv_joint_cost,
mv_costs->mv_cost_stack, MV_COST_WEIGHT);
mv_rate_calculated = 1;
for (int prev_ref_idx = 0; prev_ref_idx < ref_mv_idx; ++prev_ref_idx) { if (!args->single_newmv_valid[prev_ref_idx][ref]) continue; // Check if the motion vectors are the same. if (best_mv->as_int == args->single_newmv[prev_ref_idx][ref].as_int) { // Skip this evaluation if the previous one is skipped. if (mode_info[prev_ref_idx].skip) {
mode_info[ref_mv_idx].skip = 1; break;
} // Compare the rate cost that we current know. constint prev_rate_cost =
args->single_newmv_rate[prev_ref_idx][ref] +
mode_info[prev_ref_idx].drl_cost; constint this_rate_cost =
best_mv_rate + mode_info[ref_mv_idx].drl_cost;
if (prev_rate_cost <= this_rate_cost) { // If the current rate_cost is worse than the previous rate_cost, // then we terminate the search for this ref_mv_idx.
mode_info[ref_mv_idx].skip = 1; break;
}
}
}
}
}
// Do joint motion search in compound mode to get more accurate mv. struct buf_2d backup_yv12[2][MAX_MB_PLANE]; int last_besterr[2] = { INT_MAX, INT_MAX }; const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = {
av1_get_scaled_ref_frame(cpi, refs[0]),
av1_get_scaled_ref_frame(cpi, refs[1])
};
// Prediction buffer from second frame.
DECLARE_ALIGNED(16, uint8_t, second_pred16[MAX_SB_SQUARE * sizeof(uint16_t)]);
uint8_t *second_pred = get_buf_by_bd(xd, second_pred16);
int_mv best_mv, second_best_mv;
// Allow joint search multiple times iteratively for each reference frame // and break out of the search loop if it couldn't find a better mv. for (ite = 0; ite < (2 * joint_me_num_refine_iter); ite++) { struct buf_2d ref_yv12[2]; int bestsme = INT_MAX; int id = ite % 2; // Even iterations search in the first reference frame, // odd iterations search in the second. The predictor // found for the 'other' reference frame is factored in. if (ite >= 2 && cur_mv[!id].as_int == init_mv[!id].as_int) { if (cur_mv[id].as_int == init_mv[id].as_int) { break;
} else {
int_mv cur_int_mv, init_int_mv;
cur_int_mv.as_mv.col = cur_mv[id].as_mv.col >> 3;
cur_int_mv.as_mv.row = cur_mv[id].as_mv.row >> 3;
init_int_mv.as_mv.row = init_mv[id].as_mv.row >> 3;
init_int_mv.as_mv.col = init_mv[id].as_mv.col >> 3; if (cur_int_mv.as_int == init_int_mv.as_int) { break;
}
}
} for (ref = 0; ref < 2; ++ref) {
ref_mv[ref] = av1_get_ref_mv(x, ref); // Swap out the reference frame for a version that's been scaled to // match the resolution of the current frame, allowing the existing // motion search code to be used without additional modifications. if (scaled_ref_frame[ref]) { int i; for (i = 0; i < num_planes; i++)
backup_yv12[ref][i] = xd->plane[i].pre[ref];
av1_setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col,
NULL, num_planes);
}
}
// Since we have scaled the reference frames to match the size of the // current frame we must use a unit scaling factor during mode selection.
av1_enc_build_one_inter_predictor(second_pred, pw, &cur_mv[!id].as_mv,
&inter_pred_params);
// Do full-pixel compound motion search on the current reference frame. if (id) xd->plane[plane].pre[0] = ref_yv12[id];
// Make motion search params
FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
FULLPEL_MV_STATS best_mv_stats; const MV_SPEED_FEATURES *mv_sf = &cpi->sf.mv_sf; const SEARCH_METHODS search_method =
av1_get_default_mv_search_method(x, mv_sf, bsize); const search_site_config *src_search_sites =
av1_get_search_site_config(cpi, x, search_method); // Use the mv result from the single mode as mv predictor. const FULLPEL_MV start_fullmv = get_fullmv_from_mv(&cur_mv[id].as_mv);
av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize,
&ref_mv[id].as_mv, start_fullmv,
src_search_sites, search_method, /*fine_search_interval=*/0);
// Restore the pointer to the first (possibly scaled) prediction buffer. if (id) xd->plane[plane].pre[0] = ref_yv12[0];
for (ref = 0; ref < 2; ++ref) { if (scaled_ref_frame[ref]) { // Swap back the original buffers for subpel motion search. for (int i = 0; i < num_planes; i++) {
xd->plane[i].pre[ref] = backup_yv12[ref][i];
} // Re-initialize based on unscaled prediction buffers.
ref_yv12[ref] = xd->plane[plane].pre[ref];
}
}
// Do sub-pixel compound motion search on the current reference frame. if (id) xd->plane[plane].pre[0] = ref_yv12[id];
// Search for the best mv for one component of a compound, // given that the other component is fixed. int av1_compound_single_motion_search(const AV1_COMP *cpi, MACROBLOCK *x,
BLOCK_SIZE bsize, MV *this_mv, const uint8_t *second_pred, const uint8_t *mask, int mask_stride, int *rate_mv, int ref_idx) { const AV1_COMMON *const cm = &cpi->common; constint num_planes = av1_num_planes(cm);
MACROBLOCKD *xd = &x->e_mbd;
MB_MODE_INFO *mbmi = xd->mi[0]; constint ref = mbmi->ref_frame[ref_idx]; const int_mv ref_mv = av1_get_ref_mv(x, ref_idx); struct macroblockd_plane *const pd = &xd->plane[0]; const MvCosts *mv_costs = x->mv_costs;
// Check that this is either an interinter or an interintra block
assert(has_second_ref(mbmi) || (ref_idx == 0 && is_interintra_mode(mbmi)));
// Store the first prediction buffer. struct buf_2d orig_yv12; if (ref_idx) {
orig_yv12 = pd->pre[0];
pd->pre[0] = pd->pre[ref_idx];
}
if (scaled_ref_frame) { // Swap out the reference frame for a version that's been scaled to // match the resolution of the current frame, allowing the existing // full-pixel motion search code to be used without additional // modifications. for (int i = 0; i < num_planes; i++) {
backup_yv12[i] = xd->plane[i].pre[ref_idx];
} constint mi_row = xd->mi_row; constint mi_col = xd->mi_col; // The index below needs to be 0 instead of ref_idx since we assume the // 0th slot to be used for subsequent searches. Note that the ref_idx // reference buffer has been copied to the 0th slot in the code above. // Now we need to swap the reference frame for the 0th slot.
av1_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL,
num_planes);
}
int bestsme = INT_MAX;
int_mv best_mv;
// Make motion search params
FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
FULLPEL_MV_STATS best_mv_stats; const SEARCH_METHODS search_method =
av1_get_default_mv_search_method(x, &cpi->sf.mv_sf, bsize); const search_site_config *src_search_sites =
av1_get_search_site_config(cpi, x, search_method); // Use the mv result from the single mode as mv predictor. const FULLPEL_MV start_fullmv = get_fullmv_from_mv(this_mv);
av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize,
&ref_mv.as_mv, start_fullmv,
src_search_sites, search_method, /*fine_search_interval=*/0);
if (scaled_ref_frame) { // Swap back the original buffers for subpel motion search for the 0th slot. for (int i = 0; i < num_planes; i++) {
xd->plane[i].pre[0] = backup_yv12[i];
}
}
// Get the prediction block from the 'other' reference frame.
av1_enc_build_one_inter_predictor(second_pred, pw, other_mv,
&inter_pred_params);
}
// Wrapper for av1_compound_single_motion_search, for the common case // where the second prediction is also an inter mode. staticint compound_single_motion_search_interinter( const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, int_mv *cur_mv, const uint8_t *mask, int mask_stride, int *rate_mv, int ref_idx) {
MACROBLOCKD *xd = &x->e_mbd; // This function should only ever be called for compound modes
assert(has_second_ref(xd->mi[0]));
// Prediction buffer from second frame.
DECLARE_ALIGNED(16, uint16_t, second_pred_alloc_16[MAX_SB_SQUARE]);
uint8_t *second_pred; if (is_cur_buf_hbd(xd))
second_pred = CONVERT_TO_BYTEPTR(second_pred_alloc_16); else
second_pred = (uint8_t *)second_pred_alloc_16;
int av1_interinter_compound_motion_search(const AV1_COMP *const cpi,
MACROBLOCK *x, const int_mv *const cur_mv, const BLOCK_SIZE bsize, const PREDICTION_MODE this_mode) {
MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *const mbmi = xd->mi[0];
int_mv tmp_mv[2]; int tmp_rate_mv = 0; // TODO(jingning): The average compound mode has proper SAD and variance // functions implemented, and is triggerd by setting the mask pointer as // Null. Need to further implement those for frame distance weighted mode.
mbmi->interinter_comp.seg_mask =
mbmi->interinter_comp.type == COMPOUND_AVERAGE ? NULL : xd->seg_mask; const INTERINTER_COMPOUND_DATA *compound_data = &mbmi->interinter_comp;
cpi->mv_search_params.find_fractional_mv_step(
xd, cm, &ms_params, subpel_start_mv, &best_mv_stats, &best_mv.as_mv,
¬_used, &x->pred_sse[ref], NULL);
mbmi->mv[0] = best_mv;
// Get a copy of the prediction output
av1_enc_build_inter_predictor(cm, xd, mi_row, mi_col, NULL, bsize,
AOM_PLANE_Y, AOM_PLANE_Y);
*var = cpi->ppi->fn_ptr[bsize].vf(
x->plane[0].src.buf, x->plane[0].src.stride, xd->plane[0].dst.buf,
xd->plane[0].dst.stride, sse);
} else { // Manually convert from units of pixel to 1/8-pixels if we are not doing // subpel search
convert_fullmv_to_mv(&best_mv);
*var = best_mv_stats.distortion;
*sse = best_mv_stats.sse;
}
return best_mv;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
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.