/src/avm/av2/decoder/decodemv.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Alliance for Open Media. All rights reserved |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 3-Clause Clear License |
5 | | * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear |
6 | | * License was not distributed with this source code in the LICENSE file, you |
7 | | * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the |
8 | | * Alliance for Open Media Patent License 1.0 was not distributed with this |
9 | | * source code in the PATENTS file, you can obtain it at |
10 | | * aomedia.org/license/patent-license/. |
11 | | */ |
12 | | |
13 | | #include <assert.h> |
14 | | |
15 | | #include "av2/common/blockd.h" |
16 | | #include "av2/common/bru.h" |
17 | | #include "av2/common/cdef.h" |
18 | | #include "av2/common/ccso.h" |
19 | | #include "av2/common/cdef_block.h" |
20 | | #include "av2/common/cfl.h" |
21 | | #include "av2/common/common.h" |
22 | | #include "av2/common/txb_common.h" |
23 | | #include "av2/common/entropy.h" |
24 | | #include "av2/common/entropymode.h" |
25 | | #include "av2/common/entropymv.h" |
26 | | #include "av2/common/intra_dip.h" |
27 | | #include "av2/common/mvref_common.h" |
28 | | #include "av2/common/pred_common.h" |
29 | | #include "av2/common/reconinter.h" |
30 | | #include "av2/common/reconintra.h" |
31 | | #include "av2/common/secondary_tx.h" |
32 | | #include "av2/common/seg_common.h" |
33 | | #include "av2/common/warped_motion.h" |
34 | | |
35 | | #include "av2/decoder/decodeframe.h" |
36 | | #include "av2/decoder/decodemv.h" |
37 | | |
38 | | #include "avm_dsp/avm_dsp_common.h" |
39 | | #include "avm_dsp/binary_codes_reader.h" |
40 | | #include "avm_ports/bitops.h" |
41 | | #include "av2/common/gdf.h" |
42 | | |
43 | | #define DEC_MISMATCH_DEBUG 0 |
44 | | |
45 | 709k | void read_gdf(AV2_COMMON *cm, avm_reader *r, MACROBLOCKD *const xd) { |
46 | 709k | if (!is_allow_gdf(cm)) return; |
47 | 700k | if ((cm->gdf_info.gdf_mode < 2) || (cm->gdf_info.gdf_block_num <= 1)) return; |
48 | 174k | if ((xd->mi_row % cm->mib_size != 0) || (xd->mi_col % cm->mib_size != 0)) |
49 | 149k | return; |
50 | | |
51 | 25.4k | if (cm->bridge_frame_info.is_bridge_frame && cm->gdf_info.gdf_mode) { |
52 | 0 | avm_internal_error(&cm->error, AVM_CODEC_ERROR, |
53 | 0 | "Bridge frame cannot use gdf"); |
54 | 0 | } |
55 | 25.4k | if (cm->bru.frame_inactive_flag) return; |
56 | 25.4k | if (cm->bru.enabled && cm->gdf_info.gdf_mode == 1) { |
57 | 0 | avm_internal_error(&cm->error, AVM_CODEC_ERROR, |
58 | 0 | "BRU frame cannnot use gdf_mode 1"); |
59 | 0 | } |
60 | | |
61 | 661k | for (int mi_row = xd->mi_row; mi_row < xd->mi_row + cm->mib_size; mi_row++) { |
62 | 15.0M | for (int mi_col = xd->mi_col; mi_col < xd->mi_col + cm->mib_size; |
63 | 14.3M | mi_col++) { |
64 | 14.3M | int blk_idx = |
65 | 14.3M | gdf_get_block_idx(cm, mi_row << MI_SIZE_LOG2, mi_col << MI_SIZE_LOG2); |
66 | 14.3M | if (blk_idx >= 0) { |
67 | 25.4k | cm->gdf_info.gdf_block_flags[blk_idx] = avm_read_symbol( |
68 | 25.4k | r, xd->tile_ctx->gdf_cdf, 2, ACCT_INFO("gdf_onoff")); |
69 | 25.4k | } |
70 | 14.3M | } |
71 | 636k | } |
72 | 25.4k | } |
73 | | |
74 | 709k | void read_cdef(AV2_COMMON *cm, avm_reader *r, MACROBLOCKD *const xd) { |
75 | 709k | assert(xd->tree_type != CHROMA_PART); |
76 | 709k | const int skip_txfm = xd->mi[0]->skip_txfm[0]; |
77 | 709k | if (cm->features.coded_lossless) return; |
78 | 700k | if (!cm->cdef_info.cdef_frame_enable) return; |
79 | | |
80 | 688k | const int mi_row = xd->mi_row; |
81 | 688k | const int mi_col = xd->mi_col; |
82 | | |
83 | | // At the start of a superblock, mark that we haven't yet read CDEF strengths |
84 | | // for any of the CDEF units contained in this superblock. |
85 | 688k | const int sb_mask = (cm->mib_size - 1); |
86 | 688k | const int mi_row_in_sb = (mi_row & sb_mask); |
87 | 688k | const int mi_col_in_sb = (mi_col & sb_mask); |
88 | 688k | if (mi_row_in_sb == 0 && mi_col_in_sb == 0) { |
89 | 117k | av2_zero(xd->cdef_transmitted); |
90 | 117k | } |
91 | | |
92 | | // Find index of this CDEF unit in this superblock. |
93 | 688k | const int index = av2_get_cdef_transmitted_index(mi_row, mi_col); |
94 | | |
95 | 688k | CommonModeInfoParams *const mi_params = &cm->mi_params; |
96 | | |
97 | | // Read CDEF strength from the first non-skip coding block in this CDEF unit. |
98 | 688k | if (!xd->cdef_transmitted[index] && |
99 | 203k | (cm->cdef_info.cdef_on_skip_txfm_frame_enable == 1 || !skip_txfm)) { |
100 | 187k | const int grid_idx = fetch_cdef_mi_grid_index(cm, xd); |
101 | 187k | MB_MODE_INFO *const mbmi = mi_params->mi_grid_base[grid_idx]; |
102 | 187k | if (cm->cdef_info.nb_cdef_strengths == 1) { |
103 | 83.6k | mbmi->cdef_strength = 0; |
104 | 103k | } else { |
105 | 103k | const int cdef_strength_index0_ctx = av2_get_cdef_context(cm, xd); |
106 | 103k | const int is_strength_index0 = avm_read_symbol( |
107 | 103k | r, xd->tile_ctx->cdef_strength_index0_cdf[cdef_strength_index0_ctx], |
108 | 103k | 2, ACCT_INFO("cdef_strength_index0_cdf")); |
109 | 103k | if (is_strength_index0) { |
110 | 12.7k | mbmi->cdef_strength = 0; |
111 | 91.0k | } else { |
112 | 91.0k | const int nb_cdef_strengths = cm->cdef_info.nb_cdef_strengths; |
113 | 91.0k | if (nb_cdef_strengths == 2) { |
114 | 14.3k | mbmi->cdef_strength = 1; |
115 | 76.6k | } else { |
116 | 76.6k | mbmi->cdef_strength = |
117 | 76.6k | avm_read_symbol(r, xd->tile_ctx->cdef_cdf[nb_cdef_strengths - 3], |
118 | 76.6k | nb_cdef_strengths - 1, |
119 | 76.6k | ACCT_INFO("cdef_strength")) + |
120 | 76.6k | 1; |
121 | 76.6k | } |
122 | 91.0k | } |
123 | 103k | } |
124 | 187k | xd->cdef_transmitted[index] = true; |
125 | 501k | } else { |
126 | 501k | if (!xd->cdef_transmitted[index] && |
127 | 16.4k | !cm->cdef_info.cdef_on_skip_txfm_frame_enable && skip_txfm) { |
128 | 16.4k | const int grid_idx = fetch_cdef_mi_grid_index(cm, xd); |
129 | 16.4k | MB_MODE_INFO *const mbmi = mi_params->mi_grid_base[grid_idx]; |
130 | 16.4k | mbmi->cdef_strength = -1; |
131 | 16.4k | } |
132 | 501k | } |
133 | 688k | } |
134 | | |
135 | | // This function is to copy the block level ccso control flag when the |
136 | | // block size is larger than 128x128 chroma, e.g. 256x256 superblock with 444 |
137 | | // chroma subsampling. |
138 | | static void span_ccso(AV2_COMMON *cm, MACROBLOCKD *const xd, int pli, |
139 | 66.1k | int blk_idc) { |
140 | 66.1k | const CommonModeInfoParams *const mi_params = &cm->mi_params; |
141 | 66.1k | const int mi_row = xd->mi_row; |
142 | 66.1k | const int mi_col = xd->mi_col; |
143 | 66.1k | const BLOCK_SIZE bsize = xd->mi[0]->sb_type[PLANE_TYPE_Y]; |
144 | 66.1k | const int bw = mi_size_wide[bsize]; |
145 | 66.1k | const int bh = mi_size_high[bsize]; |
146 | 66.1k | const int ccso_blk_size = get_ccso_unit_size_log2_adaptive_tile(cm); |
147 | 66.1k | const int log2_w = ccso_blk_size; |
148 | 66.1k | const int log2_h = ccso_blk_size; |
149 | 66.1k | const int f_w = 1 << log2_w >> MI_SIZE_LOG2; |
150 | 66.1k | const int f_h = 1 << log2_h >> MI_SIZE_LOG2; |
151 | 66.1k | const int ccso_nhfb = (mi_params->mi_cols + f_w - 1) / f_w; |
152 | 132k | for (int row = mi_row; row < mi_row + bh; row += f_h) { |
153 | 132k | for (int col = mi_col; col < mi_col + bw; col += f_w) { |
154 | 66.2k | int sb_idx = (row / f_h) * ccso_nhfb + (col / f_w); |
155 | 66.2k | cm->cur_frame->ccso_info.sb_filter_control[pli][sb_idx] = blk_idc; |
156 | 66.2k | } |
157 | 66.2k | } |
158 | 66.1k | } |
159 | | |
160 | 649k | void read_ccso(AV2_COMMON *cm, avm_reader *r, MACROBLOCKD *const xd) { |
161 | 649k | if (cm->features.coded_lossless) return; |
162 | 641k | const CommonModeInfoParams *const mi_params = &cm->mi_params; |
163 | 641k | const int mi_row = xd->mi_row; |
164 | 641k | const int mi_col = xd->mi_col; |
165 | 641k | const int ccso_blk_size = get_ccso_unit_size_log2_adaptive_tile(cm); |
166 | 641k | const int blk_size_y = (1 << (ccso_blk_size - MI_SIZE_LOG2)) - 1; |
167 | 641k | const int blk_size_x = (1 << (ccso_blk_size - MI_SIZE_LOG2)) - 1; |
168 | 641k | int blk_idc; |
169 | 641k | if (!(mi_row & blk_size_y) && !(mi_col & blk_size_x) && |
170 | 81.1k | cm->ccso_info.ccso_enable[0]) { |
171 | 25.3k | const int log2_filter_unit_size = ccso_blk_size; |
172 | 25.3k | const int ccso_nhfb = ((mi_params->mi_cols >> xd->plane[0].subsampling_x) + |
173 | 25.3k | (1 << log2_filter_unit_size >> 2) - 1) / |
174 | 25.3k | (1 << log2_filter_unit_size >> 2); |
175 | 25.3k | int sb_idx = |
176 | 25.3k | (mi_row / (blk_size_y + 1)) * ccso_nhfb + (mi_col / (blk_size_x + 1)); |
177 | | |
178 | 25.3k | if (!cm->ccso_info.sb_reuse_ccso[0]) { |
179 | 25.3k | const int ccso_ctx = av2_get_ccso_context(cm, xd, 0); |
180 | 25.3k | blk_idc = avm_read_symbol(r, xd->tile_ctx->ccso_cdf[0][ccso_ctx], 2, |
181 | 25.3k | ACCT_INFO("blk_idc")); |
182 | 25.3k | } else { |
183 | 0 | CcsoInfo *ref_frame_ccso_info = |
184 | 0 | &get_ref_frame_buf(cm, cm->ccso_info.ccso_ref_idx[0])->ccso_info; |
185 | 0 | blk_idc = ref_frame_ccso_info->sb_filter_control[0][sb_idx]; |
186 | 0 | } |
187 | 25.3k | xd->ccso_blk_y = blk_idc; |
188 | 25.3k | mi_params |
189 | 25.3k | ->mi_grid_base[(mi_row & ~blk_size_y) * mi_params->mi_stride + |
190 | 25.3k | (mi_col & ~blk_size_x)] |
191 | 25.3k | ->ccso_blk_y = blk_idc; |
192 | 25.3k | span_ccso(cm, xd, 0, blk_idc); |
193 | 616k | } else if (cm->ccso_info.ccso_enable[0] && |
194 | 220k | av2_check_ccso_mbmi_inside_tile(cm, xd, xd->mi[0])) { |
195 | 220k | mi_params->mi_grid_base[mi_row * mi_params->mi_stride + mi_col] |
196 | 220k | ->ccso_blk_y = |
197 | 220k | mi_params |
198 | 220k | ->mi_grid_base[(mi_row & ~blk_size_y) * mi_params->mi_stride + |
199 | 220k | (mi_col & ~blk_size_x)] |
200 | 220k | ->ccso_blk_y; |
201 | 220k | } |
202 | | |
203 | 641k | if (!(mi_row & blk_size_y) && !(mi_col & blk_size_x) && |
204 | 81.1k | cm->ccso_info.ccso_enable[1]) { |
205 | 12.3k | const int log2_filter_unit_size = |
206 | 12.3k | (ccso_blk_size - xd->plane[1].subsampling_x); |
207 | 12.3k | const int ccso_nhfb = ((mi_params->mi_cols >> xd->plane[1].subsampling_x) + |
208 | 12.3k | (1 << log2_filter_unit_size >> 2) - 1) / |
209 | 12.3k | (1 << log2_filter_unit_size >> 2); |
210 | 12.3k | int sb_idx = |
211 | 12.3k | (mi_row / (blk_size_y + 1)) * ccso_nhfb + (mi_col / (blk_size_x + 1)); |
212 | | |
213 | 12.3k | if (!cm->ccso_info.sb_reuse_ccso[1]) { |
214 | 12.2k | const int ccso_ctx = av2_get_ccso_context(cm, xd, 1); |
215 | 12.2k | blk_idc = avm_read_symbol(r, xd->tile_ctx->ccso_cdf[1][ccso_ctx], 2, |
216 | 12.2k | ACCT_INFO("blk_idc")); |
217 | 12.2k | } else { |
218 | 3 | CcsoInfo *ref_frame_ccso_info = |
219 | 3 | &get_ref_frame_buf(cm, cm->ccso_info.ccso_ref_idx[1])->ccso_info; |
220 | 3 | blk_idc = ref_frame_ccso_info->sb_filter_control[1][sb_idx]; |
221 | 3 | } |
222 | 12.3k | xd->ccso_blk_u = blk_idc; |
223 | 12.3k | mi_params |
224 | 12.3k | ->mi_grid_base[(mi_row & ~blk_size_y) * mi_params->mi_stride + |
225 | 12.3k | (mi_col & ~blk_size_x)] |
226 | 12.3k | ->ccso_blk_u = blk_idc; |
227 | 12.3k | span_ccso(cm, xd, 1, blk_idc); |
228 | 629k | } else if (cm->ccso_info.ccso_enable[1] && |
229 | 91.4k | av2_check_ccso_mbmi_inside_tile(cm, xd, xd->mi[0])) { |
230 | 91.4k | mi_params->mi_grid_base[mi_row * mi_params->mi_stride + mi_col] |
231 | 91.4k | ->ccso_blk_u = |
232 | 91.4k | mi_params |
233 | 91.4k | ->mi_grid_base[(mi_row & ~blk_size_y) * mi_params->mi_stride + |
234 | 91.4k | (mi_col & ~blk_size_x)] |
235 | 91.4k | ->ccso_blk_u; |
236 | 91.4k | } |
237 | | |
238 | 641k | if (!(mi_row & blk_size_y) && !(mi_col & blk_size_x) && |
239 | 81.1k | cm->ccso_info.ccso_enable[2]) { |
240 | 28.4k | const int log2_filter_unit_size = |
241 | 28.4k | (ccso_blk_size - xd->plane[2].subsampling_x); |
242 | 28.4k | const int ccso_nhfb = ((mi_params->mi_cols >> xd->plane[2].subsampling_x) + |
243 | 28.4k | (1 << log2_filter_unit_size >> 2) - 1) / |
244 | 28.4k | (1 << log2_filter_unit_size >> 2); |
245 | 28.4k | int sb_idx = |
246 | 28.4k | (mi_row / (blk_size_y + 1)) * ccso_nhfb + (mi_col / (blk_size_x + 1)); |
247 | | |
248 | 28.4k | if (!cm->ccso_info.sb_reuse_ccso[2]) { |
249 | 28.4k | const int ccso_ctx = av2_get_ccso_context(cm, xd, 2); |
250 | 28.4k | blk_idc = avm_read_symbol(r, xd->tile_ctx->ccso_cdf[2][ccso_ctx], 2, |
251 | 28.4k | ACCT_INFO("blk_idc")); |
252 | 28.4k | } else { |
253 | 3 | CcsoInfo *ref_frame_ccso_info = |
254 | 3 | &get_ref_frame_buf(cm, cm->ccso_info.ccso_ref_idx[2])->ccso_info; |
255 | 3 | blk_idc = ref_frame_ccso_info->sb_filter_control[2][sb_idx]; |
256 | 3 | } |
257 | 28.4k | xd->ccso_blk_v = blk_idc; |
258 | 28.4k | mi_params |
259 | 28.4k | ->mi_grid_base[(mi_row & ~blk_size_y) * mi_params->mi_stride + |
260 | 28.4k | (mi_col & ~blk_size_x)] |
261 | 28.4k | ->ccso_blk_v = blk_idc; |
262 | 28.4k | span_ccso(cm, xd, 2, blk_idc); |
263 | 613k | } else if (cm->ccso_info.ccso_enable[2] && |
264 | 147k | av2_check_ccso_mbmi_inside_tile(cm, xd, xd->mi[0])) { |
265 | 147k | mi_params->mi_grid_base[mi_row * mi_params->mi_stride + mi_col] |
266 | 147k | ->ccso_blk_v = |
267 | 147k | mi_params |
268 | 147k | ->mi_grid_base[(mi_row & ~blk_size_y) * mi_params->mi_stride + |
269 | 147k | (mi_col & ~blk_size_x)] |
270 | 147k | ->ccso_blk_v; |
271 | 147k | } |
272 | 641k | } |
273 | | |
274 | | static int read_delta_qindex(AV2_COMMON *cm, const MACROBLOCKD *xd, |
275 | 240k | avm_reader *r, MB_MODE_INFO *const mbmi) { |
276 | 240k | int sign, abs, reduced_delta_qindex = 0; |
277 | 240k | BLOCK_SIZE bsize = mbmi->sb_type[xd->tree_type == CHROMA_PART]; |
278 | 240k | const int b_col = xd->mi_col & (cm->mib_size - 1); |
279 | 240k | const int b_row = xd->mi_row & (cm->mib_size - 1); |
280 | 240k | const int read_delta_q_flag = (b_col == 0 && b_row == 0); |
281 | 240k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
282 | 240k | if ((bsize != cm->sb_size || |
283 | 43.4k | mbmi->skip_txfm[xd->tree_type == CHROMA_PART] == 0) && |
284 | 240k | read_delta_q_flag) { |
285 | 71.1k | abs = avm_read_symbol(r, ec_ctx->delta_q_cdf, DELTA_Q_PROBS + 1, |
286 | 71.1k | ACCT_INFO("abs")); |
287 | 71.1k | const int smallval = (abs < DELTA_Q_SMALL); |
288 | | |
289 | 71.1k | if (!smallval) { |
290 | 3.09k | const int rem_bits = avm_read_literal(r, 3, ACCT_INFO("rem_bits")) + 1; |
291 | 3.09k | const int thr = (1 << rem_bits) + DELTA_Q_SMALL_MINUS_2; |
292 | 3.09k | abs = avm_read_literal(r, rem_bits, ACCT_INFO("abs")) + thr; |
293 | 3.09k | } |
294 | | |
295 | 71.1k | if (abs) { |
296 | 35.3k | sign = avm_read_bit(r, ACCT_INFO("sign")); |
297 | 35.8k | } else { |
298 | 35.8k | sign = 1; |
299 | 35.8k | } |
300 | | |
301 | 71.1k | reduced_delta_qindex = sign ? -abs : abs; |
302 | 71.1k | } |
303 | 240k | return reduced_delta_qindex; |
304 | 240k | } |
305 | | |
306 | | static uint8_t read_mrl_index(FRAME_CONTEXT *ec_ctx, avm_reader *r, |
307 | | const MB_MODE_INFO *neighbor0, |
308 | 57.4k | const MB_MODE_INFO *neighbor1) { |
309 | 57.4k | int ctx = get_mrl_index_ctx(neighbor0, neighbor1); |
310 | 57.4k | avm_cdf_prob *mrl_cdf = ec_ctx->mrl_index_cdf[ctx]; |
311 | 57.4k | const uint8_t mrl_index = |
312 | 57.4k | avm_read_symbol(r, mrl_cdf, MRL_LINE_NUMBER, ACCT_INFO()); |
313 | 57.4k | return mrl_index; |
314 | 57.4k | } |
315 | | |
316 | | static bool read_multi_line_mrl(FRAME_CONTEXT *ec_ctx, avm_reader *r, |
317 | | const MB_MODE_INFO *neighbor0, |
318 | 8.99k | const MB_MODE_INFO *neighbor1) { |
319 | 8.99k | int multi_line_mrl_ctx = get_multi_line_mrl_index_ctx(neighbor0, neighbor1); |
320 | 8.99k | avm_cdf_prob *multi_line_mrl_cdf = |
321 | 8.99k | ec_ctx->multi_line_mrl_cdf[multi_line_mrl_ctx]; |
322 | 8.99k | const bool multi_line_mrl = |
323 | 8.99k | avm_read_symbol(r, multi_line_mrl_cdf, 2, ACCT_INFO()); |
324 | 8.99k | return multi_line_mrl; |
325 | 8.99k | } |
326 | | |
327 | | // read if dpcm lossless mode is used for luma |
328 | 47.2k | static uint8_t read_dpcm_mode(FRAME_CONTEXT *ec_ctx, avm_reader *r) { |
329 | 47.2k | const uint8_t dpcm_mode = |
330 | 47.2k | avm_read_symbol(r, ec_ctx->dpcm_cdf, 2, ACCT_INFO()); |
331 | 47.2k | return dpcm_mode; |
332 | 47.2k | } |
333 | | // read dpcm lossless direction for luma |
334 | 31.0k | static uint8_t read_dpcm_vert_horz_mode(FRAME_CONTEXT *ec_ctx, avm_reader *r) { |
335 | 31.0k | const uint8_t dpcm_vert_horz_mode = |
336 | 31.0k | avm_read_symbol(r, ec_ctx->dpcm_vert_horz_cdf, 2, ACCT_INFO()); |
337 | 31.0k | return dpcm_vert_horz_mode; |
338 | 31.0k | } |
339 | | // read if dpcm lossless mode is used for chroma |
340 | 5.71k | static uint8_t read_dpcm_uv_mode(FRAME_CONTEXT *ec_ctx, avm_reader *r) { |
341 | 5.71k | const uint8_t dpcm_uv_mode = |
342 | 5.71k | avm_read_symbol(r, ec_ctx->dpcm_uv_cdf, 2, ACCT_INFO()); |
343 | 5.71k | return dpcm_uv_mode; |
344 | 5.71k | } |
345 | | // read dpcm lossless direction for chroma |
346 | | static uint8_t read_dpcm_uv_vert_horz_mode(FRAME_CONTEXT *ec_ctx, |
347 | 2.92k | avm_reader *r) { |
348 | 2.92k | const uint8_t dpcm_uv_vert_horz_mode = |
349 | 2.92k | avm_read_symbol(r, ec_ctx->dpcm_uv_vert_horz_cdf, 2, ACCT_INFO()); |
350 | 2.92k | return dpcm_uv_vert_horz_mode; |
351 | 2.92k | } |
352 | | |
353 | 342k | static uint8_t read_fsc_mode(avm_reader *r, avm_cdf_prob *fsc_cdf) { |
354 | 342k | const uint8_t fsc_mode = avm_read_symbol(r, fsc_cdf, FSC_MODES, ACCT_INFO()); |
355 | 342k | return fsc_mode; |
356 | 342k | } |
357 | | |
358 | 84.5k | static uint8_t read_cfl_mhccp_switch(FRAME_CONTEXT *ec_ctx, avm_reader *r) { |
359 | 84.5k | uint8_t cfl_mhccp_index = avm_read_symbol(r, ec_ctx->cfl_mhccp_cdf, |
360 | 84.5k | CFL_MHCCP_SWITCH_NUM, ACCT_INFO()); |
361 | 84.5k | return cfl_mhccp_index; |
362 | 84.5k | } |
363 | | |
364 | 132k | static uint8_t read_cfl_index(FRAME_CONTEXT *ec_ctx, avm_reader *r) { |
365 | 132k | uint8_t cfl_index = avm_read_symbol(r, ec_ctx->cfl_index_cdf, |
366 | 132k | CFL_TYPE_COUNT - 1, ACCT_INFO()); |
367 | 132k | return cfl_index; |
368 | 132k | } |
369 | | |
370 | | // Read multi hypothesis cross component prediction filter direction |
371 | 109k | static uint8_t read_mh_dir(avm_cdf_prob *mh_dir_cdf, avm_reader *r) { |
372 | 109k | uint8_t mh_dir = avm_read_symbol(r, mh_dir_cdf, MHCCP_MODE_NUM, ACCT_INFO()); |
373 | 109k | return mh_dir; |
374 | 109k | } |
375 | | |
376 | | static uint8_t read_cfl_alphas(FRAME_CONTEXT *const ec_ctx, avm_reader *r, |
377 | 60.0k | int8_t *signs_out) { |
378 | 60.0k | const int8_t joint_sign = avm_read_symbol( |
379 | 60.0k | r, ec_ctx->cfl_sign_cdf, CFL_JOINT_SIGNS, ACCT_INFO("cfl:signs")); |
380 | 60.0k | uint8_t idx = 0; |
381 | | // Magnitudes are only coded for nonzero values |
382 | 60.0k | if (CFL_SIGN_U(joint_sign) != CFL_SIGN_ZERO) { |
383 | 51.4k | avm_cdf_prob *cdf_u = ec_ctx->cfl_alpha_cdf[CFL_CONTEXT_U(joint_sign)]; |
384 | 51.4k | idx = (uint8_t)avm_read_symbol(r, cdf_u, CFL_ALPHABET_SIZE, |
385 | 51.4k | ACCT_INFO("cfl:alpha_u")) |
386 | 51.4k | << CFL_ALPHABET_SIZE_LOG2; |
387 | 51.4k | } |
388 | 60.0k | if (CFL_SIGN_V(joint_sign) != CFL_SIGN_ZERO) { |
389 | 24.8k | avm_cdf_prob *cdf_v = ec_ctx->cfl_alpha_cdf[CFL_CONTEXT_V(joint_sign)]; |
390 | 24.8k | idx += (uint8_t)avm_read_symbol(r, cdf_v, CFL_ALPHABET_SIZE, |
391 | 24.8k | ACCT_INFO("cfl:alpha_v")); |
392 | 24.8k | } |
393 | 60.0k | *signs_out = joint_sign; |
394 | 60.0k | return idx; |
395 | 60.0k | } |
396 | | |
397 | | static INTERINTRA_MODE read_interintra_mode(MACROBLOCKD *xd, avm_reader *r, |
398 | 2 | int size_group) { |
399 | 2 | const INTERINTRA_MODE ii_mode = (INTERINTRA_MODE)avm_read_symbol( |
400 | 2 | r, xd->tile_ctx->interintra_mode_cdf[size_group], INTERINTRA_MODES, |
401 | 2 | ACCT_INFO()); |
402 | 2 | return ii_mode; |
403 | 2 | } |
404 | | |
405 | | static PREDICTION_MODE read_inter_mode(FRAME_CONTEXT *ec_ctx, avm_reader *r, |
406 | | int16_t ctx, const AV2_COMMON *const cm, |
407 | | const MACROBLOCKD *xd, |
408 | | const MB_MODE_INFO *mbmi, |
409 | 11 | BLOCK_SIZE bsize) { |
410 | 11 | if (is_tip_ref_frame(mbmi->ref_frame[0])) { |
411 | 0 | const int tip_pred_index = avm_read_symbol( |
412 | 0 | r, ec_ctx->tip_pred_mode_cdf, TIP_PRED_MODES, ACCT_INFO("tip_mode")); |
413 | 0 | return tip_pred_index_to_mode[tip_pred_index]; |
414 | 0 | } |
415 | | |
416 | 11 | if (is_warpmv_mode_allowed(cm, mbmi, bsize)) { |
417 | 11 | const int16_t iswarpmvmode_ctx = inter_warpmv_mode_ctx(cm, xd, mbmi); |
418 | 11 | const int is_warpmv_or_warp_newmv = |
419 | 11 | avm_read_symbol(r, ec_ctx->inter_warp_mode_cdf[iswarpmvmode_ctx], 2, |
420 | 11 | ACCT_INFO("is_warpmv_or_warp_newmv")); |
421 | 11 | if (is_warpmv_or_warp_newmv) { |
422 | 7 | if (is_warp_newmv_allowed(cm, xd, mbmi, bsize)) { |
423 | 7 | const int is_warpmv = avm_read_symbol( |
424 | 7 | r, ec_ctx->is_warpmv_or_warp_newmv_cdf, 2, ACCT_INFO("is_warpmv")); |
425 | 7 | return is_warpmv ? WARPMV : WARP_NEWMV; |
426 | 7 | } else { |
427 | 0 | return WARPMV; |
428 | 0 | } |
429 | 7 | } |
430 | 11 | } |
431 | | |
432 | 4 | const int16_t ismode_ctx = inter_single_mode_ctx(ctx); |
433 | 4 | return SINGLE_INTER_MODE_START + |
434 | 4 | avm_read_symbol(r, ec_ctx->inter_single_mode_cdf[ismode_ctx], |
435 | 11 | INTER_SINGLE_MODES, ACCT_INFO("inter_single_mode")); |
436 | 11 | } |
437 | | |
438 | | static void read_drl_idx(int max_drl_bits, const int16_t mode_ctx, |
439 | | FRAME_CONTEXT *ec_ctx, MB_MODE_INFO *mbmi, |
440 | 11 | avm_reader *r) { |
441 | 11 | mbmi->ref_mv_idx[0] = 0; |
442 | 11 | mbmi->ref_mv_idx[1] = 0; |
443 | | |
444 | 23 | for (int ref = 0; ref < 1 + has_second_drl(mbmi); ref++) { |
445 | 23 | for (int idx = 0; idx < max_drl_bits; ++idx) { |
446 | 19 | if (ref && !mbmi->skip_mode && mbmi->ref_frame[0] == mbmi->ref_frame[1] && |
447 | 1 | mbmi->mode == NEAR_NEARMV && idx <= mbmi->ref_mv_idx[0]) { |
448 | 0 | mbmi->ref_mv_idx[ref] = idx + 1; |
449 | 0 | continue; |
450 | 0 | } |
451 | 19 | avm_cdf_prob *drl_cdf = av2_get_drl_cdf(mbmi, ec_ctx, mode_ctx, idx); |
452 | 19 | int drl_idx = avm_read_symbol(r, drl_cdf, 2, ACCT_INFO("drl_idx")); |
453 | 19 | mbmi->ref_mv_idx[ref] = idx + drl_idx; |
454 | 19 | if (!drl_idx) break; |
455 | 19 | } |
456 | 12 | assert(mbmi->ref_mv_idx[ref] < max_drl_bits + 1); |
457 | 12 | } |
458 | 11 | if (!mbmi->skip_mode && mbmi->ref_frame[0] == mbmi->ref_frame[1] && |
459 | 2 | has_second_drl(mbmi) && mbmi->mode == NEAR_NEARMV && |
460 | 0 | mbmi->ref_mv_idx[0] < max_drl_bits) |
461 | 11 | assert(mbmi->ref_mv_idx[0] < mbmi->ref_mv_idx[1]); |
462 | 11 | } |
463 | | |
464 | | static int8_t read_wedge_mode(avm_reader *r, FRAME_CONTEXT *ec_ctx, |
465 | 0 | const BLOCK_SIZE bsize) { |
466 | 0 | (void)bsize; |
467 | 0 | int wedge_quad_dir = avm_read_symbol(r, ec_ctx->wedge_quad_cdf, WEDGE_QUADS, |
468 | 0 | ACCT_INFO("wedge_quad")); |
469 | 0 | int wedge_angle = WEDGE_ANGLES; |
470 | 0 | wedge_angle = QUAD_WEDGE_ANGLES * wedge_quad_dir + |
471 | 0 | avm_read_symbol(r, ec_ctx->wedge_angle_cdf[wedge_quad_dir], |
472 | 0 | QUAD_WEDGE_ANGLES, |
473 | 0 | ACCT_INFO("wedge_angle", "wedge_angle_cdf")); |
474 | 0 | int wedge_dist = 0; |
475 | 0 | if ((wedge_angle >= H_WEDGE_ANGLES) || |
476 | 0 | (wedge_angle == WEDGE_90 || wedge_angle == WEDGE_0)) { |
477 | 0 | wedge_dist = avm_read_symbol(r, ec_ctx->wedge_dist_cdf2, NUM_WEDGE_DIST - 1, |
478 | 0 | ACCT_INFO("wedge_dist", "wedge_dist_cdf2")) + |
479 | 0 | 1; |
480 | 0 | } else { |
481 | 0 | assert(wedge_angle < H_WEDGE_ANGLES); |
482 | 0 | wedge_dist = avm_read_symbol(r, ec_ctx->wedge_dist_cdf, NUM_WEDGE_DIST, |
483 | 0 | ACCT_INFO("wedge_dist", "wedge_dist_cdf")); |
484 | 0 | } |
485 | 0 | return wedge_angle_dist_2_index[wedge_angle][wedge_dist]; |
486 | 0 | } |
487 | | |
488 | | // read the reference index warp_ref_idx of WRL |
489 | | static void read_warp_ref_idx(FRAME_CONTEXT *ec_ctx, MB_MODE_INFO *mbmi, |
490 | 2 | avm_reader *r) { |
491 | 2 | if (mbmi->max_num_warp_candidates <= 1) { |
492 | 0 | mbmi->warp_ref_idx = 0; |
493 | 0 | return; |
494 | 0 | } |
495 | 2 | int max_idx_bits = mbmi->max_num_warp_candidates - 1; |
496 | 3 | for (int bit_idx = 0; bit_idx < max_idx_bits; ++bit_idx) { |
497 | 3 | avm_cdf_prob *warp_ref_idx_cdf = av2_get_warp_ref_idx_cdf(ec_ctx, bit_idx); |
498 | 3 | int warp_idx = |
499 | 3 | avm_read_symbol(r, warp_ref_idx_cdf, 2, ACCT_INFO("warp_idx")); |
500 | 3 | mbmi->warp_ref_idx = bit_idx + warp_idx; |
501 | 3 | if (!warp_idx) break; |
502 | 3 | } |
503 | 2 | } |
504 | | |
505 | | static void read_warpmv_with_mvd_flag(FRAME_CONTEXT *ec_ctx, MB_MODE_INFO *mbmi, |
506 | 2 | avm_reader *r) { |
507 | 2 | mbmi->warpmv_with_mvd_flag = |
508 | 2 | avm_read_symbol(r, ec_ctx->warpmv_with_mvd_flag_cdf, 2, |
509 | 2 | ACCT_INFO("warpmv_with_mvd_flag")); |
510 | 2 | } |
511 | | |
512 | | // Read the delta for a single warp parameter |
513 | | // The maximum index value is derived from the warp_precision_idx flag |
514 | | // if mbmi->warp_precision_idx == 0, max_coded_index is |
515 | | // (WARP_DELTA_NUMSYMBOLS_LOW - 1). Only one symbol with range 0, 1, |
516 | | // ......(WARP_DELTA_NUMSYMBOLS_LOW - 1) is decoded. if mbmi->warp_precision_idx |
517 | | // == 1, max_coded_index is 14; Two symbols are decoded. The first symbol cover |
518 | | // from 0, 1, ......(WARP_DELTA_NUMSYMBOLS_LOW - 2). (WARP_DELTA_NUMSYMBOLS_LOW |
519 | | // - 1) is considered as escape code and if the first symbol is equal to |
520 | | // (WARP_DELTA_NUMSYMBOLS_LOW - 1), then the second symbol is decoded to covers |
521 | | // rest of the indices. |
522 | | static int read_warp_delta_param(const MACROBLOCKD *xd, int index, |
523 | 0 | avm_reader *r, int max_coded_index) { |
524 | 0 | assert(2 <= index && index <= 5); |
525 | 0 | int index_type = (index == 2 || index == 5) ? 0 : 1; |
526 | |
|
527 | 0 | int coded_value = |
528 | 0 | avm_read_symbol(r, xd->tile_ctx->warp_delta_param_cdf[index_type], |
529 | 0 | WARP_DELTA_NUMSYMBOLS_LOW, ACCT_INFO()); |
530 | 0 | if (max_coded_index >= WARP_DELTA_NUMSYMBOLS_LOW && |
531 | 0 | coded_value >= (WARP_DELTA_NUMSYMBOLS_LOW - 1)) { |
532 | 0 | coded_value = |
533 | 0 | 7 + avm_read_symbol(r, |
534 | 0 | xd->tile_ctx->warp_delta_param_high_cdf[index_type], |
535 | 0 | WARP_DELTA_NUMSYMBOLS_HIGH, ACCT_INFO()); |
536 | 0 | } |
537 | |
|
538 | 0 | return coded_value; |
539 | 0 | } |
540 | | |
541 | | static void read_warp_delta(const AV2_COMMON *cm, const MACROBLOCKD *xd, |
542 | | MB_MODE_INFO *mbmi, avm_reader *r, |
543 | 2 | WARP_CANDIDATE *warp_param_stack) { |
544 | 2 | WarpedMotionParams *params = &mbmi->wm_params[0]; |
545 | 2 | int mi_row = xd->mi_row; |
546 | 2 | int mi_col = xd->mi_col; |
547 | 2 | const BLOCK_SIZE bsize = mbmi->sb_type[PLANE_TYPE_Y]; |
548 | | |
549 | | // Figure out what parameters to use as a base |
550 | 2 | WarpedMotionParams base_params; |
551 | 2 | int_mv center_mv; |
552 | 2 | av2_get_warp_base_params(cm, mbmi, &base_params, ¢er_mv, |
553 | 2 | warp_param_stack); |
554 | 2 | mbmi->six_param_warp_model_flag = 0; |
555 | | |
556 | | // TODO(rachelbarker): Allow signaling warp type? |
557 | 2 | if (allow_warp_parameter_signaling(cm, mbmi)) { |
558 | 0 | mbmi->six_param_warp_model_flag = get_default_six_param_flag(cm, mbmi); |
559 | |
|
560 | 0 | mbmi->warp_precision_idx = |
561 | 0 | avm_read_symbol(r, xd->tile_ctx->warp_precision_idx_cdf[bsize], |
562 | 0 | NUM_WARP_PRECISION_MODES, ACCT_INFO()); |
563 | |
|
564 | 0 | params->wmtype = mbmi->six_param_warp_model_flag ? AFFINE : ROTZOOM; |
565 | |
|
566 | 0 | int step_size = 0; |
567 | 0 | int max_coded_index = 0; |
568 | 0 | get_warp_model_steps(mbmi, &step_size, &max_coded_index); |
569 | 0 | int32_t decoded_delta_param[6] = { 0, 0, 0, 0, 0, 0 }; |
570 | |
|
571 | 0 | for (uint8_t index = 2; index < (mbmi->six_param_warp_model_flag ? 6 : 4); |
572 | 0 | index++) { |
573 | 0 | int coded_value = read_warp_delta_param(xd, index, r, max_coded_index); |
574 | |
|
575 | 0 | decoded_delta_param[index] = coded_value; |
576 | | // decode sign |
577 | 0 | if (coded_value) { |
578 | 0 | int sign = avm_read_symbol(r, xd->tile_ctx->warp_param_sign_cdf, 2, |
579 | 0 | ACCT_INFO()); |
580 | 0 | decoded_delta_param[index] = sign ? -coded_value : coded_value; |
581 | 0 | } |
582 | 0 | } |
583 | |
|
584 | 0 | params->wmmat[2] = |
585 | 0 | base_params.wmmat[2] + decoded_delta_param[2] * step_size; |
586 | 0 | params->wmmat[3] = |
587 | 0 | base_params.wmmat[3] + decoded_delta_param[3] * step_size; |
588 | 0 | if (mbmi->six_param_warp_model_flag) { |
589 | 0 | params->wmmat[4] = |
590 | 0 | base_params.wmmat[4] + decoded_delta_param[4] * step_size; |
591 | 0 | params->wmmat[5] = |
592 | 0 | base_params.wmmat[5] + decoded_delta_param[5] * step_size; |
593 | 0 | } else { |
594 | 0 | params->wmmat[4] = -params->wmmat[3]; |
595 | 0 | params->wmmat[5] = params->wmmat[2]; |
596 | 0 | } |
597 | 2 | } else { |
598 | 2 | *params = base_params; |
599 | 2 | assert(mbmi->six_param_warp_model_flag == 0); |
600 | 2 | } |
601 | | |
602 | 2 | av2_reduce_warp_model(params); |
603 | 2 | av2_get_shear_params(params, |
604 | 2 | get_ref_scale_factors_const(cm, mbmi->ref_frame[0])); |
605 | 2 | params->invalid = 0; |
606 | 2 | av2_set_warp_translation(mi_row, mi_col, bsize, center_mv.as_mv, params); |
607 | 2 | assign_warpmv(cm, xd->submi, bsize, params, mi_row, mi_col, 0); |
608 | 2 | } |
609 | | |
610 | | static MOTION_MODE read_motion_mode(AV2_COMMON *cm, MACROBLOCKD *xd, |
611 | 13 | MB_MODE_INFO *mbmi, avm_reader *r) { |
612 | 13 | const BLOCK_SIZE bsize = mbmi->sb_type[PLANE_TYPE_Y]; |
613 | 13 | mbmi->max_num_warp_candidates = 0; |
614 | 13 | mbmi->six_param_warp_model_flag = 0; |
615 | | |
616 | 13 | mbmi->warp_precision_idx = 0; |
617 | | |
618 | 13 | const int allowed_motion_modes = |
619 | 13 | motion_mode_allowed(cm, xd, xd->ref_mv_stack[mbmi->ref_frame[0]], mbmi); |
620 | | |
621 | 13 | if (mbmi->mode == WARPMV) { |
622 | 2 | return WARP_DELTA; |
623 | 2 | } |
624 | | |
625 | 11 | if (is_warp_newmv_allowed(cm, xd, mbmi, bsize) && mbmi->mode == WARP_NEWMV) { |
626 | 5 | if (!((allowed_motion_modes & (1 << WARP_CAUSAL)) || |
627 | 0 | (allowed_motion_modes & (1 << WARP_DELTA)))) |
628 | 0 | return WARP_EXTEND; |
629 | | |
630 | 5 | if (allowed_motion_modes & (1 << WARP_EXTEND)) { |
631 | 5 | const int ctx = av2_get_warp_extend_ctx(xd); |
632 | 5 | const int use_warp_extend = |
633 | 5 | avm_read_symbol(r, xd->tile_ctx->warp_extend_cdf[ctx], 2, |
634 | 5 | ACCT_INFO("use_warp_extend")); |
635 | 5 | if (use_warp_extend) { |
636 | 2 | return WARP_EXTEND; |
637 | 2 | } |
638 | 5 | } |
639 | | |
640 | 3 | if (!(allowed_motion_modes & (1 << WARP_DELTA))) return WARP_CAUSAL; |
641 | | |
642 | 3 | if (allowed_motion_modes & (1 << WARP_CAUSAL)) { |
643 | 3 | const int ctx = av2_get_warp_causal_ctx(xd); |
644 | 3 | const int use_warp_causal = |
645 | 3 | avm_read_symbol(r, xd->tile_ctx->warp_causal_cdf[ctx], 2, |
646 | 3 | ACCT_INFO("use_warp_causal")); |
647 | 3 | if (use_warp_causal) { |
648 | 3 | return WARP_CAUSAL; |
649 | 3 | } |
650 | 3 | } |
651 | | |
652 | 0 | return WARP_DELTA; |
653 | 3 | } |
654 | | |
655 | 6 | mbmi->use_wedge_interintra = 0; |
656 | 6 | if (allowed_motion_modes & (1 << INTERINTRA)) { |
657 | 4 | const int bsize_group = size_group_lookup[bsize]; |
658 | 4 | const int use_interintra = |
659 | 4 | avm_read_symbol(r, xd->tile_ctx->interintra_cdf[bsize_group], 2, |
660 | 4 | ACCT_INFO("use_interintra")); |
661 | 4 | assert(mbmi->ref_frame[1] == NONE_FRAME); |
662 | 4 | if (use_interintra) { |
663 | 2 | const INTERINTRA_MODE interintra_mode = |
664 | 2 | read_interintra_mode(xd, r, bsize_group); |
665 | | |
666 | 2 | mbmi->interintra_mode = interintra_mode; |
667 | 2 | mbmi->angle_delta[PLANE_TYPE_Y] = 0; |
668 | 2 | mbmi->angle_delta[PLANE_TYPE_UV] = 0; |
669 | 2 | mbmi->use_dpcm_y = 0; |
670 | 2 | mbmi->dpcm_mode_y = 0; |
671 | 2 | mbmi->use_dpcm_uv = 0; |
672 | 2 | mbmi->dpcm_mode_uv = 0; |
673 | 2 | mbmi->use_intra_dip = 0; |
674 | 2 | if (av2_is_wedge_used(bsize)) { |
675 | 2 | mbmi->use_wedge_interintra = |
676 | 2 | avm_read_symbol(r, xd->tile_ctx->wedge_interintra_cdf, 2, |
677 | 2 | ACCT_INFO("use_wedge_interintra")); |
678 | 2 | if (mbmi->use_wedge_interintra) { |
679 | 0 | mbmi->interintra_wedge_index = |
680 | 0 | read_wedge_mode(r, xd->tile_ctx, bsize); |
681 | 0 | assert(mbmi->interintra_wedge_index != -1); |
682 | 0 | mbmi->wedge_boundary_index = get_wedge_boundary_type(bsize); |
683 | 0 | } |
684 | 2 | } |
685 | 2 | return INTERINTRA; |
686 | 2 | } |
687 | 4 | } |
688 | | |
689 | 4 | if (allowed_motion_modes & (1 << WARP_CAUSAL)) { |
690 | 0 | const int ctx = av2_get_warp_causal_ctx(xd); |
691 | 0 | const int use_warp_causal = avm_read_symbol( |
692 | 0 | r, xd->tile_ctx->warp_causal_cdf[ctx], 2, ACCT_INFO("use_warp_causal")); |
693 | 0 | if (use_warp_causal) { |
694 | 0 | return WARP_CAUSAL; |
695 | 0 | } |
696 | 0 | } |
697 | | |
698 | 4 | return SIMPLE_TRANSLATION; |
699 | 4 | } |
700 | | |
701 | | // Read scale mode flag for joint mvd coding mode |
702 | | static PREDICTION_MODE read_jmvd_scale_mode(MACROBLOCKD *xd, avm_reader *r, |
703 | 13 | MB_MODE_INFO *const mbmi) { |
704 | 13 | if (!is_joint_mvd_coding_mode(mbmi->mode)) return 0; |
705 | 0 | const int is_joint_amvd_mode = |
706 | 0 | is_joint_amvd_coding_mode(mbmi->mode, mbmi->use_amvd); |
707 | 0 | avm_cdf_prob *jmvd_scale_mode_cdf = |
708 | 0 | is_joint_amvd_mode ? xd->tile_ctx->jmvd_amvd_scale_mode_cdf |
709 | 0 | : xd->tile_ctx->jmvd_scale_mode_cdf; |
710 | 0 | const int jmvd_scale_cnt = is_joint_amvd_mode ? JOINT_AMVD_SCALE_FACTOR_CNT |
711 | 0 | : JOINT_NEWMV_SCALE_FACTOR_CNT; |
712 | 0 | const int jmvd_scale_mode = avm_read_symbol( |
713 | 0 | r, jmvd_scale_mode_cdf, jmvd_scale_cnt, ACCT_INFO("jmvd_scale_mode")); |
714 | 0 | return jmvd_scale_mode; |
715 | 13 | } |
716 | | |
717 | | // Read index for the weighting factor of compound weighted prediction |
718 | | static int read_cwp_idx(MACROBLOCKD *xd, avm_reader *r, const AV2_COMMON *cm, |
719 | 0 | MB_MODE_INFO *const mbmi) { |
720 | 0 | int8_t cwp_idx = 0; |
721 | 0 | int bit_cnt = 0; |
722 | 0 | const int ctx = 0; |
723 | 0 | for (int idx = 0; idx < MAX_CWP_NUM - 1; ++idx) { |
724 | 0 | const int tmp_idx = avm_read_symbol( |
725 | 0 | r, xd->tile_ctx->cwp_idx_cdf[ctx][bit_cnt], 2, ACCT_INFO()); |
726 | 0 | cwp_idx = idx + tmp_idx; |
727 | 0 | if (!tmp_idx) break; |
728 | 0 | ++bit_cnt; |
729 | 0 | } |
730 | 0 | assert(cwp_idx <= CWP_MAX); |
731 | | |
732 | | // convert index to weight |
733 | 0 | return get_cwp_coding_idx(cwp_idx, 0, cm, mbmi); |
734 | 0 | } |
735 | | |
736 | | static PREDICTION_MODE read_inter_compound_mode(MACROBLOCKD *xd, avm_reader *r, |
737 | | const AV2_COMMON *cm, |
738 | | MB_MODE_INFO *const mbmi, |
739 | 2 | int16_t ctx) { |
740 | 2 | int mode = 0; |
741 | 2 | int use_optical_flow = 0; |
742 | 2 | if (is_new_nearmv_pred_mode_disallowed(mbmi)) { |
743 | 2 | const int signal_mode_idx = |
744 | 2 | avm_read_symbol(r, xd->tile_ctx->inter_compound_mode_same_refs_cdf[ctx], |
745 | 2 | INTER_COMPOUND_SAME_REFS_TYPES, |
746 | 2 | ACCT_INFO("inter_compound_mode_same_refs_cdf")); |
747 | 2 | mode = comp_mode_signal_idx_to_mode_idx[signal_mode_idx]; |
748 | 2 | } else { |
749 | 0 | const int is_joint = avm_read_symbol( |
750 | 0 | r, |
751 | 0 | xd->tile_ctx->inter_compound_mode_is_joint_cdf |
752 | 0 | [get_inter_compound_mode_is_joint_context(cm, mbmi)], |
753 | 0 | NUM_OPTIONS_IS_JOINT, ACCT_INFO("inter_compound_mode_is_joint_cdf")); |
754 | 0 | if (is_joint) { |
755 | 0 | mode = INTER_COMPOUND_OFFSET(JOINT_NEWMV); |
756 | 0 | } else { |
757 | 0 | mode = avm_read_symbol( |
758 | 0 | r, xd->tile_ctx->inter_compound_mode_non_joint_type_cdf[ctx], |
759 | 0 | NUM_OPTIONS_NON_JOINT_TYPE, |
760 | 0 | ACCT_INFO("inter_compound_mode_non_joint_type_cdf")); |
761 | 0 | } |
762 | 0 | } |
763 | | |
764 | 2 | if (cm->features.opfl_refine_type == REFINE_SWITCHABLE && |
765 | 0 | opfl_allowed_cur_refs_bsize(cm, xd, mbmi)) { |
766 | 0 | const int allow_translational_refinement = |
767 | 0 | is_translational_refinement_allowed( |
768 | 0 | cm, mbmi->sb_type[xd->tree_type == CHROMA_PART], xd, |
769 | |
|
770 | 0 | comp_idx_to_opfl_mode[mode]); |
771 | 0 | if (allow_translational_refinement) { |
772 | 0 | const int opfl_ctx = get_optflow_context(comp_idx_to_opfl_mode[mode]); |
773 | 0 | use_optical_flow = |
774 | 0 | avm_read_symbol(r, xd->tile_ctx->use_optflow_cdf[opfl_ctx], 2, |
775 | 0 | ACCT_INFO("use_optical_flow")); |
776 | 0 | } |
777 | 0 | if (use_optical_flow) { |
778 | 0 | assert(is_inter_compound_mode(comp_idx_to_opfl_mode[mode])); |
779 | 0 | return comp_idx_to_opfl_mode[mode]; |
780 | 0 | } |
781 | 0 | } |
782 | | |
783 | 2 | assert(is_inter_compound_mode(NEAR_NEARMV + mode)); |
784 | 2 | return NEAR_NEARMV + mode; |
785 | 2 | } |
786 | | |
787 | 87.8k | int av2_neg_deinterleave(int diff, int ref, int max) { |
788 | 87.8k | if (!ref) return diff; |
789 | 73.9k | if (ref >= (max - 1)) return max - diff - 1; |
790 | 70.9k | if (2 * ref < max) { |
791 | 41.5k | if (diff <= 2 * ref) { |
792 | 36.3k | if (diff & 1) |
793 | 4.59k | return ref + ((diff + 1) >> 1); |
794 | 31.7k | else |
795 | 31.7k | return ref - (diff >> 1); |
796 | 36.3k | } |
797 | 5.15k | return diff; |
798 | 41.5k | } else { |
799 | 29.3k | if (diff <= 2 * (max - ref - 1)) { |
800 | 26.8k | if (diff & 1) |
801 | 3.65k | return ref + ((diff + 1) >> 1); |
802 | 23.2k | else |
803 | 23.2k | return ref - (diff >> 1); |
804 | 26.8k | } |
805 | 2.47k | return max - (diff + 1); |
806 | 29.3k | } |
807 | 70.9k | } |
808 | | |
809 | | static int read_segment_id(AV2_COMMON *const cm, const MACROBLOCKD *const xd, |
810 | 89.2k | avm_reader *r, int skip) { |
811 | 89.2k | int cdf_num; |
812 | 89.2k | const int pred = av2_get_spatial_seg_pred(cm, xd, &cdf_num, 0); |
813 | 89.2k | if (skip && !cm->features.has_lossless_segment) return pred; |
814 | | |
815 | 87.8k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
816 | 87.8k | struct segmentation *const seg = &cm->seg; |
817 | 87.8k | struct segmentation_probs *const segp = &ec_ctx->seg; |
818 | | |
819 | 87.8k | avm_cdf_prob *pred_cdf = NULL; |
820 | 87.8k | uint8_t seg_id_ext_flag = 0; |
821 | | |
822 | 87.8k | if (seg->enable_ext_seg == 1) { |
823 | 7.67k | avm_cdf_prob *seg_id_ext_flag_cdf = segp->seg_id_ext_flag_cdf[cdf_num]; |
824 | 7.67k | seg_id_ext_flag = avm_read_symbol(r, seg_id_ext_flag_cdf, 2, |
825 | 7.67k | ACCT_INFO("seg_id_ext_flag")); |
826 | | |
827 | 7.67k | if (seg_id_ext_flag == 0) { |
828 | 3.27k | pred_cdf = segp->spatial_pred_seg_cdf[cdf_num]; |
829 | 4.39k | } else { |
830 | 4.39k | pred_cdf = segp->spatial_pred_seg_cdf1[cdf_num]; |
831 | 4.39k | } |
832 | 80.1k | } else { |
833 | 80.1k | pred_cdf = segp->spatial_pred_seg_cdf[cdf_num]; |
834 | 80.1k | } |
835 | | |
836 | 87.8k | int coded_id = |
837 | 87.8k | avm_read_symbol(r, pred_cdf, MAX_SEGMENTS_8, ACCT_INFO("coded_id")); |
838 | 87.8k | coded_id += seg_id_ext_flag ? MAX_SEGMENTS_8 : 0; |
839 | | |
840 | 87.8k | const int segment_id = |
841 | 87.8k | av2_neg_deinterleave(coded_id, pred, seg->last_active_segid + 1); |
842 | | |
843 | 87.8k | if (segment_id < 0 || segment_id > seg->last_active_segid) { |
844 | 63 | avm_internal_error(xd->error_info, AVM_CODEC_CORRUPT_FRAME, |
845 | 63 | "Corrupted segment_ids"); |
846 | 63 | } |
847 | 87.8k | return segment_id; |
848 | 89.2k | } |
849 | | |
850 | | static int dec_get_segment_id(const AV2_COMMON *cm, const uint8_t *segment_ids, |
851 | | int mi_offset, int x_inside_boundary, |
852 | 0 | int y_inside_boundary) { |
853 | 0 | int segment_id = INT_MAX; |
854 | |
|
855 | 0 | for (int y = 0; y < y_inside_boundary; y++) |
856 | 0 | for (int x = 0; x < x_inside_boundary; x++) |
857 | 0 | segment_id = AVMMIN( |
858 | 0 | segment_id, segment_ids[mi_offset + y * cm->mi_params.mi_cols + x]); |
859 | |
|
860 | 0 | assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
861 | 0 | return segment_id; |
862 | 0 | } |
863 | | |
864 | | static void set_segment_id(AV2_COMMON *cm, int mi_offset, int x_inside_boundary, |
865 | 89.1k | int y_inside_boundary, int segment_id) { |
866 | 89.1k | assert(segment_id >= 0 && segment_id < MAX_SEGMENTS); |
867 | | |
868 | 687k | for (int y = 0; y < y_inside_boundary; y++) |
869 | 7.93M | for (int x = 0; x < x_inside_boundary; x++) |
870 | 7.33M | cm->cur_frame->seg_map[mi_offset + y * cm->mi_params.mi_cols + x] = |
871 | 7.33M | segment_id; |
872 | 89.1k | } |
873 | | |
874 | | static int read_intra_segment_id(AV2_COMMON *const cm, |
875 | | const MACROBLOCKD *const xd, BLOCK_SIZE bsize, |
876 | 710k | avm_reader *r, int skip) { |
877 | 710k | struct segmentation *const seg = &cm->seg; |
878 | 710k | if (!seg->enabled) return 0; // Default for disabled segmentation |
879 | 89.1k | if (frame_is_intra_only(cm)) assert(seg->update_map && !seg->temporal_update); |
880 | | |
881 | 89.1k | const CommonModeInfoParams *const mi_params = &cm->mi_params; |
882 | 89.1k | const int mi_row = xd->mi_row; |
883 | 89.1k | const int mi_col = xd->mi_col; |
884 | 89.1k | const int mi_offset = mi_row * mi_params->mi_cols + mi_col; |
885 | 89.1k | const int bw = mi_size_wide[bsize]; |
886 | 89.1k | const int bh = mi_size_high[bsize]; |
887 | 89.1k | const int x_inside_boundary = AVMMIN(mi_params->mi_cols - mi_col, bw); |
888 | 89.1k | const int y_inside_boundary = AVMMIN(mi_params->mi_rows - mi_row, bh); |
889 | 89.1k | const int segment_id = read_segment_id(cm, xd, r, skip); |
890 | 89.1k | set_segment_id(cm, mi_offset, x_inside_boundary, y_inside_boundary, |
891 | 89.1k | segment_id); |
892 | 89.1k | return segment_id; |
893 | 710k | } |
894 | | |
895 | | static void copy_segment_id(const CommonModeInfoParams *const mi_params, |
896 | | const uint8_t *last_segment_ids, |
897 | | uint8_t *current_segment_ids, int mi_offset, |
898 | 0 | int x_inside_boundary, int y_inside_boundary) { |
899 | 0 | for (int y = 0; y < y_inside_boundary; y++) |
900 | 0 | for (int x = 0; x < x_inside_boundary; x++) |
901 | 0 | current_segment_ids[mi_offset + y * mi_params->mi_cols + x] = |
902 | 0 | last_segment_ids |
903 | 0 | ? last_segment_ids[mi_offset + y * mi_params->mi_cols + x] |
904 | 0 | : 0; |
905 | 0 | } |
906 | | |
907 | | static int get_predicted_segment_id(AV2_COMMON *const cm, int mi_offset, |
908 | | int x_inside_boundary, |
909 | 0 | int y_inside_boundary) { |
910 | 0 | return cm->last_frame_seg_map |
911 | 0 | ? dec_get_segment_id(cm, cm->last_frame_seg_map, mi_offset, |
912 | 0 | x_inside_boundary, y_inside_boundary) |
913 | 0 | : 0; |
914 | 0 | } |
915 | | |
916 | | static int read_inter_segment_id(AV2_COMMON *const cm, MACROBLOCKD *const xd, |
917 | 26 | int preskip, avm_reader *r) { |
918 | 26 | struct segmentation *const seg = &cm->seg; |
919 | 26 | const CommonModeInfoParams *const mi_params = &cm->mi_params; |
920 | 26 | MB_MODE_INFO *const mbmi = xd->mi[0]; |
921 | 26 | const int mi_row = xd->mi_row; |
922 | 26 | const int mi_col = xd->mi_col; |
923 | 26 | const int mi_offset = mi_row * mi_params->mi_cols + mi_col; |
924 | 26 | const int bw = mi_size_wide[mbmi->sb_type[PLANE_TYPE_Y]]; |
925 | 26 | const int bh = mi_size_high[mbmi->sb_type[PLANE_TYPE_Y]]; |
926 | | |
927 | | // TODO(slavarnway): move x_inside_boundary, y_inside_boundary into xd ????? |
928 | 26 | const int x_inside_boundary = AVMMIN(mi_params->mi_cols - mi_col, bw); |
929 | 26 | const int y_inside_boundary = AVMMIN(mi_params->mi_rows - mi_row, bh); |
930 | | |
931 | 26 | if (!seg->enabled) return 0; // Default for disabled segmentation |
932 | | |
933 | 4 | if (!seg->update_map) { |
934 | 0 | copy_segment_id(mi_params, cm->last_frame_seg_map, cm->cur_frame->seg_map, |
935 | 0 | mi_offset, x_inside_boundary, y_inside_boundary); |
936 | 0 | return get_predicted_segment_id(cm, mi_offset, x_inside_boundary, |
937 | 0 | y_inside_boundary); |
938 | 0 | } |
939 | | |
940 | 4 | int segment_id; |
941 | 4 | if (preskip) { |
942 | 2 | if (!seg->segid_preskip) return 0; |
943 | 2 | } else { |
944 | 2 | if (mbmi->skip_txfm[xd->tree_type == CHROMA_PART]) { |
945 | 0 | if (seg->temporal_update) { |
946 | 0 | mbmi->seg_id_predicted = 0; |
947 | 0 | } |
948 | 0 | segment_id = read_segment_id(cm, xd, r, 1); |
949 | 0 | set_segment_id(cm, mi_offset, x_inside_boundary, y_inside_boundary, |
950 | 0 | segment_id); |
951 | 0 | return segment_id; |
952 | 0 | } |
953 | 2 | } |
954 | | |
955 | 2 | if (seg->temporal_update) { |
956 | 0 | const int ctx = av2_get_pred_context_seg_id(xd); |
957 | 0 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
958 | 0 | struct segmentation_probs *const segp = &ec_ctx->seg; |
959 | 0 | avm_cdf_prob *pred_cdf = segp->pred_cdf[ctx]; |
960 | 0 | mbmi->seg_id_predicted = |
961 | 0 | avm_read_symbol(r, pred_cdf, 2, ACCT_INFO("seg_id_predicted")); |
962 | 0 | if (mbmi->seg_id_predicted) { |
963 | 0 | segment_id = get_predicted_segment_id(cm, mi_offset, x_inside_boundary, |
964 | 0 | y_inside_boundary); |
965 | 0 | } else { |
966 | 0 | segment_id = read_segment_id(cm, xd, r, 0); |
967 | 0 | } |
968 | 2 | } else { |
969 | 2 | segment_id = read_segment_id(cm, xd, r, 0); |
970 | 2 | } |
971 | 2 | set_segment_id(cm, mi_offset, x_inside_boundary, y_inside_boundary, |
972 | 2 | segment_id); |
973 | 2 | return segment_id; |
974 | 4 | } |
975 | | |
976 | | static int read_skip_mode(AV2_COMMON *cm, const MACROBLOCKD *xd, |
977 | 13 | avm_reader *r) { |
978 | 13 | if (!is_skip_mode_allowed(cm, xd)) return 0; |
979 | | |
980 | 0 | const int ctx = av2_get_skip_mode_context(xd); |
981 | 0 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
982 | 0 | const int skip_mode = avm_read_symbol(r, ec_ctx->skip_mode_cdfs[ctx], 2, |
983 | 0 | ACCT_INFO("skip_mode")); |
984 | 0 | return skip_mode; |
985 | 13 | } |
986 | | |
987 | | static int read_skip_txfm(AV2_COMMON *cm, const MACROBLOCKD *xd, int segment_id, |
988 | 59.9k | avm_reader *r) { |
989 | 59.9k | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) { |
990 | 0 | return 1; |
991 | 59.9k | } else { |
992 | 59.9k | const int ctx = av2_get_skip_txfm_context(xd); |
993 | 59.9k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
994 | 59.9k | const int skip_txfm = avm_read_symbol(r, ec_ctx->skip_txfm_cdfs[ctx], 2, |
995 | 59.9k | ACCT_INFO("skip_txfm")); |
996 | 59.9k | return skip_txfm; |
997 | 59.9k | } |
998 | 59.9k | } |
999 | | |
1000 | | static void read_palette_colors_y(MACROBLOCKD *const xd, int bit_depth, |
1001 | 11.6k | PALETTE_MODE_INFO *const pmi, avm_reader *r) { |
1002 | 11.6k | uint16_t color_cache[2 * PALETTE_MAX_SIZE]; |
1003 | 11.6k | const int n_cache = av2_get_palette_cache(xd, 0, color_cache); |
1004 | 11.6k | const int n = pmi->palette_size[0]; |
1005 | 11.6k | int idx = 0; |
1006 | 29.4k | for (int i = 0; i < n_cache && idx < n; ++i) { |
1007 | 17.7k | if (avm_read_bit(r, ACCT_INFO("color_cache"))) |
1008 | 9.05k | pmi->palette_colors[idx++] = color_cache[i]; |
1009 | 17.7k | } |
1010 | 11.6k | if (idx < n) { |
1011 | 10.2k | pmi->palette_colors[idx++] = |
1012 | 10.2k | avm_read_literal(r, bit_depth, ACCT_INFO("palette_colors")); |
1013 | 10.2k | if (idx < n) { |
1014 | 9.28k | const int min_bits = bit_depth - 3; |
1015 | 9.28k | int bits = min_bits + avm_read_literal(r, 2, ACCT_INFO("bits")); |
1016 | 9.28k | int range = (1 << bit_depth) - pmi->palette_colors[idx - 1] - 1; |
1017 | 36.9k | for (; idx < n; ++idx) { |
1018 | 27.6k | assert(range >= 0); |
1019 | 27.6k | const int delta = avm_read_literal(r, bits, ACCT_INFO("delta")) + 1; |
1020 | 27.6k | pmi->palette_colors[idx] = clamp(pmi->palette_colors[idx - 1] + delta, |
1021 | 27.6k | 0, (1 << bit_depth) - 1); |
1022 | 27.6k | range -= (pmi->palette_colors[idx] - pmi->palette_colors[idx - 1]); |
1023 | 27.6k | bits = AVMMIN(bits, avm_ceil_log2(range)); |
1024 | 27.6k | } |
1025 | 9.28k | } |
1026 | 10.2k | } |
1027 | | // Sort Y palette |
1028 | 58.6k | for (int i = 0; i < n; i++) { |
1029 | 139k | for (int j = 1; j < n - i; j++) { |
1030 | 92.9k | if (pmi->palette_colors[j - 1] > pmi->palette_colors[j]) { |
1031 | 6.73k | const uint16_t tmp = pmi->palette_colors[j - 1]; |
1032 | 6.73k | pmi->palette_colors[j - 1] = pmi->palette_colors[j]; |
1033 | 6.73k | pmi->palette_colors[j] = tmp; |
1034 | 6.73k | } |
1035 | 92.9k | } |
1036 | 46.9k | } |
1037 | 11.6k | } |
1038 | | |
1039 | | static void read_palette_mode_info(AV2_COMMON *const cm, MACROBLOCKD *const xd, |
1040 | 584k | avm_reader *r) { |
1041 | 584k | MB_MODE_INFO *const mbmi = xd->mi[0]; |
1042 | 584k | const BLOCK_SIZE bsize = mbmi->sb_type[xd->tree_type == CHROMA_PART]; |
1043 | 584k | assert(av2_allow_palette(PLANE_TYPE_Y, |
1044 | 584k | cm->features.allow_screen_content_tools, bsize)); |
1045 | 584k | (void)bsize; |
1046 | 584k | PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info; |
1047 | 584k | if (mbmi->mode == DC_PRED && xd->tree_type != CHROMA_PART) { |
1048 | 161k | const int modev = avm_read_symbol(r, xd->tile_ctx->palette_y_mode_cdf, 2, |
1049 | 161k | ACCT_INFO("modev", "luma")); |
1050 | 161k | if (modev) { |
1051 | 11.7k | pmi->palette_size[0] = |
1052 | 11.7k | avm_read_symbol(r, xd->tile_ctx->palette_y_size_cdf, PALETTE_SIZES, |
1053 | 11.7k | ACCT_INFO("palette_size", "luma")) + |
1054 | 11.7k | 2; |
1055 | 11.7k | read_palette_colors_y(xd, cm->seq_params.bit_depth, pmi, r); |
1056 | 11.7k | } |
1057 | 161k | } |
1058 | 584k | } |
1059 | | |
1060 | | static void read_intra_dip_mode_info(const AV2_COMMON *const cm, |
1061 | 649k | MACROBLOCKD *const xd, avm_reader *r) { |
1062 | 649k | MB_MODE_INFO *const mbmi = xd->mi[0]; |
1063 | 649k | mbmi->use_intra_dip = 0; |
1064 | 649k | mbmi->intra_dip_mode = 0; |
1065 | 649k | if (av2_intra_dip_allowed(cm, mbmi) && xd->tree_type != CHROMA_PART) { |
1066 | 23.6k | BLOCK_SIZE bsize = mbmi->sb_type[xd->tree_type == CHROMA_PART]; |
1067 | 23.6k | int ctx = get_intra_dip_ctx(xd->neighbors[0], xd->neighbors[1], bsize); |
1068 | 23.6k | avm_cdf_prob *cdf = xd->tile_ctx->intra_dip_cdf[ctx]; |
1069 | 23.6k | mbmi->use_intra_dip = |
1070 | 23.6k | avm_read_symbol(r, cdf, 2, ACCT_INFO("use_intra_dip")); |
1071 | 23.6k | if (mbmi->use_intra_dip) { |
1072 | | // Read transpose bit + modes bits |
1073 | 15.5k | int has_transpose = av2_intra_dip_has_transpose(bsize); |
1074 | 15.5k | int transpose = |
1075 | 15.5k | has_transpose && |
1076 | 15.5k | avm_read_literal(r, 1, ACCT_INFO("intra_dip_mode_transpose")); |
1077 | 15.5k | mbmi->intra_dip_mode += transpose << 4; |
1078 | 15.5k | int n_modes = av2_intra_dip_modes(bsize); |
1079 | 15.5k | avm_cdf_prob *mode_cdf = xd->tile_ctx->intra_dip_mode_n6_cdf; |
1080 | 15.5k | mbmi->intra_dip_mode += |
1081 | 15.5k | avm_read_symbol(r, mode_cdf, n_modes, ACCT_INFO("intra_dip_mode_n6")); |
1082 | 15.5k | } |
1083 | 23.6k | } |
1084 | 649k | } |
1085 | | |
1086 | | void av2_read_tx_type(const AV2_COMMON *const cm, MACROBLOCKD *xd, int blk_row, |
1087 | | int blk_col, TX_SIZE tx_size, avm_reader *r, |
1088 | 2.15M | const int plane, const int eob, const int dc_skip) { |
1089 | 2.15M | if (plane != PLANE_TYPE_Y) return; |
1090 | 1.77M | MB_MODE_INFO *mbmi = xd->mi[0]; |
1091 | 1.77M | TX_TYPE *tx_type = |
1092 | 1.77M | &xd->tx_type_map[blk_row * xd->tx_type_map_stride + blk_col]; |
1093 | 1.77M | *tx_type = MAKE_TX_TYPE_FROM_PRIMARY_TX_TYPE(DCT_DCT); |
1094 | | |
1095 | 1.77M | if (dc_skip == 1) return; |
1096 | | // No need to read transform type if block is skipped. |
1097 | 445k | if (mbmi->skip_txfm[xd->tree_type == CHROMA_PART] || |
1098 | 454k | segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
1099 | 0 | return; |
1100 | | |
1101 | 445k | if (xd->lossless[mbmi->segment_id]) { |
1102 | 126k | if (is_inter_block(mbmi, xd->tree_type)) { |
1103 | 3.52k | int lossless_inter_tx_type = 0; |
1104 | 3.52k | if (tx_size == TX_4X4) { |
1105 | 3.30k | lossless_inter_tx_type = |
1106 | 3.30k | avm_read_symbol(r, xd->tile_ctx->lossless_inter_tx_type_cdf, 2, |
1107 | 3.30k | ACCT_INFO("lossless_inter_tx_type")); |
1108 | 3.30k | } |
1109 | 3.52k | if (lossless_inter_tx_type || tx_size != TX_4X4) |
1110 | 1.57k | tx_type->primary_tx = IDTX; |
1111 | 3.52k | } |
1112 | 126k | return; |
1113 | 126k | } |
1114 | | |
1115 | 318k | const int inter_block = is_inter_block(mbmi, xd->tree_type); |
1116 | | |
1117 | 318k | if (mbmi->fsc_mode[xd->tree_type == CHROMA_PART]) { |
1118 | 6.17k | assert(!inter_block); |
1119 | 6.17k | tx_type->primary_tx = IDTX; |
1120 | 6.17k | return; |
1121 | 6.17k | } |
1122 | | |
1123 | 312k | if (get_ext_tx_types(tx_size, inter_block, cm->features.reduced_tx_set_used) > |
1124 | 312k | 1) { |
1125 | 244k | const TxSetType tx_set_type = av2_get_ext_tx_set_type( |
1126 | 244k | tx_size, inter_block, cm->features.reduced_tx_set_used); |
1127 | 244k | const int eset = |
1128 | 244k | get_ext_tx_set(tx_size, inter_block, cm->features.reduced_tx_set_used); |
1129 | | // eset == 0 should correspond to a set with only DCT_DCT and |
1130 | | // there is no need to read the tx_type |
1131 | 244k | assert(eset != 0); |
1132 | | |
1133 | 244k | const TX_SIZE square_tx_size = txsize_sqr_map[tx_size]; |
1134 | 244k | const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size]; |
1135 | 244k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
1136 | 244k | if (inter_block) { |
1137 | 17.1k | const int eob_tx_ctx = get_lp2tx_ctx(tx_size, get_txb_bwl(tx_size), eob); |
1138 | 17.1k | if (tx_set_type != EXT_TX_SET_LONG_SIDE_64 && |
1139 | 16.5k | tx_set_type != EXT_TX_SET_LONG_SIDE_32) { |
1140 | 14.1k | int tx_type_idx = 0; |
1141 | 14.1k | if (eset == 1 || eset == 2) { |
1142 | 6.81k | int tx_set = avm_read_symbol( |
1143 | 6.81k | r, |
1144 | 6.81k | ec_ctx->inter_tx_type_set[eset - 1][eob_tx_ctx][square_tx_size], |
1145 | 6.81k | 2, ACCT_INFO("tx_type")); |
1146 | 6.81k | if (tx_set == 0) { |
1147 | 3.67k | tx_type_idx = avm_read_symbol( |
1148 | 3.67k | r, ec_ctx->inter_tx_type_idx[eset - 1][eob_tx_ctx], |
1149 | 3.67k | INTER_TX_TYPE_INDEX_COUNT, ACCT_INFO("tx_type")); |
1150 | 3.67k | } else { |
1151 | 3.13k | tx_type_idx = |
1152 | 3.13k | INTER_TX_TYPE_INDEX_COUNT + |
1153 | 3.13k | (eset == 1 |
1154 | 3.13k | ? avm_read_symbol( |
1155 | 3.13k | r, ec_ctx->inter_tx_type_offset_1[eob_tx_ctx], |
1156 | 3.13k | INTER_TX_TYPE_OFFSET1_COUNT, ACCT_INFO("tx_type")) |
1157 | 3.13k | : avm_read_symbol( |
1158 | 3.13k | r, ec_ctx->inter_tx_type_offset_2[eob_tx_ctx], |
1159 | 3.13k | INTER_TX_TYPE_OFFSET2_COUNT, ACCT_INFO("tx_type"))); |
1160 | 3.13k | } |
1161 | 7.31k | } else { |
1162 | 7.31k | tx_type_idx = avm_read_symbol( |
1163 | 7.31k | r, ec_ctx->inter_ext_tx_cdf[eset][eob_tx_ctx][square_tx_size], |
1164 | 7.31k | av2_num_ext_tx_set[tx_set_type], ACCT_INFO("tx_type")); |
1165 | 7.31k | } |
1166 | 14.1k | tx_type->primary_tx = av2_ext_tx_inv[tx_set_type][tx_type_idx]; |
1167 | 14.1k | } else { |
1168 | 3.00k | int is_long_side_dct = 1; |
1169 | 3.00k | if (tx_size_sqr_up == TX_32X32) { |
1170 | 2.46k | is_long_side_dct = avm_read_symbol( |
1171 | 2.46k | r, ec_ctx->tx_ext_32_cdf[inter_block], 2, ACCT_INFO("tx_type")); |
1172 | 2.46k | } |
1173 | | |
1174 | 3.00k | int short_side_idx = avm_read_symbol( |
1175 | 3.00k | r, ec_ctx->inter_ext_tx_short_side_cdf[eob_tx_ctx][square_tx_size], |
1176 | 3.00k | 4, ACCT_INFO("tx_type")); |
1177 | 3.00k | tx_type->primary_tx = get_txtype_from_idx_for_large_txfm( |
1178 | 3.00k | tx_size, tx_set_type, short_side_idx, is_long_side_dct); |
1179 | 3.00k | } |
1180 | 227k | } else { |
1181 | 227k | if (cm->features.reduced_tx_set_used == 2) { |
1182 | 11.3k | tx_type->primary_tx = DCT_DCT; |
1183 | 11.3k | return; |
1184 | 11.3k | } |
1185 | | |
1186 | 215k | if (tx_set_type != EXT_TX_SET_LONG_SIDE_64 && |
1187 | 198k | tx_set_type != EXT_TX_SET_LONG_SIDE_32) { |
1188 | 149k | const PREDICTION_MODE intra_mode = get_intra_mode(mbmi, PLANE_TYPE_Y); |
1189 | 149k | const int size_info = av2_size_class[tx_size]; |
1190 | 149k | int tx_type_idx = avm_read_symbol( |
1191 | 149k | r, |
1192 | 149k | ec_ctx->intra_ext_tx_cdf[eset + |
1193 | 149k | (cm->features.reduced_tx_set_used ? 1 : 0)] |
1194 | 149k | [square_tx_size], |
1195 | 149k | cm->features.reduced_tx_set_used |
1196 | 149k | ? av2_num_reduced_tx_set[cm->features.reduced_tx_set_used - 1] |
1197 | 149k | : av2_num_ext_tx_set_intra[tx_set_type], |
1198 | 149k | ACCT_INFO("tx_type")); |
1199 | 149k | tx_type->primary_tx = |
1200 | 149k | av2_tx_idx_to_type(tx_type_idx, tx_set_type, intra_mode, size_info); |
1201 | 149k | } else { |
1202 | 66.3k | int is_long_side_dct = 1; |
1203 | 66.3k | if (tx_size_sqr_up == TX_32X32) { |
1204 | 49.2k | is_long_side_dct = avm_read_symbol( |
1205 | 49.2k | r, ec_ctx->tx_ext_32_cdf[inter_block], 2, ACCT_INFO("tx_type")); |
1206 | 49.2k | } |
1207 | 66.3k | int short_side_idx = avm_read_symbol( |
1208 | 66.3k | r, ec_ctx->intra_ext_tx_short_side_cdf[square_tx_size], 4, |
1209 | 66.3k | ACCT_INFO("tx_type")); |
1210 | 66.3k | tx_type->primary_tx = get_txtype_from_idx_for_large_txfm( |
1211 | 66.3k | tx_size, tx_set_type, short_side_idx, is_long_side_dct); |
1212 | 66.3k | } |
1213 | 215k | } |
1214 | 244k | } |
1215 | 312k | } |
1216 | | |
1217 | | void av2_read_cctx_type(const AV2_COMMON *const cm, MACROBLOCKD *xd, |
1218 | | int blk_row, int blk_col, TX_SIZE tx_size, |
1219 | 36.2k | avm_reader *r) { |
1220 | 36.2k | MB_MODE_INFO *mbmi = xd->mi[0]; |
1221 | | // If it is a sub 8x8 chroma block, derive the mi_row and mi_col of the |
1222 | | // parent block area. Then apply cctx type update to this area w.r.t the |
1223 | | // offsets derived |
1224 | 36.2k | int row_offset, col_offset; |
1225 | 36.2k | get_chroma_mi_offsets(xd, &row_offset, &col_offset); |
1226 | 36.2k | update_cctx_array(xd, blk_row, blk_col, row_offset, col_offset, tx_size, |
1227 | 36.2k | CCTX_NONE); |
1228 | | |
1229 | | // No need to read transform type if block is skipped. |
1230 | 36.2k | if (mbmi->skip_txfm[xd->tree_type == CHROMA_PART] || |
1231 | 36.1k | segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
1232 | 0 | return; |
1233 | | |
1234 | 36.2k | assert(!xd->lossless[mbmi->segment_id]); |
1235 | | |
1236 | 36.2k | CctxType cctx_type = CCTX_NONE; |
1237 | 36.2k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
1238 | 36.2k | (void)tx_size; |
1239 | 36.2k | cctx_type = avm_read_symbol(r, ec_ctx->cctx_type_cdf, CCTX_TYPES, |
1240 | 36.2k | ACCT_INFO("cctx_type")); |
1241 | 36.2k | update_cctx_array(xd, blk_row, blk_col, row_offset, col_offset, tx_size, |
1242 | 36.2k | cctx_type); |
1243 | 36.2k | } |
1244 | | |
1245 | | // This function reads a 'secondary tx set' from the bitstream |
1246 | | static void read_secondary_tx_set(MACROBLOCKD *xd, FRAME_CONTEXT *ec_ctx, |
1247 | | avm_reader *r, MB_MODE_INFO *mbmi, |
1248 | 145k | TX_SIZE tx_size, TX_TYPE *tx_type) { |
1249 | 145k | const int inter_block = is_inter_block(mbmi, xd->tree_type); |
1250 | 145k | SEC_TX_SET stx_set_flag = SEC_TX_SET_0; |
1251 | 145k | if (!inter_block) { |
1252 | 144k | uint8_t intra_mode = get_intra_mode(mbmi, AVM_PLANE_Y); |
1253 | 144k | SEC_TX_SET reordered_stx_set_flag; |
1254 | 144k | if (tx_type->primary_tx == ADST_ADST && tx_size_wide[tx_size] >= 8 && |
1255 | 20.8k | tx_size_high[tx_size] >= 8) { |
1256 | 18.5k | reordered_stx_set_flag = avm_read_symbol( |
1257 | 18.5k | r, ec_ctx->most_probable_stx_set_cdf_ADST_ADST, IST_REDUCED_SET_SIZE, |
1258 | 18.5k | ACCT_INFO("stx_set_flag_ADST_ADST")); |
1259 | 18.5k | stx_set_flag = |
1260 | 18.5k | inv_most_probable_stx_mapping_ADST_ADST[intra_mode] |
1261 | 18.5k | [reordered_stx_set_flag]; |
1262 | 126k | } else { |
1263 | 126k | reordered_stx_set_flag = |
1264 | 126k | avm_read_symbol(r, ec_ctx->most_probable_stx_set_cdf, IST_SET_SIZE, |
1265 | 126k | ACCT_INFO("stx_set_flag")); |
1266 | 126k | stx_set_flag = |
1267 | 126k | inv_most_probable_stx_mapping[intra_mode][reordered_stx_set_flag]; |
1268 | 126k | } |
1269 | 144k | } |
1270 | 145k | if (tx_type->primary_tx == ADST_ADST) stx_set_flag += IST_SET_SIZE; |
1271 | 145k | tx_type->sec_set = stx_set_flag; |
1272 | 145k | assert(av2_tx_type_in_range(tx_type->primary_tx, tx_type->sec_tx, |
1273 | 145k | tx_type->sec_set, tx_size_wide[tx_size], |
1274 | 145k | tx_size_high[tx_size])); |
1275 | 145k | } |
1276 | | |
1277 | | void av2_read_sec_tx_type(const AV2_COMMON *const cm, MACROBLOCKD *xd, |
1278 | | int blk_row, int blk_col, TX_SIZE tx_size, |
1279 | 347k | uint16_t *eob, avm_reader *r) { |
1280 | 347k | MB_MODE_INFO *mbmi = xd->mi[0]; |
1281 | 347k | TX_TYPE *tx_type = |
1282 | 347k | &xd->tx_type_map[blk_row * xd->tx_type_map_stride + blk_col]; |
1283 | | |
1284 | | // No need to read transform type if block is skipped. |
1285 | 347k | if (mbmi->skip_txfm[xd->tree_type == CHROMA_PART] || |
1286 | 347k | segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
1287 | 0 | return; |
1288 | | |
1289 | | // No need to read transform type for lossless mode |
1290 | 347k | if (xd->lossless[mbmi->segment_id]) return; |
1291 | | |
1292 | 234k | const int inter_block = is_inter_block(mbmi, xd->tree_type); |
1293 | 234k | if (get_ext_tx_types(tx_size, inter_block, cm->features.reduced_tx_set_used) > |
1294 | 234k | 1) { |
1295 | 175k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
1296 | 175k | const TX_SIZE square_tx_size = txsize_sqr_map[tx_size]; |
1297 | 175k | if (block_signals_sec_tx_type(xd, tx_size, tx_type->primary_tx, *eob)) { |
1298 | 103k | const uint8_t stx_flag = |
1299 | 103k | avm_read_symbol(r, ec_ctx->stx_cdf[inter_block][square_tx_size], |
1300 | 103k | STX_TYPES, ACCT_INFO("stx_flag")); |
1301 | 103k | tx_type->sec_tx = stx_flag; |
1302 | 103k | if (stx_flag > 0) |
1303 | 96.4k | read_secondary_tx_set(xd, ec_ctx, r, mbmi, tx_size, tx_type); |
1304 | | #if STX_SYNTAX_DEBUG |
1305 | | const int sb_size = |
1306 | | (tx_size_wide[tx_size] >= 8 && tx_size_high[tx_size] >= 8) ? 8 : 4; |
1307 | | fprintf(stderr, |
1308 | | "(read stx) mode %d sbsize %d txs %dx%d eob %d ptx %d stx_type " |
1309 | | "%d stx_set %d\n", |
1310 | | inter_block ? 12 : mbmi->mode, sb_size, tx_size_wide[tx_size], |
1311 | | tx_size_high[tx_size], *eob, tx_type->primary_tx, stx_flag, |
1312 | | tx_type->sec_set); |
1313 | | #endif // STX_SYNTAX_DEBUG |
1314 | 103k | } |
1315 | 175k | } else { |
1316 | 58.4k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
1317 | 58.4k | const TX_SIZE square_tx_size = txsize_sqr_map[tx_size]; |
1318 | 58.4k | if (block_signals_sec_tx_type(xd, tx_size, tx_type->primary_tx, *eob)) { |
1319 | 53.0k | const uint8_t stx_flag = |
1320 | 53.0k | avm_read_symbol(r, ec_ctx->stx_cdf[inter_block][square_tx_size], |
1321 | 53.0k | STX_TYPES, ACCT_INFO("stx_flag")); |
1322 | 53.0k | tx_type->sec_tx = stx_flag; |
1323 | 53.0k | if (stx_flag > 0) |
1324 | 48.6k | read_secondary_tx_set(xd, ec_ctx, r, mbmi, tx_size, tx_type); |
1325 | | #if STX_SYNTAX_DEBUG |
1326 | | const int sb_size = |
1327 | | (tx_size_wide[tx_size] >= 8 && tx_size_high[tx_size] >= 8) ? 8 : 4; |
1328 | | fprintf(stderr, |
1329 | | "(read stx) mode %d sbsize %d txs %dx%d eob %d ptx %d stx_type " |
1330 | | "%d stx_set %d\n", |
1331 | | inter_block ? 12 : mbmi->mode, sb_size, tx_size_wide[tx_size], |
1332 | | tx_size_high[tx_size], *eob, tx_type->primary_tx, stx_flag, |
1333 | | tx_type->sec_set); |
1334 | | #endif // STX_SYNTAX_DEBUG |
1335 | 53.0k | } |
1336 | 58.4k | } |
1337 | 234k | } |
1338 | | |
1339 | | static INLINE void read_mv(avm_reader *r, MV *mv_diff, int skip_sign_coding, |
1340 | | nmv_context *ctx, MvSubpelPrecision precision, |
1341 | | int is_adaptive_mvd); |
1342 | | |
1343 | | // Clip the MV to the integer value if it goes out of range |
1344 | 59.9k | static INLINE void mv_clamp_to_integer(MV *mv) { |
1345 | 59.9k | if (mv->row < MV_LOW + 1 || mv->row > MV_UPP - 1) { |
1346 | 1 | mv->row = (MV_COMP_DATA_TYPE)clamp(mv->row, MV_LOW + 8, MV_UPP - 8); |
1347 | 1 | } |
1348 | | |
1349 | 59.9k | if (mv->col < MV_LOW + 1 || mv->col > MV_UPP - 1) { |
1350 | 1 | mv->col = (MV_COMP_DATA_TYPE)clamp(mv->col, MV_LOW + 8, MV_UPP - 8); |
1351 | 1 | } |
1352 | 59.9k | } |
1353 | | |
1354 | | static INLINE int assign_dv(AV2_COMMON *cm, MACROBLOCKD *xd, int_mv *mv, |
1355 | | const int_mv *ref_mv, int mi_row, int mi_col, |
1356 | 59.9k | BLOCK_SIZE bsize, avm_reader *r) { |
1357 | 59.9k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
1358 | 59.9k | const MB_MODE_INFO *const mbmi = xd->mi[0]; |
1359 | 59.9k | if (mbmi->intrabc_mode == 1) { |
1360 | 37.8k | mv->as_int = ref_mv->as_int; |
1361 | 37.8k | } else { |
1362 | 22.0k | MV mv_diff = kZeroMv; |
1363 | 22.0k | read_mv(r, &mv_diff, 1, &ec_ctx->ndvc, mbmi->pb_mv_precision, 0); |
1364 | | |
1365 | | // Encode sign |
1366 | 22.0k | if (mv_diff.row) { |
1367 | 14.3k | int sign = avm_read_literal(r, 1, ACCT_INFO("sign")); |
1368 | | |
1369 | 14.3k | if (sign) mv_diff.row = -mv_diff.row; |
1370 | 14.3k | } |
1371 | 22.0k | if (mv_diff.col) { |
1372 | 16.0k | int sign = avm_read_literal(r, 1, ACCT_INFO("sign")); |
1373 | | |
1374 | 16.0k | if (sign) mv_diff.col = -mv_diff.col; |
1375 | 16.0k | } |
1376 | 22.0k | MV low_prec_refmv = ref_mv->as_mv; |
1377 | 22.0k | if (mbmi->pb_mv_precision < MV_PRECISION_HALF_PEL) |
1378 | 20.8k | lower_mv_precision(&low_prec_refmv, mbmi->pb_mv_precision); |
1379 | | |
1380 | 22.0k | mv->as_mv.row = low_prec_refmv.row + mv_diff.row; |
1381 | 22.0k | mv->as_mv.col = low_prec_refmv.col + mv_diff.col; |
1382 | 22.0k | } |
1383 | | |
1384 | 59.9k | assert( |
1385 | 59.9k | is_this_mv_precision_compliant(mbmi->mv[0].as_mv, mbmi->pb_mv_precision)); |
1386 | | |
1387 | 59.9k | mv_clamp_to_integer(&mv->as_mv); |
1388 | | |
1389 | 59.9k | const int valid = av2_is_dv_valid(mv->as_mv, cm, xd, mi_row, mi_col, bsize, |
1390 | 59.9k | cm->mib_size_log2); |
1391 | 59.9k | return valid; |
1392 | 59.9k | } |
1393 | | |
1394 | | static void read_intrabc_drl_idx(int max_ref_bv_cnt, MB_MODE_INFO *mbmi, |
1395 | 59.9k | avm_reader *r) { |
1396 | 59.9k | mbmi->intrabc_drl_idx = 0; |
1397 | 103k | for (int idx = 0; idx < max_ref_bv_cnt - 1; ++idx) { |
1398 | 71.3k | const int intrabc_drl_idx = avm_read_bit(r, ACCT_INFO()); |
1399 | 71.3k | mbmi->intrabc_drl_idx = idx + intrabc_drl_idx; |
1400 | 71.3k | if (!intrabc_drl_idx) break; |
1401 | 71.3k | } |
1402 | 59.9k | assert(mbmi->intrabc_drl_idx < max_ref_bv_cnt); |
1403 | 59.9k | } |
1404 | | |
1405 | | static void read_intrabc_info(AV2_COMMON *const cm, DecoderCodingBlock *dcb, |
1406 | 587k | avm_reader *r) { |
1407 | 587k | MACROBLOCKD *const xd = &dcb->xd; |
1408 | 587k | MB_MODE_INFO *const mbmi = xd->mi[0]; |
1409 | 587k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
1410 | 587k | assert(xd->tree_type != CHROMA_PART); |
1411 | 587k | if (xd->tree_type == CHROMA_PART) |
1412 | 587k | assert(mbmi->use_intrabc[PLANE_TYPE_UV] == 0); |
1413 | 587k | if (mbmi->use_intrabc[xd->tree_type == CHROMA_PART]) { |
1414 | 59.9k | BLOCK_SIZE bsize = mbmi->sb_type[xd->tree_type == CHROMA_PART]; |
1415 | 59.9k | mbmi->mode = DC_PRED; |
1416 | 59.9k | mbmi->fsc_mode[PLANE_TYPE_Y] = 0; |
1417 | 59.9k | mbmi->fsc_mode[PLANE_TYPE_UV] = 0; |
1418 | 59.9k | mbmi->uv_mode = UV_DC_PRED; |
1419 | 59.9k | mbmi->interp_fltr = BILINEAR; |
1420 | 59.9k | mbmi->motion_mode = SIMPLE_TRANSLATION; |
1421 | | // CHECK(cm->features.fr_mv_precision != MV_PRECISION_ONE_PEL, " |
1422 | | // fr_mv_precision is not same as MV_PRECISION_ONE_PEL for intra-bc |
1423 | | // blocks"); |
1424 | 59.9k | set_default_max_mv_precision(mbmi, xd->sbi->sb_mv_precision); |
1425 | 59.9k | set_default_intraBC_bv_precision(cm, mbmi); |
1426 | 59.9k | set_default_precision_set(cm, mbmi, bsize); |
1427 | 59.9k | set_most_probable_mv_precision(cm, mbmi, bsize); |
1428 | | |
1429 | 59.9k | mbmi->refinemv_flag = 0; |
1430 | 59.9k | mbmi->bawp_flag[0] = 0; |
1431 | 59.9k | mbmi->bawp_flag[1] = 0; |
1432 | | |
1433 | | // TODO(kslu): Rework av2_find_mv_refs to avoid having this big array |
1434 | | // ref_mvs |
1435 | 59.9k | int_mv ref_mvs[INTRA_FRAME + 1][MAX_MV_REF_CANDIDATES]; |
1436 | | |
1437 | 59.9k | av2_find_mv_refs(cm, xd, mbmi, INTRA_FRAME, dcb->ref_mv_count, |
1438 | 59.9k | xd->ref_mv_stack, xd->weight, ref_mvs, /*global_mvs=*/NULL, |
1439 | 59.9k | NULL, 0, NULL); |
1440 | | |
1441 | 59.9k | mbmi->intrabc_mode = |
1442 | 59.9k | avm_read_symbol(r, ec_ctx->intrabc_mode_cdf, 2, ACCT_INFO()); |
1443 | 59.9k | read_intrabc_drl_idx(cm->features.max_bvp_drl_bits + 1, mbmi, r); |
1444 | 59.9k | int_mv dv_ref = |
1445 | 59.9k | xd->ref_mv_stack[INTRA_FRAME][mbmi->intrabc_drl_idx].this_mv; |
1446 | 59.9k | assert(dv_ref.as_int != 0); // IntraBC is illegal with a zero MV. |
1447 | | |
1448 | 59.9k | int valid_dv = 1; |
1449 | 59.9k | assert(is_this_mv_precision_compliant(dv_ref.as_mv, mbmi->pb_mv_precision)); |
1450 | 59.9k | if (is_intraBC_bv_precision_active(cm, mbmi->intrabc_mode)) { |
1451 | 2.32k | int index = avm_read_symbol(r, ec_ctx->intrabc_bv_precision_cdf[0], |
1452 | 2.32k | av2_intraBc_precision_sets.num_precisions, |
1453 | 2.32k | ACCT_INFO()); |
1454 | 2.32k | mbmi->pb_mv_precision = av2_intraBc_precision_sets.precision[index]; |
1455 | 2.32k | } |
1456 | | |
1457 | 59.9k | valid_dv = valid_dv && assign_dv(cm, xd, &mbmi->mv[0], &dv_ref, xd->mi_row, |
1458 | 59.9k | xd->mi_col, bsize, r); |
1459 | 59.9k | if (!valid_dv) { |
1460 | | // Intra bc motion vectors are not valid - signal corrupt frame |
1461 | 1.51k | avm_internal_error(xd->error_info, AVM_CODEC_CORRUPT_FRAME, |
1462 | 1.51k | "Invalid intrabc dv"); |
1463 | 1.51k | } |
1464 | | |
1465 | 59.9k | assert(is_this_mv_precision_compliant(mbmi->mv[0].as_mv, |
1466 | 59.9k | mbmi->pb_mv_precision)); |
1467 | | |
1468 | 59.9k | if (av2_allow_intrabc_morph_pred(cm)) { |
1469 | 55.5k | const int morph_pred_ctx = get_morph_pred_ctx(xd); |
1470 | 55.5k | mbmi->morph_pred = avm_read_symbol( |
1471 | 55.5k | r, ec_ctx->morph_pred_cdf[morph_pred_ctx], 2, ACCT_INFO()); |
1472 | 55.5k | if (mbmi->morph_pred != 0) { |
1473 | 31.2k | valid_dv = |
1474 | 31.2k | valid_dv && is_bv_valid_for_morph(mbmi->mv[0].as_mv, cm, xd, |
1475 | 31.2k | xd->mi_row, xd->mi_col, bsize); |
1476 | 31.2k | } |
1477 | 55.5k | if (!valid_dv) { |
1478 | | // Intra bc motion vectors are not valid - signal corrupt frame |
1479 | 11 | avm_internal_error(xd->error_info, AVM_CODEC_CORRUPT_FRAME, |
1480 | 11 | "Invalid intrabc BAWP dv"); |
1481 | 11 | } |
1482 | 55.5k | } |
1483 | 59.9k | } |
1484 | 587k | } |
1485 | | |
1486 | | // If delta q is present, reads delta_q index. |
1487 | | // Also reads delta_q loop filter levels, if present. |
1488 | | static void read_delta_q_params(AV2_COMMON *const cm, MACROBLOCKD *const xd, |
1489 | 709k | avm_reader *r) { |
1490 | 709k | DeltaQInfo *const delta_q_info = &cm->delta_q_info; |
1491 | | |
1492 | 709k | if (delta_q_info->delta_q_present_flag) { |
1493 | 240k | MB_MODE_INFO *const mbmi = xd->mi[0]; |
1494 | 240k | xd->current_base_qindex += |
1495 | 240k | read_delta_qindex(cm, xd, r, mbmi) * delta_q_info->delta_q_res; |
1496 | | /* Normative: Clamp to [1,MAXQ] to not interfere with lossless mode */ |
1497 | 240k | xd->current_base_qindex = |
1498 | 240k | clamp(xd->current_base_qindex, 1, |
1499 | 240k | MAXQ_FOR_GIVEN_BIT_DEPTH(cm->seq_params.bit_depth)); |
1500 | 240k | } |
1501 | 709k | } |
1502 | | |
1503 | | // read mode set index and mode index in set for y component, |
1504 | | // and map it to y mode and delta angle |
1505 | 617k | static void read_intra_luma_mode(MACROBLOCKD *const xd, avm_reader *r) { |
1506 | 617k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
1507 | 617k | MB_MODE_INFO *const mbmi = xd->mi[0]; |
1508 | 617k | uint8_t mode_idx = 0; |
1509 | 617k | const int context = get_y_mode_idx_ctx(xd); |
1510 | 617k | int mode_set_index = |
1511 | 617k | avm_read_symbol(r, ec_ctx->y_mode_set_cdf, INTRA_MODE_SETS, |
1512 | 617k | ACCT_INFO("mode_set_index", "y_mode_set_cdf")); |
1513 | 617k | if (mode_set_index == 0) { |
1514 | 541k | mode_idx = avm_read_symbol(r, ec_ctx->y_mode_idx_cdf[context], |
1515 | 541k | LUMA_INTRA_MODE_INDEX_COUNT, |
1516 | 541k | ACCT_INFO("mode_idx", "y_mode_idx_cdf")); |
1517 | 541k | if (mode_idx == (LUMA_INTRA_MODE_INDEX_COUNT - 1)) |
1518 | 89.8k | mode_idx += |
1519 | 89.8k | avm_read_symbol(r, ec_ctx->y_mode_idx_offset_cdf[context], |
1520 | 541k | LUMA_INTRA_MODE_OFFSET_COUNT, |
1521 | 541k | ACCT_INFO("mode_idx", "y_mode_idx_offset_cdf")); |
1522 | 541k | } else { |
1523 | 76.5k | mode_idx = FIRST_MODE_COUNT + (mode_set_index - 1) * SECOND_MODE_COUNT + |
1524 | 76.5k | avm_read_literal(r, 4, ACCT_INFO("mode_idx")); |
1525 | 76.5k | } |
1526 | 617k | assert(mode_idx < LUMA_MODE_COUNT); |
1527 | 617k | get_y_intra_mode_set(mbmi, xd); |
1528 | 617k | mbmi->joint_y_mode_delta_angle = mbmi->y_intra_mode_list[mode_idx]; |
1529 | 617k | av2_set_y_mode_and_delta_angle(mbmi->joint_y_mode_delta_angle, mbmi); |
1530 | 617k | mbmi->y_mode_idx = mode_idx; |
1531 | 617k | if (mbmi->joint_y_mode_delta_angle < NON_DIRECTIONAL_MODES_COUNT) |
1532 | 617k | assert(mbmi->joint_y_mode_delta_angle == mbmi->y_mode_idx); |
1533 | 617k | } |
1534 | | |
1535 | | // Read mode index for uv component and map it to uv mode and delta angle. |
1536 | | // First we read if the uv mode is UV_CFL_PRED. |
1537 | | // If yes, uv mode is set to UV_CFL_PRED, delta angle is set to 0. Done. |
1538 | | // If not, we read mode index and map it to uv mode and delta angle. |
1539 | | static void read_intra_uv_mode(MACROBLOCKD *const xd, |
1540 | 489k | CFL_ALLOWED_TYPE cfl_allowed, avm_reader *r) { |
1541 | 489k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
1542 | 489k | MB_MODE_INFO *const mbmi = xd->mi[0]; |
1543 | 489k | int is_cfl_mode = 0; |
1544 | 489k | if (cfl_allowed) { |
1545 | 415k | const int cfl_ctx = get_cfl_ctx(xd); |
1546 | 415k | is_cfl_mode = avm_read_symbol(r, ec_ctx->cfl_cdf[cfl_ctx], 2, |
1547 | 415k | ACCT_INFO("is_cfl_idx")); |
1548 | 415k | } |
1549 | 489k | if (is_cfl_mode) { |
1550 | 242k | mbmi->uv_mode = UV_CFL_PRED; |
1551 | 242k | mbmi->angle_delta[PLANE_TYPE_UV] = 0; |
1552 | 242k | return; |
1553 | 242k | } |
1554 | | |
1555 | 247k | const int context = av2_is_directional_mode(mbmi->mode) ? 1 : 0; |
1556 | 247k | int uv_mode_idx = |
1557 | 247k | avm_read_symbol(r, ec_ctx->uv_mode_cdf[context], |
1558 | 247k | CHROMA_INTRA_MODE_INDEX_COUNT, ACCT_INFO("uv_mode_idx")); |
1559 | 247k | if (uv_mode_idx == (CHROMA_INTRA_MODE_INDEX_COUNT - 1)) |
1560 | 5.87k | uv_mode_idx += avm_read_literal(r, 3, ACCT_INFO("uv_mode_idx")); |
1561 | 247k | if (uv_mode_idx >= UV_INTRA_MODES - 1) { |
1562 | 427 | avm_internal_error(xd->error_info, AVM_CODEC_CORRUPT_FRAME, |
1563 | 427 | "Invalid value for chroma intra mode index"); |
1564 | 427 | } |
1565 | 247k | assert(uv_mode_idx >= 0 && uv_mode_idx < UV_INTRA_MODES); |
1566 | 247k | get_uv_intra_mode_set(mbmi); |
1567 | 247k | mbmi->uv_mode = mbmi->uv_intra_mode_list[uv_mode_idx]; |
1568 | 247k | if (mbmi->uv_mode == mbmi->mode) |
1569 | 105k | mbmi->angle_delta[PLANE_TYPE_UV] = mbmi->angle_delta[PLANE_TYPE_Y]; |
1570 | 141k | else |
1571 | 141k | mbmi->angle_delta[PLANE_TYPE_UV] = 0; |
1572 | 247k | } |
1573 | | |
1574 | | static void read_intra_frame_mode_info(AV2_COMMON *const cm, |
1575 | 788k | DecoderCodingBlock *dcb, avm_reader *r) { |
1576 | 788k | MACROBLOCKD *const xd = &dcb->xd; |
1577 | 788k | MB_MODE_INFO *const mbmi = xd->mi[0]; |
1578 | 788k | const BLOCK_SIZE bsize = mbmi->sb_type[xd->tree_type == CHROMA_PART]; |
1579 | 788k | struct segmentation *const seg = &cm->seg; |
1580 | | |
1581 | 788k | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
1582 | | |
1583 | 788k | if (seg->segid_preskip && xd->tree_type != CHROMA_PART) |
1584 | 80.7k | mbmi->segment_id = read_intra_segment_id(cm, xd, bsize, r, 0); |
1585 | | |
1586 | 788k | mbmi->skip_mode = 0; |
1587 | 788k | if (xd->tree_type != CHROMA_PART) mbmi->morph_pred = 0; |
1588 | 788k | mbmi->motion_mode = SIMPLE_TRANSLATION; |
1589 | 788k | mbmi->refinemv_flag = 0; |
1590 | | |
1591 | 788k | if (av2_allow_intrabc(cm, xd, bsize) && xd->tree_type != CHROMA_PART) { |
1592 | 588k | mbmi->use_intrabc[0] = 0; |
1593 | 588k | mbmi->use_intrabc[1] = 0; |
1594 | 588k | const int intrabc_ctx = get_intrabc_ctx(xd); |
1595 | 588k | mbmi->use_intrabc[xd->tree_type == CHROMA_PART] = |
1596 | 588k | avm_read_symbol(r, ec_ctx->intrabc_cdf[intrabc_ctx], 2, |
1597 | 588k | ACCT_INFO("use_intrabc", "chroma")); |
1598 | 588k | } |
1599 | 788k | if (is_intrabc_block(mbmi, xd->tree_type)) { |
1600 | 59.9k | mbmi->skip_txfm[xd->tree_type == CHROMA_PART] = |
1601 | 59.9k | read_skip_txfm(cm, xd, mbmi->segment_id, r); |
1602 | 728k | } else { |
1603 | | // Segment SEG_LVL_SKIP should be disabled for intra prediction |
1604 | 728k | if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
1605 | 1.47k | avm_internal_error(xd->error_info, AVM_CODEC_CORRUPT_FRAME, |
1606 | 1.47k | "Corrupted segment features"); |
1607 | 1.47k | } |
1608 | 728k | mbmi->skip_txfm[xd->tree_type == CHROMA_PART] = 0; |
1609 | 728k | } |
1610 | | |
1611 | 788k | if (!seg->segid_preskip && xd->tree_type != CHROMA_PART) |
1612 | 629k | mbmi->segment_id = read_intra_segment_id( |
1613 | 629k | cm, xd, bsize, r, mbmi->skip_txfm[xd->tree_type == CHROMA_PART]); |
1614 | | |
1615 | 788k | mbmi->seg_id_predicted = 0; |
1616 | | |
1617 | 788k | if (xd->tree_type != CHROMA_PART) read_gdf(cm, r, xd); |
1618 | | |
1619 | 788k | if (xd->tree_type != CHROMA_PART) read_cdef(cm, r, xd); |
1620 | | |
1621 | 788k | if (cm->seq_params.enable_ccso && xd->tree_type != CHROMA_PART) |
1622 | 649k | read_ccso(cm, r, xd); |
1623 | | |
1624 | 788k | if (xd->tree_type != CHROMA_PART) read_delta_q_params(cm, xd, r); |
1625 | | |
1626 | 788k | mbmi->current_qindex = xd->current_base_qindex; |
1627 | | |
1628 | 788k | int seg_qindex = |
1629 | 788k | av2_get_qindex(&cm->seg, mbmi->segment_id, xd->current_base_qindex, |
1630 | 788k | cm->seq_params.bit_depth); |
1631 | 788k | get_qindex_with_offsets(cm, seg_qindex, mbmi->final_qindex_dc, |
1632 | 788k | mbmi->final_qindex_ac); |
1633 | | |
1634 | 788k | mbmi->ref_frame[0] = INTRA_FRAME; |
1635 | 788k | mbmi->ref_frame[1] = NONE_FRAME; |
1636 | 788k | if (xd->tree_type != CHROMA_PART) mbmi->palette_mode_info.palette_size[0] = 0; |
1637 | 788k | mbmi->palette_mode_info.palette_size[1] = 0; |
1638 | 788k | if (xd->tree_type != CHROMA_PART) { |
1639 | 708k | mbmi->use_intra_dip = 0; |
1640 | 708k | } |
1641 | | |
1642 | 788k | if (av2_allow_intrabc(cm, xd, bsize) && xd->tree_type != CHROMA_PART) { |
1643 | 587k | read_intrabc_info(cm, dcb, r); |
1644 | 587k | if (is_intrabc_block(mbmi, xd->tree_type)) { |
1645 | 58.3k | mbmi->use_dpcm_y = 0; |
1646 | 58.3k | mbmi->dpcm_mode_y = 0; |
1647 | 58.3k | mbmi->use_amvd = 0; |
1648 | 58.3k | return; |
1649 | 58.3k | } |
1650 | 587k | } |
1651 | 730k | if (xd->tree_type != CHROMA_PART) { |
1652 | 648k | if (xd->lossless[mbmi->segment_id]) { |
1653 | 47.2k | mbmi->use_dpcm_y = read_dpcm_mode(ec_ctx, r); |
1654 | 47.2k | if (mbmi->use_dpcm_y == 0) { |
1655 | 16.1k | read_intra_luma_mode(xd, r); |
1656 | 31.0k | } else { |
1657 | 31.0k | mbmi->dpcm_mode_y = read_dpcm_vert_horz_mode(ec_ctx, r); |
1658 | 31.0k | if (mbmi->dpcm_mode_y == 0) { |
1659 | 14.1k | mbmi->joint_y_mode_delta_angle = 22; |
1660 | 14.1k | mbmi->mode = V_PRED; |
1661 | 14.1k | mbmi->angle_delta[0] = 0; |
1662 | 16.8k | } else { |
1663 | 16.8k | mbmi->joint_y_mode_delta_angle = 50; |
1664 | 16.8k | mbmi->mode = H_PRED; |
1665 | 16.8k | mbmi->angle_delta[0] = 0; |
1666 | 16.8k | } |
1667 | 31.0k | } |
1668 | 601k | } else { |
1669 | 601k | mbmi->use_dpcm_y = 0; |
1670 | 601k | mbmi->dpcm_mode_y = 0; |
1671 | 601k | read_intra_luma_mode(xd, r); |
1672 | 601k | } |
1673 | 648k | if (allow_fsc_intra(cm, bsize, mbmi)) { |
1674 | 342k | avm_cdf_prob *fsc_cdf = get_fsc_mode_cdf(xd, bsize, 1); |
1675 | 342k | mbmi->fsc_mode[xd->tree_type == CHROMA_PART] = read_fsc_mode(r, fsc_cdf); |
1676 | 342k | } else { |
1677 | 305k | mbmi->fsc_mode[xd->tree_type == CHROMA_PART] = 0; |
1678 | 305k | } |
1679 | | |
1680 | 648k | if (xd->lossless[mbmi->segment_id]) { |
1681 | 47.2k | if (mbmi->use_dpcm_y == 0) { |
1682 | 16.1k | mbmi->mrl_index = |
1683 | 16.1k | (cm->seq_params.enable_mrls && av2_is_directional_mode(mbmi->mode)) |
1684 | 16.1k | ? read_mrl_index(ec_ctx, r, xd->neighbors[0], xd->neighbors[1]) |
1685 | 16.1k | : 0; |
1686 | 16.1k | if (mbmi->mrl_index) { |
1687 | 194 | mbmi->multi_line_mrl = read_multi_line_mrl( |
1688 | 194 | ec_ctx, r, xd->neighbors[0], xd->neighbors[1]); |
1689 | 15.9k | } else { |
1690 | 15.9k | mbmi->multi_line_mrl = 0; |
1691 | 15.9k | } |
1692 | 31.0k | } else { |
1693 | 31.0k | mbmi->mrl_index = 0; |
1694 | 31.0k | mbmi->multi_line_mrl = 0; |
1695 | 31.0k | } |
1696 | 601k | } else { |
1697 | 601k | mbmi->mrl_index = |
1698 | 601k | (cm->seq_params.enable_mrls && av2_is_directional_mode(mbmi->mode)) |
1699 | 601k | ? read_mrl_index(ec_ctx, r, xd->neighbors[0], xd->neighbors[1]) |
1700 | 601k | : 0; |
1701 | 601k | if (mbmi->mrl_index) { |
1702 | 8.80k | mbmi->multi_line_mrl = |
1703 | 8.80k | read_multi_line_mrl(ec_ctx, r, xd->neighbors[0], xd->neighbors[1]); |
1704 | 592k | } else { |
1705 | 592k | mbmi->multi_line_mrl = 0; |
1706 | 592k | } |
1707 | 601k | } |
1708 | 648k | } |
1709 | | |
1710 | 730k | if (xd->tree_type != LUMA_PART) { |
1711 | 565k | if (!cm->seq_params.monochrome && xd->is_chroma_ref) { |
1712 | 493k | if (xd->lossless[mbmi->segment_id]) { |
1713 | 5.70k | mbmi->use_dpcm_uv = read_dpcm_uv_mode(ec_ctx, r); |
1714 | 5.70k | if (mbmi->use_dpcm_uv == 0) { |
1715 | 2.78k | read_intra_uv_mode( |
1716 | 2.78k | xd, |
1717 | 2.78k | is_cfl_allowed(cm->seq_params.enable_cfl_intra, xd) || |
1718 | 2.50k | is_mhccp_allowed(cm, xd), |
1719 | 2.78k | r); |
1720 | 2.78k | mbmi->dpcm_mode_uv = 0; |
1721 | 2.92k | } else { |
1722 | 2.92k | get_uv_intra_mode_set(mbmi); |
1723 | 2.92k | mbmi->dpcm_mode_uv = read_dpcm_uv_vert_horz_mode(ec_ctx, r); |
1724 | 2.92k | mbmi->uv_mode = mbmi->dpcm_mode_uv + 1; |
1725 | 2.92k | if (mbmi->uv_mode == mbmi->mode) |
1726 | 1.14k | mbmi->angle_delta[PLANE_TYPE_UV] = mbmi->angle_delta[PLANE_TYPE_Y]; |
1727 | 1.77k | else |
1728 | 1.77k | mbmi->angle_delta[PLANE_TYPE_UV] = 0; |
1729 | 2.92k | } |
1730 | 487k | } else { |
1731 | 487k | read_intra_uv_mode( |
1732 | 487k | xd, |
1733 | 487k | is_cfl_allowed(cm->seq_params.enable_cfl_intra, xd) || |
1734 | 194k | is_mhccp_allowed(cm, xd), |
1735 | 487k | r); |
1736 | 487k | mbmi->use_dpcm_uv = 0; |
1737 | 487k | mbmi->dpcm_mode_uv = 0; |
1738 | 487k | } |
1739 | | |
1740 | 493k | if (mbmi->uv_mode == UV_CFL_PRED) { |
1741 | 242k | { |
1742 | 242k | if (is_mhccp_allowed(cm, xd)) { |
1743 | 147k | int cfl_mhccp_switch = 1; |
1744 | 147k | if (cm->seq_params.enable_cfl_intra) |
1745 | 84.5k | cfl_mhccp_switch = read_cfl_mhccp_switch(ec_ctx, r); |
1746 | 147k | if (cfl_mhccp_switch) { |
1747 | 110k | mbmi->cfl_idx = CFL_MULTI_PARAM; |
1748 | 110k | } else { |
1749 | 37.3k | mbmi->cfl_idx = read_cfl_index(ec_ctx, r); |
1750 | 37.3k | } |
1751 | 147k | } else if (cm->seq_params.enable_cfl_intra) { |
1752 | 95.1k | mbmi->cfl_idx = read_cfl_index(ec_ctx, r); |
1753 | 95.1k | } |
1754 | 242k | if (mbmi->cfl_idx == CFL_MULTI_PARAM) { |
1755 | 109k | const uint8_t mh_size_group = size_group_lookup[bsize]; |
1756 | 109k | assert(mh_size_group < MHCCP_CONTEXT_GROUP_SIZE); |
1757 | 109k | avm_cdf_prob *mh_dir_cdf = ec_ctx->filter_dir_cdf[mh_size_group]; |
1758 | 109k | mbmi->mh_dir = read_mh_dir(mh_dir_cdf, r); |
1759 | 109k | } |
1760 | 242k | } |
1761 | 242k | if (mbmi->cfl_idx == 0) |
1762 | 60.0k | mbmi->cfl_alpha_idx = |
1763 | 60.0k | read_cfl_alphas(ec_ctx, r, &mbmi->cfl_alpha_signs); |
1764 | 242k | } |
1765 | 493k | } else { |
1766 | | // Avoid decoding angle_info if there is is no chroma prediction |
1767 | 72.4k | mbmi->uv_mode = UV_DC_PRED; |
1768 | 72.4k | } |
1769 | 565k | xd->cfl.store_y = store_cfl_required(cm, xd); |
1770 | 565k | } else { |
1771 | | // Avoid decoding angle_info if there is is no chroma prediction |
1772 | 164k | mbmi->uv_mode = UV_DC_PRED; |
1773 | 164k | } |
1774 | | |
1775 | 730k | if (xd->tree_type != CHROMA_PART) mbmi->palette_mode_info.palette_size[0] = 0; |
1776 | 730k | mbmi->palette_mode_info.palette_size[1] = 0; |
1777 | 730k | if (av2_allow_palette(PLANE_TYPE_Y, cm->features.allow_screen_content_tools, |
1778 | 730k | bsize)) |
1779 | 584k | read_palette_mode_info(cm, xd, r); |
1780 | 730k | if (xd->tree_type != CHROMA_PART) { |
1781 | 649k | mbmi->use_intra_dip = 0; |
1782 | 649k | read_intra_dip_mode_info(cm, xd, r); |
1783 | 649k | } |
1784 | 730k | } |
1785 | | |
1786 | | // Coding of col mvd for shell class 2 |
1787 | | static void read_truncated_unary_mvd(avm_reader *r, nmv_context *ctx, |
1788 | | const int max_coded_value, int num_of_ctx, |
1789 | 3.69k | int *decoded_value) { |
1790 | 3.69k | (void)num_of_ctx; |
1791 | | |
1792 | 3.69k | int col = 0; |
1793 | 3.69k | int max_idx_bits = max_coded_value; |
1794 | 7.69k | for (int bit_idx = 0; bit_idx < max_idx_bits; ++bit_idx) { |
1795 | 7.11k | avm_cdf_prob *cdf = ctx->shell_offset_class2_cdf; |
1796 | 7.11k | int this_bit = |
1797 | 7.11k | bit_idx ? avm_read_literal(r, 1, ACCT_INFO("greater_flags")) |
1798 | 7.11k | : avm_read_symbol( |
1799 | 7.11k | r, cdf, 2, |
1800 | 7.11k | ACCT_INFO("greater_flags", "col_mv_greater_flags_cdf")); |
1801 | | |
1802 | 7.11k | col = bit_idx + this_bit; |
1803 | 7.11k | if (!this_bit) break; |
1804 | 7.11k | } |
1805 | 3.69k | *decoded_value = col; |
1806 | 3.69k | } |
1807 | | // Decoding of truncated unary followed by quasi uniform code |
1808 | | static void read_tu_quasi_uniform(avm_reader *r, nmv_context *ctx, |
1809 | | const int max_coded_value, int *scaled_mv_col, |
1810 | 15.6k | int max_trunc_unary_value) { |
1811 | 15.6k | int col = 0; |
1812 | 15.6k | int max_idx_bits = AVMMIN(max_coded_value, max_trunc_unary_value); |
1813 | 15.6k | int max_num_of_ctx = NUM_CTX_COL_MV_GTX; |
1814 | 34.8k | for (int bit_idx = 0; bit_idx < max_idx_bits; ++bit_idx) { |
1815 | 24.6k | int context_index = bit_idx < max_num_of_ctx ? bit_idx : max_num_of_ctx - 1; |
1816 | 24.6k | assert(context_index < max_num_of_ctx); |
1817 | 24.6k | int this_bit = |
1818 | 24.6k | avm_read_symbol(r, ctx->col_mv_greater_flags_cdf[context_index], 2, |
1819 | 24.6k | ACCT_INFO("greater_flags", "col_mv_greater_flags_cdf")); |
1820 | | |
1821 | 24.6k | col = bit_idx + this_bit; |
1822 | 24.6k | if (!this_bit) break; |
1823 | 24.6k | } |
1824 | 15.6k | if (max_coded_value > max_trunc_unary_value && col == max_trunc_unary_value) { |
1825 | 5.96k | int remainder_max_value = max_coded_value - max_trunc_unary_value; |
1826 | 5.96k | int remainder = avm_read_primitive_quniform(r, remainder_max_value + 1, |
1827 | 5.96k | ACCT_INFO("remainder")); |
1828 | 5.96k | col = remainder + max_trunc_unary_value; |
1829 | 5.96k | } |
1830 | 15.6k | *scaled_mv_col = col; |
1831 | 15.6k | } |
1832 | | // Read MVD for AMVD mode |
1833 | 1 | static INLINE void read_vq_amvd(avm_reader *r, MV *mv_diff, nmv_context *ctx) { |
1834 | 1 | MV diff_index = kZeroMv; |
1835 | | |
1836 | 1 | const MV_JOINT_TYPE joint_type = (MV_JOINT_TYPE)avm_read_symbol( |
1837 | 1 | r, ctx->amvd_joints_cdf, MV_JOINTS, |
1838 | 1 | ACCT_INFO("joint_type", "amvd_joints_cdf")); |
1839 | 1 | int code_row = mv_joint_vertical(joint_type); |
1840 | 1 | int code_col = mv_joint_horizontal(joint_type); |
1841 | | |
1842 | 1 | if (code_row) { |
1843 | 1 | diff_index.row = |
1844 | 1 | 1 + avm_read_symbol(r, ctx->comps[0].amvd_indices_cdf, MAX_AMVD_INDEX, |
1845 | 1 | ACCT_INFO("amvd_index", "amvd_indices_cdf")); |
1846 | 1 | } |
1847 | | |
1848 | 1 | if (code_col) { |
1849 | 0 | diff_index.col = |
1850 | 0 | 1 + avm_read_symbol(r, ctx->comps[1].amvd_indices_cdf, MAX_AMVD_INDEX, |
1851 | 0 | ACCT_INFO("amvd_index", "amvd_indices_cdf")); |
1852 | 0 | } |
1853 | | |
1854 | 1 | MV diff = { get_mvd_from_amvd_index(diff_index.row), |
1855 | 1 | get_mvd_from_amvd_index(diff_index.col) }; |
1856 | | |
1857 | 1 | mv_diff->row = diff.row; |
1858 | 1 | mv_diff->col = diff.col; |
1859 | 1 | } |
1860 | | |
1861 | | static INLINE void read_mv(avm_reader *r, MV *mv_diff, int skip_sign_coding, |
1862 | | nmv_context *ctx, MvSubpelPrecision precision, |
1863 | 22.0k | int is_adaptive_mvd) { |
1864 | 22.0k | if (is_adaptive_mvd) { |
1865 | 1 | read_vq_amvd(r, mv_diff, ctx); |
1866 | 1 | return; |
1867 | 1 | } |
1868 | | |
1869 | 22.0k | MV scaled_mv_diff; |
1870 | | |
1871 | | // Read shell class |
1872 | 22.0k | int num_mv_class = get_default_num_shell_class(precision); |
1873 | 22.0k | int shell_class = 0; |
1874 | 22.0k | int shell_set = 0; |
1875 | 22.0k | int num_mv_class_0, num_mv_class_1; |
1876 | 22.0k | split_num_shell_class(num_mv_class, &num_mv_class_0, &num_mv_class_1); |
1877 | 22.0k | shell_set = avm_read_symbol(r, ctx->joint_shell_set_cdf, 2, |
1878 | 22.0k | ACCT_INFO("shell_set", "joint_shell_set_cdf")); |
1879 | 22.0k | if (shell_set) { |
1880 | 206 | if (precision == MV_PRECISION_ONE_EIGHTH_PEL) { |
1881 | 0 | shell_class = |
1882 | 0 | num_mv_class_0 + |
1883 | 0 | avm_read_symbol( |
1884 | 0 | r, ctx->joint_shell_class_cdf_1[precision], num_mv_class_1 - 1, |
1885 | 0 | ACCT_INFO("shell_class_1", "joint_shell_class_cdf_1")); |
1886 | 0 | if (shell_class >= MAX_NUM_SHELL_CLASS - 2) { |
1887 | 0 | shell_class += avm_read_symbol( |
1888 | 0 | r, ctx->joint_shell_last_two_classes_cdf, 2, |
1889 | 0 | ACCT_INFO("shell_class", "joint_shell_last_two_classes_cdf")); |
1890 | 0 | } |
1891 | 206 | } else { |
1892 | 206 | shell_class = |
1893 | 206 | num_mv_class_0 + |
1894 | 206 | avm_read_symbol( |
1895 | 206 | r, ctx->joint_shell_class_cdf_1[precision], num_mv_class_1, |
1896 | 206 | ACCT_INFO("shell_class_1", "joint_shell_class_cdf_1")); |
1897 | 206 | } |
1898 | 21.8k | } else { |
1899 | 21.8k | shell_class = avm_read_symbol( |
1900 | 21.8k | r, ctx->joint_shell_class_cdf_0[precision], num_mv_class_0, |
1901 | 21.8k | ACCT_INFO("shell_class_0", "joint_shell_class_cdf_0")); |
1902 | 21.8k | } |
1903 | 22.0k | assert(shell_class < num_mv_class); |
1904 | | |
1905 | | // Decode shell class offset |
1906 | 22.0k | int shell_cls_offset = 0; |
1907 | | |
1908 | 22.0k | if (shell_class < 2) { |
1909 | 10.0k | shell_cls_offset = avm_read_symbol( |
1910 | 10.0k | r, ctx->shell_offset_low_class_cdf[shell_class], 2, |
1911 | 10.0k | ACCT_INFO("shell_cls_offset", "shell_offset_low_class_cdf")); |
1912 | 10.0k | assert(shell_cls_offset == 0 || shell_cls_offset == 1); |
1913 | 12.0k | } else if (shell_class == 2) { |
1914 | 3.69k | read_truncated_unary_mvd(r, ctx, 3, 3, &shell_cls_offset); |
1915 | | |
1916 | 8.39k | } else { |
1917 | 8.39k | const int num_of_bits_for_this_offset = |
1918 | 8.39k | (shell_class == 0) ? 1 : shell_class; |
1919 | 43.5k | for (int i = 0; i < num_of_bits_for_this_offset; ++i) { |
1920 | 35.1k | shell_cls_offset |= |
1921 | 35.1k | avm_read_symbol(r, ctx->shell_offset_other_class_cdf[0][i], 2, |
1922 | 35.1k | ACCT_INFO("offset")) |
1923 | 35.1k | << i; |
1924 | 35.1k | } |
1925 | 8.39k | } |
1926 | | |
1927 | | // Reconstruct shell index |
1928 | 22.0k | const int shell_class_base_index = |
1929 | 22.0k | (shell_class == 0) ? 0 : (1 << (shell_class)); |
1930 | 22.0k | const int shell_index = shell_cls_offset + shell_class_base_index; |
1931 | | |
1932 | 22.0k | if (shell_index > 0) { |
1933 | | // Coding the col here |
1934 | 18.8k | int scaled_mv_col; |
1935 | 18.8k | int max_trunc_unary_value = MAX_COL_TRUNCATED_UNARY_VAL; |
1936 | 18.8k | int this_pair_index = 0; |
1937 | 18.8k | int maximum_pair_index = shell_index >> 1; |
1938 | 18.8k | if (maximum_pair_index > 0) { |
1939 | 15.6k | read_tu_quasi_uniform(r, ctx, maximum_pair_index, &this_pair_index, |
1940 | 15.6k | max_trunc_unary_value); |
1941 | 15.6k | } |
1942 | 18.8k | assert(this_pair_index <= maximum_pair_index); |
1943 | 18.8k | int skip_coding_col_bit = |
1944 | 18.8k | (this_pair_index == maximum_pair_index) && ((shell_index % 2 == 0)); |
1945 | 18.8k | if (skip_coding_col_bit) { |
1946 | 3.26k | scaled_mv_col = maximum_pair_index; |
1947 | 15.5k | } else { |
1948 | | // int bit = avm_read_literal(r, 1, ACCT_INFO()); |
1949 | 15.5k | int context_index = shell_class < NUM_CTX_COL_MV_INDEX |
1950 | 15.5k | ? shell_class |
1951 | 15.5k | : NUM_CTX_COL_MV_INDEX - 1; |
1952 | 15.5k | assert(context_index < NUM_CTX_COL_MV_INDEX); |
1953 | | |
1954 | 15.5k | int this_bit = avm_read_symbol( |
1955 | 15.5k | r, ctx->col_mv_index_cdf[context_index], 2, |
1956 | 15.5k | ACCT_INFO("greater_flags", "col_mv_greater_flags_cdf")); |
1957 | 15.5k | if (!this_bit) |
1958 | 5.76k | scaled_mv_col = this_pair_index; |
1959 | 9.78k | else |
1960 | 9.78k | scaled_mv_col = shell_index - this_pair_index; |
1961 | 15.5k | } |
1962 | | |
1963 | 18.8k | scaled_mv_diff.col = scaled_mv_col; |
1964 | 18.8k | scaled_mv_diff.row = shell_index - scaled_mv_diff.col; |
1965 | 18.8k | assert(scaled_mv_diff.row >= 0 && scaled_mv_diff.col >= 0); |
1966 | 18.8k | } else { |
1967 | 3.27k | scaled_mv_diff.row = 0; |
1968 | 3.27k | scaled_mv_diff.col = 0; |
1969 | 3.27k | } |
1970 | | |
1971 | 22.0k | int start_lsb = (MV_PRECISION_ONE_EIGHTH_PEL - precision); |
1972 | 22.0k | mv_diff->row = scaled_mv_diff.row << start_lsb; |
1973 | 22.0k | mv_diff->col = scaled_mv_diff.col << start_lsb; |
1974 | | |
1975 | 22.0k | (void)skip_sign_coding; |
1976 | 22.0k | } |
1977 | | |
1978 | | static REFERENCE_MODE read_block_reference_mode(AV2_COMMON *cm, |
1979 | | const MACROBLOCKD *xd, |
1980 | 13 | avm_reader *r) { |
1981 | 13 | if (!is_comp_ref_allowed(xd->mi[0]->sb_type[PLANE_TYPE_Y])) |
1982 | 0 | return SINGLE_REFERENCE; |
1983 | 13 | if (cm->current_frame.reference_mode == REFERENCE_MODE_SELECT) { |
1984 | 8 | const int ctx = av2_get_reference_mode_context(cm, xd); |
1985 | 8 | const REFERENCE_MODE mode = (REFERENCE_MODE)avm_read_symbol( |
1986 | 8 | r, xd->tile_ctx->comp_inter_cdf[ctx], 2, ACCT_INFO()); |
1987 | 8 | return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE |
1988 | 8 | } else { |
1989 | 5 | assert(cm->current_frame.reference_mode == SINGLE_REFERENCE); |
1990 | 5 | return cm->current_frame.reference_mode; |
1991 | 5 | } |
1992 | 13 | } |
1993 | | |
1994 | | static AVM_INLINE void read_single_ref( |
1995 | | MACROBLOCKD *const xd, MV_REFERENCE_FRAME ref_frame[2], |
1996 | 11 | const RefFramesInfo *const ref_frames_info, avm_reader *r) { |
1997 | 11 | const int n_refs = ref_frames_info->num_total_refs; |
1998 | 11 | for (int i = 0; i < n_refs - 1; i++) { |
1999 | 0 | const int bit = avm_read_symbol( |
2000 | 0 | r, av2_get_pred_cdf_single_ref(xd, i, n_refs), 2, ACCT_INFO()); |
2001 | 0 | if (bit) { |
2002 | 0 | ref_frame[0] = i; |
2003 | 0 | return; |
2004 | 0 | } |
2005 | 0 | } |
2006 | 11 | ref_frame[0] = n_refs - 1; |
2007 | 11 | } |
2008 | | |
2009 | | static AVM_INLINE void read_compound_ref( |
2010 | | const MACROBLOCKD *xd, MV_REFERENCE_FRAME ref_frame[2], |
2011 | 2 | const RefFramesInfo *const ref_frames_info, avm_reader *r) { |
2012 | 2 | const int n_refs = ref_frames_info->num_total_refs; |
2013 | 2 | int n_bits = 0; |
2014 | | |
2015 | 2 | int may_have_same_ref_comp = ref_frames_info->num_same_ref_compound > 0; |
2016 | 2 | for (int i = 0; |
2017 | 4 | (i < n_refs + n_bits - 2 || may_have_same_ref_comp) && n_bits < 2; i++) { |
2018 | | // bit_type: -1 for ref0, 0 for opposite sided ref1, 1 for same sided ref1 |
2019 | 2 | const int bit_type = n_bits == 0 ? -1 |
2020 | 2 | : av2_get_compound_ref_bit_type( |
2021 | 0 | ref_frames_info, ref_frame[0], i); |
2022 | | // Implicitly signal a 1 in either case: |
2023 | | // 1) ref0 = RANKED_REF0_TO_PRUNE - 1 |
2024 | | // 2) no reference is signaled yet, the next ref is not allowed for same |
2025 | | // ref compound, and there are only two references left (this case |
2026 | | // should only be met when same ref compound is on, where the |
2027 | | // following bit may be 0 or 1). |
2028 | 2 | int implicit_ref0_bit1 = n_bits == 0 && i >= RANKED_REF0_TO_PRUNE - 1; |
2029 | 2 | implicit_ref0_bit1 |= n_bits == 0 && i >= n_refs - 2 && |
2030 | 2 | i + 1 >= ref_frames_info->num_same_ref_compound; |
2031 | 2 | assert(IMPLIES(n_bits == 0 && i >= n_refs - 2, |
2032 | 2 | i < ref_frames_info->num_same_ref_compound)); |
2033 | 2 | const int bit = implicit_ref0_bit1 |
2034 | 2 | ? 1 |
2035 | 2 | : avm_read_symbol(r, |
2036 | 2 | av2_get_pred_cdf_compound_ref( |
2037 | 2 | xd, i, n_bits, bit_type, n_refs), |
2038 | 2 | 2, ACCT_INFO()); |
2039 | 2 | if (bit) ref_frame[n_bits++] = i; |
2040 | 2 | if (i < ref_frames_info->num_same_ref_compound && may_have_same_ref_comp) { |
2041 | 2 | may_have_same_ref_comp = |
2042 | 2 | !bit && i + 1 < ref_frames_info->num_same_ref_compound; |
2043 | 2 | i -= bit; |
2044 | 2 | } else { |
2045 | 0 | may_have_same_ref_comp = 0; |
2046 | 0 | } |
2047 | 2 | } |
2048 | 2 | if (n_bits < 2) ref_frame[1] = n_refs - 1; |
2049 | 2 | if (n_bits < 1) |
2050 | 0 | ref_frame[0] = (ref_frames_info->num_same_ref_compound > 0 && |
2051 | 0 | n_refs - 1 < ref_frames_info->num_same_ref_compound) |
2052 | 0 | ? n_refs - 1 |
2053 | 0 | : n_refs - 2; |
2054 | | // TODO(kslu) This is a workaround for the corner case where |
2055 | | // num_same_ref_compound = 0 and n_refs = 1. Change the frame header syntax |
2056 | | // to disallow the use of REFERENCE_MODE_SELECT for this case. |
2057 | 2 | if (ref_frame[0] == NONE_FRAME) ref_frame[0] = 0; |
2058 | 2 | } |
2059 | | |
2060 | | static void set_ref_frames_for_skip_mode(AV2_COMMON *const cm, |
2061 | | const MACROBLOCKD *const xd, |
2062 | 0 | MV_REFERENCE_FRAME ref_frame[2]) { |
2063 | 0 | set_skip_mode_ref_frame(cm, xd, ref_frame); |
2064 | 0 | } |
2065 | | |
2066 | | // Read the reference frame |
2067 | | static void read_ref_frames(AV2_COMMON *const cm, MACROBLOCKD *const xd, |
2068 | | avm_reader *r, int segment_id, |
2069 | 13 | MV_REFERENCE_FRAME ref_frame[2]) { |
2070 | 13 | if (xd->mi[0]->skip_mode) { |
2071 | 0 | set_ref_frames_for_skip_mode(cm, xd, ref_frame); |
2072 | 0 | return; |
2073 | 0 | } |
2074 | | |
2075 | 13 | ref_frame[0] = NONE_FRAME; |
2076 | 13 | ref_frame[1] = NONE_FRAME; |
2077 | 13 | if (is_tip_allowed(cm, xd)) { |
2078 | 0 | const int tip_ctx = get_tip_ctx(xd); |
2079 | 0 | if (avm_read_symbol(r, xd->tile_ctx->tip_cdf[tip_ctx], 2, |
2080 | 0 | ACCT_INFO("tip_cdf"))) { |
2081 | 0 | ref_frame[0] = TIP_FRAME; |
2082 | 0 | } |
2083 | 0 | } |
2084 | | |
2085 | 13 | if (is_tip_ref_frame(ref_frame[0])) return; |
2086 | | |
2087 | 13 | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP) || |
2088 | 13 | segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) { |
2089 | 0 | ref_frame[0] = get_closest_pastcur_ref_or_ref0(cm); |
2090 | 0 | ref_frame[1] = NONE_FRAME; |
2091 | 13 | } else { |
2092 | 13 | const REFERENCE_MODE mode = read_block_reference_mode(cm, xd, r); |
2093 | | |
2094 | 13 | if (mode == COMPOUND_REFERENCE) { |
2095 | 2 | read_compound_ref(xd, ref_frame, &cm->ref_frames_info, r); |
2096 | 11 | } else if (mode == SINGLE_REFERENCE) { |
2097 | 11 | read_single_ref(xd, ref_frame, &cm->ref_frames_info, r); |
2098 | 11 | ref_frame[1] = NONE_FRAME; |
2099 | 11 | } else { |
2100 | 0 | assert(0 && "Invalid prediction mode."); |
2101 | 0 | } |
2102 | 13 | } |
2103 | 13 | } |
2104 | | |
2105 | | static INLINE void read_mb_interp_filter(const MACROBLOCKD *const xd, |
2106 | | InterpFilter interp_filter, |
2107 | | const AV2_COMMON *cm, |
2108 | | MB_MODE_INFO *const mbmi, |
2109 | 13 | avm_reader *r) { |
2110 | 13 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
2111 | | |
2112 | 13 | if (!av2_is_interp_needed(cm, xd)) { |
2113 | 7 | set_default_interp_filters(mbmi, cm, xd, interp_filter); |
2114 | 7 | return; |
2115 | 7 | } |
2116 | | |
2117 | 6 | if (interp_filter != SWITCHABLE) { |
2118 | 6 | mbmi->interp_fltr = interp_filter; |
2119 | 6 | } else { |
2120 | 0 | const int ctx = av2_get_pred_context_switchable_interp(xd); |
2121 | 0 | const InterpFilter filter = (InterpFilter)avm_read_symbol( |
2122 | 0 | r, ec_ctx->switchable_interp_cdf[ctx], SWITCHABLE_FILTERS, |
2123 | 0 | ACCT_INFO("switchable_interp_cdf")); |
2124 | 0 | mbmi->interp_fltr = filter; |
2125 | 0 | } |
2126 | 6 | } |
2127 | | |
2128 | | static void read_intra_block_mode_info(AV2_COMMON *const cm, |
2129 | | MACROBLOCKD *const xd, |
2130 | | MB_MODE_INFO *const mbmi, |
2131 | 0 | avm_reader *r) { |
2132 | 0 | const BLOCK_SIZE bsize = mbmi->sb_type[xd->tree_type == CHROMA_PART]; |
2133 | |
|
2134 | 0 | mbmi->ref_frame[0] = INTRA_FRAME; |
2135 | 0 | mbmi->ref_frame[1] = NONE_FRAME; |
2136 | |
|
2137 | 0 | set_default_max_mv_precision(mbmi, xd->sbi->sb_mv_precision); |
2138 | 0 | set_mv_precision(mbmi, mbmi->max_mv_precision); |
2139 | 0 | set_default_precision_set(cm, mbmi, bsize); |
2140 | 0 | set_most_probable_mv_precision(cm, mbmi, bsize); |
2141 | |
|
2142 | 0 | mbmi->bawp_flag[0] = 0; |
2143 | 0 | mbmi->bawp_flag[1] = 0; |
2144 | 0 | mbmi->refinemv_flag = 0; |
2145 | | |
2146 | | // Reset to avoid potential bug for warp mode context modeling |
2147 | 0 | mbmi->motion_mode = SIMPLE_TRANSLATION; |
2148 | |
|
2149 | 0 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
2150 | |
|
2151 | 0 | if (xd->tree_type != CHROMA_PART) { |
2152 | 0 | if (xd->lossless[mbmi->segment_id]) { |
2153 | 0 | mbmi->use_dpcm_y = read_dpcm_mode(ec_ctx, r); |
2154 | 0 | if (mbmi->use_dpcm_y == 0) { |
2155 | 0 | read_intra_luma_mode(xd, r); |
2156 | 0 | } else { |
2157 | 0 | mbmi->dpcm_mode_y = read_dpcm_vert_horz_mode(ec_ctx, r); |
2158 | 0 | if (mbmi->dpcm_mode_y == 0) { |
2159 | 0 | mbmi->joint_y_mode_delta_angle = 22; |
2160 | 0 | mbmi->mode = V_PRED; |
2161 | 0 | mbmi->angle_delta[0] = 0; |
2162 | 0 | } else { |
2163 | 0 | mbmi->joint_y_mode_delta_angle = 50; |
2164 | 0 | mbmi->mode = H_PRED; |
2165 | 0 | mbmi->angle_delta[0] = 0; |
2166 | 0 | } |
2167 | 0 | } |
2168 | 0 | } else { |
2169 | 0 | mbmi->use_dpcm_y = 0; |
2170 | 0 | mbmi->dpcm_mode_y = 0; |
2171 | 0 | read_intra_luma_mode(xd, r); |
2172 | 0 | } |
2173 | 0 | } |
2174 | |
|
2175 | 0 | if (allow_fsc_intra(cm, bsize, mbmi) && xd->tree_type != CHROMA_PART) { |
2176 | 0 | avm_cdf_prob *fsc_cdf = |
2177 | 0 | get_fsc_mode_cdf(xd, bsize, mbmi->region_type == INTRA_REGION); |
2178 | 0 | mbmi->fsc_mode[xd->tree_type == CHROMA_PART] = read_fsc_mode(r, fsc_cdf); |
2179 | 0 | } else { |
2180 | 0 | mbmi->fsc_mode[xd->tree_type == CHROMA_PART] = 0; |
2181 | 0 | } |
2182 | |
|
2183 | 0 | if (xd->tree_type != CHROMA_PART) |
2184 | | // Parsing reference line index |
2185 | 0 | { |
2186 | 0 | if (xd->lossless[mbmi->segment_id]) { |
2187 | 0 | if (mbmi->use_dpcm_y == 0) { |
2188 | 0 | mbmi->mrl_index = |
2189 | 0 | (cm->seq_params.enable_mrls && av2_is_directional_mode(mbmi->mode)) |
2190 | 0 | ? read_mrl_index(ec_ctx, r, xd->neighbors[0], xd->neighbors[1]) |
2191 | 0 | : 0; |
2192 | 0 | if (mbmi->mrl_index) { |
2193 | 0 | mbmi->multi_line_mrl = read_multi_line_mrl( |
2194 | 0 | ec_ctx, r, xd->neighbors[0], xd->neighbors[1]); |
2195 | 0 | } else { |
2196 | 0 | mbmi->multi_line_mrl = 0; |
2197 | 0 | } |
2198 | 0 | } else { |
2199 | 0 | mbmi->mrl_index = 0; |
2200 | 0 | mbmi->multi_line_mrl = 0; |
2201 | 0 | } |
2202 | 0 | } else { |
2203 | 0 | mbmi->mrl_index = |
2204 | 0 | (cm->seq_params.enable_mrls && av2_is_directional_mode(mbmi->mode)) |
2205 | 0 | ? read_mrl_index(ec_ctx, r, xd->neighbors[0], xd->neighbors[1]) |
2206 | 0 | : 0; |
2207 | 0 | if (mbmi->mrl_index) { |
2208 | 0 | mbmi->multi_line_mrl = |
2209 | 0 | read_multi_line_mrl(ec_ctx, r, xd->neighbors[0], xd->neighbors[1]); |
2210 | 0 | } else { |
2211 | 0 | mbmi->multi_line_mrl = 0; |
2212 | 0 | } |
2213 | 0 | } |
2214 | 0 | } |
2215 | |
|
2216 | 0 | if (!cm->seq_params.monochrome && xd->is_chroma_ref && |
2217 | 0 | xd->tree_type != LUMA_PART) { |
2218 | 0 | if (xd->lossless[mbmi->segment_id]) { |
2219 | 0 | mbmi->use_dpcm_uv = read_dpcm_uv_mode(ec_ctx, r); |
2220 | 0 | if (mbmi->use_dpcm_uv == 0) { |
2221 | 0 | read_intra_uv_mode( |
2222 | 0 | xd, |
2223 | 0 | is_cfl_allowed(cm->seq_params.enable_cfl_intra, xd) || |
2224 | 0 | is_mhccp_allowed(cm, xd), |
2225 | 0 | r); |
2226 | 0 | mbmi->dpcm_mode_uv = 0; |
2227 | 0 | } else { |
2228 | 0 | get_uv_intra_mode_set(mbmi); |
2229 | 0 | mbmi->dpcm_mode_uv = read_dpcm_uv_vert_horz_mode(ec_ctx, r); |
2230 | 0 | mbmi->uv_mode = mbmi->dpcm_mode_uv + 1; |
2231 | 0 | if (mbmi->uv_mode == mbmi->mode) |
2232 | 0 | mbmi->angle_delta[PLANE_TYPE_UV] = mbmi->angle_delta[PLANE_TYPE_Y]; |
2233 | 0 | else |
2234 | 0 | mbmi->angle_delta[PLANE_TYPE_UV] = 0; |
2235 | 0 | } |
2236 | 0 | } else { |
2237 | 0 | mbmi->use_dpcm_uv = 0; |
2238 | 0 | mbmi->dpcm_mode_uv = 0; |
2239 | 0 | read_intra_uv_mode(xd, |
2240 | 0 | is_cfl_allowed(cm->seq_params.enable_cfl_intra, xd) || |
2241 | 0 | is_mhccp_allowed(cm, xd), |
2242 | 0 | r); |
2243 | 0 | } |
2244 | |
|
2245 | 0 | if (mbmi->uv_mode == UV_CFL_PRED) { |
2246 | 0 | { |
2247 | 0 | if (is_mhccp_allowed(cm, xd)) { |
2248 | 0 | int cfl_mhccp_switch = 1; |
2249 | 0 | if (cm->seq_params.enable_cfl_intra) |
2250 | 0 | cfl_mhccp_switch = read_cfl_mhccp_switch(ec_ctx, r); |
2251 | 0 | if (cfl_mhccp_switch) { |
2252 | 0 | mbmi->cfl_idx = CFL_MULTI_PARAM; |
2253 | 0 | } else { |
2254 | 0 | mbmi->cfl_idx = read_cfl_index(ec_ctx, r); |
2255 | 0 | } |
2256 | 0 | } else if (cm->seq_params.enable_cfl_intra) { |
2257 | 0 | mbmi->cfl_idx = read_cfl_index(ec_ctx, r); |
2258 | 0 | } |
2259 | 0 | if (mbmi->cfl_idx == CFL_MULTI_PARAM) { |
2260 | 0 | const uint8_t mh_size_group = size_group_lookup[bsize]; |
2261 | 0 | avm_cdf_prob *mh_dir_cdf = ec_ctx->filter_dir_cdf[mh_size_group]; |
2262 | 0 | mbmi->mh_dir = read_mh_dir(mh_dir_cdf, r); |
2263 | 0 | } |
2264 | 0 | } |
2265 | 0 | if (mbmi->cfl_idx == 0) { |
2266 | 0 | mbmi->cfl_alpha_idx = |
2267 | 0 | read_cfl_alphas(xd->tile_ctx, r, &mbmi->cfl_alpha_signs); |
2268 | 0 | } |
2269 | 0 | } |
2270 | 0 | } else { |
2271 | | // Avoid decoding angle_info if there is is no chroma prediction |
2272 | 0 | mbmi->uv_mode = UV_DC_PRED; |
2273 | 0 | } |
2274 | 0 | if (xd->tree_type != LUMA_PART) xd->cfl.store_y = store_cfl_required(cm, xd); |
2275 | 0 | if (xd->tree_type != CHROMA_PART) mbmi->palette_mode_info.palette_size[0] = 0; |
2276 | 0 | mbmi->palette_mode_info.palette_size[1] = 0; |
2277 | 0 | if (av2_allow_palette(PLANE_TYPE_Y, cm->features.allow_screen_content_tools, |
2278 | 0 | bsize)) |
2279 | 0 | read_palette_mode_info(cm, xd, r); |
2280 | 0 | if (xd->tree_type != CHROMA_PART) { |
2281 | 0 | mbmi->use_intra_dip = 0; |
2282 | 0 | read_intra_dip_mode_info(cm, xd, r); |
2283 | 0 | } |
2284 | 0 | } |
2285 | | |
2286 | | static INLINE int assign_mv(AV2_COMMON *cm, MACROBLOCKD *xd, |
2287 | | PREDICTION_MODE mode, |
2288 | | MV_REFERENCE_FRAME ref_frame[2], int_mv mv[2], |
2289 | | int_mv ref_mv[2], int is_compound, |
2290 | 13 | MvSubpelPrecision precision, avm_reader *r) { |
2291 | 13 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
2292 | 13 | MB_MODE_INFO *mbmi = xd->mi[0]; |
2293 | 13 | BLOCK_SIZE bsize = mbmi->sb_type[PLANE_TYPE_Y]; |
2294 | 13 | FeatureFlags *const features = &cm->features; |
2295 | 13 | assert(IMPLIES(features->cur_frame_force_integer_mv, |
2296 | 13 | precision == MV_PRECISION_ONE_PEL)); |
2297 | 13 | int first_ref_dist = 0; |
2298 | 13 | int sec_ref_dist = 0; |
2299 | 13 | const int same_side = is_ref_frame_same_side(cm, mbmi); |
2300 | 13 | const int jmvd_base_ref_list = get_joint_mvd_base_ref_list(cm, mbmi); |
2301 | | // check whether joint mvd is applied or not |
2302 | 13 | if (is_joint_mvd_coding_mode(mbmi->mode)) { |
2303 | 0 | first_ref_dist = |
2304 | 0 | cm->ref_frame_relative_dist[mbmi->ref_frame[jmvd_base_ref_list]]; |
2305 | 0 | sec_ref_dist = |
2306 | 0 | cm->ref_frame_relative_dist[mbmi->ref_frame[1 - jmvd_base_ref_list]]; |
2307 | 0 | assert(first_ref_dist >= sec_ref_dist); |
2308 | 0 | } |
2309 | 13 | const int is_adaptive_mvd = enable_adaptive_mvd_resolution(cm, mbmi); |
2310 | 13 | assert(!(is_adaptive_mvd && is_pb_mv_precision_active(cm, mbmi, bsize))); |
2311 | 13 | MV mv_diff[2] = { kZeroMv, kZeroMv }; |
2312 | 13 | int num_signaled_mvd = 0; |
2313 | 13 | int start_signaled_mvd_idx = 0; |
2314 | 13 | int is_joint_mv_mode = 0; |
2315 | | |
2316 | 13 | switch (mode) { |
2317 | 5 | case WARP_NEWMV: |
2318 | 7 | case NEWMV: { |
2319 | 7 | nmv_context *const nmvc = &ec_ctx->nmvc; |
2320 | 7 | num_signaled_mvd = 1; |
2321 | 7 | start_signaled_mvd_idx = 0; |
2322 | 7 | read_mv(r, &mv_diff[0], 1, nmvc, precision, is_adaptive_mvd); |
2323 | 7 | break; |
2324 | 5 | } |
2325 | 2 | case NEARMV: { |
2326 | 2 | mv[0].as_int = ref_mv[0].as_int; |
2327 | 2 | break; |
2328 | 5 | } |
2329 | | |
2330 | 2 | case WARPMV: { |
2331 | 2 | mbmi->mv[0] = ref_mv[0]; |
2332 | 2 | if (mbmi->warpmv_with_mvd_flag) { |
2333 | 2 | nmv_context *const nmvc = &ec_ctx->nmvc; |
2334 | 2 | num_signaled_mvd = 1; |
2335 | 2 | start_signaled_mvd_idx = 0; |
2336 | 2 | read_mv(r, &mv_diff[0], 1, nmvc, precision, is_adaptive_mvd); |
2337 | 2 | } |
2338 | | |
2339 | 2 | break; |
2340 | 5 | } |
2341 | | |
2342 | 0 | case GLOBALMV: { |
2343 | | // Global motion is never used for the TIP ref frame |
2344 | 0 | if (is_tip_ref_frame(ref_frame[0])) { |
2345 | 0 | mv[0].as_int = 0; |
2346 | 0 | } else { |
2347 | 0 | mv[0].as_int = |
2348 | 0 | get_warp_motion_vector(xd, &cm->global_motion[ref_frame[0]], |
2349 | 0 | features->fr_mv_precision, bsize, xd->mi_col, |
2350 | 0 | xd->mi_row) |
2351 | 0 | .as_int; |
2352 | 0 | } |
2353 | 0 | break; |
2354 | 5 | } |
2355 | 1 | case NEW_NEWMV: |
2356 | 1 | case NEW_NEWMV_OPTFLOW: { |
2357 | 1 | assert(is_compound); |
2358 | 1 | num_signaled_mvd = 2; |
2359 | 1 | start_signaled_mvd_idx = 0; |
2360 | 3 | for (int i = 0; i < 2; ++i) { |
2361 | 2 | nmv_context *const nmvc = &ec_ctx->nmvc; |
2362 | 2 | read_mv(r, &mv_diff[i], 1, nmvc, precision, is_adaptive_mvd); |
2363 | 2 | } |
2364 | 1 | break; |
2365 | 1 | } |
2366 | 0 | case NEAR_NEARMV: |
2367 | 0 | case NEAR_NEARMV_OPTFLOW: { |
2368 | 0 | assert(is_compound); |
2369 | 0 | mv[0].as_int = ref_mv[0].as_int; |
2370 | 0 | mv[1].as_int = ref_mv[1].as_int; |
2371 | 0 | break; |
2372 | 0 | } |
2373 | 1 | case NEAR_NEWMV: |
2374 | 1 | case NEAR_NEWMV_OPTFLOW: { |
2375 | 1 | nmv_context *const nmvc = &ec_ctx->nmvc; |
2376 | 1 | mv[0].as_int = ref_mv[0].as_int; |
2377 | 1 | num_signaled_mvd = 1; |
2378 | 1 | start_signaled_mvd_idx = 1; |
2379 | 1 | read_mv(r, &mv_diff[1], 1, nmvc, precision, is_adaptive_mvd); |
2380 | 1 | assert(is_compound); |
2381 | 1 | break; |
2382 | 1 | } |
2383 | 0 | case NEW_NEARMV: |
2384 | 0 | case NEW_NEARMV_OPTFLOW: { |
2385 | 0 | nmv_context *const nmvc = &ec_ctx->nmvc; |
2386 | 0 | assert(is_compound); |
2387 | 0 | mv[1].as_int = ref_mv[1].as_int; |
2388 | 0 | num_signaled_mvd = 1; |
2389 | 0 | start_signaled_mvd_idx = 0; |
2390 | 0 | read_mv(r, &mv_diff[0], 1, nmvc, precision, is_adaptive_mvd); |
2391 | 0 | break; |
2392 | 0 | } |
2393 | 0 | case GLOBAL_GLOBALMV: { |
2394 | 0 | assert(is_compound); |
2395 | 0 | assert(!is_tip_ref_frame(ref_frame[0])); |
2396 | 0 | mv[0].as_int = |
2397 | 0 | get_warp_motion_vector(xd, &cm->global_motion[ref_frame[0]], |
2398 | 0 | features->fr_mv_precision, bsize, xd->mi_col, |
2399 | 0 | xd->mi_row) |
2400 | 0 | .as_int; |
2401 | 0 | mv[1].as_int = |
2402 | 0 | get_warp_motion_vector(xd, &cm->global_motion[ref_frame[1]], |
2403 | 0 | features->fr_mv_precision, bsize, xd->mi_col, |
2404 | 0 | xd->mi_row) |
2405 | 0 | .as_int; |
2406 | 0 | break; |
2407 | 0 | } |
2408 | 0 | case JOINT_NEWMV_OPTFLOW: |
2409 | 0 | case JOINT_NEWMV: { |
2410 | 0 | nmv_context *const nmvc = &ec_ctx->nmvc; |
2411 | 0 | assert(is_compound); |
2412 | 0 | mv[1 - jmvd_base_ref_list].as_int = ref_mv[1 - jmvd_base_ref_list].as_int; |
2413 | 0 | is_joint_mv_mode = 1; |
2414 | 0 | num_signaled_mvd = 1; |
2415 | 0 | start_signaled_mvd_idx = jmvd_base_ref_list; |
2416 | 0 | read_mv(r, &mv_diff[jmvd_base_ref_list], 1, nmvc, precision, |
2417 | 0 | is_adaptive_mvd); |
2418 | 0 | break; |
2419 | 0 | } |
2420 | 0 | default: { |
2421 | 0 | return 0; |
2422 | 0 | } |
2423 | 13 | } |
2424 | | |
2425 | 13 | if (num_signaled_mvd > 0) { |
2426 | 11 | int last_ref = -1; |
2427 | 11 | int last_comp = -1; |
2428 | 11 | uint16_t sum_mvd = 0; |
2429 | 11 | int precision_shift = MV_PRECISION_ONE_EIGHTH_PEL - precision; |
2430 | 11 | int th_for_num_nonzero = get_derive_sign_nzero_th(mbmi); |
2431 | 11 | uint8_t num_nonzero_mvd_comp = 0; |
2432 | 11 | uint8_t enable_sign_derive = 0; |
2433 | 11 | if (is_mvd_sign_derive_allowed(cm, xd, mbmi)) { |
2434 | 2 | for (int ref_idx = start_signaled_mvd_idx; |
2435 | 5 | ref_idx < start_signaled_mvd_idx + num_signaled_mvd; ++ref_idx) { |
2436 | 3 | assert(ref_idx == 0 || ref_idx == 1); |
2437 | 9 | for (int comp = 0; comp < 2; comp++) { |
2438 | 6 | int this_mvd_comp = |
2439 | 6 | comp == 0 ? mv_diff[ref_idx].row : mv_diff[ref_idx].col; |
2440 | 6 | assert(this_mvd_comp >= 0); |
2441 | 6 | if (this_mvd_comp) { |
2442 | 4 | last_ref = ref_idx; |
2443 | 4 | last_comp = comp; |
2444 | 4 | sum_mvd += (this_mvd_comp >> precision_shift); |
2445 | 4 | num_nonzero_mvd_comp++; |
2446 | 4 | } |
2447 | 6 | } |
2448 | 3 | } |
2449 | 2 | if (num_nonzero_mvd_comp >= th_for_num_nonzero) enable_sign_derive = 1; |
2450 | 2 | } |
2451 | | |
2452 | | // Decode sign |
2453 | 11 | for (int ref_idx = start_signaled_mvd_idx; |
2454 | 23 | ref_idx < start_signaled_mvd_idx + num_signaled_mvd; ++ref_idx) { |
2455 | 12 | assert(ref_idx == 0 || ref_idx == 1); |
2456 | | |
2457 | 36 | for (int comp = 0; comp < 2; comp++) { |
2458 | 24 | int this_mvd_comp = |
2459 | 24 | comp == 0 ? mv_diff[ref_idx].row : mv_diff[ref_idx].col; |
2460 | 24 | assert(this_mvd_comp >= 0); |
2461 | | |
2462 | 24 | if (this_mvd_comp != 0) { |
2463 | 17 | assert(this_mvd_comp > 0); |
2464 | 17 | int sign = 0; |
2465 | 17 | if (enable_sign_derive && |
2466 | 2 | (ref_idx == last_ref && comp == last_comp)) { |
2467 | 1 | sign = (sum_mvd & 0x1); |
2468 | 16 | } else { |
2469 | 16 | sign = avm_read_literal(r, 1, ACCT_INFO("sign")); |
2470 | 16 | } |
2471 | 17 | if (sign) { |
2472 | 8 | if (comp == 0) |
2473 | 4 | mv_diff[ref_idx].row = -1 * this_mvd_comp; |
2474 | 4 | else |
2475 | 4 | mv_diff[ref_idx].col = -1 * this_mvd_comp; |
2476 | 8 | } |
2477 | 17 | } |
2478 | 24 | } |
2479 | 12 | } |
2480 | | |
2481 | 11 | for (int ref_idx = start_signaled_mvd_idx; |
2482 | 23 | ref_idx < (num_signaled_mvd + start_signaled_mvd_idx); ref_idx++) { |
2483 | 12 | MV low_prec_refmv = ref_mv[ref_idx].as_mv; |
2484 | 12 | if (!is_adaptive_mvd && precision < MV_PRECISION_HALF_PEL) |
2485 | 4 | lower_mv_precision(&low_prec_refmv, precision); |
2486 | 12 | mv[ref_idx].as_mv.row = low_prec_refmv.row + mv_diff[ref_idx].row; |
2487 | 12 | mv[ref_idx].as_mv.col = low_prec_refmv.col + mv_diff[ref_idx].col; |
2488 | 12 | } |
2489 | | |
2490 | 11 | if (is_joint_mv_mode) { |
2491 | 0 | sec_ref_dist = same_side ? sec_ref_dist : -sec_ref_dist; |
2492 | 0 | MV other_mvd = { 0, 0 }; |
2493 | 0 | MV diff = { 0, 0 }; |
2494 | 0 | MV low_prec_refmv = ref_mv[jmvd_base_ref_list].as_mv; |
2495 | 0 | if (!is_adaptive_mvd && precision < MV_PRECISION_HALF_PEL) |
2496 | 0 | lower_mv_precision(&low_prec_refmv, precision); |
2497 | 0 | diff.row = mv[jmvd_base_ref_list].as_mv.row - low_prec_refmv.row; |
2498 | 0 | diff.col = mv[jmvd_base_ref_list].as_mv.col - low_prec_refmv.col; |
2499 | 0 | get_mv_projection(&other_mvd, diff, sec_ref_dist, first_ref_dist); |
2500 | 0 | scale_other_mvd(&other_mvd, mbmi->jmvd_scale_mode, mbmi->mode, |
2501 | 0 | mbmi->use_amvd); |
2502 | 0 | mv[1 - jmvd_base_ref_list].as_mv.row = |
2503 | 0 | (int)(ref_mv[1 - jmvd_base_ref_list].as_mv.row + other_mvd.row); |
2504 | 0 | mv[1 - jmvd_base_ref_list].as_mv.col = |
2505 | 0 | (int)(ref_mv[1 - jmvd_base_ref_list].as_mv.col + other_mvd.col); |
2506 | 0 | } |
2507 | 11 | } |
2508 | | |
2509 | 13 | mv_clamp_to_integer(&mv[0].as_mv); |
2510 | 13 | if (is_compound) { |
2511 | 2 | mv_clamp_to_integer(&mv[1].as_mv); |
2512 | 2 | } |
2513 | | |
2514 | 13 | return 1; |
2515 | 13 | } |
2516 | | |
2517 | | static int read_is_inter_block(AV2_COMMON *const cm, MACROBLOCKD *const xd, |
2518 | 13 | int segment_id, avm_reader *r) { |
2519 | 13 | if (xd->mi[0]->sb_type[PLANE_TYPE_Y] == BLOCK_4X4) { |
2520 | 0 | return 0; |
2521 | 0 | } |
2522 | 13 | if (xd->mi[0]->region_type == INTRA_REGION) return 0; |
2523 | 13 | if (segfeature_active(&cm->seg, segment_id, SEG_LVL_GLOBALMV)) { |
2524 | 0 | return 1; |
2525 | 0 | } |
2526 | 13 | MB_MODE_INFO *const mbmi = xd->mi[0]; |
2527 | 13 | if (mbmi->tree_type == SHARED_PART && |
2528 | 13 | mbmi->region_type == MIXED_INTER_INTRA_REGION && |
2529 | 13 | mbmi->chroma_ref_info.offset_started) { |
2530 | 0 | return 1; |
2531 | 0 | } |
2532 | 13 | const int ctx = av2_get_intra_inter_context(xd); |
2533 | 13 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
2534 | 13 | const int is_inter = |
2535 | 13 | avm_read_symbol(r, ec_ctx->intra_inter_cdf[ctx], 2, ACCT_INFO()); |
2536 | 13 | return is_inter; |
2537 | 13 | } |
2538 | | |
2539 | | #if DEC_MISMATCH_DEBUG |
2540 | | static void dec_dump_logs(AV2_COMMON *cm, MB_MODE_INFO *const mbmi, int mi_row, |
2541 | | int mi_col, int16_t mode_ctx) { |
2542 | | int_mv mv[2] = { { 0 } }; |
2543 | | for (int ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) |
2544 | | mv[ref].as_mv = mbmi->mv[ref].as_mv; |
2545 | | |
2546 | | const int16_t newmv_ctx = mode_ctx & NEWMV_CTX_MASK; |
2547 | | int16_t zeromv_ctx = -1; |
2548 | | int16_t refmv_ctx = -1; |
2549 | | if (mbmi->mode != NEWMV) { |
2550 | | zeromv_ctx = (mode_ctx >> GLOBALMV_OFFSET) & GLOBALMV_CTX_MASK; |
2551 | | if (mbmi->mode != GLOBALMV) |
2552 | | refmv_ctx = (mode_ctx >> REFMV_OFFSET) & REFMV_CTX_MASK; |
2553 | | } |
2554 | | |
2555 | | #define FRAME_TO_CHECK 11 |
2556 | | if (cm->current_frame.frame_number == FRAME_TO_CHECK && |
2557 | | cm->immediate_output_picture == 1) { |
2558 | | printf( |
2559 | | "=== DECODER ===: " |
2560 | | "Frame=%d, (mi_row,mi_col)=(%d,%d), skip_mode=%d, mode=%d, bsize=%d, " |
2561 | | "immediate_output_picture=%d, mv[0]=(%d,%d), mv[1]=(%d,%d), ref[0]=%d, " |
2562 | | "ref[1]=%d, motion_mode=%d, mode_ctx=%d, " |
2563 | | "newmv_ctx=%d, zeromv_ctx=%d, refmv_ctx=%d, tx_size=%d\n", |
2564 | | cm->current_frame.frame_number, mi_row, mi_col, mbmi->skip_mode, |
2565 | | mbmi->mode, mbmi->sb_type, cm->immediate_output_picture, |
2566 | | mv[0].as_mv.row, mv[0].as_mv.col, mv[1].as_mv.row, mv[1].as_mv.col, |
2567 | | mbmi->ref_frame[0], mbmi->ref_frame[1], mbmi->motion_mode, mode_ctx, |
2568 | | newmv_ctx, zeromv_ctx, refmv_ctx, mbmi->tx_size); |
2569 | | } |
2570 | | } |
2571 | | #endif // DEC_MISMATCH_DEBUG |
2572 | | |
2573 | | // This function read the refinemv_flag ( if require) from the bitstream |
2574 | | static void read_refinemv_flag(AV2_COMMON *const cm, MACROBLOCKD *xd, |
2575 | 13 | avm_reader *r, BLOCK_SIZE bsize) { |
2576 | 13 | MB_MODE_INFO *const mbmi = xd->mi[0]; |
2577 | 13 | mbmi->refinemv_flag = get_default_refinemv_flag(cm, mbmi); |
2578 | 13 | int signal_refinemv = switchable_refinemv_flag(cm, mbmi); |
2579 | 13 | if (signal_refinemv) { |
2580 | 0 | const int refinemv_ctx = av2_get_refinemv_context(cm, xd, bsize); |
2581 | 0 | mbmi->refinemv_flag = |
2582 | 0 | avm_read_symbol(r, xd->tile_ctx->refinemv_flag_cdf[refinemv_ctx], |
2583 | 0 | REFINEMV_NUM_MODES, ACCT_INFO("refinemv_flag")); |
2584 | 0 | } |
2585 | 13 | } |
2586 | | |
2587 | | MvSubpelPrecision av2_read_pb_mv_precision(AV2_COMMON *const cm, |
2588 | | MACROBLOCKD *const xd, |
2589 | 6 | avm_reader *r) { |
2590 | 6 | MB_MODE_INFO *const mbmi = xd->mi[0]; |
2591 | 6 | assert(mbmi->max_mv_precision == |
2592 | 6 | av2_get_mbmi_max_mv_precision(cm, xd->sbi, mbmi)); |
2593 | 6 | assert(mbmi->max_mv_precision >= MV_PRECISION_HALF_PEL); |
2594 | 6 | const MvSubpelPrecision max_precision = mbmi->max_mv_precision; |
2595 | 6 | const int down_ctx = av2_get_pb_mv_precision_down_context(cm, xd); |
2596 | | |
2597 | 6 | assert(mbmi->most_probable_pb_mv_precision <= mbmi->max_mv_precision); |
2598 | 6 | assert(mbmi->most_probable_pb_mv_precision == |
2599 | 6 | cm->features.most_probable_fr_mv_precision); |
2600 | | |
2601 | 6 | const int mpp_flag_context = av2_get_mpp_flag_context(cm, xd); |
2602 | 6 | const int mpp_flag = |
2603 | 6 | avm_read_symbol(r, xd->tile_ctx->pb_mv_mpp_flag_cdf[mpp_flag_context], 2, |
2604 | 6 | ACCT_INFO("mpp_flag")); |
2605 | 6 | if (mpp_flag) return mbmi->most_probable_pb_mv_precision; |
2606 | 3 | const PRECISION_SET *precision_def = |
2607 | 3 | &av2_mv_precision_sets[mbmi->mb_precision_set]; |
2608 | 3 | int nsymbs = precision_def->num_precisions - 1; |
2609 | 3 | int down = avm_read_symbol( |
2610 | 3 | r, |
2611 | 3 | xd->tile_ctx->pb_mv_precision_cdf[down_ctx] |
2612 | 3 | [max_precision - MV_PRECISION_HALF_PEL], |
2613 | 3 | nsymbs, ACCT_INFO("down")); |
2614 | 3 | return av2_get_precision_from_index(mbmi, down); |
2615 | 6 | } |
2616 | | |
2617 | | static void read_inter_block_mode_info(AV2Decoder *const pbi, |
2618 | | DecoderCodingBlock *dcb, |
2619 | | MB_MODE_INFO *const mbmi, |
2620 | 13 | avm_reader *r) { |
2621 | 13 | AV2_COMMON *const cm = &pbi->common; |
2622 | 13 | FeatureFlags *const features = &cm->features; |
2623 | 13 | const BLOCK_SIZE bsize = mbmi->sb_type[PLANE_TYPE_Y]; |
2624 | 13 | int_mv ref_mv[2]; |
2625 | 13 | int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES] = { { { 0 } } }; |
2626 | 13 | int16_t inter_mode_ctx[MODE_CTX_REF_FRAMES]; |
2627 | 13 | int pts0[SAMPLES_ARRAY_SIZE], pts0_inref[SAMPLES_ARRAY_SIZE]; |
2628 | 13 | int pts1[SAMPLES_ARRAY_SIZE], pts1_inref[SAMPLES_ARRAY_SIZE]; |
2629 | 13 | MACROBLOCKD *const xd = &dcb->xd; |
2630 | | |
2631 | 13 | SB_INFO *sbi = xd->sbi; |
2632 | 13 | FRAME_CONTEXT *ec_ctx = xd->tile_ctx; |
2633 | | |
2634 | 13 | mbmi->uv_mode = UV_DC_PRED; |
2635 | 13 | mbmi->palette_mode_info.palette_size[0] = 0; |
2636 | 13 | mbmi->palette_mode_info.palette_size[1] = 0; |
2637 | 13 | mbmi->fsc_mode[PLANE_TYPE_Y] = 0; |
2638 | 13 | mbmi->fsc_mode[PLANE_TYPE_UV] = 0; |
2639 | 13 | mbmi->use_intrabc[0] = 0; |
2640 | 13 | mbmi->use_intrabc[1] = 0; |
2641 | 13 | mbmi->morph_pred = 0; |
2642 | | |
2643 | 13 | set_default_max_mv_precision(mbmi, sbi->sb_mv_precision); |
2644 | 13 | set_mv_precision(mbmi, mbmi->max_mv_precision); // initialize to max |
2645 | 13 | set_default_precision_set(cm, mbmi, bsize); |
2646 | 13 | set_most_probable_mv_precision(cm, mbmi, bsize); |
2647 | | |
2648 | 13 | mbmi->bawp_flag[0] = 0; |
2649 | 13 | mbmi->bawp_flag[1] = 0; |
2650 | 13 | mbmi->refinemv_flag = 0; |
2651 | | |
2652 | 13 | mbmi->num_proj_ref[0] = 0; // assume num_proj_ref >=1 |
2653 | 13 | mbmi->num_proj_ref[1] = 0; // assume num_proj_ref >=1 |
2654 | 13 | mbmi->wm_params[0].invalid = 1; |
2655 | 13 | mbmi->wm_params[1].invalid = 1; |
2656 | | |
2657 | 13 | av2_collect_neighbors_ref_counts(xd); |
2658 | | |
2659 | 13 | read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame); |
2660 | 13 | int is_compound = has_second_ref(mbmi); |
2661 | | |
2662 | 13 | const MV_REFERENCE_FRAME ref_frame = av2_ref_frame_type(mbmi->ref_frame); |
2663 | | |
2664 | 13 | av2_initialize_warp_wrl_list(xd->warp_param_stack, |
2665 | 13 | xd->valid_num_warp_candidates); |
2666 | | |
2667 | 13 | av2_find_mode_ctx(cm, xd, inter_mode_ctx, ref_frame); |
2668 | | |
2669 | 13 | mbmi->ref_mv_idx[0] = 0; |
2670 | 13 | mbmi->ref_mv_idx[1] = 0; |
2671 | | |
2672 | 13 | mbmi->cwp_idx = CWP_EQUAL; |
2673 | 13 | mbmi->jmvd_scale_mode = 0; |
2674 | | |
2675 | 13 | mbmi->warp_ref_idx = 0; |
2676 | 13 | mbmi->max_num_warp_candidates = 0; |
2677 | | |
2678 | 13 | mbmi->warpmv_with_mvd_flag = 0; |
2679 | 13 | mbmi->motion_mode = SIMPLE_TRANSLATION; |
2680 | 13 | WARP_CANDIDATE warp_param_stack[MAX_WARP_REF_CANDIDATES]; |
2681 | 13 | WarpedMotionParams ref_warp_model = default_warp_params; |
2682 | | |
2683 | 13 | mbmi->six_param_warp_model_flag = 0; |
2684 | | |
2685 | 13 | mbmi->warp_precision_idx = 0; |
2686 | 13 | mbmi->warp_inter_intra = 0; |
2687 | 13 | if (mbmi->skip_mode) { |
2688 | 0 | assert(is_compound); |
2689 | 0 | mbmi->mode = NEAR_NEARMV; |
2690 | 0 | read_drl_idx(cm->features.max_drl_bits, |
2691 | 0 | av2_mode_context_pristine(inter_mode_ctx, mbmi->ref_frame), |
2692 | 0 | ec_ctx, mbmi, r); |
2693 | |
|
2694 | 0 | av2_find_mv_refs(cm, xd, mbmi, ref_frame, dcb->ref_mv_count, |
2695 | 0 | xd->ref_mv_stack, xd->weight, ref_mvs, /*global_mvs=*/NULL, |
2696 | 0 | NULL, 0, NULL); |
2697 | |
|
2698 | 0 | is_compound = has_second_ref(mbmi); |
2699 | 0 | if (!is_compound) { |
2700 | 0 | mbmi->mode = NEARMV; |
2701 | 0 | assert(0); |
2702 | 0 | } else { |
2703 | 0 | mbmi->mode = NEAR_NEARMV; |
2704 | 0 | } |
2705 | 13 | } else { |
2706 | 13 | if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) || |
2707 | 13 | segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_GLOBALMV)) { |
2708 | 0 | mbmi->mode = GLOBALMV; |
2709 | 13 | } else { |
2710 | 13 | const int16_t mode_ctx = |
2711 | 13 | av2_mode_context_analyzer(inter_mode_ctx, mbmi->ref_frame); |
2712 | 13 | if (is_compound) |
2713 | 2 | mbmi->mode = read_inter_compound_mode(xd, r, cm, mbmi, mode_ctx); |
2714 | 11 | else |
2715 | 11 | mbmi->mode = read_inter_mode(ec_ctx, r, mode_ctx, cm, xd, mbmi, bsize); |
2716 | | |
2717 | 13 | mbmi->use_amvd = 0; |
2718 | 13 | if (cm->seq_params.enable_adaptive_mvd && allow_amvd_mode(mbmi->mode)) { |
2719 | 4 | int amvd_index = amvd_mode_to_index(mbmi->mode); |
2720 | 4 | assert(amvd_index >= 0); |
2721 | 4 | int amvd_ctx = get_amvd_context(xd); |
2722 | 4 | mbmi->use_amvd = |
2723 | 4 | avm_read_symbol(r, ec_ctx->amvd_mode_cdf[amvd_index][amvd_ctx], 2, |
2724 | 4 | ACCT_INFO("use_amvd")); |
2725 | 4 | } |
2726 | 13 | av2_find_mv_refs( |
2727 | 13 | cm, xd, mbmi, ref_frame, dcb->ref_mv_count, xd->ref_mv_stack, |
2728 | 13 | xd->weight, ref_mvs, /*global_mvs=*/NULL, xd->warp_param_stack, |
2729 | 13 | ref_frame < SINGLE_REF_FRAMES ? MAX_WARP_REF_CANDIDATES : 0, |
2730 | 13 | xd->valid_num_warp_candidates); |
2731 | | |
2732 | 13 | if (cm->features.enable_bawp && |
2733 | 6 | av2_allow_bawp(cm, mbmi, xd->mi_row, xd->mi_col)) { |
2734 | 1 | mbmi->bawp_flag[0] = avm_read_symbol(r, xd->tile_ctx->bawp_cdf[0], 2, |
2735 | 1 | ACCT_INFO("bawp_flag_luma")); |
2736 | 1 | if (mbmi->bawp_flag[0] && av2_allow_explicit_bawp(mbmi)) { |
2737 | 0 | const int ctx_index = |
2738 | 0 | (mbmi->mode == NEARMV) |
2739 | 0 | ? 0 |
2740 | 0 | : ((mbmi->mode == NEWMV && mbmi->use_amvd) ? 1 : 2); |
2741 | 0 | mbmi->bawp_flag[0] += |
2742 | 0 | avm_read_symbol(r, xd->tile_ctx->explicit_bawp_cdf[ctx_index], 2, |
2743 | 0 | ACCT_INFO("explicit_bawp_flag")); |
2744 | 0 | } |
2745 | 1 | if (mbmi->bawp_flag[0] > 1) { |
2746 | 0 | mbmi->bawp_flag[0] += avm_read_symbol( |
2747 | 0 | r, xd->tile_ctx->explicit_bawp_scale_cdf, EXPLICIT_BAWP_SCALE_CNT, |
2748 | 0 | ACCT_INFO("explicit_bawp_scales")); |
2749 | 0 | } |
2750 | 1 | } |
2751 | | |
2752 | 13 | if (!cm->seq_params.monochrome && xd->is_chroma_ref && |
2753 | 13 | mbmi->bawp_flag[0]) { |
2754 | 0 | mbmi->bawp_flag[1] = avm_read_symbol(r, xd->tile_ctx->bawp_cdf[1], 2, |
2755 | 0 | ACCT_INFO("bawp_flag_chroma")); |
2756 | 13 | } else { |
2757 | 13 | mbmi->bawp_flag[1] = 0; |
2758 | 13 | } |
2759 | | |
2760 | 28 | for (int ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) { |
2761 | 15 | const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; |
2762 | 15 | xd->block_ref_scale_factors[ref] = |
2763 | 15 | get_ref_scale_factors_const(cm, frame); |
2764 | 15 | } |
2765 | 13 | if (is_motion_variation_allowed_bsize(mbmi->sb_type[PLANE_TYPE_Y], |
2766 | 13 | xd->mi_row, xd->mi_col) && |
2767 | 13 | !is_tip_ref_frame(mbmi->ref_frame[0]) && !mbmi->skip_mode && |
2768 | 13 | (!has_second_ref(mbmi) || |
2769 | 11 | is_compound_warp_causal_allowed(cm, xd, mbmi))) { |
2770 | 11 | mbmi->num_proj_ref[0] = av2_findSamples(cm, xd, pts0, pts0_inref, 0); |
2771 | 11 | if (has_second_ref(mbmi)) |
2772 | 0 | mbmi->num_proj_ref[1] = av2_findSamples(cm, xd, pts1, pts1_inref, 1); |
2773 | 11 | } |
2774 | 13 | mbmi->motion_mode = read_motion_mode(cm, xd, mbmi, r); |
2775 | 13 | if (mbmi->motion_mode == WARP_DELTA) { |
2776 | 2 | mbmi->max_num_warp_candidates = MAX_WARP_REF_CANDIDATES; |
2777 | 2 | av2_find_warp_delta_base_candidates( |
2778 | 2 | xd, mbmi, warp_param_stack, |
2779 | 2 | xd->warp_param_stack[av2_ref_frame_type(mbmi->ref_frame)], |
2780 | 2 | xd->valid_num_warp_candidates[av2_ref_frame_type(mbmi->ref_frame)], |
2781 | 2 | NULL); |
2782 | | |
2783 | 2 | read_warp_ref_idx(xd->tile_ctx, mbmi, r); |
2784 | 2 | ref_warp_model = warp_param_stack[mbmi->warp_ref_idx].wm_params; |
2785 | 2 | } |
2786 | | |
2787 | 13 | if (allow_warpmv_with_mvd_coding(cm, mbmi)) { |
2788 | 2 | read_warpmv_with_mvd_flag(xd->tile_ctx, mbmi, r); |
2789 | 11 | } else { |
2790 | 11 | mbmi->warpmv_with_mvd_flag = 0; |
2791 | 11 | } |
2792 | 13 | mbmi->jmvd_scale_mode = read_jmvd_scale_mode(xd, r, mbmi); |
2793 | 13 | int max_drl_bits = cm->features.max_drl_bits; |
2794 | | |
2795 | 13 | if (have_drl_index(mbmi->mode)) |
2796 | 11 | read_drl_idx(max_drl_bits, |
2797 | 11 | av2_mode_context_pristine(inter_mode_ctx, mbmi->ref_frame), |
2798 | 11 | ec_ctx, mbmi, r); |
2799 | 13 | set_mv_precision(mbmi, mbmi->max_mv_precision); |
2800 | 13 | if (is_pb_mv_precision_active(cm, mbmi, bsize)) { |
2801 | 6 | set_precision_set(cm, xd, mbmi, bsize); |
2802 | 6 | set_most_probable_mv_precision(cm, mbmi, bsize); |
2803 | 6 | mbmi->pb_mv_precision = av2_read_pb_mv_precision(cm, xd, r); |
2804 | 6 | } |
2805 | 13 | if (enable_adaptive_mvd_resolution(cm, mbmi)) |
2806 | 1 | set_amvd_mv_precision(mbmi, mbmi->max_mv_precision); |
2807 | 13 | } |
2808 | 13 | } |
2809 | | |
2810 | 13 | if (is_compound != is_inter_compound_mode(mbmi->mode)) { |
2811 | 0 | avm_internal_error(xd->error_info, AVM_CODEC_CORRUPT_FRAME, |
2812 | 0 | "Prediction mode %d invalid with ref frame %d %d", |
2813 | 0 | mbmi->mode, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
2814 | 0 | } |
2815 | | |
2816 | 13 | if (mbmi->mode == WARPMV) { |
2817 | 2 | ref_mv[0] = get_mv_from_wrl(xd, &ref_warp_model, |
2818 | 2 | !mbmi->warpmv_with_mvd_flag |
2819 | 2 | ? MV_PRECISION_ONE_EIGHTH_PEL |
2820 | 2 | : mbmi->pb_mv_precision, |
2821 | 2 | bsize, xd->mi_col, xd->mi_row); |
2822 | | |
2823 | 11 | } else { |
2824 | 11 | if (has_second_drl(mbmi)) |
2825 | 1 | ref_mv[0] = |
2826 | 1 | xd->ref_mv_stack[mbmi->ref_frame[0]][get_ref_mv_idx(mbmi, 0)].this_mv; |
2827 | 10 | else |
2828 | 10 | ref_mv[0] = xd->ref_mv_stack[ref_frame][get_ref_mv_idx(mbmi, 0)].this_mv; |
2829 | 11 | } |
2830 | | |
2831 | 13 | if (is_compound && mbmi->mode != GLOBAL_GLOBALMV) { |
2832 | 2 | if (has_second_drl(mbmi)) |
2833 | 1 | ref_mv[1] = |
2834 | 1 | xd->ref_mv_stack[mbmi->ref_frame[1]][get_ref_mv_idx(mbmi, 1)].this_mv; |
2835 | 1 | else |
2836 | 1 | ref_mv[1] = xd->ref_mv_stack[ref_frame][get_ref_mv_idx(mbmi, 1)].comp_mv; |
2837 | 2 | if (mbmi->skip_mode) { |
2838 | 0 | ref_mv[0] = |
2839 | 0 | xd->skip_mvp_candidate_list.ref_mv_stack[get_ref_mv_idx(mbmi, 0)] |
2840 | 0 | .this_mv; |
2841 | 0 | ref_mv[1] = |
2842 | 0 | xd->skip_mvp_candidate_list.ref_mv_stack[get_ref_mv_idx(mbmi, 1)] |
2843 | 0 | .comp_mv; |
2844 | 0 | } |
2845 | 2 | } |
2846 | | |
2847 | 13 | if (mbmi->skip_mode) { |
2848 | 0 | assert(is_compound); |
2849 | 0 | assert(mbmi->mode == NEAR_NEARMV); |
2850 | 0 | } |
2851 | | |
2852 | 13 | const int mv_corrupted_flag = |
2853 | 13 | !assign_mv(cm, xd, mbmi->mode, mbmi->ref_frame, mbmi->mv, ref_mv, |
2854 | 13 | is_compound, mbmi->pb_mv_precision, r); |
2855 | | |
2856 | 13 | avm_merge_corrupted_flag(&dcb->corrupted, mv_corrupted_flag); |
2857 | | |
2858 | 13 | if (mbmi->motion_mode == WARP_DELTA) { |
2859 | 2 | read_warp_delta(cm, xd, mbmi, r, warp_param_stack); |
2860 | 2 | } |
2861 | | |
2862 | 13 | mbmi->warp_inter_intra = 0; |
2863 | 13 | if (allow_warp_inter_intra(mbmi)) { |
2864 | 2 | const int bsize_group = size_group_lookup[bsize]; |
2865 | 2 | mbmi->warp_inter_intra = |
2866 | 2 | avm_read_symbol(r, xd->tile_ctx->warp_interintra_cdf[bsize_group], 2, |
2867 | 2 | ACCT_INFO("warp_inter_intra")); |
2868 | | |
2869 | 2 | if (mbmi->warp_inter_intra) { |
2870 | 0 | const INTERINTRA_MODE interintra_mode = |
2871 | 0 | read_interintra_mode(xd, r, bsize_group); |
2872 | 0 | mbmi->interintra_mode = interintra_mode; |
2873 | 0 | mbmi->angle_delta[PLANE_TYPE_Y] = 0; |
2874 | 0 | mbmi->angle_delta[PLANE_TYPE_UV] = 0; |
2875 | 0 | mbmi->use_dpcm_y = 0; |
2876 | 0 | mbmi->dpcm_mode_y = 0; |
2877 | 0 | mbmi->use_dpcm_uv = 0; |
2878 | 0 | mbmi->dpcm_mode_uv = 0; |
2879 | 0 | mbmi->use_intra_dip = 0; |
2880 | 0 | if (av2_is_wedge_used(bsize)) { |
2881 | 0 | mbmi->use_wedge_interintra = |
2882 | 0 | avm_read_symbol(r, xd->tile_ctx->wedge_interintra_cdf, 2, |
2883 | 0 | ACCT_INFO("use_wedge_interintra")); |
2884 | 0 | if (mbmi->use_wedge_interintra) { |
2885 | 0 | mbmi->interintra_wedge_index = |
2886 | 0 | read_wedge_mode(r, xd->tile_ctx, bsize); |
2887 | 0 | assert(mbmi->interintra_wedge_index != -1); |
2888 | 0 | mbmi->wedge_boundary_index = get_wedge_boundary_type(bsize); |
2889 | 0 | } |
2890 | 0 | } |
2891 | 0 | } |
2892 | 2 | } |
2893 | | |
2894 | 13 | if (!mbmi->skip_mode) { |
2895 | 13 | read_refinemv_flag(cm, xd, r, bsize); |
2896 | 13 | } |
2897 | | |
2898 | | // init |
2899 | 13 | mbmi->comp_group_idx = 0; |
2900 | 13 | mbmi->interinter_comp.type = COMPOUND_AVERAGE; |
2901 | | |
2902 | 13 | if (has_second_ref(mbmi) && mbmi->mode < NEAR_NEARMV_OPTFLOW && |
2903 | 2 | (!mbmi->refinemv_flag || !switchable_refinemv_flag(cm, mbmi)) && |
2904 | 2 | !is_joint_amvd_coding_mode(mbmi->mode, mbmi->use_amvd) && |
2905 | 2 | !mbmi->skip_mode) { |
2906 | | // Read idx to indicate current compound inter prediction mode group |
2907 | 2 | const int masked_compound_used = is_any_masked_compound_used(bsize) && |
2908 | 2 | cm->seq_params.enable_masked_compound; |
2909 | | |
2910 | 2 | if (masked_compound_used) { |
2911 | 0 | const int ctx_comp_group_idx = get_comp_group_idx_context(cm, xd); |
2912 | 0 | mbmi->comp_group_idx = (uint8_t)avm_read_symbol( |
2913 | 0 | r, ec_ctx->comp_group_idx_cdf[ctx_comp_group_idx], 2, |
2914 | 0 | ACCT_INFO("comp_group_idx")); |
2915 | 0 | } |
2916 | | |
2917 | 2 | if (mbmi->comp_group_idx == 0) { |
2918 | 2 | mbmi->interinter_comp.type = COMPOUND_AVERAGE; |
2919 | 2 | } else { |
2920 | 0 | assert(cm->current_frame.reference_mode != SINGLE_REFERENCE && |
2921 | 0 | is_inter_compound_mode(mbmi->mode) && |
2922 | 0 | (mbmi->motion_mode == SIMPLE_TRANSLATION || |
2923 | 0 | is_compound_warp_causal_allowed(cm, xd, mbmi))); |
2924 | 0 | assert(masked_compound_used); |
2925 | | |
2926 | | // compound_diffwtd, wedge |
2927 | 0 | if (is_interinter_compound_used(COMPOUND_WEDGE, bsize)) { |
2928 | 0 | mbmi->interinter_comp.type = |
2929 | 0 | COMPOUND_WEDGE + avm_read_symbol(r, ec_ctx->compound_type_cdf, |
2930 | 0 | MASKED_COMPOUND_TYPES, |
2931 | 0 | ACCT_INFO("comp_type")); |
2932 | 0 | } else { |
2933 | 0 | mbmi->interinter_comp.type = COMPOUND_DIFFWTD; |
2934 | 0 | } |
2935 | |
|
2936 | 0 | if (mbmi->interinter_comp.type == COMPOUND_WEDGE) { |
2937 | 0 | assert(is_interinter_compound_used(COMPOUND_WEDGE, bsize)); |
2938 | 0 | mbmi->interinter_comp.wedge_index = read_wedge_mode(r, ec_ctx, bsize); |
2939 | 0 | assert(mbmi->interinter_comp.wedge_index != -1); |
2940 | 0 | mbmi->interinter_comp.wedge_boundary_index = |
2941 | 0 | get_wedge_boundary_type(bsize); |
2942 | 0 | mbmi->interinter_comp.wedge_sign = |
2943 | 0 | (int8_t)avm_read_bit(r, ACCT_INFO("wedge_sign")); |
2944 | 0 | } else { |
2945 | 0 | assert(mbmi->interinter_comp.type == COMPOUND_DIFFWTD); |
2946 | 0 | mbmi->interinter_comp.mask_type = |
2947 | 0 | avm_read_literal(r, MAX_DIFFWTD_MASK_BITS, ACCT_INFO("mask_type")); |
2948 | 0 | } |
2949 | 0 | } |
2950 | 2 | } |
2951 | 13 | mbmi->cwp_idx = CWP_EQUAL; |
2952 | 13 | if (cm->features.enable_cwp) { |
2953 | 13 | if (is_cwp_allowed(mbmi) && !mbmi->skip_mode) |
2954 | 0 | mbmi->cwp_idx = read_cwp_idx(xd, r, cm, mbmi); |
2955 | 13 | if (is_cwp_allowed(mbmi) && mbmi->skip_mode) |
2956 | 0 | mbmi->cwp_idx = |
2957 | 0 | xd->skip_mvp_candidate_list.ref_mv_stack[mbmi->ref_mv_idx[0]].cwp_idx; |
2958 | 13 | } |
2959 | 13 | if (mbmi->skip_mode) { |
2960 | 0 | mbmi->refinemv_flag = 0; |
2961 | 0 | } |
2962 | | |
2963 | 13 | read_mb_interp_filter(xd, features->interp_filter, cm, mbmi, r); |
2964 | | |
2965 | 13 | const int mi_row = xd->mi_row; |
2966 | 13 | const int mi_col = xd->mi_col; |
2967 | | |
2968 | 13 | if (mbmi->motion_mode == WARP_CAUSAL) { |
2969 | 3 | mbmi->wm_params[0].wmtype = DEFAULT_WMTYPE; |
2970 | 3 | mbmi->wm_params[1].wmtype = DEFAULT_WMTYPE; |
2971 | 3 | mbmi->wm_params[0].invalid = 1; |
2972 | 3 | mbmi->wm_params[1].invalid = 1; |
2973 | 3 | MV mv0 = mbmi->mv[0].as_mv; |
2974 | 3 | MV mv1 = mbmi->mv[1].as_mv; |
2975 | | |
2976 | 3 | const struct scale_factors *sf[2]; |
2977 | 3 | sf[0] = get_ref_scale_factors(cm, mbmi->ref_frame[0]); |
2978 | 3 | sf[1] = get_ref_scale_factors(cm, mbmi->ref_frame[1]); |
2979 | | |
2980 | 3 | if (mbmi->num_proj_ref[0] > 0) { |
2981 | 3 | av2_find_projection(mbmi->num_proj_ref[0], pts0, pts0_inref, bsize, mv0, |
2982 | 3 | &mbmi->wm_params[0], mi_row, mi_col, sf[0]); |
2983 | 3 | mbmi->wm_params[0].invalid = 0; |
2984 | 3 | } |
2985 | 3 | if (has_second_ref(mbmi)) { |
2986 | 0 | if (mbmi->num_proj_ref[1] > 0) { |
2987 | 0 | av2_find_projection(mbmi->num_proj_ref[1], pts1, pts1_inref, bsize, mv1, |
2988 | 0 | &mbmi->wm_params[1], mi_row, mi_col, sf[1]); |
2989 | 0 | mbmi->wm_params[1].invalid = 0; |
2990 | 0 | } |
2991 | 0 | } |
2992 | | |
2993 | 3 | if (!mbmi->wm_params[0].invalid) |
2994 | 3 | assign_warpmv(cm, xd->submi, bsize, &mbmi->wm_params[0], mi_row, mi_col, |
2995 | 3 | 0); |
2996 | 3 | if (!mbmi->wm_params[1].invalid) |
2997 | 0 | assign_warpmv(cm, xd->submi, bsize, &mbmi->wm_params[1], mi_row, mi_col, |
2998 | 0 | 1); |
2999 | 3 | } |
3000 | | |
3001 | 13 | if (mbmi->motion_mode == WARP_EXTEND) { |
3002 | 2 | CANDIDATE_MV *neighbor = |
3003 | 2 | &xd->ref_mv_stack[ref_frame][get_ref_mv_idx(mbmi, 0)]; |
3004 | 2 | POSITION base_pos = { 0, 0 }; |
3005 | 2 | if (!get_extend_base_pos(cm, xd, mbmi, neighbor->row_offset, |
3006 | 2 | neighbor->col_offset, &base_pos)) { |
3007 | 0 | printf("Warp extend position error\n"); |
3008 | 0 | } |
3009 | 2 | assert(!(base_pos.row == 0 && base_pos.col == 0)); |
3010 | 2 | const MB_MODE_INFO *neighbor_mi = |
3011 | 2 | xd->mi[base_pos.row * xd->mi_stride + base_pos.col]; |
3012 | | |
3013 | 2 | if (mbmi->mode == NEARMV) { |
3014 | 0 | assert(is_warp_mode(neighbor_mi->motion_mode)); |
3015 | 0 | mbmi->wm_params[0] = neighbor_mi->wm_params[0]; |
3016 | 2 | } else { |
3017 | 2 | assert(mbmi->mode == WARP_NEWMV); |
3018 | | |
3019 | 2 | bool neighbor_is_above = |
3020 | 2 | xd->up_available && (base_pos.row == -1 && base_pos.col >= 0); |
3021 | | |
3022 | 2 | WarpedMotionParams neighbor_params; |
3023 | 2 | av2_get_neighbor_warp_model(cm, xd, neighbor_mi, &neighbor_params); |
3024 | 2 | if (av2_extend_warp_model( |
3025 | 2 | neighbor_is_above, bsize, &mbmi->mv[0].as_mv, mi_row, mi_col, |
3026 | 2 | &neighbor_params, &mbmi->wm_params[0], |
3027 | 2 | get_ref_scale_factors_const(cm, mbmi->ref_frame[0]))) { |
3028 | | #if WARPED_MOTION_DEBUG |
3029 | | printf("Warning: unexpected warped model from avmenc\n"); |
3030 | | #endif |
3031 | 0 | mbmi->wm_params[0].invalid = 1; |
3032 | 0 | } |
3033 | 2 | } |
3034 | 2 | assign_warpmv(cm, xd->submi, bsize, &mbmi->wm_params[0], mi_row, mi_col, 0); |
3035 | 2 | } |
3036 | | |
3037 | 13 | if (xd->tree_type != LUMA_PART) xd->cfl.store_y = store_cfl_required(cm, xd); |
3038 | | |
3039 | | #if DEC_MISMATCH_DEBUG |
3040 | | dec_dump_logs(cm, mi, mi_row, mi_col, mode_ctx); |
3041 | | #endif // DEC_MISMATCH_DEBUG |
3042 | 13 | } |
3043 | | |
3044 | | static void read_inter_frame_mode_info(AV2Decoder *const pbi, |
3045 | 13 | DecoderCodingBlock *dcb, avm_reader *r) { |
3046 | 13 | AV2_COMMON *const cm = &pbi->common; |
3047 | 13 | MACROBLOCKD *const xd = &dcb->xd; |
3048 | 13 | MB_MODE_INFO *const mbmi = xd->mi[0]; |
3049 | 13 | int inter_block = 1; |
3050 | | |
3051 | 13 | mbmi->mv[0].as_int = 0; |
3052 | 13 | mbmi->mv[1].as_int = 0; |
3053 | 13 | xd->submi[0]->mv[0].as_int = xd->submi[0]->mv[1].as_int = 0; |
3054 | 13 | span_submv(cm, xd->submi, xd->mi_row, xd->mi_col, mbmi->sb_type[PLANE_TYPE_Y], |
3055 | 13 | 0); |
3056 | 13 | span_submv(cm, xd->submi, xd->mi_row, xd->mi_col, mbmi->sb_type[PLANE_TYPE_Y], |
3057 | 13 | 1); |
3058 | 13 | set_default_max_mv_precision(mbmi, xd->sbi->sb_mv_precision); |
3059 | 13 | set_mv_precision(mbmi, mbmi->max_mv_precision); // initialize to max |
3060 | 13 | set_default_precision_set(cm, mbmi, mbmi->sb_type[PLANE_TYPE_Y]); |
3061 | 13 | set_most_probable_mv_precision(cm, mbmi, mbmi->sb_type[PLANE_TYPE_Y]); |
3062 | | |
3063 | 13 | mbmi->bawp_flag[0] = 0; |
3064 | 13 | mbmi->bawp_flag[1] = 0; |
3065 | 13 | mbmi->refinemv_flag = 0; |
3066 | | |
3067 | 13 | if (xd->tree_type != CHROMA_PART) |
3068 | 13 | mbmi->segment_id = read_inter_segment_id(cm, xd, 1, r); |
3069 | | |
3070 | 13 | mbmi->skip_mode = read_skip_mode(cm, xd, r); |
3071 | | |
3072 | 13 | mbmi->fsc_mode[xd->tree_type == CHROMA_PART] = 0; |
3073 | | |
3074 | 13 | mbmi->cwp_idx = CWP_EQUAL; |
3075 | | |
3076 | 13 | mbmi->warp_ref_idx = 0; |
3077 | 13 | mbmi->max_num_warp_candidates = 0; |
3078 | 13 | mbmi->warpmv_with_mvd_flag = 0; |
3079 | 13 | if (xd->tree_type != CHROMA_PART) { |
3080 | 13 | mbmi->use_intrabc[0] = 0; |
3081 | 13 | mbmi->use_intrabc[1] = 0; |
3082 | 13 | mbmi->use_intra_dip = 0; |
3083 | 13 | mbmi->morph_pred = 0; |
3084 | 13 | } |
3085 | | |
3086 | 13 | if (!mbmi->skip_mode) { |
3087 | 13 | inter_block = read_is_inter_block(cm, xd, mbmi->segment_id, r); |
3088 | 13 | } |
3089 | | |
3090 | 13 | if (!inter_block && |
3091 | 0 | av2_allow_intrabc(cm, xd, mbmi->sb_type[xd->tree_type == CHROMA_PART]) && |
3092 | 0 | xd->tree_type != CHROMA_PART) { |
3093 | 0 | mbmi->use_intrabc[0] = 0; |
3094 | 0 | mbmi->use_intrabc[1] = 0; |
3095 | 0 | mbmi->morph_pred = 0; |
3096 | 0 | const int intrabc_ctx = get_intrabc_ctx(xd); |
3097 | 0 | mbmi->use_intrabc[xd->tree_type == CHROMA_PART] = |
3098 | 0 | avm_read_symbol(r, xd->tile_ctx->intrabc_cdf[intrabc_ctx], 2, |
3099 | 0 | ACCT_INFO("use_intrabc", "chroma")); |
3100 | 0 | } |
3101 | | |
3102 | 13 | if (inter_block || (!inter_block && is_intrabc_block(mbmi, xd->tree_type))) { |
3103 | 13 | mbmi->skip_txfm[xd->tree_type == CHROMA_PART] = |
3104 | 13 | read_skip_txfm(cm, xd, mbmi->segment_id, r); |
3105 | 13 | } else { |
3106 | | // Segment SEG_LVL_SKIP should be disabled for intra prediction |
3107 | 0 | if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
3108 | 0 | avm_internal_error(xd->error_info, AVM_CODEC_CORRUPT_FRAME, |
3109 | 0 | "Corrupted segment features"); |
3110 | 0 | } |
3111 | 0 | mbmi->skip_txfm[xd->tree_type == CHROMA_PART] = 0; |
3112 | 0 | } |
3113 | | |
3114 | 13 | mbmi->six_param_warp_model_flag = 0; |
3115 | | |
3116 | 13 | mbmi->warp_precision_idx = 0; |
3117 | 13 | mbmi->warp_inter_intra = 0; |
3118 | | |
3119 | 13 | if (!cm->seg.segid_preskip && xd->tree_type != CHROMA_PART) |
3120 | 13 | mbmi->segment_id = read_inter_segment_id(cm, xd, 0, r); |
3121 | | |
3122 | 13 | if (xd->tree_type != CHROMA_PART) read_gdf(cm, r, xd); |
3123 | | |
3124 | 13 | if (xd->tree_type != CHROMA_PART) read_cdef(cm, r, xd); |
3125 | | |
3126 | 13 | if (cm->seq_params.enable_ccso && xd->tree_type != CHROMA_PART) |
3127 | 10 | read_ccso(cm, r, xd); |
3128 | | |
3129 | 13 | if (xd->tree_type != CHROMA_PART) read_delta_q_params(cm, xd, r); |
3130 | | |
3131 | 13 | mbmi->current_qindex = xd->current_base_qindex; |
3132 | | |
3133 | 13 | int seg_qindex = |
3134 | 13 | av2_get_qindex(&cm->seg, mbmi->segment_id, xd->current_base_qindex, |
3135 | 13 | cm->seq_params.bit_depth); |
3136 | 13 | get_qindex_with_offsets(cm, seg_qindex, mbmi->final_qindex_dc, |
3137 | 13 | mbmi->final_qindex_ac); |
3138 | | |
3139 | 13 | if (!inter_block && |
3140 | 0 | av2_allow_intrabc(cm, xd, mbmi->sb_type[xd->tree_type == CHROMA_PART]) && |
3141 | 0 | xd->tree_type != CHROMA_PART) { |
3142 | 0 | mbmi->ref_frame[0] = INTRA_FRAME; |
3143 | 0 | mbmi->ref_frame[1] = NONE_FRAME; |
3144 | 0 | mbmi->palette_mode_info.palette_size[0] = 0; |
3145 | 0 | mbmi->palette_mode_info.palette_size[1] = 0; |
3146 | 0 | read_intrabc_info(cm, dcb, r); |
3147 | 0 | if (is_intrabc_block(mbmi, xd->tree_type)) { |
3148 | 0 | mbmi->use_dpcm_y = 0; |
3149 | 0 | mbmi->dpcm_mode_y = 0; |
3150 | 0 | mbmi->use_amvd = 0; |
3151 | 0 | return; |
3152 | 0 | } |
3153 | 0 | } |
3154 | 13 | if (inter_block) |
3155 | 13 | read_inter_block_mode_info(pbi, dcb, mbmi, r); |
3156 | 0 | else |
3157 | 0 | read_intra_block_mode_info(cm, xd, mbmi, r); |
3158 | 13 | } |
3159 | | |
3160 | | static void intra_copy_frame_mvs(AV2_COMMON *const cm, int mi_row, int mi_col, |
3161 | 12 | int x_inside_boundary, int y_inside_boundary) { |
3162 | 12 | const int mi_cols = |
3163 | 12 | ROUND_POWER_OF_TWO(cm->mi_params.mi_cols, TMVP_SHIFT_BITS); |
3164 | | |
3165 | 12 | MV_REF *frame_mvs = cm->cur_frame->mvs + |
3166 | 12 | (mi_row >> TMVP_SHIFT_BITS) * mi_cols + |
3167 | 12 | (mi_col >> TMVP_SHIFT_BITS); |
3168 | 12 | x_inside_boundary = ROUND_POWER_OF_TWO(x_inside_boundary, TMVP_SHIFT_BITS); |
3169 | 12 | y_inside_boundary = ROUND_POWER_OF_TWO(y_inside_boundary, TMVP_SHIFT_BITS); |
3170 | | |
3171 | 36 | for (int h = 0; h < y_inside_boundary; h++) { |
3172 | 24 | MV_REF *mv = frame_mvs; |
3173 | 48 | for (int w = 0; w < x_inside_boundary; w++) { |
3174 | 72 | for (int idx = 0; idx < 2; ++idx) { |
3175 | 48 | mv->ref_frame[idx] = NONE_FRAME; |
3176 | 48 | } |
3177 | 24 | mv++; |
3178 | 24 | } |
3179 | 24 | frame_mvs += mi_cols; |
3180 | 24 | } |
3181 | 12 | } |
3182 | | |
3183 | | void av2_read_mode_info(AV2Decoder *const pbi, DecoderCodingBlock *dcb, |
3184 | | avm_reader *r, int x_inside_boundary, |
3185 | 789k | int y_inside_boundary) { |
3186 | 789k | AV2_COMMON *const cm = &pbi->common; |
3187 | 789k | MACROBLOCKD *const xd = &dcb->xd; |
3188 | 789k | MB_MODE_INFO *const mi = xd->mi[0]; |
3189 | 789k | mi->use_intrabc[xd->tree_type == CHROMA_PART] = 0; |
3190 | 789k | mi->warpmv_with_mvd_flag = 0; |
3191 | 789k | if (xd->tree_type == SHARED_PART) |
3192 | 531k | mi->sb_type[PLANE_TYPE_UV] = mi->sb_type[PLANE_TYPE_Y]; |
3193 | | |
3194 | 789k | if (frame_is_intra_only(cm)) { |
3195 | 788k | read_intra_frame_mode_info(cm, dcb, r); |
3196 | 788k | if (cm->seq_params.enable_refmvbank) { |
3197 | 501k | MB_MODE_INFO *const mbmi = xd->mi[0]; |
3198 | 501k | if (is_intrabc_block(mbmi, xd->tree_type)) { |
3199 | 53.2k | av2_update_ref_mv_bank(cm, xd, 1, mbmi); |
3200 | 448k | } else { |
3201 | 448k | decide_rmb_unit_update_count(cm, xd, mbmi); |
3202 | 448k | } |
3203 | 501k | } |
3204 | 788k | if (cm->seq_params.order_hint_info.enable_ref_frame_mvs) |
3205 | 12 | intra_copy_frame_mvs(cm, xd->mi_row, xd->mi_col, x_inside_boundary, |
3206 | 12 | y_inside_boundary); |
3207 | 788k | } else { |
3208 | 794 | read_inter_frame_mode_info(pbi, dcb, r); |
3209 | 794 | if (cm->seq_params.enable_refmvbank) { |
3210 | 3 | MB_MODE_INFO *const mbmi = xd->mi[0]; |
3211 | 3 | if (is_inter_block(mbmi, xd->tree_type)) { |
3212 | 3 | av2_update_ref_mv_bank(cm, xd, 1, mbmi); |
3213 | 3 | } else { |
3214 | 0 | decide_rmb_unit_update_count(cm, xd, mbmi); |
3215 | 0 | } |
3216 | 3 | } |
3217 | | |
3218 | 794 | MB_MODE_INFO *const mbmi_tmp = xd->mi[0]; |
3219 | 794 | if (is_inter_block(mbmi_tmp, xd->tree_type)) |
3220 | 13 | av2_update_warp_param_bank(cm, xd, 0, mbmi_tmp); |
3221 | 794 | } |
3222 | 789k | } |