/* * Copyright (c) 2016, 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.
*/
// Class
aom_write_symbol(w, mv_class, mvcomp->classes_cdf, MV_CLASSES);
// Integer bits if (mv_class == MV_CLASS_0) {
aom_write_symbol(w, d, mvcomp->class0_cdf, CLASS0_SIZE);
} else { int i; constint n = mv_class + CLASS0_BITS - 1; // number of bits for (i = 0; i < n; ++i)
aom_write_symbol(w, (d >> i) & 1, mvcomp->bits_cdf[i], 2);
} // Fractional bits if (precision > MV_SUBPEL_NONE) {
aom_write_symbol(
w, fr,
mv_class == MV_CLASS_0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf,
MV_FP_SIZE);
}
// High precision bit if (precision > MV_SUBPEL_LOW_PRECISION)
aom_write_symbol(
w, hp, mv_class == MV_CLASS_0 ? mvcomp->class0_hp_cdf : mvcomp->hp_cdf,
2);
}
/* TODO(siekyleb@amazon.com): This function writes MV_VALS ints or 128 KiB. This * is more than most L1D caches and is a significant chunk of L2. Write * SIMD that uses streaming writes to avoid loading all of that into L1, or * just don't update the larger component costs every time this called * (or both).
*/ void av1_build_nmv_component_cost_table(int *mvcost, const nmv_component *const mvcomp,
MvSubpelPrecision precision) { int i, j, v, o, mantissa; int sign_cost[2], class_cost[MV_CLASSES], class0_cost[CLASS0_SIZE]; int bits_cost[MV_OFFSET_BITS][2]; int class0_fp_cost[CLASS0_SIZE][MV_FP_SIZE] = { 0 },
fp_cost[MV_FP_SIZE] = { 0 }; int class0_hp_cost[2] = { 0 }, hp_cost[2] = { 0 };
av1_cost_tokens_from_cdf(sign_cost, mvcomp->sign_cdf, NULL);
av1_cost_tokens_from_cdf(class_cost, mvcomp->classes_cdf, NULL);
av1_cost_tokens_from_cdf(class0_cost, mvcomp->class0_cdf, NULL); for (i = 0; i < MV_OFFSET_BITS; ++i) {
av1_cost_tokens_from_cdf(bits_cost[i], mvcomp->bits_cdf[i], NULL);
}
if (precision > MV_SUBPEL_NONE) { for (i = 0; i < CLASS0_SIZE; ++i)
av1_cost_tokens_from_cdf(class0_fp_cost[i], mvcomp->class0_fp_cdf[i],
NULL);
av1_cost_tokens_from_cdf(fp_cost, mvcomp->fp_cdf, NULL);
}
// Instead of accumulating the cost of each vector component's bits // individually, compute the costs based on smaller vectors. Costs for // [2^exp, 2 * 2^exp - 1] are calculated based on [0, 2^exp - 1] // respectively. Offsets are maintained to swap both 1) class costs when // treated as a complete vector component with the highest set bit when // treated as a mantissa (significand) and 2) leading zeros to account for // the current exponent.
// Cost offsets int cost_swap[MV_OFFSET_BITS] = { 0 }; // Delta to convert positive vector to negative vector costs int negate_sign = sign_cost[1] - sign_cost[0];
// Initialize with offsets to swap the class costs with the costs of the // highest set bit. for (i = 1; i < MV_OFFSET_BITS; ++i) {
cost_swap[i] = bits_cost[i - 1][1]; if (i > CLASS0_BITS) cost_swap[i] -= class_cost[i - CLASS0_BITS];
}
// Seed the fractional costs onto the output (overwritten latter). for (o = 0; o < MV_FP_SIZE; ++o) { int hp; for (hp = 0; hp < 2; ++hp) {
v = 2 * o + hp + 1;
mvcost[v] = fp_cost[o] + hp_cost[hp] + sign_cost[0];
}
}
mvcost[0] = 0; // Fill the costs for each exponent's vectors, using the costs set in the // previous exponents. for (i = 0; i < MV_OFFSET_BITS; ++i) { constint exponent = (2 * MV_FP_SIZE) << i;
intclass = 0; if (i >= CLASS0_BITS) { class = class_cost[i - CLASS0_BITS + 1];
}
// Iterate through mantissas, keeping track of the location // of the highest set bit for the mantissa. // To be clear: in the outer loop, the position of the highest set bit // (exponent) is tracked and, in this loop, the highest set bit of the // mantissa is tracked.
mantissa = 0; for (j = 0; j <= i; ++j) { for (; mantissa < (2 * MV_FP_SIZE) << j; ++mantissa) { int cost = mvcost[mantissa + 1] + class + cost_swap[j];
v = exponent + mantissa + 1;
mvcost[v] = cost;
mvcost[-v] = cost + negate_sign;
}
cost_swap[j] += bits_cost[i][0];
}
}
// Special case to avoid buffer overrun
{ int exponent = (2 * MV_FP_SIZE) << MV_OFFSET_BITS; intclass = class_cost[MV_CLASSES - 1];
mantissa = 0; for (j = 0; j < MV_OFFSET_BITS; ++j) { for (; mantissa < (2 * MV_FP_SIZE) << j; ++mantissa) { int cost = mvcost[mantissa + 1] + class + cost_swap[j];
v = exponent + mantissa + 1;
mvcost[v] = cost;
mvcost[-v] = cost + negate_sign;
}
} // At this point: mantissa = exponent >> 1
// Manually calculate the final cost offset int cost_swap_hi =
bits_cost[MV_OFFSET_BITS - 1][1] - class_cost[MV_CLASSES - 2]; for (; mantissa < exponent - 1; ++mantissa) { int cost = mvcost[mantissa + 1] + class + cost_swap_hi;
v = exponent + mantissa + 1;
mvcost[v] = cost;
mvcost[-v] = cost + negate_sign;
}
}
// Fill costs for class0 vectors, overwriting previous placeholder values // used for calculating the costs of the larger vectors. for (i = 0; i < CLASS0_SIZE; ++i) { constint top = i * 2 * MV_FP_SIZE; for (o = 0; o < MV_FP_SIZE; ++o) { int hp; int cost = class0_fp_cost[i][o] + class_cost[0] + class0_cost[i]; for (hp = 0; hp < 2; ++hp) {
v = top + 2 * o + hp + 1;
mvcost[v] = cost + class0_hp_cost[hp] + sign_cost[0];
mvcost[-v] = cost + class0_hp_cost[hp] + sign_cost[1];
}
}
}
}
void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, ThreadData *td, const MV *mv, const MV *ref, nmv_context *mvctx, int usehp) { const MV diff = { mv->row - ref->row, mv->col - ref->col }; const MV_JOINT_TYPE j = av1_get_mv_joint(&diff); // If the mv_diff is zero, then we should have used near or nearest instead.
assert(j != MV_JOINT_ZERO); if (cpi->common.features.cur_frame_force_integer_mv) {
usehp = MV_SUBPEL_NONE;
}
aom_write_symbol(w, j, mvctx->joints_cdf, MV_JOINTS); if (mv_joint_vertical(j))
encode_mv_component(w, diff.row, &mvctx->comps[0], usehp);
if (mv_joint_horizontal(j))
encode_mv_component(w, diff.col, &mvctx->comps[1], usehp);
// If auto_mv_step_size is enabled then keep track of the largest // motion vector component used. if (cpi->sf.mv_sf.auto_mv_step_size) { int maxv = AOMMAX(abs(mv->row), abs(mv->col)) >> 3;
td->max_mv_magnitude = AOMMAX(maxv, td->max_mv_magnitude);
}
}
void av1_encode_dv(aom_writer *w, const MV *mv, const MV *ref,
nmv_context *mvctx) { // DV and ref DV should not have sub-pel.
assert((mv->col & 7) == 0);
assert((mv->row & 7) == 0);
assert((ref->col & 7) == 0);
assert((ref->row & 7) == 0); const MV diff = { mv->row - ref->row, mv->col - ref->col }; const MV_JOINT_TYPE j = av1_get_mv_joint(&diff);
aom_write_symbol(w, j, mvctx->joints_cdf, MV_JOINTS); if (mv_joint_vertical(j))
encode_mv_component(w, diff.row, &mvctx->comps[0], MV_SUBPEL_NONE);
if (mv_joint_horizontal(j))
encode_mv_component(w, diff.col, &mvctx->comps[1], MV_SUBPEL_NONE);
}
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.