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