diff options
author | trav90 <travawine@palemoon.org> | 2018-10-18 06:04:57 -0500 |
---|---|---|
committer | trav90 <travawine@palemoon.org> | 2018-10-18 06:04:57 -0500 |
commit | 7369c7d7a5eed32963d8af37658286617919f91c (patch) | |
tree | 5397ce7ee9bca1641118fdc3187bd9e2b24fdc9c /third_party/aom/av1/decoder | |
parent | 77887af9c4ad1420bbdb33984af4f74b55ca59db (diff) | |
download | UXP-7369c7d7a5eed32963d8af37658286617919f91c.tar UXP-7369c7d7a5eed32963d8af37658286617919f91c.tar.gz UXP-7369c7d7a5eed32963d8af37658286617919f91c.tar.lz UXP-7369c7d7a5eed32963d8af37658286617919f91c.tar.xz UXP-7369c7d7a5eed32963d8af37658286617919f91c.zip |
Update aom to commit id f5bdeac22930ff4c6b219be49c843db35970b918
Diffstat (limited to 'third_party/aom/av1/decoder')
-rw-r--r-- | third_party/aom/av1/decoder/decodeframe.c | 1792 | ||||
-rw-r--r-- | third_party/aom/av1/decoder/decodemv.c | 1133 | ||||
-rw-r--r-- | third_party/aom/av1/decoder/decodemv.h | 3 | ||||
-rw-r--r-- | third_party/aom/av1/decoder/decoder.c | 32 | ||||
-rw-r--r-- | third_party/aom/av1/decoder/decoder.h | 30 | ||||
-rw-r--r-- | third_party/aom/av1/decoder/decodetxb.c | 90 | ||||
-rw-r--r-- | third_party/aom/av1/decoder/decodetxb.h | 9 | ||||
-rw-r--r-- | third_party/aom/av1/decoder/detokenize.c | 84 | ||||
-rw-r--r-- | third_party/aom/av1/decoder/detokenize.h | 4 | ||||
-rw-r--r-- | third_party/aom/av1/decoder/inspection.c | 4 |
10 files changed, 2041 insertions, 1140 deletions
diff --git a/third_party/aom/av1/decoder/decodeframe.c b/third_party/aom/av1/decoder/decodeframe.c index 610519981..247e60e04 100644 --- a/third_party/aom/av1/decoder/decodeframe.c +++ b/third_party/aom/av1/decoder/decodeframe.c @@ -35,7 +35,6 @@ #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" @@ -49,6 +48,9 @@ #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" @@ -92,7 +94,7 @@ 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 // Normative in decoder +#if CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS // Normative in decoder return !frame_is_intra_only(cm); #else int i; @@ -101,7 +103,7 @@ static int is_compound_reference_allowed(const AV1_COMMON *cm) { if (cm->ref_frame_sign_bias[i + 1] != cm->ref_frame_sign_bias[1]) return 1; return 0; -#endif +#endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS } static void setup_compound_reference_mode(AV1_COMMON *cm) { @@ -112,8 +114,13 @@ static void setup_compound_reference_mode(AV1_COMMON *cm) { cm->comp_fwd_ref[3] = GOLDEN_FRAME; cm->comp_bwd_ref[0] = BWDREF_FRAME; +#if CONFIG_ALTREF2 + cm->comp_bwd_ref[1] = ALTREF2_FRAME; + cm->comp_bwd_ref[2] = ALTREF_FRAME; +#else // !CONFIG_ALTREF2 cm->comp_bwd_ref[1] = ALTREF_FRAME; -#else +#endif // CONFIG_ALTREF2 +#else // !CONFIG_EXT_REFS if (cm->ref_frame_sign_bias[LAST_FRAME] == cm->ref_frame_sign_bias[GOLDEN_FRAME]) { cm->comp_fixed_ref = ALTREF_FRAME; @@ -141,25 +148,15 @@ static int decode_unsigned_max(struct aom_read_bit_buffer *rb, int max) { return data > max ? max : data; } -static TX_MODE read_tx_mode(AV1_COMMON *cm, MACROBLOCKD *xd, - struct aom_read_bit_buffer *rb) { - int i, all_lossless = 1; +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->seg.enabled) { - for (i = 0; i < MAX_SEGMENTS; ++i) { - if (!xd->lossless[i]) { - all_lossless = 0; - break; - } - } - } else { - all_lossless = xd->lossless[0]; - } - - if (all_lossless) return ONLY_4X4; + 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); @@ -167,28 +164,10 @@ static TX_MODE read_tx_mode(AV1_COMMON *cm, MACROBLOCKD *xd, #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_EC_ADAPT -static void read_tx_size_probs(FRAME_CONTEXT *fc, aom_reader *r) { - int i, j, k; - for (i = 0; i < MAX_TX_DEPTH; ++i) - for (j = 0; j < TX_SIZE_CONTEXTS; ++j) - for (k = 0; k < i + 1; ++k) - av1_diff_update_prob(r, &fc->tx_size_probs[i][j][k], ACCT_STR); -} -#endif - -#if !CONFIG_EC_ADAPT -static void read_switchable_interp_probs(FRAME_CONTEXT *fc, aom_reader *r) { - int i, j; - for (j = 0; j < SWITCHABLE_FILTER_CONTEXTS; ++j) { - for (i = 0; i < SWITCHABLE_FILTERS - 1; ++i) - av1_diff_update_prob(r, &fc->switchable_interp_prob[j][i], ACCT_STR); - } -} -#endif - +#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) @@ -200,39 +179,6 @@ static void read_inter_mode_probs(FRAME_CONTEXT *fc, aom_reader *r) { for (i = 0; i < DRL_MODE_CONTEXTS; ++i) av1_diff_update_prob(r, &fc->drl_prob[i], ACCT_STR); } - -#if CONFIG_EXT_INTER -static void read_inter_compound_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_COMPOUND_MODES - 1; ++i) { - av1_diff_update_prob(r, &fc->inter_compound_mode_probs[j][i], ACCT_STR); - } - } - } -} -#endif // CONFIG_EXT_INTER -#if !CONFIG_EC_ADAPT -#if !CONFIG_EXT_TX -static void read_ext_tx_probs(FRAME_CONTEXT *fc, aom_reader *r) { - int i, j, k; - if (aom_read(r, GROUP_DIFF_UPDATE_PROB, ACCT_STR)) { - for (i = TX_4X4; i < EXT_TX_SIZES; ++i) { - for (j = 0; j < TX_TYPES; ++j) { - for (k = 0; k < TX_TYPES - 1; ++k) - av1_diff_update_prob(r, &fc->intra_ext_tx_prob[i][j][k], ACCT_STR); - } - } - } - if (aom_read(r, GROUP_DIFF_UPDATE_PROB, ACCT_STR)) { - for (i = TX_4X4; i < EXT_TX_SIZES; ++i) { - for (k = 0; k < TX_TYPES - 1; ++k) - av1_diff_update_prob(r, &fc->inter_ext_tx_prob[i][k], ACCT_STR); - } - } -} -#endif #endif static REFERENCE_MODE read_frame_reference_mode( @@ -251,23 +197,43 @@ static REFERENCE_MODE read_frame_reference_mode( } 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, j; + 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); @@ -278,9 +244,11 @@ static void read_frame_reference_mode_probs(AV1_COMMON *cm, aom_reader *r) { av1_diff_update_prob(r, &fc->comp_ref_prob[i][j], ACCT_STR); #endif // CONFIG_EXT_REFS } +#endif // CONFIG_NEW_MULTISYMBOL } } +#if !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); @@ -288,27 +256,6 @@ static void update_mv_probs(aom_prob *p, int n, aom_reader *r) { static void read_mv_probs(nmv_context *ctx, int allow_hp, aom_reader *r) { int i; - -#if !CONFIG_EC_ADAPT - int j; - update_mv_probs(ctx->joints, MV_JOINTS - 1, r); - - for (i = 0; i < 2; ++i) { - nmv_component *const comp_ctx = &ctx->comps[i]; - update_mv_probs(&comp_ctx->sign, 1, r); - update_mv_probs(comp_ctx->classes, MV_CLASSES - 1, r); - update_mv_probs(comp_ctx->class0, CLASS0_SIZE - 1, r); - update_mv_probs(comp_ctx->bits, MV_OFFSET_BITS, r); - } - for (i = 0; i < 2; ++i) { - nmv_component *const comp_ctx = &ctx->comps[i]; - for (j = 0; j < CLASS0_SIZE; ++j) { - update_mv_probs(comp_ctx->class0_fp[j], MV_FP_SIZE - 1, r); - } - update_mv_probs(comp_ctx->fp, MV_FP_SIZE - 1, r); - } -#endif // !CONFIG_EC_ADAPT - if (allow_hp) { for (i = 0; i < 2; ++i) { nmv_component *const comp_ctx = &ctx->comps[i]; @@ -317,17 +264,43 @@ static void read_mv_probs(nmv_context *ctx, int allow_hp, aom_reader *r) { } } } +#endif 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, tx_type, tx_size, dst, stride, eob); + 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])); } +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 = av1_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_PVQ static int av1_pvq_decode_helper(MACROBLOCKD *xd, tran_low_t *ref_coeff, tran_low_t *dqcoeff, int16_t *quant, int pli, @@ -452,7 +425,7 @@ static int av1_pvq_decode_helper2(AV1_COMMON *cm, MACROBLOCKD *const xd, int xdec = pd->subsampling_x; int seg_id = mbmi->segment_id; int16_t *quant; - FWD_TXFM_PARAM fwd_txfm_param; + TxfmParam 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 @@ -470,17 +443,17 @@ static int av1_pvq_decode_helper2(AV1_COMMON *cm, MACROBLOCKD *const xd, } #endif - fwd_txfm_param.tx_type = tx_type; - fwd_txfm_param.tx_size = tx_size; - fwd_txfm_param.lossless = xd->lossless[seg_id]; + txfm_param.tx_type = tx_type; + txfm_param.tx_size = tx_size; + txfm_param.lossless = xd->lossless[seg_id]; #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); + txfm_param.bd = xd->bd; + av1_highbd_fwd_txfm(pred, pvq_ref_coeff, diff_stride, &txfm_param); } else { #endif // CONFIG_HIGHBITDEPTH - av1_fwd_txfm(pred, pvq_ref_coeff, diff_stride, &fwd_txfm_param); + av1_fwd_txfm(pred, pvq_ref_coeff, diff_stride, &txfm_param); #if CONFIG_HIGHBITDEPTH } #endif // CONFIG_HIGHBITDEPTH @@ -498,26 +471,6 @@ static int av1_pvq_decode_helper2(AV1_COMMON *cm, MACROBLOCKD *const xd, } #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_CB4X4 -#if CONFIG_CHROMA_2X2 - const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); -#else - const BLOCK_SIZE plane_bsize = - AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd)); -#endif // CONFIG_CHROMA_2X2 -#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, @@ -562,7 +515,7 @@ static void hbd_process_block_dpcm_vert(TX_SIZE tx_size, TX_TYPE_1D tx_type_1d, 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); + inverse_tx(dqcoeff, 1, tx_type_1d, bd, dst, 1); dqcoeff += tx1d_width; dst += dst_stride; } @@ -590,7 +543,7 @@ static void hbd_process_block_dpcm_horz(TX_SIZE tx_size, TX_TYPE_1D tx_type_1d, 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); + inverse_tx(tx_buff, dst_stride, tx_type_1d, bd, dst, 0); } } #endif // CONFIG_HIGHBITDEPTH @@ -662,12 +615,14 @@ static void predict_and_reconstruct_intra_block( int16_t max_scan_line = 0; int eob; av1_read_coeffs_txb_facade(cm, xd, r, row, col, block_idx, plane, - pd->dqcoeff, &max_scan_line, &eob); + 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); + const TX_TYPE tx_type = + av1_get_tx_type(plane_type, xd, row, col, 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, 0); + const TX_TYPE tx_type = + av1_get_tx_type(plane_type, xd, row, col, 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, @@ -676,34 +631,46 @@ static void predict_and_reconstruct_intra_block( 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 - const int block_raster_idx = - av1_block_index_to_raster_order(tx_size, block_idx); - const PREDICTION_MODE mode = (plane == 0) - ? get_y_mode(xd->mi[0], block_raster_idx) - : mbmi->uv_mode; 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 - inverse_transform_block(xd, plane, tx_type, tx_size, dst, - pd->dst.stride, max_scan_line, eob); +#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 - TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size); +#else // !CONFIG_PVQ + const TX_TYPE tx_type = + av1_get_tx_type(plane_type, xd, row, col, block_idx, tx_size); av1_pvq_decode_helper2(cm, xd, mbmi, plane, row, col, tx_size, tx_type); -#endif +#endif // !CONFIG_PVQ } #if CONFIG_CFL if (plane == AOM_PLANE_Y) { struct macroblockd_plane *const pd = &xd->plane[plane]; +#if CONFIG_CHROMA_SUB8X8 + 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]]; - cfl_store(xd->cfl, dst, pd->dst.stride, row, col, tx_size); + // 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 } @@ -712,8 +679,8 @@ static void predict_and_reconstruct_intra_block( 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, TX_SIZE tx_size, - int *eob_total) { + 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); @@ -729,43 +696,66 @@ static void decode_reconstruct_tx(AV1_COMMON *cm, MACROBLOCKD *const xd, if (tx_size == plane_tx_size) { PLANE_TYPE plane_type = get_plane_type(plane); - int block_idx = get_block_idx(xd, plane, blk_row, blk_col); #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_idx, plane, - pd->dqcoeff, &max_scan_line, &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_idx, plane_tx_size); + const TX_TYPE tx_type = + av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, plane_tx_size); #else // CONFIG_LV_MAP - TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, plane_tx_size); - const SCAN_ORDER *sc = get_scan(cm, plane_tx_size, tx_type, 1); + const TX_TYPE tx_type = + av1_get_tx_type(plane_type, xd, blk_row, blk_col, 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, tx_type, plane_tx_size, + 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 { +#if CONFIG_RECT_TX_EXT + int is_qttx = plane_tx_size == quarter_txsize_lookup[plane_bsize]; + const TX_SIZE sub_txs = is_qttx ? plane_tx_size : sub_tx_size_map[tx_size]; + if (is_qttx) assert(blk_row == 0 && blk_col == 0 && block == 0); +#else const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; - const int bsl = tx_size_wide_unit[sub_txs]; assert(sub_txs < tx_size); +#endif + const int bsl = tx_size_wide_unit[sub_txs]; + int sub_step = tx_size_wide_unit[sub_txs] * tx_size_high_unit[sub_txs]; int i; assert(bsl > 0); for (i = 0; i < 4; ++i) { +#if CONFIG_RECT_TX_EXT + int is_wide_tx = tx_size_wide_unit[sub_txs] > tx_size_high_unit[sub_txs]; + const int offsetr = + is_qttx ? (is_wide_tx ? i * tx_size_high_unit[sub_txs] : 0) + : blk_row + ((i >> 1) * bsl); + const int offsetc = + is_qttx ? (is_wide_tx ? 0 : i * tx_size_wide_unit[sub_txs]) + : blk_col + (i & 0x01) * bsl; +#else const int offsetr = blk_row + (i >> 1) * bsl; const int offsetc = blk_col + (i & 0x01) * bsl; +#endif if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue; decode_reconstruct_tx(cm, xd, r, mbmi, plane, plane_bsize, offsetr, - offsetc, sub_txs, eob_total); + offsetc, block, sub_txs, eob_total); + block += sub_step; } } } @@ -793,13 +783,16 @@ static int reconstruct_inter_block(AV1_COMMON *cm, MACROBLOCKD *const xd, int16_t max_scan_line = 0; int eob; av1_read_coeffs_txb_facade(cm, xd, r, row, col, block_idx, plane, pd->dqcoeff, - &max_scan_line, &eob); + 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); + const TX_TYPE tx_type = + av1_get_tx_type(plane_type, xd, row, col, 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, 1); + const TX_TYPE tx_type = + av1_get_tx_type(plane_type, xd, row, col, 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); @@ -807,10 +800,15 @@ static int reconstruct_inter_block(AV1_COMMON *cm, MACROBLOCKD *const xd, uint8_t *dst = &pd->dst.buf[(row * pd->dst.stride + col) << tx_size_wide_log2[0]]; if (eob) - inverse_transform_block(xd, plane, tx_type, tx_size, dst, pd->dst.stride, + 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); + const TX_TYPE tx_type = + av1_get_tx_type(plane_type, xd, row, col, block_idx, tx_size); eob = av1_pvq_decode_helper2(cm, xd, &xd->mi[0]->mbmi, plane, row, col, tx_size, tx_type); #endif @@ -834,6 +832,10 @@ static void set_offsets(AV1_COMMON *const cm, MACROBLOCKD *const xd, 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]; @@ -959,7 +961,13 @@ static void set_param_topblock(AV1_COMMON *const cm, MACROBLOCKD *const xd, 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, @@ -972,7 +980,7 @@ static void set_ref(AV1_COMMON *const cm, MACROBLOCKD *const xd, int idx, 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, uint8_t *dst_buf[3], int dst_stride[3], + 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 @@ -997,44 +1005,42 @@ static void dec_predict_b_extend( 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 (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[0].dst.stride = dst_stride[0]; - xd->plane[1].dst.stride = dst_stride[1]; - xd->plane[2].dst.stride = dst_stride[2]; - xd->plane[0].dst.buf = dst_buf[0] + - (r >> xd->plane[0].subsampling_y) * dst_stride[0] + - (c >> xd->plane[0].subsampling_x); - xd->plane[1].dst.buf = dst_buf[1] + - (r >> xd->plane[1].subsampling_y) * dst_stride[1] + - (c >> xd->plane[1].subsampling_x); - xd->plane[2].dst.buf = dst_buf[2] + - (r >> xd->plane[2].subsampling_y) * dst_stride[2] + - (c >> xd->plane[2].subsampling_x); + 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_predictors_sb_extend(&pbi->common, xd, + av1_build_inter_predictor_sb_extend(&pbi->common, xd, #if CONFIG_EXT_INTER - mi_row_ori, mi_col_ori, + mi_row_ori, mi_col_ori, #endif // CONFIG_EXT_INTER - mi_row_pred, mi_col_pred, bsize_pred); + mi_row_pred, mi_col_pred, plane, + bsize_pred); else - av1_build_inter_predictors_sb_sub8x8_extend(&pbi->common, xd, + av1_build_inter_predictor_sb_sub8x8_extend(&pbi->common, xd, #if CONFIG_EXT_INTER - mi_row_ori, mi_col_ori, + mi_row_ori, mi_col_ori, #endif // CONFIG_EXT_INTER - mi_row_pred, mi_col_pred, - bsize_pred, block); + 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, + 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, - uint8_t *dst_buf[3], int dst_stride[3], int dir) { + 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]; @@ -1074,9 +1080,9 @@ static void dec_extend_dir(AV1Decoder *const pbi, MACROBLOCKD *const xd, 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, mi_col, + 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, dst_buf, dst_stride, top_bsize, + mi_col_top, plane, dst_buf, dst_stride, top_bsize, extend_bsize, b_sub8x8, 1); } else if (dir == 2 || dir == 3) { extend_bsize = @@ -1098,9 +1104,9 @@ static void dec_extend_dir(AV1Decoder *const pbi, MACROBLOCKD *const xd, 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, mi_col, + 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, dst_buf, dst_stride, top_bsize, + mi_col_top, plane, dst_buf, dst_stride, top_bsize, extend_bsize, b_sub8x8, 1); } else { extend_bsize = BLOCK_8X8; @@ -1120,21 +1126,23 @@ static void dec_extend_dir(AV1Decoder *const pbi, MACROBLOCKD *const xd, 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, mi_col, + 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, dst_buf, dst_stride, top_bsize, + 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, + 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, - uint8_t *dst_buf[3], int dst_stride[3]) { + 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, mi_col, - mi_row_top, mi_col_top, dst_buf, dst_stride, 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); } } @@ -1206,30 +1214,37 @@ static void dec_predict_sb_complex(AV1Decoder *const pbi, MACROBLOCKD *const xd, switch (partition) { case PARTITION_NONE: assert(bsize < top_bsize); - 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, bsize, 0, 0); - dec_extend_all(pbi, xd, tile, 0, bsize, top_bsize, mi_row, mi_col, - mi_row_top, mi_col_top, dst_buf, dst_stride); + 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 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, dst_buf, dst_stride, - 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_top, mi_col_top, dst_buf, dst_stride); - - // Second half - dec_predict_b_extend(pbi, xd, tile, 2, mi_row, mi_col, mi_row, mi_col, - mi_row_top, mi_col_top, dst_buf1, dst_stride1, - 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_top, mi_col_top, dst_buf1, dst_stride1); + 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]; @@ -1239,60 +1254,91 @@ static void dec_predict_sb_complex(AV1Decoder *const pbi, MACROBLOCKD *const xd, mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_HORZ, 0); } else { - // First half - 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); - - 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, - dst_buf1, dst_stride1, 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_buf1, - dst_stride1); - else - dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize, mi_row + hbs, - mi_col, mi_row_top, mi_col_top, dst_buf1, - dst_stride1, 1); - - // weighted average to smooth the boundary - 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++) { +#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) { - // First half - 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, BLOCK_8X8, 1, 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); - - // Second half - dec_predict_b_extend(pbi, xd, tile, 1, mi_row, mi_col, mi_row, mi_col, - mi_row_top, mi_col_top, dst_buf1, dst_stride1, - 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_top, mi_col_top, dst_buf1, dst_stride1); + 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]; @@ -1302,67 +1348,163 @@ static void dec_predict_sb_complex(AV1Decoder *const pbi, MACROBLOCKD *const xd, mi_col, mi_row_top, mi_col_top, bsize, top_bsize, PARTITION_VERT, 0); } else { - // First half - 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); - - // 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, dst_buf1, - dst_stride1, 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_buf1, - dst_stride1); - else - dec_extend_dir(pbi, xd, tile, 0, subsize, top_bsize, mi_row, - mi_col + hbs, mi_row_top, mi_col_top, dst_buf1, - dst_stride1, 2); - - // Smooth - 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++) { +#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) { - 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, 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, dst_buf1, dst_stride1, - 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, dst_buf2, dst_stride2, - 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, dst_buf3, dst_stride3, - 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_top, mi_col_top, dst_buf, dst_stride); - dec_extend_all(pbi, xd, tile, 1, subsize, top_bsize, mi_row, mi_col, - mi_row_top, mi_col_top, dst_buf1, dst_stride1); - dec_extend_all(pbi, xd, tile, 2, subsize, top_bsize, mi_row, mi_col, - mi_row_top, mi_col_top, dst_buf2, dst_stride2); - dec_extend_all(pbi, xd, tile, 3, subsize, top_bsize, mi_row, mi_col, - mi_row_top, mi_col_top, dst_buf3, dst_stride3); + 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, @@ -1381,7 +1523,12 @@ static void dec_predict_sb_complex(AV1Decoder *const pbi, MACROBLOCKD *const xd, dst_buf3, dst_stride3); } for (i = 0; i < MAX_MB_PLANE; i++) { -#if !CONFIG_CB4X4 +#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 @@ -1722,7 +1869,7 @@ static void decode_token_and_recon_block(AV1Decoder *const pbi, 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 TX_SIZE tx_log2_c = av1_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; @@ -1844,16 +1991,14 @@ static void decode_token_and_recon_block(AV1Decoder *const pbi, #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 TX_SIZE tx_size = av1_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_CB4X4 -#if CONFIG_CHROMA_2X2 - const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); -#else +#if CONFIG_CHROMA_SUB8X8 const BLOCK_SIZE plane_bsize = AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd)); -#endif // CONFIG_CHROMA_2X2 +#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); @@ -1866,17 +2011,38 @@ static void decode_token_and_recon_block(AV1Decoder *const pbi, 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); + int blk_row, blk_col; + const BLOCK_SIZE max_unit_bsize = get_plane_block_size(BLOCK_64X64, pd); + int mu_blocks_wide = + block_size_wide[max_unit_bsize] >> tx_size_wide_log2[0]; + int mu_blocks_high = + block_size_high[max_unit_bsize] >> tx_size_high_log2[0]; + mu_blocks_wide = AOMMIN(max_blocks_wide, mu_blocks_wide); + mu_blocks_high = AOMMIN(max_blocks_high, mu_blocks_high); + + for (row = 0; row < max_blocks_high; row += mu_blocks_high) { + const int unit_height = AOMMIN(mu_blocks_high + row, max_blocks_high); + for (col = 0; col < max_blocks_wide; col += mu_blocks_wide) { + const int unit_width = AOMMIN(mu_blocks_wide + col, max_blocks_wide); + + for (blk_row = row; blk_row < unit_height; blk_row += stepr) + for (blk_col = col; blk_col < unit_width; blk_col += stepc) + predict_and_reconstruct_intra_block(cm, xd, r, mbmi, plane, + blk_row, blk_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)); @@ -1921,16 +2087,14 @@ static void decode_token_and_recon_block(AV1Decoder *const pbi, for (plane = 0; plane < MAX_MB_PLANE; ++plane) { const struct macroblockd_plane *const pd = &xd->plane[plane]; -#if CONFIG_CB4X4 -#if CONFIG_CHROMA_2X2 - const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); -#else +#if CONFIG_CHROMA_SUB8X8 const BLOCK_SIZE plane_bsize = AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd)); -#endif // CONFIG_CHROMA_2X2 +#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); + 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); @@ -1943,15 +2107,41 @@ static void decode_token_and_recon_block(AV1Decoder *const pbi, #endif #if CONFIG_VAR_TX + const BLOCK_SIZE max_unit_bsize = get_plane_block_size(BLOCK_64X64, pd); + int mu_blocks_wide = + block_size_wide[max_unit_bsize] >> tx_size_wide_log2[0]; + int mu_blocks_high = + block_size_high[max_unit_bsize] >> tx_size_high_log2[0]; + + mu_blocks_wide = AOMMIN(max_blocks_wide, mu_blocks_wide); + mu_blocks_high = AOMMIN(max_blocks_high, mu_blocks_high); + 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]; - 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, - max_tx_size, &eobtotal); + 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 += mu_blocks_high) { + for (col = 0; col < max_blocks_wide; col += mu_blocks_wide) { + int blk_row, blk_col; + const int unit_height = + AOMMIN(mu_blocks_high + row, max_blocks_high); + const int unit_width = + AOMMIN(mu_blocks_wide + col, max_blocks_wide); + for (blk_row = row; blk_row < unit_height; blk_row += bh_var_tx) { + for (blk_col = col; blk_col < unit_width; blk_col += bw_var_tx) { + decode_reconstruct_tx(cm, xd, r, mbmi, plane, plane_bsize, + blk_row, blk_col, block, max_tx_size, + &eobtotal); + block += step; + } + } + } + } #else - const TX_SIZE tx_size = get_tx_size(plane, xd); + const TX_SIZE tx_size = av1_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) @@ -1968,7 +2158,7 @@ static void decode_token_and_recon_block(AV1Decoder *const pbi, aom_merge_corrupted_flag(&xd->corrupted, reader_corrupted_flag); } -#if CONFIG_NCOBMC && CONFIG_MOTION_VAR +#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) { @@ -2067,7 +2257,8 @@ static void decode_block(AV1Decoder *const pbi, MACROBLOCKD *const xd, partition, #endif bsize); -#if !(CONFIG_MOTION_VAR && CONFIG_NCOBMC) + +#if !(CONFIG_MOTION_VAR && (CONFIG_NCOBMC || CONFIG_NCOBMC_ADAPT_WEIGHT)) #if CONFIG_SUPERTX if (!supertx_enabled) #endif // CONFIG_SUPERTX @@ -2091,12 +2282,8 @@ static PARTITION_TYPE read_partition(AV1_COMMON *cm, MACROBLOCKD *xd, FRAME_COUNTS *const counts = xd->counts; #endif PARTITION_TYPE p; -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; (void)cm; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif aom_cdf_prob *partition_cdf = (ctx >= 0) ? ec_ctx->partition_cdf[ctx] : NULL; @@ -2131,7 +2318,12 @@ static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id, return 1; } else { const int ctx = av1_get_skip_context(xd); +#if CONFIG_NEW_MULTISYMBOL + FRAME_CONTEXT *ec_ctx = xd->tile_ctx; + const int skip = aom_read_symbol(r, ec_ctx->skip_cdfs[ctx], 2, ACCT_STR); +#else const int skip = aom_read(r, cm->fc->skip_probs[ctx], ACCT_STR); +#endif FRAME_COUNTS *counts = xd->counts; if (counts) ++counts->skip[ctx][skip]; return skip; @@ -2145,9 +2337,8 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd, int supertx_enabled, #endif int mi_row, int mi_col, aom_reader *r, - BLOCK_SIZE bsize, int n4x4_l2) { + BLOCK_SIZE bsize) { AV1_COMMON *const cm = &pbi->common; - const int n8x8_l2 = n4x4_l2 - 1; const int num_8x8_wh = mi_size_wide[bsize]; const int hbs = num_8x8_wh >> 1; #if CONFIG_CB4X4 @@ -2159,6 +2350,8 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd, BLOCK_SIZE subsize; #if CONFIG_EXT_PARTITION_TYPES BLOCK_SIZE bsize2 = get_subsize(bsize, PARTITION_SPLIT); + const int quarter_step = num_8x8_wh / 4; + int i; #endif const int has_rows = (mi_row + hbs) < cm->mi_rows; const int has_cols = (mi_col + hbs) < cm->mi_cols; @@ -2179,7 +2372,7 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd, #if CONFIG_PVQ assert(partition < PARTITION_TYPES); - assert(subsize < BLOCK_SIZES); + assert(subsize < BLOCK_SIZES_ALL); #endif #if CONFIG_SUPERTX if (!frame_is_intra_only(cm) && partition != PARTITION_NONE && @@ -2267,22 +2460,22 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd, #if CONFIG_SUPERTX supertx_enabled, #endif // CONFIG_SUPERTX - mi_row, mi_col, r, subsize, n8x8_l2); + mi_row, mi_col, r, subsize); decode_partition(pbi, xd, #if CONFIG_SUPERTX supertx_enabled, #endif // CONFIG_SUPERTX - mi_row, mi_col + hbs, r, subsize, n8x8_l2); + mi_row, mi_col + hbs, r, subsize); decode_partition(pbi, xd, #if CONFIG_SUPERTX supertx_enabled, #endif // CONFIG_SUPERTX - mi_row + hbs, mi_col, r, subsize, n8x8_l2); + mi_row + hbs, mi_col, r, subsize); decode_partition(pbi, xd, #if CONFIG_SUPERTX supertx_enabled, #endif // CONFIG_SUPERTX - mi_row + hbs, mi_col + hbs, r, subsize, n8x8_l2); + mi_row + hbs, mi_col + hbs, r, subsize); break; #if CONFIG_EXT_PARTITION_TYPES case PARTITION_HORZ_A: @@ -2353,7 +2546,31 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd, #endif mi_row + hbs, mi_col + hbs, r, partition, bsize2); break; + case PARTITION_HORZ_4: + for (i = 0; i < 4; ++i) { + int this_mi_row = mi_row + i * quarter_step; + if (i > 0 && this_mi_row >= cm->mi_rows) break; + + decode_block(pbi, xd, +#if CONFIG_SUPERTX + supertx_enabled, +#endif + this_mi_row, mi_col, r, partition, subsize); + } + break; + case PARTITION_VERT_4: + for (i = 0; i < 4; ++i) { + int this_mi_col = mi_col + i * quarter_step; + if (i > 0 && this_mi_col >= cm->mi_cols) break; + + decode_block(pbi, xd, +#if CONFIG_SUPERTX + supertx_enabled, #endif + mi_row, this_mi_col, r, partition, subsize); + } + break; +#endif // CONFIG_EXT_PARTITION_TYPES default: assert(0 && "Invalid partition type"); } } @@ -2398,22 +2615,24 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd, if (skip) { av1_reset_skip_context(xd, mi_row, mi_col, bsize); } else { + FRAME_CONTEXT *ec_ctx = xd->tile_ctx; #if CONFIG_EXT_TX if (get_ext_tx_types(supertx_size, bsize, 1, cm->reduced_tx_set_used) > 1) { const int eset = get_ext_tx_set(supertx_size, bsize, 1, cm->reduced_tx_set_used); if (eset > 0) { - txfm = aom_read_tree(r, av1_ext_tx_inter_tree[eset], - cm->fc->inter_ext_tx_prob[eset][supertx_size], - ACCT_STR); + const int packed_sym = + aom_read_symbol(r, ec_ctx->inter_ext_tx_cdf[eset][supertx_size], + ext_tx_cnt_inter[eset], ACCT_STR); + txfm = av1_ext_tx_inter_inv[eset][packed_sym]; if (xd->counts) ++xd->counts->inter_ext_tx[eset][supertx_size][txfm]; } } #else if (supertx_size < TX_32X32) { - txfm = aom_read_tree(r, av1_ext_tx_tree, - cm->fc->inter_ext_tx_prob[supertx_size], ACCT_STR); + txfm = aom_read_symbol(r, ec_ctx->inter_ext_tx_cdf[supertx_size], + TX_TYPES, ACCT_STR); if (xd->counts) ++xd->counts->inter_ext_tx[supertx_size][txfm]; } #endif // CONFIG_EXT_TX @@ -2438,7 +2657,7 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd, for (i = 0; i < MAX_MB_PLANE; ++i) { const struct macroblockd_plane *const pd = &xd->plane[i]; int row, col; - const TX_SIZE tx_size = get_tx_size(i, xd); + const TX_SIZE tx_size = av1_get_tx_size(i, xd); const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); const int stepr = tx_size_high_unit[tx_size]; const int stepc = tx_size_wide_unit[tx_size]; @@ -2467,12 +2686,21 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd, #if CONFIG_CDEF if (bsize == cm->sb_size) { - if (!sb_all_skip(cm, mi_row, mi_col)) { - cm->mi_grid_visible[mi_row * cm->mi_stride + mi_col]->mbmi.cdef_strength = - aom_read_literal(r, cm->cdef_bits, ACCT_STR); - } else { - cm->mi_grid_visible[mi_row * cm->mi_stride + mi_col]->mbmi.cdef_strength = - -1; + int width_step = mi_size_wide[BLOCK_64X64]; + int height_step = mi_size_wide[BLOCK_64X64]; + int w, h; + for (h = 0; (h < mi_size_high[cm->sb_size]) && (mi_row + h < cm->mi_rows); + h += height_step) { + for (w = 0; (w < mi_size_wide[cm->sb_size]) && (mi_col + w < cm->mi_cols); + w += width_step) { + if (!cm->all_lossless && !sb_all_skip(cm, mi_row + h, mi_col + w)) + cm->mi_grid_visible[(mi_row + h) * cm->mi_stride + (mi_col + w)] + ->mbmi.cdef_strength = + aom_read_literal(r, cm->cdef_bits, ACCT_STR); + else + cm->mi_grid_visible[(mi_row + h) * cm->mi_stride + (mi_col + w)] + ->mbmi.cdef_strength = -1; + } } } #endif // CONFIG_CDEF @@ -2501,33 +2729,6 @@ static void setup_bool_decoder(const uint8_t *data, const uint8_t *data_end, "Failed to allocate bool decoder %d", 1); } -#if !CONFIG_PVQ && !CONFIG_EC_ADAPT && !CONFIG_LV_MAP -static void read_coef_probs_common(av1_coeff_probs_model *coef_probs, - aom_reader *r) { - int i, j, k, l, m; -#if CONFIG_EC_ADAPT - const int node_limit = UNCONSTRAINED_NODES - 1; -#else - const int node_limit = UNCONSTRAINED_NODES; -#endif - - if (aom_read_bit(r, ACCT_STR)) - for (i = 0; i < PLANE_TYPES; ++i) - for (j = 0; j < REF_TYPES; ++j) - for (k = 0; k < COEF_BANDS; ++k) - for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) - for (m = 0; m < node_limit; ++m) - av1_diff_update_prob(r, &coef_probs[i][j][k][l][m], ACCT_STR); -} - -static void read_coef_probs(FRAME_CONTEXT *fc, TX_MODE tx_mode, aom_reader *r) { - const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; - TX_SIZE tx_size; - for (tx_size = 0; tx_size <= max_tx_size; ++tx_size) - read_coef_probs_common(fc->coef_probs[tx_size], r); -} -#endif - static void setup_segmentation(AV1_COMMON *const cm, struct aom_read_bit_buffer *rb) { struct segmentation *const seg = &cm->seg; @@ -2609,9 +2810,16 @@ static void decode_restoration_mode(AV1_COMMON *cm, if (rsi->restoration_tilesize != RESTORATION_TILESIZE_MAX) { rsi->restoration_tilesize >>= aom_rb_read_bit(rb); } + } + int s = AOMMIN(cm->subsampling_x, cm->subsampling_y); + if (s && (cm->rst_info[1].frame_restoration_type != RESTORE_NONE || + cm->rst_info[2].frame_restoration_type != RESTORE_NONE)) { + cm->rst_info[1].restoration_tilesize = + cm->rst_info[0].restoration_tilesize >> (aom_rb_read_bit(rb) * s); + } else { cm->rst_info[1].restoration_tilesize = cm->rst_info[0].restoration_tilesize; - cm->rst_info[2].restoration_tilesize = cm->rst_info[0].restoration_tilesize; } + cm->rst_info[2].restoration_tilesize = cm->rst_info[1].restoration_tilesize; } static void read_wiener_filter(WienerInfo *wiener_info, @@ -2682,16 +2890,23 @@ static void read_sgrproj_filter(SgrprojInfo *sgrproj_info, static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) { int i, p; +#if CONFIG_FRAME_SUPERRES + const int width = cm->superres_upscaled_width; + const int height = cm->superres_upscaled_height; +#else + const int width = cm->width; + const int height = cm->height; +#endif // CONFIG_FRAME_SUPERRES SgrprojInfo ref_sgrproj_info; WienerInfo ref_wiener_info; set_default_wiener(&ref_wiener_info); set_default_sgrproj(&ref_sgrproj_info); - const int ntiles = av1_get_rest_ntiles(cm->width, cm->height, - cm->rst_info[0].restoration_tilesize, - NULL, NULL, NULL, NULL); + const int ntiles = + av1_get_rest_ntiles(width, height, cm->rst_info[0].restoration_tilesize, + NULL, NULL, NULL, NULL); const int ntiles_uv = av1_get_rest_ntiles( - ROUND_POWER_OF_TWO(cm->width, cm->subsampling_x), - ROUND_POWER_OF_TWO(cm->height, cm->subsampling_y), + ROUND_POWER_OF_TWO(width, cm->subsampling_x), + ROUND_POWER_OF_TWO(height, cm->subsampling_y), cm->rst_info[1].restoration_tilesize, NULL, NULL, NULL, NULL); RestorationInfo *rsi = &cm->rst_info[0]; if (rsi->frame_restoration_type != RESTORE_NONE) { @@ -2765,6 +2980,12 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) { static void setup_loopfilter(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { struct loopfilter *lf = &cm->lf; lf->filter_level = aom_rb_read_literal(rb, 6); +#if CONFIG_UV_LVL + if (lf->filter_level > 0) { + lf->filter_level_u = aom_rb_read_literal(rb, 6); + lf->filter_level_v = aom_rb_read_literal(rb, 6); + } +#endif lf->sharpness_level = aom_rb_read_literal(rb, 3); // Read in loop filter deltas applied at the MB level based on mode or ref @@ -2877,34 +3098,33 @@ static InterpFilter read_frame_interp_filter(struct aom_read_bit_buffer *rb) { } static void setup_render_size(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { +#if CONFIG_FRAME_SUPERRES + cm->render_width = cm->superres_upscaled_width; + cm->render_height = cm->superres_upscaled_height; +#else cm->render_width = cm->width; cm->render_height = cm->height; +#endif // CONFIG_FRAME_SUPERRES if (aom_rb_read_bit(rb)) av1_read_frame_size(rb, &cm->render_width, &cm->render_height); } #if CONFIG_FRAME_SUPERRES // TODO(afergs): make "struct aom_read_bit_buffer *const rb"? -static void setup_superres_size(AV1_COMMON *const cm, - struct aom_read_bit_buffer *rb, int *width, - int *height) { - // TODO(afergs): Save input resolution - it's the upscaled resolution +static void setup_superres(AV1_COMMON *const cm, struct aom_read_bit_buffer *rb, + int *width, int *height) { + cm->superres_upscaled_width = *width; + cm->superres_upscaled_height = *height; if (aom_rb_read_bit(rb)) { cm->superres_scale_numerator = (uint8_t)aom_rb_read_literal(rb, SUPERRES_SCALE_BITS); cm->superres_scale_numerator += SUPERRES_SCALE_NUMERATOR_MIN; // Don't edit cm->width or cm->height directly, or the buffers won't get // resized correctly - // TODO(afergs): Should the render resolution not be modified? It's the same - // by default (ie. when it isn't sent)... - // resize_context_buffers() will change cm->width to equal cm->render_width, - // then they'll be the same again - *width = *width * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR; - *height = - *width * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR; + av1_calculate_scaled_size(width, height, cm->superres_scale_numerator); } else { // 1:1 scaling - ie. no scaling, scale not provided - cm->superres_scale_numerator = SUPERRES_SCALE_DENOMINATOR; + cm->superres_scale_numerator = SCALE_DENOMINATOR; } } #endif // CONFIG_FRAME_SUPERRES @@ -2954,10 +3174,10 @@ static void setup_frame_size(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { int width, height; BufferPool *const pool = cm->buffer_pool; av1_read_frame_size(rb, &width, &height); - setup_render_size(cm, rb); #if CONFIG_FRAME_SUPERRES - setup_superres_size(cm, rb, &width, &height); + setup_superres(cm, rb, &width, &height); #endif // CONFIG_FRAME_SUPERRES + setup_render_size(cm, rb); resize_context_buffers(cm, width, height); lock_buffer_pool(pool); @@ -2980,6 +3200,12 @@ static void setup_frame_size(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space; +#if CONFIG_COLORSPACE_HEADERS + pool->frame_bufs[cm->new_fb_idx].buf.transfer_function = + cm->transfer_function; + pool->frame_bufs[cm->new_fb_idx].buf.chroma_sample_position = + cm->chroma_sample_position; +#endif pool->frame_bufs[cm->new_fb_idx].buf.color_range = cm->color_range; pool->frame_bufs[cm->new_fb_idx].buf.render_width = cm->render_width; pool->frame_bufs[cm->new_fb_idx].buf.render_height = cm->render_height; @@ -3006,6 +3232,9 @@ static void setup_frame_size_with_refs(AV1_COMMON *cm, height = buf->y_crop_height; cm->render_width = buf->render_width; cm->render_height = buf->render_height; +#if CONFIG_FRAME_SUPERRES + setup_superres(cm, rb, &width, &height); +#endif // CONFIG_FRAME_SUPERRES found = 1; break; } @@ -3013,10 +3242,10 @@ static void setup_frame_size_with_refs(AV1_COMMON *cm, if (!found) { av1_read_frame_size(rb, &width, &height); - setup_render_size(cm, rb); #if CONFIG_FRAME_SUPERRES - setup_superres_size(cm, rb, &width, &height); + setup_superres(cm, rb, &width, &height); #endif // CONFIG_FRAME_SUPERRES + setup_render_size(cm, rb); } if (width <= 0 || height <= 0) @@ -3066,6 +3295,12 @@ static void setup_frame_size_with_refs(AV1_COMMON *cm, pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space; +#if CONFIG_COLORSPACE_HEADERS + pool->frame_bufs[cm->new_fb_idx].buf.transfer_function = + cm->transfer_function; + pool->frame_bufs[cm->new_fb_idx].buf.chroma_sample_position = + cm->chroma_sample_position; +#endif pool->frame_bufs[cm->new_fb_idx].buf.color_range = cm->color_range; pool->frame_bufs[cm->new_fb_idx].buf.render_width = cm->render_width; pool->frame_bufs[cm->new_fb_idx].buf.render_height = cm->render_height; @@ -3075,94 +3310,96 @@ static void read_tile_info(AV1Decoder *const pbi, struct aom_read_bit_buffer *const rb) { AV1_COMMON *const cm = &pbi->common; #if CONFIG_EXT_TILE - cm->tile_encoding_mode = aom_rb_read_literal(rb, 1); + cm->single_tile_decoding = 0; + if (cm->large_scale_tile) { + struct loopfilter *lf = &cm->lf; + + // Figure out single_tile_decoding by loopfilter_level. + cm->single_tile_decoding = (!lf->filter_level) ? 1 : 0; // Read the tile width/height #if CONFIG_EXT_PARTITION - if (cm->sb_size == BLOCK_128X128) { - cm->tile_width = aom_rb_read_literal(rb, 5) + 1; - cm->tile_height = aom_rb_read_literal(rb, 5) + 1; - } else + if (cm->sb_size == BLOCK_128X128) { + cm->tile_width = aom_rb_read_literal(rb, 5) + 1; + cm->tile_height = aom_rb_read_literal(rb, 5) + 1; + } else { +#endif // CONFIG_EXT_PARTITION + cm->tile_width = aom_rb_read_literal(rb, 6) + 1; + cm->tile_height = aom_rb_read_literal(rb, 6) + 1; +#if CONFIG_EXT_PARTITION + } #endif // CONFIG_EXT_PARTITION - { - cm->tile_width = aom_rb_read_literal(rb, 6) + 1; - cm->tile_height = aom_rb_read_literal(rb, 6) + 1; - } #if CONFIG_LOOPFILTERING_ACROSS_TILES - cm->loop_filter_across_tiles_enabled = aom_rb_read_bit(rb); + cm->loop_filter_across_tiles_enabled = aom_rb_read_bit(rb); #endif // CONFIG_LOOPFILTERING_ACROSS_TILES - cm->tile_width <<= cm->mib_size_log2; - cm->tile_height <<= cm->mib_size_log2; + cm->tile_width <<= cm->mib_size_log2; + cm->tile_height <<= cm->mib_size_log2; - cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); - cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); + cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); + cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); - // Get the number of tiles - cm->tile_cols = 1; - while (cm->tile_cols * cm->tile_width < cm->mi_cols) ++cm->tile_cols; + // Get the number of tiles + cm->tile_cols = 1; + while (cm->tile_cols * cm->tile_width < cm->mi_cols) ++cm->tile_cols; - cm->tile_rows = 1; - while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; + cm->tile_rows = 1; + while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; - if (cm->tile_cols * cm->tile_rows > 1) { - // Read the number of bytes used to store tile size - pbi->tile_col_size_bytes = aom_rb_read_literal(rb, 2) + 1; - pbi->tile_size_bytes = aom_rb_read_literal(rb, 2) + 1; - } + if (cm->tile_cols * cm->tile_rows > 1) { + // Read the number of bytes used to store tile size + pbi->tile_col_size_bytes = aom_rb_read_literal(rb, 2) + 1; + pbi->tile_size_bytes = aom_rb_read_literal(rb, 2) + 1; + } #if CONFIG_DEPENDENT_HORZTILES - if (cm->tile_rows <= 1) - cm->dependent_horz_tiles = aom_rb_read_bit(rb); - else cm->dependent_horz_tiles = 0; #endif -#else - int min_log2_tile_cols, max_log2_tile_cols, max_ones; - av1_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); + } else { +#endif // CONFIG_EXT_TILE + int min_log2_tile_cols, max_log2_tile_cols, max_ones; + av1_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); - // columns - max_ones = max_log2_tile_cols - min_log2_tile_cols; - cm->log2_tile_cols = min_log2_tile_cols; - while (max_ones-- && aom_rb_read_bit(rb)) cm->log2_tile_cols++; + // columns + max_ones = max_log2_tile_cols - min_log2_tile_cols; + cm->log2_tile_cols = min_log2_tile_cols; + while (max_ones-- && aom_rb_read_bit(rb)) cm->log2_tile_cols++; - if (cm->log2_tile_cols > 6) - aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, - "Invalid number of tile columns"); + if (cm->log2_tile_cols > 6) + aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, + "Invalid number of tile columns"); - // rows - cm->log2_tile_rows = aom_rb_read_bit(rb); - if (cm->log2_tile_rows) cm->log2_tile_rows += aom_rb_read_bit(rb); + // rows + cm->log2_tile_rows = aom_rb_read_bit(rb); + if (cm->log2_tile_rows) cm->log2_tile_rows += aom_rb_read_bit(rb); #if CONFIG_DEPENDENT_HORZTILES - if (cm->log2_tile_rows != 0) - cm->dependent_horz_tiles = aom_rb_read_bit(rb); - else - cm->dependent_horz_tiles = 0; + if (cm->log2_tile_rows != 0) + cm->dependent_horz_tiles = aom_rb_read_bit(rb); + else + cm->dependent_horz_tiles = 0; #endif #if CONFIG_LOOPFILTERING_ACROSS_TILES - cm->loop_filter_across_tiles_enabled = aom_rb_read_bit(rb); + cm->loop_filter_across_tiles_enabled = aom_rb_read_bit(rb); #endif // CONFIG_LOOPFILTERING_ACROSS_TILES - cm->tile_cols = 1 << cm->log2_tile_cols; - cm->tile_rows = 1 << cm->log2_tile_rows; + cm->tile_cols = 1 << cm->log2_tile_cols; + cm->tile_rows = 1 << cm->log2_tile_rows; - cm->tile_width = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); - cm->tile_width >>= cm->log2_tile_cols; - cm->tile_height = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); - cm->tile_height >>= cm->log2_tile_rows; + cm->tile_width = ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); + cm->tile_width >>= cm->log2_tile_cols; + cm->tile_height = ALIGN_POWER_OF_TWO(cm->mi_rows, MAX_MIB_SIZE_LOG2); + cm->tile_height >>= cm->log2_tile_rows; - // round to integer multiples of superblock size - cm->tile_width = ALIGN_POWER_OF_TWO(cm->tile_width, MAX_MIB_SIZE_LOG2); - cm->tile_height = ALIGN_POWER_OF_TWO(cm->tile_height, MAX_MIB_SIZE_LOG2); + // round to integer multiples of superblock size + cm->tile_width = ALIGN_POWER_OF_TWO(cm->tile_width, MAX_MIB_SIZE_LOG2); + cm->tile_height = ALIGN_POWER_OF_TWO(cm->tile_height, MAX_MIB_SIZE_LOG2); -// tile size magnitude -#if !CONFIG_TILE_GROUPS - if (cm->tile_rows > 1 || cm->tile_cols > 1) -#endif + // tile size magnitude pbi->tile_size_bytes = aom_rb_read_literal(rb, 2) + 1; +#if CONFIG_EXT_TILE + } #endif // CONFIG_EXT_TILE -#if CONFIG_TILE_GROUPS // Store an index to the location of the tile group information pbi->tg_size_bit_offset = rb->bit_offset; pbi->tg_size = 1 << (cm->log2_tile_rows + cm->log2_tile_cols); @@ -3172,7 +3409,6 @@ static void read_tile_info(AV1Decoder *const pbi, pbi->tg_size = 1 + aom_rb_read_literal(rb, cm->log2_tile_rows + cm->log2_tile_cols); } -#endif } static int mem_get_varsize(const uint8_t *src, int sz) { @@ -3181,20 +3417,18 @@ static int mem_get_varsize(const uint8_t *src, int sz) { case 2: return mem_get_le16(src); case 3: return mem_get_le24(src); case 4: return mem_get_le32(src); - default: assert("Invalid size" && 0); return -1; + default: assert(0 && "Invalid size"); return -1; } } #if CONFIG_EXT_TILE // Reads the next tile returning its size and adjusting '*data' accordingly // based on 'is_last'. -static void get_tile_buffer(const uint8_t *const data_end, - struct aom_internal_error_info *error_info, - const uint8_t **data, aom_decrypt_cb decrypt_cb, - void *decrypt_state, - TileBufferDec (*const tile_buffers)[MAX_TILE_COLS], - int tile_size_bytes, int col, int row, - unsigned int tile_encoding_mode) { +static void get_ls_tile_buffer( + const uint8_t *const data_end, struct aom_internal_error_info *error_info, + const uint8_t **data, aom_decrypt_cb decrypt_cb, void *decrypt_state, + TileBufferDec (*const tile_buffers)[MAX_TILE_COLS], int tile_size_bytes, + int col, int row, int tile_copy_mode) { size_t size; size_t copy_size = 0; @@ -3213,9 +3447,9 @@ static void get_tile_buffer(const uint8_t *const data_end, size = mem_get_varsize(*data, tile_size_bytes); } - // If cm->tile_encoding_mode = 1 (i.e. TILE_VR), then the top bit of the tile - // header indicates copy mode. - if (tile_encoding_mode && (size >> (tile_size_bytes * 8 - 1)) == 1) { + // If tile_copy_mode = 1, then the top bit of the tile header indicates copy + // mode. + if (tile_copy_mode && (size >> (tile_size_bytes * 8 - 1)) == 1) { // The remaining bits in the top byte signal the row offset int offset = (size >> (tile_size_bytes - 1) * 8) & 0x7f; @@ -3244,7 +3478,7 @@ static void get_tile_buffer(const uint8_t *const data_end, tile_buffers[row][col].raw_data_end = *data; } -static void get_tile_buffers( +static void get_ls_tile_buffers( AV1Decoder *pbi, const uint8_t *data, const uint8_t *data_end, TileBufferDec (*const tile_buffers)[MAX_TILE_COLS]) { AV1_COMMON *const cm = &pbi->common; @@ -3277,7 +3511,9 @@ static void get_tile_buffers( const int tile_col_size_bytes = pbi->tile_col_size_bytes; const int tile_size_bytes = pbi->tile_size_bytes; - + const int tile_copy_mode = + ((AOMMAX(cm->tile_width, cm->tile_height) << MI_SIZE_LOG2) <= 256) ? 1 + : 0; size_t tile_col_size; int r, c; @@ -3309,9 +3545,9 @@ static void get_tile_buffers( for (r = 0; r < (is_last ? tile_rows : tile_rows_end); ++r) { tile_buffers[r][c].col = c; - get_tile_buffer(tile_col_data_end[c], &pbi->common.error, &data, - pbi->decrypt_cb, pbi->decrypt_state, tile_buffers, - tile_size_bytes, c, r, cm->tile_encoding_mode); + get_ls_tile_buffer(tile_col_data_end[c], &pbi->common.error, &data, + pbi->decrypt_cb, pbi->decrypt_state, tile_buffers, + tile_size_bytes, c, r, tile_copy_mode); } } @@ -3324,14 +3560,15 @@ static void get_tile_buffers( for (r = 0; r < tile_rows; ++r) { tile_buffers[r][c].col = c; - get_tile_buffer(tile_col_data_end[c], &pbi->common.error, &data, - pbi->decrypt_cb, pbi->decrypt_state, tile_buffers, - tile_size_bytes, c, r, cm->tile_encoding_mode); + get_ls_tile_buffer(tile_col_data_end[c], &pbi->common.error, &data, + pbi->decrypt_cb, pbi->decrypt_state, tile_buffers, + tile_size_bytes, c, r, tile_copy_mode); } } } } -#else +#endif // CONFIG_EXT_TILE + // Reads the next tile returning its size and adjusting '*data' accordingly // based on 'is_last'. static void get_tile_buffer(const uint8_t *const data_end, @@ -3372,7 +3609,6 @@ static void get_tile_buffers( AV1Decoder *pbi, const uint8_t *data, const uint8_t *data_end, TileBufferDec (*const tile_buffers)[MAX_TILE_COLS]) { AV1_COMMON *const cm = &pbi->common; -#if CONFIG_TILE_GROUPS int r, c; const int tile_cols = cm->tile_cols; const int tile_rows = cm->tile_rows; @@ -3419,23 +3655,7 @@ static void get_tile_buffers( #endif } } -#else - int r, c; - const int tile_cols = cm->tile_cols; - const int tile_rows = cm->tile_rows; - - for (r = 0; r < tile_rows; ++r) { - for (c = 0; c < tile_cols; ++c) { - const int is_last = (r == tile_rows - 1) && (c == tile_cols - 1); - TileBufferDec *const buf = &tile_buffers[r][c]; - buf->col = c; - get_tile_buffer(data_end, pbi->tile_size_bytes, is_last, &cm->error, - &data, pbi->decrypt_cb, pbi->decrypt_state, buf); - } - } -#endif } -#endif // CONFIG_EXT_TILE #if CONFIG_PVQ static void daala_dec_init(AV1_COMMON *const cm, daala_dec_ctx *daala_dec, @@ -3498,24 +3718,37 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, #if CONFIG_EXT_TILE const int dec_tile_row = AOMMIN(pbi->dec_tile_row, tile_rows); const int single_row = pbi->dec_tile_row >= 0; - const int tile_rows_start = single_row ? dec_tile_row : 0; - const int tile_rows_end = single_row ? dec_tile_row + 1 : tile_rows; const int dec_tile_col = AOMMIN(pbi->dec_tile_col, tile_cols); const int single_col = pbi->dec_tile_col >= 0; - const int tile_cols_start = single_col ? dec_tile_col : 0; - const int tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; - const int inv_col_order = pbi->inv_tile_order && !single_col; - const int inv_row_order = pbi->inv_tile_order && !single_row; -#else - const int tile_rows_start = 0; - const int tile_rows_end = tile_rows; - const int tile_cols_start = 0; - const int tile_cols_end = tile_cols; - const int inv_col_order = pbi->inv_tile_order; - const int inv_row_order = pbi->inv_tile_order; #endif // CONFIG_EXT_TILE + int tile_rows_start; + int tile_rows_end; + int tile_cols_start; + int tile_cols_end; + int inv_col_order; + int inv_row_order; int tile_row, tile_col; +#if CONFIG_EXT_TILE + if (cm->large_scale_tile) { + tile_rows_start = single_row ? dec_tile_row : 0; + tile_rows_end = single_row ? dec_tile_row + 1 : tile_rows; + tile_cols_start = single_col ? dec_tile_col : 0; + tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; + inv_col_order = pbi->inv_tile_order && !single_col; + inv_row_order = pbi->inv_tile_order && !single_row; + } else { +#endif // CONFIG_EXT_TILE + tile_rows_start = 0; + tile_rows_end = tile_rows; + tile_cols_start = 0; + tile_cols_end = tile_cols; + inv_col_order = pbi->inv_tile_order; + inv_row_order = pbi->inv_tile_order; +#if CONFIG_EXT_TILE + } +#endif // CONFIG_EXT_TILE + if (cm->lf.filter_level && !cm->skip_loop_filter && pbi->lf_worker.data1 == NULL) { CHECK_MEM_ERROR(cm, pbi->lf_worker.data1, @@ -3538,7 +3771,12 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, assert(tile_rows <= MAX_TILE_ROWS); assert(tile_cols <= MAX_TILE_COLS); - get_tile_buffers(pbi, data, data_end, tile_buffers); +#if CONFIG_EXT_TILE + if (cm->large_scale_tile) + get_ls_tile_buffers(pbi, data, data_end, tile_buffers); + else +#endif // CONFIG_EXT_TILE + get_tile_buffers(pbi, data, data_end, tile_buffers); if (pbi->tile_data == NULL || n_tiles != pbi->allocated_tiles) { aom_free(pbi->tile_data); @@ -3591,11 +3829,9 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, #endif td->dqcoeff); -#if CONFIG_EC_ADAPT // Initialise the tile context from the frame context td->tctx = *cm->fc; td->xd.tile_ctx = &td->tctx; -#endif #if CONFIG_PVQ daala_dec_init(cm, &td->xd.daala_dec, &td->bit_reader); @@ -3629,13 +3865,9 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, av1_tile_set_col(&tile_info, cm, col); #if CONFIG_DEPENDENT_HORZTILES -#if CONFIG_TILE_GROUPS av1_tile_set_tg_boundary(&tile_info, cm, tile_row, tile_col); if (!cm->dependent_horz_tiles || tile_row == 0 || tile_info.tg_horz_boundary) { -#else - if (!cm->dependent_horz_tiles || tile_row == 0) { -#endif av1_zero_above_context(cm, tile_info.mi_col_start, tile_info.mi_col_end); } @@ -3643,6 +3875,8 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, av1_zero_above_context(cm, tile_info.mi_col_start, tile_info.mi_col_end); #endif + av1_setup_across_tile_boundary_info(cm, &tile_info); + for (mi_row = tile_info.mi_row_start; mi_row < tile_info.mi_row_end; mi_row += cm->mib_size) { int mi_col; @@ -3651,14 +3885,12 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, for (mi_col = tile_info.mi_col_start; mi_col < tile_info.mi_col_end; mi_col += cm->mib_size) { - av1_update_boundary_info(cm, &tile_info, mi_row, mi_col); decode_partition(pbi, &td->xd, #if CONFIG_SUPERTX 0, #endif // CONFIG_SUPERTX - mi_row, mi_col, &td->bit_reader, cm->sb_size, - b_width_log2_lookup[cm->sb_size]); -#if CONFIG_NCOBMC && CONFIG_MOTION_VAR + mi_row, mi_col, &td->bit_reader, cm->sb_size); +#if (CONFIG_NCOBMC || CONFIG_NCOBMC_ADAPT_WEIGHT) && CONFIG_MOTION_VAR detoken_and_recon_sb(pbi, &td->xd, mi_row, mi_col, &td->bit_reader, cm->sb_size); #endif @@ -3709,9 +3941,20 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, } #if CONFIG_VAR_TX || CONFIG_CB4X4 - // Loopfilter the whole frame. +// Loopfilter the whole frame. +#if CONFIG_UV_LVL + if (cm->lf.filter_level > 0) { + av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, + cm->lf.filter_level, 0, 0); + av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, + cm->lf.filter_level_u, 1, 0); + av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, + cm->lf.filter_level_v, 2, 0); + } +#else av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, cm->lf.filter_level, 0, 0); +#endif // CONFIG_UV_LVL #else #if CONFIG_PARALLEL_DEBLOCKING // Loopfilter all rows in the frame in the frame. @@ -3737,20 +3980,22 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, av1_frameworker_broadcast(pbi->cur_buf, INT_MAX); #if CONFIG_EXT_TILE - if (n_tiles == 1) { + if (cm->large_scale_tile) { + if (n_tiles == 1) { #if CONFIG_ANS - return data_end; + return data_end; #else - // Find the end of the single tile buffer - return aom_reader_find_end(&pbi->tile_data->bit_reader); + // Find the end of the single tile buffer + return aom_reader_find_end(&pbi->tile_data->bit_reader); #endif // CONFIG_ANS + } else { + // Return the end of the last tile buffer + return tile_buffers[tile_rows - 1][tile_cols - 1].raw_data_end; + } } else { - // Return the end of the last tile buffer - return tile_buffers[tile_rows - 1][tile_cols - 1].raw_data_end; - } -#else +#endif // CONFIG_EXT_TILE #if CONFIG_ANS - return data_end; + return data_end; #else { // Get last tile data. @@ -3758,6 +4003,8 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, return aom_reader_find_end(&td->bit_reader); } #endif // CONFIG_ANS +#if CONFIG_EXT_TILE + } #endif // CONFIG_EXT_TILE } @@ -3776,11 +4023,7 @@ static int tile_worker_hook(TileWorkerData *const tile_data, tile_data->error_info.setjmp = 1; tile_data->xd.error_info = &tile_data->error_info; #if CONFIG_DEPENDENT_HORZTILES -#if CONFIG_TILE_GROUPS if (!cm->dependent_horz_tiles || tile->tg_horz_boundary) { -#else - if (!cm->dependent_horz_tiles) { -#endif av1_zero_above_context(&pbi->common, tile->mi_col_start, tile->mi_col_end); } #else @@ -3797,9 +4040,8 @@ static int tile_worker_hook(TileWorkerData *const tile_data, #if CONFIG_SUPERTX 0, #endif - mi_row, mi_col, &tile_data->bit_reader, cm->sb_size, - b_width_log2_lookup[cm->sb_size]); -#if CONFIG_NCOBMC && CONFIG_MOTION_VAR + mi_row, mi_col, &tile_data->bit_reader, cm->sb_size); +#if (CONFIG_NCOBMC || CONFIG_NCOBMC_ADAPT_WEIGHT) && CONFIG_MOTION_VAR detoken_and_recon_sb(pbi, &tile_data->xd, mi_row, mi_col, &tile_data->bit_reader, cm->sb_size); #endif @@ -3826,24 +4068,35 @@ static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data, #if CONFIG_EXT_TILE const int dec_tile_row = AOMMIN(pbi->dec_tile_row, tile_rows); const int single_row = pbi->dec_tile_row >= 0; - const int tile_rows_start = single_row ? dec_tile_row : 0; - const int tile_rows_end = single_row ? dec_tile_row + 1 : tile_rows; const int dec_tile_col = AOMMIN(pbi->dec_tile_col, tile_cols); const int single_col = pbi->dec_tile_col >= 0; - const int tile_cols_start = single_col ? dec_tile_col : 0; - const int tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; -#else - const int tile_rows_start = 0; - const int tile_rows_end = tile_rows; - const int tile_cols_start = 0; - const int tile_cols_end = tile_cols; #endif // CONFIG_EXT_TILE + int tile_rows_start; + int tile_rows_end; + int tile_cols_start; + int tile_cols_end; int tile_row, tile_col; int i; -#if !(CONFIG_ANS || CONFIG_EXT_TILE) +#if CONFIG_EXT_TILE + if (cm->large_scale_tile) { + tile_rows_start = single_row ? dec_tile_row : 0; + tile_rows_end = single_row ? dec_tile_row + 1 : tile_rows; + tile_cols_start = single_col ? dec_tile_col : 0; + tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; + } else { +#endif // CONFIG_EXT_TILE + tile_rows_start = 0; + tile_rows_end = tile_rows; + tile_cols_start = 0; + tile_cols_end = tile_cols; +#if CONFIG_EXT_TILE + } +#endif // CONFIG_EXT_TILE + +#if !CONFIG_ANS int final_worker = -1; -#endif // !(CONFIG_ANS || CONFIG_EXT_TILE) +#endif // !CONFIG_ANS assert(tile_rows <= MAX_TILE_ROWS); assert(tile_cols <= MAX_TILE_COLS); @@ -3893,8 +4146,13 @@ static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data, } } - // Load tile data into tile_buffers - get_tile_buffers(pbi, data, data_end, tile_buffers); +// Load tile data into tile_buffers +#if CONFIG_EXT_TILE + if (cm->large_scale_tile) + get_ls_tile_buffers(pbi, data, data_end, tile_buffers); + else +#endif // CONFIG_EXT_TILE + get_tile_buffers(pbi, data, data_end, tile_buffers); for (tile_row = tile_rows_start; tile_row < tile_rows_end; ++tile_row) { // Sort the buffers in this tile row based on size in descending order. @@ -3938,6 +4196,9 @@ static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data, av1_zero(twd->dqcoeff); av1_tile_init(tile_info, cm, tile_row, buf->col); av1_tile_init(&twd->xd.tile, cm, tile_row, buf->col); + + av1_setup_across_tile_boundary_info(cm, tile_info); + setup_bool_decoder(buf->data, data_end, buf->size, &cm->error, &twd->bit_reader, #if CONFIG_ANS && ANS_MAX_SYMBOLS @@ -3956,11 +4217,9 @@ static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data, daala_dec_init(cm, &twd->xd.daala_dec, &twd->bit_reader); twd->xd.daala_dec.state.adapt = &twd->tctx.pvq_context; #endif -#if CONFIG_EC_ADAPT // Initialise the tile context from the frame context twd->tctx = *cm->fc; twd->xd.tile_ctx = &twd->tctx; -#endif #if CONFIG_PALETTE twd->xd.plane[0].color_index_map = twd->color_index_map[0]; twd->xd.plane[1].color_index_map = twd->color_index_map[1]; @@ -3973,11 +4232,11 @@ static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data, winterface->launch(worker); } -#if !(CONFIG_ANS || CONFIG_EXT_TILE) +#if !CONFIG_ANS if (tile_row == tile_rows - 1 && buf->col == tile_cols - 1) { final_worker = i; } -#endif // !(CONFIG_ANS || CONFIG_EXT_TILE) +#endif // !CONFIG_ANS } // Sync all workers @@ -4001,11 +4260,13 @@ static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data, } #if CONFIG_EXT_TILE - // Return the end of the last tile buffer - return tile_buffers[tile_rows - 1][tile_cols - 1].raw_data_end; -#else + if (cm->large_scale_tile) { + // Return the end of the last tile buffer + return tile_buffers[tile_rows - 1][tile_cols - 1].raw_data_end; + } else { +#endif // CONFIG_EXT_TILE #if CONFIG_ANS - return data_end; + return data_end; #else assert(final_worker != -1); { @@ -4014,6 +4275,8 @@ static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data, return aom_reader_find_end(&twd->bit_reader); } #endif // CONFIG_ANS +#if CONFIG_EXT_TILE + } #endif // CONFIG_EXT_TILE } @@ -4023,7 +4286,8 @@ static void error_handler(void *data) { } static void read_bitdepth_colorspace_sampling(AV1_COMMON *cm, - struct aom_read_bit_buffer *rb) { + struct aom_read_bit_buffer *rb, + int allow_lowbitdepth) { if (cm->profile >= PROFILE_2) { cm->bit_depth = aom_rb_read_bit(rb) ? AOM_BITS_12 : AOM_BITS_10; } else { @@ -4031,10 +4295,16 @@ static void read_bitdepth_colorspace_sampling(AV1_COMMON *cm, } #if CONFIG_HIGHBITDEPTH - cm->use_highbitdepth = cm->bit_depth > AOM_BITS_8 || !CONFIG_LOWBITDEPTH; + cm->use_highbitdepth = cm->bit_depth > AOM_BITS_8 || !allow_lowbitdepth; +#else + (void)allow_lowbitdepth; #endif - +#if CONFIG_COLORSPACE_HEADERS + cm->color_space = aom_rb_read_literal(rb, 5); + cm->transfer_function = aom_rb_read_literal(rb, 5); +#else cm->color_space = aom_rb_read_literal(rb, 3); +#endif if (cm->color_space != AOM_CS_SRGB) { // [16,235] (including xvycc) vs [0,255] range cm->color_range = aom_rb_read_bit(rb); @@ -4050,6 +4320,11 @@ static void read_bitdepth_colorspace_sampling(AV1_COMMON *cm, } else { cm->subsampling_y = cm->subsampling_x = 1; } +#if CONFIG_COLORSPACE_HEADERS + if (cm->subsampling_x == 1 && cm->subsampling_y == 1) { + cm->chroma_sample_position = aom_rb_read_literal(rb, 2); + } +#endif } else { if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) { // Note if colorspace is SRGB then 4:4:4 chroma sampling is assumed. @@ -4087,7 +4362,11 @@ static void read_compound_tools(AV1_COMMON *cm, } #endif // CONFIG_INTERINTRA #if CONFIG_WEDGE || CONFIG_COMPOUND_SEGMENT +#if CONFIG_COMPOUND_SINGLEREF + if (!frame_is_intra_only(cm)) { +#else // !CONFIG_COMPOUND_SINGLEREF if (!frame_is_intra_only(cm) && cm->reference_mode != SINGLE_REFERENCE) { +#endif // CONFIG_COMPOUND_SINGLEREF cm->allow_masked_compound = aom_rb_read_bit(rb); } else { cm->allow_masked_compound = 0; @@ -4096,6 +4375,38 @@ static void read_compound_tools(AV1_COMMON *cm, } #endif // CONFIG_EXT_INTER +#if CONFIG_VAR_REFS +static void check_valid_ref_frames(AV1_COMMON *cm) { + MV_REFERENCE_FRAME ref_frame; + // TODO(zoeliu): To handle ALTREF_FRAME the same way as do with other + // reference frames: Current encoder invalid ALTREF when ALTREF + // is the same as LAST, but invalid all the other references + // when they are the same as ALTREF. + for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { + RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - LAST_FRAME]; + + if (ref_buf->idx != INVALID_IDX) { + ref_buf->is_valid = 1; + + MV_REFERENCE_FRAME ref; + for (ref = LAST_FRAME; ref < ref_frame; ++ref) { + RefBuffer *const buf = &cm->frame_refs[ref - LAST_FRAME]; + if (buf->is_valid && buf->idx == ref_buf->idx) { + if (ref_frame != ALTREF_FRAME || ref == LAST_FRAME) { + ref_buf->is_valid = 0; + break; + } else { + buf->is_valid = 0; + } + } + } + } else { + ref_buf->is_valid = 0; + } + } +} +#endif // CONFIG_VAR_REFS + static size_t read_uncompressed_header(AV1Decoder *pbi, struct aom_read_bit_buffer *rb) { AV1_COMMON *const cm = &pbi->common; @@ -4131,6 +4442,13 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, "Unsupported bitstream profile"); +#if CONFIG_EXT_TILE + cm->large_scale_tile = aom_rb_read_literal(rb, 1); +#if CONFIG_REFERENCE_BUFFER + if (cm->large_scale_tile) pbi->seq_params.frame_id_numbers_present_flag = 0; +#endif // CONFIG_REFERENCE_BUFFER +#endif // CONFIG_EXT_TILE + cm->show_existing_frame = aom_rb_read_bit(rb); if (cm->show_existing_frame) { @@ -4221,12 +4539,15 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, "Invalid frame sync code"); - read_bitdepth_colorspace_sampling(cm, rb); + read_bitdepth_colorspace_sampling(cm, rb, pbi->allow_lowbitdepth); pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1; for (i = 0; i < INTER_REFS_PER_FRAME; ++i) { cm->frame_refs[i].idx = INVALID_IDX; cm->frame_refs[i].buf = NULL; +#if CONFIG_VAR_REFS + cm->frame_refs[i].is_valid = 0; +#endif // CONFIG_VAR_REFS } setup_frame_size(cm, rb); @@ -4274,7 +4595,7 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, "Invalid frame sync code"); - read_bitdepth_colorspace_sampling(cm, rb); + read_bitdepth_colorspace_sampling(cm, rb, pbi->allow_lowbitdepth); pbi->refresh_frame_flags = aom_rb_read_literal(rb, REF_FRAMES); setup_frame_size(cm, rb); @@ -4322,6 +4643,10 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, #endif } +#if CONFIG_VAR_REFS + check_valid_ref_frames(cm); +#endif // CONFIG_VAR_REFS + #if CONFIG_FRAME_SIZE if (cm->error_resilient_mode == 0) { setup_frame_size_with_refs(cm, rb); @@ -4375,6 +4700,10 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, get_frame_new_buffer(cm)->bit_depth = cm->bit_depth; get_frame_new_buffer(cm)->color_space = cm->color_space; +#if CONFIG_COLORSPACE_HEADERS + get_frame_new_buffer(cm)->transfer_function = cm->transfer_function; + get_frame_new_buffer(cm)->chroma_sample_position = cm->chroma_sample_position; +#endif get_frame_new_buffer(cm)->color_range = cm->color_range; get_frame_new_buffer(cm)->render_width = cm->render_width; get_frame_new_buffer(cm)->render_height = cm->render_height; @@ -4432,12 +4761,6 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, #endif // CONFIG_EXT_PARTITION setup_loopfilter(cm, rb); -#if CONFIG_CDEF - setup_cdef(cm, rb); -#endif -#if CONFIG_LOOP_RESTORATION - decode_restoration_mode(cm, rb); -#endif // CONFIG_LOOP_RESTORATION setup_quantization(cm, rb); xd->bd = (int)cm->bit_depth; @@ -4476,15 +4799,11 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, xd->prev_qindex = cm->base_qindex; cm->delta_q_res = 1 << aom_rb_read_literal(rb, 2); #if CONFIG_EXT_DELTA_Q - if (segment_quantizer_active) { - assert(seg->abs_delta == SEGMENT_DELTADATA); - } + assert(!segment_quantizer_active); cm->delta_lf_present_flag = aom_rb_read_bit(rb); if (cm->delta_lf_present_flag) { xd->prev_delta_lf_from_base = 0; cm->delta_lf_res = 1 << aom_rb_read_literal(rb, 2); - } else { - cm->delta_lf_present_flag = 0; } #endif // CONFIG_EXT_DELTA_Q } @@ -4499,9 +4818,17 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0; xd->qindex[i] = qindex; } - + cm->all_lossless = all_lossless(cm, xd); setup_segmentation_dequant(cm); - cm->tx_mode = read_tx_mode(cm, xd, rb); +#if CONFIG_CDEF + if (!cm->all_lossless) { + setup_cdef(cm, rb); + } +#endif +#if CONFIG_LOOP_RESTORATION + decode_restoration_mode(cm, rb); +#endif // CONFIG_LOOP_RESTORATION + cm->tx_mode = read_tx_mode(cm, rb); cm->reference_mode = read_frame_reference_mode(cm, rb); #if CONFIG_EXT_INTER read_compound_tools(cm, rb); @@ -4520,37 +4847,6 @@ static size_t read_uncompressed_header(AV1Decoder *pbi, return sz; } -#if CONFIG_EXT_TX -#if !CONFIG_EC_ADAPT -static void read_ext_tx_probs(FRAME_CONTEXT *fc, aom_reader *r) { - int i, j, k; - int s; - for (s = 1; s < EXT_TX_SETS_INTER; ++s) { - if (aom_read(r, GROUP_DIFF_UPDATE_PROB, ACCT_STR)) { - for (i = TX_4X4; i < EXT_TX_SIZES; ++i) { - if (!use_inter_ext_tx_for_txsize[s][i]) continue; - for (j = 0; j < num_ext_tx_set[ext_tx_set_type_inter[s]] - 1; ++j) - av1_diff_update_prob(r, &fc->inter_ext_tx_prob[s][i][j], ACCT_STR); - } - } - } - - for (s = 1; s < EXT_TX_SETS_INTRA; ++s) { - if (aom_read(r, GROUP_DIFF_UPDATE_PROB, ACCT_STR)) { - for (i = TX_4X4; i < EXT_TX_SIZES; ++i) { - if (!use_intra_ext_tx_for_txsize[s][i]) continue; - for (j = 0; j < INTRA_MODES; ++j) - for (k = 0; k < num_ext_tx_set[ext_tx_set_type_intra[s]] - 1; ++k) - av1_diff_update_prob(r, &fc->intra_ext_tx_prob[s][i][j][k], - ACCT_STR); - } - } - } -} -#endif // !CONFIG_EC_ADAPT -#else - -#endif // CONFIG_EXT_TX #if CONFIG_SUPERTX static void read_supertx_probs(FRAME_CONTEXT *fc, aom_reader *r) { int i, j; @@ -4567,10 +4863,9 @@ static void read_supertx_probs(FRAME_CONTEXT *fc, aom_reader *r) { #if CONFIG_GLOBAL_MOTION static void read_global_motion_params(WarpedMotionParams *params, WarpedMotionParams *ref_params, - aom_prob *probs, aom_reader *r, - int allow_hp) { - TransformationType type = - aom_read_tree(r, av1_global_motion_types_tree, probs, ACCT_STR); + aom_reader *r, int allow_hp) { + TransformationType type = aom_read_bit(r, ACCT_STR); + if (type != IDENTITY) type += aom_read_literal(r, GLOBAL_TYPE_BITS, ACCT_STR); int trans_bits; int trans_dec_factor; int trans_prec_diff; @@ -4654,10 +4949,17 @@ static void read_global_motion_params(WarpedMotionParams *params, static void read_global_motion(AV1_COMMON *cm, aom_reader *r) { int frame; + YV12_BUFFER_CONFIG *ref_buf; for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) { - read_global_motion_params( - &cm->global_motion[frame], &cm->prev_frame->global_motion[frame], - cm->fc->global_motion_types_prob, r, cm->allow_high_precision_mv); + ref_buf = get_ref_frame(cm, frame); + if (cm->width == ref_buf->y_crop_width && + cm->height == ref_buf->y_crop_height) { + read_global_motion_params(&cm->global_motion[frame], + &cm->prev_frame->global_motion[frame], r, + cm->allow_high_precision_mv); + } else { + set_default_warp_params(&cm->global_motion[frame]); + } /* printf("Dec Ref %d [%d/%d]: %d %d %d %d\n", frame, cm->current_video_frame, cm->show_frame, @@ -4678,12 +4980,10 @@ static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data, #if CONFIG_SUPERTX MACROBLOCKD *const xd = &pbi->mb; #endif - FRAME_CONTEXT *const fc = cm->fc; aom_reader r; - int k, i; -#if !CONFIG_EC_ADAPT || \ - (CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION || CONFIG_EXT_INTER) - int j; +#if !CONFIG_NEW_MULTISYMBOL + FRAME_CONTEXT *const fc = cm->fc; + int i; #endif #if CONFIG_ANS && ANS_MAX_SYMBOLS @@ -4703,122 +5003,54 @@ static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data, } #endif -#if !CONFIG_EC_ADAPT - if (cm->tx_mode == TX_MODE_SELECT) read_tx_size_probs(fc, &r); -#endif -#if CONFIG_EXT_TX && CONFIG_RECT_TX && CONFIG_RECT_TX_EXT +#if CONFIG_RECT_TX_EXT && (CONFIG_EXT_TX || CONFIG_VAR_TX) if (cm->tx_mode == TX_MODE_SELECT) av1_diff_update_prob(&r, &fc->quarter_tx_size_prob, ACCT_STR); -#endif // CONFIG_EXT_TX && CONFIG_RECT_TX && CONFIG_RECT_TX_EXT +#endif #if CONFIG_LV_MAP av1_read_txb_probs(fc, cm->tx_mode, &r); -#else // CONFIG_LV_MAP -#if !CONFIG_PVQ -#if !CONFIG_EC_ADAPT - read_coef_probs(fc, cm->tx_mode, &r); -#endif // !CONFIG_EC_ADAPT -#endif // !CONFIG_PVQ #endif // CONFIG_LV_MAP +#if !CONFIG_NEW_MULTISYMBOL #if CONFIG_VAR_TX - for (k = 0; k < TXFM_PARTITION_CONTEXTS; ++k) - av1_diff_update_prob(&r, &fc->txfm_partition_prob[k], ACCT_STR); + for (i = 0; i < TXFM_PARTITION_CONTEXTS; ++i) + av1_diff_update_prob(&r, &fc->txfm_partition_prob[i], ACCT_STR); #endif // CONFIG_VAR_TX - for (k = 0; k < SKIP_CONTEXTS; ++k) - av1_diff_update_prob(&r, &fc->skip_probs[k], ACCT_STR); - -#if CONFIG_DELTA_Q && !CONFIG_EC_ADAPT -#if CONFIG_EXT_DELTA_Q - if (cm->delta_q_present_flag) { - for (k = 0; k < DELTA_Q_PROBS; ++k) - av1_diff_update_prob(&r, &fc->delta_q_prob[k], ACCT_STR); - } - if (cm->delta_lf_present_flag) { - for (k = 0; k < DELTA_LF_PROBS; ++k) - av1_diff_update_prob(&r, &fc->delta_lf_prob[k], ACCT_STR); - } -#else - for (k = 0; k < DELTA_Q_PROBS; ++k) - av1_diff_update_prob(&r, &fc->delta_q_prob[k], ACCT_STR); -#endif + for (i = 0; i < SKIP_CONTEXTS; ++i) + av1_diff_update_prob(&r, &fc->skip_probs[i], ACCT_STR); #endif -#if !CONFIG_EC_ADAPT - if (cm->seg.enabled && cm->seg.update_map) { - if (cm->seg.temporal_update) { - for (k = 0; k < PREDICTION_PROBS; k++) - av1_diff_update_prob(&r, &cm->fc->seg.pred_probs[k], ACCT_STR); - } - for (k = 0; k < MAX_SEGMENTS - 1; k++) - av1_diff_update_prob(&r, &cm->fc->seg.tree_probs[k], ACCT_STR); - } - - for (j = 0; j < INTRA_MODES; j++) { - for (i = 0; i < INTRA_MODES - 1; ++i) - av1_diff_update_prob(&r, &fc->uv_mode_prob[j][i], ACCT_STR); - } - -#if CONFIG_EXT_PARTITION_TYPES - for (j = 0; j < PARTITION_PLOFFSET; ++j) - for (i = 0; i < PARTITION_TYPES - 1; ++i) - av1_diff_update_prob(&r, &fc->partition_prob[j][i], ACCT_STR); - for (; j < PARTITION_CONTEXTS_PRIMARY; ++j) - for (i = 0; i < EXT_PARTITION_TYPES - 1; ++i) - av1_diff_update_prob(&r, &fc->partition_prob[j][i], ACCT_STR); -#else - for (j = 0; j < PARTITION_CONTEXTS_PRIMARY; ++j) - for (i = 0; i < PARTITION_TYPES - 1; ++i) - av1_diff_update_prob(&r, &fc->partition_prob[j][i], ACCT_STR); -#endif // CONFIG_EXT_PARTITION_TYPES - -#if CONFIG_UNPOISON_PARTITION_CTX - for (; j < PARTITION_CONTEXTS_PRIMARY + PARTITION_BLOCK_SIZES; ++j) - av1_diff_update_prob(&r, &fc->partition_prob[j][PARTITION_VERT], ACCT_STR); - for (; j < PARTITION_CONTEXTS_PRIMARY + 2 * PARTITION_BLOCK_SIZES; ++j) - av1_diff_update_prob(&r, &fc->partition_prob[j][PARTITION_HORZ], ACCT_STR); -#endif // CONFIG_UNPOISON_PARTITION_CTX - -#if CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP - for (i = 0; i < INTRA_FILTERS + 1; ++i) - for (j = 0; j < INTRA_FILTERS - 1; ++j) - av1_diff_update_prob(&r, &fc->intra_filter_probs[i][j], ACCT_STR); -#endif // CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP -#endif // !CONFIG_EC_ADAPT - if (frame_is_intra_only(cm)) { - av1_copy(cm->kf_y_prob, av1_kf_y_mode_prob); av1_copy(cm->fc->kf_y_cdf, av1_kf_y_mode_cdf); -#if !CONFIG_EC_ADAPT - for (k = 0; k < INTRA_MODES; k++) - for (j = 0; j < INTRA_MODES; j++) - for (i = 0; i < INTRA_MODES - 1; ++i) - av1_diff_update_prob(&r, &cm->kf_y_prob[k][j][i], ACCT_STR); -#endif #if CONFIG_INTRABC if (cm->allow_screen_content_tools) { av1_diff_update_prob(&r, &fc->intrabc_prob, ACCT_STR); } #endif } else { +#if !CONFIG_NEW_MULTISYMBOL read_inter_mode_probs(fc, &r); +#endif #if CONFIG_EXT_INTER - read_inter_compound_mode_probs(fc, &r); #if CONFIG_INTERINTRA if (cm->reference_mode != COMPOUND_REFERENCE && cm->allow_interintra_compound) { +#if !CONFIG_NEW_MULTISYMBOL for (i = 0; i < BLOCK_SIZE_GROUPS; i++) { if (is_interintra_allowed_bsize_group(i)) { av1_diff_update_prob(&r, &fc->interintra_prob[i], ACCT_STR); } } - for (i = 0; i < BLOCK_SIZE_GROUPS; i++) { - for (j = 0; j < INTERINTRA_MODES - 1; j++) - av1_diff_update_prob(&r, &fc->interintra_mode_prob[i][j], ACCT_STR); - } -#if CONFIG_WEDGE - for (i = 0; i < BLOCK_SIZES; i++) { +#endif +#if CONFIG_WEDGE && !CONFIG_NEW_MULTISYMBOL +#if CONFIG_EXT_PARTITION_TYPES + int block_sizes_to_update = BLOCK_SIZES_ALL; +#else + int block_sizes_to_update = BLOCK_SIZES; +#endif + for (i = 0; i < block_sizes_to_update; i++) { if (is_interintra_allowed_bsize(i) && is_interintra_wedge_used(i)) { av1_diff_update_prob(&r, &fc->wedge_interintra_prob[i], ACCT_STR); } @@ -4826,47 +5058,33 @@ static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data, #endif // CONFIG_WEDGE } #endif // CONFIG_INTERINTRA -#if CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE - if (cm->reference_mode != SINGLE_REFERENCE && cm->allow_masked_compound) { - for (i = 0; i < BLOCK_SIZES; i++) { - for (j = 0; j < COMPOUND_TYPES - 1; j++) { - av1_diff_update_prob(&r, &fc->compound_type_prob[i][j], ACCT_STR); - } - } - } -#endif // CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE #endif // CONFIG_EXT_INTER -#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION - for (i = BLOCK_8X8; i < BLOCK_SIZES; ++i) { - for (j = 0; j < MOTION_MODES - 1; ++j) - av1_diff_update_prob(&r, &fc->motion_mode_prob[i][j], ACCT_STR); +#if CONFIG_NCOBMC_ADAPT_WEIGHT && CONFIG_MOTION_VAR + for (i = 0; i < ADAPT_OVERLAP_BLOCKS; ++i) { + for (int j = 0; j < MAX_NCOBMC_MODES - 1; ++j) + av1_diff_update_prob(&r, &fc->ncobmc_mode_prob[i][j], ACCT_STR); } -#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION - -#if !CONFIG_EC_ADAPT - if (cm->interp_filter == SWITCHABLE) read_switchable_interp_probs(fc, &r); -#endif +#endif // CONFIG_NCOBMC_ADAPT_WEIGHT && CONFIG_MOTION_VAR +#if !CONFIG_NEW_MULTISYMBOL for (i = 0; i < INTRA_INTER_CONTEXTS; i++) av1_diff_update_prob(&r, &fc->intra_inter_prob[i], ACCT_STR); +#endif if (cm->reference_mode != SINGLE_REFERENCE) setup_compound_reference_mode(cm); read_frame_reference_mode_probs(cm, &r); -#if !CONFIG_EC_ADAPT - for (j = 0; j < BLOCK_SIZE_GROUPS; j++) { - for (i = 0; i < INTRA_MODES - 1; ++i) - av1_diff_update_prob(&r, &fc->y_mode_prob[j][i], ACCT_STR); - } -#endif +#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF + for (i = 0; i < COMP_INTER_MODE_CONTEXTS; i++) + av1_diff_update_prob(&r, &fc->comp_inter_mode_prob[i], ACCT_STR); +#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF +#if !CONFIG_NEW_MULTISYMBOL for (i = 0; i < NMV_CONTEXTS; ++i) read_mv_probs(&fc->nmvc[i], cm->allow_high_precision_mv, &r); -#if !CONFIG_EC_ADAPT - read_ext_tx_probs(fc, &r); -#endif // EC_ADAPT +#endif #if CONFIG_SUPERTX if (!xd->lossless[0]) read_supertx_probs(fc, &r); #endif @@ -4874,17 +5092,9 @@ static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data, read_global_motion(cm, &r); #endif } -#if !CONFIG_EC_ADAPT - av1_coef_head_cdfs(fc); - /* Make tail distribution from head */ - av1_coef_pareto_cdfs(fc); - for (i = 0; i < NMV_CONTEXTS; ++i) av1_set_mv_cdfs(&fc->nmvc[i]); - av1_set_mode_cdfs(cm); -#endif // !CONFIG_EC_ADAPT return aom_reader_has_error(&r); } - #ifdef NDEBUG #define debug_check_frame_counts(cm) (void)0 #else // !NDEBUG @@ -4895,10 +5105,12 @@ static void debug_check_frame_counts(const AV1_COMMON *const cm) { av1_zero(zero_counts); assert(cm->refresh_frame_context != REFRESH_FRAME_CONTEXT_BACKWARD || cm->error_resilient_mode); +#if CONFIG_ENTROPY_STATS assert(!memcmp(cm->counts.y_mode, zero_counts.y_mode, sizeof(cm->counts.y_mode))); assert(!memcmp(cm->counts.uv_mode, zero_counts.uv_mode, sizeof(cm->counts.uv_mode))); +#endif assert(!memcmp(cm->counts.partition, zero_counts.partition, sizeof(cm->counts.partition))); assert(!memcmp(cm->counts.coef, zero_counts.coef, sizeof(cm->counts.coef))); @@ -4908,8 +5120,6 @@ static void debug_check_frame_counts(const AV1_COMMON *const cm) { sizeof(cm->counts.blockz_count))); assert(!memcmp(cm->counts.switchable_interp, zero_counts.switchable_interp, sizeof(cm->counts.switchable_interp))); - assert(!memcmp(cm->counts.inter_mode, zero_counts.inter_mode, - sizeof(cm->counts.inter_mode))); #if CONFIG_EXT_INTER assert(!memcmp(cm->counts.inter_compound_mode, zero_counts.inter_compound_mode, @@ -4930,10 +5140,24 @@ static void debug_check_frame_counts(const AV1_COMMON *const cm) { assert(!memcmp(cm->counts.motion_mode, zero_counts.motion_mode, sizeof(cm->counts.motion_mode))); #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION +#if CONFIG_NCOBMC_ADAPT_WEIGHT && CONFIG_MOTION_VAR + assert(!memcmp(cm->counts.ncobmc_mode, zero_counts.ncobmc_mode, + sizeof(cm->counts.ncobmc_mode))); +#endif assert(!memcmp(cm->counts.intra_inter, zero_counts.intra_inter, sizeof(cm->counts.intra_inter))); +#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF + assert(!memcmp(cm->counts.comp_inter_mode, zero_counts.comp_inter_mode, + sizeof(cm->counts.comp_inter_mode))); +#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF assert(!memcmp(cm->counts.comp_inter, zero_counts.comp_inter, sizeof(cm->counts.comp_inter))); +#if CONFIG_EXT_COMP_REFS + assert(!memcmp(cm->counts.comp_ref_type, zero_counts.comp_ref_type, + sizeof(cm->counts.comp_ref_type))); + assert(!memcmp(cm->counts.uni_comp_ref, zero_counts.uni_comp_ref, + sizeof(cm->counts.uni_comp_ref))); +#endif // CONFIG_EXT_COMP_REFS assert(!memcmp(cm->counts.single_ref, zero_counts.single_ref, sizeof(cm->counts.single_ref))); assert(!memcmp(cm->counts.comp_ref, zero_counts.comp_ref, @@ -4995,14 +5219,25 @@ BITSTREAM_PROFILE av1_read_profile(struct aom_read_bit_buffer *rb) { return (BITSTREAM_PROFILE)profile; } -#if CONFIG_EC_ADAPT static void make_update_tile_list_dec(AV1Decoder *pbi, int tile_rows, int tile_cols, FRAME_CONTEXT *ec_ctxs[]) { int i; for (i = 0; i < tile_rows * tile_cols; ++i) ec_ctxs[i] = &pbi->tile_data[i].tctx; } -#endif + +#if CONFIG_FRAME_SUPERRES +void superres_post_decode(AV1Decoder *pbi) { + AV1_COMMON *const cm = &pbi->common; + BufferPool *const pool = cm->buffer_pool; + + if (av1_superres_unscaled(cm)) return; + + lock_buffer_pool(pool); + av1_superres_upscale(cm, pool); + unlock_buffer_pool(pool); +} +#endif // CONFIG_FRAME_SUPERRES void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data, const uint8_t *data_end, const uint8_t **p_data_end) { @@ -5028,19 +5263,17 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data, pbi, init_read_bit_buffer(pbi, &rb, data, data_end, clear_data)); #if CONFIG_EXT_TILE - // If cm->tile_encoding_mode == TILE_NORMAL, the independent decoding of a - // single tile or a section of a frame is not allowed. - if (!cm->tile_encoding_mode && + // If cm->single_tile_decoding = 0, the independent decoding of a single tile + // or a section of a frame is not allowed. + if (!cm->single_tile_decoding && (pbi->dec_tile_row >= 0 || pbi->dec_tile_col >= 0)) { pbi->dec_tile_row = -1; pbi->dec_tile_col = -1; } #endif // CONFIG_EXT_TILE -#if CONFIG_TILE_GROUPS pbi->first_partition_size = first_partition_size; pbi->uncomp_hdr_size = aom_rb_bytes_read(&rb); -#endif new_fb = get_frame_new_buffer(cm); xd->cur_buf = new_fb; #if CONFIG_INTRABC @@ -5098,15 +5331,24 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data, #if CONFIG_TEMPMV_SIGNALING if (cm->use_prev_frame_mvs) { - assert(!cm->error_resilient_mode && cm->prev_frame && - cm->width == last_fb_ref_buf->buf->y_width && - cm->height == last_fb_ref_buf->buf->y_height && - !cm->prev_frame->intra_only); + assert(!cm->error_resilient_mode && cm->prev_frame); +#if CONFIG_FRAME_SUPERRES + assert(cm->width == cm->last_width && cm->height == cm->last_height); +#else + assert(cm->width == last_fb_ref_buf->buf->y_crop_width && + cm->height == last_fb_ref_buf->buf->y_crop_height); +#endif // CONFIG_FRAME_SUPERRES + assert(!cm->prev_frame->intra_only); } #else cm->use_prev_frame_mvs = !cm->error_resilient_mode && cm->prev_frame && +#if CONFIG_FRAME_SUPERRES + cm->width == cm->last_width && + cm->height == cm->last_height && +#else cm->width == cm->prev_frame->buf.y_crop_width && cm->height == cm->prev_frame->buf.y_crop_height && +#endif // CONFIG_FRAME_SUPERRES !cm->last_intra_only && cm->last_show_frame && (cm->last_frame_type != KEY_FRAME); #endif // CONFIG_TEMPMV_SIGNALING @@ -5150,6 +5392,8 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data, av1_frameworker_unlock_stats(worker); } + av1_setup_frame_boundary_info(cm); + if (pbi->max_threads > 1 && !CONFIG_CB4X4 && #if CONFIG_EXT_TILE pbi->dec_tile_col < 0 && // Decoding all columns @@ -5174,11 +5418,15 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data, } #if CONFIG_CDEF - if (!cm->skip_loop_filter) { + if (!cm->skip_loop_filter && !cm->all_lossless) { av1_cdef_frame(&pbi->cur_buf->buf, cm, &pbi->mb); } #endif // CONFIG_CDEF +#if CONFIG_FRAME_SUPERRES + superres_post_decode(pbi); +#endif // CONFIG_FRAME_SUPERRES + #if CONFIG_LOOP_RESTORATION if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || cm->rst_info[1].frame_restoration_type != RESTORE_NONE || @@ -5189,17 +5437,14 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data, if (!xd->corrupted) { if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { -#if CONFIG_EC_ADAPT FRAME_CONTEXT **tile_ctxs = aom_malloc(cm->tile_rows * cm->tile_cols * sizeof(&pbi->tile_data[0].tctx)); aom_cdf_prob **cdf_ptrs = aom_malloc(cm->tile_rows * cm->tile_cols * sizeof(&pbi->tile_data[0].tctx.partition_cdf[0][0])); make_update_tile_list_dec(pbi, cm->tile_rows, cm->tile_cols, tile_ctxs); -#endif av1_adapt_coef_probs(cm); av1_adapt_intra_frame_probs(cm); -#if CONFIG_EC_ADAPT av1_average_tile_coef_cdfs(pbi->common.fc, tile_ctxs, cdf_ptrs, cm->tile_rows * cm->tile_cols); av1_average_tile_intra_cdfs(pbi->common.fc, tile_ctxs, cdf_ptrs, @@ -5208,7 +5453,6 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data, av1_average_tile_pvq_cdfs(pbi->common.fc, tile_ctxs, cm->tile_rows * cm->tile_cols); #endif // CONFIG_PVQ -#endif // CONFIG_EC_ADAPT #if CONFIG_ADAPT_SCAN av1_adapt_scan_order(cm); #endif // CONFIG_ADAPT_SCAN @@ -5216,17 +5460,13 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data, if (!frame_is_intra_only(cm)) { av1_adapt_inter_frame_probs(cm); av1_adapt_mv_probs(cm, cm->allow_high_precision_mv); -#if CONFIG_EC_ADAPT av1_average_tile_inter_cdfs(&pbi->common, pbi->common.fc, tile_ctxs, cdf_ptrs, cm->tile_rows * cm->tile_cols); av1_average_tile_mv_cdfs(pbi->common.fc, tile_ctxs, cdf_ptrs, cm->tile_rows * cm->tile_cols); -#endif } -#if CONFIG_EC_ADAPT aom_free(tile_ctxs); aom_free(cdf_ptrs); -#endif } else { debug_check_frame_counts(cm); } diff --git a/third_party/aom/av1/decoder/decodemv.c b/third_party/aom/av1/decoder/decodemv.c index b3ce86e49..7c8544283 100644 --- a/third_party/aom/av1/decoder/decodemv.c +++ b/third_party/aom/av1/decoder/decodemv.c @@ -32,18 +32,8 @@ #include "aom_dsp/aom_dsp_common.h" #define ACCT_STR __func__ -#if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA || CONFIG_PALETTE -static INLINE int read_uniform(aom_reader *r, int n) { - const int l = get_unsigned_bits(n); - const int m = (1 << l) - n; - const int v = aom_read_literal(r, l - 1, ACCT_STR); - assert(l != 0); - if (v < m) - return v; - else - return (v << 1) - m + aom_read_literal(r, 1, ACCT_STR); -} -#endif // CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA || CONFIG_PALETTE + +#define DEC_MISMATCH_DEBUG 0 static PREDICTION_MODE read_intra_mode(aom_reader *r, aom_cdf_prob *cdf) { return (PREDICTION_MODE) @@ -61,12 +51,8 @@ static int read_delta_qindex(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r, const int read_delta_q_flag = (b_col == 0 && b_row == 0); int rem_bits, thr; int i, smallval; -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; (void)cm; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif if ((bsize != BLOCK_LARGEST || mbmi->skip == 0) && read_delta_q_flag) { abs = aom_read_symbol(r, ec_ctx->delta_q_cdf, DELTA_Q_PROBS + 1, ACCT_STR); @@ -104,12 +90,8 @@ static int read_delta_lflevel(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r, const int read_delta_lf_flag = (b_col == 0 && b_row == 0); int rem_bits, thr; int i, smallval; -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; (void)cm; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif if ((bsize != BLOCK_64X64 || mbmi->skip == 0) && read_delta_lf_flag) { abs = @@ -142,51 +124,56 @@ static PREDICTION_MODE read_intra_mode_y(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd, aom_reader *r, int size_group) { const PREDICTION_MODE y_mode = read_intra_mode(r, ec_ctx->y_mode_cdf[size_group]); +#if CONFIG_ENTROPY_STATS FRAME_COUNTS *counts = xd->counts; if (counts) ++counts->y_mode[size_group][y_mode]; +#else + /* TODO(negge): Can we remove this parameter? */ + (void)xd; +#endif // CONFIG_ENTROPY_STATS return y_mode; } -static PREDICTION_MODE read_intra_mode_uv(FRAME_CONTEXT *ec_ctx, - MACROBLOCKD *xd, aom_reader *r, - PREDICTION_MODE y_mode) { - const PREDICTION_MODE uv_mode = +static UV_PREDICTION_MODE read_intra_mode_uv(FRAME_CONTEXT *ec_ctx, + MACROBLOCKD *xd, aom_reader *r, + PREDICTION_MODE y_mode) { + const UV_PREDICTION_MODE uv_mode = read_intra_mode(r, ec_ctx->uv_mode_cdf[y_mode]); +#if CONFIG_ENTROPY_STATS FRAME_COUNTS *counts = xd->counts; if (counts) ++counts->uv_mode[y_mode][uv_mode]; +#else + /* TODO(negge): Can we remove this parameter? */ + (void)xd; +#endif // CONFIG_ENTROPY_STATS return uv_mode; } #if CONFIG_CFL -static int read_cfl_alphas(FRAME_CONTEXT *const ec_ctx, aom_reader *r, int skip, +static int read_cfl_alphas(FRAME_CONTEXT *const ec_ctx, aom_reader *r, CFL_SIGN_TYPE signs_out[CFL_PRED_PLANES]) { - if (skip) { - signs_out[CFL_PRED_U] = CFL_SIGN_POS; - signs_out[CFL_PRED_V] = CFL_SIGN_POS; - return 0; - } else { - const int ind = aom_read_symbol(r, ec_ctx->cfl_alpha_cdf, CFL_ALPHABET_SIZE, - "cfl:alpha"); - // Signs are only coded for nonzero values - // sign == 0 implies negative alpha - // sign == 1 implies positive alpha - signs_out[CFL_PRED_U] = cfl_alpha_codes[ind][CFL_PRED_U] - ? aom_read_bit(r, "cfl:sign") - : CFL_SIGN_POS; - signs_out[CFL_PRED_V] = cfl_alpha_codes[ind][CFL_PRED_V] - ? aom_read_bit(r, "cfl:sign") - : CFL_SIGN_POS; - - return ind; - } + const int ind = + aom_read_symbol(r, ec_ctx->cfl_alpha_cdf, CFL_ALPHABET_SIZE, "cfl:alpha"); + // Signs are only coded for nonzero values + // sign == 0 implies negative alpha + // sign == 1 implies positive alpha + signs_out[CFL_PRED_U] = cfl_alpha_codes[ind][CFL_PRED_U] + ? aom_read_bit(r, "cfl:sign") + : CFL_SIGN_POS; + signs_out[CFL_PRED_V] = cfl_alpha_codes[ind][CFL_PRED_V] + ? aom_read_bit(r, "cfl:sign") + : CFL_SIGN_POS; + + return ind; } #endif #if CONFIG_EXT_INTER && CONFIG_INTERINTRA static INTERINTRA_MODE read_interintra_mode(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r, int size_group) { - const INTERINTRA_MODE ii_mode = (INTERINTRA_MODE)aom_read_tree( - r, av1_interintra_mode_tree, cm->fc->interintra_mode_prob[size_group], + (void)cm; + const INTERINTRA_MODE ii_mode = (INTERINTRA_MODE)aom_read_symbol( + r, xd->tile_ctx->interintra_mode_cdf[size_group], INTERINTRA_MODES, ACCT_STR); FRAME_COUNTS *counts = xd->counts; if (counts) ++counts->interintra_mode[size_group][ii_mode]; @@ -198,9 +185,14 @@ static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd, aom_reader *r, int16_t ctx) { FRAME_COUNTS *counts = xd->counts; int16_t mode_ctx = ctx & NEWMV_CTX_MASK; - aom_prob mode_prob = ec_ctx->newmv_prob[mode_ctx]; + int is_newmv, is_zeromv, is_refmv; +#if CONFIG_NEW_MULTISYMBOL + is_newmv = aom_read_symbol(r, ec_ctx->newmv_cdf[mode_ctx], 2, ACCT_STR) == 0; +#else + is_newmv = aom_read(r, ec_ctx->newmv_prob[mode_ctx], ACCT_STR) == 0; +#endif - if (aom_read(r, mode_prob, ACCT_STR) == 0) { + if (is_newmv) { if (counts) ++counts->newmv_mode[mode_ctx][0]; return NEWMV; } @@ -210,8 +202,13 @@ static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd, mode_ctx = (ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK; - mode_prob = ec_ctx->zeromv_prob[mode_ctx]; - if (aom_read(r, mode_prob, ACCT_STR) == 0) { +#if CONFIG_NEW_MULTISYMBOL + is_zeromv = + aom_read_symbol(r, ec_ctx->zeromv_cdf[mode_ctx], 2, ACCT_STR) == 0; +#else + is_zeromv = aom_read(r, ec_ctx->zeromv_prob[mode_ctx], ACCT_STR) == 0; +#endif + if (is_zeromv) { if (counts) ++counts->zeromv_mode[mode_ctx][0]; return ZEROMV; } @@ -223,9 +220,13 @@ static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd, if (ctx & (1 << SKIP_NEARMV_OFFSET)) mode_ctx = 7; if (ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) mode_ctx = 8; - mode_prob = ec_ctx->refmv_prob[mode_ctx]; +#if CONFIG_NEW_MULTISYMBOL + is_refmv = aom_read_symbol(r, ec_ctx->refmv_cdf[mode_ctx], 2, ACCT_STR) == 0; +#else + is_refmv = aom_read(r, ec_ctx->refmv_prob[mode_ctx], ACCT_STR) == 0; +#endif - if (aom_read(r, mode_prob, ACCT_STR) == 0) { + if (is_refmv) { if (counts) ++counts->refmv_mode[mode_ctx][0]; return NEARESTMV; @@ -238,28 +239,33 @@ static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd, assert(0); } -static void read_drl_idx(const AV1_COMMON *cm, MACROBLOCKD *xd, +static void read_drl_idx(FRAME_CONTEXT *ec_ctx, MACROBLOCKD *xd, MB_MODE_INFO *mbmi, aom_reader *r) { uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); mbmi->ref_mv_idx = 0; #if CONFIG_EXT_INTER +#if CONFIG_COMPOUND_SINGLEREF + if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV || + mbmi->mode == SR_NEW_NEWMV) { +#else // !CONFIG_COMPOUND_SINGLEREF if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV) { -#else +#endif // CONFIG_COMPOUND_SINGLEREF +#else // !CONFIG_EXT_INTER if (mbmi->mode == NEWMV) { -#endif +#endif // CONFIG_EXT_INTER int idx; for (idx = 0; idx < 2; ++idx) { if (xd->ref_mv_count[ref_frame_type] > idx + 1) { uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx); - aom_prob drl_prob = cm->fc->drl_prob[drl_ctx]; - if (!aom_read(r, drl_prob, ACCT_STR)) { - mbmi->ref_mv_idx = idx; - if (xd->counts) ++xd->counts->drl_mode[drl_ctx][0]; - return; - } - mbmi->ref_mv_idx = idx + 1; - if (xd->counts) ++xd->counts->drl_mode[drl_ctx][1]; +#if CONFIG_NEW_MULTISYMBOL + int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR); +#else + int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR); +#endif + mbmi->ref_mv_idx = idx + drl_idx; + if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx]; + if (!drl_idx) return; } } } @@ -272,14 +278,14 @@ static void read_drl_idx(const AV1_COMMON *cm, MACROBLOCKD *xd, for (idx = 1; idx < 3; ++idx) { if (xd->ref_mv_count[ref_frame_type] > idx + 1) { uint8_t drl_ctx = av1_drl_ctx(xd->ref_mv_stack[ref_frame_type], idx); - aom_prob drl_prob = cm->fc->drl_prob[drl_ctx]; - if (!aom_read(r, drl_prob, ACCT_STR)) { - mbmi->ref_mv_idx = idx - 1; - if (xd->counts) ++xd->counts->drl_mode[drl_ctx][0]; - return; - } - mbmi->ref_mv_idx = idx; - if (xd->counts) ++xd->counts->drl_mode[drl_ctx][1]; +#if CONFIG_NEW_MULTISYMBOL + int drl_idx = aom_read_symbol(r, ec_ctx->drl_cdf[drl_ctx], 2, ACCT_STR); +#else + int drl_idx = aom_read(r, ec_ctx->drl_prob[drl_ctx], ACCT_STR); +#endif + mbmi->ref_mv_idx = idx + drl_idx - 1; + if (xd->counts) ++xd->counts->drl_mode[drl_ctx][drl_idx]; + if (!drl_idx) return; } } } @@ -289,39 +295,106 @@ static void read_drl_idx(const AV1_COMMON *cm, MACROBLOCKD *xd, static MOTION_MODE read_motion_mode(AV1_COMMON *cm, MACROBLOCKD *xd, MODE_INFO *mi, aom_reader *r) { MB_MODE_INFO *mbmi = &mi->mbmi; +#if CONFIG_NEW_MULTISYMBOL + (void)cm; +#endif + +#if CONFIG_NCOBMC_ADAPT_WEIGHT + const MOTION_MODE last_motion_mode_allowed = + motion_mode_allowed_wrapper(0, +#if CONFIG_GLOBAL_MOTION + 0, xd->global_motion, +#endif // CONFIG_GLOBAL_MOTION +#if CONFIG_WARPED_MOTION + xd, +#endif + mi); +#else const MOTION_MODE last_motion_mode_allowed = motion_mode_allowed( -#if CONFIG_GLOBAL_MOTION && SEPARATE_GLOBAL_MOTION +#if CONFIG_GLOBAL_MOTION 0, xd->global_motion, -#endif // CONFIG_GLOBAL_MOTION && SEPARATE_GLOBAL_MOTION +#endif // CONFIG_GLOBAL_MOTION +#if CONFIG_WARPED_MOTION + xd, +#endif mi); +#endif // CONFIG_NCOBMC_ADAPT_WEIGHT int motion_mode; FRAME_COUNTS *counts = xd->counts; if (last_motion_mode_allowed == SIMPLE_TRANSLATION) return SIMPLE_TRANSLATION; #if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION if (last_motion_mode_allowed == OBMC_CAUSAL) { +#if CONFIG_NEW_MULTISYMBOL + motion_mode = + aom_read_symbol(r, xd->tile_ctx->obmc_cdf[mbmi->sb_type], 2, ACCT_STR); +#else motion_mode = aom_read(r, cm->fc->obmc_prob[mbmi->sb_type], ACCT_STR); +#endif if (counts) ++counts->obmc[mbmi->sb_type][motion_mode]; return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode); } else { #endif // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION motion_mode = - aom_read_tree(r, av1_motion_mode_tree, - cm->fc->motion_mode_prob[mbmi->sb_type], ACCT_STR); + aom_read_symbol(r, xd->tile_ctx->motion_mode_cdf[mbmi->sb_type], + MOTION_MODES, ACCT_STR); if (counts) ++counts->motion_mode[mbmi->sb_type][motion_mode]; return (MOTION_MODE)(SIMPLE_TRANSLATION + motion_mode); #if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION } #endif // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION } + +#if CONFIG_NCOBMC_ADAPT_WEIGHT +static void read_ncobmc_mode(MACROBLOCKD *xd, MODE_INFO *mi, +#ifndef TRAINING_WEIGHTS + NCOBMC_MODE ncobmc_mode[2], +#else + NCOBMC_MODE ncobmc_mode[][4], +#endif + aom_reader *r) { + MB_MODE_INFO *mbmi = &mi->mbmi; + FRAME_COUNTS *counts = xd->counts; + ADAPT_OVERLAP_BLOCK ao_block = adapt_overlap_block_lookup[mbmi->sb_type]; + if (mbmi->motion_mode != NCOBMC_ADAPT_WEIGHT) return; + +#ifndef TRAINING_WEIGHTS + ncobmc_mode[0] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block], + MAX_NCOBMC_MODES, ACCT_STR); + if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[0]]; + + if (mi_size_wide[mbmi->sb_type] != mi_size_high[mbmi->sb_type]) { + ncobmc_mode[1] = aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block], + MAX_NCOBMC_MODES, ACCT_STR); + if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[1]]; + } +#else + int i; + for (i = 0; i < 4; ++i) { + ncobmc_mode[0][i] = aom_read_symbol( + r, xd->tile_ctx->ncobmc_mode_cdf[ao_block], MAX_NCOBMC_MODES, ACCT_STR); + if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[0][i]]; + } + if (mi_size_wide[mbmi->sb_type] != mi_size_high[mbmi->sb_type]) { + for (i = 0; i < 4; ++i) { + ncobmc_mode[1][i] = + aom_read_symbol(r, xd->tile_ctx->ncobmc_mode_cdf[ao_block], + MAX_NCOBMC_MODES, ACCT_STR); + if (counts) ++counts->ncobmc_mode[ao_block][ncobmc_mode[1][i]]; + } + } +#endif +} +#endif #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION #if CONFIG_EXT_INTER static PREDICTION_MODE read_inter_compound_mode(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r, int16_t ctx) { + (void)cm; const int mode = - aom_read_tree(r, av1_inter_compound_mode_tree, - cm->fc->inter_compound_mode_probs[ctx], ACCT_STR); + aom_read_symbol(r, xd->tile_ctx->inter_compound_mode_cdf[ctx], + INTER_COMPOUND_MODES, ACCT_STR); FRAME_COUNTS *counts = xd->counts; if (counts) ++counts->inter_compound_mode[ctx][mode]; @@ -329,6 +402,22 @@ static PREDICTION_MODE read_inter_compound_mode(AV1_COMMON *cm, MACROBLOCKD *xd, assert(is_inter_compound_mode(NEAREST_NEARESTMV + mode)); return NEAREST_NEARESTMV + mode; } + +#if CONFIG_COMPOUND_SINGLEREF +static PREDICTION_MODE read_inter_singleref_comp_mode(MACROBLOCKD *xd, + aom_reader *r, + int16_t ctx) { + const int mode = + aom_read_symbol(r, xd->tile_ctx->inter_singleref_comp_mode_cdf[ctx], + INTER_SINGLEREF_COMP_MODES, ACCT_STR); + FRAME_COUNTS *counts = xd->counts; + + if (counts) ++counts->inter_singleref_comp_mode[ctx][mode]; + + assert(is_inter_singleref_comp_mode(SR_NEAREST_NEARMV + mode)); + return SR_NEAREST_NEARMV + mode; +} +#endif // CONFIG_COMPOUND_SINGLEREF #endif // CONFIG_EXT_INTER static int read_segment_id(aom_reader *r, struct segmentation_probs *segp) { @@ -340,6 +429,10 @@ static void read_tx_size_vartx(AV1_COMMON *cm, MACROBLOCKD *xd, MB_MODE_INFO *mbmi, FRAME_COUNTS *counts, TX_SIZE tx_size, int depth, int blk_row, int blk_col, aom_reader *r) { +#if CONFIG_NEW_MULTISYMBOL + FRAME_CONTEXT *ec_ctx = xd->tile_ctx; + (void)cm; +#endif int is_split = 0; const int tx_row = blk_row >> 1; const int tx_col = blk_col >> 1; @@ -367,7 +460,11 @@ static void read_tx_size_vartx(AV1_COMMON *cm, MACROBLOCKD *xd, return; } +#if CONFIG_NEW_MULTISYMBOL + is_split = aom_read_symbol(r, ec_ctx->txfm_partition_cdf[ctx], 2, ACCT_STR); +#else is_split = aom_read(r, cm->fc->txfm_partition_prob[ctx], ACCT_STR); +#endif if (is_split) { const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; @@ -415,12 +512,8 @@ static TX_SIZE read_selected_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd, int tx_size_cat, aom_reader *r) { FRAME_COUNTS *counts = xd->counts; const int ctx = get_tx_size_context(xd); -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; (void)cm; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif const int depth = aom_read_symbol(r, ec_ctx->tx_size_cdf[tx_size_cat][ctx], tx_size_cat + 2, ACCT_STR); @@ -450,16 +543,22 @@ static TX_SIZE read_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd, int is_inter, #if CONFIG_RECT_TX && (CONFIG_EXT_TX || CONFIG_VAR_TX) if (coded_tx_size > max_txsize_lookup[bsize]) { assert(coded_tx_size == max_txsize_lookup[bsize] + 1); -#if CONFIG_EXT_TX && CONFIG_RECT_TX_EXT +#if CONFIG_RECT_TX_EXT if (is_quarter_tx_allowed(xd, &xd->mi[0]->mbmi, is_inter)) { - int quarter_tx = aom_read(r, cm->fc->quarter_tx_size_prob, ACCT_STR); - FRAME_COUNTS *counts = xd->counts; + int quarter_tx; + + if (quarter_txsize_lookup[bsize] != max_txsize_lookup[bsize]) { + quarter_tx = aom_read(r, cm->fc->quarter_tx_size_prob, ACCT_STR); + FRAME_COUNTS *counts = xd->counts; - if (counts) ++counts->quarter_tx_size[quarter_tx]; + if (counts) ++counts->quarter_tx_size[quarter_tx]; + } else { + quarter_tx = 1; + } return quarter_tx ? quarter_txsize_lookup[bsize] : max_txsize_rect_lookup[bsize]; } -#endif // CONFIG_EXT_TX && CONFIG_RECT_TX_EXT +#endif // CONFIG_RECT_TX_EXT return max_txsize_rect_lookup[bsize]; } @@ -509,7 +608,8 @@ static int read_intra_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd, aom_reader *r) { struct segmentation *const seg = &cm->seg; FRAME_COUNTS *counts = xd->counts; - struct segmentation_probs *const segp = &cm->fc->seg; + FRAME_CONTEXT *ec_ctx = xd->tile_ctx; + struct segmentation_probs *const segp = &ec_ctx->seg; int segment_id; if (!seg->enabled) return 0; // Default for disabled segmentation @@ -539,7 +639,9 @@ static int read_inter_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd, int mi_row, int mi_col, aom_reader *r) { struct segmentation *const seg = &cm->seg; FRAME_COUNTS *counts = xd->counts; - struct segmentation_probs *const segp = &cm->fc->seg; + FRAME_CONTEXT *ec_ctx = xd->tile_ctx; + struct segmentation_probs *const segp = &ec_ctx->seg; + MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; int predicted_segment_id, segment_id; const int mi_offset = mi_row * cm->mi_cols + mi_col; @@ -565,8 +667,13 @@ static int read_inter_segment_id(AV1_COMMON *const cm, MACROBLOCKD *const xd, if (seg->temporal_update) { const int ctx = av1_get_pred_context_seg_id(xd); +#if CONFIG_NEW_MULTISYMBOL + aom_cdf_prob *pred_cdf = segp->pred_cdf[ctx]; + mbmi->seg_id_predicted = aom_read_symbol(r, pred_cdf, 2, ACCT_STR); +#else const aom_prob pred_prob = segp->pred_probs[ctx]; mbmi->seg_id_predicted = aom_read(r, pred_prob, ACCT_STR); +#endif if (counts) ++counts->seg.pred[ctx][mbmi->seg_id_predicted]; if (mbmi->seg_id_predicted) { segment_id = predicted_segment_id; @@ -588,7 +695,12 @@ static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id, return 1; } else { const int ctx = av1_get_skip_context(xd); +#if CONFIG_NEW_MULTISYMBOL + FRAME_CONTEXT *ec_ctx = xd->tile_ctx; + const int skip = aom_read_symbol(r, ec_ctx->skip_cdfs[ctx], 2, ACCT_STR); +#else const int skip = aom_read(r, cm->fc->skip_probs[ctx], ACCT_STR); +#endif FRAME_COUNTS *counts = xd->counts; if (counts) ++counts->skip[ctx][skip]; return skip; @@ -690,61 +802,54 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd, const MODE_INFO *const above_mi = xd->above_mi; const MODE_INFO *const left_mi = xd->left_mi; const BLOCK_SIZE bsize = mbmi->sb_type; - int n; PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info; if (mbmi->mode == DC_PRED) { int palette_y_mode_ctx = 0; - if (above_mi) + if (above_mi) { palette_y_mode_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0); - if (left_mi) + } + if (left_mi) { palette_y_mode_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0); + } if (aom_read(r, av1_default_palette_y_mode_prob[bsize - BLOCK_8X8] [palette_y_mode_ctx], ACCT_STR)) { pmi->palette_size[0] = - aom_read_tree(r, av1_palette_size_tree, - av1_default_palette_y_size_prob[bsize - BLOCK_8X8], - ACCT_STR) + + aom_read_symbol(r, + xd->tile_ctx->palette_y_size_cdf[bsize - BLOCK_8X8], + PALETTE_SIZES, ACCT_STR) + 2; - n = pmi->palette_size[0]; #if CONFIG_PALETTE_DELTA_ENCODING read_palette_colors_y(xd, cm->bit_depth, pmi, r); #else - int i; - for (i = 0; i < n; ++i) + for (int i = 0; i < pmi->palette_size[0]; ++i) pmi->palette_colors[i] = aom_read_literal(r, cm->bit_depth, ACCT_STR); #endif // CONFIG_PALETTE_DELTA_ENCODING - xd->plane[0].color_index_map[0] = read_uniform(r, n); - assert(xd->plane[0].color_index_map[0] < n); } } - if (mbmi->uv_mode == DC_PRED) { + if (mbmi->uv_mode == UV_DC_PRED) { const int palette_uv_mode_ctx = (pmi->palette_size[0] > 0); if (aom_read(r, av1_default_palette_uv_mode_prob[palette_uv_mode_ctx], ACCT_STR)) { pmi->palette_size[1] = - aom_read_tree(r, av1_palette_size_tree, - av1_default_palette_uv_size_prob[bsize - BLOCK_8X8], - ACCT_STR) + + aom_read_symbol(r, + xd->tile_ctx->palette_uv_size_cdf[bsize - BLOCK_8X8], + PALETTE_SIZES, ACCT_STR) + 2; - n = pmi->palette_size[1]; #if CONFIG_PALETTE_DELTA_ENCODING read_palette_colors_uv(xd, cm->bit_depth, pmi, r); #else - int i; - for (i = 0; i < n; ++i) { + for (int i = 0; i < pmi->palette_size[1]; ++i) { pmi->palette_colors[PALETTE_MAX_SIZE + i] = aom_read_literal(r, cm->bit_depth, ACCT_STR); pmi->palette_colors[2 * PALETTE_MAX_SIZE + i] = aom_read_literal(r, cm->bit_depth, ACCT_STR); } #endif // CONFIG_PALETTE_DELTA_ENCODING - xd->plane[1].color_index_map[0] = read_uniform(r, n); - assert(xd->plane[1].color_index_map[0] < n); } } } @@ -769,7 +874,7 @@ static void read_filter_intra_mode_info(AV1_COMMON *const cm, aom_read(r, cm->fc->filter_intra_probs[0], ACCT_STR); if (filter_intra_mode_info->use_filter_intra_mode[0]) { filter_intra_mode_info->filter_intra_mode[0] = - read_uniform(r, FILTER_INTRA_MODES); + av1_read_uniform(r, FILTER_INTRA_MODES); } if (counts) { ++counts @@ -787,7 +892,7 @@ static void read_filter_intra_mode_info(AV1_COMMON *const cm, (void)mi_col; #endif // CONFIG_CB4X4 - if (mbmi->uv_mode == DC_PRED + if (mbmi->uv_mode == UV_DC_PRED #if CONFIG_PALETTE && mbmi->palette_mode_info.palette_size[1] == 0 #endif // CONFIG_PALETTE @@ -796,7 +901,7 @@ static void read_filter_intra_mode_info(AV1_COMMON *const cm, aom_read(r, cm->fc->filter_intra_probs[1], ACCT_STR); if (filter_intra_mode_info->use_filter_intra_mode[1]) { filter_intra_mode_info->filter_intra_mode[1] = - read_uniform(r, FILTER_INTRA_MODES); + av1_read_uniform(r, FILTER_INTRA_MODES); } if (counts) { ++counts @@ -812,21 +917,21 @@ static void read_intra_angle_info(AV1_COMMON *const cm, MACROBLOCKD *const xd, MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; const BLOCK_SIZE bsize = mbmi->sb_type; #if CONFIG_INTRA_INTERP -#if CONFIG_EC_ADAPT FRAME_CONTEXT *const ec_ctx = xd->tile_ctx; -#else - FRAME_CONTEXT *const ec_ctx = cm->fc; -#endif // CONFIG_EC_ADAPT const int ctx = av1_get_pred_context_intra_interp(xd); int p_angle; #endif // CONFIG_INTRA_INTERP (void)cm; - if (bsize < BLOCK_8X8) return; + + mbmi->angle_delta[0] = 0; + mbmi->angle_delta[1] = 0; + + if (!av1_use_angle_delta(bsize)) return; if (av1_is_directional_mode(mbmi->mode, bsize)) { mbmi->angle_delta[0] = - read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA; + av1_read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA; #if CONFIG_INTRA_INTERP p_angle = mode_to_angle_map[mbmi->mode] + mbmi->angle_delta[0] * ANGLE_STEP; if (av1_is_intra_filter_switchable(p_angle)) { @@ -840,9 +945,9 @@ static void read_intra_angle_info(AV1_COMMON *const cm, MACROBLOCKD *const xd, #endif // CONFIG_INTRA_INTERP } - if (av1_is_directional_mode(mbmi->uv_mode, bsize)) { + if (av1_is_directional_mode(get_uv_mode(mbmi->uv_mode), bsize)) { mbmi->angle_delta[1] = - read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA; + av1_read_uniform(r, 2 * MAX_ANGLE_DELTA + 1) - MAX_ANGLE_DELTA; } } #endif // CONFIG_EXT_INTRA @@ -852,28 +957,28 @@ void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd, int supertx_enabled, #endif #if CONFIG_TXK_SEL - int block, int plane, + int blk_row, int blk_col, int block, int plane, + TX_SIZE tx_size, #endif aom_reader *r) { MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; const int inter_block = is_inter_block(mbmi); +#if !CONFIG_TXK_SEL #if CONFIG_VAR_TX const TX_SIZE tx_size = inter_block ? mbmi->min_tx_size : mbmi->tx_size; #else const TX_SIZE tx_size = mbmi->tx_size; #endif -#if CONFIG_EC_ADAPT +#endif // !CONFIG_TXK_SEL FRAME_CONTEXT *ec_ctx = xd->tile_ctx; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif #if !CONFIG_TXK_SEL TX_TYPE *tx_type = &mbmi->tx_type; #else // only y plane's tx_type is transmitted if (plane > 0) return; - TX_TYPE *tx_type = &mbmi->txk_type[block]; + (void)block; + TX_TYPE *tx_type = &mbmi->txk_type[(blk_row << 4) + blk_col]; #endif if (!FIXED_TX_TYPE) { @@ -890,23 +995,22 @@ void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd, !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { const int eset = get_ext_tx_set(tx_size, mbmi->sb_type, inter_block, cm->reduced_tx_set_used); + // eset == 0 should correspond to a set with only DCT_DCT and + // there is no need to read the tx_type + assert(eset != 0); FRAME_COUNTS *counts = xd->counts; if (inter_block) { - if (eset > 0) { - *tx_type = av1_ext_tx_inter_inv[eset][aom_read_symbol( - r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size], - ext_tx_cnt_inter[eset], ACCT_STR)]; - if (counts) ++counts->inter_ext_tx[eset][square_tx_size][*tx_type]; - } + *tx_type = av1_ext_tx_inter_inv[eset][aom_read_symbol( + r, ec_ctx->inter_ext_tx_cdf[eset][square_tx_size], + ext_tx_cnt_inter[eset], ACCT_STR)]; + if (counts) ++counts->inter_ext_tx[eset][square_tx_size][*tx_type]; } else if (ALLOW_INTRA_EXT_TX) { - if (eset > 0) { - *tx_type = av1_ext_tx_intra_inv[eset][aom_read_symbol( - r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][mbmi->mode], - ext_tx_cnt_intra[eset], ACCT_STR)]; - if (counts) - ++counts->intra_ext_tx[eset][square_tx_size][mbmi->mode][*tx_type]; - } + *tx_type = av1_ext_tx_intra_inv[eset][aom_read_symbol( + r, ec_ctx->intra_ext_tx_cdf[eset][square_tx_size][mbmi->mode], + ext_tx_cnt_intra[eset], ACCT_STR)]; + if (counts) + ++counts->intra_ext_tx[eset][square_tx_size][mbmi->mode][*tx_type]; } } else { *tx_type = DCT_DCT; @@ -939,27 +1043,27 @@ void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd, } #endif // CONFIG_EXT_TX } +#if FIXED_TX_TYPE + assert(mbmi->tx_type == DCT_DCT); +#endif } #if CONFIG_INTRABC static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref, nmv_context *ctx, nmv_context_counts *counts, - int allow_hp); + MvSubpelPrecision precision); static INLINE int is_mv_valid(const MV *mv); static INLINE int assign_dv(AV1_COMMON *cm, MACROBLOCKD *xd, int_mv *mv, const int_mv *ref_mv, int mi_row, int mi_col, BLOCK_SIZE bsize, aom_reader *r) { -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; (void)cm; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif FRAME_COUNTS *counts = xd->counts; nmv_context_counts *const dv_counts = counts ? &counts->dv : NULL; - read_mv(r, &mv->as_mv, &ref_mv->as_mv, &ec_ctx->ndvc, dv_counts, 0); + read_mv(r, &mv->as_mv, &ref_mv->as_mv, &ec_ctx->ndvc, dv_counts, + MV_SUBPEL_NONE); int valid = is_mv_valid(&mv->as_mv) && is_dv_valid(mv->as_mv, &xd->tile, mi_row, mi_col, bsize); return valid; @@ -982,11 +1086,7 @@ static void read_intra_frame_mode_info(AV1_COMMON *const cm, // TODO(slavarnway): move x_mis, y_mis into xd ????? const int x_mis = AOMMIN(cm->mi_cols - mi_col, bw); const int y_mis = AOMMIN(cm->mi_rows - mi_row, bh); -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif mbmi->segment_id = read_intra_segment_id(cm, xd, mi_offset, x_mis, y_mis, r); mbmi->skip = read_skip(cm, xd, mbmi->segment_id, r); @@ -1013,13 +1113,13 @@ static void read_intra_frame_mode_info(AV1_COMMON *const cm, mbmi->ref_frame[0] = INTRA_FRAME; mbmi->ref_frame[1] = NONE_FRAME; - mbmi->tx_size = read_tx_size(cm, xd, 0, 1, r); #if CONFIG_INTRABC if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools) { mbmi->use_intrabc = aom_read(r, ec_ctx->intrabc_prob, ACCT_STR); if (mbmi->use_intrabc) { - mbmi->mode = mbmi->uv_mode = DC_PRED; + mbmi->tx_size = read_tx_size(cm, xd, 1, !mbmi->skip, r); + mbmi->mode = mbmi->uv_mode = UV_DC_PRED; #if CONFIG_DUAL_FILTER for (int idx = 0; idx < 4; ++idx) mbmi->interp_filter[idx] = BILINEAR; #else @@ -1066,6 +1166,8 @@ static void read_intra_frame_mode_info(AV1_COMMON *const cm, } #endif // CONFIG_INTRABC + mbmi->tx_size = read_tx_size(cm, xd, 0, 1, r); + #if CONFIG_CB4X4 (void)i; mbmi->mode = @@ -1106,13 +1208,15 @@ static void read_intra_frame_mode_info(AV1_COMMON *const cm, #if CONFIG_CFL // TODO(ltrudeau) support PALETTE - if (mbmi->uv_mode == DC_PRED) { - mbmi->cfl_alpha_idx = - read_cfl_alphas(ec_ctx, r, mbmi->skip, mbmi->cfl_alpha_signs); + if (mbmi->uv_mode == UV_DC_PRED) { + mbmi->cfl_alpha_idx = read_cfl_alphas(ec_ctx, r, mbmi->cfl_alpha_signs); } #endif // CONFIG_CFL #if CONFIG_CB4X4 + } else { + // Avoid decoding angle_info if there is is no chroma prediction + mbmi->uv_mode = UV_DC_PRED; } #endif @@ -1141,16 +1245,28 @@ static void read_intra_frame_mode_info(AV1_COMMON *const cm, #endif // !CONFIG_TXK_SEL } -static int read_mv_component(aom_reader *r, nmv_component *mvcomp, int usehp) { +static int read_mv_component(aom_reader *r, nmv_component *mvcomp, +#if CONFIG_INTRABC + int use_subpel, +#endif // CONFIG_INTRABC + int usehp) { int mag, d, fr, hp; +#if CONFIG_NEW_MULTISYMBOL + const int sign = aom_read_bit(r, ACCT_STR); +#else const int sign = aom_read(r, mvcomp->sign, ACCT_STR); +#endif const int mv_class = aom_read_symbol(r, mvcomp->class_cdf, MV_CLASSES, ACCT_STR); const int class0 = mv_class == MV_CLASS_0; // Integer part if (class0) { +#if CONFIG_NEW_MULTISYMBOL + d = aom_read_symbol(r, mvcomp->class0_cdf, CLASS0_SIZE, ACCT_STR); +#else d = aom_read(r, mvcomp->class0[0], ACCT_STR); +#endif mag = 0; } else { int i; @@ -1161,13 +1277,29 @@ static int read_mv_component(aom_reader *r, nmv_component *mvcomp, int usehp) { mag = CLASS0_SIZE << (mv_class + 2); } - // Fractional part - fr = aom_read_symbol(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf, - MV_FP_SIZE, ACCT_STR); - - // High precision part (if hp is not used, the default value of the hp is 1) +#if CONFIG_INTRABC + if (use_subpel) { +#endif // CONFIG_INTRABC + // Fractional part + fr = aom_read_symbol(r, class0 ? mvcomp->class0_fp_cdf[d] : mvcomp->fp_cdf, + MV_FP_SIZE, ACCT_STR); + +// High precision part (if hp is not used, the default value of the hp is 1) +#if CONFIG_NEW_MULTISYMBOL + hp = usehp ? aom_read_symbol( + r, class0 ? mvcomp->class0_hp_cdf : mvcomp->hp_cdf, 2, + ACCT_STR) + : 1; +#else hp = usehp ? aom_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp, ACCT_STR) : 1; +#endif +#if CONFIG_INTRABC + } else { + fr = 3; + hp = 1; + } +#endif // CONFIG_INTRABC // Result mag += ((d << 3) | (fr << 1) | hp) + 1; @@ -1176,19 +1308,27 @@ static int read_mv_component(aom_reader *r, nmv_component *mvcomp, int usehp) { static INLINE void read_mv(aom_reader *r, MV *mv, const MV *ref, nmv_context *ctx, nmv_context_counts *counts, - int allow_hp) { + MvSubpelPrecision precision) { MV_JOINT_TYPE joint_type; MV diff = { 0, 0 }; joint_type = (MV_JOINT_TYPE)aom_read_symbol(r, ctx->joint_cdf, MV_JOINTS, ACCT_STR); if (mv_joint_vertical(joint_type)) - diff.row = read_mv_component(r, &ctx->comps[0], allow_hp); + diff.row = read_mv_component(r, &ctx->comps[0], +#if CONFIG_INTRABC + precision > MV_SUBPEL_NONE, +#endif // CONFIG_INTRABC + precision > MV_SUBPEL_LOW_PRECISION); if (mv_joint_horizontal(joint_type)) - diff.col = read_mv_component(r, &ctx->comps[1], allow_hp); + diff.col = read_mv_component(r, &ctx->comps[1], +#if CONFIG_INTRABC + precision > MV_SUBPEL_NONE, +#endif // CONFIG_INTRABC + precision > MV_SUBPEL_LOW_PRECISION); - av1_inc_mv(&diff, counts, allow_hp); + av1_inc_mv(&diff, counts, precision); mv->row = ref->row + diff.row; mv->col = ref->col + diff.col; @@ -1202,8 +1342,13 @@ static REFERENCE_MODE read_block_reference_mode(AV1_COMMON *cm, #endif if (cm->reference_mode == REFERENCE_MODE_SELECT) { const int ctx = av1_get_reference_mode_context(cm, xd); +#if CONFIG_NEW_MULTISYMBOL + const REFERENCE_MODE mode = (REFERENCE_MODE)aom_read_symbol( + r, xd->tile_ctx->comp_inter_cdf[ctx], 2, ACCT_STR); +#else const REFERENCE_MODE mode = (REFERENCE_MODE)aom_read(r, cm->fc->comp_inter_prob[ctx], ACCT_STR); +#endif FRAME_COUNTS *counts = xd->counts; if (counts) ++counts->comp_inter[ctx][mode]; return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE @@ -1212,11 +1357,50 @@ static REFERENCE_MODE read_block_reference_mode(AV1_COMMON *cm, } } +#if CONFIG_NEW_MULTISYMBOL +#define READ_REF_BIT(pname) \ + aom_read_symbol(r, av1_get_pred_cdf_##pname(cm, xd), 2, ACCT_STR) +#else +#define READ_REF_BIT(pname) \ + aom_read(r, av1_get_pred_prob_##pname(cm, xd), ACCT_STR) +#endif + +#if CONFIG_EXT_COMP_REFS +static REFERENCE_MODE read_comp_reference_type(AV1_COMMON *cm, + const MACROBLOCKD *xd, + aom_reader *r) { + const int ctx = av1_get_comp_reference_type_context(xd); +#if USE_UNI_COMP_REFS + COMP_REFERENCE_TYPE comp_ref_type; +#if CONFIG_VAR_REFS + if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm)) + if (L_AND_L2(cm) || L_AND_L3(cm) || L_AND_G(cm) || BWD_AND_ALT(cm)) +#endif // CONFIG_VAR_REFS + comp_ref_type = (COMP_REFERENCE_TYPE)aom_read( + r, cm->fc->comp_ref_type_prob[ctx], ACCT_STR); +#if CONFIG_VAR_REFS + else + comp_ref_type = BIDIR_COMP_REFERENCE; + else + comp_ref_type = UNIDIR_COMP_REFERENCE; +#endif // CONFIG_VAR_REFS +#else // !USE_UNI_COMP_REFS + // TODO(zoeliu): Temporarily turn off uni-directional comp refs + const COMP_REFERENCE_TYPE comp_ref_type = BIDIR_COMP_REFERENCE; +#endif // USE_UNI_COMP_REFS + FRAME_COUNTS *counts = xd->counts; + if (counts) ++counts->comp_ref_type[ctx][comp_ref_type]; + return comp_ref_type; // UNIDIR_COMP_REFERENCE or BIDIR_COMP_REFERENCE +} +#endif // CONFIG_EXT_COMP_REFS + // Read the referncence frame static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd, aom_reader *r, int segment_id, MV_REFERENCE_FRAME ref_frame[2]) { +#if CONFIG_EXT_COMP_REFS FRAME_CONTEXT *const fc = cm->fc; +#endif FRAME_COUNTS *counts = xd->counts; if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) { @@ -1227,81 +1411,279 @@ static void read_ref_frames(AV1_COMMON *const cm, MACROBLOCKD *const xd, const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r); // FIXME(rbultje) I'm pretty sure this breaks segmentation ref frame coding if (mode == COMPOUND_REFERENCE) { -#if CONFIG_ONE_SIDED_COMPOUND // Normative in decoder (for low delay) +#if CONFIG_EXT_COMP_REFS + const COMP_REFERENCE_TYPE comp_ref_type = + read_comp_reference_type(cm, xd, r); + +#if !USE_UNI_COMP_REFS + // TODO(zoeliu): Temporarily turn off uni-directional comp refs + assert(comp_ref_type == BIDIR_COMP_REFERENCE); +#endif // !USE_UNI_COMP_REFS + + if (comp_ref_type == UNIDIR_COMP_REFERENCE) { + const int ctx = av1_get_pred_context_uni_comp_ref_p(xd); + int bit; +#if CONFIG_VAR_REFS + if ((L_AND_L2(cm) || L_AND_L3(cm) || L_AND_G(cm)) && BWD_AND_ALT(cm)) +#endif // CONFIG_VAR_REFS + bit = aom_read(r, fc->uni_comp_ref_prob[ctx][0], ACCT_STR); +#if CONFIG_VAR_REFS + else + bit = BWD_AND_ALT(cm); +#endif // CONFIG_VAR_REFS + if (counts) ++counts->uni_comp_ref[ctx][0][bit]; + + if (bit) { + ref_frame[0] = BWDREF_FRAME; + ref_frame[1] = ALTREF_FRAME; + } else { + const int ctx1 = av1_get_pred_context_uni_comp_ref_p1(xd); + int bit1; +#if CONFIG_VAR_REFS + if (L_AND_L2(cm) && (L_AND_L3(cm) || L_AND_G(cm))) +#endif // CONFIG_VAR_REFS + bit1 = aom_read(r, fc->uni_comp_ref_prob[ctx1][1], ACCT_STR); +#if CONFIG_VAR_REFS + else + bit1 = L_AND_L3(cm) || L_AND_G(cm); +#endif // CONFIG_VAR_REFS + if (counts) ++counts->uni_comp_ref[ctx1][1][bit1]; + + if (bit1) { + const int ctx2 = av1_get_pred_context_uni_comp_ref_p2(xd); + int bit2; +#if CONFIG_VAR_REFS + if (L_AND_L3(cm) && L_AND_G(cm)) +#endif // CONFIG_VAR_REFS + bit2 = aom_read(r, fc->uni_comp_ref_prob[ctx2][2], ACCT_STR); +#if CONFIG_VAR_REFS + else + bit2 = L_AND_G(cm); +#endif // CONFIG_VAR_REFS + if (counts) ++counts->uni_comp_ref[ctx2][2][bit2]; + + if (bit2) { + ref_frame[0] = LAST_FRAME; + ref_frame[1] = GOLDEN_FRAME; + } else { + ref_frame[0] = LAST_FRAME; + ref_frame[1] = LAST3_FRAME; + } + } else { + ref_frame[0] = LAST_FRAME; + ref_frame[1] = LAST2_FRAME; + } + } + + return; + } + + assert(comp_ref_type == BIDIR_COMP_REFERENCE); +#endif // CONFIG_EXT_COMP_REFS + +// Normative in decoder (for low delay) +#if CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS const int idx = 1; -#else +#else // !(CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS) #if CONFIG_EXT_REFS const int idx = cm->ref_frame_sign_bias[cm->comp_bwd_ref[0]]; -#else +#else // !CONFIG_EXT_REFS const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref]; #endif // CONFIG_EXT_REFS -#endif - const int ctx = av1_get_pred_context_comp_ref_p(cm, xd); +#endif // CONFIG_ONE_SIDED_COMPOUND || CONFIG_EXT_COMP_REFS - const int bit = aom_read(r, fc->comp_ref_prob[ctx][0], ACCT_STR); + const int ctx = av1_get_pred_context_comp_ref_p(cm, xd); +#if CONFIG_VAR_REFS + int bit; + // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree + if (L_OR_L2(cm) && L3_OR_G(cm)) + bit = READ_REF_BIT(comp_ref_p); + else + bit = L3_OR_G(cm); +#else // !CONFIG_VAR_REFS + const int bit = READ_REF_BIT(comp_ref_p); +#endif // CONFIG_VAR_REFS if (counts) ++counts->comp_ref[ctx][0][bit]; #if CONFIG_EXT_REFS // Decode forward references. if (!bit) { const int ctx1 = av1_get_pred_context_comp_ref_p1(cm, xd); - const int bit1 = aom_read(r, fc->comp_ref_prob[ctx1][1], ACCT_STR); +#if CONFIG_VAR_REFS + int bit1; + // Test need to explicitly code (L) vs (L2) branch node in tree + if (L_AND_L2(cm)) + bit1 = READ_REF_BIT(comp_ref_p1); + else + bit1 = LAST_IS_VALID(cm); +#else // !CONFIG_VAR_REFS + const int bit1 = READ_REF_BIT(comp_ref_p1); +#endif // CONFIG_VAR_REFS if (counts) ++counts->comp_ref[ctx1][1][bit1]; ref_frame[!idx] = cm->comp_fwd_ref[bit1 ? 0 : 1]; } else { const int ctx2 = av1_get_pred_context_comp_ref_p2(cm, xd); - const int bit2 = aom_read(r, fc->comp_ref_prob[ctx2][2], ACCT_STR); +#if CONFIG_VAR_REFS + int bit2; + // Test need to explicitly code (L3) vs (G) branch node in tree + if (L3_AND_G(cm)) + bit2 = READ_REF_BIT(comp_ref_p2); + else + bit2 = GOLDEN_IS_VALID(cm); +#else // !CONFIG_VAR_REFS + const int bit2 = READ_REF_BIT(comp_ref_p2); +#endif // CONFIG_VAR_REFS if (counts) ++counts->comp_ref[ctx2][2][bit2]; ref_frame[!idx] = cm->comp_fwd_ref[bit2 ? 3 : 2]; } // Decode backward references. - { - const int ctx_bwd = av1_get_pred_context_comp_bwdref_p(cm, xd); - const int bit_bwd = - aom_read(r, fc->comp_bwdref_prob[ctx_bwd][0], ACCT_STR); - if (counts) ++counts->comp_bwdref[ctx_bwd][0][bit_bwd]; - ref_frame[idx] = cm->comp_bwd_ref[bit_bwd]; + const int ctx_bwd = av1_get_pred_context_comp_bwdref_p(cm, xd); +#if CONFIG_VAR_REFS + int bit_bwd; +// Test need to explicitly code (BWD/ALT2) vs (ALT) branch node in tree +#if CONFIG_ALTREF2 + const int bit_bwd_uncertain = BWD_OR_ALT2(cm) && ALTREF_IS_VALID(cm); +#else // !CONFIG_ALTREF2 + const int bit_bwd_uncertain = BWD_AND_ALT(cm); +#endif // CONFIG_ALTREF2 + if (bit_bwd_uncertain) + bit_bwd = READ_REF_BIT(comp_bwdref_p); + else + bit_bwd = ALTREF_IS_VALID(cm); +#else // !CONFIG_VAR_REFS + const int bit_bwd = READ_REF_BIT(comp_bwdref_p); +#endif // CONFIG_VAR_REFS + if (counts) ++counts->comp_bwdref[ctx_bwd][0][bit_bwd]; +#if CONFIG_ALTREF2 + if (!bit_bwd) { + const int ctx1_bwd = av1_get_pred_context_comp_bwdref_p1(cm, xd); +#if CONFIG_VAR_REFS + int bit1_bwd; + if (BWD_AND_ALT2(cm)) + bit1_bwd = READ_REF_BIT(comp_bwdref_p1); + else + bit1_bwd = ALTREF2_IS_VALID(cm); +#else // !CONFIG_VAR_REFS + const int bit1_bwd = READ_REF_BIT(comp_bwdref_p1); +#endif // CONFIG_VAR_REFS + if (counts) ++counts->comp_bwdref[ctx1_bwd][1][bit1_bwd]; + ref_frame[idx] = cm->comp_bwd_ref[bit1_bwd]; + } else { + ref_frame[idx] = cm->comp_bwd_ref[2]; } -#else +#else // !CONFIG_ALTREF2 + ref_frame[idx] = cm->comp_bwd_ref[bit_bwd]; +#endif // CONFIG_ALTREF2 +#else // !CONFIG_EXT_REFS ref_frame[!idx] = cm->comp_var_ref[bit]; ref_frame[idx] = cm->comp_fixed_ref; #endif // CONFIG_EXT_REFS } else if (mode == SINGLE_REFERENCE) { #if CONFIG_EXT_REFS const int ctx0 = av1_get_pred_context_single_ref_p1(xd); - const int bit0 = aom_read(r, fc->single_ref_prob[ctx0][0], ACCT_STR); +#if CONFIG_VAR_REFS + int bit0; + // Test need to explicitly code (L,L2,L3,G) vs (BWD,ALT) branch node in + // tree + if ((L_OR_L2(cm) || L3_OR_G(cm)) && BWD_OR_ALT(cm)) + bit0 = READ_REF_BIT(single_ref_p1); + else + bit0 = BWD_OR_ALT(cm); +#else // !CONFIG_VAR_REFS + const int bit0 = READ_REF_BIT(single_ref_p1); +#endif // CONFIG_VAR_REFS if (counts) ++counts->single_ref[ctx0][0][bit0]; if (bit0) { const int ctx1 = av1_get_pred_context_single_ref_p2(xd); - const int bit1 = aom_read(r, fc->single_ref_prob[ctx1][1], ACCT_STR); +#if CONFIG_VAR_REFS + int bit1; +// Test need to explicitly code (BWD/ALT2) vs (ALT) branch node in tree +#if CONFIG_ALTREF2 + const int bit1_uncertain = BWD_OR_ALT2(cm) && ALTREF_IS_VALID(cm); +#else // !CONFIG_ALTREF2 + const int bit1_uncertain = BWD_AND_ALT(cm); +#endif // CONFIG_ALTREF2 + if (bit1_uncertain) + bit1 = READ_REF_BIT(single_ref_p2); + else + bit1 = ALTREF_IS_VALID(cm); +#else // !CONFIG_VAR_REFS + const int bit1 = READ_REF_BIT(single_ref_p2); +#endif // CONFIG_VAR_REFS if (counts) ++counts->single_ref[ctx1][1][bit1]; +#if CONFIG_ALTREF2 + if (!bit1) { + const int ctx5 = av1_get_pred_context_single_ref_p6(xd); +#if CONFIG_VAR_REFS + int bit5; + if (BWD_AND_ALT2(cm)) + bit5 = READ_REF_BIT(single_ref_p6); + else + bit5 = ALTREF2_IS_VALID(cm); +#else // !CONFIG_VAR_REFS + const int bit5 = READ_REF_BIT(single_ref_p6); +#endif // CONFIG_VAR_REFS + if (counts) ++counts->single_ref[ctx5][5][bit5]; + ref_frame[0] = bit5 ? ALTREF2_FRAME : BWDREF_FRAME; + } else { + ref_frame[0] = ALTREF_FRAME; + } +#else // !CONFIG_ALTREF2 ref_frame[0] = bit1 ? ALTREF_FRAME : BWDREF_FRAME; +#endif // CONFIG_ALTREF2 } else { const int ctx2 = av1_get_pred_context_single_ref_p3(xd); - const int bit2 = aom_read(r, fc->single_ref_prob[ctx2][2], ACCT_STR); +#if CONFIG_VAR_REFS + int bit2; + // Test need to explicitly code (L,L2) vs (L3,G) branch node in tree + if (L_OR_L2(cm) && L3_OR_G(cm)) + bit2 = READ_REF_BIT(single_ref_p3); + else + bit2 = L3_OR_G(cm); +#else // !CONFIG_VAR_REFS + const int bit2 = READ_REF_BIT(single_ref_p3); +#endif // CONFIG_VAR_REFS if (counts) ++counts->single_ref[ctx2][2][bit2]; if (bit2) { const int ctx4 = av1_get_pred_context_single_ref_p5(xd); - const int bit4 = aom_read(r, fc->single_ref_prob[ctx4][4], ACCT_STR); +#if CONFIG_VAR_REFS + int bit4; + // Test need to explicitly code (L3) vs (G) branch node in tree + if (L3_AND_G(cm)) + bit4 = READ_REF_BIT(single_ref_p5); + else + bit4 = GOLDEN_IS_VALID(cm); +#else // !CONFIG_VAR_REFS + const int bit4 = READ_REF_BIT(single_ref_p5); +#endif // CONFIG_VAR_REFS if (counts) ++counts->single_ref[ctx4][4][bit4]; ref_frame[0] = bit4 ? GOLDEN_FRAME : LAST3_FRAME; } else { const int ctx3 = av1_get_pred_context_single_ref_p4(xd); - const int bit3 = aom_read(r, fc->single_ref_prob[ctx3][3], ACCT_STR); +#if CONFIG_VAR_REFS + int bit3; + // Test need to explicitly code (L) vs (L2) branch node in tree + if (L_AND_L2(cm)) + bit3 = READ_REF_BIT(single_ref_p4); + else + bit3 = LAST2_IS_VALID(cm); +#else // !CONFIG_VAR_REFS + const int bit3 = READ_REF_BIT(single_ref_p4); +#endif // CONFIG_VAR_REFS if (counts) ++counts->single_ref[ctx3][3][bit3]; ref_frame[0] = bit3 ? LAST2_FRAME : LAST_FRAME; } } -#else +#else // !CONFIG_EXT_REFS const int ctx0 = av1_get_pred_context_single_ref_p1(xd); - const int bit0 = aom_read(r, fc->single_ref_prob[ctx0][0], ACCT_STR); + const int bit0 = READ_REF_BIT(single_ref_p1); if (counts) ++counts->single_ref[ctx0][0][bit0]; if (bit0) { const int ctx1 = av1_get_pred_context_single_ref_p2(xd); - const int bit1 = aom_read(r, fc->single_ref_prob[ctx1][1], ACCT_STR); + const int bit1 = READ_REF_BIT(single_ref_p2); if (counts) ++counts->single_ref[ctx1][1][bit1]; ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME; } else { @@ -1321,11 +1703,7 @@ static INLINE void read_mb_interp_filter(AV1_COMMON *const cm, MB_MODE_INFO *const mbmi, aom_reader *r) { FRAME_COUNTS *counts = xd->counts; -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif if (!av1_is_interp_needed(xd)) { set_default_interp_filters(mbmi, cm->interp_filter); @@ -1384,11 +1762,7 @@ static void read_intra_block_mode_info(AV1_COMMON *const cm, const int mi_row, mbmi->ref_frame[0] = INTRA_FRAME; mbmi->ref_frame[1] = NONE_FRAME; -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif #if CONFIG_CB4X4 (void)i; @@ -1429,14 +1803,9 @@ static void read_intra_block_mode_info(AV1_COMMON *const cm, const int mi_row, #if CONFIG_CFL // TODO(ltrudeau) support PALETTE - if (mbmi->uv_mode == DC_PRED) { - mbmi->cfl_alpha_idx = read_cfl_alphas( -#if CONFIG_EC_ADAPT - xd->tile_ctx, -#else - cm->fc, -#endif // CONFIG_EC_ADAPT - r, mbmi->skip, mbmi->cfl_alpha_signs); + if (mbmi->uv_mode == UV_DC_PRED) { + mbmi->cfl_alpha_idx = + read_cfl_alphas(xd->tile_ctx, r, mbmi->cfl_alpha_signs); } #endif // CONFIG_CFL @@ -1475,11 +1844,7 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r) { int i; int ret = 1; -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type; MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; #if CONFIG_CB4X4 @@ -1550,6 +1915,84 @@ static INLINE int assign_mv(AV1_COMMON *cm, MACROBLOCKD *xd, break; } #if CONFIG_EXT_INTER +#if CONFIG_COMPOUND_SINGLEREF + case SR_NEAREST_NEARMV: { + assert(!is_compound); + mv[0].as_int = nearest_mv[0].as_int; + mv[1].as_int = near_mv[0].as_int; + break; + } + /* + case SR_NEAREST_NEWMV: { + assert(!is_compound); + mv[0].as_int = nearest_mv[0].as_int; + + FRAME_COUNTS *counts = xd->counts; + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], + xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); + nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; + nmv_context_counts *const mv_counts = + counts ? &counts->mv[nmv_ctx] : NULL; + read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); + ret = ret && is_mv_valid(&mv[1].as_mv); + break; + }*/ + case SR_NEAR_NEWMV: { + assert(!is_compound); + mv[0].as_int = near_mv[0].as_int; + + FRAME_COUNTS *counts = xd->counts; + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], + xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); + nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; + nmv_context_counts *const mv_counts = + counts ? &counts->mv[nmv_ctx] : NULL; + read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); + ret = ret && is_mv_valid(&mv[1].as_mv); + break; + } + case SR_ZERO_NEWMV: { + assert(!is_compound); +#if CONFIG_GLOBAL_MOTION + mv[0].as_int = gm_get_motion_vector(&cm->global_motion[ref_frame[0]], + cm->allow_high_precision_mv, bsize, + mi_col, mi_row, block) + .as_int; +#else + mv[0].as_int = 0; +#endif // CONFIG_GLOBAL_MOTION + + FRAME_COUNTS *counts = xd->counts; + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = av1_nmv_ctx(xd->ref_mv_count[rf_type], + xd->ref_mv_stack[rf_type], 0, mbmi->ref_mv_idx); + nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; + nmv_context_counts *const mv_counts = + counts ? &counts->mv[nmv_ctx] : NULL; + read_mv(r, &mv[1].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); + ret = ret && is_mv_valid(&mv[1].as_mv); + break; + } + case SR_NEW_NEWMV: { + assert(!is_compound); + + FRAME_COUNTS *counts = xd->counts; + for (i = 0; i < 2; ++i) { + int8_t rf_type = av1_ref_frame_type(mbmi->ref_frame); + int nmv_ctx = + av1_nmv_ctx(xd->ref_mv_count[rf_type], xd->ref_mv_stack[rf_type], 0, + mbmi->ref_mv_idx); + nmv_context *const nmvc = &ec_ctx->nmvc[nmv_ctx]; + nmv_context_counts *const mv_counts = + counts ? &counts->mv[nmv_ctx] : NULL; + read_mv(r, &mv[i].as_mv, &ref_mv[0].as_mv, nmvc, mv_counts, allow_hp); + ret = ret && is_mv_valid(&mv[i].as_mv); + } + break; + } +#endif // CONFIG_COMPOUND_SINGLEREF case NEW_NEWMV: { FRAME_COUNTS *counts = xd->counts; assert(is_compound); @@ -1664,19 +2107,102 @@ static int read_is_inter_block(AV1_COMMON *const cm, MACROBLOCKD *const xd, return get_segdata(&cm->seg, segment_id, SEG_LVL_REF_FRAME) != INTRA_FRAME; } else { const int ctx = av1_get_intra_inter_context(xd); +#if CONFIG_NEW_MULTISYMBOL + FRAME_CONTEXT *ec_ctx = xd->tile_ctx; + const int is_inter = + aom_read_symbol(r, ec_ctx->intra_inter_cdf[ctx], 2, ACCT_STR); +#else const int is_inter = aom_read(r, cm->fc->intra_inter_prob[ctx], ACCT_STR); +#endif FRAME_COUNTS *counts = xd->counts; if (counts) ++counts->intra_inter[ctx][is_inter]; return is_inter; } } +#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF +static int read_is_inter_singleref_comp_mode(AV1_COMMON *const cm, + MACROBLOCKD *const xd, + int segment_id, aom_reader *r) { + if (segfeature_active(&cm->seg, segment_id, SEG_LVL_REF_FRAME)) return 0; + + const int ctx = av1_get_inter_mode_context(xd); + const int is_singleref_comp_mode = + aom_read(r, cm->fc->comp_inter_mode_prob[ctx], ACCT_STR); + FRAME_COUNTS *counts = xd->counts; + + if (counts) ++counts->comp_inter_mode[ctx][is_singleref_comp_mode]; + return is_singleref_comp_mode; +} +#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF + static void fpm_sync(void *const data, int mi_row) { AV1Decoder *const pbi = (AV1Decoder *)data; av1_frameworker_wait(pbi->frame_worker_owner, pbi->common.prev_frame, mi_row << pbi->common.mib_size_log2); } +#if DEC_MISMATCH_DEBUG +static void dec_dump_logs(AV1_COMMON *cm, MODE_INFO *const mi, + MACROBLOCKD *const xd, int mi_row, int mi_col, + int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES], + int16_t mode_ctx) { + int_mv mv[2] = { { 0 } }; + int ref; + MB_MODE_INFO *const mbmi = &mi->mbmi; + for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) + mv[ref].as_mv = mbmi->mv[ref].as_mv; + + int interp_ctx[2] = { -1 }; + int interp_filter[2] = { cm->interp_filter }; + if (cm->interp_filter == SWITCHABLE) { + int dir; + for (dir = 0; dir < 2; ++dir) { + if (has_subpel_mv_component(xd->mi[0], xd, dir) || + (mbmi->ref_frame[1] > INTRA_FRAME && + has_subpel_mv_component(xd->mi[0], xd, dir + 2))) { + interp_ctx[dir] = av1_get_pred_context_switchable_interp(xd, dir); + interp_filter[dir] = mbmi->interp_filter[dir]; + } else { + interp_filter[dir] = EIGHTTAP_REGULAR; + } + } + } + + const int16_t newmv_ctx = mode_ctx & NEWMV_CTX_MASK; + int16_t zeromv_ctx = -1; + int16_t refmv_ctx = -1; + if (mbmi->mode != NEWMV) { + if (mode_ctx & (1 << ALL_ZERO_FLAG_OFFSET)) assert(mbmi->mode == ZEROMV); + zeromv_ctx = (mode_ctx >> ZEROMV_OFFSET) & ZEROMV_CTX_MASK; + if (mbmi->mode != ZEROMV) { + refmv_ctx = (mode_ctx >> REFMV_OFFSET) & REFMV_CTX_MASK; + if (mode_ctx & (1 << SKIP_NEARESTMV_OFFSET)) refmv_ctx = 6; + if (mode_ctx & (1 << SKIP_NEARMV_OFFSET)) refmv_ctx = 7; + if (mode_ctx & (1 << SKIP_NEARESTMV_SUB8X8_OFFSET)) refmv_ctx = 8; + } + } + + int8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); +#define FRAME_TO_CHECK 1 + if (cm->current_video_frame == FRAME_TO_CHECK /*&& cm->show_frame == 0*/) { + printf( + "=== DECODER ===: " + "Frame=%d, (mi_row,mi_col)=(%d,%d), mode=%d, bsize=%d, " + "show_frame=%d, mv[0]=(%d,%d), mv[1]=(%d,%d), ref[0]=%d, " + "ref[1]=%d, motion_mode=%d, inter_mode_ctx=%d, mode_ctx=%d, " + "interp_ctx=(%d,%d), interp_filter=(%d,%d), newmv_ctx=%d, " + "zeromv_ctx=%d, refmv_ctx=%d\n", + cm->current_video_frame, mi_row, mi_col, mbmi->mode, mbmi->sb_type, + cm->show_frame, mv[0].as_mv.row, mv[0].as_mv.col, mv[1].as_mv.row, + mv[1].as_mv.col, mbmi->ref_frame[0], mbmi->ref_frame[1], + mbmi->motion_mode, inter_mode_ctx[ref_frame_type], mode_ctx, + interp_ctx[0], interp_ctx[1], interp_filter[0], interp_filter[1], + newmv_ctx, zeromv_ctx, refmv_ctx); + } +} +#endif // DEC_MISMATCH_DEBUG + static void read_inter_block_mode_info(AV1Decoder *const pbi, MACROBLOCKD *const xd, MODE_INFO *const mi, @@ -1695,6 +2221,9 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, int_mv nearestmv[2], nearmv[2]; int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; int ref, is_compound; +#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF + int is_singleref_comp_mode = 0; +#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES]; #if CONFIG_EXT_INTER int16_t compound_inter_mode_ctx[MODE_CTX_REF_FRAMES]; @@ -1702,12 +2231,11 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, int16_t mode_ctx = 0; #if CONFIG_WARPED_MOTION int pts[SAMPLES_ARRAY_SIZE], pts_inref[SAMPLES_ARRAY_SIZE]; +#if WARPED_MOTION_SORT_SAMPLES + int pts_mv[SAMPLES_ARRAY_SIZE]; +#endif // WARPED_MOTION_SORT_SAMPLES #endif // CONFIG_WARPED_MOTION -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; -#else - FRAME_CONTEXT *ec_ctx = cm->fc; -#endif assert(NELEMENTS(mode_2_counter) == MB_MODE_COUNT); @@ -1721,6 +2249,21 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame); is_compound = has_second_ref(mbmi); +#if CONFIG_EXT_COMP_REFS +#if !USE_UNI_COMP_REFS + // NOTE: uni-directional comp refs disabled + if (is_compound) + assert(mbmi->ref_frame[0] < BWDREF_FRAME && + mbmi->ref_frame[1] >= BWDREF_FRAME); +#endif // !USE_UNI_COMP_REFS +#endif // CONFIG_EXT_COMP_REFS + +#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF + if (!is_compound) + is_singleref_comp_mode = + read_is_inter_singleref_comp_mode(cm, xd, mbmi->segment_id, r); +#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF + for (ref = 0; ref < 1 + is_compound; ++ref) { MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; @@ -1772,7 +2315,11 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, } #if CONFIG_EXT_INTER +#if CONFIG_COMPOUND_SINGLEREF + if (is_compound || is_singleref_comp_mode) +#else // !CONFIG_COMPOUND_SINGLEREF if (is_compound) +#endif // CONFIG_COMPOUND_SINGLEREF mode_ctx = compound_inter_mode_ctx[mbmi->ref_frame[0]]; else #endif // CONFIG_EXT_INTER @@ -1784,7 +2331,7 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, mbmi->mode = ZEROMV; if (bsize < BLOCK_8X8 && !unify_bsize) { aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM, - "Invalid usage of segement feature on small blocks"); + "Invalid usage of segment feature on small blocks"); return; } } else { @@ -1792,16 +2339,23 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, #if CONFIG_EXT_INTER if (is_compound) mbmi->mode = read_inter_compound_mode(cm, xd, r, mode_ctx); +#if CONFIG_COMPOUND_SINGLEREF + else if (is_singleref_comp_mode) + mbmi->mode = read_inter_singleref_comp_mode(xd, r, mode_ctx); +#endif // CONFIG_COMPOUND_SINGLEREF else #endif // CONFIG_EXT_INTER mbmi->mode = read_inter_mode(ec_ctx, xd, r, mode_ctx); #if CONFIG_EXT_INTER if (mbmi->mode == NEWMV || mbmi->mode == NEW_NEWMV || +#if CONFIG_COMPOUND_SINGLEREF + mbmi->mode == SR_NEW_NEWMV || +#endif // CONFIG_COMPOUND_SINGLEREF have_nearmv_in_inter_mode(mbmi->mode)) -#else +#else // !CONFIG_EXT_INTER if (mbmi->mode == NEARMV || mbmi->mode == NEWMV) -#endif - read_drl_idx(cm, xd, mbmi, r); +#endif // CONFIG_EXT_INTER + read_drl_idx(ec_ctx, xd, mbmi, r); } } @@ -1817,16 +2371,15 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, } } - if (mbmi->ref_mv_idx > 0) { - int_mv cur_mv = - xd->ref_mv_stack[mbmi->ref_frame[0]][1 + mbmi->ref_mv_idx].this_mv; - nearmv[0] = cur_mv; - } - #if CONFIG_EXT_INTER +#if CONFIG_COMPOUND_SINGLEREF + if ((is_compound || is_singleref_comp_mode) && + (bsize >= BLOCK_8X8 || unify_bsize) && mbmi->mode != ZERO_ZEROMV) { +#else // !CONFIG_COMPOUND_SINGLEREF if (is_compound && (bsize >= BLOCK_8X8 || unify_bsize) && mbmi->mode != ZERO_ZEROMV) { -#else +#endif // CONFIG_COMPOUND_SINGLEREF +#else // !CONFIG_EXT_INTER if (is_compound && (bsize >= BLOCK_8X8 || unify_bsize) && mbmi->mode != NEWMV && mbmi->mode != ZEROMV) { #endif // CONFIG_EXT_INTER @@ -1845,7 +2398,12 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, lower_mv_precision(&nearestmv[0].as_mv, allow_hp); lower_mv_precision(&nearestmv[1].as_mv, allow_hp); #if CONFIG_EXT_INTER - } else if (mbmi->mode == NEAREST_NEWMV) { + } else if (mbmi->mode == NEAREST_NEWMV +#if CONFIG_COMPOUND_SINGLEREF + || mbmi->mode == SR_NEAREST_NEARMV +// || mbmi->mode == SR_NEAREST_NEWMV +#endif // CONFIG_COMPOUND_SINGLEREF + ) { nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv; lower_mv_precision(&nearestmv[0].as_mv, allow_hp); } else if (mbmi->mode == NEW_NEARESTMV) { @@ -1858,17 +2416,30 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, #if CONFIG_EXT_INTER if (xd->ref_mv_count[ref_frame_type] > 1) { int ref_mv_idx = 1 + mbmi->ref_mv_idx; - if (compound_ref0_mode(mbmi->mode) == NEARMV) { - nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; - lower_mv_precision(&nearmv[0].as_mv, allow_hp); - } +#if CONFIG_COMPOUND_SINGLEREF + if (is_compound) { +#endif // CONFIG_COMPOUND_SINGLEREF + if (compound_ref0_mode(mbmi->mode) == NEARMV) { + nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; + lower_mv_precision(&nearmv[0].as_mv, allow_hp); + } - if (compound_ref1_mode(mbmi->mode) == NEARMV) { - nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv; - lower_mv_precision(&nearmv[1].as_mv, allow_hp); + if (compound_ref1_mode(mbmi->mode) == NEARMV) { + nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv; + lower_mv_precision(&nearmv[1].as_mv, allow_hp); + } +#if CONFIG_COMPOUND_SINGLEREF + } else { + assert(is_singleref_comp_mode); + if (compound_ref0_mode(mbmi->mode) == NEARMV || + compound_ref1_mode(mbmi->mode) == NEARMV) { + nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; + lower_mv_precision(&nearmv[0].as_mv, allow_hp); + } } +#endif // CONFIG_COMPOUND_SINGLEREF } -#else +#else // !CONFIG_EXT_INTER if (xd->ref_mv_count[ref_frame_type] > 1) { int ref_mv_idx = 1 + mbmi->ref_mv_idx; nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv; @@ -1877,6 +2448,10 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv; } #endif // CONFIG_EXT_INTER + } else if (mbmi->ref_mv_idx > 0 && mbmi->mode == NEARMV) { + int_mv cur_mv = + xd->ref_mv_stack[mbmi->ref_frame[0]][1 + mbmi->ref_mv_idx].this_mv; + nearmv[0] = cur_mv; } #if !CONFIG_DUAL_FILTER && !CONFIG_WARPED_MOTION && !CONFIG_GLOBAL_MOTION @@ -2008,6 +2583,26 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, } nearestmv[1] = ref_mv[1]; } +#if CONFIG_COMPOUND_SINGLEREF + } else if (is_singleref_comp_mode) { + int ref_mv_idx = mbmi->ref_mv_idx; + // Special case: SR_NEAR_NEWMV use 1 + mbmi->ref_mv_idx (like NEARMV) + // instead of mbmi->ref_mv_idx (like NEWMV) + if (mbmi->mode == SR_NEAR_NEWMV) ref_mv_idx = 1 + mbmi->ref_mv_idx; + + if (compound_ref0_mode(mbmi->mode) == NEWMV || + compound_ref1_mode(mbmi->mode) == NEWMV) { + uint8_t ref_frame_type = av1_ref_frame_type(mbmi->ref_frame); + if (xd->ref_mv_count[ref_frame_type] > 1) { + ref_mv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv; + clamp_mv_ref(&ref_mv[0].as_mv, xd->n8_w << MI_SIZE_LOG2, + xd->n8_h << MI_SIZE_LOG2, xd); + } + // TODO(zoeliu): To further investigate why this would not cause a + // mismatch for the mode of SR_NEAREST_NEWMV. + nearestmv[0] = ref_mv[0]; + } +#endif // CONFIG_COMPOUND_SINGLEREF } else { #endif // CONFIG_EXT_INTER if (mbmi->mode == NEWMV) { @@ -2043,8 +2638,13 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, #endif cm->allow_interintra_compound && is_interintra_allowed(mbmi)) { const int bsize_group = size_group_lookup[bsize]; +#if CONFIG_NEW_MULTISYMBOL + const int interintra = + aom_read_symbol(r, ec_ctx->interintra_cdf[bsize_group], 2, ACCT_STR); +#else const int interintra = aom_read(r, cm->fc->interintra_prob[bsize_group], ACCT_STR); +#endif if (xd->counts) xd->counts->interintra[bsize_group][interintra]++; assert(mbmi->ref_frame[1] == NONE_FRAME); if (interintra) { @@ -2064,8 +2664,13 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, mbmi->filter_intra_mode_info.use_filter_intra_mode[1] = 0; #endif // CONFIG_FILTER_INTRA if (is_interintra_wedge_used(bsize)) { +#if CONFIG_NEW_MULTISYMBOL + mbmi->use_wedge_interintra = aom_read_symbol( + r, ec_ctx->wedge_interintra_cdf[bsize], 2, ACCT_STR); +#else mbmi->use_wedge_interintra = aom_read(r, cm->fc->wedge_interintra_prob[bsize], ACCT_STR); +#endif if (xd->counts) xd->counts->wedge_interintra[bsize][mbmi->use_wedge_interintra]++; if (mbmi->use_wedge_interintra) { @@ -2078,11 +2683,25 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, } #endif // CONFIG_EXT_INTER && CONFIG_INTERINTRA +#if CONFIG_WARPED_MOTION + for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) { + const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; + RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME]; + + xd->block_refs[ref] = ref_buf; + } +#endif + #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION mbmi->motion_mode = SIMPLE_TRANSLATION; #if CONFIG_WARPED_MOTION if (mbmi->sb_type >= BLOCK_8X8 && !has_second_ref(mbmi)) +#if WARPED_MOTION_SORT_SAMPLES + mbmi->num_proj_ref[0] = + findSamples(cm, xd, mi_row, mi_col, pts, pts_inref, pts_mv); +#else mbmi->num_proj_ref[0] = findSamples(cm, xd, mi_row, mi_col, pts, pts_inref); +#endif // WARPED_MOTION_SORT_SAMPLES #endif // CONFIG_WARPED_MOTION #if CONFIG_MOTION_VAR av1_count_overlappable_neighbors(cm, xd, mi_row, mi_col); @@ -2095,13 +2714,28 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, if (mbmi->ref_frame[1] != INTRA_FRAME) #endif // CONFIG_EXT_INTER mbmi->motion_mode = read_motion_mode(cm, xd, mi, r); + +#if CONFIG_NCOBMC_ADAPT_WEIGHT + read_ncobmc_mode(xd, mi, mbmi->ncobmc_mode, r); +#endif + +#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF + if (is_singleref_comp_mode) assert(mbmi->motion_mode == SIMPLE_TRANSLATION); +#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF #if CONFIG_WARPED_MOTION if (mbmi->motion_mode == WARPED_CAUSAL) { mbmi->wm_params[0].wmtype = DEFAULT_WMTYPE; + +#if WARPED_MOTION_SORT_SAMPLES + if (mbmi->num_proj_ref[0] > 1) + mbmi->num_proj_ref[0] = sortSamples(pts_mv, &mbmi->mv[0].as_mv, pts, + pts_inref, mbmi->num_proj_ref[0]); +#endif // WARPED_MOTION_SORT_SAMPLES + if (find_projection(mbmi->num_proj_ref[0], pts, pts_inref, bsize, mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col, &mbmi->wm_params[0], mi_row, mi_col)) { - assert(0 && "Invalid Warped Model."); + aom_internal_error(&cm->error, AOM_CODEC_ERROR, "Invalid Warped Model"); } } #endif // CONFIG_WARPED_MOTION @@ -2112,8 +2746,13 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, #if CONFIG_EXT_INTER mbmi->interinter_compound_type = COMPOUND_AVERAGE; - if (cm->reference_mode != SINGLE_REFERENCE && + if ( +#if CONFIG_COMPOUND_SINGLEREF + is_inter_anyref_comp_mode(mbmi->mode) +#else // !CONFIG_COMPOUND_SINGLEREF + cm->reference_mode != SINGLE_REFERENCE && is_inter_compound_mode(mbmi->mode) +#endif // CONFIG_COMPOUND_SINGLEREF #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION && mbmi->motion_mode == SIMPLE_TRANSLATION #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION @@ -2121,9 +2760,8 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, if (is_any_masked_compound_used(bsize)) { #if CONFIG_COMPOUND_SEGMENT || CONFIG_WEDGE if (cm->allow_masked_compound) { - mbmi->interinter_compound_type = - aom_read_tree(r, av1_compound_type_tree, - cm->fc->compound_type_prob[bsize], ACCT_STR); + mbmi->interinter_compound_type = aom_read_symbol( + r, ec_ctx->compound_type_cdf[bsize], COMPOUND_TYPES, ACCT_STR); #if CONFIG_WEDGE if (mbmi->interinter_compound_type == COMPOUND_WEDGE) { mbmi->wedge_index = @@ -2149,6 +2787,11 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi, #if CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION || CONFIG_GLOBAL_MOTION read_mb_interp_filter(cm, xd, mbmi, r); #endif // CONFIG_DUAL_FILTER || CONFIG_WARPED_MOTION + +#if DEC_MISMATCH_DEBUG + // NOTE(zoeliu): For debug + dec_dump_logs(cm, mi, xd, mi_row, mi_col, inter_mode_ctx, mode_ctx); +#endif // DEC_MISMATCH_DEBUG } static void read_inter_frame_mode_info(AV1Decoder *const pbi, @@ -2223,6 +2866,26 @@ static void read_inter_frame_mode_info(AV1Decoder *const pbi, for (idx = 0; idx < width; idx += bw) read_tx_size_vartx(cm, xd, mbmi, xd->counts, max_tx_size, height != width, idy, idx, r); +#if CONFIG_RECT_TX_EXT + if (is_quarter_tx_allowed(xd, mbmi, inter_block) && + mbmi->tx_size == max_tx_size) { + int quarter_tx; + + if (quarter_txsize_lookup[bsize] != max_tx_size) { + quarter_tx = aom_read(r, cm->fc->quarter_tx_size_prob, ACCT_STR); + if (xd->counts) ++xd->counts->quarter_tx_size[quarter_tx]; + } else { + quarter_tx = 1; + } + if (quarter_tx) { + mbmi->tx_size = quarter_txsize_lookup[bsize]; + for (idy = 0; idy < tx_size_high_unit[max_tx_size] / 2; ++idy) + for (idx = 0; idx < tx_size_wide_unit[max_tx_size] / 2; ++idx) + mbmi->inter_tx_size[idy][idx] = mbmi->tx_size; + mbmi->min_tx_size = get_min_tx_size(mbmi->tx_size); + } + } +#endif } else { mbmi->tx_size = read_tx_size(cm, xd, inter_block, !mbmi->skip, r); diff --git a/third_party/aom/av1/decoder/decodemv.h b/third_party/aom/av1/decoder/decodemv.h index ceaee1d6b..162cf3254 100644 --- a/third_party/aom/av1/decoder/decodemv.h +++ b/third_party/aom/av1/decoder/decodemv.h @@ -37,7 +37,8 @@ void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd, int supertx_enabled, #endif #if CONFIG_TXK_SEL - int block, int plane, + int blk_row, int blk_col, int block, int plane, + TX_SIZE tx_size, #endif aom_reader *r); diff --git a/third_party/aom/av1/decoder/decoder.c b/third_party/aom/av1/decoder/decoder.c index b4f37d4e7..3998c20ee 100644 --- a/third_party/aom/av1/decoder/decoder.c +++ b/third_party/aom/av1/decoder/decoder.c @@ -50,8 +50,6 @@ static void initialize_dec(void) { av1_init_wedge_masks(); #endif // CONFIG_EXT_INTER init_done = 1; - av1_indices_from_tree(av1_intra_mode_ind, av1_intra_mode_inv, - av1_intra_mode_tree); av1_indices_from_tree(av1_switchable_interp_ind, av1_switchable_interp_inv, av1_switchable_interp_tree); #if CONFIG_EXT_TX @@ -65,8 +63,6 @@ static void initialize_dec(void) { #else av1_indices_from_tree(av1_ext_tx_ind, av1_ext_tx_inv, av1_ext_tx_tree); #endif - av1_indices_from_tree(av1_inter_mode_ind, av1_inter_mode_inv, - av1_inter_mode_tree); } } @@ -236,7 +232,12 @@ aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, // cpi->lst3_fb_idx = 2; // cpi->gld_fb_idx = 3; // cpi->bwd_fb_idx = 4; + // #if CONFIG_ALTREF2 + // cpi->alt2_fb_idx = 5; + // cpi->alt_fb_idx = 6; + // #else // !CONFIG_ALTREF2 // cpi->alt_fb_idx = 5; + // #endif // CONFIG_ALTREF2 // #else // CONFIG_EXT_REFS // cpi->gld_fb_idx = 1; // cpi->alt_fb_idx = 2; @@ -255,9 +256,16 @@ aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, idx = cm->ref_frame_map[3]; } else if (ref_frame_flag == AOM_BWD_FLAG) { idx = cm->ref_frame_map[4]; +#if CONFIG_ALTREF2 + } else if (ref_frame_flag == AOM_ALT2_FLAG) { + idx = cm->ref_frame_map[5]; + } else if (ref_frame_flag == AOM_ALT_FLAG) { + idx = cm->ref_frame_map[6]; +#else // !CONFIG_ALTREF2 } else if (ref_frame_flag == AOM_ALT_FLAG) { idx = cm->ref_frame_map[5]; -#else +#endif // CONFIG_ALTREF2 +#else // !CONFIG_EXT_REFS } else if (ref_frame_flag == AOM_GOLD_FLAG) { idx = cm->ref_frame_map[1]; } else if (ref_frame_flag == AOM_ALT_FLAG) { @@ -446,7 +454,10 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size, // border. if (pbi->dec_tile_row == -1 && pbi->dec_tile_col == -1) #endif // CONFIG_EXT_TILE - aom_extend_frame_inner_borders(cm->frame_to_show); + // TODO(debargha): Fix encoder side mv range, so that we can use the + // inner border extension. As of now use the larger extension. + // aom_extend_frame_inner_borders(cm->frame_to_show); + aom_extend_frame_borders(cm->frame_to_show); aom_clear_system_state(); @@ -500,7 +511,6 @@ int av1_get_raw_frame(AV1Decoder *pbi, YV12_BUFFER_CONFIG *sd) { /* no raw frame to show!!! */ if (!cm->show_frame) return ret; - pbi->ready_for_new_data = 1; *sd = *cm->frame_to_show; ret = 0; aom_clear_system_state(); @@ -518,6 +528,7 @@ int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) { aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz, uint32_t sizes[8], int *count, + int *index_size, aom_decrypt_cb decrypt_cb, void *decrypt_state) { // A chunk ending with a byte matching 0xc0 is an invalid chunk unless @@ -530,13 +541,14 @@ aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz, size_t frame_sz_sum = 0; assert(data_sz); - marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1); + marker = read_marker(decrypt_cb, decrypt_state, data); *count = 0; if ((marker & 0xe0) == 0xc0) { const uint32_t frames = (marker & 0x7) + 1; const uint32_t mag = ((marker >> 3) & 0x3) + 1; const size_t index_sz = 2 + mag * (frames - 1); + *index_size = (int)index_sz; // This chunk is marked as having a superframe index but doesn't have // enough data for it, thus it's an invalid superframe index. @@ -544,7 +556,7 @@ aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz, { const uint8_t marker2 = - read_marker(decrypt_cb, decrypt_state, data + data_sz - index_sz); + read_marker(decrypt_cb, decrypt_state, data + index_sz - 1); // This chunk is marked as having a superframe index but doesn't have // the matching marker byte at the front of the index therefore it's an @@ -555,7 +567,7 @@ aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz, { // Found a valid superframe index. uint32_t i, j; - const uint8_t *x = &data[data_sz - index_sz + 1]; + const uint8_t *x = &data[1]; // Frames has a maximum of 8 and mag has a maximum of 4. uint8_t clear_buffer[28]; diff --git a/third_party/aom/av1/decoder/decoder.h b/third_party/aom/av1/decoder/decoder.h index 139fde1c0..5e6afc2dc 100644 --- a/third_party/aom/av1/decoder/decoder.h +++ b/third_party/aom/av1/decoder/decoder.h @@ -53,9 +53,7 @@ typedef struct TileData { #if CONFIG_CFL CFL_CTX cfl; #endif -#if CONFIG_EC_ADAPT DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx); -#endif #if CONFIG_PALETTE DECLARE_ALIGNED(16, uint8_t, color_index_map[2][MAX_SB_SQUARE]); #endif // CONFIG_PALETTE @@ -75,9 +73,7 @@ typedef struct TileWorkerData { #if CONFIG_CFL CFL_CTX cfl; #endif -#if CONFIG_EC_ADAPT FRAME_CONTEXT tctx; -#endif #if CONFIG_PALETTE DECLARE_ALIGNED(16, uint8_t, color_index_map[2][MAX_SB_SQUARE]); #endif // CONFIG_PALETTE @@ -122,6 +118,7 @@ typedef struct AV1Decoder { aom_decrypt_cb decrypt_cb; void *decrypt_state; + int allow_lowbitdepth; int max_threads; int inv_tile_order; int need_resync; // wait for key/intra-only frame. @@ -130,19 +127,17 @@ typedef struct AV1Decoder { int tile_size_bytes; #if CONFIG_EXT_TILE int tile_col_size_bytes; - int dec_tile_row, dec_tile_col; -#endif // CONFIG_EXT_TILE + int dec_tile_row, dec_tile_col; // always -1 for non-VR tile encoding +#endif // CONFIG_EXT_TILE #if CONFIG_ACCOUNTING int acct_enabled; Accounting accounting; #endif size_t uncomp_hdr_size; // Size of the uncompressed header size_t first_partition_size; // Size of the compressed header -#if CONFIG_TILE_GROUPS - int tg_size; // Number of tiles in the current tilegroup - int tg_start; // First tile in the current tilegroup + int tg_size; // Number of tiles in the current tilegroup + int tg_start; // First tile in the current tilegroup int tg_size_bit_offset; -#endif #if CONFIG_REFERENCE_BUFFER SequenceHeader seq_params; #endif @@ -181,6 +176,7 @@ static INLINE uint8_t read_marker(aom_decrypt_cb decrypt_cb, // "read_marker". aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz, uint32_t sizes[8], int *count, + int *index_size, aom_decrypt_cb decrypt_cb, void *decrypt_state); @@ -217,6 +213,20 @@ static INLINE int dec_is_ref_frame_buf(AV1Decoder *const pbi, } #endif // CONFIG_EXT_REFS +#if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA || CONFIG_PALETTE +#define ACCT_STR __func__ +static INLINE int av1_read_uniform(aom_reader *r, int n) { + const int l = get_unsigned_bits(n); + const int m = (1 << l) - n; + const int v = aom_read_literal(r, l - 1, ACCT_STR); + assert(l != 0); + if (v < m) + return v; + else + return (v << 1) - m + aom_read_literal(r, 1, ACCT_STR); +} +#endif // CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA || CONFIG_PALETTE + #ifdef __cplusplus } // extern "C" #endif diff --git a/third_party/aom/av1/decoder/decodetxb.c b/third_party/aom/av1/decoder/decodetxb.c index 90685a18d..6e38427b3 100644 --- a/third_party/aom/av1/decoder/decodetxb.c +++ b/third_party/aom/av1/decoder/decodetxb.c @@ -42,14 +42,14 @@ static int read_golomb(MACROBLOCKD *xd, aom_reader *r) { } uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd, - aom_reader *r, int block, int plane, - tran_low_t *tcoeffs, TXB_CTX *txb_ctx, - int16_t *max_scan_line, int *eob) { + aom_reader *r, int blk_row, int blk_col, int block, + int plane, tran_low_t *tcoeffs, TXB_CTX *txb_ctx, + TX_SIZE tx_size, int16_t *max_scan_line, int *eob) { FRAME_COUNTS *counts = xd->counts; - TX_SIZE tx_size = get_tx_size(plane, xd); + TX_SIZE txs_ctx = get_txsize_context(tx_size); PLANE_TYPE plane_type = get_plane_type(plane); - aom_prob *nz_map = cm->fc->nz_map[tx_size][plane_type]; - aom_prob *eob_flag = cm->fc->eob_flag[tx_size][plane_type]; + aom_prob *nz_map = cm->fc->nz_map[txs_ctx][plane_type]; + aom_prob *eob_flag = cm->fc->eob_flag[txs_ctx][plane_type]; MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; const int seg_eob = tx_size_2d[tx_size]; int c = 0; @@ -57,40 +57,47 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd, const int16_t *const dequant = xd->plane[plane].seg_dequant[mbmi->segment_id]; const int shift = av1_get_tx_scale(tx_size); const int bwl = b_width_log2_lookup[txsize_to_bsize[tx_size]] + 2; + const int height = tx_size_high[tx_size]; int cul_level = 0; unsigned int(*nz_map_count)[SIG_COEF_CONTEXTS][2]; - uint8_t txb_mask[32 * 32] = { 0 }; - nz_map_count = (counts) ? &counts->nz_map[tx_size][plane_type] : NULL; + nz_map_count = (counts) ? &counts->nz_map[txs_ctx][plane_type] : NULL; memset(tcoeffs, 0, sizeof(*tcoeffs) * seg_eob); int all_zero = - aom_read(r, cm->fc->txb_skip[tx_size][txb_ctx->txb_skip_ctx], ACCT_STR); + aom_read(r, cm->fc->txb_skip[txs_ctx][txb_ctx->txb_skip_ctx], ACCT_STR); if (xd->counts) - ++xd->counts->txb_skip[tx_size][txb_ctx->txb_skip_ctx][all_zero]; + ++xd->counts->txb_skip[txs_ctx][txb_ctx->txb_skip_ctx][all_zero]; *eob = 0; if (all_zero) { *max_scan_line = 0; +#if CONFIG_TXK_SEL + if (plane == 0) mbmi->txk_type[(blk_row << 4) + blk_col] = DCT_DCT; +#endif return 0; } + (void)blk_row; + (void)blk_col; #if CONFIG_TXK_SEL - av1_read_tx_type(cm, xd, block, plane, r); + av1_read_tx_type(cm, xd, blk_row, blk_col, block, plane, + get_min_tx_size(tx_size), r); #endif - TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size); - const SCAN_ORDER *const scan_order = - get_scan(cm, tx_size, tx_type, is_inter_block(mbmi)); + const TX_TYPE tx_type = + av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size); + const SCAN_ORDER *const scan_order = get_scan(cm, tx_size, tx_type, mbmi); const int16_t *scan = scan_order->scan; + const int16_t *iscan = scan_order->iscan; for (c = 0; c < seg_eob; ++c) { int is_nz; - int coeff_ctx = get_nz_map_ctx(tcoeffs, txb_mask, scan[c], bwl); - int eob_ctx = get_eob_ctx(tcoeffs, scan[c], bwl); + int coeff_ctx = get_nz_map_ctx(tcoeffs, scan[c], bwl, height, iscan); + int eob_ctx = get_eob_ctx(tcoeffs, scan[c], txs_ctx); if (c < seg_eob - 1) - is_nz = aom_read(r, nz_map[coeff_ctx], tx_size); + is_nz = aom_read(r, nz_map[coeff_ctx], ACCT_STR); else is_nz = 1; @@ -105,11 +112,10 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd, if (counts) ++(*nz_map_count)[coeff_ctx][is_nz]; if (is_nz) { - int is_eob = aom_read(r, eob_flag[eob_ctx], tx_size); - if (counts) ++counts->eob_flag[tx_size][plane_type][eob_ctx][is_eob]; + int is_eob = aom_read(r, eob_flag[eob_ctx], ACCT_STR); + if (counts) ++counts->eob_flag[txs_ctx][plane_type][eob_ctx][is_eob]; if (is_eob) break; } - txb_mask[scan[c]] = 1; } *eob = AOMMIN(seg_eob, c + 1); @@ -117,7 +123,7 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd, int i; for (i = 0; i < NUM_BASE_LEVELS; ++i) { - aom_prob *coeff_base = cm->fc->coeff_base[tx_size][plane_type][i]; + aom_prob *coeff_base = cm->fc->coeff_base[txs_ctx][plane_type][i]; update_eob = 0; for (c = *eob - 1; c >= 0; --c) { @@ -127,17 +133,18 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd, if (*v <= i) continue; - ctx = get_base_ctx(tcoeffs, scan[c], bwl, i + 1); + ctx = get_base_ctx(tcoeffs, scan[c], bwl, height, i + 1); - if (aom_read(r, coeff_base[ctx], tx_size)) { + if (aom_read(r, coeff_base[ctx], ACCT_STR)) { *v = i + 1; cul_level += i + 1; - if (counts) ++counts->coeff_base[tx_size][plane_type][i][ctx][1]; + if (counts) ++counts->coeff_base[txs_ctx][plane_type][i][ctx][1]; if (c == 0) { int dc_sign_ctx = txb_ctx->dc_sign_ctx; - sign = aom_read(r, cm->fc->dc_sign[plane_type][dc_sign_ctx], tx_size); + sign = + aom_read(r, cm->fc->dc_sign[plane_type][dc_sign_ctx], ACCT_STR); if (counts) ++counts->dc_sign[plane_type][dc_sign_ctx][sign]; } else { sign = aom_read_bit(r, ACCT_STR); @@ -146,7 +153,7 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd, continue; } *v = i + 2; - if (counts) ++counts->coeff_base[tx_size][plane_type][i][ctx][0]; + if (counts) ++counts->coeff_base[txs_ctx][plane_type][i][ctx][0]; // update the eob flag for coefficients with magnitude above 1. update_eob = AOMMAX(update_eob, c); @@ -163,26 +170,26 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd, if (c == 0) { int dc_sign_ctx = txb_ctx->dc_sign_ctx; - sign = aom_read(r, cm->fc->dc_sign[plane_type][dc_sign_ctx], tx_size); + sign = aom_read(r, cm->fc->dc_sign[plane_type][dc_sign_ctx], ACCT_STR); if (counts) ++counts->dc_sign[plane_type][dc_sign_ctx][sign]; } else { sign = aom_read_bit(r, ACCT_STR); } - ctx = get_br_ctx(tcoeffs, scan[c], bwl); + ctx = get_br_ctx(tcoeffs, scan[c], bwl, height); - if (cm->fc->coeff_lps[tx_size][plane_type][ctx] == 0) exit(0); + if (cm->fc->coeff_lps[txs_ctx][plane_type][ctx] == 0) exit(0); for (idx = 0; idx < COEFF_BASE_RANGE; ++idx) { - if (aom_read(r, cm->fc->coeff_lps[tx_size][plane_type][ctx], tx_size)) { + if (aom_read(r, cm->fc->coeff_lps[txs_ctx][plane_type][ctx], ACCT_STR)) { *v = (idx + 1 + NUM_BASE_LEVELS); if (sign) *v = -(*v); cul_level += abs(*v); - if (counts) ++counts->coeff_lps[tx_size][plane_type][ctx][1]; + if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][1]; break; } - if (counts) ++counts->coeff_lps[tx_size][plane_type][ctx][0]; + if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][0]; } if (idx < COEFF_BASE_RANGE) continue; @@ -211,32 +218,31 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd, uint8_t av1_read_coeffs_txb_facade(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r, int row, int col, int block, int plane, tran_low_t *tcoeffs, - int16_t *max_scan_line, int *eob) { + TX_SIZE tx_size, int16_t *max_scan_line, + int *eob) { MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; struct macroblockd_plane *pd = &xd->plane[plane]; const BLOCK_SIZE bsize = mbmi->sb_type; -#if CONFIG_CB4X4 -#if CONFIG_CHROMA_2X2 - const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); -#else +#if CONFIG_CHROMA_SUB8X8 const BLOCK_SIZE plane_bsize = AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd)); -#endif // CONFIG_CHROMA_2X2 +#elif CONFIG_CB4X4 + const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); #else // CONFIG_CB4X4 const BLOCK_SIZE plane_bsize = get_plane_block_size(AOMMAX(BLOCK_8X8, bsize), pd); #endif // CONFIG_CB4X4 - TX_SIZE tx_size = get_tx_size(plane, xd); TXB_CTX txb_ctx; get_txb_ctx(plane_bsize, tx_size, plane, pd->above_context + col, pd->left_context + row, &txb_ctx); - uint8_t cul_level = av1_read_coeffs_txb(cm, xd, r, block, plane, tcoeffs, - &txb_ctx, max_scan_line, eob); + uint8_t cul_level = + av1_read_coeffs_txb(cm, xd, r, row, col, block, plane, tcoeffs, &txb_ctx, + tx_size, max_scan_line, eob); #if CONFIG_ADAPT_SCAN PLANE_TYPE plane_type = get_plane_type(plane); - TX_TYPE tx_type = get_tx_type(plane_type, xd, block, tx_size); + TX_TYPE tx_type = av1_get_tx_type(plane_type, xd, row, col, block, tx_size); if (xd->counts && *eob > 0) av1_update_scan_count_facade(cm, xd->counts, tx_size, tx_type, pd->dqcoeff, *eob); diff --git a/third_party/aom/av1/decoder/decodetxb.h b/third_party/aom/av1/decoder/decodetxb.h index ee1bf6a3d..313476139 100644 --- a/third_party/aom/av1/decoder/decodetxb.h +++ b/third_party/aom/av1/decoder/decodetxb.h @@ -19,13 +19,14 @@ #include "aom_dsp/bitreader.h" uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd, - aom_reader *r, int block, int plane, - tran_low_t *tcoeffs, TXB_CTX *txb_ctx, - int16_t *max_scan_line, int *eob); + aom_reader *r, int blk_row, int blk_col, int block, + int plane, tran_low_t *tcoeffs, TXB_CTX *txb_ctx, + TX_SIZE tx_size, int16_t *max_scan_line, int *eob); uint8_t av1_read_coeffs_txb_facade(AV1_COMMON *cm, MACROBLOCKD *xd, aom_reader *r, int row, int col, int block, int plane, tran_low_t *tcoeffs, - int16_t *max_scan_line, int *eob); + TX_SIZE tx_size, int16_t *max_scan_line, + int *eob); void av1_read_txb_probs(FRAME_CONTEXT *fc, TX_MODE tx_mode, aom_reader *r); #endif // DECODETXB_H_ diff --git a/third_party/aom/av1/decoder/detokenize.c b/third_party/aom/av1/decoder/detokenize.c index 2e3309c07..461494dfe 100644 --- a/third_party/aom/av1/decoder/detokenize.c +++ b/third_party/aom/av1/decoder/detokenize.c @@ -16,6 +16,7 @@ #endif // !CONFIG_PVQ #include "av1/common/blockd.h" +#include "av1/decoder/detokenize.h" #define ACCT_STR __func__ @@ -23,7 +24,6 @@ #include "av1/common/common.h" #include "av1/common/entropy.h" #include "av1/common/idct.h" -#include "av1/decoder/detokenize.h" #define EOB_CONTEXT_NODE 0 #define ZERO_CONTEXT_NODE 1 @@ -110,16 +110,13 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff, #endif // CONFIG_AOM_QM int ctx, const int16_t *scan, const int16_t *nb, int16_t *max_scan_line, aom_reader *r) { - FRAME_COUNTS *counts = xd->counts; -#if CONFIG_EC_ADAPT FRAME_CONTEXT *ec_ctx = xd->tile_ctx; -#else - FRAME_CONTEXT *const ec_ctx = xd->fc; -#endif const int max_eob = tx_size_2d[tx_size]; const int ref = is_inter_block(&xd->mi[0]->mbmi); #if CONFIG_AOM_QM const qm_val_t *iqmatrix = iqm[!ref][tx_size]; +#else + (void)tx_type; #endif // CONFIG_AOM_QM int band, c = 0; const int tx_size_ctx = txsize_sqr_map[tx_size]; @@ -129,11 +126,6 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff, ec_ctx->coef_tail_cdfs[tx_size_ctx][type][ref]; int val = 0; -#if !CONFIG_EC_ADAPT - unsigned int *blockz_count; - unsigned int(*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1] = NULL; - unsigned int(*eob_branch_count)[COEFF_CONTEXTS] = NULL; -#endif uint8_t token_cache[MAX_TX_SQUARE]; const uint8_t *band_translate = get_band_translate(tx_size); int dq_shift; @@ -142,15 +134,6 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff, #if CONFIG_NEW_QUANT const tran_low_t *dqv_val = &dq_val[0][0]; #endif // CONFIG_NEW_QUANT - (void)tx_type; - - if (counts) { -#if !CONFIG_EC_ADAPT - coef_counts = counts->coef[tx_size_ctx][type][ref]; - eob_branch_count = counts->eob_branch[tx_size_ctx][type][ref]; - blockz_count = counts->blockz_count[tx_size_ctx][type][ref][ctx]; -#endif - } dq_shift = av1_get_tx_scale(tx_size); @@ -171,9 +154,6 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff, HEAD_TOKENS + first_pos, ACCT_STR) + !first_pos; if (first_pos) { -#if !CONFIG_EC_ADAPT - if (counts) ++blockz_count[comb_token != 0]; -#endif if (comb_token == 0) return 0; } token = comb_token >> 1; @@ -181,11 +161,6 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff, while (!token) { *max_scan_line = AOMMAX(*max_scan_line, scan[c]); token_cache[scan[c]] = 0; -#if !CONFIG_EC_ADAPT - if (counts && !last_pos) { - ++coef_counts[band][ctx][ZERO_TOKEN]; - } -#endif ++c; dqv = dq[1]; ctx = get_coef_context(nb, token_cache, c); @@ -201,13 +176,6 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff, } more_data = comb_token & 1; -#if !CONFIG_EC_ADAPT - if (counts && !last_pos) { - ++coef_counts[band][ctx][token]; - ++eob_branch_count[band][ctx]; - if (!more_data) ++coef_counts[band][ctx][EOB_MODEL_TOKEN]; - } -#endif if (token > ONE_TOKEN) token += @@ -226,16 +194,15 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff, v = dq_shift ? ROUND_POWER_OF_TWO(v, dq_shift) : v; #else #if CONFIG_AOM_QM - dqv = ((iqmatrix[scan[c]] * (int)dqv) + (1 << (AOM_QM_BITS - 1))) >> - AOM_QM_BITS; + // Apply quant matrix only for 2D transforms + if (IS_2D_TRANSFORM(tx_type)) + dqv = ((iqmatrix[scan[c]] * (int)dqv) + (1 << (AOM_QM_BITS - 1))) >> + AOM_QM_BITS; #endif v = (val * dqv) >> dq_shift; #endif - v = aom_read_bit(r, ACCT_STR) ? -v : v; -#if CONFIG_COEFFICIENT_RANGE_CHECKING - check_range(v, xd->bd); -#endif // CONFIG_COEFFICIENT_RANGE_CHECKING + v = (int)check_range(aom_read_bit(r, ACCT_STR) ? -v : v, xd->bd); dqcoeff[scan[c]] = v; @@ -258,46 +225,47 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, const MB_MODE_INFO *const mbmi = &mi->mbmi; uint8_t color_order[PALETTE_MAX_SIZE]; const int n = mbmi->palette_mode_info.palette_size[plane]; - int i, j; uint8_t *const color_map = xd->plane[plane].color_index_map; - const aom_prob( - *const prob)[PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1] = - plane ? av1_default_palette_uv_color_index_prob - : av1_default_palette_y_color_index_prob; + aom_cdf_prob( + *palette_cdf)[PALETTE_COLOR_INDEX_CONTEXTS][CDF_SIZE(PALETTE_COLORS)] = + plane ? xd->tile_ctx->palette_uv_color_index_cdf + : xd->tile_ctx->palette_y_color_index_cdf; int plane_block_width, plane_block_height, rows, cols; av1_get_block_dimensions(mbmi->sb_type, plane, xd, &plane_block_width, &plane_block_height, &rows, &cols); assert(plane == 0 || plane == 1); + // The first color index. + color_map[0] = av1_read_uniform(r, n); + assert(color_map[0] < n); + #if CONFIG_PALETTE_THROUGHPUT // Run wavefront on the palette map index decoding. - for (i = 1; i < rows + cols - 1; ++i) { - for (j = AOMMIN(i, cols - 1); j >= AOMMAX(0, i - rows + 1); --j) { + for (int i = 1; i < rows + cols - 1; ++i) { + for (int j = AOMMIN(i, cols - 1); j >= AOMMAX(0, i - rows + 1); --j) { const int color_ctx = av1_get_palette_color_index_context( color_map, plane_block_width, (i - j), j, n, color_order, NULL); - const int color_idx = - aom_read_tree(r, av1_palette_color_index_tree[n - 2], - prob[n - 2][color_ctx], ACCT_STR); + const int color_idx = aom_read_symbol( + r, palette_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR); assert(color_idx >= 0 && color_idx < n); color_map[(i - j) * plane_block_width + j] = color_order[color_idx]; } } // Copy last column to extra columns. if (cols < plane_block_width) { - for (i = 0; i < plane_block_height; ++i) { + for (int i = 0; i < plane_block_height; ++i) { memset(color_map + i * plane_block_width + cols, color_map[i * plane_block_width + cols - 1], (plane_block_width - cols)); } } #else - for (i = 0; i < rows; ++i) { - for (j = (i == 0 ? 1 : 0); j < cols; ++j) { + for (int i = 0; i < rows; ++i) { + for (int j = (i == 0 ? 1 : 0); j < cols; ++j) { const int color_ctx = av1_get_palette_color_index_context( color_map, plane_block_width, i, j, n, color_order, NULL); - const int color_idx = - aom_read_tree(r, av1_palette_color_index_tree[n - PALETTE_MIN_SIZE], - prob[n - PALETTE_MIN_SIZE][color_ctx], ACCT_STR); + const int color_idx = aom_read_symbol( + r, palette_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR); assert(color_idx >= 0 && color_idx < n); color_map[i * plane_block_width + j] = color_order[color_idx]; } @@ -307,7 +275,7 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, } #endif // CONFIG_PALETTE_THROUGHPUT // Copy last row to extra rows. - for (i = rows; i < plane_block_height; ++i) { + for (int i = rows; i < plane_block_height; ++i) { memcpy(color_map + i * plane_block_width, color_map + (rows - 1) * plane_block_width, plane_block_width); } diff --git a/third_party/aom/av1/decoder/detokenize.h b/third_party/aom/av1/decoder/detokenize.h index ba4066603..0e58a2803 100644 --- a/third_party/aom/av1/decoder/detokenize.h +++ b/third_party/aom/av1/decoder/detokenize.h @@ -14,9 +14,9 @@ #include "./aom_config.h" #if !CONFIG_PVQ || CONFIG_VAR_TX -#include "av1/decoder/decoder.h" #include "av1/common/scan.h" -#endif // !CONFIG_PVQ +#endif // !CONFIG_PVQ || CONFIG_VAR_TX +#include "av1/decoder/decoder.h" #ifdef __cplusplus extern "C" { diff --git a/third_party/aom/av1/decoder/inspection.c b/third_party/aom/av1/decoder/inspection.c index 926c77e17..4f98f18ea 100644 --- a/third_party/aom/av1/decoder/inspection.c +++ b/third_party/aom/av1/decoder/inspection.c @@ -78,7 +78,7 @@ int ifd_inspect(insp_frame_data *fd, void *decoder) { if (mi->mode < INTRA_MODES) { mi->uv_mode = mbmi->uv_mode; } else { - mi->uv_mode = INTRA_INVALID; + mi->uv_mode = UV_MODE_INVALID; } // Block Size mi->sb_type = mbmi->sb_type; @@ -101,7 +101,7 @@ int ifd_inspect(insp_frame_data *fd, void *decoder) { mi->cdef_strength += mi->cdef_strength == 3; #endif #if CONFIG_CFL - if (mbmi->uv_mode == DC_PRED) { + if (mbmi->uv_mode == UV_DC_PRED) { mi->cfl_alpha_idx = mbmi->cfl_alpha_idx; mi->cfl_alpha_sign = (mbmi->cfl_alpha_signs[CFL_PRED_V] << CFL_PRED_V) + mbmi->cfl_alpha_signs[CFL_PRED_U]; |