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