/src/ffmpeg/libavcodec/vvc/cabac.c
Line | Count | Source |
1 | | /* |
2 | | * VVC CABAC decoder |
3 | | * |
4 | | * Copyright (C) 2021 Nuo Mi |
5 | | * |
6 | | * This file is part of FFmpeg. |
7 | | * |
8 | | * FFmpeg is free software; you can redistribute it and/or |
9 | | * modify it under the terms of the GNU Lesser General Public |
10 | | * License as published by the Free Software Foundation; either |
11 | | * version 2.1 of the License, or (at your option) any later version. |
12 | | * |
13 | | * FFmpeg is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | | * Lesser General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public |
19 | | * License along with FFmpeg; if not, write to the Free Software |
20 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | | */ |
22 | | |
23 | | #include <assert.h> |
24 | | |
25 | | #include "libavcodec/cabac_functions.h" |
26 | | |
27 | | #include "cabac.h" |
28 | | #include "ctu.h" |
29 | | #include "data.h" |
30 | | |
31 | | #define CABAC_MAX_BIN 31 |
32 | | |
33 | | #define CNU 35 |
34 | | |
35 | | enum SyntaxElement { |
36 | | ALF_CTB_FLAG = 0, |
37 | | ALF_USE_APS_FLAG = ALF_CTB_FLAG + 9, |
38 | | ALF_CTB_CC_CB_IDC, |
39 | | ALF_CTB_CC_CR_IDC = ALF_CTB_CC_CB_IDC + 3, |
40 | | ALF_CTB_FILTER_ALT_IDX = ALF_CTB_CC_CR_IDC + 3, |
41 | | SAO_MERGE_FLAG = ALF_CTB_FILTER_ALT_IDX + 2, |
42 | | SAO_TYPE_IDX, |
43 | | SPLIT_CU_FLAG, |
44 | | SPLIT_QT_FLAG = SPLIT_CU_FLAG + 9, |
45 | | MTT_SPLIT_CU_VERTICAL_FLAG = SPLIT_QT_FLAG + 6, |
46 | | MTT_SPLIT_CU_BINARY_FLAG = MTT_SPLIT_CU_VERTICAL_FLAG + 5, |
47 | | NON_INTER_FLAG = MTT_SPLIT_CU_BINARY_FLAG + 4, |
48 | | CU_SKIP_FLAG = NON_INTER_FLAG + 2, |
49 | | PRED_MODE_IBC_FLAG = CU_SKIP_FLAG + 3, |
50 | | PRED_MODE_FLAG = PRED_MODE_IBC_FLAG + 3, |
51 | | PRED_MODE_PLT_FLAG = PRED_MODE_FLAG + 2, |
52 | | CU_ACT_ENABLED_FLAG, |
53 | | INTRA_BDPCM_LUMA_FLAG, |
54 | | INTRA_BDPCM_LUMA_DIR_FLAG, |
55 | | INTRA_MIP_FLAG, |
56 | | INTRA_LUMA_REF_IDX = INTRA_MIP_FLAG + 4, |
57 | | INTRA_SUBPARTITIONS_MODE_FLAG = INTRA_LUMA_REF_IDX + 2, |
58 | | INTRA_SUBPARTITIONS_SPLIT_FLAG, |
59 | | INTRA_LUMA_MPM_FLAG, |
60 | | INTRA_LUMA_NOT_PLANAR_FLAG, |
61 | | INTRA_BDPCM_CHROMA_FLAG = INTRA_LUMA_NOT_PLANAR_FLAG + 2, |
62 | | INTRA_BDPCM_CHROMA_DIR_FLAG, |
63 | | CCLM_MODE_FLAG, |
64 | | CCLM_MODE_IDX, |
65 | | INTRA_CHROMA_PRED_MODE, |
66 | | GENERAL_MERGE_FLAG, |
67 | | INTER_PRED_IDC, |
68 | | INTER_AFFINE_FLAG = INTER_PRED_IDC + 6, |
69 | | CU_AFFINE_TYPE_FLAG = INTER_AFFINE_FLAG + 3, |
70 | | SYM_MVD_FLAG, |
71 | | REF_IDX_LX, |
72 | | MVP_LX_FLAG = REF_IDX_LX + 2, |
73 | | AMVR_FLAG, |
74 | | AMVR_PRECISION_IDX = AMVR_FLAG + 2, |
75 | | BCW_IDX = AMVR_PRECISION_IDX + 3, |
76 | | CU_CODED_FLAG, |
77 | | CU_SBT_FLAG, |
78 | | CU_SBT_QUAD_FLAG = CU_SBT_FLAG + 2, |
79 | | CU_SBT_HORIZONTAL_FLAG, |
80 | | CU_SBT_POS_FLAG = CU_SBT_HORIZONTAL_FLAG + 3, |
81 | | LFNST_IDX, |
82 | | MTS_IDX = LFNST_IDX + 3, |
83 | | COPY_ABOVE_PALETTE_INDICES_FLAG = MTS_IDX + 4, |
84 | | PALETTE_TRANSPOSE_FLAG, |
85 | | RUN_COPY_FLAG, |
86 | | REGULAR_MERGE_FLAG = RUN_COPY_FLAG + 8, |
87 | | MMVD_MERGE_FLAG = REGULAR_MERGE_FLAG + 2, |
88 | | MMVD_CAND_FLAG, |
89 | | MMVD_DISTANCE_IDX, |
90 | | CIIP_FLAG, |
91 | | MERGE_SUBBLOCK_FLAG, |
92 | | MERGE_SUBBLOCK_IDX = MERGE_SUBBLOCK_FLAG + 3, |
93 | | MERGE_IDX, |
94 | | ABS_MVD_GREATER0_FLAG, |
95 | | ABS_MVD_GREATER1_FLAG, |
96 | | TU_Y_CODED_FLAG, |
97 | | TU_CB_CODED_FLAG = TU_Y_CODED_FLAG + 4, |
98 | | TU_CR_CODED_FLAG = TU_CB_CODED_FLAG + 2, |
99 | | CU_QP_DELTA_ABS = TU_CR_CODED_FLAG + 3, |
100 | | CU_CHROMA_QP_OFFSET_FLAG = CU_QP_DELTA_ABS + 2, |
101 | | CU_CHROMA_QP_OFFSET_IDX, |
102 | | TRANSFORM_SKIP_FLAG, |
103 | | TU_JOINT_CBCR_RESIDUAL_FLAG = TRANSFORM_SKIP_FLAG + 2, |
104 | | LAST_SIG_COEFF_X_PREFIX = TU_JOINT_CBCR_RESIDUAL_FLAG + 3, |
105 | | LAST_SIG_COEFF_Y_PREFIX = LAST_SIG_COEFF_X_PREFIX +23, |
106 | | SB_CODED_FLAG = LAST_SIG_COEFF_Y_PREFIX +23, |
107 | | SIG_COEFF_FLAG = SB_CODED_FLAG + 7, |
108 | | PAR_LEVEL_FLAG = SIG_COEFF_FLAG +63, |
109 | | ABS_LEVEL_GTX_FLAG = PAR_LEVEL_FLAG +33, |
110 | | COEFF_SIGN_FLAG = ABS_LEVEL_GTX_FLAG +72, |
111 | | SYNTAX_ELEMENT_LAST = COEFF_SIGN_FLAG + 6, |
112 | | }; |
113 | | |
114 | | static_assert(VVC_CONTEXTS == SYNTAX_ELEMENT_LAST, "VVC_CONTEXTS wrong"); |
115 | | |
116 | | static const uint8_t init_values[4][SYNTAX_ELEMENT_LAST] = { |
117 | | { |
118 | | //alf_ctb_flag |
119 | | 62, 39, 39, 54, 39, 39, 31, 39, 39, |
120 | | //alf_use_aps_flag |
121 | | 46, |
122 | | //alf_ctb_cc_cb_idc |
123 | | 18, 30, 31, |
124 | | //alf_ctb_cc_cr_idc |
125 | | 18, 30, 31, |
126 | | //alf_ctb_filter_alt_idx |
127 | | 11, 11, |
128 | | //sao_merge_left_flag and sao_merge_up_flag |
129 | | 60, |
130 | | //sao_type_idx_luma and sao_type_idx_chroma |
131 | | 13, |
132 | | //split_cu_flag |
133 | | 19, 28, 38, 27, 29, 38, 20, 30, 31, |
134 | | //split_qt_flag |
135 | | 27, 6, 15, 25, 19, 37, |
136 | | //mtt_split_cu_vertical_flag |
137 | | 43, 42, 29, 27, 44, |
138 | | //mtt_split_cu_binary_flag |
139 | | 36, 45, 36, 45, |
140 | | //non_inter_flag |
141 | | CNU, CNU, |
142 | | //cu_skip_flag |
143 | | 0, 26, 28, |
144 | | //pred_mode_ibc_flag |
145 | | 17, 42, 36, |
146 | | //pred_mode_flag |
147 | | CNU, CNU, |
148 | | //pred_mode_plt_flag |
149 | | 25, |
150 | | //cu_act_enabled_flag |
151 | | 52, |
152 | | //intra_bdpcm_luma_flag |
153 | | 19, |
154 | | //intra_bdpcm_luma_dir_flag |
155 | | 35, |
156 | | //intra_mip_flag |
157 | | 33, 49, 50, 25, |
158 | | //intra_luma_ref_idx |
159 | | 25, 60, |
160 | | //intra_subpartitions_mode_flag |
161 | | 33, |
162 | | //intra_subpartitions_split_flag |
163 | | 43, |
164 | | //intra_luma_mpm_flag |
165 | | 45, |
166 | | //intra_luma_not_planar_flag |
167 | | 13, 28, |
168 | | //intra_bdpcm_chroma_flag |
169 | | 1, |
170 | | //intra_bdpcm_chroma_dir_flag |
171 | | 27, |
172 | | //cclm_mode_flag |
173 | | 59, |
174 | | //cclm_mode_idx |
175 | | 27, |
176 | | //intra_chroma_pred_mode |
177 | | 34, |
178 | | //general_merge_flag |
179 | | 26, |
180 | | //inter_pred_idc |
181 | | CNU, CNU, CNU, CNU, CNU, CNU, |
182 | | //inter_affine_flag |
183 | | CNU, CNU, CNU, |
184 | | //cu_affine_type_flag |
185 | | CNU, |
186 | | //sym_mvd_flag |
187 | | CNU, |
188 | | //ref_idx_l0 and ref_idx_l1 |
189 | | CNU, CNU, |
190 | | //mvp_l0_flag and mvp_l1_flag |
191 | | 42, |
192 | | //amvr_flag |
193 | | CNU, CNU, |
194 | | //amvr_precision_idx |
195 | | 35, 34, 35, |
196 | | //bcw_idx |
197 | | CNU, |
198 | | //cu_coded_flag |
199 | | 6, |
200 | | //cu_sbt_flag |
201 | | CNU, CNU, |
202 | | //cu_sbt_quad_flag |
203 | | CNU, |
204 | | //cu_sbt_horizontal_flag |
205 | | CNU, CNU, CNU, |
206 | | //cu_sbt_pos_flag |
207 | | CNU, |
208 | | //lfnst_idx |
209 | | 28, 52, 42, |
210 | | //mts_idx |
211 | | 29, 0, 28, 0, |
212 | | //copy_above_palette_indices_flag |
213 | | 42, |
214 | | //palette_transpose_flag |
215 | | 42, |
216 | | //run_copy_flag |
217 | | 50, 37, 45, 30, 46, 45, 38, 46, |
218 | | //regular_merge_flag |
219 | | CNU, CNU, |
220 | | //mmvd_merge_flag |
221 | | CNU, |
222 | | //mmvd_cand_flag |
223 | | CNU, |
224 | | //mmvd_distance_idx |
225 | | CNU, |
226 | | //ciip_flag |
227 | | CNU, |
228 | | //merge_subblock_flag |
229 | | CNU, CNU, CNU, |
230 | | //merge_subblock_idx |
231 | | CNU, |
232 | | //merge_idx, merge_gpm_idx0, and merge_gpm_idx1 |
233 | | 34, |
234 | | //abs_mvd_greater0_flag |
235 | | 14, |
236 | | //abs_mvd_greater1_flag |
237 | | 45, |
238 | | //tu_y_coded_flag |
239 | | 15, 12, 5, 7, |
240 | | //tu_cb_coded_flag |
241 | | 12, 21, |
242 | | //tu_cr_coded_flag |
243 | | 33, 28, 36, |
244 | | //cu_qp_delta_abs |
245 | | CNU, CNU, |
246 | | //cu_chroma_qp_offset_flag |
247 | | CNU, |
248 | | //cu_chroma_qp_offset_idx |
249 | | CNU, |
250 | | //transform_skip_flag |
251 | | 25, 9, |
252 | | //tu_joint_cbcr_residual_flag |
253 | | 12, 21, 35, |
254 | | //last_sig_coeff_x_prefix |
255 | | 13, 5, 4, 21, 14, 4, 6, 14, 21, 11, 14, 7, 14, 5, 11, 21, |
256 | | 30, 22, 13, 42, 12, 4, 3, |
257 | | //last_sig_coeff_y_prefix |
258 | | 13, 5, 4, 6, 13, 11, 14, 6, 5, 3, 14, 22, 6, 4, 3, 6, |
259 | | 22, 29, 20, 34, 12, 4, 3, |
260 | | //sb_coded_flag |
261 | | 18, 31, 25, 15, 18, 20, 38, |
262 | | //sig_coeff_flag |
263 | | 25, 19, 28, 14, 25, 20, 29, 30, 19, 37, 30, 38, 11, 38, 46, 54, |
264 | | 27, 39, 39, 39, 44, 39, 39, 39, 18, 39, 39, 39, 27, 39, 39, 39, |
265 | | 0, 39, 39, 39, 25, 27, 28, 37, 34, 53, 53, 46, 19, 46, 38, 39, |
266 | | 52, 39, 39, 39, 11, 39, 39, 39, 19, 39, 39, 39, 25, 28, 38, |
267 | | //par_level_flag |
268 | | 33, 25, 18, 26, 34, 27, 25, 26, 19, 42, 35, 33, 19, 27, 35, 35, |
269 | | 34, 42, 20, 43, 20, 33, 25, 26, 42, 19, 27, 26, 50, 35, 20, 43, |
270 | | 11, |
271 | | //abs_level_gtx_flag |
272 | | 25, 25, 11, 27, 20, 21, 33, 12, 28, 21, 22, 34, 28, 29, 29, 30, |
273 | | 36, 29, 45, 30, 23, 40, 33, 27, 28, 21, 37, 36, 37, 45, 38, 46, |
274 | | 25, 1, 40, 25, 33, 11, 17, 25, 25, 18, 4, 17, 33, 26, 19, 13, |
275 | | 33, 19, 20, 28, 22, 40, 9, 25, 18, 26, 35, 25, 26, 35, 28, 37, |
276 | | 11, 5, 5, 14, 10, 3, 3, 3, |
277 | | //coeff_sign_flag |
278 | | 12, 17, 46, 28, 25, 46, |
279 | | }, |
280 | | { |
281 | | //alf_ctb_flag |
282 | | 13, 23, 46, 4, 61, 54, 19, 46, 54, |
283 | | //alf_use_aps_flag |
284 | | 46, |
285 | | //alf_ctb_cc_cb_idc |
286 | | 18, 21, 38, |
287 | | //alf_ctb_cc_cr_idc |
288 | | 18, 21, 38, |
289 | | //alf_ctb_filter_alt_idx |
290 | | 20, 12, |
291 | | //sao_merge_left_flag and sao_merge_up_flag |
292 | | 60, |
293 | | //sao_type_idx_luma and sao_type_idx_chroma |
294 | | 5, |
295 | | //split_cu_flag |
296 | | 11, 35, 53, 12, 6, 30, 13, 15, 31, |
297 | | //split_qt_flag |
298 | | 20, 14, 23, 18, 19, 6, |
299 | | //mtt_split_cu_vertical_flag |
300 | | 43, 35, 37, 34, 52, |
301 | | //mtt_split_cu_binary_flag |
302 | | 43, 37, 21, 22, |
303 | | //non_inter_flag |
304 | | 25, 12, |
305 | | //cu_skip_flag |
306 | | 57, 59, 45, |
307 | | //pred_mode_ibc_flag |
308 | | 0, 57, 44, |
309 | | //pred_mode_flag |
310 | | 40, 35, |
311 | | //pred_mode_plt_flag |
312 | | 0, |
313 | | //cu_act_enabled_flag |
314 | | 46, |
315 | | //intra_bdpcm_luma_flag |
316 | | 40, |
317 | | //intra_bdpcm_luma_dir_flag |
318 | | 36, |
319 | | //intra_mip_flag |
320 | | 41, 57, 58, 26, |
321 | | //intra_luma_ref_idx |
322 | | 25, 58, |
323 | | //intra_subpartitions_mode_flag |
324 | | 33, |
325 | | //intra_subpartitions_split_flag |
326 | | 36, |
327 | | //intra_luma_mpm_flag |
328 | | 36, |
329 | | //intra_luma_not_planar_flag |
330 | | 12, 20, |
331 | | //intra_bdpcm_chroma_flag |
332 | | 0, |
333 | | //intra_bdpcm_chroma_dir_flag |
334 | | 13, |
335 | | //cclm_mode_flag |
336 | | 34, |
337 | | //cclm_mode_idx |
338 | | 27, |
339 | | //intra_chroma_pred_mode |
340 | | 25, |
341 | | //general_merge_flag |
342 | | 21, |
343 | | //inter_pred_idc |
344 | | 7, 6, 5, 12, 4, 40, |
345 | | //inter_affine_flag |
346 | | 12, 13, 14, |
347 | | //cu_affine_type_flag |
348 | | 35, |
349 | | //sym_mvd_flag |
350 | | 28, |
351 | | //ref_idx_l0 and ref_idx_l1 |
352 | | 20, 35, |
353 | | //mvp_l0_flag and mvp_l1_flag |
354 | | 34, |
355 | | //amvr_flag |
356 | | 59, 58, |
357 | | //amvr_precision_idx |
358 | | 60, 48, 60, |
359 | | //bcw_idx |
360 | | 4, |
361 | | //cu_coded_flag |
362 | | 5, |
363 | | //cu_sbt_flag |
364 | | 56, 57, |
365 | | //cu_sbt_quad_flag |
366 | | 42, |
367 | | //cu_sbt_horizontal_flag |
368 | | 20, 43, 12, |
369 | | //cu_sbt_pos_flag |
370 | | 28, |
371 | | //lfnst_idx |
372 | | 37, 45, 27, |
373 | | //mts_idx |
374 | | 45, 40, 27, 0, |
375 | | //copy_above_palette_indices_flag |
376 | | 59, |
377 | | //palette_transpose_flag |
378 | | 42, |
379 | | //run_copy_flag |
380 | | 51, 30, 30, 38, 23, 38, 53, 46, |
381 | | //regular_merge_flag |
382 | | 38, 7, |
383 | | //mmvd_merge_flag |
384 | | 26, |
385 | | //mmvd_cand_flag |
386 | | 43, |
387 | | //mmvd_distance_idx |
388 | | 60, |
389 | | //ciip_flag |
390 | | 57, |
391 | | //merge_subblock_flag |
392 | | 48, 57, 44, |
393 | | //merge_subblock_idx |
394 | | 5, |
395 | | //merge_idx, merge_gpm_idx0, and merge_gpm_idx1 |
396 | | 20, |
397 | | //abs_mvd_greater0_flag |
398 | | 44, |
399 | | //abs_mvd_greater1_flag |
400 | | 43, |
401 | | //tu_y_coded_flag |
402 | | 23, 5, 20, 7, |
403 | | //tu_cb_coded_flag |
404 | | 25, 28, |
405 | | //tu_cr_coded_flag |
406 | | 25, 29, 45, |
407 | | //cu_qp_delta_abs |
408 | | CNU, CNU, |
409 | | //cu_chroma_qp_offset_flag |
410 | | CNU, |
411 | | //cu_chroma_qp_offset_idx |
412 | | CNU, |
413 | | //transform_skip_flag |
414 | | 25, 9, |
415 | | //tu_joint_cbcr_residual_flag |
416 | | 27, 36, 45, |
417 | | //last_sig_coeff_x_prefix |
418 | | 6, 13, 12, 6, 6, 12, 14, 14, 13, 12, 29, 7, 6, 13, 36, 28, |
419 | | 14, 13, 5, 26, 12, 4, 18, |
420 | | //last_sig_coeff_y_prefix |
421 | | 5, 5, 12, 6, 6, 4, 6, 14, 5, 12, 14, 7, 13, 5, 13, 21, |
422 | | 14, 20, 12, 34, 11, 4, 18, |
423 | | //sb_coded_flag |
424 | | 25, 30, 25, 45, 18, 12, 29, |
425 | | //sig_coeff_flag |
426 | | 17, 41, 42, 29, 25, 49, 43, 37, 33, 58, 51, 30, 19, 38, 38, 46, |
427 | | 34, 54, 54, 39, 6, 39, 39, 39, 19, 39, 54, 39, 19, 39, 39, 39, |
428 | | 56, 39, 39, 39, 17, 34, 35, 21, 41, 59, 60, 38, 35, 45, 53, 54, |
429 | | 44, 39, 39, 39, 34, 38, 62, 39, 26, 39, 39, 39, 40, 35, 44, |
430 | | //par_level_flag |
431 | | 18, 17, 33, 18, 26, 42, 25, 33, 26, 42, 27, 25, 34, 42, 42, 35, |
432 | | 26, 27, 42, 20, 20, 25, 25, 26, 11, 19, 27, 33, 42, 35, 35, 43, |
433 | | 3, |
434 | | //abs_level_gtx_flag |
435 | | 0, 17, 26, 19, 35, 21, 25, 34, 20, 28, 29, 33, 27, 28, 29, 22, |
436 | | 34, 28, 44, 37, 38, 0, 25, 19, 20, 13, 14, 57, 44, 30, 30, 23, |
437 | | 17, 0, 1, 17, 25, 18, 0, 9, 25, 33, 34, 9, 25, 18, 26, 20, |
438 | | 25, 18, 19, 27, 29, 17, 9, 25, 10, 18, 4, 17, 33, 19, 20, 29, |
439 | | 18, 11, 4, 28, 2, 10, 3, 3, |
440 | | //coeff_sign_flag |
441 | | 5, 10, 53, 43, 25, 46, |
442 | | }, |
443 | | { |
444 | | //alf_ctb_flag |
445 | | 33, 52, 46, 25, 61, 54, 25, 61, 54, |
446 | | //alf_use_aps_flag |
447 | | 46, |
448 | | //alf_ctb_cc_cb_idc |
449 | | 25, 35, 38, |
450 | | //alf_ctb_cc_cr_idc |
451 | | 25, 28, 38, |
452 | | //alf_ctb_filter_alt_idx |
453 | | 11, 26, |
454 | | //sao_merge_left_flag and sao_merge_up_flag |
455 | | 2, |
456 | | //sao_type_idx_luma and sao_type_idx_chroma |
457 | | 2, |
458 | | //split_cu_flag |
459 | | 18, 27, 15, 18, 28, 45, 26, 7, 23, |
460 | | //split_qt_flag |
461 | | 26, 36, 38, 18, 34, 21, |
462 | | //mtt_split_cu_vertical_flag |
463 | | 43, 42, 37, 42, 44, |
464 | | //mtt_split_cu_binary_flag |
465 | | 28, 29, 28, 29, |
466 | | //non_inter_flag |
467 | | 25, 20, |
468 | | //cu_skip_flag |
469 | | 57, 60, 46, |
470 | | //pred_mode_ibc_flag |
471 | | 0, 43, 45, |
472 | | //pred_mode_flag |
473 | | 40, 35, |
474 | | //pred_mode_plt_flag |
475 | | 17, |
476 | | //cu_act_enabled_flag |
477 | | 46, |
478 | | //intra_bdpcm_luma_flag |
479 | | 19, |
480 | | //intra_bdpcm_luma_dir_flag |
481 | | 21, |
482 | | //intra_mip_flag |
483 | | 56, 57, 50, 26, |
484 | | //intra_luma_ref_idx |
485 | | 25, 59, |
486 | | //intra_subpartitions_mode_flag |
487 | | 33, |
488 | | //intra_subpartitions_split_flag |
489 | | 43, |
490 | | //intra_luma_mpm_flag |
491 | | 44, |
492 | | //intra_luma_not_planar_flag |
493 | | 13, 6, |
494 | | //intra_bdpcm_chroma_flag |
495 | | 0, |
496 | | //intra_bdpcm_chroma_dir_flag |
497 | | 28, |
498 | | //cclm_mode_flag |
499 | | 26, |
500 | | //cclm_mode_idx |
501 | | 27, |
502 | | //intra_chroma_pred_mode |
503 | | 25, |
504 | | //general_merge_flag |
505 | | 6, |
506 | | //inter_pred_idc |
507 | | 14, 13, 5, 4, 3, 40, |
508 | | //inter_affine_flag |
509 | | 19, 13, 6, |
510 | | //cu_affine_type_flag |
511 | | 35, |
512 | | //sym_mvd_flag |
513 | | 28, |
514 | | //ref_idx_l0 and ref_idx_l1 |
515 | | 5, 35, |
516 | | //mvp_l0_flag and mvp_l1_flag |
517 | | 34, |
518 | | //amvr_flag |
519 | | 59, 50, |
520 | | //amvr_precision_idx |
521 | | 38, 26, 60, |
522 | | //bcw_idx |
523 | | 5, |
524 | | //cu_coded_flag |
525 | | 12, |
526 | | //cu_sbt_flag |
527 | | 41, 57, |
528 | | //cu_sbt_quad_flag |
529 | | 42, |
530 | | //cu_sbt_horizontal_flag |
531 | | 35, 51, 27, |
532 | | //cu_sbt_pos_flag |
533 | | 28, |
534 | | //lfnst_idx |
535 | | 52, 37, 27, |
536 | | //mts_idx |
537 | | 45, 25, 27, 0, |
538 | | //copy_above_palette_indices_flag |
539 | | 50, |
540 | | //palette_transpose_flag |
541 | | 35, |
542 | | //run_copy_flag |
543 | | 58, 45, 45, 30, 38, 45, 38, 46, |
544 | | //regular_merge_flag |
545 | | 46, 15, |
546 | | //mmvd_merge_flag |
547 | | 25, |
548 | | //mmvd_cand_flag |
549 | | 43, |
550 | | //mmvd_distance_idx |
551 | | 59, |
552 | | //ciip_flag |
553 | | 57, |
554 | | //merge_subblock_flag |
555 | | 25, 58, 45, |
556 | | //merge_subblock_idx |
557 | | 4, |
558 | | //merge_idx, merge_gpm_idx0, and merge_gpm_idx1 |
559 | | 18, |
560 | | //abs_mvd_greater0_flag |
561 | | 51, |
562 | | //abs_mvd_greater1_flag |
563 | | 36, |
564 | | //tu_y_coded_flag |
565 | | 15, 6, 5, 14, |
566 | | //tu_cb_coded_flag |
567 | | 25, 37, |
568 | | //tu_cr_coded_flag |
569 | | 9, 36, 45, |
570 | | //cu_qp_delta_abs |
571 | | CNU, CNU, |
572 | | //cu_chroma_qp_offset_flag |
573 | | CNU, |
574 | | //cu_chroma_qp_offset_idx |
575 | | CNU, |
576 | | //transform_skip_flag |
577 | | 25, 17, |
578 | | //tu_joint_cbcr_residual_flag |
579 | | 42, 43, 52, |
580 | | //last_sig_coeff_x_prefix |
581 | | 6, 6, 12, 14, 6, 4, 14, 7, 6, 4, 29, 7, 6, 6, 12, 28, |
582 | | 7, 13, 13, 35, 19, 5, 4, |
583 | | //last_sig_coeff_y_prefix |
584 | | 5, 5, 20, 13, 13, 19, 21, 6, 12, 12, 14, 14, 5, 4, 12, 13, |
585 | | 7, 13, 12, 41, 11, 5, 27, |
586 | | //sb_coded_flag |
587 | | 25, 45, 25, 14, 18, 35, 45, |
588 | | //sig_coeff_flag |
589 | | 17, 41, 49, 36, 1, 49, 50, 37, 48, 51, 58, 45, 26, 45, 53, 46, |
590 | | 49, 54, 61, 39, 35, 39, 39, 39, 19, 54, 39, 39, 50, 39, 39, 39, |
591 | | 0, 39, 39, 39, 9, 49, 50, 36, 48, 59, 59, 38, 34, 45, 38, 31, |
592 | | 58, 39, 39, 39, 34, 38, 54, 39, 41, 39, 39, 39, 25, 50, 37, |
593 | | //par_level_flag |
594 | | 33, 40, 25, 41, 26, 42, 25, 33, 26, 34, 27, 25, 41, 42, 42, 35, |
595 | | 33, 27, 35, 42, 43, 33, 25, 26, 34, 19, 27, 33, 42, 43, 35, 43, |
596 | | 11, |
597 | | //abs_level_gtx_flag |
598 | | 0, 0, 33, 34, 35, 21, 25, 34, 35, 28, 29, 40, 42, 43, 29, 30, |
599 | | 49, 36, 37, 45, 38, 0, 40, 34, 43, 36, 37, 57, 52, 45, 38, 46, |
600 | | 25, 0, 0, 17, 25, 26, 0, 9, 25, 33, 19, 0, 25, 33, 26, 20, |
601 | | 25, 33, 27, 35, 22, 25, 1, 25, 33, 26, 12, 25, 33, 27, 28, 37, |
602 | | 19, 11, 4, 6, 3, 4, 4, 5, |
603 | | //coeff_sign_flag |
604 | | 35, 25, 46, 28, 33, 38, |
605 | | }, |
606 | | //shiftIdx |
607 | | { |
608 | | //alf_ctb_flag |
609 | | 0, 0, 0, 4, 0, 0, 1, 0, 0, |
610 | | //alf_use_aps_flag |
611 | | 0, |
612 | | //alf_ctb_cc_cb_idc |
613 | | 4, 1, 4, |
614 | | //alf_ctb_cc_cr_idc |
615 | | 4, 1, 4, |
616 | | //alf_ctb_filter_alt_idx |
617 | | 0, 0, |
618 | | //sao_merge_left_flag and sao_merge_up_flag |
619 | | 0, |
620 | | //sao_type_idx_luma and sao_type_idx_chroma |
621 | | 4, |
622 | | //split_cu_flag |
623 | | 12, 13, 8, 8, 13, 12, 5, 9, 9, |
624 | | //split_qt_flag |
625 | | 0, 8, 8, 12, 12, 8, |
626 | | //mtt_split_cu_vertical_flag |
627 | | 9, 8, 9, 8, 5, |
628 | | //mtt_split_cu_binary_flag |
629 | | 12, 13, 12, 13, |
630 | | //non_inter_flag |
631 | | 1, 0, |
632 | | //cu_skip_flag |
633 | | 5, 4, 8, |
634 | | //pred_mode_ibc_flag |
635 | | 1, 5, 8, |
636 | | //pred_mode_flag |
637 | | 5, 1, |
638 | | //pred_mode_plt_flag |
639 | | 1, |
640 | | //cu_act_enabled_flag |
641 | | 1, |
642 | | //intra_bdpcm_luma_flag |
643 | | 1, |
644 | | //intra_bdpcm_luma_dir_flag |
645 | | 4, |
646 | | //intra_mip_flag |
647 | | 9, 10, 9, 6, |
648 | | //intra_luma_ref_idx |
649 | | 5, 8, |
650 | | //intra_subpartitions_mode_flag |
651 | | 9, |
652 | | //intra_subpartitions_split_flag |
653 | | 2, |
654 | | //intra_luma_mpm_flag |
655 | | 6, |
656 | | //intra_luma_not_planar_flag |
657 | | 1, 5, |
658 | | //intra_bdpcm_chroma_flag |
659 | | 1, |
660 | | //intra_bdpcm_chroma_dir_flag |
661 | | 0, |
662 | | //cclm_mode_flag |
663 | | 4, |
664 | | //cclm_mode_idx |
665 | | 9, |
666 | | //intra_chroma_pred_mode |
667 | | 5, |
668 | | //general_merge_flag |
669 | | 4, |
670 | | //inter_pred_idc |
671 | | 0, 0, 1, 4, 4, 0, |
672 | | //inter_affine_flag |
673 | | 4, 0, 0, |
674 | | //cu_affine_type_flag |
675 | | 4, |
676 | | //sym_mvd_flag |
677 | | 5, |
678 | | //ref_idx_l0 and ref_idx_l1 |
679 | | 0, 4, |
680 | | //mvp_l0_flag and mvp_l1_flag |
681 | | 12, |
682 | | //amvr_flag |
683 | | 0, 0, |
684 | | //amvr_precision_idx |
685 | | 4, 5, 0, |
686 | | //bcw_idx |
687 | | 1, |
688 | | //cu_coded_flag |
689 | | 4, |
690 | | //cu_sbt_flag |
691 | | 1, 5, |
692 | | //cu_sbt_quad_flag |
693 | | 10, |
694 | | //cu_sbt_horizontal_flag |
695 | | 8, 4, 1, |
696 | | //cu_sbt_pos_flag |
697 | | 13, |
698 | | //lfnst_idx |
699 | | 9, 9, 10, |
700 | | //mts_idx |
701 | | 8, 0, 9, 0, |
702 | | //copy_above_palette_indices_flag |
703 | | 9, |
704 | | //palette_transpose_flag |
705 | | 5, |
706 | | //run_copy_flag |
707 | | 9, 6, 9, 10, 5, 0, 9, 5, |
708 | | //regular_merge_flag |
709 | | 5, 5, |
710 | | //mmvd_merge_flag |
711 | | 4, |
712 | | //mmvd_cand_flag |
713 | | 10, |
714 | | //mmvd_distance_idx |
715 | | 0, |
716 | | //ciip_flag |
717 | | 1, |
718 | | //merge_subblock_flag |
719 | | 4, 4, 4, |
720 | | //merge_subblock_idx |
721 | | 0, |
722 | | //merge_idx, merge_gpm_idx0, and merge_gpm_idx1 |
723 | | 4, |
724 | | //abs_mvd_greater0_flag |
725 | | 9, |
726 | | //abs_mvd_greater1_flag |
727 | | 5, |
728 | | //tu_y_coded_flag |
729 | | 5, 1, 8, 9, |
730 | | //tu_cb_coded_flag |
731 | | 5, 0, |
732 | | //tu_cr_coded_flag |
733 | | 2, 1, 0, |
734 | | //cu_qp_delta_abs |
735 | | 8, 8, |
736 | | //cu_chroma_qp_offset_flag |
737 | | 8, |
738 | | //cu_chroma_qp_offset_idx |
739 | | 8, |
740 | | //transform_skip_flag |
741 | | 1, 1, |
742 | | //tu_joint_cbcr_residual_flag |
743 | | 1, 1, 0, |
744 | | //last_sig_coeff_x_prefix |
745 | | 8, 5, 4, 5, 4, 4, 5, 4, 1, 0, 4, 1, 0, 0, 0, 0, |
746 | | 1, 0, 0, 0, 5, 4, 4, |
747 | | //last_sig_coeff_y_prefix |
748 | | 8, 5, 8, 5, 5, 4, 5, 5, 4, 0, 5, 4, 1, 0, 0, 1, |
749 | | 4, 0, 0, 0, 6, 5, 5, |
750 | | //sb_coded_flag |
751 | | 8, 5, 5, 8, 5, 8, 8, |
752 | | //sig_coeff_flag |
753 | | 12, 9, 9, 10, 9, 9, 9, 10, 8, 8, 8, 10, 9, 13, 8, 8, |
754 | | 8, 8, 8, 5, 8, 0, 0, 0, 8, 8, 8, 8, 8, 0, 4, 4, |
755 | | 0, 0, 0, 0, 12, 12, 9, 13, 4, 5, 8, 9, 8, 12, 12, 8, |
756 | | 4, 0, 0, 0, 8, 8, 8, 8, 4, 0, 0, 0, 13, 13, 8, |
757 | | //par_level_flag |
758 | | 8, 9, 12, 13, 13, 13, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13, |
759 | | 10, 13, 13, 13, 13, 8, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, |
760 | | 6, |
761 | | //abs_level_gtx_flag |
762 | | 9, 5, 10, 13, 13, 10, 9, 10, 13, 13, 13, 9, 10, 10, 10, 13, |
763 | | 8, 9, 10, 10, 13, 8, 8, 9, 12, 12, 10, 5, 9, 9, 9, 13, |
764 | | 1, 5, 9, 9, 9, 6, 5, 9, 10, 10, 9, 9, 9, 9, 9, 9, |
765 | | 6, 8, 9, 9, 10, 1, 5, 8, 8, 9, 6, 6, 9, 8, 8, 9, |
766 | | 4, 2, 1, 6, 1, 1, 1, 1, |
767 | | //coeff_sign_flag |
768 | | 1, 4, 4, 5, 8, 8, |
769 | | } |
770 | | }; |
771 | | |
772 | | #define MAX_SUB_BLOCKS 16 |
773 | | #define MAX_SUB_BLOCK_SIZE 4 |
774 | | #define MAX_TB_SIZE 64 |
775 | | |
776 | | typedef struct ResidualCoding { |
777 | | //common for ts and non ts |
778 | | TransformBlock *tb; |
779 | | |
780 | | int log2_sb_w; |
781 | | int log2_sb_h; |
782 | | int last_sub_block; |
783 | | int hist_value; |
784 | | int update_hist; |
785 | | int num_sb_coeff; |
786 | | int rem_bins_pass1; |
787 | | |
788 | | int width_in_sbs; |
789 | | int height_in_sbs; |
790 | | int nb_sbs; |
791 | | |
792 | | const uint8_t *sb_scan_x_off; |
793 | | const uint8_t *sb_scan_y_off; |
794 | | const uint8_t *scan_x_off; |
795 | | const uint8_t *scan_y_off; |
796 | | |
797 | | uint8_t sb_coded_flag[MAX_SUB_BLOCKS * MAX_SUB_BLOCKS]; |
798 | | int sig_coeff_flag[MAX_TB_SIZE * MAX_TB_SIZE]; |
799 | | int abs_level_pass1[MAX_TB_SIZE * MAX_TB_SIZE]; ///< AbsLevelPass1[][] |
800 | | int abs_level[MAX_TB_SIZE * MAX_TB_SIZE]; |
801 | | |
802 | | //for ts only |
803 | | uint8_t infer_sb_cbf; |
804 | | int coeff_sign_level[MAX_TB_SIZE * MAX_TB_SIZE]; ///< CoeffSignLevel[][] |
805 | | |
806 | | //for non ts only |
807 | | int qstate; |
808 | | int last_scan_pos; |
809 | | int last_significant_coeff_x; |
810 | | int last_significant_coeff_y; |
811 | | } ResidualCoding; |
812 | | |
813 | | static int cabac_reinit(VVCLocalContext *lc) |
814 | 29.6k | { |
815 | 29.6k | return skip_bytes(&lc->ep->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0; |
816 | 29.6k | } |
817 | | |
818 | | static void cabac_init_state(VVCLocalContext *lc) |
819 | 1.47M | { |
820 | 1.47M | const VVCSPS *sps = lc->fc->ps.sps; |
821 | 1.47M | const H266RawSliceHeader *rsh = lc->sc->sh.r; |
822 | 1.47M | const int qp = av_clip_uintp2(lc->sc->sh.slice_qp_y, 6); |
823 | 1.47M | int init_type = 2 - rsh->sh_slice_type; |
824 | | |
825 | 1.47M | ff_vvc_ep_init_stat_coeff(lc->ep, sps->bit_depth, sps->r->sps_persistent_rice_adaptation_enabled_flag); |
826 | | |
827 | 1.47M | if (rsh->sh_cabac_init_flag && !IS_I(rsh)) |
828 | 85.7k | init_type ^= 3; |
829 | | |
830 | 557M | for (int i = 0; i < VVC_CONTEXTS; i++) { |
831 | 556M | VVCCabacState *state = &lc->ep->cabac_state[i]; |
832 | 556M | const int init_value = init_values[init_type][i]; |
833 | 556M | const int shift_idx = init_values[3][i]; |
834 | 556M | const int m = (init_value >> 3) - 4; |
835 | 556M | const int n = ((init_value & 7) * 18) + 1; |
836 | 556M | const int pre = av_clip(((m * (qp - 16)) >> 1) + n, 1, 127); |
837 | | |
838 | 556M | state->state[0] = pre << 3; |
839 | 556M | state->state[1] = pre << 7; |
840 | 556M | state->shift[0] = (shift_idx >> 2 ) + 2; |
841 | 556M | state->shift[1] = (shift_idx & 3 ) + 3 + state->shift[0]; |
842 | 556M | } |
843 | 1.47M | } |
844 | | |
845 | | int ff_vvc_cabac_init(VVCLocalContext *lc, |
846 | | const int ctu_idx, const int rx, const int ry) |
847 | 1.57M | { |
848 | 1.57M | int ret = 0; |
849 | 1.57M | const VVCPPS *pps = lc->fc->ps.pps; |
850 | 1.57M | const int first_ctb_in_slice = !ctu_idx; |
851 | 1.57M | const int first_ctb_in_tile = rx == pps->ctb_to_col_bd[rx] && ry == pps->ctb_to_row_bd[ry]; |
852 | | |
853 | 1.57M | if (first_ctb_in_slice|| first_ctb_in_tile) { |
854 | 1.47M | if (lc->sc->nb_eps == 1 && !first_ctb_in_slice) |
855 | 0 | ret = cabac_reinit(lc); |
856 | 1.47M | if (!ret) |
857 | 1.47M | cabac_init_state(lc); |
858 | 1.47M | } |
859 | 1.57M | return ret; |
860 | 1.57M | } |
861 | | |
862 | | //fixme |
863 | 9.27M | static void vvc_refill2(CABACContext* c) { |
864 | 9.27M | int i; |
865 | 9.27M | unsigned x; |
866 | 9.27M | #if !HAVE_FAST_CLZ |
867 | 9.27M | x = c->low ^ (c->low - 1); |
868 | 9.27M | i = 7 - ff_h264_norm_shift[x >> (CABAC_BITS - 1)]; |
869 | | #else |
870 | | i = ff_ctz(c->low) - CABAC_BITS; |
871 | | #endif |
872 | | |
873 | 9.27M | x = -CABAC_MASK; |
874 | | |
875 | 9.27M | #if CABAC_BITS == 16 |
876 | 9.27M | x += (c->bytestream[0] << 9) + (c->bytestream[1] << 1); |
877 | | #else |
878 | | x += c->bytestream[0] << 1; |
879 | | #endif |
880 | | |
881 | 9.27M | c->low += x << i; |
882 | 9.27M | #if !UNCHECKED_BITSTREAM_READER |
883 | 9.27M | if (c->bytestream < c->bytestream_end) |
884 | 5.11M | #endif |
885 | 5.11M | c->bytestream += CABAC_BITS / 8; |
886 | 9.27M | } |
887 | | |
888 | | static int inline vvc_get_cabac(CABACContext *c, VVCCabacState* base, const int ctx) |
889 | 519M | { |
890 | 519M | VVCCabacState *s = base + ctx; |
891 | 519M | const int qRangeIdx = c->range >> 5; |
892 | 519M | const int pState = s->state[1] + (s->state[0] << 4); |
893 | 519M | const int valMps = pState >> 14; |
894 | 519M | const int RangeLPS = (qRangeIdx * ((valMps ? 32767 - pState : pState) >> 9 ) >> 1) + 4; |
895 | 519M | int bit, lps_mask; |
896 | | |
897 | 519M | c->range -= RangeLPS; |
898 | 519M | lps_mask = ((c->range<<(CABAC_BITS+1)) - c->low)>>31; |
899 | | |
900 | 519M | c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask; |
901 | 519M | c->range += (RangeLPS - c->range) & lps_mask; |
902 | | |
903 | 519M | bit = valMps ^ (lps_mask & 1); |
904 | | |
905 | 519M | lps_mask = ff_h264_norm_shift[c->range]; |
906 | 519M | c->range <<= lps_mask; |
907 | 519M | c->low <<= lps_mask; |
908 | | |
909 | 519M | if (!(c->low & CABAC_MASK)) |
910 | 9.27M | vvc_refill2(c); |
911 | 519M | s->state[0] = s->state[0] - (s->state[0] >> s->shift[0]) + (1023 * bit >> s->shift[0]); |
912 | 519M | s->state[1] = s->state[1] - (s->state[1] >> s->shift[1]) + (16383 * bit >> s->shift[1]); |
913 | 519M | return bit; |
914 | 519M | } |
915 | | |
916 | 519M | #define GET_CABAC(ctx) vvc_get_cabac(&lc->ep->cc, lc->ep->cabac_state, ctx) |
917 | | |
918 | | //9.3.3.4 Truncated binary (TB) binarization process |
919 | | static int truncated_binary_decode(VVCLocalContext *lc, const int c_max) |
920 | 2.08M | { |
921 | 2.08M | const int n = c_max + 1; |
922 | 2.08M | const int k = av_log2(n); |
923 | 2.08M | const int u = (1 << (k+1)) - n; |
924 | 2.08M | int v = 0; |
925 | 10.2M | for (int i = 0; i < k; i++) |
926 | 8.14M | v = (v << 1) | get_cabac_bypass(&lc->ep->cc); |
927 | 2.08M | if (v >= u) { |
928 | 1.15M | v = (v << 1) | get_cabac_bypass(&lc->ep->cc); |
929 | 1.15M | v -= u; |
930 | 1.15M | } |
931 | 2.08M | return v; |
932 | 2.08M | } |
933 | | |
934 | | // 9.3.3.5 k-th order Exp - Golomb binarization process |
935 | | static int kth_order_egk_decode(CABACContext *c, int k, const int max) |
936 | 985k | { |
937 | 985k | int bit = 1; |
938 | 985k | int value = 0; |
939 | 985k | int symbol = 0; |
940 | | |
941 | 2.70M | while (bit) { |
942 | 1.72M | bit = get_cabac_bypass(c); |
943 | 1.72M | if (max - value < (bit << k)) |
944 | 6.04k | return AVERROR_INVALIDDATA; |
945 | 1.72M | value += bit << k++; |
946 | 1.72M | } |
947 | | |
948 | 979k | if (--k) { |
949 | 6.18M | for (int i = 0; i < k; i++) |
950 | 5.21M | symbol = (symbol << 1) | get_cabac_bypass(c); |
951 | 967k | value += symbol; |
952 | 967k | } |
953 | | |
954 | 979k | if (value > max) |
955 | 4.35k | return AVERROR_INVALIDDATA; |
956 | | |
957 | 975k | return value; |
958 | 979k | } |
959 | | |
960 | | // 9.3.3.6 Limited k-th order Exp-Golomb binarization process |
961 | | static int limited_kth_order_egk_decode(CABACContext *c, const int k, const int max_pre_ext_len, const int trunc_suffix_len) |
962 | 692k | { |
963 | 692k | int pre_ext_len = 0; |
964 | 692k | int escape_length; |
965 | 692k | int val = 0; |
966 | 2.03M | while ((pre_ext_len < max_pre_ext_len) && get_cabac_bypass(c)) |
967 | 1.34M | pre_ext_len++; |
968 | 692k | if (pre_ext_len == max_pre_ext_len) |
969 | 87.6k | escape_length = trunc_suffix_len; |
970 | 604k | else |
971 | 604k | escape_length = pre_ext_len + k; |
972 | 3.32M | while (escape_length-- > 0) { |
973 | 2.63M | val = (val << 1) + get_cabac_bypass(c); |
974 | 2.63M | } |
975 | 692k | val += ((1 << pre_ext_len) - 1) << k; |
976 | 692k | return val; |
977 | 692k | } |
978 | | |
979 | | // 9.3.3.7 Fixed-length binarization process |
980 | | static int fixed_length_decode(CABACContext* c, const int len) |
981 | 722k | { |
982 | 722k | int value = 0; |
983 | | |
984 | 8.40M | for (int i = 0; i < len; i++) |
985 | 7.67M | value = (value << 1) | get_cabac_bypass(c); |
986 | | |
987 | 722k | return value; |
988 | 722k | } |
989 | | |
990 | | static av_always_inline |
991 | | void get_left_top(const VVCLocalContext *lc, uint8_t *left, uint8_t *top, |
992 | | const int x0, const int y0, const uint8_t *left_ctx, const uint8_t *top_ctx) |
993 | 17.4M | { |
994 | 17.4M | const VVCFrameContext *fc = lc->fc; |
995 | 17.4M | const VVCSPS *sps = fc->ps.sps; |
996 | 17.4M | const int min_cb_width = fc->ps.pps->min_cb_width; |
997 | 17.4M | const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y); |
998 | 17.4M | const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y); |
999 | 17.4M | const int x_cb = x0 >> sps->min_cb_log2_size_y; |
1000 | 17.4M | const int y_cb = y0 >> sps->min_cb_log2_size_y; |
1001 | | |
1002 | 17.4M | if (lc->ctb_left_flag || x0b) |
1003 | 10.4M | *left = SAMPLE_CTB(left_ctx, x_cb - 1, y_cb); |
1004 | 17.4M | if (lc->ctb_up_flag || y0b) |
1005 | 11.0M | *top = SAMPLE_CTB(top_ctx, x_cb, y_cb - 1); |
1006 | 17.4M | } |
1007 | | |
1008 | | static av_always_inline |
1009 | | uint8_t get_inc(VVCLocalContext *lc, const uint8_t *ctx) |
1010 | 3.26M | { |
1011 | 3.26M | uint8_t left = 0, top = 0; |
1012 | 3.26M | get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx); |
1013 | 3.26M | return left + top; |
1014 | 3.26M | } |
1015 | | |
1016 | | int ff_vvc_sao_merge_flag_decode(VVCLocalContext *lc) |
1017 | 111k | { |
1018 | 111k | return GET_CABAC(SAO_MERGE_FLAG); |
1019 | 111k | } |
1020 | | |
1021 | | int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc) |
1022 | 1.44M | { |
1023 | 1.44M | if (!GET_CABAC(SAO_TYPE_IDX)) |
1024 | 1.23M | return SAO_NOT_APPLIED; |
1025 | | |
1026 | 209k | if (!get_cabac_bypass(&lc->ep->cc)) |
1027 | 88.8k | return SAO_BAND; |
1028 | 120k | return SAO_EDGE; |
1029 | 209k | } |
1030 | | |
1031 | | int ff_vvc_sao_band_position_decode(VVCLocalContext *lc) |
1032 | 108k | { |
1033 | 108k | return fixed_length_decode(&lc->ep->cc, 5); |
1034 | 108k | } |
1035 | | |
1036 | | int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc) |
1037 | 1.29M | { |
1038 | 1.29M | int i = 0; |
1039 | 1.29M | const int length = (1 << (FFMIN(lc->fc->ps.sps->bit_depth, 10) - 5)) - 1; |
1040 | | |
1041 | 2.64M | while (i < length && get_cabac_bypass(&lc->ep->cc)) |
1042 | 1.35M | i++; |
1043 | 1.29M | return i; |
1044 | 1.29M | } |
1045 | | |
1046 | | int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc) |
1047 | 202k | { |
1048 | 202k | return get_cabac_bypass(&lc->ep->cc); |
1049 | 202k | } |
1050 | | |
1051 | | int ff_vvc_sao_eo_class_decode(VVCLocalContext *lc) |
1052 | 120k | { |
1053 | 120k | return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc); |
1054 | 120k | } |
1055 | | |
1056 | | int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx) |
1057 | 335k | { |
1058 | 335k | int inc = c_idx * 3; |
1059 | 335k | const VVCFrameContext *fc = lc->fc; |
1060 | 335k | if (lc->ctb_left_flag) { |
1061 | 298k | const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry); |
1062 | 298k | inc += left->ctb_flag[c_idx]; |
1063 | 298k | } |
1064 | 335k | if (lc->ctb_up_flag) { |
1065 | 281k | const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1); |
1066 | 281k | inc += above->ctb_flag[c_idx]; |
1067 | 281k | } |
1068 | 335k | return GET_CABAC(ALF_CTB_FLAG + inc); |
1069 | 335k | } |
1070 | | |
1071 | | int ff_vvc_alf_use_aps_flag(VVCLocalContext *lc) |
1072 | 105k | { |
1073 | 105k | return GET_CABAC(ALF_USE_APS_FLAG); |
1074 | 105k | } |
1075 | | |
1076 | | int ff_vvc_alf_luma_prev_filter_idx(VVCLocalContext *lc) |
1077 | 0 | { |
1078 | 0 | return truncated_binary_decode(lc, lc->sc->sh.r->sh_num_alf_aps_ids_luma - 1); |
1079 | 0 | } |
1080 | | |
1081 | | int ff_vvc_alf_luma_fixed_filter_idx(VVCLocalContext *lc) |
1082 | 17.2k | { |
1083 | 17.2k | return truncated_binary_decode(lc, 15); |
1084 | 17.2k | } |
1085 | | |
1086 | | int ff_vvc_alf_ctb_filter_alt_idx(VVCLocalContext *lc, const int c_idx, const int num_chroma_filters) |
1087 | 40.2k | { |
1088 | 40.2k | int i = 0; |
1089 | 40.2k | const int length = num_chroma_filters - 1; |
1090 | | |
1091 | 47.5k | while (i < length && GET_CABAC(ALF_CTB_FILTER_ALT_IDX + c_idx - 1)) |
1092 | 7.29k | i++; |
1093 | 40.2k | return i; |
1094 | 40.2k | } |
1095 | | |
1096 | | int ff_vvc_alf_ctb_cc_idc(VVCLocalContext *lc, const int rx, const int ry, const int idx, const int cc_filters_signalled) |
1097 | 106k | { |
1098 | 106k | int inc = !idx ? ALF_CTB_CC_CB_IDC : ALF_CTB_CC_CR_IDC; |
1099 | 106k | int i = 0; |
1100 | 106k | const VVCFrameContext *fc = lc->fc; |
1101 | 106k | if (lc->ctb_left_flag) { |
1102 | 99.4k | const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry); |
1103 | 99.4k | inc += left->ctb_cc_idc[idx] != 0; |
1104 | 99.4k | } |
1105 | 106k | if (lc->ctb_up_flag) { |
1106 | 93.9k | const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1); |
1107 | 93.9k | inc += above->ctb_cc_idc[idx] != 0; |
1108 | 93.9k | } |
1109 | | |
1110 | 106k | if (!GET_CABAC(inc)) |
1111 | 71.1k | return 0; |
1112 | 35.6k | i++; |
1113 | 43.5k | while (i < cc_filters_signalled && get_cabac_bypass(&lc->ep->cc)) |
1114 | 7.96k | i++; |
1115 | 35.6k | return i; |
1116 | 106k | } |
1117 | | |
1118 | | int ff_vvc_split_cu_flag(VVCLocalContext *lc, const int x0, const int y0, |
1119 | | const int cb_width, const int cb_height, const int is_chroma, const VVCAllowedSplit *a) |
1120 | 19.7M | { |
1121 | 19.7M | const VVCFrameContext *fc = lc->fc; |
1122 | 19.7M | const VVCPPS *pps = fc->ps.pps; |
1123 | 19.7M | const int is_inside = (x0 + cb_width <= pps->width) && (y0 + cb_height <= pps->height); |
1124 | | |
1125 | 19.7M | if ((a->btv || a->bth || a->ttv || a->tth || a->qt) && is_inside) |
1126 | 7.28M | { |
1127 | 7.28M | uint8_t inc = 0, left_height = cb_height, top_width = cb_width; |
1128 | | |
1129 | 7.28M | get_left_top(lc, &left_height, &top_width, x0, y0, fc->tab.cb_height[is_chroma], fc->tab.cb_width[is_chroma]); |
1130 | 7.28M | inc += left_height < cb_height; |
1131 | 7.28M | inc += top_width < cb_width; |
1132 | 7.28M | inc += (a->btv + a->bth + a->ttv + a->tth + 2 * a->qt - 1) / 2 * 3; |
1133 | | |
1134 | 7.28M | return GET_CABAC(SPLIT_CU_FLAG + inc); |
1135 | | |
1136 | 7.28M | } |
1137 | 12.5M | return !is_inside; |
1138 | 19.7M | } |
1139 | | |
1140 | | static int split_qt_flag_decode(VVCLocalContext *lc, const int x0, const int y0, const int ch_type, const int cqt_depth) |
1141 | 1.22M | { |
1142 | 1.22M | const VVCFrameContext *fc = lc->fc; |
1143 | 1.22M | int inc = 0; |
1144 | 1.22M | uint8_t depth_left = 0, depth_top = 0; |
1145 | | |
1146 | 1.22M | get_left_top(lc, &depth_left, &depth_top, x0, y0, fc->tab.cqt_depth[ch_type], fc->tab.cqt_depth[ch_type]); |
1147 | 1.22M | inc += depth_left > cqt_depth; |
1148 | 1.22M | inc += depth_top > cqt_depth; |
1149 | 1.22M | inc += (cqt_depth >= 2) * 3; |
1150 | | |
1151 | 1.22M | return GET_CABAC(SPLIT_QT_FLAG + inc); |
1152 | 1.22M | } |
1153 | | |
1154 | | static int mtt_split_cu_vertical_flag_decode(VVCLocalContext *lc, const int x0, const int y0, |
1155 | | const int cb_width, const int cb_height, const int ch_type, const VVCAllowedSplit* a) |
1156 | 3.44M | { |
1157 | 3.44M | if ((a->bth || a->tth) && (a->btv || a->ttv)) { |
1158 | 1.98M | int inc; |
1159 | 1.98M | const int v = a->btv + a->ttv; |
1160 | 1.98M | const int h = a->bth + a->tth; |
1161 | 1.98M | if (v > h) |
1162 | 126k | inc = 4; |
1163 | 1.85M | else if (v < h) |
1164 | 148k | inc = 3; |
1165 | 1.70M | else { |
1166 | 1.70M | const VVCFrameContext *fc = lc->fc; |
1167 | 1.70M | const VVCSPS *sps = fc->ps.sps; |
1168 | 1.70M | const int min_cb_width = fc->ps.pps->min_cb_width; |
1169 | 1.70M | const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y); |
1170 | 1.70M | const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y); |
1171 | 1.70M | const int x_cb = x0 >> sps->min_cb_log2_size_y; |
1172 | 1.70M | const int y_cb = y0 >> sps->min_cb_log2_size_y; |
1173 | 1.70M | const int available_a = lc->ctb_up_flag || y0b; |
1174 | 1.70M | const int available_l = lc->ctb_left_flag || x0b; |
1175 | 1.70M | const int da = cb_width / (available_a ? SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cb, y_cb - 1) : 1); |
1176 | 1.70M | const int dl = cb_height / (available_l ? SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cb - 1, y_cb) : 1); |
1177 | | |
1178 | 1.70M | if (da == dl || !available_a || !available_l) |
1179 | 710k | inc = 0; |
1180 | 996k | else if (da < dl) |
1181 | 558k | inc = 1; |
1182 | 437k | else |
1183 | 437k | inc = 2; |
1184 | 1.70M | } |
1185 | 1.98M | return GET_CABAC(MTT_SPLIT_CU_VERTICAL_FLAG + inc); |
1186 | 1.98M | } |
1187 | 1.46M | return !(a->bth || a->tth); |
1188 | 3.44M | } |
1189 | | |
1190 | | static int mtt_split_cu_binary_flag_decode(VVCLocalContext *lc, const int mtt_split_cu_vertical_flag, const int mtt_depth) |
1191 | 1.08M | { |
1192 | 1.08M | const int inc = (2 * mtt_split_cu_vertical_flag) + ((mtt_depth <= 1) ? 1 : 0); |
1193 | 1.08M | return GET_CABAC(MTT_SPLIT_CU_BINARY_FLAG + inc); |
1194 | 1.08M | } |
1195 | | |
1196 | | VVCSplitMode ff_vvc_split_mode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, |
1197 | | const int cqt_depth, const int mtt_depth, const int ch_type, const VVCAllowedSplit *a) |
1198 | 10.3M | { |
1199 | 10.3M | const int allow_no_qt = a->btv || a->bth || a->ttv || a->tth; |
1200 | 10.3M | int split_qt_flag; |
1201 | 10.3M | int mtt_split_cu_vertical_flag; |
1202 | 10.3M | int mtt_split_cu_binary_flag; |
1203 | 10.3M | const VVCSplitMode mtt_split_modes[] = { |
1204 | 10.3M | SPLIT_TT_HOR, SPLIT_BT_HOR, SPLIT_TT_VER, SPLIT_BT_VER, |
1205 | 10.3M | }; |
1206 | 10.3M | if (allow_no_qt && a->qt) { |
1207 | 1.22M | split_qt_flag = split_qt_flag_decode(lc, x0, y0, ch_type, cqt_depth); |
1208 | 9.14M | } else { |
1209 | 9.14M | split_qt_flag = !allow_no_qt || a->qt; |
1210 | 9.14M | } |
1211 | 10.3M | if (split_qt_flag) |
1212 | 6.92M | return SPLIT_QT; |
1213 | 3.44M | mtt_split_cu_vertical_flag = mtt_split_cu_vertical_flag_decode(lc, x0, y0, cb_width, cb_height, ch_type, a); |
1214 | 3.44M | if ((a->btv && a->ttv && mtt_split_cu_vertical_flag) || |
1215 | 2.98M | (a->bth && a->tth && !mtt_split_cu_vertical_flag)) { |
1216 | 1.08M | mtt_split_cu_binary_flag = mtt_split_cu_binary_flag_decode(lc, mtt_split_cu_vertical_flag, mtt_depth); |
1217 | 2.35M | } else { |
1218 | 2.35M | if (!a->btv && !a->bth) |
1219 | 253k | mtt_split_cu_binary_flag = 0; |
1220 | 2.10M | else if (!a->ttv && !a->tth) |
1221 | 2.01M | mtt_split_cu_binary_flag = 1; |
1222 | 90.5k | else if (a->bth && a->ttv) |
1223 | 50.4k | mtt_split_cu_binary_flag = 1 - mtt_split_cu_vertical_flag; |
1224 | 40.1k | else |
1225 | 40.1k | mtt_split_cu_binary_flag = mtt_split_cu_vertical_flag; |
1226 | 2.35M | } |
1227 | 3.44M | return mtt_split_modes[(mtt_split_cu_vertical_flag << 1) + mtt_split_cu_binary_flag]; |
1228 | 10.3M | } |
1229 | | |
1230 | | int ff_vvc_non_inter_flag(VVCLocalContext *lc, const int x0, const int y0, const int ch_type) |
1231 | 13.9k | { |
1232 | 13.9k | const VVCFrameContext *fc = lc->fc; |
1233 | 13.9k | uint8_t inc, left = MODE_INTER, top = MODE_INTER; |
1234 | | |
1235 | 13.9k | get_left_top(lc, &left, &top, x0, y0, fc->tab.cpm[ch_type], fc->tab.cpm[ch_type]); |
1236 | 13.9k | inc = left == MODE_INTRA || top == MODE_INTRA; |
1237 | 13.9k | return GET_CABAC(NON_INTER_FLAG + inc); |
1238 | 13.9k | } |
1239 | | |
1240 | | int ff_vvc_pred_mode_flag(VVCLocalContext *lc, const int is_chroma) |
1241 | 61.0k | { |
1242 | 61.0k | const VVCFrameContext *fc = lc->fc; |
1243 | 61.0k | const CodingUnit *cu = lc->cu; |
1244 | 61.0k | uint8_t inc, left = MODE_INTER, top = MODE_INTER; |
1245 | | |
1246 | 61.0k | get_left_top(lc, &left, &top, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]); |
1247 | 61.0k | inc = left == MODE_INTRA || top == MODE_INTRA; |
1248 | 61.0k | return GET_CABAC(PRED_MODE_FLAG + inc); |
1249 | 61.0k | } |
1250 | | |
1251 | | int ff_vvc_pred_mode_plt_flag(VVCLocalContext *lc) |
1252 | 834k | { |
1253 | 834k | return GET_CABAC(PRED_MODE_PLT_FLAG); |
1254 | 834k | } |
1255 | | |
1256 | | int ff_vvc_intra_bdpcm_luma_flag(VVCLocalContext *lc) |
1257 | 1.25M | { |
1258 | 1.25M | return GET_CABAC(INTRA_BDPCM_LUMA_FLAG); |
1259 | 1.25M | } |
1260 | | |
1261 | | int ff_vvc_intra_bdpcm_luma_dir_flag(VVCLocalContext *lc) |
1262 | 291k | { |
1263 | 291k | return GET_CABAC(INTRA_BDPCM_LUMA_DIR_FLAG); |
1264 | 291k | } |
1265 | | |
1266 | | int ff_vvc_intra_bdpcm_chroma_flag(VVCLocalContext *lc) |
1267 | 395k | { |
1268 | 395k | return GET_CABAC(INTRA_BDPCM_CHROMA_FLAG); |
1269 | 395k | } |
1270 | | |
1271 | | int ff_vvc_intra_bdpcm_chroma_dir_flag(VVCLocalContext *lc) |
1272 | 23.9k | { |
1273 | 23.9k | return GET_CABAC(INTRA_BDPCM_CHROMA_DIR_FLAG); |
1274 | 23.9k | } |
1275 | | |
1276 | | int ff_vvc_cu_skip_flag(VVCLocalContext *lc, const uint8_t *cu_skip_flag) |
1277 | 3.26M | { |
1278 | 3.26M | const int inc = get_inc(lc, cu_skip_flag); |
1279 | 3.26M | return GET_CABAC(CU_SKIP_FLAG + inc); |
1280 | 3.26M | } |
1281 | | |
1282 | | int ff_vvc_pred_mode_ibc_flag(VVCLocalContext *lc, const int is_chroma) |
1283 | 3.17M | { |
1284 | 3.17M | const VVCFrameContext *fc = lc->fc; |
1285 | 3.17M | const CodingUnit *cu = lc->cu; |
1286 | 3.17M | uint8_t left_mode = MODE_INTER, top_mode = MODE_INTER; |
1287 | 3.17M | int inc; |
1288 | | |
1289 | 3.17M | get_left_top(lc, &left_mode, &top_mode, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]); |
1290 | 3.17M | inc = (left_mode == MODE_IBC) + (top_mode == MODE_IBC); |
1291 | 3.17M | return GET_CABAC(PRED_MODE_IBC_FLAG + inc); |
1292 | 3.17M | } |
1293 | | |
1294 | | static av_always_inline |
1295 | | uint8_t get_mip_inc(VVCLocalContext *lc, const uint8_t *ctx) |
1296 | 2.39M | { |
1297 | 2.39M | uint8_t left = 0, top = 0; |
1298 | 2.39M | get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx); |
1299 | 2.39M | return (left & 1) + (top & 1); |
1300 | 2.39M | } |
1301 | | |
1302 | | int ff_vvc_intra_mip_flag(VVCLocalContext *lc, const uint8_t *intra_mip_flag) |
1303 | 2.59M | { |
1304 | 2.59M | const int w = lc->cu->cb_width; |
1305 | 2.59M | const int h = lc->cu->cb_height; |
1306 | 2.59M | const int inc = (w > h * 2 || h > w * 2) ? 3 : get_mip_inc(lc, intra_mip_flag); |
1307 | 2.59M | return GET_CABAC(INTRA_MIP_FLAG + inc); |
1308 | 2.59M | } |
1309 | | |
1310 | | int ff_vvc_intra_mip_transposed_flag(VVCLocalContext *lc) |
1311 | 308k | { |
1312 | 308k | return get_cabac_bypass(&lc->ep->cc); |
1313 | 308k | } |
1314 | | |
1315 | | int ff_vvc_intra_mip_mode(VVCLocalContext *lc) |
1316 | 308k | { |
1317 | 308k | const int w = lc->cu->cb_width; |
1318 | 308k | const int h = lc->cu->cb_height; |
1319 | 308k | const int c_max = (w == 4 && h == 4) ? 15 : |
1320 | 308k | ((w == 4 || h == 4) || (w == 8 && h == 8)) ? 7: 5; |
1321 | 308k | return truncated_binary_decode(lc, c_max); |
1322 | 308k | } |
1323 | | |
1324 | | int ff_vvc_intra_luma_ref_idx(VVCLocalContext *lc) |
1325 | 1.70M | { |
1326 | 1.70M | int i; |
1327 | 1.80M | for (i = 0; i < 2; i++) { |
1328 | 1.76M | if (!GET_CABAC(INTRA_LUMA_REF_IDX + i)) |
1329 | 1.66M | return i; |
1330 | 1.76M | } |
1331 | 41.0k | return i; |
1332 | 1.70M | } |
1333 | | |
1334 | | int ff_vvc_intra_subpartitions_mode_flag(VVCLocalContext *lc) |
1335 | 1.88M | { |
1336 | 1.88M | return GET_CABAC(INTRA_SUBPARTITIONS_MODE_FLAG); |
1337 | 1.88M | } |
1338 | | |
1339 | | enum IspType ff_vvc_isp_split_type(VVCLocalContext *lc, const int intra_subpartitions_mode_flag) |
1340 | 5.34M | { |
1341 | 5.34M | if (!intra_subpartitions_mode_flag) |
1342 | 5.26M | return ISP_NO_SPLIT; |
1343 | 85.8k | return 1 + GET_CABAC(INTRA_SUBPARTITIONS_SPLIT_FLAG); |
1344 | 5.34M | } |
1345 | | |
1346 | | int ff_vvc_intra_luma_mpm_flag(VVCLocalContext *lc) |
1347 | 5.29M | { |
1348 | 5.29M | return GET_CABAC(INTRA_LUMA_MPM_FLAG); |
1349 | 5.29M | } |
1350 | | |
1351 | | int ff_vvc_intra_luma_not_planar_flag(VVCLocalContext *lc, const int intra_subpartitions_mode_flag) |
1352 | 4.12M | { |
1353 | 4.12M | return GET_CABAC(INTRA_LUMA_NOT_PLANAR_FLAG + !intra_subpartitions_mode_flag); |
1354 | 4.12M | } |
1355 | | |
1356 | | int ff_vvc_intra_luma_mpm_idx(VVCLocalContext *lc) |
1357 | 2.16M | { |
1358 | 2.16M | int i; |
1359 | 3.30M | for (i = 0; i < 4 && get_cabac_bypass(&lc->ep->cc); i++) |
1360 | 1.13M | /* nothing */; |
1361 | 2.16M | return i; |
1362 | 2.16M | } |
1363 | | |
1364 | | int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc) |
1365 | 1.16M | { |
1366 | 1.16M | return truncated_binary_decode(lc, 60); |
1367 | 1.16M | } |
1368 | | |
1369 | | int ff_vvc_cclm_mode_flag(VVCLocalContext *lc) |
1370 | 2.69M | { |
1371 | 2.69M | return GET_CABAC(CCLM_MODE_FLAG); |
1372 | 2.69M | } |
1373 | | |
1374 | | int ff_vvc_cclm_mode_idx(VVCLocalContext *lc) |
1375 | 1.79M | { |
1376 | 1.79M | if (!GET_CABAC(CCLM_MODE_IDX)) |
1377 | 1.33M | return 0; |
1378 | 457k | return get_cabac_bypass(&lc->ep->cc) + 1; |
1379 | 1.79M | } |
1380 | | |
1381 | | int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc) |
1382 | 1.68M | { |
1383 | 1.68M | if (!GET_CABAC(INTRA_CHROMA_PRED_MODE)) |
1384 | 1.40M | return 4; |
1385 | 275k | return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc); |
1386 | 1.68M | } |
1387 | | |
1388 | | int ff_vvc_palette_predictor_run(VVCLocalContext *lc, const int max) |
1389 | 1.83k | { |
1390 | 1.83k | return kth_order_egk_decode(&lc->ep->cc, 0, max); |
1391 | 1.83k | } |
1392 | | |
1393 | | int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc, const int max) |
1394 | 77.4k | { |
1395 | 77.4k | return kth_order_egk_decode(&lc->ep->cc, 0, max); |
1396 | 77.4k | } |
1397 | | |
1398 | | int ff_vvc_new_palette_entries(VVCLocalContext *lc, const int bit_depth) |
1399 | 604k | { |
1400 | 604k | return fixed_length_decode(&lc->ep->cc, bit_depth); |
1401 | 604k | } |
1402 | | |
1403 | | bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc) |
1404 | 65.9k | { |
1405 | 65.9k | return get_cabac_bypass(&lc->ep->cc); |
1406 | 65.9k | } |
1407 | | |
1408 | | bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc) |
1409 | 64.8k | { |
1410 | 64.8k | return GET_CABAC(PALETTE_TRANSPOSE_FLAG); |
1411 | 64.8k | } |
1412 | | |
1413 | | bool ff_vvc_run_copy_flag(VVCLocalContext *lc, const int prev_run_type, const int prev_run_position, const int cur_pos) |
1414 | 4.06M | { |
1415 | 4.06M | uint8_t run_left_lut[] = { 0, 1, 2, 3, 4 }; |
1416 | 4.06M | uint8_t run_top_lut[] = { 5, 6, 6, 7, 7 }; |
1417 | | |
1418 | 4.06M | int bin_dist = cur_pos - prev_run_position - 1; |
1419 | 4.06M | uint8_t *run_lut = prev_run_type == 1 ? run_top_lut : run_left_lut; |
1420 | 4.06M | uint8_t ctx_inc = bin_dist <= 4 ? run_lut[bin_dist] : run_lut[4]; |
1421 | | |
1422 | 4.06M | return GET_CABAC(RUN_COPY_FLAG + ctx_inc); |
1423 | 4.06M | } |
1424 | | |
1425 | | bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc) |
1426 | 389k | { |
1427 | 389k | return GET_CABAC(COPY_ABOVE_PALETTE_INDICES_FLAG); |
1428 | 389k | } |
1429 | | |
1430 | | int ff_vvc_palette_idx_idc(VVCLocalContext *lc, const int max_palette_index, const bool adjust) |
1431 | 589k | { |
1432 | 589k | return truncated_binary_decode(lc, max_palette_index - adjust); |
1433 | 589k | } |
1434 | | |
1435 | | int ff_vvc_palette_escape_val(VVCLocalContext *lc, const int max) |
1436 | 906k | { |
1437 | 906k | return kth_order_egk_decode(&lc->ep->cc, 5, max); |
1438 | 906k | } |
1439 | | |
1440 | | int ff_vvc_general_merge_flag(VVCLocalContext *lc) |
1441 | 392k | { |
1442 | 392k | return GET_CABAC(GENERAL_MERGE_FLAG); |
1443 | 392k | } |
1444 | | |
1445 | | static int get_inter_flag_inc(VVCLocalContext *lc, const int x0, const int y0) |
1446 | 22.8k | { |
1447 | 22.8k | uint8_t left_merge = 0, top_merge = 0; |
1448 | 22.8k | uint8_t left_affine = 0, top_affine = 0; |
1449 | 22.8k | const VVCFrameContext *fc = lc->fc; |
1450 | | |
1451 | 22.8k | get_left_top(lc, &left_merge, &top_merge, x0, y0, fc->tab.msf, fc->tab.msf); |
1452 | 22.8k | get_left_top(lc, &left_affine, &top_affine, x0, y0, fc->tab.iaf, fc->tab.iaf); |
1453 | 22.8k | return (left_merge || left_affine) + (top_merge + top_affine); |
1454 | 22.8k | } |
1455 | | |
1456 | | int ff_vvc_merge_subblock_flag(VVCLocalContext *lc) |
1457 | 22.8k | { |
1458 | 22.8k | const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0); |
1459 | 22.8k | return GET_CABAC(MERGE_SUBBLOCK_FLAG + inc); |
1460 | 22.8k | } |
1461 | | |
1462 | | int ff_vvc_merge_subblock_idx(VVCLocalContext *lc, const int max_num_subblock_merge_cand) |
1463 | 3.87k | { |
1464 | 3.87k | int i; |
1465 | 3.87k | if (!GET_CABAC(MERGE_SUBBLOCK_IDX)) |
1466 | 1.19k | return 0; |
1467 | 6.90k | for (i = 1; i < max_num_subblock_merge_cand - 1 && get_cabac_bypass(&lc->ep->cc); i++) |
1468 | 4.22k | /* nothing */; |
1469 | 2.68k | return i; |
1470 | 3.87k | } |
1471 | | |
1472 | | int ff_vvc_regular_merge_flag(VVCLocalContext *lc, const int cu_skip_flag) |
1473 | 33.9k | { |
1474 | 33.9k | int inc = !cu_skip_flag; |
1475 | 33.9k | return GET_CABAC(REGULAR_MERGE_FLAG + inc); |
1476 | 33.9k | } |
1477 | | |
1478 | | int ff_vvc_mmvd_merge_flag(VVCLocalContext *lc) |
1479 | 38.8k | { |
1480 | 38.8k | return GET_CABAC(MMVD_MERGE_FLAG); |
1481 | 38.8k | } |
1482 | | |
1483 | | int ff_vvc_mmvd_cand_flag(VVCLocalContext *lc) |
1484 | 18.8k | { |
1485 | 18.8k | return GET_CABAC(MMVD_CAND_FLAG); |
1486 | 18.8k | } |
1487 | | |
1488 | | static int mmvd_distance_idx_decode(VVCLocalContext *lc) |
1489 | 19.4k | { |
1490 | 19.4k | int i; |
1491 | 19.4k | if (!GET_CABAC(MMVD_DISTANCE_IDX)) |
1492 | 5.90k | return 0; |
1493 | 24.3k | for (i = 1; i < 7 && get_cabac_bypass(&lc->ep->cc); i++) |
1494 | 10.8k | /* nothing */; |
1495 | 13.5k | return i; |
1496 | 19.4k | } |
1497 | | |
1498 | | static int mmvd_direction_idx_decode(VVCLocalContext *lc) |
1499 | 19.4k | { |
1500 | 19.4k | return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc); |
1501 | 19.4k | } |
1502 | | |
1503 | | void ff_vvc_mmvd_offset_coding(VVCLocalContext *lc, Mv *mmvd_offset, const int ph_mmvd_fullpel_only_flag) |
1504 | 19.4k | { |
1505 | 19.4k | const int shift = ph_mmvd_fullpel_only_flag ? 4 : 2; |
1506 | 19.4k | const int mmvd_distance = 1 << (mmvd_distance_idx_decode(lc) + shift); |
1507 | 19.4k | const int mmvd_direction_idx = mmvd_direction_idx_decode(lc); |
1508 | 19.4k | const int mmvd_signs[][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} }; |
1509 | 19.4k | mmvd_offset->x = mmvd_distance * mmvd_signs[mmvd_direction_idx][0]; |
1510 | 19.4k | mmvd_offset->y = mmvd_distance * mmvd_signs[mmvd_direction_idx][1]; |
1511 | 19.4k | } |
1512 | | |
1513 | | static PredMode get_luma_pred_mode(VVCLocalContext *lc) |
1514 | 140k | { |
1515 | 140k | const VVCFrameContext *fc = lc->fc; |
1516 | 140k | const CodingUnit *cu = lc->cu; |
1517 | 140k | PredMode pred_mode; |
1518 | | |
1519 | 140k | if (cu->tree_type != DUAL_TREE_CHROMA) { |
1520 | 140k | pred_mode = cu->pred_mode; |
1521 | 140k | } else { |
1522 | 0 | const int x_cb = cu->x0 >> fc->ps.sps->min_cb_log2_size_y; |
1523 | 0 | const int y_cb = cu->y0 >> fc->ps.sps->min_cb_log2_size_y; |
1524 | 0 | const int min_cb_width = fc->ps.pps->min_cb_width; |
1525 | 0 | pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_cb, y_cb); |
1526 | 0 | } |
1527 | 140k | return pred_mode; |
1528 | 140k | } |
1529 | | |
1530 | | int ff_vvc_merge_idx(VVCLocalContext *lc) |
1531 | 140k | { |
1532 | 140k | const VVCSPS *sps = lc->fc->ps.sps; |
1533 | 140k | const int is_ibc = get_luma_pred_mode(lc) == MODE_IBC; |
1534 | 140k | const int c_max = (is_ibc ? sps->max_num_ibc_merge_cand : sps->max_num_merge_cand) - 1; |
1535 | 140k | int i; |
1536 | | |
1537 | 140k | if (!GET_CABAC(MERGE_IDX)) |
1538 | 99.4k | return 0; |
1539 | | |
1540 | 83.0k | for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++) |
1541 | 42.1k | /* nothing */; |
1542 | 40.9k | return i; |
1543 | 140k | } |
1544 | | |
1545 | | int ff_vvc_merge_gpm_partition_idx(VVCLocalContext *lc) |
1546 | 9.35k | { |
1547 | 9.35k | return fixed_length_decode(&lc->ep->cc, 6); |
1548 | 9.35k | } |
1549 | | |
1550 | | int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx) |
1551 | 16.0k | { |
1552 | 16.0k | const int c_max = lc->fc->ps.sps->max_num_gpm_merge_cand - idx - 1; |
1553 | 16.0k | int i; |
1554 | | |
1555 | 16.0k | if (!GET_CABAC(MERGE_IDX)) |
1556 | 7.90k | return 0; |
1557 | | |
1558 | 10.5k | for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++) |
1559 | 2.40k | /* nothing */; |
1560 | | |
1561 | 8.11k | return i; |
1562 | 16.0k | } |
1563 | | |
1564 | | int ff_vvc_ciip_flag(VVCLocalContext *lc) |
1565 | 4.81k | { |
1566 | 4.81k | return GET_CABAC(CIIP_FLAG); |
1567 | 4.81k | } |
1568 | | |
1569 | | PredFlag ff_vvc_pred_flag(VVCLocalContext *lc, const int is_b) |
1570 | 33.5k | { |
1571 | 33.5k | const int w = lc->cu->cb_width; |
1572 | 33.5k | const int h = lc->cu->cb_height; |
1573 | 33.5k | if (!is_b) |
1574 | 6.94k | return PF_L0; |
1575 | 26.5k | if (w + h > 12) { |
1576 | 15.0k | const int log2 = av_log2(w) + av_log2(h); |
1577 | 15.0k | const int inc = 7 - ((1 + log2)>>1); |
1578 | 15.0k | if (GET_CABAC(INTER_PRED_IDC + inc)) |
1579 | 1.92k | return PF_BI; |
1580 | 15.0k | } |
1581 | 24.6k | return PF_L0 + GET_CABAC(INTER_PRED_IDC + 5); |
1582 | 26.5k | } |
1583 | | |
1584 | | int ff_vvc_inter_affine_flag(VVCLocalContext *lc) |
1585 | 0 | { |
1586 | 0 | const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0); |
1587 | 0 | return GET_CABAC(INTER_AFFINE_FLAG + inc); |
1588 | 0 | } |
1589 | | |
1590 | | int ff_vvc_cu_affine_type_flag(VVCLocalContext *lc) |
1591 | 0 | { |
1592 | 0 | return GET_CABAC(CU_AFFINE_TYPE_FLAG); |
1593 | 0 | } |
1594 | | |
1595 | | int ff_vvc_sym_mvd_flag(VVCLocalContext *lc) |
1596 | 171 | { |
1597 | 171 | return GET_CABAC(SYM_MVD_FLAG); |
1598 | 171 | } |
1599 | | |
1600 | | int ff_vvc_ref_idx_lx(VVCLocalContext *lc, const uint8_t nb_refs) |
1601 | 1.07k | { |
1602 | 1.07k | const int c_max = nb_refs - 1; |
1603 | 1.07k | const int max_ctx = FFMIN(c_max, 2); |
1604 | 1.07k | int i = 0; |
1605 | | |
1606 | 1.83k | while (i < max_ctx && GET_CABAC(REF_IDX_LX + i)) |
1607 | 762 | i++; |
1608 | 1.07k | if (i == 2) { |
1609 | 291 | while (i < c_max && get_cabac_bypass(&lc->ep->cc)) |
1610 | 130 | i++; |
1611 | 161 | } |
1612 | 1.07k | return i; |
1613 | 1.07k | } |
1614 | | |
1615 | | int ff_vvc_abs_mvd_greater0_flag(VVCLocalContext *lc) |
1616 | 549k | { |
1617 | 549k | return GET_CABAC(ABS_MVD_GREATER0_FLAG); |
1618 | 549k | } |
1619 | | |
1620 | | int ff_vvc_abs_mvd_greater1_flag(VVCLocalContext *lc) |
1621 | 386k | { |
1622 | 386k | return GET_CABAC(ABS_MVD_GREATER1_FLAG); |
1623 | 386k | } |
1624 | | |
1625 | | int ff_vvc_abs_mvd_minus2(VVCLocalContext *lc) |
1626 | 296k | { |
1627 | 296k | return limited_kth_order_egk_decode(&lc->ep->cc, 1, 15, 17); |
1628 | 296k | } |
1629 | | |
1630 | | int ff_vvc_mvd_sign_flag(VVCLocalContext *lc) |
1631 | 386k | { |
1632 | 386k | return get_cabac_bypass(&lc->ep->cc); |
1633 | 386k | } |
1634 | | |
1635 | | int ff_vvc_mvp_lx_flag(VVCLocalContext *lc) |
1636 | 273k | { |
1637 | 273k | return GET_CABAC(MVP_LX_FLAG); |
1638 | 273k | } |
1639 | | |
1640 | | static int amvr_flag(VVCLocalContext *lc, const int inter_affine_flag) |
1641 | 5.17k | { |
1642 | 5.17k | return GET_CABAC(AMVR_FLAG + inter_affine_flag); |
1643 | 5.17k | } |
1644 | | |
1645 | | static int amvr_precision_idx(VVCLocalContext *lc, const int inc, const int c_max) |
1646 | 172k | { |
1647 | 172k | int i = 0; |
1648 | 172k | if (!GET_CABAC(AMVR_PRECISION_IDX + inc)) |
1649 | 121k | return 0; |
1650 | 51.3k | i++; |
1651 | 51.3k | if (i < c_max && GET_CABAC(AMVR_PRECISION_IDX + 1)) |
1652 | 319 | i++; |
1653 | 51.3k | return i; |
1654 | 172k | } |
1655 | | |
1656 | | int ff_vvc_amvr_shift(VVCLocalContext *lc, const int inter_affine_flag, |
1657 | | const PredMode pred_mode, const int has_amvr_flag) |
1658 | 202k | { |
1659 | 202k | int amvr_shift = 2; |
1660 | 202k | if (has_amvr_flag) { |
1661 | 174k | if (pred_mode == MODE_IBC || amvr_flag(lc, inter_affine_flag)) { |
1662 | 172k | int idx; |
1663 | 172k | if (inter_affine_flag) { |
1664 | 0 | idx = amvr_precision_idx(lc, 2, 1); |
1665 | 0 | amvr_shift = idx * 4; |
1666 | 172k | } else if (pred_mode == MODE_IBC) { |
1667 | 169k | idx = amvr_precision_idx(lc, 1, 1); |
1668 | 169k | amvr_shift = 4 + idx * 2; |
1669 | 169k | } else { |
1670 | 3.87k | static const int shifts[] = {3, 4, 6}; |
1671 | 3.87k | idx = amvr_precision_idx(lc, 0, 2); |
1672 | 3.87k | amvr_shift = shifts[idx]; |
1673 | 3.87k | } |
1674 | 172k | } |
1675 | 174k | } |
1676 | 202k | return amvr_shift; |
1677 | 202k | } |
1678 | | |
1679 | | int ff_vvc_bcw_idx(VVCLocalContext *lc, const int no_backward_pred_flag) |
1680 | 0 | { |
1681 | 0 | const int c_max = no_backward_pred_flag ? 4 : 2; |
1682 | 0 | int i = 1; |
1683 | 0 | if (!GET_CABAC(BCW_IDX)) |
1684 | 0 | return 0; |
1685 | 0 | while (i < c_max && get_cabac_bypass(&lc->ep->cc)) |
1686 | 0 | i++; |
1687 | 0 | return i; |
1688 | 0 | } |
1689 | | |
1690 | | int ff_vvc_tu_cb_coded_flag(VVCLocalContext *lc) |
1691 | 3.79M | { |
1692 | 3.79M | return GET_CABAC(TU_CB_CODED_FLAG + lc->cu->bdpcm_flag[1]); |
1693 | 3.79M | } |
1694 | | |
1695 | | int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag) |
1696 | 3.79M | { |
1697 | 3.79M | return GET_CABAC(TU_CR_CODED_FLAG + (lc->cu->bdpcm_flag[1] ? 2 : tu_cb_coded_flag)); |
1698 | 3.79M | } |
1699 | | |
1700 | | int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc) |
1701 | 6.00M | { |
1702 | 6.00M | const CodingUnit *cu = lc->cu; |
1703 | 6.00M | int inc; |
1704 | 6.00M | if (cu->bdpcm_flag[0]) |
1705 | 291k | inc = 1; |
1706 | 5.71M | else if (cu->isp_split_type == ISP_NO_SPLIT) |
1707 | 5.44M | inc = 0; |
1708 | 264k | else |
1709 | 264k | inc = 2 + lc->parse.prev_tu_cbf_y; |
1710 | 6.00M | lc->parse.prev_tu_cbf_y = GET_CABAC(TU_Y_CODED_FLAG + inc); |
1711 | 6.00M | return lc->parse.prev_tu_cbf_y; |
1712 | 6.00M | } |
1713 | | |
1714 | | int ff_vvc_cu_act_enabled_flag(VVCLocalContext *lc) |
1715 | 319k | { |
1716 | 319k | return GET_CABAC(CU_ACT_ENABLED_FLAG); |
1717 | 319k | } |
1718 | | |
1719 | | int ff_vvc_cu_qp_delta_abs(VVCLocalContext *lc) |
1720 | 737k | { |
1721 | 737k | int v, i, k; |
1722 | 737k | if (!GET_CABAC(CU_QP_DELTA_ABS)) |
1723 | 179k | return 0; |
1724 | | |
1725 | | // prefixVal |
1726 | 766k | for (v = 1; v < 5 && GET_CABAC(CU_QP_DELTA_ABS + 1); v++) |
1727 | 208k | /* nothing */; |
1728 | 557k | if (v < 5) |
1729 | 551k | return v; |
1730 | | |
1731 | | // 9.3.3.5 k-th order Exp-Golomb binarization process |
1732 | | // suffixVal |
1733 | | |
1734 | | // CuQpDeltaVal shall in the range of −( 32 + QpBdOffset / 2 ) to +( 31 + QpBdOffset / 2 ) |
1735 | | // so k = 6 should enough |
1736 | 20.5k | for (k = 0; k < 6 && get_cabac_bypass(&lc->ep->cc); k++) |
1737 | 14.0k | /* nothing */; |
1738 | 6.57k | i = (1 << k) - 1; |
1739 | 6.57k | v = 0; |
1740 | 20.5k | while (k--) |
1741 | 14.0k | v = (v << 1) + get_cabac_bypass(&lc->ep->cc); |
1742 | 6.57k | v += i; |
1743 | | |
1744 | 6.57k | return v + 5; |
1745 | 557k | } |
1746 | | |
1747 | | int ff_vvc_cu_qp_delta_sign_flag(VVCLocalContext *lc) |
1748 | 557k | { |
1749 | 557k | return get_cabac_bypass(&lc->ep->cc); |
1750 | 557k | } |
1751 | | |
1752 | | int ff_vvc_cu_chroma_qp_offset_flag(VVCLocalContext *lc) |
1753 | 19.3k | { |
1754 | 19.3k | return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG); |
1755 | 19.3k | } |
1756 | | |
1757 | | int ff_vvc_cu_chroma_qp_offset_idx(VVCLocalContext *lc) |
1758 | 4.14k | { |
1759 | 4.14k | const int c_max = lc->fc->ps.pps->r->pps_chroma_qp_offset_list_len_minus1; |
1760 | 4.14k | int i; |
1761 | 6.90k | for (i = 0; i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX); i++) |
1762 | 2.75k | /* nothing */; |
1763 | 4.14k | return i; |
1764 | 4.14k | } |
1765 | | |
1766 | | static av_always_inline int last_significant_coeff_xy_prefix(VVCLocalContext *lc, |
1767 | | const int log2_tb_size, const int log2_zo_tb_size, const int c_idx, const int ctx) |
1768 | 13.9M | { |
1769 | 13.9M | int i = 0; |
1770 | 13.9M | int max = (log2_zo_tb_size << 1) - 1; |
1771 | 13.9M | int ctx_offset, ctx_shift; |
1772 | 13.9M | if (!log2_tb_size) |
1773 | 4.74k | return 0; |
1774 | 13.9M | if (!c_idx) { |
1775 | 10.7M | const int offset_y[] = {0, 0, 3, 6, 10, 15}; |
1776 | 10.7M | ctx_offset = offset_y[log2_tb_size - 1]; |
1777 | 10.7M | ctx_shift = (log2_tb_size + 1) >> 2; |
1778 | 10.7M | } else { |
1779 | 3.19M | const int shifts[] = {0, 0, 0, 1, 2, 2, 2}; |
1780 | 3.19M | ctx_offset = 20; |
1781 | 3.19M | ctx_shift = shifts[log2_tb_size]; |
1782 | 3.19M | } |
1783 | 45.7M | while (i < max && GET_CABAC(ctx + (i >> ctx_shift) + ctx_offset)) |
1784 | 31.8M | i++; |
1785 | 13.9M | return i; |
1786 | 13.9M | } |
1787 | | |
1788 | | static av_always_inline int last_significant_coeff_x_prefix_decode(VVCLocalContext *lc, |
1789 | | const int log2_tb_width, const int log2_zo_tb_width, const int c_idx) |
1790 | 6.95M | { |
1791 | 6.95M | return last_significant_coeff_xy_prefix(lc, log2_tb_width, log2_zo_tb_width, c_idx, LAST_SIG_COEFF_X_PREFIX); |
1792 | 6.95M | } |
1793 | | |
1794 | | static av_always_inline int last_significant_coeff_y_prefix_decode(VVCLocalContext *lc, |
1795 | | const int log2_tb_height, const int log2_zo_tb_height, const int c_idx) |
1796 | 6.95M | { |
1797 | 6.95M | return last_significant_coeff_xy_prefix(lc, log2_tb_height, log2_zo_tb_height, c_idx, LAST_SIG_COEFF_Y_PREFIX); |
1798 | 6.95M | } |
1799 | | |
1800 | | static av_always_inline int last_sig_coeff_suffix_decode(VVCLocalContext *lc, |
1801 | | const int last_significant_coeff_y_prefix) |
1802 | 3.96M | { |
1803 | 3.96M | const int length = (last_significant_coeff_y_prefix >> 1) - 1; |
1804 | 3.96M | int value = get_cabac_bypass(&lc->ep->cc); |
1805 | | |
1806 | 6.80M | for (int i = 1; i < length; i++) |
1807 | 2.84M | value = (value << 1) | get_cabac_bypass(&lc->ep->cc); |
1808 | 3.96M | return value; |
1809 | 3.96M | } |
1810 | | |
1811 | | int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, const int tu_cb_coded_flag, const int tu_cr_coded_flag) |
1812 | 1.22M | { |
1813 | 1.22M | return GET_CABAC(TU_JOINT_CBCR_RESIDUAL_FLAG + 2 * tu_cb_coded_flag + tu_cr_coded_flag - 1); |
1814 | 1.22M | } |
1815 | | |
1816 | | int ff_vvc_transform_skip_flag(VVCLocalContext *lc, const int inc) |
1817 | 5.26M | { |
1818 | 5.26M | return GET_CABAC(TRANSFORM_SKIP_FLAG + inc); |
1819 | 5.26M | } |
1820 | | |
1821 | | //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1 |
1822 | | static int get_local_sum(const int *level, const int w, const int h, |
1823 | | const int xc, const int yc, const int hist_value) |
1824 | 421M | { |
1825 | 421M | int loc_sum = 3 * hist_value; |
1826 | 421M | level += w * yc + xc; |
1827 | 421M | if (xc < w - 1) { |
1828 | 415M | loc_sum += level[1]; |
1829 | 415M | if (xc < w - 2) |
1830 | 404M | loc_sum += level[2] - hist_value; |
1831 | 415M | if (yc < h - 1) |
1832 | 404M | loc_sum += level[w + 1] - hist_value; |
1833 | 415M | } |
1834 | 421M | if (yc < h - 1) { |
1835 | 410M | loc_sum += level[w]; |
1836 | 410M | if (yc < h - 2) |
1837 | 393M | loc_sum += level[w << 1] - hist_value; |
1838 | 410M | } |
1839 | 421M | return loc_sum; |
1840 | 421M | } |
1841 | | |
1842 | | //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1 |
1843 | | static int get_local_sum_ts(const int *level, const int w, const int h, const int xc, const int yc) |
1844 | 8.91M | { |
1845 | 8.91M | int loc_sum = 0; |
1846 | 8.91M | level += w * yc + xc; |
1847 | 8.91M | if (xc > 0) |
1848 | 6.88M | loc_sum += level[-1]; |
1849 | 8.91M | if (yc > 0) |
1850 | 6.85M | loc_sum += level[-w]; |
1851 | 8.91M | return loc_sum; |
1852 | 8.91M | } |
1853 | | |
1854 | | static int get_gtx_flag_inc(const ResidualCoding* rc, const int xc, const int yc, const int last) |
1855 | 91.0M | { |
1856 | 91.0M | const TransformBlock *tb = rc->tb; |
1857 | 91.0M | int inc; |
1858 | 91.0M | if (last) { |
1859 | 6.95M | const int incs[] = {0, 21, 21}; |
1860 | 6.95M | inc = incs[tb->c_idx]; |
1861 | 84.1M | } else { |
1862 | 84.1M | const int d = xc + yc; |
1863 | 84.1M | const int local_sum_sig = get_local_sum(rc->sig_coeff_flag, |
1864 | 84.1M | tb->tb_width,tb->tb_height, xc, yc, rc->hist_value); |
1865 | 84.1M | const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1, |
1866 | 84.1M | tb->tb_width, tb->tb_height, xc, yc, rc->hist_value); |
1867 | 84.1M | const int offset = FFMIN(loc_sum_abs_pass1 - local_sum_sig, 4); |
1868 | | |
1869 | 84.1M | if (!tb->c_idx) |
1870 | 80.6M | inc = 1 + offset + (!d ? 15 : (d < 3 ? 10 : (d < 10 ? 5 : 0))); |
1871 | 3.48M | else |
1872 | 3.48M | inc = 22 + offset + (!d ? 5 : 0); |
1873 | 84.1M | } |
1874 | 91.0M | return inc; |
1875 | 91.0M | } |
1876 | | |
1877 | | static int abs_level_gtx_flag_decode(VVCLocalContext *lc, const int inc) |
1878 | 101M | { |
1879 | 101M | return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc); |
1880 | 101M | } |
1881 | | |
1882 | | static int par_level_flag_decode(VVCLocalContext *lc, const int inc) |
1883 | 10.2M | { |
1884 | 10.2M | return GET_CABAC(PAR_LEVEL_FLAG + inc); |
1885 | 10.2M | } |
1886 | | |
1887 | | static int par_level_flag_ts_decode(VVCLocalContext *lc) |
1888 | 1.70M | { |
1889 | 1.70M | const int inc = 32; |
1890 | 1.70M | return GET_CABAC(PAR_LEVEL_FLAG + inc); |
1891 | 1.70M | } |
1892 | | |
1893 | | static int sb_coded_flag_decode(VVCLocalContext *lc, const uint8_t *sb_coded_flag, |
1894 | | const ResidualCoding *rc, const int xs, const int ys) |
1895 | 19.3M | { |
1896 | 19.3M | const H266RawSliceHeader *rsh = lc->sc->sh.r; |
1897 | 19.3M | const TransformBlock *tb = rc->tb; |
1898 | 19.3M | const int w = rc->width_in_sbs; |
1899 | 19.3M | const int h = rc->height_in_sbs; |
1900 | 19.3M | int inc; |
1901 | | |
1902 | 19.3M | if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) { |
1903 | 596k | const int left = xs > 0 ? sb_coded_flag[-1] : 0; |
1904 | 596k | const int above = ys > 0 ? sb_coded_flag[-w] : 0; |
1905 | 596k | inc = left + above + 4; |
1906 | 18.7M | } else { |
1907 | 18.7M | const int right = (xs < w - 1) ? sb_coded_flag[1] : 0; |
1908 | 18.7M | const int bottom = (ys < h - 1) ? sb_coded_flag[w] : 0; |
1909 | 18.7M | inc = (right | bottom) + (tb->c_idx ? 2 : 0); |
1910 | 18.7M | } |
1911 | 19.3M | return GET_CABAC(SB_CODED_FLAG + inc); |
1912 | 19.3M | } |
1913 | | |
1914 | | static int sig_coeff_flag_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc) |
1915 | 258M | { |
1916 | 258M | const H266RawSliceHeader *rsh = lc->sc->sh.r; |
1917 | 258M | const TransformBlock *tb = rc->tb; |
1918 | 258M | int inc; |
1919 | | |
1920 | 258M | if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) { |
1921 | 8.91M | const int local_num_sig = get_local_sum_ts(rc->sig_coeff_flag, tb->tb_width, tb->tb_height, xc, yc); |
1922 | 8.91M | inc = 60 + local_num_sig; |
1923 | 249M | } else { |
1924 | 249M | const int d = xc + yc; |
1925 | 249M | const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1, |
1926 | 249M | tb->tb_width, tb->tb_height, xc, yc, 0); |
1927 | | |
1928 | 249M | if (!tb->c_idx) { |
1929 | 241M | inc = 12 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + ((d < 2) ? 8 : (d < 5 ? 4 : 0)); |
1930 | 241M | } else { |
1931 | 7.49M | inc = 36 + 8 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + (d < 2 ? 4 : 0); |
1932 | 7.49M | } |
1933 | 249M | } |
1934 | 258M | return GET_CABAC(SIG_COEFF_FLAG + inc); |
1935 | 258M | } |
1936 | | |
1937 | | static int abs_get_rice_param(VVCLocalContext *lc, const ResidualCoding* rc, |
1938 | | const int xc, const int yc, const int base_level) |
1939 | 3.47M | { |
1940 | 3.47M | const VVCSPS *sps = lc->fc->ps.sps; |
1941 | 3.47M | const TransformBlock* tb = rc->tb; |
1942 | 3.47M | const int rice_params[] = { |
1943 | 3.47M | 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, |
1944 | 3.47M | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, |
1945 | 3.47M | }; |
1946 | 3.47M | int loc_sum_abs; |
1947 | 3.47M | int shift_val; |
1948 | | |
1949 | 3.47M | loc_sum_abs = get_local_sum(rc->abs_level, tb->tb_width, tb->tb_height, xc, |
1950 | 3.47M | yc, rc->hist_value); |
1951 | | |
1952 | 3.47M | if (!sps->r->sps_rrc_rice_extension_flag) { |
1953 | 3.29M | shift_val = 0; |
1954 | 3.29M | } else { |
1955 | 178k | shift_val = (av_log2(FFMAX(FFMIN(loc_sum_abs, 2048), 8)) - 3) & ~1; |
1956 | 178k | } |
1957 | | |
1958 | 3.47M | loc_sum_abs = av_clip_uintp2((loc_sum_abs >> shift_val) - base_level * 5, 5); |
1959 | | |
1960 | 3.47M | return rice_params[loc_sum_abs] + shift_val; |
1961 | 3.47M | } |
1962 | | |
1963 | | static int abs_decode(VVCLocalContext *lc, const int c_rice_param) |
1964 | 5.81M | { |
1965 | 5.81M | const VVCSPS *sps = lc->fc->ps.sps; |
1966 | 5.81M | const int MAX_BIN = 6; |
1967 | 5.81M | int prefix = 0; |
1968 | 5.81M | int suffix = 0; |
1969 | | |
1970 | 12.8M | while (prefix < MAX_BIN && get_cabac_bypass(&lc->ep->cc)) |
1971 | 7.01M | prefix++; |
1972 | 5.81M | if (prefix < MAX_BIN) { |
1973 | 9.00M | for (int i = 0; i < c_rice_param; i++) { |
1974 | 3.59M | suffix = (suffix << 1) | get_cabac_bypass(&lc->ep->cc); |
1975 | 3.59M | } |
1976 | 5.41M | } else { |
1977 | 396k | suffix = limited_kth_order_egk_decode(&lc->ep->cc, |
1978 | 396k | c_rice_param + 1, |
1979 | 396k | 26 - sps->log2_transform_range, |
1980 | 396k | sps->log2_transform_range); |
1981 | 396k | } |
1982 | 5.81M | return suffix + (prefix << c_rice_param); |
1983 | 5.81M | } |
1984 | | |
1985 | | static int abs_remainder_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc) |
1986 | 2.08M | { |
1987 | 2.08M | const VVCSPS *sps = lc->fc->ps.sps; |
1988 | 2.08M | const H266RawSliceHeader *rsh = lc->sc->sh.r; |
1989 | 2.08M | const int base_level[][2][2] = { |
1990 | 2.08M | { {4, 4}, {4, 4} }, |
1991 | 2.08M | { {3, 2}, {2, 1} } |
1992 | 2.08M | }; |
1993 | 2.08M | const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc, |
1994 | 2.08M | base_level[sps->r->sps_rrc_rice_extension_flag][sps->bit_depth > 12][IS_I(rsh)]); |
1995 | 2.08M | const int rem = abs_decode(lc, c_rice_param); |
1996 | | |
1997 | 2.08M | return rem; |
1998 | 2.08M | } |
1999 | | |
2000 | | static int abs_remainder_ts_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc) |
2001 | 2.33M | { |
2002 | 2.33M | const H266RawSliceHeader *rsh = lc->sc->sh.r; |
2003 | 2.33M | const int c_rice_param = rsh->sh_ts_residual_coding_rice_idx_minus1 + 1; |
2004 | 2.33M | const int rem = abs_decode(lc, c_rice_param); |
2005 | | |
2006 | 2.33M | return rem; |
2007 | 2.33M | } |
2008 | | |
2009 | | static int coeff_sign_flag_decode(VVCLocalContext *lc) |
2010 | 91.3M | { |
2011 | 91.3M | return get_cabac_bypass(&lc->ep->cc); |
2012 | 91.3M | } |
2013 | | |
2014 | | //9.3.4.2.10 Derivation process of ctxInc for the syntax element coeff_sign_flag for transform skip mode |
2015 | | static int coeff_sign_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc) |
2016 | 2.69M | { |
2017 | 2.69M | const TransformBlock *tb = rc->tb; |
2018 | 2.69M | const int w = tb->tb_width; |
2019 | 2.69M | const int *level = rc->coeff_sign_level + yc * w + xc; |
2020 | 2.69M | const int left_sign = xc ? level[-1] : 0; |
2021 | 2.69M | const int above_sign = yc ? level[-w] : 0; |
2022 | 2.69M | const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx]; |
2023 | 2.69M | int inc; |
2024 | | |
2025 | 2.69M | if (left_sign == -above_sign) |
2026 | 811k | inc = bdpcm_flag ? 3 : 0; |
2027 | 1.88M | else if (left_sign >= 0 && above_sign >= 0) |
2028 | 1.16M | inc = bdpcm_flag ? 4 : 1; |
2029 | 720k | else |
2030 | 720k | inc = bdpcm_flag ? 5 : 2; |
2031 | 2.69M | return GET_CABAC(COEFF_SIGN_FLAG + inc); |
2032 | 2.69M | } |
2033 | | |
2034 | | static int abs_level_gt1_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc) |
2035 | 2.69M | { |
2036 | 2.69M | const TransformBlock *tb = rc->tb; |
2037 | 2.69M | const int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc; |
2038 | 2.69M | int inc; |
2039 | | |
2040 | 2.69M | if (cu->bdpcm_flag[tb->c_idx]) { |
2041 | 967k | inc = 67; |
2042 | 1.72M | } else { |
2043 | 1.72M | const int l = xc > 0 ? sig_coeff_flag[-1] : 0; |
2044 | 1.72M | const int a = yc > 0 ? sig_coeff_flag[-tb->tb_width] : 0; |
2045 | 1.72M | inc = 64 + a + l; |
2046 | 1.72M | } |
2047 | 2.69M | return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc); |
2048 | 2.69M | } |
2049 | | |
2050 | | static int abs_level_gtx_flag_ts_decode(VVCLocalContext *lc, const int j) |
2051 | 718k | { |
2052 | 718k | const int inc = 67 + j; |
2053 | 718k | return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc); |
2054 | 718k | } |
2055 | | |
2056 | | static const uint8_t qstate_translate_table[][2] = { |
2057 | | { 0, 2 }, { 2, 0 }, { 1, 3 }, { 3, 1 } |
2058 | | }; |
2059 | | |
2060 | | static int dec_abs_level_decode(VVCLocalContext *lc, const ResidualCoding *rc, |
2061 | | const int xc, const int yc, int *abs_level) |
2062 | 1.39M | { |
2063 | 1.39M | const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc, 0); |
2064 | 1.39M | const int dec_abs_level = abs_decode(lc, c_rice_param); |
2065 | 1.39M | const int zero_pos = (rc->qstate < 2 ? 1 : 2) << c_rice_param; |
2066 | | |
2067 | 1.39M | *abs_level = 0; |
2068 | 1.39M | if (dec_abs_level != zero_pos) { |
2069 | 1.18M | *abs_level = dec_abs_level; |
2070 | 1.18M | if (dec_abs_level < zero_pos) |
2071 | 798k | *abs_level += 1; |
2072 | 1.18M | } |
2073 | 1.39M | return dec_abs_level; |
2074 | 1.39M | } |
2075 | | |
2076 | | static void ep_update_hist(EntryPoint *ep, ResidualCoding *rc, |
2077 | | const int remainder, const int addin) |
2078 | 3.47M | { |
2079 | 3.47M | int *stat = ep->stat_coeff + rc->tb->c_idx; |
2080 | 3.47M | if (rc->update_hist && remainder > 0) { |
2081 | 83.5k | *stat = (*stat + av_log2(remainder) + addin) >> 1; |
2082 | 83.5k | rc->update_hist = 0; |
2083 | 83.5k | } |
2084 | 3.47M | } |
2085 | | |
2086 | | static void init_residual_coding(const VVCLocalContext *lc, ResidualCoding *rc, |
2087 | | const int log2_zo_tb_width, const int log2_zo_tb_height, |
2088 | | TransformBlock *tb) |
2089 | 7.49M | { |
2090 | 7.49M | const VVCSPS *sps = lc->fc->ps.sps; |
2091 | 7.49M | int log2_sb_w = (FFMIN(log2_zo_tb_width, log2_zo_tb_height ) < 2 ? 1 : 2 ); |
2092 | 7.49M | int log2_sb_h = log2_sb_w; |
2093 | | |
2094 | 7.49M | if ( log2_zo_tb_width + log2_zo_tb_height > 3 ) { |
2095 | 7.48M | if ( log2_zo_tb_width < 2 ) { |
2096 | 62.2k | log2_sb_w = log2_zo_tb_width; |
2097 | 62.2k | log2_sb_h = 4 - log2_sb_w; |
2098 | 7.42M | } else if ( log2_zo_tb_height < 2 ) { |
2099 | 81.0k | log2_sb_h = log2_zo_tb_height; |
2100 | 81.0k | log2_sb_w = 4 - log2_sb_h; |
2101 | 81.0k | } |
2102 | 7.48M | } |
2103 | 7.49M | rc->log2_sb_w = log2_sb_w; |
2104 | 7.49M | rc->log2_sb_h = log2_sb_h; |
2105 | 7.49M | rc->num_sb_coeff = 1 << (log2_sb_w + log2_sb_h); |
2106 | 7.49M | rc->last_sub_block = ( 1 << ( log2_zo_tb_width + log2_zo_tb_height - (log2_sb_w + log2_sb_h))) - 1; |
2107 | 7.49M | rc->hist_value = sps->r->sps_persistent_rice_adaptation_enabled_flag ? (1 << lc->ep->stat_coeff[tb->c_idx]) : 0; |
2108 | 7.49M | rc->update_hist = sps->r->sps_persistent_rice_adaptation_enabled_flag ? 1 : 0; |
2109 | 7.49M | rc->rem_bins_pass1 = (( 1 << ( log2_zo_tb_width + log2_zo_tb_height)) * 7 ) >> 2; |
2110 | | |
2111 | | |
2112 | 7.49M | rc->sb_scan_x_off = ff_vvc_diag_scan_x[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h]; |
2113 | 7.49M | rc->sb_scan_y_off = ff_vvc_diag_scan_y[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h]; |
2114 | | |
2115 | 7.49M | rc->scan_x_off = ff_vvc_diag_scan_x[log2_sb_w][log2_sb_h]; |
2116 | 7.49M | rc->scan_y_off = ff_vvc_diag_scan_y[log2_sb_w][log2_sb_h]; |
2117 | | |
2118 | 7.49M | rc->infer_sb_cbf = 1; |
2119 | | |
2120 | 7.49M | rc->width_in_sbs = (1 << (log2_zo_tb_width - log2_sb_w)); |
2121 | 7.49M | rc->height_in_sbs = (1 << (log2_zo_tb_height - log2_sb_h)); |
2122 | 7.49M | rc->nb_sbs = rc->width_in_sbs * rc->height_in_sbs; |
2123 | | |
2124 | 7.49M | rc->last_scan_pos = rc->num_sb_coeff; |
2125 | 7.49M | rc->qstate = 0; |
2126 | | |
2127 | 7.49M | rc->tb = tb; |
2128 | 7.49M | } |
2129 | | |
2130 | | static int residual_ts_coding_subblock(VVCLocalContext *lc, ResidualCoding* rc, const int i) |
2131 | 1.10M | { |
2132 | 1.10M | const CodingUnit *cu = lc->cu; |
2133 | 1.10M | TransformBlock *tb = rc->tb; |
2134 | 1.10M | const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx]; |
2135 | 1.10M | const int xs = rc->sb_scan_x_off[i]; |
2136 | 1.10M | const int ys = rc->sb_scan_y_off[i]; |
2137 | 1.10M | uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs; |
2138 | 1.10M | int infer_sb_sig_coeff_flag = 1; |
2139 | 1.10M | int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -1, n; |
2140 | 1.10M | int abs_level_gtx_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; |
2141 | 1.10M | int abs_level_pass2[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; ///< AbsLevelPass2 |
2142 | | |
2143 | 1.10M | if (i != rc->last_sub_block || !rc->infer_sb_cbf) |
2144 | 596k | *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys); |
2145 | 513k | else |
2146 | 513k | *sb_coded_flag = 1; |
2147 | 1.10M | if (*sb_coded_flag && i < rc->last_sub_block) |
2148 | 116k | rc->infer_sb_cbf = 0; |
2149 | | |
2150 | | //first scan pass |
2151 | 17.5M | for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) { |
2152 | 16.4M | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; |
2153 | 16.4M | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; |
2154 | 16.4M | const int off = yc * tb->tb_width + xc; |
2155 | 16.4M | int *sig_coeff_flag = rc->sig_coeff_flag + off; |
2156 | 16.4M | int *abs_level_pass1 = rc->abs_level_pass1 + off; |
2157 | 16.4M | int *coeff_sign_level = rc->coeff_sign_level + off; |
2158 | 16.4M | int par_level_flag = 0; |
2159 | | |
2160 | 16.4M | abs_level_gtx_flag[n] = 0; |
2161 | 16.4M | last_scan_pos_pass1 = n; |
2162 | 16.4M | if (*sb_coded_flag && (n != rc->num_sb_coeff - 1 || !infer_sb_sig_coeff_flag)) { |
2163 | 8.91M | *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc); |
2164 | 8.91M | rc->rem_bins_pass1--; |
2165 | 8.91M | if (*sig_coeff_flag) |
2166 | 2.60M | infer_sb_sig_coeff_flag = 0; |
2167 | 8.91M | } else { |
2168 | 7.53M | *sig_coeff_flag = (n == rc->num_sb_coeff - 1) && infer_sb_sig_coeff_flag && *sb_coded_flag; |
2169 | 7.53M | } |
2170 | 16.4M | *coeff_sign_level = 0; |
2171 | 16.4M | if (*sig_coeff_flag) { |
2172 | 2.69M | *coeff_sign_level = 1 - 2 * coeff_sign_flag_ts_decode(lc, cu, rc, xc, yc); |
2173 | 2.69M | abs_level_gtx_flag[n] = abs_level_gt1_flag_ts_decode(lc, cu, rc, xc, yc); |
2174 | 2.69M | rc->rem_bins_pass1 -= 2; |
2175 | 2.69M | if (abs_level_gtx_flag[n]) { |
2176 | 1.70M | par_level_flag = par_level_flag_ts_decode(lc); |
2177 | 1.70M | rc->rem_bins_pass1--; |
2178 | 1.70M | } |
2179 | 2.69M | } |
2180 | 16.4M | *abs_level_pass1 = *sig_coeff_flag + par_level_flag + abs_level_gtx_flag[n]; |
2181 | 16.4M | } |
2182 | | |
2183 | | //greater than x scan pass |
2184 | 13.9M | for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) { |
2185 | 12.8M | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; |
2186 | 12.8M | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; |
2187 | 12.8M | const int off = yc * tb->tb_width + xc; |
2188 | | |
2189 | 12.8M | abs_level_pass2[n] = rc->abs_level_pass1[off]; |
2190 | 13.6M | for (int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) { |
2191 | 718k | abs_level_gtx_flag[n] = abs_level_gtx_flag_ts_decode(lc, j); |
2192 | 718k | abs_level_pass2[n] += abs_level_gtx_flag[n] << 1; |
2193 | 718k | rc->rem_bins_pass1--; |
2194 | 718k | } |
2195 | 12.8M | last_scan_pos_pass2 = n; |
2196 | 12.8M | } |
2197 | | |
2198 | | /* remainder scan pass */ |
2199 | 18.8M | for (n = 0; n < rc->num_sb_coeff; n++) { |
2200 | 17.7M | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; |
2201 | 17.7M | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; |
2202 | 17.7M | const int off = yc * tb->tb_width + xc; |
2203 | 17.7M | const int *abs_level_pass1 = rc->abs_level_pass1 + off; |
2204 | 17.7M | int *abs_level = rc->abs_level + off; |
2205 | 17.7M | int *coeff_sign_level = rc->coeff_sign_level + off; |
2206 | 17.7M | int abs_remainder = 0; |
2207 | | |
2208 | 17.7M | if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) || |
2209 | 17.7M | (n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 && |
2210 | 3.55M | *abs_level_pass1 >= 2) || |
2211 | 16.6M | (n > last_scan_pos_pass1 && *sb_coded_flag)) |
2212 | 2.33M | abs_remainder = abs_remainder_ts_decode(lc, rc, xc, yc); |
2213 | 17.7M | if (n <= last_scan_pos_pass2) { |
2214 | 12.8M | *abs_level = abs_level_pass2[n] + 2 * abs_remainder; |
2215 | 12.8M | } else if (n <= last_scan_pos_pass1) { |
2216 | 3.55M | *abs_level = *abs_level_pass1 + 2 * abs_remainder; |
2217 | 3.55M | } else { |
2218 | 1.30M | *abs_level = abs_remainder; |
2219 | 1.30M | if (abs_remainder) { |
2220 | | //n > lastScanPosPass1 |
2221 | 838k | *coeff_sign_level = 1 - 2 * coeff_sign_flag_decode(lc); |
2222 | 838k | } |
2223 | 1.30M | } |
2224 | 17.7M | if (!bdpcm_flag && n <= last_scan_pos_pass1) { |
2225 | 13.5M | const int left = xc > 0 ? abs_level[-1] : 0; |
2226 | 13.5M | const int above = yc > 0 ? abs_level[-tb->tb_width] : 0; |
2227 | 13.5M | const int pred = FFMAX(left, above); |
2228 | | |
2229 | 13.5M | if (*abs_level == 1 && pred > 0) |
2230 | 450k | *abs_level = pred; |
2231 | 13.1M | else if (*abs_level > 0 && *abs_level <= pred) |
2232 | 330k | (*abs_level)--; |
2233 | 13.5M | } |
2234 | 17.7M | if (*abs_level) { |
2235 | 3.53M | tb->coeffs[off] = *coeff_sign_level * *abs_level; |
2236 | 3.53M | tb->max_scan_x = FFMAX(xc, tb->max_scan_x); |
2237 | 3.53M | tb->max_scan_y = FFMAX(yc, tb->max_scan_y); |
2238 | 3.53M | tb->min_scan_x = FFMIN(xc, tb->min_scan_x); |
2239 | 3.53M | tb->min_scan_y = FFMIN(yc, tb->min_scan_y); |
2240 | 14.2M | } else { |
2241 | 14.2M | tb->coeffs[off] = 0; |
2242 | 14.2M | } |
2243 | 17.7M | } |
2244 | | |
2245 | 1.10M | return 0; |
2246 | 1.10M | } |
2247 | | |
2248 | | static int hls_residual_ts_coding(VVCLocalContext *lc, TransformBlock *tb) |
2249 | 532k | { |
2250 | 532k | ResidualCoding rc; |
2251 | 532k | tb->min_scan_x = tb->min_scan_y = INT_MAX; |
2252 | 532k | init_residual_coding(lc, &rc, tb->log2_tb_width, tb->log2_tb_height, tb); |
2253 | 1.64M | for (int i = 0; i <= rc.last_sub_block; i++) { |
2254 | 1.10M | int ret = residual_ts_coding_subblock(lc, &rc, i); |
2255 | 1.10M | if (ret < 0) |
2256 | 0 | return ret; |
2257 | 1.10M | } |
2258 | | |
2259 | 532k | return 0; |
2260 | 532k | } |
2261 | | |
2262 | | static inline int residual_coding_subblock(VVCLocalContext *lc, ResidualCoding *rc, const int i) |
2263 | 28.2M | { |
2264 | 28.2M | const H266RawSliceHeader *rsh = lc->sc->sh.r; |
2265 | 28.2M | TransformBlock *tb = rc->tb; |
2266 | 28.2M | int first_sig_scan_pos_sb, last_sig_scan_pos_sb; |
2267 | 28.2M | int first_pos_mode0, first_pos_mode1; |
2268 | 28.2M | int infer_sb_dc_sig_coeff_flag = 0; |
2269 | 28.2M | int n, sig_hidden_flag, sum = 0; |
2270 | 28.2M | int abs_level_gt2_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; |
2271 | 28.2M | const int start_qstate_sb = rc->qstate; |
2272 | 28.2M | const int xs = rc->sb_scan_x_off[i]; |
2273 | 28.2M | const int ys = rc->sb_scan_y_off[i]; |
2274 | 28.2M | uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs; |
2275 | | |
2276 | | |
2277 | 28.2M | av_assert0(rc->num_sb_coeff <= MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE); |
2278 | 28.2M | if (i < rc->last_sub_block && i > 0) { |
2279 | 18.7M | *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys); |
2280 | 18.7M | infer_sb_dc_sig_coeff_flag = 1; |
2281 | 18.7M | } else { |
2282 | 9.57M | *sb_coded_flag = 1; |
2283 | 9.57M | } |
2284 | 28.2M | if (*sb_coded_flag && (xs > 3 || ys > 3) && !tb->c_idx) |
2285 | 2.30M | lc->parse.mts_zero_out_sig_coeff_flag = 0; |
2286 | | |
2287 | 28.2M | if (!*sb_coded_flag) |
2288 | 7.10M | return 0; |
2289 | | |
2290 | 21.1M | first_sig_scan_pos_sb = rc->num_sb_coeff; |
2291 | 21.1M | last_sig_scan_pos_sb = -1; |
2292 | 21.1M | first_pos_mode0 = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1); |
2293 | 21.1M | first_pos_mode1 = first_pos_mode0; |
2294 | 282M | for (n = first_pos_mode0; n >= 0 && rc->rem_bins_pass1 >= 4; n--) { |
2295 | 261M | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; |
2296 | 261M | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; |
2297 | 261M | const int last = (xc == rc->last_significant_coeff_x && yc == rc->last_significant_coeff_y); |
2298 | 261M | int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc; |
2299 | 261M | int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc; |
2300 | | |
2301 | 261M | if ((n > 0 || !infer_sb_dc_sig_coeff_flag ) && !last) { |
2302 | 249M | *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc); |
2303 | 249M | rc->rem_bins_pass1--; |
2304 | 249M | if (*sig_coeff_flag) |
2305 | 79.1M | infer_sb_dc_sig_coeff_flag = 0; |
2306 | 249M | } else { |
2307 | 11.8M | *sig_coeff_flag = last || (!rc->scan_x_off[n] && !rc ->scan_y_off[n] && |
2308 | 4.91M | infer_sb_dc_sig_coeff_flag); |
2309 | 11.8M | } |
2310 | 261M | *abs_level_pass1 = 0; |
2311 | 261M | if (*sig_coeff_flag) { |
2312 | 91.0M | int abs_level_gt1_flag, par_level_flag = 0; |
2313 | 91.0M | const int inc = get_gtx_flag_inc(rc, xc, yc, last); |
2314 | 91.0M | abs_level_gt1_flag = abs_level_gtx_flag_decode(lc, inc); |
2315 | 91.0M | rc->rem_bins_pass1--; |
2316 | 91.0M | if (abs_level_gt1_flag) { |
2317 | 10.2M | par_level_flag = par_level_flag_decode(lc, inc); |
2318 | 10.2M | abs_level_gt2_flag[n] = abs_level_gtx_flag_decode(lc, inc + 32); |
2319 | 10.2M | rc->rem_bins_pass1 -= 2; |
2320 | 80.7M | } else { |
2321 | 80.7M | abs_level_gt2_flag[n] = 0; |
2322 | 80.7M | } |
2323 | 91.0M | if (last_sig_scan_pos_sb == -1) |
2324 | 20.8M | last_sig_scan_pos_sb = n; |
2325 | 91.0M | first_sig_scan_pos_sb = n; |
2326 | | |
2327 | 91.0M | *abs_level_pass1 = |
2328 | 91.0M | 1 + par_level_flag + abs_level_gt1_flag + (abs_level_gt2_flag[n] << 1); |
2329 | 170M | } else { |
2330 | 170M | abs_level_gt2_flag[n] = 0; |
2331 | 170M | } |
2332 | | |
2333 | 261M | if (rsh->sh_dep_quant_used_flag) |
2334 | 173M | rc->qstate = qstate_translate_table[rc->qstate][*abs_level_pass1 & 1]; |
2335 | | |
2336 | 261M | first_pos_mode1 = n - 1; |
2337 | 261M | } |
2338 | 282M | for (n = first_pos_mode0; n > first_pos_mode1; n--) { |
2339 | 261M | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; |
2340 | 261M | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; |
2341 | 261M | const int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc; |
2342 | 261M | int *abs_level = rc->abs_level + yc * tb->tb_width + xc; |
2343 | | |
2344 | 261M | *abs_level = *abs_level_pass1; |
2345 | 261M | if (abs_level_gt2_flag[n]) { |
2346 | 2.08M | const int abs_remainder = abs_remainder_decode(lc, rc, xc, yc); |
2347 | 2.08M | ep_update_hist(lc->ep, rc, abs_remainder, 2); |
2348 | 2.08M | *abs_level += 2 * abs_remainder; |
2349 | 2.08M | } |
2350 | 261M | } |
2351 | 22.5M | for (n = first_pos_mode1; n >= 0; n--) { |
2352 | 1.39M | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; |
2353 | 1.39M | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; |
2354 | 1.39M | int *abs_level = rc->abs_level + yc * tb->tb_width + xc; |
2355 | | |
2356 | 1.39M | if (*sb_coded_flag) { |
2357 | 1.39M | const int dec_abs_level = dec_abs_level_decode(lc, rc, xc, yc, abs_level); |
2358 | 1.39M | ep_update_hist(lc->ep, rc, dec_abs_level, 0); |
2359 | 1.39M | } |
2360 | 1.39M | if (*abs_level > 0) { |
2361 | 1.18M | if (last_sig_scan_pos_sb == -1) |
2362 | 640 | last_sig_scan_pos_sb = n; |
2363 | 1.18M | first_sig_scan_pos_sb = n; |
2364 | 1.18M | } |
2365 | 1.39M | if (rsh->sh_dep_quant_used_flag) |
2366 | 638k | rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1]; |
2367 | 1.39M | } |
2368 | 21.1M | sig_hidden_flag = rsh->sh_sign_data_hiding_used_flag && |
2369 | 3.99M | (last_sig_scan_pos_sb - first_sig_scan_pos_sb > 3 ? 1 : 0); |
2370 | | |
2371 | 21.1M | if (rsh->sh_dep_quant_used_flag) |
2372 | 13.1M | rc->qstate = start_qstate_sb; |
2373 | 21.1M | n = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1); |
2374 | 283M | for (/* nothing */; n >= 0; n--) { |
2375 | 262M | int trans_coeff_level; |
2376 | 262M | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; |
2377 | 262M | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; |
2378 | 262M | const int off = yc * tb->tb_width + xc; |
2379 | 262M | const int *abs_level = rc->abs_level + off; |
2380 | | |
2381 | 262M | if (*abs_level > 0) { |
2382 | 92.2M | int sign = 1; |
2383 | 92.2M | if (!sig_hidden_flag || (n != first_sig_scan_pos_sb)) |
2384 | 90.4M | sign = 1 - 2 * coeff_sign_flag_decode(lc); |
2385 | 92.2M | if (rsh->sh_dep_quant_used_flag) { |
2386 | 69.0M | trans_coeff_level = (2 * *abs_level - (rc->qstate > 1)) * sign; |
2387 | 69.0M | } else { |
2388 | 23.1M | trans_coeff_level = *abs_level * sign; |
2389 | 23.1M | if (sig_hidden_flag) { |
2390 | 11.7M | sum += *abs_level; |
2391 | 11.7M | if (n == first_sig_scan_pos_sb && (sum % 2)) |
2392 | 914k | trans_coeff_level = -trans_coeff_level; |
2393 | 11.7M | } |
2394 | 23.1M | } |
2395 | 92.2M | tb->coeffs[off] = trans_coeff_level; |
2396 | 92.2M | tb->max_scan_x = FFMAX(xc, tb->max_scan_x); |
2397 | 92.2M | tb->max_scan_y = FFMAX(yc, tb->max_scan_y); |
2398 | 92.2M | } |
2399 | 262M | if (rsh->sh_dep_quant_used_flag) |
2400 | 174M | rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1]; |
2401 | 262M | } |
2402 | | |
2403 | 21.1M | return 0; |
2404 | 28.2M | } |
2405 | | |
2406 | | static void derive_last_scan_pos(ResidualCoding *rc) |
2407 | 6.95M | { |
2408 | 6.95M | int xc, yc, xs, ys; |
2409 | 841M | do { |
2410 | 841M | if (!rc->last_scan_pos) { |
2411 | 47.4M | rc->last_scan_pos = rc->num_sb_coeff; |
2412 | 47.4M | rc->last_sub_block--; |
2413 | 47.4M | } |
2414 | 841M | rc->last_scan_pos--; |
2415 | 841M | xs = rc->sb_scan_x_off[rc->last_sub_block]; |
2416 | 841M | ys = rc->sb_scan_y_off[rc->last_sub_block]; |
2417 | 841M | xc = (xs << rc->log2_sb_w) + rc->scan_x_off[rc->last_scan_pos]; |
2418 | 841M | yc = (ys << rc->log2_sb_h) + rc->scan_y_off[rc->last_scan_pos]; |
2419 | 841M | } while ((xc != rc->last_significant_coeff_x) || (yc != rc->last_significant_coeff_y)); |
2420 | 6.95M | } |
2421 | | |
2422 | | static void last_significant_coeff_x_y_decode(ResidualCoding *rc, VVCLocalContext *lc, |
2423 | | const int log2_zo_tb_width, const int log2_zo_tb_height) |
2424 | 6.95M | { |
2425 | 6.95M | const H266RawSliceHeader *rsh = lc->sc->sh.r; |
2426 | 6.95M | const TransformBlock *tb = rc->tb; |
2427 | 6.95M | int last_significant_coeff_x, last_significant_coeff_y; |
2428 | | |
2429 | 6.95M | last_significant_coeff_x = last_significant_coeff_x_prefix_decode(lc, |
2430 | 6.95M | tb->log2_tb_width, log2_zo_tb_width, tb->c_idx); |
2431 | | |
2432 | 6.95M | last_significant_coeff_y = last_significant_coeff_y_prefix_decode(lc, |
2433 | 6.95M | tb->log2_tb_height, log2_zo_tb_height, tb->c_idx); |
2434 | | |
2435 | 6.95M | if (last_significant_coeff_x > 3) { |
2436 | 2.21M | int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_x); |
2437 | 2.21M | last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) * |
2438 | 2.21M | (2 + (last_significant_coeff_x & 1)) + suffix; |
2439 | 2.21M | } |
2440 | 6.95M | if (last_significant_coeff_y > 3) { |
2441 | 1.74M | int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_y); |
2442 | 1.74M | last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) * |
2443 | 1.74M | (2 + (last_significant_coeff_y & 1)) + suffix; |
2444 | 1.74M | } |
2445 | 6.95M | if (rsh->sh_reverse_last_sig_coeff_flag) { |
2446 | 13.1k | last_significant_coeff_x = (1 << log2_zo_tb_width) - 1 - last_significant_coeff_x; |
2447 | 13.1k | last_significant_coeff_y = (1 << log2_zo_tb_height) - 1 - last_significant_coeff_y; |
2448 | 13.1k | } |
2449 | 6.95M | rc->last_significant_coeff_x = last_significant_coeff_x; |
2450 | 6.95M | rc->last_significant_coeff_y = last_significant_coeff_y; |
2451 | 6.95M | } |
2452 | | |
2453 | | static int hls_residual_coding(VVCLocalContext *lc, TransformBlock *tb) |
2454 | 6.95M | { |
2455 | 6.95M | const VVCSPS *sps = lc->fc->ps.sps; |
2456 | 6.95M | const CodingUnit *cu = lc->cu; |
2457 | 6.95M | const int log2_tb_width = tb->log2_tb_width; |
2458 | 6.95M | const int log2_tb_height = tb->log2_tb_height; |
2459 | 6.95M | const int c_idx = tb->c_idx; |
2460 | 6.95M | int log2_zo_tb_width, log2_zo_tb_height; |
2461 | 6.95M | ResidualCoding rc; |
2462 | | |
2463 | 6.95M | if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width == 5 && log2_tb_height < 6) |
2464 | 0 | log2_zo_tb_width = 4; |
2465 | 6.95M | else |
2466 | 6.95M | log2_zo_tb_width = FFMIN(log2_tb_width, 5 ); |
2467 | | |
2468 | 6.95M | if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width < 6 && log2_tb_height == 5 ) |
2469 | 0 | log2_zo_tb_height = 4; |
2470 | 6.95M | else |
2471 | 6.95M | log2_zo_tb_height = FFMIN(log2_tb_height, 5); |
2472 | | |
2473 | 6.95M | init_residual_coding(lc, &rc, log2_zo_tb_width, log2_zo_tb_height, tb); |
2474 | 6.95M | last_significant_coeff_x_y_decode(&rc, lc, log2_zo_tb_width, log2_zo_tb_height); |
2475 | 6.95M | derive_last_scan_pos(&rc); |
2476 | | |
2477 | 6.95M | if (!rc.last_sub_block && log2_tb_width >= 2 && log2_tb_height >= 2 && !tb->ts && rc.last_scan_pos > 0) |
2478 | 3.31M | lc->parse.lfnst_dc_only = 0; |
2479 | 6.95M | if ((rc.last_sub_block > 0 && log2_tb_width >= 2 && log2_tb_height >= 2 ) || |
2480 | 4.35M | (rc.last_scan_pos > 7 && (log2_tb_width == 2 || log2_tb_width == 3 ) && |
2481 | 1.09M | log2_tb_width == log2_tb_height)) |
2482 | 3.52M | lc->parse.lfnst_zero_out_sig_coeff_flag = 0; |
2483 | 6.95M | if ((rc.last_sub_block > 0 || rc.last_scan_pos > 0 ) && !c_idx) |
2484 | 4.94M | lc->parse.mts_dc_only = 0; |
2485 | | |
2486 | 6.95M | memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs)); |
2487 | 6.95M | memset(rc.abs_level, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level[0])); |
2488 | 6.95M | memset(rc.sb_coded_flag, 0, rc.nb_sbs); |
2489 | 6.95M | memset(rc.abs_level_pass1, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level_pass1[0])); |
2490 | 6.95M | memset(rc.sig_coeff_flag, 0, tb->tb_width * tb->tb_height * sizeof(rc.sig_coeff_flag[0])); |
2491 | | |
2492 | 35.2M | for (int i = rc.last_sub_block; i >= 0; i--) { |
2493 | 28.2M | int ret = residual_coding_subblock(lc, &rc, i); |
2494 | 28.2M | if (ret < 0) |
2495 | 0 | return ret; |
2496 | 28.2M | } |
2497 | | |
2498 | 6.95M | return 0; |
2499 | 6.95M | } |
2500 | | |
2501 | | int ff_vvc_residual_coding(VVCLocalContext *lc, TransformBlock *tb) |
2502 | 7.49M | { |
2503 | 7.49M | const H266RawSliceHeader *rsh = lc->sc->sh.r; |
2504 | 7.49M | const int ts = !rsh->sh_ts_residual_coding_disabled_flag && tb->ts; |
2505 | | |
2506 | 7.49M | return ts ? hls_residual_ts_coding(lc, tb) : hls_residual_coding(lc, tb); |
2507 | 7.49M | } |
2508 | | |
2509 | | int ff_vvc_cu_coded_flag(VVCLocalContext *lc) |
2510 | 256k | { |
2511 | 256k | return GET_CABAC(CU_CODED_FLAG); |
2512 | 256k | } |
2513 | | |
2514 | | int ff_vvc_sbt_flag(VVCLocalContext *lc) |
2515 | 22.9k | { |
2516 | 22.9k | const int w = lc->cu->cb_width; |
2517 | 22.9k | const int h = lc->cu->cb_height; |
2518 | 22.9k | const int inc = w * h <= 256; |
2519 | 22.9k | return GET_CABAC(CU_SBT_FLAG + inc); |
2520 | 22.9k | } |
2521 | | |
2522 | | int ff_vvc_sbt_quad_flag(VVCLocalContext *lc) |
2523 | 0 | { |
2524 | 0 | return GET_CABAC(CU_SBT_QUAD_FLAG); |
2525 | 0 | } |
2526 | | |
2527 | | int ff_vvc_sbt_horizontal_flag(VVCLocalContext *lc) |
2528 | 5.50k | { |
2529 | 5.50k | const int w = lc->cu->cb_width; |
2530 | 5.50k | const int h = lc->cu->cb_height; |
2531 | 5.50k | const int inc = (w == h) ? 0 : ((w < h) ? 1 : 2); |
2532 | 5.50k | return GET_CABAC(CU_SBT_HORIZONTAL_FLAG + inc); |
2533 | 5.50k | } |
2534 | | |
2535 | | int ff_vvc_sbt_pos_flag(VVCLocalContext *lc) |
2536 | 6.53k | { |
2537 | 6.53k | return GET_CABAC(CU_SBT_POS_FLAG); |
2538 | 6.53k | } |
2539 | | |
2540 | | int ff_vvc_lfnst_idx(VVCLocalContext *lc, const int inc) |
2541 | 488k | { |
2542 | 488k | if (!GET_CABAC(LFNST_IDX + inc)) |
2543 | 102k | return 0; |
2544 | 385k | if (!GET_CABAC(LFNST_IDX + 2)) |
2545 | 299k | return 1; |
2546 | 85.8k | return 2; |
2547 | 385k | } |
2548 | | |
2549 | | int ff_vvc_mts_idx(VVCLocalContext *lc) |
2550 | 1.56M | { |
2551 | 1.56M | int i; |
2552 | 3.12M | for (i = 0; i < 4; i++) { |
2553 | 3.12M | if (!GET_CABAC(MTS_IDX + i)) |
2554 | 1.56M | return i; |
2555 | 3.12M | } |
2556 | 6.58k | return i; |
2557 | 1.56M | } |
2558 | | |
2559 | | int ff_vvc_end_of_slice_flag_decode(VVCLocalContext *lc) |
2560 | 1.44M | { |
2561 | 1.44M | return get_cabac_terminate(&lc->ep->cc); |
2562 | 1.44M | } |
2563 | | |
2564 | | int ff_vvc_end_of_tile_one_bit(VVCLocalContext *lc) |
2565 | 1 | { |
2566 | 1 | return get_cabac_terminate(&lc->ep->cc); |
2567 | 1 | } |
2568 | | |
2569 | | int ff_vvc_end_of_subset_one_bit(VVCLocalContext *lc) |
2570 | 0 | { |
2571 | 0 | return get_cabac_terminate(&lc->ep->cc); |
2572 | 0 | } |