Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
James Zern | b7c05bd | 2024-06-11 19:15:10 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <assert.h> |
venkat sanampudi | 4a46999 | 2023-04-10 10:10:58 +0530 | [diff] [blame] | 13 | #include <stdbool.h> |
Wan-Teh Chang | 4eda284 | 2018-05-07 15:03:35 -0700 | [diff] [blame] | 14 | #include <stddef.h> |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 15 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 16 | #include "config/aom_config.h" |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 17 | #include "config/aom_scale_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | |
Steinar Midtskogen | 2fd70ee | 2016-09-02 10:02:30 +0200 | [diff] [blame] | 19 | #include "aom/aom_codec.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 20 | #include "aom/aom_image.h" |
| 21 | #include "aom/internal/aom_codec_internal.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 22 | #include "aom_dsp/aom_dsp_common.h" |
Cheng Chen | c7855b1 | 2017-09-05 10:49:08 -0700 | [diff] [blame] | 23 | #include "aom_dsp/binary_codes_reader.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 24 | #include "aom_dsp/bitreader.h" |
| 25 | #include "aom_dsp/bitreader_buffer.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 26 | #include "aom_dsp/txfm_common.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 27 | #include "aom_mem/aom_mem.h" |
Jingning Han | 53c0896 | 2017-11-16 14:03:41 -0800 | [diff] [blame] | 28 | #include "aom_ports/aom_timer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | #include "aom_ports/mem.h" |
| 30 | #include "aom_ports/mem_ops.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 31 | #include "aom_scale/yv12config.h" |
Peter Kasting | bad2f8d | 2024-02-12 14:24:41 -0800 | [diff] [blame] | 32 | #include "aom_util/aom_pthread.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 33 | #include "aom_util/aom_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 34 | |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 35 | #if CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG |
Fergus Simpson | 350a9b7 | 2017-04-17 15:08:45 -0700 | [diff] [blame] | 36 | #include "aom_util/debug_util.h" |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 37 | #endif // CONFIG_BITSTREAM_DEBUG || CONFIG_MISMATCH_DEBUG |
Fergus Simpson | 350a9b7 | 2017-04-17 15:08:45 -0700 | [diff] [blame] | 38 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | #include "av1/common/alloccommon.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 40 | #include "av1/common/av1_common_int.h" |
| 41 | #include "av1/common/blockd.h" |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 42 | #include "av1/common/cdef.h" |
Luc Trudeau | 3ec16a3 | 2018-03-01 20:58:09 -0500 | [diff] [blame] | 43 | #include "av1/common/cfl.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 44 | #include "av1/common/common_data.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 45 | #include "av1/common/common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 46 | #include "av1/common/entropy.h" |
| 47 | #include "av1/common/entropymode.h" |
Thomas Davies | 6519beb | 2016-10-19 14:46:07 +0100 | [diff] [blame] | 48 | #include "av1/common/entropymv.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 49 | #include "av1/common/enums.h" |
Wan-Teh Chang | c613fd4 | 2018-09-06 12:31:17 -0700 | [diff] [blame] | 50 | #include "av1/common/frame_buffers.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | #include "av1/common/idct.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 52 | #include "av1/common/mv.h" |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 53 | #include "av1/common/mvref_common.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 54 | #include "av1/common/obmc.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 55 | #include "av1/common/pred_common.h" |
| 56 | #include "av1/common/quant_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | #include "av1/common/reconinter.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 58 | #include "av1/common/reconintra.h" |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 59 | #include "av1/common/resize.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 60 | #include "av1/common/restoration.h" |
| 61 | #include "av1/common/scale.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 62 | #include "av1/common/seg_common.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 63 | #include "av1/common/thread_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 64 | #include "av1/common/tile_common.h" |
Yunqing Wang | 1694a4f | 2018-01-30 16:40:55 -0800 | [diff] [blame] | 65 | #include "av1/common/warped_motion.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 66 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 67 | #include "av1/decoder/decodeframe.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 68 | #include "av1/decoder/decodemv.h" |
| 69 | #include "av1/decoder/decoder.h" |
Angie Chiang | 133733c | 2017-03-17 12:50:20 -0700 | [diff] [blame] | 70 | #include "av1/decoder/decodetxb.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 71 | #include "av1/decoder/detokenize.h" |
Jerome Jiang | 013132e | 2024-03-05 10:23:12 -0500 | [diff] [blame] | 72 | #if CONFIG_INSPECTION |
| 73 | #include "av1/decoder/inspection.h" |
| 74 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 75 | |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 76 | #define ACCT_STR __func__ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 77 | |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 78 | #define AOM_MIN_THREADS_PER_TILE 1 |
| 79 | #define AOM_MAX_THREADS_PER_TILE 2 |
| 80 | |
Yunqing Wang | 3a74b25 | 2018-05-03 15:24:07 -0700 | [diff] [blame] | 81 | // This is needed by ext_tile related unit tests. |
| 82 | #define EXT_TILE_DEBUG 1 |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 83 | #define MC_TEMP_BUF_PELS \ |
| 84 | (((MAX_SB_SIZE)*2 + (AOM_INTERP_EXTEND)*2) * \ |
| 85 | ((MAX_SB_SIZE)*2 + (AOM_INTERP_EXTEND)*2)) |
Yunqing Wang | 3a74b25 | 2018-05-03 15:24:07 -0700 | [diff] [blame] | 86 | |
Jingning Han | 8a59bd5 | 2018-03-22 21:30:31 -0700 | [diff] [blame] | 87 | // Checks that the remaining bits start with a 1 and ends with 0s. |
| 88 | // It consumes an additional byte, if already byte aligned before the check. |
Jingning Han | 53995e1 | 2018-03-23 08:02:57 -0700 | [diff] [blame] | 89 | int av1_check_trailing_bits(AV1Decoder *pbi, struct aom_read_bit_buffer *rb) { |
Jingning Han | 8a59bd5 | 2018-03-22 21:30:31 -0700 | [diff] [blame] | 90 | // bit_offset is set to 0 (mod 8) when the reader is already byte aligned |
| 91 | int bits_before_alignment = 8 - rb->bit_offset % 8; |
Jingning Han | 8a59bd5 | 2018-03-22 21:30:31 -0700 | [diff] [blame] | 92 | int trailing = aom_rb_read_literal(rb, bits_before_alignment); |
| 93 | if (trailing != (1 << (bits_before_alignment - 1))) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 94 | pbi->error.error_code = AOM_CODEC_CORRUPT_FRAME; |
Wan-Teh Chang | 4eda284 | 2018-05-07 15:03:35 -0700 | [diff] [blame] | 95 | return -1; |
Jingning Han | 8a59bd5 | 2018-03-22 21:30:31 -0700 | [diff] [blame] | 96 | } |
| 97 | return 0; |
| 98 | } |
Jingning Han | 8a59bd5 | 2018-03-22 21:30:31 -0700 | [diff] [blame] | 99 | |
Imdad Sardharwalla | 714b268 | 2018-03-12 17:20:09 +0000 | [diff] [blame] | 100 | // Use only_chroma = 1 to only set the chroma planes |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 101 | static inline void set_planes_to_neutral_grey( |
Elliott Karpilovsky | 18fcd6a | 2019-09-16 15:15:06 -0700 | [diff] [blame] | 102 | const SequenceHeader *const seq_params, const YV12_BUFFER_CONFIG *const buf, |
| 103 | int only_chroma) { |
Wan-Teh Chang | 6efd3b2 | 2018-09-17 12:22:37 -0700 | [diff] [blame] | 104 | if (seq_params->use_highbitdepth) { |
| 105 | const int val = 1 << (seq_params->bit_depth - 1); |
| 106 | for (int plane = only_chroma; plane < MAX_MB_PLANE; plane++) { |
| 107 | const int is_uv = plane > 0; |
| 108 | uint16_t *const base = CONVERT_TO_SHORTPTR(buf->buffers[plane]); |
| 109 | // Set the first row to neutral grey. Then copy the first row to all |
| 110 | // subsequent rows. |
| 111 | if (buf->crop_heights[is_uv] > 0) { |
| 112 | aom_memset16(base, val, buf->crop_widths[is_uv]); |
| 113 | for (int row_idx = 1; row_idx < buf->crop_heights[is_uv]; row_idx++) { |
| 114 | memcpy(&base[row_idx * buf->strides[is_uv]], base, |
| 115 | sizeof(*base) * buf->crop_widths[is_uv]); |
Imdad Sardharwalla | 714b268 | 2018-03-12 17:20:09 +0000 | [diff] [blame] | 116 | } |
Wan-Teh Chang | 6efd3b2 | 2018-09-17 12:22:37 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | } else { |
| 120 | for (int plane = only_chroma; plane < MAX_MB_PLANE; plane++) { |
| 121 | const int is_uv = plane > 0; |
| 122 | for (int row_idx = 0; row_idx < buf->crop_heights[is_uv]; row_idx++) { |
Wan-Teh Chang | bc67b66 | 2022-03-29 13:33:27 -0700 | [diff] [blame] | 123 | memset(&buf->buffers[plane][row_idx * buf->strides[is_uv]], 1 << 7, |
Imdad Sardharwalla | fea0304 | 2018-04-03 13:07:49 +0100 | [diff] [blame] | 124 | buf->crop_widths[is_uv]); |
Imdad Sardharwalla | 714b268 | 2018-03-12 17:20:09 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 130 | static inline void loop_restoration_read_sb_coeffs(const AV1_COMMON *const cm, |
| 131 | MACROBLOCKD *xd, |
| 132 | aom_reader *const r, |
| 133 | int plane, int runit_idx); |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 134 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 135 | static int read_is_valid(const uint8_t *start, size_t len, const uint8_t *end) { |
| 136 | return len != 0 && len <= (size_t)(end - start); |
| 137 | } |
| 138 | |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 139 | static TX_MODE read_tx_mode(struct aom_read_bit_buffer *rb, |
| 140 | int coded_lossless) { |
| 141 | if (coded_lossless) return ONLY_4X4; |
Debargha Mukherjee | 923b73d | 2017-10-31 18:11:34 -0700 | [diff] [blame] | 142 | return aom_rb_read_bit(rb) ? TX_MODE_SELECT : TX_MODE_LARGEST; |
Debargha Mukherjee | 923b73d | 2017-10-31 18:11:34 -0700 | [diff] [blame] | 143 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 144 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 145 | static REFERENCE_MODE read_frame_reference_mode( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 146 | const AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
Cheng Chen | 5209162 | 2018-03-12 17:27:13 -0700 | [diff] [blame] | 147 | if (frame_is_intra_only(cm)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 148 | return SINGLE_REFERENCE; |
Cheng Chen | 5209162 | 2018-03-12 17:27:13 -0700 | [diff] [blame] | 149 | } else { |
| 150 | return aom_rb_read_bit(rb) ? REFERENCE_MODE_SELECT : SINGLE_REFERENCE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 154 | static inline void inverse_transform_block(DecoderCodingBlock *dcb, int plane, |
| 155 | const TX_TYPE tx_type, |
| 156 | const TX_SIZE tx_size, uint8_t *dst, |
| 157 | int stride, int reduced_tx_set) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 158 | tran_low_t *const dqcoeff = dcb->dqcoeff_block[plane] + dcb->cb_offset[plane]; |
| 159 | eob_info *eob_data = dcb->eob_data[plane] + dcb->txb_offset[plane]; |
Deepa K G | 610c9b8 | 2018-06-19 12:47:01 +0530 | [diff] [blame] | 160 | uint16_t scan_line = eob_data->max_scan_line; |
| 161 | uint16_t eob = eob_data->eob; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 162 | av1_inverse_transform_block(&dcb->xd, dqcoeff, plane, tx_type, tx_size, dst, |
| 163 | stride, eob, reduced_tx_set); |
Jingning Han | 1be1878 | 2016-10-21 11:48:15 -0700 | [diff] [blame] | 164 | memset(dqcoeff, 0, (scan_line + 1) * sizeof(dqcoeff[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 167 | static inline void read_coeffs_tx_intra_block( |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 168 | const AV1_COMMON *const cm, DecoderCodingBlock *dcb, aom_reader *const r, |
Elliott Karpilovsky | 18fcd6a | 2019-09-16 15:15:06 -0700 | [diff] [blame] | 169 | const int plane, const int row, const int col, const TX_SIZE tx_size) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 170 | MB_MODE_INFO *mbmi = dcb->xd.mi[0]; |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 171 | if (!mbmi->skip_txfm) { |
Jingning Han | 53c0896 | 2017-11-16 14:03:41 -0800 | [diff] [blame] | 172 | #if TXCOEFF_TIMER |
| 173 | struct aom_usec_timer timer; |
| 174 | aom_usec_timer_start(&timer); |
| 175 | #endif |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 176 | av1_read_coeffs_txb_facade(cm, dcb, r, plane, row, col, tx_size); |
Jingning Han | 53c0896 | 2017-11-16 14:03:41 -0800 | [diff] [blame] | 177 | #if TXCOEFF_TIMER |
| 178 | aom_usec_timer_mark(&timer); |
| 179 | const int64_t elapsed_time = aom_usec_timer_elapsed(&timer); |
| 180 | cm->txcoeff_timer += elapsed_time; |
| 181 | ++cm->txb_count; |
| 182 | #endif |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 186 | static inline void decode_block_void(const AV1_COMMON *const cm, |
| 187 | DecoderCodingBlock *dcb, |
| 188 | aom_reader *const r, const int plane, |
| 189 | const int row, const int col, |
| 190 | const TX_SIZE tx_size) { |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 191 | (void)cm; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 192 | (void)dcb; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 193 | (void)r; |
| 194 | (void)plane; |
| 195 | (void)row; |
| 196 | (void)col; |
| 197 | (void)tx_size; |
| 198 | } |
| 199 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 200 | static inline void predict_inter_block_void(AV1_COMMON *const cm, |
| 201 | DecoderCodingBlock *dcb, |
| 202 | BLOCK_SIZE bsize) { |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 203 | (void)cm; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 204 | (void)dcb; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 205 | (void)bsize; |
| 206 | } |
| 207 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 208 | static inline void cfl_store_inter_block_void(AV1_COMMON *const cm, |
| 209 | MACROBLOCKD *const xd) { |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 210 | (void)cm; |
| 211 | (void)xd; |
| 212 | } |
| 213 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 214 | static inline void predict_and_reconstruct_intra_block( |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 215 | const AV1_COMMON *const cm, DecoderCodingBlock *dcb, aom_reader *const r, |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 216 | const int plane, const int row, const int col, const TX_SIZE tx_size) { |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 217 | (void)r; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 218 | MACROBLOCKD *const xd = &dcb->xd; |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 219 | MB_MODE_INFO *mbmi = xd->mi[0]; |
| 220 | PLANE_TYPE plane_type = get_plane_type(plane); |
| 221 | |
| 222 | av1_predict_intra_block_facade(cm, xd, plane, col, row, tx_size); |
| 223 | |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 224 | if (!mbmi->skip_txfm) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 225 | eob_info *eob_data = dcb->eob_data[plane] + dcb->txb_offset[plane]; |
Deepa K G | 610c9b8 | 2018-06-19 12:47:01 +0530 | [diff] [blame] | 226 | if (eob_data->eob) { |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 227 | const bool reduced_tx_set_used = cm->features.reduced_tx_set_used; |
Hui Su | 32fdb83 | 2019-10-22 10:20:03 -0700 | [diff] [blame] | 228 | // tx_type was read out in av1_read_coeffs_txb. |
| 229 | const TX_TYPE tx_type = av1_get_tx_type(xd, plane_type, row, col, tx_size, |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 230 | reduced_tx_set_used); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 231 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
Hui Su | adda587 | 2019-12-09 10:08:49 -0800 | [diff] [blame] | 232 | uint8_t *dst = &pd->dst.buf[(row * pd->dst.stride + col) << MI_SIZE_LOG2]; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 233 | inverse_transform_block(dcb, plane, tx_type, tx_size, dst, pd->dst.stride, |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 234 | reduced_tx_set_used); |
Angie Chiang | 3d005e4 | 2017-04-02 16:31:35 -0700 | [diff] [blame] | 235 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 236 | } |
Luc Trudeau | dae377d | 2018-04-10 13:02:47 -0400 | [diff] [blame] | 237 | if (plane == AOM_PLANE_Y && store_cfl_required(cm, xd)) { |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 238 | cfl_store_tx(xd, row, col, tx_size, mbmi->bsize); |
Luc Trudeau | e398028 | 2017-04-25 23:17:21 -0400 | [diff] [blame] | 239 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 242 | static inline void inverse_transform_inter_block( |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 243 | const AV1_COMMON *const cm, DecoderCodingBlock *dcb, aom_reader *const r, |
Elliott Karpilovsky | 18fcd6a | 2019-09-16 15:15:06 -0700 | [diff] [blame] | 244 | const int plane, const int blk_row, const int blk_col, |
| 245 | const TX_SIZE tx_size) { |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 246 | (void)r; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 247 | MACROBLOCKD *const xd = &dcb->xd; |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 248 | PLANE_TYPE plane_type = get_plane_type(plane); |
| 249 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 250 | const bool reduced_tx_set_used = cm->features.reduced_tx_set_used; |
Hui Su | 32fdb83 | 2019-10-22 10:20:03 -0700 | [diff] [blame] | 251 | // tx_type was read out in av1_read_coeffs_txb. |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 252 | const TX_TYPE tx_type = av1_get_tx_type(xd, plane_type, blk_row, blk_col, |
| 253 | tx_size, reduced_tx_set_used); |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 254 | |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 255 | uint8_t *dst = |
Hui Su | adda587 | 2019-12-09 10:08:49 -0800 | [diff] [blame] | 256 | &pd->dst.buf[(blk_row * pd->dst.stride + blk_col) << MI_SIZE_LOG2]; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 257 | inverse_transform_block(dcb, plane, tx_type, tx_size, dst, pd->dst.stride, |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 258 | reduced_tx_set_used); |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 259 | #if CONFIG_MISMATCH_DEBUG |
| 260 | int pixel_c, pixel_r; |
| 261 | BLOCK_SIZE bsize = txsize_to_bsize[tx_size]; |
| 262 | int blk_w = block_size_wide[bsize]; |
| 263 | int blk_h = block_size_high[bsize]; |
Urvang Joshi | bde9c5d | 2019-07-29 14:33:52 -0700 | [diff] [blame] | 264 | const int mi_row = -xd->mb_to_top_edge >> (3 + MI_SIZE_LOG2); |
| 265 | const int mi_col = -xd->mb_to_left_edge >> (3 + MI_SIZE_LOG2); |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 266 | mi_to_pixel_loc(&pixel_c, &pixel_r, mi_col, mi_row, blk_col, blk_row, |
| 267 | pd->subsampling_x, pd->subsampling_y); |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 268 | mismatch_check_block_tx(dst, pd->dst.stride, cm->current_frame.order_hint, |
| 269 | plane, pixel_c, pixel_r, blk_w, blk_h, |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 270 | xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH); |
| 271 | #endif |
Deepa K G | 610c9b8 | 2018-06-19 12:47:01 +0530 | [diff] [blame] | 272 | } |
| 273 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 274 | static inline void set_cb_buffer_offsets(DecoderCodingBlock *dcb, |
| 275 | TX_SIZE tx_size, int plane) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 276 | dcb->cb_offset[plane] += tx_size_wide[tx_size] * tx_size_high[tx_size]; |
| 277 | dcb->txb_offset[plane] = |
| 278 | dcb->cb_offset[plane] / (TX_SIZE_W_MIN * TX_SIZE_H_MIN); |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 279 | } |
| 280 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 281 | static inline void decode_reconstruct_tx(AV1_COMMON *cm, ThreadData *const td, |
| 282 | aom_reader *r, |
| 283 | MB_MODE_INFO *const mbmi, int plane, |
| 284 | BLOCK_SIZE plane_bsize, int blk_row, |
| 285 | int blk_col, int block, |
| 286 | TX_SIZE tx_size, int *eob_total) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 287 | DecoderCodingBlock *const dcb = &td->dcb; |
| 288 | MACROBLOCKD *const xd = &dcb->xd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 289 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 290 | const TX_SIZE plane_tx_size = |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 291 | plane ? av1_get_max_uv_txsize(mbmi->bsize, pd->subsampling_x, |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 292 | pd->subsampling_y) |
Hui Su | 7167d95 | 2018-02-01 16:33:12 -0800 | [diff] [blame] | 293 | : mbmi->inter_tx_size[av1_get_txb_size_index(plane_bsize, blk_row, |
| 294 | blk_col)]; |
Jingning Han | 5f61426 | 2016-10-27 14:27:43 -0700 | [diff] [blame] | 295 | // Scale to match transform block unit. |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 296 | const int max_blocks_high = max_block_high(xd, plane_bsize, plane); |
| 297 | const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 298 | |
| 299 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; |
| 300 | |
Debargha Mukherjee | 6396d3a | 2017-12-21 00:12:38 -0800 | [diff] [blame] | 301 | if (tx_size == plane_tx_size || plane) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 302 | td->read_coeffs_tx_inter_block_visit(cm, dcb, r, plane, blk_row, blk_col, |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 303 | tx_size); |
Jingning Han | 53c0896 | 2017-11-16 14:03:41 -0800 | [diff] [blame] | 304 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 305 | td->inverse_tx_inter_block_visit(cm, dcb, r, plane, blk_row, blk_col, |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 306 | tx_size); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 307 | eob_info *eob_data = dcb->eob_data[plane] + dcb->txb_offset[plane]; |
Deepa K G | 610c9b8 | 2018-06-19 12:47:01 +0530 | [diff] [blame] | 308 | *eob_total += eob_data->eob; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 309 | set_cb_buffer_offsets(dcb, tx_size, plane); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 310 | } else { |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 311 | const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; |
Urvang Joshi | dff57e0 | 2017-09-29 11:15:48 -0700 | [diff] [blame] | 312 | assert(IMPLIES(tx_size <= TX_4X4, sub_txs == tx_size)); |
| 313 | assert(IMPLIES(tx_size > TX_4X4, sub_txs < tx_size)); |
Yue Chen | 0797a20 | 2017-10-27 17:24:56 -0700 | [diff] [blame] | 314 | const int bsw = tx_size_wide_unit[sub_txs]; |
| 315 | const int bsh = tx_size_high_unit[sub_txs]; |
| 316 | const int sub_step = bsw * bsh; |
Wan-Teh Chang | 0cb03d9 | 2021-03-05 08:27:21 -0800 | [diff] [blame] | 317 | const int row_end = |
| 318 | AOMMIN(tx_size_high_unit[tx_size], max_blocks_high - blk_row); |
| 319 | const int col_end = |
| 320 | AOMMIN(tx_size_wide_unit[tx_size], max_blocks_wide - blk_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 321 | |
Yue Chen | 0797a20 | 2017-10-27 17:24:56 -0700 | [diff] [blame] | 322 | assert(bsw > 0 && bsh > 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 323 | |
Wan-Teh Chang | 0cb03d9 | 2021-03-05 08:27:21 -0800 | [diff] [blame] | 324 | for (int row = 0; row < row_end; row += bsh) { |
| 325 | const int offsetr = blk_row + row; |
| 326 | for (int col = 0; col < col_end; col += bsw) { |
Yue Chen | 0797a20 | 2017-10-27 17:24:56 -0700 | [diff] [blame] | 327 | const int offsetc = blk_col + col; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 328 | |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 329 | decode_reconstruct_tx(cm, td, r, mbmi, plane, plane_bsize, offsetr, |
| 330 | offsetc, block, sub_txs, eob_total); |
Yue Chen | 0797a20 | 2017-10-27 17:24:56 -0700 | [diff] [blame] | 331 | block += sub_step; |
| 332 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 336 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 337 | static inline void set_offsets(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 338 | BLOCK_SIZE bsize, int mi_row, int mi_col, int bw, |
| 339 | int bh, int x_mis, int y_mis) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 340 | const int num_planes = av1_num_planes(cm); |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 341 | const CommonModeInfoParams *const mi_params = &cm->mi_params; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 342 | const TileInfo *const tile = &xd->tile; |
| 343 | |
Urvang Joshi | 2603bfe | 2020-03-25 13:33:18 -0700 | [diff] [blame] | 344 | set_mi_offsets(mi_params, xd, mi_row, mi_col); |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 345 | xd->mi[0]->bsize = bsize; |
Angie Chiang | 394c337 | 2016-11-03 11:13:15 -0700 | [diff] [blame] | 346 | #if CONFIG_RD_DEBUG |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 347 | xd->mi[0]->mi_row = mi_row; |
| 348 | xd->mi[0]->mi_col = mi_col; |
Angie Chiang | 394c337 | 2016-11-03 11:13:15 -0700 | [diff] [blame] | 349 | #endif |
Yunqing Wang | b90a97a | 2017-10-24 11:50:15 -0700 | [diff] [blame] | 350 | |
| 351 | assert(x_mis && y_mis); |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 352 | for (int x = 1; x < x_mis; ++x) xd->mi[x] = xd->mi[0]; |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 353 | int idx = mi_params->mi_stride; |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 354 | for (int y = 1; y < y_mis; ++y) { |
Yunqing Wang | b90a97a | 2017-10-24 11:50:15 -0700 | [diff] [blame] | 355 | memcpy(&xd->mi[idx], &xd->mi[0], x_mis * sizeof(xd->mi[0])); |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 356 | idx += mi_params->mi_stride; |
Yunqing Wang | b90a97a | 2017-10-24 11:50:15 -0700 | [diff] [blame] | 357 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 358 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 359 | set_plane_n4(xd, bw, bh, num_planes); |
Urvang Joshi | 46ff552 | 2020-03-30 15:27:37 -0700 | [diff] [blame] | 360 | set_entropy_context(xd, mi_row, mi_col, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 361 | |
Urvang Joshi | 359dc2b | 2017-04-27 15:41:47 -0700 | [diff] [blame] | 362 | // Distance of Mb to the various image edges. These are specified to 8th pel |
| 363 | // as they are always compared to values that are in 1/8th pel units |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 364 | set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, mi_params->mi_rows, |
| 365 | mi_params->mi_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 366 | |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 367 | av1_setup_dst_planes(xd->plane, bsize, &cm->cur_frame->buf, mi_row, mi_col, 0, |
| 368 | num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 371 | static inline void decode_mbmi_block(AV1Decoder *const pbi, |
| 372 | DecoderCodingBlock *dcb, int mi_row, |
| 373 | int mi_col, aom_reader *r, |
| 374 | PARTITION_TYPE partition, |
| 375 | BLOCK_SIZE bsize) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 376 | AV1_COMMON *const cm = &pbi->common; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 377 | const SequenceHeader *const seq_params = cm->seq_params; |
Jingning Han | 85dc03f | 2016-12-06 16:03:10 -0800 | [diff] [blame] | 378 | const int bw = mi_size_wide[bsize]; |
| 379 | const int bh = mi_size_high[bsize]; |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 380 | const int x_mis = AOMMIN(bw, cm->mi_params.mi_cols - mi_col); |
| 381 | const int y_mis = AOMMIN(bh, cm->mi_params.mi_rows - mi_row); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 382 | MACROBLOCKD *const xd = &dcb->xd; |
Nathan E. Egge | ebbd479 | 2016-10-05 19:30:15 -0400 | [diff] [blame] | 383 | |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 384 | #if CONFIG_ACCOUNTING |
| 385 | aom_accounting_set_context(&pbi->accounting, mi_col, mi_row); |
| 386 | #endif |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 387 | set_offsets(cm, xd, bsize, mi_row, mi_col, bw, bh, x_mis, y_mis); |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 388 | xd->mi[0]->partition = partition; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 389 | av1_read_mode_info(pbi, dcb, r, x_mis, y_mis); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 390 | if (bsize >= BLOCK_8X8 && |
| 391 | (seq_params->subsampling_x || seq_params->subsampling_y)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 392 | const BLOCK_SIZE uv_subsize = |
Ivan Rosales | 4daac5e | 2022-11-22 08:46:35 -0800 | [diff] [blame] | 393 | av1_ss_size_lookup[bsize][seq_params->subsampling_x] |
| 394 | [seq_params->subsampling_y]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 395 | if (uv_subsize == BLOCK_INVALID) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 396 | aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 397 | "Invalid block size."); |
| 398 | } |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 399 | } |
| 400 | |
Ravi Chaudhary | 18c5f6f | 2018-06-06 13:43:07 +0530 | [diff] [blame] | 401 | typedef struct PadBlock { |
| 402 | int x0; |
| 403 | int x1; |
| 404 | int y0; |
| 405 | int y1; |
| 406 | } PadBlock; |
| 407 | |
Jerome Jiang | ebba9c7 | 2019-09-20 12:23:01 -0700 | [diff] [blame] | 408 | #if CONFIG_AV1_HIGHBITDEPTH |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 409 | static inline void highbd_build_mc_border(const uint8_t *src8, int src_stride, |
| 410 | uint8_t *dst8, int dst_stride, int x, |
| 411 | int y, int b_w, int b_h, int w, |
| 412 | int h) { |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 413 | // Get a pointer to the start of the real data for this row. |
| 414 | const uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
| 415 | uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); |
| 416 | const uint16_t *ref_row = src - x - y * src_stride; |
| 417 | |
| 418 | if (y >= h) |
| 419 | ref_row += (h - 1) * src_stride; |
| 420 | else if (y > 0) |
| 421 | ref_row += y * src_stride; |
| 422 | |
| 423 | do { |
| 424 | int right = 0, copy; |
| 425 | int left = x < 0 ? -x : 0; |
| 426 | |
| 427 | if (left > b_w) left = b_w; |
| 428 | |
| 429 | if (x + b_w > w) right = x + b_w - w; |
| 430 | |
| 431 | if (right > b_w) right = b_w; |
| 432 | |
| 433 | copy = b_w - left - right; |
| 434 | |
| 435 | if (left) aom_memset16(dst, ref_row[0], left); |
| 436 | |
| 437 | if (copy) memcpy(dst + left, ref_row + x + left, copy * sizeof(uint16_t)); |
| 438 | |
| 439 | if (right) aom_memset16(dst + left + copy, ref_row[w - 1], right); |
| 440 | |
| 441 | dst += dst_stride; |
| 442 | ++y; |
| 443 | |
| 444 | if (y > 0 && y < h) ref_row += src_stride; |
| 445 | } while (--b_h); |
| 446 | } |
Jerome Jiang | ebba9c7 | 2019-09-20 12:23:01 -0700 | [diff] [blame] | 447 | #endif // CONFIG_AV1_HIGHBITDEPTH |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 448 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 449 | static inline void build_mc_border(const uint8_t *src, int src_stride, |
| 450 | uint8_t *dst, int dst_stride, int x, int y, |
| 451 | int b_w, int b_h, int w, int h) { |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 452 | // Get a pointer to the start of the real data for this row. |
| 453 | const uint8_t *ref_row = src - x - y * src_stride; |
| 454 | |
| 455 | if (y >= h) |
| 456 | ref_row += (h - 1) * src_stride; |
| 457 | else if (y > 0) |
| 458 | ref_row += y * src_stride; |
| 459 | |
| 460 | do { |
| 461 | int right = 0, copy; |
| 462 | int left = x < 0 ? -x : 0; |
| 463 | |
| 464 | if (left > b_w) left = b_w; |
| 465 | |
| 466 | if (x + b_w > w) right = x + b_w - w; |
| 467 | |
| 468 | if (right > b_w) right = b_w; |
| 469 | |
| 470 | copy = b_w - left - right; |
| 471 | |
| 472 | if (left) memset(dst, ref_row[0], left); |
| 473 | |
| 474 | if (copy) memcpy(dst + left, ref_row + x + left, copy); |
| 475 | |
| 476 | if (right) memset(dst + left + copy, ref_row[w - 1], right); |
| 477 | |
| 478 | dst += dst_stride; |
| 479 | ++y; |
| 480 | |
| 481 | if (y > 0 && y < h) ref_row += src_stride; |
| 482 | } while (--b_h); |
| 483 | } |
| 484 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 485 | static inline int update_extend_mc_border_params( |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 486 | const struct scale_factors *const sf, struct buf_2d *const pre_buf, |
| 487 | MV32 scaled_mv, PadBlock *block, int subpel_x_mv, int subpel_y_mv, |
| 488 | int do_warp, int is_intrabc, int *x_pad, int *y_pad) { |
| 489 | const int is_scaled = av1_is_scaled(sf); |
| 490 | // Get reference width and height. |
| 491 | int frame_width = pre_buf->width; |
| 492 | int frame_height = pre_buf->height; |
| 493 | |
| 494 | // Do border extension if there is motion or |
| 495 | // width/height is not a multiple of 8 pixels. |
| 496 | if ((!is_intrabc) && (!do_warp) && |
| 497 | (is_scaled || scaled_mv.col || scaled_mv.row || (frame_width & 0x7) || |
| 498 | (frame_height & 0x7))) { |
| 499 | if (subpel_x_mv || (sf->x_step_q4 != SUBPEL_SHIFTS)) { |
| 500 | block->x0 -= AOM_INTERP_EXTEND - 1; |
| 501 | block->x1 += AOM_INTERP_EXTEND; |
| 502 | *x_pad = 1; |
| 503 | } |
| 504 | |
| 505 | if (subpel_y_mv || (sf->y_step_q4 != SUBPEL_SHIFTS)) { |
| 506 | block->y0 -= AOM_INTERP_EXTEND - 1; |
| 507 | block->y1 += AOM_INTERP_EXTEND; |
| 508 | *y_pad = 1; |
| 509 | } |
| 510 | |
| 511 | // Skip border extension if block is inside the frame. |
| 512 | if (block->x0 < 0 || block->x1 > frame_width - 1 || block->y0 < 0 || |
| 513 | block->y1 > frame_height - 1) { |
| 514 | return 1; |
| 515 | } |
| 516 | } |
| 517 | return 0; |
| 518 | } |
| 519 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 520 | static inline void extend_mc_border(const struct scale_factors *const sf, |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 521 | struct buf_2d *const pre_buf, |
| 522 | MV32 scaled_mv, PadBlock block, |
| 523 | int subpel_x_mv, int subpel_y_mv, |
| 524 | int do_warp, int is_intrabc, int highbd, |
| 525 | uint8_t *mc_buf, uint8_t **pre, |
| 526 | int *src_stride) { |
| 527 | int x_pad = 0, y_pad = 0; |
| 528 | if (update_extend_mc_border_params(sf, pre_buf, scaled_mv, &block, |
| 529 | subpel_x_mv, subpel_y_mv, do_warp, |
| 530 | is_intrabc, &x_pad, &y_pad)) { |
| 531 | // Get reference block pointer. |
| 532 | const uint8_t *const buf_ptr = |
| 533 | pre_buf->buf0 + block.y0 * pre_buf->stride + block.x0; |
| 534 | int buf_stride = pre_buf->stride; |
| 535 | const int b_w = block.x1 - block.x0; |
| 536 | const int b_h = block.y1 - block.y0; |
| 537 | |
Jerome Jiang | ebba9c7 | 2019-09-20 12:23:01 -0700 | [diff] [blame] | 538 | #if CONFIG_AV1_HIGHBITDEPTH |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 539 | // Extend the border. |
| 540 | if (highbd) { |
| 541 | highbd_build_mc_border(buf_ptr, buf_stride, mc_buf, b_w, block.x0, |
| 542 | block.y0, b_w, b_h, pre_buf->width, |
| 543 | pre_buf->height); |
| 544 | } else { |
| 545 | build_mc_border(buf_ptr, buf_stride, mc_buf, b_w, block.x0, block.y0, b_w, |
| 546 | b_h, pre_buf->width, pre_buf->height); |
| 547 | } |
Jerome Jiang | ebba9c7 | 2019-09-20 12:23:01 -0700 | [diff] [blame] | 548 | #else |
| 549 | (void)highbd; |
| 550 | build_mc_border(buf_ptr, buf_stride, mc_buf, b_w, block.x0, block.y0, b_w, |
| 551 | b_h, pre_buf->width, pre_buf->height); |
| 552 | #endif |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 553 | *src_stride = b_w; |
| 554 | *pre = mc_buf + y_pad * (AOM_INTERP_EXTEND - 1) * b_w + |
| 555 | x_pad * (AOM_INTERP_EXTEND - 1); |
| 556 | } |
| 557 | } |
| 558 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 559 | static inline void dec_calc_subpel_params( |
chiyotsai | f4c53bd | 2022-11-08 12:55:18 -0800 | [diff] [blame] | 560 | const MV *const src_mv, InterPredParams *const inter_pred_params, |
| 561 | const MACROBLOCKD *const xd, int mi_x, int mi_y, uint8_t **pre, |
| 562 | SubpelParams *subpel_params, int *src_stride, PadBlock *block, |
| 563 | MV32 *scaled_mv, int *subpel_x_mv, int *subpel_y_mv) { |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 564 | const struct scale_factors *sf = inter_pred_params->scale_factors; |
| 565 | struct buf_2d *pre_buf = &inter_pred_params->ref_frame_buf; |
| 566 | const int bw = inter_pred_params->block_width; |
| 567 | const int bh = inter_pred_params->block_height; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 568 | const int is_scaled = av1_is_scaled(sf); |
| 569 | if (is_scaled) { |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 570 | int ssx = inter_pred_params->subsampling_x; |
| 571 | int ssy = inter_pred_params->subsampling_y; |
| 572 | int orig_pos_y = inter_pred_params->pix_row << SUBPEL_BITS; |
| 573 | orig_pos_y += src_mv->row * (1 << (1 - ssy)); |
| 574 | int orig_pos_x = inter_pred_params->pix_col << SUBPEL_BITS; |
| 575 | orig_pos_x += src_mv->col * (1 << (1 - ssx)); |
chiyotsai | fee3f75 | 2022-11-08 15:56:34 -0800 | [diff] [blame] | 576 | int pos_y = av1_scaled_y(orig_pos_y, sf); |
| 577 | int pos_x = av1_scaled_x(orig_pos_x, sf); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 578 | pos_x += SCALE_EXTRA_OFF; |
| 579 | pos_y += SCALE_EXTRA_OFF; |
| 580 | |
| 581 | const int top = -AOM_LEFT_TOP_MARGIN_SCALED(ssy); |
| 582 | const int left = -AOM_LEFT_TOP_MARGIN_SCALED(ssx); |
| 583 | const int bottom = (pre_buf->height + AOM_INTERP_EXTEND) |
| 584 | << SCALE_SUBPEL_BITS; |
| 585 | const int right = (pre_buf->width + AOM_INTERP_EXTEND) << SCALE_SUBPEL_BITS; |
| 586 | pos_y = clamp(pos_y, top, bottom); |
| 587 | pos_x = clamp(pos_x, left, right); |
| 588 | |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 589 | subpel_params->subpel_x = pos_x & SCALE_SUBPEL_MASK; |
| 590 | subpel_params->subpel_y = pos_y & SCALE_SUBPEL_MASK; |
| 591 | subpel_params->xs = sf->x_step_q4; |
| 592 | subpel_params->ys = sf->y_step_q4; |
Ravi Chaudhary | 18c5f6f | 2018-06-06 13:43:07 +0530 | [diff] [blame] | 593 | |
| 594 | // Get reference block top left coordinate. |
| 595 | block->x0 = pos_x >> SCALE_SUBPEL_BITS; |
| 596 | block->y0 = pos_y >> SCALE_SUBPEL_BITS; |
| 597 | |
| 598 | // Get reference block bottom right coordinate. |
| 599 | block->x1 = |
| 600 | ((pos_x + (bw - 1) * subpel_params->xs) >> SCALE_SUBPEL_BITS) + 1; |
| 601 | block->y1 = |
| 602 | ((pos_y + (bh - 1) * subpel_params->ys) >> SCALE_SUBPEL_BITS) + 1; |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 603 | |
Remy Foray | 9333b31 | 2018-11-28 09:17:05 +0000 | [diff] [blame] | 604 | MV temp_mv; |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 605 | temp_mv = clamp_mv_to_umv_border_sb(xd, src_mv, bw, bh, |
| 606 | inter_pred_params->subsampling_x, |
| 607 | inter_pred_params->subsampling_y); |
| 608 | *scaled_mv = av1_scale_mv(&temp_mv, mi_x, mi_y, sf); |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 609 | scaled_mv->row += SCALE_EXTRA_OFF; |
| 610 | scaled_mv->col += SCALE_EXTRA_OFF; |
| 611 | |
| 612 | *subpel_x_mv = scaled_mv->col & SCALE_SUBPEL_MASK; |
| 613 | *subpel_y_mv = scaled_mv->row & SCALE_SUBPEL_MASK; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 614 | } else { |
Ravi Chaudhary | 18c5f6f | 2018-06-06 13:43:07 +0530 | [diff] [blame] | 615 | // Get block position in current frame. |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 616 | int pos_x = inter_pred_params->pix_col << SUBPEL_BITS; |
| 617 | int pos_y = inter_pred_params->pix_row << SUBPEL_BITS; |
Ravi Chaudhary | 18c5f6f | 2018-06-06 13:43:07 +0530 | [diff] [blame] | 618 | |
Remy Foray | 9333b31 | 2018-11-28 09:17:05 +0000 | [diff] [blame] | 619 | const MV mv_q4 = clamp_mv_to_umv_border_sb( |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 620 | xd, src_mv, bw, bh, inter_pred_params->subsampling_x, |
| 621 | inter_pred_params->subsampling_y); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 622 | subpel_params->xs = subpel_params->ys = SCALE_SUBPEL_SHIFTS; |
| 623 | subpel_params->subpel_x = (mv_q4.col & SUBPEL_MASK) << SCALE_EXTRA_BITS; |
| 624 | subpel_params->subpel_y = (mv_q4.row & SUBPEL_MASK) << SCALE_EXTRA_BITS; |
Ravi Chaudhary | 18c5f6f | 2018-06-06 13:43:07 +0530 | [diff] [blame] | 625 | |
| 626 | // Get reference block top left coordinate. |
| 627 | pos_x += mv_q4.col; |
| 628 | pos_y += mv_q4.row; |
| 629 | block->x0 = pos_x >> SUBPEL_BITS; |
| 630 | block->y0 = pos_y >> SUBPEL_BITS; |
| 631 | |
| 632 | // Get reference block bottom right coordinate. |
| 633 | block->x1 = (pos_x >> SUBPEL_BITS) + (bw - 1) + 1; |
| 634 | block->y1 = (pos_y >> SUBPEL_BITS) + (bh - 1) + 1; |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 635 | |
| 636 | scaled_mv->row = mv_q4.row; |
| 637 | scaled_mv->col = mv_q4.col; |
| 638 | *subpel_x_mv = scaled_mv->col & SUBPEL_MASK; |
| 639 | *subpel_y_mv = scaled_mv->row & SUBPEL_MASK; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 640 | } |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 641 | *pre = pre_buf->buf0 + block->y0 * pre_buf->stride + block->x0; |
| 642 | *src_stride = pre_buf->stride; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 643 | } |
| 644 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 645 | static inline void dec_calc_subpel_params_and_extend( |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 646 | const MV *const src_mv, InterPredParams *const inter_pred_params, |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 647 | MACROBLOCKD *const xd, int mi_x, int mi_y, int ref, uint8_t **mc_buf, |
| 648 | uint8_t **pre, SubpelParams *subpel_params, int *src_stride) { |
Urvang Joshi | 628177a | 2019-09-26 16:50:36 -0700 | [diff] [blame] | 649 | PadBlock block; |
| 650 | MV32 scaled_mv; |
| 651 | int subpel_x_mv, subpel_y_mv; |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 652 | dec_calc_subpel_params(src_mv, inter_pred_params, xd, mi_x, mi_y, pre, |
| 653 | subpel_params, src_stride, &block, &scaled_mv, |
Urvang Joshi | 628177a | 2019-09-26 16:50:36 -0700 | [diff] [blame] | 654 | &subpel_x_mv, &subpel_y_mv); |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 655 | extend_mc_border( |
| 656 | inter_pred_params->scale_factors, &inter_pred_params->ref_frame_buf, |
| 657 | scaled_mv, block, subpel_x_mv, subpel_y_mv, |
| 658 | inter_pred_params->mode == WARP_PRED, inter_pred_params->is_intrabc, |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 659 | inter_pred_params->use_hbd_buf, mc_buf[ref], pre, src_stride); |
Urvang Joshi | 63de7bb | 2020-04-10 15:41:39 -0700 | [diff] [blame] | 660 | } |
| 661 | |
chiyotsai | 740d491 | 2022-11-10 14:59:18 -0800 | [diff] [blame] | 662 | #define IS_DEC 1 |
chiyotsai | f4c53bd | 2022-11-08 12:55:18 -0800 | [diff] [blame] | 663 | #include "av1/common/reconinter_template.inc" |
chiyotsai | 740d491 | 2022-11-10 14:59:18 -0800 | [diff] [blame] | 664 | #undef IS_DEC |
chiyotsai | f4c53bd | 2022-11-08 12:55:18 -0800 | [diff] [blame] | 665 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 666 | static void dec_build_inter_predictors(const AV1_COMMON *cm, |
| 667 | DecoderCodingBlock *dcb, int plane, |
| 668 | const MB_MODE_INFO *mi, |
Urvang Joshi | 628177a | 2019-09-26 16:50:36 -0700 | [diff] [blame] | 669 | int build_for_obmc, int bw, int bh, |
| 670 | int mi_x, int mi_y) { |
chiyotsai | 740d491 | 2022-11-10 14:59:18 -0800 | [diff] [blame] | 671 | build_inter_predictors(cm, &dcb->xd, plane, mi, build_for_obmc, bw, bh, mi_x, |
| 672 | mi_y, dcb->mc_buf); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 673 | } |
| 674 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 675 | static inline void dec_build_inter_predictor(const AV1_COMMON *cm, |
| 676 | DecoderCodingBlock *dcb, |
| 677 | int mi_row, int mi_col, |
| 678 | BLOCK_SIZE bsize) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 679 | MACROBLOCKD *const xd = &dcb->xd; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 680 | const int num_planes = av1_num_planes(cm); |
Xin Zhao | c420ec0 | 2020-04-02 10:53:01 -0700 | [diff] [blame] | 681 | for (int plane = 0; plane < num_planes; ++plane) { |
| 682 | if (plane && !xd->is_chroma_ref) break; |
| 683 | const int mi_x = mi_col * MI_SIZE; |
| 684 | const int mi_y = mi_row * MI_SIZE; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 685 | dec_build_inter_predictors(cm, dcb, plane, xd->mi[0], 0, |
Xin Zhao | c420ec0 | 2020-04-02 10:53:01 -0700 | [diff] [blame] | 686 | xd->plane[plane].width, xd->plane[plane].height, |
| 687 | mi_x, mi_y); |
| 688 | if (is_interintra_pred(xd->mi[0])) { |
| 689 | BUFFER_SET ctx = { { xd->plane[0].dst.buf, xd->plane[1].dst.buf, |
| 690 | xd->plane[2].dst.buf }, |
| 691 | { xd->plane[0].dst.stride, xd->plane[1].dst.stride, |
| 692 | xd->plane[2].dst.stride } }; |
| 693 | av1_build_interintra_predictor(cm, xd, xd->plane[plane].dst.buf, |
| 694 | xd->plane[plane].dst.stride, &ctx, plane, |
| 695 | bsize); |
| 696 | } |
| 697 | } |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 698 | } |
| 699 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 700 | static inline void dec_build_prediction_by_above_pred( |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 701 | MACROBLOCKD *const xd, int rel_mi_row, int rel_mi_col, uint8_t op_mi_size, |
Jingning Han | b726c56 | 2019-11-12 15:45:50 -0800 | [diff] [blame] | 702 | int dir, MB_MODE_INFO *above_mbmi, void *fun_ctxt, const int num_planes) { |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 703 | struct build_prediction_ctxt *ctxt = (struct build_prediction_ctxt *)fun_ctxt; |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 704 | const int above_mi_col = xd->mi_col + rel_mi_col; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 705 | int mi_x, mi_y; |
| 706 | MB_MODE_INFO backup_mbmi = *above_mbmi; |
| 707 | |
Jingning Han | b726c56 | 2019-11-12 15:45:50 -0800 | [diff] [blame] | 708 | (void)rel_mi_row; |
| 709 | (void)dir; |
| 710 | |
| 711 | av1_setup_build_prediction_by_above_pred(xd, rel_mi_col, op_mi_size, |
Deepa K G | 77e15a4 | 2018-06-11 15:40:00 +0530 | [diff] [blame] | 712 | &backup_mbmi, ctxt, num_planes); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 713 | mi_x = above_mi_col << MI_SIZE_LOG2; |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 714 | mi_y = xd->mi_row << MI_SIZE_LOG2; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 715 | |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 716 | const BLOCK_SIZE bsize = xd->mi[0]->bsize; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 717 | |
| 718 | for (int j = 0; j < num_planes; ++j) { |
| 719 | const struct macroblockd_plane *pd = &xd->plane[j]; |
Jingning Han | b726c56 | 2019-11-12 15:45:50 -0800 | [diff] [blame] | 720 | int bw = (op_mi_size * MI_SIZE) >> pd->subsampling_x; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 721 | int bh = clamp(block_size_high[bsize] >> (pd->subsampling_y + 1), 4, |
| 722 | block_size_high[BLOCK_64X64] >> (pd->subsampling_y + 1)); |
| 723 | |
| 724 | if (av1_skip_u4x4_pred_in_obmc(bsize, pd, 0)) continue; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 725 | dec_build_inter_predictors(ctxt->cm, (DecoderCodingBlock *)ctxt->dcb, j, |
| 726 | &backup_mbmi, 1, bw, bh, mi_x, mi_y); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 727 | } |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 728 | } |
| 729 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 730 | static inline void dec_build_prediction_by_above_preds( |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 731 | const AV1_COMMON *cm, DecoderCodingBlock *dcb, |
| 732 | uint8_t *tmp_buf[MAX_MB_PLANE], int tmp_width[MAX_MB_PLANE], |
| 733 | int tmp_height[MAX_MB_PLANE], int tmp_stride[MAX_MB_PLANE]) { |
| 734 | MACROBLOCKD *const xd = &dcb->xd; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 735 | if (!xd->up_available) return; |
| 736 | |
| 737 | // Adjust mb_to_bottom_edge to have the correct value for the OBMC |
| 738 | // prediction block. This is half the height of the original block, |
| 739 | // except for 128-wide blocks, where we only use a height of 32. |
Urvang Joshi | 33930b8 | 2020-04-06 12:41:27 -0700 | [diff] [blame] | 740 | const int this_height = xd->height * MI_SIZE; |
| 741 | const int pred_height = AOMMIN(this_height / 2, 32); |
chiyotsai | 87bb805 | 2020-02-12 16:56:33 -0800 | [diff] [blame] | 742 | xd->mb_to_bottom_edge += GET_MV_SUBPEL(this_height - pred_height); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 743 | struct build_prediction_ctxt ctxt = { |
| 744 | cm, tmp_buf, tmp_width, tmp_height, tmp_stride, xd->mb_to_right_edge, dcb |
| 745 | }; |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 746 | const BLOCK_SIZE bsize = xd->mi[0]->bsize; |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 747 | foreach_overlappable_nb_above(cm, xd, |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 748 | max_neighbor_obmc[mi_size_wide_log2[bsize]], |
| 749 | dec_build_prediction_by_above_pred, &ctxt); |
| 750 | |
chiyotsai | 87bb805 | 2020-02-12 16:56:33 -0800 | [diff] [blame] | 751 | xd->mb_to_left_edge = -GET_MV_SUBPEL(xd->mi_col * MI_SIZE); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 752 | xd->mb_to_right_edge = ctxt.mb_to_far_edge; |
chiyotsai | 87bb805 | 2020-02-12 16:56:33 -0800 | [diff] [blame] | 753 | xd->mb_to_bottom_edge -= GET_MV_SUBPEL(this_height - pred_height); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 754 | } |
| 755 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 756 | static inline void dec_build_prediction_by_left_pred( |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 757 | MACROBLOCKD *const xd, int rel_mi_row, int rel_mi_col, uint8_t op_mi_size, |
Jingning Han | b726c56 | 2019-11-12 15:45:50 -0800 | [diff] [blame] | 758 | int dir, MB_MODE_INFO *left_mbmi, void *fun_ctxt, const int num_planes) { |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 759 | struct build_prediction_ctxt *ctxt = (struct build_prediction_ctxt *)fun_ctxt; |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 760 | const int left_mi_row = xd->mi_row + rel_mi_row; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 761 | int mi_x, mi_y; |
| 762 | MB_MODE_INFO backup_mbmi = *left_mbmi; |
| 763 | |
Jingning Han | b726c56 | 2019-11-12 15:45:50 -0800 | [diff] [blame] | 764 | (void)rel_mi_col; |
| 765 | (void)dir; |
| 766 | |
| 767 | av1_setup_build_prediction_by_left_pred(xd, rel_mi_row, op_mi_size, |
Deepa K G | 77e15a4 | 2018-06-11 15:40:00 +0530 | [diff] [blame] | 768 | &backup_mbmi, ctxt, num_planes); |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 769 | mi_x = xd->mi_col << MI_SIZE_LOG2; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 770 | mi_y = left_mi_row << MI_SIZE_LOG2; |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 771 | const BLOCK_SIZE bsize = xd->mi[0]->bsize; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 772 | |
| 773 | for (int j = 0; j < num_planes; ++j) { |
| 774 | const struct macroblockd_plane *pd = &xd->plane[j]; |
| 775 | int bw = clamp(block_size_wide[bsize] >> (pd->subsampling_x + 1), 4, |
| 776 | block_size_wide[BLOCK_64X64] >> (pd->subsampling_x + 1)); |
Jingning Han | b726c56 | 2019-11-12 15:45:50 -0800 | [diff] [blame] | 777 | int bh = (op_mi_size << MI_SIZE_LOG2) >> pd->subsampling_y; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 778 | |
| 779 | if (av1_skip_u4x4_pred_in_obmc(bsize, pd, 1)) continue; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 780 | dec_build_inter_predictors(ctxt->cm, (DecoderCodingBlock *)ctxt->dcb, j, |
| 781 | &backup_mbmi, 1, bw, bh, mi_x, mi_y); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 782 | } |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 783 | } |
| 784 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 785 | static inline void dec_build_prediction_by_left_preds( |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 786 | const AV1_COMMON *cm, DecoderCodingBlock *dcb, |
| 787 | uint8_t *tmp_buf[MAX_MB_PLANE], int tmp_width[MAX_MB_PLANE], |
| 788 | int tmp_height[MAX_MB_PLANE], int tmp_stride[MAX_MB_PLANE]) { |
| 789 | MACROBLOCKD *const xd = &dcb->xd; |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 790 | if (!xd->left_available) return; |
| 791 | |
| 792 | // Adjust mb_to_right_edge to have the correct value for the OBMC |
| 793 | // prediction block. This is half the width of the original block, |
| 794 | // except for 128-wide blocks, where we only use a width of 32. |
Urvang Joshi | 33930b8 | 2020-04-06 12:41:27 -0700 | [diff] [blame] | 795 | const int this_width = xd->width * MI_SIZE; |
| 796 | const int pred_width = AOMMIN(this_width / 2, 32); |
chiyotsai | 87bb805 | 2020-02-12 16:56:33 -0800 | [diff] [blame] | 797 | xd->mb_to_right_edge += GET_MV_SUBPEL(this_width - pred_width); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 798 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 799 | struct build_prediction_ctxt ctxt = { |
| 800 | cm, tmp_buf, tmp_width, tmp_height, tmp_stride, xd->mb_to_bottom_edge, dcb |
| 801 | }; |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 802 | const BLOCK_SIZE bsize = xd->mi[0]->bsize; |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 803 | foreach_overlappable_nb_left(cm, xd, |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 804 | max_neighbor_obmc[mi_size_high_log2[bsize]], |
| 805 | dec_build_prediction_by_left_pred, &ctxt); |
| 806 | |
chiyotsai | 87bb805 | 2020-02-12 16:56:33 -0800 | [diff] [blame] | 807 | xd->mb_to_top_edge = -GET_MV_SUBPEL(xd->mi_row * MI_SIZE); |
| 808 | xd->mb_to_right_edge -= GET_MV_SUBPEL(this_width - pred_width); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 809 | xd->mb_to_bottom_edge = ctxt.mb_to_far_edge; |
| 810 | } |
| 811 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 812 | static inline void dec_build_obmc_inter_predictors_sb(const AV1_COMMON *cm, |
| 813 | DecoderCodingBlock *dcb) { |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 814 | const int num_planes = av1_num_planes(cm); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 815 | uint8_t *dst_buf1[MAX_MB_PLANE], *dst_buf2[MAX_MB_PLANE]; |
| 816 | int dst_stride1[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE }; |
| 817 | int dst_stride2[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE }; |
| 818 | int dst_width1[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE }; |
| 819 | int dst_width2[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE }; |
| 820 | int dst_height1[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE }; |
| 821 | int dst_height2[MAX_MB_PLANE] = { MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE }; |
| 822 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 823 | MACROBLOCKD *const xd = &dcb->xd; |
Urvang Joshi | 7ccbade | 2020-04-16 12:48:42 -0700 | [diff] [blame] | 824 | av1_setup_obmc_dst_bufs(xd, dst_buf1, dst_buf2); |
Jerome Jiang | ebba9c7 | 2019-09-20 12:23:01 -0700 | [diff] [blame] | 825 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 826 | dec_build_prediction_by_above_preds(cm, dcb, dst_buf1, dst_width1, |
| 827 | dst_height1, dst_stride1); |
| 828 | dec_build_prediction_by_left_preds(cm, dcb, dst_buf2, dst_width2, dst_height2, |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 829 | dst_stride2); |
| 830 | const int mi_row = xd->mi_row; |
| 831 | const int mi_col = xd->mi_col; |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 832 | av1_setup_dst_planes(xd->plane, xd->mi[0]->bsize, &cm->cur_frame->buf, mi_row, |
| 833 | mi_col, 0, num_planes); |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 834 | av1_build_obmc_inter_prediction(cm, xd, dst_buf1, dst_stride1, dst_buf2, |
| 835 | dst_stride2); |
Ravi Chaudhary | 6ac4b13 | 2018-05-08 16:34:44 +0530 | [diff] [blame] | 836 | } |
| 837 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 838 | static inline void cfl_store_inter_block(AV1_COMMON *const cm, |
| 839 | MACROBLOCKD *const xd) { |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 840 | MB_MODE_INFO *mbmi = xd->mi[0]; |
| 841 | if (store_cfl_required(cm, xd)) { |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 842 | cfl_store_block(xd, mbmi->bsize, mbmi->tx_size); |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 846 | static inline void predict_inter_block(AV1_COMMON *const cm, |
| 847 | DecoderCodingBlock *dcb, |
| 848 | BLOCK_SIZE bsize) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 849 | MACROBLOCKD *const xd = &dcb->xd; |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 850 | MB_MODE_INFO *mbmi = xd->mi[0]; |
| 851 | const int num_planes = av1_num_planes(cm); |
Hui Su | b94cd5e | 2019-11-06 12:05:47 -0800 | [diff] [blame] | 852 | const int mi_row = xd->mi_row; |
| 853 | const int mi_col = xd->mi_col; |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 854 | for (int ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) { |
| 855 | const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; |
| 856 | if (frame < LAST_FRAME) { |
| 857 | assert(is_intrabc_block(mbmi)); |
| 858 | assert(frame == INTRA_FRAME); |
| 859 | assert(ref == 0); |
| 860 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 861 | const RefCntBuffer *ref_buf = get_ref_frame_buf(cm, frame); |
| 862 | const struct scale_factors *ref_scale_factors = |
| 863 | get_ref_scale_factors_const(cm, frame); |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 864 | |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 865 | xd->block_ref_scale_factors[ref] = ref_scale_factors; |
| 866 | av1_setup_pre_planes(xd, ref, &ref_buf->buf, mi_row, mi_col, |
| 867 | ref_scale_factors, num_planes); |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 871 | dec_build_inter_predictor(cm, dcb, mi_row, mi_col, bsize); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 872 | if (mbmi->motion_mode == OBMC_CAUSAL) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 873 | dec_build_obmc_inter_predictors_sb(cm, dcb); |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 874 | } |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 875 | #if CONFIG_MISMATCH_DEBUG |
| 876 | for (int plane = 0; plane < num_planes; ++plane) { |
| 877 | const struct macroblockd_plane *pd = &xd->plane[plane]; |
| 878 | int pixel_c, pixel_r; |
| 879 | mi_to_pixel_loc(&pixel_c, &pixel_r, mi_col, mi_row, 0, 0, pd->subsampling_x, |
| 880 | pd->subsampling_y); |
| 881 | if (!is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x, |
| 882 | pd->subsampling_y)) |
| 883 | continue; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 884 | mismatch_check_block_pre(pd->dst.buf, pd->dst.stride, |
| 885 | cm->current_frame.order_hint, plane, pixel_c, |
| 886 | pixel_r, pd->width, pd->height, |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 887 | xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH); |
| 888 | } |
| 889 | #endif |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 890 | } |
| 891 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 892 | static inline void set_color_index_map_offset(MACROBLOCKD *const xd, int plane, |
| 893 | aom_reader *r) { |
Deepa K G | 99f7ddb | 2018-06-20 11:21:21 +0530 | [diff] [blame] | 894 | (void)r; |
| 895 | Av1ColorMapParam params; |
| 896 | const MB_MODE_INFO *const mbmi = xd->mi[0]; |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 897 | av1_get_block_dimensions(mbmi->bsize, plane, xd, ¶ms.plane_width, |
Deepa K G | 99f7ddb | 2018-06-20 11:21:21 +0530 | [diff] [blame] | 898 | ¶ms.plane_height, NULL, NULL); |
| 899 | xd->color_index_map_offset[plane] += params.plane_width * params.plane_height; |
| 900 | } |
| 901 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 902 | static inline void decode_token_recon_block(AV1Decoder *const pbi, |
| 903 | ThreadData *const td, aom_reader *r, |
| 904 | BLOCK_SIZE bsize) { |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 905 | AV1_COMMON *const cm = &pbi->common; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 906 | DecoderCodingBlock *const dcb = &td->dcb; |
| 907 | MACROBLOCKD *const xd = &dcb->xd; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 908 | const int num_planes = av1_num_planes(cm); |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 909 | MB_MODE_INFO *mbmi = xd->mi[0]; |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 910 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 911 | if (!is_inter_block(mbmi)) { |
Jingning Han | ad54a98 | 2018-01-12 14:40:29 -0800 | [diff] [blame] | 912 | int row, col; |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 913 | assert(bsize == get_plane_block_size(bsize, xd->plane[0].subsampling_x, |
| 914 | xd->plane[0].subsampling_y)); |
Yushin Cho | ca63a8b | 2018-04-20 16:46:36 -0700 | [diff] [blame] | 915 | const int max_blocks_wide = max_block_wide(xd, bsize, 0); |
| 916 | const int max_blocks_high = max_block_high(xd, bsize, 0); |
| 917 | const BLOCK_SIZE max_unit_bsize = BLOCK_64X64; |
Hui Su | adda587 | 2019-12-09 10:08:49 -0800 | [diff] [blame] | 918 | int mu_blocks_wide = mi_size_wide[max_unit_bsize]; |
| 919 | int mu_blocks_high = mi_size_high[max_unit_bsize]; |
Jingning Han | ad54a98 | 2018-01-12 14:40:29 -0800 | [diff] [blame] | 920 | mu_blocks_wide = AOMMIN(max_blocks_wide, mu_blocks_wide); |
| 921 | mu_blocks_high = AOMMIN(max_blocks_high, mu_blocks_high); |
Jingning Han | 5b70174 | 2017-07-19 14:39:07 -0700 | [diff] [blame] | 922 | |
Jingning Han | ad54a98 | 2018-01-12 14:40:29 -0800 | [diff] [blame] | 923 | for (row = 0; row < max_blocks_high; row += mu_blocks_high) { |
| 924 | for (col = 0; col < max_blocks_wide; col += mu_blocks_wide) { |
| 925 | for (int plane = 0; plane < num_planes; ++plane) { |
Hui Su | 474e1e1 | 2020-02-27 15:46:36 -0800 | [diff] [blame] | 926 | if (plane && !xd->is_chroma_ref) break; |
Jingning Han | ad54a98 | 2018-01-12 14:40:29 -0800 | [diff] [blame] | 927 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
Jingning Han | ad54a98 | 2018-01-12 14:40:29 -0800 | [diff] [blame] | 928 | const TX_SIZE tx_size = av1_get_tx_size(plane, xd); |
| 929 | const int stepr = tx_size_high_unit[tx_size]; |
| 930 | const int stepc = tx_size_wide_unit[tx_size]; |
| 931 | |
| 932 | const int unit_height = ROUND_POWER_OF_TWO( |
| 933 | AOMMIN(mu_blocks_high + row, max_blocks_high), pd->subsampling_y); |
| 934 | const int unit_width = ROUND_POWER_OF_TWO( |
| 935 | AOMMIN(mu_blocks_wide + col, max_blocks_wide), pd->subsampling_x); |
| 936 | |
| 937 | for (int blk_row = row >> pd->subsampling_y; blk_row < unit_height; |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 938 | blk_row += stepr) { |
Jingning Han | ad54a98 | 2018-01-12 14:40:29 -0800 | [diff] [blame] | 939 | for (int blk_col = col >> pd->subsampling_x; blk_col < unit_width; |
Deepa K G | 4960730 | 2018-06-18 14:00:57 +0530 | [diff] [blame] | 940 | blk_col += stepc) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 941 | td->read_coeffs_tx_intra_block_visit(cm, dcb, r, plane, blk_row, |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 942 | blk_col, tx_size); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 943 | td->predict_and_recon_intra_block_visit( |
| 944 | cm, dcb, r, plane, blk_row, blk_col, tx_size); |
| 945 | set_cb_buffer_offsets(dcb, tx_size, plane); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | } else { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 952 | td->predict_inter_block_visit(cm, dcb, bsize); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 953 | // Reconstruction |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 954 | if (!mbmi->skip_txfm) { |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 955 | int eobtotal = 0; |
| 956 | |
| 957 | const int max_blocks_wide = max_block_wide(xd, bsize, 0); |
| 958 | const int max_blocks_high = max_block_high(xd, bsize, 0); |
| 959 | int row, col; |
| 960 | |
| 961 | const BLOCK_SIZE max_unit_bsize = BLOCK_64X64; |
| 962 | assert(max_unit_bsize == |
| 963 | get_plane_block_size(BLOCK_64X64, xd->plane[0].subsampling_x, |
| 964 | xd->plane[0].subsampling_y)); |
Hui Su | adda587 | 2019-12-09 10:08:49 -0800 | [diff] [blame] | 965 | int mu_blocks_wide = mi_size_wide[max_unit_bsize]; |
| 966 | int mu_blocks_high = mi_size_high[max_unit_bsize]; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 967 | |
| 968 | mu_blocks_wide = AOMMIN(max_blocks_wide, mu_blocks_wide); |
| 969 | mu_blocks_high = AOMMIN(max_blocks_high, mu_blocks_high); |
| 970 | |
| 971 | for (row = 0; row < max_blocks_high; row += mu_blocks_high) { |
| 972 | for (col = 0; col < max_blocks_wide; col += mu_blocks_wide) { |
| 973 | for (int plane = 0; plane < num_planes; ++plane) { |
Hui Su | 474e1e1 | 2020-02-27 15:46:36 -0800 | [diff] [blame] | 974 | if (plane && !xd->is_chroma_ref) break; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 975 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
Hui Su | 56e838f | 2019-12-04 14:48:30 -0800 | [diff] [blame] | 976 | const int ss_x = pd->subsampling_x; |
| 977 | const int ss_y = pd->subsampling_y; |
Hui Su | 56e838f | 2019-12-04 14:48:30 -0800 | [diff] [blame] | 978 | const BLOCK_SIZE plane_bsize = |
Hui Su | aadb0b4 | 2019-12-06 15:56:47 -0800 | [diff] [blame] | 979 | get_plane_block_size(bsize, ss_x, ss_y); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 980 | const TX_SIZE max_tx_size = |
| 981 | get_vartx_max_txsize(xd, plane_bsize, plane); |
| 982 | const int bh_var_tx = tx_size_high_unit[max_tx_size]; |
| 983 | const int bw_var_tx = tx_size_wide_unit[max_tx_size]; |
| 984 | int block = 0; |
| 985 | int step = |
| 986 | tx_size_wide_unit[max_tx_size] * tx_size_high_unit[max_tx_size]; |
| 987 | int blk_row, blk_col; |
| 988 | const int unit_height = ROUND_POWER_OF_TWO( |
Hui Su | 56e838f | 2019-12-04 14:48:30 -0800 | [diff] [blame] | 989 | AOMMIN(mu_blocks_high + row, max_blocks_high), ss_y); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 990 | const int unit_width = ROUND_POWER_OF_TWO( |
Hui Su | 56e838f | 2019-12-04 14:48:30 -0800 | [diff] [blame] | 991 | AOMMIN(mu_blocks_wide + col, max_blocks_wide), ss_x); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 992 | |
Hui Su | 56e838f | 2019-12-04 14:48:30 -0800 | [diff] [blame] | 993 | for (blk_row = row >> ss_y; blk_row < unit_height; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 994 | blk_row += bh_var_tx) { |
Hui Su | 56e838f | 2019-12-04 14:48:30 -0800 | [diff] [blame] | 995 | for (blk_col = col >> ss_x; blk_col < unit_width; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 996 | blk_col += bw_var_tx) { |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 997 | decode_reconstruct_tx(cm, td, r, mbmi, plane, plane_bsize, |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 998 | blk_row, blk_col, block, max_tx_size, |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 999 | &eobtotal); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1000 | block += step; |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | } |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 1007 | td->cfl_store_inter_block_visit(cm, xd); |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 1008 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1009 | |
Hui Su | 474e1e1 | 2020-02-27 15:46:36 -0800 | [diff] [blame] | 1010 | av1_visit_palette(pbi, xd, r, set_color_index_map_offset); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1013 | static inline void set_inter_tx_size(MB_MODE_INFO *mbmi, int stride_log2, |
| 1014 | int tx_w_log2, int tx_h_log2, int min_txs, |
| 1015 | int split_size, int txs, int blk_row, |
| 1016 | int blk_col) { |
Jim Bankoski | 7634c33 | 2018-10-14 09:31:47 -0700 | [diff] [blame] | 1017 | for (int idy = 0; idy < tx_size_high_unit[split_size]; |
| 1018 | idy += tx_size_high_unit[min_txs]) { |
| 1019 | for (int idx = 0; idx < tx_size_wide_unit[split_size]; |
| 1020 | idx += tx_size_wide_unit[min_txs]) { |
| 1021 | const int index = (((blk_row + idy) >> tx_h_log2) << stride_log2) + |
| 1022 | ((blk_col + idx) >> tx_w_log2); |
| 1023 | mbmi->inter_tx_size[index] = txs; |
| 1024 | } |
| 1025 | } |
| 1026 | } |
| 1027 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1028 | static inline void read_tx_size_vartx(MACROBLOCKD *xd, MB_MODE_INFO *mbmi, |
| 1029 | TX_SIZE tx_size, int depth, int blk_row, |
| 1030 | int blk_col, aom_reader *r) { |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1031 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 1032 | int is_split = 0; |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 1033 | const BLOCK_SIZE bsize = mbmi->bsize; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1034 | const int max_blocks_high = max_block_high(xd, bsize, 0); |
| 1035 | const int max_blocks_wide = max_block_wide(xd, bsize, 0); |
| 1036 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; |
| 1037 | assert(tx_size > TX_4X4); |
Jim Bankoski | 7634c33 | 2018-10-14 09:31:47 -0700 | [diff] [blame] | 1038 | TX_SIZE txs = max_txsize_rect_lookup[bsize]; |
| 1039 | for (int level = 0; level < MAX_VARTX_DEPTH - 1; ++level) |
| 1040 | txs = sub_tx_size_map[txs]; |
| 1041 | const int tx_w_log2 = tx_size_wide_log2[txs] - MI_SIZE_LOG2; |
| 1042 | const int tx_h_log2 = tx_size_high_log2[txs] - MI_SIZE_LOG2; |
| 1043 | const int bw_log2 = mi_size_wide_log2[bsize]; |
| 1044 | const int stride_log2 = bw_log2 - tx_w_log2; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1045 | |
| 1046 | if (depth == MAX_VARTX_DEPTH) { |
Jim Bankoski | 7634c33 | 2018-10-14 09:31:47 -0700 | [diff] [blame] | 1047 | set_inter_tx_size(mbmi, stride_log2, tx_w_log2, tx_h_log2, txs, tx_size, |
| 1048 | tx_size, blk_row, blk_col); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1049 | mbmi->tx_size = tx_size; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1050 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 1051 | xd->left_txfm_context + blk_row, tx_size, tx_size); |
| 1052 | return; |
| 1053 | } |
| 1054 | |
| 1055 | const int ctx = txfm_partition_context(xd->above_txfm_context + blk_col, |
| 1056 | xd->left_txfm_context + blk_row, |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 1057 | mbmi->bsize, tx_size); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1058 | is_split = aom_read_symbol(r, ec_ctx->txfm_partition_cdf[ctx], 2, ACCT_STR); |
| 1059 | |
| 1060 | if (is_split) { |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 1061 | const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1062 | const int bsw = tx_size_wide_unit[sub_txs]; |
| 1063 | const int bsh = tx_size_high_unit[sub_txs]; |
| 1064 | |
| 1065 | if (sub_txs == TX_4X4) { |
Jim Bankoski | 7634c33 | 2018-10-14 09:31:47 -0700 | [diff] [blame] | 1066 | set_inter_tx_size(mbmi, stride_log2, tx_w_log2, tx_h_log2, txs, tx_size, |
| 1067 | sub_txs, blk_row, blk_col); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1068 | mbmi->tx_size = sub_txs; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1069 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 1070 | xd->left_txfm_context + blk_row, sub_txs, tx_size); |
| 1071 | return; |
| 1072 | } |
| 1073 | |
| 1074 | assert(bsw > 0 && bsh > 0); |
| 1075 | for (int row = 0; row < tx_size_high_unit[tx_size]; row += bsh) { |
| 1076 | for (int col = 0; col < tx_size_wide_unit[tx_size]; col += bsw) { |
| 1077 | int offsetr = blk_row + row; |
| 1078 | int offsetc = blk_col + col; |
Yannis Guyon | ee564d2 | 2021-06-15 13:25:50 +0200 | [diff] [blame] | 1079 | read_tx_size_vartx(xd, mbmi, sub_txs, depth + 1, offsetr, offsetc, r); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | } else { |
Jim Bankoski | 7634c33 | 2018-10-14 09:31:47 -0700 | [diff] [blame] | 1083 | set_inter_tx_size(mbmi, stride_log2, tx_w_log2, tx_h_log2, txs, tx_size, |
| 1084 | tx_size, blk_row, blk_col); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1085 | mbmi->tx_size = tx_size; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1086 | txfm_partition_update(xd->above_txfm_context + blk_col, |
| 1087 | xd->left_txfm_context + blk_row, tx_size, tx_size); |
| 1088 | } |
| 1089 | } |
| 1090 | |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 1091 | static TX_SIZE read_selected_tx_size(const MACROBLOCKD *const xd, |
| 1092 | aom_reader *r) { |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1093 | // TODO(debargha): Clean up the logic here. This function should only |
| 1094 | // be called for intra. |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 1095 | const BLOCK_SIZE bsize = xd->mi[0]->bsize; |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 1096 | const int32_t tx_size_cat = bsize_to_tx_size_cat(bsize); |
| 1097 | const int max_depths = bsize_to_max_depth(bsize); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1098 | const int ctx = get_tx_size_context(xd); |
| 1099 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 1100 | const int depth = aom_read_symbol(r, ec_ctx->tx_size_cdf[tx_size_cat][ctx], |
| 1101 | max_depths + 1, ACCT_STR); |
| 1102 | assert(depth >= 0 && depth <= max_depths); |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 1103 | const TX_SIZE tx_size = depth_to_tx_size(depth, bsize); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1104 | return tx_size; |
| 1105 | } |
| 1106 | |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 1107 | static TX_SIZE read_tx_size(const MACROBLOCKD *const xd, TX_MODE tx_mode, |
| 1108 | int is_inter, int allow_select_inter, |
| 1109 | aom_reader *r) { |
chiyotsai | 0f5cd05 | 2020-08-27 14:37:44 -0700 | [diff] [blame] | 1110 | const BLOCK_SIZE bsize = xd->mi[0]->bsize; |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 1111 | if (xd->lossless[xd->mi[0]->segment_id]) return TX_4X4; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1112 | |
| 1113 | if (block_signals_txsize(bsize)) { |
| 1114 | if ((!is_inter || allow_select_inter) && tx_mode == TX_MODE_SELECT) { |
Frederic Barbier | 4b56b10 | 2018-03-30 16:09:34 +0200 | [diff] [blame] | 1115 | const TX_SIZE coded_tx_size = read_selected_tx_size(xd, r); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1116 | return coded_tx_size; |
| 1117 | } else { |
| 1118 | return tx_size_from_tx_mode(bsize, tx_mode); |
| 1119 | } |
| 1120 | } else { |
| 1121 | assert(IMPLIES(tx_mode == ONLY_4X4, bsize == BLOCK_4X4)); |
Urvang Joshi | dd0376f | 2018-05-02 16:37:25 -0700 | [diff] [blame] | 1122 | return max_txsize_rect_lookup[bsize]; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1126 | static inline void parse_decode_block(AV1Decoder *const pbi, |
| 1127 | ThreadData *const td, int mi_row, |
| 1128 | int mi_col, aom_reader *r, |
| 1129 | PARTITION_TYPE partition, |
| 1130 | BLOCK_SIZE bsize) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 1131 | DecoderCodingBlock *const dcb = &td->dcb; |
| 1132 | MACROBLOCKD *const xd = &dcb->xd; |
| 1133 | decode_mbmi_block(pbi, dcb, mi_row, mi_col, r, partition, bsize); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1134 | |
Hui Su | 474e1e1 | 2020-02-27 15:46:36 -0800 | [diff] [blame] | 1135 | av1_visit_palette(pbi, xd, r, av1_decode_palette_tokens); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1136 | |
| 1137 | AV1_COMMON *cm = &pbi->common; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1138 | const int num_planes = av1_num_planes(cm); |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 1139 | MB_MODE_INFO *mbmi = xd->mi[0]; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1140 | int inter_block_tx = is_inter_block(mbmi) || is_intrabc_block(mbmi); |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 1141 | if (cm->features.tx_mode == TX_MODE_SELECT && block_signals_txsize(bsize) && |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 1142 | !mbmi->skip_txfm && inter_block_tx && !xd->lossless[mbmi->segment_id]) { |
Urvang Joshi | dd0376f | 2018-05-02 16:37:25 -0700 | [diff] [blame] | 1143 | const TX_SIZE max_tx_size = max_txsize_rect_lookup[bsize]; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1144 | const int bh = tx_size_high_unit[max_tx_size]; |
| 1145 | const int bw = tx_size_wide_unit[max_tx_size]; |
Hui Su | adda587 | 2019-12-09 10:08:49 -0800 | [diff] [blame] | 1146 | const int width = mi_size_wide[bsize]; |
| 1147 | const int height = mi_size_high[bsize]; |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1148 | |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1149 | for (int idy = 0; idy < height; idy += bh) |
| 1150 | for (int idx = 0; idx < width; idx += bw) |
Yannis Guyon | ee564d2 | 2021-06-15 13:25:50 +0200 | [diff] [blame] | 1151 | read_tx_size_vartx(xd, mbmi, max_tx_size, 0, idy, idx, r); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1152 | } else { |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 1153 | mbmi->tx_size = read_tx_size(xd, cm->features.tx_mode, inter_block_tx, |
| 1154 | !mbmi->skip_txfm, r); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1155 | if (inter_block_tx) |
| 1156 | memset(mbmi->inter_tx_size, mbmi->tx_size, sizeof(mbmi->inter_tx_size)); |
Urvang Joshi | 33930b8 | 2020-04-06 12:41:27 -0700 | [diff] [blame] | 1157 | set_txfm_ctxs(mbmi->tx_size, xd->width, xd->height, |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 1158 | mbmi->skip_txfm && is_inter_block(mbmi), xd); |
Jingning Han | 088217b | 2018-02-23 21:55:21 -0800 | [diff] [blame] | 1159 | } |
| 1160 | |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1161 | if (cm->delta_q_info.delta_q_present_flag) { |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1162 | for (int i = 0; i < MAX_SEGMENTS; i++) { |
| 1163 | const int current_qindex = |
Urvang Joshi | acad1ca | 2020-04-27 17:03:25 -0700 | [diff] [blame] | 1164 | av1_get_qindex(&cm->seg, i, xd->current_base_qindex); |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1165 | const CommonQuantParams *const quant_params = &cm->quant_params; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1166 | for (int j = 0; j < num_planes; ++j) { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1167 | const int dc_delta_q = j == 0 ? quant_params->y_dc_delta_q |
| 1168 | : (j == 1 ? quant_params->u_dc_delta_q |
| 1169 | : quant_params->v_dc_delta_q); |
| 1170 | const int ac_delta_q = j == 0 ? 0 |
| 1171 | : (j == 1 ? quant_params->u_ac_delta_q |
| 1172 | : quant_params->v_ac_delta_q); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1173 | xd->plane[j].seg_dequant_QTX[i][0] = av1_dc_quant_QTX( |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 1174 | current_qindex, dc_delta_q, cm->seq_params->bit_depth); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1175 | xd->plane[j].seg_dequant_QTX[i][1] = av1_ac_quant_QTX( |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 1176 | current_qindex, ac_delta_q, cm->seq_params->bit_depth); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1177 | } |
| 1178 | } |
| 1179 | } |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 1180 | if (mbmi->skip_txfm) av1_reset_entropy_context(xd, bsize, num_planes); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1181 | |
Hui Su | d62a63a | 2020-02-27 16:59:54 -0800 | [diff] [blame] | 1182 | decode_token_recon_block(pbi, td, r, bsize); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1183 | } |
| 1184 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1185 | static inline void set_offsets_for_pred_and_recon(AV1Decoder *const pbi, |
| 1186 | ThreadData *const td, |
| 1187 | int mi_row, int mi_col, |
| 1188 | BLOCK_SIZE bsize) { |
Deepa K G | 7d17c38 | 2018-07-10 20:07:08 +0530 | [diff] [blame] | 1189 | AV1_COMMON *const cm = &pbi->common; |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1190 | const CommonModeInfoParams *const mi_params = &cm->mi_params; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 1191 | DecoderCodingBlock *const dcb = &td->dcb; |
| 1192 | MACROBLOCKD *const xd = &dcb->xd; |
Deepa K G | 7d17c38 | 2018-07-10 20:07:08 +0530 | [diff] [blame] | 1193 | const int bw = mi_size_wide[bsize]; |
| 1194 | const int bh = mi_size_high[bsize]; |
| 1195 | const int num_planes = av1_num_planes(cm); |
| 1196 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1197 | const int offset = mi_row * mi_params->mi_stride + mi_col; |
Deepa K G | 7d17c38 | 2018-07-10 20:07:08 +0530 | [diff] [blame] | 1198 | const TileInfo *const tile = &xd->tile; |
| 1199 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1200 | xd->mi = mi_params->mi_grid_base + offset; |
| 1201 | xd->tx_type_map = |
| 1202 | &mi_params->tx_type_map[mi_row * mi_params->mi_stride + mi_col]; |
| 1203 | xd->tx_type_map_stride = mi_params->mi_stride; |
Deepa K G | 7d17c38 | 2018-07-10 20:07:08 +0530 | [diff] [blame] | 1204 | |
| 1205 | set_plane_n4(xd, bw, bh, num_planes); |
| 1206 | |
| 1207 | // Distance of Mb to the various image edges. These are specified to 8th pel |
| 1208 | // as they are always compared to values that are in 1/8th pel units |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1209 | set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, mi_params->mi_rows, |
| 1210 | mi_params->mi_cols); |
Deepa K G | 7d17c38 | 2018-07-10 20:07:08 +0530 | [diff] [blame] | 1211 | |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 1212 | av1_setup_dst_planes(xd->plane, bsize, &cm->cur_frame->buf, mi_row, mi_col, 0, |
| 1213 | num_planes); |
Deepa K G | 7d17c38 | 2018-07-10 20:07:08 +0530 | [diff] [blame] | 1214 | } |
| 1215 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1216 | static inline void decode_block(AV1Decoder *const pbi, ThreadData *const td, |
| 1217 | int mi_row, int mi_col, aom_reader *r, |
| 1218 | PARTITION_TYPE partition, BLOCK_SIZE bsize) { |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1219 | (void)partition; |
Deepa K G | 7d17c38 | 2018-07-10 20:07:08 +0530 | [diff] [blame] | 1220 | set_offsets_for_pred_and_recon(pbi, td, mi_row, mi_col, bsize); |
Hui Su | d62a63a | 2020-02-27 16:59:54 -0800 | [diff] [blame] | 1221 | decode_token_recon_block(pbi, td, r, bsize); |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 1222 | } |
| 1223 | |
Rupert Swarbrick | eb12393 | 2017-11-22 15:20:47 +0000 | [diff] [blame] | 1224 | static PARTITION_TYPE read_partition(MACROBLOCKD *xd, int mi_row, int mi_col, |
| 1225 | aom_reader *r, int has_rows, int has_cols, |
Jingning Han | 1beb010 | 2016-12-07 11:08:30 -0800 | [diff] [blame] | 1226 | BLOCK_SIZE bsize) { |
| 1227 | const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); |
Thomas Davies | c2ec0e4 | 2017-01-11 16:27:27 +0000 | [diff] [blame] | 1228 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1229 | |
Rupert Swarbrick | eb12393 | 2017-11-22 15:20:47 +0000 | [diff] [blame] | 1230 | if (!has_rows && !has_cols) return PARTITION_SPLIT; |
Jingning Han | 5fe79db | 2017-03-27 15:10:30 -0700 | [diff] [blame] | 1231 | |
Rupert Swarbrick | eb12393 | 2017-11-22 15:20:47 +0000 | [diff] [blame] | 1232 | assert(ctx >= 0); |
| 1233 | aom_cdf_prob *partition_cdf = ec_ctx->partition_cdf[ctx]; |
Rupert Swarbrick | b95cf12 | 2017-07-31 16:51:12 +0100 | [diff] [blame] | 1234 | if (has_rows && has_cols) { |
Rupert Swarbrick | eb12393 | 2017-11-22 15:20:47 +0000 | [diff] [blame] | 1235 | return (PARTITION_TYPE)aom_read_symbol( |
| 1236 | r, partition_cdf, partition_cdf_length(bsize), ACCT_STR); |
Rupert Swarbrick | b95cf12 | 2017-07-31 16:51:12 +0100 | [diff] [blame] | 1237 | } else if (!has_rows && has_cols) { |
Stanislav Vitvitskyy | 8711cf5 | 2017-08-18 15:17:57 -0700 | [diff] [blame] | 1238 | assert(bsize > BLOCK_8X8); |
| 1239 | aom_cdf_prob cdf[2]; |
Rupert Swarbrick | eb12393 | 2017-11-22 15:20:47 +0000 | [diff] [blame] | 1240 | partition_gather_vert_alike(cdf, partition_cdf, bsize); |
Stanislav Vitvitskyy | 8711cf5 | 2017-08-18 15:17:57 -0700 | [diff] [blame] | 1241 | assert(cdf[1] == AOM_ICDF(CDF_PROB_TOP)); |
Rupert Swarbrick | eb12393 | 2017-11-22 15:20:47 +0000 | [diff] [blame] | 1242 | return aom_read_cdf(r, cdf, 2, ACCT_STR) ? PARTITION_SPLIT : PARTITION_HORZ; |
| 1243 | } else { |
| 1244 | assert(has_rows && !has_cols); |
Stanislav Vitvitskyy | 8711cf5 | 2017-08-18 15:17:57 -0700 | [diff] [blame] | 1245 | assert(bsize > BLOCK_8X8); |
| 1246 | aom_cdf_prob cdf[2]; |
Rupert Swarbrick | eb12393 | 2017-11-22 15:20:47 +0000 | [diff] [blame] | 1247 | partition_gather_horz_alike(cdf, partition_cdf, bsize); |
Stanislav Vitvitskyy | 8711cf5 | 2017-08-18 15:17:57 -0700 | [diff] [blame] | 1248 | assert(cdf[1] == AOM_ICDF(CDF_PROB_TOP)); |
Rupert Swarbrick | eb12393 | 2017-11-22 15:20:47 +0000 | [diff] [blame] | 1249 | return aom_read_cdf(r, cdf, 2, ACCT_STR) ? PARTITION_SPLIT : PARTITION_VERT; |
Rupert Swarbrick | b95cf12 | 2017-07-31 16:51:12 +0100 | [diff] [blame] | 1250 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1253 | // TODO(slavarnway): eliminate bsize and subsize in future commits |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1254 | static inline void decode_partition(AV1Decoder *const pbi, ThreadData *const td, |
| 1255 | int mi_row, int mi_col, aom_reader *reader, |
| 1256 | BLOCK_SIZE bsize, int parse_decode_flag) { |
kyslov | 5859dca | 2019-04-08 12:13:11 -0700 | [diff] [blame] | 1257 | assert(bsize < BLOCK_SIZES_ALL); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1258 | AV1_COMMON *const cm = &pbi->common; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 1259 | DecoderCodingBlock *const dcb = &td->dcb; |
| 1260 | MACROBLOCKD *const xd = &dcb->xd; |
Yushin Cho | cee5d20 | 2018-03-29 14:06:54 -0700 | [diff] [blame] | 1261 | const int bw = mi_size_wide[bsize]; |
| 1262 | const int hbs = bw >> 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1263 | PARTITION_TYPE partition; |
| 1264 | BLOCK_SIZE subsize; |
Yushin Cho | cee5d20 | 2018-03-29 14:06:54 -0700 | [diff] [blame] | 1265 | const int quarter_step = bw / 4; |
Cheng Chen | 82b4fa1 | 2018-05-02 18:43:17 -0700 | [diff] [blame] | 1266 | BLOCK_SIZE bsize2 = get_partition_subsize(bsize, PARTITION_SPLIT); |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1267 | const int has_rows = (mi_row + hbs) < cm->mi_params.mi_rows; |
| 1268 | const int has_cols = (mi_col + hbs) < cm->mi_params.mi_cols; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1269 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1270 | if (mi_row >= cm->mi_params.mi_rows || mi_col >= cm->mi_params.mi_cols) |
| 1271 | return; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1272 | |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1273 | // parse_decode_flag takes the following values : |
| 1274 | // 01 - do parse only |
| 1275 | // 10 - do decode only |
| 1276 | // 11 - do parse and decode |
Hien Ho | 830b897 | 2019-04-04 15:51:14 -0700 | [diff] [blame] | 1277 | static const block_visitor_fn_t block_visit[4] = { NULL, parse_decode_block, |
| 1278 | decode_block, |
| 1279 | parse_decode_block }; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1280 | |
| 1281 | if (parse_decode_flag & 1) { |
| 1282 | const int num_planes = av1_num_planes(cm); |
| 1283 | for (int plane = 0; plane < num_planes; ++plane) { |
| 1284 | int rcol0, rcol1, rrow0, rrow1; |
Rachel Barker | 2b98f1b | 2023-07-06 19:39:45 +0000 | [diff] [blame] | 1285 | |
| 1286 | // Skip some unnecessary work if loop restoration is disabled |
| 1287 | if (cm->rst_info[plane].frame_restoration_type == RESTORE_NONE) continue; |
| 1288 | |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1289 | if (av1_loop_restoration_corners_in_sb(cm, plane, mi_row, mi_col, bsize, |
| 1290 | &rcol0, &rcol1, &rrow0, &rrow1)) { |
Rachel Barker | 0483cbe | 2023-07-05 23:31:38 +0000 | [diff] [blame] | 1291 | const int rstride = cm->rst_info[plane].horz_units; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1292 | for (int rrow = rrow0; rrow < rrow1; ++rrow) { |
| 1293 | for (int rcol = rcol0; rcol < rcol1; ++rcol) { |
| 1294 | const int runit_idx = rcol + rrow * rstride; |
Wan-Teh Chang | e232afb | 2018-09-25 16:44:47 -0700 | [diff] [blame] | 1295 | loop_restoration_read_sb_coeffs(cm, xd, reader, plane, runit_idx); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1296 | } |
Imdad Sardharwalla | 7d2e5c9 | 2018-01-05 18:41:00 +0000 | [diff] [blame] | 1297 | } |
| 1298 | } |
Wan-Teh Chang | d38c8ef | 2021-06-17 12:13:09 -0700 | [diff] [blame] | 1299 | } |
Yunqing Wang | 01b18aa | 2018-06-25 22:05:26 +0000 | [diff] [blame] | 1300 | |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1301 | partition = (bsize < BLOCK_8X8) ? PARTITION_NONE |
Wan-Teh Chang | e232afb | 2018-09-25 16:44:47 -0700 | [diff] [blame] | 1302 | : read_partition(xd, mi_row, mi_col, reader, |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1303 | has_rows, has_cols, bsize); |
| 1304 | } else { |
| 1305 | partition = get_partition(cm, mi_row, mi_col, bsize); |
| 1306 | } |
Cheng Chen | 82b4fa1 | 2018-05-02 18:43:17 -0700 | [diff] [blame] | 1307 | subsize = get_partition_subsize(bsize, partition); |
kyslov | 6fdf934 | 2019-04-09 14:53:43 -0700 | [diff] [blame] | 1308 | if (subsize == BLOCK_INVALID) { |
venkat sanampudi | ee9dbcb | 2022-02-24 21:34:22 +0530 | [diff] [blame] | 1309 | // When an internal error occurs ensure that xd->mi_row is set appropriately |
| 1310 | // w.r.t. current tile, which is used to signal processing of current row is |
| 1311 | // done. |
| 1312 | xd->mi_row = mi_row; |
kyslov | 6fdf934 | 2019-04-09 14:53:43 -0700 | [diff] [blame] | 1313 | aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, |
| 1314 | "Partition is invalid for block size %dx%d", |
| 1315 | block_size_wide[bsize], block_size_high[bsize]); |
| 1316 | } |
Rupert Swarbrick | 415c8f1 | 2017-10-09 16:26:23 +0100 | [diff] [blame] | 1317 | // Check the bitstream is conformant: if there is subsampling on the |
| 1318 | // chroma planes, subsize must subsample to a valid block size. |
| 1319 | const struct macroblockd_plane *const pd_u = &xd->plane[1]; |
Cheng Chen | 8ab1f44 | 2018-04-27 18:01:52 -0700 | [diff] [blame] | 1320 | if (get_plane_block_size(subsize, pd_u->subsampling_x, pd_u->subsampling_y) == |
| 1321 | BLOCK_INVALID) { |
venkat sanampudi | ee9dbcb | 2022-02-24 21:34:22 +0530 | [diff] [blame] | 1322 | // When an internal error occurs ensure that xd->mi_row is set appropriately |
| 1323 | // w.r.t. current tile, which is used to signal processing of current row is |
| 1324 | // done. |
| 1325 | xd->mi_row = mi_row; |
Yunqing Wang | 1f68fee | 2018-07-02 12:39:09 -0700 | [diff] [blame] | 1326 | aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, |
Rupert Swarbrick | 415c8f1 | 2017-10-09 16:26:23 +0100 | [diff] [blame] | 1327 | "Block size %dx%d invalid with this subsampling mode", |
| 1328 | block_size_wide[subsize], block_size_high[subsize]); |
| 1329 | } |
| 1330 | |
Rupert Swarbrick | 668d3d9 | 2017-09-06 16:09:51 +0100 | [diff] [blame] | 1331 | #define DEC_BLOCK_STX_ARG |
Rupert Swarbrick | 668d3d9 | 2017-09-06 16:09:51 +0100 | [diff] [blame] | 1332 | #define DEC_BLOCK_EPT_ARG partition, |
Wan-Teh Chang | e232afb | 2018-09-25 16:44:47 -0700 | [diff] [blame] | 1333 | #define DEC_BLOCK(db_r, db_c, db_subsize) \ |
| 1334 | block_visit[parse_decode_flag](pbi, td, DEC_BLOCK_STX_ARG(db_r), (db_c), \ |
| 1335 | reader, DEC_BLOCK_EPT_ARG(db_subsize)) |
| 1336 | #define DEC_PARTITION(db_r, db_c, db_subsize) \ |
| 1337 | decode_partition(pbi, td, DEC_BLOCK_STX_ARG(db_r), (db_c), reader, \ |
| 1338 | (db_subsize), parse_decode_flag) |
Rupert Swarbrick | 668d3d9 | 2017-09-06 16:09:51 +0100 | [diff] [blame] | 1339 | |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1340 | switch (partition) { |
| 1341 | case PARTITION_NONE: DEC_BLOCK(mi_row, mi_col, subsize); break; |
| 1342 | case PARTITION_HORZ: |
| 1343 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 1344 | if (has_rows) DEC_BLOCK(mi_row + hbs, mi_col, subsize); |
| 1345 | break; |
| 1346 | case PARTITION_VERT: |
| 1347 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 1348 | if (has_cols) DEC_BLOCK(mi_row, mi_col + hbs, subsize); |
| 1349 | break; |
| 1350 | case PARTITION_SPLIT: |
| 1351 | DEC_PARTITION(mi_row, mi_col, subsize); |
| 1352 | DEC_PARTITION(mi_row, mi_col + hbs, subsize); |
| 1353 | DEC_PARTITION(mi_row + hbs, mi_col, subsize); |
| 1354 | DEC_PARTITION(mi_row + hbs, mi_col + hbs, subsize); |
| 1355 | break; |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1356 | case PARTITION_HORZ_A: |
| 1357 | DEC_BLOCK(mi_row, mi_col, bsize2); |
| 1358 | DEC_BLOCK(mi_row, mi_col + hbs, bsize2); |
| 1359 | DEC_BLOCK(mi_row + hbs, mi_col, subsize); |
| 1360 | break; |
| 1361 | case PARTITION_HORZ_B: |
| 1362 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 1363 | DEC_BLOCK(mi_row + hbs, mi_col, bsize2); |
| 1364 | DEC_BLOCK(mi_row + hbs, mi_col + hbs, bsize2); |
| 1365 | break; |
| 1366 | case PARTITION_VERT_A: |
| 1367 | DEC_BLOCK(mi_row, mi_col, bsize2); |
| 1368 | DEC_BLOCK(mi_row + hbs, mi_col, bsize2); |
| 1369 | DEC_BLOCK(mi_row, mi_col + hbs, subsize); |
| 1370 | break; |
| 1371 | case PARTITION_VERT_B: |
| 1372 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 1373 | DEC_BLOCK(mi_row, mi_col + hbs, bsize2); |
| 1374 | DEC_BLOCK(mi_row + hbs, mi_col + hbs, bsize2); |
| 1375 | break; |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1376 | case PARTITION_HORZ_4: |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 1377 | for (int i = 0; i < 4; ++i) { |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1378 | int this_mi_row = mi_row + i * quarter_step; |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1379 | if (i > 0 && this_mi_row >= cm->mi_params.mi_rows) break; |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1380 | DEC_BLOCK(this_mi_row, mi_col, subsize); |
| 1381 | } |
| 1382 | break; |
| 1383 | case PARTITION_VERT_4: |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 1384 | for (int i = 0; i < 4; ++i) { |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1385 | int this_mi_col = mi_col + i * quarter_step; |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1386 | if (i > 0 && this_mi_col >= cm->mi_params.mi_cols) break; |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1387 | DEC_BLOCK(mi_row, this_mi_col, subsize); |
| 1388 | } |
| 1389 | break; |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1390 | default: assert(0 && "Invalid partition type"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
Rupert Swarbrick | 668d3d9 | 2017-09-06 16:09:51 +0100 | [diff] [blame] | 1393 | #undef DEC_PARTITION |
| 1394 | #undef DEC_BLOCK |
| 1395 | #undef DEC_BLOCK_EPT_ARG |
| 1396 | #undef DEC_BLOCK_STX_ARG |
| 1397 | |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 1398 | if (parse_decode_flag & 1) |
| 1399 | update_ext_partition_context(xd, mi_row, mi_col, subsize, bsize, partition); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1402 | static inline void setup_bool_decoder( |
venkat sanampudi | ee9dbcb | 2022-02-24 21:34:22 +0530 | [diff] [blame] | 1403 | MACROBLOCKD *const xd, const uint8_t *data, const uint8_t *data_end, |
| 1404 | const size_t read_size, struct aom_internal_error_info *error_info, |
| 1405 | aom_reader *r, uint8_t allow_update_cdf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1406 | // Validate the calculated partition length. If the buffer |
| 1407 | // described by the partition can't be fully read, then restrict |
| 1408 | // it to the portion that can be (for EC mode) or throw an error. |
venkat sanampudi | ee9dbcb | 2022-02-24 21:34:22 +0530 | [diff] [blame] | 1409 | if (!read_is_valid(data, read_size, data_end)) { |
| 1410 | // When internal error occurs ensure that xd->mi_row is set appropriately |
| 1411 | // w.r.t. current tile, which is used to signal processing of current row is |
| 1412 | // done in row-mt decoding. |
| 1413 | xd->mi_row = xd->tile.mi_row_start; |
| 1414 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1415 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1416 | "Truncated packet or corrupt tile length"); |
venkat sanampudi | ee9dbcb | 2022-02-24 21:34:22 +0530 | [diff] [blame] | 1417 | } |
| 1418 | if (aom_reader_init(r, data, read_size)) { |
| 1419 | // When internal error occurs ensure that xd->mi_row is set appropriately |
| 1420 | // w.r.t. current tile, which is used to signal processing of current row is |
| 1421 | // done in row-mt decoding. |
| 1422 | xd->mi_row = xd->tile.mi_row_start; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1423 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1424 | aom_internal_error(error_info, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1425 | "Failed to allocate bool decoder %d", 1); |
venkat sanampudi | ee9dbcb | 2022-02-24 21:34:22 +0530 | [diff] [blame] | 1426 | } |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 1427 | |
| 1428 | r->allow_update_cdf = allow_update_cdf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1429 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1430 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1431 | static inline void setup_segmentation(AV1_COMMON *const cm, |
| 1432 | struct aom_read_bit_buffer *rb) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1433 | struct segmentation *const seg = &cm->seg; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1434 | |
| 1435 | seg->update_map = 0; |
| 1436 | seg->update_data = 0; |
Ryan | dd8df16 | 2017-09-27 15:40:13 -0700 | [diff] [blame] | 1437 | seg->temporal_update = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1438 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1439 | seg->enabled = aom_rb_read_bit(rb); |
Jonathan Matthews | 98c8fcc | 2018-01-31 15:54:33 +0000 | [diff] [blame] | 1440 | if (!seg->enabled) { |
Urvang Joshi | 5209fa5 | 2020-10-30 09:58:36 -0700 | [diff] [blame] | 1441 | if (cm->cur_frame->seg_map) { |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1442 | memset(cm->cur_frame->seg_map, 0, |
Urvang Joshi | 5209fa5 | 2020-10-30 09:58:36 -0700 | [diff] [blame] | 1443 | (cm->cur_frame->mi_rows * cm->cur_frame->mi_cols)); |
| 1444 | } |
David Barker | 190b77a | 2018-03-16 14:29:46 +0000 | [diff] [blame] | 1445 | |
| 1446 | memset(seg, 0, sizeof(*seg)); |
| 1447 | segfeatures_copy(&cm->cur_frame->seg, seg); |
Jonathan Matthews | 98c8fcc | 2018-01-31 15:54:33 +0000 | [diff] [blame] | 1448 | return; |
| 1449 | } |
Debargha Mukherjee | 5521a18 | 2018-03-06 12:29:01 -0800 | [diff] [blame] | 1450 | if (cm->seg.enabled && cm->prev_frame && |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1451 | (cm->mi_params.mi_rows == cm->prev_frame->mi_rows) && |
| 1452 | (cm->mi_params.mi_cols == cm->prev_frame->mi_cols)) { |
Soo-Chul Han | 2638cb5 | 2017-11-22 16:34:47 -0500 | [diff] [blame] | 1453 | cm->last_frame_seg_map = cm->prev_frame->seg_map; |
Jonathan Matthews | 74e8a99 | 2018-02-01 11:31:08 +0000 | [diff] [blame] | 1454 | } else { |
| 1455 | cm->last_frame_seg_map = NULL; |
| 1456 | } |
David Barker | 190b77a | 2018-03-16 14:29:46 +0000 | [diff] [blame] | 1457 | // Read update flags |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 1458 | if (cm->features.primary_ref_frame == PRIMARY_REF_NONE) { |
David Barker | 190b77a | 2018-03-16 14:29:46 +0000 | [diff] [blame] | 1459 | // These frames can't use previous frames, so must signal map + features |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1460 | seg->update_map = 1; |
David Barker | 190b77a | 2018-03-16 14:29:46 +0000 | [diff] [blame] | 1461 | seg->temporal_update = 0; |
| 1462 | seg->update_data = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1463 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1464 | seg->update_map = aom_rb_read_bit(rb); |
David Barker | 190b77a | 2018-03-16 14:29:46 +0000 | [diff] [blame] | 1465 | if (seg->update_map) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1466 | seg->temporal_update = aom_rb_read_bit(rb); |
David Barker | 190b77a | 2018-03-16 14:29:46 +0000 | [diff] [blame] | 1467 | } else { |
| 1468 | seg->temporal_update = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1469 | } |
David Barker | 190b77a | 2018-03-16 14:29:46 +0000 | [diff] [blame] | 1470 | seg->update_data = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | // Segmentation data update |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1474 | if (seg->update_data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1475 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1476 | |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 1477 | for (int i = 0; i < MAX_SEGMENTS; i++) { |
| 1478 | for (int j = 0; j < SEG_LVL_MAX; j++) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1479 | int data = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1480 | const int feature_enabled = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1481 | if (feature_enabled) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1482 | av1_enable_segfeature(seg, i, j); |
Sebastien Alaiwan | ca14b47 | 2017-12-11 11:46:00 +0100 | [diff] [blame] | 1483 | |
| 1484 | const int data_max = av1_seg_feature_data_max(j); |
| 1485 | const int data_min = -data_max; |
| 1486 | const int ubits = get_unsigned_bits(data_max); |
| 1487 | |
| 1488 | if (av1_is_segfeature_signed(j)) { |
| 1489 | data = aom_rb_read_inv_signed_literal(rb, ubits); |
| 1490 | } else { |
| 1491 | data = aom_rb_read_literal(rb, ubits); |
| 1492 | } |
| 1493 | |
| 1494 | data = clamp(data, data_min, data_max); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1495 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1496 | av1_set_segdata(seg, i, j, data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1497 | } |
| 1498 | } |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 1499 | av1_calculate_segdata(seg); |
Rostislav Pehlivanov | 3a96462 | 2018-03-14 18:00:32 +0000 | [diff] [blame] | 1500 | } else if (cm->prev_frame) { |
| 1501 | segfeatures_copy(seg, &cm->prev_frame->seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1502 | } |
David Barker | cab3755 | 2018-03-21 11:56:24 +0000 | [diff] [blame] | 1503 | segfeatures_copy(&cm->cur_frame->seg, seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1506 | static inline void decode_restoration_mode(AV1_COMMON *cm, |
| 1507 | struct aom_read_bit_buffer *rb) { |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 1508 | assert(!cm->features.all_lossless); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1509 | const int num_planes = av1_num_planes(cm); |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 1510 | if (cm->features.allow_intrabc) return; |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 1511 | int all_none = 1, chroma_none = 1; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1512 | for (int p = 0; p < num_planes; ++p) { |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame] | 1513 | RestorationInfo *rsi = &cm->rst_info[p]; |
Debargha Mukherjee | d23ceea | 2017-05-18 20:33:52 -0700 | [diff] [blame] | 1514 | if (aom_rb_read_bit(rb)) { |
| 1515 | rsi->frame_restoration_type = |
| 1516 | aom_rb_read_bit(rb) ? RESTORE_SGRPROJ : RESTORE_WIENER; |
| 1517 | } else { |
Debargha Mukherjee | a3d4fe5 | 2017-05-19 16:22:54 -0700 | [diff] [blame] | 1518 | rsi->frame_restoration_type = |
| 1519 | aom_rb_read_bit(rb) ? RESTORE_SWITCHABLE : RESTORE_NONE; |
Debargha Mukherjee | d23ceea | 2017-05-18 20:33:52 -0700 | [diff] [blame] | 1520 | } |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 1521 | if (rsi->frame_restoration_type != RESTORE_NONE) { |
| 1522 | all_none = 0; |
| 1523 | chroma_none &= p == 0; |
| 1524 | } |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1525 | } |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 1526 | if (!all_none) { |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 1527 | assert(cm->seq_params->sb_size == BLOCK_64X64 || |
| 1528 | cm->seq_params->sb_size == BLOCK_128X128); |
| 1529 | const int sb_size = cm->seq_params->sb_size == BLOCK_128X128 ? 128 : 64; |
Imdad Sardharwalla | b1dce0a | 2018-02-12 16:43:59 +0000 | [diff] [blame] | 1530 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1531 | for (int p = 0; p < num_planes; ++p) |
Imdad Sardharwalla | b1dce0a | 2018-02-12 16:43:59 +0000 | [diff] [blame] | 1532 | cm->rst_info[p].restoration_unit_size = sb_size; |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame] | 1533 | |
| 1534 | RestorationInfo *rsi = &cm->rst_info[0]; |
Imdad Sardharwalla | b1dce0a | 2018-02-12 16:43:59 +0000 | [diff] [blame] | 1535 | |
| 1536 | if (sb_size == 64) { |
| 1537 | rsi->restoration_unit_size <<= aom_rb_read_bit(rb); |
| 1538 | } |
| 1539 | if (rsi->restoration_unit_size > 64) { |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 1540 | rsi->restoration_unit_size <<= aom_rb_read_bit(rb); |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 1541 | } |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame] | 1542 | } else { |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 1543 | const int size = RESTORATION_UNITSIZE_MAX; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1544 | for (int p = 0; p < num_planes; ++p) |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame] | 1545 | cm->rst_info[p].restoration_unit_size = size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 1546 | } |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame] | 1547 | |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1548 | if (num_planes > 1) { |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 1549 | int s = |
| 1550 | AOMMIN(cm->seq_params->subsampling_x, cm->seq_params->subsampling_y); |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 1551 | if (s && !chroma_none) { |
| 1552 | cm->rst_info[1].restoration_unit_size = |
| 1553 | cm->rst_info[0].restoration_unit_size >> (aom_rb_read_bit(rb) * s); |
| 1554 | } else { |
| 1555 | cm->rst_info[1].restoration_unit_size = |
| 1556 | cm->rst_info[0].restoration_unit_size; |
| 1557 | } |
| 1558 | cm->rst_info[2].restoration_unit_size = |
| 1559 | cm->rst_info[1].restoration_unit_size; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 1560 | } |
Debargha Mukherjee | 5cd2ab9 | 2016-09-08 15:15:17 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1563 | static inline void read_wiener_filter(int wiener_win, WienerInfo *wiener_info, |
| 1564 | WienerInfo *ref_wiener_info, |
| 1565 | aom_reader *rb) { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1566 | memset(wiener_info->vfilter, 0, sizeof(wiener_info->vfilter)); |
| 1567 | memset(wiener_info->hfilter, 0, sizeof(wiener_info->hfilter)); |
| 1568 | |
Debargha Mukherjee | 1cb757c | 2017-08-21 02:46:31 -0700 | [diff] [blame] | 1569 | if (wiener_win == WIENER_WIN) |
| 1570 | wiener_info->vfilter[0] = wiener_info->vfilter[WIENER_WIN - 1] = |
| 1571 | aom_read_primitive_refsubexpfin( |
| 1572 | rb, WIENER_FILT_TAP0_MAXV - WIENER_FILT_TAP0_MINV + 1, |
| 1573 | WIENER_FILT_TAP0_SUBEXP_K, |
| 1574 | ref_wiener_info->vfilter[0] - WIENER_FILT_TAP0_MINV, ACCT_STR) + |
| 1575 | WIENER_FILT_TAP0_MINV; |
| 1576 | else |
| 1577 | wiener_info->vfilter[0] = wiener_info->vfilter[WIENER_WIN - 1] = 0; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1578 | wiener_info->vfilter[1] = wiener_info->vfilter[WIENER_WIN - 2] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1579 | aom_read_primitive_refsubexpfin( |
| 1580 | rb, WIENER_FILT_TAP1_MAXV - WIENER_FILT_TAP1_MINV + 1, |
| 1581 | WIENER_FILT_TAP1_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1582 | ref_wiener_info->vfilter[1] - WIENER_FILT_TAP1_MINV, ACCT_STR) + |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1583 | WIENER_FILT_TAP1_MINV; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1584 | wiener_info->vfilter[2] = wiener_info->vfilter[WIENER_WIN - 3] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1585 | aom_read_primitive_refsubexpfin( |
| 1586 | rb, WIENER_FILT_TAP2_MAXV - WIENER_FILT_TAP2_MINV + 1, |
| 1587 | WIENER_FILT_TAP2_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1588 | ref_wiener_info->vfilter[2] - WIENER_FILT_TAP2_MINV, ACCT_STR) + |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1589 | WIENER_FILT_TAP2_MINV; |
David Barker | 1e8e6b9 | 2017-01-13 13:45:51 +0000 | [diff] [blame] | 1590 | // The central element has an implicit +WIENER_FILT_STEP |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1591 | wiener_info->vfilter[WIENER_HALFWIN] = |
David Barker | 1e8e6b9 | 2017-01-13 13:45:51 +0000 | [diff] [blame] | 1592 | -2 * (wiener_info->vfilter[0] + wiener_info->vfilter[1] + |
| 1593 | wiener_info->vfilter[2]); |
| 1594 | |
Debargha Mukherjee | 1cb757c | 2017-08-21 02:46:31 -0700 | [diff] [blame] | 1595 | if (wiener_win == WIENER_WIN) |
| 1596 | wiener_info->hfilter[0] = wiener_info->hfilter[WIENER_WIN - 1] = |
| 1597 | aom_read_primitive_refsubexpfin( |
| 1598 | rb, WIENER_FILT_TAP0_MAXV - WIENER_FILT_TAP0_MINV + 1, |
| 1599 | WIENER_FILT_TAP0_SUBEXP_K, |
| 1600 | ref_wiener_info->hfilter[0] - WIENER_FILT_TAP0_MINV, ACCT_STR) + |
| 1601 | WIENER_FILT_TAP0_MINV; |
| 1602 | else |
| 1603 | wiener_info->hfilter[0] = wiener_info->hfilter[WIENER_WIN - 1] = 0; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1604 | wiener_info->hfilter[1] = wiener_info->hfilter[WIENER_WIN - 2] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1605 | aom_read_primitive_refsubexpfin( |
| 1606 | rb, WIENER_FILT_TAP1_MAXV - WIENER_FILT_TAP1_MINV + 1, |
| 1607 | WIENER_FILT_TAP1_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1608 | ref_wiener_info->hfilter[1] - WIENER_FILT_TAP1_MINV, ACCT_STR) + |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1609 | WIENER_FILT_TAP1_MINV; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1610 | wiener_info->hfilter[2] = wiener_info->hfilter[WIENER_WIN - 3] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1611 | aom_read_primitive_refsubexpfin( |
| 1612 | rb, WIENER_FILT_TAP2_MAXV - WIENER_FILT_TAP2_MINV + 1, |
| 1613 | WIENER_FILT_TAP2_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1614 | ref_wiener_info->hfilter[2] - WIENER_FILT_TAP2_MINV, ACCT_STR) + |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1615 | WIENER_FILT_TAP2_MINV; |
David Barker | 1e8e6b9 | 2017-01-13 13:45:51 +0000 | [diff] [blame] | 1616 | // The central element has an implicit +WIENER_FILT_STEP |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1617 | wiener_info->hfilter[WIENER_HALFWIN] = |
David Barker | 1e8e6b9 | 2017-01-13 13:45:51 +0000 | [diff] [blame] | 1618 | -2 * (wiener_info->hfilter[0] + wiener_info->hfilter[1] + |
| 1619 | wiener_info->hfilter[2]); |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1620 | memcpy(ref_wiener_info, wiener_info, sizeof(*wiener_info)); |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1623 | static inline void read_sgrproj_filter(SgrprojInfo *sgrproj_info, |
| 1624 | SgrprojInfo *ref_sgrproj_info, |
| 1625 | aom_reader *rb) { |
Imdad Sardharwalla | fdeb116 | 2018-02-21 17:38:20 +0000 | [diff] [blame] | 1626 | sgrproj_info->ep = aom_read_literal(rb, SGRPROJ_PARAMS_BITS, ACCT_STR); |
Yaowu Xu | bf732b8 | 2019-04-30 15:21:52 -0700 | [diff] [blame] | 1627 | const sgr_params_type *params = &av1_sgr_params[sgrproj_info->ep]; |
Imdad Sardharwalla | fdeb116 | 2018-02-21 17:38:20 +0000 | [diff] [blame] | 1628 | |
Urvang Joshi | 3715b88 | 2018-05-14 20:05:25 -0400 | [diff] [blame] | 1629 | if (params->r[0] == 0) { |
Imdad Sardharwalla | fdeb116 | 2018-02-21 17:38:20 +0000 | [diff] [blame] | 1630 | sgrproj_info->xqd[0] = 0; |
| 1631 | sgrproj_info->xqd[1] = |
| 1632 | aom_read_primitive_refsubexpfin( |
| 1633 | rb, SGRPROJ_PRJ_MAX1 - SGRPROJ_PRJ_MIN1 + 1, SGRPROJ_PRJ_SUBEXP_K, |
| 1634 | ref_sgrproj_info->xqd[1] - SGRPROJ_PRJ_MIN1, ACCT_STR) + |
| 1635 | SGRPROJ_PRJ_MIN1; |
Urvang Joshi | 3715b88 | 2018-05-14 20:05:25 -0400 | [diff] [blame] | 1636 | } else if (params->r[1] == 0) { |
Imdad Sardharwalla | fdeb116 | 2018-02-21 17:38:20 +0000 | [diff] [blame] | 1637 | sgrproj_info->xqd[0] = |
| 1638 | aom_read_primitive_refsubexpfin( |
| 1639 | rb, SGRPROJ_PRJ_MAX0 - SGRPROJ_PRJ_MIN0 + 1, SGRPROJ_PRJ_SUBEXP_K, |
| 1640 | ref_sgrproj_info->xqd[0] - SGRPROJ_PRJ_MIN0, ACCT_STR) + |
| 1641 | SGRPROJ_PRJ_MIN0; |
Debargha Mukherjee | 114575d | 2018-02-23 11:18:37 -0800 | [diff] [blame] | 1642 | sgrproj_info->xqd[1] = clamp((1 << SGRPROJ_PRJ_BITS) - sgrproj_info->xqd[0], |
| 1643 | SGRPROJ_PRJ_MIN1, SGRPROJ_PRJ_MAX1); |
Imdad Sardharwalla | fdeb116 | 2018-02-21 17:38:20 +0000 | [diff] [blame] | 1644 | } else { |
| 1645 | sgrproj_info->xqd[0] = |
| 1646 | aom_read_primitive_refsubexpfin( |
| 1647 | rb, SGRPROJ_PRJ_MAX0 - SGRPROJ_PRJ_MIN0 + 1, SGRPROJ_PRJ_SUBEXP_K, |
| 1648 | ref_sgrproj_info->xqd[0] - SGRPROJ_PRJ_MIN0, ACCT_STR) + |
| 1649 | SGRPROJ_PRJ_MIN0; |
| 1650 | sgrproj_info->xqd[1] = |
| 1651 | aom_read_primitive_refsubexpfin( |
| 1652 | rb, SGRPROJ_PRJ_MAX1 - SGRPROJ_PRJ_MIN1 + 1, SGRPROJ_PRJ_SUBEXP_K, |
| 1653 | ref_sgrproj_info->xqd[1] - SGRPROJ_PRJ_MIN1, ACCT_STR) + |
| 1654 | SGRPROJ_PRJ_MIN1; |
| 1655 | } |
| 1656 | |
| 1657 | memcpy(ref_sgrproj_info, sgrproj_info, sizeof(*sgrproj_info)); |
| 1658 | } |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1659 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1660 | static inline void loop_restoration_read_sb_coeffs(const AV1_COMMON *const cm, |
| 1661 | MACROBLOCKD *xd, |
| 1662 | aom_reader *const r, |
| 1663 | int plane, int runit_idx) { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1664 | const RestorationInfo *rsi = &cm->rst_info[plane]; |
Urvang Joshi | 813186b | 2018-03-08 15:38:46 -0800 | [diff] [blame] | 1665 | RestorationUnitInfo *rui = &rsi->unit_info[runit_idx]; |
Elliott Karpilovsky | 3c5e16f | 2020-11-05 18:43:18 -0800 | [diff] [blame] | 1666 | assert(rsi->frame_restoration_type != RESTORE_NONE); |
Rupert Swarbrick | 09b5b16 | 2017-08-31 16:32:29 +0100 | [diff] [blame] | 1667 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 1668 | assert(!cm->features.all_lossless); |
Urvang Joshi | 5ec7b81 | 2018-02-28 14:37:06 -0800 | [diff] [blame] | 1669 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1670 | const int wiener_win = (plane > 0) ? WIENER_WIN_CHROMA : WIENER_WIN; |
| 1671 | WienerInfo *wiener_info = xd->wiener_info + plane; |
| 1672 | SgrprojInfo *sgrproj_info = xd->sgrproj_info + plane; |
Rupert Swarbrick | 09b5b16 | 2017-08-31 16:32:29 +0100 | [diff] [blame] | 1673 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1674 | if (rsi->frame_restoration_type == RESTORE_SWITCHABLE) { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1675 | rui->restoration_type = |
Debargha Mukherjee | bc732ef | 2017-10-12 12:40:25 -0700 | [diff] [blame] | 1676 | aom_read_symbol(r, xd->tile_ctx->switchable_restore_cdf, |
| 1677 | RESTORE_SWITCHABLE_TYPES, ACCT_STR); |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1678 | switch (rui->restoration_type) { |
| 1679 | case RESTORE_WIENER: |
| 1680 | read_wiener_filter(wiener_win, &rui->wiener_info, wiener_info, r); |
| 1681 | break; |
| 1682 | case RESTORE_SGRPROJ: |
| 1683 | read_sgrproj_filter(&rui->sgrproj_info, sgrproj_info, r); |
| 1684 | break; |
| 1685 | default: assert(rui->restoration_type == RESTORE_NONE); break; |
Rupert Swarbrick | 09b5b16 | 2017-08-31 16:32:29 +0100 | [diff] [blame] | 1686 | } |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1687 | } else if (rsi->frame_restoration_type == RESTORE_WIENER) { |
Debargha Mukherjee | bc732ef | 2017-10-12 12:40:25 -0700 | [diff] [blame] | 1688 | if (aom_read_symbol(r, xd->tile_ctx->wiener_restore_cdf, 2, ACCT_STR)) { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1689 | rui->restoration_type = RESTORE_WIENER; |
| 1690 | read_wiener_filter(wiener_win, &rui->wiener_info, wiener_info, r); |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1691 | } else { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1692 | rui->restoration_type = RESTORE_NONE; |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1693 | } |
| 1694 | } else if (rsi->frame_restoration_type == RESTORE_SGRPROJ) { |
Debargha Mukherjee | bc732ef | 2017-10-12 12:40:25 -0700 | [diff] [blame] | 1695 | if (aom_read_symbol(r, xd->tile_ctx->sgrproj_restore_cdf, 2, ACCT_STR)) { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1696 | rui->restoration_type = RESTORE_SGRPROJ; |
| 1697 | read_sgrproj_filter(&rui->sgrproj_info, sgrproj_info, r); |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1698 | } else { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1699 | rui->restoration_type = RESTORE_NONE; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1700 | } |
| 1701 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1702 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1703 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1704 | static inline void setup_loopfilter(AV1_COMMON *cm, |
| 1705 | struct aom_read_bit_buffer *rb) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1706 | const int num_planes = av1_num_planes(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1707 | struct loopfilter *lf = &cm->lf; |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 1708 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 1709 | if (cm->features.allow_intrabc || cm->features.coded_lossless) { |
Cheng Chen | 7d089ae | 2018-03-15 19:11:03 -0700 | [diff] [blame] | 1710 | // write default deltas to frame buffer |
Cheng Chen | 7d089ae | 2018-03-15 19:11:03 -0700 | [diff] [blame] | 1711 | av1_set_default_ref_deltas(cm->cur_frame->ref_deltas); |
| 1712 | av1_set_default_mode_deltas(cm->cur_frame->mode_deltas); |
Cheng Chen | 7d089ae | 2018-03-15 19:11:03 -0700 | [diff] [blame] | 1713 | return; |
| 1714 | } |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 1715 | assert(!cm->features.coded_lossless); |
Cheng Chen | 7d089ae | 2018-03-15 19:11:03 -0700 | [diff] [blame] | 1716 | if (cm->prev_frame) { |
| 1717 | // write deltas to frame buffer |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 1718 | memcpy(lf->ref_deltas, cm->prev_frame->ref_deltas, REF_FRAMES); |
Cheng Chen | 7d089ae | 2018-03-15 19:11:03 -0700 | [diff] [blame] | 1719 | memcpy(lf->mode_deltas, cm->prev_frame->mode_deltas, MAX_MODE_LF_DELTAS); |
Debargha Mukherjee | 5d94969 | 2018-03-20 14:51:47 -0700 | [diff] [blame] | 1720 | } else { |
| 1721 | av1_set_default_ref_deltas(lf->ref_deltas); |
| 1722 | av1_set_default_mode_deltas(lf->mode_deltas); |
Cheng Chen | 7d089ae | 2018-03-15 19:11:03 -0700 | [diff] [blame] | 1723 | } |
Cheng Chen | 76224b0 | 2017-12-15 12:21:01 -0800 | [diff] [blame] | 1724 | lf->filter_level[0] = aom_rb_read_literal(rb, 6); |
| 1725 | lf->filter_level[1] = aom_rb_read_literal(rb, 6); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1726 | if (num_planes > 1) { |
Cheng Chen | 76224b0 | 2017-12-15 12:21:01 -0800 | [diff] [blame] | 1727 | if (lf->filter_level[0] || lf->filter_level[1]) { |
| 1728 | lf->filter_level_u = aom_rb_read_literal(rb, 6); |
| 1729 | lf->filter_level_v = aom_rb_read_literal(rb, 6); |
Cheng Chen | 765e34e | 2017-12-11 11:43:35 -0800 | [diff] [blame] | 1730 | } |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 1731 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1732 | lf->sharpness_level = aom_rb_read_literal(rb, 3); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1733 | |
| 1734 | // Read in loop filter deltas applied at the MB level based on mode or ref |
| 1735 | // frame. |
| 1736 | lf->mode_ref_delta_update = 0; |
| 1737 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1738 | lf->mode_ref_delta_enabled = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1739 | if (lf->mode_ref_delta_enabled) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1740 | lf->mode_ref_delta_update = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1741 | if (lf->mode_ref_delta_update) { |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 1742 | for (int i = 0; i < REF_FRAMES; i++) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1743 | if (aom_rb_read_bit(rb)) |
| 1744 | lf->ref_deltas[i] = aom_rb_read_inv_signed_literal(rb, 6); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1745 | |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 1746 | for (int i = 0; i < MAX_MODE_LF_DELTAS; i++) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1747 | if (aom_rb_read_bit(rb)) |
| 1748 | lf->mode_deltas[i] = aom_rb_read_inv_signed_literal(rb, 6); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1749 | } |
| 1750 | } |
Cheng Chen | 7d089ae | 2018-03-15 19:11:03 -0700 | [diff] [blame] | 1751 | |
| 1752 | // write deltas to frame buffer |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 1753 | memcpy(cm->cur_frame->ref_deltas, lf->ref_deltas, REF_FRAMES); |
Cheng Chen | 7d089ae | 2018-03-15 19:11:03 -0700 | [diff] [blame] | 1754 | memcpy(cm->cur_frame->mode_deltas, lf->mode_deltas, MAX_MODE_LF_DELTAS); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1757 | static inline void setup_cdef(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1758 | const int num_planes = av1_num_planes(cm); |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1759 | CdefInfo *const cdef_info = &cm->cdef_info; |
| 1760 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 1761 | if (cm->features.allow_intrabc) return; |
Hui Su | 584ba48 | 2019-06-19 11:48:05 -0700 | [diff] [blame] | 1762 | cdef_info->cdef_damping = aom_rb_read_literal(rb, 2) + 3; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 1763 | cdef_info->cdef_bits = aom_rb_read_literal(rb, 2); |
| 1764 | cdef_info->nb_cdef_strengths = 1 << cdef_info->cdef_bits; |
| 1765 | for (int i = 0; i < cdef_info->nb_cdef_strengths; i++) { |
| 1766 | cdef_info->cdef_strengths[i] = aom_rb_read_literal(rb, CDEF_STRENGTH_BITS); |
| 1767 | cdef_info->cdef_uv_strengths[i] = |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1768 | num_planes > 1 ? aom_rb_read_literal(rb, CDEF_STRENGTH_BITS) : 0; |
Jean-Marc Valin | 5f5c132 | 2017-03-21 16:20:21 -0400 | [diff] [blame] | 1769 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1770 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1771 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 1772 | static inline int read_delta_q(struct aom_read_bit_buffer *rb) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1773 | return aom_rb_read_bit(rb) ? aom_rb_read_inv_signed_literal(rb, 6) : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1776 | static inline void setup_quantization(CommonQuantParams *quant_params, |
| 1777 | int num_planes, bool separate_uv_delta_q, |
| 1778 | struct aom_read_bit_buffer *rb) { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1779 | quant_params->base_qindex = aom_rb_read_literal(rb, QINDEX_BITS); |
| 1780 | quant_params->y_dc_delta_q = read_delta_q(rb); |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 1781 | if (num_planes > 1) { |
Debargha Mukherjee | 18f4fb2 | 2017-12-14 14:26:27 -0800 | [diff] [blame] | 1782 | int diff_uv_delta = 0; |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1783 | if (separate_uv_delta_q) diff_uv_delta = aom_rb_read_bit(rb); |
| 1784 | quant_params->u_dc_delta_q = read_delta_q(rb); |
| 1785 | quant_params->u_ac_delta_q = read_delta_q(rb); |
Debargha Mukherjee | 18f4fb2 | 2017-12-14 14:26:27 -0800 | [diff] [blame] | 1786 | if (diff_uv_delta) { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1787 | quant_params->v_dc_delta_q = read_delta_q(rb); |
| 1788 | quant_params->v_ac_delta_q = read_delta_q(rb); |
Debargha Mukherjee | 18f4fb2 | 2017-12-14 14:26:27 -0800 | [diff] [blame] | 1789 | } else { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1790 | quant_params->v_dc_delta_q = quant_params->u_dc_delta_q; |
| 1791 | quant_params->v_ac_delta_q = quant_params->u_ac_delta_q; |
Debargha Mukherjee | 18f4fb2 | 2017-12-14 14:26:27 -0800 | [diff] [blame] | 1792 | } |
Jonathan Matthews | 292bfe2 | 2018-07-26 14:00:53 +0100 | [diff] [blame] | 1793 | } else { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1794 | quant_params->u_dc_delta_q = 0; |
| 1795 | quant_params->u_ac_delta_q = 0; |
| 1796 | quant_params->v_dc_delta_q = 0; |
| 1797 | quant_params->v_ac_delta_q = 0; |
Yaowu Xu | 6fc47e5 | 2017-12-04 15:07:48 -0800 | [diff] [blame] | 1798 | } |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1799 | quant_params->using_qmatrix = aom_rb_read_bit(rb); |
| 1800 | if (quant_params->using_qmatrix) { |
Urvang Joshi | 7fdbd05 | 2020-03-30 17:50:22 -0700 | [diff] [blame] | 1801 | quant_params->qmatrix_level_y = aom_rb_read_literal(rb, QM_LEVEL_BITS); |
| 1802 | quant_params->qmatrix_level_u = aom_rb_read_literal(rb, QM_LEVEL_BITS); |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1803 | if (!separate_uv_delta_q) |
Urvang Joshi | 7fdbd05 | 2020-03-30 17:50:22 -0700 | [diff] [blame] | 1804 | quant_params->qmatrix_level_v = quant_params->qmatrix_level_u; |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 1805 | else |
Urvang Joshi | 7fdbd05 | 2020-03-30 17:50:22 -0700 | [diff] [blame] | 1806 | quant_params->qmatrix_level_v = aom_rb_read_literal(rb, QM_LEVEL_BITS); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1807 | } else { |
Urvang Joshi | 7fdbd05 | 2020-03-30 17:50:22 -0700 | [diff] [blame] | 1808 | quant_params->qmatrix_level_y = 0; |
| 1809 | quant_params->qmatrix_level_u = 0; |
| 1810 | quant_params->qmatrix_level_v = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1811 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
James Zern | f3cf030 | 2024-09-11 13:43:35 -0700 | [diff] [blame^] | 1814 | // Get global dequant matrix. |
| 1815 | static const qm_val_t *get_iqmatrix(const CommonQuantParams *quant_params, |
| 1816 | int qmlevel, int plane, TX_SIZE tx_size) { |
| 1817 | assert(quant_params->giqmatrix[qmlevel][plane][tx_size] != NULL || |
| 1818 | qmlevel == NUM_QM_LEVELS - 1); |
| 1819 | return quant_params->giqmatrix[qmlevel][plane][tx_size]; |
| 1820 | } |
| 1821 | |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1822 | // Build y/uv dequant values based on segmentation. |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1823 | static inline void setup_segmentation_dequant(AV1_COMMON *const cm, |
| 1824 | MACROBLOCKD *const xd) { |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 1825 | const int bit_depth = cm->seq_params->bit_depth; |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1826 | // When segmentation is disabled, only the first value is used. The |
| 1827 | // remaining are don't cares. |
| 1828 | const int max_segments = cm->seg.enabled ? MAX_SEGMENTS : 1; |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1829 | CommonQuantParams *const quant_params = &cm->quant_params; |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1830 | for (int i = 0; i < max_segments; ++i) { |
Wan-Teh Chang | 98c01e0 | 2018-10-18 09:48:27 -0700 | [diff] [blame] | 1831 | const int qindex = xd->qindex[i]; |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1832 | quant_params->y_dequant_QTX[i][0] = |
| 1833 | av1_dc_quant_QTX(qindex, quant_params->y_dc_delta_q, bit_depth); |
| 1834 | quant_params->y_dequant_QTX[i][1] = av1_ac_quant_QTX(qindex, 0, bit_depth); |
| 1835 | quant_params->u_dequant_QTX[i][0] = |
| 1836 | av1_dc_quant_QTX(qindex, quant_params->u_dc_delta_q, bit_depth); |
| 1837 | quant_params->u_dequant_QTX[i][1] = |
| 1838 | av1_ac_quant_QTX(qindex, quant_params->u_ac_delta_q, bit_depth); |
| 1839 | quant_params->v_dequant_QTX[i][0] = |
| 1840 | av1_dc_quant_QTX(qindex, quant_params->v_dc_delta_q, bit_depth); |
| 1841 | quant_params->v_dequant_QTX[i][1] = |
| 1842 | av1_ac_quant_QTX(qindex, quant_params->v_ac_delta_q, bit_depth); |
| 1843 | const int use_qmatrix = av1_use_qmatrix(quant_params, xd, i); |
Yaowu Xu | 3b54633 | 2018-03-26 12:53:46 -0700 | [diff] [blame] | 1844 | // NB: depends on base index so there is only 1 set per frame |
| 1845 | // No quant weighting when lossless or signalled not using QM |
Urvang Joshi | 7fdbd05 | 2020-03-30 17:50:22 -0700 | [diff] [blame] | 1846 | const int qmlevel_y = |
| 1847 | use_qmatrix ? quant_params->qmatrix_level_y : NUM_QM_LEVELS - 1; |
Thomas Davies | 6675adf | 2017-05-04 17:39:21 +0100 | [diff] [blame] | 1848 | for (int j = 0; j < TX_SIZES_ALL; ++j) { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1849 | quant_params->y_iqmatrix[i][j] = |
James Zern | f3cf030 | 2024-09-11 13:43:35 -0700 | [diff] [blame^] | 1850 | get_iqmatrix(quant_params, qmlevel_y, AOM_PLANE_Y, j); |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 1851 | } |
Urvang Joshi | 7fdbd05 | 2020-03-30 17:50:22 -0700 | [diff] [blame] | 1852 | const int qmlevel_u = |
| 1853 | use_qmatrix ? quant_params->qmatrix_level_u : NUM_QM_LEVELS - 1; |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 1854 | for (int j = 0; j < TX_SIZES_ALL; ++j) { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1855 | quant_params->u_iqmatrix[i][j] = |
James Zern | f3cf030 | 2024-09-11 13:43:35 -0700 | [diff] [blame^] | 1856 | get_iqmatrix(quant_params, qmlevel_u, AOM_PLANE_U, j); |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 1857 | } |
Urvang Joshi | 7fdbd05 | 2020-03-30 17:50:22 -0700 | [diff] [blame] | 1858 | const int qmlevel_v = |
| 1859 | use_qmatrix ? quant_params->qmatrix_level_v : NUM_QM_LEVELS - 1; |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 1860 | for (int j = 0; j < TX_SIZES_ALL; ++j) { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 1861 | quant_params->v_iqmatrix[i][j] = |
James Zern | f3cf030 | 2024-09-11 13:43:35 -0700 | [diff] [blame^] | 1862 | get_iqmatrix(quant_params, qmlevel_v, AOM_PLANE_V, j); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1863 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | |
Angie Chiang | 5678ad9 | 2016-11-21 09:38:40 -0800 | [diff] [blame] | 1867 | static InterpFilter read_frame_interp_filter(struct aom_read_bit_buffer *rb) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1868 | return aom_rb_read_bit(rb) ? SWITCHABLE |
Angie Chiang | 6305abe | 2016-10-24 12:24:44 -0700 | [diff] [blame] | 1869 | : aom_rb_read_literal(rb, LOG_SWITCHABLE_FILTERS); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1872 | static inline void setup_render_size(AV1_COMMON *cm, |
| 1873 | struct aom_read_bit_buffer *rb) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1874 | cm->render_width = cm->superres_upscaled_width; |
| 1875 | cm->render_height = cm->superres_upscaled_height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1876 | if (aom_rb_read_bit(rb)) |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 1877 | av1_read_frame_size(rb, 16, 16, &cm->render_width, &cm->render_height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1878 | } |
| 1879 | |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1880 | // TODO(afergs): make "struct aom_read_bit_buffer *const rb"? |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1881 | static inline void setup_superres(AV1_COMMON *const cm, |
| 1882 | struct aom_read_bit_buffer *rb, int *width, |
| 1883 | int *height) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1884 | cm->superres_upscaled_width = *width; |
| 1885 | cm->superres_upscaled_height = *height; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 1886 | |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 1887 | const SequenceHeader *const seq_params = cm->seq_params; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 1888 | if (!seq_params->enable_superres) return; |
| 1889 | |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1890 | if (aom_rb_read_bit(rb)) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1891 | cm->superres_scale_denominator = |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1892 | (uint8_t)aom_rb_read_literal(rb, SUPERRES_SCALE_BITS); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1893 | cm->superres_scale_denominator += SUPERRES_SCALE_DENOMINATOR_MIN; |
Fergus Simpson | 7b2d144 | 2017-05-22 17:18:33 -0700 | [diff] [blame] | 1894 | // Don't edit cm->width or cm->height directly, or the buffers won't get |
| 1895 | // resized correctly |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 1896 | av1_calculate_scaled_superres_size(width, height, |
| 1897 | cm->superres_scale_denominator); |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1898 | } else { |
| 1899 | // 1:1 scaling - ie. no scaling, scale not provided |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1900 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1901 | } |
| 1902 | } |
Soo-Chul Han | 2638cb5 | 2017-11-22 16:34:47 -0500 | [diff] [blame] | 1903 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1904 | static inline void resize_context_buffers(AV1_COMMON *cm, int width, |
| 1905 | int height) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1906 | #if CONFIG_SIZE_LIMIT |
| 1907 | if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 1908 | aom_internal_error(cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1909 | "Dimensions of %dx%d beyond allowed size of %dx%d.", |
| 1910 | width, height, DECODE_WIDTH_LIMIT, DECODE_HEIGHT_LIMIT); |
| 1911 | #endif |
| 1912 | if (cm->width != width || cm->height != height) { |
Mudassir Galagnath | 77f3160 | 2022-04-19 16:28:25 +0530 | [diff] [blame] | 1913 | const int new_mi_rows = CEIL_POWER_OF_TWO(height, MI_SIZE_LOG2); |
| 1914 | const int new_mi_cols = CEIL_POWER_OF_TWO(width, MI_SIZE_LOG2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1915 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1916 | // Allocations in av1_alloc_context_buffers() depend on individual |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1917 | // dimensions as well as the overall size. |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1918 | if (new_mi_cols > cm->mi_params.mi_cols || |
| 1919 | new_mi_rows > cm->mi_params.mi_rows) { |
Jayasanker J | fb66696 | 2022-03-29 18:56:42 +0530 | [diff] [blame] | 1920 | if (av1_alloc_context_buffers(cm, width, height, BLOCK_4X4)) { |
Wan-Teh Chang | fb0dd0b | 2018-07-11 15:03:14 -0700 | [diff] [blame] | 1921 | // The cm->mi_* values have been cleared and any existing context |
| 1922 | // buffers have been freed. Clear cm->width and cm->height to be |
| 1923 | // consistent and to force a realloc next time. |
| 1924 | cm->width = 0; |
| 1925 | cm->height = 0; |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 1926 | aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1927 | "Failed to allocate context buffers"); |
Wan-Teh Chang | fb0dd0b | 2018-07-11 15:03:14 -0700 | [diff] [blame] | 1928 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1929 | } else { |
Jayasanker J | fb66696 | 2022-03-29 18:56:42 +0530 | [diff] [blame] | 1930 | cm->mi_params.set_mb_mi(&cm->mi_params, width, height, BLOCK_4X4); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1931 | } |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 1932 | av1_init_mi_buffers(&cm->mi_params); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1933 | cm->width = width; |
| 1934 | cm->height = height; |
| 1935 | } |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 1936 | |
| 1937 | ensure_mv_buffer(cm->cur_frame, cm); |
| 1938 | cm->cur_frame->width = cm->width; |
| 1939 | cm->cur_frame->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1942 | static inline void setup_buffer_pool(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1943 | BufferPool *const pool = cm->buffer_pool; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 1944 | const SequenceHeader *const seq_params = cm->seq_params; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1945 | |
| 1946 | lock_buffer_pool(pool); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1947 | if (aom_realloc_frame_buffer( |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 1948 | &cm->cur_frame->buf, cm->width, cm->height, seq_params->subsampling_x, |
| 1949 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 1950 | AOM_DEC_BORDER_IN_PIXELS, cm->features.byte_alignment, |
Rachel Barker | 72e349e | 2024-02-13 14:31:10 +0000 | [diff] [blame] | 1951 | &cm->cur_frame->raw_frame_buffer, pool->get_fb_cb, pool->cb_priv, |
| 1952 | false, 0)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1953 | unlock_buffer_pool(pool); |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 1954 | aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1955 | "Failed to allocate frame buffer"); |
| 1956 | } |
| 1957 | unlock_buffer_pool(pool); |
| 1958 | |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 1959 | cm->cur_frame->buf.bit_depth = (unsigned int)seq_params->bit_depth; |
| 1960 | cm->cur_frame->buf.color_primaries = seq_params->color_primaries; |
| 1961 | cm->cur_frame->buf.transfer_characteristics = |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1962 | seq_params->transfer_characteristics; |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 1963 | cm->cur_frame->buf.matrix_coefficients = seq_params->matrix_coefficients; |
| 1964 | cm->cur_frame->buf.monochrome = seq_params->monochrome; |
| 1965 | cm->cur_frame->buf.chroma_sample_position = |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 1966 | seq_params->chroma_sample_position; |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 1967 | cm->cur_frame->buf.color_range = seq_params->color_range; |
| 1968 | cm->cur_frame->buf.render_width = cm->render_width; |
| 1969 | cm->cur_frame->buf.render_height = cm->render_height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1972 | static inline void setup_frame_size(AV1_COMMON *cm, |
| 1973 | int frame_size_override_flag, |
| 1974 | struct aom_read_bit_buffer *rb) { |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 1975 | const SequenceHeader *const seq_params = cm->seq_params; |
Urvang Joshi | c9497b2 | 2018-08-03 12:40:02 -0700 | [diff] [blame] | 1976 | int width, height; |
| 1977 | |
| 1978 | if (frame_size_override_flag) { |
| 1979 | int num_bits_width = seq_params->num_bits_width; |
| 1980 | int num_bits_height = seq_params->num_bits_height; |
| 1981 | av1_read_frame_size(rb, num_bits_width, num_bits_height, &width, &height); |
| 1982 | if (width > seq_params->max_frame_width || |
| 1983 | height > seq_params->max_frame_height) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 1984 | aom_internal_error(cm->error, AOM_CODEC_CORRUPT_FRAME, |
Urvang Joshi | c9497b2 | 2018-08-03 12:40:02 -0700 | [diff] [blame] | 1985 | "Frame dimensions are larger than the maximum values"); |
| 1986 | } |
| 1987 | } else { |
| 1988 | width = seq_params->max_frame_width; |
| 1989 | height = seq_params->max_frame_height; |
| 1990 | } |
| 1991 | |
| 1992 | setup_superres(cm, rb, &width, &height); |
| 1993 | resize_context_buffers(cm, width, height); |
| 1994 | setup_render_size(cm, rb); |
| 1995 | setup_buffer_pool(cm); |
| 1996 | } |
| 1997 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 1998 | static inline void setup_sb_size(SequenceHeader *seq_params, |
| 1999 | struct aom_read_bit_buffer *rb) { |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 2000 | set_sb_size(seq_params, aom_rb_read_bit(rb) ? BLOCK_128X128 : BLOCK_64X64); |
Debargha Mukherjee | d2630fa | 2017-09-22 10:32:51 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 2003 | static inline int valid_ref_frame_img_fmt(aom_bit_depth_t ref_bit_depth, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2004 | int ref_xss, int ref_yss, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2005 | aom_bit_depth_t this_bit_depth, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2006 | int this_xss, int this_yss) { |
| 2007 | return ref_bit_depth == this_bit_depth && ref_xss == this_xss && |
| 2008 | ref_yss == this_yss; |
| 2009 | } |
| 2010 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2011 | static inline void setup_frame_size_with_refs(AV1_COMMON *cm, |
| 2012 | struct aom_read_bit_buffer *rb) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2013 | int width, height; |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2014 | int found = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2015 | int has_valid_ref_frame = 0; |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 2016 | for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2017 | if (aom_rb_read_bit(rb)) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 2018 | const RefCntBuffer *const ref_buf = get_ref_frame_buf(cm, i); |
| 2019 | // This will never be NULL in a normal stream, as streams are required to |
| 2020 | // have a shown keyframe before any inter frames, which would refresh all |
| 2021 | // the reference buffers. However, it might be null if we're starting in |
| 2022 | // the middle of a stream, and static analysis will error if we don't do |
| 2023 | // a null check here. |
| 2024 | if (ref_buf == NULL) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2025 | aom_internal_error(cm->error, AOM_CODEC_CORRUPT_FRAME, |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 2026 | "Invalid condition: invalid reference buffer"); |
| 2027 | } else { |
| 2028 | const YV12_BUFFER_CONFIG *const buf = &ref_buf->buf; |
| 2029 | width = buf->y_crop_width; |
| 2030 | height = buf->y_crop_height; |
| 2031 | cm->render_width = buf->render_width; |
| 2032 | cm->render_height = buf->render_height; |
| 2033 | setup_superres(cm, rb, &width, &height); |
| 2034 | resize_context_buffers(cm, width, height); |
| 2035 | found = 1; |
| 2036 | break; |
| 2037 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2038 | } |
| 2039 | } |
| 2040 | |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 2041 | const SequenceHeader *const seq_params = cm->seq_params; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2042 | if (!found) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2043 | int num_bits_width = seq_params->num_bits_width; |
| 2044 | int num_bits_height = seq_params->num_bits_height; |
Tom Finegan | 8ab2bba | 2018-02-28 07:36:28 -0800 | [diff] [blame] | 2045 | |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 2046 | av1_read_frame_size(rb, num_bits_width, num_bits_height, &width, &height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 2047 | setup_superres(cm, rb, &width, &height); |
David Barker | 6e5ade9 | 2017-11-17 13:56:38 +0000 | [diff] [blame] | 2048 | resize_context_buffers(cm, width, height); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 2049 | setup_render_size(cm, rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | if (width <= 0 || height <= 0) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2053 | aom_internal_error(cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2054 | "Invalid frame size"); |
| 2055 | |
| 2056 | // Check to make sure at least one of frames that this frame references |
| 2057 | // has valid dimensions. |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 2058 | for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 2059 | const RefCntBuffer *const ref_frame = get_ref_frame_buf(cm, i); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2060 | has_valid_ref_frame |= |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 2061 | valid_ref_frame_size(ref_frame->buf.y_crop_width, |
| 2062 | ref_frame->buf.y_crop_height, width, height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2063 | } |
| 2064 | if (!has_valid_ref_frame) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2065 | aom_internal_error(cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2066 | "Referenced frame has invalid size"); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 2067 | for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 2068 | const RefCntBuffer *const ref_frame = get_ref_frame_buf(cm, i); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2069 | if (!valid_ref_frame_img_fmt( |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 2070 | ref_frame->buf.bit_depth, ref_frame->buf.subsampling_x, |
| 2071 | ref_frame->buf.subsampling_y, seq_params->bit_depth, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 2072 | seq_params->subsampling_x, seq_params->subsampling_y)) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2073 | aom_internal_error(cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2074 | "Referenced frame has incompatible color format"); |
| 2075 | } |
Urvang Joshi | c9497b2 | 2018-08-03 12:40:02 -0700 | [diff] [blame] | 2076 | setup_buffer_pool(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2079 | // Same function as av1_read_uniform but reading from uncompresses header wb |
| 2080 | static int rb_read_uniform(struct aom_read_bit_buffer *const rb, int n) { |
| 2081 | const int l = get_unsigned_bits(n); |
| 2082 | const int m = (1 << l) - n; |
| 2083 | const int v = aom_rb_read_literal(rb, l - 1); |
| 2084 | assert(l != 0); |
| 2085 | if (v < m) |
| 2086 | return v; |
| 2087 | else |
Wan-Teh Chang | b6680ff | 2018-07-27 14:50:25 -0700 | [diff] [blame] | 2088 | return (v << 1) - m + aom_rb_read_bit(rb); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2089 | } |
| 2090 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2091 | static inline void read_tile_info_max_tile( |
Elliott Karpilovsky | 18fcd6a | 2019-09-16 15:15:06 -0700 | [diff] [blame] | 2092 | AV1_COMMON *const cm, struct aom_read_bit_buffer *const rb) { |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 2093 | const SequenceHeader *const seq_params = cm->seq_params; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2094 | CommonTileParams *const tiles = &cm->tiles; |
Mudassir Galagnath | 77f3160 | 2022-04-19 16:28:25 +0530 | [diff] [blame] | 2095 | int width_sb = |
| 2096 | CEIL_POWER_OF_TWO(cm->mi_params.mi_cols, seq_params->mib_size_log2); |
| 2097 | int height_sb = |
| 2098 | CEIL_POWER_OF_TWO(cm->mi_params.mi_rows, seq_params->mib_size_log2); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2099 | |
| 2100 | av1_get_tile_limits(cm); |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2101 | tiles->uniform_spacing = aom_rb_read_bit(rb); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2102 | |
| 2103 | // Read tile columns |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2104 | if (tiles->uniform_spacing) { |
| 2105 | tiles->log2_cols = tiles->min_log2_cols; |
| 2106 | while (tiles->log2_cols < tiles->max_log2_cols) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2107 | if (!aom_rb_read_bit(rb)) { |
| 2108 | break; |
| 2109 | } |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2110 | tiles->log2_cols++; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2111 | } |
| 2112 | } else { |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2113 | int i; |
| 2114 | int start_sb; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 2115 | for (i = 0, start_sb = 0; width_sb > 0 && i < MAX_TILE_COLS; i++) { |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2116 | const int size_sb = |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2117 | 1 + rb_read_uniform(rb, AOMMIN(width_sb, tiles->max_width_sb)); |
| 2118 | tiles->col_start_sb[i] = start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2119 | start_sb += size_sb; |
| 2120 | width_sb -= size_sb; |
| 2121 | } |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2122 | tiles->cols = i; |
| 2123 | tiles->col_start_sb[i] = start_sb + width_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2124 | } |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 2125 | av1_calculate_tile_cols(seq_params, cm->mi_params.mi_rows, |
| 2126 | cm->mi_params.mi_cols, tiles); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2127 | |
| 2128 | // Read tile rows |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2129 | if (tiles->uniform_spacing) { |
| 2130 | tiles->log2_rows = tiles->min_log2_rows; |
| 2131 | while (tiles->log2_rows < tiles->max_log2_rows) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2132 | if (!aom_rb_read_bit(rb)) { |
| 2133 | break; |
| 2134 | } |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2135 | tiles->log2_rows++; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2136 | } |
| 2137 | } else { |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2138 | int i; |
| 2139 | int start_sb; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 2140 | for (i = 0, start_sb = 0; height_sb > 0 && i < MAX_TILE_ROWS; i++) { |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2141 | const int size_sb = |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2142 | 1 + rb_read_uniform(rb, AOMMIN(height_sb, tiles->max_height_sb)); |
| 2143 | tiles->row_start_sb[i] = start_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2144 | start_sb += size_sb; |
| 2145 | height_sb -= size_sb; |
| 2146 | } |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2147 | tiles->rows = i; |
| 2148 | tiles->row_start_sb[i] = start_sb + height_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2149 | } |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 2150 | av1_calculate_tile_rows(seq_params, cm->mi_params.mi_rows, tiles); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2151 | } |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 2152 | |
Yunqing Wang | 2f7b7a9 | 2018-06-11 10:07:23 -0700 | [diff] [blame] | 2153 | void av1_set_single_tile_decoding_mode(AV1_COMMON *const cm) { |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2154 | cm->tiles.single_tile_decoding = 0; |
| 2155 | if (cm->tiles.large_scale) { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2156 | struct loopfilter *lf = &cm->lf; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 2157 | RestorationInfo *const rst_info = cm->rst_info; |
| 2158 | const CdefInfo *const cdef_info = &cm->cdef_info; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2159 | |
Debargha Mukherjee | 2382b14 | 2018-02-26 14:31:32 -0800 | [diff] [blame] | 2160 | // Figure out single_tile_decoding by loopfilter_level. |
Rupert Swarbrick | 566155f | 2017-10-27 11:59:17 +0100 | [diff] [blame] | 2161 | const int no_loopfilter = !(lf->filter_level[0] || lf->filter_level[1]); |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 2162 | const int no_cdef = cdef_info->cdef_bits == 0 && |
| 2163 | cdef_info->cdef_strengths[0] == 0 && |
| 2164 | cdef_info->cdef_uv_strengths[0] == 0; |
Yaowu Xu | 35ee234 | 2017-11-08 11:50:46 -0800 | [diff] [blame] | 2165 | const int no_restoration = |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 2166 | rst_info[0].frame_restoration_type == RESTORE_NONE && |
| 2167 | rst_info[1].frame_restoration_type == RESTORE_NONE && |
| 2168 | rst_info[2].frame_restoration_type == RESTORE_NONE; |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 2169 | assert(IMPLIES(cm->features.coded_lossless, no_loopfilter && no_cdef)); |
| 2170 | assert(IMPLIES(cm->features.all_lossless, no_restoration)); |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2171 | cm->tiles.single_tile_decoding = no_loopfilter && no_cdef && no_restoration; |
Yunqing Wang | a10b46b | 2018-03-22 15:36:56 -0700 | [diff] [blame] | 2172 | } |
| 2173 | } |
| 2174 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2175 | static inline void read_tile_info(AV1Decoder *const pbi, |
| 2176 | struct aom_read_bit_buffer *const rb) { |
Yunqing Wang | a10b46b | 2018-03-22 15:36:56 -0700 | [diff] [blame] | 2177 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2178 | |
James Zern | 3df52f8 | 2018-02-26 12:57:14 -0800 | [diff] [blame] | 2179 | read_tile_info_max_tile(cm, rb); |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 2180 | |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 2181 | pbi->context_update_tile_id = 0; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2182 | if (cm->tiles.rows * cm->tiles.cols > 1) { |
Dominic Symes | a48289a | 2018-04-03 21:07:59 +0200 | [diff] [blame] | 2183 | // tile to use for cdf update |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 2184 | pbi->context_update_tile_id = |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2185 | aom_rb_read_literal(rb, cm->tiles.log2_rows + cm->tiles.log2_cols); |
| 2186 | if (pbi->context_update_tile_id >= cm->tiles.rows * cm->tiles.cols) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2187 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Wan-Teh Chang | 7c24185 | 2018-08-04 15:48:49 -0700 | [diff] [blame] | 2188 | "Invalid context_update_tile_id"); |
| 2189 | } |
James Zern | 9e9f7ad | 2018-03-02 17:38:53 -0800 | [diff] [blame] | 2190 | // tile size magnitude |
| 2191 | pbi->tile_size_bytes = aom_rb_read_literal(rb, 2) + 1; |
| 2192 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
Yunqing Wang | 445739a | 2018-06-10 12:27:34 -0700 | [diff] [blame] | 2195 | #if EXT_TILE_DEBUG |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2196 | static inline void read_ext_tile_info(AV1Decoder *const pbi, |
| 2197 | struct aom_read_bit_buffer *const rb) { |
Yunqing Wang | 445739a | 2018-06-10 12:27:34 -0700 | [diff] [blame] | 2198 | AV1_COMMON *const cm = &pbi->common; |
| 2199 | |
Yunqing Wang | 3f9c1e2 | 2018-06-16 16:48:15 -0700 | [diff] [blame] | 2200 | // This information is stored as a separate byte. |
| 2201 | int mod = rb->bit_offset % CHAR_BIT; |
| 2202 | if (mod > 0) aom_rb_read_literal(rb, CHAR_BIT - mod); |
| 2203 | assert(rb->bit_offset % CHAR_BIT == 0); |
| 2204 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2205 | if (cm->tiles.cols * cm->tiles.rows > 1) { |
Yunqing Wang | 445739a | 2018-06-10 12:27:34 -0700 | [diff] [blame] | 2206 | // Read the number of bytes used to store tile size |
| 2207 | pbi->tile_col_size_bytes = aom_rb_read_literal(rb, 2) + 1; |
| 2208 | pbi->tile_size_bytes = aom_rb_read_literal(rb, 2) + 1; |
| 2209 | } |
Yunqing Wang | 445739a | 2018-06-10 12:27:34 -0700 | [diff] [blame] | 2210 | } |
| 2211 | #endif // EXT_TILE_DEBUG |
| 2212 | |
Hui Su | 5ab25aa | 2018-04-25 12:25:05 -0700 | [diff] [blame] | 2213 | static size_t mem_get_varsize(const uint8_t *src, int sz) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2214 | switch (sz) { |
| 2215 | case 1: return src[0]; |
| 2216 | case 2: return mem_get_le16(src); |
| 2217 | case 3: return mem_get_le24(src); |
| 2218 | case 4: return mem_get_le32(src); |
James Zern | 8889673 | 2017-06-23 15:55:09 -0700 | [diff] [blame] | 2219 | default: assert(0 && "Invalid size"); return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | |
Yunqing Wang | 3a74b25 | 2018-05-03 15:24:07 -0700 | [diff] [blame] | 2223 | #if EXT_TILE_DEBUG |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2224 | // Reads the next tile returning its size and adjusting '*data' accordingly |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2225 | // based on 'is_last'. On return, '*data' is updated to point to the end of the |
| 2226 | // raw tile buffer in the bit stream. |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2227 | static inline void get_ls_tile_buffer( |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2228 | const uint8_t *const data_end, struct aom_internal_error_info *error_info, |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 2229 | const uint8_t **data, TileBufferDec (*const tile_buffers)[MAX_TILE_COLS], |
| 2230 | int tile_size_bytes, int col, int row, int tile_copy_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2231 | size_t size; |
| 2232 | |
| 2233 | size_t copy_size = 0; |
| 2234 | const uint8_t *copy_data = NULL; |
| 2235 | |
| 2236 | if (!read_is_valid(*data, tile_size_bytes, data_end)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2237 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2238 | "Truncated packet or corrupt tile length"); |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 2239 | size = mem_get_varsize(*data, tile_size_bytes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2240 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2241 | // If tile_copy_mode = 1, then the top bit of the tile header indicates copy |
| 2242 | // mode. |
| 2243 | if (tile_copy_mode && (size >> (tile_size_bytes * 8 - 1)) == 1) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2244 | // The remaining bits in the top byte signal the row offset |
| 2245 | int offset = (size >> (tile_size_bytes - 1) * 8) & 0x7f; |
Wan-Teh Chang | 4aefb93 | 2024-05-28 14:24:57 -0700 | [diff] [blame] | 2246 | if (offset > row) { |
| 2247 | aom_internal_error( |
| 2248 | error_info, AOM_CODEC_CORRUPT_FRAME, |
| 2249 | "Invalid row offset in tile copy mode: row=%d offset=%d", row, |
| 2250 | offset); |
| 2251 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2252 | |
| 2253 | // Currently, only use tiles in same column as reference tiles. |
| 2254 | copy_data = tile_buffers[row - offset][col].data; |
| 2255 | copy_size = tile_buffers[row - offset][col].size; |
| 2256 | size = 0; |
James Zern | 2f22bfd | 2018-03-10 12:58:22 -0800 | [diff] [blame] | 2257 | } else { |
| 2258 | size += AV1_MIN_TILE_SIZE_BYTES; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | *data += tile_size_bytes; |
| 2262 | |
| 2263 | if (size > (size_t)(data_end - *data)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2264 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2265 | "Truncated packet or corrupt tile size"); |
| 2266 | |
| 2267 | if (size > 0) { |
| 2268 | tile_buffers[row][col].data = *data; |
| 2269 | tile_buffers[row][col].size = size; |
| 2270 | } else { |
| 2271 | tile_buffers[row][col].data = copy_data; |
| 2272 | tile_buffers[row][col].size = copy_size; |
| 2273 | } |
| 2274 | |
| 2275 | *data += size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2278 | // Returns the end of the last tile buffer |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2279 | // (tile_buffers[cm->tiles.rows - 1][cm->tiles.cols - 1]). |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2280 | static const uint8_t *get_ls_tile_buffers( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2281 | AV1Decoder *pbi, const uint8_t *data, const uint8_t *data_end, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2282 | TileBufferDec (*const tile_buffers)[MAX_TILE_COLS]) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2283 | AV1_COMMON *const cm = &pbi->common; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2284 | const int tile_cols = cm->tiles.cols; |
| 2285 | const int tile_rows = cm->tiles.rows; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2286 | const int have_tiles = tile_cols * tile_rows > 1; |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2287 | const uint8_t *raw_data_end; // The end of the last tile buffer |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2288 | |
| 2289 | if (!have_tiles) { |
Jingning Han | 99ffce6 | 2017-04-25 15:48:41 -0700 | [diff] [blame] | 2290 | const size_t tile_size = data_end - data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2291 | tile_buffers[0][0].data = data; |
| 2292 | tile_buffers[0][0].size = tile_size; |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2293 | raw_data_end = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2294 | } else { |
| 2295 | // We locate only the tile buffers that are required, which are the ones |
| 2296 | // specified by pbi->dec_tile_col and pbi->dec_tile_row. Also, we always |
| 2297 | // need the last (bottom right) tile buffer, as we need to know where the |
| 2298 | // end of the compressed frame buffer is for proper superframe decoding. |
| 2299 | |
Yunqing Wang | ecc0734 | 2018-02-26 16:45:38 -0800 | [diff] [blame] | 2300 | const uint8_t *tile_col_data_end[MAX_TILE_COLS] = { NULL }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2301 | const uint8_t *const data_start = data; |
| 2302 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2303 | const int dec_tile_row = AOMMIN(pbi->dec_tile_row, tile_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2304 | const int single_row = pbi->dec_tile_row >= 0; |
| 2305 | const int tile_rows_start = single_row ? dec_tile_row : 0; |
| 2306 | const int tile_rows_end = single_row ? tile_rows_start + 1 : tile_rows; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2307 | const int dec_tile_col = AOMMIN(pbi->dec_tile_col, tile_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2308 | const int single_col = pbi->dec_tile_col >= 0; |
| 2309 | const int tile_cols_start = single_col ? dec_tile_col : 0; |
| 2310 | const int tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; |
| 2311 | |
| 2312 | const int tile_col_size_bytes = pbi->tile_col_size_bytes; |
| 2313 | const int tile_size_bytes = pbi->tile_size_bytes; |
Frederic Barbier | 9662189 | 2018-11-29 14:48:01 +0100 | [diff] [blame] | 2314 | int tile_width, tile_height; |
Wan-Teh Chang | cc71588 | 2024-03-04 13:52:25 -0800 | [diff] [blame] | 2315 | if (!av1_get_uniform_tile_size(cm, &tile_width, &tile_height)) { |
| 2316 | aom_internal_error( |
| 2317 | &pbi->error, AOM_CODEC_CORRUPT_FRAME, |
| 2318 | "Not all the tiles in the tile list have the same size."); |
| 2319 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2320 | const int tile_copy_mode = |
Frederic Barbier | 9662189 | 2018-11-29 14:48:01 +0100 | [diff] [blame] | 2321 | ((AOMMAX(tile_width, tile_height) << MI_SIZE_LOG2) <= 256) ? 1 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2322 | // Read tile column sizes for all columns (we need the last tile buffer) |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2323 | for (int c = 0; c < tile_cols; ++c) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2324 | const int is_last = c == tile_cols - 1; |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2325 | size_t tile_col_size; |
| 2326 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2327 | if (!is_last) { |
Wan-Teh Chang | 08efc14 | 2024-03-04 17:11:12 -0800 | [diff] [blame] | 2328 | if (tile_col_size_bytes > data_end - data) { |
| 2329 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
| 2330 | "Not enough data to read tile_col_size"); |
| 2331 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2332 | tile_col_size = mem_get_varsize(data, tile_col_size_bytes); |
| 2333 | data += tile_col_size_bytes; |
Wan-Teh Chang | 08efc14 | 2024-03-04 17:11:12 -0800 | [diff] [blame] | 2334 | if (tile_col_size > (size_t)(data_end - data)) { |
| 2335 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
| 2336 | "tile_col_data_end[%d] is out of bound", c); |
| 2337 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2338 | tile_col_data_end[c] = data + tile_col_size; |
| 2339 | } else { |
| 2340 | tile_col_size = data_end - data; |
| 2341 | tile_col_data_end[c] = data_end; |
| 2342 | } |
| 2343 | data += tile_col_size; |
| 2344 | } |
| 2345 | |
| 2346 | data = data_start; |
| 2347 | |
| 2348 | // Read the required tile sizes. |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2349 | for (int c = tile_cols_start; c < tile_cols_end; ++c) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2350 | const int is_last = c == tile_cols - 1; |
| 2351 | |
| 2352 | if (c > 0) data = tile_col_data_end[c - 1]; |
| 2353 | |
| 2354 | if (!is_last) data += tile_col_size_bytes; |
| 2355 | |
| 2356 | // Get the whole of the last column, otherwise stop at the required tile. |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2357 | for (int r = 0; r < (is_last ? tile_rows : tile_rows_end); ++r) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2358 | get_ls_tile_buffer(tile_col_data_end[c], &pbi->error, &data, |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 2359 | tile_buffers, tile_size_bytes, c, r, tile_copy_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | // If we have not read the last column, then read it to get the last tile. |
| 2364 | if (tile_cols_end != tile_cols) { |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2365 | const int c = tile_cols - 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2366 | |
| 2367 | data = tile_col_data_end[c - 1]; |
| 2368 | |
Sebastien Alaiwan | 3e4068e | 2017-12-01 14:23:45 +0100 | [diff] [blame] | 2369 | for (int r = 0; r < tile_rows; ++r) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2370 | get_ls_tile_buffer(tile_col_data_end[c], &pbi->error, &data, |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 2371 | tile_buffers, tile_size_bytes, c, r, tile_copy_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2372 | } |
| 2373 | } |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2374 | raw_data_end = data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2375 | } |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2376 | return raw_data_end; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2377 | } |
Yunqing Wang | 3a74b25 | 2018-05-03 15:24:07 -0700 | [diff] [blame] | 2378 | #endif // EXT_TILE_DEBUG |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2379 | |
Yunqing Wang | d7546d4 | 2018-06-06 15:08:05 -0700 | [diff] [blame] | 2380 | static const uint8_t *get_ls_single_tile_buffer( |
| 2381 | AV1Decoder *pbi, const uint8_t *data, |
| 2382 | TileBufferDec (*const tile_buffers)[MAX_TILE_COLS]) { |
| 2383 | assert(pbi->dec_tile_row >= 0 && pbi->dec_tile_col >= 0); |
| 2384 | tile_buffers[pbi->dec_tile_row][pbi->dec_tile_col].data = data; |
| 2385 | tile_buffers[pbi->dec_tile_row][pbi->dec_tile_col].size = |
| 2386 | (size_t)pbi->coded_tile_data_size; |
| 2387 | return data + pbi->coded_tile_data_size; |
| 2388 | } |
| 2389 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2390 | // Reads the next tile returning its size and adjusting '*data' accordingly |
| 2391 | // based on 'is_last'. |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2392 | static inline void get_tile_buffer(const uint8_t *const data_end, |
| 2393 | const int tile_size_bytes, int is_last, |
| 2394 | struct aom_internal_error_info *error_info, |
| 2395 | const uint8_t **data, |
| 2396 | TileBufferDec *const buf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2397 | size_t size; |
| 2398 | |
| 2399 | if (!is_last) { |
Yaowu Xu | 0a79a1b | 2017-02-17 13:04:54 -0800 | [diff] [blame] | 2400 | if (!read_is_valid(*data, tile_size_bytes, data_end)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2401 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Wan-Teh Chang | c40acb2 | 2019-06-20 09:51:39 -0700 | [diff] [blame] | 2402 | "Not enough data to read tile size"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2403 | |
James Zern | 2f22bfd | 2018-03-10 12:58:22 -0800 | [diff] [blame] | 2404 | size = mem_get_varsize(*data, tile_size_bytes) + AV1_MIN_TILE_SIZE_BYTES; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2405 | *data += tile_size_bytes; |
| 2406 | |
| 2407 | if (size > (size_t)(data_end - *data)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2408 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2409 | "Truncated packet or corrupt tile size"); |
| 2410 | } else { |
| 2411 | size = data_end - *data; |
| 2412 | } |
| 2413 | |
| 2414 | buf->data = *data; |
| 2415 | buf->size = size; |
| 2416 | |
| 2417 | *data += size; |
| 2418 | } |
| 2419 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2420 | static inline void get_tile_buffers( |
Elliott Karpilovsky | 18fcd6a | 2019-09-16 15:15:06 -0700 | [diff] [blame] | 2421 | AV1Decoder *pbi, const uint8_t *data, const uint8_t *data_end, |
| 2422 | TileBufferDec (*const tile_buffers)[MAX_TILE_COLS], int start_tile, |
| 2423 | int end_tile) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2424 | AV1_COMMON *const cm = &pbi->common; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2425 | const int tile_cols = cm->tiles.cols; |
| 2426 | const int tile_rows = cm->tiles.rows; |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2427 | int tc = 0; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2428 | |
Sebastien Alaiwan | f518f14 | 2017-12-01 14:25:41 +0100 | [diff] [blame] | 2429 | for (int r = 0; r < tile_rows; ++r) { |
| 2430 | for (int c = 0; c < tile_cols; ++c, ++tc) { |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2431 | TileBufferDec *const buf = &tile_buffers[r][c]; |
Tom Finegan | ff86395 | 2017-12-22 11:41:14 -0800 | [diff] [blame] | 2432 | |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 2433 | const int is_last = (tc == end_tile); |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2434 | const size_t hdr_offset = 0; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2435 | |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 2436 | if (tc < start_tile || tc > end_tile) continue; |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2437 | |
Rupert Swarbrick | cd75739 | 2017-09-01 13:57:53 +0100 | [diff] [blame] | 2438 | if (data + hdr_offset >= data_end) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2439 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Rupert Swarbrick | cd75739 | 2017-09-01 13:57:53 +0100 | [diff] [blame] | 2440 | "Data ended before all tiles were read."); |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2441 | data += hdr_offset; |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2442 | get_tile_buffer(data_end, pbi->tile_size_bytes, is_last, &pbi->error, |
| 2443 | &data, buf); |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2444 | } |
| 2445 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2446 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2447 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2448 | static inline void set_cb_buffer(AV1Decoder *pbi, DecoderCodingBlock *dcb, |
| 2449 | CB_BUFFER *cb_buffer_base, |
| 2450 | const int num_planes, int mi_row, int mi_col) { |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 2451 | AV1_COMMON *const cm = &pbi->common; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 2452 | int mib_size_log2 = cm->seq_params->mib_size_log2; |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 2453 | int stride = (cm->mi_params.mi_cols >> mib_size_log2) + 1; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 2454 | int offset = (mi_row >> mib_size_log2) * stride + (mi_col >> mib_size_log2); |
| 2455 | CB_BUFFER *cb_buffer = cb_buffer_base + offset; |
| 2456 | |
Deepa K G | 610c9b8 | 2018-06-19 12:47:01 +0530 | [diff] [blame] | 2457 | for (int plane = 0; plane < num_planes; ++plane) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2458 | dcb->dqcoeff_block[plane] = cb_buffer->dqcoeff[plane]; |
| 2459 | dcb->eob_data[plane] = cb_buffer->eob_data[plane]; |
| 2460 | dcb->cb_offset[plane] = 0; |
| 2461 | dcb->txb_offset[plane] = 0; |
Deepa K G | 610c9b8 | 2018-06-19 12:47:01 +0530 | [diff] [blame] | 2462 | } |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2463 | MACROBLOCKD *const xd = &dcb->xd; |
Deepa K G | 99f7ddb | 2018-06-20 11:21:21 +0530 | [diff] [blame] | 2464 | xd->plane[0].color_index_map = cb_buffer->color_index_map[0]; |
| 2465 | xd->plane[1].color_index_map = cb_buffer->color_index_map[1]; |
| 2466 | xd->color_index_map_offset[0] = 0; |
| 2467 | xd->color_index_map_offset[1] = 0; |
Deepa K G | 610c9b8 | 2018-06-19 12:47:01 +0530 | [diff] [blame] | 2468 | } |
| 2469 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2470 | static inline void decoder_alloc_tile_data(AV1Decoder *pbi, const int n_tiles) { |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2471 | AV1_COMMON *const cm = &pbi->common; |
| 2472 | aom_free(pbi->tile_data); |
Satheesh Kumar | c127972 | 2023-12-20 15:17:10 +0530 | [diff] [blame] | 2473 | pbi->allocated_tiles = 0; |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2474 | CHECK_MEM_ERROR(cm, pbi->tile_data, |
| 2475 | aom_memalign(32, n_tiles * sizeof(*pbi->tile_data))); |
| 2476 | pbi->allocated_tiles = n_tiles; |
| 2477 | for (int i = 0; i < n_tiles; i++) { |
| 2478 | TileDataDec *const tile_data = pbi->tile_data + i; |
| 2479 | av1_zero(tile_data->dec_row_mt_sync); |
| 2480 | } |
| 2481 | pbi->allocated_row_mt_sync_rows = 0; |
| 2482 | } |
| 2483 | |
| 2484 | // Set up nsync by width. |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 2485 | static inline int get_sync_range(int width) { |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2486 | // nsync numbers are picked by testing. |
| 2487 | #if 0 |
| 2488 | if (width < 640) |
| 2489 | return 1; |
| 2490 | else if (width <= 1280) |
| 2491 | return 2; |
| 2492 | else if (width <= 4096) |
| 2493 | return 4; |
| 2494 | else |
| 2495 | return 8; |
| 2496 | #else |
| 2497 | (void)width; |
| 2498 | #endif |
| 2499 | return 1; |
| 2500 | } |
| 2501 | |
| 2502 | // Allocate memory for decoder row synchronization |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2503 | static inline void dec_row_mt_alloc(AV1DecRowMTSync *dec_row_mt_sync, |
| 2504 | AV1_COMMON *cm, int rows) { |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2505 | dec_row_mt_sync->allocated_sb_rows = rows; |
| 2506 | #if CONFIG_MULTITHREAD |
| 2507 | { |
| 2508 | int i; |
| 2509 | |
| 2510 | CHECK_MEM_ERROR(cm, dec_row_mt_sync->mutex_, |
| 2511 | aom_malloc(sizeof(*(dec_row_mt_sync->mutex_)) * rows)); |
| 2512 | if (dec_row_mt_sync->mutex_) { |
| 2513 | for (i = 0; i < rows; ++i) { |
| 2514 | pthread_mutex_init(&dec_row_mt_sync->mutex_[i], NULL); |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | CHECK_MEM_ERROR(cm, dec_row_mt_sync->cond_, |
| 2519 | aom_malloc(sizeof(*(dec_row_mt_sync->cond_)) * rows)); |
| 2520 | if (dec_row_mt_sync->cond_) { |
| 2521 | for (i = 0; i < rows; ++i) { |
| 2522 | pthread_cond_init(&dec_row_mt_sync->cond_[i], NULL); |
| 2523 | } |
| 2524 | } |
| 2525 | } |
| 2526 | #endif // CONFIG_MULTITHREAD |
| 2527 | |
| 2528 | CHECK_MEM_ERROR(cm, dec_row_mt_sync->cur_sb_col, |
| 2529 | aom_malloc(sizeof(*(dec_row_mt_sync->cur_sb_col)) * rows)); |
| 2530 | |
| 2531 | // Set up nsync. |
| 2532 | dec_row_mt_sync->sync_range = get_sync_range(cm->width); |
| 2533 | } |
| 2534 | |
| 2535 | // Deallocate decoder row synchronization related mutex and data |
| 2536 | void av1_dec_row_mt_dealloc(AV1DecRowMTSync *dec_row_mt_sync) { |
| 2537 | if (dec_row_mt_sync != NULL) { |
| 2538 | #if CONFIG_MULTITHREAD |
| 2539 | int i; |
| 2540 | if (dec_row_mt_sync->mutex_ != NULL) { |
| 2541 | for (i = 0; i < dec_row_mt_sync->allocated_sb_rows; ++i) { |
| 2542 | pthread_mutex_destroy(&dec_row_mt_sync->mutex_[i]); |
| 2543 | } |
| 2544 | aom_free(dec_row_mt_sync->mutex_); |
| 2545 | } |
| 2546 | if (dec_row_mt_sync->cond_ != NULL) { |
| 2547 | for (i = 0; i < dec_row_mt_sync->allocated_sb_rows; ++i) { |
| 2548 | pthread_cond_destroy(&dec_row_mt_sync->cond_[i]); |
| 2549 | } |
| 2550 | aom_free(dec_row_mt_sync->cond_); |
| 2551 | } |
| 2552 | #endif // CONFIG_MULTITHREAD |
| 2553 | aom_free(dec_row_mt_sync->cur_sb_col); |
| 2554 | |
| 2555 | // clear the structure as the source of this call may be a resize in which |
| 2556 | // case this call will be followed by an _alloc() which may fail. |
| 2557 | av1_zero(*dec_row_mt_sync); |
| 2558 | } |
| 2559 | } |
| 2560 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 2561 | static inline void sync_read(AV1DecRowMTSync *const dec_row_mt_sync, int r, |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2562 | int c) { |
| 2563 | #if CONFIG_MULTITHREAD |
| 2564 | const int nsync = dec_row_mt_sync->sync_range; |
| 2565 | |
| 2566 | if (r && !(c & (nsync - 1))) { |
| 2567 | pthread_mutex_t *const mutex = &dec_row_mt_sync->mutex_[r - 1]; |
| 2568 | pthread_mutex_lock(mutex); |
| 2569 | |
Jayasanker J | 34ec50a | 2022-07-01 19:00:02 +0530 | [diff] [blame] | 2570 | while (c > dec_row_mt_sync->cur_sb_col[r - 1] - nsync - |
| 2571 | dec_row_mt_sync->intrabc_extra_top_right_sb_delay) { |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2572 | pthread_cond_wait(&dec_row_mt_sync->cond_[r - 1], mutex); |
| 2573 | } |
| 2574 | pthread_mutex_unlock(mutex); |
| 2575 | } |
| 2576 | #else |
| 2577 | (void)dec_row_mt_sync; |
| 2578 | (void)r; |
| 2579 | (void)c; |
| 2580 | #endif // CONFIG_MULTITHREAD |
| 2581 | } |
| 2582 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 2583 | static inline void sync_write(AV1DecRowMTSync *const dec_row_mt_sync, int r, |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2584 | int c, const int sb_cols) { |
| 2585 | #if CONFIG_MULTITHREAD |
| 2586 | const int nsync = dec_row_mt_sync->sync_range; |
| 2587 | int cur; |
| 2588 | int sig = 1; |
| 2589 | |
| 2590 | if (c < sb_cols - 1) { |
| 2591 | cur = c; |
| 2592 | if (c % nsync) sig = 0; |
| 2593 | } else { |
Jayasanker J | 34ec50a | 2022-07-01 19:00:02 +0530 | [diff] [blame] | 2594 | cur = sb_cols + nsync + dec_row_mt_sync->intrabc_extra_top_right_sb_delay; |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | if (sig) { |
| 2598 | pthread_mutex_lock(&dec_row_mt_sync->mutex_[r]); |
| 2599 | |
| 2600 | dec_row_mt_sync->cur_sb_col[r] = cur; |
| 2601 | |
| 2602 | pthread_cond_signal(&dec_row_mt_sync->cond_[r]); |
| 2603 | pthread_mutex_unlock(&dec_row_mt_sync->mutex_[r]); |
| 2604 | } |
| 2605 | #else |
| 2606 | (void)dec_row_mt_sync; |
| 2607 | (void)r; |
| 2608 | (void)c; |
| 2609 | (void)sb_cols; |
| 2610 | #endif // CONFIG_MULTITHREAD |
| 2611 | } |
| 2612 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 2613 | static inline void signal_decoding_done_for_erroneous_row( |
venkat sanampudi | dd5066d | 2022-02-14 21:17:02 +0530 | [diff] [blame] | 2614 | AV1Decoder *const pbi, const MACROBLOCKD *const xd) { |
| 2615 | AV1_COMMON *const cm = &pbi->common; |
| 2616 | const TileInfo *const tile = &xd->tile; |
| 2617 | const int sb_row_in_tile = |
| 2618 | ((xd->mi_row - tile->mi_row_start) >> cm->seq_params->mib_size_log2); |
| 2619 | const int sb_cols_in_tile = av1_get_sb_cols_in_tile(cm, tile); |
| 2620 | TileDataDec *const tile_data = |
| 2621 | pbi->tile_data + tile->tile_row * cm->tiles.cols + tile->tile_col; |
| 2622 | AV1DecRowMTSync *dec_row_mt_sync = &tile_data->dec_row_mt_sync; |
| 2623 | |
| 2624 | sync_write(dec_row_mt_sync, sb_row_in_tile, sb_cols_in_tile - 1, |
| 2625 | sb_cols_in_tile); |
| 2626 | } |
| 2627 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2628 | static inline void decode_tile_sb_row(AV1Decoder *pbi, ThreadData *const td, |
| 2629 | const TileInfo *tile_info, |
| 2630 | const int mi_row) { |
Cherma Rajan A | ccd8651 | 2018-03-28 17:24:20 +0530 | [diff] [blame] | 2631 | AV1_COMMON *const cm = &pbi->common; |
Deepa K G | 610c9b8 | 2018-06-19 12:47:01 +0530 | [diff] [blame] | 2632 | const int num_planes = av1_num_planes(cm); |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 2633 | TileDataDec *const tile_data = pbi->tile_data + |
| 2634 | tile_info->tile_row * cm->tiles.cols + |
| 2635 | tile_info->tile_col; |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 2636 | const int sb_cols_in_tile = av1_get_sb_cols_in_tile(cm, tile_info); |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2637 | const int sb_row_in_tile = |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 2638 | (mi_row - tile_info->mi_row_start) >> cm->seq_params->mib_size_log2; |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2639 | int sb_col_in_tile = 0; |
venkat sanampudi | 870fa86 | 2022-02-21 09:15:53 +0530 | [diff] [blame] | 2640 | int row_mt_exit = 0; |
Cherma Rajan A | ccd8651 | 2018-03-28 17:24:20 +0530 | [diff] [blame] | 2641 | |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 2642 | for (int mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 2643 | mi_col += cm->seq_params->mib_size, sb_col_in_tile++) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2644 | set_cb_buffer(pbi, &td->dcb, pbi->cb_buffer_base, num_planes, mi_row, |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 2645 | mi_col); |
Deepa K G | 610c9b8 | 2018-06-19 12:47:01 +0530 | [diff] [blame] | 2646 | |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2647 | sync_read(&tile_data->dec_row_mt_sync, sb_row_in_tile, sb_col_in_tile); |
| 2648 | |
venkat sanampudi | 870fa86 | 2022-02-21 09:15:53 +0530 | [diff] [blame] | 2649 | #if CONFIG_MULTITHREAD |
| 2650 | pthread_mutex_lock(pbi->row_mt_mutex_); |
| 2651 | #endif |
| 2652 | row_mt_exit = pbi->frame_row_mt_info.row_mt_exit; |
| 2653 | #if CONFIG_MULTITHREAD |
| 2654 | pthread_mutex_unlock(pbi->row_mt_mutex_); |
| 2655 | #endif |
| 2656 | |
| 2657 | if (!row_mt_exit) { |
| 2658 | // Decoding of the super-block |
| 2659 | decode_partition(pbi, td, mi_row, mi_col, td->bit_reader, |
| 2660 | cm->seq_params->sb_size, 0x2); |
| 2661 | } |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2662 | |
| 2663 | sync_write(&tile_data->dec_row_mt_sync, sb_row_in_tile, sb_col_in_tile, |
| 2664 | sb_cols_in_tile); |
Cherma Rajan A | ccd8651 | 2018-03-28 17:24:20 +0530 | [diff] [blame] | 2665 | } |
Cherma Rajan A | ccd8651 | 2018-03-28 17:24:20 +0530 | [diff] [blame] | 2666 | } |
| 2667 | |
Wan-Teh Chang | 4eda284 | 2018-05-07 15:03:35 -0700 | [diff] [blame] | 2668 | static int check_trailing_bits_after_symbol_coder(aom_reader *r) { |
Wan-Teh Chang | 47d59ce | 2018-08-14 10:15:45 -0700 | [diff] [blame] | 2669 | if (aom_reader_has_overflowed(r)) return -1; |
| 2670 | |
Wan-Teh Chang | 4eda284 | 2018-05-07 15:03:35 -0700 | [diff] [blame] | 2671 | uint32_t nb_bits = aom_reader_tell(r); |
| 2672 | uint32_t nb_bytes = (nb_bits + 7) >> 3; |
Wan-Teh Chang | 47d59ce | 2018-08-14 10:15:45 -0700 | [diff] [blame] | 2673 | const uint8_t *p = aom_reader_find_begin(r) + nb_bytes; |
Wan-Teh Chang | 4eda284 | 2018-05-07 15:03:35 -0700 | [diff] [blame] | 2674 | |
| 2675 | // aom_reader_tell() returns 1 for a newly initialized decoder, and the |
| 2676 | // return value only increases as values are decoded. So nb_bits > 0, and |
| 2677 | // thus p > p_begin. Therefore accessing p[-1] is safe. |
| 2678 | uint8_t last_byte = p[-1]; |
| 2679 | uint8_t pattern = 128 >> ((nb_bits - 1) & 7); |
| 2680 | if ((last_byte & (2 * pattern - 1)) != pattern) return -1; |
| 2681 | |
| 2682 | // Make sure that all padding bytes are zero as required by the spec. |
Wan-Teh Chang | 47d59ce | 2018-08-14 10:15:45 -0700 | [diff] [blame] | 2683 | const uint8_t *p_end = aom_reader_find_end(r); |
Wan-Teh Chang | 4eda284 | 2018-05-07 15:03:35 -0700 | [diff] [blame] | 2684 | while (p < p_end) { |
| 2685 | if (*p != 0) return -1; |
| 2686 | p++; |
| 2687 | } |
| 2688 | return 0; |
| 2689 | } |
| 2690 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2691 | static inline void set_decode_func_pointers(ThreadData *td, |
| 2692 | int parse_decode_flag) { |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 2693 | td->read_coeffs_tx_intra_block_visit = decode_block_void; |
| 2694 | td->predict_and_recon_intra_block_visit = decode_block_void; |
| 2695 | td->read_coeffs_tx_inter_block_visit = decode_block_void; |
| 2696 | td->inverse_tx_inter_block_visit = decode_block_void; |
| 2697 | td->predict_inter_block_visit = predict_inter_block_void; |
| 2698 | td->cfl_store_inter_block_visit = cfl_store_inter_block_void; |
| 2699 | |
| 2700 | if (parse_decode_flag & 0x1) { |
| 2701 | td->read_coeffs_tx_intra_block_visit = read_coeffs_tx_intra_block; |
| 2702 | td->read_coeffs_tx_inter_block_visit = av1_read_coeffs_txb_facade; |
| 2703 | } |
| 2704 | if (parse_decode_flag & 0x2) { |
| 2705 | td->predict_and_recon_intra_block_visit = |
| 2706 | predict_and_reconstruct_intra_block; |
| 2707 | td->inverse_tx_inter_block_visit = inverse_transform_inter_block; |
| 2708 | td->predict_inter_block_visit = predict_inter_block; |
| 2709 | td->cfl_store_inter_block_visit = cfl_store_inter_block; |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 2710 | } |
| 2711 | } |
| 2712 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2713 | static inline void decode_tile(AV1Decoder *pbi, ThreadData *const td, |
| 2714 | int tile_row, int tile_col) { |
Cherma Rajan A | ccd8651 | 2018-03-28 17:24:20 +0530 | [diff] [blame] | 2715 | TileInfo tile_info; |
| 2716 | |
| 2717 | AV1_COMMON *const cm = &pbi->common; |
| 2718 | const int num_planes = av1_num_planes(cm); |
Cherma Rajan A | ccd8651 | 2018-03-28 17:24:20 +0530 | [diff] [blame] | 2719 | |
| 2720 | av1_tile_set_row(&tile_info, cm, tile_row); |
| 2721 | av1_tile_set_col(&tile_info, cm, tile_col); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2722 | DecoderCodingBlock *const dcb = &td->dcb; |
| 2723 | MACROBLOCKD *const xd = &dcb->xd; |
| 2724 | |
| 2725 | av1_zero_above_context(cm, xd, tile_info.mi_col_start, tile_info.mi_col_end, |
| 2726 | tile_row); |
| 2727 | av1_reset_loop_filter_delta(xd, num_planes); |
| 2728 | av1_reset_loop_restoration(xd, num_planes); |
Cherma Rajan A | ccd8651 | 2018-03-28 17:24:20 +0530 | [diff] [blame] | 2729 | |
| 2730 | for (int mi_row = tile_info.mi_row_start; mi_row < tile_info.mi_row_end; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 2731 | mi_row += cm->seq_params->mib_size) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2732 | av1_zero_left_context(xd); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 2733 | |
| 2734 | for (int mi_col = tile_info.mi_col_start; mi_col < tile_info.mi_col_end; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 2735 | mi_col += cm->seq_params->mib_size) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2736 | set_cb_buffer(pbi, dcb, &td->cb_buffer_base, num_planes, 0, 0); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 2737 | |
| 2738 | // Bit-stream parsing and decoding of the superblock |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 2739 | decode_partition(pbi, td, mi_row, mi_col, td->bit_reader, |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 2740 | cm->seq_params->sb_size, 0x3); |
Wan-Teh Chang | 47d59ce | 2018-08-14 10:15:45 -0700 | [diff] [blame] | 2741 | |
| 2742 | if (aom_reader_has_overflowed(td->bit_reader)) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2743 | aom_merge_corrupted_flag(&dcb->corrupted, 1); |
Wan-Teh Chang | 47d59ce | 2018-08-14 10:15:45 -0700 | [diff] [blame] | 2744 | return; |
| 2745 | } |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 2746 | } |
Cherma Rajan A | ccd8651 | 2018-03-28 17:24:20 +0530 | [diff] [blame] | 2747 | } |
Frank Bossen | df46b22 | 2018-03-27 14:53:51 -0400 | [diff] [blame] | 2748 | |
Yunqing Wang | 789d528 | 2018-05-04 17:18:02 -0700 | [diff] [blame] | 2749 | int corrupted = |
| 2750 | (check_trailing_bits_after_symbol_coder(td->bit_reader)) ? 1 : 0; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2751 | aom_merge_corrupted_flag(&dcb->corrupted, corrupted); |
Cherma Rajan A | ccd8651 | 2018-03-28 17:24:20 +0530 | [diff] [blame] | 2752 | } |
| 2753 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2754 | static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 2755 | const uint8_t *data_end, int start_tile, |
| 2756 | int end_tile) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2757 | AV1_COMMON *const cm = &pbi->common; |
Wan-Teh Chang | f4fe661 | 2018-05-31 17:42:18 -0700 | [diff] [blame] | 2758 | ThreadData *const td = &pbi->td; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2759 | CommonTileParams *const tiles = &cm->tiles; |
| 2760 | const int tile_cols = tiles->cols; |
| 2761 | const int tile_rows = tiles->rows; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2762 | const int n_tiles = tile_cols * tile_rows; |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 2763 | TileBufferDec(*const tile_buffers)[MAX_TILE_COLS] = pbi->tile_buffers; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2764 | const int dec_tile_row = AOMMIN(pbi->dec_tile_row, tile_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2765 | const int single_row = pbi->dec_tile_row >= 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2766 | const int dec_tile_col = AOMMIN(pbi->dec_tile_col, tile_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2767 | const int single_col = pbi->dec_tile_col >= 0; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2768 | int tile_rows_start; |
| 2769 | int tile_rows_end; |
| 2770 | int tile_cols_start; |
| 2771 | int tile_cols_end; |
| 2772 | int inv_col_order; |
| 2773 | int inv_row_order; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2774 | int tile_row, tile_col; |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 2775 | uint8_t allow_update_cdf; |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2776 | const uint8_t *raw_data_end = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2777 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2778 | if (tiles->large_scale) { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2779 | tile_rows_start = single_row ? dec_tile_row : 0; |
| 2780 | tile_rows_end = single_row ? dec_tile_row + 1 : tile_rows; |
| 2781 | tile_cols_start = single_col ? dec_tile_col : 0; |
| 2782 | tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; |
| 2783 | inv_col_order = pbi->inv_tile_order && !single_col; |
| 2784 | inv_row_order = pbi->inv_tile_order && !single_row; |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 2785 | allow_update_cdf = 0; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2786 | } else { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2787 | tile_rows_start = 0; |
| 2788 | tile_rows_end = tile_rows; |
| 2789 | tile_cols_start = 0; |
| 2790 | tile_cols_end = tile_cols; |
| 2791 | inv_col_order = pbi->inv_tile_order; |
| 2792 | inv_row_order = pbi->inv_tile_order; |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 2793 | allow_update_cdf = 1; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2794 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2795 | |
Hui Su | 4ff7883 | 2018-03-05 10:29:34 -0800 | [diff] [blame] | 2796 | // No tiles to decode. |
Hui Su | 51948b2 | 2018-03-30 16:49:08 -0700 | [diff] [blame] | 2797 | if (tile_rows_end <= tile_rows_start || tile_cols_end <= tile_cols_start || |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 2798 | // First tile is larger than end_tile. |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2799 | tile_rows_start * tiles->cols + tile_cols_start > end_tile || |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 2800 | // Last tile is smaller than start_tile. |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2801 | (tile_rows_end - 1) * tiles->cols + tile_cols_end - 1 < start_tile) |
Hui Su | 4ff7883 | 2018-03-05 10:29:34 -0800 | [diff] [blame] | 2802 | return data; |
| 2803 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 2804 | allow_update_cdf = allow_update_cdf && !cm->features.disable_cdf_update; |
Hui Su | 483a845 | 2018-02-26 12:28:48 -0800 | [diff] [blame] | 2805 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2806 | assert(tile_rows <= MAX_TILE_ROWS); |
| 2807 | assert(tile_cols <= MAX_TILE_COLS); |
| 2808 | |
Yunqing Wang | 3a74b25 | 2018-05-03 15:24:07 -0700 | [diff] [blame] | 2809 | #if EXT_TILE_DEBUG |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2810 | if (tiles->large_scale && !pbi->ext_tile_debug) |
Yunqing Wang | d7546d4 | 2018-06-06 15:08:05 -0700 | [diff] [blame] | 2811 | raw_data_end = get_ls_single_tile_buffer(pbi, data, tile_buffers); |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2812 | else if (tiles->large_scale && pbi->ext_tile_debug) |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2813 | raw_data_end = get_ls_tile_buffers(pbi, data, data_end, tile_buffers); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2814 | else |
Yunqing Wang | 3a74b25 | 2018-05-03 15:24:07 -0700 | [diff] [blame] | 2815 | #endif // EXT_TILE_DEBUG |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 2816 | get_tile_buffers(pbi, data, data_end, tile_buffers, start_tile, end_tile); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2817 | |
| 2818 | if (pbi->tile_data == NULL || n_tiles != pbi->allocated_tiles) { |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 2819 | decoder_alloc_tile_data(pbi, n_tiles); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2820 | } |
Chethan Kumar R E | a494e2b | 2021-03-18 17:19:44 +0530 | [diff] [blame] | 2821 | if (pbi->dcb.xd.seg_mask == NULL) |
| 2822 | CHECK_MEM_ERROR(cm, pbi->dcb.xd.seg_mask, |
| 2823 | (uint8_t *)aom_memalign( |
| 2824 | 16, 2 * MAX_SB_SQUARE * sizeof(*pbi->dcb.xd.seg_mask))); |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2825 | #if CONFIG_ACCOUNTING |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 2826 | if (pbi->acct_enabled) { |
| 2827 | aom_accounting_reset(&pbi->accounting); |
| 2828 | } |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2829 | #endif |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 2830 | |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 2831 | set_decode_func_pointers(&pbi->td, 0x3); |
Deepa K G | 3bc1f93 | 2018-06-21 14:25:03 +0530 | [diff] [blame] | 2832 | |
Cherma Rajan A | e4121f6 | 2018-04-18 17:30:55 +0530 | [diff] [blame] | 2833 | // Load all tile information into thread_data. |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2834 | td->dcb = pbi->dcb; |
| 2835 | |
| 2836 | td->dcb.corrupted = 0; |
| 2837 | td->dcb.mc_buf[0] = td->mc_buf[0]; |
| 2838 | td->dcb.mc_buf[1] = td->mc_buf[1]; |
| 2839 | td->dcb.xd.tmp_conv_dst = td->tmp_conv_dst; |
Urvang Joshi | e58f6eca | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2840 | for (int j = 0; j < 2; ++j) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2841 | td->dcb.xd.tmp_obmc_bufs[j] = td->tmp_obmc_bufs[j]; |
Urvang Joshi | e58f6eca | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 2842 | } |
| 2843 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2844 | for (tile_row = tile_rows_start; tile_row < tile_rows_end; ++tile_row) { |
| 2845 | const int row = inv_row_order ? tile_rows - 1 - tile_row : tile_row; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2846 | |
| 2847 | for (tile_col = tile_cols_start; tile_col < tile_cols_end; ++tile_col) { |
| 2848 | const int col = inv_col_order ? tile_cols - 1 - tile_col : tile_col; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2849 | TileDataDec *const tile_data = pbi->tile_data + row * tiles->cols + col; |
Cherma Rajan A | e4121f6 | 2018-04-18 17:30:55 +0530 | [diff] [blame] | 2850 | const TileBufferDec *const tile_bs_buf = &tile_buffers[row][col]; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2851 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2852 | if (row * tiles->cols + col < start_tile || |
| 2853 | row * tiles->cols + col > end_tile) |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2854 | continue; |
| 2855 | |
Cherma Rajan A | e4121f6 | 2018-04-18 17:30:55 +0530 | [diff] [blame] | 2856 | td->bit_reader = &tile_data->bit_reader; |
wenyao.liu | 00c80e6 | 2018-12-28 10:42:26 +0800 | [diff] [blame] | 2857 | av1_zero(td->cb_buffer_base.dqcoeff); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2858 | av1_tile_init(&td->dcb.xd.tile, cm, row, col); |
Urvang Joshi | acad1ca | 2020-04-27 17:03:25 -0700 | [diff] [blame] | 2859 | td->dcb.xd.current_base_qindex = cm->quant_params.base_qindex; |
venkat sanampudi | ee9dbcb | 2022-02-24 21:34:22 +0530 | [diff] [blame] | 2860 | setup_bool_decoder(&td->dcb.xd, tile_bs_buf->data, data_end, |
| 2861 | tile_bs_buf->size, &pbi->error, td->bit_reader, |
| 2862 | allow_update_cdf); |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2863 | #if CONFIG_ACCOUNTING |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 2864 | if (pbi->acct_enabled) { |
Cherma Rajan A | e4121f6 | 2018-04-18 17:30:55 +0530 | [diff] [blame] | 2865 | td->bit_reader->accounting = &pbi->accounting; |
| 2866 | td->bit_reader->accounting->last_tell_frac = |
| 2867 | aom_reader_tell_frac(td->bit_reader); |
| 2868 | } else { |
| 2869 | td->bit_reader->accounting = NULL; |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 2870 | } |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2871 | #endif |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2872 | av1_init_macroblockd(cm, &td->dcb.xd); |
Urvang Joshi | 5c8625a | 2020-03-30 13:16:37 -0700 | [diff] [blame] | 2873 | av1_init_above_context(&cm->above_contexts, av1_num_planes(cm), row, |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2874 | &td->dcb.xd); |
Cherma Rajan A | e4121f6 | 2018-04-18 17:30:55 +0530 | [diff] [blame] | 2875 | |
| 2876 | // Initialise the tile context from the frame context |
| 2877 | tile_data->tctx = *cm->fc; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2878 | td->dcb.xd.tile_ctx = &tile_data->tctx; |
Cherma Rajan A | e4121f6 | 2018-04-18 17:30:55 +0530 | [diff] [blame] | 2879 | |
| 2880 | // decode tile |
Wan-Teh Chang | 553b0fe | 2018-06-27 18:02:19 -0700 | [diff] [blame] | 2881 | decode_tile(pbi, td, row, col); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2882 | aom_merge_corrupted_flag(&pbi->dcb.corrupted, td->dcb.corrupted); |
| 2883 | if (pbi->dcb.corrupted) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 2884 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Yunqing Wang | 789d528 | 2018-05-04 17:18:02 -0700 | [diff] [blame] | 2885 | "Failed to decode tile data"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2886 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2889 | if (tiles->large_scale) { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2890 | if (n_tiles == 1) { |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2891 | // Find the end of the single tile buffer |
| 2892 | return aom_reader_find_end(&pbi->tile_data->bit_reader); |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2893 | } |
Sebastien Alaiwan | 86da7eb | 2017-12-20 09:44:19 +0100 | [diff] [blame] | 2894 | // Return the end of the last tile buffer |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 2895 | return raw_data_end; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2896 | } |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 2897 | TileDataDec *const tile_data = pbi->tile_data + end_tile; |
Sebastien Alaiwan | 86da7eb | 2017-12-20 09:44:19 +0100 | [diff] [blame] | 2898 | |
Cherma Rajan A | e4121f6 | 2018-04-18 17:30:55 +0530 | [diff] [blame] | 2899 | return aom_reader_find_end(&tile_data->bit_reader); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2900 | } |
| 2901 | |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 2902 | static TileJobsDec *get_dec_job_info(AV1DecTileMT *tile_mt_info) { |
| 2903 | TileJobsDec *cur_job_info = NULL; |
| 2904 | #if CONFIG_MULTITHREAD |
| 2905 | pthread_mutex_lock(tile_mt_info->job_mutex); |
| 2906 | |
| 2907 | if (tile_mt_info->jobs_dequeued < tile_mt_info->jobs_enqueued) { |
| 2908 | cur_job_info = tile_mt_info->job_queue + tile_mt_info->jobs_dequeued; |
| 2909 | tile_mt_info->jobs_dequeued++; |
| 2910 | } |
| 2911 | |
| 2912 | pthread_mutex_unlock(tile_mt_info->job_mutex); |
| 2913 | #else |
| 2914 | (void)tile_mt_info; |
| 2915 | #endif |
| 2916 | return cur_job_info; |
| 2917 | } |
| 2918 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 2919 | static inline void tile_worker_hook_init(AV1Decoder *const pbi, |
| 2920 | DecWorkerData *const thread_data, |
| 2921 | const TileBufferDec *const tile_buffer, |
| 2922 | TileDataDec *const tile_data, |
| 2923 | uint8_t allow_update_cdf) { |
Deepa K G | 984c6eb | 2018-06-28 16:02:28 +0530 | [diff] [blame] | 2924 | AV1_COMMON *cm = &pbi->common; |
| 2925 | ThreadData *const td = thread_data->td; |
Wan-Teh Chang | a98cd33 | 2018-06-29 10:06:29 -0700 | [diff] [blame] | 2926 | int tile_row = tile_data->tile_info.tile_row; |
| 2927 | int tile_col = tile_data->tile_info.tile_col; |
Deepa K G | 984c6eb | 2018-06-28 16:02:28 +0530 | [diff] [blame] | 2928 | |
Deepa K G | 984c6eb | 2018-06-28 16:02:28 +0530 | [diff] [blame] | 2929 | td->bit_reader = &tile_data->bit_reader; |
wenyao.liu | 00c80e6 | 2018-12-28 10:42:26 +0800 | [diff] [blame] | 2930 | av1_zero(td->cb_buffer_base.dqcoeff); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2931 | |
| 2932 | MACROBLOCKD *const xd = &td->dcb.xd; |
| 2933 | av1_tile_init(&xd->tile, cm, tile_row, tile_col); |
Urvang Joshi | acad1ca | 2020-04-27 17:03:25 -0700 | [diff] [blame] | 2934 | xd->current_base_qindex = cm->quant_params.base_qindex; |
venkat sanampudi | ee9dbcb | 2022-02-24 21:34:22 +0530 | [diff] [blame] | 2935 | |
| 2936 | setup_bool_decoder(xd, tile_buffer->data, thread_data->data_end, |
Yunqing Wang | ebc3a31 | 2018-07-03 13:05:40 -0700 | [diff] [blame] | 2937 | tile_buffer->size, &thread_data->error_info, |
| 2938 | td->bit_reader, allow_update_cdf); |
Deepa K G | 984c6eb | 2018-06-28 16:02:28 +0530 | [diff] [blame] | 2939 | #if CONFIG_ACCOUNTING |
| 2940 | if (pbi->acct_enabled) { |
| 2941 | td->bit_reader->accounting = &pbi->accounting; |
| 2942 | td->bit_reader->accounting->last_tell_frac = |
| 2943 | aom_reader_tell_frac(td->bit_reader); |
| 2944 | } else { |
| 2945 | td->bit_reader->accounting = NULL; |
| 2946 | } |
| 2947 | #endif |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2948 | av1_init_macroblockd(cm, xd); |
| 2949 | xd->error_info = &thread_data->error_info; |
| 2950 | av1_init_above_context(&cm->above_contexts, av1_num_planes(cm), tile_row, xd); |
Deepa K G | 984c6eb | 2018-06-28 16:02:28 +0530 | [diff] [blame] | 2951 | |
| 2952 | // Initialise the tile context from the frame context |
| 2953 | tile_data->tctx = *cm->fc; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2954 | xd->tile_ctx = &tile_data->tctx; |
Deepa K G | 984c6eb | 2018-06-28 16:02:28 +0530 | [diff] [blame] | 2955 | #if CONFIG_ACCOUNTING |
| 2956 | if (pbi->acct_enabled) { |
| 2957 | tile_data->bit_reader.accounting->last_tell_frac = |
| 2958 | aom_reader_tell_frac(&tile_data->bit_reader); |
| 2959 | } |
| 2960 | #endif |
| 2961 | } |
| 2962 | |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 2963 | static int tile_worker_hook(void *arg1, void *arg2) { |
| 2964 | DecWorkerData *const thread_data = (DecWorkerData *)arg1; |
| 2965 | AV1Decoder *const pbi = (AV1Decoder *)arg2; |
| 2966 | AV1_COMMON *cm = &pbi->common; |
| 2967 | ThreadData *const td = thread_data->td; |
| 2968 | uint8_t allow_update_cdf; |
| 2969 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 2970 | // The jmp_buf is valid only for the duration of the function that calls |
| 2971 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 2972 | // before it returns. |
Wan-Teh Chang | f3ac651 | 2018-07-18 17:18:53 -0700 | [diff] [blame] | 2973 | if (setjmp(thread_data->error_info.jmp)) { |
| 2974 | thread_data->error_info.setjmp = 0; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2975 | thread_data->td->dcb.corrupted = 1; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 2976 | return 0; |
| 2977 | } |
Wan-Teh Chang | f3ac651 | 2018-07-18 17:18:53 -0700 | [diff] [blame] | 2978 | thread_data->error_info.setjmp = 1; |
Yunqing Wang | 1f68fee | 2018-07-02 12:39:09 -0700 | [diff] [blame] | 2979 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2980 | allow_update_cdf = cm->tiles.large_scale ? 0 : 1; |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 2981 | allow_update_cdf = allow_update_cdf && !cm->features.disable_cdf_update; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 2982 | |
Deepa K G | 1909dee | 2018-07-03 17:37:56 +0530 | [diff] [blame] | 2983 | set_decode_func_pointers(td, 0x3); |
| 2984 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 2985 | assert(cm->tiles.cols > 0); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 2986 | while (!td->dcb.corrupted) { |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 2987 | TileJobsDec *cur_job_info = get_dec_job_info(&pbi->tile_mt_info); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 2988 | |
Wan-Teh Chang | 30e8ddb | 2018-09-19 18:17:32 -0700 | [diff] [blame] | 2989 | if (cur_job_info != NULL) { |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 2990 | const TileBufferDec *const tile_buffer = cur_job_info->tile_buffer; |
| 2991 | TileDataDec *const tile_data = cur_job_info->tile_data; |
Deepa K G | 984c6eb | 2018-06-28 16:02:28 +0530 | [diff] [blame] | 2992 | tile_worker_hook_init(pbi, thread_data, tile_buffer, tile_data, |
| 2993 | allow_update_cdf); |
| 2994 | // decode tile |
Wan-Teh Chang | a98cd33 | 2018-06-29 10:06:29 -0700 | [diff] [blame] | 2995 | int tile_row = tile_data->tile_info.tile_row; |
| 2996 | int tile_col = tile_data->tile_info.tile_col; |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 2997 | decode_tile(pbi, td, tile_row, tile_col); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 2998 | } else { |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 2999 | break; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3000 | } |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3001 | } |
Wan-Teh Chang | 323a009d | 2018-07-03 14:20:47 -0700 | [diff] [blame] | 3002 | thread_data->error_info.setjmp = 0; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3003 | return !td->dcb.corrupted; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3004 | } |
| 3005 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 3006 | static inline int get_max_row_mt_workers_per_tile(AV1_COMMON *cm, |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3007 | const TileInfo *tile) { |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3008 | // NOTE: Currently value of max workers is calculated based |
| 3009 | // on the parse and decode time. As per the theoretical estimate |
| 3010 | // when percentage of parse time is equal to percentage of decode |
| 3011 | // time, number of workers needed to parse + decode a tile can not |
| 3012 | // exceed more than 2. |
| 3013 | // TODO(any): Modify this value if parsing is optimized in future. |
| 3014 | int sb_rows = av1_get_sb_rows_in_tile(cm, tile); |
| 3015 | int max_workers = |
| 3016 | sb_rows == 1 ? AOM_MIN_THREADS_PER_TILE : AOM_MAX_THREADS_PER_TILE; |
| 3017 | return max_workers; |
| 3018 | } |
| 3019 | |
Wan-Teh Chang | 516badf | 2018-09-20 13:54:01 -0700 | [diff] [blame] | 3020 | // The caller must hold pbi->row_mt_mutex_ when calling this function. |
| 3021 | // Returns 1 if either the next job is stored in *next_job_info or 1 is stored |
| 3022 | // in *end_of_frame. |
| 3023 | // NOTE: The caller waits on pbi->row_mt_cond_ if this function returns 0. |
| 3024 | // The return value of this function depends on the following variables: |
| 3025 | // - frame_row_mt_info->mi_rows_parse_done |
| 3026 | // - frame_row_mt_info->mi_rows_decode_started |
| 3027 | // - frame_row_mt_info->row_mt_exit |
| 3028 | // Therefore we may need to signal or broadcast pbi->row_mt_cond_ if any of |
| 3029 | // these variables is modified. |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3030 | static int get_next_job_info(AV1Decoder *const pbi, |
| 3031 | AV1DecRowMTJobInfo *next_job_info, |
| 3032 | int *end_of_frame) { |
| 3033 | AV1_COMMON *cm = &pbi->common; |
| 3034 | TileDataDec *tile_data; |
| 3035 | AV1DecRowMTSync *dec_row_mt_sync; |
| 3036 | AV1DecRowMTInfo *frame_row_mt_info = &pbi->frame_row_mt_info; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3037 | const int tile_rows_start = frame_row_mt_info->tile_rows_start; |
| 3038 | const int tile_rows_end = frame_row_mt_info->tile_rows_end; |
| 3039 | const int tile_cols_start = frame_row_mt_info->tile_cols_start; |
| 3040 | const int tile_cols_end = frame_row_mt_info->tile_cols_end; |
| 3041 | const int start_tile = frame_row_mt_info->start_tile; |
| 3042 | const int end_tile = frame_row_mt_info->end_tile; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3043 | const int sb_mi_size = mi_size_wide[cm->seq_params->sb_size]; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3044 | int num_mis_to_decode, num_threads_working; |
Deepa K G | 5392235 | 2018-07-16 12:07:20 +0530 | [diff] [blame] | 3045 | int num_mis_waiting_for_decode; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3046 | int min_threads_working = INT_MAX; |
Deepa K G | 5392235 | 2018-07-16 12:07:20 +0530 | [diff] [blame] | 3047 | int max_mis_to_decode = 0; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3048 | int tile_row_idx, tile_col_idx; |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3049 | int tile_row = -1; |
| 3050 | int tile_col = -1; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3051 | |
| 3052 | memset(next_job_info, 0, sizeof(*next_job_info)); |
| 3053 | |
| 3054 | // Frame decode is completed or error is encountered. |
| 3055 | *end_of_frame = (frame_row_mt_info->mi_rows_decode_started == |
| 3056 | frame_row_mt_info->mi_rows_to_decode) || |
| 3057 | (frame_row_mt_info->row_mt_exit == 1); |
| 3058 | if (*end_of_frame) { |
| 3059 | return 1; |
| 3060 | } |
| 3061 | |
| 3062 | // Decoding cannot start as bit-stream parsing is not complete. |
Wan-Teh Chang | 516badf | 2018-09-20 13:54:01 -0700 | [diff] [blame] | 3063 | assert(frame_row_mt_info->mi_rows_parse_done >= |
| 3064 | frame_row_mt_info->mi_rows_decode_started); |
| 3065 | if (frame_row_mt_info->mi_rows_parse_done == |
| 3066 | frame_row_mt_info->mi_rows_decode_started) |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3067 | return 0; |
| 3068 | |
| 3069 | // Choose the tile to decode. |
| 3070 | for (tile_row_idx = tile_rows_start; tile_row_idx < tile_rows_end; |
| 3071 | ++tile_row_idx) { |
| 3072 | for (tile_col_idx = tile_cols_start; tile_col_idx < tile_cols_end; |
| 3073 | ++tile_col_idx) { |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3074 | if (tile_row_idx * cm->tiles.cols + tile_col_idx < start_tile || |
| 3075 | tile_row_idx * cm->tiles.cols + tile_col_idx > end_tile) |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3076 | continue; |
| 3077 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3078 | tile_data = pbi->tile_data + tile_row_idx * cm->tiles.cols + tile_col_idx; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3079 | dec_row_mt_sync = &tile_data->dec_row_mt_sync; |
| 3080 | |
| 3081 | num_threads_working = dec_row_mt_sync->num_threads_working; |
Deepa K G | 5392235 | 2018-07-16 12:07:20 +0530 | [diff] [blame] | 3082 | num_mis_waiting_for_decode = (dec_row_mt_sync->mi_rows_parse_done - |
| 3083 | dec_row_mt_sync->mi_rows_decode_started) * |
| 3084 | dec_row_mt_sync->mi_cols; |
| 3085 | num_mis_to_decode = |
| 3086 | (dec_row_mt_sync->mi_rows - dec_row_mt_sync->mi_rows_decode_started) * |
| 3087 | dec_row_mt_sync->mi_cols; |
| 3088 | |
| 3089 | assert(num_mis_to_decode >= num_mis_waiting_for_decode); |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3090 | |
| 3091 | // Pick the tile which has minimum number of threads working on it. |
Deepa K G | 5392235 | 2018-07-16 12:07:20 +0530 | [diff] [blame] | 3092 | if (num_mis_waiting_for_decode > 0) { |
| 3093 | if (num_threads_working < min_threads_working) { |
| 3094 | min_threads_working = num_threads_working; |
| 3095 | max_mis_to_decode = 0; |
| 3096 | } |
| 3097 | if (num_threads_working == min_threads_working && |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3098 | num_mis_to_decode > max_mis_to_decode && |
| 3099 | num_threads_working < |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3100 | get_max_row_mt_workers_per_tile(cm, &tile_data->tile_info)) { |
Deepa K G | 5392235 | 2018-07-16 12:07:20 +0530 | [diff] [blame] | 3101 | max_mis_to_decode = num_mis_to_decode; |
| 3102 | tile_row = tile_row_idx; |
| 3103 | tile_col = tile_col_idx; |
| 3104 | } |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3105 | } |
| 3106 | } |
| 3107 | } |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3108 | // No job found to process |
| 3109 | if (tile_row == -1 || tile_col == -1) return 0; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3110 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3111 | tile_data = pbi->tile_data + tile_row * cm->tiles.cols + tile_col; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3112 | dec_row_mt_sync = &tile_data->dec_row_mt_sync; |
| 3113 | |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3114 | next_job_info->tile_row = tile_row; |
| 3115 | next_job_info->tile_col = tile_col; |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3116 | next_job_info->mi_row = dec_row_mt_sync->mi_rows_decode_started + |
| 3117 | tile_data->tile_info.mi_row_start; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3118 | |
| 3119 | dec_row_mt_sync->num_threads_working++; |
| 3120 | dec_row_mt_sync->mi_rows_decode_started += sb_mi_size; |
| 3121 | frame_row_mt_info->mi_rows_decode_started += sb_mi_size; |
Wan-Teh Chang | 516badf | 2018-09-20 13:54:01 -0700 | [diff] [blame] | 3122 | assert(frame_row_mt_info->mi_rows_parse_done >= |
| 3123 | frame_row_mt_info->mi_rows_decode_started); |
| 3124 | #if CONFIG_MULTITHREAD |
| 3125 | if (frame_row_mt_info->mi_rows_decode_started == |
| 3126 | frame_row_mt_info->mi_rows_to_decode) { |
| 3127 | pthread_cond_broadcast(pbi->row_mt_cond_); |
| 3128 | } |
| 3129 | #endif |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3130 | |
| 3131 | return 1; |
| 3132 | } |
| 3133 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 3134 | static inline void signal_parse_sb_row_done(AV1Decoder *const pbi, |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3135 | TileDataDec *const tile_data, |
| 3136 | const int sb_mi_size) { |
| 3137 | AV1DecRowMTInfo *frame_row_mt_info = &pbi->frame_row_mt_info; |
| 3138 | #if CONFIG_MULTITHREAD |
| 3139 | pthread_mutex_lock(pbi->row_mt_mutex_); |
| 3140 | #endif |
Wan-Teh Chang | 516badf | 2018-09-20 13:54:01 -0700 | [diff] [blame] | 3141 | assert(frame_row_mt_info->mi_rows_parse_done >= |
| 3142 | frame_row_mt_info->mi_rows_decode_started); |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3143 | tile_data->dec_row_mt_sync.mi_rows_parse_done += sb_mi_size; |
| 3144 | frame_row_mt_info->mi_rows_parse_done += sb_mi_size; |
| 3145 | #if CONFIG_MULTITHREAD |
Wan-Teh Chang | 516badf | 2018-09-20 13:54:01 -0700 | [diff] [blame] | 3146 | // A new decode job is available. Wake up one worker thread to handle the |
| 3147 | // new decode job. |
| 3148 | // NOTE: This assumes we bump mi_rows_parse_done and mi_rows_decode_started |
| 3149 | // by the same increment (sb_mi_size). |
| 3150 | pthread_cond_signal(pbi->row_mt_cond_); |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3151 | pthread_mutex_unlock(pbi->row_mt_mutex_); |
| 3152 | #endif |
| 3153 | } |
| 3154 | |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3155 | // This function is very similar to decode_tile(). It would be good to figure |
| 3156 | // out how to share code. |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3157 | static inline void parse_tile_row_mt(AV1Decoder *pbi, ThreadData *const td, |
| 3158 | TileDataDec *const tile_data) { |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3159 | AV1_COMMON *const cm = &pbi->common; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3160 | const int sb_mi_size = mi_size_wide[cm->seq_params->sb_size]; |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3161 | const int num_planes = av1_num_planes(cm); |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3162 | const TileInfo *const tile_info = &tile_data->tile_info; |
| 3163 | int tile_row = tile_info->tile_row; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3164 | DecoderCodingBlock *const dcb = &td->dcb; |
| 3165 | MACROBLOCKD *const xd = &dcb->xd; |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3166 | |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3167 | av1_zero_above_context(cm, xd, tile_info->mi_col_start, tile_info->mi_col_end, |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3168 | tile_row); |
| 3169 | av1_reset_loop_filter_delta(xd, num_planes); |
| 3170 | av1_reset_loop_restoration(xd, num_planes); |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3171 | |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3172 | for (int mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3173 | mi_row += cm->seq_params->mib_size) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3174 | av1_zero_left_context(xd); |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3175 | |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3176 | for (int mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3177 | mi_col += cm->seq_params->mib_size) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3178 | set_cb_buffer(pbi, dcb, pbi->cb_buffer_base, num_planes, mi_row, mi_col); |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3179 | |
| 3180 | // Bit-stream parsing of the superblock |
| 3181 | decode_partition(pbi, td, mi_row, mi_col, td->bit_reader, |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3182 | cm->seq_params->sb_size, 0x1); |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3183 | |
| 3184 | if (aom_reader_has_overflowed(td->bit_reader)) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3185 | aom_merge_corrupted_flag(&dcb->corrupted, 1); |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3186 | return; |
| 3187 | } |
| 3188 | } |
| 3189 | signal_parse_sb_row_done(pbi, tile_data, sb_mi_size); |
| 3190 | } |
| 3191 | |
| 3192 | int corrupted = |
| 3193 | (check_trailing_bits_after_symbol_coder(td->bit_reader)) ? 1 : 0; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3194 | aom_merge_corrupted_flag(&dcb->corrupted, corrupted); |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3197 | static int row_mt_worker_hook(void *arg1, void *arg2) { |
| 3198 | DecWorkerData *const thread_data = (DecWorkerData *)arg1; |
| 3199 | AV1Decoder *const pbi = (AV1Decoder *)arg2; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3200 | ThreadData *const td = thread_data->td; |
| 3201 | uint8_t allow_update_cdf; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3202 | AV1DecRowMTInfo *frame_row_mt_info = &pbi->frame_row_mt_info; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3203 | td->dcb.corrupted = 0; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3204 | |
Wan-Teh Chang | a2fad3e | 2018-07-19 16:55:19 -0700 | [diff] [blame] | 3205 | // The jmp_buf is valid only for the duration of the function that calls |
| 3206 | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
| 3207 | // before it returns. |
Wan-Teh Chang | f3ac651 | 2018-07-18 17:18:53 -0700 | [diff] [blame] | 3208 | if (setjmp(thread_data->error_info.jmp)) { |
| 3209 | thread_data->error_info.setjmp = 0; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3210 | thread_data->td->dcb.corrupted = 1; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3211 | #if CONFIG_MULTITHREAD |
| 3212 | pthread_mutex_lock(pbi->row_mt_mutex_); |
| 3213 | #endif |
| 3214 | frame_row_mt_info->row_mt_exit = 1; |
Mudassir Galaganath | 4245c19 | 2023-12-14 12:36:20 +0530 | [diff] [blame] | 3215 | #if CONFIG_MULTITHREAD |
| 3216 | pthread_cond_broadcast(pbi->row_mt_cond_); |
| 3217 | pthread_mutex_unlock(pbi->row_mt_mutex_); |
| 3218 | #endif |
venkat sanampudi | dd5066d | 2022-02-14 21:17:02 +0530 | [diff] [blame] | 3219 | // If any SB row (erroneous row) processed by a thread encounters an |
| 3220 | // internal error, there is a need to indicate other threads that decoding |
| 3221 | // of the erroneous row is complete. This ensures that other threads which |
| 3222 | // wait upon the completion of SB's present in erroneous row are not waiting |
| 3223 | // indefinitely. |
| 3224 | signal_decoding_done_for_erroneous_row(pbi, &thread_data->td->dcb.xd); |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3225 | return 0; |
| 3226 | } |
Wan-Teh Chang | f3ac651 | 2018-07-18 17:18:53 -0700 | [diff] [blame] | 3227 | thread_data->error_info.setjmp = 1; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3228 | |
venkat sanampudi | dd5066d | 2022-02-14 21:17:02 +0530 | [diff] [blame] | 3229 | AV1_COMMON *cm = &pbi->common; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3230 | allow_update_cdf = cm->tiles.large_scale ? 0 : 1; |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 3231 | allow_update_cdf = allow_update_cdf && !cm->features.disable_cdf_update; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3232 | |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3233 | set_decode_func_pointers(td, 0x1); |
| 3234 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3235 | assert(cm->tiles.cols > 0); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3236 | while (!td->dcb.corrupted) { |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3237 | TileJobsDec *cur_job_info = get_dec_job_info(&pbi->tile_mt_info); |
| 3238 | |
Wan-Teh Chang | 30e8ddb | 2018-09-19 18:17:32 -0700 | [diff] [blame] | 3239 | if (cur_job_info != NULL) { |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3240 | const TileBufferDec *const tile_buffer = cur_job_info->tile_buffer; |
| 3241 | TileDataDec *const tile_data = cur_job_info->tile_data; |
| 3242 | tile_worker_hook_init(pbi, thread_data, tile_buffer, tile_data, |
| 3243 | allow_update_cdf); |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3244 | #if CONFIG_MULTITHREAD |
| 3245 | pthread_mutex_lock(pbi->row_mt_mutex_); |
| 3246 | #endif |
| 3247 | tile_data->dec_row_mt_sync.num_threads_working++; |
| 3248 | #if CONFIG_MULTITHREAD |
| 3249 | pthread_mutex_unlock(pbi->row_mt_mutex_); |
| 3250 | #endif |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3251 | // decode tile |
Wan-Teh Chang | fe9ce8d | 2018-09-24 18:39:56 -0700 | [diff] [blame] | 3252 | parse_tile_row_mt(pbi, td, tile_data); |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3253 | #if CONFIG_MULTITHREAD |
| 3254 | pthread_mutex_lock(pbi->row_mt_mutex_); |
| 3255 | #endif |
| 3256 | tile_data->dec_row_mt_sync.num_threads_working--; |
| 3257 | #if CONFIG_MULTITHREAD |
| 3258 | pthread_mutex_unlock(pbi->row_mt_mutex_); |
| 3259 | #endif |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3260 | } else { |
| 3261 | break; |
| 3262 | } |
| 3263 | } |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3264 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3265 | if (td->dcb.corrupted) { |
Wan-Teh Chang | 82e0ef6 | 2018-09-19 15:32:56 -0700 | [diff] [blame] | 3266 | thread_data->error_info.setjmp = 0; |
| 3267 | #if CONFIG_MULTITHREAD |
| 3268 | pthread_mutex_lock(pbi->row_mt_mutex_); |
| 3269 | #endif |
| 3270 | frame_row_mt_info->row_mt_exit = 1; |
| 3271 | #if CONFIG_MULTITHREAD |
| 3272 | pthread_cond_broadcast(pbi->row_mt_cond_); |
| 3273 | pthread_mutex_unlock(pbi->row_mt_mutex_); |
| 3274 | #endif |
| 3275 | return 0; |
| 3276 | } |
| 3277 | |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3278 | set_decode_func_pointers(td, 0x2); |
| 3279 | |
| 3280 | while (1) { |
| 3281 | AV1DecRowMTJobInfo next_job_info; |
| 3282 | int end_of_frame = 0; |
| 3283 | |
| 3284 | #if CONFIG_MULTITHREAD |
| 3285 | pthread_mutex_lock(pbi->row_mt_mutex_); |
| 3286 | #endif |
| 3287 | while (!get_next_job_info(pbi, &next_job_info, &end_of_frame)) { |
| 3288 | #if CONFIG_MULTITHREAD |
| 3289 | pthread_cond_wait(pbi->row_mt_cond_, pbi->row_mt_mutex_); |
| 3290 | #endif |
| 3291 | } |
| 3292 | #if CONFIG_MULTITHREAD |
| 3293 | pthread_mutex_unlock(pbi->row_mt_mutex_); |
| 3294 | #endif |
| 3295 | |
| 3296 | if (end_of_frame) break; |
| 3297 | |
| 3298 | int tile_row = next_job_info.tile_row; |
| 3299 | int tile_col = next_job_info.tile_col; |
| 3300 | int mi_row = next_job_info.mi_row; |
| 3301 | |
| 3302 | TileDataDec *tile_data = |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3303 | pbi->tile_data + tile_row * cm->tiles.cols + tile_col; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3304 | AV1DecRowMTSync *dec_row_mt_sync = &tile_data->dec_row_mt_sync; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3305 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3306 | av1_tile_init(&td->dcb.xd.tile, cm, tile_row, tile_col); |
| 3307 | av1_init_macroblockd(cm, &td->dcb.xd); |
| 3308 | td->dcb.xd.error_info = &thread_data->error_info; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3309 | |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3310 | decode_tile_sb_row(pbi, td, &tile_data->tile_info, mi_row); |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3311 | |
| 3312 | #if CONFIG_MULTITHREAD |
| 3313 | pthread_mutex_lock(pbi->row_mt_mutex_); |
| 3314 | #endif |
| 3315 | dec_row_mt_sync->num_threads_working--; |
| 3316 | #if CONFIG_MULTITHREAD |
| 3317 | pthread_mutex_unlock(pbi->row_mt_mutex_); |
| 3318 | #endif |
| 3319 | } |
Wan-Teh Chang | 9f2e331 | 2018-07-06 11:00:36 -0700 | [diff] [blame] | 3320 | thread_data->error_info.setjmp = 0; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3321 | return !td->dcb.corrupted; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3322 | } |
| 3323 | |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3324 | // sorts in descending order |
| 3325 | static int compare_tile_buffers(const void *a, const void *b) { |
| 3326 | const TileJobsDec *const buf1 = (const TileJobsDec *)a; |
| 3327 | const TileJobsDec *const buf2 = (const TileJobsDec *)b; |
Ravi Chaudhary | 09693ea | 2018-06-20 19:23:47 +0530 | [diff] [blame] | 3328 | return (((int)buf2->tile_buffer->size) - ((int)buf1->tile_buffer->size)); |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3329 | } |
| 3330 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3331 | static inline void enqueue_tile_jobs(AV1Decoder *pbi, AV1_COMMON *cm, |
| 3332 | int tile_rows_start, int tile_rows_end, |
| 3333 | int tile_cols_start, int tile_cols_end, |
| 3334 | int start_tile, int end_tile) { |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3335 | AV1DecTileMT *tile_mt_info = &pbi->tile_mt_info; |
| 3336 | TileJobsDec *tile_job_queue = tile_mt_info->job_queue; |
| 3337 | tile_mt_info->jobs_enqueued = 0; |
| 3338 | tile_mt_info->jobs_dequeued = 0; |
| 3339 | |
| 3340 | for (int row = tile_rows_start; row < tile_rows_end; row++) { |
| 3341 | for (int col = tile_cols_start; col < tile_cols_end; col++) { |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3342 | if (row * cm->tiles.cols + col < start_tile || |
| 3343 | row * cm->tiles.cols + col > end_tile) |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3344 | continue; |
| 3345 | tile_job_queue->tile_buffer = &pbi->tile_buffers[row][col]; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3346 | tile_job_queue->tile_data = pbi->tile_data + row * cm->tiles.cols + col; |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3347 | tile_job_queue++; |
| 3348 | tile_mt_info->jobs_enqueued++; |
| 3349 | } |
| 3350 | } |
| 3351 | } |
| 3352 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3353 | static inline void alloc_dec_jobs(AV1DecTileMT *tile_mt_info, AV1_COMMON *cm, |
| 3354 | int tile_rows, int tile_cols) { |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3355 | tile_mt_info->alloc_tile_rows = tile_rows; |
| 3356 | tile_mt_info->alloc_tile_cols = tile_cols; |
| 3357 | int num_tiles = tile_rows * tile_cols; |
| 3358 | #if CONFIG_MULTITHREAD |
| 3359 | { |
| 3360 | CHECK_MEM_ERROR(cm, tile_mt_info->job_mutex, |
| 3361 | aom_malloc(sizeof(*tile_mt_info->job_mutex) * num_tiles)); |
| 3362 | |
| 3363 | for (int i = 0; i < num_tiles; i++) { |
| 3364 | pthread_mutex_init(&tile_mt_info->job_mutex[i], NULL); |
| 3365 | } |
| 3366 | } |
| 3367 | #endif |
| 3368 | CHECK_MEM_ERROR(cm, tile_mt_info->job_queue, |
| 3369 | aom_malloc(sizeof(*tile_mt_info->job_queue) * num_tiles)); |
| 3370 | } |
| 3371 | |
Wan-Teh Chang | 8d728cc | 2018-08-30 15:34:47 -0700 | [diff] [blame] | 3372 | void av1_free_mc_tmp_buf(ThreadData *thread_data) { |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3373 | int ref; |
| 3374 | for (ref = 0; ref < 2; ref++) { |
Wan-Teh Chang | 8d728cc | 2018-08-30 15:34:47 -0700 | [diff] [blame] | 3375 | if (thread_data->mc_buf_use_highbd) |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3376 | aom_free(CONVERT_TO_SHORTPTR(thread_data->mc_buf[ref])); |
| 3377 | else |
| 3378 | aom_free(thread_data->mc_buf[ref]); |
| 3379 | thread_data->mc_buf[ref] = NULL; |
| 3380 | } |
Ravi Chaudhary | 4bce229 | 2018-06-11 15:03:44 +0530 | [diff] [blame] | 3381 | thread_data->mc_buf_size = 0; |
Wan-Teh Chang | 8d728cc | 2018-08-30 15:34:47 -0700 | [diff] [blame] | 3382 | thread_data->mc_buf_use_highbd = 0; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3383 | |
| 3384 | aom_free(thread_data->tmp_conv_dst); |
| 3385 | thread_data->tmp_conv_dst = NULL; |
Chethan Kumar R E | a494e2b | 2021-03-18 17:19:44 +0530 | [diff] [blame] | 3386 | aom_free(thread_data->seg_mask); |
| 3387 | thread_data->seg_mask = NULL; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3388 | for (int i = 0; i < 2; ++i) { |
| 3389 | aom_free(thread_data->tmp_obmc_bufs[i]); |
| 3390 | thread_data->tmp_obmc_bufs[i] = NULL; |
| 3391 | } |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3392 | } |
| 3393 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3394 | static inline void allocate_mc_tmp_buf(AV1_COMMON *const cm, |
| 3395 | ThreadData *thread_data, int buf_size, |
| 3396 | int use_highbd) { |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3397 | for (int ref = 0; ref < 2; ref++) { |
Sachin Kumar Garg | da73940 | 2020-06-05 10:40:07 +0530 | [diff] [blame] | 3398 | // The mc_buf/hbd_mc_buf must be zeroed to fix a intermittent valgrind error |
| 3399 | // 'Conditional jump or move depends on uninitialised value' from the loop |
| 3400 | // filter. Uninitialized reads in convolve function (e.g. horiz_4tap path in |
| 3401 | // av1_convolve_2d_sr_avx2()) from mc_buf/hbd_mc_buf are seen to be the |
| 3402 | // potential reason for this issue. |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3403 | if (use_highbd) { |
| 3404 | uint16_t *hbd_mc_buf; |
| 3405 | CHECK_MEM_ERROR(cm, hbd_mc_buf, (uint16_t *)aom_memalign(16, buf_size)); |
Sachin Kumar Garg | da73940 | 2020-06-05 10:40:07 +0530 | [diff] [blame] | 3406 | memset(hbd_mc_buf, 0, buf_size); |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3407 | thread_data->mc_buf[ref] = CONVERT_TO_BYTEPTR(hbd_mc_buf); |
| 3408 | } else { |
| 3409 | CHECK_MEM_ERROR(cm, thread_data->mc_buf[ref], |
| 3410 | (uint8_t *)aom_memalign(16, buf_size)); |
Sachin Kumar Garg | da73940 | 2020-06-05 10:40:07 +0530 | [diff] [blame] | 3411 | memset(thread_data->mc_buf[ref], 0, buf_size); |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3412 | } |
| 3413 | } |
| 3414 | thread_data->mc_buf_size = buf_size; |
Wan-Teh Chang | 8d728cc | 2018-08-30 15:34:47 -0700 | [diff] [blame] | 3415 | thread_data->mc_buf_use_highbd = use_highbd; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3416 | |
| 3417 | CHECK_MEM_ERROR(cm, thread_data->tmp_conv_dst, |
| 3418 | aom_memalign(32, MAX_SB_SIZE * MAX_SB_SIZE * |
| 3419 | sizeof(*thread_data->tmp_conv_dst))); |
Chethan Kumar R E | a494e2b | 2021-03-18 17:19:44 +0530 | [diff] [blame] | 3420 | CHECK_MEM_ERROR(cm, thread_data->seg_mask, |
| 3421 | (uint8_t *)aom_memalign( |
| 3422 | 16, 2 * MAX_SB_SQUARE * sizeof(*thread_data->seg_mask))); |
| 3423 | |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 3424 | for (int i = 0; i < 2; ++i) { |
| 3425 | CHECK_MEM_ERROR( |
| 3426 | cm, thread_data->tmp_obmc_bufs[i], |
| 3427 | aom_memalign(16, 2 * MAX_MB_PLANE * MAX_SB_SQUARE * |
| 3428 | sizeof(*thread_data->tmp_obmc_bufs[i]))); |
| 3429 | } |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3430 | } |
| 3431 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3432 | static inline void reset_dec_workers(AV1Decoder *pbi, AVxWorkerHook worker_hook, |
| 3433 | int num_workers) { |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3434 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
| 3435 | |
| 3436 | // Reset tile decoding hook |
| 3437 | for (int worker_idx = 0; worker_idx < num_workers; ++worker_idx) { |
| 3438 | AVxWorker *const worker = &pbi->tile_workers[worker_idx]; |
| 3439 | DecWorkerData *const thread_data = pbi->thread_data + worker_idx; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3440 | thread_data->td->dcb = pbi->dcb; |
| 3441 | thread_data->td->dcb.corrupted = 0; |
| 3442 | thread_data->td->dcb.mc_buf[0] = thread_data->td->mc_buf[0]; |
| 3443 | thread_data->td->dcb.mc_buf[1] = thread_data->td->mc_buf[1]; |
| 3444 | thread_data->td->dcb.xd.tmp_conv_dst = thread_data->td->tmp_conv_dst; |
Chethan Kumar R E | a494e2b | 2021-03-18 17:19:44 +0530 | [diff] [blame] | 3445 | if (worker_idx) |
| 3446 | thread_data->td->dcb.xd.seg_mask = thread_data->td->seg_mask; |
Urvang Joshi | e58f6eca | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 3447 | for (int j = 0; j < 2; ++j) { |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3448 | thread_data->td->dcb.xd.tmp_obmc_bufs[j] = |
| 3449 | thread_data->td->tmp_obmc_bufs[j]; |
Urvang Joshi | e58f6eca | 2018-09-10 15:10:12 -0700 | [diff] [blame] | 3450 | } |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3451 | winterface->sync(worker); |
| 3452 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3453 | worker->hook = worker_hook; |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3454 | worker->data1 = thread_data; |
| 3455 | worker->data2 = pbi; |
| 3456 | } |
| 3457 | #if CONFIG_ACCOUNTING |
| 3458 | if (pbi->acct_enabled) { |
| 3459 | aom_accounting_reset(&pbi->accounting); |
| 3460 | } |
| 3461 | #endif |
| 3462 | } |
| 3463 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3464 | static inline void launch_dec_workers(AV1Decoder *pbi, const uint8_t *data_end, |
| 3465 | int num_workers) { |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3466 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
| 3467 | |
Deepa K G | 5786774 | 2021-01-19 12:52:41 -0800 | [diff] [blame] | 3468 | for (int worker_idx = num_workers - 1; worker_idx >= 0; --worker_idx) { |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3469 | AVxWorker *const worker = &pbi->tile_workers[worker_idx]; |
| 3470 | DecWorkerData *const thread_data = (DecWorkerData *)worker->data1; |
| 3471 | |
| 3472 | thread_data->data_end = data_end; |
| 3473 | |
| 3474 | worker->had_error = 0; |
Deepa K G | 5786774 | 2021-01-19 12:52:41 -0800 | [diff] [blame] | 3475 | if (worker_idx == 0) { |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3476 | winterface->execute(worker); |
| 3477 | } else { |
| 3478 | winterface->launch(worker); |
| 3479 | } |
| 3480 | } |
| 3481 | } |
| 3482 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3483 | static inline void sync_dec_workers(AV1Decoder *pbi, int num_workers) { |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3484 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
| 3485 | int corrupted = 0; |
| 3486 | |
| 3487 | for (int worker_idx = num_workers; worker_idx > 0; --worker_idx) { |
| 3488 | AVxWorker *const worker = &pbi->tile_workers[worker_idx - 1]; |
| 3489 | aom_merge_corrupted_flag(&corrupted, !winterface->sync(worker)); |
| 3490 | } |
| 3491 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3492 | pbi->dcb.corrupted = corrupted; |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3493 | } |
| 3494 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3495 | static inline void decode_mt_init(AV1Decoder *pbi) { |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3496 | AV1_COMMON *const cm = &pbi->common; |
| 3497 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3498 | int worker_idx; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3499 | |
| 3500 | // Create workers and thread_data |
| 3501 | if (pbi->num_workers == 0) { |
| 3502 | const int num_threads = pbi->max_threads; |
| 3503 | CHECK_MEM_ERROR(cm, pbi->tile_workers, |
| 3504 | aom_malloc(num_threads * sizeof(*pbi->tile_workers))); |
| 3505 | CHECK_MEM_ERROR(cm, pbi->thread_data, |
James Zern | a3b61c1 | 2022-12-06 15:29:22 -0800 | [diff] [blame] | 3506 | aom_calloc(num_threads, sizeof(*pbi->thread_data))); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3507 | |
| 3508 | for (worker_idx = 0; worker_idx < num_threads; ++worker_idx) { |
| 3509 | AVxWorker *const worker = &pbi->tile_workers[worker_idx]; |
| 3510 | DecWorkerData *const thread_data = pbi->thread_data + worker_idx; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3511 | |
| 3512 | winterface->init(worker); |
Wan-Teh Chang | 4d29ee8 | 2018-09-20 10:07:52 -0700 | [diff] [blame] | 3513 | worker->thread_name = "aom tile worker"; |
Deepa K G | 5786774 | 2021-01-19 12:52:41 -0800 | [diff] [blame] | 3514 | if (worker_idx != 0 && !winterface->reset(worker)) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3515 | aom_internal_error(&pbi->error, AOM_CODEC_ERROR, |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3516 | "Tile decoder thread creation failed"); |
| 3517 | } |
James Zern | a3b61c1 | 2022-12-06 15:29:22 -0800 | [diff] [blame] | 3518 | ++pbi->num_workers; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3519 | |
Deepa K G | 5786774 | 2021-01-19 12:52:41 -0800 | [diff] [blame] | 3520 | if (worker_idx != 0) { |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3521 | // Allocate thread data. |
| 3522 | CHECK_MEM_ERROR(cm, thread_data->td, |
| 3523 | aom_memalign(32, sizeof(*thread_data->td))); |
| 3524 | av1_zero(*thread_data->td); |
| 3525 | } else { |
| 3526 | // Main thread acts as a worker and uses the thread data in pbi |
| 3527 | thread_data->td = &pbi->td; |
| 3528 | } |
Wan-Teh Chang | 61f2353 | 2018-07-12 18:20:02 -0700 | [diff] [blame] | 3529 | thread_data->error_info.error_code = AOM_CODEC_OK; |
| 3530 | thread_data->error_info.setjmp = 0; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3531 | } |
| 3532 | } |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3533 | const int use_highbd = cm->seq_params->use_highbitdepth; |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3534 | const int buf_size = MC_TEMP_BUF_PELS << use_highbd; |
Deepa K G | 5786774 | 2021-01-19 12:52:41 -0800 | [diff] [blame] | 3535 | for (worker_idx = 1; worker_idx < pbi->max_threads; ++worker_idx) { |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3536 | DecWorkerData *const thread_data = pbi->thread_data + worker_idx; |
| 3537 | if (thread_data->td->mc_buf_size != buf_size) { |
Wan-Teh Chang | 8d728cc | 2018-08-30 15:34:47 -0700 | [diff] [blame] | 3538 | av1_free_mc_tmp_buf(thread_data->td); |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 3539 | allocate_mc_tmp_buf(cm, thread_data->td, buf_size, use_highbd); |
| 3540 | } |
| 3541 | } |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3542 | } |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3543 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3544 | static inline void tile_mt_queue(AV1Decoder *pbi, int tile_cols, int tile_rows, |
| 3545 | int tile_rows_start, int tile_rows_end, |
| 3546 | int tile_cols_start, int tile_cols_end, |
| 3547 | int start_tile, int end_tile) { |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3548 | AV1_COMMON *const cm = &pbi->common; |
| 3549 | if (pbi->tile_mt_info.alloc_tile_cols != tile_cols || |
| 3550 | pbi->tile_mt_info.alloc_tile_rows != tile_rows) { |
| 3551 | av1_dealloc_dec_jobs(&pbi->tile_mt_info); |
| 3552 | alloc_dec_jobs(&pbi->tile_mt_info, cm, tile_rows, tile_cols); |
| 3553 | } |
| 3554 | enqueue_tile_jobs(pbi, cm, tile_rows_start, tile_rows_end, tile_cols_start, |
| 3555 | tile_cols_end, start_tile, end_tile); |
| 3556 | qsort(pbi->tile_mt_info.job_queue, pbi->tile_mt_info.jobs_enqueued, |
| 3557 | sizeof(pbi->tile_mt_info.job_queue[0]), compare_tile_buffers); |
| 3558 | } |
| 3559 | |
| 3560 | static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data, |
| 3561 | const uint8_t *data_end, int start_tile, |
| 3562 | int end_tile) { |
| 3563 | AV1_COMMON *const cm = &pbi->common; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3564 | CommonTileParams *const tiles = &cm->tiles; |
| 3565 | const int tile_cols = tiles->cols; |
| 3566 | const int tile_rows = tiles->rows; |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3567 | const int n_tiles = tile_cols * tile_rows; |
| 3568 | TileBufferDec(*const tile_buffers)[MAX_TILE_COLS] = pbi->tile_buffers; |
| 3569 | const int dec_tile_row = AOMMIN(pbi->dec_tile_row, tile_rows); |
| 3570 | const int single_row = pbi->dec_tile_row >= 0; |
| 3571 | const int dec_tile_col = AOMMIN(pbi->dec_tile_col, tile_cols); |
| 3572 | const int single_col = pbi->dec_tile_col >= 0; |
| 3573 | int tile_rows_start; |
| 3574 | int tile_rows_end; |
| 3575 | int tile_cols_start; |
| 3576 | int tile_cols_end; |
| 3577 | int tile_count_tg; |
| 3578 | int num_workers; |
| 3579 | const uint8_t *raw_data_end = NULL; |
| 3580 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3581 | if (tiles->large_scale) { |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3582 | tile_rows_start = single_row ? dec_tile_row : 0; |
| 3583 | tile_rows_end = single_row ? dec_tile_row + 1 : tile_rows; |
| 3584 | tile_cols_start = single_col ? dec_tile_col : 0; |
| 3585 | tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; |
| 3586 | } else { |
| 3587 | tile_rows_start = 0; |
| 3588 | tile_rows_end = tile_rows; |
| 3589 | tile_cols_start = 0; |
| 3590 | tile_cols_end = tile_cols; |
| 3591 | } |
| 3592 | tile_count_tg = end_tile - start_tile + 1; |
| 3593 | num_workers = AOMMIN(pbi->max_threads, tile_count_tg); |
| 3594 | |
| 3595 | // No tiles to decode. |
| 3596 | if (tile_rows_end <= tile_rows_start || tile_cols_end <= tile_cols_start || |
| 3597 | // First tile is larger than end_tile. |
| 3598 | tile_rows_start * tile_cols + tile_cols_start > end_tile || |
| 3599 | // Last tile is smaller than start_tile. |
| 3600 | (tile_rows_end - 1) * tile_cols + tile_cols_end - 1 < start_tile) |
| 3601 | return data; |
| 3602 | |
| 3603 | assert(tile_rows <= MAX_TILE_ROWS); |
| 3604 | assert(tile_cols <= MAX_TILE_COLS); |
| 3605 | assert(tile_count_tg > 0); |
| 3606 | assert(num_workers > 0); |
| 3607 | assert(start_tile <= end_tile); |
| 3608 | assert(start_tile >= 0 && end_tile < n_tiles); |
| 3609 | |
| 3610 | decode_mt_init(pbi); |
| 3611 | |
| 3612 | // get tile size in tile group |
Yunqing Wang | 3a74b25 | 2018-05-03 15:24:07 -0700 | [diff] [blame] | 3613 | #if EXT_TILE_DEBUG |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3614 | if (tiles->large_scale) assert(pbi->ext_tile_debug == 1); |
| 3615 | if (tiles->large_scale) |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 3616 | raw_data_end = get_ls_tile_buffers(pbi, data, data_end, tile_buffers); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3617 | else |
Yunqing Wang | 3a74b25 | 2018-05-03 15:24:07 -0700 | [diff] [blame] | 3618 | #endif // EXT_TILE_DEBUG |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 3619 | get_tile_buffers(pbi, data, data_end, tile_buffers, start_tile, end_tile); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3620 | |
| 3621 | if (pbi->tile_data == NULL || n_tiles != pbi->allocated_tiles) { |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 3622 | decoder_alloc_tile_data(pbi, n_tiles); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3623 | } |
Chethan Kumar R E | a494e2b | 2021-03-18 17:19:44 +0530 | [diff] [blame] | 3624 | if (pbi->dcb.xd.seg_mask == NULL) |
| 3625 | CHECK_MEM_ERROR(cm, pbi->dcb.xd.seg_mask, |
| 3626 | (uint8_t *)aom_memalign( |
| 3627 | 16, 2 * MAX_SB_SQUARE * sizeof(*pbi->dcb.xd.seg_mask))); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3628 | |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3629 | for (int row = 0; row < tile_rows; row++) { |
| 3630 | for (int col = 0; col < tile_cols; col++) { |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3631 | TileDataDec *tile_data = pbi->tile_data + row * tiles->cols + col; |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3632 | av1_tile_init(&tile_data->tile_info, cm, row, col); |
| 3633 | } |
| 3634 | } |
| 3635 | |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3636 | tile_mt_queue(pbi, tile_cols, tile_rows, tile_rows_start, tile_rows_end, |
| 3637 | tile_cols_start, tile_cols_end, start_tile, end_tile); |
Ravi Chaudhary | 2ad23c3 | 2018-06-13 15:45:48 +0530 | [diff] [blame] | 3638 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3639 | reset_dec_workers(pbi, tile_worker_hook, num_workers); |
| 3640 | launch_dec_workers(pbi, data_end, num_workers); |
| 3641 | sync_dec_workers(pbi, num_workers); |
| 3642 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3643 | if (pbi->dcb.corrupted) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3644 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3645 | "Failed to decode tile data"); |
| 3646 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3647 | if (tiles->large_scale) { |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3648 | if (n_tiles == 1) { |
| 3649 | // Find the end of the single tile buffer |
| 3650 | return aom_reader_find_end(&pbi->tile_data->bit_reader); |
| 3651 | } |
| 3652 | // Return the end of the last tile buffer |
| 3653 | return raw_data_end; |
| 3654 | } |
| 3655 | TileDataDec *const tile_data = pbi->tile_data + end_tile; |
| 3656 | |
| 3657 | return aom_reader_find_end(&tile_data->bit_reader); |
| 3658 | } |
| 3659 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3660 | static inline void dec_alloc_cb_buf(AV1Decoder *pbi) { |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3661 | AV1_COMMON *const cm = &pbi->common; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3662 | int size = ((cm->mi_params.mi_rows >> cm->seq_params->mib_size_log2) + 1) * |
| 3663 | ((cm->mi_params.mi_cols >> cm->seq_params->mib_size_log2) + 1); |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3664 | |
| 3665 | if (pbi->cb_buffer_alloc_size < size) { |
| 3666 | av1_dec_free_cb_buf(pbi); |
| 3667 | CHECK_MEM_ERROR(cm, pbi->cb_buffer_base, |
| 3668 | aom_memalign(32, sizeof(*pbi->cb_buffer_base) * size)); |
wenyao.liu | 00c80e6 | 2018-12-28 10:42:26 +0800 | [diff] [blame] | 3669 | memset(pbi->cb_buffer_base, 0, sizeof(*pbi->cb_buffer_base) * size); |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3670 | pbi->cb_buffer_alloc_size = size; |
| 3671 | } |
| 3672 | } |
| 3673 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3674 | static inline void row_mt_frame_init(AV1Decoder *pbi, int tile_rows_start, |
| 3675 | int tile_rows_end, int tile_cols_start, |
| 3676 | int tile_cols_end, int start_tile, |
| 3677 | int end_tile, int max_sb_rows) { |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3678 | AV1_COMMON *const cm = &pbi->common; |
| 3679 | AV1DecRowMTInfo *frame_row_mt_info = &pbi->frame_row_mt_info; |
| 3680 | |
| 3681 | frame_row_mt_info->tile_rows_start = tile_rows_start; |
| 3682 | frame_row_mt_info->tile_rows_end = tile_rows_end; |
| 3683 | frame_row_mt_info->tile_cols_start = tile_cols_start; |
| 3684 | frame_row_mt_info->tile_cols_end = tile_cols_end; |
| 3685 | frame_row_mt_info->start_tile = start_tile; |
| 3686 | frame_row_mt_info->end_tile = end_tile; |
| 3687 | frame_row_mt_info->mi_rows_to_decode = 0; |
| 3688 | frame_row_mt_info->mi_rows_parse_done = 0; |
| 3689 | frame_row_mt_info->mi_rows_decode_started = 0; |
| 3690 | frame_row_mt_info->row_mt_exit = 0; |
| 3691 | |
| 3692 | for (int tile_row = tile_rows_start; tile_row < tile_rows_end; ++tile_row) { |
| 3693 | for (int tile_col = tile_cols_start; tile_col < tile_cols_end; ++tile_col) { |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3694 | if (tile_row * cm->tiles.cols + tile_col < start_tile || |
| 3695 | tile_row * cm->tiles.cols + tile_col > end_tile) |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3696 | continue; |
| 3697 | |
| 3698 | TileDataDec *const tile_data = |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3699 | pbi->tile_data + tile_row * cm->tiles.cols + tile_col; |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3700 | const TileInfo *const tile_info = &tile_data->tile_info; |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3701 | |
| 3702 | tile_data->dec_row_mt_sync.mi_rows_parse_done = 0; |
| 3703 | tile_data->dec_row_mt_sync.mi_rows_decode_started = 0; |
| 3704 | tile_data->dec_row_mt_sync.num_threads_working = 0; |
| 3705 | tile_data->dec_row_mt_sync.mi_rows = |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3706 | ALIGN_POWER_OF_TWO(tile_info->mi_row_end - tile_info->mi_row_start, |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3707 | cm->seq_params->mib_size_log2); |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3708 | tile_data->dec_row_mt_sync.mi_cols = |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3709 | ALIGN_POWER_OF_TWO(tile_info->mi_col_end - tile_info->mi_col_start, |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3710 | cm->seq_params->mib_size_log2); |
Jayasanker J | 34ec50a | 2022-07-01 19:00:02 +0530 | [diff] [blame] | 3711 | tile_data->dec_row_mt_sync.intrabc_extra_top_right_sb_delay = |
| 3712 | av1_get_intrabc_extra_top_right_sb_delay(cm); |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3713 | |
| 3714 | frame_row_mt_info->mi_rows_to_decode += |
| 3715 | tile_data->dec_row_mt_sync.mi_rows; |
| 3716 | |
| 3717 | // Initialize cur_sb_col to -1 for all SB rows. |
| 3718 | memset(tile_data->dec_row_mt_sync.cur_sb_col, -1, |
| 3719 | sizeof(*tile_data->dec_row_mt_sync.cur_sb_col) * max_sb_rows); |
| 3720 | } |
| 3721 | } |
| 3722 | |
| 3723 | #if CONFIG_MULTITHREAD |
| 3724 | if (pbi->row_mt_mutex_ == NULL) { |
| 3725 | CHECK_MEM_ERROR(cm, pbi->row_mt_mutex_, |
| 3726 | aom_malloc(sizeof(*(pbi->row_mt_mutex_)))); |
| 3727 | if (pbi->row_mt_mutex_) { |
| 3728 | pthread_mutex_init(pbi->row_mt_mutex_, NULL); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | if (pbi->row_mt_cond_ == NULL) { |
| 3733 | CHECK_MEM_ERROR(cm, pbi->row_mt_cond_, |
| 3734 | aom_malloc(sizeof(*(pbi->row_mt_cond_)))); |
| 3735 | if (pbi->row_mt_cond_) { |
| 3736 | pthread_cond_init(pbi->row_mt_cond_, NULL); |
| 3737 | } |
| 3738 | } |
| 3739 | #endif |
| 3740 | } |
| 3741 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3742 | static const uint8_t *decode_tiles_row_mt(AV1Decoder *pbi, const uint8_t *data, |
| 3743 | const uint8_t *data_end, |
| 3744 | int start_tile, int end_tile) { |
| 3745 | AV1_COMMON *const cm = &pbi->common; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3746 | CommonTileParams *const tiles = &cm->tiles; |
| 3747 | const int tile_cols = tiles->cols; |
| 3748 | const int tile_rows = tiles->rows; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3749 | const int n_tiles = tile_cols * tile_rows; |
| 3750 | TileBufferDec(*const tile_buffers)[MAX_TILE_COLS] = pbi->tile_buffers; |
| 3751 | const int dec_tile_row = AOMMIN(pbi->dec_tile_row, tile_rows); |
| 3752 | const int single_row = pbi->dec_tile_row >= 0; |
| 3753 | const int dec_tile_col = AOMMIN(pbi->dec_tile_col, tile_cols); |
| 3754 | const int single_col = pbi->dec_tile_col >= 0; |
| 3755 | int tile_rows_start; |
| 3756 | int tile_rows_end; |
| 3757 | int tile_cols_start; |
| 3758 | int tile_cols_end; |
| 3759 | int tile_count_tg; |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3760 | int num_workers = 0; |
| 3761 | int max_threads; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3762 | const uint8_t *raw_data_end = NULL; |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 3763 | int max_sb_rows = 0; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3764 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3765 | if (tiles->large_scale) { |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3766 | tile_rows_start = single_row ? dec_tile_row : 0; |
| 3767 | tile_rows_end = single_row ? dec_tile_row + 1 : tile_rows; |
| 3768 | tile_cols_start = single_col ? dec_tile_col : 0; |
| 3769 | tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; |
| 3770 | } else { |
| 3771 | tile_rows_start = 0; |
| 3772 | tile_rows_end = tile_rows; |
| 3773 | tile_cols_start = 0; |
| 3774 | tile_cols_end = tile_cols; |
| 3775 | } |
| 3776 | tile_count_tg = end_tile - start_tile + 1; |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3777 | max_threads = pbi->max_threads; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3778 | |
| 3779 | // No tiles to decode. |
| 3780 | if (tile_rows_end <= tile_rows_start || tile_cols_end <= tile_cols_start || |
| 3781 | // First tile is larger than end_tile. |
| 3782 | tile_rows_start * tile_cols + tile_cols_start > end_tile || |
| 3783 | // Last tile is smaller than start_tile. |
| 3784 | (tile_rows_end - 1) * tile_cols + tile_cols_end - 1 < start_tile) |
| 3785 | return data; |
| 3786 | |
| 3787 | assert(tile_rows <= MAX_TILE_ROWS); |
| 3788 | assert(tile_cols <= MAX_TILE_COLS); |
| 3789 | assert(tile_count_tg > 0); |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3790 | assert(max_threads > 0); |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3791 | assert(start_tile <= end_tile); |
| 3792 | assert(start_tile >= 0 && end_tile < n_tiles); |
| 3793 | |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3794 | (void)tile_count_tg; |
| 3795 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3796 | decode_mt_init(pbi); |
| 3797 | |
| 3798 | // get tile size in tile group |
| 3799 | #if EXT_TILE_DEBUG |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3800 | if (tiles->large_scale) assert(pbi->ext_tile_debug == 1); |
| 3801 | if (tiles->large_scale) |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3802 | raw_data_end = get_ls_tile_buffers(pbi, data, data_end, tile_buffers); |
| 3803 | else |
| 3804 | #endif // EXT_TILE_DEBUG |
| 3805 | get_tile_buffers(pbi, data, data_end, tile_buffers, start_tile, end_tile); |
| 3806 | |
| 3807 | if (pbi->tile_data == NULL || n_tiles != pbi->allocated_tiles) { |
Yaowu Xu | dbe5aaa | 2020-04-13 08:59:42 -0700 | [diff] [blame] | 3808 | if (pbi->tile_data != NULL) { |
| 3809 | for (int i = 0; i < pbi->allocated_tiles; i++) { |
| 3810 | TileDataDec *const tile_data = pbi->tile_data + i; |
| 3811 | av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync); |
| 3812 | } |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 3813 | } |
| 3814 | decoder_alloc_tile_data(pbi, n_tiles); |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3815 | } |
Chethan Kumar R E | a494e2b | 2021-03-18 17:19:44 +0530 | [diff] [blame] | 3816 | if (pbi->dcb.xd.seg_mask == NULL) |
| 3817 | CHECK_MEM_ERROR(cm, pbi->dcb.xd.seg_mask, |
| 3818 | (uint8_t *)aom_memalign( |
| 3819 | 16, 2 * MAX_SB_SQUARE * sizeof(*pbi->dcb.xd.seg_mask))); |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3820 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3821 | for (int row = 0; row < tile_rows; row++) { |
| 3822 | for (int col = 0; col < tile_cols; col++) { |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3823 | TileDataDec *tile_data = pbi->tile_data + row * tiles->cols + col; |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3824 | av1_tile_init(&tile_data->tile_info, cm, row, col); |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 3825 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 3826 | max_sb_rows = AOMMAX(max_sb_rows, |
Wan-Teh Chang | 5350a5e | 2022-01-29 11:50:17 -0800 | [diff] [blame] | 3827 | av1_get_sb_rows_in_tile(cm, &tile_data->tile_info)); |
| 3828 | num_workers += get_max_row_mt_workers_per_tile(cm, &tile_data->tile_info); |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3829 | } |
| 3830 | } |
Cherma Rajan A | 6166169 | 2019-01-22 19:35:27 +0530 | [diff] [blame] | 3831 | num_workers = AOMMIN(num_workers, max_threads); |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3832 | |
Deepa K G | cebe078 | 2018-07-05 11:27:40 +0530 | [diff] [blame] | 3833 | if (pbi->allocated_row_mt_sync_rows != max_sb_rows) { |
| 3834 | for (int i = 0; i < n_tiles; ++i) { |
| 3835 | TileDataDec *const tile_data = pbi->tile_data + i; |
| 3836 | av1_dec_row_mt_dealloc(&tile_data->dec_row_mt_sync); |
| 3837 | dec_row_mt_alloc(&tile_data->dec_row_mt_sync, cm, max_sb_rows); |
| 3838 | } |
| 3839 | pbi->allocated_row_mt_sync_rows = max_sb_rows; |
| 3840 | } |
| 3841 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3842 | tile_mt_queue(pbi, tile_cols, tile_rows, tile_rows_start, tile_rows_end, |
| 3843 | tile_cols_start, tile_cols_end, start_tile, end_tile); |
| 3844 | |
| 3845 | dec_alloc_cb_buf(pbi); |
| 3846 | |
Deepa K G | 36ff5b1 | 2018-07-06 18:22:50 +0530 | [diff] [blame] | 3847 | row_mt_frame_init(pbi, tile_rows_start, tile_rows_end, tile_cols_start, |
| 3848 | tile_cols_end, start_tile, end_tile, max_sb_rows); |
| 3849 | |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 3850 | reset_dec_workers(pbi, row_mt_worker_hook, num_workers); |
Deepa K G | bf4f07a | 2018-06-28 15:16:19 +0530 | [diff] [blame] | 3851 | launch_dec_workers(pbi, data_end, num_workers); |
| 3852 | sync_dec_workers(pbi, num_workers); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3853 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 3854 | if (pbi->dcb.corrupted) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3855 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Yunqing Wang | 789d528 | 2018-05-04 17:18:02 -0700 | [diff] [blame] | 3856 | "Failed to decode tile data"); |
| 3857 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 3858 | if (tiles->large_scale) { |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3859 | if (n_tiles == 1) { |
| 3860 | // Find the end of the single tile buffer |
| 3861 | return aom_reader_find_end(&pbi->tile_data->bit_reader); |
| 3862 | } |
| 3863 | // Return the end of the last tile buffer |
Wan-Teh Chang | 5bab3e4 | 2018-05-29 11:35:04 -0700 | [diff] [blame] | 3864 | return raw_data_end; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3865 | } |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 3866 | TileDataDec *const tile_data = pbi->tile_data + end_tile; |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 3867 | |
| 3868 | return aom_reader_find_end(&tile_data->bit_reader); |
| 3869 | } |
| 3870 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3871 | static inline void error_handler(void *data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3872 | AV1_COMMON *const cm = (AV1_COMMON *)data; |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3873 | aom_internal_error(cm->error, AOM_CODEC_CORRUPT_FRAME, "Truncated packet"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
Wan-Teh Chang | a19fdce | 2018-05-22 14:08:16 -0700 | [diff] [blame] | 3876 | // Reads the high_bitdepth and twelve_bit fields in color_config() and sets |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3877 | // seq_params->bit_depth based on the values of those fields and |
| 3878 | // seq_params->profile. Reports errors by calling rb->error_handler() or |
| 3879 | // aom_internal_error(). |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 3880 | static inline void read_bitdepth(struct aom_read_bit_buffer *rb, |
| 3881 | SequenceHeader *seq_params, |
| 3882 | struct aom_internal_error_info *error_info) { |
Debargha Mukherjee | 9dd7779 | 2018-03-30 16:31:36 -0700 | [diff] [blame] | 3883 | const int high_bitdepth = aom_rb_read_bit(rb); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3884 | if (seq_params->profile == PROFILE_2 && high_bitdepth) { |
Debargha Mukherjee | 9dd7779 | 2018-03-30 16:31:36 -0700 | [diff] [blame] | 3885 | const int twelve_bit = aom_rb_read_bit(rb); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3886 | seq_params->bit_depth = twelve_bit ? AOM_BITS_12 : AOM_BITS_10; |
| 3887 | } else if (seq_params->profile <= PROFILE_2) { |
| 3888 | seq_params->bit_depth = high_bitdepth ? AOM_BITS_10 : AOM_BITS_8; |
Debargha Mukherjee | 9dd7779 | 2018-03-30 16:31:36 -0700 | [diff] [blame] | 3889 | } else { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3890 | aom_internal_error(error_info, AOM_CODEC_UNSUP_BITSTREAM, |
Debargha Mukherjee | 39c0f63 | 2018-04-17 13:02:56 -0700 | [diff] [blame] | 3891 | "Unsupported profile/bit-depth combination"); |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 3892 | } |
Wan-Teh Chang | 0f03698 | 2019-09-05 10:00:41 -0700 | [diff] [blame] | 3893 | #if !CONFIG_AV1_HIGHBITDEPTH |
| 3894 | if (seq_params->bit_depth > AOM_BITS_8) { |
| 3895 | aom_internal_error(error_info, AOM_CODEC_UNSUP_BITSTREAM, |
| 3896 | "Bit-depth %d not supported", seq_params->bit_depth); |
| 3897 | } |
| 3898 | #endif |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 3899 | } |
| 3900 | |
James Zern | 0d1a79c | 2024-03-29 16:34:20 -0700 | [diff] [blame] | 3901 | static void read_film_grain_params(AV1_COMMON *cm, |
| 3902 | struct aom_read_bit_buffer *rb) { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3903 | aom_film_grain_t *pars = &cm->film_grain_params; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 3904 | const SequenceHeader *const seq_params = cm->seq_params; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3905 | |
| 3906 | pars->apply_grain = aom_rb_read_bit(rb); |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3907 | if (!pars->apply_grain) { |
| 3908 | memset(pars, 0, sizeof(*pars)); |
| 3909 | return; |
| 3910 | } |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3911 | |
| 3912 | pars->random_seed = aom_rb_read_literal(rb, 16); |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 3913 | if (cm->current_frame.frame_type == INTER_FRAME) |
Andrey Norkin | 879488f | 2018-02-28 15:30:26 -0800 | [diff] [blame] | 3914 | pars->update_parameters = aom_rb_read_bit(rb); |
| 3915 | else |
| 3916 | pars->update_parameters = 1; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3917 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3918 | pars->bit_depth = seq_params->bit_depth; |
David Barker | a70532c | 2018-07-03 17:29:28 +0100 | [diff] [blame] | 3919 | |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 3920 | if (!pars->update_parameters) { |
| 3921 | // inherit parameters from a previous reference frame |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 3922 | int film_grain_params_ref_idx = aom_rb_read_literal(rb, 3); |
Wan-Teh Chang | 0c164bf | 2019-03-19 16:48:03 -0700 | [diff] [blame] | 3923 | // Section 6.8.20: It is a requirement of bitstream conformance that |
| 3924 | // film_grain_params_ref_idx is equal to ref_frame_idx[ j ] for some value |
| 3925 | // of j in the range 0 to REFS_PER_FRAME - 1. |
| 3926 | int found = 0; |
| 3927 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 3928 | if (film_grain_params_ref_idx == cm->remapped_ref_idx[i]) { |
| 3929 | found = 1; |
| 3930 | break; |
| 3931 | } |
| 3932 | } |
| 3933 | if (!found) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3934 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Wan-Teh Chang | 0c164bf | 2019-03-19 16:48:03 -0700 | [diff] [blame] | 3935 | "Invalid film grain reference idx %d. ref_frame_idx = " |
| 3936 | "{%d, %d, %d, %d, %d, %d, %d}", |
| 3937 | film_grain_params_ref_idx, cm->remapped_ref_idx[0], |
| 3938 | cm->remapped_ref_idx[1], cm->remapped_ref_idx[2], |
| 3939 | cm->remapped_ref_idx[3], cm->remapped_ref_idx[4], |
| 3940 | cm->remapped_ref_idx[5], cm->remapped_ref_idx[6]); |
| 3941 | } |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3942 | RefCntBuffer *const buf = cm->ref_frame_map[film_grain_params_ref_idx]; |
| 3943 | if (buf == NULL) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3944 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Debargha Mukherjee | 9844c8d | 2018-05-02 11:15:54 -0700 | [diff] [blame] | 3945 | "Invalid Film grain reference idx"); |
| 3946 | } |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3947 | if (!buf->film_grain_params_present) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3948 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 3949 | "Film grain reference parameters not available"); |
| 3950 | } |
| 3951 | uint16_t random_seed = pars->random_seed; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 3952 | *pars = buf->film_grain_params; // inherit paramaters |
| 3953 | pars->random_seed = random_seed; // with new random seed |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 3954 | return; |
| 3955 | } |
Dominic Symes | d492901 | 2018-01-31 17:32:01 +0100 | [diff] [blame] | 3956 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3957 | // Scaling functions parameters |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3958 | pars->num_y_points = aom_rb_read_literal(rb, 4); // max 14 |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3959 | if (pars->num_y_points > 14) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3960 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3961 | "Number of points for film grain luma scaling function " |
| 3962 | "exceeds the maximum value."); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3963 | for (int i = 0; i < pars->num_y_points; i++) { |
| 3964 | pars->scaling_points_y[i][0] = aom_rb_read_literal(rb, 8); |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3965 | if (i && pars->scaling_points_y[i - 1][0] >= pars->scaling_points_y[i][0]) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3966 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
David Barker | fa6dfe5 | 2018-04-17 12:53:29 +0100 | [diff] [blame] | 3967 | "First coordinate of the scaling function points " |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3968 | "shall be increasing."); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3969 | pars->scaling_points_y[i][1] = aom_rb_read_literal(rb, 8); |
| 3970 | } |
| 3971 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3972 | if (!seq_params->monochrome) |
Andrey Norkin | 20be545 | 2018-02-20 17:46:13 -0800 | [diff] [blame] | 3973 | pars->chroma_scaling_from_luma = aom_rb_read_bit(rb); |
Jonathan Matthews | 080299a | 2018-07-28 15:54:33 +0100 | [diff] [blame] | 3974 | else |
| 3975 | pars->chroma_scaling_from_luma = 0; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3976 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 3977 | if (seq_params->monochrome || pars->chroma_scaling_from_luma || |
| 3978 | ((seq_params->subsampling_x == 1) && (seq_params->subsampling_y == 1) && |
Andrey Norkin | 626a1b2 | 2018-03-23 21:47:17 -0700 | [diff] [blame] | 3979 | (pars->num_y_points == 0))) { |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3980 | pars->num_cb_points = 0; |
| 3981 | pars->num_cr_points = 0; |
| 3982 | } else { |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3983 | pars->num_cb_points = aom_rb_read_literal(rb, 4); // max 10 |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3984 | if (pars->num_cb_points > 10) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3985 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3986 | "Number of points for film grain cb scaling function " |
| 3987 | "exceeds the maximum value."); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3988 | for (int i = 0; i < pars->num_cb_points; i++) { |
| 3989 | pars->scaling_points_cb[i][0] = aom_rb_read_literal(rb, 8); |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3990 | if (i && |
| 3991 | pars->scaling_points_cb[i - 1][0] >= pars->scaling_points_cb[i][0]) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 3992 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3993 | "First coordinate of the scaling function points " |
| 3994 | "shall be increasing."); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 3995 | pars->scaling_points_cb[i][1] = aom_rb_read_literal(rb, 8); |
| 3996 | } |
| 3997 | |
| 3998 | pars->num_cr_points = aom_rb_read_literal(rb, 4); // max 10 |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 3999 | if (pars->num_cr_points > 10) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4000 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 4001 | "Number of points for film grain cr scaling function " |
| 4002 | "exceeds the maximum value."); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 4003 | for (int i = 0; i < pars->num_cr_points; i++) { |
| 4004 | pars->scaling_points_cr[i][0] = aom_rb_read_literal(rb, 8); |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 4005 | if (i && |
| 4006 | pars->scaling_points_cr[i - 1][0] >= pars->scaling_points_cr[i][0]) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4007 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Andrey Norkin | 0c294fa | 2018-02-16 18:32:12 -0800 | [diff] [blame] | 4008 | "First coordinate of the scaling function points " |
| 4009 | "shall be increasing."); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 4010 | pars->scaling_points_cr[i][1] = aom_rb_read_literal(rb, 8); |
| 4011 | } |
Andrey Norkin | 626a1b2 | 2018-03-23 21:47:17 -0700 | [diff] [blame] | 4012 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4013 | if ((seq_params->subsampling_x == 1) && (seq_params->subsampling_y == 1) && |
Andrey Norkin | 626a1b2 | 2018-03-23 21:47:17 -0700 | [diff] [blame] | 4014 | (((pars->num_cb_points == 0) && (pars->num_cr_points != 0)) || |
| 4015 | ((pars->num_cb_points != 0) && (pars->num_cr_points == 0)))) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4016 | aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Andrey Norkin | 626a1b2 | 2018-03-23 21:47:17 -0700 | [diff] [blame] | 4017 | "In YCbCr 4:2:0, film grain shall be applied " |
| 4018 | "to both chroma components or neither."); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | pars->scaling_shift = aom_rb_read_literal(rb, 2) + 8; // 8 + value |
| 4022 | |
| 4023 | // AR coefficients |
| 4024 | // Only sent if the corresponsing scaling function has |
| 4025 | // more than 0 points |
| 4026 | |
| 4027 | pars->ar_coeff_lag = aom_rb_read_literal(rb, 2); |
| 4028 | |
| 4029 | int num_pos_luma = 2 * pars->ar_coeff_lag * (pars->ar_coeff_lag + 1); |
Andrey Norkin | 20be545 | 2018-02-20 17:46:13 -0800 | [diff] [blame] | 4030 | int num_pos_chroma = num_pos_luma; |
| 4031 | if (pars->num_y_points > 0) ++num_pos_chroma; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 4032 | |
| 4033 | if (pars->num_y_points) |
| 4034 | for (int i = 0; i < num_pos_luma; i++) |
| 4035 | pars->ar_coeffs_y[i] = aom_rb_read_literal(rb, 8) - 128; |
| 4036 | |
| 4037 | if (pars->num_cb_points || pars->chroma_scaling_from_luma) |
| 4038 | for (int i = 0; i < num_pos_chroma; i++) |
| 4039 | pars->ar_coeffs_cb[i] = aom_rb_read_literal(rb, 8) - 128; |
| 4040 | |
| 4041 | if (pars->num_cr_points || pars->chroma_scaling_from_luma) |
| 4042 | for (int i = 0; i < num_pos_chroma; i++) |
| 4043 | pars->ar_coeffs_cr[i] = aom_rb_read_literal(rb, 8) - 128; |
| 4044 | |
| 4045 | pars->ar_coeff_shift = aom_rb_read_literal(rb, 2) + 6; // 6 + value |
| 4046 | |
Andrey Norkin | a840cde | 2018-02-16 15:39:50 -0800 | [diff] [blame] | 4047 | pars->grain_scale_shift = aom_rb_read_literal(rb, 2); |
| 4048 | |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 4049 | if (pars->num_cb_points) { |
| 4050 | pars->cb_mult = aom_rb_read_literal(rb, 8); |
| 4051 | pars->cb_luma_mult = aom_rb_read_literal(rb, 8); |
| 4052 | pars->cb_offset = aom_rb_read_literal(rb, 9); |
| 4053 | } |
| 4054 | |
| 4055 | if (pars->num_cr_points) { |
| 4056 | pars->cr_mult = aom_rb_read_literal(rb, 8); |
| 4057 | pars->cr_luma_mult = aom_rb_read_literal(rb, 8); |
| 4058 | pars->cr_offset = aom_rb_read_literal(rb, 9); |
| 4059 | } |
| 4060 | |
| 4061 | pars->overlap_flag = aom_rb_read_bit(rb); |
| 4062 | |
| 4063 | pars->clip_to_restricted_range = aom_rb_read_bit(rb); |
| 4064 | } |
| 4065 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 4066 | static inline void read_film_grain(AV1_COMMON *cm, |
| 4067 | struct aom_read_bit_buffer *rb) { |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 4068 | if (cm->seq_params->film_grain_params_present && |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 4069 | (cm->show_frame || cm->showable_frame)) { |
James Zern | 0d1a79c | 2024-03-29 16:34:20 -0700 | [diff] [blame] | 4070 | read_film_grain_params(cm, rb); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 4071 | } else { |
| 4072 | memset(&cm->film_grain_params, 0, sizeof(cm->film_grain_params)); |
| 4073 | } |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 4074 | cm->film_grain_params.bit_depth = cm->seq_params->bit_depth; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 4075 | memcpy(&cm->cur_frame->film_grain_params, &cm->film_grain_params, |
| 4076 | sizeof(aom_film_grain_t)); |
| 4077 | } |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 4078 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4079 | void av1_read_color_config(struct aom_read_bit_buffer *rb, |
| 4080 | int allow_lowbitdepth, SequenceHeader *seq_params, |
| 4081 | struct aom_internal_error_info *error_info) { |
| 4082 | read_bitdepth(rb, seq_params, error_info); |
Sebastien Alaiwan | 9837813 | 2017-01-04 11:23:09 +0100 | [diff] [blame] | 4083 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4084 | seq_params->use_highbitdepth = |
| 4085 | seq_params->bit_depth > AOM_BITS_8 || !allow_lowbitdepth; |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 4086 | // monochrome bit (not needed for PROFILE_1) |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4087 | const int is_monochrome = |
| 4088 | seq_params->profile != PROFILE_1 ? aom_rb_read_bit(rb) : 0; |
Hui Su | d31a600 | 2018-07-09 14:44:35 -0700 | [diff] [blame] | 4089 | seq_params->monochrome = is_monochrome; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 4090 | int color_description_present_flag = aom_rb_read_bit(rb); |
| 4091 | if (color_description_present_flag) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4092 | seq_params->color_primaries = aom_rb_read_literal(rb, 8); |
| 4093 | seq_params->transfer_characteristics = aom_rb_read_literal(rb, 8); |
| 4094 | seq_params->matrix_coefficients = aom_rb_read_literal(rb, 8); |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 4095 | } else { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4096 | seq_params->color_primaries = AOM_CICP_CP_UNSPECIFIED; |
| 4097 | seq_params->transfer_characteristics = AOM_CICP_TC_UNSPECIFIED; |
| 4098 | seq_params->matrix_coefficients = AOM_CICP_MC_UNSPECIFIED; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 4099 | } |
Debargha Mukherjee | e526769 | 2018-01-16 09:41:15 -0800 | [diff] [blame] | 4100 | if (is_monochrome) { |
Debargha Mukherjee | 085095d | 2018-03-30 12:39:56 -0700 | [diff] [blame] | 4101 | // [16,235] (including xvycc) vs [0,255] range |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4102 | seq_params->color_range = aom_rb_read_bit(rb); |
| 4103 | seq_params->subsampling_y = seq_params->subsampling_x = 1; |
| 4104 | seq_params->chroma_sample_position = AOM_CSP_UNKNOWN; |
| 4105 | seq_params->separate_uv_delta_q = 0; |
Debargha Mukherjee | e526769 | 2018-01-16 09:41:15 -0800 | [diff] [blame] | 4106 | return; |
| 4107 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4108 | if (seq_params->color_primaries == AOM_CICP_CP_BT_709 && |
| 4109 | seq_params->transfer_characteristics == AOM_CICP_TC_SRGB && |
| 4110 | seq_params->matrix_coefficients == AOM_CICP_MC_IDENTITY) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4111 | seq_params->subsampling_y = seq_params->subsampling_x = 0; |
| 4112 | seq_params->color_range = 1; // assume full color-range |
| 4113 | if (!(seq_params->profile == PROFILE_1 || |
| 4114 | (seq_params->profile == PROFILE_2 && |
| 4115 | seq_params->bit_depth == AOM_BITS_12))) { |
Debargha Mukherjee | 6eacb99 | 2018-03-30 13:07:27 -0700 | [diff] [blame] | 4116 | aom_internal_error( |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4117 | error_info, AOM_CODEC_UNSUP_BITSTREAM, |
Debargha Mukherjee | 6eacb99 | 2018-03-30 13:07:27 -0700 | [diff] [blame] | 4118 | "sRGB colorspace not compatible with specified profile"); |
Imdad Sardharwalla | 317002f | 2017-12-05 16:24:56 +0000 | [diff] [blame] | 4119 | } |
Imdad Sardharwalla | 317002f | 2017-12-05 16:24:56 +0000 | [diff] [blame] | 4120 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4121 | // [16,235] (including xvycc) vs [0,255] range |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4122 | seq_params->color_range = aom_rb_read_bit(rb); |
| 4123 | if (seq_params->profile == PROFILE_0) { |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 4124 | // 420 only |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4125 | seq_params->subsampling_x = seq_params->subsampling_y = 1; |
| 4126 | } else if (seq_params->profile == PROFILE_1) { |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 4127 | // 444 only |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4128 | seq_params->subsampling_x = seq_params->subsampling_y = 0; |
Wan-Teh Chang | a19fdce | 2018-05-22 14:08:16 -0700 | [diff] [blame] | 4129 | } else { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4130 | assert(seq_params->profile == PROFILE_2); |
| 4131 | if (seq_params->bit_depth == AOM_BITS_12) { |
| 4132 | seq_params->subsampling_x = aom_rb_read_bit(rb); |
| 4133 | if (seq_params->subsampling_x) |
| 4134 | seq_params->subsampling_y = aom_rb_read_bit(rb); // 422 or 420 |
Wan-Teh Chang | a19fdce | 2018-05-22 14:08:16 -0700 | [diff] [blame] | 4135 | else |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4136 | seq_params->subsampling_y = 0; // 444 |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 4137 | } else { |
| 4138 | // 422 |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4139 | seq_params->subsampling_x = 1; |
| 4140 | seq_params->subsampling_y = 0; |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 4141 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4142 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4143 | if (seq_params->matrix_coefficients == AOM_CICP_MC_IDENTITY && |
| 4144 | (seq_params->subsampling_x || seq_params->subsampling_y)) { |
Debargha Mukherjee | f61c0d1 | 2018-03-30 19:29:59 -0700 | [diff] [blame] | 4145 | aom_internal_error( |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4146 | error_info, AOM_CODEC_UNSUP_BITSTREAM, |
Debargha Mukherjee | f61c0d1 | 2018-03-30 19:29:59 -0700 | [diff] [blame] | 4147 | "Identity CICP Matrix incompatible with non 4:4:4 color sampling"); |
| 4148 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4149 | if (seq_params->subsampling_x && seq_params->subsampling_y) { |
| 4150 | seq_params->chroma_sample_position = aom_rb_read_literal(rb, 2); |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 4151 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4152 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4153 | seq_params->separate_uv_delta_q = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4154 | } |
| 4155 | |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4156 | void av1_read_timing_info_header(aom_timing_info_t *timing_info, |
| 4157 | struct aom_internal_error_info *error, |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 4158 | struct aom_read_bit_buffer *rb) { |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4159 | timing_info->num_units_in_display_tick = |
| 4160 | aom_rb_read_unsigned_literal(rb, |
| 4161 | 32); // Number of units in a display tick |
| 4162 | timing_info->time_scale = aom_rb_read_unsigned_literal(rb, 32); // Time scale |
| 4163 | if (timing_info->num_units_in_display_tick == 0 || |
| 4164 | timing_info->time_scale == 0) { |
Wan-Teh Chang | f250f48 | 2018-05-23 12:54:36 -0700 | [diff] [blame] | 4165 | aom_internal_error( |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4166 | error, AOM_CODEC_UNSUP_BITSTREAM, |
Wan-Teh Chang | f250f48 | 2018-05-23 12:54:36 -0700 | [diff] [blame] | 4167 | "num_units_in_display_tick and time_scale must be greater than 0."); |
| 4168 | } |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4169 | timing_info->equal_picture_interval = |
Wan-Teh Chang | f250f48 | 2018-05-23 12:54:36 -0700 | [diff] [blame] | 4170 | aom_rb_read_bit(rb); // Equal picture interval bit |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4171 | if (timing_info->equal_picture_interval) { |
Wan-Teh Chang | 2d7e831 | 2019-03-19 09:32:40 -0700 | [diff] [blame] | 4172 | const uint32_t num_ticks_per_picture_minus_1 = aom_rb_read_uvlc(rb); |
| 4173 | if (num_ticks_per_picture_minus_1 == UINT32_MAX) { |
Wan-Teh Chang | a19fdce | 2018-05-22 14:08:16 -0700 | [diff] [blame] | 4174 | aom_internal_error( |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4175 | error, AOM_CODEC_UNSUP_BITSTREAM, |
Wan-Teh Chang | 854b276 | 2020-12-08 09:59:52 -0800 | [diff] [blame] | 4176 | "num_ticks_per_picture_minus_1 cannot be (1 << 32) - 1."); |
Wan-Teh Chang | a19fdce | 2018-05-22 14:08:16 -0700 | [diff] [blame] | 4177 | } |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4178 | timing_info->num_ticks_per_picture = num_ticks_per_picture_minus_1 + 1; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 4179 | } |
| 4180 | } |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 4181 | |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4182 | void av1_read_decoder_model_info(aom_dec_model_info_t *decoder_model_info, |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4183 | struct aom_read_bit_buffer *rb) { |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4184 | decoder_model_info->encoder_decoder_buffer_delay_length = |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4185 | aom_rb_read_literal(rb, 5) + 1; |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4186 | decoder_model_info->num_units_in_decoding_tick = |
| 4187 | aom_rb_read_unsigned_literal(rb, |
| 4188 | 32); // Number of units in a decoding tick |
| 4189 | decoder_model_info->buffer_removal_time_length = |
| 4190 | aom_rb_read_literal(rb, 5) + 1; |
| 4191 | decoder_model_info->frame_presentation_time_length = |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4192 | aom_rb_read_literal(rb, 5) + 1; |
| 4193 | } |
| 4194 | |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4195 | void av1_read_op_parameters_info(aom_dec_model_op_parameters_t *op_params, |
| 4196 | int buffer_delay_length, |
| 4197 | struct aom_read_bit_buffer *rb) { |
| 4198 | op_params->decoder_buffer_delay = |
| 4199 | aom_rb_read_unsigned_literal(rb, buffer_delay_length); |
| 4200 | op_params->encoder_buffer_delay = |
| 4201 | aom_rb_read_unsigned_literal(rb, buffer_delay_length); |
| 4202 | op_params->low_delay_mode_flag = aom_rb_read_bit(rb); |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4203 | } |
| 4204 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 4205 | static inline void read_temporal_point_info(AV1_COMMON *const cm, |
| 4206 | struct aom_read_bit_buffer *rb) { |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 4207 | cm->frame_presentation_time = aom_rb_read_unsigned_literal( |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 4208 | rb, cm->seq_params->decoder_model_info.frame_presentation_time_length); |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4209 | } |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4210 | |
Hui Su | d31a600 | 2018-07-09 14:44:35 -0700 | [diff] [blame] | 4211 | void av1_read_sequence_header(AV1_COMMON *cm, struct aom_read_bit_buffer *rb, |
| 4212 | SequenceHeader *seq_params) { |
| 4213 | const int num_bits_width = aom_rb_read_literal(rb, 4) + 1; |
| 4214 | const int num_bits_height = aom_rb_read_literal(rb, 4) + 1; |
| 4215 | const int max_frame_width = aom_rb_read_literal(rb, num_bits_width) + 1; |
| 4216 | const int max_frame_height = aom_rb_read_literal(rb, num_bits_height) + 1; |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 4217 | |
| 4218 | seq_params->num_bits_width = num_bits_width; |
| 4219 | seq_params->num_bits_height = num_bits_height; |
| 4220 | seq_params->max_frame_width = max_frame_width; |
| 4221 | seq_params->max_frame_height = max_frame_height; |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 4222 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4223 | if (seq_params->reduced_still_picture_hdr) { |
| 4224 | seq_params->frame_id_numbers_present_flag = 0; |
| 4225 | } else { |
| 4226 | seq_params->frame_id_numbers_present_flag = aom_rb_read_bit(rb); |
| 4227 | } |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 4228 | if (seq_params->frame_id_numbers_present_flag) { |
Frederic Barbier | 4d5d90e | 2017-10-13 09:22:33 +0200 | [diff] [blame] | 4229 | // We must always have delta_frame_id_length < frame_id_length, |
| 4230 | // in order for a frame to be referenced with a unique delta. |
| 4231 | // Avoid wasting bits by using a coding that enforces this restriction. |
Frederic Barbier | e83fcfe | 2017-10-13 10:37:50 +0200 | [diff] [blame] | 4232 | seq_params->delta_frame_id_length = aom_rb_read_literal(rb, 4) + 2; |
Frederic Barbier | 4d5d90e | 2017-10-13 09:22:33 +0200 | [diff] [blame] | 4233 | seq_params->frame_id_length = |
| 4234 | aom_rb_read_literal(rb, 3) + seq_params->delta_frame_id_length + 1; |
Thomas Davies | 0cbcf79 | 2018-03-15 14:10:02 +0000 | [diff] [blame] | 4235 | if (seq_params->frame_id_length > 16) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4236 | aom_internal_error(cm->error, AOM_CODEC_CORRUPT_FRAME, |
Thomas Davies | 0cbcf79 | 2018-03-15 14:10:02 +0000 | [diff] [blame] | 4237 | "Invalid frame_id_length"); |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 4238 | } |
Imdad Sardharwalla | 4ec84ab | 2018-02-06 12:20:18 +0000 | [diff] [blame] | 4239 | |
| 4240 | setup_sb_size(seq_params, rb); |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 4241 | |
Debargha Mukherjee | 365eae8 | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 4242 | seq_params->enable_filter_intra = aom_rb_read_bit(rb); |
| 4243 | seq_params->enable_intra_edge_filter = aom_rb_read_bit(rb); |
| 4244 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4245 | if (seq_params->reduced_still_picture_hdr) { |
| 4246 | seq_params->enable_interintra_compound = 0; |
| 4247 | seq_params->enable_masked_compound = 0; |
| 4248 | seq_params->enable_warped_motion = 0; |
| 4249 | seq_params->enable_dual_filter = 0; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4250 | seq_params->order_hint_info.enable_order_hint = 0; |
Debargha Mukherjee | 7ac3eb1 | 2018-12-12 10:26:50 -0800 | [diff] [blame] | 4251 | seq_params->order_hint_info.enable_dist_wtd_comp = 0; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4252 | seq_params->order_hint_info.enable_ref_frame_mvs = 0; |
Wan-Teh Chang | a19fdce | 2018-05-22 14:08:16 -0700 | [diff] [blame] | 4253 | seq_params->force_screen_content_tools = 2; // SELECT_SCREEN_CONTENT_TOOLS |
| 4254 | seq_params->force_integer_mv = 2; // SELECT_INTEGER_MV |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4255 | seq_params->order_hint_info.order_hint_bits_minus_1 = -1; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4256 | } else { |
| 4257 | seq_params->enable_interintra_compound = aom_rb_read_bit(rb); |
| 4258 | seq_params->enable_masked_compound = aom_rb_read_bit(rb); |
| 4259 | seq_params->enable_warped_motion = aom_rb_read_bit(rb); |
| 4260 | seq_params->enable_dual_filter = aom_rb_read_bit(rb); |
| 4261 | |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4262 | seq_params->order_hint_info.enable_order_hint = aom_rb_read_bit(rb); |
Debargha Mukherjee | 7ac3eb1 | 2018-12-12 10:26:50 -0800 | [diff] [blame] | 4263 | seq_params->order_hint_info.enable_dist_wtd_comp = |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4264 | seq_params->order_hint_info.enable_order_hint ? aom_rb_read_bit(rb) : 0; |
| 4265 | seq_params->order_hint_info.enable_ref_frame_mvs = |
| 4266 | seq_params->order_hint_info.enable_order_hint ? aom_rb_read_bit(rb) : 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4267 | |
| 4268 | if (aom_rb_read_bit(rb)) { |
Wan-Teh Chang | a19fdce | 2018-05-22 14:08:16 -0700 | [diff] [blame] | 4269 | seq_params->force_screen_content_tools = |
| 4270 | 2; // SELECT_SCREEN_CONTENT_TOOLS |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4271 | } else { |
| 4272 | seq_params->force_screen_content_tools = aom_rb_read_bit(rb); |
| 4273 | } |
| 4274 | |
| 4275 | if (seq_params->force_screen_content_tools > 0) { |
| 4276 | if (aom_rb_read_bit(rb)) { |
Wan-Teh Chang | a19fdce | 2018-05-22 14:08:16 -0700 | [diff] [blame] | 4277 | seq_params->force_integer_mv = 2; // SELECT_INTEGER_MV |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4278 | } else { |
| 4279 | seq_params->force_integer_mv = aom_rb_read_bit(rb); |
| 4280 | } |
| 4281 | } else { |
Wan-Teh Chang | a19fdce | 2018-05-22 14:08:16 -0700 | [diff] [blame] | 4282 | seq_params->force_integer_mv = 2; // SELECT_INTEGER_MV |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4283 | } |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4284 | seq_params->order_hint_info.order_hint_bits_minus_1 = |
| 4285 | seq_params->order_hint_info.enable_order_hint |
| 4286 | ? aom_rb_read_literal(rb, 3) |
| 4287 | : -1; |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 4288 | } |
Imdad Sardharwalla | e68aa8a | 2018-03-07 18:52:54 +0000 | [diff] [blame] | 4289 | |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 4290 | seq_params->enable_superres = aom_rb_read_bit(rb); |
Debargha Mukherjee | 98a311c | 2018-03-25 16:33:11 -0700 | [diff] [blame] | 4291 | seq_params->enable_cdef = aom_rb_read_bit(rb); |
| 4292 | seq_params->enable_restoration = aom_rb_read_bit(rb); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4293 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4294 | |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4295 | static int read_global_motion_params(WarpedMotionParams *params, |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 4296 | const WarpedMotionParams *ref_params, |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4297 | struct aom_read_bit_buffer *rb, |
| 4298 | int allow_hp) { |
| 4299 | TransformationType type = aom_rb_read_bit(rb); |
| 4300 | if (type != IDENTITY) { |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4301 | if (aom_rb_read_bit(rb)) |
| 4302 | type = ROTZOOM; |
| 4303 | else |
| 4304 | type = aom_rb_read_bit(rb) ? TRANSLATION : AFFINE; |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 4307 | *params = default_warp_params; |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4308 | params->wmtype = type; |
Sebastien Alaiwan | 238a6d6 | 2017-11-01 11:29:46 +0100 | [diff] [blame] | 4309 | |
| 4310 | if (type >= ROTZOOM) { |
| 4311 | params->wmmat[2] = aom_rb_read_signed_primitive_refsubexpfin( |
| 4312 | rb, GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 4313 | (ref_params->wmmat[2] >> GM_ALPHA_PREC_DIFF) - |
| 4314 | (1 << GM_ALPHA_PREC_BITS)) * |
| 4315 | GM_ALPHA_DECODE_FACTOR + |
| 4316 | (1 << WARPEDMODEL_PREC_BITS); |
| 4317 | params->wmmat[3] = aom_rb_read_signed_primitive_refsubexpfin( |
| 4318 | rb, GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 4319 | (ref_params->wmmat[3] >> GM_ALPHA_PREC_DIFF)) * |
| 4320 | GM_ALPHA_DECODE_FACTOR; |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4321 | } |
Sebastien Alaiwan | 238a6d6 | 2017-11-01 11:29:46 +0100 | [diff] [blame] | 4322 | |
| 4323 | if (type >= AFFINE) { |
| 4324 | params->wmmat[4] = aom_rb_read_signed_primitive_refsubexpfin( |
| 4325 | rb, GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 4326 | (ref_params->wmmat[4] >> GM_ALPHA_PREC_DIFF)) * |
| 4327 | GM_ALPHA_DECODE_FACTOR; |
| 4328 | params->wmmat[5] = aom_rb_read_signed_primitive_refsubexpfin( |
| 4329 | rb, GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 4330 | (ref_params->wmmat[5] >> GM_ALPHA_PREC_DIFF) - |
| 4331 | (1 << GM_ALPHA_PREC_BITS)) * |
| 4332 | GM_ALPHA_DECODE_FACTOR + |
| 4333 | (1 << WARPEDMODEL_PREC_BITS); |
| 4334 | } else { |
| 4335 | params->wmmat[4] = -params->wmmat[3]; |
| 4336 | params->wmmat[5] = params->wmmat[2]; |
| 4337 | } |
| 4338 | |
| 4339 | if (type >= TRANSLATION) { |
| 4340 | const int trans_bits = (type == TRANSLATION) |
| 4341 | ? GM_ABS_TRANS_ONLY_BITS - !allow_hp |
| 4342 | : GM_ABS_TRANS_BITS; |
| 4343 | const int trans_dec_factor = |
| 4344 | (type == TRANSLATION) ? GM_TRANS_ONLY_DECODE_FACTOR * (1 << !allow_hp) |
| 4345 | : GM_TRANS_DECODE_FACTOR; |
| 4346 | const int trans_prec_diff = (type == TRANSLATION) |
| 4347 | ? GM_TRANS_ONLY_PREC_DIFF + !allow_hp |
| 4348 | : GM_TRANS_PREC_DIFF; |
| 4349 | params->wmmat[0] = aom_rb_read_signed_primitive_refsubexpfin( |
| 4350 | rb, (1 << trans_bits) + 1, SUBEXPFIN_K, |
| 4351 | (ref_params->wmmat[0] >> trans_prec_diff)) * |
| 4352 | trans_dec_factor; |
| 4353 | params->wmmat[1] = aom_rb_read_signed_primitive_refsubexpfin( |
| 4354 | rb, (1 << trans_bits) + 1, SUBEXPFIN_K, |
| 4355 | (ref_params->wmmat[1] >> trans_prec_diff)) * |
| 4356 | trans_dec_factor; |
| 4357 | } |
| 4358 | |
Rachel Barker | 0d9df42 | 2023-03-07 20:51:55 +0000 | [diff] [blame] | 4359 | int good_shear_params = av1_get_shear_params(params); |
| 4360 | if (!good_shear_params) return 0; |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4361 | |
| 4362 | return 1; |
| 4363 | } |
| 4364 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 4365 | static inline void read_global_motion(AV1_COMMON *cm, |
| 4366 | struct aom_read_bit_buffer *rb) { |
Sebastien Alaiwan | bc51d0e | 2017-12-07 11:13:57 +0100 | [diff] [blame] | 4367 | for (int frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 4368 | const WarpedMotionParams *ref_params = |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 4369 | cm->prev_frame ? &cm->prev_frame->global_motion[frame] |
| 4370 | : &default_warp_params; |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4371 | int good_params = |
| 4372 | read_global_motion_params(&cm->global_motion[frame], ref_params, rb, |
| 4373 | cm->features.allow_high_precision_mv); |
Sebastien Alaiwan | 8d88b29 | 2017-11-03 17:38:30 +0100 | [diff] [blame] | 4374 | if (!good_params) { |
| 4375 | #if WARPED_MOTION_DEBUG |
| 4376 | printf("Warning: unexpected global motion shear params from aomenc\n"); |
| 4377 | #endif |
| 4378 | cm->global_motion[frame].invalid = 1; |
| 4379 | } |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4380 | |
| 4381 | // TODO(sarahparker, debargha): The logic in the commented out code below |
| 4382 | // does not work currently and causes mismatches when resize is on. Fix it |
| 4383 | // before turning the optimization back on. |
| 4384 | /* |
| 4385 | YV12_BUFFER_CONFIG *ref_buf = get_ref_frame(cm, frame); |
| 4386 | if (cm->width == ref_buf->y_crop_width && |
| 4387 | cm->height == ref_buf->y_crop_height) { |
| 4388 | read_global_motion_params(&cm->global_motion[frame], |
| 4389 | &cm->prev_frame->global_motion[frame], rb, |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4390 | cm->features.allow_high_precision_mv); |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4391 | } else { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 4392 | cm->global_motion[frame] = default_warp_params; |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4393 | } |
| 4394 | */ |
| 4395 | /* |
| 4396 | printf("Dec Ref %d [%d/%d]: %d %d %d %d\n", |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4397 | frame, cm->current_frame.frame_number, cm->show_frame, |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4398 | cm->global_motion[frame].wmmat[0], |
| 4399 | cm->global_motion[frame].wmmat[1], |
| 4400 | cm->global_motion[frame].wmmat[2], |
| 4401 | cm->global_motion[frame].wmmat[3]); |
| 4402 | */ |
| 4403 | } |
David Barker | cba7da7 | 2017-09-14 11:24:27 +0100 | [diff] [blame] | 4404 | memcpy(cm->cur_frame->global_motion, cm->global_motion, |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 4405 | REF_FRAMES * sizeof(WarpedMotionParams)); |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4406 | } |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 4407 | |
Wan-Teh Chang | 38353c8 | 2018-09-27 18:46:55 -0700 | [diff] [blame] | 4408 | // Release the references to the frame buffers in cm->ref_frame_map and reset |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4409 | // all elements of cm->ref_frame_map to NULL. |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 4410 | static inline void reset_ref_frame_map(AV1_COMMON *const cm) { |
Wan-Teh Chang | 38353c8 | 2018-09-27 18:46:55 -0700 | [diff] [blame] | 4411 | BufferPool *const pool = cm->buffer_pool; |
Wan-Teh Chang | 38353c8 | 2018-09-27 18:46:55 -0700 | [diff] [blame] | 4412 | |
| 4413 | for (int i = 0; i < REF_FRAMES; i++) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4414 | decrease_ref_count(cm->ref_frame_map[i], pool); |
| 4415 | cm->ref_frame_map[i] = NULL; |
Wan-Teh Chang | 38353c8 | 2018-09-27 18:46:55 -0700 | [diff] [blame] | 4416 | } |
Wan-Teh Chang | 38353c8 | 2018-09-27 18:46:55 -0700 | [diff] [blame] | 4417 | } |
| 4418 | |
Wan-Teh Chang | 7c4cb45 | 2018-12-03 12:08:20 -0800 | [diff] [blame] | 4419 | // If the refresh_frame_flags bitmask is set, update reference frame id values |
| 4420 | // and mark frames as valid for reference. |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 4421 | static inline void update_ref_frame_id(AV1Decoder *const pbi) { |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 4422 | AV1_COMMON *const cm = &pbi->common; |
Wan-Teh Chang | 7c4cb45 | 2018-12-03 12:08:20 -0800 | [diff] [blame] | 4423 | int refresh_frame_flags = cm->current_frame.refresh_frame_flags; |
| 4424 | for (int i = 0; i < REF_FRAMES; i++) { |
| 4425 | if ((refresh_frame_flags >> i) & 1) { |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 4426 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 4427 | pbi->valid_for_referencing[i] = 1; |
Wan-Teh Chang | 7c4cb45 | 2018-12-03 12:08:20 -0800 | [diff] [blame] | 4428 | } |
| 4429 | } |
| 4430 | } |
| 4431 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 4432 | static inline void show_existing_frame_reset(AV1Decoder *const pbi, |
| 4433 | int existing_frame_idx) { |
Wan-Teh Chang | a08349c | 2018-09-26 10:38:53 -0700 | [diff] [blame] | 4434 | AV1_COMMON *const cm = &pbi->common; |
| 4435 | |
Bruno Berthier | f03d936 | 2018-02-23 15:47:13 +0100 | [diff] [blame] | 4436 | assert(cm->show_existing_frame); |
| 4437 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4438 | cm->current_frame.frame_type = KEY_FRAME; |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 4439 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4440 | cm->current_frame.refresh_frame_flags = (1 << REF_FRAMES) - 1; |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 4441 | |
| 4442 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4443 | cm->remapped_ref_idx[i] = INVALID_IDX; |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | if (pbi->need_resync) { |
Wan-Teh Chang | 38353c8 | 2018-09-27 18:46:55 -0700 | [diff] [blame] | 4447 | reset_ref_frame_map(cm); |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 4448 | pbi->need_resync = 0; |
| 4449 | } |
| 4450 | |
Wan-Teh Chang | 7c4cb45 | 2018-12-03 12:08:20 -0800 | [diff] [blame] | 4451 | // Note that the displayed frame must be valid for referencing in order to |
| 4452 | // have been selected. |
Wan-Teh Chang | 58e4a15 | 2019-06-25 13:44:35 -0700 | [diff] [blame] | 4453 | cm->current_frame_id = cm->ref_frame_id[existing_frame_idx]; |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 4454 | update_ref_frame_id(pbi); |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 4455 | |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 4456 | cm->features.refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 4457 | } |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 4458 | |
Wan-Teh Chang | 12c64e8 | 2024-08-08 16:02:19 -0700 | [diff] [blame] | 4459 | static inline void reset_frame_buffers(AV1_COMMON *cm) { |
Yaowu Xu | 78f49b2 | 2018-08-30 12:47:20 -0700 | [diff] [blame] | 4460 | RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
| 4461 | int i; |
| 4462 | |
Yaowu Xu | 78f49b2 | 2018-08-30 12:47:20 -0700 | [diff] [blame] | 4463 | lock_buffer_pool(cm->buffer_pool); |
Wan-Teh Chang | 0c1b8c1 | 2018-10-03 09:56:24 -0700 | [diff] [blame] | 4464 | reset_ref_frame_map(cm); |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4465 | assert(cm->cur_frame->ref_count == 1); |
Apurve Kumar Pandey | 24f62e8 | 2022-12-27 11:55:45 +0530 | [diff] [blame] | 4466 | for (i = 0; i < cm->buffer_pool->num_frame_bufs; ++i) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4467 | // Reset all unreferenced frame buffers. We can also reset cm->cur_frame |
| 4468 | // because we are the sole owner of cm->cur_frame. |
| 4469 | if (frame_bufs[i].ref_count > 0 && &frame_bufs[i] != cm->cur_frame) { |
Wan-Teh Chang | 0c1b8c1 | 2018-10-03 09:56:24 -0700 | [diff] [blame] | 4470 | continue; |
Yaowu Xu | 78f49b2 | 2018-08-30 12:47:20 -0700 | [diff] [blame] | 4471 | } |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 4472 | frame_bufs[i].order_hint = 0; |
| 4473 | av1_zero(frame_bufs[i].ref_order_hints); |
Yaowu Xu | 78f49b2 | 2018-08-30 12:47:20 -0700 | [diff] [blame] | 4474 | } |
Wan-Teh Chang | c613fd4 | 2018-09-06 12:31:17 -0700 | [diff] [blame] | 4475 | av1_zero_unused_internal_frame_buffers(&cm->buffer_pool->int_frame_buffers); |
Yaowu Xu | 78f49b2 | 2018-08-30 12:47:20 -0700 | [diff] [blame] | 4476 | unlock_buffer_pool(cm->buffer_pool); |
| 4477 | } |
| 4478 | |
Wan-Teh Chang | bb6192a | 2018-07-10 11:01:04 -0700 | [diff] [blame] | 4479 | // On success, returns 0. On failure, calls aom_internal_error and does not |
| 4480 | // return. |
Yunqing Wang | e7142e1 | 2018-01-17 11:20:12 -0800 | [diff] [blame] | 4481 | static int read_uncompressed_header(AV1Decoder *pbi, |
| 4482 | struct aom_read_bit_buffer *rb) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4483 | AV1_COMMON *const cm = &pbi->common; |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 4484 | const SequenceHeader *const seq_params = cm->seq_params; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4485 | CurrentFrame *const current_frame = &cm->current_frame; |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4486 | FeatureFlags *const features = &cm->features; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 4487 | MACROBLOCKD *const xd = &pbi->dcb.xd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4488 | BufferPool *const pool = cm->buffer_pool; |
| 4489 | RefCntBuffer *const frame_bufs = pool->frame_bufs; |
Aasaipriya Chandran | d0588a7 | 2020-07-21 13:28:48 +0530 | [diff] [blame] | 4490 | aom_s_frame_info *sframe_info = &pbi->sframe_info; |
| 4491 | sframe_info->is_s_frame = 0; |
| 4492 | sframe_info->is_s_frame_at_altref = 0; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4493 | |
David Barker | 3a7b5c2 | 2018-03-21 12:06:16 +0000 | [diff] [blame] | 4494 | if (!pbi->sequence_header_ready) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4495 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Hui Su | 224cf96 | 2018-03-11 12:28:10 -0700 | [diff] [blame] | 4496 | "No sequence header"); |
| 4497 | } |
| 4498 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4499 | if (seq_params->reduced_still_picture_hdr) { |
David Barker | c9acf93 | 2018-04-17 12:54:34 +0100 | [diff] [blame] | 4500 | cm->show_existing_frame = 0; |
| 4501 | cm->show_frame = 1; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4502 | current_frame->frame_type = KEY_FRAME; |
Wan-Teh Chang | 7c92440 | 2018-09-29 11:23:39 -0700 | [diff] [blame] | 4503 | if (pbi->sequence_header_changed) { |
| 4504 | // This is the start of a new coded video sequence. |
| 4505 | pbi->sequence_header_changed = 0; |
| 4506 | pbi->decoding_first_frame = 1; |
| 4507 | reset_frame_buffers(cm); |
| 4508 | } |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4509 | features->error_resilient_mode = 1; |
David Barker | c9acf93 | 2018-04-17 12:54:34 +0100 | [diff] [blame] | 4510 | } else { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4511 | cm->show_existing_frame = aom_rb_read_bit(rb); |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4512 | pbi->reset_decoder_state = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4513 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4514 | if (cm->show_existing_frame) { |
Yaowu Xu | 45a30ac | 2018-09-04 08:47:05 -0700 | [diff] [blame] | 4515 | if (pbi->sequence_header_changed) { |
| 4516 | aom_internal_error( |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4517 | &pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | 45a30ac | 2018-09-04 08:47:05 -0700 | [diff] [blame] | 4518 | "New sequence header starts with a show_existing_frame."); |
| 4519 | } |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4520 | // Show an existing frame directly. |
| 4521 | const int existing_frame_idx = aom_rb_read_literal(rb, 3); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4522 | RefCntBuffer *const frame_to_show = cm->ref_frame_map[existing_frame_idx]; |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4523 | if (frame_to_show == NULL) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4524 | aom_internal_error(&pbi->error, AOM_CODEC_UNSUP_BITSTREAM, |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4525 | "Buffer does not contain a decoded frame"); |
| 4526 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4527 | if (seq_params->decoder_model_info_present_flag && |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4528 | seq_params->timing_info.equal_picture_interval == 0) { |
Yaowu Xu | 96c0f98 | 2019-05-17 09:10:54 -0700 | [diff] [blame] | 4529 | read_temporal_point_info(cm, rb); |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4530 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4531 | if (seq_params->frame_id_numbers_present_flag) { |
| 4532 | int frame_id_length = seq_params->frame_id_length; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4533 | int display_frame_id = aom_rb_read_literal(rb, frame_id_length); |
| 4534 | /* Compare display_frame_id with ref_frame_id and check valid for |
| 4535 | * referencing */ |
| 4536 | if (display_frame_id != cm->ref_frame_id[existing_frame_idx] || |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 4537 | pbi->valid_for_referencing[existing_frame_idx] == 0) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4538 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4539 | "Reference buffer frame ID mismatch"); |
| 4540 | } |
| 4541 | lock_buffer_pool(pool); |
Wan-Teh Chang | 88cd166 | 2019-01-14 12:38:41 -0800 | [diff] [blame] | 4542 | assert(frame_to_show->ref_count > 0); |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4543 | // cm->cur_frame should be the buffer referenced by the return value |
Wan-Teh Chang | 6f954e7 | 2019-08-30 12:01:26 -0700 | [diff] [blame] | 4544 | // of the get_free_fb() call in assign_cur_frame_new_fb() (called by |
| 4545 | // av1_receive_compressed_data()), so the ref_count should be 1. |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4546 | assert(cm->cur_frame->ref_count == 1); |
Wan-Teh Chang | 8634e61 | 2018-12-19 11:41:37 -0800 | [diff] [blame] | 4547 | // assign_frame_buffer_p() decrements ref_count directly rather than |
| 4548 | // call decrease_ref_count(). If cm->cur_frame->raw_frame_buffer has |
| 4549 | // already been allocated, it will not be released by |
| 4550 | // assign_frame_buffer_p()! |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4551 | assert(!cm->cur_frame->raw_frame_buffer.data); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4552 | assign_frame_buffer_p(&cm->cur_frame, frame_to_show); |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4553 | pbi->reset_decoder_state = frame_to_show->frame_type == KEY_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4554 | unlock_buffer_pool(pool); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4555 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4556 | cm->lf.filter_level[0] = 0; |
| 4557 | cm->lf.filter_level[1] = 0; |
| 4558 | cm->show_frame = 1; |
Bohan Li | 15b3c6d | 2021-07-27 17:27:20 -0700 | [diff] [blame] | 4559 | current_frame->order_hint = frame_to_show->order_hint; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4560 | |
Wan-Teh Chang | ab5aa98 | 2018-12-19 11:17:47 -0800 | [diff] [blame] | 4561 | // Section 6.8.2: It is a requirement of bitstream conformance that when |
| 4562 | // show_existing_frame is used to show a previous frame, that the value |
| 4563 | // of showable_frame for the previous frame was equal to 1. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4564 | if (!frame_to_show->showable_frame) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4565 | aom_internal_error(&pbi->error, AOM_CODEC_UNSUP_BITSTREAM, |
Wan-Teh Chang | ab5aa98 | 2018-12-19 11:17:47 -0800 | [diff] [blame] | 4566 | "Buffer does not contain a showable frame"); |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4567 | } |
Wan-Teh Chang | ab5aa98 | 2018-12-19 11:17:47 -0800 | [diff] [blame] | 4568 | // Section 6.8.2: It is a requirement of bitstream conformance that when |
| 4569 | // show_existing_frame is used to show a previous frame with |
| 4570 | // RefFrameType[ frame_to_show_map_idx ] equal to KEY_FRAME, that the |
| 4571 | // frame is output via the show_existing_frame mechanism at most once. |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4572 | if (pbi->reset_decoder_state) frame_to_show->showable_frame = 0; |
Debargha Mukherjee | 171f4b3 | 2018-06-21 10:06:41 -0700 | [diff] [blame] | 4573 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4574 | cm->film_grain_params = frame_to_show->film_grain_params; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4575 | |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 4576 | if (pbi->reset_decoder_state) { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4577 | show_existing_frame_reset(pbi, existing_frame_idx); |
| 4578 | } else { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4579 | current_frame->refresh_frame_flags = 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4580 | } |
| 4581 | |
| 4582 | return 0; |
| 4583 | } |
| 4584 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4585 | current_frame->frame_type = (FRAME_TYPE)aom_rb_read_literal(rb, 2); |
Yaowu Xu | 3ff57a63 | 2018-08-29 10:50:57 -0700 | [diff] [blame] | 4586 | if (pbi->sequence_header_changed) { |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4587 | if (current_frame->frame_type == KEY_FRAME) { |
Yaowu Xu | 3ff57a63 | 2018-08-29 10:50:57 -0700 | [diff] [blame] | 4588 | // This is the start of a new coded video sequence. |
| 4589 | pbi->sequence_header_changed = 0; |
Frederic Barbier | d2a1efa | 2018-09-07 14:28:08 +0200 | [diff] [blame] | 4590 | pbi->decoding_first_frame = 1; |
Wan-Teh Chang | 7c92440 | 2018-09-29 11:23:39 -0700 | [diff] [blame] | 4591 | reset_frame_buffers(cm); |
Yaowu Xu | 3ff57a63 | 2018-08-29 10:50:57 -0700 | [diff] [blame] | 4592 | } else { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4593 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | 3ff57a63 | 2018-08-29 10:50:57 -0700 | [diff] [blame] | 4594 | "Sequence header has changed without a keyframe."); |
| 4595 | } |
| 4596 | } |
| 4597 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4598 | cm->show_frame = aom_rb_read_bit(rb); |
Aasaipriya Chandran | c8d7b28 | 2020-07-02 12:33:32 +0530 | [diff] [blame] | 4599 | if (cm->show_frame == 0) pbi->is_arf_frame_present = 1; |
Aasaipriya Chandran | b2209ce | 2020-06-18 19:41:22 +0530 | [diff] [blame] | 4600 | if (cm->show_frame == 0 && cm->current_frame.frame_type == KEY_FRAME) |
| 4601 | pbi->is_fwd_kf_present = 1; |
Aasaipriya Chandran | d0588a7 | 2020-07-21 13:28:48 +0530 | [diff] [blame] | 4602 | if (cm->current_frame.frame_type == S_FRAME) { |
| 4603 | sframe_info->is_s_frame = 1; |
| 4604 | sframe_info->is_s_frame_at_altref = cm->show_frame ? 0 : 1; |
| 4605 | } |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4606 | if (seq_params->still_picture && |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4607 | (current_frame->frame_type != KEY_FRAME || !cm->show_frame)) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4608 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
David Barker | c9acf93 | 2018-04-17 12:54:34 +0100 | [diff] [blame] | 4609 | "Still pictures must be coded as shown keyframes"); |
| 4610 | } |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4611 | cm->showable_frame = current_frame->frame_type != KEY_FRAME; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4612 | if (cm->show_frame) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4613 | if (seq_params->decoder_model_info_present_flag && |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4614 | seq_params->timing_info.equal_picture_interval == 0) |
Yaowu Xu | 96c0f98 | 2019-05-17 09:10:54 -0700 | [diff] [blame] | 4615 | read_temporal_point_info(cm, rb); |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4616 | } else { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4617 | // See if this frame can be used as show_existing_frame in future |
| 4618 | cm->showable_frame = aom_rb_read_bit(rb); |
| 4619 | } |
| 4620 | cm->cur_frame->showable_frame = cm->showable_frame; |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4621 | features->error_resilient_mode = |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4622 | frame_is_sframe(cm) || |
| 4623 | (current_frame->frame_type == KEY_FRAME && cm->show_frame) |
Debargha Mukherjee | ae0b90c | 2018-04-10 18:00:41 -0700 | [diff] [blame] | 4624 | ? 1 |
| 4625 | : aom_rb_read_bit(rb); |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4626 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4627 | |
Wan-Teh Chang | 58e4a15 | 2019-06-25 13:44:35 -0700 | [diff] [blame] | 4628 | if (current_frame->frame_type == KEY_FRAME && cm->show_frame) { |
| 4629 | /* All frames need to be marked as not valid for referencing */ |
| 4630 | for (int i = 0; i < REF_FRAMES; i++) { |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 4631 | pbi->valid_for_referencing[i] = 0; |
Wan-Teh Chang | 58e4a15 | 2019-06-25 13:44:35 -0700 | [diff] [blame] | 4632 | } |
| 4633 | } |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4634 | features->disable_cdf_update = aom_rb_read_bit(rb); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4635 | if (seq_params->force_screen_content_tools == 2) { |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4636 | features->allow_screen_content_tools = aom_rb_read_bit(rb); |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 4637 | } else { |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4638 | features->allow_screen_content_tools = |
| 4639 | seq_params->force_screen_content_tools; |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4642 | if (features->allow_screen_content_tools) { |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4643 | if (seq_params->force_integer_mv == 2) { |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4644 | features->cur_frame_force_integer_mv = aom_rb_read_bit(rb); |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 4645 | } else { |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4646 | features->cur_frame_force_integer_mv = seq_params->force_integer_mv; |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 4647 | } |
| 4648 | } else { |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4649 | features->cur_frame_force_integer_mv = 0; |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 4650 | } |
Imdad Sardharwalla | bf2cc01 | 2018-02-09 17:32:10 +0000 | [diff] [blame] | 4651 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4652 | int frame_size_override_flag = 0; |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4653 | features->allow_intrabc = 0; |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 4654 | features->primary_ref_frame = PRIMARY_REF_NONE; |
Zoe Liu | 45a8fed | 2018-03-02 16:51:02 -0800 | [diff] [blame] | 4655 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4656 | if (!seq_params->reduced_still_picture_hdr) { |
| 4657 | if (seq_params->frame_id_numbers_present_flag) { |
| 4658 | int frame_id_length = seq_params->frame_id_length; |
| 4659 | int diff_len = seq_params->delta_frame_id_length; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4660 | int prev_frame_id = 0; |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4661 | int have_prev_frame_id = |
| 4662 | !pbi->decoding_first_frame && |
| 4663 | !(current_frame->frame_type == KEY_FRAME && cm->show_frame); |
David Barker | f6f8fa1 | 2018-06-20 14:46:05 +0100 | [diff] [blame] | 4664 | if (have_prev_frame_id) { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4665 | prev_frame_id = cm->current_frame_id; |
| 4666 | } |
| 4667 | cm->current_frame_id = aom_rb_read_literal(rb, frame_id_length); |
Zoe Liu | 45a8fed | 2018-03-02 16:51:02 -0800 | [diff] [blame] | 4668 | |
David Barker | f6f8fa1 | 2018-06-20 14:46:05 +0100 | [diff] [blame] | 4669 | if (have_prev_frame_id) { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4670 | int diff_frame_id; |
| 4671 | if (cm->current_frame_id > prev_frame_id) { |
| 4672 | diff_frame_id = cm->current_frame_id - prev_frame_id; |
| 4673 | } else { |
| 4674 | diff_frame_id = |
| 4675 | (1 << frame_id_length) + cm->current_frame_id - prev_frame_id; |
| 4676 | } |
| 4677 | /* Check current_frame_id for conformance */ |
| 4678 | if (prev_frame_id == cm->current_frame_id || |
| 4679 | diff_frame_id >= (1 << (frame_id_length - 1))) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4680 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4681 | "Invalid value of current_frame_id"); |
| 4682 | } |
| 4683 | } |
| 4684 | /* Check if some frames need to be marked as not valid for referencing */ |
| 4685 | for (int i = 0; i < REF_FRAMES; i++) { |
Wan-Teh Chang | 58e4a15 | 2019-06-25 13:44:35 -0700 | [diff] [blame] | 4686 | if (cm->current_frame_id - (1 << diff_len) > 0) { |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4687 | if (cm->ref_frame_id[i] > cm->current_frame_id || |
| 4688 | cm->ref_frame_id[i] < cm->current_frame_id - (1 << diff_len)) |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 4689 | pbi->valid_for_referencing[i] = 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4690 | } else { |
| 4691 | if (cm->ref_frame_id[i] > cm->current_frame_id && |
| 4692 | cm->ref_frame_id[i] < (1 << frame_id_length) + |
| 4693 | cm->current_frame_id - (1 << diff_len)) |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 4694 | pbi->valid_for_referencing[i] = 0; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4695 | } |
| 4696 | } |
| 4697 | } |
| 4698 | |
Wan-Teh Chang | b6680ff | 2018-07-27 14:50:25 -0700 | [diff] [blame] | 4699 | frame_size_override_flag = frame_is_sframe(cm) ? 1 : aom_rb_read_bit(rb); |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4700 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4701 | current_frame->order_hint = aom_rb_read_literal( |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4702 | rb, seq_params->order_hint_info.order_hint_bits_minus_1 + 1); |
Yunqing Wang | b397f7a | 2022-03-18 15:10:31 -0700 | [diff] [blame] | 4703 | |
| 4704 | if (seq_params->order_hint_info.enable_order_hint) |
| 4705 | current_frame->frame_number = current_frame->order_hint; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4706 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4707 | if (!features->error_resilient_mode && !frame_is_intra_only(cm)) { |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 4708 | features->primary_ref_frame = aom_rb_read_literal(rb, PRIMARY_REF_BITS); |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4709 | } |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4710 | } |
| 4711 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4712 | if (seq_params->decoder_model_info_present_flag) { |
Tarundeep Singh | d00b98f | 2021-04-21 16:13:51 +0530 | [diff] [blame] | 4713 | pbi->buffer_removal_time_present = aom_rb_read_bit(rb); |
| 4714 | if (pbi->buffer_removal_time_present) { |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 4715 | for (int op_num = 0; |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4716 | op_num < seq_params->operating_points_cnt_minus_1 + 1; op_num++) { |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4717 | if (seq_params->op_params[op_num].decoder_model_param_present_flag) { |
Wan-Teh Chang | 62e8d9c | 2021-05-28 12:30:23 -0700 | [diff] [blame] | 4718 | if (seq_params->operating_point_idc[op_num] == 0 || |
| 4719 | (((seq_params->operating_point_idc[op_num] >> |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 4720 | cm->temporal_layer_id) & |
| 4721 | 0x1) && |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4722 | ((seq_params->operating_point_idc[op_num] >> |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 4723 | (cm->spatial_layer_id + 8)) & |
Wan-Teh Chang | 62e8d9c | 2021-05-28 12:30:23 -0700 | [diff] [blame] | 4724 | 0x1))) { |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4725 | cm->buffer_removal_times[op_num] = aom_rb_read_unsigned_literal( |
| 4726 | rb, seq_params->decoder_model_info.buffer_removal_time_length); |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 4727 | } else { |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4728 | cm->buffer_removal_times[op_num] = 0; |
Adrian Grange | c56f6ec | 2018-05-31 14:19:32 -0700 | [diff] [blame] | 4729 | } |
| 4730 | } else { |
Urvang Joshi | 450a9a2 | 2020-03-31 16:00:22 -0700 | [diff] [blame] | 4731 | cm->buffer_removal_times[op_num] = 0; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 4732 | } |
| 4733 | } |
| 4734 | } |
| 4735 | } |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4736 | if (current_frame->frame_type == KEY_FRAME) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4737 | if (!cm->show_frame) { // unshown keyframe (forward keyframe) |
| 4738 | current_frame->refresh_frame_flags = aom_rb_read_literal(rb, REF_FRAMES); |
| 4739 | } else { // shown keyframe |
| 4740 | current_frame->refresh_frame_flags = (1 << REF_FRAMES) - 1; |
| 4741 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4742 | |
Sebastien Alaiwan | f518f14 | 2017-12-01 14:25:41 +0100 | [diff] [blame] | 4743 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4744 | cm->remapped_ref_idx[i] = INVALID_IDX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4745 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4746 | if (pbi->need_resync) { |
Wan-Teh Chang | 38353c8 | 2018-09-27 18:46:55 -0700 | [diff] [blame] | 4747 | reset_ref_frame_map(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4748 | pbi->need_resync = 0; |
| 4749 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4750 | } else { |
David Turner | 45f416c | 2018-11-15 11:34:30 +0000 | [diff] [blame] | 4751 | if (current_frame->frame_type == INTRA_ONLY_FRAME) { |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4752 | current_frame->refresh_frame_flags = aom_rb_read_literal(rb, REF_FRAMES); |
| 4753 | if (current_frame->refresh_frame_flags == 0xFF) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4754 | aom_internal_error(&pbi->error, AOM_CODEC_UNSUP_BITSTREAM, |
Debargha Mukherjee | 33f4265 | 2018-04-12 14:27:32 -0700 | [diff] [blame] | 4755 | "Intra only frames cannot have refresh flags 0xFF"); |
| 4756 | } |
| 4757 | if (pbi->need_resync) { |
Wan-Teh Chang | 38353c8 | 2018-09-27 18:46:55 -0700 | [diff] [blame] | 4758 | reset_ref_frame_map(cm); |
Debargha Mukherjee | 33f4265 | 2018-04-12 14:27:32 -0700 | [diff] [blame] | 4759 | pbi->need_resync = 0; |
| 4760 | } |
| 4761 | } else if (pbi->need_resync != 1) { /* Skip if need resync */ |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4762 | current_frame->refresh_frame_flags = |
Debargha Mukherjee | 33f4265 | 2018-04-12 14:27:32 -0700 | [diff] [blame] | 4763 | frame_is_sframe(cm) ? 0xFF : aom_rb_read_literal(rb, REF_FRAMES); |
Debargha Mukherjee | 33f4265 | 2018-04-12 14:27:32 -0700 | [diff] [blame] | 4764 | } |
| 4765 | } |
| 4766 | |
David Turner | 996b2c1 | 2018-12-07 15:52:30 +0000 | [diff] [blame] | 4767 | if (!frame_is_intra_only(cm) || current_frame->refresh_frame_flags != 0xFF) { |
Imdad Sardharwalla | 21cc90b | 2018-03-12 16:39:38 +0000 | [diff] [blame] | 4768 | // Read all ref frame order hints if error_resilient_mode == 1 |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4769 | if (features->error_resilient_mode && |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4770 | seq_params->order_hint_info.enable_order_hint) { |
Imdad Sardharwalla | 21cc90b | 2018-03-12 16:39:38 +0000 | [diff] [blame] | 4771 | for (int ref_idx = 0; ref_idx < REF_FRAMES; ref_idx++) { |
Imdad Sardharwalla | 21cc90b | 2018-03-12 16:39:38 +0000 | [diff] [blame] | 4772 | // Read order hint from bit stream |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 4773 | unsigned int order_hint = aom_rb_read_literal( |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4774 | rb, seq_params->order_hint_info.order_hint_bits_minus_1 + 1); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4775 | // Get buffer |
| 4776 | RefCntBuffer *buf = cm->ref_frame_map[ref_idx]; |
| 4777 | if (buf == NULL || order_hint != buf->order_hint) { |
| 4778 | if (buf != NULL) { |
Debargha Mukherjee | eeda6d2 | 2018-04-02 11:21:13 -0700 | [diff] [blame] | 4779 | lock_buffer_pool(pool); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4780 | decrease_ref_count(buf, pool); |
Debargha Mukherjee | eeda6d2 | 2018-04-02 11:21:13 -0700 | [diff] [blame] | 4781 | unlock_buffer_pool(pool); |
Wan-Teh Chang | ee70d94 | 2019-06-25 18:02:47 -0700 | [diff] [blame] | 4782 | cm->ref_frame_map[ref_idx] = NULL; |
Debargha Mukherjee | eeda6d2 | 2018-04-02 11:21:13 -0700 | [diff] [blame] | 4783 | } |
Imdad Sardharwalla | 714b268 | 2018-03-12 17:20:09 +0000 | [diff] [blame] | 4784 | // If no corresponding buffer exists, allocate a new buffer with all |
| 4785 | // pixels set to neutral grey. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4786 | int buf_idx = get_free_fb(cm); |
Wan-Teh Chang | 7b1404ab | 2018-04-24 17:47:17 -0700 | [diff] [blame] | 4787 | if (buf_idx == INVALID_IDX) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4788 | aom_internal_error(&pbi->error, AOM_CODEC_MEM_ERROR, |
Wan-Teh Chang | 7b1404ab | 2018-04-24 17:47:17 -0700 | [diff] [blame] | 4789 | "Unable to find free frame buffer"); |
| 4790 | } |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4791 | buf = &frame_bufs[buf_idx]; |
Debargha Mukherjee | eeda6d2 | 2018-04-02 11:21:13 -0700 | [diff] [blame] | 4792 | lock_buffer_pool(pool); |
| 4793 | if (aom_realloc_frame_buffer( |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4794 | &buf->buf, seq_params->max_frame_width, |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4795 | seq_params->max_frame_height, seq_params->subsampling_x, |
| 4796 | seq_params->subsampling_y, seq_params->use_highbitdepth, |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 4797 | AOM_BORDER_IN_PIXELS, features->byte_alignment, |
Rachel Barker | 72e349e | 2024-02-13 14:31:10 +0000 | [diff] [blame] | 4798 | &buf->raw_frame_buffer, pool->get_fb_cb, pool->cb_priv, false, |
Cherma Rajan A | d3b1571 | 2022-04-11 17:02:19 +0530 | [diff] [blame] | 4799 | 0)) { |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4800 | decrease_ref_count(buf, pool); |
Debargha Mukherjee | eeda6d2 | 2018-04-02 11:21:13 -0700 | [diff] [blame] | 4801 | unlock_buffer_pool(pool); |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4802 | aom_internal_error(&pbi->error, AOM_CODEC_MEM_ERROR, |
Debargha Mukherjee | eeda6d2 | 2018-04-02 11:21:13 -0700 | [diff] [blame] | 4803 | "Failed to allocate frame buffer"); |
| 4804 | } |
| 4805 | unlock_buffer_pool(pool); |
Yaowu Xu | c8a9f55 | 2020-03-23 08:41:35 -0700 | [diff] [blame] | 4806 | // According to the specification, valid bitstreams are required to |
| 4807 | // never use missing reference frames so the filling process for |
| 4808 | // missing frames is not normatively defined and RefValid for missing |
| 4809 | // frames is set to 0. |
Imdad Sardharwalla | 714b268 | 2018-03-12 17:20:09 +0000 | [diff] [blame] | 4810 | |
Yaowu Xu | c8a9f55 | 2020-03-23 08:41:35 -0700 | [diff] [blame] | 4811 | // To make libaom more robust when the bitstream has been corrupted |
| 4812 | // by the loss of some frames of data, this code adds a neutral grey |
| 4813 | // buffer in place of missing frames, i.e. |
| 4814 | // |
| 4815 | set_planes_to_neutral_grey(seq_params, &buf->buf, 0); |
| 4816 | // |
| 4817 | // and allows the frames to be used for referencing, i.e. |
| 4818 | // |
| 4819 | pbi->valid_for_referencing[ref_idx] = 1; |
| 4820 | // |
| 4821 | // Please note such behavior is not normative and other decoders may |
| 4822 | // use a different approach. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4823 | cm->ref_frame_map[ref_idx] = buf; |
| 4824 | buf->order_hint = order_hint; |
Imdad Sardharwalla | 714b268 | 2018-03-12 17:20:09 +0000 | [diff] [blame] | 4825 | } |
Imdad Sardharwalla | 21cc90b | 2018-03-12 16:39:38 +0000 | [diff] [blame] | 4826 | } |
| 4827 | } |
Debargha Mukherjee | 33f4265 | 2018-04-12 14:27:32 -0700 | [diff] [blame] | 4828 | } |
Imdad Sardharwalla | 21cc90b | 2018-03-12 16:39:38 +0000 | [diff] [blame] | 4829 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4830 | if (current_frame->frame_type == KEY_FRAME) { |
Debargha Mukherjee | 33f4265 | 2018-04-12 14:27:32 -0700 | [diff] [blame] | 4831 | setup_frame_size(cm, frame_size_override_flag, rb); |
| 4832 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4833 | if (features->allow_screen_content_tools && !av1_superres_scaled(cm)) |
| 4834 | features->allow_intrabc = aom_rb_read_bit(rb); |
| 4835 | features->allow_ref_frame_mvs = 0; |
Debargha Mukherjee | 33f4265 | 2018-04-12 14:27:32 -0700 | [diff] [blame] | 4836 | cm->prev_frame = NULL; |
| 4837 | } else { |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4838 | features->allow_ref_frame_mvs = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4839 | |
David Turner | 45f416c | 2018-11-15 11:34:30 +0000 | [diff] [blame] | 4840 | if (current_frame->frame_type == INTRA_ONLY_FRAME) { |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 4841 | cm->cur_frame->film_grain_params_present = |
| 4842 | seq_params->film_grain_params_present; |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 4843 | setup_frame_size(cm, frame_size_override_flag, rb); |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4844 | if (features->allow_screen_content_tools && !av1_superres_scaled(cm)) |
| 4845 | features->allow_intrabc = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4846 | |
Debargha Mukherjee | 33f4265 | 2018-04-12 14:27:32 -0700 | [diff] [blame] | 4847 | } else if (pbi->need_resync != 1) { /* Skip if need resync */ |
David Turner | 45f416c | 2018-11-15 11:34:30 +0000 | [diff] [blame] | 4848 | int frame_refs_short_signaling = 0; |
Zoe Liu | 592d73e | 2018-02-20 14:06:44 -0800 | [diff] [blame] | 4849 | // Frame refs short signaling is off when error resilient mode is on. |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 4850 | if (seq_params->order_hint_info.enable_order_hint) |
David Turner | 45f416c | 2018-11-15 11:34:30 +0000 | [diff] [blame] | 4851 | frame_refs_short_signaling = aom_rb_read_bit(rb); |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4852 | |
David Turner | 45f416c | 2018-11-15 11:34:30 +0000 | [diff] [blame] | 4853 | if (frame_refs_short_signaling) { |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4854 | // == LAST_FRAME == |
| 4855 | const int lst_ref = aom_rb_read_literal(rb, REF_FRAMES_LOG2); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4856 | const RefCntBuffer *const lst_buf = cm->ref_frame_map[lst_ref]; |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4857 | |
| 4858 | // == GOLDEN_FRAME == |
| 4859 | const int gld_ref = aom_rb_read_literal(rb, REF_FRAMES_LOG2); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4860 | const RefCntBuffer *const gld_buf = cm->ref_frame_map[gld_ref]; |
Rupert Swarbrick | 5eb471c | 2017-10-02 16:06:54 +0100 | [diff] [blame] | 4861 | |
| 4862 | // Most of the time, streams start with a keyframe. In that case, |
| 4863 | // ref_frame_map will have been filled in at that point and will not |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4864 | // contain any NULLs. However, streams are explicitly allowed to start |
Rupert Swarbrick | 5eb471c | 2017-10-02 16:06:54 +0100 | [diff] [blame] | 4865 | // with an intra-only frame, so long as they don't then signal a |
| 4866 | // reference to a slot that hasn't been set yet. That's what we are |
| 4867 | // checking here. |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4868 | if (lst_buf == NULL) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4869 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4870 | "Inter frame requests nonexistent reference"); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 4871 | if (gld_buf == NULL) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4872 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Rupert Swarbrick | 5eb471c | 2017-10-02 16:06:54 +0100 | [diff] [blame] | 4873 | "Inter frame requests nonexistent reference"); |
| 4874 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 4875 | av1_set_frame_refs(cm, cm->remapped_ref_idx, lst_ref, gld_ref); |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4876 | } |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4877 | |
| 4878 | for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 4879 | int ref = 0; |
David Turner | 45f416c | 2018-11-15 11:34:30 +0000 | [diff] [blame] | 4880 | if (!frame_refs_short_signaling) { |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4881 | ref = aom_rb_read_literal(rb, REF_FRAMES_LOG2); |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4882 | |
| 4883 | // Most of the time, streams start with a keyframe. In that case, |
| 4884 | // ref_frame_map will have been filled in at that point and will not |
Wan-Teh Chang | 62e4bbd | 2019-03-22 12:52:33 -0700 | [diff] [blame] | 4885 | // contain any NULLs. However, streams are explicitly allowed to start |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4886 | // with an intra-only frame, so long as they don't then signal a |
| 4887 | // reference to a slot that hasn't been set yet. That's what we are |
| 4888 | // checking here. |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4889 | if (cm->ref_frame_map[ref] == NULL) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4890 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4891 | "Inter frame requests nonexistent reference"); |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4892 | cm->remapped_ref_idx[i] = ref; |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4893 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4894 | ref = cm->remapped_ref_idx[i]; |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4895 | } |
Wan-Teh Chang | 58e4a15 | 2019-06-25 13:44:35 -0700 | [diff] [blame] | 4896 | // Check valid for referencing |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 4897 | if (pbi->valid_for_referencing[ref] == 0) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4898 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Wan-Teh Chang | 58e4a15 | 2019-06-25 13:44:35 -0700 | [diff] [blame] | 4899 | "Reference frame not valid for referencing"); |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4900 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 4901 | cm->ref_frame_sign_bias[LAST_FRAME + i] = 0; |
Zoe Liu | b57fee0 | 2018-02-15 17:41:41 -0800 | [diff] [blame] | 4902 | |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4903 | if (seq_params->frame_id_numbers_present_flag) { |
| 4904 | int frame_id_length = seq_params->frame_id_length; |
| 4905 | int diff_len = seq_params->delta_frame_id_length; |
Wan-Teh Chang | 6958297 | 2018-05-15 13:18:52 -0700 | [diff] [blame] | 4906 | int delta_frame_id_minus_1 = aom_rb_read_literal(rb, diff_len); |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 4907 | int ref_frame_id = |
Wan-Teh Chang | 6958297 | 2018-05-15 13:18:52 -0700 | [diff] [blame] | 4908 | ((cm->current_frame_id - (delta_frame_id_minus_1 + 1) + |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 4909 | (1 << frame_id_length)) % |
| 4910 | (1 << frame_id_length)); |
Wan-Teh Chang | 6958297 | 2018-05-15 13:18:52 -0700 | [diff] [blame] | 4911 | // Compare values derived from delta_frame_id_minus_1 and |
Wan-Teh Chang | 58e4a15 | 2019-06-25 13:44:35 -0700 | [diff] [blame] | 4912 | // refresh_frame_flags. |
| 4913 | if (ref_frame_id != cm->ref_frame_id[ref]) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4914 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 4915 | "Reference buffer frame ID mismatch"); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4916 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4917 | } |
| 4918 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4919 | if (!features->error_resilient_mode && frame_size_override_flag) { |
Arild Fuldseth | 842e9b0 | 2016-09-02 13:00:05 +0200 | [diff] [blame] | 4920 | setup_frame_size_with_refs(cm, rb); |
| 4921 | } else { |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 4922 | setup_frame_size(cm, frame_size_override_flag, rb); |
Arild Fuldseth | 842e9b0 | 2016-09-02 13:00:05 +0200 | [diff] [blame] | 4923 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4924 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4925 | if (features->cur_frame_force_integer_mv) { |
| 4926 | features->allow_high_precision_mv = 0; |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 4927 | } else { |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4928 | features->allow_high_precision_mv = aom_rb_read_bit(rb); |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 4929 | } |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 4930 | features->interp_filter = read_frame_interp_filter(rb); |
| 4931 | features->switchable_motion_mode = aom_rb_read_bit(rb); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4934 | cm->prev_frame = get_primary_ref_frame_buf(cm); |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 4935 | if (features->primary_ref_frame != PRIMARY_REF_NONE && |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4936 | get_primary_ref_frame_buf(cm) == NULL) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4937 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 4938 | "Reference frame containing this frame's initial " |
| 4939 | "frame context is unavailable."); |
Yue Chen | d90d343 | 2018-03-16 11:28:42 -0700 | [diff] [blame] | 4940 | } |
| 4941 | |
David Turner | 45f416c | 2018-11-15 11:34:30 +0000 | [diff] [blame] | 4942 | if (!(current_frame->frame_type == INTRA_ONLY_FRAME) && |
| 4943 | pbi->need_resync != 1) { |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 4944 | if (frame_might_allow_ref_frame_mvs(cm)) |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4945 | features->allow_ref_frame_mvs = aom_rb_read_bit(rb); |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 4946 | else |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4947 | features->allow_ref_frame_mvs = 0; |
Jingning Han | e17ebe9 | 2017-11-03 15:25:42 -0700 | [diff] [blame] | 4948 | |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4949 | for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 4950 | const RefCntBuffer *const ref_buf = get_ref_frame_buf(cm, i); |
| 4951 | struct scale_factors *const ref_scale_factors = |
| 4952 | get_ref_scale_factors(cm, i); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 4953 | av1_setup_scale_factors_for_frame( |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 4954 | ref_scale_factors, ref_buf->buf.y_crop_width, |
| 4955 | ref_buf->buf.y_crop_height, cm->width, cm->height); |
| 4956 | if ((!av1_is_valid_scale(ref_scale_factors))) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4957 | aom_internal_error(&pbi->error, AOM_CODEC_UNSUP_BITSTREAM, |
Debargha Mukherjee | 4f51ce8 | 2018-04-17 07:16:55 -0700 | [diff] [blame] | 4958 | "Reference frame has invalid dimensions"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4959 | } |
| 4960 | } |
| 4961 | } |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 4962 | |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 4963 | av1_setup_frame_buf_refs(cm); |
| 4964 | |
Debargha Mukherjee | d30cde5 | 2018-03-20 17:35:20 -0700 | [diff] [blame] | 4965 | av1_setup_frame_sign_bias(cm); |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 4966 | |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 4967 | cm->cur_frame->frame_type = current_frame->frame_type; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4968 | |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 4969 | update_ref_frame_id(pbi); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 4970 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4971 | const int might_bwd_adapt = !(seq_params->reduced_still_picture_hdr) && |
| 4972 | !(features->disable_cdf_update); |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4973 | if (might_bwd_adapt) { |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 4974 | features->refresh_frame_context = aom_rb_read_bit(rb) |
| 4975 | ? REFRESH_FRAME_CONTEXT_DISABLED |
| 4976 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4977 | } else { |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 4978 | features->refresh_frame_context = REFRESH_FRAME_CONTEXT_DISABLED; |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 4979 | } |
| 4980 | |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4981 | cm->cur_frame->buf.bit_depth = seq_params->bit_depth; |
| 4982 | cm->cur_frame->buf.color_primaries = seq_params->color_primaries; |
| 4983 | cm->cur_frame->buf.transfer_characteristics = |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4984 | seq_params->transfer_characteristics; |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4985 | cm->cur_frame->buf.matrix_coefficients = seq_params->matrix_coefficients; |
| 4986 | cm->cur_frame->buf.monochrome = seq_params->monochrome; |
| 4987 | cm->cur_frame->buf.chroma_sample_position = |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 4988 | seq_params->chroma_sample_position; |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 4989 | cm->cur_frame->buf.color_range = seq_params->color_range; |
| 4990 | cm->cur_frame->buf.render_width = cm->render_width; |
| 4991 | cm->cur_frame->buf.render_height = cm->render_height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4992 | |
| 4993 | if (pbi->need_resync) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 4994 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4995 | "Keyframe / intra-only frame required to reset decoder" |
| 4996 | " state"); |
| 4997 | } |
| 4998 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 4999 | if (features->allow_intrabc) { |
Hui Su | 27df834 | 2017-11-07 15:16:05 -0800 | [diff] [blame] | 5000 | // Set parameters corresponding to no filtering. |
| 5001 | struct loopfilter *lf = &cm->lf; |
Hui Su | 27df834 | 2017-11-07 15:16:05 -0800 | [diff] [blame] | 5002 | lf->filter_level[0] = 0; |
| 5003 | lf->filter_level[1] = 0; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5004 | cm->cdef_info.cdef_bits = 0; |
| 5005 | cm->cdef_info.cdef_strengths[0] = 0; |
| 5006 | cm->cdef_info.nb_cdef_strengths = 1; |
| 5007 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Hui Su | 27df834 | 2017-11-07 15:16:05 -0800 | [diff] [blame] | 5008 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 5009 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 5010 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Hui Su | 27df834 | 2017-11-07 15:16:05 -0800 | [diff] [blame] | 5011 | } |
Hui Su | 27df834 | 2017-11-07 15:16:05 -0800 | [diff] [blame] | 5012 | |
Cyril Concolato | 3b5afc1 | 2017-12-15 12:54:15 -0800 | [diff] [blame] | 5013 | read_tile_info(pbi, rb); |
Yaowu Xu | 7e45088 | 2019-04-30 15:09:18 -0700 | [diff] [blame] | 5014 | if (!av1_is_min_tile_width_satisfied(cm)) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 5015 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Debargha Mukherjee | a082f76 | 2019-03-04 15:05:18 -0800 | [diff] [blame] | 5016 | "Minimum tile width requirement not satisfied"); |
| 5017 | } |
| 5018 | |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 5019 | CommonQuantParams *const quant_params = &cm->quant_params; |
| 5020 | setup_quantization(quant_params, av1_num_planes(cm), |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 5021 | cm->seq_params->separate_uv_delta_q, rb); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5022 | xd->bd = (int)seq_params->bit_depth; |
David Barker | cc615a8 | 2018-03-19 14:38:51 +0000 | [diff] [blame] | 5023 | |
Urvang Joshi | 5c8625a | 2020-03-30 13:16:37 -0700 | [diff] [blame] | 5024 | CommonContexts *const above_contexts = &cm->above_contexts; |
| 5025 | if (above_contexts->num_planes < av1_num_planes(cm) || |
| 5026 | above_contexts->num_mi_cols < cm->mi_params.mi_cols || |
| 5027 | above_contexts->num_tile_rows < cm->tiles.rows) { |
| 5028 | av1_free_above_context_buffers(above_contexts); |
| 5029 | if (av1_alloc_above_context_buffers(above_contexts, cm->tiles.rows, |
| 5030 | cm->mi_params.mi_cols, |
| 5031 | av1_num_planes(cm))) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 5032 | aom_internal_error(&pbi->error, AOM_CODEC_MEM_ERROR, |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 5033 | "Failed to allocate context buffers"); |
Urvang Joshi | 5c8625a | 2020-03-30 13:16:37 -0700 | [diff] [blame] | 5034 | } |
Cherma Rajan A | 71d20db | 2018-04-27 11:15:32 +0530 | [diff] [blame] | 5035 | } |
| 5036 | |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 5037 | if (features->primary_ref_frame == PRIMARY_REF_NONE) { |
David Barker | e0d56e6 | 2018-03-07 13:56:19 +0000 | [diff] [blame] | 5038 | av1_setup_past_independence(cm); |
David Barker | e0d56e6 | 2018-03-07 13:56:19 +0000 | [diff] [blame] | 5039 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5040 | |
| 5041 | setup_segmentation(cm, rb); |
| 5042 | |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5043 | cm->delta_q_info.delta_q_res = 1; |
| 5044 | cm->delta_q_info.delta_lf_res = 1; |
| 5045 | cm->delta_q_info.delta_lf_present_flag = 0; |
| 5046 | cm->delta_q_info.delta_lf_multi = 0; |
| 5047 | cm->delta_q_info.delta_q_present_flag = |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 5048 | quant_params->base_qindex > 0 ? aom_rb_read_bit(rb) : 0; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5049 | if (cm->delta_q_info.delta_q_present_flag) { |
Urvang Joshi | acad1ca | 2020-04-27 17:03:25 -0700 | [diff] [blame] | 5050 | xd->current_base_qindex = quant_params->base_qindex; |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5051 | cm->delta_q_info.delta_q_res = 1 << aom_rb_read_literal(rb, 2); |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5052 | if (!features->allow_intrabc) |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5053 | cm->delta_q_info.delta_lf_present_flag = aom_rb_read_bit(rb); |
| 5054 | if (cm->delta_q_info.delta_lf_present_flag) { |
| 5055 | cm->delta_q_info.delta_lf_res = 1 << aom_rb_read_literal(rb, 2); |
| 5056 | cm->delta_q_info.delta_lf_multi = aom_rb_read_bit(rb); |
Wan-Teh Chang | 69ac7eb | 2018-06-08 09:41:37 -0700 | [diff] [blame] | 5057 | av1_reset_loop_filter_delta(xd, av1_num_planes(cm)); |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 5058 | } |
| 5059 | } |
Yue Chen | 6bec057 | 2018-05-15 09:53:35 -0700 | [diff] [blame] | 5060 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5061 | xd->cur_frame_force_integer_mv = features->cur_frame_force_integer_mv; |
Thomas Davies | 3ab20b4 | 2017-09-19 10:30:53 +0100 | [diff] [blame] | 5062 | |
Sebastien Alaiwan | f518f14 | 2017-12-01 14:25:41 +0100 | [diff] [blame] | 5063 | for (int i = 0; i < MAX_SEGMENTS; ++i) { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 5064 | const int qindex = av1_get_qindex(&cm->seg, i, quant_params->base_qindex); |
| 5065 | xd->lossless[i] = |
| 5066 | qindex == 0 && quant_params->y_dc_delta_q == 0 && |
| 5067 | quant_params->u_dc_delta_q == 0 && quant_params->u_ac_delta_q == 0 && |
| 5068 | quant_params->v_dc_delta_q == 0 && quant_params->v_ac_delta_q == 0; |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 5069 | xd->qindex[i] = qindex; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5070 | } |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5071 | features->coded_lossless = is_coded_lossless(cm, xd); |
| 5072 | features->all_lossless = features->coded_lossless && !av1_superres_scaled(cm); |
Wan-Teh Chang | 98c01e0 | 2018-10-18 09:48:27 -0700 | [diff] [blame] | 5073 | setup_segmentation_dequant(cm, xd); |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5074 | if (features->coded_lossless) { |
Jonathan Matthews | bfd2454 | 2018-03-02 11:20:15 +0000 | [diff] [blame] | 5075 | cm->lf.filter_level[0] = 0; |
| 5076 | cm->lf.filter_level[1] = 0; |
Debargha Mukherjee | 98a311c | 2018-03-25 16:33:11 -0700 | [diff] [blame] | 5077 | } |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5078 | if (features->coded_lossless || !seq_params->enable_cdef) { |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5079 | cm->cdef_info.cdef_bits = 0; |
| 5080 | cm->cdef_info.cdef_strengths[0] = 0; |
| 5081 | cm->cdef_info.cdef_uv_strengths[0] = 0; |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 5082 | } |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5083 | if (features->all_lossless || !seq_params->enable_restoration) { |
Jonathan Matthews | bfd2454 | 2018-03-02 11:20:15 +0000 | [diff] [blame] | 5084 | cm->rst_info[0].frame_restoration_type = RESTORE_NONE; |
| 5085 | cm->rst_info[1].frame_restoration_type = RESTORE_NONE; |
| 5086 | cm->rst_info[2].frame_restoration_type = RESTORE_NONE; |
Debargha Mukherjee | 63bcfa7 | 2018-03-20 15:25:22 -0700 | [diff] [blame] | 5087 | } |
| 5088 | setup_loopfilter(cm, rb); |
| 5089 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5090 | if (!features->coded_lossless && seq_params->enable_cdef) { |
Thomas Daede | f636d5c | 2017-06-29 13:48:27 -0700 | [diff] [blame] | 5091 | setup_cdef(cm, rb); |
Urvang Joshi | c8b52d5 | 2018-03-23 13:16:51 -0700 | [diff] [blame] | 5092 | } |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5093 | if (!features->all_lossless && seq_params->enable_restoration) { |
Urvang Joshi | 5ec7b81 | 2018-02-28 14:37:06 -0800 | [diff] [blame] | 5094 | decode_restoration_mode(cm, rb); |
Thomas Daede | f636d5c | 2017-06-29 13:48:27 -0700 | [diff] [blame] | 5095 | } |
Urvang Joshi | 5ec7b81 | 2018-02-28 14:37:06 -0800 | [diff] [blame] | 5096 | |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 5097 | features->tx_mode = read_tx_mode(rb, features->coded_lossless); |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5098 | current_frame->reference_mode = read_frame_reference_mode(cm, rb); |
Zoe Liu | 4b847e1 | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 5099 | |
Zoe Liu | 4b847e1 | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 5100 | av1_setup_skip_mode_allowed(cm); |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 5101 | current_frame->skip_mode_info.skip_mode_flag = |
| 5102 | current_frame->skip_mode_info.skip_mode_allowed ? aom_rb_read_bit(rb) : 0; |
Zoe Liu | 4b847e1 | 2017-12-07 12:44:45 -0800 | [diff] [blame] | 5103 | |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 5104 | if (frame_might_allow_warped_motion(cm)) |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5105 | features->allow_warped_motion = aom_rb_read_bit(rb); |
Debargha Mukherjee | 07a7c1f | 2018-03-21 17:39:13 -0700 | [diff] [blame] | 5106 | else |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5107 | features->allow_warped_motion = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5108 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5109 | features->reduced_tx_set_used = aom_rb_read_bit(rb); |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 5110 | |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5111 | if (features->allow_ref_frame_mvs && !frame_might_allow_ref_frame_mvs(cm)) { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 5112 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Debargha Mukherjee | a5b810a | 2018-03-26 19:19:55 -0700 | [diff] [blame] | 5113 | "Frame wrongly requests reference frame MVs"); |
Pavel Frolov | 57c36e1 | 2017-09-12 15:00:40 +0300 | [diff] [blame] | 5114 | } |
Pavel Frolov | 57c36e1 | 2017-09-12 15:00:40 +0300 | [diff] [blame] | 5115 | |
Sarah Parker | f289f9f | 2017-09-12 18:50:02 -0700 | [diff] [blame] | 5116 | if (!frame_is_intra_only(cm)) read_global_motion(cm, rb); |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 5117 | |
Urvang Joshi | 8d5a4ba | 2018-07-19 16:26:34 -0700 | [diff] [blame] | 5118 | cm->cur_frame->film_grain_params_present = |
| 5119 | seq_params->film_grain_params_present; |
David Barker | e8cedfa | 2018-04-09 14:54:13 +0100 | [diff] [blame] | 5120 | read_film_grain(cm, rb); |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 5121 | |
Yunqing Wang | 445739a | 2018-06-10 12:27:34 -0700 | [diff] [blame] | 5122 | #if EXT_TILE_DEBUG |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 5123 | if (pbi->ext_tile_debug && cm->tiles.large_scale) { |
Yunqing Wang | 2f7b7a9 | 2018-06-11 10:07:23 -0700 | [diff] [blame] | 5124 | read_ext_tile_info(pbi, rb); |
| 5125 | av1_set_single_tile_decoding_mode(cm); |
| 5126 | } |
Yunqing Wang | 445739a | 2018-06-10 12:27:34 -0700 | [diff] [blame] | 5127 | #endif // EXT_TILE_DEBUG |
Thomas Davies | e715483 | 2017-10-03 10:12:17 +0100 | [diff] [blame] | 5128 | return 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5129 | } |
Debargha Mukherjee | 2eada61 | 2017-09-22 15:37:39 -0700 | [diff] [blame] | 5130 | |
Sebastien Alaiwan | e9644be | 2017-12-19 18:20:12 +0100 | [diff] [blame] | 5131 | struct aom_read_bit_buffer *av1_init_read_bit_buffer( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5132 | AV1Decoder *pbi, struct aom_read_bit_buffer *rb, const uint8_t *data, |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 5133 | const uint8_t *data_end) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5134 | rb->bit_offset = 0; |
| 5135 | rb->error_handler = error_handler; |
| 5136 | rb->error_handler_data = &pbi->common; |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 5137 | rb->bit_buffer = data; |
| 5138 | rb->bit_buffer_end = data_end; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5139 | return rb; |
| 5140 | } |
| 5141 | |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 5142 | void av1_read_frame_size(struct aom_read_bit_buffer *rb, int num_bits_width, |
| 5143 | int num_bits_height, int *width, int *height) { |
| 5144 | *width = aom_rb_read_literal(rb, num_bits_width) + 1; |
| 5145 | *height = aom_rb_read_literal(rb, num_bits_height) + 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 5148 | BITSTREAM_PROFILE av1_read_profile(struct aom_read_bit_buffer *rb) { |
Debargha Mukherjee | 53396fb | 2018-03-30 12:19:38 -0700 | [diff] [blame] | 5149 | int profile = aom_rb_read_literal(rb, PROFILE_BITS); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 5150 | return (BITSTREAM_PROFILE)profile; |
| 5151 | } |
| 5152 | |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 5153 | static inline void superres_post_decode(AV1Decoder *pbi) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5154 | AV1_COMMON *const cm = &pbi->common; |
| 5155 | BufferPool *const pool = cm->buffer_pool; |
| 5156 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 5157 | if (!av1_superres_scaled(cm)) return; |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5158 | assert(!cm->features.all_lossless); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5159 | |
Rachel Barker | 674eaa0 | 2022-12-22 16:03:44 +0000 | [diff] [blame] | 5160 | av1_superres_upscale(cm, pool, 0); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5161 | } |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 5162 | |
Wan-Teh Chang | bb6192a | 2018-07-10 11:01:04 -0700 | [diff] [blame] | 5163 | uint32_t av1_decode_frame_headers_and_setup(AV1Decoder *pbi, |
| 5164 | struct aom_read_bit_buffer *rb, |
Wan-Teh Chang | bb6192a | 2018-07-10 11:01:04 -0700 | [diff] [blame] | 5165 | int trailing_bits_present) { |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5166 | AV1_COMMON *const cm = &pbi->common; |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 5167 | const int num_planes = av1_num_planes(cm); |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 5168 | MACROBLOCKD *const xd = &pbi->dcb.xd; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5169 | |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5170 | #if CONFIG_BITSTREAM_DEBUG |
Wan-Teh Chang | 2e1c16e | 2022-03-30 18:27:20 -0700 | [diff] [blame] | 5171 | if (cm->seq_params->order_hint_info.enable_order_hint) { |
Yunqing Wang | b397f7a | 2022-03-18 15:10:31 -0700 | [diff] [blame] | 5172 | aom_bitstream_queue_set_frame_read(cm->current_frame.order_hint * 2 + |
| 5173 | cm->show_frame); |
Wan-Teh Chang | 2e1c16e | 2022-03-30 18:27:20 -0700 | [diff] [blame] | 5174 | } else { |
Yunqing Wang | b397f7a | 2022-03-18 15:10:31 -0700 | [diff] [blame] | 5175 | // This is currently used in RTC encoding. cm->show_frame is always 1. |
Wan-Teh Chang | 2e1c16e | 2022-03-30 18:27:20 -0700 | [diff] [blame] | 5176 | assert(cm->show_frame); |
Yunqing Wang | b397f7a | 2022-03-18 15:10:31 -0700 | [diff] [blame] | 5177 | aom_bitstream_queue_set_frame_read(cm->current_frame.frame_number); |
Wan-Teh Chang | 2e1c16e | 2022-03-30 18:27:20 -0700 | [diff] [blame] | 5178 | } |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5179 | #endif |
Angie Chiang | 5b5f4df | 2017-12-06 10:41:12 -0800 | [diff] [blame] | 5180 | #if CONFIG_MISMATCH_DEBUG |
| 5181 | mismatch_move_frame_idx_r(); |
| 5182 | #endif |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5183 | |
Sebastien Alaiwan | f518f14 | 2017-12-01 14:25:41 +0100 | [diff] [blame] | 5184 | for (int i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 5185 | cm->global_motion[i] = default_warp_params; |
| 5186 | cm->cur_frame->global_motion[i] = default_warp_params; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5187 | } |
| 5188 | xd->global_motion = cm->global_motion; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5189 | |
Yaowu Xu | c407123 | 2018-03-30 12:53:22 -0700 | [diff] [blame] | 5190 | read_uncompressed_header(pbi, rb); |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5191 | |
Vignesh Venkatasubramanian | bd7b0e3 | 2018-04-10 11:31:59 -0700 | [diff] [blame] | 5192 | if (trailing_bits_present) av1_check_trailing_bits(pbi, rb); |
Jingning Han | 8a59bd5 | 2018-03-22 21:30:31 -0700 | [diff] [blame] | 5193 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 5194 | if (!cm->tiles.single_tile_decoding && |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5195 | (pbi->dec_tile_row >= 0 || pbi->dec_tile_col >= 0)) { |
| 5196 | pbi->dec_tile_row = -1; |
| 5197 | pbi->dec_tile_col = -1; |
| 5198 | } |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5199 | |
Wan-Teh Chang | bb6192a | 2018-07-10 11:01:04 -0700 | [diff] [blame] | 5200 | const uint32_t uncomp_hdr_size = |
| 5201 | (uint32_t)aom_rb_bytes_read(rb); // Size of the uncompressed header |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 5202 | YV12_BUFFER_CONFIG *new_fb = &cm->cur_frame->buf; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5203 | xd->cur_buf = new_fb; |
Hui Su | e8eb3a7 | 2018-03-17 17:46:21 -0700 | [diff] [blame] | 5204 | if (av1_allow_intrabc(cm)) { |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 5205 | av1_setup_scale_factors_for_frame( |
| 5206 | &cm->sf_identity, xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height, |
Debargha Mukherjee | e242a81 | 2018-03-07 21:43:09 -0800 | [diff] [blame] | 5207 | xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height); |
Hui Su | 5ebd870 | 2018-01-08 18:09:20 -0800 | [diff] [blame] | 5208 | } |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5209 | |
Elliott Karpilovsky | 1d1bc84 | 2020-12-21 21:20:43 -0800 | [diff] [blame] | 5210 | // Showing a frame directly. |
Debargha Mukherjee | 2eada61 | 2017-09-22 15:37:39 -0700 | [diff] [blame] | 5211 | if (cm->show_existing_frame) { |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 5212 | if (pbi->reset_decoder_state) { |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 5213 | // Use the default frame context values. |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 5214 | *cm->fc = *cm->default_frame_context; |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 5215 | if (!cm->fc->initialized) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 5216 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Zoe Liu | a7c1b19 | 2017-12-19 16:59:38 -0800 | [diff] [blame] | 5217 | "Uninitialized entropy context."); |
| 5218 | } |
Wan-Teh Chang | bb6192a | 2018-07-10 11:01:04 -0700 | [diff] [blame] | 5219 | return uncomp_hdr_size; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5220 | } |
| 5221 | |
Urvang Joshi | 9dc909d | 2020-03-23 16:07:02 -0700 | [diff] [blame] | 5222 | cm->mi_params.setup_mi(&cm->mi_params); |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5223 | |
Yunqing Wang | fa74d0e | 2021-07-29 16:41:37 -0700 | [diff] [blame] | 5224 | av1_calculate_ref_frame_side(cm); |
| 5225 | if (cm->features.allow_ref_frame_mvs) av1_setup_motion_field(cm); |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5226 | |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 5227 | av1_setup_block_planes(xd, cm->seq_params->subsampling_x, |
| 5228 | cm->seq_params->subsampling_y, num_planes); |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 5229 | if (cm->features.primary_ref_frame == PRIMARY_REF_NONE) { |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5230 | // use the default frame context values |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 5231 | *cm->fc = *cm->default_frame_context; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5232 | } else { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 5233 | *cm->fc = get_primary_ref_frame_buf(cm)->frame_context; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5234 | } |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5235 | if (!cm->fc->initialized) |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 5236 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5237 | "Uninitialized entropy context."); |
| 5238 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 5239 | pbi->dcb.corrupted = 0; |
Wan-Teh Chang | bb6192a | 2018-07-10 11:01:04 -0700 | [diff] [blame] | 5240 | return uncomp_hdr_size; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5241 | } |
| 5242 | |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 5243 | // Once-per-frame initialization |
Wan-Teh Chang | 9453443 | 2024-08-08 20:29:57 -0700 | [diff] [blame] | 5244 | static inline void setup_frame_info(AV1Decoder *pbi) { |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5245 | AV1_COMMON *const cm = &pbi->common; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5246 | |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5247 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 5248 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 5249 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
venkat sanampudi | 4a46999 | 2023-04-10 10:10:58 +0530 | [diff] [blame] | 5250 | av1_alloc_restoration_buffers(cm, /*is_sgr_enabled =*/true); |
Rachel Barker | c65670f6 | 2023-10-25 00:35:23 +0000 | [diff] [blame] | 5251 | for (int p = 0; p < av1_num_planes(cm); p++) { |
| 5252 | av1_alloc_restoration_struct(cm, &cm->rst_info[p], p > 0); |
| 5253 | } |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5254 | } |
Jerome Jiang | f883c11 | 2022-04-15 17:52:28 -0400 | [diff] [blame] | 5255 | |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 5256 | const int use_highbd = cm->seq_params->use_highbitdepth; |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 5257 | const int buf_size = MC_TEMP_BUF_PELS << use_highbd; |
| 5258 | if (pbi->td.mc_buf_size != buf_size) { |
Wan-Teh Chang | 8d728cc | 2018-08-30 15:34:47 -0700 | [diff] [blame] | 5259 | av1_free_mc_tmp_buf(&pbi->td); |
Ravi Chaudhary | 4e7b6f0 | 2018-06-08 19:36:56 +0530 | [diff] [blame] | 5260 | allocate_mc_tmp_buf(cm, &pbi->td, buf_size, use_highbd); |
| 5261 | } |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 5262 | } |
| 5263 | |
| 5264 | void av1_decode_tg_tiles_and_wrapup(AV1Decoder *pbi, const uint8_t *data, |
| 5265 | const uint8_t *data_end, |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 5266 | const uint8_t **p_data_end, int start_tile, |
| 5267 | int end_tile, int initialize_flag) { |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 5268 | AV1_COMMON *const cm = &pbi->common; |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 5269 | CommonTileParams *const tiles = &cm->tiles; |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 5270 | MACROBLOCKD *const xd = &pbi->dcb.xd; |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 5271 | const int tile_count_tg = end_tile - start_tile + 1; |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 5272 | |
Mudassir Galaganath | 24d4b29 | 2023-09-16 15:51:13 +0530 | [diff] [blame] | 5273 | xd->error_info = cm->error; |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 5274 | if (initialize_flag) setup_frame_info(pbi); |
Cheng Chen | c75fb08 | 2018-07-06 19:01:04 -0700 | [diff] [blame] | 5275 | const int num_planes = av1_num_planes(cm); |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5276 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 5277 | if (pbi->max_threads > 1 && !(tiles->large_scale && !pbi->ext_tile_debug) && |
Deepa K G | 966c44e | 2018-06-22 17:41:12 +0530 | [diff] [blame] | 5278 | pbi->row_mt) |
Deepa K G | ec1987a | 2018-07-03 14:22:27 +0530 | [diff] [blame] | 5279 | *p_data_end = |
| 5280 | decode_tiles_row_mt(pbi, data, data_end, start_tile, end_tile); |
Deepa K G | 966c44e | 2018-06-22 17:41:12 +0530 | [diff] [blame] | 5281 | else if (pbi->max_threads > 1 && tile_count_tg > 1 && |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 5282 | !(tiles->large_scale && !pbi->ext_tile_debug)) |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 5283 | *p_data_end = decode_tiles_mt(pbi, data, data_end, start_tile, end_tile); |
Cherma Rajan A | a91ed82 | 2018-04-23 14:45:49 +0530 | [diff] [blame] | 5284 | else |
Cheng Chen | a98e55e | 2018-06-12 23:14:19 -0700 | [diff] [blame] | 5285 | *p_data_end = decode_tiles(pbi, data, data_end, start_tile, end_tile); |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5286 | |
Imdad Sardharwalla | 317002f | 2017-12-05 16:24:56 +0000 | [diff] [blame] | 5287 | // If the bit stream is monochrome, set the U and V buffers to a constant. |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5288 | if (num_planes < 3) { |
Tarundeep Singh | 4243e62 | 2021-04-20 16:10:22 +0530 | [diff] [blame] | 5289 | set_planes_to_neutral_grey(cm->seq_params, xd->cur_buf, 1); |
Urvang Joshi | 20cf30e | 2018-07-19 02:33:58 -0700 | [diff] [blame] | 5290 | } |
Imdad Sardharwalla | d8397d6 | 2017-11-30 15:28:05 +0000 | [diff] [blame] | 5291 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 5292 | if (end_tile != tiles->rows * tiles->cols - 1) { |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5293 | return; |
| 5294 | } |
| 5295 | |
Vishnu Teja Manyam | f194981 | 2021-04-08 19:07:51 +0530 | [diff] [blame] | 5296 | av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync, |
Nithya V S | 709ccb3 | 2021-08-18 11:05:46 +0530 | [diff] [blame] | 5297 | pbi->num_workers, 1); |
Vishnu Teja Manyam | f194981 | 2021-04-08 19:07:51 +0530 | [diff] [blame] | 5298 | av1_alloc_cdef_sync(cm, &pbi->cdef_sync, pbi->num_workers); |
| 5299 | |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 5300 | if (!cm->features.allow_intrabc && !tiles->single_tile_decoding) { |
Yaowu Xu | 73a1215 | 2018-04-18 12:00:51 -0700 | [diff] [blame] | 5301 | if (cm->lf.filter_level[0] || cm->lf.filter_level[1]) { |
Yannis Guyon | 27bdea5 | 2021-07-21 10:41:02 +0200 | [diff] [blame] | 5302 | av1_loop_filter_frame_mt(&cm->cur_frame->buf, cm, &pbi->dcb.xd, 0, |
| 5303 | num_planes, 0, pbi->tile_workers, |
| 5304 | pbi->num_workers, &pbi->lf_row_sync, 0); |
Yaowu Xu | 73a1215 | 2018-04-18 12:00:51 -0700 | [diff] [blame] | 5305 | } |
| 5306 | |
Yunqing Wang | e802503 | 2018-04-10 18:50:29 -0700 | [diff] [blame] | 5307 | const int do_cdef = |
Urvang Joshi | b6409e9 | 2020-03-23 11:23:27 -0700 | [diff] [blame] | 5308 | !pbi->skip_loop_filter && !cm->features.coded_lossless && |
David Turner | ebf96f4 | 2018-11-14 16:57:57 +0000 | [diff] [blame] | 5309 | (cm->cdef_info.cdef_bits || cm->cdef_info.cdef_strengths[0] || |
| 5310 | cm->cdef_info.cdef_uv_strengths[0]); |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 5311 | const int do_superres = av1_superres_scaled(cm); |
Yunqing Wang | e802503 | 2018-04-10 18:50:29 -0700 | [diff] [blame] | 5312 | const int optimized_loop_restoration = !do_cdef && !do_superres; |
Jerome Jiang | 87c414e | 2020-10-30 19:03:47 -0700 | [diff] [blame] | 5313 | const int do_loop_restoration = |
| 5314 | cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 5315 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 5316 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE; |
Deepa K G | aeee77c | 2022-05-28 14:00:56 +0530 | [diff] [blame] | 5317 | // Frame border extension is not required in the decoder |
| 5318 | // as it happens in extend_mc_border(). |
| 5319 | int do_extend_border_mt = 0; |
Yunqing Wang | 2ff71af | 2018-04-24 15:10:10 -0700 | [diff] [blame] | 5320 | if (!optimized_loop_restoration) { |
Yunqing Wang | 883f644 | 2018-04-09 18:11:20 -0700 | [diff] [blame] | 5321 | if (do_loop_restoration) |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 5322 | av1_loop_restoration_save_boundary_lines(&pbi->common.cur_frame->buf, |
| 5323 | cm, 0); |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5324 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 5325 | if (do_cdef) { |
Vishnu Teja Manyam | f194981 | 2021-04-08 19:07:51 +0530 | [diff] [blame] | 5326 | if (pbi->num_workers > 1) { |
| 5327 | av1_cdef_frame_mt(cm, &pbi->dcb.xd, pbi->cdef_worker, |
| 5328 | pbi->tile_workers, &pbi->cdef_sync, |
Deepa K G | aeee77c | 2022-05-28 14:00:56 +0530 | [diff] [blame] | 5329 | pbi->num_workers, av1_cdef_init_fb_row_mt, |
| 5330 | do_extend_border_mt); |
Vishnu Teja Manyam | f194981 | 2021-04-08 19:07:51 +0530 | [diff] [blame] | 5331 | } else { |
| 5332 | av1_cdef_frame(&pbi->common.cur_frame->buf, cm, &pbi->dcb.xd, |
| 5333 | av1_cdef_init_fb_row); |
| 5334 | } |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 5335 | } |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5336 | |
Yunqing Wang | 883f644 | 2018-04-09 18:11:20 -0700 | [diff] [blame] | 5337 | superres_post_decode(pbi); |
| 5338 | |
| 5339 | if (do_loop_restoration) { |
Jack Haughton | ddb8060 | 2018-11-21 16:41:49 +0000 | [diff] [blame] | 5340 | av1_loop_restoration_save_boundary_lines(&pbi->common.cur_frame->buf, |
| 5341 | cm, 1); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 5342 | if (pbi->num_workers > 1) { |
| 5343 | av1_loop_restoration_filter_frame_mt( |
| 5344 | (YV12_BUFFER_CONFIG *)xd->cur_buf, cm, optimized_loop_restoration, |
| 5345 | pbi->tile_workers, pbi->num_workers, &pbi->lr_row_sync, |
Deepa K G | aeee77c | 2022-05-28 14:00:56 +0530 | [diff] [blame] | 5346 | &pbi->lr_ctxt, do_extend_border_mt); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 5347 | } else { |
| 5348 | av1_loop_restoration_filter_frame((YV12_BUFFER_CONFIG *)xd->cur_buf, |
| 5349 | cm, optimized_loop_restoration, |
| 5350 | &pbi->lr_ctxt); |
| 5351 | } |
Yunqing Wang | 883f644 | 2018-04-09 18:11:20 -0700 | [diff] [blame] | 5352 | } |
| 5353 | } else { |
Yunqing Wang | e802503 | 2018-04-10 18:50:29 -0700 | [diff] [blame] | 5354 | // In no cdef and no superres case. Provide an optimized version of |
| 5355 | // loop_restoration_filter. |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 5356 | if (do_loop_restoration) { |
| 5357 | if (pbi->num_workers > 1) { |
| 5358 | av1_loop_restoration_filter_frame_mt( |
| 5359 | (YV12_BUFFER_CONFIG *)xd->cur_buf, cm, optimized_loop_restoration, |
| 5360 | pbi->tile_workers, pbi->num_workers, &pbi->lr_row_sync, |
Deepa K G | aeee77c | 2022-05-28 14:00:56 +0530 | [diff] [blame] | 5361 | &pbi->lr_ctxt, do_extend_border_mt); |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 5362 | } else { |
| 5363 | av1_loop_restoration_filter_frame((YV12_BUFFER_CONFIG *)xd->cur_buf, |
| 5364 | cm, optimized_loop_restoration, |
| 5365 | &pbi->lr_ctxt); |
| 5366 | } |
| 5367 | } |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5368 | } |
David Barker | 218556e | 2018-02-14 14:23:12 +0000 | [diff] [blame] | 5369 | } |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5370 | |
Urvang Joshi | bac1dea | 2020-04-20 11:37:15 -0700 | [diff] [blame] | 5371 | if (!pbi->dcb.corrupted) { |
Urvang Joshi | 6237b88 | 2020-03-26 15:02:26 -0700 | [diff] [blame] | 5372 | if (cm->features.refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Urvang Joshi | 1de67aa | 2020-03-20 11:21:57 -0700 | [diff] [blame] | 5373 | assert(pbi->context_update_tile_id < pbi->allocated_tiles); |
| 5374 | *cm->fc = pbi->tile_data[pbi->context_update_tile_id].tctx; |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 5375 | av1_reset_cdf_symbol_counters(cm->fc); |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5376 | } |
| 5377 | } else { |
Tarundeep Singh | cfa5fb4 | 2021-04-23 18:25:32 +0530 | [diff] [blame] | 5378 | aom_internal_error(&pbi->error, AOM_CODEC_CORRUPT_FRAME, |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5379 | "Decode failed. Frame data is corrupted."); |
| 5380 | } |
| 5381 | |
| 5382 | #if CONFIG_INSPECTION |
| 5383 | if (pbi->inspect_cb != NULL) { |
| 5384 | (*pbi->inspect_cb)(pbi, pbi->inspect_ctx); |
| 5385 | } |
| 5386 | #endif |
| 5387 | |
Yaowu Xu | dd6ef6c | 2018-03-02 16:43:52 -0800 | [diff] [blame] | 5388 | // Non frame parallel update frame context here. |
Urvang Joshi | 54ffae7 | 2020-03-23 13:37:10 -0700 | [diff] [blame] | 5389 | if (!tiles->large_scale) { |
David Turner | 1bcefb3 | 2018-11-19 17:54:00 +0000 | [diff] [blame] | 5390 | cm->cur_frame->frame_context = *cm->fc; |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 5391 | } |
Yunqing Wang | b397f7a | 2022-03-18 15:10:31 -0700 | [diff] [blame] | 5392 | |
| 5393 | if (cm->show_frame && !cm->seq_params->order_hint_info.enable_order_hint) { |
| 5394 | ++cm->current_frame.frame_number; |
| 5395 | } |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 5396 | } |