blob: b941c02913c63d9d6aa795bdea9778f7dac552e5 [file] [log] [blame]
/*
* 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.
*/
#include <assert.h>
#include <stdlib.h> // qsort()
#include "./aom_config.h"
#include "./aom_dsp_rtcd.h"
#include "./aom_scale_rtcd.h"
#include "./av1_rtcd.h"
#include "aom/aom_codec.h"
#include "aom_dsp/aom_dsp_common.h"
#include "aom_dsp/bitreader.h"
#include "aom_dsp/bitreader_buffer.h"
#include "aom_dsp/binary_codes_reader.h"
#include "aom_mem/aom_mem.h"
#include "aom_ports/mem.h"
#include "aom_ports/mem_ops.h"
#include "aom_scale/aom_scale.h"
#include "aom_util/aom_thread.h"
#if CONFIG_BITSTREAM_DEBUG
#include "aom_util/debug_util.h"
#endif // CONFIG_BITSTREAM_DEBUG
#include "av1/common/alloccommon.h"
#if CONFIG_CDEF
#include "av1/common/cdef.h"
#include "av1/common/clpf.h"
#endif
#if CONFIG_INSPECTION
#include "av1/decoder/inspection.h"
#endif
#include "av1/common/common.h"
#include "av1/common/entropy.h"
#include "av1/common/entropymode.h"
#include "av1/common/entropymv.h"
#include "av1/common/idct.h"
#include "av1/common/pred_common.h"
#include "av1/common/quant_common.h"
#include "av1/common/reconinter.h"
#include "av1/common/reconintra.h"
#if CONFIG_FRAME_SUPERRES
#include "av1/common/resize.h"
#endif // CONFIG_FRAME_SUPERRES
#include "av1/common/seg_common.h"
#include "av1/common/thread_common.h"
#include "av1/common/tile_common.h"
#include "av1/decoder/decodeframe.h"
#include "av1/decoder/decodemv.h"
#include "av1/decoder/decoder.h"
#if CONFIG_LV_MAP
#include "av1/decoder/decodetxb.h"
#endif
#include "av1/decoder/detokenize.h"
#include "av1/decoder/dsubexp.h"
#if CONFIG_WARPED_MOTION || CONFIG_GLOBAL_MOTION
#include "av1/common/warped_motion.h"
#endif // CONFIG_WARPED_MOTION || CONFIG_GLOBAL_MOTION
#define MAX_AV1_HEADER_SIZE 80
#define ACCT_STR __func__
#if CONFIG_PVQ
#include "av1/common/partition.h"
#include "av1/common/pvq.h"
#include "av1/common/scan.h"
#include "av1/decoder/decint.h"
#include "av1/decoder/pvq_decoder.h"
#include "av1/encoder/encodemb.h"
#include "av1/encoder/hybrid_fwd_txfm.h"
#endif
#if CONFIG_CFL
#include "av1/common/cfl.h"
#endif
static struct aom_read_bit_buffer *init_read_bit_buffer(
AV1Decoder *pbi, struct aom_read_bit_buffer *rb, const uint8_t *data,
const uint8_t *data_end, uint8_t clear_data[MAX_AV1_HEADER_SIZE]);
static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data,
size_t partition_size);
static size_t read_uncompressed_header(AV1Decoder *pbi,
struct aom_read_bit_buffer *rb);
static int is_compound_reference_allowed(const AV1_COMMON *cm) {
#if CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS // Normative in decoder
return !frame_is_intra_only(cm);
#else
int i;
if (frame_is_intra_only(cm)) return 0;
for (i = 1; i < INTER_REFS_PER_FRAME; ++i)
if (cm->ref_frame_sign_bias[i + 1] != cm->ref_frame_sign_bias[1]) return 1;
return 0;
#endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS
}
static void setup_compound_reference_mode(AV1_COMMON *cm) {
#if CONFIG_EXT_REFS
cm->comp_fwd_ref[0] = LAST_FRAME;
cm->comp_fwd_ref[1] = LAST2_FRAME;
cm->comp_fwd_ref[2] = LAST3_FRAME;
cm->comp_fwd_ref[3] = GOLDEN_FRAME;
cm->comp_bwd_ref[0] = BWDREF_FRAME;
cm->comp_bwd_ref[1] = ALTREF_FRAME;
#else
if (cm->ref_frame_sign_bias[LAST_FRAME] ==
cm->ref_frame_sign_bias[GOLDEN_FRAME]) {
cm->comp_fixed_ref = ALTREF_FRAME;
cm->comp_var_ref[0] = LAST_FRAME;
cm->comp_var_ref[1] = GOLDEN_FRAME;
} else if (cm->ref_frame_sign_bias[LAST_FRAME] ==
cm->ref_frame_sign_bias[ALTREF_FRAME]) {
cm->comp_fixed_ref = GOLDEN_FRAME;
cm->comp_var_ref[0] = LAST_FRAME;
cm->comp_var_ref[1] = ALTREF_FRAME;
} else {
cm->comp_fixed_ref = LAST_FRAME;
cm->comp_var_ref[0] = GOLDEN_FRAME;
cm->comp_var_ref[1] = ALTREF_FRAME;
}
#endif // CONFIG_EXT_REFS
}
static int read_is_valid(const uint8_t *start, size_t len, const uint8_t *end) {
return len != 0 && len <= (size_t)(end - start);
}
static int decode_unsigned_max(struct aom_read_bit_buffer *rb, int max) {
const int data = aom_rb_read_literal(rb, get_unsigned_bits(max));
return data > max ? max : data;
}
static TX_MODE read_tx_mode(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) {
#if CONFIG_TX64X64
TX_MODE tx_mode;
#endif
if (cm->all_lossless) return ONLY_4X4;
#if CONFIG_VAR_TX_NO_TX_MODE
(void)rb;
return TX_MODE_SELECT;
#else
#if CONFIG_TX64X64
tx_mode = aom_rb_read_bit(rb) ? TX_MODE_SELECT : aom_rb_read_literal(rb, 2);
if (tx_mode == ALLOW_32X32) tx_mode += aom_rb_read_bit(rb);
return tx_mode;
#else
return aom_rb_read_bit(rb) ? TX_MODE_SELECT : aom_rb_read_literal(rb, 2);
#endif // CONFIG_TX64X64
#endif // CONFIG_VAR_TX_NO_TX_MODE
}
#if !CONFIG_NEW_MULTISYMBOL
static void read_inter_mode_probs(FRAME_CONTEXT *fc, aom_reader *r) {
int i;
for (i = 0; i < NEWMV_MODE_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->newmv_prob[i], ACCT_STR);
for (i = 0; i < ZEROMV_MODE_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->zeromv_prob[i], ACCT_STR);
for (i = 0; i < REFMV_MODE_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->refmv_prob[i], ACCT_STR);
for (i = 0; i < DRL_MODE_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->drl_prob[i], ACCT_STR);
}
#endif
#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
static void read_inter_singleref_comp_mode_probs(FRAME_CONTEXT *fc,
aom_reader *r) {
int i, j;
if (aom_read(r, GROUP_DIFF_UPDATE_PROB, ACCT_STR)) {
for (j = 0; j < INTER_MODE_CONTEXTS; ++j) {
for (i = 0; i < INTER_SINGLEREF_COMP_MODES - 1; ++i) {
av1_diff_update_prob(r, &fc->inter_singleref_comp_mode_probs[j][i],
ACCT_STR);
}
}
}
}
#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
static REFERENCE_MODE read_frame_reference_mode(
const AV1_COMMON *cm, struct aom_read_bit_buffer *rb) {
if (is_compound_reference_allowed(cm)) {
#if CONFIG_REF_ADAPT
return aom_rb_read_bit(rb) ? REFERENCE_MODE_SELECT : SINGLE_REFERENCE;
#else
return aom_rb_read_bit(rb)
? REFERENCE_MODE_SELECT
: (aom_rb_read_bit(rb) ? COMPOUND_REFERENCE : SINGLE_REFERENCE);
#endif // CONFIG_REF_ADAPT
} else {
return SINGLE_REFERENCE;
}
}
static void read_frame_reference_mode_probs(AV1_COMMON *cm, aom_reader *r) {
#if CONFIG_NEW_MULTISYMBOL && !CONFIG_EXT_COMP_REFS
(void)r;
#else
FRAME_CONTEXT *const fc = cm->fc;
int i;
#endif
#if !CONFIG_NEW_MULTISYMBOL
if (cm->reference_mode == REFERENCE_MODE_SELECT)
for (i = 0; i < COMP_INTER_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->comp_inter_prob[i], ACCT_STR);
if (cm->reference_mode != COMPOUND_REFERENCE) {
for (i = 0; i < REF_CONTEXTS; ++i) {
int j;
for (j = 0; j < (SINGLE_REFS - 1); ++j) {
av1_diff_update_prob(r, &fc->single_ref_prob[i][j], ACCT_STR);
}
}
}
#endif
if (cm->reference_mode != SINGLE_REFERENCE) {
#if CONFIG_EXT_COMP_REFS
for (i = 0; i < COMP_REF_TYPE_CONTEXTS; ++i)
av1_diff_update_prob(r, &fc->comp_ref_type_prob[i], ACCT_STR);
for (i = 0; i < UNI_COMP_REF_CONTEXTS; ++i) {
int j;
for (j = 0; j < (UNIDIR_COMP_REFS - 1); ++j)
av1_diff_update_prob(r, &fc->uni_comp_ref_prob[i][j], ACCT_STR);
}
#endif // CONFIG_EXT_COMP_REFS
#if !CONFIG_NEW_MULTISYMBOL
for (i = 0; i < REF_CONTEXTS; ++i) {
int j;
#if CONFIG_EXT_REFS
for (j = 0; j < (FWD_REFS - 1); ++j)
av1_diff_update_prob(r, &fc->comp_ref_prob[i][j], ACCT_STR);
for (j = 0; j < (BWD_REFS - 1); ++j)
av1_diff_update_prob(r, &fc->comp_bwdref_prob[i][j], ACCT_STR);
#else
for (j = 0; j < (COMP_REFS - 1); ++j)
av1_diff_update_prob(r, &fc->comp_ref_prob[i][j], ACCT_STR);
#endif // CONFIG_EXT_REFS
}
#endif // CONFIG_NEW_MULTISYMBOL
}
}
static void update_mv_probs(aom_prob *p, int n, aom_reader *r) {
int i;
for (i = 0; i < n; ++i) av1_diff_update_prob(r, &p[i], ACCT_STR);
}
static void read_mv_probs(nmv_context *ctx, int allow_hp, aom_reader *r) {
int i;
if (allow_hp) {
for (i = 0; i < 2; ++i) {
nmv_component *const comp_ctx = &ctx->comps[i];
update_mv_probs(&comp_ctx->class0_hp, 1, r);
update_mv_probs(&comp_ctx->hp, 1, r);
}
}
}
static void inverse_transform_block(MACROBLOCKD *xd, int plane,
#if CONFIG_LGT
PREDICTION_MODE mode,
#endif
const TX_TYPE tx_type,
const TX_SIZE tx_size, uint8_t *dst,
int stride, int16_t scan_line, int eob) {
struct macroblockd_plane *const pd = &xd->plane[plane];
tran_low_t *const dqcoeff = pd->dqcoeff;
av1_inverse_transform_block(xd, dqcoeff,
#if CONFIG_LGT
mode,
#endif
tx_type, tx_size, dst, stride, eob);
memset(dqcoeff, 0, (scan_line + 1) * sizeof(dqcoeff[0]));
}
#if CONFIG_PVQ
static int av1_pvq_decode_helper(MACROBLOCKD *xd, tran_low_t *ref_coeff,
tran_low_t *dqcoeff, int16_t *quant, int pli,
int bs, TX_TYPE tx_type, int xdec,
PVQ_SKIP_TYPE ac_dc_coded) {
unsigned int flags; // used for daala's stream analyzer.
int off;
const int is_keyframe = 0;
const int has_dc_skip = 1;
int coeff_shift = 3 - av1_get_tx_scale(bs);
int hbd_downshift = 0;
int rounding_mask;
// DC quantizer for PVQ
int pvq_dc_quant;
int lossless = (quant[0] == 0);
const int blk_size = tx_size_wide[bs];
int eob = 0;
int i;
od_dec_ctx *dec = &xd->daala_dec;
int use_activity_masking = dec->use_activity_masking;
DECLARE_ALIGNED(16, tran_low_t, dqcoeff_pvq[OD_TXSIZE_MAX * OD_TXSIZE_MAX]);
DECLARE_ALIGNED(16, tran_low_t, ref_coeff_pvq[OD_TXSIZE_MAX * OD_TXSIZE_MAX]);
od_coeff ref_int32[OD_TXSIZE_MAX * OD_TXSIZE_MAX];
od_coeff out_int32[OD_TXSIZE_MAX * OD_TXSIZE_MAX];
hbd_downshift = xd->bd - 8;
od_raster_to_coding_order(ref_coeff_pvq, blk_size, tx_type, ref_coeff,
blk_size);
assert(OD_COEFF_SHIFT >= 4);
if (lossless)
pvq_dc_quant = 1;
else {
if (use_activity_masking)
pvq_dc_quant = OD_MAXI(
1, (quant[0] << (OD_COEFF_SHIFT - 3) >> hbd_downshift) *
dec->state.pvq_qm_q4[pli][od_qm_get_index(bs, 0)] >>
4);
else
pvq_dc_quant =
OD_MAXI(1, quant[0] << (OD_COEFF_SHIFT - 3) >> hbd_downshift);
}
off = od_qm_offset(bs, xdec);
// copy int16 inputs to int32
for (i = 0; i < blk_size * blk_size; i++) {
ref_int32[i] =
AOM_SIGNED_SHL(ref_coeff_pvq[i], OD_COEFF_SHIFT - coeff_shift) >>
hbd_downshift;
}
od_pvq_decode(dec, ref_int32, out_int32,
OD_MAXI(1, quant[1] << (OD_COEFF_SHIFT - 3) >> hbd_downshift),
pli, bs, OD_PVQ_BETA[use_activity_masking][pli][bs],
is_keyframe, &flags, ac_dc_coded, dec->state.qm + off,
dec->state.qm_inv + off);
if (!has_dc_skip || out_int32[0]) {
out_int32[0] =
has_dc_skip + generic_decode(dec->r, &dec->state.adapt->model_dc[pli],
&dec->state.adapt->ex_dc[pli][bs][0], 2,
"dc:mag");
if (out_int32[0]) out_int32[0] *= aom_read_bit(dec->r, "dc:sign") ? -1 : 1;
}
out_int32[0] = out_int32[0] * pvq_dc_quant + ref_int32[0];
// copy int32 result back to int16
assert(OD_COEFF_SHIFT > coeff_shift);
rounding_mask = (1 << (OD_COEFF_SHIFT - coeff_shift - 1)) - 1;
for (i = 0; i < blk_size * blk_size; i++) {
out_int32[i] = AOM_SIGNED_SHL(out_int32[i], hbd_downshift);
dqcoeff_pvq[i] = (out_int32[i] + (out_int32[i] < 0) + rounding_mask) >>
(OD_COEFF_SHIFT - coeff_shift);
}
od_coding_order_to_raster(dqcoeff, blk_size, tx_type, dqcoeff_pvq, blk_size);
eob = blk_size * blk_size;
return eob;
}
static PVQ_SKIP_TYPE read_pvq_skip(AV1_COMMON *cm, MACROBLOCKD *const xd,
int plane, TX_SIZE tx_size) {
// decode ac/dc coded flag. bit0: DC coded, bit1 : AC coded
// NOTE : we don't use 5 symbols for luma here in aom codebase,
// since block partition is taken care of by aom.
// So, only AC/DC skip info is coded
const int ac_dc_coded = aom_read_symbol(
xd->daala_dec.r,
xd->daala_dec.state.adapt->skip_cdf[2 * tx_size + (plane != 0)], 4,
"skip");
if (ac_dc_coded < 0 || ac_dc_coded > 3) {
aom_internal_error(&cm->error, AOM_CODEC_INVALID_PARAM,
"Invalid PVQ Skip Type");
}
return ac_dc_coded;
}
static int av1_pvq_decode_helper2(AV1_COMMON *cm, MACROBLOCKD *const xd,
MB_MODE_INFO *const mbmi, int plane, int row,
int col, TX_SIZE tx_size, TX_TYPE tx_type) {
struct macroblockd_plane *const pd = &xd->plane[plane];
// transform block size in pixels
int tx_blk_size = tx_size_wide[tx_size];
int i, j;
tran_low_t *pvq_ref_coeff = pd->pvq_ref_coeff;
const int diff_stride = tx_blk_size;
int16_t *pred = pd->pred;
tran_low_t *const dqcoeff = pd->dqcoeff;
uint8_t *dst;
int eob;
const PVQ_SKIP_TYPE ac_dc_coded = read_pvq_skip(cm, xd, plane, tx_size);
eob = 0;
dst = &pd->dst.buf[4 * row * pd->dst.stride + 4 * col];
if (ac_dc_coded) {
int xdec = pd->subsampling_x;
int seg_id = mbmi->segment_id;
int16_t *quant;
FWD_TXFM_PARAM fwd_txfm_param;
// ToDo(yaowu): correct this with optimal number from decoding process.
const int max_scan_line = tx_size_2d[tx_size];
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
for (j = 0; j < tx_blk_size; j++)
for (i = 0; i < tx_blk_size; i++)
pred[diff_stride * j + i] =
CONVERT_TO_SHORTPTR(dst)[pd->dst.stride * j + i];
} else {
#endif
for (j = 0; j < tx_blk_size; j++)
for (i = 0; i < tx_blk_size; i++)
pred[diff_stride * j + i] = dst[pd->dst.stride * j + i];
#if CONFIG_HIGHBITDEPTH
}
#endif
fwd_txfm_param.tx_type = tx_type;
fwd_txfm_param.tx_size = tx_size;
fwd_txfm_param.lossless = xd->lossless[seg_id];
#if CONFIG_LGT
fwd_txfm_param.is_inter = is_inter_block(mbmi);
fwd_txfm_param.dst = dst;
fwd_txfm_param.mode = get_prediction_mode(xd->mi[0], plane, tx_size, block);
#endif
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
fwd_txfm_param.bd = xd->bd;
av1_highbd_fwd_txfm(pred, pvq_ref_coeff, diff_stride, &fwd_txfm_param);
} else {
#endif // CONFIG_HIGHBITDEPTH
av1_fwd_txfm(pred, pvq_ref_coeff, diff_stride, &fwd_txfm_param);
#if CONFIG_HIGHBITDEPTH
}
#endif // CONFIG_HIGHBITDEPTH
quant = &pd->seg_dequant[seg_id][0]; // aom's quantizer
eob = av1_pvq_decode_helper(xd, pvq_ref_coeff, dqcoeff, quant, plane,
tx_size, tx_type, xdec, ac_dc_coded);
inverse_transform_block(xd, plane,
#if CONFIG_LGT
fwd_txfm_param.mode,
#endif
tx_type, tx_size, dst, pd->dst.stride,
max_scan_line, eob);
}
return eob;
}
#endif
static int get_block_idx(const MACROBLOCKD *xd, int plane, int row, int col) {
const int bsize = xd->mi[0]->mbmi.sb_type;
const struct macroblockd_plane *pd = &xd->plane[plane];
#if CONFIG_CHROMA_SUB8X8
const BLOCK_SIZE plane_bsize =
AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd));
#elif CONFIG_CB4X4
const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
#else
const BLOCK_SIZE plane_bsize =
get_plane_block_size(AOMMAX(BLOCK_8X8, bsize), pd);
#endif
const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane);
const TX_SIZE tx_size = get_tx_size(plane, xd);
const uint8_t txh_unit = tx_size_high_unit[tx_size];
return row * max_blocks_wide + col * txh_unit;
}
#if CONFIG_DPCM_INTRA
static void process_block_dpcm_vert(TX_SIZE tx_size, TX_TYPE_1D tx_type_1d,
const tran_low_t *dqcoeff, uint8_t *dst,
int dst_stride) {
const int tx1d_width = tx_size_wide[tx_size];
const int tx1d_height = tx_size_high[tx_size];
dpcm_inv_txfm_add_func inverse_tx =
av1_get_dpcm_inv_txfm_add_func(tx1d_width);
for (int r = 0; r < tx1d_height; ++r) {
if (r > 0) memcpy(dst, dst - dst_stride, tx1d_width * sizeof(dst[0]));
inverse_tx(dqcoeff, 1, tx_type_1d, dst);
dqcoeff += tx1d_width;
dst += dst_stride;
}
}
static void process_block_dpcm_horz(TX_SIZE tx_size, TX_TYPE_1D tx_type_1d,
const tran_low_t *dqcoeff, uint8_t *dst,
int dst_stride) {
const int tx1d_width = tx_size_wide[tx_size];
const int tx1d_height = tx_size_high[tx_size];
dpcm_inv_txfm_add_func inverse_tx =
av1_get_dpcm_inv_txfm_add_func(tx1d_height);
tran_low_t tx_buff[64];
for (int c = 0; c < tx1d_width; ++c, ++dqcoeff, ++dst) {
for (int r = 0; r < tx1d_height; ++r) {
if (c > 0) dst[r * dst_stride] = dst[r * dst_stride - 1];
tx_buff[r] = dqcoeff[r * tx1d_width];
}
inverse_tx(tx_buff, dst_stride, tx_type_1d, dst);
}
}
#if CONFIG_HIGHBITDEPTH
static void hbd_process_block_dpcm_vert(TX_SIZE tx_size, TX_TYPE_1D tx_type_1d,
int bd, const tran_low_t *dqcoeff,
uint8_t *dst8, int dst_stride) {
uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
const int tx1d_width = tx_size_wide[tx_size];
const int tx1d_height = tx_size_high[tx_size];
hbd_dpcm_inv_txfm_add_func inverse_tx =
av1_get_hbd_dpcm_inv_txfm_add_func(tx1d_width);
for (int r = 0; r < tx1d_height; ++r) {
if (r > 0) memcpy(dst, dst - dst_stride, tx1d_width * sizeof(dst[0]));
inverse_tx(dqcoeff, 1, tx_type_1d, bd, dst, 1);
dqcoeff += tx1d_width;
dst += dst_stride;
}
}
static void hbd_process_block_dpcm_horz(TX_SIZE tx_size, TX_TYPE_1D tx_type_1d,
int bd, const tran_low_t *dqcoeff,
uint8_t *dst8, int dst_stride) {
uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
const int tx1d_width = tx_size_wide[tx_size];
const int tx1d_height = tx_size_high[tx_size];
hbd_dpcm_inv_txfm_add_func inverse_tx =
av1_get_hbd_dpcm_inv_txfm_add_func(tx1d_height);
tran_low_t tx_buff[64];
switch (tx1d_height) {
case 4: inverse_tx = av1_hbd_dpcm_inv_txfm_add_4_c; break;
case 8: inverse_tx = av1_hbd_dpcm_inv_txfm_add_8_c; break;
case 16: inverse_tx = av1_hbd_dpcm_inv_txfm_add_16_c; break;
case 32: inverse_tx = av1_hbd_dpcm_inv_txfm_add_32_c; break;
default: assert(0);
}
for (int c = 0; c < tx1d_width; ++c, ++dqcoeff, ++dst) {
for (int r = 0; r < tx1d_height; ++r) {
if (c > 0) dst[r * dst_stride] = dst[r * dst_stride - 1];
tx_buff[r] = dqcoeff[r * tx1d_width];
}
inverse_tx(tx_buff, dst_stride, tx_type_1d, bd, dst, 0);
}
}
#endif // CONFIG_HIGHBITDEPTH
static void inverse_transform_block_dpcm(MACROBLOCKD *xd, int plane,
PREDICTION_MODE mode, TX_SIZE tx_size,
TX_TYPE tx_type, uint8_t *dst,
int dst_stride, int16_t scan_line) {
struct macroblockd_plane *const pd = &xd->plane[plane];
tran_low_t *const dqcoeff = pd->dqcoeff;
TX_TYPE_1D tx_type_1d = DCT_1D;
switch (tx_type) {
case IDTX: tx_type_1d = IDTX_1D; break;
case V_DCT:
assert(mode == H_PRED);
tx_type_1d = DCT_1D;
break;
case H_DCT:
assert(mode == V_PRED);
tx_type_1d = DCT_1D;
break;
default: assert(0);
}
switch (mode) {
case V_PRED:
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
hbd_process_block_dpcm_vert(tx_size, tx_type_1d, xd->bd, dqcoeff, dst,
dst_stride);
} else {
#endif // CONFIG_HIGHBITDEPTH
process_block_dpcm_vert(tx_size, tx_type_1d, dqcoeff, dst, dst_stride);
#if CONFIG_HIGHBITDEPTH
}
#endif // CONFIG_HIGHBITDEPTH
break;
case H_PRED:
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
hbd_process_block_dpcm_horz(tx_size, tx_type_1d, xd->bd, dqcoeff, dst,
dst_stride);
} else {
#endif // CONFIG_HIGHBITDEPTH
process_block_dpcm_horz(tx_size, tx_type_1d, dqcoeff, dst, dst_stride);
#if CONFIG_HIGHBITDEPTH
}
#endif // CONFIG_HIGHBITDEPTH
break;
default: assert(0);
}
memset(dqcoeff, 0, (scan_line + 1) * sizeof(dqcoeff[0]));
}
#endif // CONFIG_DPCM_INTRA
static void predict_and_reconstruct_intra_block(
AV1_COMMON *cm, MACROBLOCKD *const xd, aom_reader *const r,
MB_MODE_INFO *const mbmi, int plane, int row, int col, TX_SIZE tx_size) {
PLANE_TYPE plane_type = get_plane_type(plane);
const int block_idx = get_block_idx(xd, plane, row, col);
#if CONFIG_PVQ
(void)r;
#endif
av1_predict_intra_block_facade(xd, plane, block_idx, col, row, tx_size);
if (!mbmi->skip) {
#if !CONFIG_PVQ
struct macroblockd_plane *const pd = &xd->plane[plane];
#if CONFIG_LV_MAP
int16_t max_scan_line = 0;
int eob;
av1_read_coeffs_txb_facade(cm, xd, r, row, col, block_idx, plane,
pd->dqcoeff, tx_size, &max_scan_line, &eob);
// tx_type will be read out in av1_read_coeffs_txb_facade
TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
#else // CONFIG_LV_MAP
TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
const SCAN_ORDER *scan_order = get_scan(cm, tx_size, tx_type, mbmi);
int16_t max_scan_line = 0;
const int eob =
av1_decode_block_tokens(cm, xd, plane, scan_order, col, row, tx_size,
tx_type, &max_scan_line, r, mbmi->segment_id);
#endif // CONFIG_LV_MAP
if (eob) {
uint8_t *dst =
&pd->dst.buf[(row * pd->dst.stride + col) << tx_size_wide_log2[0]];
#if CONFIG_DPCM_INTRA || CONFIG_LGT
const PREDICTION_MODE mode =
get_prediction_mode(xd->mi[0], plane, tx_size, block_idx);
#if CONFIG_DPCM_INTRA
if (av1_use_dpcm_intra(plane, mode, tx_type, mbmi)) {
inverse_transform_block_dpcm(xd, plane, mode, tx_size, tx_type, dst,
pd->dst.stride, max_scan_line);
} else {
#endif // CONFIG_DPCM_INTRA
#endif // CONFIG_DPCM_INTRA || CONFIG_LGT
inverse_transform_block(xd, plane,
#if CONFIG_LGT
mode,
#endif
tx_type, tx_size, dst, pd->dst.stride,
max_scan_line, eob);
#if CONFIG_DPCM_INTRA
}
#endif // CONFIG_DPCM_INTRA
}
#else // !CONFIG_PVQ
TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
av1_pvq_decode_helper2(cm, xd, mbmi, plane, row, col, tx_size, tx_type);
#endif // !CONFIG_PVQ
}
#if CONFIG_CFL
if (plane == AOM_PLANE_Y) {
struct macroblockd_plane *const pd = &xd->plane[plane];
#if CONFIG_CB4X4 && !CONFIG_CHROMA_2X2
const BLOCK_SIZE plane_bsize =
AOMMAX(BLOCK_4X4, get_plane_block_size(mbmi->sb_type, pd));
#else
const BLOCK_SIZE plane_bsize = get_plane_block_size(mbmi->sb_type, pd);
#endif
uint8_t *dst =
&pd->dst.buf[(row * pd->dst.stride + col) << tx_size_wide_log2[0]];
// TODO (ltrudeau) Store sub-8x8 inter blocks when bottom right block is
// intra predicted.
cfl_store(xd->cfl, dst, pd->dst.stride, row, col, tx_size, plane_bsize);
}
#endif
}
#if CONFIG_VAR_TX && !CONFIG_COEF_INTERLEAVE
static void decode_reconstruct_tx(AV1_COMMON *cm, MACROBLOCKD *const xd,
aom_reader *r, MB_MODE_INFO *const mbmi,
int plane, BLOCK_SIZE plane_bsize,
int blk_row, int blk_col, int block,
TX_SIZE tx_size, int *eob_total) {
const struct macroblockd_plane *const pd = &xd->plane[plane];
const BLOCK_SIZE bsize = txsize_to_bsize[tx_size];
const int tx_row = blk_row >> (1 - pd->subsampling_y);
const int tx_col = blk_col >> (1 - pd->subsampling_x);
const TX_SIZE plane_tx_size =
plane ? uv_txsize_lookup[bsize][mbmi->inter_tx_size[tx_row][tx_col]][0][0]
: mbmi->inter_tx_size[tx_row][tx_col];
// Scale to match transform block unit.
const int max_blocks_high = max_block_high(xd, plane_bsize, plane);
const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane);
if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return;
if (tx_size == plane_tx_size) {
PLANE_TYPE plane_type = get_plane_type(plane);
#if CONFIG_LV_MAP
int16_t max_scan_line = 0;
int eob;
av1_read_coeffs_txb_facade(cm, xd, r, blk_row, blk_col, block, plane,
pd->dqcoeff, tx_size, &max_scan_line, &eob);
// tx_type will be read out in av1_read_coeffs_txb_facade
TX_TYPE tx_type = get_tx_type(plane_type, xd, block, plane_tx_size);
#else // CONFIG_LV_MAP
TX_TYPE tx_type = get_tx_type(plane_type, xd, block, plane_tx_size);
const SCAN_ORDER *sc = get_scan(cm, plane_tx_size, tx_type, mbmi);
int16_t max_scan_line = 0;
const int eob = av1_decode_block_tokens(
cm, xd, plane, sc, blk_col, blk_row, plane_tx_size, tx_type,
&max_scan_line, r, mbmi->segment_id);
#endif // CONFIG_LV_MAP
inverse_transform_block(xd, plane,
#if CONFIG_LGT
mbmi->mode,
#endif
tx_type, plane_tx_size,
&pd->dst.buf[(blk_row * pd->dst.stride + blk_col)
<< tx_size_wide_log2[0]],
pd->dst.stride, max_scan_line, eob);
*eob_total += eob;
} else {
const TX_SIZE sub_txs = sub_tx_size_map[tx_size];
const int bsl = tx_size_wide_unit[sub_txs];
int sub_step = tx_size_wide_unit[sub_txs] * tx_size_high_unit[sub_txs];
assert(sub_txs < tx_size);
int i;
assert(bsl > 0);
for (i = 0; i < 4; ++i) {
const int offsetr = blk_row + (i >> 1) * bsl;
const int offsetc = blk_col + (i & 0x01) * bsl;
if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue;
decode_reconstruct_tx(cm, xd, r, mbmi, plane, plane_bsize, offsetr,
offsetc, block, sub_txs, eob_total);
block += sub_step;
}
}
}
#endif // CONFIG_VAR_TX
#if !CONFIG_VAR_TX || CONFIG_SUPERTX || CONFIG_COEF_INTERLEAVE || \
(!CONFIG_VAR_TX && CONFIG_EXT_TX && CONFIG_RECT_TX)
static int reconstruct_inter_block(AV1_COMMON *cm, MACROBLOCKD *const xd,
aom_reader *const r, int segment_id,
int plane, int row, int col,
TX_SIZE tx_size) {
PLANE_TYPE plane_type = get_plane_type(plane);
int block_idx = get_block_idx(xd, plane, row, col);
#if CONFIG_PVQ
int eob;
(void)r;
(void)segment_id;
#else
struct macroblockd_plane *const pd = &xd->plane[plane];
#endif
#if !CONFIG_PVQ
#if CONFIG_LV_MAP
(void)segment_id;
int16_t max_scan_line = 0;
int eob;
av1_read_coeffs_txb_facade(cm, xd, r, row, col, block_idx, plane, pd->dqcoeff,
tx_size, &max_scan_line, &eob);
// tx_type will be read out in av1_read_coeffs_txb_facade
TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
#else // CONFIG_LV_MAP
int16_t max_scan_line = 0;
TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
const SCAN_ORDER *scan_order =
get_scan(cm, tx_size, tx_type, &xd->mi[0]->mbmi);
const int eob =
av1_decode_block_tokens(cm, xd, plane, scan_order, col, row, tx_size,
tx_type, &max_scan_line, r, segment_id);
#endif // CONFIG_LV_MAP
uint8_t *dst =
&pd->dst.buf[(row * pd->dst.stride + col) << tx_size_wide_log2[0]];
if (eob)
inverse_transform_block(xd, plane,
#if CONFIG_LGT
xd->mi[0]->mbmi.mode,
#endif
tx_type, tx_size, dst, pd->dst.stride,
max_scan_line, eob);
#else
TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
eob = av1_pvq_decode_helper2(cm, xd, &xd->mi[0]->mbmi, plane, row, col,
tx_size, tx_type);
#endif
return eob;
}
#endif // !CONFIG_VAR_TX || CONFIG_SUPER_TX
static void set_offsets(AV1_COMMON *const cm, MACROBLOCKD *const xd,
BLOCK_SIZE bsize, int mi_row, int mi_col, int bw,
int bh, int x_mis, int y_mis) {
const int offset = mi_row * cm->mi_stride + mi_col;
int x, y;
const TileInfo *const tile = &xd->tile;
xd->mi = cm->mi_grid_visible + offset;
xd->mi[0] = &cm->mi[offset];
// TODO(slavarnway): Generate sb_type based on bwl and bhl, instead of
// passing bsize from decode_partition().
xd->mi[0]->mbmi.sb_type = bsize;
#if CONFIG_RD_DEBUG
xd->mi[0]->mbmi.mi_row = mi_row;
xd->mi[0]->mbmi.mi_col = mi_col;
#endif
#if CONFIG_CFL
xd->cfl->mi_row = mi_row;
xd->cfl->mi_col = mi_col;
#endif
for (y = 0; y < y_mis; ++y)
for (x = !y; x < x_mis; ++x) xd->mi[y * cm->mi_stride + x] = xd->mi[0];
set_plane_n4(xd, bw, bh);
set_skip_context(xd, mi_row, mi_col);
#if CONFIG_VAR_TX
xd->max_tx_size = max_txsize_lookup[bsize];
#endif
// Distance of Mb to the various image edges. These are specified to 8th pel
// as they are always compared to values that are in 1/8th pel units
set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw,
#if CONFIG_DEPENDENT_HORZTILES
cm->dependent_horz_tiles,
#endif // CONFIG_DEPENDENT_HORZTILES
cm->mi_rows, cm->mi_cols);
av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
mi_col);
}
#if CONFIG_SUPERTX
static MB_MODE_INFO *set_offsets_extend(AV1_COMMON *const cm,
MACROBLOCKD *const xd,
const TileInfo *const tile,
BLOCK_SIZE bsize_pred, int mi_row_pred,
int mi_col_pred, int mi_row_ori,
int mi_col_ori) {
// Used in supertx
// (mi_row_ori, mi_col_ori): location for mv
// (mi_row_pred, mi_col_pred, bsize_pred): region to predict
const int bw = mi_size_wide[bsize_pred];
const int bh = mi_size_high[bsize_pred];
const int offset = mi_row_ori * cm->mi_stride + mi_col_ori;
xd->mi = cm->mi_grid_visible + offset;
xd->mi[0] = cm->mi + offset;
set_mi_row_col(xd, tile, mi_row_pred, bh, mi_col_pred, bw,
#if CONFIG_DEPENDENT_HORZTILES
cm->dependent_horz_tiles,
#endif // CONFIG_DEPENDENT_HORZTILES
cm->mi_rows, cm->mi_cols);
xd->up_available = (mi_row_ori > tile->mi_row_start);
xd->left_available = (mi_col_ori > tile->mi_col_start);
set_plane_n4(xd, bw, bh);
return &xd->mi[0]->mbmi;
}
#if CONFIG_SUPERTX
static MB_MODE_INFO *set_mb_offsets(AV1_COMMON *const cm, MACROBLOCKD *const xd,
BLOCK_SIZE bsize, int mi_row, int mi_col,
int bw, int bh, int x_mis, int y_mis) {
const int offset = mi_row * cm->mi_stride + mi_col;
const TileInfo *const tile = &xd->tile;
int x, y;
xd->mi = cm->mi_grid_visible + offset;
xd->mi[0] = cm->mi + offset;
xd->mi[0]->mbmi.sb_type = bsize;
for (y = 0; y < y_mis; ++y)
for (x = !y; x < x_mis; ++x) xd->mi[y * cm->mi_stride + x] = xd->mi[0];
set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw,
#if CONFIG_DEPENDENT_HORZTILES
cm->dependent_horz_tiles,
#endif // CONFIG_DEPENDENT_HORZTILES
cm->mi_rows, cm->mi_cols);
return &xd->mi[0]->mbmi;
}
#endif
static void set_offsets_topblock(AV1_COMMON *const cm, MACROBLOCKD *const xd,
const TileInfo *const tile, BLOCK_SIZE bsize,
int mi_row, int mi_col) {
const int bw = mi_size_wide[bsize];
const int bh = mi_size_high[bsize];
const int offset = mi_row * cm->mi_stride + mi_col;
xd->mi = cm->mi_grid_visible + offset;
xd->mi[0] = cm->mi + offset;
set_plane_n4(xd, bw, bh);
set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw,
#if CONFIG_DEPENDENT_HORZTILES
cm->dependent_horz_tiles,
#endif // CONFIG_DEPENDENT_HORZTILES
cm->mi_rows, cm->mi_cols);
av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row,
mi_col);
}
static void set_param_topblock(AV1_COMMON *const cm, MACROBLOCKD *const xd,
BLOCK_SIZE bsize, int mi_row, int mi_col,
int txfm, int skip) {
const int bw = mi_size_wide[bsize];
const int bh = mi_size_high[bsize];
const int x_mis = AOMMIN(bw, cm->mi_cols - mi_col);
const int y_mis = AOMMIN(bh, cm->mi_rows - mi_row);
const int offset = mi_row * cm->mi_stride + mi_col;
int x, y;
xd->mi = cm->mi_grid_visible + offset;
xd->mi[0] = cm->mi + offset;
for (y = 0; y < y_mis; ++y)
for (x = 0; x < x_mis; ++x) {
xd->mi[y * cm->mi_stride + x]->mbmi.skip = skip;
xd->mi[y * cm->mi_stride + x]->mbmi.tx_type = txfm;
}
#if CONFIG_VAR_TX
xd->above_txfm_context = cm->above_txfm_context + mi_col;
xd->left_txfm_context =
xd->left_txfm_context_buffer + (mi_row & MAX_MIB_MASK);
set_txfm_ctxs(xd->mi[0]->mbmi.tx_size, bw, bh, skip, xd);
#endif
}
static void set_ref(AV1_COMMON *const cm, MACROBLOCKD *const xd, int idx,
int mi_row, int mi_col) {
MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
RefBuffer *ref_buffer =
has_second_ref(mbmi) ? &cm->frame_refs[mbmi->ref_frame[idx] - LAST_FRAME]
: &cm->frame_refs[mbmi->ref_frame[0] - LAST_FRAME];
#else
RefBuffer *ref_buffer = &cm->frame_refs[mbmi->ref_frame[idx] - LAST_FRAME];
#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
xd->block_refs[idx] = ref_buffer;
if (!av1_is_valid_scale(&ref_buffer->sf))
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
"Invalid scale factors");
av1_setup_pre_planes(xd, idx, ref_buffer->buf, mi_row, mi_col,
&ref_buffer->sf);
aom_merge_corrupted_flag(&xd->corrupted, ref_buffer->buf->corrupted);
}
static void dec_predict_b_extend(
AV1Decoder *const pbi, MACROBLOCKD *const xd, const TileInfo *const tile,
int block, int mi_row_ori, int mi_col_ori, int mi_row_pred, int mi_col_pred,
int mi_row_top, int mi_col_top, int plane, uint8_t *dst_buf, int dst_stride,
BLOCK_SIZE bsize_top, BLOCK_SIZE bsize_pred, int b_sub8x8, int bextend) {
// Used in supertx
// (mi_row_ori, mi_col_ori): location for mv
// (mi_row_pred, mi_col_pred, bsize_pred): region to predict
// (mi_row_top, mi_col_top, bsize_top): region of the top partition size
// block: sub location of sub8x8 blocks
// b_sub8x8: 1: ori is sub8x8; 0: ori is not sub8x8
// bextend: 1: region to predict is an extension of ori; 0: not
int r = (mi_row_pred - mi_row_top) * MI_SIZE;
int c = (mi_col_pred - mi_col_top) * MI_SIZE;
const int mi_width_top = mi_size_wide[bsize_top];
const int mi_height_top = mi_size_high[bsize_top];
MB_MODE_INFO *mbmi;
AV1_COMMON *const cm = &pbi->common;
if (mi_row_pred < mi_row_top || mi_col_pred < mi_col_top ||
mi_row_pred >= mi_row_top + mi_height_top ||
mi_col_pred >= mi_col_top + mi_width_top || mi_row_pred >= cm->mi_rows ||
mi_col_pred >= cm->mi_cols)
return;
mbmi = set_offsets_extend(cm, xd, tile, bsize_pred, mi_row_pred, mi_col_pred,
mi_row_ori, mi_col_ori);
set_ref(cm, xd, 0, mi_row_pred, mi_col_pred);
if (has_second_ref(&xd->mi[0]->mbmi)
#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
|| is_inter_singleref_comp_mode(xd->mi[0]->mbmi.mode)
#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
)
set_ref(cm, xd, 1, mi_row_pred, mi_col_pred);
if (!bextend) mbmi->tx_size = max_txsize_lookup[bsize_top];
xd->plane[plane].dst.stride = dst_stride;
xd->plane[plane].dst.buf =
dst_buf + (r >> xd->plane[plane].subsampling_y) * dst_stride +
(c >> xd->plane[plane].subsampling_x);
if (!b_sub8x8)
av1_build_inter_predictor_sb_extend(&pbi->common, xd,
#if CONFIG_EXT_INTER
mi_row_ori, mi_col_ori,
#endif // CONFIG_EXT_INTER
mi_row_pred, mi_col_pred, plane,
bsize_pred);
else
av1_build_inter_predictor_sb_sub8x8_extend(&pbi->common, xd,
#if CONFIG_EXT_INTER
mi_row_ori, mi_col_ori,
#endif // CONFIG_EXT_INTER
mi_row_pred, mi_col_pred, plane,
bsize_pred, block);
}
static void dec_extend_dir(AV1Decoder *const pbi, MACROBLOCKD *const xd,
const TileInfo *const tile, int block,
BLOCK_SIZE bsize, BLOCK_SIZE top_bsize,
int mi_row_ori, int mi_col_ori, int mi_row,
int mi_col, int mi_row_top, int mi_col_top,
int plane, uint8_t *dst_buf, int dst_stride,
int dir) {
// dir: 0-lower, 1-upper, 2-left, 3-right
// 4-lowerleft, 5-upperleft, 6-lowerright, 7-upperright
const int mi_width = mi_size_wide[bsize];
const int mi_height = mi_size_high[bsize];
int xss = xd->plane[1].subsampling_x;
int yss = xd->plane[1].subsampling_y;
#if CONFIG_CB4X4
const int unify_bsize = 1;
#else
const int unify_bsize = 0;
#endif
int b_sub8x8 = (bsize < BLOCK_8X8) && !unify_bsize ? 1 : 0;
BLOCK_SIZE extend_bsize;
int mi_row_pred, mi_col_pred;
int wide_unit, high_unit;
int i, j;
int ext_offset = 0;
if (dir == 0 || dir == 1) {
extend_bsize =
(mi_width == mi_size_wide[BLOCK_8X8] || bsize < BLOCK_8X8 || xss < yss)
? BLOCK_8X8
: BLOCK_16X8;
#if CONFIG_CB4X4
if (bsize < BLOCK_8X8) {
extend_bsize = BLOCK_4X4;
ext_offset = mi_size_wide[BLOCK_8X8];
}
#endif
wide_unit = mi_size_wide[extend_bsize];
high_unit = mi_size_high[extend_bsize];
mi_row_pred = mi_row + ((dir == 0) ? mi_height : -(mi_height + ext_offset));
mi_col_pred = mi_col;
for (j = 0; j < mi_height + ext_offset; j += high_unit)
for (i = 0; i < mi_width + ext_offset; i += wide_unit)
dec_predict_b_extend(pbi, xd, tile, block, mi_row_ori, mi_col_ori,
mi_row_pred + j, mi_col_pred + i, mi_row_top,
mi_col_top, plane, dst_buf, dst_stride, top_bsize,
extend_bsize, b_sub8x8, 1);
} else if (dir == 2 || dir == 3) {
extend_bsize =
(mi_height == mi_size_high[BLOCK_8X8] || bsize < BLOCK_8X8 || yss < xss)
? BLOCK_8X8
: BLOCK_8X16;
#if CONFIG_CB4X4
if (bsize < BLOCK_8X8) {
extend_bsize = BLOCK_4X4;
ext_offset = mi_size_wide[BLOCK_8X8];
}
#endif
wide_unit = mi_size_wide[extend_bsize];
high_unit = mi_size_high[extend_bsize];
mi_row_pred = mi_row;
mi_col_pred = mi_col + ((dir == 3) ? mi_width : -(mi_width + ext_offset));
for (j = 0; j < mi_height + ext_offset; j += high_unit)
for (i = 0; i < mi_width + ext_offset; i += wide_unit)
dec_predict_b_extend(pbi, xd, tile, block, mi_row_ori, mi_col_ori,
mi_row_pred + j, mi_col_pred + i, mi_row_top,
mi_col_top, plane, dst_buf, dst_stride, top_bsize,
extend_bsize, b_sub8x8, 1);
} else {
extend_bsize = BLOCK_8X8;
#if CONFIG_CB4X4
if (bsize < BLOCK_8X8) {
extend_bsize = BLOCK_4X4;
ext_offset = mi_size_wide[BLOCK_8X8];
}
#endif
wide_unit = mi_size_wide[extend_bsize];
high_unit = mi_size_high[extend_bsize];
mi_row_pred = mi_row + ((dir == 4 || dir == 6) ? mi_height
: -(mi_height + ext_offset));
mi_col_pred =
mi_col + ((dir == 6 || dir == 7) ? mi_width : -(mi_width + ext_offset));
for (j = 0; j < mi_height + ext_offset; j += high_unit)
for (i = 0; i < mi_width + ext_offset; i += wide_unit)
dec_predict_b_extend(pbi, xd, tile, block, mi_row_ori, mi_col_ori,
mi_row_pred + j, mi_col_pred + i, mi_row_top,
mi_col_top, plane, dst_buf, dst_stride, top_bsize,
extend_bsize, b_sub8x8, 1);
}
}
static void dec_extend_all(AV1Decoder *const pbi, MACROBLOCKD *const xd,
const TileInfo *const tile, int block,
BLOCK_SIZE bsize, BLOCK_SIZE top_bsize,
int mi_row_ori, int mi_col_ori, int mi_row,
int mi_col, int mi_row_top, int mi_col_top,
int plane, uint8_t *dst_buf, int dst_stride) {
for (int i = 0; i < 8; ++i) {
dec_extend_dir(pbi, xd, tile, block, bsize, top_bsize, mi_row_ori,
mi_col_ori, mi_row, mi_col, mi_row_top, mi_col_top, plane,
dst_buf, dst_stride, i);
}
}
static void dec_predict_sb_complex(AV1Decoder *const pbi, MACROBLOCKD *const xd,
const TileInfo *const tile, int mi_row,
int mi_col, int mi_row_top, int mi_col_top,
BLOCK_SIZE bsize, BLOCK_SIZE top_bsize,
uint8_t *dst_buf[3], int dst_stride[3]) {
const AV1_COMMON *const cm = &pbi->common;
const int hbs = mi_size_wide[bsize] / 2;
const PARTITION_TYPE partition = get_partition(cm, mi_row, mi_col, bsize);
const BLOCK_SIZE subsize = get_subsize(bsize, partition);
#if CONFIG_EXT_PARTITION_TYPES
const BLOCK_SIZE bsize2 = get_subsize(bsize, PARTITION_SPLIT);
#endif
int i;
const int mi_offset = mi_row * cm->mi_stride + mi_col;
uint8_t *dst_buf1[3], *dst_buf2[3], *dst_buf3[3];
#if CONFIG_CB4X4
const int unify_bsize = 1;
#else
const int unify_bsize = 0;
#endif
DECLARE_ALIGNED(16, uint8_t, tmp_buf1[MAX_MB_PLANE * MAX_TX_SQUARE * 2]);
DECLARE_ALIGNED(16, uint8_t, tmp_buf2[MAX_MB_PLANE * MAX_TX_SQUARE * 2]);
DECLARE_ALIGNED(16, uint8_t, tmp_buf3[MAX_MB_PLANE * MAX_TX_SQUARE * 2]);
int dst_stride1[3] = { MAX_TX_SIZE, MAX_TX_SIZE, MAX_TX_SIZE };
int dst_stride2[3] = { MAX_TX_SIZE, MAX_TX_SIZE, MAX_TX_SIZE };
int dst_stride3[3] = { MAX_TX_SIZE, MAX_TX_SIZE, MAX_TX_SIZE };
#if CONFIG_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
int len = sizeof(uint16_t);
dst_buf1[0] = CONVERT_TO_BYTEPTR(tmp_buf1);
dst_buf1[1] = CONVERT_TO_BYTEPTR(tmp_buf1 + MAX_TX_SQUARE * len);
dst_buf1[2] = CONVERT_TO_BYTEPTR(tmp_buf1 + 2 * MAX_TX_SQUARE * len);
dst_buf2[0] = CONVERT_TO_BYTEPTR(tmp_buf2);
dst_buf2[1] = CONVERT_TO_BYTEPTR(tmp_buf2 + MAX_TX_SQUARE * len);
dst_buf2[2] = CONVERT_TO_BYTEPTR(tmp_buf2 + 2 * MAX_TX_SQUARE * len);
dst_buf3[0] = CONVERT_TO_BYTEPTR(tmp_buf3);
dst_buf3[1] = CONVERT_TO_BYTEPTR(tmp_buf3 + MAX_TX_SQUARE * len);
dst_buf3[2] = CONVERT_TO_BYTEPTR(tmp_buf3 + 2 * MAX_TX_SQUARE * len);
} else {
#endif
dst_buf1[0] = tmp_buf1;
dst_buf1[1] = tmp_buf1 + MAX_TX_SQUARE;
dst_buf1[2] = tmp_buf1 + 2 * MAX_TX_SQUARE;
dst_buf2[0] = tmp_buf2;
dst_buf2[1] = tmp_buf2 + MAX_TX_SQUARE;
dst_buf2[2] = tmp_buf2 + 2 * MAX_TX_SQUARE;
dst_buf3[0] = tmp_buf3;
dst_buf3[1] = tmp_buf3 + MAX_TX_SQUARE;
dst_buf3[2] = tmp_buf3 + 2 * MAX_TX_SQUARE;
#if CONFIG_HIGHBITDEPTH
}
#endif
if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return;
xd->mi = cm->mi_grid_visible + mi_offset;
xd->mi[0] = cm->mi + mi_offset;
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].dst.buf = dst_buf[i];
xd->plane[i].dst.stride = dst_stride[i];
}
switch (partition) {
case PARTITION_NONE:
assert(bsize < top_bsize);
for (i = 0; i < MAX_MB_PLANE; i++) {
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i], top_bsize, bsize, 0, 0);
dec_extend_all(pbi, xd, tile, 0, bsize, top_bsize, mi_row, mi_col,
mi_row, mi_col, mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i]);
}
break;
case PARTITION_HORZ:
if (bsize == BLOCK_8X8 && !unify_bsize) {
for (i = 0; i < MAX_MB_PLANE; i++) {
// For sub8x8, predict in 8x8 unit
// First half
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i], top_bsize, BLOCK_8X8, 1, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row, mi_col,
mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf[i], dst_stride[i]);
// Second half
dec_predict_b_extend(pbi, xd, tile, 2, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf1[i],
dst_stride1[i], top_bsize, BLOCK_8X8, 1, 1);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 2, subsize, top_bsize, mi_row, mi_col,
mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf1[i], dst_stride1[i]);
}
// weighted average to smooth the boundary
xd->plane[0].dst.buf = dst_buf[0];
xd->plane[0].dst.stride = dst_stride[0];
av1_build_masked_inter_predictor_complex(
xd, dst_buf[0], dst_stride[0], dst_buf1[0], dst_stride1[0], mi_row,
mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_HORZ,
0);
} else {
for (i = 0; i < MAX_MB_PLANE; i++) {
#if CONFIG_CB4X4
const struct macroblockd_plane *pd = &xd->plane[i];
int handle_chroma_sub8x8 = need_handle_chroma_sub8x8(
subsize, pd->subsampling_x, pd->subsampling_y);
if (handle_chroma_sub8x8) {
int mode_offset_row = CONFIG_CHROMA_SUB8X8 ? hbs : 0;
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + mode_offset_row,
mi_col, mi_row, mi_col, mi_row_top, mi_col_top,
i, dst_buf[i], dst_stride[i], top_bsize, bsize,
0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, bsize, top_bsize,
mi_row + mode_offset_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i]);
} else {
#endif
// First half
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row,
mi_col, mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i], top_bsize, subsize, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col, mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf[i], dst_stride[i]);
else
dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col, mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf[i], dst_stride[i], 0);
if (mi_row + hbs < cm->mi_rows) {
// Second half
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + hbs, mi_col,
mi_row + hbs, mi_col, mi_row_top, mi_col_top,
i, dst_buf1[i], dst_stride1[i], top_bsize,
subsize, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize,
mi_row + hbs, mi_col, mi_row + hbs, mi_col,
mi_row_top, mi_col_top, i, dst_buf1[i],
dst_stride1[i]);
else
dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize,
mi_row + hbs, mi_col, mi_row + hbs, mi_col,
mi_row_top, mi_col_top, i, dst_buf1[i],
dst_stride1[i], 1);
// weighted average to smooth the boundary
xd->plane[i].dst.buf = dst_buf[i];
xd->plane[i].dst.stride = dst_stride[i];
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf1[i], dst_stride1[i],
mi_row, mi_col, mi_row_top, mi_col_top, bsize, top_bsize,
PARTITION_HORZ, i);
}
#if CONFIG_CB4X4
}
#endif
}
}
break;
case PARTITION_VERT:
if (bsize == BLOCK_8X8 && !unify_bsize) {
for (i = 0; i < MAX_MB_PLANE; i++) {
// First half
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i], top_bsize, BLOCK_8X8, 1, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row, mi_col,
mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf[i], dst_stride[i]);
// Second half
dec_predict_b_extend(pbi, xd, tile, 1, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf1[i],
dst_stride1[i], top_bsize, BLOCK_8X8, 1, 1);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 1, subsize, top_bsize, mi_row, mi_col,
mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf1[i], dst_stride1[i]);
}
// Smooth
xd->plane[0].dst.buf = dst_buf[0];
xd->plane[0].dst.stride = dst_stride[0];
av1_build_masked_inter_predictor_complex(
xd, dst_buf[0], dst_stride[0], dst_buf1[0], dst_stride1[0], mi_row,
mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_VERT,
0);
} else {
for (i = 0; i < MAX_MB_PLANE; i++) {
#if CONFIG_CB4X4
const struct macroblockd_plane *pd = &xd->plane[i];
int handle_chroma_sub8x8 = need_handle_chroma_sub8x8(
subsize, pd->subsampling_x, pd->subsampling_y);
if (handle_chroma_sub8x8) {
int mode_offset_col = CONFIG_CHROMA_SUB8X8 ? hbs : 0;
assert(i > 0 && bsize == BLOCK_8X8);
dec_predict_b_extend(pbi, xd, tile, 0, mi_row,
mi_col + mode_offset_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i], top_bsize, bsize, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, bsize, top_bsize, mi_row,
mi_col + mode_offset_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i]);
} else {
#endif
// First half
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row,
mi_col, mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i], top_bsize, subsize, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col, mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf[i], dst_stride[i]);
else
dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col, mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf[i], dst_stride[i], 3);
// Second half
if (mi_col + hbs < cm->mi_cols) {
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col + hbs,
mi_row, mi_col + hbs, mi_row_top, mi_col_top,
i, dst_buf1[i], dst_stride1[i], top_bsize,
subsize, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col + hbs, mi_row, mi_col + hbs, mi_row_top,
mi_col_top, i, dst_buf1[i], dst_stride1[i]);
else
dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col + hbs, mi_row, mi_col + hbs, mi_row_top,
mi_col_top, i, dst_buf1[i], dst_stride1[i], 2);
// Smooth
xd->plane[i].dst.buf = dst_buf[i];
xd->plane[i].dst.stride = dst_stride[i];
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf1[i], dst_stride1[i],
mi_row, mi_col, mi_row_top, mi_col_top, bsize, top_bsize,
PARTITION_VERT, i);
}
#if CONFIG_CB4X4
}
#endif
}
}
break;
case PARTITION_SPLIT:
if (bsize == BLOCK_8X8 && !unify_bsize) {
for (i = 0; i < MAX_MB_PLANE; i++) {
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i], top_bsize, BLOCK_8X8, 1, 0);
dec_predict_b_extend(pbi, xd, tile, 1, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf1[i],
dst_stride1[i], top_bsize, BLOCK_8X8, 1, 1);
dec_predict_b_extend(pbi, xd, tile, 2, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf2[i],
dst_stride2[i], top_bsize, BLOCK_8X8, 1, 1);
dec_predict_b_extend(pbi, xd, tile, 3, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf3[i],
dst_stride3[i], top_bsize, BLOCK_8X8, 1, 1);
if (bsize < top_bsize) {
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row, mi_col,
mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf[i], dst_stride[i]);
dec_extend_all(pbi, xd, tile, 1, subsize, top_bsize, mi_row, mi_col,
mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf1[i], dst_stride1[i]);
dec_extend_all(pbi, xd, tile, 2, subsize, top_bsize, mi_row, mi_col,
mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf2[i], dst_stride2[i]);
dec_extend_all(pbi, xd, tile, 3, subsize, top_bsize, mi_row, mi_col,
mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf3[i], dst_stride3[i]);
}
}
#if CONFIG_CB4X4
} else if (bsize == BLOCK_8X8) {
for (i = 0; i < MAX_MB_PLANE; i++) {
const struct macroblockd_plane *pd = &xd->plane[i];
int handle_chroma_sub8x8 = need_handle_chroma_sub8x8(
subsize, pd->subsampling_x, pd->subsampling_y);
if (handle_chroma_sub8x8) {
int mode_offset_row =
CONFIG_CHROMA_SUB8X8 && mi_row + hbs < cm->mi_rows ? hbs : 0;
int mode_offset_col =
CONFIG_CHROMA_SUB8X8 && mi_col + hbs < cm->mi_cols ? hbs : 0;
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + mode_offset_row,
mi_col + mode_offset_col, mi_row, mi_col,
mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i], top_bsize, BLOCK_8X8, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, BLOCK_8X8, top_bsize,
mi_row + mode_offset_row, mi_col + mode_offset_col,
mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf[i], dst_stride[i]);
} else {
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row,
mi_col, mi_row_top, mi_col_top, i, dst_buf[i],
dst_stride[i], top_bsize, subsize, 0, 0);
if (mi_row < cm->mi_rows && mi_col + hbs < cm->mi_cols)
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col + hbs,
mi_row, mi_col + hbs, mi_row_top, mi_col_top,
i, dst_buf1[i], dst_stride1[i], top_bsize,
subsize, 0, 0);
if (mi_row + hbs < cm->mi_rows && mi_col < cm->mi_cols)
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + hbs, mi_col,
mi_row + hbs, mi_col, mi_row_top, mi_col_top,
i, dst_buf2[i], dst_stride2[i], top_bsize,
subsize, 0, 0);
if (mi_row + hbs < cm->mi_rows && mi_col + hbs < cm->mi_cols)
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + hbs, mi_col + hbs,
mi_row + hbs, mi_col + hbs, mi_row_top,
mi_col_top, i, dst_buf3[i], dst_stride3[i],
top_bsize, subsize, 0, 0);
if (bsize < top_bsize) {
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col, mi_row, mi_col, mi_row_top, mi_col_top, i,
dst_buf[i], dst_stride[i]);
if (mi_row < cm->mi_rows && mi_col + hbs < cm->mi_cols)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col + hbs, mi_row, mi_col + hbs, mi_row_top,
mi_col_top, i, dst_buf1[i], dst_stride1[i]);
if (mi_row + hbs < cm->mi_rows && mi_col < cm->mi_cols)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize,
mi_row + hbs, mi_col, mi_row + hbs, mi_col,
mi_row_top, mi_col_top, i, dst_buf2[i],
dst_stride2[i]);
if (mi_row + hbs < cm->mi_rows && mi_col + hbs < cm->mi_cols)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize,
mi_row + hbs, mi_col + hbs, mi_row + hbs,
mi_col + hbs, mi_row_top, mi_col_top, i,
dst_buf3[i], dst_stride3[i]);
}
}
}
#endif
} else {
dec_predict_sb_complex(pbi, xd, tile, mi_row, mi_col, mi_row_top,
mi_col_top, subsize, top_bsize, dst_buf,
dst_stride);
if (mi_row < cm->mi_rows && mi_col + hbs < cm->mi_cols)
dec_predict_sb_complex(pbi, xd, tile, mi_row, mi_col + hbs,
mi_row_top, mi_col_top, subsize, top_bsize,
dst_buf1, dst_stride1);
if (mi_row + hbs < cm->mi_rows && mi_col < cm->mi_cols)
dec_predict_sb_complex(pbi, xd, tile, mi_row + hbs, mi_col,
mi_row_top, mi_col_top, subsize, top_bsize,
dst_buf2, dst_stride2);
if (mi_row + hbs < cm->mi_rows && mi_col + hbs < cm->mi_cols)
dec_predict_sb_complex(pbi, xd, tile, mi_row + hbs, mi_col + hbs,
mi_row_top, mi_col_top, subsize, top_bsize,
dst_buf3, dst_stride3);
}
for (i = 0; i < MAX_MB_PLANE; i++) {
#if CONFIG_CB4X4
const struct macroblockd_plane *pd = &xd->plane[i];
int handle_chroma_sub8x8 = need_handle_chroma_sub8x8(
subsize, pd->subsampling_x, pd->subsampling_y);
if (handle_chroma_sub8x8) continue; // Skip <4x4 chroma smoothing
#else
if (bsize == BLOCK_8X8 && i != 0)
continue; // Skip <4x4 chroma smoothing
#endif
if (mi_row < cm->mi_rows && mi_col + hbs < cm->mi_cols) {
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf1[i], dst_stride1[i],
mi_row, mi_col, mi_row_top, mi_col_top, bsize, top_bsize,
PARTITION_VERT, i);
if (mi_row + hbs < cm->mi_rows) {
av1_build_masked_inter_predictor_complex(
xd, dst_buf2[i], dst_stride2[i], dst_buf3[i], dst_stride3[i],
mi_row, mi_col, mi_row_top, mi_col_top, bsize, top_bsize,
PARTITION_VERT, i);
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf2[i], dst_stride2[i],
mi_row, mi_col, mi_row_top, mi_col_top, bsize, top_bsize,
PARTITION_HORZ, i);
}
} else if (mi_row + hbs < cm->mi_rows && mi_col < cm->mi_cols) {
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf2[i], dst_stride2[i],
mi_row, mi_col, mi_row_top, mi_col_top, bsize, top_bsize,
PARTITION_HORZ, i);
}
}
break;
#if CONFIG_EXT_PARTITION_TYPES
case PARTITION_HORZ_A:
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride,
top_bsize, bsize2, 0, 0);
dec_extend_all(pbi, xd, tile, 0, bsize2, top_bsize, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride);
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col + hbs, mi_row,
mi_col + hbs, mi_row_top, mi_col_top, dst_buf1,
dst_stride1, top_bsize, bsize2, 0, 0);
dec_extend_all(pbi, xd, tile, 0, bsize2, top_bsize, mi_row, mi_col + hbs,
mi_row_top, mi_col_top, dst_buf1, dst_stride1);
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + hbs, mi_col, mi_row + hbs,
mi_col, mi_row_top, mi_col_top, dst_buf2,
dst_stride2, top_bsize, subsize, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row + hbs,
mi_col, mi_row_top, mi_col_top, dst_buf2, dst_stride2);
else
dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize, mi_row + hbs,
mi_col, mi_row_top, mi_col_top, dst_buf2, dst_stride2,
1);
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].dst.buf = dst_buf[i];
xd->plane[i].dst.stride = dst_stride[i];
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf1[i], dst_stride1[i], mi_row,
mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_VERT,
i);
}
for (i = 0; i < MAX_MB_PLANE; i++) {
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf2[i], dst_stride2[i], mi_row,
mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_HORZ,
i);
}
break;
case PARTITION_VERT_A:
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride,
top_bsize, bsize2, 0, 0);
dec_extend_all(pbi, xd, tile, 0, bsize2, top_bsize, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride);
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + hbs, mi_col, mi_row + hbs,
mi_col, mi_row_top, mi_col_top, dst_buf1,
dst_stride1, top_bsize, bsize2, 0, 0);
dec_extend_all(pbi, xd, tile, 0, bsize2, top_bsize, mi_row + hbs, mi_col,
mi_row_top, mi_col_top, dst_buf1, dst_stride1);
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col + hbs, mi_row,
mi_col + hbs, mi_row_top, mi_col_top, dst_buf2,
dst_stride2, top_bsize, subsize, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col + hbs, mi_row_top, mi_col_top, dst_buf2,
dst_stride2);
else
dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize, mi_row,
mi_col + hbs, mi_row_top, mi_col_top, dst_buf2,
dst_stride2, 2);
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].dst.buf = dst_buf[i];
xd->plane[i].dst.stride = dst_stride[i];
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf1[i], dst_stride1[i], mi_row,
mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_HORZ,
i);
}
for (i = 0; i < MAX_MB_PLANE; i++) {
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf2[i], dst_stride2[i], mi_row,
mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_VERT,
i);
}
break;
case PARTITION_HORZ_B:
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride,
top_bsize, subsize, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride);
else
dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride, 0);
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + hbs, mi_col, mi_row + hbs,
mi_col, mi_row_top, mi_col_top, dst_buf1,
dst_stride1, top_bsize, bsize2, 0, 0);
dec_extend_all(pbi, xd, tile, 0, bsize2, top_bsize, mi_row + hbs, mi_col,
mi_row_top, mi_col_top, dst_buf1, dst_stride1);
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + hbs, mi_col + hbs,
mi_row + hbs, mi_col + hbs, mi_row_top, mi_col_top,
dst_buf2, dst_stride2, top_bsize, bsize2, 0, 0);
dec_extend_all(pbi, xd, tile, 0, bsize2, top_bsize, mi_row + hbs,
mi_col + hbs, mi_row_top, mi_col_top, dst_buf2,
dst_stride2);
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].dst.buf = dst_buf1[i];
xd->plane[i].dst.stride = dst_stride1[i];
av1_build_masked_inter_predictor_complex(
xd, dst_buf1[i], dst_stride1[i], dst_buf2[i], dst_stride2[i],
mi_row, mi_col, mi_row_top, mi_col_top, bsize, top_bsize,
PARTITION_VERT, i);
}
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].dst.buf = dst_buf[i];
xd->plane[i].dst.stride = dst_stride[i];
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf1[i], dst_stride1[i], mi_row,
mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_HORZ,
i);
}
break;
case PARTITION_VERT_B:
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride,
top_bsize, subsize, 0, 0);
if (bsize < top_bsize)
dec_extend_all(pbi, xd, tile, 0, subsize, top_bsize, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride);
else
dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize, mi_row, mi_col,
mi_row_top, mi_col_top, dst_buf, dst_stride, 3);
dec_predict_b_extend(pbi, xd, tile, 0, mi_row, mi_col + hbs, mi_row,
mi_col + hbs, mi_row_top, mi_col_top, dst_buf1,
dst_stride1, top_bsize, bsize2, 0, 0);
dec_extend_all(pbi, xd, tile, 0, bsize2, top_bsize, mi_row, mi_col + hbs,
mi_row_top, mi_col_top, dst_buf1, dst_stride1);
dec_predict_b_extend(pbi, xd, tile, 0, mi_row + hbs, mi_col + hbs,
mi_row + hbs, mi_col + hbs, mi_row_top, mi_col_top,
dst_buf2, dst_stride2, top_bsize, bsize2, 0, 0);
dec_extend_all(pbi, xd, tile, 0, bsize2, top_bsize, mi_row + hbs,
mi_col + hbs, mi_row_top, mi_col_top, dst_buf2,
dst_stride2);
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].dst.buf = dst_buf1[i];
xd->plane[i].dst.stride = dst_stride1[i];
av1_build_masked_inter_predictor_complex(
xd, dst_buf1[i], dst_stride1[i], dst_buf2[i], dst_stride2[i],
mi_row, mi_col, mi_row_top, mi_col_top, bsize, top_bsize,
PARTITION_HORZ, i);
}
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].dst.buf = dst_buf[i];
xd->plane[i].dst.stride = dst_stride[i];
av1_build_masked_inter_predictor_complex(
xd, dst_buf[i], dst_stride[i], dst_buf1[i], dst_stride1[i], mi_row,
mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_VERT,
i);
}
break;
#endif // CONFIG_EXT_PARTITION_TYPES
default: assert(0);
}
}
static void set_segment_id_supertx(const AV1_COMMON *const cm, int mi_row,
int mi_col, BLOCK_SIZE bsize) {
const struct segmentation *seg = &cm->seg;
const int miw = AOMMIN(mi_size_wide[bsize], cm->mi_cols - mi_col);
const int mih = AOMMIN(mi_size_high[bsize], cm->mi_rows - mi_row);
const int mi_offset = mi_row * cm->mi_stride + mi_col;
MODE_INFO **const mip = cm->mi_grid_visible + mi_offset;
int r, c;
int seg_id_supertx = MAX_SEGMENTS;
if (!seg->enabled) {
seg_id_supertx = 0;
} else {
// Find the minimum segment_id
for (r = 0; r < mih; r++)
for (c = 0; c < miw; c++)
seg_id_supertx =
AOMMIN(mip[r * cm->mi_stride + c]->mbmi.segment_id, seg_id_supertx);
assert(0 <= seg_id_supertx && seg_id_supertx < MAX_SEGMENTS);
}
// Assign the the segment_id back to segment_id_supertx
for (r = 0; r < mih; r++)
for (c = 0; c < miw; c++)
mip[r * cm->mi_stride + c]->mbmi.segment_id_supertx = seg_id_supertx;
}
#endif // CONFIG_SUPERTX
static void decode_mbmi_block(AV1Decoder *const pbi, MACROBLOCKD *const xd,
#if CONFIG_SUPERTX
int supertx_enabled,
#endif // CONFIG_SUPERTX
int mi_row, int mi_col, aom_reader *r,
#if CONFIG_EXT_PARTITION_TYPES
PARTITION_TYPE partition,
#endif // CONFIG_EXT_PARTITION_TYPES
BLOCK_SIZE bsize) {
AV1_COMMON *const cm = &pbi->common;
const int bw = mi_size_wide[bsize];
const int bh = mi_size_high[bsize];
const int x_mis = AOMMIN(bw, cm->mi_cols - mi_col);
const int y_mis = AOMMIN(bh, cm->mi_rows - mi_row);
#if CONFIG_ACCOUNTING
aom_accounting_set_context(&pbi->accounting, mi_col, mi_row);
#endif
#if CONFIG_SUPERTX
if (supertx_enabled) {
set_mb_offsets(cm, xd, bsize, mi_row, mi_col, bw, bh, x_mis, y_mis);
} else {
set_offsets(cm, xd, bsize, mi_row, mi_col, bw, bh, x_mis, y_mis);
}
#if CONFIG_EXT_PARTITION_TYPES
xd->mi[0]->mbmi.partition = partition;
#endif
av1_read_mode_info(pbi, xd, supertx_enabled, mi_row, mi_col, r, x_mis, y_mis);
#else
set_offsets(cm, xd, bsize, mi_row, mi_col, bw, bh, x_mis, y_mis);
#if CONFIG_EXT_PARTITION_TYPES
xd->mi[0]->mbmi.partition = partition;
#endif
av1_read_mode_info(pbi, xd, mi_row, mi_col, r, x_mis, y_mis);
#endif // CONFIG_SUPERTX
if (bsize >= BLOCK_8X8 && (cm->subsampling_x || cm->subsampling_y)) {
const BLOCK_SIZE uv_subsize =
ss_size_lookup[bsize][cm->subsampling_x][cm->subsampling_y];
if (uv_subsize == BLOCK_INVALID)
aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME,
"Invalid block size.");
}
#if CONFIG_SUPERTX
xd->mi[0]->mbmi.segment_id_supertx = MAX_SEGMENTS;
#endif // CONFIG_SUPERTX
int reader_corrupted_flag = aom_reader_has_error(r);
aom_merge_corrupted_flag(&xd->corrupted, reader_corrupted_flag);
}
static void decode_token_and_recon_block(AV1Decoder *const pbi,
MACROBLOCKD *const xd, int mi_row,
int mi_col, aom_reader *r,
BLOCK_SIZE bsize) {
AV1_COMMON *const cm = &pbi->common;
const int bw = mi_size_wide[bsize];
const int bh = mi_size_high[bsize];
const int x_mis = AOMMIN(bw, cm->mi_cols - mi_col);
const int y_mis = AOMMIN(bh, cm->mi_rows - mi_row);
set_offsets(cm, xd, bsize, mi_row, mi_col, bw, bh, x_mis, y_mis);
MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
#if CONFIG_DELTA_Q
if (cm->delta_q_present_flag) {
int i;
for (i = 0; i < MAX_SEGMENTS; i++) {
#if CONFIG_EXT_DELTA_Q
xd->plane[0].seg_dequant[i][0] =
av1_dc_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->y_dc_delta_q, cm->bit_depth);
xd->plane[0].seg_dequant[i][1] = av1_ac_quant(
av1_get_qindex(&cm->seg, i, xd->current_qindex), 0, cm->bit_depth);
xd->plane[1].seg_dequant[i][0] =
av1_dc_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->uv_dc_delta_q, cm->bit_depth);
xd->plane[1].seg_dequant[i][1] =
av1_ac_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->uv_ac_delta_q, cm->bit_depth);
xd->plane[2].seg_dequant[i][0] =
av1_dc_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->uv_dc_delta_q, cm->bit_depth);
xd->plane[2].seg_dequant[i][1] =
av1_ac_quant(av1_get_qindex(&cm->seg, i, xd->current_qindex),
cm->uv_ac_delta_q, cm->bit_depth);
#else
xd->plane[0].seg_dequant[i][0] =
av1_dc_quant(xd->current_qindex, cm->y_dc_delta_q, cm->bit_depth);
xd->plane[0].seg_dequant[i][1] =
av1_ac_quant(xd->current_qindex, 0, cm->bit_depth);
xd->plane[1].seg_dequant[i][0] =
av1_dc_quant(xd->current_qindex, cm->uv_dc_delta_q, cm->bit_depth);
xd->plane[1].seg_dequant[i][1] =
av1_ac_quant(xd->current_qindex, cm->uv_ac_delta_q, cm->bit_depth);
xd->plane[2].seg_dequant[i][0] =
av1_dc_quant(xd->current_qindex, cm->uv_dc_delta_q, cm->bit_depth);
xd->plane[2].seg_dequant[i][1] =
av1_ac_quant(xd->current_qindex, cm->uv_ac_delta_q, cm->bit_depth);
#endif
}
}
#endif
#if CONFIG_CB4X4
if (mbmi->skip) av1_reset_skip_context(xd, mi_row, mi_col, bsize);
#else
if (mbmi->skip) {
av1_reset_skip_context(xd, mi_row, mi_col, AOMMAX(BLOCK_8X8, bsize));
}
#endif
#if CONFIG_COEF_INTERLEAVE
{
const struct macroblockd_plane *const pd_y = &xd->plane[0];
const struct macroblockd_plane *const pd_c = &xd->plane[1];
const TX_SIZE tx_log2_y = mbmi->tx_size;
const TX_SIZE tx_log2_c = get_uv_tx_size(mbmi, pd_c);
const int tx_sz_y = (1 << tx_log2_y);
const int tx_sz_c = (1 << tx_log2_c);
const int num_4x4_w_y = pd_y->n4_w;
const int num_4x4_h_y = pd_y->n4_h;
const int num_4x4_w_c = pd_c->n4_w;
const int num_4x4_h_c = pd_c->n4_h;
const int max_4x4_w_y = get_max_4x4_size(num_4x4_w_y, xd->mb_to_right_edge,
pd_y->subsampling_x);
const int max_4x4_h_y = get_max_4x4_size(num_4x4_h_y, xd->mb_to_bottom_edge,
pd_y->subsampling_y);
const int max_4x4_w_c = get_max_4x4_size(num_4x4_w_c, xd->mb_to_right_edge,
pd_c->subsampling_x);
const int max_4x4_h_c = get_max_4x4_size(num_4x4_h_c, xd->mb_to_bottom_edge,
pd_c->subsampling_y);
// The max_4x4_w/h may be smaller than tx_sz under some corner cases,
// i.e. when the SB is splitted by tile boundaries.
const int tu_num_w_y = (max_4x4_w_y + tx_sz_y - 1) / tx_sz_y;
const int tu_num_h_y = (max_4x4_h_y + tx_sz_y - 1) / tx_sz_y;
const int tu_num_w_c = (max_4x4_w_c + tx_sz_c - 1) / tx_sz_c;
const int tu_num_h_c = (max_4x4_h_c + tx_sz_c - 1) / tx_sz_c;
const int tu_num_c = tu_num_w_c * tu_num_h_c;
if (!is_inter_block(mbmi)) {
int tu_idx_c = 0;
int row_y, col_y, row_c, col_c;
int plane;
#if CONFIG_PALETTE
for (plane = 0; plane <= 1; ++plane) {
if (mbmi->palette_mode_info.palette_size[plane])
av1_decode_palette_tokens(xd, plane, r);
}
#endif
for (row_y = 0; row_y < tu_num_h_y; row_y++) {
for (col_y = 0; col_y < tu_num_w_y; col_y++) {
// luma
predict_and_reconstruct_intra_block(
cm, xd, r, mbmi, 0, row_y * tx_sz_y, col_y * tx_sz_y, tx_log2_y);
// chroma
if (tu_idx_c < tu_num_c) {
row_c = (tu_idx_c / tu_num_w_c) * tx_sz_c;
col_c = (tu_idx_c % tu_num_w_c) * tx_sz_c;
predict_and_reconstruct_intra_block(cm, xd, r, mbmi, 1, row_c,
col_c, tx_log2_c);
predict_and_reconstruct_intra_block(cm, xd, r, mbmi, 2, row_c,
col_c, tx_log2_c);
tu_idx_c++;
}
}
}
// In 422 case, it's possilbe that Chroma has more TUs than Luma
while (tu_idx_c < tu_num_c) {
row_c = (tu_idx_c / tu_num_w_c) * tx_sz_c;
col_c = (tu_idx_c % tu_num_w_c) * tx_sz_c;
predict_and_reconstruct_intra_block(cm, xd, r, mbmi, 1, row_c, col_c,
tx_log2_c);
predict_and_reconstruct_intra_block(cm, xd, r, mbmi, 2, row_c, col_c,
tx_log2_c);
tu_idx_c++;
}
} else {
// Prediction
av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL,
AOMMAX(bsize, BLOCK_8X8));
// Reconstruction
if (!mbmi->skip) {
int eobtotal = 0;
int tu_idx_c = 0;
int row_y, col_y, row_c, col_c;
for (row_y = 0; row_y < tu_num_h_y; row_y++) {
for (col_y = 0; col_y < tu_num_w_y; col_y++) {
// luma
eobtotal += reconstruct_inter_block(cm, xd, r, mbmi->segment_id, 0,
row_y * tx_sz_y,
col_y * tx_sz_y, tx_log2_y);
// chroma
if (tu_idx_c < tu_num_c) {
row_c = (tu_idx_c / tu_num_w_c) * tx_sz_c;
col_c = (tu_idx_c % tu_num_w_c) * tx_sz_c;
eobtotal += reconstruct_inter_block(cm, xd, r, mbmi->segment_id,
1, row_c, col_c, tx_log2_c);
eobtotal += reconstruct_inter_block(cm, xd, r, mbmi->segment_id,
2, row_c, col_c, tx_log2_c);
tu_idx_c++;
}
}
}
// In 422 case, it's possilbe that Chroma has more TUs than Luma
while (tu_idx_c < tu_num_c) {
row_c = (tu_idx_c / tu_num_w_c) * tx_sz_c;
col_c = (tu_idx_c % tu_num_w_c) * tx_sz_c;
eobtotal += reconstruct_inter_block(cm, xd, r, mbmi->segment_id, 1,
row_c, col_c, tx_log2_c);
eobtotal += reconstruct_inter_block(cm, xd, r, mbmi->segment_id, 2,
row_c, col_c, tx_log2_c);
tu_idx_c++;
}
// TODO(CONFIG_COEF_INTERLEAVE owners): bring eob == 0 corner case
// into line with the defaut configuration
if (bsize >= BLOCK_8X8 && eobtotal == 0) mbmi->skip = 1;
}
}
}
#else // CONFIG_COEF_INTERLEAVE
if (!is_inter_block(mbmi)) {
int plane;
#if CONFIG_PALETTE
for (plane = 0; plane <= 1; ++plane) {
if (mbmi->palette_mode_info.palette_size[plane])
av1_decode_palette_tokens(xd, plane, r);
}
#endif // CONFIG_PALETTE
for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
const struct macroblockd_plane *const pd = &xd->plane[plane];
const TX_SIZE tx_size = get_tx_size(plane, xd);
const int stepr = tx_size_high_unit[tx_size];
const int stepc = tx_size_wide_unit[tx_size];
#if CONFIG_CHROMA_SUB8X8
const BLOCK_SIZE plane_bsize =
AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd));
#elif CONFIG_CB4X4
const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
#else
const BLOCK_SIZE plane_bsize =
get_plane_block_size(AOMMAX(BLOCK_8X8, bsize), pd);
#endif
int row, col;
const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane);
const int max_blocks_high = max_block_high(xd, plane_bsize, plane);
#if CONFIG_CB4X4
if (!is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x,
pd->subsampling_y))
continue;
#endif
for (row = 0; row < max_blocks_high; row += stepr)
for (col = 0; col < max_blocks_wide; col += stepc)
predict_and_reconstruct_intra_block(cm, xd, r, mbmi, plane, row, col,
tx_size);
}
} else {
int ref;
#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
for (ref = 0; ref < 1 + is_inter_anyref_comp_mode(mbmi->mode); ++ref) {
const MV_REFERENCE_FRAME frame =
has_second_ref(mbmi) ? mbmi->ref_frame[ref] : mbmi->ref_frame[0];
#else
for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
if (frame < LAST_FRAME) {
#if CONFIG_INTRABC
assert(is_intrabc_block(mbmi));
assert(frame == INTRA_FRAME);
assert(ref == 0);
#else
assert(0);
#endif // CONFIG_INTRABC
} else {
RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME];
xd->block_refs[ref] = ref_buf;
if ((!av1_is_valid_scale(&ref_buf->sf)))
aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM,
"Reference frame has invalid dimensions");
av1_setup_pre_planes(xd, ref, ref_buf->buf, mi_row, mi_col,
&ref_buf->sf);
}
}
#if CONFIG_CB4X4
av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize);
#else
av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL,
AOMMAX(bsize, BLOCK_8X8));
#endif
#if CONFIG_MOTION_VAR
if (mbmi->motion_mode == OBMC_CAUSAL) {
#if CONFIG_NCOBMC
av1_build_ncobmc_inter_predictors_sb(cm, xd, mi_row, mi_col);
#else
av1_build_obmc_inter_predictors_sb(cm, xd, mi_row, mi_col);
#endif
}
#endif // CONFIG_MOTION_VAR
// Reconstruction
if (!mbmi->skip) {
int eobtotal = 0;
int plane;
for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
const struct macroblockd_plane *const pd = &xd->plane[plane];
#if CONFIG_CHROMA_SUB8X8
const BLOCK_SIZE plane_bsize =
AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd));
#elif CONFIG_CB4X4
const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
#else
const BLOCK_SIZE plane_bsize =
get_plane_block_size(AOMMAX(BLOCK_8X8, bsize), pd);
#endif
const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane);
const int max_blocks_high = max_block_high(xd, plane_bsize, plane);
int row, col;
#if CONFIG_CB4X4
if (!is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x,
pd->subsampling_y))
continue;
#endif
#if CONFIG_VAR_TX
const TX_SIZE max_tx_size = get_vartx_max_txsize(mbmi, plane_bsize);
const int bh_var_tx = tx_size_high_unit[max_tx_size];
const int bw_var_tx = tx_size_wide_unit[max_tx_size];
int block = 0;
int step =
tx_size_wide_unit[max_tx_size] * tx_size_high_unit[max_tx_size];
for (row = 0; row < max_blocks_high; row += bh_var_tx) {
for (col = 0; col < max_blocks_wide; col += bw_var_tx) {
decode_reconstruct_tx(cm, xd, r, mbmi, plane, plane_bsize, row, col,
block, max_tx_size, &eobtotal);
block += step;
}
}
#else
const TX_SIZE tx_size = get_tx_size(plane, xd);
const int stepr = tx_size_high_unit[tx_size];
const int stepc = tx_size_wide_unit[tx_size];
for (row = 0; row < max_blocks_high; row += stepr)
for (col = 0; col < max_blocks_wide; col += stepc)
eobtotal += reconstruct_inter_block(cm, xd, r, mbmi->segment_id,
plane, row, col, tx_size);
#endif
}
}
}
#endif // CONFIG_COEF_INTERLEAVE
int reader_corrupted_flag = aom_reader_has_error(r);
aom_merge_corrupted_flag(&xd->corrupted, reader_corrupted_flag);
}
#if (CONFIG_NCOBMC || CONFIG_NCOBMC_ADAPT_WEIGHT) && CONFIG_MOTION_VAR
static void detoken_and_recon_sb(AV1Decoder *const pbi, MACROBLOCKD *const xd,
int mi_row, int mi_col, aom_reader *r,
BLOCK_SIZE bsize) {
AV1_COMMON *const cm = &pbi->common;
const int hbs = mi_size_wide[bsize] >> 1;
#if CONFIG_CB4X4
const int unify_bsize = 1;
#else
const int unify_bsize = 0;
#endif
#if CONFIG_EXT_PARTITION_TYPES
BLOCK_SIZE bsize2 = get_subsize(bsize, PARTITION_SPLIT);
#endif
PARTITION_TYPE partition;
BLOCK_SIZE subsize;
const int has_rows = (mi_row + hbs) < cm->mi_rows;
const int has_cols = (mi_col + hbs) < cm->mi_cols;
if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return;
partition = get_partition(cm, mi_row, mi_col, bsize);
subsize = subsize_lookup[partition][bsize];
if (!hbs && !unify_bsize) {
xd->bmode_blocks_wl = 1 >> !!(partition & PARTITION_VERT);
xd->bmode_blocks_hl = 1 >> !!(partition & PARTITION_HORZ);
decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, subsize);
} else {
switch (partition) {
case PARTITION_NONE:
decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, bsize);
break;
case PARTITION_HORZ:
decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, subsize);
if (has_rows)
decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col, r,
subsize);
break;
case PARTITION_VERT:
decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, subsize);
if (has_cols)
decode_token_and_recon_block(pbi, xd, mi_row, mi_col + hbs, r,
subsize);
break;
case PARTITION_SPLIT:
detoken_and_recon_sb(pbi, xd, mi_row, mi_col, r, subsize);
detoken_and_recon_sb(pbi, xd, mi_row, mi_col + hbs, r, subsize);
detoken_and_recon_sb(pbi, xd, mi_row + hbs, mi_col, r, subsize);
detoken_and_recon_sb(pbi, xd, mi_row + hbs, mi_col + hbs, r, subsize);
break;
#if CONFIG_EXT_PARTITION_TYPES
case PARTITION_HORZ_A:
decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, bsize2);
decode_token_and_recon_block(pbi, xd, mi_row, mi_col + hbs, r, bsize2);
decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col, r, subsize);
break;
case PARTITION_HORZ_B:
decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, subsize);
decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col, r, bsize2);
decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col + hbs, r,
bsize2);
break;
case PARTITION_VERT_A:
decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, bsize2);
decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col, r, bsize2);
decode_token_and_recon_block(pbi, xd, mi_row, mi_col + hbs, r, subsize);
break;
case PARTITION_VERT_B:
decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, subsize);
decode_token_and_recon_block(pbi, xd, mi_row, mi_col + hbs, r, bsize2);
decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col + hbs, r,
bsize2);
break;
#endif
default: assert(0 && "Invalid partition type");
}
}
}
#endif
static void decode_block(AV1Decoder *const pbi, MACROBLOCKD *const xd,
#if CONFIG_SUPERTX
int supertx_enabled,
#endif // CONFIG_SUPERTX
int mi_row, int mi_col, aom_reader *r,
#if CONFIG_EXT_PARTITION_TYPES
PARTITION_TYPE partition,
#endif // CONFIG_EXT_PARTITION_TYPES
BLOCK_SIZE bsize) {
decode_mbmi_block(pbi, xd,
#if CONFIG_SUPERTX
supertx_enabled,
#endif
mi_row, mi_col, r,
#if CONFIG_EXT_PARTITION_TYPES
partition,
#endif
bsize);
#if !(CONFIG_MOTION_VAR && (CONFIG_NCOBMC || CONFIG_NCOBMC_ADAPT_WEIGHT))
#if CONFIG_SUPERTX
if (!supertx_enabled)
#endif // CONFIG_SUPERTX
decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, bsize);
#endif
}
static PARTITION_TYPE read_partition(AV1_COMMON *cm, MACROBLOCKD *xd,
int mi_row, int mi_col, aom_reader *r,
int has_rows, int has_cols,
BLOCK_SIZE bsize) {
#if CONFIG_UNPOISON_PARTITION_CTX
const int ctx =
partition_plane_context(xd, mi_row, mi_col, has_rows, has_cols, bsize);
const aom_prob *const probs =
ctx < PARTITION_CONTEXTS ? cm->fc->partition_prob[ctx] : NULL;
FRAME_COUNTS *const counts = ctx < PARTITION_CONTEXTS ? xd->counts : NULL;
#else
const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
const aom_prob *const probs = cm->fc->partition_prob[ctx];
FRAME_COUNTS *const counts = xd->counts;
#endif
PARTITION_TYPE p;
FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
(void)cm;
aom_cdf_prob *partition_cdf = (ctx >= 0) ? ec_ctx