/* * Copyright (c) 2014 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
staticint mv_refs_rt(VP9_COMP *cpi, const VP9_COMMON *cm, const MACROBLOCK *x, const MACROBLOCKD *xd, const TileInfo *const tile,
MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
int_mv *mv_ref_list, int_mv *base_mv, int mi_row, int mi_col, int use_base_mv) { constint *ref_sign_bias = cm->ref_frame_sign_bias; int i, refmv_count = 0;
const POSITION *const mv_ref_search = mv_ref_blocks[mi->sb_type];
int different_ref_found = 0; int context_counter = 0; int const_motion = 0;
// Blank the reference vector list
memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES);
// 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]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MODE_INFO *const candidate_mi =
xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]; // Keep counts for entropy encoding.
context_counter += mode_2_counter[candidate_mi->mode];
different_ref_found = 1;
// 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 && !refmv_count; ++i) { const POSITION *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MODE_INFO *const candidate_mi =
xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
different_ref_found = 1;
if (candidate_mi->ref_frame[0] == ref_frame)
ADD_MV_REF_LIST(candidate_mi->mv[0], refmv_count, mv_ref_list, Done);
}
}
// 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 && !refmv_count) { for (i = 0; i < MVREF_NEIGHBOURS; ++i) { const POSITION *mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MODE_INFO *const candidate_mi =
xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride];
// If the candidate is INTRA we don't want to consider its mv.
IF_DIFF_REF_FRAME_ADD_MV(candidate_mi, ref_frame, ref_sign_bias,
refmv_count, mv_ref_list, Done);
}
}
} if (use_base_mv &&
!cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame &&
ref_frame == LAST_FRAME) { // Get base layer mv. constint prev_layer = cpi->svc.spatial_layer_id - 1; constint index =
(mi_col >> 1) + (mi_row >> 1) * cpi->svc.mi_cols[prev_layer]; // prev_frame->mvs[] is allocated to size mi_cols * mi_rows corresponding // to the previous spatial layer, so the index check is against // svc.mi_col/rows[prev_layer]. if (index < cpi->svc.mi_cols[prev_layer] * cpi->svc.mi_rows[prev_layer]) {
MV_REF *candidate = &cm->prev_frame->mvs[index]; // Avoid using base_mv if scaled mv is out of range, for either component. if (candidate->mv[0].as_int != INVALID_MV &&
abs(candidate->mv[0].as_mv.row) <= INT16_MAX >> 1 &&
abs(candidate->mv[0].as_mv.col) <= INT16_MAX >> 1) {
base_mv->as_mv.row = candidate->mv[0].as_mv.row * 2;
base_mv->as_mv.col = candidate->mv[0].as_mv.col * 2;
clamp_mv_ref(&base_mv->as_mv, xd);
} else {
base_mv->as_int = INVALID_MV;
}
}
}
// Clamp vectors for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i)
clamp_mv_ref(&mv_ref_list[i].as_mv, xd);
return const_motion;
}
staticint combined_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
BLOCK_SIZE bsize, int mi_row, int mi_col,
int_mv *tmp_mv, int *rate_mv,
int64_t best_rd_sofar, int use_base_mv) {
MACROBLOCKD *xd = &x->e_mbd;
MODE_INFO *mi = xd->mi[0]; struct buf_2d backup_yv12[MAX_MB_PLANE] = { { 0, 0 } }; constint step_param = cpi->sf.mv.fullpel_search_step_param; constint sadpb = x->sadperbit16;
MV mvp_full; constint ref = mi->ref_frame[0]; const MV ref_mv = x->mbmi_ext->ref_mvs[ref][0].as_mv;
MV center_mv;
uint32_t dis; int rate_mode; const MvLimits tmp_mv_limits = x->mv_limits; int rv = 0; int cost_list[5]; int search_subpel = 1; const YV12_BUFFER_CONFIG *scaled_ref_frame =
vp9_get_scaled_ref_frame(cpi, ref); if (scaled_ref_frame) { int i; // 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. for (i = 0; i < MAX_MB_PLANE; i++) backup_yv12[i] = xd->plane[i].pre[0];
vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL);
}
vp9_set_mv_search_range(&x->mv_limits, &ref_mv);
if (scaled_ref_frame) { int i; for (i = 0; i < MAX_MB_PLANE; i++) xd->plane[i].pre[0] = backup_yv12[i];
} return rv;
}
staticvoid block_variance(const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, int w, int h, unsignedint *sse, int *sum, int block_size, #if CONFIG_VP9_HIGHBITDEPTH int use_highbitdepth, vpx_bit_depth_t bd, #endif
uint32_t *sse8x8, int *sum8x8, uint32_t *var8x8) { int i, j, k = 0;
uint32_t k_sqr = 0;
*sse = 0;
*sum = 0;
for (i = 0; i < h; i += block_size) { for (j = 0; j < w; j += block_size) { #if CONFIG_VP9_HIGHBITDEPTH if (use_highbitdepth) { switch (bd) { case VPX_BITS_8:
vpx_highbd_8_get8x8var(src + src_stride * i + j, src_stride,
ref + ref_stride * i + j, ref_stride,
&sse8x8[k], &sum8x8[k]); break; case VPX_BITS_10:
vpx_highbd_10_get8x8var(src + src_stride * i + j, src_stride,
ref + ref_stride * i + j, ref_stride,
&sse8x8[k], &sum8x8[k]); break; case VPX_BITS_12:
vpx_highbd_12_get8x8var(src + src_stride * i + j, src_stride,
ref + ref_stride * i + j, ref_stride,
&sse8x8[k], &sum8x8[k]); break;
}
} else {
vpx_get8x8var(src + src_stride * i + j, src_stride,
ref + ref_stride * i + j, ref_stride, &sse8x8[k],
&sum8x8[k]);
} #else
vpx_get8x8var(src + src_stride * i + j, src_stride,
ref + ref_stride * i + j, ref_stride, &sse8x8[k],
&sum8x8[k]); #endif
*sse += sse8x8[k];
*sum += sum8x8[k];
k_sqr = (uint32_t)(((int64_t)sum8x8[k] * sum8x8[k]) >> 6);
var8x8[k] = sse8x8[k] > k_sqr ? sse8x8[k] - k_sqr : k_sqr - sse8x8[k];
k++;
}
}
}
staticvoid calculate_variance(int bw, int bh, TX_SIZE tx_size, unsignedint *sse_i, int *sum_i, unsignedint *var_o, unsignedint *sse_o, int *sum_o) { const BLOCK_SIZE unit_size = txsize_to_bsize[tx_size]; constint nw = 1 << (bw - b_width_log2_lookup[unit_size]); constint nh = 1 << (bh - b_height_log2_lookup[unit_size]); int i, j, k = 0;
uint32_t k_sqr = 0;
// Adjust the ac_thr according to speed, width, height and normalized sum staticint ac_thr_factor(constint speed, constint width, constint height, constint norm_sum) { if (speed >= 8 && norm_sum < 5) { if (width <= 640 && height <= 480) return 4; else return 2;
} return 1;
}
static TX_SIZE calculate_tx_size(VP9_COMP *const cpi, BLOCK_SIZE bsize,
MACROBLOCKD *const xd, unsignedint var, unsignedint sse, int64_t ac_thr, unsignedint source_variance, int is_intra) { // TODO(marpan): Tune selection for intra-modes, screen content, etc.
TX_SIZE tx_size; unsignedint var_thresh = is_intra ? (unsignedint)ac_thr : 1; int limit_tx = 1; if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
(source_variance == 0 || var < var_thresh))
limit_tx = 0; if (cpi->common.tx_mode == TX_MODE_SELECT) { if (sse > (var << 2))
tx_size = VPXMIN(max_txsize_lookup[bsize],
tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); else
tx_size = TX_8X8; if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && limit_tx &&
cyclic_refresh_segment_id_boosted(xd->mi[0]->segment_id))
tx_size = TX_8X8; elseif (tx_size > TX_16X16 && limit_tx)
tx_size = TX_16X16; // For screen-content force 4X4 tx_size over 8X8, for large variance. if (cpi->oxcf.content == VP9E_CONTENT_SCREEN && tx_size == TX_8X8 &&
bsize <= BLOCK_16X16 && ((var >> 5) > (unsignedint)ac_thr))
tx_size = TX_4X4;
} else {
tx_size = VPXMIN(max_txsize_lookup[bsize],
tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
} return tx_size;
}
staticvoid compute_intra_yprediction(PREDICTION_MODE mode, BLOCK_SIZE bsize,
MACROBLOCK *x, MACROBLOCKD *xd) { struct macroblockd_plane *const pd = &xd->plane[0]; struct macroblock_plane *const p = &x->plane[0];
uint8_t *const src_buf_base = p->src.buf;
uint8_t *const dst_buf_base = pd->dst.buf; constint src_stride = p->src.stride; constint dst_stride = pd->dst.stride; // block and transform sizes, in number of 4x4 blocks log 2 ("*_b") // 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8 const TX_SIZE tx_size = max_txsize_lookup[bsize]; constint num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; constint num_4x4_h = num_4x4_blocks_high_lookup[bsize]; int row, col; // If mb_to_right_edge is < 0 we are in a situation in which // the current block size extends into the UMV and we won't // visit the sub blocks that are wholly within the UMV. constint max_blocks_wide =
num_4x4_w + (xd->mb_to_right_edge >= 0
? 0
: xd->mb_to_right_edge >> (5 + pd->subsampling_x)); constint max_blocks_high =
num_4x4_h + (xd->mb_to_bottom_edge >= 0
? 0
: xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
// Keep track of the row and column of the blocks we use so that we know // if we are in the unrestricted motion border. for (row = 0; row < max_blocks_high; row += (1 << tx_size)) { // Skip visiting the sub blocks that are wholly within the UMV. for (col = 0; col < max_blocks_wide; col += (1 << tx_size)) {
p->src.buf = &src_buf_base[4 * (row * (int64_t)src_stride + col)];
pd->dst.buf = &dst_buf_base[4 * (row * (int64_t)dst_stride + col)];
vp9_predict_intra_block(xd, b_width_log2_lookup[bsize], tx_size, mode,
x->skip_encode ? p->src.buf : pd->dst.buf,
x->skip_encode ? src_stride : dst_stride,
pd->dst.buf, dst_stride, col, row, 0);
}
}
p->src.buf = src_buf_base;
pd->dst.buf = dst_buf_base;
}
staticvoid model_rd_for_sb_y_large(VP9_COMP *cpi, BLOCK_SIZE bsize,
MACROBLOCK *x, MACROBLOCKD *xd, int *out_rate_sum, int64_t *out_dist_sum, unsignedint *var_y, unsignedint *sse_y, int mi_row, int mi_col, int *early_term, int *flag_preduv_computed) { // Note our transform coeffs are 8 times an orthogonal transform. // Hence quantizer step is also 8 times. To get effective quantizer // we need to divide by 8 before sending to modeling function. unsignedint sse; int rate;
int64_t dist; struct macroblock_plane *const p = &x->plane[0]; struct macroblockd_plane *const pd = &xd->plane[0]; const uint32_t dc_quant = pd->dequant[0]; const uint32_t ac_quant = pd->dequant[1];
int64_t dc_thr = dc_quant * dc_quant >> 6;
int64_t ac_thr = ac_quant * ac_quant >> 6; unsignedint var; int sum; int skip_dc = 0;
constint bw = b_width_log2_lookup[bsize]; constint bh = b_height_log2_lookup[bsize]; constint num8x8 = 1 << (bw + bh - 2); unsignedint sse8x8[64] = { 0 }; int sum8x8[64] = { 0 }; unsignedint var8x8[64] = { 0 };
TX_SIZE tx_size; int i, k;
uint32_t sum_sqr; #if CONFIG_VP9_HIGHBITDEPTH const vpx_bit_depth_t bd = cpi->common.bit_depth; #endif // Calculate variance for whole partition, and also save 8x8 blocks' variance // to be used in following transform skipping test.
block_variance(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride,
4 << bw, 4 << bh, &sse, &sum, 8, #if CONFIG_VP9_HIGHBITDEPTH
cpi->common.use_highbitdepth, bd, #endif
sse8x8, sum8x8, var8x8);
sum_sqr = (uint32_t)((int64_t)sum * sum) >> (bw + bh + 4);
var = sse > sum_sqr ? sse - sum_sqr : sum_sqr - sse;
tx_size = calculate_tx_size(cpi, bsize, xd, var, sse, ac_thr,
x->source_variance, 0); // The code below for setting skip flag assumes tranform size of at least 8x8, // so force this lower limit on transform. if (tx_size < TX_8X8) tx_size = TX_8X8;
xd->mi[0]->tx_size = tx_size;
// Skipping test
x->skip_txfm[0] = SKIP_TXFM_NONE; for (k = 0; k < num; k++) // Check if all ac coefficients can be quantized to zero. if (!(var_tx[k] < ac_thr || var == 0)) {
ac_test = 0; break;
}
for (k = 0; k < num; k++) // Check if dc coefficient can be quantized to zero. if (!(sse_tx[k] - var_tx[k] < dc_thr || sse == var)) {
dc_test = 0; break;
}
if (ac_test) {
x->skip_txfm[0] = SKIP_TXFM_AC_ONLY;
// If the transform in YUV planes are skippable, the mode search checks // fewer inter modes and doesn't check intra modes. if (skip_uv[0] & skip_uv[1]) {
*early_term = 1;
} return;
}
if (!skip_dc) { #if CONFIG_VP9_HIGHBITDEPTH
vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize],
dc_quant >> (xd->bd - 5), &rate, &dist); #else
vp9_model_rd_from_var_lapndz(sse - var, num_pels_log2_lookup[bsize],
dc_quant >> 3, &rate, &dist); #endif// CONFIG_VP9_HIGHBITDEPTH
}
staticvoid model_rd_for_sb_y(VP9_COMP *cpi, BLOCK_SIZE bsize, MACROBLOCK *x,
MACROBLOCKD *xd, int *out_rate_sum,
int64_t *out_dist_sum, unsignedint *var_y, unsignedint *sse_y, int is_intra) { // Note our transform coeffs are 8 times an orthogonal transform. // Hence quantizer step is also 8 times. To get effective quantizer // we need to divide by 8 before sending to modeling function. unsignedint sse; int rate;
int64_t dist; struct macroblock_plane *const p = &x->plane[0]; struct macroblockd_plane *const pd = &xd->plane[0]; const int64_t dc_thr = p->quant_thred[0] >> 6; const int64_t ac_thr = p->quant_thred[1] >> 6; const uint32_t dc_quant = pd->dequant[0]; const uint32_t ac_quant = pd->dequant[1]; unsignedint var = cpi->fn_ptr[bsize].vf(p->src.buf, p->src.stride,
pd->dst.buf, pd->dst.stride, &sse); int skip_dc = 0;
*var_y = var;
*sse_y = sse;
xd->mi[0]->tx_size = calculate_tx_size(cpi, bsize, xd, var, sse, ac_thr,
x->source_variance, is_intra);
// Evaluate if the partition block is a skippable block in Y plane.
{ const BLOCK_SIZE unit_size = txsize_to_bsize[xd->mi[0]->tx_size]; constunsignedint num_blk_log2 =
(b_width_log2_lookup[bsize] - b_width_log2_lookup[unit_size]) +
(b_height_log2_lookup[bsize] - b_height_log2_lookup[unit_size]); constunsignedint sse_tx = sse >> num_blk_log2; constunsignedint var_tx = var >> num_blk_log2;
x->skip_txfm[0] = SKIP_TXFM_NONE; // Check if all ac coefficients can be quantized to zero. if (var_tx < ac_thr || var == 0) {
x->skip_txfm[0] = SKIP_TXFM_AC_ONLY; // Check if dc coefficient can be quantized to zero. if (sse_tx - var_tx < dc_thr || sse == var)
x->skip_txfm[0] = SKIP_TXFM_AC_DC;
} else { if (sse_tx - var_tx < dc_thr || sse == var) skip_dc = 1;
}
}
// If skippable is set, rate gets clobbered later.
this_rdc->rate <<= (2 + VP9_PROB_COST_SHIFT);
this_rdc->rate += (eob_cost << VP9_PROB_COST_SHIFT);
}
staticvoid model_rd_for_sb_uv(VP9_COMP *cpi, BLOCK_SIZE plane_bsize,
MACROBLOCK *x, MACROBLOCKD *xd,
RD_COST *this_rdc, unsignedint *var_y, unsignedint *sse_y, int start_plane, int stop_plane) { // Note our transform coeffs are 8 times an orthogonal transform. // Hence quantizer step is also 8 times. To get effective quantizer // we need to divide by 8 before sending to modeling function. unsignedint sse; int rate;
int64_t dist; int i; #if CONFIG_VP9_HIGHBITDEPTH
uint64_t tot_var = *var_y;
uint64_t tot_sse = *sse_y; #else
uint32_t tot_var = *var_y;
uint32_t tot_sse = *sse_y; #endif
this_rdc->rate = 0;
this_rdc->dist = 0;
for (i = start_plane; i <= stop_plane; ++i) { struct macroblock_plane *const p = &x->plane[i]; struct macroblockd_plane *const pd = &xd->plane[i]; const uint32_t dc_quant = pd->dequant[0]; const uint32_t ac_quant = pd->dequant[1]; const BLOCK_SIZE bs = plane_bsize; unsignedint var; if (!x->color_sensitivity[i - 1]) continue;
// The cost of skip bit needs to be added.
*rate = cpi->inter_mode_cost[x->mbmi_ext->mode_context[ref_frame]]
[INTER_OFFSET(this_mode)];
// More on this part of rate // rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
// Scaling factor for SSE from spatial domain to frequency // domain is 16. Adjust distortion accordingly. // TODO(yunqingwang): In this function, only y-plane dist is // calculated.
*dist = (sse << 4); // + ((sse_u + sse_v) << 4);
mi->ref_frame[0] = INTRA_FRAME; // Initialize interp_filter here so we do not have to check for inter block // modes in get_pred_context_switchable_interp()
mi->interp_filter = SWITCHABLE_FILTERS;
staticINLINEvoid find_predictors(
VP9_COMP *cpi, MACROBLOCK *x, MV_REFERENCE_FRAME ref_frame,
int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], int const_motion[MAX_REF_FRAMES], int *ref_frame_skip_mask,
TileDataEnc *tile_data, int mi_row, int mi_col, struct buf_2d yv12_mb[4][MAX_MB_PLANE], BLOCK_SIZE bsize, int force_skip_low_temp_var, int comp_pred_allowed) {
VP9_COMMON *const cm = &cpi->common;
MACROBLOCKD *const xd = &x->e_mbd; const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
TileInfo *const tile_info = &tile_data->tile_info; // TODO(jingning) placeholder for inter-frame non-RD mode decision.
x->pred_mv_sad[ref_frame] = INT_MAX;
frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
frame_mv[ZEROMV][ref_frame].as_int = 0; // this needs various further optimizations. to be continued.. if ((cpi->ref_frame_flags & ref_frame_to_flag(ref_frame)) && (yv12 != NULL)) {
int_mv *const candidates = x->mbmi_ext->ref_mvs[ref_frame]; conststruct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf); if (cm->use_prev_frame_mvs || comp_pred_allowed) {
vp9_find_mv_refs(cm, xd, xd->mi[0], ref_frame, candidates, mi_row, mi_col,
x->mbmi_ext->mode_context);
} else {
const_motion[ref_frame] =
mv_refs_rt(cpi, cm, x, xd, tile_info, xd->mi[0], ref_frame,
candidates, &frame_mv[NEWMV][ref_frame], mi_row, mi_col,
(int)(cpi->svc.use_base_mv && cpi->svc.spatial_layer_id));
}
vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
&frame_mv[NEARESTMV][ref_frame],
&frame_mv[NEARMV][ref_frame]); // Early exit for golden frame if force_skip_low_temp_var is set. if (!vp9_is_scaled(sf) && bsize >= BLOCK_8X8 &&
!(force_skip_low_temp_var && ref_frame == GOLDEN_FRAME)) {
vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, ref_frame,
bsize);
}
} else {
*ref_frame_skip_mask |= (1 << ref_frame);
}
}
staticvoid vp9_NEWMV_diff_bias(const NOISE_ESTIMATE *ne, MACROBLOCKD *xd,
PREDICTION_MODE this_mode, RD_COST *this_rdc,
BLOCK_SIZE bsize, int mv_row, int mv_col, int is_last_frame, int lowvar_highsumdiff, int is_skin) { // Bias against MVs associated with NEWMV mode that are very different from // top/left neighbors. if (this_mode == NEWMV) { int al_mv_average_row; int al_mv_average_col; int left_row, left_col; int row_diff, col_diff; int above_mv_valid = 0; int left_mv_valid = 0; int above_row = 0; int above_col = 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.