void av1_set_ssim_rdmult(const AV1_COMP *const cpi, int *errorperbit, const BLOCK_SIZE bsize, const int mi_row, const int mi_col, int *const rdmult) { const AV1_COMMON *const cm = &cpi->common;
const BLOCK_SIZE bsize_base = BLOCK_16X16; const int num_mi_w = mi_size_wide[bsize_base]; const int num_mi_h = mi_size_high[bsize_base]; const int num_cols = (cm->mi_params.mi_cols + num_mi_w - 1) / num_mi_w; const int num_rows = (cm->mi_params.mi_rows + num_mi_h - 1) / num_mi_h; const int num_bcols = (mi_size_wide[bsize] + num_mi_w - 1) / num_mi_w; const int num_brows = (mi_size_high[bsize] + num_mi_h - 1) / num_mi_h;
int row, col; double num_of_mi = 0.0; double geom_mean_of_scale = 1.0;
// To avoid overflow of 'geom_mean_of_scale', bsize_base must be at least // BLOCK_8X8. // // For bsize=BLOCK_128X128 and bsize_base=BLOCK_8X8, the loop below would // iterate 256 times. Considering the maximum value of // cpi->ssim_rdmult_scaling_factors (see av1_set_mb_ssim_rdmult_scaling()), // geom_mean_of_scale can go up to 4.8323^256, which is within DBL_MAX // (maximum value a double data type can hold). If bsize_base is modified to // BLOCK_4X4 (minimum possible block size), geom_mean_of_scale can go up // to 4.8323^1024 and exceed DBL_MAX, resulting in data overflow.
assert(bsize_base >= BLOCK_8X8);
assert(cpi->oxcf.tune_cfg.tuning == AOM_TUNE_SSIM ||
cpi->oxcf.tune_cfg.tuning == AOM_TUNE_IQ ||
cpi->oxcf.tune_cfg.tuning == AOM_TUNE_SSIMULACRA2);
xd->tx_type_map = ctx->tx_type_map;
xd->tx_type_map_stride = mi_size_wide[bsize]; // If not dry_run, copy the transform type data into the frame level buffer. // Encoder will fetch tx types when writing bitstream.
if (!dry_run) { const int grid_idx = get_mi_grid_idx(mi_params, mi_row, mi_col);
uint8_t *const tx_type_map = mi_params->tx_type_map + grid_idx; const int mi_stride = mi_params->mi_stride;
for (int blk_row = 0; blk_row < bh; ++blk_row) {
av1_copy_array(tx_type_map + blk_row * mi_stride,
xd->tx_type_map + blk_row * xd->tx_type_map_stride, bw);
}
xd->tx_type_map = tx_type_map;
xd->tx_type_map_stride = mi_stride;
}
// If segmentation in use
if (seg->enabled) { // For in frame complexity AQ or ROI copy the segment id from the // segment map.
if (cpi->oxcf.q_cfg.aq_mode == COMPLEXITY_AQ || cpi->roi.enabled) { const uint8_t *const map =
seg->update_map ? cpi->enc_seg.map : cm->last_frame_seg_map;
mi_addr->segment_id =
map ? get_segment_id(mi_params, map, bsize, mi_row, mi_col) : 0;
} // Else for cyclic refresh mode update the segment map, set the segment id // and then update the quantizer.
if (cpi->oxcf.q_cfg.aq_mode == CYCLIC_REFRESH_AQ && !cpi->roi.enabled &&
mi_addr->segment_id != AM_SEGMENT_ID_INACTIVE &&
!cpi->rc.rtc_external_ratectrl) {
av1_cyclic_refresh_update_segment(cpi, x, mi_row, mi_col, bsize,
ctx->rd_stats.rate, ctx->rd_stats.dist,
txfm_info->skip_txfm, dry_run);
}
if (mi_addr->uv_mode == UV_CFL_PRED && !is_cfl_allowed(xd))
mi_addr->uv_mode = UV_DC_PRED;
for (i = 0; i < num_planes; ++i) {
p[i].coeff = ctx->coeff[i];
p[i].qcoeff = ctx->qcoeff[i];
p[i].dqcoeff = ctx->dqcoeff[i];
p[i].eobs = ctx->eobs[i];
p[i].txb_entropy_ctx = ctx->txb_entropy_ctx[i];
}
for (i = 0; i < 2; ++i) pd[i].color_index_map = ctx->color_index_map[i]; // Restore the coding context of the MB to that that was in place // when the mode was picked for it
const int cols =
AOMMIN((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width, mi_width); const int rows = AOMMIN(
(xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height, mi_height);
for (y = 0; y < rows; y++) {
for (x_idx = 0; x_idx < cols; x_idx++) xd->mi[x_idx + y * mis] = mi_addr;
}
if (cpi->oxcf.q_cfg.aq_mode ||
(cpi->roi.enabled && cpi->roi.delta_qp_enabled))
av1_init_plane_quantizers(cpi, x, mi_addr->segment_id, 0);
if (dry_run) return;
#if CONFIG_INTERNAL_STATS
{ unsigned int *const mode_chosen_counts =
(unsigned int *)cpi->mode_chosen_counts; // Cast const away.
if (frame_is_intra_only(cm)) { staticconst int kf_mode_index[] = {
THR_DC /*DC_PRED*/,
THR_V_PRED /*V_PRED*/,
THR_H_PRED /*H_PRED*/,
THR_D45_PRED /*D45_PRED*/,
THR_D135_PRED /*D135_PRED*/,
THR_D113_PRED /*D113_PRED*/,
THR_D157_PRED /*D157_PRED*/,
THR_D203_PRED /*D203_PRED*/,
THR_D67_PRED /*D67_PRED*/,
THR_SMOOTH, /*SMOOTH_PRED*/
THR_SMOOTH_V, /*SMOOTH_V_PRED*/
THR_SMOOTH_H, /*SMOOTH_H_PRED*/
THR_PAETH /*PAETH_PRED*/,
};
++mode_chosen_counts[kf_mode_index[mi_addr->mode]];
} else { // Note how often each mode chosen as best
++mode_chosen_counts[ctx->best_mode_index];
}
} #endif
if (!frame_is_intra_only(cm)) {
if (is_inter_block(mi) && cm->features.interp_filter == SWITCHABLE) { // When the frame interp filter is SWITCHABLE, several cases that always // use the default type (EIGHTTAP_REGULAR) are described in // av1_is_interp_needed(). Here, we should keep the counts for all // applicable blocks, so the frame filter resetting decision in // fix_interp_filter() is made correctly.
update_filter_type_count(td->counts, xd, mi_addr);
}
}
const int x_mis = AOMMIN(bw, mi_params->mi_cols - mi_col); const int y_mis = AOMMIN(bh, mi_params->mi_rows - mi_row);
if (cm->seq_params->order_hint_info.enable_ref_frame_mvs)
av1_copy_frame_mvs(cm, mi, mi_row, mi_col, x_mis, y_mis);
}
staticvoid set_partial_sb_partition(const AV1_COMMON *const cm,
MB_MODE_INFO *mi, int bh_in, int bw_in,
int mi_rows_remaining,
int mi_cols_remaining, BLOCK_SIZE bsize,
MB_MODE_INFO **mib) {
int bh = bh_in;
int r, c;
for (r = 0; r < cm->seq_params->mib_size; r += bh) {
int bw = bw_in;
for (c = 0; c < cm->seq_params->mib_size; c += bw) { const int grid_index = get_mi_grid_idx(&cm->mi_params, r, c); const int mi_index = get_alloc_mi_idx(&cm->mi_params, r, c);
mib[grid_index] = mi + mi_index;
mib[grid_index]->bsize = find_partition_size(
bsize, mi_rows_remaining - r, mi_cols_remaining - c, &bh, &bw);
}
}
}
// This function attempts to set all mode info entries in a given superblock // to the same block partition size. // However, at the bottom and right borders of the image the requested size // may not be allowed in which case this code attempts to choose the largest // allowable partition. void av1_set_fixed_partitioning(AV1_COMP *cpi, const TileInfo *const tile,
MB_MODE_INFO **mib, int mi_row, int mi_col,
BLOCK_SIZE bsize) {
AV1_COMMON *const cm = &cpi->common; const CommonModeInfoParams *const mi_params = &cm->mi_params; const int mi_rows_remaining = tile->mi_row_end - mi_row; const int mi_cols_remaining = tile->mi_col_end - mi_col;
MB_MODE_INFO *const mi_upper_left =
mi_params->mi_alloc + get_alloc_mi_idx(mi_params, mi_row, mi_col);
int bh = mi_size_high[bsize];
int bw = mi_size_wide[bsize];
assert(bsize >= mi_params->mi_alloc_bsize && "Attempted to use bsize < mi_params->mi_alloc_bsize");
assert((mi_rows_remaining > 0) && (mi_cols_remaining > 0));
// Apply the requested partition size to the SB if it is all "in image"
if ((mi_cols_remaining >= cm->seq_params->mib_size) &&
(mi_rows_remaining >= cm->seq_params->mib_size)) {
for (int block_row = 0; block_row < cm->seq_params->mib_size;
block_row += bh) {
for (int block_col = 0; block_col < cm->seq_params->mib_size;
block_col += bw) { const int grid_index = get_mi_grid_idx(mi_params, block_row, block_col); const int mi_index = get_alloc_mi_idx(mi_params, block_row, block_col);
mib[grid_index] = mi_upper_left + mi_index;
mib[grid_index]->bsize = bsize;
}
}
} else { // Else this is a partial SB.
set_partial_sb_partition(cm, mi_upper_left, bh, bw, mi_rows_remaining,
mi_cols_remaining, bsize, mib);
}
}
int av1_is_leaf_split_partition(AV1_COMMON *cm, int mi_row, int mi_col,
BLOCK_SIZE bsize) { const int bs = mi_size_wide[bsize]; const int hbs = bs / 2;
assert(bsize >= BLOCK_8X8); const BLOCK_SIZE subsize = get_partition_subsize(bsize, PARTITION_SPLIT);
for (int i = 0; i < 4; i++) {
int x_idx = (i & 1) * hbs;
int y_idx = (i >> 1) * hbs;
if ((mi_row + y_idx >= cm->mi_params.mi_rows) ||
(mi_col + x_idx >= cm->mi_params.mi_cols)) return0;
if (get_partition(cm, mi_row + y_idx, mi_col + x_idx, subsize) !=
PARTITION_NONE &&
subsize != BLOCK_8X8) return0;
} return1;
}
#if !CONFIG_REALTIME_ONLY
int av1_get_rdmult_delta(AV1_COMP *cpi, BLOCK_SIZE bsize, int mi_row,
int mi_col, int orig_rdmult) {
AV1_COMMON *const cm = &cpi->common; const GF_GROUP *const gf_group = &cpi->ppi->gf_group;
assert(IMPLIES(cpi->ppi->gf_group.size > 0,
cpi->gf_frame_index < cpi->ppi->gf_group.size)); const int tpl_idx = cpi->gf_frame_index;
TplParams *const tpl_data = &cpi->ppi->tpl_data; const uint8_t block_mis_log2 = tpl_data->tpl_stats_block_mis_log2;
int64_t intra_cost = 0;
int64_t mc_dep_cost = 0; const int mi_wide = mi_size_wide[bsize]; const int mi_high = mi_size_high[bsize];
// Checks to see if a super block is on a horizontal image edge. // In most cases this is the "real" edge unless there are formatting // bars embedded in the stream.
int av1_active_h_edge(const AV1_COMP *cpi, int mi_row, int mi_step) {
int top_edge = 0;
int bottom_edge = cpi->common.mi_params.mi_rows;
int is_active_h_edge = 0;
// For two pass account for any formatting bars detected.
if (is_stat_consumption_stage_twopass(cpi)) { const AV1_COMMON *const cm = &cpi->common; const FIRSTPASS_STATS *const this_frame_stats = read_one_frame_stats(
&cpi->ppi->twopass, cm->current_frame.display_order_hint);
if (this_frame_stats == NULL) return AOM_CODEC_ERROR;
// The inactive region is specified in MBs not mi units. // The image edge is in the following MB row.
top_edge += (int)(this_frame_stats->inactive_zone_rows * 4);
// Checks to see if a super block is on a vertical image edge. // In most cases this is the "real" edge unless there are formatting // bars embedded in the stream.
int av1_active_v_edge(const AV1_COMP *cpi, int mi_col, int mi_step) {
int left_edge = 0;
int right_edge = cpi->common.mi_params.mi_cols;
int is_active_v_edge = 0;
// For two pass account for any formatting bars detected.
if (is_stat_consumption_stage_twopass(cpi)) { const AV1_COMMON *const cm = &cpi->common; const FIRSTPASS_STATS *const this_frame_stats = read_one_frame_stats(
&cpi->ppi->twopass, cm->current_frame.display_order_hint);
if (this_frame_stats == NULL) return AOM_CODEC_ERROR;
// The inactive region is specified in MBs not mi units. // The image edge is in the following MB row.
left_edge += (int)(this_frame_stats->inactive_zone_cols * 4);
int mi_count = 0;
int count = 0; const int mi_col_sr =
coded_to_superres_mi(mi_col, cm->superres_scale_denominator); const int mi_col_end_sr =
coded_to_superres_mi(mi_col + mi_wide, cm->superres_scale_denominator); // mi_cols_sr is mi_cols at superres case. const int mi_cols_sr = av1_pixels_to_mi(cm->superres_upscaled_width);
// TPL store unit size is not the same as the motion estimation unit size. // Here always use motion estimation size to avoid getting repetitive inter/ // intra cost. const BLOCK_SIZE tpl_bsize = convert_length_to_bsize(tpl_data->tpl_bsize_1d);
assert(mi_size_wide[tpl_bsize] == mi_size_high[tpl_bsize]); const int row_step = mi_size_high[tpl_bsize]; const int col_step_sr = coded_to_superres_mi(mi_size_wide[tpl_bsize],
cm->superres_scale_denominator);
// Stride is only based on SB size, and we fill in values for every 16x16 // block in a SB.
sb_enc->tpl_stride = (mi_col_end_sr - mi_col_sr) / col_step_sr;
for (int row = mi_row; row < mi_row + mi_high; row += row_step) {
for (int col = mi_col_sr; col < mi_col_end_sr; col += col_step_sr) {
assert(count < MAX_TPL_BLK_IN_SB * MAX_TPL_BLK_IN_SB); // Handle partial SB, so that no invalid values are used later.
if (row >= cm->mi_params.mi_rows || col >= mi_cols_sr) {
sb_enc->tpl_inter_cost[count] = INT64_MAX;
sb_enc->tpl_intra_cost[count] = INT64_MAX;
for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
sb_enc->tpl_mv[count][i].as_int = INVALID_MV;
}
count++; continue;
}
staticvoid avg_nmv(nmv_context *nmv_left, nmv_context *nmv_tr, int wt_left,
int wt_tr) {
AVERAGE_CDF(nmv_left->joints_cdf, nmv_tr->joints_cdf, 4);
for (int i = 0; i < 2; i++) {
AVERAGE_CDF(nmv_left->comps[i].classes_cdf, nmv_tr->comps[i].classes_cdf,
MV_CLASSES);
AVERAGE_CDF(nmv_left->comps[i].class0_fp_cdf,
nmv_tr->comps[i].class0_fp_cdf, MV_FP_SIZE);
AVERAGE_CDF(nmv_left->comps[i].fp_cdf, nmv_tr->comps[i].fp_cdf, MV_FP_SIZE);
AVERAGE_CDF(nmv_left->comps[i].sign_cdf, nmv_tr->comps[i].sign_cdf, 2);
AVERAGE_CDF(nmv_left->comps[i].class0_hp_cdf,
nmv_tr->comps[i].class0_hp_cdf, 2);
AVERAGE_CDF(nmv_left->comps[i].hp_cdf, nmv_tr->comps[i].hp_cdf, 2);
AVERAGE_CDF(nmv_left->comps[i].class0_cdf, nmv_tr->comps[i].class0_cdf,
CLASS0_SIZE);
AVERAGE_CDF(nmv_left->comps[i].bits_cdf, nmv_tr->comps[i].bits_cdf, 2);
}
}
// In case of row-based multi-threading of encoder, since we always // keep a top - right sync, we can average the top - right SB's CDFs and // the left SB's CDFs and use the same for current SB's encoding to // improve the performance. This function facilitates the averaging // of CDF and used only when row-mt is enabled in encoder. void av1_avg_cdf_symbols(FRAME_CONTEXT *ctx_left, FRAME_CONTEXT *ctx_tr,
int wt_left, int wt_tr) {
AVERAGE_CDF(ctx_left->txb_skip_cdf, ctx_tr->txb_skip_cdf, 2);
AVERAGE_CDF(ctx_left->eob_extra_cdf, ctx_tr->eob_extra_cdf, 2);
AVERAGE_CDF(ctx_left->dc_sign_cdf, ctx_tr->dc_sign_cdf, 2);
AVERAGE_CDF(ctx_left->eob_flag_cdf16, ctx_tr->eob_flag_cdf16, 5);
AVERAGE_CDF(ctx_left->eob_flag_cdf32, ctx_tr->eob_flag_cdf32, 6);
AVERAGE_CDF(ctx_left->eob_flag_cdf64, ctx_tr->eob_flag_cdf64, 7);
AVERAGE_CDF(ctx_left->eob_flag_cdf128, ctx_tr->eob_flag_cdf128, 8);
AVERAGE_CDF(ctx_left->eob_flag_cdf256, ctx_tr->eob_flag_cdf256, 9);
AVERAGE_CDF(ctx_left->eob_flag_cdf512, ctx_tr->eob_flag_cdf512, 10);
AVERAGE_CDF(ctx_left->eob_flag_cdf1024, ctx_tr->eob_flag_cdf1024, 11);
AVERAGE_CDF(ctx_left->coeff_base_eob_cdf, ctx_tr->coeff_base_eob_cdf, 3);
AVERAGE_CDF(ctx_left->coeff_base_cdf, ctx_tr->coeff_base_cdf, 4);
AVERAGE_CDF(ctx_left->coeff_br_cdf, ctx_tr->coeff_br_cdf, BR_CDF_SIZE);
AVERAGE_CDF(ctx_left->newmv_cdf, ctx_tr->newmv_cdf, 2);
AVERAGE_CDF(ctx_left->zeromv_cdf, ctx_tr->zeromv_cdf, 2);
AVERAGE_CDF(ctx_left->refmv_cdf, ctx_tr->refmv_cdf, 2);
AVERAGE_CDF(ctx_left->drl_cdf, ctx_tr->drl_cdf, 2);
AVERAGE_CDF(ctx_left->inter_compound_mode_cdf,
ctx_tr->inter_compound_mode_cdf, INTER_COMPOUND_MODES);
AVERAGE_CDF(ctx_left->compound_type_cdf, ctx_tr->compound_type_cdf,
MASKED_COMPOUND_TYPES);
AVERAGE_CDF(ctx_left->wedge_idx_cdf, ctx_tr->wedge_idx_cdf, 16);
AVERAGE_CDF(ctx_left->interintra_cdf, ctx_tr->interintra_cdf, 2);
AVERAGE_CDF(ctx_left->wedge_interintra_cdf, ctx_tr->wedge_interintra_cdf, 2);
AVERAGE_CDF(ctx_left->interintra_mode_cdf, ctx_tr->interintra_mode_cdf,
INTERINTRA_MODES);
AVERAGE_CDF(ctx_left->motion_mode_cdf, ctx_tr->motion_mode_cdf, MOTION_MODES);
AVERAGE_CDF(ctx_left->obmc_cdf, ctx_tr->obmc_cdf, 2);
AVERAGE_CDF(ctx_left->palette_y_size_cdf, ctx_tr->palette_y_size_cdf,
PALETTE_SIZES);
AVERAGE_CDF(ctx_left->palette_uv_size_cdf, ctx_tr->palette_uv_size_cdf,
PALETTE_SIZES);
for (int j = 0; j < PALETTE_SIZES; j++) {
int nsymbs = j + PALETTE_MIN_SIZE;
AVG_CDF_STRIDE(ctx_left->palette_y_color_index_cdf[j],
ctx_tr->palette_y_color_index_cdf[j], nsymbs,
CDF_SIZE(PALETTE_COLORS));
AVG_CDF_STRIDE(ctx_left->palette_uv_color_index_cdf[j],
ctx_tr->palette_uv_color_index_cdf[j], nsymbs,
CDF_SIZE(PALETTE_COLORS));
}
AVERAGE_CDF(ctx_left->palette_y_mode_cdf, ctx_tr->palette_y_mode_cdf, 2);
AVERAGE_CDF(ctx_left->palette_uv_mode_cdf, ctx_tr->palette_uv_mode_cdf, 2);
AVERAGE_CDF(ctx_left->comp_inter_cdf, ctx_tr->comp_inter_cdf, 2);
AVERAGE_CDF(ctx_left->single_ref_cdf, ctx_tr->single_ref_cdf, 2);
AVERAGE_CDF(ctx_left->comp_ref_type_cdf, ctx_tr->comp_ref_type_cdf, 2);
AVERAGE_CDF(ctx_left->uni_comp_ref_cdf, ctx_tr->uni_comp_ref_cdf, 2);
AVERAGE_CDF(ctx_left->comp_ref_cdf, ctx_tr->comp_ref_cdf, 2);
AVERAGE_CDF(ctx_left->comp_bwdref_cdf, ctx_tr->comp_bwdref_cdf, 2);
AVERAGE_CDF(ctx_left->txfm_partition_cdf, ctx_tr->txfm_partition_cdf, 2);
AVERAGE_CDF(ctx_left->compound_index_cdf, ctx_tr->compound_index_cdf, 2);
AVERAGE_CDF(ctx_left->comp_group_idx_cdf, ctx_tr->comp_group_idx_cdf, 2);
AVERAGE_CDF(ctx_left->skip_mode_cdfs, ctx_tr->skip_mode_cdfs, 2);
AVERAGE_CDF(ctx_left->skip_txfm_cdfs, ctx_tr->skip_txfm_cdfs, 2);
AVERAGE_CDF(ctx_left->intra_inter_cdf, ctx_tr->intra_inter_cdf, 2);
avg_nmv(&ctx_left->nmvc, &ctx_tr->nmvc, wt_left, wt_tr);
avg_nmv(&ctx_left->ndvc, &ctx_tr->ndvc, wt_left, wt_tr);
AVERAGE_CDF(ctx_left->intrabc_cdf, ctx_tr->intrabc_cdf, 2);
AVERAGE_CDF(ctx_left->seg.pred_cdf, ctx_tr->seg.pred_cdf, 2);
AVERAGE_CDF(ctx_left->seg.spatial_pred_seg_cdf,
ctx_tr->seg.spatial_pred_seg_cdf, MAX_SEGMENTS);
AVERAGE_CDF(ctx_left->filter_intra_cdfs, ctx_tr->filter_intra_cdfs, 2);
AVERAGE_CDF(ctx_left->filter_intra_mode_cdf, ctx_tr->filter_intra_mode_cdf,
FILTER_INTRA_MODES);
AVERAGE_CDF(ctx_left->switchable_restore_cdf, ctx_tr->switchable_restore_cdf,
RESTORE_SWITCHABLE_TYPES);
AVERAGE_CDF(ctx_left->wiener_restore_cdf, ctx_tr->wiener_restore_cdf, 2);
AVERAGE_CDF(ctx_left->sgrproj_restore_cdf, ctx_tr->sgrproj_restore_cdf, 2);
AVERAGE_CDF(ctx_left->y_mode_cdf, ctx_tr->y_mode_cdf, INTRA_MODES);
AVG_CDF_STRIDE(ctx_left->uv_mode_cdf[0], ctx_tr->uv_mode_cdf[0],
UV_INTRA_MODES - 1, CDF_SIZE(UV_INTRA_MODES));
AVERAGE_CDF(ctx_left->uv_mode_cdf[1], ctx_tr->uv_mode_cdf[1], UV_INTRA_MODES);
for (int i = 0; i < PARTITION_CONTEXTS; i++) {
if (i < 4) {
AVG_CDF_STRIDE(ctx_left->partition_cdf[i], ctx_tr->partition_cdf[i], 4,
CDF_SIZE(10));
} else if (i < 16) {
AVERAGE_CDF(ctx_left->partition_cdf[i], ctx_tr->partition_cdf[i], 10);
} else {
AVG_CDF_STRIDE(ctx_left->partition_cdf[i], ctx_tr->partition_cdf[i], 8,
CDF_SIZE(10));
}
}
AVERAGE_CDF(ctx_left->switchable_interp_cdf, ctx_tr->switchable_interp_cdf,
SWITCHABLE_FILTERS);
AVERAGE_CDF(ctx_left->kf_y_cdf, ctx_tr->kf_y_cdf, INTRA_MODES);
AVERAGE_CDF(ctx_left->angle_delta_cdf, ctx_tr->angle_delta_cdf, 2 * MAX_ANGLE_DELTA + 1);
AVG_CDF_STRIDE(ctx_left->tx_size_cdf[0], ctx_tr->tx_size_cdf[0], MAX_TX_DEPTH,
CDF_SIZE(MAX_TX_DEPTH + 1));
AVERAGE_CDF(ctx_left->tx_size_cdf[1], ctx_tr->tx_size_cdf[1],
MAX_TX_DEPTH + 1);
AVERAGE_CDF(ctx_left->tx_size_cdf[2], ctx_tr->tx_size_cdf[2],
MAX_TX_DEPTH + 1);
AVERAGE_CDF(ctx_left->tx_size_cdf[3], ctx_tr->tx_size_cdf[3],
MAX_TX_DEPTH + 1);
AVERAGE_CDF(ctx_left->delta_q_cdf, ctx_tr->delta_q_cdf, DELTA_Q_PROBS + 1);
AVERAGE_CDF(ctx_left->delta_lf_cdf, ctx_tr->delta_lf_cdf, DELTA_LF_PROBS + 1);
for (int i = 0; i < FRAME_LF_COUNT; i++) {
AVERAGE_CDF(ctx_left->delta_lf_multi_cdf[i], ctx_tr->delta_lf_multi_cdf[i],
DELTA_LF_PROBS + 1);
}
AVG_CDF_STRIDE(ctx_left->intra_ext_tx_cdf[1], ctx_tr->intra_ext_tx_cdf[1], 7,
CDF_SIZE(TX_TYPES));
AVG_CDF_STRIDE(ctx_left->intra_ext_tx_cdf[2], ctx_tr->intra_ext_tx_cdf[2], 5,
CDF_SIZE(TX_TYPES));
AVG_CDF_STRIDE(ctx_left->inter_ext_tx_cdf[1], ctx_tr->inter_ext_tx_cdf[1], 16,
CDF_SIZE(TX_TYPES));
AVG_CDF_STRIDE(ctx_left->inter_ext_tx_cdf[2], ctx_tr->inter_ext_tx_cdf[2], 12,
CDF_SIZE(TX_TYPES));
AVG_CDF_STRIDE(ctx_left->inter_ext_tx_cdf[3], ctx_tr->inter_ext_tx_cdf[3], 2,
CDF_SIZE(TX_TYPES));
AVERAGE_CDF(ctx_left->cfl_sign_cdf, ctx_tr->cfl_sign_cdf, CFL_JOINT_SIGNS);
AVERAGE_CDF(ctx_left->cfl_alpha_cdf, ctx_tr->cfl_alpha_cdf,
CFL_ALPHABET_SIZE);
}
// Check neighbor blocks' motion information. static int check_neighbor_blocks(MB_MODE_INFO **mi, int mi_stride, const TileInfo *const tile_info, int mi_row,
int mi_col) {
int is_above_low_motion = 1;
int is_left_low_motion = 1; const int thr = 24;
// Grade the temporal variation of the source by comparing the current sb and // its collocated block in the last frame. void av1_source_content_sb(AV1_COMP *cpi, MACROBLOCK *x, TileDataEnc *tile_data,
int mi_row, int mi_col) {
if (cpi->last_source->y_width != cpi->source->y_width ||
cpi->last_source->y_height != cpi->source->y_height) return; #if CONFIG_AV1_HIGHBITDEPTH
if (x->e_mbd.cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) return; #endif
// TODO(yunqing): use a weighted sum instead of averaging in filtering.
if (tmp_variance <= threshold && nmean2 <= 15) { // Check neighbor blocks. If neighbor blocks aren't low-motion blocks, // skip temporal filtering for this block.
MB_MODE_INFO **mi = cm->mi_params.mi_grid_base +
get_mi_grid_idx(&cm->mi_params, mi_row, mi_col); const TileInfo *const tile_info = &tile_data->tile_info; const int is_neighbor_blocks_low_motion = check_neighbor_blocks(
mi, cm->mi_params.mi_stride, tile_info, mi_row, mi_col);
if (!is_neighbor_blocks_low_motion) return;
// Only consider 64x64 SB for now. Need to extend to 128x128 for large SB // size. // Test several nearby points. If non-zero mv exists, don't do temporal // filtering. const int is_this_blk_low_motion = fast_detect_non_zero_motion(
cpi, src_y, src_ystride, last_src_y, last_src_ystride, mi_row, mi_col);
if (!is_this_blk_low_motion) return;
const int shift_x[2] = { 0, cpi->source->subsampling_x }; const int shift_y[2] = { 0, cpi->source->subsampling_y }; const uint8_t h = block_size_high[bsize]; const uint8_t w = block_size_wide[bsize];
for (int i = 0; i < (h >> shift_y[plane != 0]); ++i) {
for (int j = 0; j < (w >> shift_x[plane != 0]); ++j) {
src[j] = (last_src[j] + src[j]) >> 1;
}
src += src_stride;
last_src += last_src_stride;
}
}
}
}
// Memset the mbmis at the current superblock to 0 void av1_reset_mbmi(CommonModeInfoParams *const mi_params, BLOCK_SIZE sb_size,
int mi_row, int mi_col) { // size of sb in unit of mi (BLOCK_4X4) const int sb_size_mi = mi_size_wide[sb_size]; const int mi_alloc_size_1d = mi_size_wide[mi_params->mi_alloc_bsize]; // size of sb in unit of allocated mi size const int sb_size_alloc_mi = mi_size_wide[sb_size] / mi_alloc_size_1d;
assert(mi_params->mi_alloc_stride % sb_size_alloc_mi == 0 && "mi is not allocated as a multiple of sb!");
assert(mi_params->mi_stride % sb_size_mi == 0 && "mi_grid_base is not allocated as a multiple of sb!");
// Don't copy in row_mt case, otherwise run into data race. No behavior change // in row_mt case.
if (cpi->sf.inter_sf.inter_mode_rd_model_estimation == 1) {
memcpy(sb_fp_stats->inter_mode_rd_models, tile_data->inter_mode_rd_models, sizeof(sb_fp_stats->inter_mode_rd_models));
}
/*! Checks whether to skip updating the entropy cost based on tile info. * *Thisfunctioncontainsthecommoncodeusedtoskipthecostupdateofcoeff, *mode,mvanddvsymbols.
*/ static int skip_cost_update(const SequenceHeader *seq_params, const TileInfo *const tile_info, const int mi_row, const int mi_col,
INTERNAL_COST_UPDATE_TYPE upd_level) {
if (upd_level == INTERNAL_COST_UPD_SB) return0;
if (upd_level == INTERNAL_COST_UPD_OFF) return1;
// upd_level is at most as frequent as each sb_row in a tile.
if (mi_col != tile_info->mi_col_start) return1;
if (upd_level == INTERNAL_COST_UPD_SBROW_SET) { const int mib_size_log2 = seq_params->mib_size_log2; const int sb_row = (mi_row - tile_info->mi_row_start) >> mib_size_log2; const int sb_size = seq_params->mib_size * MI_SIZE; const int tile_height =
(tile_info->mi_row_end - tile_info->mi_row_start) * MI_SIZE; // When upd_level = INTERNAL_COST_UPD_SBROW_SET, the cost update happens // once for 2, 4 sb rows for sb size 128, sb size 64 respectively. However, // as the update will not be equally spaced in smaller resolutions making // it equally spaced by calculating (mv_num_rows_cost_update) the number of // rows after which the cost update should happen. const int sb_size_update_freq_map[2] = { 2, 4 }; const int update_freq_sb_rows =
sb_size_update_freq_map[sb_size != MAX_SB_SIZE]; const int update_freq_num_rows = sb_size * update_freq_sb_rows; // Round-up the division result to next integer. const int num_updates_per_tile =
(tile_height + update_freq_num_rows - 1) / update_freq_num_rows; const int num_rows_update_per_tile = num_updates_per_tile * sb_size; // Round-up the division result to next integer. const int num_sb_rows_per_update =
(tile_height + num_rows_update_per_tile - 1) / num_rows_update_per_tile;
if ((sb_row % num_sb_rows_per_update) != 0) return1;
} return0;
}
// Checks for skip status of mv cost update. static int skip_mv_cost_update(AV1_COMP *cpi, const TileInfo *const tile_info, const int mi_row, const int mi_col) { const AV1_COMMON *cm = &cpi->common; // For intra frames, mv cdfs are not updated during the encode. Hence, the mv // cost calculation is skipped in this case.
if (frame_is_intra_only(cm)) return1;
// Checks for skip status of dv cost update. static int skip_dv_cost_update(AV1_COMP *cpi, const TileInfo *const tile_info, const int mi_row, const int mi_col) { const AV1_COMMON *cm = &cpi->common; // Intrabc is only applicable to intra frames. So skip if intrabc is not // allowed.
if (!av1_allow_intrabc(cm) || is_stat_generation_stage(cpi)) { return1;
}
// Update the rate costs of some symbols according to the frequency directed // by speed features void av1_set_cost_upd_freq(AV1_COMP *cpi, ThreadData *td, const TileInfo *const tile_info, const int mi_row, const int mi_col) {
AV1_COMMON *const cm = &cpi->common; const int num_planes = av1_num_planes(cm);
MACROBLOCK *const x = &td->mb;
MACROBLOCKD *const xd = &x->e_mbd;
if (cm->features.disable_cdf_update) { return;
}
switch (cpi->sf.inter_sf.coeff_cost_upd_level) { case INTERNAL_COST_UPD_OFF: case INTERNAL_COST_UPD_TILE: // Tile level break; case INTERNAL_COST_UPD_SBROW_SET: // SB row set level in tile case INTERNAL_COST_UPD_SBROW: // SB row level in tile case INTERNAL_COST_UPD_SB: // SB level
if (skip_cost_update(cm->seq_params, tile_info, mi_row, mi_col,
cpi->sf.inter_sf.coeff_cost_upd_level)) break;
av1_fill_coeff_costs(&x->coeff_costs, xd->tile_ctx, num_planes); break; default: assert(0);
}
switch (cpi->sf.inter_sf.mode_cost_upd_level) { case INTERNAL_COST_UPD_OFF: case INTERNAL_COST_UPD_TILE: // Tile level break; case INTERNAL_COST_UPD_SBROW_SET: // SB row set level in tile case INTERNAL_COST_UPD_SBROW: // SB row level in tile case INTERNAL_COST_UPD_SB: // SB level
if (skip_cost_update(cm->seq_params, tile_info, mi_row, mi_col,
cpi->sf.inter_sf.mode_cost_upd_level)) break;
av1_fill_mode_rates(cm, &x->mode_costs, xd->tile_ctx); break; default: assert(0);
}
switch (cpi->sf.inter_sf.mv_cost_upd_level) { case INTERNAL_COST_UPD_OFF: case INTERNAL_COST_UPD_TILE: // Tile level break; case INTERNAL_COST_UPD_SBROW_SET: // SB row set level in tile case INTERNAL_COST_UPD_SBROW: // SB row level in tile case INTERNAL_COST_UPD_SB: // SB level // Checks for skip status of mv cost update.
if (skip_mv_cost_update(cpi, tile_info, mi_row, mi_col)) break;
av1_fill_mv_costs(&xd->tile_ctx->nmvc,
cm->features.cur_frame_force_integer_mv,
cm->features.allow_high_precision_mv, x->mv_costs); break; default: assert(0);
}
switch (cpi->sf.intra_sf.dv_cost_upd_level) { case INTERNAL_COST_UPD_OFF: case INTERNAL_COST_UPD_TILE: // Tile level break; case INTERNAL_COST_UPD_SBROW_SET: // SB row set level in tile case INTERNAL_COST_UPD_SBROW: // SB row level in tile case INTERNAL_COST_UPD_SB: // SB level // Checks for skip status of dv cost update.
if (skip_dv_cost_update(cpi, tile_info, mi_row, mi_col)) break;
av1_fill_dv_costs(&xd->tile_ctx->ndvc, x->dv_costs); break; default: assert(0);
}
}
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.