Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -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> |
| 13 | #include <stdlib.h> // qsort() |
| 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_config.h" |
| 16 | #include "./aom_dsp_rtcd.h" |
| 17 | #include "./aom_scale_rtcd.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 18 | #include "./av1_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | |
Steinar Midtskogen | 2fd70ee | 2016-09-02 10:02:30 +0200 | [diff] [blame] | 20 | #include "aom/aom_codec.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 21 | #include "aom_dsp/aom_dsp_common.h" |
Cheng Chen | c7855b1 | 2017-09-05 10:49:08 -0700 | [diff] [blame] | 22 | #include "aom_dsp/binary_codes_reader.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 23 | #include "aom_dsp/bitreader.h" |
| 24 | #include "aom_dsp/bitreader_buffer.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 25 | #include "aom_mem/aom_mem.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 26 | #include "aom_ports/mem.h" |
| 27 | #include "aom_ports/mem_ops.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 28 | #include "aom_scale/aom_scale.h" |
| 29 | #include "aom_util/aom_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 30 | |
Fergus Simpson | 350a9b7 | 2017-04-17 15:08:45 -0700 | [diff] [blame] | 31 | #if CONFIG_BITSTREAM_DEBUG |
| 32 | #include "aom_util/debug_util.h" |
| 33 | #endif // CONFIG_BITSTREAM_DEBUG |
| 34 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 35 | #include "av1/common/alloccommon.h" |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 36 | #if CONFIG_CDEF |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 37 | #include "av1/common/cdef.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 38 | #endif |
Nathan E. Egge | 2cf03b1 | 2017-02-22 16:19:59 -0500 | [diff] [blame] | 39 | #if CONFIG_INSPECTION |
| 40 | #include "av1/decoder/inspection.h" |
| 41 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 42 | #include "av1/common/common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | #include "av1/common/entropy.h" |
| 44 | #include "av1/common/entropymode.h" |
Thomas Davies | 6519beb | 2016-10-19 14:46:07 +0100 | [diff] [blame] | 45 | #include "av1/common/entropymv.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 46 | #include "av1/common/idct.h" |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 47 | #include "av1/common/mvref_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 48 | #include "av1/common/pred_common.h" |
| 49 | #include "av1/common/quant_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 50 | #include "av1/common/reconinter.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 51 | #include "av1/common/reconintra.h" |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 52 | #if CONFIG_FRAME_SUPERRES |
| 53 | #include "av1/common/resize.h" |
| 54 | #endif // CONFIG_FRAME_SUPERRES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 55 | #include "av1/common/seg_common.h" |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 56 | #include "av1/common/thread_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | #include "av1/common/tile_common.h" |
| 58 | |
| 59 | #include "av1/decoder/decodeframe.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 60 | #include "av1/decoder/decodemv.h" |
| 61 | #include "av1/decoder/decoder.h" |
Angie Chiang | 133733c | 2017-03-17 12:50:20 -0700 | [diff] [blame] | 62 | #if CONFIG_LV_MAP |
| 63 | #include "av1/decoder/decodetxb.h" |
| 64 | #endif |
Jingning Han | 1aab818 | 2016-06-03 11:09:06 -0700 | [diff] [blame] | 65 | #include "av1/decoder/detokenize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | #include "av1/decoder/dsubexp.h" |
Angie Chiang | 85e3b96 | 2017-10-01 16:04:43 -0700 | [diff] [blame] | 67 | #include "av1/decoder/symbolrate.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 68 | |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 69 | #include "av1/common/warped_motion.h" |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 70 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 71 | #define MAX_AV1_HEADER_SIZE 80 |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 72 | #define ACCT_STR __func__ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | |
Luc Trudeau | e398028 | 2017-04-25 23:17:21 -0400 | [diff] [blame] | 74 | #if CONFIG_CFL |
| 75 | #include "av1/common/cfl.h" |
| 76 | #endif |
| 77 | |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 78 | #if CONFIG_STRIPED_LOOP_RESTORATION && !CONFIG_LOOP_RESTORATION |
| 79 | #error "striped_loop_restoration requires loop_restoration" |
| 80 | #endif |
| 81 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 82 | #if CONFIG_LOOP_RESTORATION |
| 83 | static void loop_restoration_read_sb_coeffs(const AV1_COMMON *const cm, |
| 84 | MACROBLOCKD *xd, |
| 85 | aom_reader *const r, int plane, |
| 86 | int rtile_idx); |
| 87 | #endif |
| 88 | |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 89 | static struct aom_read_bit_buffer *init_read_bit_buffer( |
| 90 | AV1Decoder *pbi, struct aom_read_bit_buffer *rb, const uint8_t *data, |
| 91 | const uint8_t *data_end, uint8_t clear_data[MAX_AV1_HEADER_SIZE]); |
| 92 | static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data, |
| 93 | size_t partition_size); |
| 94 | static size_t read_uncompressed_header(AV1Decoder *pbi, |
| 95 | struct aom_read_bit_buffer *rb); |
| 96 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 97 | static int is_compound_reference_allowed(const AV1_COMMON *cm) { |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 98 | #if CONFIG_ONE_SIDED_COMPOUND // Normative in decoder |
Arild Fuldseth (arilfuld) | 3889730 | 2017-04-27 20:03:03 +0200 | [diff] [blame] | 99 | return !frame_is_intra_only(cm); |
| 100 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 101 | int i; |
| 102 | if (frame_is_intra_only(cm)) return 0; |
| 103 | for (i = 1; i < INTER_REFS_PER_FRAME; ++i) |
| 104 | if (cm->ref_frame_sign_bias[i + 1] != cm->ref_frame_sign_bias[1]) return 1; |
| 105 | |
| 106 | return 0; |
Zoe Liu | 5a97883 | 2017-08-15 16:33:34 -0700 | [diff] [blame] | 107 | #endif // CONFIG_ONE_SIDED_COMPOUND |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 110 | static void setup_compound_reference_mode(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 111 | cm->comp_fwd_ref[0] = LAST_FRAME; |
| 112 | cm->comp_fwd_ref[1] = LAST2_FRAME; |
| 113 | cm->comp_fwd_ref[2] = LAST3_FRAME; |
| 114 | cm->comp_fwd_ref[3] = GOLDEN_FRAME; |
| 115 | |
| 116 | cm->comp_bwd_ref[0] = BWDREF_FRAME; |
Zoe Liu | 043c227 | 2017-07-19 12:40:29 -0700 | [diff] [blame] | 117 | cm->comp_bwd_ref[1] = ALTREF2_FRAME; |
| 118 | cm->comp_bwd_ref[2] = ALTREF_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static int read_is_valid(const uint8_t *start, size_t len, const uint8_t *end) { |
| 122 | return len != 0 && len <= (size_t)(end - start); |
| 123 | } |
| 124 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 125 | static int decode_unsigned_max(struct aom_read_bit_buffer *rb, int max) { |
| 126 | const int data = aom_rb_read_literal(rb, get_unsigned_bits(max)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 127 | return data > max ? max : data; |
| 128 | } |
| 129 | |
Debargha Mukherjee | 923b73d | 2017-10-31 18:11:34 -0700 | [diff] [blame] | 130 | #if CONFIG_SIMPLIFY_TX_MODE |
| 131 | static TX_MODE read_tx_mode(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
| 132 | if (cm->all_lossless) return ONLY_4X4; |
| 133 | #if CONFIG_VAR_TX_NO_TX_MODE |
| 134 | (void)rb; |
| 135 | return TX_MODE_SELECT; |
| 136 | #else |
| 137 | return aom_rb_read_bit(rb) ? TX_MODE_SELECT : TX_MODE_LARGEST; |
| 138 | #endif // CONFIG_VAR_TX_NO_TX_MODE |
| 139 | } |
| 140 | #else |
Thomas Daede | f636d5c | 2017-06-29 13:48:27 -0700 | [diff] [blame] | 141 | static TX_MODE read_tx_mode(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
Debargha Mukherjee | 18d38f6 | 2016-11-17 20:30:16 -0800 | [diff] [blame] | 142 | #if CONFIG_TX64X64 |
Yue Chen | eeacc4c | 2017-01-17 17:29:17 -0800 | [diff] [blame] | 143 | TX_MODE tx_mode; |
| 144 | #endif |
Thomas Daede | f636d5c | 2017-06-29 13:48:27 -0700 | [diff] [blame] | 145 | if (cm->all_lossless) return ONLY_4X4; |
Nathan E. Egge | a33304f | 2017-06-28 20:48:34 -0400 | [diff] [blame] | 146 | #if CONFIG_VAR_TX_NO_TX_MODE |
| 147 | (void)rb; |
| 148 | return TX_MODE_SELECT; |
| 149 | #else |
Yue Chen | eeacc4c | 2017-01-17 17:29:17 -0800 | [diff] [blame] | 150 | #if CONFIG_TX64X64 |
| 151 | tx_mode = aom_rb_read_bit(rb) ? TX_MODE_SELECT : aom_rb_read_literal(rb, 2); |
Debargha Mukherjee | 18d38f6 | 2016-11-17 20:30:16 -0800 | [diff] [blame] | 152 | if (tx_mode == ALLOW_32X32) tx_mode += aom_rb_read_bit(rb); |
| 153 | return tx_mode; |
| 154 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 155 | return aom_rb_read_bit(rb) ? TX_MODE_SELECT : aom_rb_read_literal(rb, 2); |
Debargha Mukherjee | 18d38f6 | 2016-11-17 20:30:16 -0800 | [diff] [blame] | 156 | #endif // CONFIG_TX64X64 |
Nathan E. Egge | a33304f | 2017-06-28 20:48:34 -0400 | [diff] [blame] | 157 | #endif // CONFIG_VAR_TX_NO_TX_MODE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 158 | } |
Debargha Mukherjee | 923b73d | 2017-10-31 18:11:34 -0700 | [diff] [blame] | 159 | #endif // CONFIG_SIMPLIFY_TX_MODE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 160 | |
Thomas Davies | 2e868ab | 2017-10-24 10:42:27 +0100 | [diff] [blame] | 161 | #if !CONFIG_NEW_MULTISYMBOL |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 162 | static void read_inter_mode_probs(FRAME_CONTEXT *fc, aom_reader *r) { |
Yaowu Xu | 8af861b | 2016-11-01 12:12:11 -0700 | [diff] [blame] | 163 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 164 | for (i = 0; i < NEWMV_MODE_CONTEXTS; ++i) |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 165 | av1_diff_update_prob(r, &fc->newmv_prob[i], ACCT_STR); |
Sarah Parker | 2b9ec2e | 2017-10-30 17:34:08 -0700 | [diff] [blame] | 166 | for (i = 0; i < GLOBALMV_MODE_CONTEXTS; ++i) |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 167 | av1_diff_update_prob(r, &fc->zeromv_prob[i], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 168 | for (i = 0; i < REFMV_MODE_CONTEXTS; ++i) |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 169 | av1_diff_update_prob(r, &fc->refmv_prob[i], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 170 | for (i = 0; i < DRL_MODE_CONTEXTS; ++i) |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 171 | av1_diff_update_prob(r, &fc->drl_prob[i], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | } |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 173 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 174 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 175 | static REFERENCE_MODE read_frame_reference_mode( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 176 | const AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 177 | if (is_compound_reference_allowed(cm)) { |
Zoe Liu | b05e5d1 | 2017-02-07 14:32:53 -0800 | [diff] [blame] | 178 | #if CONFIG_REF_ADAPT |
| 179 | return aom_rb_read_bit(rb) ? REFERENCE_MODE_SELECT : SINGLE_REFERENCE; |
| 180 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 181 | return aom_rb_read_bit(rb) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 182 | ? REFERENCE_MODE_SELECT |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 183 | : (aom_rb_read_bit(rb) ? COMPOUND_REFERENCE : SINGLE_REFERENCE); |
Zoe Liu | b05e5d1 | 2017-02-07 14:32:53 -0800 | [diff] [blame] | 184 | #endif // CONFIG_REF_ADAPT |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 185 | } else { |
| 186 | return SINGLE_REFERENCE; |
| 187 | } |
| 188 | } |
| 189 | |
Thomas Davies | 2e868ab | 2017-10-24 10:42:27 +0100 | [diff] [blame] | 190 | #if !CONFIG_NEW_MULTISYMBOL |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 191 | static void read_frame_reference_mode_probs(AV1_COMMON *cm, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 192 | FRAME_CONTEXT *const fc = cm->fc; |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 193 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 194 | |
| 195 | if (cm->reference_mode == REFERENCE_MODE_SELECT) |
| 196 | for (i = 0; i < COMP_INTER_CONTEXTS; ++i) |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 197 | av1_diff_update_prob(r, &fc->comp_inter_prob[i], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 198 | |
| 199 | if (cm->reference_mode != COMPOUND_REFERENCE) { |
| 200 | for (i = 0; i < REF_CONTEXTS; ++i) { |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 201 | int j; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 202 | for (j = 0; j < (SINGLE_REFS - 1); ++j) { |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 203 | av1_diff_update_prob(r, &fc->single_ref_prob[i][j], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if (cm->reference_mode != SINGLE_REFERENCE) { |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 209 | #if CONFIG_EXT_COMP_REFS |
| 210 | for (i = 0; i < COMP_REF_TYPE_CONTEXTS; ++i) |
| 211 | av1_diff_update_prob(r, &fc->comp_ref_type_prob[i], ACCT_STR); |
| 212 | |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 213 | for (i = 0; i < UNI_COMP_REF_CONTEXTS; ++i) { |
| 214 | int j; |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 215 | for (j = 0; j < (UNIDIR_COMP_REFS - 1); ++j) |
| 216 | av1_diff_update_prob(r, &fc->uni_comp_ref_prob[i][j], ACCT_STR); |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 217 | } |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 218 | #endif // CONFIG_EXT_COMP_REFS |
| 219 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 220 | for (i = 0; i < REF_CONTEXTS; ++i) { |
Thomas Davies | 894cc81 | 2017-06-22 17:51:33 +0100 | [diff] [blame] | 221 | int j; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 222 | for (j = 0; j < (FWD_REFS - 1); ++j) |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 223 | av1_diff_update_prob(r, &fc->comp_ref_prob[i][j], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 224 | for (j = 0; j < (BWD_REFS - 1); ++j) |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 225 | av1_diff_update_prob(r, &fc->comp_bwdref_prob[i][j], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 230 | static void update_mv_probs(aom_prob *p, int n, aom_reader *r) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 231 | int i; |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 232 | for (i = 0; i < n; ++i) av1_diff_update_prob(r, &p[i], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 235 | static void read_mv_probs(nmv_context *ctx, int allow_hp, aom_reader *r) { |
Thomas | 9ac5508 | 2016-09-23 18:04:17 +0100 | [diff] [blame] | 236 | int i; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 237 | if (allow_hp) { |
| 238 | for (i = 0; i < 2; ++i) { |
| 239 | nmv_component *const comp_ctx = &ctx->comps[i]; |
| 240 | update_mv_probs(&comp_ctx->class0_hp, 1, r); |
| 241 | update_mv_probs(&comp_ctx->hp, 1, r); |
| 242 | } |
| 243 | } |
| 244 | } |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 245 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 246 | |
| 247 | static void inverse_transform_block(MACROBLOCKD *xd, int plane, |
| 248 | const TX_TYPE tx_type, |
| 249 | const TX_SIZE tx_size, uint8_t *dst, |
Jingning Han | 1be1878 | 2016-10-21 11:48:15 -0700 | [diff] [blame] | 250 | int stride, int16_t scan_line, int eob) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 251 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
Jingning Han | 1be1878 | 2016-10-21 11:48:15 -0700 | [diff] [blame] | 252 | tran_low_t *const dqcoeff = pd->dqcoeff; |
Lester Lu | 708c1ec | 2017-06-14 14:54:49 -0700 | [diff] [blame] | 253 | av1_inverse_transform_block(xd, dqcoeff, |
Sarah Parker | 99e7daa | 2017-08-29 10:30:13 -0700 | [diff] [blame] | 254 | #if CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK |
| 255 | xd->mrc_mask, |
| 256 | #endif // CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK |
Sebastien Alaiwan | 3bac992 | 2017-11-02 12:34:41 +0100 | [diff] [blame] | 257 | plane, tx_type, tx_size, dst, stride, eob); |
Jingning Han | 1be1878 | 2016-10-21 11:48:15 -0700 | [diff] [blame] | 258 | memset(dqcoeff, 0, (scan_line + 1) * sizeof(dqcoeff[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Lester Lu | 9c52192 | 2017-07-11 11:16:45 -0700 | [diff] [blame] | 261 | static int get_block_idx(const MACROBLOCKD *xd, int plane, int row, int col) { |
| 262 | const int bsize = xd->mi[0]->mbmi.sb_type; |
| 263 | const struct macroblockd_plane *pd = &xd->plane[plane]; |
Lester Lu | 9c52192 | 2017-07-11 11:16:45 -0700 | [diff] [blame] | 264 | const BLOCK_SIZE plane_bsize = |
| 265 | AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd)); |
Lester Lu | 9c52192 | 2017-07-11 11:16:45 -0700 | [diff] [blame] | 266 | const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 267 | const TX_SIZE tx_size = av1_get_tx_size(plane, xd); |
Lester Lu | 9c52192 | 2017-07-11 11:16:45 -0700 | [diff] [blame] | 268 | const uint8_t txh_unit = tx_size_high_unit[tx_size]; |
| 269 | return row * max_blocks_wide + col * txh_unit; |
| 270 | } |
| 271 | |
Alex Converse | 8aca36d | 2017-01-31 12:33:15 -0800 | [diff] [blame] | 272 | static void predict_and_reconstruct_intra_block( |
| 273 | AV1_COMMON *cm, MACROBLOCKD *const xd, aom_reader *const r, |
| 274 | MB_MODE_INFO *const mbmi, int plane, int row, int col, TX_SIZE tx_size) { |
Luc Trudeau | 005feb6 | 2017-02-22 13:34:01 -0500 | [diff] [blame] | 275 | PLANE_TYPE plane_type = get_plane_type(plane); |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 276 | const int block_idx = get_block_idx(xd, plane, row, col); |
David Barker | 761b1ac | 2017-09-25 11:23:03 +0100 | [diff] [blame] | 277 | av1_predict_intra_block_facade(cm, xd, plane, block_idx, col, row, tx_size); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 278 | |
| 279 | if (!mbmi->skip) { |
Angie Chiang | 3d005e4 | 2017-04-02 16:31:35 -0700 | [diff] [blame] | 280 | struct macroblockd_plane *const pd = &xd->plane[plane]; |
Angie Chiang | 133733c | 2017-03-17 12:50:20 -0700 | [diff] [blame] | 281 | #if CONFIG_LV_MAP |
| 282 | int16_t max_scan_line = 0; |
Angie Chiang | 29b0fad | 2017-03-20 16:18:45 -0700 | [diff] [blame] | 283 | int eob; |
| 284 | av1_read_coeffs_txb_facade(cm, xd, r, row, col, block_idx, plane, |
Jingning Han | aba246d | 2017-06-14 12:00:16 -0700 | [diff] [blame] | 285 | pd->dqcoeff, tx_size, &max_scan_line, &eob); |
Angie Chiang | b6d770c | 2017-04-14 16:27:57 -0700 | [diff] [blame] | 286 | // tx_type will be read out in av1_read_coeffs_txb_facade |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 287 | const TX_TYPE tx_type = |
| 288 | av1_get_tx_type(plane_type, xd, row, col, block_idx, tx_size); |
Angie Chiang | 133733c | 2017-03-17 12:50:20 -0700 | [diff] [blame] | 289 | #else // CONFIG_LV_MAP |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 290 | const TX_TYPE tx_type = |
| 291 | av1_get_tx_type(plane_type, xd, row, col, block_idx, tx_size); |
Angie Chiang | bd99b38 | 2017-06-20 15:11:16 -0700 | [diff] [blame] | 292 | const SCAN_ORDER *scan_order = get_scan(cm, tx_size, tx_type, mbmi); |
Jingning Han | 1be1878 | 2016-10-21 11:48:15 -0700 | [diff] [blame] | 293 | int16_t max_scan_line = 0; |
| 294 | const int eob = |
Angie Chiang | 5c0568a | 2017-03-21 16:00:39 -0700 | [diff] [blame] | 295 | av1_decode_block_tokens(cm, xd, plane, scan_order, col, row, tx_size, |
Jingning Han | 1be1878 | 2016-10-21 11:48:15 -0700 | [diff] [blame] | 296 | tx_type, &max_scan_line, r, mbmi->segment_id); |
Angie Chiang | 133733c | 2017-03-17 12:50:20 -0700 | [diff] [blame] | 297 | #endif // CONFIG_LV_MAP |
Angie Chiang | 3d005e4 | 2017-04-02 16:31:35 -0700 | [diff] [blame] | 298 | if (eob) { |
| 299 | uint8_t *dst = |
| 300 | &pd->dst.buf[(row * pd->dst.stride + col) << tx_size_wide_log2[0]]; |
Sebastien Alaiwan | 7fc6b2a | 2017-11-02 18:14:50 +0100 | [diff] [blame] | 301 | inverse_transform_block(xd, plane, tx_type, tx_size, dst, pd->dst.stride, |
Hui Su | 400bf65 | 2017-08-15 15:42:19 -0700 | [diff] [blame] | 302 | max_scan_line, eob); |
Angie Chiang | 3d005e4 | 2017-04-02 16:31:35 -0700 | [diff] [blame] | 303 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 304 | } |
Luc Trudeau | e398028 | 2017-04-25 23:17:21 -0400 | [diff] [blame] | 305 | #if CONFIG_CFL |
Luc Trudeau | e784b3f | 2017-08-14 15:25:28 -0400 | [diff] [blame] | 306 | if (plane == AOM_PLANE_Y && xd->cfl->store_y) { |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 307 | cfl_store_tx(xd, row, col, tx_size, mbmi->sb_type); |
Luc Trudeau | e398028 | 2017-04-25 23:17:21 -0400 | [diff] [blame] | 308 | } |
Sebastien Alaiwan | c4559ca | 2017-09-27 09:47:30 +0200 | [diff] [blame] | 309 | #endif // CONFIG_CFL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Angie Chiang | ff6d890 | 2016-10-21 11:02:09 -0700 | [diff] [blame] | 312 | static void decode_reconstruct_tx(AV1_COMMON *cm, MACROBLOCKD *const xd, |
| 313 | aom_reader *r, MB_MODE_INFO *const mbmi, |
Jingning Han | 8fd62b7 | 2016-10-21 12:55:54 -0700 | [diff] [blame] | 314 | int plane, BLOCK_SIZE plane_bsize, |
Jingning Han | a65f305 | 2017-06-23 10:52:05 -0700 | [diff] [blame] | 315 | int blk_row, int blk_col, int block, |
| 316 | TX_SIZE tx_size, int *eob_total) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 317 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 318 | const BLOCK_SIZE bsize = txsize_to_bsize[tx_size]; |
| 319 | const int tx_row = blk_row >> (1 - pd->subsampling_y); |
| 320 | const int tx_col = blk_col >> (1 - pd->subsampling_x); |
| 321 | const TX_SIZE plane_tx_size = |
Debargha Mukherjee | 2f12340 | 2016-08-30 17:43:38 -0700 | [diff] [blame] | 322 | plane ? uv_txsize_lookup[bsize][mbmi->inter_tx_size[tx_row][tx_col]][0][0] |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 323 | : mbmi->inter_tx_size[tx_row][tx_col]; |
Jingning Han | 5f61426 | 2016-10-27 14:27:43 -0700 | [diff] [blame] | 324 | // Scale to match transform block unit. |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 325 | const int max_blocks_high = max_block_high(xd, plane_bsize, plane); |
| 326 | const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 327 | |
| 328 | if (blk_row >= max_blocks_high || blk_col >= max_blocks_wide) return; |
| 329 | |
| 330 | if (tx_size == plane_tx_size) { |
Luc Trudeau | 005feb6 | 2017-02-22 13:34:01 -0500 | [diff] [blame] | 331 | PLANE_TYPE plane_type = get_plane_type(plane); |
Angie Chiang | 133733c | 2017-03-17 12:50:20 -0700 | [diff] [blame] | 332 | #if CONFIG_LV_MAP |
Angie Chiang | 133733c | 2017-03-17 12:50:20 -0700 | [diff] [blame] | 333 | int16_t max_scan_line = 0; |
Angie Chiang | 29b0fad | 2017-03-20 16:18:45 -0700 | [diff] [blame] | 334 | int eob; |
Jingning Han | a65f305 | 2017-06-23 10:52:05 -0700 | [diff] [blame] | 335 | av1_read_coeffs_txb_facade(cm, xd, r, blk_row, blk_col, block, plane, |
Jingning Han | aba246d | 2017-06-14 12:00:16 -0700 | [diff] [blame] | 336 | pd->dqcoeff, tx_size, &max_scan_line, &eob); |
Angie Chiang | b6d770c | 2017-04-14 16:27:57 -0700 | [diff] [blame] | 337 | // tx_type will be read out in av1_read_coeffs_txb_facade |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 338 | const TX_TYPE tx_type = |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 339 | av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, plane_tx_size); |
Angie Chiang | 133733c | 2017-03-17 12:50:20 -0700 | [diff] [blame] | 340 | #else // CONFIG_LV_MAP |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 341 | const TX_TYPE tx_type = |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 342 | av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, plane_tx_size); |
Angie Chiang | bd99b38 | 2017-06-20 15:11:16 -0700 | [diff] [blame] | 343 | const SCAN_ORDER *sc = get_scan(cm, plane_tx_size, tx_type, mbmi); |
Jingning Han | 1be1878 | 2016-10-21 11:48:15 -0700 | [diff] [blame] | 344 | int16_t max_scan_line = 0; |
Angie Chiang | 5c0568a | 2017-03-21 16:00:39 -0700 | [diff] [blame] | 345 | const int eob = av1_decode_block_tokens( |
| 346 | cm, xd, plane, sc, blk_col, blk_row, plane_tx_size, tx_type, |
| 347 | &max_scan_line, r, mbmi->segment_id); |
Angie Chiang | 133733c | 2017-03-17 12:50:20 -0700 | [diff] [blame] | 348 | #endif // CONFIG_LV_MAP |
Sebastien Alaiwan | 7fc6b2a | 2017-11-02 18:14:50 +0100 | [diff] [blame] | 349 | inverse_transform_block(xd, plane, tx_type, plane_tx_size, |
Jingning Han | 9ca05b7 | 2017-01-03 14:41:36 -0800 | [diff] [blame] | 350 | &pd->dst.buf[(blk_row * pd->dst.stride + blk_col) |
| 351 | << tx_size_wide_log2[0]], |
| 352 | pd->dst.stride, max_scan_line, eob); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 353 | *eob_total += eob; |
| 354 | } else { |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 355 | #if CONFIG_RECT_TX_EXT |
| 356 | int is_qttx = plane_tx_size == quarter_txsize_lookup[plane_bsize]; |
| 357 | const TX_SIZE sub_txs = is_qttx ? plane_tx_size : sub_tx_size_map[tx_size]; |
| 358 | if (is_qttx) assert(blk_row == 0 && blk_col == 0 && block == 0); |
| 359 | #else |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 360 | const TX_SIZE sub_txs = sub_tx_size_map[tx_size]; |
Urvang Joshi | dff57e0 | 2017-09-29 11:15:48 -0700 | [diff] [blame] | 361 | assert(IMPLIES(tx_size <= TX_4X4, sub_txs == tx_size)); |
| 362 | assert(IMPLIES(tx_size > TX_4X4, sub_txs < tx_size)); |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 363 | #endif |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 364 | const int bsl = tx_size_wide_unit[sub_txs]; |
Jingning Han | a65f305 | 2017-06-23 10:52:05 -0700 | [diff] [blame] | 365 | int sub_step = tx_size_wide_unit[sub_txs] * tx_size_high_unit[sub_txs]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 366 | int i; |
| 367 | |
| 368 | assert(bsl > 0); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 369 | |
| 370 | for (i = 0; i < 4; ++i) { |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 371 | #if CONFIG_RECT_TX_EXT |
| 372 | int is_wide_tx = tx_size_wide_unit[sub_txs] > tx_size_high_unit[sub_txs]; |
| 373 | const int offsetr = |
| 374 | is_qttx ? (is_wide_tx ? i * tx_size_high_unit[sub_txs] : 0) |
| 375 | : blk_row + ((i >> 1) * bsl); |
| 376 | const int offsetc = |
| 377 | is_qttx ? (is_wide_tx ? 0 : i * tx_size_wide_unit[sub_txs]) |
| 378 | : blk_col + (i & 0x01) * bsl; |
| 379 | #else |
Jingning Han | 5f61426 | 2016-10-27 14:27:43 -0700 | [diff] [blame] | 380 | const int offsetr = blk_row + (i >> 1) * bsl; |
| 381 | const int offsetc = blk_col + (i & 0x01) * bsl; |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 382 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 383 | |
| 384 | if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue; |
| 385 | |
Jingning Han | 8fd62b7 | 2016-10-21 12:55:54 -0700 | [diff] [blame] | 386 | decode_reconstruct_tx(cm, xd, r, mbmi, plane, plane_bsize, offsetr, |
Jingning Han | a65f305 | 2017-06-23 10:52:05 -0700 | [diff] [blame] | 387 | offsetc, block, sub_txs, eob_total); |
| 388 | block += sub_step; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 392 | |
Angie Chiang | 44701f2 | 2017-02-27 10:36:44 -0800 | [diff] [blame] | 393 | static void set_offsets(AV1_COMMON *const cm, MACROBLOCKD *const xd, |
| 394 | BLOCK_SIZE bsize, int mi_row, int mi_col, int bw, |
| 395 | int bh, int x_mis, int y_mis) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 396 | const int offset = mi_row * cm->mi_stride + mi_col; |
| 397 | int x, y; |
| 398 | const TileInfo *const tile = &xd->tile; |
| 399 | |
| 400 | xd->mi = cm->mi_grid_visible + offset; |
| 401 | xd->mi[0] = &cm->mi[offset]; |
| 402 | // TODO(slavarnway): Generate sb_type based on bwl and bhl, instead of |
| 403 | // passing bsize from decode_partition(). |
| 404 | xd->mi[0]->mbmi.sb_type = bsize; |
Angie Chiang | 394c337 | 2016-11-03 11:13:15 -0700 | [diff] [blame] | 405 | #if CONFIG_RD_DEBUG |
| 406 | xd->mi[0]->mbmi.mi_row = mi_row; |
| 407 | xd->mi[0]->mbmi.mi_col = mi_col; |
| 408 | #endif |
Luc Trudeau | 780d249 | 2017-06-15 22:26:41 -0400 | [diff] [blame] | 409 | #if CONFIG_CFL |
| 410 | xd->cfl->mi_row = mi_row; |
| 411 | xd->cfl->mi_col = mi_col; |
| 412 | #endif |
Yunqing Wang | b90a97a | 2017-10-24 11:50:15 -0700 | [diff] [blame] | 413 | |
| 414 | assert(x_mis && y_mis); |
| 415 | for (x = 1; x < x_mis; ++x) xd->mi[x] = xd->mi[0]; |
| 416 | int idx = cm->mi_stride; |
| 417 | for (y = 1; y < y_mis; ++y) { |
| 418 | memcpy(&xd->mi[idx], &xd->mi[0], x_mis * sizeof(xd->mi[0])); |
| 419 | idx += cm->mi_stride; |
| 420 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 421 | |
Jingning Han | faad0e1 | 2016-12-07 10:54:57 -0800 | [diff] [blame] | 422 | set_plane_n4(xd, bw, bh); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 423 | set_skip_context(xd, mi_row, mi_col); |
| 424 | |
Urvang Joshi | 359dc2b | 2017-04-27 15:41:47 -0700 | [diff] [blame] | 425 | // Distance of Mb to the various image edges. These are specified to 8th pel |
| 426 | // as they are always compared to values that are in 1/8th pel units |
| 427 | set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 428 | #if CONFIG_DEPENDENT_HORZTILES |
Urvang Joshi | 359dc2b | 2017-04-27 15:41:47 -0700 | [diff] [blame] | 429 | cm->dependent_horz_tiles, |
| 430 | #endif // CONFIG_DEPENDENT_HORZTILES |
| 431 | cm->mi_rows, cm->mi_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 432 | |
Jingning Han | 91d9a79 | 2017-04-18 12:01:52 -0700 | [diff] [blame] | 433 | av1_setup_dst_planes(xd->plane, bsize, get_frame_new_buffer(cm), mi_row, |
| 434 | mi_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 437 | static void decode_mbmi_block(AV1Decoder *const pbi, MACROBLOCKD *const xd, |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 438 | int mi_row, int mi_col, aom_reader *r, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 439 | #if CONFIG_EXT_PARTITION_TYPES |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 440 | PARTITION_TYPE partition, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 441 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 442 | BLOCK_SIZE bsize) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 443 | AV1_COMMON *const cm = &pbi->common; |
Jingning Han | 85dc03f | 2016-12-06 16:03:10 -0800 | [diff] [blame] | 444 | const int bw = mi_size_wide[bsize]; |
| 445 | const int bh = mi_size_high[bsize]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 446 | const int x_mis = AOMMIN(bw, cm->mi_cols - mi_col); |
| 447 | const int y_mis = AOMMIN(bh, cm->mi_rows - mi_row); |
Nathan E. Egge | ebbd479 | 2016-10-05 19:30:15 -0400 | [diff] [blame] | 448 | |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 449 | #if CONFIG_ACCOUNTING |
| 450 | aom_accounting_set_context(&pbi->accounting, mi_col, mi_row); |
| 451 | #endif |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 452 | set_offsets(cm, xd, bsize, mi_row, mi_col, bw, bh, x_mis, y_mis); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 453 | #if CONFIG_EXT_PARTITION_TYPES |
| 454 | xd->mi[0]->mbmi.partition = partition; |
| 455 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 456 | av1_read_mode_info(pbi, xd, mi_row, mi_col, r, x_mis, y_mis); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 457 | if (bsize >= BLOCK_8X8 && (cm->subsampling_x || cm->subsampling_y)) { |
| 458 | const BLOCK_SIZE uv_subsize = |
| 459 | ss_size_lookup[bsize][cm->subsampling_x][cm->subsampling_y]; |
| 460 | if (uv_subsize == BLOCK_INVALID) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 461 | aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 462 | "Invalid block size."); |
| 463 | } |
| 464 | |
Angie Chiang | d0916d9 | 2017-03-10 17:54:18 -0800 | [diff] [blame] | 465 | int reader_corrupted_flag = aom_reader_has_error(r); |
| 466 | aom_merge_corrupted_flag(&xd->corrupted, reader_corrupted_flag); |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | static void decode_token_and_recon_block(AV1Decoder *const pbi, |
| 470 | MACROBLOCKD *const xd, int mi_row, |
| 471 | int mi_col, aom_reader *r, |
| 472 | BLOCK_SIZE bsize) { |
| 473 | AV1_COMMON *const cm = &pbi->common; |
| 474 | const int bw = mi_size_wide[bsize]; |
| 475 | const int bh = mi_size_high[bsize]; |
| 476 | const int x_mis = AOMMIN(bw, cm->mi_cols - mi_col); |
| 477 | const int y_mis = AOMMIN(bh, cm->mi_rows - mi_row); |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 478 | |
Angie Chiang | 44701f2 | 2017-02-27 10:36:44 -0800 | [diff] [blame] | 479 | set_offsets(cm, xd, bsize, mi_row, mi_col, bw, bh, x_mis, y_mis); |
| 480 | MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 481 | #if CONFIG_CFL |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 482 | CFL_CTX *const cfl = xd->cfl; |
| 483 | cfl->is_chroma_reference = is_chroma_reference( |
| 484 | mi_row, mi_col, bsize, cfl->subsampling_x, cfl->subsampling_y); |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 485 | #endif // CONFIG_CFL |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 486 | |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 487 | if (cm->delta_q_present_flag) { |
| 488 | int i; |
| 489 | for (i = 0; i < MAX_SEGMENTS; i++) { |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 490 | #if CONFIG_EXT_DELTA_Q |
Cheng Chen | 49d30e6 | 2017-08-28 20:59:27 -0700 | [diff] [blame] | 491 | const int current_qindex = |
| 492 | av1_get_qindex(&cm->seg, i, xd->current_qindex); |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 493 | #else |
Cheng Chen | 49d30e6 | 2017-08-28 20:59:27 -0700 | [diff] [blame] | 494 | const int current_qindex = xd->current_qindex; |
| 495 | #endif // CONFIG_EXT_DELTA_Q |
| 496 | int j; |
| 497 | for (j = 0; j < MAX_MB_PLANE; ++j) { |
| 498 | const int dc_delta_q = j == 0 ? cm->y_dc_delta_q : cm->uv_dc_delta_q; |
| 499 | const int ac_delta_q = j == 0 ? 0 : cm->uv_ac_delta_q; |
| 500 | |
| 501 | xd->plane[j].seg_dequant[i][0] = |
| 502 | av1_dc_quant(current_qindex, dc_delta_q, cm->bit_depth); |
| 503 | xd->plane[j].seg_dequant[i][1] = |
| 504 | av1_ac_quant(current_qindex, ac_delta_q, cm->bit_depth); |
| 505 | } |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 506 | } |
| 507 | } |
Timothy B. Terriberry | a2d5cde | 2017-05-10 18:33:50 -0700 | [diff] [blame] | 508 | if (mbmi->skip) av1_reset_skip_context(xd, mi_row, mi_col, bsize); |
Jingning Han | d39cc72 | 2016-12-02 14:03:26 -0800 | [diff] [blame] | 509 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 510 | if (!is_inter_block(mbmi)) { |
| 511 | int plane; |
Yushin Cho | a881039 | 2017-09-06 15:16:14 -0700 | [diff] [blame] | 512 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 513 | for (plane = 0; plane <= 1; ++plane) { |
| 514 | if (mbmi->palette_mode_info.palette_size[plane]) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 515 | av1_decode_palette_tokens(xd, plane, r); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 516 | } |
Yushin Cho | a881039 | 2017-09-06 15:16:14 -0700 | [diff] [blame] | 517 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
| 519 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 520 | const TX_SIZE tx_size = av1_get_tx_size(plane, xd); |
Jingning Han | 2d64f12 | 2016-10-21 12:44:29 -0700 | [diff] [blame] | 521 | const int stepr = tx_size_high_unit[tx_size]; |
| 522 | const int stepc = tx_size_wide_unit[tx_size]; |
Jingning Han | c20dc8e | 2017-02-17 15:37:28 -0800 | [diff] [blame] | 523 | const BLOCK_SIZE plane_bsize = |
| 524 | AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 525 | int row, col; |
Jingning Han | bafee8d | 2016-12-02 10:25:03 -0800 | [diff] [blame] | 526 | const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); |
| 527 | const int max_blocks_high = max_block_high(xd, plane_bsize, plane); |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 528 | if (!is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x, |
| 529 | pd->subsampling_y)) |
Jingning Han | c20dc8e | 2017-02-17 15:37:28 -0800 | [diff] [blame] | 530 | continue; |
Jingning Han | 5b70174 | 2017-07-19 14:39:07 -0700 | [diff] [blame] | 531 | int blk_row, blk_col; |
| 532 | const BLOCK_SIZE max_unit_bsize = get_plane_block_size(BLOCK_64X64, pd); |
| 533 | int mu_blocks_wide = |
| 534 | block_size_wide[max_unit_bsize] >> tx_size_wide_log2[0]; |
| 535 | int mu_blocks_high = |
| 536 | block_size_high[max_unit_bsize] >> tx_size_high_log2[0]; |
| 537 | mu_blocks_wide = AOMMIN(max_blocks_wide, mu_blocks_wide); |
| 538 | mu_blocks_high = AOMMIN(max_blocks_high, mu_blocks_high); |
Jingning Han | c20dc8e | 2017-02-17 15:37:28 -0800 | [diff] [blame] | 539 | |
Jingning Han | 5b70174 | 2017-07-19 14:39:07 -0700 | [diff] [blame] | 540 | for (row = 0; row < max_blocks_high; row += mu_blocks_high) { |
Luc Trudeau | da9397a | 2017-07-21 12:00:22 -0400 | [diff] [blame] | 541 | const int unit_height = AOMMIN(mu_blocks_high + row, max_blocks_high); |
Jingning Han | 5b70174 | 2017-07-19 14:39:07 -0700 | [diff] [blame] | 542 | for (col = 0; col < max_blocks_wide; col += mu_blocks_wide) { |
Jingning Han | 5b70174 | 2017-07-19 14:39:07 -0700 | [diff] [blame] | 543 | const int unit_width = AOMMIN(mu_blocks_wide + col, max_blocks_wide); |
| 544 | |
| 545 | for (blk_row = row; blk_row < unit_height; blk_row += stepr) |
| 546 | for (blk_col = col; blk_col < unit_width; blk_col += stepc) |
| 547 | predict_and_reconstruct_intra_block(cm, xd, r, mbmi, plane, |
| 548 | blk_row, blk_col, tx_size); |
| 549 | } |
| 550 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 551 | } |
| 552 | } else { |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 553 | int ref; |
| 554 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 555 | #if CONFIG_COMPOUND_SINGLEREF |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 556 | for (ref = 0; ref < 1 + is_inter_anyref_comp_mode(mbmi->mode); ++ref) |
| 557 | #else |
| 558 | for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 559 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 560 | { |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 561 | const MV_REFERENCE_FRAME frame = |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 562 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 563 | has_second_ref(mbmi) ? mbmi->ref_frame[ref] : mbmi->ref_frame[0]; |
| 564 | #else |
Yushin Cho | 127c583 | 2017-07-28 16:39:04 -0700 | [diff] [blame] | 565 | mbmi->ref_frame[ref]; |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 566 | #endif // CONFIG_COMPOUND_SINGLEREF |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 567 | if (frame < LAST_FRAME) { |
| 568 | #if CONFIG_INTRABC |
| 569 | assert(is_intrabc_block(mbmi)); |
| 570 | assert(frame == INTRA_FRAME); |
| 571 | assert(ref == 0); |
| 572 | #else |
| 573 | assert(0); |
| 574 | #endif // CONFIG_INTRABC |
| 575 | } else { |
| 576 | RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME]; |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 577 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 578 | xd->block_refs[ref] = ref_buf; |
| 579 | if ((!av1_is_valid_scale(&ref_buf->sf))) |
| 580 | aom_internal_error(xd->error_info, AOM_CODEC_UNSUP_BITSTREAM, |
| 581 | "Reference frame has invalid dimensions"); |
| 582 | av1_setup_pre_planes(xd, ref, ref_buf->buf, mi_row, mi_col, |
| 583 | &ref_buf->sf); |
| 584 | } |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 585 | } |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 586 | |
Jingning Han | c44009c | 2017-05-06 11:36:49 -0700 | [diff] [blame] | 587 | av1_build_inter_predictors_sb(cm, xd, mi_row, mi_col, NULL, bsize); |
Sarah Parker | 4c10a3c | 2017-04-10 19:37:59 -0700 | [diff] [blame] | 588 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 589 | if (mbmi->motion_mode == OBMC_CAUSAL) { |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 590 | #if CONFIG_NCOBMC |
| 591 | av1_build_ncobmc_inter_predictors_sb(cm, xd, mi_row, mi_col); |
| 592 | #else |
Yue Chen | 894fcce | 2016-10-21 16:50:52 -0700 | [diff] [blame] | 593 | av1_build_obmc_inter_predictors_sb(cm, xd, mi_row, mi_col); |
Yue Chen | f27b160 | 2017-01-13 11:11:43 -0800 | [diff] [blame] | 594 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 595 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 596 | // Reconstruction |
| 597 | if (!mbmi->skip) { |
| 598 | int eobtotal = 0; |
| 599 | int plane; |
| 600 | |
| 601 | for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
| 602 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
Jingning Han | c20dc8e | 2017-02-17 15:37:28 -0800 | [diff] [blame] | 603 | const BLOCK_SIZE plane_bsize = |
| 604 | AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd)); |
Jingning Han | bafee8d | 2016-12-02 10:25:03 -0800 | [diff] [blame] | 605 | const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); |
| 606 | const int max_blocks_high = max_block_high(xd, plane_bsize, plane); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 607 | int row, col; |
Jingning Han | c20dc8e | 2017-02-17 15:37:28 -0800 | [diff] [blame] | 608 | |
Jingning Han | d3a6443 | 2017-04-06 17:04:17 -0700 | [diff] [blame] | 609 | if (!is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x, |
| 610 | pd->subsampling_y)) |
Jingning Han | c20dc8e | 2017-02-17 15:37:28 -0800 | [diff] [blame] | 611 | continue; |
Jingning Han | c20dc8e | 2017-02-17 15:37:28 -0800 | [diff] [blame] | 612 | |
Jingning Han | c2b797f | 2017-07-19 09:37:11 -0700 | [diff] [blame] | 613 | const BLOCK_SIZE max_unit_bsize = get_plane_block_size(BLOCK_64X64, pd); |
| 614 | int mu_blocks_wide = |
| 615 | block_size_wide[max_unit_bsize] >> tx_size_wide_log2[0]; |
| 616 | int mu_blocks_high = |
| 617 | block_size_high[max_unit_bsize] >> tx_size_high_log2[0]; |
| 618 | |
| 619 | mu_blocks_wide = AOMMIN(max_blocks_wide, mu_blocks_wide); |
| 620 | mu_blocks_high = AOMMIN(max_blocks_high, mu_blocks_high); |
| 621 | |
Rupert Swarbrick | 4e7b7d6 | 2017-09-28 17:30:44 +0100 | [diff] [blame] | 622 | const TX_SIZE max_tx_size = get_vartx_max_txsize( |
| 623 | mbmi, plane_bsize, pd->subsampling_x || pd->subsampling_y); |
Jingning Han | f64062f | 2016-11-02 16:22:18 -0700 | [diff] [blame] | 624 | const int bh_var_tx = tx_size_high_unit[max_tx_size]; |
| 625 | const int bw_var_tx = tx_size_wide_unit[max_tx_size]; |
Jingning Han | a65f305 | 2017-06-23 10:52:05 -0700 | [diff] [blame] | 626 | int block = 0; |
| 627 | int step = |
| 628 | tx_size_wide_unit[max_tx_size] * tx_size_high_unit[max_tx_size]; |
Jingning Han | c2b797f | 2017-07-19 09:37:11 -0700 | [diff] [blame] | 629 | |
| 630 | for (row = 0; row < max_blocks_high; row += mu_blocks_high) { |
| 631 | for (col = 0; col < max_blocks_wide; col += mu_blocks_wide) { |
| 632 | int blk_row, blk_col; |
| 633 | const int unit_height = |
| 634 | AOMMIN(mu_blocks_high + row, max_blocks_high); |
| 635 | const int unit_width = |
| 636 | AOMMIN(mu_blocks_wide + col, max_blocks_wide); |
| 637 | for (blk_row = row; blk_row < unit_height; blk_row += bh_var_tx) { |
| 638 | for (blk_col = col; blk_col < unit_width; blk_col += bw_var_tx) { |
| 639 | decode_reconstruct_tx(cm, xd, r, mbmi, plane, plane_bsize, |
| 640 | blk_row, blk_col, block, max_tx_size, |
| 641 | &eobtotal); |
| 642 | block += step; |
| 643 | } |
| 644 | } |
Jingning Han | a65f305 | 2017-06-23 10:52:05 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 647 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 648 | } |
| 649 | } |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 650 | #if CONFIG_CFL |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 651 | if (mbmi->uv_mode != UV_CFL_PRED) { |
Luc Trudeau | b05eeae | 2017-08-18 15:14:30 -0400 | [diff] [blame] | 652 | if (!cfl->is_chroma_reference && is_inter_block(mbmi)) { |
| 653 | cfl_store_block(xd, mbmi->sb_type, mbmi->tx_size); |
| 654 | } |
| 655 | } |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 656 | #endif // CONFIG_CFL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 657 | |
Angie Chiang | d0916d9 | 2017-03-10 17:54:18 -0800 | [diff] [blame] | 658 | int reader_corrupted_flag = aom_reader_has_error(r); |
| 659 | aom_merge_corrupted_flag(&xd->corrupted, reader_corrupted_flag); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 662 | #if NC_MODE_INFO |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 663 | static void detoken_and_recon_sb(AV1Decoder *const pbi, MACROBLOCKD *const xd, |
| 664 | int mi_row, int mi_col, aom_reader *r, |
| 665 | BLOCK_SIZE bsize) { |
| 666 | AV1_COMMON *const cm = &pbi->common; |
| 667 | const int hbs = mi_size_wide[bsize] >> 1; |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 668 | #if CONFIG_EXT_PARTITION_TYPES |
| 669 | BLOCK_SIZE bsize2 = get_subsize(bsize, PARTITION_SPLIT); |
| 670 | #endif |
| 671 | PARTITION_TYPE partition; |
| 672 | BLOCK_SIZE subsize; |
| 673 | const int has_rows = (mi_row + hbs) < cm->mi_rows; |
| 674 | const int has_cols = (mi_col + hbs) < cm->mi_cols; |
| 675 | |
| 676 | if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return; |
| 677 | |
| 678 | partition = get_partition(cm, mi_row, mi_col, bsize); |
| 679 | subsize = subsize_lookup[partition][bsize]; |
| 680 | |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 681 | switch (partition) { |
| 682 | case PARTITION_NONE: |
| 683 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, bsize); |
| 684 | break; |
| 685 | case PARTITION_HORZ: |
| 686 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, subsize); |
| 687 | if (has_rows) |
| 688 | decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col, r, subsize); |
| 689 | break; |
| 690 | case PARTITION_VERT: |
| 691 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, subsize); |
| 692 | if (has_cols) |
| 693 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col + hbs, r, subsize); |
| 694 | break; |
| 695 | case PARTITION_SPLIT: |
| 696 | detoken_and_recon_sb(pbi, xd, mi_row, mi_col, r, subsize); |
| 697 | detoken_and_recon_sb(pbi, xd, mi_row, mi_col + hbs, r, subsize); |
| 698 | detoken_and_recon_sb(pbi, xd, mi_row + hbs, mi_col, r, subsize); |
| 699 | detoken_and_recon_sb(pbi, xd, mi_row + hbs, mi_col + hbs, r, subsize); |
| 700 | break; |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 701 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 702 | #if CONFIG_EXT_PARTITION_TYPES_AB |
| 703 | #error NC_MODE_INFO+MOTION_VAR not yet supported for new HORZ/VERT_AB partitions |
| 704 | #endif |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 705 | case PARTITION_HORZ_A: |
| 706 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, bsize2); |
| 707 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col + hbs, r, bsize2); |
| 708 | decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col, r, subsize); |
| 709 | break; |
| 710 | case PARTITION_HORZ_B: |
| 711 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, subsize); |
| 712 | decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col, r, bsize2); |
| 713 | decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col + hbs, r, |
| 714 | bsize2); |
| 715 | break; |
| 716 | case PARTITION_VERT_A: |
| 717 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, bsize2); |
| 718 | decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col, r, bsize2); |
| 719 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col + hbs, r, subsize); |
| 720 | break; |
| 721 | case PARTITION_VERT_B: |
| 722 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, subsize); |
| 723 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col + hbs, r, bsize2); |
| 724 | decode_token_and_recon_block(pbi, xd, mi_row + hbs, mi_col + hbs, r, |
| 725 | bsize2); |
| 726 | break; |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 727 | #endif |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 728 | default: assert(0 && "Invalid partition type"); |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | #endif |
| 732 | |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 733 | static void decode_block(AV1Decoder *const pbi, MACROBLOCKD *const xd, |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 734 | int mi_row, int mi_col, aom_reader *r, |
| 735 | #if CONFIG_EXT_PARTITION_TYPES |
| 736 | PARTITION_TYPE partition, |
| 737 | #endif // CONFIG_EXT_PARTITION_TYPES |
| 738 | BLOCK_SIZE bsize) { |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 739 | decode_mbmi_block(pbi, xd, mi_row, mi_col, r, |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 740 | #if CONFIG_EXT_PARTITION_TYPES |
| 741 | partition, |
| 742 | #endif |
| 743 | bsize); |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 744 | |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 745 | #if !(NC_MODE_INFO) |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 746 | decode_token_and_recon_block(pbi, xd, mi_row, mi_col, r, bsize); |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 747 | #endif |
Yue Chen | 64550b6 | 2017-01-12 12:18:22 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 750 | static PARTITION_TYPE read_partition(AV1_COMMON *cm, MACROBLOCKD *xd, |
| 751 | int mi_row, int mi_col, aom_reader *r, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 752 | int has_rows, int has_cols, |
Jingning Han | 1beb010 | 2016-12-07 11:08:30 -0800 | [diff] [blame] | 753 | BLOCK_SIZE bsize) { |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 754 | #if CONFIG_UNPOISON_PARTITION_CTX |
| 755 | const int ctx = |
| 756 | partition_plane_context(xd, mi_row, mi_col, has_rows, has_cols, bsize); |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 757 | #else |
Jingning Han | 1beb010 | 2016-12-07 11:08:30 -0800 | [diff] [blame] | 758 | const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); |
Alex Converse | 55c6bde | 2017-01-12 15:55:31 -0800 | [diff] [blame] | 759 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 760 | PARTITION_TYPE p; |
Thomas Davies | c2ec0e4 | 2017-01-11 16:27:27 +0000 | [diff] [blame] | 761 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
| 762 | (void)cm; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 763 | |
Jingning Han | 5fe79db | 2017-03-27 15:10:30 -0700 | [diff] [blame] | 764 | aom_cdf_prob *partition_cdf = (ctx >= 0) ? ec_ctx->partition_cdf[ctx] : NULL; |
Jingning Han | 5fe79db | 2017-03-27 15:10:30 -0700 | [diff] [blame] | 765 | |
Rupert Swarbrick | b95cf12 | 2017-07-31 16:51:12 +0100 | [diff] [blame] | 766 | if (has_rows && has_cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 767 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 768 | const int num_partition_types = |
| 769 | (mi_width_log2_lookup[bsize] > mi_width_log2_lookup[BLOCK_8X8]) |
| 770 | ? EXT_PARTITION_TYPES |
| 771 | : PARTITION_TYPES; |
Alex Converse | 57795a4 | 2017-03-14 12:18:25 -0700 | [diff] [blame] | 772 | #else |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 773 | const int num_partition_types = PARTITION_TYPES; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 774 | #endif // CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 775 | p = (PARTITION_TYPE)aom_read_symbol(r, partition_cdf, num_partition_types, |
| 776 | ACCT_STR); |
Rupert Swarbrick | b95cf12 | 2017-07-31 16:51:12 +0100 | [diff] [blame] | 777 | } else if (!has_rows && has_cols) { |
Stanislav Vitvitskyy | 8711cf5 | 2017-08-18 15:17:57 -0700 | [diff] [blame] | 778 | assert(bsize > BLOCK_8X8); |
| 779 | aom_cdf_prob cdf[2]; |
| 780 | partition_gather_vert_alike(cdf, partition_cdf); |
| 781 | assert(cdf[1] == AOM_ICDF(CDF_PROB_TOP)); |
| 782 | p = aom_read_cdf(r, cdf, 2, ACCT_STR) ? PARTITION_SPLIT : PARTITION_HORZ; |
| 783 | // gather cols |
Rupert Swarbrick | b95cf12 | 2017-07-31 16:51:12 +0100 | [diff] [blame] | 784 | } else if (has_rows && !has_cols) { |
Stanislav Vitvitskyy | 8711cf5 | 2017-08-18 15:17:57 -0700 | [diff] [blame] | 785 | assert(bsize > BLOCK_8X8); |
| 786 | aom_cdf_prob cdf[2]; |
| 787 | partition_gather_horz_alike(cdf, partition_cdf); |
| 788 | assert(cdf[1] == AOM_ICDF(CDF_PROB_TOP)); |
| 789 | p = aom_read_cdf(r, cdf, 2, ACCT_STR) ? PARTITION_SPLIT : PARTITION_VERT; |
Rupert Swarbrick | b95cf12 | 2017-07-31 16:51:12 +0100 | [diff] [blame] | 790 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 791 | p = PARTITION_SPLIT; |
Rupert Swarbrick | b95cf12 | 2017-07-31 16:51:12 +0100 | [diff] [blame] | 792 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 793 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 794 | return p; |
| 795 | } |
| 796 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 797 | // TODO(slavarnway): eliminate bsize and subsize in future commits |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 798 | static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 799 | int mi_row, int mi_col, aom_reader *r, |
Jingning Han | ea10ad4 | 2017-07-20 11:19:08 -0700 | [diff] [blame] | 800 | BLOCK_SIZE bsize) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 801 | AV1_COMMON *const cm = &pbi->common; |
Jingning Han | ff17e16 | 2016-12-07 17:58:18 -0800 | [diff] [blame] | 802 | const int num_8x8_wh = mi_size_wide[bsize]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 803 | const int hbs = num_8x8_wh >> 1; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 804 | #if CONFIG_EXT_PARTITION_TYPES && CONFIG_EXT_PARTITION_TYPES_AB |
| 805 | const int qbs = num_8x8_wh >> 2; |
| 806 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 807 | PARTITION_TYPE partition; |
| 808 | BLOCK_SIZE subsize; |
| 809 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 810 | const int quarter_step = num_8x8_wh / 4; |
| 811 | int i; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 812 | #if !CONFIG_EXT_PARTITION_TYPES_AB |
| 813 | BLOCK_SIZE bsize2 = get_subsize(bsize, PARTITION_SPLIT); |
| 814 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 815 | #endif |
| 816 | const int has_rows = (mi_row + hbs) < cm->mi_rows; |
| 817 | const int has_cols = (mi_col + hbs) < cm->mi_cols; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 818 | |
| 819 | if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return; |
| 820 | |
Jingning Han | cd95976 | 2017-03-27 14:49:59 -0700 | [diff] [blame] | 821 | partition = (bsize < BLOCK_8X8) ? PARTITION_NONE |
| 822 | : read_partition(cm, xd, mi_row, mi_col, r, |
| 823 | has_rows, has_cols, bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 824 | subsize = subsize_lookup[partition][bsize]; // get_subsize(bsize, partition); |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 825 | |
Rupert Swarbrick | 415c8f1 | 2017-10-09 16:26:23 +0100 | [diff] [blame] | 826 | // Check the bitstream is conformant: if there is subsampling on the |
| 827 | // chroma planes, subsize must subsample to a valid block size. |
| 828 | const struct macroblockd_plane *const pd_u = &xd->plane[1]; |
| 829 | if (get_plane_block_size(subsize, pd_u) == BLOCK_INVALID) { |
| 830 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 831 | "Block size %dx%d invalid with this subsampling mode", |
| 832 | block_size_wide[subsize], block_size_high[subsize]); |
| 833 | } |
| 834 | |
Rupert Swarbrick | 668d3d9 | 2017-09-06 16:09:51 +0100 | [diff] [blame] | 835 | #define DEC_BLOCK_STX_ARG |
Rupert Swarbrick | 668d3d9 | 2017-09-06 16:09:51 +0100 | [diff] [blame] | 836 | #if CONFIG_EXT_PARTITION_TYPES |
| 837 | #define DEC_BLOCK_EPT_ARG partition, |
| 838 | #else |
| 839 | #define DEC_BLOCK_EPT_ARG |
| 840 | #endif |
| 841 | #define DEC_BLOCK(db_r, db_c, db_subsize) \ |
| 842 | decode_block(pbi, xd, DEC_BLOCK_STX_ARG(db_r), (db_c), r, \ |
| 843 | DEC_BLOCK_EPT_ARG(db_subsize)) |
| 844 | #define DEC_PARTITION(db_r, db_c, db_subsize) \ |
| 845 | decode_partition(pbi, xd, DEC_BLOCK_STX_ARG(db_r), (db_c), r, (db_subsize)) |
| 846 | |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 847 | switch (partition) { |
| 848 | case PARTITION_NONE: DEC_BLOCK(mi_row, mi_col, subsize); break; |
| 849 | case PARTITION_HORZ: |
| 850 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 851 | if (has_rows) DEC_BLOCK(mi_row + hbs, mi_col, subsize); |
| 852 | break; |
| 853 | case PARTITION_VERT: |
| 854 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 855 | if (has_cols) DEC_BLOCK(mi_row, mi_col + hbs, subsize); |
| 856 | break; |
| 857 | case PARTITION_SPLIT: |
| 858 | DEC_PARTITION(mi_row, mi_col, subsize); |
| 859 | DEC_PARTITION(mi_row, mi_col + hbs, subsize); |
| 860 | DEC_PARTITION(mi_row + hbs, mi_col, subsize); |
| 861 | DEC_PARTITION(mi_row + hbs, mi_col + hbs, subsize); |
| 862 | break; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 863 | #if CONFIG_EXT_PARTITION_TYPES |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 864 | #if CONFIG_EXT_PARTITION_TYPES_AB |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 865 | case PARTITION_HORZ_A: |
| 866 | DEC_BLOCK(mi_row, mi_col, get_subsize(bsize, PARTITION_HORZ_4)); |
| 867 | DEC_BLOCK(mi_row + qbs, mi_col, get_subsize(bsize, PARTITION_HORZ_4)); |
| 868 | DEC_BLOCK(mi_row + hbs, mi_col, subsize); |
| 869 | break; |
| 870 | case PARTITION_HORZ_B: |
| 871 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 872 | DEC_BLOCK(mi_row + hbs, mi_col, get_subsize(bsize, PARTITION_HORZ_4)); |
| 873 | if (mi_row + 3 * qbs < cm->mi_rows) |
| 874 | DEC_BLOCK(mi_row + 3 * qbs, mi_col, |
| 875 | get_subsize(bsize, PARTITION_HORZ_4)); |
| 876 | break; |
| 877 | case PARTITION_VERT_A: |
| 878 | DEC_BLOCK(mi_row, mi_col, get_subsize(bsize, PARTITION_VERT_4)); |
| 879 | DEC_BLOCK(mi_row, mi_col + qbs, get_subsize(bsize, PARTITION_VERT_4)); |
| 880 | DEC_BLOCK(mi_row, mi_col + hbs, subsize); |
| 881 | break; |
| 882 | case PARTITION_VERT_B: |
| 883 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 884 | DEC_BLOCK(mi_row, mi_col + hbs, get_subsize(bsize, PARTITION_VERT_4)); |
| 885 | if (mi_col + 3 * qbs < cm->mi_cols) |
| 886 | DEC_BLOCK(mi_row, mi_col + 3 * qbs, |
| 887 | get_subsize(bsize, PARTITION_VERT_4)); |
| 888 | break; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 889 | #else |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 890 | case PARTITION_HORZ_A: |
| 891 | DEC_BLOCK(mi_row, mi_col, bsize2); |
| 892 | DEC_BLOCK(mi_row, mi_col + hbs, bsize2); |
| 893 | DEC_BLOCK(mi_row + hbs, mi_col, subsize); |
| 894 | break; |
| 895 | case PARTITION_HORZ_B: |
| 896 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 897 | DEC_BLOCK(mi_row + hbs, mi_col, bsize2); |
| 898 | DEC_BLOCK(mi_row + hbs, mi_col + hbs, bsize2); |
| 899 | break; |
| 900 | case PARTITION_VERT_A: |
| 901 | DEC_BLOCK(mi_row, mi_col, bsize2); |
| 902 | DEC_BLOCK(mi_row + hbs, mi_col, bsize2); |
| 903 | DEC_BLOCK(mi_row, mi_col + hbs, subsize); |
| 904 | break; |
| 905 | case PARTITION_VERT_B: |
| 906 | DEC_BLOCK(mi_row, mi_col, subsize); |
| 907 | DEC_BLOCK(mi_row, mi_col + hbs, bsize2); |
| 908 | DEC_BLOCK(mi_row + hbs, mi_col + hbs, bsize2); |
| 909 | break; |
Rupert Swarbrick | 3dd3391 | 2017-09-12 14:24:11 +0100 | [diff] [blame] | 910 | #endif |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 911 | case PARTITION_HORZ_4: |
| 912 | for (i = 0; i < 4; ++i) { |
| 913 | int this_mi_row = mi_row + i * quarter_step; |
| 914 | if (i > 0 && this_mi_row >= cm->mi_rows) break; |
| 915 | DEC_BLOCK(this_mi_row, mi_col, subsize); |
| 916 | } |
| 917 | break; |
| 918 | case PARTITION_VERT_4: |
| 919 | for (i = 0; i < 4; ++i) { |
| 920 | int this_mi_col = mi_col + i * quarter_step; |
| 921 | if (i > 0 && this_mi_col >= cm->mi_cols) break; |
| 922 | DEC_BLOCK(mi_row, this_mi_col, subsize); |
| 923 | } |
| 924 | break; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 925 | #endif // CONFIG_EXT_PARTITION_TYPES |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 926 | default: assert(0 && "Invalid partition type"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Rupert Swarbrick | 668d3d9 | 2017-09-06 16:09:51 +0100 | [diff] [blame] | 929 | #undef DEC_PARTITION |
| 930 | #undef DEC_BLOCK |
| 931 | #undef DEC_BLOCK_EPT_ARG |
| 932 | #undef DEC_BLOCK_STX_ARG |
| 933 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 934 | #if CONFIG_EXT_PARTITION_TYPES |
Alex Converse | ffabff3 | 2017-03-27 09:52:19 -0700 | [diff] [blame] | 935 | update_ext_partition_context(xd, mi_row, mi_col, subsize, bsize, partition); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 936 | #else |
| 937 | // update partition context |
| 938 | if (bsize >= BLOCK_8X8 && |
| 939 | (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT)) |
Jingning Han | 1beb010 | 2016-12-07 11:08:30 -0800 | [diff] [blame] | 940 | update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
David Barker | f8935c9 | 2016-10-26 14:54:06 +0100 | [diff] [blame] | 941 | #endif // CONFIG_EXT_PARTITION_TYPES |
Yaowu Xu | d71be78 | 2016-10-14 08:47:03 -0700 | [diff] [blame] | 942 | |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 943 | #if CONFIG_LPF_SB |
| 944 | if (bsize == cm->sb_size) { |
Cheng Chen | a4b27de | 2017-08-31 16:05:19 -0700 | [diff] [blame] | 945 | int filt_lvl; |
| 946 | if (mi_row == 0 && mi_col == 0) { |
| 947 | filt_lvl = aom_read_literal(r, 6, ACCT_STR); |
Cheng Chen | 41d37c2 | 2017-09-08 19:00:21 -0700 | [diff] [blame] | 948 | cm->mi_grid_visible[0]->mbmi.reuse_sb_lvl = 0; |
| 949 | cm->mi_grid_visible[0]->mbmi.delta = 0; |
| 950 | cm->mi_grid_visible[0]->mbmi.sign = 0; |
Cheng Chen | a4b27de | 2017-08-31 16:05:19 -0700 | [diff] [blame] | 951 | } else { |
| 952 | int prev_mi_row, prev_mi_col; |
| 953 | if (mi_col - MAX_MIB_SIZE < 0) { |
| 954 | prev_mi_row = mi_row - MAX_MIB_SIZE; |
| 955 | prev_mi_col = mi_col; |
| 956 | } else { |
| 957 | prev_mi_row = mi_row; |
| 958 | prev_mi_col = mi_col - MAX_MIB_SIZE; |
| 959 | } |
Cheng Chen | c7855b1 | 2017-09-05 10:49:08 -0700 | [diff] [blame] | 960 | |
Cheng Chen | 41d37c2 | 2017-09-08 19:00:21 -0700 | [diff] [blame] | 961 | MB_MODE_INFO *curr_mbmi = |
| 962 | &cm->mi_grid_visible[mi_row * cm->mi_stride + mi_col]->mbmi; |
| 963 | MB_MODE_INFO *prev_mbmi = |
| 964 | &cm->mi_grid_visible[prev_mi_row * cm->mi_stride + prev_mi_col]->mbmi; |
| 965 | const uint8_t prev_lvl = prev_mbmi->filt_lvl; |
Cheng Chen | a4b27de | 2017-08-31 16:05:19 -0700 | [diff] [blame] | 966 | |
Cheng Chen | 41d37c2 | 2017-09-08 19:00:21 -0700 | [diff] [blame] | 967 | const int reuse_ctx = prev_mbmi->reuse_sb_lvl; |
| 968 | const int reuse_prev_lvl = aom_read_symbol( |
| 969 | r, xd->tile_ctx->lpf_reuse_cdf[reuse_ctx], 2, ACCT_STR); |
| 970 | curr_mbmi->reuse_sb_lvl = reuse_prev_lvl; |
| 971 | |
Cheng Chen | c7855b1 | 2017-09-05 10:49:08 -0700 | [diff] [blame] | 972 | if (reuse_prev_lvl) { |
Cheng Chen | a4b27de | 2017-08-31 16:05:19 -0700 | [diff] [blame] | 973 | filt_lvl = prev_lvl; |
Cheng Chen | 41d37c2 | 2017-09-08 19:00:21 -0700 | [diff] [blame] | 974 | curr_mbmi->delta = 0; |
| 975 | curr_mbmi->sign = 0; |
Cheng Chen | c7855b1 | 2017-09-05 10:49:08 -0700 | [diff] [blame] | 976 | } else { |
Cheng Chen | 41d37c2 | 2017-09-08 19:00:21 -0700 | [diff] [blame] | 977 | const int delta_ctx = prev_mbmi->delta; |
| 978 | unsigned int delta = aom_read_symbol( |
| 979 | r, xd->tile_ctx->lpf_delta_cdf[delta_ctx], DELTA_RANGE, ACCT_STR); |
| 980 | curr_mbmi->delta = delta; |
Cheng Chen | f89ca3e | 2017-09-07 14:47:47 -0700 | [diff] [blame] | 981 | delta *= LPF_STEP; |
Cheng Chen | c7855b1 | 2017-09-05 10:49:08 -0700 | [diff] [blame] | 982 | |
| 983 | if (delta) { |
Cheng Chen | 41d37c2 | 2017-09-08 19:00:21 -0700 | [diff] [blame] | 984 | const int sign_ctx = prev_mbmi->sign; |
| 985 | const int sign = aom_read_symbol( |
| 986 | r, xd->tile_ctx->lpf_sign_cdf[reuse_ctx][sign_ctx], 2, ACCT_STR); |
| 987 | curr_mbmi->sign = sign; |
Cheng Chen | c7855b1 | 2017-09-05 10:49:08 -0700 | [diff] [blame] | 988 | filt_lvl = sign ? prev_lvl + delta : prev_lvl - delta; |
| 989 | } else { |
| 990 | filt_lvl = prev_lvl; |
Cheng Chen | 41d37c2 | 2017-09-08 19:00:21 -0700 | [diff] [blame] | 991 | curr_mbmi->sign = 0; |
Cheng Chen | c7855b1 | 2017-09-05 10:49:08 -0700 | [diff] [blame] | 992 | } |
Cheng Chen | a4b27de | 2017-08-31 16:05:19 -0700 | [diff] [blame] | 993 | } |
| 994 | } |
Cheng Chen | 5589d71 | 2017-09-05 12:03:25 -0700 | [diff] [blame] | 995 | |
| 996 | av1_loop_filter_sb_level_init(cm, mi_row, mi_col, filt_lvl); |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 997 | } |
| 998 | #endif |
| 999 | |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 1000 | #if CONFIG_CDEF |
Jingning Han | df06833 | 2017-05-09 09:03:17 -0700 | [diff] [blame] | 1001 | if (bsize == cm->sb_size) { |
Cheng Chen | f5bdeac | 2017-07-24 14:31:30 -0700 | [diff] [blame] | 1002 | int width_step = mi_size_wide[BLOCK_64X64]; |
| 1003 | int height_step = mi_size_wide[BLOCK_64X64]; |
| 1004 | int w, h; |
| 1005 | for (h = 0; (h < mi_size_high[cm->sb_size]) && (mi_row + h < cm->mi_rows); |
| 1006 | h += height_step) { |
| 1007 | for (w = 0; (w < mi_size_wide[cm->sb_size]) && (mi_col + w < cm->mi_cols); |
| 1008 | w += width_step) { |
| 1009 | if (!cm->all_lossless && !sb_all_skip(cm, mi_row + h, mi_col + w)) |
| 1010 | cm->mi_grid_visible[(mi_row + h) * cm->mi_stride + (mi_col + w)] |
| 1011 | ->mbmi.cdef_strength = |
| 1012 | aom_read_literal(r, cm->cdef_bits, ACCT_STR); |
| 1013 | else |
| 1014 | cm->mi_grid_visible[(mi_row + h) * cm->mi_stride + (mi_col + w)] |
| 1015 | ->mbmi.cdef_strength = -1; |
| 1016 | } |
Yaowu Xu | d71be78 | 2016-10-14 08:47:03 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 1019 | #endif // CONFIG_CDEF |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1020 | #if CONFIG_LOOP_RESTORATION |
| 1021 | for (int plane = 0; plane < MAX_MB_PLANE; ++plane) { |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 1022 | int rcol0, rcol1, rrow0, rrow1, tile_tl_idx; |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1023 | if (av1_loop_restoration_corners_in_sb(cm, plane, mi_row, mi_col, bsize, |
| 1024 | &rcol0, &rcol1, &rrow0, &rrow1, |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 1025 | &tile_tl_idx)) { |
| 1026 | const int rstride = cm->rst_info[plane].horz_units_per_tile; |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1027 | for (int rrow = rrow0; rrow < rrow1; ++rrow) { |
| 1028 | for (int rcol = rcol0; rcol < rcol1; ++rcol) { |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 1029 | const int rtile_idx = tile_tl_idx + rcol + rrow * rstride; |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1030 | loop_restoration_read_sb_coeffs(cm, xd, r, plane, rtile_idx); |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1038 | static void setup_bool_decoder(const uint8_t *data, const uint8_t *data_end, |
| 1039 | const size_t read_size, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1040 | struct aom_internal_error_info *error_info, |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 1041 | aom_reader *r, uint8_t allow_update_cdf, |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 1042 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 1043 | int window_size, |
| 1044 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
| 1045 | aom_decrypt_cb decrypt_cb, void *decrypt_state) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1046 | // Validate the calculated partition length. If the buffer |
| 1047 | // described by the partition can't be fully read, then restrict |
| 1048 | // it to the portion that can be (for EC mode) or throw an error. |
| 1049 | if (!read_is_valid(data, read_size, data_end)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1050 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1051 | "Truncated packet or corrupt tile length"); |
| 1052 | |
Alex Converse | 2cdf0d8 | 2016-12-13 13:53:09 -0800 | [diff] [blame] | 1053 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 1054 | r->window_size = window_size; |
Alex Converse | 2cdf0d8 | 2016-12-13 13:53:09 -0800 | [diff] [blame] | 1055 | #endif |
Alex Converse | 346440b | 2017-01-03 13:47:37 -0800 | [diff] [blame] | 1056 | if (aom_reader_init(r, data, read_size, decrypt_cb, decrypt_state)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1057 | aom_internal_error(error_info, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1058 | "Failed to allocate bool decoder %d", 1); |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 1059 | |
| 1060 | r->allow_update_cdf = allow_update_cdf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1061 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1062 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1063 | static void setup_segmentation(AV1_COMMON *const cm, |
| 1064 | struct aom_read_bit_buffer *rb) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1065 | struct segmentation *const seg = &cm->seg; |
| 1066 | int i, j; |
| 1067 | |
| 1068 | seg->update_map = 0; |
| 1069 | seg->update_data = 0; |
Ryan | dd8df16 | 2017-09-27 15:40:13 -0700 | [diff] [blame] | 1070 | seg->temporal_update = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1071 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1072 | seg->enabled = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1073 | if (!seg->enabled) return; |
| 1074 | |
| 1075 | // Segmentation map update |
| 1076 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
| 1077 | seg->update_map = 1; |
| 1078 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1079 | seg->update_map = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1080 | } |
| 1081 | if (seg->update_map) { |
| 1082 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) { |
| 1083 | seg->temporal_update = 0; |
| 1084 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1085 | seg->temporal_update = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | // Segmentation data update |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1090 | seg->update_data = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1091 | if (seg->update_data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1092 | av1_clearall_segfeatures(seg); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1093 | |
| 1094 | for (i = 0; i < MAX_SEGMENTS; i++) { |
| 1095 | for (j = 0; j < SEG_LVL_MAX; j++) { |
| 1096 | int data = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1097 | const int feature_enabled = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1098 | if (feature_enabled) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1099 | av1_enable_segfeature(seg, i, j); |
| 1100 | data = decode_unsigned_max(rb, av1_seg_feature_data_max(j)); |
| 1101 | if (av1_is_segfeature_signed(j)) |
| 1102 | data = aom_rb_read_bit(rb) ? -data : data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1103 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1104 | av1_set_segdata(seg, i, j, data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | #if CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 5cd2ab9 | 2016-09-08 15:15:17 -0700 | [diff] [blame] | 1111 | static void decode_restoration_mode(AV1_COMMON *cm, |
| 1112 | struct aom_read_bit_buffer *rb) { |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame^] | 1113 | for (int p = 0; p < MAX_MB_PLANE; ++p) { |
| 1114 | RestorationInfo *rsi = &cm->rst_info[p]; |
Debargha Mukherjee | d23ceea | 2017-05-18 20:33:52 -0700 | [diff] [blame] | 1115 | if (aom_rb_read_bit(rb)) { |
| 1116 | rsi->frame_restoration_type = |
| 1117 | aom_rb_read_bit(rb) ? RESTORE_SGRPROJ : RESTORE_WIENER; |
| 1118 | } else { |
Debargha Mukherjee | a3d4fe5 | 2017-05-19 16:22:54 -0700 | [diff] [blame] | 1119 | rsi->frame_restoration_type = |
| 1120 | aom_rb_read_bit(rb) ? RESTORE_SWITCHABLE : RESTORE_NONE; |
Debargha Mukherjee | d23ceea | 2017-05-18 20:33:52 -0700 | [diff] [blame] | 1121 | } |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1122 | } |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 1123 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 1124 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 1125 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame^] | 1126 | const int qsize = RESTORATION_TILESIZE_MAX >> 2; |
| 1127 | for (int p = 0; p < MAX_MB_PLANE; ++p) |
| 1128 | cm->rst_info[p].restoration_unit_size = qsize; |
| 1129 | |
| 1130 | RestorationInfo *rsi = &cm->rst_info[0]; |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 1131 | rsi->restoration_unit_size <<= aom_rb_read_bit(rb); |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame^] | 1132 | if (rsi->restoration_unit_size != qsize) { |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 1133 | rsi->restoration_unit_size <<= aom_rb_read_bit(rb); |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 1134 | } |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame^] | 1135 | } else { |
| 1136 | const int size = RESTORATION_TILESIZE_MAX; |
| 1137 | for (int p = 0; p < MAX_MB_PLANE; ++p) |
| 1138 | cm->rst_info[p].restoration_unit_size = size; |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 1139 | } |
Rupert Swarbrick | 4596deb | 2017-11-07 18:06:38 +0000 | [diff] [blame^] | 1140 | |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 1141 | int s = AOMMIN(cm->subsampling_x, cm->subsampling_y); |
| 1142 | if (s && (cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 1143 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE)) { |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 1144 | cm->rst_info[1].restoration_unit_size = |
| 1145 | cm->rst_info[0].restoration_unit_size >> (aom_rb_read_bit(rb) * s); |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 1146 | } else { |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 1147 | cm->rst_info[1].restoration_unit_size = |
| 1148 | cm->rst_info[0].restoration_unit_size; |
Debargha Mukherjee | 84f567c | 2017-06-21 10:53:59 -0700 | [diff] [blame] | 1149 | } |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 1150 | cm->rst_info[2].restoration_unit_size = cm->rst_info[1].restoration_unit_size; |
Debargha Mukherjee | 5cd2ab9 | 2016-09-08 15:15:17 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Debargha Mukherjee | 1cb757c | 2017-08-21 02:46:31 -0700 | [diff] [blame] | 1153 | static void read_wiener_filter(int wiener_win, WienerInfo *wiener_info, |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1154 | WienerInfo *ref_wiener_info, aom_reader *rb) { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1155 | memset(wiener_info->vfilter, 0, sizeof(wiener_info->vfilter)); |
| 1156 | memset(wiener_info->hfilter, 0, sizeof(wiener_info->hfilter)); |
| 1157 | |
Debargha Mukherjee | 1cb757c | 2017-08-21 02:46:31 -0700 | [diff] [blame] | 1158 | if (wiener_win == WIENER_WIN) |
| 1159 | wiener_info->vfilter[0] = wiener_info->vfilter[WIENER_WIN - 1] = |
| 1160 | aom_read_primitive_refsubexpfin( |
| 1161 | rb, WIENER_FILT_TAP0_MAXV - WIENER_FILT_TAP0_MINV + 1, |
| 1162 | WIENER_FILT_TAP0_SUBEXP_K, |
| 1163 | ref_wiener_info->vfilter[0] - WIENER_FILT_TAP0_MINV, ACCT_STR) + |
| 1164 | WIENER_FILT_TAP0_MINV; |
| 1165 | else |
| 1166 | wiener_info->vfilter[0] = wiener_info->vfilter[WIENER_WIN - 1] = 0; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1167 | wiener_info->vfilter[1] = wiener_info->vfilter[WIENER_WIN - 2] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1168 | aom_read_primitive_refsubexpfin( |
| 1169 | rb, WIENER_FILT_TAP1_MAXV - WIENER_FILT_TAP1_MINV + 1, |
| 1170 | WIENER_FILT_TAP1_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1171 | ref_wiener_info->vfilter[1] - WIENER_FILT_TAP1_MINV, ACCT_STR) + |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1172 | WIENER_FILT_TAP1_MINV; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1173 | wiener_info->vfilter[2] = wiener_info->vfilter[WIENER_WIN - 3] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1174 | aom_read_primitive_refsubexpfin( |
| 1175 | rb, WIENER_FILT_TAP2_MAXV - WIENER_FILT_TAP2_MINV + 1, |
| 1176 | WIENER_FILT_TAP2_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1177 | ref_wiener_info->vfilter[2] - WIENER_FILT_TAP2_MINV, ACCT_STR) + |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1178 | WIENER_FILT_TAP2_MINV; |
David Barker | 1e8e6b9 | 2017-01-13 13:45:51 +0000 | [diff] [blame] | 1179 | // The central element has an implicit +WIENER_FILT_STEP |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1180 | wiener_info->vfilter[WIENER_HALFWIN] = |
David Barker | 1e8e6b9 | 2017-01-13 13:45:51 +0000 | [diff] [blame] | 1181 | -2 * (wiener_info->vfilter[0] + wiener_info->vfilter[1] + |
| 1182 | wiener_info->vfilter[2]); |
| 1183 | |
Debargha Mukherjee | 1cb757c | 2017-08-21 02:46:31 -0700 | [diff] [blame] | 1184 | if (wiener_win == WIENER_WIN) |
| 1185 | wiener_info->hfilter[0] = wiener_info->hfilter[WIENER_WIN - 1] = |
| 1186 | aom_read_primitive_refsubexpfin( |
| 1187 | rb, WIENER_FILT_TAP0_MAXV - WIENER_FILT_TAP0_MINV + 1, |
| 1188 | WIENER_FILT_TAP0_SUBEXP_K, |
| 1189 | ref_wiener_info->hfilter[0] - WIENER_FILT_TAP0_MINV, ACCT_STR) + |
| 1190 | WIENER_FILT_TAP0_MINV; |
| 1191 | else |
| 1192 | wiener_info->hfilter[0] = wiener_info->hfilter[WIENER_WIN - 1] = 0; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1193 | wiener_info->hfilter[1] = wiener_info->hfilter[WIENER_WIN - 2] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1194 | aom_read_primitive_refsubexpfin( |
| 1195 | rb, WIENER_FILT_TAP1_MAXV - WIENER_FILT_TAP1_MINV + 1, |
| 1196 | WIENER_FILT_TAP1_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1197 | ref_wiener_info->hfilter[1] - WIENER_FILT_TAP1_MINV, ACCT_STR) + |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1198 | WIENER_FILT_TAP1_MINV; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1199 | wiener_info->hfilter[2] = wiener_info->hfilter[WIENER_WIN - 3] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1200 | aom_read_primitive_refsubexpfin( |
| 1201 | rb, WIENER_FILT_TAP2_MAXV - WIENER_FILT_TAP2_MINV + 1, |
| 1202 | WIENER_FILT_TAP2_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1203 | ref_wiener_info->hfilter[2] - WIENER_FILT_TAP2_MINV, ACCT_STR) + |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1204 | WIENER_FILT_TAP2_MINV; |
David Barker | 1e8e6b9 | 2017-01-13 13:45:51 +0000 | [diff] [blame] | 1205 | // The central element has an implicit +WIENER_FILT_STEP |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1206 | wiener_info->hfilter[WIENER_HALFWIN] = |
David Barker | 1e8e6b9 | 2017-01-13 13:45:51 +0000 | [diff] [blame] | 1207 | -2 * (wiener_info->hfilter[0] + wiener_info->hfilter[1] + |
| 1208 | wiener_info->hfilter[2]); |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1209 | memcpy(ref_wiener_info, wiener_info, sizeof(*wiener_info)); |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1212 | static void read_sgrproj_filter(SgrprojInfo *sgrproj_info, |
| 1213 | SgrprojInfo *ref_sgrproj_info, aom_reader *rb) { |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1214 | sgrproj_info->ep = aom_read_literal(rb, SGRPROJ_PARAMS_BITS, ACCT_STR); |
| 1215 | sgrproj_info->xqd[0] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1216 | aom_read_primitive_refsubexpfin( |
| 1217 | rb, SGRPROJ_PRJ_MAX0 - SGRPROJ_PRJ_MIN0 + 1, SGRPROJ_PRJ_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1218 | ref_sgrproj_info->xqd[0] - SGRPROJ_PRJ_MIN0, ACCT_STR) + |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1219 | SGRPROJ_PRJ_MIN0; |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1220 | sgrproj_info->xqd[1] = |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1221 | aom_read_primitive_refsubexpfin( |
| 1222 | rb, SGRPROJ_PRJ_MAX1 - SGRPROJ_PRJ_MIN1 + 1, SGRPROJ_PRJ_SUBEXP_K, |
Debargha Mukherjee | e23d5c3 | 2017-04-13 15:33:58 -0700 | [diff] [blame] | 1223 | ref_sgrproj_info->xqd[1] - SGRPROJ_PRJ_MIN1, ACCT_STR) + |
Debargha Mukherjee | cfc12f3 | 2017-04-18 07:03:32 -0700 | [diff] [blame] | 1224 | SGRPROJ_PRJ_MIN1; |
| 1225 | memcpy(ref_sgrproj_info, sgrproj_info, sizeof(*sgrproj_info)); |
Debargha Mukherjee | 8f209a8 | 2016-10-12 10:47:01 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1228 | static void loop_restoration_read_sb_coeffs(const AV1_COMMON *const cm, |
| 1229 | MACROBLOCKD *xd, |
| 1230 | aom_reader *const r, int plane, |
| 1231 | int rtile_idx) { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1232 | const RestorationInfo *rsi = &cm->rst_info[plane]; |
| 1233 | RestorationUnitInfo *rui = &rsi->unit_info[rtile_idx]; |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1234 | if (rsi->frame_restoration_type == RESTORE_NONE) return; |
Rupert Swarbrick | 09b5b16 | 2017-08-31 16:32:29 +0100 | [diff] [blame] | 1235 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1236 | const int wiener_win = (plane > 0) ? WIENER_WIN_CHROMA : WIENER_WIN; |
| 1237 | WienerInfo *wiener_info = xd->wiener_info + plane; |
| 1238 | SgrprojInfo *sgrproj_info = xd->sgrproj_info + plane; |
Rupert Swarbrick | 09b5b16 | 2017-08-31 16:32:29 +0100 | [diff] [blame] | 1239 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1240 | if (rsi->frame_restoration_type == RESTORE_SWITCHABLE) { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1241 | rui->restoration_type = |
Debargha Mukherjee | bc732ef | 2017-10-12 12:40:25 -0700 | [diff] [blame] | 1242 | aom_read_symbol(r, xd->tile_ctx->switchable_restore_cdf, |
| 1243 | RESTORE_SWITCHABLE_TYPES, ACCT_STR); |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1244 | switch (rui->restoration_type) { |
| 1245 | case RESTORE_WIENER: |
| 1246 | read_wiener_filter(wiener_win, &rui->wiener_info, wiener_info, r); |
| 1247 | break; |
| 1248 | case RESTORE_SGRPROJ: |
| 1249 | read_sgrproj_filter(&rui->sgrproj_info, sgrproj_info, r); |
| 1250 | break; |
| 1251 | default: assert(rui->restoration_type == RESTORE_NONE); break; |
Rupert Swarbrick | 09b5b16 | 2017-08-31 16:32:29 +0100 | [diff] [blame] | 1252 | } |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1253 | } else if (rsi->frame_restoration_type == RESTORE_WIENER) { |
Debargha Mukherjee | bc732ef | 2017-10-12 12:40:25 -0700 | [diff] [blame] | 1254 | #if CONFIG_NEW_MULTISYMBOL |
| 1255 | if (aom_read_symbol(r, xd->tile_ctx->wiener_restore_cdf, 2, ACCT_STR)) { |
| 1256 | #else |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1257 | if (aom_read(r, RESTORE_NONE_WIENER_PROB, ACCT_STR)) { |
Debargha Mukherjee | bc732ef | 2017-10-12 12:40:25 -0700 | [diff] [blame] | 1258 | #endif // CONFIG_NEW_MULTISYMBOL |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1259 | rui->restoration_type = RESTORE_WIENER; |
| 1260 | read_wiener_filter(wiener_win, &rui->wiener_info, wiener_info, r); |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1261 | } else { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1262 | rui->restoration_type = RESTORE_NONE; |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1263 | } |
| 1264 | } else if (rsi->frame_restoration_type == RESTORE_SGRPROJ) { |
Debargha Mukherjee | bc732ef | 2017-10-12 12:40:25 -0700 | [diff] [blame] | 1265 | #if CONFIG_NEW_MULTISYMBOL |
| 1266 | if (aom_read_symbol(r, xd->tile_ctx->sgrproj_restore_cdf, 2, ACCT_STR)) { |
| 1267 | #else |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1268 | if (aom_read(r, RESTORE_NONE_SGRPROJ_PROB, ACCT_STR)) { |
Debargha Mukherjee | bc732ef | 2017-10-12 12:40:25 -0700 | [diff] [blame] | 1269 | #endif // CONFIG_NEW_MULTISYMBOL |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1270 | rui->restoration_type = RESTORE_SGRPROJ; |
| 1271 | read_sgrproj_filter(&rui->sgrproj_info, sgrproj_info, r); |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 1272 | } else { |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 1273 | rui->restoration_type = RESTORE_NONE; |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 1274 | } |
| 1275 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1276 | } |
| 1277 | #endif // CONFIG_LOOP_RESTORATION |
| 1278 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1279 | static void setup_loopfilter(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1280 | struct loopfilter *lf = &cm->lf; |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 1281 | #if !CONFIG_LPF_SB |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 1282 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 1283 | lf->filter_level[0] = aom_rb_read_literal(rb, 6); |
| 1284 | lf->filter_level[1] = aom_rb_read_literal(rb, 6); |
| 1285 | if (lf->filter_level[0] || lf->filter_level[1]) { |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 1286 | lf->filter_level_u = aom_rb_read_literal(rb, 6); |
| 1287 | lf->filter_level_v = aom_rb_read_literal(rb, 6); |
| 1288 | } |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 1289 | #else |
| 1290 | lf->filter_level = aom_rb_read_literal(rb, 6); |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 1291 | #endif |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 1292 | #endif // CONFIG_LPF_SB |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1293 | lf->sharpness_level = aom_rb_read_literal(rb, 3); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1294 | |
| 1295 | // Read in loop filter deltas applied at the MB level based on mode or ref |
| 1296 | // frame. |
| 1297 | lf->mode_ref_delta_update = 0; |
| 1298 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1299 | lf->mode_ref_delta_enabled = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1300 | if (lf->mode_ref_delta_enabled) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1301 | lf->mode_ref_delta_update = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1302 | if (lf->mode_ref_delta_update) { |
| 1303 | int i; |
| 1304 | |
| 1305 | for (i = 0; i < TOTAL_REFS_PER_FRAME; i++) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1306 | if (aom_rb_read_bit(rb)) |
| 1307 | lf->ref_deltas[i] = aom_rb_read_inv_signed_literal(rb, 6); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1308 | |
| 1309 | for (i = 0; i < MAX_MODE_LF_DELTAS; i++) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1310 | if (aom_rb_read_bit(rb)) |
| 1311 | lf->mode_deltas[i] = aom_rb_read_inv_signed_literal(rb, 6); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | } |
| 1315 | |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 1316 | #if CONFIG_CDEF |
Steinar Midtskogen | a9d41e8 | 2017-03-17 12:48:15 +0100 | [diff] [blame] | 1317 | static void setup_cdef(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
Jean-Marc Valin | 5f5c132 | 2017-03-21 16:20:21 -0400 | [diff] [blame] | 1318 | int i; |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 1319 | #if CONFIG_CDEF_SINGLEPASS |
| 1320 | cm->cdef_pri_damping = cm->cdef_sec_damping = aom_rb_read_literal(rb, 2) + 3; |
| 1321 | #else |
Steinar Midtskogen | 94de0aa | 2017-08-02 10:30:12 +0200 | [diff] [blame] | 1322 | cm->cdef_pri_damping = aom_rb_read_literal(rb, 1) + 5; |
| 1323 | cm->cdef_sec_damping = aom_rb_read_literal(rb, 2) + 3; |
Steinar Midtskogen | 5978212 | 2017-07-20 08:49:43 +0200 | [diff] [blame] | 1324 | #endif |
Jean-Marc Valin | 5f5c132 | 2017-03-21 16:20:21 -0400 | [diff] [blame] | 1325 | cm->cdef_bits = aom_rb_read_literal(rb, 2); |
| 1326 | cm->nb_cdef_strengths = 1 << cm->cdef_bits; |
| 1327 | for (i = 0; i < cm->nb_cdef_strengths; i++) { |
| 1328 | cm->cdef_strengths[i] = aom_rb_read_literal(rb, CDEF_STRENGTH_BITS); |
Steinar Midtskogen | 1c1161f | 2017-09-08 15:03:51 +0200 | [diff] [blame] | 1329 | cm->cdef_uv_strengths[i] = cm->subsampling_x == cm->subsampling_y |
| 1330 | ? aom_rb_read_literal(rb, CDEF_STRENGTH_BITS) |
| 1331 | : 0; |
Jean-Marc Valin | 5f5c132 | 2017-03-21 16:20:21 -0400 | [diff] [blame] | 1332 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1333 | } |
Jean-Marc Valin | 0143513 | 2017-02-18 14:12:53 -0500 | [diff] [blame] | 1334 | #endif // CONFIG_CDEF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1335 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1336 | static INLINE int read_delta_q(struct aom_read_bit_buffer *rb) { |
| 1337 | 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] | 1338 | } |
| 1339 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1340 | static void setup_quantization(AV1_COMMON *const cm, |
| 1341 | struct aom_read_bit_buffer *rb) { |
| 1342 | cm->base_qindex = aom_rb_read_literal(rb, QINDEX_BITS); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1343 | cm->y_dc_delta_q = read_delta_q(rb); |
| 1344 | cm->uv_dc_delta_q = read_delta_q(rb); |
| 1345 | cm->uv_ac_delta_q = read_delta_q(rb); |
| 1346 | cm->dequant_bit_depth = cm->bit_depth; |
| 1347 | #if CONFIG_AOM_QM |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1348 | cm->using_qmatrix = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1349 | if (cm->using_qmatrix) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1350 | cm->min_qmlevel = aom_rb_read_literal(rb, QM_LEVEL_BITS); |
| 1351 | cm->max_qmlevel = aom_rb_read_literal(rb, QM_LEVEL_BITS); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1352 | } else { |
| 1353 | cm->min_qmlevel = 0; |
| 1354 | cm->max_qmlevel = 0; |
| 1355 | } |
| 1356 | #endif |
| 1357 | } |
| 1358 | |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1359 | // Build y/uv dequant values based on segmentation. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1360 | static void setup_segmentation_dequant(AV1_COMMON *const cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1361 | #if CONFIG_AOM_QM |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1362 | const int using_qm = cm->using_qmatrix; |
| 1363 | const int minqm = cm->min_qmlevel; |
| 1364 | const int maxqm = cm->max_qmlevel; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1365 | #endif |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1366 | // When segmentation is disabled, only the first value is used. The |
| 1367 | // remaining are don't cares. |
| 1368 | const int max_segments = cm->seg.enabled ? MAX_SEGMENTS : 1; |
| 1369 | for (int i = 0; i < max_segments; ++i) { |
| 1370 | const int qindex = av1_get_qindex(&cm->seg, i, cm->base_qindex); |
| 1371 | cm->y_dequant[i][0] = av1_dc_quant(qindex, cm->y_dc_delta_q, cm->bit_depth); |
| 1372 | cm->y_dequant[i][1] = av1_ac_quant(qindex, 0, cm->bit_depth); |
| 1373 | cm->uv_dequant[i][0] = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1374 | av1_dc_quant(qindex, cm->uv_dc_delta_q, cm->bit_depth); |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1375 | cm->uv_dequant[i][1] = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1376 | av1_ac_quant(qindex, cm->uv_ac_delta_q, cm->bit_depth); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1377 | #if CONFIG_AOM_QM |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1378 | const int lossless = qindex == 0 && cm->y_dc_delta_q == 0 && |
| 1379 | cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0; |
| 1380 | // NB: depends on base index so there is only 1 set per frame |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1381 | // No quant weighting when lossless or signalled not using QM |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1382 | const int qmlevel = (lossless || using_qm == 0) |
| 1383 | ? NUM_QM_LEVELS - 1 |
| 1384 | : aom_get_qmlevel(cm->base_qindex, minqm, maxqm); |
Thomas Davies | 6675adf | 2017-05-04 17:39:21 +0100 | [diff] [blame] | 1385 | for (int j = 0; j < TX_SIZES_ALL; ++j) { |
Thomas Davies | dd3cf83 | 2017-10-20 15:49:57 +0100 | [diff] [blame] | 1386 | cm->y_iqmatrix[i][j] = aom_iqmatrix(cm, qmlevel, 0, j); |
| 1387 | cm->uv_iqmatrix[i][j] = aom_iqmatrix(cm, qmlevel, 1, j); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1388 | } |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1389 | #endif // CONFIG_AOM_QM |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1390 | #if CONFIG_NEW_QUANT |
Alex Converse | 05a3e7d | 2017-05-16 12:20:07 -0700 | [diff] [blame] | 1391 | for (int dq = 0; dq < QUANT_PROFILES; dq++) { |
| 1392 | for (int b = 0; b < COEF_BANDS; ++b) { |
| 1393 | av1_get_dequant_val_nuq(cm->y_dequant[i][b != 0], b, |
| 1394 | cm->y_dequant_nuq[i][dq][b], NULL, dq); |
| 1395 | av1_get_dequant_val_nuq(cm->uv_dequant[i][b != 0], b, |
| 1396 | cm->uv_dequant_nuq[i][dq][b], NULL, dq); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1397 | } |
| 1398 | } |
| 1399 | #endif // CONFIG_NEW_QUANT |
| 1400 | } |
| 1401 | } |
| 1402 | |
Angie Chiang | 5678ad9 | 2016-11-21 09:38:40 -0800 | [diff] [blame] | 1403 | static InterpFilter read_frame_interp_filter(struct aom_read_bit_buffer *rb) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1404 | return aom_rb_read_bit(rb) ? SWITCHABLE |
Angie Chiang | 6305abe | 2016-10-24 12:24:44 -0700 | [diff] [blame] | 1405 | : aom_rb_read_literal(rb, LOG_SWITCHABLE_FILTERS); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1408 | static void setup_render_size(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1409 | #if CONFIG_FRAME_SUPERRES |
| 1410 | cm->render_width = cm->superres_upscaled_width; |
| 1411 | cm->render_height = cm->superres_upscaled_height; |
| 1412 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1413 | cm->render_width = cm->width; |
| 1414 | cm->render_height = cm->height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1415 | #endif // CONFIG_FRAME_SUPERRES |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1416 | if (aom_rb_read_bit(rb)) |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 1417 | #if CONFIG_FRAME_SIZE |
| 1418 | av1_read_frame_size(rb, 16, 16, &cm->render_width, &cm->render_height); |
| 1419 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1420 | av1_read_frame_size(rb, &cm->render_width, &cm->render_height); |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 1421 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Fergus Simpson | d91c8c9 | 2017-04-07 12:12:00 -0700 | [diff] [blame] | 1424 | #if CONFIG_FRAME_SUPERRES |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1425 | // TODO(afergs): make "struct aom_read_bit_buffer *const rb"? |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1426 | static void setup_superres(AV1_COMMON *const cm, struct aom_read_bit_buffer *rb, |
| 1427 | int *width, int *height) { |
| 1428 | cm->superres_upscaled_width = *width; |
| 1429 | cm->superres_upscaled_height = *height; |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1430 | if (aom_rb_read_bit(rb)) { |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1431 | cm->superres_scale_denominator = |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1432 | (uint8_t)aom_rb_read_literal(rb, SUPERRES_SCALE_BITS); |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1433 | cm->superres_scale_denominator += SUPERRES_SCALE_DENOMINATOR_MIN; |
Fergus Simpson | 7b2d144 | 2017-05-22 17:18:33 -0700 | [diff] [blame] | 1434 | // Don't edit cm->width or cm->height directly, or the buffers won't get |
| 1435 | // resized correctly |
Urvang Joshi | 69fde2e | 2017-10-09 15:34:18 -0700 | [diff] [blame] | 1436 | av1_calculate_scaled_superres_size(width, height, |
| 1437 | cm->superres_scale_denominator); |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1438 | } else { |
| 1439 | // 1:1 scaling - ie. no scaling, scale not provided |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 1440 | cm->superres_scale_denominator = SCALE_NUMERATOR; |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1441 | } |
| 1442 | } |
Fergus Simpson | d91c8c9 | 2017-04-07 12:12:00 -0700 | [diff] [blame] | 1443 | #endif // CONFIG_FRAME_SUPERRES |
Fergus Simpson | e750841 | 2017-03-14 18:14:09 -0700 | [diff] [blame] | 1444 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1445 | static void resize_context_buffers(AV1_COMMON *cm, int width, int height) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1446 | #if CONFIG_SIZE_LIMIT |
| 1447 | if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1448 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1449 | "Dimensions of %dx%d beyond allowed size of %dx%d.", |
| 1450 | width, height, DECODE_WIDTH_LIMIT, DECODE_HEIGHT_LIMIT); |
| 1451 | #endif |
| 1452 | if (cm->width != width || cm->height != height) { |
| 1453 | const int new_mi_rows = |
| 1454 | ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2) >> MI_SIZE_LOG2; |
| 1455 | const int new_mi_cols = |
| 1456 | ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2) >> MI_SIZE_LOG2; |
| 1457 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1458 | // Allocations in av1_alloc_context_buffers() depend on individual |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1459 | // dimensions as well as the overall size. |
| 1460 | if (new_mi_cols > cm->mi_cols || new_mi_rows > cm->mi_rows) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1461 | if (av1_alloc_context_buffers(cm, width, height)) |
| 1462 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1463 | "Failed to allocate context buffers"); |
| 1464 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1465 | av1_set_mb_mi(cm, width, height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1466 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1467 | av1_init_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1468 | cm->width = width; |
| 1469 | cm->height = height; |
| 1470 | } |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 1471 | |
| 1472 | ensure_mv_buffer(cm->cur_frame, cm); |
| 1473 | cm->cur_frame->width = cm->width; |
| 1474 | cm->cur_frame->height = cm->height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 1477 | #if CONFIG_FRAME_SIZE |
| 1478 | static void setup_frame_size(AV1_COMMON *cm, int frame_size_override_flag, |
| 1479 | struct aom_read_bit_buffer *rb) { |
| 1480 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1481 | static void setup_frame_size(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 1482 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1483 | int width, height; |
| 1484 | BufferPool *const pool = cm->buffer_pool; |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 1485 | #if CONFIG_FRAME_SIZE |
| 1486 | if (frame_size_override_flag) { |
| 1487 | int num_bits_width = cm->seq_params.num_bits_width; |
| 1488 | int num_bits_height = cm->seq_params.num_bits_height; |
| 1489 | av1_read_frame_size(rb, num_bits_width, num_bits_height, &width, &height); |
| 1490 | } else { |
| 1491 | width = cm->seq_params.max_frame_width; |
| 1492 | height = cm->seq_params.max_frame_height; |
| 1493 | } |
| 1494 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1495 | av1_read_frame_size(rb, &width, &height); |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 1496 | #endif |
Fergus Simpson | 7b2d144 | 2017-05-22 17:18:33 -0700 | [diff] [blame] | 1497 | #if CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1498 | setup_superres(cm, rb, &width, &height); |
Fergus Simpson | 7b2d144 | 2017-05-22 17:18:33 -0700 | [diff] [blame] | 1499 | #endif // CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1500 | setup_render_size(cm, rb); |
Fergus Simpson | 7b2d144 | 2017-05-22 17:18:33 -0700 | [diff] [blame] | 1501 | resize_context_buffers(cm, width, height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1502 | |
| 1503 | lock_buffer_pool(pool); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1504 | if (aom_realloc_frame_buffer( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1505 | get_frame_new_buffer(cm), cm->width, cm->height, cm->subsampling_x, |
| 1506 | cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1507 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1508 | cm->use_highbitdepth, |
| 1509 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 1510 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1511 | &pool->frame_bufs[cm->new_fb_idx].raw_frame_buffer, pool->get_fb_cb, |
| 1512 | pool->cb_priv)) { |
| 1513 | unlock_buffer_pool(pool); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1514 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1515 | "Failed to allocate frame buffer"); |
| 1516 | } |
| 1517 | unlock_buffer_pool(pool); |
| 1518 | |
| 1519 | pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x; |
| 1520 | pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; |
| 1521 | pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; |
| 1522 | pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1523 | #if CONFIG_COLORSPACE_HEADERS |
| 1524 | pool->frame_bufs[cm->new_fb_idx].buf.transfer_function = |
| 1525 | cm->transfer_function; |
| 1526 | pool->frame_bufs[cm->new_fb_idx].buf.chroma_sample_position = |
| 1527 | cm->chroma_sample_position; |
| 1528 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1529 | pool->frame_bufs[cm->new_fb_idx].buf.color_range = cm->color_range; |
| 1530 | pool->frame_bufs[cm->new_fb_idx].buf.render_width = cm->render_width; |
| 1531 | pool->frame_bufs[cm->new_fb_idx].buf.render_height = cm->render_height; |
| 1532 | } |
| 1533 | |
Debargha Mukherjee | d2630fa | 2017-09-22 10:32:51 -0700 | [diff] [blame] | 1534 | static void setup_sb_size(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
| 1535 | (void)rb; |
| 1536 | #if CONFIG_EXT_PARTITION |
| 1537 | set_sb_size(cm, aom_rb_read_bit(rb) ? BLOCK_128X128 : BLOCK_64X64); |
| 1538 | #else |
| 1539 | set_sb_size(cm, BLOCK_64X64); |
| 1540 | #endif // CONFIG_EXT_PARTITION |
| 1541 | } |
| 1542 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1543 | 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] | 1544 | int ref_xss, int ref_yss, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1545 | aom_bit_depth_t this_bit_depth, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1546 | int this_xss, int this_yss) { |
| 1547 | return ref_bit_depth == this_bit_depth && ref_xss == this_xss && |
| 1548 | ref_yss == this_yss; |
| 1549 | } |
| 1550 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1551 | static void setup_frame_size_with_refs(AV1_COMMON *cm, |
| 1552 | struct aom_read_bit_buffer *rb) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1553 | int width, height; |
| 1554 | int found = 0, i; |
| 1555 | int has_valid_ref_frame = 0; |
| 1556 | BufferPool *const pool = cm->buffer_pool; |
| 1557 | for (i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1558 | if (aom_rb_read_bit(rb)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1559 | YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf; |
| 1560 | width = buf->y_crop_width; |
| 1561 | height = buf->y_crop_height; |
| 1562 | cm->render_width = buf->render_width; |
| 1563 | cm->render_height = buf->render_height; |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1564 | #if CONFIG_FRAME_SUPERRES |
| 1565 | setup_superres(cm, rb, &width, &height); |
| 1566 | #endif // CONFIG_FRAME_SUPERRES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1567 | found = 1; |
| 1568 | break; |
| 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | if (!found) { |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 1573 | #if CONFIG_FRAME_SIZE |
| 1574 | int num_bits_width = cm->seq_params.num_bits_width; |
| 1575 | int num_bits_height = cm->seq_params.num_bits_height; |
| 1576 | av1_read_frame_size(rb, num_bits_width, num_bits_height, &width, &height); |
| 1577 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1578 | av1_read_frame_size(rb, &width, &height); |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 1579 | #endif |
Fergus Simpson | 7b2d144 | 2017-05-22 17:18:33 -0700 | [diff] [blame] | 1580 | #if CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1581 | setup_superres(cm, rb, &width, &height); |
Fergus Simpson | 7b2d144 | 2017-05-22 17:18:33 -0700 | [diff] [blame] | 1582 | #endif // CONFIG_FRAME_SUPERRES |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 1583 | setup_render_size(cm, rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | if (width <= 0 || height <= 0) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1587 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1588 | "Invalid frame size"); |
| 1589 | |
| 1590 | // Check to make sure at least one of frames that this frame references |
| 1591 | // has valid dimensions. |
| 1592 | for (i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 1593 | RefBuffer *const ref_frame = &cm->frame_refs[i]; |
| 1594 | has_valid_ref_frame |= |
| 1595 | valid_ref_frame_size(ref_frame->buf->y_crop_width, |
| 1596 | ref_frame->buf->y_crop_height, width, height); |
| 1597 | } |
| 1598 | if (!has_valid_ref_frame) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1599 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1600 | "Referenced frame has invalid size"); |
| 1601 | for (i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 1602 | RefBuffer *const ref_frame = &cm->frame_refs[i]; |
| 1603 | if (!valid_ref_frame_img_fmt(ref_frame->buf->bit_depth, |
| 1604 | ref_frame->buf->subsampling_x, |
| 1605 | ref_frame->buf->subsampling_y, cm->bit_depth, |
| 1606 | cm->subsampling_x, cm->subsampling_y)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1607 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1608 | "Referenced frame has incompatible color format"); |
| 1609 | } |
| 1610 | |
| 1611 | resize_context_buffers(cm, width, height); |
| 1612 | |
| 1613 | lock_buffer_pool(pool); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1614 | if (aom_realloc_frame_buffer( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1615 | get_frame_new_buffer(cm), cm->width, cm->height, cm->subsampling_x, |
| 1616 | cm->subsampling_y, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1617 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1618 | cm->use_highbitdepth, |
| 1619 | #endif |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 1620 | AOM_BORDER_IN_PIXELS, cm->byte_alignment, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1621 | &pool->frame_bufs[cm->new_fb_idx].raw_frame_buffer, pool->get_fb_cb, |
| 1622 | pool->cb_priv)) { |
| 1623 | unlock_buffer_pool(pool); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1624 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1625 | "Failed to allocate frame buffer"); |
| 1626 | } |
| 1627 | unlock_buffer_pool(pool); |
| 1628 | |
| 1629 | pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x; |
| 1630 | pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; |
| 1631 | pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; |
| 1632 | pool->frame_bufs[cm->new_fb_idx].buf.color_space = cm->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 1633 | #if CONFIG_COLORSPACE_HEADERS |
| 1634 | pool->frame_bufs[cm->new_fb_idx].buf.transfer_function = |
| 1635 | cm->transfer_function; |
| 1636 | pool->frame_bufs[cm->new_fb_idx].buf.chroma_sample_position = |
| 1637 | cm->chroma_sample_position; |
| 1638 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1639 | pool->frame_bufs[cm->new_fb_idx].buf.color_range = cm->color_range; |
| 1640 | pool->frame_bufs[cm->new_fb_idx].buf.render_width = cm->render_width; |
| 1641 | pool->frame_bufs[cm->new_fb_idx].buf.render_height = cm->render_height; |
| 1642 | } |
| 1643 | |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 1644 | #if !CONFIG_OBU |
David Barker | 1a19112 | 2017-09-06 15:24:16 +0100 | [diff] [blame] | 1645 | static void read_tile_group_range(AV1Decoder *pbi, |
| 1646 | struct aom_read_bit_buffer *const rb) { |
| 1647 | AV1_COMMON *const cm = &pbi->common; |
| 1648 | const int num_bits = cm->log2_tile_rows + cm->log2_tile_cols; |
| 1649 | const int num_tiles = |
| 1650 | cm->tile_rows * cm->tile_cols; // Note: May be < (1<<num_bits) |
| 1651 | pbi->tg_start = aom_rb_read_literal(rb, num_bits); |
| 1652 | pbi->tg_size = 1 + aom_rb_read_literal(rb, num_bits); |
| 1653 | if (pbi->tg_start + pbi->tg_size > num_tiles) |
| 1654 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 1655 | "Tile group extends past last tile in frame"); |
| 1656 | } |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 1657 | #endif // !CONFIG_OBU |
David Barker | 1a19112 | 2017-09-06 15:24:16 +0100 | [diff] [blame] | 1658 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1659 | #if CONFIG_MAX_TILE |
| 1660 | |
| 1661 | // Same function as av1_read_uniform but reading from uncompresses header wb |
| 1662 | static int rb_read_uniform(struct aom_read_bit_buffer *const rb, int n) { |
| 1663 | const int l = get_unsigned_bits(n); |
| 1664 | const int m = (1 << l) - n; |
| 1665 | const int v = aom_rb_read_literal(rb, l - 1); |
| 1666 | assert(l != 0); |
| 1667 | if (v < m) |
| 1668 | return v; |
| 1669 | else |
| 1670 | return (v << 1) - m + aom_rb_read_literal(rb, 1); |
| 1671 | } |
| 1672 | |
| 1673 | static void read_tile_info_max_tile(AV1_COMMON *const cm, |
| 1674 | struct aom_read_bit_buffer *const rb) { |
Dominic Symes | ab8bb8b | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 1675 | int width_mi = ALIGN_POWER_OF_TWO(cm->mi_cols, cm->mib_size_log2); |
| 1676 | int height_mi = ALIGN_POWER_OF_TWO(cm->mi_rows, cm->mib_size_log2); |
| 1677 | int width_sb = width_mi >> cm->mib_size_log2; |
| 1678 | int height_sb = height_mi >> cm->mib_size_log2; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1679 | int start_sb, size_sb, i; |
| 1680 | |
| 1681 | av1_get_tile_limits(cm); |
| 1682 | cm->uniform_tile_spacing_flag = aom_rb_read_bit(rb); |
| 1683 | |
| 1684 | // Read tile columns |
| 1685 | if (cm->uniform_tile_spacing_flag) { |
| 1686 | cm->log2_tile_cols = cm->min_log2_tile_cols; |
| 1687 | while (cm->log2_tile_cols < cm->max_log2_tile_cols) { |
| 1688 | if (!aom_rb_read_bit(rb)) { |
| 1689 | break; |
| 1690 | } |
| 1691 | cm->log2_tile_cols++; |
| 1692 | } |
| 1693 | } else { |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1694 | for (i = 0, start_sb = 0; width_sb > 0 && i < MAX_TILE_COLS; i++) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1695 | size_sb = 1 + rb_read_uniform(rb, AOMMIN(width_sb, MAX_TILE_WIDTH_SB)); |
| 1696 | cm->tile_col_start_sb[i] = start_sb; |
| 1697 | start_sb += size_sb; |
| 1698 | width_sb -= size_sb; |
| 1699 | } |
| 1700 | cm->tile_cols = i; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1701 | cm->tile_col_start_sb[i] = start_sb + width_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1702 | } |
| 1703 | av1_calculate_tile_cols(cm); |
| 1704 | |
| 1705 | // Read tile rows |
| 1706 | if (cm->uniform_tile_spacing_flag) { |
| 1707 | cm->log2_tile_rows = cm->min_log2_tile_rows; |
| 1708 | while (cm->log2_tile_rows < cm->max_log2_tile_rows) { |
| 1709 | if (!aom_rb_read_bit(rb)) { |
| 1710 | break; |
| 1711 | } |
| 1712 | cm->log2_tile_rows++; |
| 1713 | } |
| 1714 | } else { |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1715 | for (i = 0, start_sb = 0; height_sb > 0 && i < MAX_TILE_ROWS; i++) { |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1716 | size_sb = |
| 1717 | 1 + rb_read_uniform(rb, AOMMIN(height_sb, cm->max_tile_height_sb)); |
| 1718 | cm->tile_row_start_sb[i] = start_sb; |
| 1719 | start_sb += size_sb; |
| 1720 | height_sb -= size_sb; |
| 1721 | } |
| 1722 | cm->tile_rows = i; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 1723 | cm->tile_row_start_sb[i] = start_sb + height_sb; |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1724 | } |
| 1725 | av1_calculate_tile_rows(cm); |
| 1726 | } |
| 1727 | #endif |
| 1728 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1729 | static void read_tile_info(AV1Decoder *const pbi, |
| 1730 | struct aom_read_bit_buffer *const rb) { |
| 1731 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1732 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1733 | cm->single_tile_decoding = 0; |
| 1734 | if (cm->large_scale_tile) { |
| 1735 | struct loopfilter *lf = &cm->lf; |
| 1736 | |
Rupert Swarbrick | 566155f | 2017-10-27 11:59:17 +0100 | [diff] [blame] | 1737 | // Figure out single_tile_decoding by loopfilter_level. |
| 1738 | #if CONFIG_LOOPFILTER_LEVEL |
| 1739 | const int no_loopfilter = !(lf->filter_level[0] || lf->filter_level[1]); |
| 1740 | #else |
| 1741 | const int no_loopfilter = !lf->filter_level; |
| 1742 | #endif |
| 1743 | cm->single_tile_decoding = no_loopfilter ? 1 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1744 | // Read the tile width/height |
| 1745 | #if CONFIG_EXT_PARTITION |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1746 | if (cm->sb_size == BLOCK_128X128) { |
| 1747 | cm->tile_width = aom_rb_read_literal(rb, 5) + 1; |
| 1748 | cm->tile_height = aom_rb_read_literal(rb, 5) + 1; |
| 1749 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1750 | #endif // CONFIG_EXT_PARTITION |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1751 | cm->tile_width = aom_rb_read_literal(rb, 6) + 1; |
| 1752 | cm->tile_height = aom_rb_read_literal(rb, 6) + 1; |
| 1753 | #if CONFIG_EXT_PARTITION |
| 1754 | } |
| 1755 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1756 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1757 | cm->tile_width <<= cm->mib_size_log2; |
| 1758 | cm->tile_height <<= cm->mib_size_log2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1759 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1760 | cm->tile_width = AOMMIN(cm->tile_width, cm->mi_cols); |
| 1761 | cm->tile_height = AOMMIN(cm->tile_height, cm->mi_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1762 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1763 | // Get the number of tiles |
| 1764 | cm->tile_cols = 1; |
| 1765 | while (cm->tile_cols * cm->tile_width < cm->mi_cols) ++cm->tile_cols; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1766 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1767 | cm->tile_rows = 1; |
| 1768 | while (cm->tile_rows * cm->tile_height < cm->mi_rows) ++cm->tile_rows; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1769 | |
Yunqing Wang | 42015d1 | 2017-10-17 15:43:49 -0700 | [diff] [blame] | 1770 | #if CONFIG_DEPENDENT_HORZTILES |
| 1771 | cm->dependent_horz_tiles = 0; |
| 1772 | #endif |
| 1773 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
| 1774 | if (cm->tile_cols * cm->tile_rows > 1) |
| 1775 | cm->loop_filter_across_tiles_enabled = aom_rb_read_bit(rb); |
| 1776 | else |
| 1777 | cm->loop_filter_across_tiles_enabled = 1; |
| 1778 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
| 1779 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1780 | if (cm->tile_cols * cm->tile_rows > 1) { |
| 1781 | // Read the number of bytes used to store tile size |
| 1782 | pbi->tile_col_size_bytes = aom_rb_read_literal(rb, 2) + 1; |
| 1783 | pbi->tile_size_bytes = aom_rb_read_literal(rb, 2) + 1; |
| 1784 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1785 | } else { |
| 1786 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1787 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1788 | #if CONFIG_MAX_TILE |
| 1789 | read_tile_info_max_tile(cm, rb); |
| 1790 | #else |
| 1791 | int min_log2_tile_cols, max_log2_tile_cols, max_ones; |
| 1792 | av1_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1793 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1794 | // columns |
| 1795 | max_ones = max_log2_tile_cols - min_log2_tile_cols; |
| 1796 | cm->log2_tile_cols = min_log2_tile_cols; |
| 1797 | while (max_ones-- && aom_rb_read_bit(rb)) cm->log2_tile_cols++; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1798 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1799 | if (cm->log2_tile_cols > 6) |
| 1800 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 1801 | "Invalid number of tile columns"); |
| 1802 | |
| 1803 | // rows |
| 1804 | cm->log2_tile_rows = aom_rb_read_bit(rb); |
| 1805 | if (cm->log2_tile_rows) cm->log2_tile_rows += aom_rb_read_bit(rb); |
| 1806 | |
Rupert Swarbrick | 5a010aa | 2017-09-26 16:16:48 +0100 | [diff] [blame] | 1807 | cm->tile_width = |
| 1808 | get_tile_size(cm->mi_cols, cm->log2_tile_cols, &cm->tile_cols); |
| 1809 | cm->tile_height = |
| 1810 | get_tile_size(cm->mi_rows, cm->log2_tile_rows, &cm->tile_rows); |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1811 | |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1812 | #endif // CONFIG_MAX_TILE |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 1813 | #if CONFIG_DEPENDENT_HORZTILES |
Dominic Symes | db5d66f | 2017-08-18 18:11:34 +0200 | [diff] [blame] | 1814 | if (cm->tile_rows > 1) |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1815 | cm->dependent_horz_tiles = aom_rb_read_bit(rb); |
| 1816 | else |
| 1817 | cm->dependent_horz_tiles = 0; |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 1818 | #endif |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1819 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Yunqing Wang | 42015d1 | 2017-10-17 15:43:49 -0700 | [diff] [blame] | 1820 | if (cm->tile_cols * cm->tile_rows > 1) |
| 1821 | cm->loop_filter_across_tiles_enabled = aom_rb_read_bit(rb); |
| 1822 | else |
| 1823 | cm->loop_filter_across_tiles_enabled = 1; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1824 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 1825 | |
Thomas Davies | b25ba50 | 2017-07-18 10:18:24 +0100 | [diff] [blame] | 1826 | // tile size magnitude |
| 1827 | pbi->tile_size_bytes = aom_rb_read_literal(rb, 2) + 1; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1828 | #if CONFIG_EXT_TILE |
| 1829 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1830 | #endif // CONFIG_EXT_TILE |
Thomas Davies | 4974e52 | 2016-11-07 17:44:05 +0000 | [diff] [blame] | 1831 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 1832 | // each tile group header is in its own tile group OBU |
| 1833 | #if !CONFIG_OBU |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 1834 | // Store an index to the location of the tile group information |
| 1835 | pbi->tg_size_bit_offset = rb->bit_offset; |
David Barker | 1a19112 | 2017-09-06 15:24:16 +0100 | [diff] [blame] | 1836 | read_tile_group_range(pbi, rb); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 1837 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1840 | static int mem_get_varsize(const uint8_t *src, int sz) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1841 | switch (sz) { |
| 1842 | case 1: return src[0]; |
| 1843 | case 2: return mem_get_le16(src); |
| 1844 | case 3: return mem_get_le24(src); |
| 1845 | case 4: return mem_get_le32(src); |
James Zern | 8889673 | 2017-06-23 15:55:09 -0700 | [diff] [blame] | 1846 | default: assert(0 && "Invalid size"); return -1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | #if CONFIG_EXT_TILE |
| 1851 | // Reads the next tile returning its size and adjusting '*data' accordingly |
| 1852 | // based on 'is_last'. |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1853 | static void get_ls_tile_buffer( |
| 1854 | const uint8_t *const data_end, struct aom_internal_error_info *error_info, |
| 1855 | const uint8_t **data, aom_decrypt_cb decrypt_cb, void *decrypt_state, |
| 1856 | TileBufferDec (*const tile_buffers)[MAX_TILE_COLS], int tile_size_bytes, |
| 1857 | int col, int row, int tile_copy_mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1858 | size_t size; |
| 1859 | |
| 1860 | size_t copy_size = 0; |
| 1861 | const uint8_t *copy_data = NULL; |
| 1862 | |
| 1863 | if (!read_is_valid(*data, tile_size_bytes, data_end)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1864 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1865 | "Truncated packet or corrupt tile length"); |
| 1866 | if (decrypt_cb) { |
| 1867 | uint8_t be_data[4]; |
| 1868 | decrypt_cb(decrypt_state, *data, be_data, tile_size_bytes); |
| 1869 | |
| 1870 | // Only read number of bytes in cm->tile_size_bytes. |
| 1871 | size = mem_get_varsize(be_data, tile_size_bytes); |
| 1872 | } else { |
| 1873 | size = mem_get_varsize(*data, tile_size_bytes); |
| 1874 | } |
| 1875 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1876 | // If tile_copy_mode = 1, then the top bit of the tile header indicates copy |
| 1877 | // mode. |
| 1878 | if (tile_copy_mode && (size >> (tile_size_bytes * 8 - 1)) == 1) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1879 | // The remaining bits in the top byte signal the row offset |
| 1880 | int offset = (size >> (tile_size_bytes - 1) * 8) & 0x7f; |
| 1881 | |
| 1882 | // Currently, only use tiles in same column as reference tiles. |
| 1883 | copy_data = tile_buffers[row - offset][col].data; |
| 1884 | copy_size = tile_buffers[row - offset][col].size; |
| 1885 | size = 0; |
| 1886 | } |
| 1887 | |
| 1888 | *data += tile_size_bytes; |
| 1889 | |
| 1890 | if (size > (size_t)(data_end - *data)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1891 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1892 | "Truncated packet or corrupt tile size"); |
| 1893 | |
| 1894 | if (size > 0) { |
| 1895 | tile_buffers[row][col].data = *data; |
| 1896 | tile_buffers[row][col].size = size; |
| 1897 | } else { |
| 1898 | tile_buffers[row][col].data = copy_data; |
| 1899 | tile_buffers[row][col].size = copy_size; |
| 1900 | } |
| 1901 | |
| 1902 | *data += size; |
| 1903 | |
| 1904 | tile_buffers[row][col].raw_data_end = *data; |
| 1905 | } |
| 1906 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1907 | static void get_ls_tile_buffers( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1908 | AV1Decoder *pbi, const uint8_t *data, const uint8_t *data_end, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1909 | TileBufferDec (*const tile_buffers)[MAX_TILE_COLS]) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1910 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1911 | const int tile_cols = cm->tile_cols; |
| 1912 | const int tile_rows = cm->tile_rows; |
| 1913 | const int have_tiles = tile_cols * tile_rows > 1; |
| 1914 | |
| 1915 | if (!have_tiles) { |
Jingning Han | 99ffce6 | 2017-04-25 15:48:41 -0700 | [diff] [blame] | 1916 | const size_t tile_size = data_end - data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1917 | tile_buffers[0][0].data = data; |
| 1918 | tile_buffers[0][0].size = tile_size; |
| 1919 | tile_buffers[0][0].raw_data_end = NULL; |
| 1920 | } else { |
| 1921 | // We locate only the tile buffers that are required, which are the ones |
| 1922 | // specified by pbi->dec_tile_col and pbi->dec_tile_row. Also, we always |
| 1923 | // need the last (bottom right) tile buffer, as we need to know where the |
| 1924 | // end of the compressed frame buffer is for proper superframe decoding. |
| 1925 | |
| 1926 | const uint8_t *tile_col_data_end[MAX_TILE_COLS]; |
| 1927 | const uint8_t *const data_start = data; |
| 1928 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1929 | const int dec_tile_row = AOMMIN(pbi->dec_tile_row, tile_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1930 | const int single_row = pbi->dec_tile_row >= 0; |
| 1931 | const int tile_rows_start = single_row ? dec_tile_row : 0; |
| 1932 | 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] | 1933 | const int dec_tile_col = AOMMIN(pbi->dec_tile_col, tile_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1934 | const int single_col = pbi->dec_tile_col >= 0; |
| 1935 | const int tile_cols_start = single_col ? dec_tile_col : 0; |
| 1936 | const int tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; |
| 1937 | |
| 1938 | const int tile_col_size_bytes = pbi->tile_col_size_bytes; |
| 1939 | const int tile_size_bytes = pbi->tile_size_bytes; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1940 | const int tile_copy_mode = |
| 1941 | ((AOMMAX(cm->tile_width, cm->tile_height) << MI_SIZE_LOG2) <= 256) ? 1 |
| 1942 | : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1943 | size_t tile_col_size; |
| 1944 | int r, c; |
| 1945 | |
| 1946 | // Read tile column sizes for all columns (we need the last tile buffer) |
| 1947 | for (c = 0; c < tile_cols; ++c) { |
| 1948 | const int is_last = c == tile_cols - 1; |
| 1949 | if (!is_last) { |
| 1950 | tile_col_size = mem_get_varsize(data, tile_col_size_bytes); |
| 1951 | data += tile_col_size_bytes; |
| 1952 | tile_col_data_end[c] = data + tile_col_size; |
| 1953 | } else { |
| 1954 | tile_col_size = data_end - data; |
| 1955 | tile_col_data_end[c] = data_end; |
| 1956 | } |
| 1957 | data += tile_col_size; |
| 1958 | } |
| 1959 | |
| 1960 | data = data_start; |
| 1961 | |
| 1962 | // Read the required tile sizes. |
| 1963 | for (c = tile_cols_start; c < tile_cols_end; ++c) { |
| 1964 | const int is_last = c == tile_cols - 1; |
| 1965 | |
| 1966 | if (c > 0) data = tile_col_data_end[c - 1]; |
| 1967 | |
| 1968 | if (!is_last) data += tile_col_size_bytes; |
| 1969 | |
| 1970 | // Get the whole of the last column, otherwise stop at the required tile. |
| 1971 | for (r = 0; r < (is_last ? tile_rows : tile_rows_end); ++r) { |
| 1972 | tile_buffers[r][c].col = c; |
| 1973 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1974 | get_ls_tile_buffer(tile_col_data_end[c], &pbi->common.error, &data, |
| 1975 | pbi->decrypt_cb, pbi->decrypt_state, tile_buffers, |
| 1976 | tile_size_bytes, c, r, tile_copy_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | |
| 1980 | // If we have not read the last column, then read it to get the last tile. |
| 1981 | if (tile_cols_end != tile_cols) { |
| 1982 | c = tile_cols - 1; |
| 1983 | |
| 1984 | data = tile_col_data_end[c - 1]; |
| 1985 | |
| 1986 | for (r = 0; r < tile_rows; ++r) { |
| 1987 | tile_buffers[r][c].col = c; |
| 1988 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1989 | get_ls_tile_buffer(tile_col_data_end[c], &pbi->common.error, &data, |
| 1990 | pbi->decrypt_cb, pbi->decrypt_state, tile_buffers, |
| 1991 | tile_size_bytes, c, r, tile_copy_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1992 | } |
| 1993 | } |
| 1994 | } |
| 1995 | } |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 1996 | #endif // CONFIG_EXT_TILE |
| 1997 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1998 | // Reads the next tile returning its size and adjusting '*data' accordingly |
| 1999 | // based on 'is_last'. |
| 2000 | static void get_tile_buffer(const uint8_t *const data_end, |
| 2001 | const int tile_size_bytes, int is_last, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2002 | struct aom_internal_error_info *error_info, |
| 2003 | const uint8_t **data, aom_decrypt_cb decrypt_cb, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2004 | void *decrypt_state, TileBufferDec *const buf) { |
| 2005 | size_t size; |
| 2006 | |
| 2007 | if (!is_last) { |
Yaowu Xu | 0a79a1b | 2017-02-17 13:04:54 -0800 | [diff] [blame] | 2008 | if (!read_is_valid(*data, tile_size_bytes, data_end)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2009 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2010 | "Truncated packet or corrupt tile length"); |
| 2011 | |
| 2012 | if (decrypt_cb) { |
| 2013 | uint8_t be_data[4]; |
| 2014 | decrypt_cb(decrypt_state, *data, be_data, tile_size_bytes); |
| 2015 | size = mem_get_varsize(be_data, tile_size_bytes); |
| 2016 | } else { |
| 2017 | size = mem_get_varsize(*data, tile_size_bytes); |
| 2018 | } |
| 2019 | *data += tile_size_bytes; |
| 2020 | |
| 2021 | if (size > (size_t)(data_end - *data)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2022 | aom_internal_error(error_info, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2023 | "Truncated packet or corrupt tile size"); |
| 2024 | } else { |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 2025 | #if !CONFIG_OBU || CONFIG_ADD_4BYTES_OBUSIZE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2026 | size = data_end - *data; |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 2027 | #else |
| 2028 | size = mem_get_varsize(*data, tile_size_bytes); |
| 2029 | *data += tile_size_bytes; |
| 2030 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | buf->data = *data; |
| 2034 | buf->size = size; |
| 2035 | |
| 2036 | *data += size; |
| 2037 | } |
| 2038 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2039 | static void get_tile_buffers(AV1Decoder *pbi, const uint8_t *data, |
| 2040 | const uint8_t *data_end, |
| 2041 | TileBufferDec (*const tile_buffers)[MAX_TILE_COLS], |
| 2042 | int startTile, int endTile) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2043 | AV1_COMMON *const cm = &pbi->common; |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2044 | int r, c; |
| 2045 | const int tile_cols = cm->tile_cols; |
| 2046 | const int tile_rows = cm->tile_rows; |
| 2047 | int tc = 0; |
| 2048 | int first_tile_in_tg = 0; |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 2049 | #if !CONFIG_OBU |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2050 | struct aom_read_bit_buffer rb_tg_hdr; |
| 2051 | uint8_t clear_data[MAX_AV1_HEADER_SIZE]; |
James Zern | 6efba48 | 2017-04-20 20:53:49 -0700 | [diff] [blame] | 2052 | const size_t hdr_size = pbi->uncomp_hdr_size + pbi->first_partition_size; |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2053 | const int tg_size_bit_offset = pbi->tg_size_bit_offset; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2054 | #endif |
| 2055 | |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 2056 | #if CONFIG_DEPENDENT_HORZTILES |
| 2057 | int tile_group_start_col = 0; |
| 2058 | int tile_group_start_row = 0; |
| 2059 | #endif |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2060 | |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 2061 | #if CONFIG_SIMPLE_BWD_ADAPT |
| 2062 | size_t max_tile_size = 0; |
| 2063 | cm->largest_tile_id = 0; |
| 2064 | #endif |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2065 | for (r = 0; r < tile_rows; ++r) { |
| 2066 | for (c = 0; c < tile_cols; ++c, ++tc) { |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2067 | TileBufferDec *const buf = &tile_buffers[r][c]; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2068 | #if CONFIG_OBU |
| 2069 | const int is_last = (tc == endTile); |
| 2070 | const size_t hdr_offset = 0; |
| 2071 | #else |
Thomas Davies | a0de6d5 | 2017-01-20 14:45:25 +0000 | [diff] [blame] | 2072 | const int is_last = (r == tile_rows - 1) && (c == tile_cols - 1); |
James Zern | 6efba48 | 2017-04-20 20:53:49 -0700 | [diff] [blame] | 2073 | const size_t hdr_offset = (tc && tc == first_tile_in_tg) ? hdr_size : 0; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2074 | #endif |
| 2075 | |
| 2076 | if (tc < startTile || tc > endTile) continue; |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2077 | |
Rupert Swarbrick | cd75739 | 2017-09-01 13:57:53 +0100 | [diff] [blame] | 2078 | if (data + hdr_offset >= data_end) |
| 2079 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 2080 | "Data ended before all tiles were read."); |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2081 | buf->col = c; |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 2082 | #if CONFIG_OBU |
| 2083 | #if CONFIG_DEPENDENT_HORZTILES |
| 2084 | if (tc == startTile) { |
| 2085 | tile_group_start_row = r; |
| 2086 | tile_group_start_col = c; |
| 2087 | } |
| 2088 | #endif // CONFIG_DEPENDENT_HORZTILES |
| 2089 | #else // CONFIG_OBU |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2090 | if (hdr_offset) { |
| 2091 | init_read_bit_buffer(pbi, &rb_tg_hdr, data, data_end, clear_data); |
| 2092 | rb_tg_hdr.bit_offset = tg_size_bit_offset; |
David Barker | 1a19112 | 2017-09-06 15:24:16 +0100 | [diff] [blame] | 2093 | read_tile_group_range(pbi, &rb_tg_hdr); |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 2094 | #if CONFIG_DEPENDENT_HORZTILES |
David Barker | 1a19112 | 2017-09-06 15:24:16 +0100 | [diff] [blame] | 2095 | tile_group_start_row = r; |
| 2096 | tile_group_start_col = c; |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 2097 | #endif |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2098 | } |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 2099 | #endif // CONFIG_OBU |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2100 | first_tile_in_tg += tc == first_tile_in_tg ? pbi->tg_size : 0; |
| 2101 | data += hdr_offset; |
Thomas Davies | a0de6d5 | 2017-01-20 14:45:25 +0000 | [diff] [blame] | 2102 | get_tile_buffer(data_end, pbi->tile_size_bytes, is_last, |
| 2103 | &pbi->common.error, &data, pbi->decrypt_cb, |
| 2104 | pbi->decrypt_state, buf); |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 2105 | #if CONFIG_DEPENDENT_HORZTILES |
| 2106 | cm->tile_group_start_row[r][c] = tile_group_start_row; |
| 2107 | cm->tile_group_start_col[r][c] = tile_group_start_col; |
| 2108 | #endif |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 2109 | #if CONFIG_SIMPLE_BWD_ADAPT |
| 2110 | if (buf->size > max_tile_size) { |
| 2111 | max_tile_size = buf->size; |
| 2112 | cm->largest_tile_id = r * tile_cols + c; |
| 2113 | } |
| 2114 | #endif |
Thomas Davies | 80188d1 | 2016-10-26 16:08:35 -0700 | [diff] [blame] | 2115 | } |
| 2116 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2117 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2118 | |
David Barker | 5c06a64 | 2017-08-18 13:18:16 +0100 | [diff] [blame] | 2119 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 2120 | static void dec_setup_across_tile_boundary_info( |
| 2121 | const AV1_COMMON *const cm, const TileInfo *const tile_info) { |
Frederic Barbier | 94e3856 | 2017-08-16 14:38:48 +0200 | [diff] [blame] | 2122 | if (tile_info->mi_row_start >= tile_info->mi_row_end || |
| 2123 | tile_info->mi_col_start >= tile_info->mi_col_end) |
| 2124 | return; |
| 2125 | |
David Barker | 5c06a64 | 2017-08-18 13:18:16 +0100 | [diff] [blame] | 2126 | if (!cm->loop_filter_across_tiles_enabled) { |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 2127 | av1_setup_across_tile_boundary_info(cm, tile_info); |
| 2128 | } |
| 2129 | } |
David Barker | 5c06a64 | 2017-08-18 13:18:16 +0100 | [diff] [blame] | 2130 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 2131 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2132 | static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data, |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2133 | const uint8_t *data_end, int startTile, |
| 2134 | int endTile) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2135 | AV1_COMMON *const cm = &pbi->common; |
Cheng Chen | 9ac7a0f | 2017-10-17 20:36:46 -0700 | [diff] [blame] | 2136 | #if !CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2137 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
Cheng Chen | 9ac7a0f | 2017-10-17 20:36:46 -0700 | [diff] [blame] | 2138 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2139 | const int tile_cols = cm->tile_cols; |
| 2140 | const int tile_rows = cm->tile_rows; |
| 2141 | const int n_tiles = tile_cols * tile_rows; |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 2142 | TileBufferDec(*const tile_buffers)[MAX_TILE_COLS] = pbi->tile_buffers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2143 | #if CONFIG_EXT_TILE |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2144 | const int dec_tile_row = AOMMIN(pbi->dec_tile_row, tile_rows); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2145 | const int single_row = pbi->dec_tile_row >= 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2146 | const int dec_tile_col = AOMMIN(pbi->dec_tile_col, tile_cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2147 | const int single_col = pbi->dec_tile_col >= 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2148 | #endif // CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2149 | int tile_rows_start; |
| 2150 | int tile_rows_end; |
| 2151 | int tile_cols_start; |
| 2152 | int tile_cols_end; |
| 2153 | int inv_col_order; |
| 2154 | int inv_row_order; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2155 | int tile_row, tile_col; |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 2156 | uint8_t allow_update_cdf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2157 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2158 | #if CONFIG_EXT_TILE |
| 2159 | if (cm->large_scale_tile) { |
| 2160 | tile_rows_start = single_row ? dec_tile_row : 0; |
| 2161 | tile_rows_end = single_row ? dec_tile_row + 1 : tile_rows; |
| 2162 | tile_cols_start = single_col ? dec_tile_col : 0; |
| 2163 | tile_cols_end = single_col ? tile_cols_start + 1 : tile_cols; |
| 2164 | inv_col_order = pbi->inv_tile_order && !single_col; |
| 2165 | inv_row_order = pbi->inv_tile_order && !single_row; |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 2166 | allow_update_cdf = 0; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2167 | } else { |
| 2168 | #endif // CONFIG_EXT_TILE |
| 2169 | tile_rows_start = 0; |
| 2170 | tile_rows_end = tile_rows; |
| 2171 | tile_cols_start = 0; |
| 2172 | tile_cols_end = tile_cols; |
| 2173 | inv_col_order = pbi->inv_tile_order; |
| 2174 | inv_row_order = pbi->inv_tile_order; |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 2175 | allow_update_cdf = 1; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2176 | #if CONFIG_EXT_TILE |
| 2177 | } |
| 2178 | #endif // CONFIG_EXT_TILE |
| 2179 | |
Cheng Chen | 9ac7a0f | 2017-10-17 20:36:46 -0700 | [diff] [blame] | 2180 | #if !CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2181 | if (cm->lf.filter_level && !cm->skip_loop_filter && |
| 2182 | pbi->lf_worker.data1 == NULL) { |
| 2183 | CHECK_MEM_ERROR(cm, pbi->lf_worker.data1, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2184 | aom_memalign(32, sizeof(LFWorkerData))); |
| 2185 | pbi->lf_worker.hook = (AVxWorkerHook)av1_loop_filter_worker; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2186 | if (pbi->max_threads > 1 && !winterface->reset(&pbi->lf_worker)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2187 | aom_internal_error(&cm->error, AOM_CODEC_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2188 | "Loop filter thread creation failed"); |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | if (cm->lf.filter_level && !cm->skip_loop_filter) { |
| 2193 | LFWorkerData *const lf_data = (LFWorkerData *)pbi->lf_worker.data1; |
| 2194 | // Be sure to sync as we might be resuming after a failed frame decode. |
| 2195 | winterface->sync(&pbi->lf_worker); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2196 | av1_loop_filter_data_reset(lf_data, get_frame_new_buffer(cm), cm, |
| 2197 | pbi->mb.plane); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2198 | } |
Cheng Chen | 9ac7a0f | 2017-10-17 20:36:46 -0700 | [diff] [blame] | 2199 | #endif // CONFIG_LOOPFILTER_LEVEL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2200 | |
| 2201 | assert(tile_rows <= MAX_TILE_ROWS); |
| 2202 | assert(tile_cols <= MAX_TILE_COLS); |
| 2203 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2204 | #if CONFIG_EXT_TILE |
| 2205 | if (cm->large_scale_tile) |
| 2206 | get_ls_tile_buffers(pbi, data, data_end, tile_buffers); |
| 2207 | else |
| 2208 | #endif // CONFIG_EXT_TILE |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2209 | get_tile_buffers(pbi, data, data_end, tile_buffers, startTile, endTile); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2210 | |
| 2211 | if (pbi->tile_data == NULL || n_tiles != pbi->allocated_tiles) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2212 | aom_free(pbi->tile_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2213 | CHECK_MEM_ERROR(cm, pbi->tile_data, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2214 | aom_memalign(32, n_tiles * (sizeof(*pbi->tile_data)))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2215 | pbi->allocated_tiles = n_tiles; |
| 2216 | } |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2217 | #if CONFIG_ACCOUNTING |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 2218 | if (pbi->acct_enabled) { |
| 2219 | aom_accounting_reset(&pbi->accounting); |
| 2220 | } |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2221 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2222 | // Load all tile information into tile_data. |
| 2223 | for (tile_row = tile_rows_start; tile_row < tile_rows_end; ++tile_row) { |
| 2224 | for (tile_col = tile_cols_start; tile_col < tile_cols_end; ++tile_col) { |
| 2225 | const TileBufferDec *const buf = &tile_buffers[tile_row][tile_col]; |
| 2226 | TileData *const td = pbi->tile_data + tile_cols * tile_row + tile_col; |
| 2227 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2228 | if (tile_row * cm->tile_cols + tile_col < startTile || |
| 2229 | tile_row * cm->tile_cols + tile_col > endTile) |
| 2230 | continue; |
| 2231 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2232 | td->cm = cm; |
| 2233 | td->xd = pbi->mb; |
| 2234 | td->xd.corrupted = 0; |
| 2235 | td->xd.counts = |
| 2236 | cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD |
| 2237 | ? &cm->counts |
| 2238 | : NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2239 | av1_zero(td->dqcoeff); |
| 2240 | av1_tile_init(&td->xd.tile, td->cm, tile_row, tile_col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2241 | setup_bool_decoder(buf->data, data_end, buf->size, &cm->error, |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 2242 | &td->bit_reader, allow_update_cdf, |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2243 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2244 | 1 << cm->ans_window_size_log2, |
| 2245 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2246 | pbi->decrypt_cb, pbi->decrypt_state); |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2247 | #if CONFIG_ACCOUNTING |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 2248 | if (pbi->acct_enabled) { |
David Barker | d971f40 | 2016-10-25 13:52:07 +0100 | [diff] [blame] | 2249 | td->bit_reader.accounting = &pbi->accounting; |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 2250 | } else { |
David Barker | d971f40 | 2016-10-25 13:52:07 +0100 | [diff] [blame] | 2251 | td->bit_reader.accounting = NULL; |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 2252 | } |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2253 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 2254 | av1_init_macroblockd(cm, &td->xd, |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 2255 | #if CONFIG_CFL |
| 2256 | &td->cfl, |
| 2257 | #endif |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 2258 | td->dqcoeff); |
Yushin Cho | c49ef3a | 2017-03-13 17:27:25 -0700 | [diff] [blame] | 2259 | |
Thomas Davies | f77d4ad | 2017-01-10 18:55:42 +0000 | [diff] [blame] | 2260 | // Initialise the tile context from the frame context |
| 2261 | td->tctx = *cm->fc; |
| 2262 | td->xd.tile_ctx = &td->tctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2263 | td->xd.plane[0].color_index_map = td->color_index_map[0]; |
| 2264 | td->xd.plane[1].color_index_map = td->color_index_map[1]; |
Sarah Parker | 5c6744b | 2017-08-25 17:27:45 -0700 | [diff] [blame] | 2265 | #if CONFIG_MRC_TX |
| 2266 | td->xd.mrc_mask = td->mrc_mask; |
| 2267 | #endif // CONFIG_MRC_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | for (tile_row = tile_rows_start; tile_row < tile_rows_end; ++tile_row) { |
| 2272 | const int row = inv_row_order ? tile_rows - 1 - tile_row : tile_row; |
| 2273 | int mi_row = 0; |
| 2274 | TileInfo tile_info; |
| 2275 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2276 | av1_tile_set_row(&tile_info, cm, row); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2277 | |
| 2278 | for (tile_col = tile_cols_start; tile_col < tile_cols_end; ++tile_col) { |
| 2279 | const int col = inv_col_order ? tile_cols - 1 - tile_col : tile_col; |
| 2280 | TileData *const td = pbi->tile_data + tile_cols * row + col; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2281 | |
| 2282 | if (tile_row * cm->tile_cols + tile_col < startTile || |
| 2283 | tile_row * cm->tile_cols + tile_col > endTile) |
| 2284 | continue; |
| 2285 | |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2286 | #if CONFIG_ACCOUNTING |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 2287 | if (pbi->acct_enabled) { |
David Barker | d971f40 | 2016-10-25 13:52:07 +0100 | [diff] [blame] | 2288 | td->bit_reader.accounting->last_tell_frac = |
| 2289 | aom_reader_tell_frac(&td->bit_reader); |
Nathan E. Egge | eb64fc2 | 2016-10-05 19:33:48 -0400 | [diff] [blame] | 2290 | } |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 2291 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2292 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2293 | av1_tile_set_col(&tile_info, cm, col); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2294 | |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 2295 | #if CONFIG_DEPENDENT_HORZTILES |
Fangwen Fu | 73126c0 | 2017-02-08 22:37:47 -0800 | [diff] [blame] | 2296 | av1_tile_set_tg_boundary(&tile_info, cm, tile_row, tile_col); |
| 2297 | if (!cm->dependent_horz_tiles || tile_row == 0 || |
| 2298 | tile_info.tg_horz_boundary) { |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 2299 | av1_zero_above_context(cm, tile_info.mi_col_start, |
| 2300 | tile_info.mi_col_end); |
| 2301 | } |
| 2302 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2303 | av1_zero_above_context(cm, tile_info.mi_col_start, tile_info.mi_col_end); |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 2304 | #endif |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 2305 | #if CONFIG_LOOP_RESTORATION |
| 2306 | for (int p = 0; p < MAX_MB_PLANE; ++p) { |
| 2307 | set_default_wiener(td->xd.wiener_info + p); |
| 2308 | set_default_sgrproj(td->xd.sgrproj_info + p); |
| 2309 | } |
| 2310 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2311 | |
David Barker | 5c06a64 | 2017-08-18 13:18:16 +0100 | [diff] [blame] | 2312 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 2313 | dec_setup_across_tile_boundary_info(cm, &tile_info); |
David Barker | 5c06a64 | 2017-08-18 13:18:16 +0100 | [diff] [blame] | 2314 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yi Luo | f190a16 | 2017-07-13 16:16:56 -0700 | [diff] [blame] | 2315 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2316 | for (mi_row = tile_info.mi_row_start; mi_row < tile_info.mi_row_end; |
| 2317 | mi_row += cm->mib_size) { |
| 2318 | int mi_col; |
| 2319 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2320 | av1_zero_left_context(&td->xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2321 | |
| 2322 | for (mi_col = tile_info.mi_col_start; mi_col < tile_info.mi_col_end; |
| 2323 | mi_col += cm->mib_size) { |
Angie Chiang | d9af8ac | 2017-10-25 10:48:53 -0700 | [diff] [blame] | 2324 | #if CONFIG_SYMBOLRATE |
| 2325 | av1_record_superblock(td->xd.counts); |
| 2326 | #endif |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 2327 | decode_partition(pbi, &td->xd, mi_row, mi_col, &td->bit_reader, |
| 2328 | cm->sb_size); |
Sebastien Alaiwan | 1bc94fc | 2017-10-31 10:25:17 +0100 | [diff] [blame] | 2329 | #if NC_MODE_INFO |
Yue Chen | 9ab6d71 | 2017-01-12 15:50:46 -0800 | [diff] [blame] | 2330 | detoken_and_recon_sb(pbi, &td->xd, mi_row, mi_col, &td->bit_reader, |
| 2331 | cm->sb_size); |
| 2332 | #endif |
Cheng Chen | 5ad5b28 | 2017-10-05 16:36:06 -0700 | [diff] [blame] | 2333 | #if CONFIG_LPF_SB |
| 2334 | if (USE_LOOP_FILTER_SUPERBLOCK) { |
| 2335 | // apply deblocking filtering right after each superblock is decoded |
| 2336 | const int guess_filter_lvl = FAKE_FILTER_LEVEL; |
| 2337 | av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, |
| 2338 | guess_filter_lvl, 0, 1, mi_row, mi_col); |
| 2339 | } |
| 2340 | #endif // CONFIG_LPF_SB |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2341 | } |
Angie Chiang | d0916d9 | 2017-03-10 17:54:18 -0800 | [diff] [blame] | 2342 | aom_merge_corrupted_flag(&pbi->mb.corrupted, td->xd.corrupted); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2343 | if (pbi->mb.corrupted) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2344 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2345 | "Failed to decode tile data"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2346 | } |
| 2347 | } |
| 2348 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2349 | #if !CONFIG_OBU |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2350 | assert(mi_row > 0); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2351 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2352 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2353 | // After loopfiltering, the last 7 row pixels in each superblock row may |
| 2354 | // still be changed by the longest loopfilter of the next superblock row. |
| 2355 | if (cm->frame_parallel_decode) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2356 | av1_frameworker_broadcast(pbi->cur_buf, mi_row << cm->mib_size_log2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
Cheng Chen | 5ad5b28 | 2017-10-05 16:36:06 -0700 | [diff] [blame] | 2359 | #if CONFIG_INTRABC |
| 2360 | // When intraBC is on, do loop filtering per superblock, |
| 2361 | // instead of do it after the whole frame has been encoded, |
| 2362 | // as is in the else branch |
| 2363 | #else |
Cheng Chen | e94df5c | 2017-07-19 17:25:33 -0700 | [diff] [blame] | 2364 | // Loopfilter the whole frame. |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 2365 | #if CONFIG_LPF_SB |
| 2366 | av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, |
| 2367 | cm->lf.filter_level, 0, 0, 0, 0); |
| 2368 | #else |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2369 | #if CONFIG_OBU |
| 2370 | if (endTile == cm->tile_rows * cm->tile_cols - 1) |
| 2371 | #endif |
David Barker | 3dffa27 | 2017-10-18 17:07:26 +0100 | [diff] [blame] | 2372 | #if CONFIG_LOOPFILTER_LEVEL |
| 2373 | if (cm->lf.filter_level[0] || cm->lf.filter_level[1]) { |
| 2374 | av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, |
| 2375 | cm->lf.filter_level[0], cm->lf.filter_level[1], 0, |
| 2376 | 0); |
| 2377 | av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, |
| 2378 | cm->lf.filter_level_u, cm->lf.filter_level_u, 1, 0); |
| 2379 | av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, |
| 2380 | cm->lf.filter_level_v, cm->lf.filter_level_v, 2, 0); |
| 2381 | } |
| 2382 | #else |
| 2383 | av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb, |
| 2384 | cm->lf.filter_level, 0, 0); |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 2385 | #endif // CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 2386 | #endif // CONFIG_LPF_SB |
Cheng Chen | 5ad5b28 | 2017-10-05 16:36:06 -0700 | [diff] [blame] | 2387 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2388 | if (cm->frame_parallel_decode) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2389 | av1_frameworker_broadcast(pbi->cur_buf, INT_MAX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2390 | |
| 2391 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2392 | if (cm->large_scale_tile) { |
| 2393 | if (n_tiles == 1) { |
| 2394 | #if CONFIG_ANS |
| 2395 | return data_end; |
| 2396 | #else |
| 2397 | // Find the end of the single tile buffer |
| 2398 | return aom_reader_find_end(&pbi->tile_data->bit_reader); |
| 2399 | #endif // CONFIG_ANS |
| 2400 | } else { |
| 2401 | // Return the end of the last tile buffer |
| 2402 | return tile_buffers[tile_rows - 1][tile_cols - 1].raw_data_end; |
| 2403 | } |
| 2404 | } else { |
| 2405 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2406 | #if CONFIG_ANS |
| 2407 | return data_end; |
| 2408 | #else |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2409 | #if !CONFIG_OBU |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2410 | { |
| 2411 | // Get last tile data. |
| 2412 | TileData *const td = pbi->tile_data + tile_cols * tile_rows - 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2413 | return aom_reader_find_end(&td->bit_reader); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2414 | } |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2415 | #else |
| 2416 | TileData *const td = pbi->tile_data + endTile; |
| 2417 | return aom_reader_find_end(&td->bit_reader); |
| 2418 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2419 | #endif // CONFIG_ANS |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 2420 | #if CONFIG_EXT_TILE |
| 2421 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2422 | #endif // CONFIG_EXT_TILE |
| 2423 | } |
| 2424 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2425 | static void error_handler(void *data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2426 | AV1_COMMON *const cm = (AV1_COMMON *)data; |
| 2427 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, "Truncated packet"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2430 | static void read_bitdepth_colorspace_sampling(AV1_COMMON *cm, |
Sebastien Alaiwan | 8b7a4e1 | 2017-06-13 11:25:57 +0200 | [diff] [blame] | 2431 | struct aom_read_bit_buffer *rb, |
| 2432 | int allow_lowbitdepth) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2433 | if (cm->profile >= PROFILE_2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2434 | cm->bit_depth = aom_rb_read_bit(rb) ? AOM_BITS_12 : AOM_BITS_10; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2435 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2436 | cm->bit_depth = AOM_BITS_8; |
Sebastien Alaiwan | 9837813 | 2017-01-04 11:23:09 +0100 | [diff] [blame] | 2437 | } |
| 2438 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2439 | #if CONFIG_HIGHBITDEPTH |
Sebastien Alaiwan | 8b7a4e1 | 2017-06-13 11:25:57 +0200 | [diff] [blame] | 2440 | cm->use_highbitdepth = cm->bit_depth > AOM_BITS_8 || !allow_lowbitdepth; |
James Zern | 91adea5 | 2017-06-15 23:27:26 -0700 | [diff] [blame] | 2441 | #else |
| 2442 | (void)allow_lowbitdepth; |
Sebastien Alaiwan | 9837813 | 2017-01-04 11:23:09 +0100 | [diff] [blame] | 2443 | #endif |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 2444 | #if CONFIG_COLORSPACE_HEADERS |
| 2445 | cm->color_space = aom_rb_read_literal(rb, 5); |
| 2446 | cm->transfer_function = aom_rb_read_literal(rb, 5); |
| 2447 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2448 | cm->color_space = aom_rb_read_literal(rb, 3); |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 2449 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2450 | if (cm->color_space != AOM_CS_SRGB) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2451 | // [16,235] (including xvycc) vs [0,255] range |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2452 | cm->color_range = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2453 | if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2454 | cm->subsampling_x = aom_rb_read_bit(rb); |
| 2455 | cm->subsampling_y = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2456 | if (cm->subsampling_x == 1 && cm->subsampling_y == 1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2457 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2458 | "4:2:0 color not supported in profile 1 or 3"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2459 | if (aom_rb_read_bit(rb)) |
| 2460 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2461 | "Reserved bit set"); |
| 2462 | } else { |
| 2463 | cm->subsampling_y = cm->subsampling_x = 1; |
| 2464 | } |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 2465 | #if CONFIG_COLORSPACE_HEADERS |
| 2466 | if (cm->subsampling_x == 1 && cm->subsampling_y == 1) { |
| 2467 | cm->chroma_sample_position = aom_rb_read_literal(rb, 2); |
| 2468 | } |
| 2469 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2470 | } else { |
| 2471 | if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) { |
| 2472 | // Note if colorspace is SRGB then 4:4:4 chroma sampling is assumed. |
| 2473 | // 4:2:2 or 4:4:0 chroma sampling is not allowed. |
| 2474 | cm->subsampling_y = cm->subsampling_x = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2475 | if (aom_rb_read_bit(rb)) |
| 2476 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2477 | "Reserved bit set"); |
| 2478 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2479 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2480 | "4:4:4 color not supported in profile 0 or 2"); |
| 2481 | } |
| 2482 | } |
| 2483 | } |
| 2484 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2485 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2486 | void read_sequence_header(SequenceHeader *seq_params, |
| 2487 | struct aom_read_bit_buffer *rb) { |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 2488 | #if CONFIG_FRAME_SIZE |
| 2489 | int num_bits_width = aom_rb_read_literal(rb, 4) + 1; |
| 2490 | int num_bits_height = aom_rb_read_literal(rb, 4) + 1; |
| 2491 | int max_frame_width = aom_rb_read_literal(rb, num_bits_width) + 1; |
| 2492 | int max_frame_height = aom_rb_read_literal(rb, num_bits_height) + 1; |
| 2493 | |
| 2494 | seq_params->num_bits_width = num_bits_width; |
| 2495 | seq_params->num_bits_height = num_bits_height; |
| 2496 | seq_params->max_frame_width = max_frame_width; |
| 2497 | seq_params->max_frame_height = max_frame_height; |
| 2498 | #endif |
| 2499 | |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2500 | /* Placeholder for actually reading from the bitstream */ |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2501 | seq_params->frame_id_numbers_present_flag = aom_rb_read_bit(rb); |
| 2502 | if (seq_params->frame_id_numbers_present_flag) { |
Frederic Barbier | 4d5d90e | 2017-10-13 09:22:33 +0200 | [diff] [blame] | 2503 | // We must always have delta_frame_id_length < frame_id_length, |
| 2504 | // in order for a frame to be referenced with a unique delta. |
| 2505 | // Avoid wasting bits by using a coding that enforces this restriction. |
Frederic Barbier | e83fcfe | 2017-10-13 10:37:50 +0200 | [diff] [blame] | 2506 | 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] | 2507 | seq_params->frame_id_length = |
| 2508 | aom_rb_read_literal(rb, 3) + seq_params->delta_frame_id_length + 1; |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2509 | } |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2510 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 2511 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2512 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2513 | static void read_compound_tools(AV1_COMMON *cm, |
| 2514 | struct aom_read_bit_buffer *rb) { |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2515 | if (!frame_is_intra_only(cm) && cm->reference_mode != COMPOUND_REFERENCE) { |
| 2516 | cm->allow_interintra_compound = aom_rb_read_bit(rb); |
| 2517 | } else { |
| 2518 | cm->allow_interintra_compound = 0; |
| 2519 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2520 | #if CONFIG_COMPOUND_SINGLEREF |
| 2521 | if (!frame_is_intra_only(cm)) { |
| 2522 | #else // !CONFIG_COMPOUND_SINGLEREF |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2523 | if (!frame_is_intra_only(cm) && cm->reference_mode != SINGLE_REFERENCE) { |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 2524 | #endif // CONFIG_COMPOUND_SINGLEREF |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2525 | cm->allow_masked_compound = aom_rb_read_bit(rb); |
| 2526 | } else { |
| 2527 | cm->allow_masked_compound = 0; |
| 2528 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2529 | } |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 2530 | |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2531 | static int read_global_motion_params(WarpedMotionParams *params, |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 2532 | const WarpedMotionParams *ref_params, |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2533 | struct aom_read_bit_buffer *rb, |
| 2534 | int allow_hp) { |
| 2535 | TransformationType type = aom_rb_read_bit(rb); |
| 2536 | if (type != IDENTITY) { |
| 2537 | #if GLOBAL_TRANS_TYPES > 4 |
| 2538 | type += aom_rb_read_literal(rb, GLOBAL_TYPE_BITS); |
| 2539 | #else |
| 2540 | if (aom_rb_read_bit(rb)) |
| 2541 | type = ROTZOOM; |
| 2542 | else |
| 2543 | type = aom_rb_read_bit(rb) ? TRANSLATION : AFFINE; |
| 2544 | #endif // GLOBAL_TRANS_TYPES > 4 |
| 2545 | } |
| 2546 | |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 2547 | *params = default_warp_params; |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2548 | params->wmtype = type; |
Sebastien Alaiwan | 238a6d6 | 2017-11-01 11:29:46 +0100 | [diff] [blame] | 2549 | |
| 2550 | if (type >= ROTZOOM) { |
| 2551 | params->wmmat[2] = aom_rb_read_signed_primitive_refsubexpfin( |
| 2552 | rb, GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 2553 | (ref_params->wmmat[2] >> GM_ALPHA_PREC_DIFF) - |
| 2554 | (1 << GM_ALPHA_PREC_BITS)) * |
| 2555 | GM_ALPHA_DECODE_FACTOR + |
| 2556 | (1 << WARPEDMODEL_PREC_BITS); |
| 2557 | params->wmmat[3] = aom_rb_read_signed_primitive_refsubexpfin( |
| 2558 | rb, GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 2559 | (ref_params->wmmat[3] >> GM_ALPHA_PREC_DIFF)) * |
| 2560 | GM_ALPHA_DECODE_FACTOR; |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2561 | } |
Sebastien Alaiwan | 238a6d6 | 2017-11-01 11:29:46 +0100 | [diff] [blame] | 2562 | |
| 2563 | if (type >= AFFINE) { |
| 2564 | params->wmmat[4] = aom_rb_read_signed_primitive_refsubexpfin( |
| 2565 | rb, GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 2566 | (ref_params->wmmat[4] >> GM_ALPHA_PREC_DIFF)) * |
| 2567 | GM_ALPHA_DECODE_FACTOR; |
| 2568 | params->wmmat[5] = aom_rb_read_signed_primitive_refsubexpfin( |
| 2569 | rb, GM_ALPHA_MAX + 1, SUBEXPFIN_K, |
| 2570 | (ref_params->wmmat[5] >> GM_ALPHA_PREC_DIFF) - |
| 2571 | (1 << GM_ALPHA_PREC_BITS)) * |
| 2572 | GM_ALPHA_DECODE_FACTOR + |
| 2573 | (1 << WARPEDMODEL_PREC_BITS); |
| 2574 | } else { |
| 2575 | params->wmmat[4] = -params->wmmat[3]; |
| 2576 | params->wmmat[5] = params->wmmat[2]; |
| 2577 | } |
| 2578 | |
| 2579 | if (type >= TRANSLATION) { |
| 2580 | const int trans_bits = (type == TRANSLATION) |
| 2581 | ? GM_ABS_TRANS_ONLY_BITS - !allow_hp |
| 2582 | : GM_ABS_TRANS_BITS; |
| 2583 | const int trans_dec_factor = |
| 2584 | (type == TRANSLATION) ? GM_TRANS_ONLY_DECODE_FACTOR * (1 << !allow_hp) |
| 2585 | : GM_TRANS_DECODE_FACTOR; |
| 2586 | const int trans_prec_diff = (type == TRANSLATION) |
| 2587 | ? GM_TRANS_ONLY_PREC_DIFF + !allow_hp |
| 2588 | : GM_TRANS_PREC_DIFF; |
| 2589 | params->wmmat[0] = aom_rb_read_signed_primitive_refsubexpfin( |
| 2590 | rb, (1 << trans_bits) + 1, SUBEXPFIN_K, |
| 2591 | (ref_params->wmmat[0] >> trans_prec_diff)) * |
| 2592 | trans_dec_factor; |
| 2593 | params->wmmat[1] = aom_rb_read_signed_primitive_refsubexpfin( |
| 2594 | rb, (1 << trans_bits) + 1, SUBEXPFIN_K, |
| 2595 | (ref_params->wmmat[1] >> trans_prec_diff)) * |
| 2596 | trans_dec_factor; |
| 2597 | } |
| 2598 | |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2599 | if (params->wmtype <= AFFINE) { |
| 2600 | int good_shear_params = get_shear_params(params); |
| 2601 | if (!good_shear_params) return 0; |
| 2602 | } |
| 2603 | |
| 2604 | return 1; |
| 2605 | } |
| 2606 | |
| 2607 | static void read_global_motion(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) { |
| 2608 | int frame; |
| 2609 | for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 2610 | const WarpedMotionParams *ref_params = |
| 2611 | cm->error_resilient_mode ? &default_warp_params |
| 2612 | : &cm->prev_frame->global_motion[frame]; |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2613 | int good_params = read_global_motion_params( |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 2614 | &cm->global_motion[frame], ref_params, rb, cm->allow_high_precision_mv); |
Sebastien Alaiwan | 8d88b29 | 2017-11-03 17:38:30 +0100 | [diff] [blame] | 2615 | if (!good_params) { |
| 2616 | #if WARPED_MOTION_DEBUG |
| 2617 | printf("Warning: unexpected global motion shear params from aomenc\n"); |
| 2618 | #endif |
| 2619 | cm->global_motion[frame].invalid = 1; |
| 2620 | } |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2621 | |
| 2622 | // TODO(sarahparker, debargha): The logic in the commented out code below |
| 2623 | // does not work currently and causes mismatches when resize is on. Fix it |
| 2624 | // before turning the optimization back on. |
| 2625 | /* |
| 2626 | YV12_BUFFER_CONFIG *ref_buf = get_ref_frame(cm, frame); |
| 2627 | if (cm->width == ref_buf->y_crop_width && |
| 2628 | cm->height == ref_buf->y_crop_height) { |
| 2629 | read_global_motion_params(&cm->global_motion[frame], |
| 2630 | &cm->prev_frame->global_motion[frame], rb, |
| 2631 | cm->allow_high_precision_mv); |
| 2632 | } else { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 2633 | cm->global_motion[frame] = default_warp_params; |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2634 | } |
| 2635 | */ |
| 2636 | /* |
| 2637 | printf("Dec Ref %d [%d/%d]: %d %d %d %d\n", |
| 2638 | frame, cm->current_video_frame, cm->show_frame, |
| 2639 | cm->global_motion[frame].wmmat[0], |
| 2640 | cm->global_motion[frame].wmmat[1], |
| 2641 | cm->global_motion[frame].wmmat[2], |
| 2642 | cm->global_motion[frame].wmmat[3]); |
| 2643 | */ |
| 2644 | } |
David Barker | cba7da7 | 2017-09-14 11:24:27 +0100 | [diff] [blame] | 2645 | memcpy(cm->cur_frame->global_motion, cm->global_motion, |
| 2646 | TOTAL_REFS_PER_FRAME * sizeof(WarpedMotionParams)); |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2647 | } |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 2648 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2649 | static size_t read_uncompressed_header(AV1Decoder *pbi, |
| 2650 | struct aom_read_bit_buffer *rb) { |
| 2651 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2652 | MACROBLOCKD *const xd = &pbi->mb; |
| 2653 | BufferPool *const pool = cm->buffer_pool; |
| 2654 | RefCntBuffer *const frame_bufs = pool->frame_bufs; |
| 2655 | int i, mask, ref_index = 0; |
| 2656 | size_t sz; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2657 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2658 | cm->last_frame_type = cm->frame_type; |
| 2659 | cm->last_intra_only = cm->intra_only; |
| 2660 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2661 | // NOTE: By default all coded frames to be used as a reference |
| 2662 | cm->is_reference_frame = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2663 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2664 | #if !CONFIG_OBU |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2665 | if (aom_rb_read_literal(rb, 2) != AOM_FRAME_MARKER) |
| 2666 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2667 | "Invalid frame marker"); |
| 2668 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2669 | cm->profile = av1_read_profile(rb); |
Sebastien Alaiwan | b9c652a | 2017-05-03 15:44:28 +0200 | [diff] [blame] | 2670 | |
| 2671 | const BITSTREAM_PROFILE MAX_SUPPORTED_PROFILE = |
| 2672 | CONFIG_HIGHBITDEPTH ? MAX_PROFILES : PROFILE_2; |
| 2673 | |
| 2674 | if (cm->profile >= MAX_SUPPORTED_PROFILE) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2675 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2676 | "Unsupported bitstream profile"); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2677 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2678 | |
Yunqing Wang | c2502b5 | 2017-07-19 17:44:18 -0700 | [diff] [blame] | 2679 | #if CONFIG_EXT_TILE |
| 2680 | cm->large_scale_tile = aom_rb_read_literal(rb, 1); |
| 2681 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2682 | if (cm->large_scale_tile) cm->seq_params.frame_id_numbers_present_flag = 0; |
Yunqing Wang | c2502b5 | 2017-07-19 17:44:18 -0700 | [diff] [blame] | 2683 | #endif // CONFIG_REFERENCE_BUFFER |
| 2684 | #endif // CONFIG_EXT_TILE |
| 2685 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2686 | cm->show_existing_frame = aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2687 | |
| 2688 | if (cm->show_existing_frame) { |
Yaowu Xu | 415ba93 | 2016-12-27 11:17:32 -0800 | [diff] [blame] | 2689 | // Show an existing frame directly. |
Arild Fuldseth (arilfuld) | 788dc23 | 2016-12-20 17:55:52 +0100 | [diff] [blame] | 2690 | const int existing_frame_idx = aom_rb_read_literal(rb, 3); |
| 2691 | const int frame_to_show = cm->ref_frame_map[existing_frame_idx]; |
Yaowu Xu | 415ba93 | 2016-12-27 11:17:32 -0800 | [diff] [blame] | 2692 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2693 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Frederic Barbier | e83fcfe | 2017-10-13 10:37:50 +0200 | [diff] [blame] | 2694 | int frame_id_length = cm->seq_params.frame_id_length; |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2695 | int display_frame_id = aom_rb_read_literal(rb, frame_id_length); |
| 2696 | /* Compare display_frame_id with ref_frame_id and check valid for |
| 2697 | * referencing */ |
| 2698 | if (display_frame_id != cm->ref_frame_id[existing_frame_idx] || |
| 2699 | cm->valid_for_referencing[existing_frame_idx] == 0) |
| 2700 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 2701 | "Reference buffer frame ID mismatch"); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2702 | } |
| 2703 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2704 | lock_buffer_pool(pool); |
| 2705 | if (frame_to_show < 0 || frame_bufs[frame_to_show].ref_count < 1) { |
| 2706 | unlock_buffer_pool(pool); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2707 | aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2708 | "Buffer %d does not contain a decoded frame", |
| 2709 | frame_to_show); |
| 2710 | } |
| 2711 | ref_cnt_fb(frame_bufs, &cm->new_fb_idx, frame_to_show); |
| 2712 | unlock_buffer_pool(pool); |
| 2713 | |
Cheng Chen | 13fc819 | 2017-08-19 11:49:28 -0700 | [diff] [blame] | 2714 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 2715 | cm->lf.filter_level[0] = 0; |
| 2716 | cm->lf.filter_level[1] = 0; |
| 2717 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2718 | cm->lf.filter_level = 0; |
Cheng Chen | 179479f | 2017-08-04 10:56:39 -0700 | [diff] [blame] | 2719 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2720 | cm->show_frame = 1; |
| 2721 | pbi->refresh_frame_flags = 0; |
| 2722 | |
| 2723 | if (cm->frame_parallel_decode) { |
| 2724 | for (i = 0; i < REF_FRAMES; ++i) |
| 2725 | cm->next_ref_frame_map[i] = cm->ref_frame_map[i]; |
| 2726 | } |
| 2727 | |
| 2728 | return 0; |
| 2729 | } |
| 2730 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2731 | #if !CONFIG_OBU |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2732 | cm->frame_type = (FRAME_TYPE)aom_rb_read_bit(rb); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 2733 | cm->show_frame = aom_rb_read_bit(rb); |
| 2734 | if (cm->frame_type != KEY_FRAME) |
| 2735 | cm->intra_only = cm->show_frame ? 0 : aom_rb_read_bit(rb); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2736 | #else |
| 2737 | cm->frame_type = (FRAME_TYPE)aom_rb_read_literal(rb, 2); // 2 bits |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 2738 | cm->show_frame = aom_rb_read_bit(rb); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2739 | cm->intra_only = cm->frame_type == INTRA_ONLY_FRAME; |
| 2740 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2741 | cm->error_resilient_mode = aom_rb_read_bit(rb); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2742 | #if CONFIG_REFERENCE_BUFFER |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 2743 | #if !CONFIG_OBU |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2744 | if (frame_is_intra_only(cm)) read_sequence_header(&cm->seq_params, rb); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 2745 | #endif // !CONFIG_OBU |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2746 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Frederic Barbier | e83fcfe | 2017-10-13 10:37:50 +0200 | [diff] [blame] | 2747 | int frame_id_length = cm->seq_params.frame_id_length; |
| 2748 | int diff_len = cm->seq_params.delta_frame_id_length; |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2749 | int prev_frame_id = 0; |
| 2750 | if (cm->frame_type != KEY_FRAME) { |
| 2751 | prev_frame_id = cm->current_frame_id; |
| 2752 | } |
| 2753 | cm->current_frame_id = aom_rb_read_literal(rb, frame_id_length); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2754 | |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2755 | if (cm->frame_type != KEY_FRAME) { |
| 2756 | int diff_frame_id; |
| 2757 | if (cm->current_frame_id > prev_frame_id) { |
| 2758 | diff_frame_id = cm->current_frame_id - prev_frame_id; |
| 2759 | } else { |
| 2760 | diff_frame_id = |
| 2761 | (1 << frame_id_length) + cm->current_frame_id - prev_frame_id; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2762 | } |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2763 | /* Check current_frame_id for conformance */ |
| 2764 | if (prev_frame_id == cm->current_frame_id || |
| 2765 | diff_frame_id >= (1 << (frame_id_length - 1))) { |
| 2766 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 2767 | "Invalid value of current_frame_id"); |
| 2768 | } |
| 2769 | } |
| 2770 | /* Check if some frames need to be marked as not valid for referencing */ |
| 2771 | for (i = 0; i < REF_FRAMES; i++) { |
| 2772 | if (cm->frame_type == KEY_FRAME) { |
| 2773 | cm->valid_for_referencing[i] = 0; |
| 2774 | } else if (cm->current_frame_id - (1 << diff_len) > 0) { |
| 2775 | if (cm->ref_frame_id[i] > cm->current_frame_id || |
| 2776 | cm->ref_frame_id[i] < cm->current_frame_id - (1 << diff_len)) |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2777 | cm->valid_for_referencing[i] = 0; |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2778 | } else { |
| 2779 | if (cm->ref_frame_id[i] > cm->current_frame_id && |
| 2780 | cm->ref_frame_id[i] < |
| 2781 | (1 << frame_id_length) + cm->current_frame_id - (1 << diff_len)) |
| 2782 | cm->valid_for_referencing[i] = 0; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2783 | } |
| 2784 | } |
| 2785 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 2786 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 2787 | |
| 2788 | #if CONFIG_FRAME_SIZE |
| 2789 | int frame_size_override_flag = aom_rb_read_literal(rb, 1); |
| 2790 | #endif |
| 2791 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2792 | if (cm->frame_type == KEY_FRAME) { |
Jingning Han | d8a15a6 | 2017-10-30 10:53:42 -0700 | [diff] [blame] | 2793 | cm->current_video_frame = 0; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2794 | #if !CONFIG_OBU |
Sebastien Alaiwan | 8b7a4e1 | 2017-06-13 11:25:57 +0200 | [diff] [blame] | 2795 | read_bitdepth_colorspace_sampling(cm, rb, pbi->allow_lowbitdepth); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2796 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2797 | pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1; |
| 2798 | |
| 2799 | for (i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 2800 | cm->frame_refs[i].idx = INVALID_IDX; |
| 2801 | cm->frame_refs[i].buf = NULL; |
| 2802 | } |
| 2803 | |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 2804 | #if CONFIG_FRAME_SIZE |
| 2805 | setup_frame_size(cm, frame_size_override_flag, rb); |
| 2806 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2807 | setup_frame_size(cm, rb); |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 2808 | #endif |
Debargha Mukherjee | d2630fa | 2017-09-22 10:32:51 -0700 | [diff] [blame] | 2809 | setup_sb_size(cm, rb); |
| 2810 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2811 | if (pbi->need_resync) { |
| 2812 | memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); |
| 2813 | pbi->need_resync = 0; |
| 2814 | } |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2815 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2816 | cm->ans_window_size_log2 = aom_rb_read_literal(rb, 4) + 8; |
| 2817 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
hui su | 24f7b07 | 2016-10-12 11:36:24 -0700 | [diff] [blame] | 2818 | cm->allow_screen_content_tools = aom_rb_read_bit(rb); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2819 | #if CONFIG_AMVR |
| 2820 | if (cm->allow_screen_content_tools) { |
| 2821 | if (aom_rb_read_bit(rb)) { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2822 | cm->seq_force_integer_mv = 2; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2823 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2824 | cm->seq_force_integer_mv = aom_rb_read_bit(rb); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2825 | } |
| 2826 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2827 | cm->seq_force_integer_mv = 0; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2828 | } |
| 2829 | #endif |
Fangwen Fu | 930c51c | 2017-05-07 20:39:17 -0700 | [diff] [blame] | 2830 | #if CONFIG_TEMPMV_SIGNALING |
| 2831 | cm->use_prev_frame_mvs = 0; |
| 2832 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2833 | } else { |
hui su | 24f7b07 | 2016-10-12 11:36:24 -0700 | [diff] [blame] | 2834 | if (cm->intra_only) cm->allow_screen_content_tools = aom_rb_read_bit(rb); |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2835 | #if CONFIG_TEMPMV_SIGNALING |
| 2836 | if (cm->intra_only || cm->error_resilient_mode) cm->use_prev_frame_mvs = 0; |
| 2837 | #endif |
| 2838 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 2839 | // The only way to reset all frame contexts to their default values is with a |
| 2840 | // keyframe. |
| 2841 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2842 | if (cm->error_resilient_mode) { |
| 2843 | cm->reset_frame_context = RESET_FRAME_CONTEXT_ALL; |
| 2844 | } else { |
| 2845 | if (cm->intra_only) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2846 | cm->reset_frame_context = aom_rb_read_bit(rb) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2847 | ? RESET_FRAME_CONTEXT_ALL |
| 2848 | : RESET_FRAME_CONTEXT_CURRENT; |
| 2849 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2850 | cm->reset_frame_context = aom_rb_read_bit(rb) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2851 | ? RESET_FRAME_CONTEXT_CURRENT |
| 2852 | : RESET_FRAME_CONTEXT_NONE; |
| 2853 | if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2854 | cm->reset_frame_context = aom_rb_read_bit(rb) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2855 | ? RESET_FRAME_CONTEXT_ALL |
| 2856 | : RESET_FRAME_CONTEXT_CURRENT; |
| 2857 | } |
| 2858 | } |
Thomas Daede | a6a854b | 2017-06-22 17:49:11 -0700 | [diff] [blame] | 2859 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2860 | |
| 2861 | if (cm->intra_only) { |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2862 | #if !CONFIG_OBU |
Sebastien Alaiwan | 8b7a4e1 | 2017-06-13 11:25:57 +0200 | [diff] [blame] | 2863 | read_bitdepth_colorspace_sampling(cm, rb, pbi->allow_lowbitdepth); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2864 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2865 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2866 | pbi->refresh_frame_flags = aom_rb_read_literal(rb, REF_FRAMES); |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 2867 | #if CONFIG_FRAME_SIZE |
| 2868 | setup_frame_size(cm, frame_size_override_flag, rb); |
| 2869 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2870 | setup_frame_size(cm, rb); |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 2871 | #endif |
Pavel Frolov | ea3dd3a | 2017-09-25 16:06:19 +0300 | [diff] [blame] | 2872 | setup_sb_size(cm, rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2873 | if (pbi->need_resync) { |
| 2874 | memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); |
| 2875 | pbi->need_resync = 0; |
| 2876 | } |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 2877 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 2878 | cm->ans_window_size_log2 = aom_rb_read_literal(rb, 4) + 8; |
| 2879 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2880 | } else if (pbi->need_resync != 1) { /* Skip if need resync */ |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2881 | #if CONFIG_OBU |
| 2882 | pbi->refresh_frame_flags = (cm->frame_type == S_FRAME) |
| 2883 | ? ~(1 << REF_FRAMES) |
| 2884 | : aom_rb_read_literal(rb, REF_FRAMES); |
| 2885 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2886 | pbi->refresh_frame_flags = aom_rb_read_literal(rb, REF_FRAMES); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2887 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2888 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2889 | if (!pbi->refresh_frame_flags) { |
| 2890 | // NOTE: "pbi->refresh_frame_flags == 0" indicates that the coded frame |
| 2891 | // will not be used as a reference |
| 2892 | cm->is_reference_frame = 0; |
| 2893 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2894 | |
| 2895 | for (i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2896 | const int ref = aom_rb_read_literal(rb, REF_FRAMES_LOG2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2897 | const int idx = cm->ref_frame_map[ref]; |
Rupert Swarbrick | 5eb471c | 2017-10-02 16:06:54 +0100 | [diff] [blame] | 2898 | |
| 2899 | // Most of the time, streams start with a keyframe. In that case, |
| 2900 | // ref_frame_map will have been filled in at that point and will not |
| 2901 | // contain any -1's. However, streams are explicitly allowed to start |
| 2902 | // with an intra-only frame, so long as they don't then signal a |
| 2903 | // reference to a slot that hasn't been set yet. That's what we are |
| 2904 | // checking here. |
| 2905 | if (idx == -1) |
| 2906 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 2907 | "Inter frame requests nonexistent reference"); |
| 2908 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2909 | RefBuffer *const ref_frame = &cm->frame_refs[i]; |
| 2910 | ref_frame->idx = idx; |
| 2911 | ref_frame->buf = &frame_bufs[idx].buf; |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 2912 | #if CONFIG_FRAME_SIGN_BIAS |
| 2913 | #if CONFIG_OBU |
| 2914 | // NOTE: For the scenario of (cm->frame_type != S_FRAME), |
| 2915 | // ref_frame_sign_bias will be reset based on frame offsets. |
| 2916 | cm->ref_frame_sign_bias[LAST_FRAME + i] = 0; |
| 2917 | #endif // CONFIG_OBU |
| 2918 | #else // !CONFIG_FRAME_SIGN_BIAS |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 2919 | #if CONFIG_OBU |
| 2920 | cm->ref_frame_sign_bias[LAST_FRAME + i] = |
| 2921 | (cm->frame_type == S_FRAME) ? 0 : aom_rb_read_bit(rb); |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 2922 | #else // !CONFIG_OBU |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2923 | cm->ref_frame_sign_bias[LAST_FRAME + i] = aom_rb_read_bit(rb); |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 2924 | #endif // CONFIG_OBU |
| 2925 | #endif // CONFIG_FRAME_SIGN_BIAS |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2926 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2927 | if (cm->seq_params.frame_id_numbers_present_flag) { |
Frederic Barbier | e83fcfe | 2017-10-13 10:37:50 +0200 | [diff] [blame] | 2928 | int frame_id_length = cm->seq_params.frame_id_length; |
| 2929 | int diff_len = cm->seq_params.delta_frame_id_length; |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 2930 | int delta_frame_id_minus1 = aom_rb_read_literal(rb, diff_len); |
| 2931 | int ref_frame_id = |
| 2932 | ((cm->current_frame_id - (delta_frame_id_minus1 + 1) + |
| 2933 | (1 << frame_id_length)) % |
| 2934 | (1 << frame_id_length)); |
| 2935 | /* Compare values derived from delta_frame_id_minus1 and |
| 2936 | * refresh_frame_flags. Also, check valid for referencing */ |
| 2937 | if (ref_frame_id != cm->ref_frame_id[ref] || |
| 2938 | cm->valid_for_referencing[ref] == 0) |
| 2939 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 2940 | "Reference buffer frame ID mismatch"); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 2941 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 2942 | #endif // CONFIG_REFERENCE_BUFFER |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
Arild Fuldseth | 842e9b0 | 2016-09-02 13:00:05 +0200 | [diff] [blame] | 2945 | #if CONFIG_FRAME_SIZE |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 2946 | if (cm->error_resilient_mode == 0 && frame_size_override_flag) { |
Arild Fuldseth | 842e9b0 | 2016-09-02 13:00:05 +0200 | [diff] [blame] | 2947 | setup_frame_size_with_refs(cm, rb); |
| 2948 | } else { |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 2949 | setup_frame_size(cm, frame_size_override_flag, rb); |
Arild Fuldseth | 842e9b0 | 2016-09-02 13:00:05 +0200 | [diff] [blame] | 2950 | } |
| 2951 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2952 | setup_frame_size_with_refs(cm, rb); |
Arild Fuldseth | 842e9b0 | 2016-09-02 13:00:05 +0200 | [diff] [blame] | 2953 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2954 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2955 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2956 | if (cm->seq_force_integer_mv == 2) { |
| 2957 | cm->cur_frame_force_integer_mv = aom_rb_read_bit(rb); |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2958 | } else { |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2959 | cm->cur_frame_force_integer_mv = cm->seq_force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 2960 | } |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2961 | |
| 2962 | if (cm->cur_frame_force_integer_mv) { |
| 2963 | cm->allow_high_precision_mv = 0; |
| 2964 | } else { |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2965 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 2966 | cm->allow_high_precision_mv = 1; |
| 2967 | #else |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2968 | cm->allow_high_precision_mv = aom_rb_read_bit(rb); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2969 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2970 | } |
| 2971 | #else |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2972 | #if CONFIG_EIGHTH_PEL_MV_ONLY |
| 2973 | cm->allow_high_precision_mv = 1; |
| 2974 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2975 | cm->allow_high_precision_mv = aom_rb_read_bit(rb); |
Debargha Mukherjee | b214775 | 2017-11-01 07:00:45 -0700 | [diff] [blame] | 2976 | #endif // CONFIG_EIGHTH_PEL_MV_ONLY |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 2977 | #endif |
Angie Chiang | 5678ad9 | 2016-11-21 09:38:40 -0800 | [diff] [blame] | 2978 | cm->interp_filter = read_frame_interp_filter(rb); |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 2979 | #if CONFIG_TEMPMV_SIGNALING |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 2980 | if (frame_might_use_prev_frame_mvs(cm)) |
Jingning Han | e17ebe9 | 2017-11-03 15:25:42 -0700 | [diff] [blame] | 2981 | cm->use_ref_frame_mvs = aom_rb_read_bit(rb); |
Rupert Swarbrick | 1f990a6 | 2017-07-11 11:09:33 +0100 | [diff] [blame] | 2982 | else |
Jingning Han | e17ebe9 | 2017-11-03 15:25:42 -0700 | [diff] [blame] | 2983 | cm->use_ref_frame_mvs = 0; |
| 2984 | |
| 2985 | cm->use_prev_frame_mvs = |
| 2986 | cm->use_ref_frame_mvs && frame_can_use_prev_frame_mvs(cm); |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 2987 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2988 | for (i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
| 2989 | RefBuffer *const ref_buf = &cm->frame_refs[i]; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 2990 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2991 | av1_setup_scale_factors_for_frame( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2992 | &ref_buf->sf, ref_buf->buf->y_crop_width, |
| 2993 | ref_buf->buf->y_crop_height, cm->width, cm->height, |
| 2994 | cm->use_highbitdepth); |
| 2995 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 2996 | av1_setup_scale_factors_for_frame( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 2997 | &ref_buf->sf, ref_buf->buf->y_crop_width, |
| 2998 | ref_buf->buf->y_crop_height, cm->width, cm->height); |
| 2999 | #endif |
| 3000 | } |
| 3001 | } |
| 3002 | } |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 3003 | |
Jingning Han | ea255c9 | 2017-09-29 08:12:09 -0700 | [diff] [blame] | 3004 | #if CONFIG_FRAME_MARKER |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 3005 | if (cm->show_frame == 0) { |
| 3006 | cm->frame_offset = cm->current_video_frame + aom_rb_read_literal(rb, 4); |
| 3007 | } else { |
| 3008 | cm->frame_offset = cm->current_video_frame; |
| 3009 | } |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 3010 | av1_setup_frame_buf_refs(cm); |
| 3011 | |
| 3012 | #if CONFIG_FRAME_SIGN_BIAS |
| 3013 | #if CONFIG_OBU |
| 3014 | if (cm->frame_type != S_FRAME) |
| 3015 | #endif // CONFIG_OBU |
| 3016 | av1_setup_frame_sign_bias(cm); |
Zoe Liu | 17af274 | 2017-10-06 10:36:42 -0700 | [diff] [blame] | 3017 | #endif // CONFIG_FRAME_SIGN_BIAS |
| 3018 | #endif // CONFIG_FRAME_MARKER |
Jingning Han | c723b34 | 2017-08-24 11:19:46 -0700 | [diff] [blame] | 3019 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 3020 | #if CONFIG_TEMPMV_SIGNALING |
| 3021 | cm->cur_frame->intra_only = cm->frame_type == KEY_FRAME || cm->intra_only; |
| 3022 | #endif |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 3023 | |
| 3024 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 3025 | if (cm->seq_params.frame_id_numbers_present_flag) { |
| 3026 | /* If bitmask is set, update reference frame id values and |
| 3027 | mark frames as valid for reference */ |
| 3028 | int refresh_frame_flags = |
| 3029 | cm->frame_type == KEY_FRAME ? 0xFF : pbi->refresh_frame_flags; |
| 3030 | for (i = 0; i < REF_FRAMES; i++) { |
| 3031 | if ((refresh_frame_flags >> i) & 1) { |
| 3032 | cm->ref_frame_id[i] = cm->current_frame_id; |
| 3033 | cm->valid_for_referencing[i] = 1; |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 3034 | } |
| 3035 | } |
| 3036 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 3037 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 3038 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3039 | get_frame_new_buffer(cm)->bit_depth = cm->bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3040 | get_frame_new_buffer(cm)->color_space = cm->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 3041 | #if CONFIG_COLORSPACE_HEADERS |
| 3042 | get_frame_new_buffer(cm)->transfer_function = cm->transfer_function; |
| 3043 | get_frame_new_buffer(cm)->chroma_sample_position = cm->chroma_sample_position; |
| 3044 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3045 | get_frame_new_buffer(cm)->color_range = cm->color_range; |
| 3046 | get_frame_new_buffer(cm)->render_width = cm->render_width; |
| 3047 | get_frame_new_buffer(cm)->render_height = cm->render_height; |
| 3048 | |
| 3049 | if (pbi->need_resync) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3050 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3051 | "Keyframe / intra-only frame required to reset decoder" |
| 3052 | " state"); |
| 3053 | } |
| 3054 | |
Rupert Swarbrick | 84b05ac | 2017-10-27 18:10:53 +0100 | [diff] [blame] | 3055 | #if CONFIG_EXT_TILE |
| 3056 | const int might_bwd_adapt = |
| 3057 | !(cm->error_resilient_mode || cm->large_scale_tile); |
| 3058 | #else |
| 3059 | const int might_bwd_adapt = !cm->error_resilient_mode; |
| 3060 | #endif // CONFIG_EXT_TILE |
| 3061 | if (might_bwd_adapt) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3062 | cm->refresh_frame_context = aom_rb_read_bit(rb) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3063 | ? REFRESH_FRAME_CONTEXT_FORWARD |
| 3064 | : REFRESH_FRAME_CONTEXT_BACKWARD; |
| 3065 | } else { |
| 3066 | cm->refresh_frame_context = REFRESH_FRAME_CONTEXT_FORWARD; |
| 3067 | } |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 3068 | #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3069 | // This flag will be overridden by the call to av1_setup_past_independence |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3070 | // below, forcing the use of context 0 for those frame types. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3071 | cm->frame_context_idx = aom_rb_read_literal(rb, FRAME_CONTEXTS_LOG2); |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 3072 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3073 | |
| 3074 | // Generate next_ref_frame_map. |
| 3075 | lock_buffer_pool(pool); |
| 3076 | for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) { |
| 3077 | if (mask & 1) { |
| 3078 | cm->next_ref_frame_map[ref_index] = cm->new_fb_idx; |
| 3079 | ++frame_bufs[cm->new_fb_idx].ref_count; |
| 3080 | } else { |
| 3081 | cm->next_ref_frame_map[ref_index] = cm->ref_frame_map[ref_index]; |
| 3082 | } |
| 3083 | // Current thread holds the reference frame. |
| 3084 | if (cm->ref_frame_map[ref_index] >= 0) |
| 3085 | ++frame_bufs[cm->ref_frame_map[ref_index]].ref_count; |
| 3086 | ++ref_index; |
| 3087 | } |
| 3088 | |
| 3089 | for (; ref_index < REF_FRAMES; ++ref_index) { |
| 3090 | cm->next_ref_frame_map[ref_index] = cm->ref_frame_map[ref_index]; |
| 3091 | |
| 3092 | // Current thread holds the reference frame. |
| 3093 | if (cm->ref_frame_map[ref_index] >= 0) |
| 3094 | ++frame_bufs[cm->ref_frame_map[ref_index]].ref_count; |
| 3095 | } |
| 3096 | unlock_buffer_pool(pool); |
| 3097 | pbi->hold_ref_buf = 1; |
| 3098 | |
| 3099 | if (frame_is_intra_only(cm) || cm->error_resilient_mode) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3100 | av1_setup_past_independence(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3101 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3102 | setup_loopfilter(cm, rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3103 | setup_quantization(cm, rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3104 | xd->bd = (int)cm->bit_depth; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3105 | |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 3106 | #if CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3107 | av1_default_coef_probs(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3108 | if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || |
| 3109 | cm->reset_frame_context == RESET_FRAME_CONTEXT_ALL) { |
| 3110 | for (i = 0; i < FRAME_CONTEXTS; ++i) cm->frame_contexts[i] = *cm->fc; |
| 3111 | } else if (cm->reset_frame_context == RESET_FRAME_CONTEXT_CURRENT) { |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 3112 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 3113 | if (cm->frame_refs[0].idx <= 0) { |
| 3114 | cm->frame_contexts[cm->frame_refs[0].idx] = *cm->fc; |
| 3115 | } |
| 3116 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3117 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Thomas Daede | da4d8b9 | 2017-06-05 15:44:14 -0700 | [diff] [blame] | 3118 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3119 | } |
hui su | 0d10357 | 2017-03-01 17:58:01 -0800 | [diff] [blame] | 3120 | #endif // CONFIG_Q_ADAPT_PROBS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3121 | |
| 3122 | setup_segmentation(cm, rb); |
| 3123 | |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3124 | { |
Thomas Davies | 28444be | 2017-10-13 18:12:25 +0100 | [diff] [blame] | 3125 | int delta_q_allowed = 1; |
| 3126 | #if !CONFIG_EXT_DELTA_Q |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3127 | struct segmentation *const seg = &cm->seg; |
| 3128 | int segment_quantizer_active = 0; |
| 3129 | for (i = 0; i < MAX_SEGMENTS; i++) { |
| 3130 | if (segfeature_active(seg, i, SEG_LVL_ALT_Q)) { |
| 3131 | segment_quantizer_active = 1; |
| 3132 | } |
| 3133 | } |
Thomas Davies | 28444be | 2017-10-13 18:12:25 +0100 | [diff] [blame] | 3134 | delta_q_allowed = !segment_quantizer_active; |
| 3135 | #endif |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3136 | |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 3137 | cm->delta_q_res = 1; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3138 | #if CONFIG_EXT_DELTA_Q |
| 3139 | cm->delta_lf_res = 1; |
Jonathan Matthews | a48b1e6 | 2017-09-01 14:58:47 +0100 | [diff] [blame] | 3140 | cm->delta_lf_present_flag = 0; |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 3141 | #if CONFIG_LOOPFILTER_LEVEL |
| 3142 | cm->delta_lf_multi = 0; |
| 3143 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3144 | #endif |
Thomas Davies | 28444be | 2017-10-13 18:12:25 +0100 | [diff] [blame] | 3145 | if (delta_q_allowed == 1 && cm->base_qindex > 0) { |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3146 | cm->delta_q_present_flag = aom_rb_read_bit(rb); |
| 3147 | } else { |
| 3148 | cm->delta_q_present_flag = 0; |
| 3149 | } |
| 3150 | if (cm->delta_q_present_flag) { |
| 3151 | xd->prev_qindex = cm->base_qindex; |
Thomas Davies | f693610 | 2016-09-05 16:51:31 +0100 | [diff] [blame] | 3152 | cm->delta_q_res = 1 << aom_rb_read_literal(rb, 2); |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3153 | #if CONFIG_EXT_DELTA_Q |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3154 | cm->delta_lf_present_flag = aom_rb_read_bit(rb); |
| 3155 | if (cm->delta_lf_present_flag) { |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 3156 | xd->prev_delta_lf_from_base = 0; |
| 3157 | cm->delta_lf_res = 1 << aom_rb_read_literal(rb, 2); |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 3158 | #if CONFIG_LOOPFILTER_LEVEL |
Cheng Chen | 880166a | 2017-10-02 17:48:48 -0700 | [diff] [blame] | 3159 | cm->delta_lf_multi = aom_rb_read_bit(rb); |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 3160 | for (int lf_id = 0; lf_id < FRAME_LF_COUNT; ++lf_id) |
| 3161 | xd->prev_delta_lf[lf_id] = 0; |
| 3162 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 3163 | } |
| 3164 | #endif // CONFIG_EXT_DELTA_Q |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 3165 | } |
| 3166 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3167 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 3168 | xd->cur_frame_force_integer_mv = cm->cur_frame_force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3169 | #endif |
Thomas Davies | 3ab20b4 | 2017-09-19 10:30:53 +0100 | [diff] [blame] | 3170 | |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 3171 | for (i = 0; i < MAX_SEGMENTS; ++i) { |
| 3172 | const int qindex = cm->seg.enabled |
| 3173 | ? av1_get_qindex(&cm->seg, i, cm->base_qindex) |
| 3174 | : cm->base_qindex; |
| 3175 | xd->lossless[i] = qindex == 0 && cm->y_dc_delta_q == 0 && |
| 3176 | cm->uv_dc_delta_q == 0 && cm->uv_ac_delta_q == 0; |
| 3177 | xd->qindex[i] = qindex; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3178 | } |
Thomas Daede | f636d5c | 2017-06-29 13:48:27 -0700 | [diff] [blame] | 3179 | cm->all_lossless = all_lossless(cm, xd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3180 | setup_segmentation_dequant(cm); |
Thomas Daede | f636d5c | 2017-06-29 13:48:27 -0700 | [diff] [blame] | 3181 | #if CONFIG_CDEF |
| 3182 | if (!cm->all_lossless) { |
| 3183 | setup_cdef(cm, rb); |
| 3184 | } |
| 3185 | #endif |
| 3186 | #if CONFIG_LOOP_RESTORATION |
| 3187 | decode_restoration_mode(cm, rb); |
| 3188 | #endif // CONFIG_LOOP_RESTORATION |
| 3189 | cm->tx_mode = read_tx_mode(cm, rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3190 | cm->reference_mode = read_frame_reference_mode(cm, rb); |
Debargha Mukherjee | 6f3c898 | 2017-09-22 21:14:01 -0700 | [diff] [blame] | 3191 | if (cm->reference_mode != SINGLE_REFERENCE) setup_compound_reference_mode(cm); |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3192 | read_compound_tools(cm, rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3193 | |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 3194 | cm->reduced_tx_set_used = aom_rb_read_bit(rb); |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 3195 | |
Angie Chiang | 6dbffbf | 2017-10-06 16:59:54 -0700 | [diff] [blame] | 3196 | #if CONFIG_ADAPT_SCAN |
| 3197 | cm->use_adapt_scan = aom_rb_read_bit(rb); |
| 3198 | // TODO(angiebird): call av1_init_scan_order only when use_adapt_scan |
| 3199 | // switches from 1 to 0 |
| 3200 | if (cm->use_adapt_scan == 0) av1_init_scan_order(cm); |
| 3201 | #endif // CONFIG_ADAPT_SCAN |
| 3202 | |
Pavel Frolov | 57c36e1 | 2017-09-12 15:00:40 +0300 | [diff] [blame] | 3203 | // NOTE(zoeliu): As cm->prev_frame can take neither a frame of |
| 3204 | // show_exisiting_frame=1, nor can it take a frame not used as |
| 3205 | // a reference, it is probable that by the time it is being |
| 3206 | // referred to, the frame buffer it originally points to may |
| 3207 | // already get expired and have been reassigned to the current |
| 3208 | // newly coded frame. Hence, we need to check whether this is |
| 3209 | // the case, and if yes, we have 2 choices: |
| 3210 | // (1) Simply disable the use of previous frame mvs; or |
| 3211 | // (2) Have cm->prev_frame point to one reference frame buffer, |
| 3212 | // e.g. LAST_FRAME. |
| 3213 | if (!dec_is_ref_frame_buf(pbi, cm->prev_frame)) { |
| 3214 | // Reassign the LAST_FRAME buffer to cm->prev_frame. |
| 3215 | cm->prev_frame = |
| 3216 | cm->frame_refs[LAST_FRAME - LAST_FRAME].idx != INVALID_IDX |
| 3217 | ? &cm->buffer_pool |
| 3218 | ->frame_bufs[cm->frame_refs[LAST_FRAME - LAST_FRAME].idx] |
| 3219 | : NULL; |
| 3220 | } |
Pavel Frolov | 57c36e1 | 2017-09-12 15:00:40 +0300 | [diff] [blame] | 3221 | |
| 3222 | #if CONFIG_TEMPMV_SIGNALING |
| 3223 | if (cm->use_prev_frame_mvs && !frame_can_use_prev_frame_mvs(cm)) { |
| 3224 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 3225 | "Frame wrongly requests previous frame MVs"); |
| 3226 | } |
| 3227 | #else |
| 3228 | cm->use_prev_frame_mvs = !cm->error_resilient_mode && cm->prev_frame && |
| 3229 | #if CONFIG_FRAME_SUPERRES |
| 3230 | cm->width == cm->last_width && |
| 3231 | cm->height == cm->last_height && |
| 3232 | #else |
| 3233 | cm->width == cm->prev_frame->buf.y_crop_width && |
| 3234 | cm->height == cm->prev_frame->buf.y_crop_height && |
| 3235 | #endif // CONFIG_FRAME_SUPERRES |
| 3236 | !cm->last_intra_only && cm->last_show_frame && |
| 3237 | (cm->last_frame_type != KEY_FRAME); |
| 3238 | #endif // CONFIG_TEMPMV_SIGNALING |
| 3239 | |
Sarah Parker | f289f9f | 2017-09-12 18:50:02 -0700 | [diff] [blame] | 3240 | if (!frame_is_intra_only(cm)) read_global_motion(cm, rb); |
Sarah Parker | 3e579a6 | 2017-08-23 16:53:20 -0700 | [diff] [blame] | 3241 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3242 | read_tile_info(pbi, rb); |
Debargha Mukherjee | 2eada61 | 2017-09-22 15:37:39 -0700 | [diff] [blame] | 3243 | if (use_compressed_header(cm)) { |
| 3244 | sz = aom_rb_read_literal(rb, 16); |
| 3245 | if (sz == 0) |
| 3246 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 3247 | "Invalid header size"); |
| 3248 | } else { |
| 3249 | sz = 0; |
| 3250 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3251 | return sz; |
| 3252 | } |
| 3253 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3254 | static int read_compressed_header(AV1Decoder *pbi, const uint8_t *data, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3255 | size_t partition_size) { |
Thomas Davies | 2e868ab | 2017-10-24 10:42:27 +0100 | [diff] [blame] | 3256 | #if CONFIG_NEW_MULTISYMBOL |
Thomas Davies | e715483 | 2017-10-03 10:12:17 +0100 | [diff] [blame] | 3257 | (void)pbi; |
| 3258 | (void)data; |
| 3259 | (void)partition_size; |
| 3260 | return 0; |
| 3261 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3262 | AV1_COMMON *const cm = &pbi->common; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3263 | aom_reader r; |
Ryan | f0e3919 | 2017-10-09 09:45:13 -0700 | [diff] [blame] | 3264 | |
Sebastien Alaiwan | fb83877 | 2017-10-24 12:02:54 +0200 | [diff] [blame] | 3265 | #if ((CONFIG_RECT_TX_EXT) || (!CONFIG_NEW_MULTISYMBOL || CONFIG_LV_MAP) || \ |
Sebastien Alaiwan | 0cf54d4 | 2017-10-16 16:10:04 +0200 | [diff] [blame] | 3266 | (CONFIG_COMPOUND_SINGLEREF)) |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 3267 | FRAME_CONTEXT *const fc = cm->fc; |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 3268 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3269 | |
Alex Converse | 2cdf0d8 | 2016-12-13 13:53:09 -0800 | [diff] [blame] | 3270 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 3271 | r.window_size = 1 << cm->ans_window_size_log2; |
Alex Converse | 2cdf0d8 | 2016-12-13 13:53:09 -0800 | [diff] [blame] | 3272 | #endif |
Alex Converse | 346440b | 2017-01-03 13:47:37 -0800 | [diff] [blame] | 3273 | if (aom_reader_init(&r, data, partition_size, pbi->decrypt_cb, |
| 3274 | pbi->decrypt_state)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3275 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3276 | "Failed to allocate bool decoder 0"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3277 | |
Sebastien Alaiwan | fb83877 | 2017-10-24 12:02:54 +0200 | [diff] [blame] | 3278 | #if CONFIG_RECT_TX_EXT |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 3279 | if (cm->tx_mode == TX_MODE_SELECT) |
| 3280 | av1_diff_update_prob(&r, &fc->quarter_tx_size_prob, ACCT_STR); |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 3281 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3282 | |
Thomas Davies | 985bfc3 | 2017-06-27 16:51:26 +0100 | [diff] [blame] | 3283 | #if !CONFIG_NEW_MULTISYMBOL |
David Barker | 16c64e3 | 2017-08-23 16:54:59 +0100 | [diff] [blame] | 3284 | if (cm->tx_mode == TX_MODE_SELECT) |
Ryan | f0e3919 | 2017-10-09 09:45:13 -0700 | [diff] [blame] | 3285 | for (int i = 0; i < TXFM_PARTITION_CONTEXTS; ++i) |
David Barker | 16c64e3 | 2017-08-23 16:54:59 +0100 | [diff] [blame] | 3286 | av1_diff_update_prob(&r, &fc->txfm_partition_prob[i], ACCT_STR); |
Ryan | f0e3919 | 2017-10-09 09:45:13 -0700 | [diff] [blame] | 3287 | for (int i = 0; i < SKIP_CONTEXTS; ++i) |
Thomas Davies | 61e3e37 | 2017-04-04 16:10:23 +0100 | [diff] [blame] | 3288 | av1_diff_update_prob(&r, &fc->skip_probs[i], ACCT_STR); |
Cheng Chen | 0a7f2f5 | 2017-10-10 15:16:09 -0700 | [diff] [blame] | 3289 | |
| 3290 | #if CONFIG_JNT_COMP |
| 3291 | for (int i = 0; i < COMP_INDEX_CONTEXTS; ++i) |
| 3292 | av1_diff_update_prob(&r, &fc->compound_index_probs[i], ACCT_STR); |
| 3293 | #endif // CONFIG_JNT_COMP |
Thomas Davies | 61e3e37 | 2017-04-04 16:10:23 +0100 | [diff] [blame] | 3294 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3295 | |
Debargha Mukherjee | 801cc92 | 2017-09-22 17:22:50 -0700 | [diff] [blame] | 3296 | if (!frame_is_intra_only(cm)) { |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 3297 | #if !CONFIG_NEW_MULTISYMBOL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3298 | read_inter_mode_probs(fc, &r); |
Thomas Davies | 149eda5 | 2017-06-12 18:11:55 +0100 | [diff] [blame] | 3299 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3300 | |
Debargha Mukherjee | 9e2c7a6 | 2017-05-23 21:18:42 -0700 | [diff] [blame] | 3301 | if (cm->reference_mode != COMPOUND_REFERENCE && |
| 3302 | cm->allow_interintra_compound) { |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 3303 | #if !CONFIG_NEW_MULTISYMBOL |
Ryan | f0e3919 | 2017-10-09 09:45:13 -0700 | [diff] [blame] | 3304 | for (int i = 0; i < BLOCK_SIZE_GROUPS; i++) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3305 | if (is_interintra_allowed_bsize_group(i)) { |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 3306 | av1_diff_update_prob(&r, &fc->interintra_prob[i], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3307 | } |
| 3308 | } |
Thomas Davies | cff9171 | 2017-07-07 11:49:55 +0100 | [diff] [blame] | 3309 | #endif |
Debargha Mukherjee | 371968c | 2017-10-29 12:30:04 -0700 | [diff] [blame] | 3310 | #if !CONFIG_NEW_MULTISYMBOL |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 3311 | #if CONFIG_EXT_PARTITION_TYPES |
| 3312 | int block_sizes_to_update = BLOCK_SIZES_ALL; |
| 3313 | #else |
| 3314 | int block_sizes_to_update = BLOCK_SIZES; |
| 3315 | #endif |
Ryan | f0e3919 | 2017-10-09 09:45:13 -0700 | [diff] [blame] | 3316 | for (int i = 0; i < block_sizes_to_update; i++) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3317 | if (is_interintra_allowed_bsize(i) && is_interintra_wedge_used(i)) { |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 3318 | av1_diff_update_prob(&r, &fc->wedge_interintra_prob[i], ACCT_STR); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3319 | } |
| 3320 | } |
Debargha Mukherjee | 371968c | 2017-10-29 12:30:04 -0700 | [diff] [blame] | 3321 | #endif // !CONFIG_NEW_MULTISYMBOL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3322 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3323 | |
Thomas Davies | f6ad935 | 2017-04-19 11:38:06 +0100 | [diff] [blame] | 3324 | #if !CONFIG_NEW_MULTISYMBOL |
Ryan | f0e3919 | 2017-10-09 09:45:13 -0700 | [diff] [blame] | 3325 | for (int i = 0; i < INTRA_INTER_CONTEXTS; i++) |
Michael Bebenita | 6048d05 | 2016-08-25 14:40:54 -0700 | [diff] [blame] | 3326 | av1_diff_update_prob(&r, &fc->intra_inter_prob[i], ACCT_STR); |
Thomas Davies | f6ad935 | 2017-04-19 11:38:06 +0100 | [diff] [blame] | 3327 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3328 | |
David Barker | 037ee41 | 2017-09-19 12:43:46 +0100 | [diff] [blame] | 3329 | #if !CONFIG_NEW_MULTISYMBOL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3330 | read_frame_reference_mode_probs(cm, &r); |
David Barker | 037ee41 | 2017-09-19 12:43:46 +0100 | [diff] [blame] | 3331 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3332 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 3333 | #if CONFIG_COMPOUND_SINGLEREF |
Ryan | f0e3919 | 2017-10-09 09:45:13 -0700 | [diff] [blame] | 3334 | for (int i = 0; i < COMP_INTER_MODE_CONTEXTS; i++) |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 3335 | av1_diff_update_prob(&r, &fc->comp_inter_mode_prob[i], ACCT_STR); |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 3336 | #endif // CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 3337 | |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 3338 | #if !CONFIG_NEW_MULTISYMBOL |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3339 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 3340 | if (cm->cur_frame_force_integer_mv == 0) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3341 | #endif |
Ryan | f0e3919 | 2017-10-09 09:45:13 -0700 | [diff] [blame] | 3342 | for (int i = 0; i < NMV_CONTEXTS; ++i) |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 3343 | read_mv_probs(&fc->nmvc[i], cm->allow_high_precision_mv, &r); |
| 3344 | #if CONFIG_AMVR |
| 3345 | } |
| 3346 | #endif |
Thomas Davies | 599395e | 2017-07-21 18:02:48 +0100 | [diff] [blame] | 3347 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3350 | return aom_reader_has_error(&r); |
Thomas Davies | 2e868ab | 2017-10-24 10:42:27 +0100 | [diff] [blame] | 3351 | #endif // CONFIG_NEW_MULTISYMBOL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3352 | } |
Debargha Mukherjee | 2eada61 | 2017-09-22 15:37:39 -0700 | [diff] [blame] | 3353 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3354 | #ifdef NDEBUG |
| 3355 | #define debug_check_frame_counts(cm) (void)0 |
| 3356 | #else // !NDEBUG |
| 3357 | // Counts should only be incremented when frame_parallel_decoding_mode and |
| 3358 | // error_resilient_mode are disabled. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3359 | static void debug_check_frame_counts(const AV1_COMMON *const cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3360 | FRAME_COUNTS zero_counts; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3361 | av1_zero(zero_counts); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3362 | assert(cm->refresh_frame_context != REFRESH_FRAME_CONTEXT_BACKWARD || |
| 3363 | cm->error_resilient_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3364 | assert(!memcmp(cm->counts.partition, zero_counts.partition, |
| 3365 | sizeof(cm->counts.partition))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3366 | assert(!memcmp(cm->counts.switchable_interp, zero_counts.switchable_interp, |
| 3367 | sizeof(cm->counts.switchable_interp))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3368 | assert(!memcmp(cm->counts.inter_compound_mode, |
| 3369 | zero_counts.inter_compound_mode, |
| 3370 | sizeof(cm->counts.inter_compound_mode))); |
| 3371 | assert(!memcmp(cm->counts.interintra, zero_counts.interintra, |
| 3372 | sizeof(cm->counts.interintra))); |
| 3373 | assert(!memcmp(cm->counts.wedge_interintra, zero_counts.wedge_interintra, |
| 3374 | sizeof(cm->counts.wedge_interintra))); |
Sarah Parker | 6fddd18 | 2016-11-10 20:57:20 -0800 | [diff] [blame] | 3375 | assert(!memcmp(cm->counts.compound_interinter, |
| 3376 | zero_counts.compound_interinter, |
| 3377 | sizeof(cm->counts.compound_interinter))); |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 3378 | assert(!memcmp(cm->counts.motion_mode, zero_counts.motion_mode, |
| 3379 | sizeof(cm->counts.motion_mode))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3380 | assert(!memcmp(cm->counts.intra_inter, zero_counts.intra_inter, |
| 3381 | sizeof(cm->counts.intra_inter))); |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 3382 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 3383 | assert(!memcmp(cm->counts.comp_inter_mode, zero_counts.comp_inter_mode, |
| 3384 | sizeof(cm->counts.comp_inter_mode))); |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 3385 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3386 | assert(!memcmp(cm->counts.comp_inter, zero_counts.comp_inter, |
| 3387 | sizeof(cm->counts.comp_inter))); |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 3388 | #if CONFIG_EXT_COMP_REFS |
| 3389 | assert(!memcmp(cm->counts.comp_ref_type, zero_counts.comp_ref_type, |
| 3390 | sizeof(cm->counts.comp_ref_type))); |
| 3391 | assert(!memcmp(cm->counts.uni_comp_ref, zero_counts.uni_comp_ref, |
| 3392 | sizeof(cm->counts.uni_comp_ref))); |
| 3393 | #endif // CONFIG_EXT_COMP_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3394 | assert(!memcmp(cm->counts.single_ref, zero_counts.single_ref, |
| 3395 | sizeof(cm->counts.single_ref))); |
| 3396 | assert(!memcmp(cm->counts.comp_ref, zero_counts.comp_ref, |
| 3397 | sizeof(cm->counts.comp_ref))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3398 | assert(!memcmp(cm->counts.comp_bwdref, zero_counts.comp_bwdref, |
| 3399 | sizeof(cm->counts.comp_bwdref))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3400 | assert(!memcmp(cm->counts.skip, zero_counts.skip, sizeof(cm->counts.skip))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3401 | assert( |
| 3402 | !memcmp(&cm->counts.mv[0], &zero_counts.mv[0], sizeof(cm->counts.mv[0]))); |
| 3403 | assert( |
| 3404 | !memcmp(&cm->counts.mv[1], &zero_counts.mv[1], sizeof(cm->counts.mv[0]))); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3405 | } |
| 3406 | #endif // NDEBUG |
| 3407 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3408 | static struct aom_read_bit_buffer *init_read_bit_buffer( |
| 3409 | AV1Decoder *pbi, struct aom_read_bit_buffer *rb, const uint8_t *data, |
| 3410 | const uint8_t *data_end, uint8_t clear_data[MAX_AV1_HEADER_SIZE]) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3411 | rb->bit_offset = 0; |
| 3412 | rb->error_handler = error_handler; |
| 3413 | rb->error_handler_data = &pbi->common; |
| 3414 | if (pbi->decrypt_cb) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3415 | const int n = (int)AOMMIN(MAX_AV1_HEADER_SIZE, data_end - data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3416 | pbi->decrypt_cb(pbi->decrypt_state, data, clear_data, n); |
| 3417 | rb->bit_buffer = clear_data; |
| 3418 | rb->bit_buffer_end = clear_data + n; |
| 3419 | } else { |
| 3420 | rb->bit_buffer = data; |
| 3421 | rb->bit_buffer_end = data_end; |
| 3422 | } |
| 3423 | return rb; |
| 3424 | } |
| 3425 | |
| 3426 | //------------------------------------------------------------------------------ |
| 3427 | |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 3428 | #if CONFIG_FRAME_SIZE |
| 3429 | void av1_read_frame_size(struct aom_read_bit_buffer *rb, int num_bits_width, |
| 3430 | int num_bits_height, int *width, int *height) { |
| 3431 | *width = aom_rb_read_literal(rb, num_bits_width) + 1; |
| 3432 | *height = aom_rb_read_literal(rb, num_bits_height) + 1; |
| 3433 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3434 | void av1_read_frame_size(struct aom_read_bit_buffer *rb, int *width, |
| 3435 | int *height) { |
| 3436 | *width = aom_rb_read_literal(rb, 16) + 1; |
| 3437 | *height = aom_rb_read_literal(rb, 16) + 1; |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 3438 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3441 | BITSTREAM_PROFILE av1_read_profile(struct aom_read_bit_buffer *rb) { |
| 3442 | int profile = aom_rb_read_bit(rb); |
| 3443 | profile |= aom_rb_read_bit(rb) << 1; |
| 3444 | if (profile > 2) profile += aom_rb_read_bit(rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3445 | return (BITSTREAM_PROFILE)profile; |
| 3446 | } |
| 3447 | |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 3448 | static void make_update_tile_list_dec(AV1Decoder *pbi, int start_tile, |
| 3449 | int num_tile, FRAME_CONTEXT *ec_ctxs[]) { |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 3450 | int i; |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 3451 | for (i = start_tile; i < start_tile + num_tile; ++i) |
| 3452 | ec_ctxs[i - start_tile] = &pbi->tile_data[i].tctx; |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 3453 | } |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 3454 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 3455 | #if CONFIG_FRAME_SUPERRES |
| 3456 | void superres_post_decode(AV1Decoder *pbi) { |
| 3457 | AV1_COMMON *const cm = &pbi->common; |
| 3458 | BufferPool *const pool = cm->buffer_pool; |
| 3459 | |
| 3460 | if (av1_superres_unscaled(cm)) return; |
| 3461 | |
| 3462 | lock_buffer_pool(pool); |
| 3463 | av1_superres_upscale(cm, pool); |
| 3464 | unlock_buffer_pool(pool); |
| 3465 | } |
| 3466 | #endif // CONFIG_FRAME_SUPERRES |
| 3467 | |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 3468 | static void dec_setup_frame_boundary_info(AV1_COMMON *const cm) { |
David Barker | 5c06a64 | 2017-08-18 13:18:16 +0100 | [diff] [blame] | 3469 | // Note: When LOOPFILTERING_ACROSS_TILES is enabled, we need to clear the |
| 3470 | // boundary information every frame, since the tile boundaries may |
| 3471 | // change every frame (particularly when dependent-horztiles is also |
| 3472 | // enabled); when it is disabled, the only information stored is the frame |
| 3473 | // boundaries, which only depend on the frame size. |
| 3474 | #if !CONFIG_LOOPFILTERING_ACROSS_TILES |
| 3475 | if (cm->width != cm->last_width || cm->height != cm->last_height) |
| 3476 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
| 3477 | { |
Yi Luo | 10e2300 | 2017-07-31 11:54:43 -0700 | [diff] [blame] | 3478 | int row, col; |
| 3479 | for (row = 0; row < cm->mi_rows; ++row) { |
| 3480 | MODE_INFO *mi = cm->mi + row * cm->mi_stride; |
| 3481 | for (col = 0; col < cm->mi_cols; ++col) { |
| 3482 | mi->mbmi.boundary_info = 0; |
| 3483 | mi++; |
| 3484 | } |
| 3485 | } |
| 3486 | av1_setup_frame_boundary_info(cm); |
| 3487 | } |
| 3488 | } |
| 3489 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3490 | size_t av1_decode_frame_headers_and_setup(AV1Decoder *pbi, const uint8_t *data, |
| 3491 | const uint8_t *data_end, |
| 3492 | const uint8_t **p_data_end) { |
| 3493 | AV1_COMMON *const cm = &pbi->common; |
| 3494 | MACROBLOCKD *const xd = &pbi->mb; |
| 3495 | struct aom_read_bit_buffer rb; |
| 3496 | uint8_t clear_data[MAX_AV1_HEADER_SIZE]; |
| 3497 | size_t first_partition_size; |
| 3498 | YV12_BUFFER_CONFIG *new_fb; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3499 | RefBuffer *last_fb_ref_buf = &cm->frame_refs[LAST_FRAME - LAST_FRAME]; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3500 | |
| 3501 | #if CONFIG_ADAPT_SCAN |
| 3502 | av1_deliver_eob_threshold(cm, xd); |
| 3503 | #endif |
| 3504 | #if CONFIG_BITSTREAM_DEBUG |
| 3505 | bitstream_queue_set_frame_read(cm->current_video_frame * 2 + cm->show_frame); |
| 3506 | #endif |
| 3507 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3508 | int i; |
| 3509 | for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
David Barker | d7c8bd5 | 2017-09-25 14:47:29 +0100 | [diff] [blame] | 3510 | cm->global_motion[i] = default_warp_params; |
| 3511 | cm->cur_frame->global_motion[i] = default_warp_params; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3512 | } |
| 3513 | xd->global_motion = cm->global_motion; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3514 | |
| 3515 | first_partition_size = read_uncompressed_header( |
| 3516 | pbi, init_read_bit_buffer(pbi, &rb, data, data_end, clear_data)); |
| 3517 | |
| 3518 | #if CONFIG_EXT_TILE |
| 3519 | // If cm->single_tile_decoding = 0, the independent decoding of a single tile |
| 3520 | // or a section of a frame is not allowed. |
| 3521 | if (!cm->single_tile_decoding && |
| 3522 | (pbi->dec_tile_row >= 0 || pbi->dec_tile_col >= 0)) { |
| 3523 | pbi->dec_tile_row = -1; |
| 3524 | pbi->dec_tile_col = -1; |
| 3525 | } |
| 3526 | #endif // CONFIG_EXT_TILE |
| 3527 | |
| 3528 | pbi->first_partition_size = first_partition_size; |
| 3529 | pbi->uncomp_hdr_size = aom_rb_bytes_read(&rb); |
| 3530 | new_fb = get_frame_new_buffer(cm); |
| 3531 | xd->cur_buf = new_fb; |
| 3532 | #if CONFIG_INTRABC |
| 3533 | #if CONFIG_HIGHBITDEPTH |
| 3534 | av1_setup_scale_factors_for_frame( |
| 3535 | &xd->sf_identity, xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height, |
| 3536 | xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height, |
| 3537 | cm->use_highbitdepth); |
| 3538 | #else |
| 3539 | av1_setup_scale_factors_for_frame( |
| 3540 | &xd->sf_identity, xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height, |
| 3541 | xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height); |
| 3542 | #endif // CONFIG_HIGHBITDEPTH |
| 3543 | #endif // CONFIG_INTRABC |
| 3544 | |
Debargha Mukherjee | 2eada61 | 2017-09-22 15:37:39 -0700 | [diff] [blame] | 3545 | if (cm->show_existing_frame) { |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3546 | // showing a frame directly |
| 3547 | *p_data_end = data + aom_rb_bytes_read(&rb); |
| 3548 | return 0; |
| 3549 | } |
| 3550 | |
| 3551 | data += aom_rb_bytes_read(&rb); |
Debargha Mukherjee | 2eada61 | 2017-09-22 15:37:39 -0700 | [diff] [blame] | 3552 | if (first_partition_size) |
| 3553 | if (!read_is_valid(data, first_partition_size, data_end)) |
| 3554 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 3555 | "Truncated packet or corrupt header length"); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3556 | |
| 3557 | cm->setup_mi(cm); |
| 3558 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3559 | // NOTE(zoeliu): As cm->prev_frame can take neither a frame of |
| 3560 | // show_exisiting_frame=1, nor can it take a frame not used as |
| 3561 | // a reference, it is probable that by the time it is being |
| 3562 | // referred to, the frame buffer it originally points to may |
| 3563 | // already get expired and have been reassigned to the current |
| 3564 | // newly coded frame. Hence, we need to check whether this is |
| 3565 | // the case, and if yes, we have 2 choices: |
| 3566 | // (1) Simply disable the use of previous frame mvs; or |
| 3567 | // (2) Have cm->prev_frame point to one reference frame buffer, |
| 3568 | // e.g. LAST_FRAME. |
| 3569 | if (!dec_is_ref_frame_buf(pbi, cm->prev_frame)) { |
| 3570 | // Reassign the LAST_FRAME buffer to cm->prev_frame. |
| 3571 | cm->prev_frame = last_fb_ref_buf->idx != INVALID_IDX |
| 3572 | ? &cm->buffer_pool->frame_bufs[last_fb_ref_buf->idx] |
| 3573 | : NULL; |
| 3574 | } |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3575 | |
| 3576 | #if CONFIG_TEMPMV_SIGNALING |
| 3577 | if (cm->use_prev_frame_mvs && !frame_can_use_prev_frame_mvs(cm)) { |
| 3578 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 3579 | "Frame wrongly requests previous frame MVs"); |
| 3580 | } |
| 3581 | #else |
| 3582 | cm->use_prev_frame_mvs = !cm->error_resilient_mode && cm->prev_frame && |
| 3583 | #if CONFIG_FRAME_SUPERRES |
| 3584 | cm->width == cm->last_width && |
| 3585 | cm->height == cm->last_height && |
| 3586 | #else |
| 3587 | cm->width == cm->prev_frame->buf.y_crop_width && |
| 3588 | cm->height == cm->prev_frame->buf.y_crop_height && |
| 3589 | #endif // CONFIG_FRAME_SUPERRES |
| 3590 | !cm->last_intra_only && cm->last_show_frame && |
| 3591 | (cm->last_frame_type != KEY_FRAME); |
| 3592 | #endif // CONFIG_TEMPMV_SIGNALING |
| 3593 | |
Zoe Liu | f704a1c | 2017-10-02 16:55:59 -0700 | [diff] [blame] | 3594 | #if CONFIG_EXT_SKIP |
| 3595 | av1_setup_skip_mode_allowed(cm); |
| 3596 | #if 0 |
| 3597 | printf("\nDECODER: Frame=%d, frame_offset=%d, show_frame=%d, " |
| 3598 | "is_skip_mode_allowed=%d, ref_frame_idx=(%d,%d)\n", |
| 3599 | cm->current_video_frame, cm->frame_offset, cm->show_frame, |
| 3600 | cm->is_skip_mode_allowed, cm->ref_frame_idx_0, cm->ref_frame_idx_1); |
| 3601 | #endif // 0 |
| 3602 | #endif // CONFIG_EXT_SKIP |
| 3603 | |
Jingning Han | ea255c9 | 2017-09-29 08:12:09 -0700 | [diff] [blame] | 3604 | #if CONFIG_MFMV |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3605 | av1_setup_motion_field(cm); |
Jingning Han | ea255c9 | 2017-09-29 08:12:09 -0700 | [diff] [blame] | 3606 | #endif // CONFIG_MFMV |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3607 | |
| 3608 | av1_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y); |
| 3609 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 3610 | if (cm->error_resilient_mode || frame_is_intra_only(cm)) { |
| 3611 | // use the default frame context values |
| 3612 | *cm->fc = cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 3613 | cm->pre_fc = &cm->frame_contexts[FRAME_CONTEXT_DEFAULTS]; |
| 3614 | } else { |
| 3615 | *cm->fc = cm->frame_contexts[cm->frame_refs[0].idx]; |
| 3616 | cm->pre_fc = &cm->frame_contexts[cm->frame_refs[0].idx]; |
| 3617 | } |
| 3618 | #else |
| 3619 | *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
| 3620 | cm->pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
| 3621 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 3622 | if (!cm->fc->initialized) |
| 3623 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 3624 | "Uninitialized entropy context."); |
| 3625 | |
| 3626 | av1_zero(cm->counts); |
| 3627 | |
| 3628 | xd->corrupted = 0; |
Debargha Mukherjee | 2eada61 | 2017-09-22 15:37:39 -0700 | [diff] [blame] | 3629 | if (first_partition_size) { |
| 3630 | new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size); |
| 3631 | if (new_fb->corrupted) |
| 3632 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 3633 | "Decode failed. Frame data header is corrupted."); |
| 3634 | } |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3635 | return first_partition_size; |
| 3636 | } |
| 3637 | |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 3638 | // Once-per-frame initialization |
| 3639 | static void setup_frame_info(AV1Decoder *pbi) { |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3640 | AV1_COMMON *const cm = &pbi->common; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3641 | |
| 3642 | #if CONFIG_LOOP_RESTORATION |
| 3643 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 3644 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 3645 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
| 3646 | av1_alloc_restoration_buffers(cm); |
| 3647 | } |
| 3648 | #endif |
| 3649 | |
Cheng Chen | d8184da | 2017-09-26 18:15:22 -0700 | [diff] [blame] | 3650 | #if !CONFIG_LOOPFILTER_LEVEL |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3651 | if (cm->lf.filter_level && !cm->skip_loop_filter) { |
| 3652 | av1_loop_filter_frame_init(cm, cm->lf.filter_level, cm->lf.filter_level); |
| 3653 | } |
| 3654 | #endif |
| 3655 | |
| 3656 | // If encoded in frame parallel mode, frame context is ready after decoding |
| 3657 | // the frame header. |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 3658 | if (cm->frame_parallel_decode && |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3659 | cm->refresh_frame_context != REFRESH_FRAME_CONTEXT_BACKWARD) { |
| 3660 | AVxWorker *const worker = pbi->frame_worker_owner; |
| 3661 | FrameWorkerData *const frame_worker_data = worker->data1; |
| 3662 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_FORWARD) { |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3663 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 3664 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
| 3665 | #else |
| 3666 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
| 3667 | #endif // CONFIG_NO_FRAME_CONTEXT_SIGNALING |
| 3668 | } |
| 3669 | av1_frameworker_lock_stats(worker); |
| 3670 | pbi->cur_buf->row = -1; |
| 3671 | pbi->cur_buf->col = -1; |
| 3672 | frame_worker_data->frame_context_ready = 1; |
| 3673 | // Signal the main thread that context is ready. |
| 3674 | av1_frameworker_signal_stats(worker); |
| 3675 | av1_frameworker_unlock_stats(worker); |
| 3676 | } |
| 3677 | |
| 3678 | dec_setup_frame_boundary_info(cm); |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | void av1_decode_tg_tiles_and_wrapup(AV1Decoder *pbi, const uint8_t *data, |
| 3682 | const uint8_t *data_end, |
| 3683 | const uint8_t **p_data_end, int startTile, |
| 3684 | int endTile, int initialize_flag) { |
| 3685 | AV1_COMMON *const cm = &pbi->common; |
| 3686 | MACROBLOCKD *const xd = &pbi->mb; |
| 3687 | |
| 3688 | if (initialize_flag) setup_frame_info(pbi); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3689 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3690 | #if CONFIG_OBU |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 3691 | *p_data_end = decode_tiles(pbi, data, data_end, startTile, endTile); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3692 | #else |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 3693 | *p_data_end = |
| 3694 | decode_tiles(pbi, data + pbi->uncomp_hdr_size + pbi->first_partition_size, |
| 3695 | data_end, startTile, endTile); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3696 | #endif |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3697 | |
| 3698 | if (endTile != cm->tile_rows * cm->tile_cols - 1) { |
| 3699 | return; |
| 3700 | } |
| 3701 | |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 3702 | #if CONFIG_STRIPED_LOOP_RESTORATION |
Rupert Swarbrick | 8ce049e | 2017-11-06 16:47:47 +0000 | [diff] [blame] | 3703 | #if CONFIG_FRAME_SUPERRES && CONFIG_HORZONLY_FRAME_SUPERRES |
| 3704 | if (!av1_superres_unscaled(cm)) aom_extend_frame_borders(&pbi->cur_buf->buf); |
| 3705 | #endif |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 3706 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 3707 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 3708 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Rupert Swarbrick | 921b334 | 2017-11-06 18:04:22 +0000 | [diff] [blame] | 3709 | av1_loop_restoration_save_boundary_lines(&pbi->cur_buf->buf, cm, 0); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 3710 | } |
| 3711 | #endif |
| 3712 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3713 | #if CONFIG_CDEF |
| 3714 | if (!cm->skip_loop_filter && !cm->all_lossless) { |
| 3715 | av1_cdef_frame(&pbi->cur_buf->buf, cm, &pbi->mb); |
| 3716 | } |
| 3717 | #endif // CONFIG_CDEF |
| 3718 | |
| 3719 | #if CONFIG_FRAME_SUPERRES |
| 3720 | superres_post_decode(pbi); |
| 3721 | #endif // CONFIG_FRAME_SUPERRES |
| 3722 | |
| 3723 | #if CONFIG_LOOP_RESTORATION |
| 3724 | if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE || |
| 3725 | cm->rst_info[1].frame_restoration_type != RESTORE_NONE || |
| 3726 | cm->rst_info[2].frame_restoration_type != RESTORE_NONE) { |
Rupert Swarbrick | 921b334 | 2017-11-06 18:04:22 +0000 | [diff] [blame] | 3727 | av1_loop_restoration_save_boundary_lines(&pbi->cur_buf->buf, cm, 1); |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 3728 | av1_loop_restoration_filter_frame((YV12_BUFFER_CONFIG *)xd->cur_buf, cm, |
| 3729 | cm->rst_info, 7, NULL); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3730 | } |
| 3731 | #endif // CONFIG_LOOP_RESTORATION |
| 3732 | |
| 3733 | if (!xd->corrupted) { |
| 3734 | if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) { |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 3735 | #if CONFIG_SIMPLE_BWD_ADAPT |
| 3736 | const int num_bwd_ctxs = 1; |
| 3737 | #else |
| 3738 | const int num_bwd_ctxs = cm->tile_rows * cm->tile_cols; |
| 3739 | #endif |
| 3740 | FRAME_CONTEXT **tile_ctxs = |
| 3741 | aom_malloc(num_bwd_ctxs * sizeof(&pbi->tile_data[0].tctx)); |
| 3742 | aom_cdf_prob **cdf_ptrs = aom_malloc( |
| 3743 | num_bwd_ctxs * sizeof(&pbi->tile_data[0].tctx.partition_cdf[0][0])); |
| 3744 | #if CONFIG_SIMPLE_BWD_ADAPT |
| 3745 | make_update_tile_list_dec(pbi, cm->largest_tile_id, num_bwd_ctxs, |
| 3746 | tile_ctxs); |
| 3747 | #else |
| 3748 | make_update_tile_list_dec(pbi, 0, num_bwd_ctxs, tile_ctxs); |
| 3749 | #endif |
Angie Chiang | 85e3b96 | 2017-10-01 16:04:43 -0700 | [diff] [blame] | 3750 | #if CONFIG_SYMBOLRATE |
| 3751 | av1_dump_symbol_rate(cm); |
| 3752 | #endif |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3753 | av1_adapt_intra_frame_probs(cm); |
| 3754 | av1_average_tile_coef_cdfs(pbi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 3755 | num_bwd_ctxs); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3756 | av1_average_tile_intra_cdfs(pbi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 3757 | num_bwd_ctxs); |
Debargha Mukherjee | 43061b3 | 2017-10-13 16:50:17 -0700 | [diff] [blame] | 3758 | av1_average_tile_loopfilter_cdfs(pbi->common.fc, tile_ctxs, cdf_ptrs, |
| 3759 | num_bwd_ctxs); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3760 | #if CONFIG_ADAPT_SCAN |
| 3761 | av1_adapt_scan_order(cm); |
| 3762 | #endif // CONFIG_ADAPT_SCAN |
| 3763 | |
| 3764 | if (!frame_is_intra_only(cm)) { |
| 3765 | av1_adapt_inter_frame_probs(cm); |
Thomas Davies | 0e7b1d7 | 2017-10-02 10:54:24 +0100 | [diff] [blame] | 3766 | #if !CONFIG_NEW_MULTISYMBOL |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3767 | av1_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
Thomas Davies | 0e7b1d7 | 2017-10-02 10:54:24 +0100 | [diff] [blame] | 3768 | #endif |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3769 | av1_average_tile_inter_cdfs(&pbi->common, pbi->common.fc, tile_ctxs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 3770 | cdf_ptrs, num_bwd_ctxs); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3771 | av1_average_tile_mv_cdfs(pbi->common.fc, tile_ctxs, cdf_ptrs, |
Thomas Davies | 4822e14 | 2017-10-10 11:30:36 +0100 | [diff] [blame] | 3772 | num_bwd_ctxs); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3773 | } |
| 3774 | aom_free(tile_ctxs); |
| 3775 | aom_free(cdf_ptrs); |
| 3776 | } else { |
| 3777 | debug_check_frame_counts(cm); |
| 3778 | } |
| 3779 | } else { |
| 3780 | aom_internal_error(&cm->error, AOM_CODEC_CORRUPT_FRAME, |
| 3781 | "Decode failed. Frame data is corrupted."); |
| 3782 | } |
| 3783 | |
| 3784 | #if CONFIG_INSPECTION |
| 3785 | if (pbi->inspect_cb != NULL) { |
| 3786 | (*pbi->inspect_cb)(pbi, pbi->inspect_ctx); |
| 3787 | } |
| 3788 | #endif |
| 3789 | |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 3790 | // Non frame parallel update frame context here. |
David Barker | b44deca | 2017-11-03 17:06:10 +0000 | [diff] [blame] | 3791 | if (!cm->frame_parallel_decode || |
| 3792 | cm->refresh_frame_context != REFRESH_FRAME_CONTEXT_FORWARD) { |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3793 | #if CONFIG_NO_FRAME_CONTEXT_SIGNALING |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 3794 | cm->frame_contexts[cm->new_fb_idx] = *cm->fc; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3795 | #else |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 3796 | if (!cm->error_resilient_mode) |
| 3797 | cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3798 | #endif |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 3799 | } |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | #if CONFIG_OBU |
| 3803 | |
| 3804 | static OBU_TYPE read_obu_header(struct aom_read_bit_buffer *rb, |
| 3805 | uint32_t *header_size) { |
| 3806 | OBU_TYPE obu_type; |
| 3807 | int obu_extension_flag; |
| 3808 | |
| 3809 | *header_size = 1; |
| 3810 | |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 3811 | // first bit is obu_forbidden_bit (0) according to R19 |
| 3812 | aom_rb_read_bit(rb); |
| 3813 | |
| 3814 | obu_type = (OBU_TYPE)aom_rb_read_literal(rb, 4); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3815 | aom_rb_read_literal(rb, 2); // reserved |
| 3816 | obu_extension_flag = aom_rb_read_bit(rb); |
| 3817 | if (obu_extension_flag) { |
| 3818 | *header_size += 1; |
| 3819 | aom_rb_read_literal(rb, 3); // temporal_id |
| 3820 | aom_rb_read_literal(rb, 2); |
| 3821 | aom_rb_read_literal(rb, 2); |
| 3822 | aom_rb_read_literal(rb, 1); // reserved |
| 3823 | } |
| 3824 | |
| 3825 | return obu_type; |
| 3826 | } |
| 3827 | |
| 3828 | static uint32_t read_temporal_delimiter_obu() { return 0; } |
| 3829 | |
| 3830 | static uint32_t read_sequence_header_obu(AV1Decoder *pbi, |
| 3831 | struct aom_read_bit_buffer *rb) { |
| 3832 | AV1_COMMON *const cm = &pbi->common; |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 3833 | SequenceHeader *const seq_params = &cm->seq_params; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3834 | uint32_t saved_bit_offset = rb->bit_offset; |
| 3835 | |
| 3836 | cm->profile = av1_read_profile(rb); |
| 3837 | aom_rb_read_literal(rb, 4); // level |
| 3838 | |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 3839 | #if CONFIG_FRAME_SIZE |
| 3840 | int num_bits_width = aom_rb_read_literal(rb, 4) + 1; |
| 3841 | int num_bits_height = aom_rb_read_literal(rb, 4) + 1; |
| 3842 | int max_frame_width = aom_rb_read_literal(rb, num_bits_width) + 1; |
| 3843 | int max_frame_height = aom_rb_read_literal(rb, num_bits_height) + 1; |
| 3844 | |
| 3845 | seq_params->num_bits_width = num_bits_width; |
| 3846 | seq_params->num_bits_height = num_bits_height; |
| 3847 | seq_params->max_frame_width = max_frame_width; |
| 3848 | seq_params->max_frame_height = max_frame_height; |
| 3849 | #endif |
| 3850 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3851 | seq_params->frame_id_numbers_present_flag = aom_rb_read_bit(rb); |
| 3852 | if (seq_params->frame_id_numbers_present_flag) { |
Frederic Barbier | 4d5d90e | 2017-10-13 09:22:33 +0200 | [diff] [blame] | 3853 | // We must always have delta_frame_id_length < frame_id_length, |
| 3854 | // in order for a frame to be referenced with a unique delta. |
| 3855 | // Avoid wasting bits by using a coding that enforces this restriction. |
Frederic Barbier | e83fcfe | 2017-10-13 10:37:50 +0200 | [diff] [blame] | 3856 | 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] | 3857 | seq_params->frame_id_length = |
| 3858 | aom_rb_read_literal(rb, 3) + seq_params->delta_frame_id_length + 1; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | read_bitdepth_colorspace_sampling(cm, rb, pbi->allow_lowbitdepth); |
| 3862 | |
| 3863 | return ((rb->bit_offset - saved_bit_offset + 7) >> 3); |
| 3864 | } |
| 3865 | |
| 3866 | static uint32_t read_frame_header_obu(AV1Decoder *pbi, const uint8_t *data, |
| 3867 | const uint8_t *data_end, |
| 3868 | const uint8_t **p_data_end) { |
| 3869 | size_t header_size; |
| 3870 | |
| 3871 | header_size = |
| 3872 | av1_decode_frame_headers_and_setup(pbi, data, data_end, p_data_end); |
| 3873 | return (uint32_t)(pbi->uncomp_hdr_size + header_size); |
| 3874 | } |
| 3875 | |
| 3876 | static uint32_t read_tile_group_header(AV1Decoder *pbi, |
| 3877 | struct aom_read_bit_buffer *rb, |
| 3878 | int *startTile, int *endTile) { |
| 3879 | AV1_COMMON *const cm = &pbi->common; |
| 3880 | uint32_t saved_bit_offset = rb->bit_offset; |
| 3881 | |
| 3882 | *startTile = aom_rb_read_literal(rb, cm->log2_tile_rows + cm->log2_tile_cols); |
| 3883 | *endTile = aom_rb_read_literal(rb, cm->log2_tile_rows + cm->log2_tile_cols); |
| 3884 | |
| 3885 | return ((rb->bit_offset - saved_bit_offset + 7) >> 3); |
| 3886 | } |
| 3887 | |
| 3888 | static uint32_t read_one_tile_group_obu(AV1Decoder *pbi, |
| 3889 | struct aom_read_bit_buffer *rb, |
| 3890 | int is_first_tg, const uint8_t *data, |
| 3891 | const uint8_t *data_end, |
| 3892 | const uint8_t **p_data_end, |
| 3893 | int *is_last_tg) { |
| 3894 | AV1_COMMON *const cm = &pbi->common; |
| 3895 | int startTile, endTile; |
| 3896 | uint32_t header_size, tg_payload_size; |
| 3897 | |
| 3898 | header_size = read_tile_group_header(pbi, rb, &startTile, &endTile); |
| 3899 | data += header_size; |
| 3900 | av1_decode_tg_tiles_and_wrapup(pbi, data, data_end, p_data_end, startTile, |
| 3901 | endTile, is_first_tg); |
| 3902 | tg_payload_size = (uint32_t)(*p_data_end - data); |
| 3903 | |
| 3904 | // TODO(shan): For now, assume all tile groups received in order |
| 3905 | *is_last_tg = endTile == cm->tile_rows * cm->tile_cols - 1; |
| 3906 | |
| 3907 | return header_size + tg_payload_size; |
| 3908 | } |
| 3909 | |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 3910 | static void read_metadata_private_data(const uint8_t *data, uint32_t sz) { |
| 3911 | int i; |
| 3912 | |
| 3913 | for (i = 0; i < (int)sz; i++) { |
| 3914 | mem_get_le16(data); |
| 3915 | data += 2; |
| 3916 | } |
| 3917 | } |
| 3918 | |
| 3919 | static void read_metadata_hdr_cll(const uint8_t *data) { |
| 3920 | mem_get_le16(data); |
| 3921 | mem_get_le16(data + 2); |
| 3922 | } |
| 3923 | |
| 3924 | static void read_metadata_hdr_mdcv(const uint8_t *data) { |
| 3925 | int i; |
| 3926 | |
| 3927 | for (i = 0; i < 3; i++) { |
| 3928 | mem_get_le16(data); |
| 3929 | data += 2; |
| 3930 | mem_get_le16(data); |
| 3931 | data += 2; |
| 3932 | } |
| 3933 | |
| 3934 | mem_get_le16(data); |
| 3935 | data += 2; |
| 3936 | mem_get_le16(data); |
| 3937 | data += 2; |
| 3938 | mem_get_le16(data); |
| 3939 | data += 2; |
| 3940 | mem_get_le16(data); |
| 3941 | } |
| 3942 | |
| 3943 | static uint32_t read_metadata(const uint8_t *data, uint32_t sz) { |
| 3944 | METADATA_TYPE metadata_type; |
| 3945 | |
| 3946 | metadata_type = (METADATA_TYPE)mem_get_le16(data); |
| 3947 | |
| 3948 | if (metadata_type == METADATA_TYPE_PRIVATE_DATA) { |
| 3949 | read_metadata_private_data(data + 2, sz - 2); |
| 3950 | } else if (metadata_type == METADATA_TYPE_HDR_CLL) { |
| 3951 | read_metadata_hdr_cll(data + 2); |
| 3952 | } else if (metadata_type == METADATA_TYPE_HDR_MDCV) { |
| 3953 | read_metadata_hdr_mdcv(data + 2); |
| 3954 | } |
| 3955 | |
| 3956 | return sz; |
| 3957 | } |
| 3958 | |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3959 | void av1_decode_frame_from_obus(struct AV1Decoder *pbi, const uint8_t *data, |
| 3960 | const uint8_t *data_end, |
| 3961 | const uint8_t **p_data_end) { |
| 3962 | AV1_COMMON *const cm = &pbi->common; |
| 3963 | int frame_decoding_finished = 0; |
| 3964 | int is_first_tg_obu_received = 1; |
| 3965 | int frame_header_received = 0; |
| 3966 | int frame_header_size = 0; |
| 3967 | |
| 3968 | // decode frame as a series of OBUs |
| 3969 | while (!frame_decoding_finished && !cm->error.error_code) { |
| 3970 | struct aom_read_bit_buffer rb; |
| 3971 | uint8_t clear_data[80]; |
| 3972 | uint32_t obu_size, obu_header_size, obu_payload_size = 0; |
| 3973 | OBU_TYPE obu_type; |
| 3974 | |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 3975 | init_read_bit_buffer(pbi, &rb, data + PRE_OBU_SIZE_BYTES, data_end, |
| 3976 | clear_data); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3977 | |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 3978 | // every obu is preceded by PRE_OBU_SIZE_BYTES-byte size of obu (obu header + |
| 3979 | // payload size) |
| 3980 | // The obu size is only needed for tile group OBUs |
| 3981 | #if CONFIG_ADD_4BYTES_OBUSIZE |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3982 | obu_size = mem_get_le32(data); |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 3983 | #else |
| 3984 | obu_size = data_end - data; |
| 3985 | #endif |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3986 | obu_type = read_obu_header(&rb, &obu_header_size); |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 3987 | data += (PRE_OBU_SIZE_BYTES + obu_header_size); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 3988 | |
| 3989 | switch (obu_type) { |
| 3990 | case OBU_TD: obu_payload_size = read_temporal_delimiter_obu(); break; |
| 3991 | case OBU_SEQUENCE_HEADER: |
| 3992 | obu_payload_size = read_sequence_header_obu(pbi, &rb); |
| 3993 | break; |
| 3994 | case OBU_FRAME_HEADER: |
| 3995 | // Only decode first frame header received |
| 3996 | if (!frame_header_received) { |
| 3997 | frame_header_size = obu_payload_size = |
| 3998 | read_frame_header_obu(pbi, data, data_end, p_data_end); |
| 3999 | frame_header_received = 1; |
| 4000 | } else { |
| 4001 | obu_payload_size = frame_header_size; |
| 4002 | } |
| 4003 | if (cm->show_existing_frame) frame_decoding_finished = 1; |
| 4004 | break; |
| 4005 | case OBU_TILE_GROUP: |
David Barker | 0156308 | 2017-10-09 13:59:16 +0100 | [diff] [blame] | 4006 | obu_payload_size = |
| 4007 | read_one_tile_group_obu(pbi, &rb, is_first_tg_obu_received, data, |
| 4008 | data + obu_size - obu_header_size, |
| 4009 | p_data_end, &frame_decoding_finished); |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 4010 | is_first_tg_obu_received = 0; |
| 4011 | break; |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 4012 | case OBU_METADATA: |
| 4013 | obu_payload_size = read_metadata(data, obu_size); |
| 4014 | break; |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 4015 | default: break; |
| 4016 | } |
| 4017 | data += obu_payload_size; |
| 4018 | } |
| 4019 | } |
| 4020 | #endif |