FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/cabac.c
Date: 2026-10-19 08:11:58
Exec Total Coverage
Lines: 1021 1036 98.6%
Functions: 139 139 100.0%
Branches: 675 702 96.2%

Line Branch Exec 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 273 static int cabac_reinit(VVCLocalContext *lc)
814 {
815
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 273 times.
273 return skip_bytes(&lc->ep->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
816 }
817
818 2428 static void cabac_init_state(VVCLocalContext *lc)
819 {
820 2428 const VVCSPS *sps = lc->fc->ps.sps;
821 2428 const H266RawSliceHeader *rsh = lc->sc->sh.r;
822 2428 const int qp = av_clip_uintp2(lc->sc->sh.slice_qp_y, 6);
823 2428 int init_type = 2 - rsh->sh_slice_type;
824
825 2428 ff_vvc_ep_init_stat_coeff(lc->ep, sps->bit_depth, sps->r->sps_persistent_rice_adaptation_enabled_flag);
826
827
3/4
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 1852 times.
✓ Branch 2 taken 576 times.
✗ Branch 3 not taken.
2428 if (rsh->sh_cabac_init_flag && !IS_I(rsh))
828 576 init_type ^= 3;
829
830
2/2
✓ Branch 0 taken 917784 times.
✓ Branch 1 taken 2428 times.
920212 for (int i = 0; i < VVC_CONTEXTS; i++) {
831 917784 VVCCabacState *state = &lc->ep->cabac_state[i];
832 917784 const int init_value = init_values[init_type][i];
833 917784 const int shift_idx = init_values[3][i];
834 917784 const int m = (init_value >> 3) - 4;
835 917784 const int n = ((init_value & 7) * 18) + 1;
836 917784 const int pre = av_clip(((m * (qp - 16)) >> 1) + n, 1, 127);
837
838 917784 state->state[0] = pre << 3;
839 917784 state->state[1] = pre << 7;
840 917784 state->shift[0] = (shift_idx >> 2 ) + 2;
841 917784 state->shift[1] = (shift_idx & 3 ) + 3 + state->shift[0];
842 }
843 2428 }
844
845 55834 int ff_vvc_cabac_init(VVCLocalContext *lc,
846 const int ctu_idx, const int rx, const int ry)
847 {
848 55834 int ret = 0;
849 55834 const VVCPPS *pps = lc->fc->ps.pps;
850 55834 const int first_ctb_in_slice = !ctu_idx;
851
4/4
✓ Branch 0 taken 6929 times.
✓ Branch 1 taken 48905 times.
✓ Branch 2 taken 2316 times.
✓ Branch 3 taken 4613 times.
55834 const int first_ctb_in_tile = rx == pps->ctb_to_col_bd[rx] && ry == pps->ctb_to_row_bd[ry];
852
853
4/4
✓ Branch 0 taken 53933 times.
✓ Branch 1 taken 1901 times.
✓ Branch 2 taken 527 times.
✓ Branch 3 taken 53406 times.
55834 if (first_ctb_in_slice|| first_ctb_in_tile) {
854
4/4
✓ Branch 0 taken 2047 times.
✓ Branch 1 taken 381 times.
✓ Branch 2 taken 273 times.
✓ Branch 3 taken 1774 times.
2428 if (lc->sc->nb_eps == 1 && !first_ctb_in_slice)
855 273 ret = cabac_reinit(lc);
856
1/2
✓ Branch 0 taken 2428 times.
✗ Branch 1 not taken.
2428 if (!ret)
857 2428 cabac_init_state(lc);
858
4/4
✓ Branch 0 taken 48356 times.
✓ Branch 1 taken 5050 times.
✓ Branch 2 taken 3665 times.
✓ Branch 3 taken 44691 times.
53406 } else if (lc->sc->nb_eps == 1 && rx == pps->ctb_to_col_bd[rx] &&
859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3665 times.
3665 lc->fc->ps.sps->r->sps_entropy_coding_sync_enabled_flag) {
860 ✗ avpriv_report_missing_feature(lc->fc->log_ctx, "Entropy coding sync without entry points");
861 ✗ return AVERROR_PATCHWELCOME;
862 }
863 55834 return ret;
864 }
865
866 //fixme
867 2250590 static void vvc_refill2(CABACContext* c) {
868 int i;
869 unsigned x;
870 #if !HAVE_FAST_CLZ
871 x = c->low ^ (c->low - 1);
872 i = 7 - ff_h264_norm_shift[x >> (CABAC_BITS - 1)];
873 #else
874 2250590 i = ff_ctz(c->low) - CABAC_BITS;
875 #endif
876
877 2250590 x = -CABAC_MASK;
878
879 #if CABAC_BITS == 16
880 2250590 x += (c->bytestream[0] << 9) + (c->bytestream[1] << 1);
881 #else
882 x += c->bytestream[0] << 1;
883 #endif
884
885 2250590 c->low += x << i;
886 #if !UNCHECKED_BITSTREAM_READER
887
2/2
✓ Branch 0 taken 2250467 times.
✓ Branch 1 taken 123 times.
2250590 if (c->bytestream < c->bytestream_end)
888 #endif
889 2250467 c->bytestream += CABAC_BITS / 8;
890 2250590 }
891
892 58548636 static int inline vvc_get_cabac(CABACContext *c, VVCCabacState* base, const int ctx)
893 {
894 58548636 VVCCabacState *s = base + ctx;
895 58548636 const int qRangeIdx = c->range >> 5;
896 58548636 const int pState = s->state[1] + (s->state[0] << 4);
897 58548636 const int valMps = pState >> 14;
898
2/2
✓ Branch 0 taken 24028854 times.
✓ Branch 1 taken 34519782 times.
58548636 const int RangeLPS = (qRangeIdx * ((valMps ? 32767 - pState : pState) >> 9 ) >> 1) + 4;
899 int bit, lps_mask;
900
901 58548636 c->range -= RangeLPS;
902 58548636 lps_mask = ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
903
904 58548636 c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
905 58548636 c->range += (RangeLPS - c->range) & lps_mask;
906
907 58548636 bit = valMps ^ (lps_mask & 1);
908
909 58548636 lps_mask = ff_h264_norm_shift[c->range];
910 58548636 c->range <<= lps_mask;
911 58548636 c->low <<= lps_mask;
912
913
2/2
✓ Branch 0 taken 2250590 times.
✓ Branch 1 taken 56298046 times.
58548636 if (!(c->low & CABAC_MASK))
914 2250590 vvc_refill2(c);
915 58548636 s->state[0] = s->state[0] - (s->state[0] >> s->shift[0]) + (1023 * bit >> s->shift[0]);
916 58548636 s->state[1] = s->state[1] - (s->state[1] >> s->shift[1]) + (16383 * bit >> s->shift[1]);
917 58548636 return bit;
918 }
919
920 #define GET_CABAC(ctx) vvc_get_cabac(&lc->ep->cc, lc->ep->cabac_state, ctx)
921
922 //9.3.3.4 Truncated binary (TB) binarization process
923 359404 static int truncated_binary_decode(VVCLocalContext *lc, const int c_max)
924 {
925 359404 const int n = c_max + 1;
926 359404 const int k = av_log2(n);
927 359404 const int u = (1 << (k+1)) - n;
928 359404 int v = 0;
929
2/2
✓ Branch 0 taken 1229574 times.
✓ Branch 1 taken 359404 times.
1588978 for (int i = 0; i < k; i++)
930 1229574 v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
931
2/2
✓ Branch 0 taken 183380 times.
✓ Branch 1 taken 176024 times.
359404 if (v >= u) {
932 183380 v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
933 183380 v -= u;
934 }
935 359404 return v;
936 }
937
938 // 9.3.3.5 k-th order Exp - Golomb binarization process
939 50372 static int kth_order_egk_decode(CABACContext *c, int k, const int max)
940 {
941 50372 int bit = 1;
942 50372 int value = 0;
943 50372 int symbol = 0;
944
945
2/2
✓ Branch 0 taken 91119 times.
✓ Branch 1 taken 50372 times.
141491 while (bit) {
946 91119 bit = get_cabac_bypass(c);
947
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 91119 times.
91119 if (max - value < (bit << k))
948 ✗ return AVERROR_INVALIDDATA;
949 91119 value += bit << k++;
950 }
951
952
2/2
✓ Branch 0 taken 23986 times.
✓ Branch 1 taken 26386 times.
50372 if (--k) {
953
2/2
✓ Branch 0 taken 41492 times.
✓ Branch 1 taken 23986 times.
65478 for (int i = 0; i < k; i++)
954 41492 symbol = (symbol << 1) | get_cabac_bypass(c);
955 23986 value += symbol;
956 }
957
958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50372 times.
50372 if (value > max)
959 ✗ return AVERROR_INVALIDDATA;
960
961 50372 return value;
962 }
963
964 // 9.3.3.6 Limited k-th order Exp-Golomb binarization process
965 230115 static int limited_kth_order_egk_decode(CABACContext *c, const int k, const int max_pre_ext_len, const int trunc_suffix_len)
966 {
967 230115 int pre_ext_len = 0;
968 int escape_length;
969 230115 int val = 0;
970
4/4
✓ Branch 0 taken 706984 times.
✓ Branch 1 taken 110 times.
✓ Branch 3 taken 476979 times.
✓ Branch 4 taken 230005 times.
707094 while ((pre_ext_len < max_pre_ext_len) && get_cabac_bypass(c))
971 476979 pre_ext_len++;
972
2/2
✓ Branch 0 taken 110 times.
✓ Branch 1 taken 230005 times.
230115 if (pre_ext_len == max_pre_ext_len)
973 110 escape_length = trunc_suffix_len;
974 else
975 230005 escape_length = pre_ext_len + k;
976
2/2
✓ Branch 0 taken 775621 times.
✓ Branch 1 taken 230115 times.
1005736 while (escape_length-- > 0) {
977 775621 val = (val << 1) + get_cabac_bypass(c);
978 }
979 230115 val += ((1 << pre_ext_len) - 1) << k;
980 230115 return val;
981 }
982
983 // 9.3.3.7 Fixed-length binarization process
984 33621 static int fixed_length_decode(CABACContext* c, const int len)
985 {
986 33621 int value = 0;
987
988
2/2
✓ Branch 0 taken 216969 times.
✓ Branch 1 taken 33621 times.
250590 for (int i = 0; i < len; i++)
989 216969 value = (value << 1) | get_cabac_bypass(c);
990
991 33621 return value;
992 }
993
994 static av_always_inline
995 4103783 void get_left_top(const VVCLocalContext *lc, uint8_t *left, uint8_t *top,
996 const int x0, const int y0, const uint8_t *left_ctx, const uint8_t *top_ctx)
997 {
998 4103783 const VVCFrameContext *fc = lc->fc;
999 4103783 const VVCSPS *sps = fc->ps.sps;
1000 4103783 const int min_cb_width = fc->ps.pps->min_cb_width;
1001 4103783 const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
1002 4103783 const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
1003 4103783 const int x_cb = x0 >> sps->min_cb_log2_size_y;
1004 4103783 const int y_cb = y0 >> sps->min_cb_log2_size_y;
1005
1006
4/4
✓ Branch 0 taken 800792 times.
✓ Branch 1 taken 3302991 times.
✓ Branch 2 taken 668182 times.
✓ Branch 3 taken 132610 times.
4103783 if (lc->ctb_left_flag || x0b)
1007 3971173 *left = SAMPLE_CTB(left_ctx, x_cb - 1, y_cb);
1008
4/4
✓ Branch 0 taken 1233503 times.
✓ Branch 1 taken 2870280 times.
✓ Branch 2 taken 1044734 times.
✓ Branch 3 taken 188769 times.
4103783 if (lc->ctb_up_flag || y0b)
1009 3915014 *top = SAMPLE_CTB(top_ctx, x_cb, y_cb - 1);
1010 4103783 }
1011
1012 static av_always_inline
1013 686199 uint8_t get_inc(VVCLocalContext *lc, const uint8_t *ctx)
1014 {
1015 686199 uint8_t left = 0, top = 0;
1016 686199 get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx);
1017 686199 return left + top;
1018 }
1019
1020 25043 int ff_vvc_sao_merge_flag_decode(VVCLocalContext *lc)
1021 {
1022 25043 return GET_CABAC(SAO_MERGE_FLAG);
1023 }
1024
1025 14344 int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc)
1026 {
1027
2/2
✓ Branch 1 taken 9461 times.
✓ Branch 2 taken 4883 times.
14344 if (!GET_CABAC(SAO_TYPE_IDX))
1028 9461 return SAO_NOT_APPLIED;
1029
1030
2/2
✓ Branch 1 taken 1453 times.
✓ Branch 2 taken 3430 times.
4883 if (!get_cabac_bypass(&lc->ep->cc))
1031 1453 return SAO_BAND;
1032 3430 return SAO_EDGE;
1033 }
1034
1035 1773 int ff_vvc_sao_band_position_decode(VVCLocalContext *lc)
1036 {
1037 1773 return fixed_length_decode(&lc->ep->cc, 5);
1038 }
1039
1040 25700 int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc)
1041 {
1042 25700 int i = 0;
1043 25700 const int length = (1 << (FFMIN(lc->fc->ps.sps->bit_depth, 10) - 5)) - 1;
1044
1045
4/4
✓ Branch 0 taken 130647 times.
✓ Branch 1 taken 262 times.
✓ Branch 3 taken 105209 times.
✓ Branch 4 taken 25438 times.
130909 while (i < length && get_cabac_bypass(&lc->ep->cc))
1046 105209 i++;
1047 25700 return i;
1048 }
1049
1050 3338 int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc)
1051 {
1052 3338 return get_cabac_bypass(&lc->ep->cc);
1053 }
1054
1055 3430 int ff_vvc_sao_eo_class_decode(VVCLocalContext *lc)
1056 {
1057 3430 return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1058 }
1059
1060 65751 int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx)
1061 {
1062 65751 int inc = c_idx * 3;
1063 65751 const VVCFrameContext *fc = lc->fc;
1064
2/2
✓ Branch 0 taken 56241 times.
✓ Branch 1 taken 9510 times.
65751 if (lc->ctb_left_flag) {
1065 56241 const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry);
1066 56241 inc += left->ctb_flag[c_idx];
1067 }
1068
2/2
✓ Branch 0 taken 49854 times.
✓ Branch 1 taken 15897 times.
65751 if (lc->ctb_up_flag) {
1069 49854 const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1);
1070 49854 inc += above->ctb_flag[c_idx];
1071 }
1072 65751 return GET_CABAC(ALF_CTB_FLAG + inc);
1073 }
1074
1075 20237 int ff_vvc_alf_use_aps_flag(VVCLocalContext *lc)
1076 {
1077 20237 return GET_CABAC(ALF_USE_APS_FLAG);
1078 }
1079
1080 5167 int ff_vvc_alf_luma_prev_filter_idx(VVCLocalContext *lc)
1081 {
1082 5167 return truncated_binary_decode(lc, lc->sc->sh.r->sh_num_alf_aps_ids_luma - 1);
1083 }
1084
1085 2803 int ff_vvc_alf_luma_fixed_filter_idx(VVCLocalContext *lc)
1086 {
1087 2803 return truncated_binary_decode(lc, 15);
1088 }
1089
1090 18421 int ff_vvc_alf_ctb_filter_alt_idx(VVCLocalContext *lc, const int c_idx, const int num_chroma_filters)
1091 {
1092 18421 int i = 0;
1093 18421 const int length = num_chroma_filters - 1;
1094
1095
4/4
✓ Branch 0 taken 34163 times.
✓ Branch 1 taken 3130 times.
✓ Branch 3 taken 18872 times.
✓ Branch 4 taken 15291 times.
37293 while (i < length && GET_CABAC(ALF_CTB_FILTER_ALT_IDX + c_idx - 1))
1096 18872 i++;
1097 18421 return i;
1098 }
1099
1100 22625 int ff_vvc_alf_ctb_cc_idc(VVCLocalContext *lc, const int rx, const int ry, const int idx, const int cc_filters_signalled)
1101 {
1102
2/2
✓ Branch 0 taken 12154 times.
✓ Branch 1 taken 10471 times.
22625 int inc = !idx ? ALF_CTB_CC_CB_IDC : ALF_CTB_CC_CR_IDC;
1103 22625 int i = 0;
1104 22625 const VVCFrameContext *fc = lc->fc;
1105
2/2
✓ Branch 0 taken 19914 times.
✓ Branch 1 taken 2711 times.
22625 if (lc->ctb_left_flag) {
1106 19914 const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry);
1107 19914 inc += left->ctb_cc_idc[idx] != 0;
1108 }
1109
2/2
✓ Branch 0 taken 18700 times.
✓ Branch 1 taken 3925 times.
22625 if (lc->ctb_up_flag) {
1110 18700 const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1);
1111 18700 inc += above->ctb_cc_idc[idx] != 0;
1112 }
1113
1114
2/2
✓ Branch 1 taken 12098 times.
✓ Branch 2 taken 10527 times.
22625 if (!GET_CABAC(inc))
1115 12098 return 0;
1116 10527 i++;
1117
4/4
✓ Branch 0 taken 17808 times.
✓ Branch 1 taken 1908 times.
✓ Branch 3 taken 9189 times.
✓ Branch 4 taken 8619 times.
19716 while (i < cc_filters_signalled && get_cabac_bypass(&lc->ep->cc))
1118 9189 i++;
1119 10527 return i;
1120 }
1121
1122 2277091 int ff_vvc_split_cu_flag(VVCLocalContext *lc, const int x0, const int y0,
1123 const int cb_width, const int cb_height, const int is_chroma, const VVCAllowedSplit *a)
1124 {
1125 2277091 const VVCFrameContext *fc = lc->fc;
1126 2277091 const VVCPPS *pps = fc->ps.pps;
1127
4/4
✓ Branch 0 taken 2272062 times.
✓ Branch 1 taken 5029 times.
✓ Branch 2 taken 2217315 times.
✓ Branch 3 taken 54747 times.
2277091 const int is_inside = (x0 + cb_width <= pps->width) && (y0 + cb_height <= pps->height);
1128
1129
12/12
✓ Branch 0 taken 905810 times.
✓ Branch 1 taken 1371281 times.
✓ Branch 2 taken 658462 times.
✓ Branch 3 taken 247348 times.
✓ Branch 4 taken 652635 times.
✓ Branch 5 taken 5827 times.
✓ Branch 6 taken 651050 times.
✓ Branch 7 taken 1585 times.
✓ Branch 8 taken 56530 times.
✓ Branch 9 taken 594520 times.
✓ Branch 10 taken 1622795 times.
✓ Branch 11 taken 59776 times.
2277091 if ((a->btv || a->bth || a->ttv || a->tth || a->qt) && is_inside)
1130 {
1131 1622795 uint8_t inc = 0, left_height = cb_height, top_width = cb_width;
1132
1133 1622795 get_left_top(lc, &left_height, &top_width, x0, y0, fc->tab.cb_height[is_chroma], fc->tab.cb_width[is_chroma]);
1134 1622795 inc += left_height < cb_height;
1135 1622795 inc += top_width < cb_width;
1136 1622795 inc += (a->btv + a->bth + a->ttv + a->tth + 2 * a->qt - 1) / 2 * 3;
1137
1138 1622795 return GET_CABAC(SPLIT_CU_FLAG + inc);
1139
1140 }
1141 654296 return !is_inside;
1142 }
1143
1144 295495 static int split_qt_flag_decode(VVCLocalContext *lc, const int x0, const int y0, const int ch_type, const int cqt_depth)
1145 {
1146 295495 const VVCFrameContext *fc = lc->fc;
1147 295495 int inc = 0;
1148 295495 uint8_t depth_left = 0, depth_top = 0;
1149
1150 295495 get_left_top(lc, &depth_left, &depth_top, x0, y0, fc->tab.cqt_depth[ch_type], fc->tab.cqt_depth[ch_type]);
1151 295495 inc += depth_left > cqt_depth;
1152 295495 inc += depth_top > cqt_depth;
1153
2/2
✓ Branch 0 taken 224088 times.
✓ Branch 1 taken 71407 times.
295495 inc += (cqt_depth >= 2) * 3;
1154
1155 295495 return GET_CABAC(SPLIT_QT_FLAG + inc);
1156 }
1157
1158 775925 static int mtt_split_cu_vertical_flag_decode(VVCLocalContext *lc, const int x0, const int y0,
1159 const int cb_width, const int cb_height, const int ch_type, const VVCAllowedSplit* a)
1160 {
1161
8/8
✓ Branch 0 taken 89104 times.
✓ Branch 1 taken 686821 times.
✓ Branch 2 taken 18204 times.
✓ Branch 3 taken 70900 times.
✓ Branch 4 taken 125700 times.
✓ Branch 5 taken 579325 times.
✓ Branch 6 taken 15072 times.
✓ Branch 7 taken 110628 times.
775925 if ((a->bth || a->tth) && (a->btv || a->ttv)) {
1162 int inc;
1163 594397 const int v = a->btv + a->ttv;
1164 594397 const int h = a->bth + a->tth;
1165
2/2
✓ Branch 0 taken 95794 times.
✓ Branch 1 taken 498603 times.
594397 if (v > h)
1166 95794 inc = 4;
1167
2/2
✓ Branch 0 taken 95839 times.
✓ Branch 1 taken 402764 times.
498603 else if (v < h)
1168 95839 inc = 3;
1169 else {
1170 402764 const VVCFrameContext *fc = lc->fc;
1171 402764 const VVCSPS *sps = fc->ps.sps;
1172 402764 const int min_cb_width = fc->ps.pps->min_cb_width;
1173 402764 const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
1174 402764 const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
1175 402764 const int x_cb = x0 >> sps->min_cb_log2_size_y;
1176 402764 const int y_cb = y0 >> sps->min_cb_log2_size_y;
1177
4/4
✓ Branch 0 taken 118293 times.
✓ Branch 1 taken 284471 times.
✓ Branch 2 taken 97192 times.
✓ Branch 3 taken 21101 times.
402764 const int available_a = lc->ctb_up_flag || y0b;
1178
4/4
✓ Branch 0 taken 73214 times.
✓ Branch 1 taken 329550 times.
✓ Branch 2 taken 57662 times.
✓ Branch 3 taken 15552 times.
402764 const int available_l = lc->ctb_left_flag || x0b;
1179
2/2
✓ Branch 0 taken 381663 times.
✓ Branch 1 taken 21101 times.
402764 const int da = cb_width / (available_a ? SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cb, y_cb - 1) : 1);
1180
2/2
✓ Branch 0 taken 387212 times.
✓ Branch 1 taken 15552 times.
402764 const int dl = cb_height / (available_l ? SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cb - 1, y_cb) : 1);
1181
1182
6/6
✓ Branch 0 taken 293880 times.
✓ Branch 1 taken 108884 times.
✓ Branch 2 taken 274262 times.
✓ Branch 3 taken 19618 times.
✓ Branch 4 taken 13415 times.
✓ Branch 5 taken 260847 times.
402764 if (da == dl || !available_a || !available_l)
1183 141917 inc = 0;
1184
2/2
✓ Branch 0 taken 136649 times.
✓ Branch 1 taken 124198 times.
260847 else if (da < dl)
1185 136649 inc = 1;
1186 else
1187 124198 inc = 2;
1188 }
1189 594397 return GET_CABAC(MTT_SPLIT_CU_VERTICAL_FLAG + inc);
1190 }
1191
4/4
✓ Branch 0 taken 71646 times.
✓ Branch 1 taken 109882 times.
✓ Branch 2 taken 70900 times.
✓ Branch 3 taken 746 times.
181528 return !(a->bth || a->tth);
1192 }
1193
1194 520688 static int mtt_split_cu_binary_flag_decode(VVCLocalContext *lc, const int mtt_split_cu_vertical_flag, const int mtt_depth)
1195 {
1196 520688 const int inc = (2 * mtt_split_cu_vertical_flag) + ((mtt_depth <= 1) ? 1 : 0);
1197 520688 return GET_CABAC(MTT_SPLIT_CU_BINARY_FLAG + inc);
1198 }
1199
1200 890161 VVCSplitMode ff_vvc_split_mode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height,
1201 const int cqt_depth, const int mtt_depth, const int ch_type, const VVCAllowedSplit *a)
1202 {
1203
8/8
✓ Branch 0 taken 171852 times.
✓ Branch 1 taken 718309 times.
✓ Branch 2 taken 43522 times.
✓ Branch 3 taken 128330 times.
✓ Branch 4 taken 39239 times.
✓ Branch 5 taken 4283 times.
✓ Branch 6 taken 746 times.
✓ Branch 7 taken 38493 times.
890161 const int allow_no_qt = a->btv || a->bth || a->ttv || a->tth;
1204 int split_qt_flag;
1205 int mtt_split_cu_vertical_flag;
1206 int mtt_split_cu_binary_flag;
1207 890161 const VVCSplitMode mtt_split_modes[] = {
1208 SPLIT_TT_HOR, SPLIT_BT_HOR, SPLIT_TT_VER, SPLIT_BT_VER,
1209 };
1210
4/4
✓ Branch 0 taken 851668 times.
✓ Branch 1 taken 38493 times.
✓ Branch 2 taken 295495 times.
✓ Branch 3 taken 556173 times.
890161 if (allow_no_qt && a->qt) {
1211 295495 split_qt_flag = split_qt_flag_decode(lc, x0, y0, ch_type, cqt_depth);
1212 } else {
1213
3/4
✓ Branch 0 taken 556173 times.
✓ Branch 1 taken 38493 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 556173 times.
594666 split_qt_flag = !allow_no_qt || a->qt;
1214 }
1215
2/2
✓ Branch 0 taken 114236 times.
✓ Branch 1 taken 775925 times.
890161 if (split_qt_flag)
1216 114236 return SPLIT_QT;
1217 775925 mtt_split_cu_vertical_flag = mtt_split_cu_vertical_flag_decode(lc, x0, y0, cb_width, cb_height, ch_type, a);
1218
6/6
✓ Branch 0 taken 649363 times.
✓ Branch 1 taken 126562 times.
✓ Branch 2 taken 457217 times.
✓ Branch 3 taken 192146 times.
✓ Branch 4 taken 203771 times.
✓ Branch 5 taken 253446 times.
775925 if ((a->btv && a->ttv && mtt_split_cu_vertical_flag) ||
1219
6/6
✓ Branch 0 taken 484161 times.
✓ Branch 1 taken 38318 times.
✓ Branch 2 taken 300877 times.
✓ Branch 3 taken 183284 times.
✓ Branch 4 taken 267242 times.
✓ Branch 5 taken 33635 times.
522479 (a->bth && a->tth && !mtt_split_cu_vertical_flag)) {
1220 520688 mtt_split_cu_binary_flag = mtt_split_cu_binary_flag_decode(lc, mtt_split_cu_vertical_flag, mtt_depth);
1221 } else {
1222
4/4
✓ Branch 0 taken 80460 times.
✓ Branch 1 taken 174777 times.
✓ Branch 2 taken 2341 times.
✓ Branch 3 taken 78119 times.
255237 if (!a->btv && !a->bth)
1223 2341 mtt_split_cu_binary_flag = 0;
1224
4/4
✓ Branch 0 taken 210328 times.
✓ Branch 1 taken 42568 times.
✓ Branch 2 taken 179000 times.
✓ Branch 3 taken 31328 times.
252896 else if (!a->ttv && !a->tth)
1225 179000 mtt_split_cu_binary_flag = 1;
1226
4/4
✓ Branch 0 taken 66361 times.
✓ Branch 1 taken 7535 times.
✓ Branch 2 taken 37026 times.
✓ Branch 3 taken 29335 times.
73896 else if (a->bth && a->ttv)
1227 37026 mtt_split_cu_binary_flag = 1 - mtt_split_cu_vertical_flag;
1228 else
1229 36870 mtt_split_cu_binary_flag = mtt_split_cu_vertical_flag;
1230 }
1231 775925 return mtt_split_modes[(mtt_split_cu_vertical_flag << 1) + mtt_split_cu_binary_flag];
1232 }
1233
1234 42486 int ff_vvc_non_inter_flag(VVCLocalContext *lc, const int x0, const int y0, const int ch_type)
1235 {
1236 42486 const VVCFrameContext *fc = lc->fc;
1237 42486 uint8_t inc, left = MODE_INTER, top = MODE_INTER;
1238
1239 42486 get_left_top(lc, &left, &top, x0, y0, fc->tab.cpm[ch_type], fc->tab.cpm[ch_type]);
1240
4/4
✓ Branch 0 taken 31276 times.
✓ Branch 1 taken 11210 times.
✓ Branch 2 taken 5716 times.
✓ Branch 3 taken 25560 times.
42486 inc = left == MODE_INTRA || top == MODE_INTRA;
1241 42486 return GET_CABAC(NON_INTER_FLAG + inc);
1242 }
1243
1244 211931 int ff_vvc_pred_mode_flag(VVCLocalContext *lc, const int is_chroma)
1245 {
1246 211931 const VVCFrameContext *fc = lc->fc;
1247 211931 const CodingUnit *cu = lc->cu;
1248 211931 uint8_t inc, left = MODE_INTER, top = MODE_INTER;
1249
1250 211931 get_left_top(lc, &left, &top, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]);
1251
4/4
✓ Branch 0 taken 167887 times.
✓ Branch 1 taken 44044 times.
✓ Branch 2 taken 18663 times.
✓ Branch 3 taken 149224 times.
211931 inc = left == MODE_INTRA || top == MODE_INTRA;
1252 211931 return GET_CABAC(PRED_MODE_FLAG + inc);
1253 }
1254
1255 33521 int ff_vvc_pred_mode_plt_flag(VVCLocalContext *lc)
1256 {
1257 33521 return GET_CABAC(PRED_MODE_PLT_FLAG);
1258 }
1259
1260 57938 int ff_vvc_intra_bdpcm_luma_flag(VVCLocalContext *lc)
1261 {
1262 57938 return GET_CABAC(INTRA_BDPCM_LUMA_FLAG);
1263 }
1264
1265 18949 int ff_vvc_intra_bdpcm_luma_dir_flag(VVCLocalContext *lc)
1266 {
1267 18949 return GET_CABAC(INTRA_BDPCM_LUMA_DIR_FLAG);
1268 }
1269
1270 50258 int ff_vvc_intra_bdpcm_chroma_flag(VVCLocalContext *lc)
1271 {
1272 50258 return GET_CABAC(INTRA_BDPCM_CHROMA_FLAG);
1273 }
1274
1275 258 int ff_vvc_intra_bdpcm_chroma_dir_flag(VVCLocalContext *lc)
1276 {
1277 258 return GET_CABAC(INTRA_BDPCM_CHROMA_DIR_FLAG);
1278 }
1279
1280 686199 int ff_vvc_cu_skip_flag(VVCLocalContext *lc, const uint8_t *cu_skip_flag)
1281 {
1282 686199 const int inc = get_inc(lc, cu_skip_flag);
1283 686199 return GET_CABAC(CU_SKIP_FLAG + inc);
1284 }
1285
1286 189023 int ff_vvc_pred_mode_ibc_flag(VVCLocalContext *lc, const int is_chroma)
1287 {
1288 189023 const VVCFrameContext *fc = lc->fc;
1289 189023 const CodingUnit *cu = lc->cu;
1290 189023 uint8_t left_mode = MODE_INTER, top_mode = MODE_INTER;
1291 int inc;
1292
1293 189023 get_left_top(lc, &left_mode, &top_mode, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]);
1294 189023 inc = (left_mode == MODE_IBC) + (top_mode == MODE_IBC);
1295 189023 return GET_CABAC(PRED_MODE_IBC_FLAG + inc);
1296 }
1297
1298 static av_always_inline
1299 374620 uint8_t get_mip_inc(VVCLocalContext *lc, const uint8_t *ctx)
1300 {
1301 374620 uint8_t left = 0, top = 0;
1302 374620 get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx);
1303 374620 return (left & 1) + (top & 1);
1304 }
1305
1306 474655 int ff_vvc_intra_mip_flag(VVCLocalContext *lc, const uint8_t *intra_mip_flag)
1307 {
1308 474655 const int w = lc->cu->cb_width;
1309 474655 const int h = lc->cu->cb_height;
1310
4/4
✓ Branch 0 taken 402353 times.
✓ Branch 1 taken 72302 times.
✓ Branch 2 taken 374620 times.
✓ Branch 3 taken 27733 times.
474655 const int inc = (w > h * 2 || h > w * 2) ? 3 : get_mip_inc(lc, intra_mip_flag);
1311 474655 return GET_CABAC(INTRA_MIP_FLAG + inc);
1312 }
1313
1314 111335 int ff_vvc_intra_mip_transposed_flag(VVCLocalContext *lc)
1315 {
1316 111335 return get_cabac_bypass(&lc->ep->cc);
1317 }
1318
1319 111335 int ff_vvc_intra_mip_mode(VVCLocalContext *lc)
1320 {
1321 111335 const int w = lc->cu->cb_width;
1322 111335 const int h = lc->cu->cb_height;
1323
4/4
✓ Branch 0 taken 32475 times.
✓ Branch 1 taken 78860 times.
✓ Branch 2 taken 16281 times.
✓ Branch 3 taken 16194 times.
206476 const int c_max = (w == 4 && h == 4) ? 15 :
1324
8/8
✓ Branch 0 taken 78860 times.
✓ Branch 1 taken 16281 times.
✓ Branch 2 taken 54719 times.
✓ Branch 3 taken 24141 times.
✓ Branch 4 taken 18293 times.
✓ Branch 5 taken 36426 times.
✓ Branch 6 taken 10861 times.
✓ Branch 7 taken 7432 times.
95141 ((w == 4 || h == 4) || (w == 8 && h == 8)) ? 7: 5;
1325 111335 return truncated_binary_decode(lc, c_max);
1326 }
1327
1328 445971 int ff_vvc_intra_luma_ref_idx(VVCLocalContext *lc)
1329 {
1330 int i;
1331
2/2
✓ Branch 0 taken 491103 times.
✓ Branch 1 taken 26705 times.
517808 for (i = 0; i < 2; i++) {
1332
2/2
✓ Branch 1 taken 419266 times.
✓ Branch 2 taken 71837 times.
491103 if (!GET_CABAC(INTRA_LUMA_REF_IDX + i))
1333 419266 return i;
1334 }
1335 26705 return i;
1336 }
1337
1338 371225 int ff_vvc_intra_subpartitions_mode_flag(VVCLocalContext *lc)
1339 {
1340 371225 return GET_CABAC(INTRA_SUBPARTITIONS_MODE_FLAG);
1341 }
1342
1343 506892 enum IspType ff_vvc_isp_split_type(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
1344 {
1345
2/2
✓ Branch 0 taken 441685 times.
✓ Branch 1 taken 65207 times.
506892 if (!intra_subpartitions_mode_flag)
1346 441685 return ISP_NO_SPLIT;
1347 65207 return 1 + GET_CABAC(INTRA_SUBPARTITIONS_SPLIT_FLAG);
1348 }
1349
1350 461760 int ff_vvc_intra_luma_mpm_flag(VVCLocalContext *lc)
1351 {
1352 461760 return GET_CABAC(INTRA_LUMA_MPM_FLAG);
1353 }
1354
1355 333414 int ff_vvc_intra_luma_not_planar_flag(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
1356 {
1357
2/2
✓ Branch 0 taken 283821 times.
✓ Branch 1 taken 49593 times.
333414 return GET_CABAC(INTRA_LUMA_NOT_PLANAR_FLAG + !intra_subpartitions_mode_flag);
1358 }
1359
1360 203369 int ff_vvc_intra_luma_mpm_idx(VVCLocalContext *lc)
1361 {
1362 int i;
1363
4/4
✓ Branch 0 taken 379631 times.
✓ Branch 1 taken 14577 times.
✓ Branch 3 taken 190839 times.
✓ Branch 4 taken 188792 times.
394208 for (i = 0; i < 4 && get_cabac_bypass(&lc->ep->cc); i++)
1364 /* nothing */;
1365 203369 return i;
1366 }
1367
1368 128346 int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc)
1369 {
1370 128346 return truncated_binary_decode(lc, 60);
1371 }
1372
1373 235203 int ff_vvc_cclm_mode_flag(VVCLocalContext *lc)
1374 {
1375 235203 return GET_CABAC(CCLM_MODE_FLAG);
1376 }
1377
1378 101430 int ff_vvc_cclm_mode_idx(VVCLocalContext *lc)
1379 {
1380
2/2
✓ Branch 1 taken 57136 times.
✓ Branch 2 taken 44294 times.
101430 if (!GET_CABAC(CCLM_MODE_IDX))
1381 57136 return 0;
1382 44294 return get_cabac_bypass(&lc->ep->cc) + 1;
1383 }
1384
1385 155205 int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc)
1386 {
1387
2/2
✓ Branch 1 taken 110752 times.
✓ Branch 2 taken 44453 times.
155205 if (!GET_CABAC(INTRA_CHROMA_PRED_MODE))
1388 110752 return 4;
1389 44453 return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1390 }
1391
1392 43246 int ff_vvc_palette_predictor_run(VVCLocalContext *lc, const int max)
1393 {
1394 43246 return kth_order_egk_decode(&lc->ep->cc, 0, max);
1395 }
1396
1397 6977 int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc, const int max)
1398 {
1399 6977 return kth_order_egk_decode(&lc->ep->cc, 0, max);
1400 }
1401
1402 4254 int ff_vvc_new_palette_entries(VVCLocalContext *lc, const int bit_depth)
1403 {
1404 4254 return fixed_length_decode(&lc->ep->cc, bit_depth);
1405 }
1406
1407 6977 bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc)
1408 {
1409 6977 return get_cabac_bypass(&lc->ep->cc);
1410 }
1411
1412 6462 bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc)
1413 {
1414 6462 return GET_CABAC(PALETTE_TRANSPOSE_FLAG);
1415 }
1416
1417 1000866 bool ff_vvc_run_copy_flag(VVCLocalContext *lc, const int prev_run_type, const int prev_run_position, const int cur_pos)
1418 {
1419 1000866 uint8_t run_left_lut[] = { 0, 1, 2, 3, 4 };
1420 1000866 uint8_t run_top_lut[] = { 5, 6, 6, 7, 7 };
1421
1422 1000866 int bin_dist = cur_pos - prev_run_position - 1;
1423
2/2
✓ Branch 0 taken 378928 times.
✓ Branch 1 taken 621938 times.
1000866 uint8_t *run_lut = prev_run_type == 1 ? run_top_lut : run_left_lut;
1424
2/2
✓ Branch 0 taken 330437 times.
✓ Branch 1 taken 670429 times.
1000866 uint8_t ctx_inc = bin_dist <= 4 ? run_lut[bin_dist] : run_lut[4];
1425
1426 1000866 return GET_CABAC(RUN_COPY_FLAG + ctx_inc);
1427 }
1428
1429 105524 bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc)
1430 {
1431 105524 return GET_CABAC(COPY_ABOVE_PALETTE_INDICES_FLAG);
1432 }
1433
1434 111753 int ff_vvc_palette_idx_idc(VVCLocalContext *lc, const int max_palette_index, const bool adjust)
1435 {
1436 111753 return truncated_binary_decode(lc, max_palette_index - adjust);
1437 }
1438
1439 149 int ff_vvc_palette_escape_val(VVCLocalContext *lc, const int max)
1440 {
1441 149 return kth_order_egk_decode(&lc->ep->cc, 5, max);
1442 }
1443
1444 264030 int ff_vvc_general_merge_flag(VVCLocalContext *lc)
1445 {
1446 264030 return GET_CABAC(GENERAL_MERGE_FLAG);
1447 }
1448
1449 340617 static int get_inter_flag_inc(VVCLocalContext *lc, const int x0, const int y0)
1450 {
1451 340617 uint8_t left_merge = 0, top_merge = 0;
1452 340617 uint8_t left_affine = 0, top_affine = 0;
1453 340617 const VVCFrameContext *fc = lc->fc;
1454
1455 340617 get_left_top(lc, &left_merge, &top_merge, x0, y0, fc->tab.msf, fc->tab.msf);
1456 340617 get_left_top(lc, &left_affine, &top_affine, x0, y0, fc->tab.iaf, fc->tab.iaf);
1457
4/4
✓ Branch 0 taken 296279 times.
✓ Branch 1 taken 44338 times.
✓ Branch 2 taken 10017 times.
✓ Branch 3 taken 286262 times.
340617 return (left_merge || left_affine) + (top_merge + top_affine);
1458 }
1459
1460 310328 int ff_vvc_merge_subblock_flag(VVCLocalContext *lc)
1461 {
1462 310328 const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0);
1463 310328 return GET_CABAC(MERGE_SUBBLOCK_FLAG + inc);
1464 }
1465
1466 54720 int ff_vvc_merge_subblock_idx(VVCLocalContext *lc, const int max_num_subblock_merge_cand)
1467 {
1468 int i;
1469
2/2
✓ Branch 1 taken 33823 times.
✓ Branch 2 taken 20897 times.
54720 if (!GET_CABAC(MERGE_SUBBLOCK_IDX))
1470 33823 return 0;
1471
4/4
✓ Branch 0 taken 34770 times.
✓ Branch 1 taken 2770 times.
✓ Branch 3 taken 16643 times.
✓ Branch 4 taken 18127 times.
37540 for (i = 1; i < max_num_subblock_merge_cand - 1 && get_cabac_bypass(&lc->ep->cc); i++)
1472 /* nothing */;
1473 20897 return i;
1474 }
1475
1476 236333 int ff_vvc_regular_merge_flag(VVCLocalContext *lc, const int cu_skip_flag)
1477 {
1478 236333 int inc = !cu_skip_flag;
1479 236333 return GET_CABAC(REGULAR_MERGE_FLAG + inc);
1480 }
1481
1482 276130 int ff_vvc_mmvd_merge_flag(VVCLocalContext *lc)
1483 {
1484 276130 return GET_CABAC(MMVD_MERGE_FLAG);
1485 }
1486
1487 58027 int ff_vvc_mmvd_cand_flag(VVCLocalContext *lc)
1488 {
1489 58027 return GET_CABAC(MMVD_CAND_FLAG);
1490 }
1491
1492 58027 static int mmvd_distance_idx_decode(VVCLocalContext *lc)
1493 {
1494 int i;
1495
2/2
✓ Branch 1 taken 15128 times.
✓ Branch 2 taken 42899 times.
58027 if (!GET_CABAC(MMVD_DISTANCE_IDX))
1496 15128 return 0;
1497
4/4
✓ Branch 0 taken 84225 times.
✓ Branch 1 taken 225 times.
✓ Branch 3 taken 41551 times.
✓ Branch 4 taken 42674 times.
84450 for (i = 1; i < 7 && get_cabac_bypass(&lc->ep->cc); i++)
1498 /* nothing */;
1499 42899 return i;
1500 }
1501
1502 58027 static int mmvd_direction_idx_decode(VVCLocalContext *lc)
1503 {
1504 58027 return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1505 }
1506
1507 58027 void ff_vvc_mmvd_offset_coding(VVCLocalContext *lc, Mv *mmvd_offset, const int ph_mmvd_fullpel_only_flag)
1508 {
1509
2/2
✓ Branch 0 taken 660 times.
✓ Branch 1 taken 57367 times.
58027 const int shift = ph_mmvd_fullpel_only_flag ? 4 : 2;
1510 58027 const int mmvd_distance = 1 << (mmvd_distance_idx_decode(lc) + shift);
1511 58027 const int mmvd_direction_idx = mmvd_direction_idx_decode(lc);
1512 58027 const int mmvd_signs[][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
1513 58027 mmvd_offset->x = mmvd_distance * mmvd_signs[mmvd_direction_idx][0];
1514 58027 mmvd_offset->y = mmvd_distance * mmvd_signs[mmvd_direction_idx][1];
1515 58027 }
1516
1517 272288 static PredMode get_luma_pred_mode(VVCLocalContext *lc)
1518 {
1519 272288 const VVCFrameContext *fc = lc->fc;
1520 272288 const CodingUnit *cu = lc->cu;
1521 PredMode pred_mode;
1522
1523
1/2
✓ Branch 0 taken 272288 times.
✗ Branch 1 not taken.
272288 if (cu->tree_type != DUAL_TREE_CHROMA) {
1524 272288 pred_mode = cu->pred_mode;
1525 } else {
1526 ✗ const int x_cb = cu->x0 >> fc->ps.sps->min_cb_log2_size_y;
1527 ✗ const int y_cb = cu->y0 >> fc->ps.sps->min_cb_log2_size_y;
1528 ✗ const int min_cb_width = fc->ps.pps->min_cb_width;
1529 ✗ pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_cb, y_cb);
1530 }
1531 272288 return pred_mode;
1532 }
1533
1534 272288 int ff_vvc_merge_idx(VVCLocalContext *lc)
1535 {
1536 272288 const VVCSPS *sps = lc->fc->ps.sps;
1537 272288 const int is_ibc = get_luma_pred_mode(lc) == MODE_IBC;
1538
2/2
✓ Branch 0 taken 30794 times.
✓ Branch 1 taken 241494 times.
272288 const int c_max = (is_ibc ? sps->max_num_ibc_merge_cand : sps->max_num_merge_cand) - 1;
1539 int i;
1540
1541
2/2
✓ Branch 1 taken 165913 times.
✓ Branch 2 taken 106375 times.
272288 if (!GET_CABAC(MERGE_IDX))
1542 165913 return 0;
1543
1544
4/4
✓ Branch 0 taken 202170 times.
✓ Branch 1 taken 11006 times.
✓ Branch 3 taken 106801 times.
✓ Branch 4 taken 95369 times.
213176 for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++)
1545 /* nothing */;
1546 106375 return i;
1547 }
1548
1549 27594 int ff_vvc_merge_gpm_partition_idx(VVCLocalContext *lc)
1550 {
1551 27594 return fixed_length_decode(&lc->ep->cc, 6);
1552 }
1553
1554 55188 int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx)
1555 {
1556 55188 const int c_max = lc->fc->ps.sps->max_num_gpm_merge_cand - idx - 1;
1557 int i;
1558
1559
2/2
✓ Branch 1 taken 30818 times.
✓ Branch 2 taken 24370 times.
55188 if (!GET_CABAC(MERGE_IDX))
1560 30818 return 0;
1561
1562
4/4
✓ Branch 0 taken 43274 times.
✓ Branch 1 taken 4114 times.
✓ Branch 3 taken 23018 times.
✓ Branch 4 taken 20256 times.
47388 for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++)
1563 /* nothing */;
1564
1565 24370 return i;
1566 }
1567
1568 20147 int ff_vvc_ciip_flag(VVCLocalContext *lc)
1569 {
1570 20147 return GET_CABAC(CIIP_FLAG);
1571 }
1572
1573 81046 PredFlag ff_vvc_pred_flag(VVCLocalContext *lc, const int is_b)
1574 {
1575 81046 const int w = lc->cu->cb_width;
1576 81046 const int h = lc->cu->cb_height;
1577
2/2
✓ Branch 0 taken 7380 times.
✓ Branch 1 taken 73666 times.
81046 if (!is_b)
1578 7380 return PF_L0;
1579
2/2
✓ Branch 0 taken 64418 times.
✓ Branch 1 taken 9248 times.
73666 if (w + h > 12) {
1580 64418 const int log2 = av_log2(w) + av_log2(h);
1581 64418 const int inc = 7 - ((1 + log2)>>1);
1582
2/2
✓ Branch 1 taken 21784 times.
✓ Branch 2 taken 42634 times.
64418 if (GET_CABAC(INTER_PRED_IDC + inc))
1583 21784 return PF_BI;
1584 }
1585 51882 return PF_L0 + GET_CABAC(INTER_PRED_IDC + 5);
1586 }
1587
1588 30289 int ff_vvc_inter_affine_flag(VVCLocalContext *lc)
1589 {
1590 30289 const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0);
1591 30289 return GET_CABAC(INTER_AFFINE_FLAG + inc);
1592 }
1593
1594 9334 int ff_vvc_cu_affine_type_flag(VVCLocalContext *lc)
1595 {
1596 9334 return GET_CABAC(CU_AFFINE_TYPE_FLAG);
1597 }
1598
1599 12921 int ff_vvc_sym_mvd_flag(VVCLocalContext *lc)
1600 {
1601 12921 return GET_CABAC(SYM_MVD_FLAG);
1602 }
1603
1604 71767 int ff_vvc_ref_idx_lx(VVCLocalContext *lc, const uint8_t nb_refs)
1605 {
1606 71767 const int c_max = nb_refs - 1;
1607 71767 const int max_ctx = FFMIN(c_max, 2);
1608 71767 int i = 0;
1609
1610
4/4
✓ Branch 0 taken 88542 times.
✓ Branch 1 taken 27339 times.
✓ Branch 3 taken 44114 times.
✓ Branch 4 taken 44428 times.
115881 while (i < max_ctx && GET_CABAC(REF_IDX_LX + i))
1611 44114 i++;
1612
2/2
✓ Branch 0 taken 14956 times.
✓ Branch 1 taken 56811 times.
71767 if (i == 2) {
1613
4/4
✓ Branch 0 taken 45136 times.
✓ Branch 1 taken 10535 times.
✓ Branch 3 taken 40715 times.
✓ Branch 4 taken 4421 times.
55671 while (i < c_max && get_cabac_bypass(&lc->ep->cc))
1614 40715 i++;
1615 }
1616 71767 return i;
1617 }
1618
1619 328270 int ff_vvc_abs_mvd_greater0_flag(VVCLocalContext *lc)
1620 {
1621 328270 return GET_CABAC(ABS_MVD_GREATER0_FLAG);
1622 }
1623
1624 204652 int ff_vvc_abs_mvd_greater1_flag(VVCLocalContext *lc)
1625 {
1626 204652 return GET_CABAC(ABS_MVD_GREATER1_FLAG);
1627 }
1628
1629 146131 int ff_vvc_abs_mvd_minus2(VVCLocalContext *lc)
1630 {
1631 146131 return limited_kth_order_egk_decode(&lc->ep->cc, 1, 15, 17);
1632 }
1633
1634 204652 int ff_vvc_mvd_sign_flag(VVCLocalContext *lc)
1635 {
1636 204652 return get_cabac_bypass(&lc->ep->cc);
1637 }
1638
1639 157628 int ff_vvc_mvp_lx_flag(VVCLocalContext *lc)
1640 {
1641 157628 return GET_CABAC(MVP_LX_FLAG);
1642 }
1643
1644 74308 static int amvr_flag(VVCLocalContext *lc, const int inter_affine_flag)
1645 {
1646 74308 return GET_CABAC(AMVR_FLAG + inter_affine_flag);
1647 }
1648
1649 85028 static int amvr_precision_idx(VVCLocalContext *lc, const int inc, const int c_max)
1650 {
1651 85028 int i = 0;
1652
2/2
✓ Branch 1 taken 28225 times.
✓ Branch 2 taken 56803 times.
85028 if (!GET_CABAC(AMVR_PRECISION_IDX + inc))
1653 28225 return 0;
1654 56803 i++;
1655
4/4
✓ Branch 0 taken 36735 times.
✓ Branch 1 taken 20068 times.
✓ Branch 3 taken 13063 times.
✓ Branch 4 taken 23672 times.
56803 if (i < c_max && GET_CABAC(AMVR_PRECISION_IDX + 1))
1656 13063 i++;
1657 56803 return i;
1658 }
1659
1660 114691 int ff_vvc_amvr_shift(VVCLocalContext *lc, const int inter_affine_flag,
1661 const PredMode pred_mode, const int has_amvr_flag)
1662 {
1663 114691 int amvr_shift = 2;
1664
2/2
✓ Branch 0 taken 107953 times.
✓ Branch 1 taken 6738 times.
114691 if (has_amvr_flag) {
1665
4/4
✓ Branch 0 taken 74308 times.
✓ Branch 1 taken 33645 times.
✓ Branch 3 taken 51383 times.
✓ Branch 4 taken 22925 times.
107953 if (pred_mode == MODE_IBC || amvr_flag(lc, inter_affine_flag)) {
1666 int idx;
1667
2/2
✓ Branch 0 taken 4569 times.
✓ Branch 1 taken 80459 times.
85028 if (inter_affine_flag) {
1668 4569 idx = amvr_precision_idx(lc, 2, 1);
1669 4569 amvr_shift = idx * 4;
1670
2/2
✓ Branch 0 taken 33645 times.
✓ Branch 1 taken 46814 times.
80459 } else if (pred_mode == MODE_IBC) {
1671 33645 idx = amvr_precision_idx(lc, 1, 1);
1672 33645 amvr_shift = 4 + idx * 2;
1673 } else {
1674 static const int shifts[] = {3, 4, 6};
1675 46814 idx = amvr_precision_idx(lc, 0, 2);
1676 46814 amvr_shift = shifts[idx];
1677 }
1678 }
1679 }
1680 114691 return amvr_shift;
1681 }
1682
1683 12147 int ff_vvc_bcw_idx(VVCLocalContext *lc, const int no_backward_pred_flag)
1684 {
1685
2/2
✓ Branch 0 taken 2598 times.
✓ Branch 1 taken 9549 times.
12147 const int c_max = no_backward_pred_flag ? 4 : 2;
1686 12147 int i = 1;
1687
2/2
✓ Branch 1 taken 7118 times.
✓ Branch 2 taken 5029 times.
12147 if (!GET_CABAC(BCW_IDX))
1688 7118 return 0;
1689
4/4
✓ Branch 0 taken 5911 times.
✓ Branch 1 taken 1982 times.
✓ Branch 3 taken 2864 times.
✓ Branch 4 taken 3047 times.
7893 while (i < c_max && get_cabac_bypass(&lc->ep->cc))
1690 2864 i++;
1691 5029 return i;
1692 }
1693
1694 444631 int ff_vvc_tu_cb_coded_flag(VVCLocalContext *lc)
1695 {
1696 444631 return GET_CABAC(TU_CB_CODED_FLAG + lc->cu->bdpcm_flag[1]);
1697 }
1698
1699 444631 int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag)
1700 {
1701
2/2
✓ Branch 0 taken 444373 times.
✓ Branch 1 taken 258 times.
444631 return GET_CABAC(TU_CR_CODED_FLAG + (lc->cu->bdpcm_flag[1] ? 2 : tu_cb_coded_flag));
1702 }
1703
1704 842046 int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc)
1705 {
1706 842046 const CodingUnit *cu = lc->cu;
1707 int inc;
1708
2/2
✓ Branch 0 taken 18582 times.
✓ Branch 1 taken 823464 times.
842046 if (cu->bdpcm_flag[0])
1709 18582 inc = 1;
1710
2/2
✓ Branch 0 taken 623569 times.
✓ Branch 1 taken 199895 times.
823464 else if (cu->isp_split_type == ISP_NO_SPLIT)
1711 623569 inc = 0;
1712 else
1713 199895 inc = 2 + lc->parse.prev_tu_cbf_y;
1714 842046 lc->parse.prev_tu_cbf_y = GET_CABAC(TU_Y_CODED_FLAG + inc);
1715 842046 return lc->parse.prev_tu_cbf_y;
1716 }
1717
1718 15652 int ff_vvc_cu_act_enabled_flag(VVCLocalContext *lc)
1719 {
1720 15652 return GET_CABAC(CU_ACT_ENABLED_FLAG);
1721 }
1722
1723 3618 int ff_vvc_cu_qp_delta_abs(VVCLocalContext *lc)
1724 {
1725 int v, i, k;
1726
2/2
✓ Branch 1 taken 2293 times.
✓ Branch 2 taken 1325 times.
3618 if (!GET_CABAC(CU_QP_DELTA_ABS))
1727 2293 return 0;
1728
1729 // prefixVal
1730
4/4
✓ Branch 0 taken 2601 times.
✓ Branch 1 taken 35 times.
✓ Branch 3 taken 1311 times.
✓ Branch 4 taken 1290 times.
2636 for (v = 1; v < 5 && GET_CABAC(CU_QP_DELTA_ABS + 1); v++)
1731 /* nothing */;
1732
2/2
✓ Branch 0 taken 1290 times.
✓ Branch 1 taken 35 times.
1325 if (v < 5)
1733 1290 return v;
1734
1735 // 9.3.3.5 k-th order Exp-Golomb binarization process
1736 // suffixVal
1737
1738 // CuQpDeltaVal shall in the range of −( 32 + QpBdOffset / 2 ) to +( 31 + QpBdOffset / 2 )
1739 // so k = 6 should enough
1740
3/4
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 31 times.
✓ Branch 4 taken 35 times.
66 for (k = 0; k < 6 && get_cabac_bypass(&lc->ep->cc); k++)
1741 /* nothing */;
1742 35 i = (1 << k) - 1;
1743 35 v = 0;
1744
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 35 times.
66 while (k--)
1745 31 v = (v << 1) + get_cabac_bypass(&lc->ep->cc);
1746 35 v += i;
1747
1748 35 return v + 5;
1749 }
1750
1751 1325 int ff_vvc_cu_qp_delta_sign_flag(VVCLocalContext *lc)
1752 {
1753 1325 return get_cabac_bypass(&lc->ep->cc);
1754 }
1755
1756 1029 int ff_vvc_cu_chroma_qp_offset_flag(VVCLocalContext *lc)
1757 {
1758 1029 return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG);
1759 }
1760
1761 931 int ff_vvc_cu_chroma_qp_offset_idx(VVCLocalContext *lc)
1762 {
1763 931 const int c_max = lc->fc->ps.pps->r->pps_chroma_qp_offset_list_len_minus1;
1764 int i;
1765
4/4
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 532 times.
✓ Branch 3 taken 1677 times.
✓ Branch 4 taken 399 times.
2608 for (i = 0; i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX); i++)
1766 /* nothing */;
1767 931 return i;
1768 }
1769
1770 1936376 static av_always_inline int last_significant_coeff_xy_prefix(VVCLocalContext *lc,
1771 const int log2_tb_size, const int log2_zo_tb_size, const int c_idx, const int ctx)
1772 {
1773 1936376 int i = 0;
1774 1936376 int max = (log2_zo_tb_size << 1) - 1;
1775 int ctx_offset, ctx_shift;
1776
2/2
✓ Branch 0 taken 16594 times.
✓ Branch 1 taken 1919782 times.
1936376 if (!log2_tb_size)
1777 16594 return 0;
1778
2/2
✓ Branch 0 taken 1376466 times.
✓ Branch 1 taken 543316 times.
1919782 if (!c_idx) {
1779 1376466 const int offset_y[] = {0, 0, 3, 6, 10, 15};
1780 1376466 ctx_offset = offset_y[log2_tb_size - 1];
1781 1376466 ctx_shift = (log2_tb_size + 1) >> 2;
1782 } else {
1783 543316 const int shifts[] = {0, 0, 0, 1, 2, 2, 2};
1784 543316 ctx_offset = 20;
1785 543316 ctx_shift = shifts[log2_tb_size];
1786 }
1787
4/4
✓ Branch 0 taken 5052012 times.
✓ Branch 1 taken 309800 times.
✓ Branch 3 taken 3442030 times.
✓ Branch 4 taken 1609982 times.
5361812 while (i < max && GET_CABAC(ctx + (i >> ctx_shift) + ctx_offset))
1788 3442030 i++;
1789 1919782 return i;
1790 }
1791
1792 968188 static av_always_inline int last_significant_coeff_x_prefix_decode(VVCLocalContext *lc,
1793 const int log2_tb_width, const int log2_zo_tb_width, const int c_idx)
1794 {
1795 968188 return last_significant_coeff_xy_prefix(lc, log2_tb_width, log2_zo_tb_width, c_idx, LAST_SIG_COEFF_X_PREFIX);
1796 }
1797
1798 968188 static av_always_inline int last_significant_coeff_y_prefix_decode(VVCLocalContext *lc,
1799 const int log2_tb_height, const int log2_zo_tb_height, const int c_idx)
1800 {
1801 968188 return last_significant_coeff_xy_prefix(lc, log2_tb_height, log2_zo_tb_height, c_idx, LAST_SIG_COEFF_Y_PREFIX);
1802 }
1803
1804 370430 static av_always_inline int last_sig_coeff_suffix_decode(VVCLocalContext *lc,
1805 const int last_significant_coeff_y_prefix)
1806 {
1807 370430 const int length = (last_significant_coeff_y_prefix >> 1) - 1;
1808 370430 int value = get_cabac_bypass(&lc->ep->cc);
1809
1810
2/2
✓ Branch 0 taken 155188 times.
✓ Branch 1 taken 370430 times.
525618 for (int i = 1; i < length; i++)
1811 155188 value = (value << 1) | get_cabac_bypass(&lc->ep->cc);
1812 370430 return value;
1813 }
1814
1815 161245 int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, const int tu_cb_coded_flag, const int tu_cr_coded_flag)
1816 {
1817 161245 return GET_CABAC(TU_JOINT_CBCR_RESIDUAL_FLAG + 2 * tu_cb_coded_flag + tu_cr_coded_flag - 1);
1818 }
1819
1820 696962 int ff_vvc_transform_skip_flag(VVCLocalContext *lc, const int inc)
1821 {
1822 696962 return GET_CABAC(TRANSFORM_SKIP_FLAG + inc);
1823 }
1824
1825 //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1
1826 40222377 static int get_local_sum(const int *level, const int w, const int h,
1827 const int xc, const int yc, const int hist_value)
1828 {
1829 40222377 int loc_sum = 3 * hist_value;
1830 40222377 level += w * yc + xc;
1831
2/2
✓ Branch 0 taken 38742374 times.
✓ Branch 1 taken 1480003 times.
40222377 if (xc < w - 1) {
1832 38742374 loc_sum += level[1];
1833
2/2
✓ Branch 0 taken 36549399 times.
✓ Branch 1 taken 2192975 times.
38742374 if (xc < w - 2)
1834 36549399 loc_sum += level[2] - hist_value;
1835
2/2
✓ Branch 0 taken 35820725 times.
✓ Branch 1 taken 2921649 times.
38742374 if (yc < h - 1)
1836 35820725 loc_sum += level[w + 1] - hist_value;
1837 }
1838
2/2
✓ Branch 0 taken 37299612 times.
✓ Branch 1 taken 2922765 times.
40222377 if (yc < h - 1) {
1839 37299612 loc_sum += level[w];
1840
2/2
✓ Branch 0 taken 33835517 times.
✓ Branch 1 taken 3464095 times.
37299612 if (yc < h - 2)
1841 33835517 loc_sum += level[w << 1] - hist_value;
1842 }
1843 40222377 return loc_sum;
1844 }
1845
1846 //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1
1847 1637127 static int get_local_sum_ts(const int *level, const int w, const int h, const int xc, const int yc)
1848 {
1849 1637127 int loc_sum = 0;
1850 1637127 level += w * yc + xc;
1851
2/2
✓ Branch 0 taken 1417109 times.
✓ Branch 1 taken 220018 times.
1637127 if (xc > 0)
1852 1417109 loc_sum += level[-1];
1853
2/2
✓ Branch 0 taken 1425096 times.
✓ Branch 1 taken 212031 times.
1637127 if (yc > 0)
1854 1425096 loc_sum += level[-w];
1855 1637127 return loc_sum;
1856 }
1857
1858 11245407 static int get_gtx_flag_inc(const ResidualCoding* rc, const int xc, const int yc, const int last)
1859 {
1860 11245407 const TransformBlock *tb = rc->tb;
1861 int inc;
1862
2/2
✓ Branch 0 taken 968188 times.
✓ Branch 1 taken 10277219 times.
11245407 if (last) {
1863 968188 const int incs[] = {0, 21, 21};
1864 968188 inc = incs[tb->c_idx];
1865 } else {
1866 10277219 const int d = xc + yc;
1867 10277219 const int local_sum_sig = get_local_sum(rc->sig_coeff_flag,
1868 10277219 tb->tb_width,tb->tb_height, xc, yc, rc->hist_value);
1869 10277219 const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1,
1870 10277219 tb->tb_width, tb->tb_height, xc, yc, rc->hist_value);
1871 10277219 const int offset = FFMIN(loc_sum_abs_pass1 - local_sum_sig, 4);
1872
1873
2/2
✓ Branch 0 taken 7379186 times.
✓ Branch 1 taken 2898033 times.
10277219 if (!tb->c_idx)
1874
6/6
✓ Branch 0 taken 6903148 times.
✓ Branch 1 taken 476038 times.
✓ Branch 2 taken 5415113 times.
✓ Branch 3 taken 1488035 times.
✓ Branch 4 taken 3332108 times.
✓ Branch 5 taken 2083005 times.
7379186 inc = 1 + offset + (!d ? 15 : (d < 3 ? 10 : (d < 10 ? 5 : 0)));
1875 else
1876
2/2
✓ Branch 0 taken 161511 times.
✓ Branch 1 taken 2736522 times.
2898033 inc = 22 + offset + (!d ? 5 : 0);
1877 }
1878 11245407 return inc;
1879 }
1880
1881 13604433 static int abs_level_gtx_flag_decode(VVCLocalContext *lc, const int inc)
1882 {
1883 13604433 return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
1884 }
1885
1886 2359026 static int par_level_flag_decode(VVCLocalContext *lc, const int inc)
1887 {
1888 2359026 return GET_CABAC(PAR_LEVEL_FLAG + inc);
1889 }
1890
1891 166154 static int par_level_flag_ts_decode(VVCLocalContext *lc)
1892 {
1893 166154 const int inc = 32;
1894 166154 return GET_CABAC(PAR_LEVEL_FLAG + inc);
1895 }
1896
1897 1200193 static int sb_coded_flag_decode(VVCLocalContext *lc, const uint8_t *sb_coded_flag,
1898 const ResidualCoding *rc, const int xs, const int ys)
1899 {
1900 1200193 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1901 1200193 const TransformBlock *tb = rc->tb;
1902 1200193 const int w = rc->width_in_sbs;
1903 1200193 const int h = rc->height_in_sbs;
1904 int inc;
1905
1906
3/4
✓ Branch 0 taken 248363 times.
✓ Branch 1 taken 951830 times.
✓ Branch 2 taken 248363 times.
✗ Branch 3 not taken.
1200193 if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) {
1907
2/2
✓ Branch 0 taken 142072 times.
✓ Branch 1 taken 106291 times.
248363 const int left = xs > 0 ? sb_coded_flag[-1] : 0;
1908
2/2
✓ Branch 0 taken 147056 times.
✓ Branch 1 taken 101307 times.
248363 const int above = ys > 0 ? sb_coded_flag[-w] : 0;
1909 248363 inc = left + above + 4;
1910 } else {
1911
2/2
✓ Branch 0 taken 828187 times.
✓ Branch 1 taken 123643 times.
951830 const int right = (xs < w - 1) ? sb_coded_flag[1] : 0;
1912
2/2
✓ Branch 0 taken 727324 times.
✓ Branch 1 taken 224506 times.
951830 const int bottom = (ys < h - 1) ? sb_coded_flag[w] : 0;
1913
2/2
✓ Branch 0 taken 339845 times.
✓ Branch 1 taken 611985 times.
951830 inc = (right | bottom) + (tb->c_idx ? 2 : 0);
1914 }
1915 1200193 return GET_CABAC(SB_CODED_FLAG + inc);
1916 }
1917
1918 20288766 static int sig_coeff_flag_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1919 {
1920 20288766 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1921 20288766 const TransformBlock *tb = rc->tb;
1922 int inc;
1923
1924
3/4
✓ Branch 0 taken 1637127 times.
✓ Branch 1 taken 18651639 times.
✓ Branch 2 taken 1637127 times.
✗ Branch 3 not taken.
20288766 if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) {
1925 1637127 const int local_num_sig = get_local_sum_ts(rc->sig_coeff_flag, tb->tb_width, tb->tb_height, xc, yc);
1926 1637127 inc = 60 + local_num_sig;
1927 } else {
1928 18651639 const int d = xc + yc;
1929 18651639 const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1,
1930 18651639 tb->tb_width, tb->tb_height, xc, yc, 0);
1931
1932
2/2
✓ Branch 0 taken 13085234 times.
✓ Branch 1 taken 5566405 times.
18651639 if (!tb->c_idx) {
1933
4/4
✓ Branch 0 taken 11600450 times.
✓ Branch 1 taken 1484784 times.
✓ Branch 2 taken 3358631 times.
✓ Branch 3 taken 8241819 times.
13085234 inc = 12 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + ((d < 2) ? 8 : (d < 5 ? 4 : 0));
1934 } else {
1935
2/2
✓ Branch 0 taken 532885 times.
✓ Branch 1 taken 5033520 times.
5566405 inc = 36 + 8 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + (d < 2 ? 4 : 0);
1936 }
1937 }
1938 20288766 return GET_CABAC(SIG_COEFF_FLAG + inc);
1939 }
1940
1941 1016300 static int abs_get_rice_param(VVCLocalContext *lc, const ResidualCoding* rc,
1942 const int xc, const int yc, const int base_level)
1943 {
1944 1016300 const VVCSPS *sps = lc->fc->ps.sps;
1945 1016300 const TransformBlock* tb = rc->tb;
1946 1016300 const int rice_params[] = {
1947 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2,
1948 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
1949 };
1950 int loc_sum_abs;
1951 int shift_val;
1952
1953 1016300 loc_sum_abs = get_local_sum(rc->abs_level, tb->tb_width, tb->tb_height, xc,
1954 1016300 yc, rc->hist_value);
1955
1956
1/2
✓ Branch 0 taken 1016300 times.
✗ Branch 1 not taken.
1016300 if (!sps->r->sps_rrc_rice_extension_flag) {
1957 1016300 shift_val = 0;
1958 } else {
1959 ✗ shift_val = (av_log2(FFMAX(FFMIN(loc_sum_abs, 2048), 8)) - 3) & ~1;
1960 }
1961
1962 1016300 loc_sum_abs = av_clip_uintp2((loc_sum_abs >> shift_val) - base_level * 5, 5);
1963
1964 1016300 return rice_params[loc_sum_abs] + shift_val;
1965 }
1966
1967 1084698 static int abs_decode(VVCLocalContext *lc, const int c_rice_param)
1968 {
1969 1084698 const VVCSPS *sps = lc->fc->ps.sps;
1970 1084698 const int MAX_BIN = 6;
1971 1084698 int prefix = 0;
1972 1084698 int suffix = 0;
1973
1974
4/4
✓ Branch 0 taken 2476357 times.
✓ Branch 1 taken 83984 times.
✓ Branch 3 taken 1475643 times.
✓ Branch 4 taken 1000714 times.
2560341 while (prefix < MAX_BIN && get_cabac_bypass(&lc->ep->cc))
1975 1475643 prefix++;
1976
2/2
✓ Branch 0 taken 1000714 times.
✓ Branch 1 taken 83984 times.
1084698 if (prefix < MAX_BIN) {
1977
2/2
✓ Branch 0 taken 696247 times.
✓ Branch 1 taken 1000714 times.
1696961 for (int i = 0; i < c_rice_param; i++) {
1978 696247 suffix = (suffix << 1) | get_cabac_bypass(&lc->ep->cc);
1979 }
1980 } else {
1981 83984 suffix = limited_kth_order_egk_decode(&lc->ep->cc,
1982 c_rice_param + 1,
1983 83984 26 - sps->log2_transform_range,
1984 83984 sps->log2_transform_range);
1985 }
1986 1084698 return suffix + (prefix << c_rice_param);
1987 }
1988
1989 633634 static int abs_remainder_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1990 {
1991 633634 const VVCSPS *sps = lc->fc->ps.sps;
1992 633634 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1993 633634 const int base_level[][2][2] = {
1994 { {4, 4}, {4, 4} },
1995 { {3, 2}, {2, 1} }
1996 };
1997 633634 const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc,
1998 633634 base_level[sps->r->sps_rrc_rice_extension_flag][sps->bit_depth > 12][IS_I(rsh)]);
1999 633634 const int rem = abs_decode(lc, c_rice_param);
2000
2001 633634 return rem;
2002 }
2003
2004 68398 static int abs_remainder_ts_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
2005 {
2006 68398 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2007 68398 const int c_rice_param = rsh->sh_ts_residual_coding_rice_idx_minus1 + 1;
2008 68398 const int rem = abs_decode(lc, c_rice_param);
2009
2010 68398 return rem;
2011 }
2012
2013 11566656 static int coeff_sign_flag_decode(VVCLocalContext *lc)
2014 {
2015 11566656 return get_cabac_bypass(&lc->ep->cc);
2016 }
2017
2018 //9.3.4.2.10 Derivation process of ctxInc for the syntax element coeff_sign_flag for transform skip mode
2019 372847 static int coeff_sign_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
2020 {
2021 372847 const TransformBlock *tb = rc->tb;
2022 372847 const int w = tb->tb_width;
2023 372847 const int *level = rc->coeff_sign_level + yc * w + xc;
2024
2/2
✓ Branch 0 taken 326042 times.
✓ Branch 1 taken 46805 times.
372847 const int left_sign = xc ? level[-1] : 0;
2025
2/2
✓ Branch 0 taken 330975 times.
✓ Branch 1 taken 41872 times.
372847 const int above_sign = yc ? level[-w] : 0;
2026 372847 const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx];
2027 int inc;
2028
2029
2/2
✓ Branch 0 taken 142276 times.
✓ Branch 1 taken 230571 times.
372847 if (left_sign == -above_sign)
2030
2/2
✓ Branch 0 taken 7236 times.
✓ Branch 1 taken 135040 times.
142276 inc = bdpcm_flag ? 3 : 0;
2031
4/4
✓ Branch 0 taken 138600 times.
✓ Branch 1 taken 91971 times.
✓ Branch 2 taken 86099 times.
✓ Branch 3 taken 52501 times.
230571 else if (left_sign >= 0 && above_sign >= 0)
2032
2/2
✓ Branch 0 taken 1968 times.
✓ Branch 1 taken 84131 times.
86099 inc = bdpcm_flag ? 4 : 1;
2033 else
2034
2/2
✓ Branch 0 taken 3970 times.
✓ Branch 1 taken 140502 times.
144472 inc = bdpcm_flag ? 5 : 2;
2035 372847 return GET_CABAC(COEFF_SIGN_FLAG + inc);
2036 }
2037
2038 372847 static int abs_level_gt1_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
2039 {
2040 372847 const TransformBlock *tb = rc->tb;
2041 372847 const int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc;
2042 int inc;
2043
2044
2/2
✓ Branch 0 taken 13174 times.
✓ Branch 1 taken 359673 times.
372847 if (cu->bdpcm_flag[tb->c_idx]) {
2045 13174 inc = 67;
2046 } else {
2047
2/2
✓ Branch 0 taken 314433 times.
✓ Branch 1 taken 45240 times.
359673 const int l = xc > 0 ? sig_coeff_flag[-1] : 0;
2048
2/2
✓ Branch 0 taken 319550 times.
✓ Branch 1 taken 40123 times.
359673 const int a = yc > 0 ? sig_coeff_flag[-tb->tb_width] : 0;
2049 359673 inc = 64 + a + l;
2050 }
2051 372847 return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
2052 }
2053
2054 278569 static int abs_level_gtx_flag_ts_decode(VVCLocalContext *lc, const int j)
2055 {
2056 278569 const int inc = 67 + j;
2057 278569 return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
2058 }
2059
2060 static const uint8_t qstate_translate_table[][2] = {
2061 { 0, 2 }, { 2, 0 }, { 1, 3 }, { 3, 1 }
2062 };
2063
2064 382666 static int dec_abs_level_decode(VVCLocalContext *lc, const ResidualCoding *rc,
2065 const int xc, const int yc, int *abs_level)
2066 {
2067 382666 const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc, 0);
2068 382666 const int dec_abs_level = abs_decode(lc, c_rice_param);
2069
2/2
✓ Branch 0 taken 237540 times.
✓ Branch 1 taken 145126 times.
382666 const int zero_pos = (rc->qstate < 2 ? 1 : 2) << c_rice_param;
2070
2071 382666 *abs_level = 0;
2072
2/2
✓ Branch 0 taken 346663 times.
✓ Branch 1 taken 36003 times.
382666 if (dec_abs_level != zero_pos) {
2073 346663 *abs_level = dec_abs_level;
2074
2/2
✓ Branch 0 taken 206122 times.
✓ Branch 1 taken 140541 times.
346663 if (dec_abs_level < zero_pos)
2075 206122 *abs_level += 1;
2076 }
2077 382666 return dec_abs_level;
2078 }
2079
2080 1016300 static void ep_update_hist(EntryPoint *ep, ResidualCoding *rc,
2081 const int remainder, const int addin)
2082 {
2083 1016300 int *stat = ep->stat_coeff + rc->tb->c_idx;
2084
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1016300 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1016300 if (rc->update_hist && remainder > 0) {
2085 ✗ *stat = (*stat + av_log2(remainder) + addin) >> 1;
2086 ✗ rc->update_hist = 0;
2087 }
2088 1016300 }
2089
2090 1024755 static void init_residual_coding(const VVCLocalContext *lc, ResidualCoding *rc,
2091 const int log2_zo_tb_width, const int log2_zo_tb_height,
2092 TransformBlock *tb)
2093 {
2094 1024755 const VVCSPS *sps = lc->fc->ps.sps;
2095
2/2
✓ Branch 0 taken 102794 times.
✓ Branch 1 taken 921961 times.
1024755 int log2_sb_w = (FFMIN(log2_zo_tb_width, log2_zo_tb_height ) < 2 ? 1 : 2 );
2096 1024755 int log2_sb_h = log2_sb_w;
2097
2098
2/2
✓ Branch 0 taken 1015729 times.
✓ Branch 1 taken 9026 times.
1024755 if ( log2_zo_tb_width + log2_zo_tb_height > 3 ) {
2099
2/2
✓ Branch 0 taken 21473 times.
✓ Branch 1 taken 994256 times.
1015729 if ( log2_zo_tb_width < 2 ) {
2100 21473 log2_sb_w = log2_zo_tb_width;
2101 21473 log2_sb_h = 4 - log2_sb_w;
2102
2/2
✓ Branch 0 taken 72295 times.
✓ Branch 1 taken 921961 times.
994256 } else if ( log2_zo_tb_height < 2 ) {
2103 72295 log2_sb_h = log2_zo_tb_height;
2104 72295 log2_sb_w = 4 - log2_sb_h;
2105 }
2106 }
2107 1024755 rc->log2_sb_w = log2_sb_w;
2108 1024755 rc->log2_sb_h = log2_sb_h;
2109 1024755 rc->num_sb_coeff = 1 << (log2_sb_w + log2_sb_h);
2110 1024755 rc->last_sub_block = ( 1 << ( log2_zo_tb_width + log2_zo_tb_height - (log2_sb_w + log2_sb_h))) - 1;
2111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024755 times.
1024755 rc->hist_value = sps->r->sps_persistent_rice_adaptation_enabled_flag ? (1 << lc->ep->stat_coeff[tb->c_idx]) : 0;
2112 1024755 rc->update_hist = sps->r->sps_persistent_rice_adaptation_enabled_flag ? 1 : 0;
2113 1024755 rc->rem_bins_pass1 = (( 1 << ( log2_zo_tb_width + log2_zo_tb_height)) * 7 ) >> 2;
2114
2115
2116 1024755 rc->sb_scan_x_off = ff_vvc_diag_scan_x[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h];
2117 1024755 rc->sb_scan_y_off = ff_vvc_diag_scan_y[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h];
2118
2119 1024755 rc->scan_x_off = ff_vvc_diag_scan_x[log2_sb_w][log2_sb_h];
2120 1024755 rc->scan_y_off = ff_vvc_diag_scan_y[log2_sb_w][log2_sb_h];
2121
2122 1024755 rc->infer_sb_cbf = 1;
2123
2124 1024755 rc->width_in_sbs = (1 << (log2_zo_tb_width - log2_sb_w));
2125 1024755 rc->height_in_sbs = (1 << (log2_zo_tb_height - log2_sb_h));
2126 1024755 rc->nb_sbs = rc->width_in_sbs * rc->height_in_sbs;
2127
2128 1024755 rc->last_scan_pos = rc->num_sb_coeff;
2129 1024755 rc->qstate = 0;
2130
2131 1024755 rc->tb = tb;
2132 1024755 }
2133
2134 272258 static int residual_ts_coding_subblock(VVCLocalContext *lc, ResidualCoding* rc, const int i)
2135 {
2136 272258 const CodingUnit *cu = lc->cu;
2137 272258 TransformBlock *tb = rc->tb;
2138 272258 const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx];
2139 272258 const int xs = rc->sb_scan_x_off[i];
2140 272258 const int ys = rc->sb_scan_y_off[i];
2141 272258 uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
2142 272258 int infer_sb_sig_coeff_flag = 1;
2143 272258 int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -1, n;
2144 int abs_level_gtx_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];
2145 int abs_level_pass2[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; ///< AbsLevelPass2
2146
2147
4/4
✓ Branch 0 taken 56567 times.
✓ Branch 1 taken 215691 times.
✓ Branch 2 taken 32672 times.
✓ Branch 3 taken 23895 times.
272258 if (i != rc->last_sub_block || !rc->infer_sb_cbf)
2148 248363 *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
2149 else
2150 23895 *sb_coded_flag = 1;
2151
4/4
✓ Branch 0 taken 104489 times.
✓ Branch 1 taken 167769 times.
✓ Branch 2 taken 66307 times.
✓ Branch 3 taken 38182 times.
272258 if (*sb_coded_flag && i < rc->last_sub_block)
2152 66307 rc->infer_sb_cbf = 0;
2153
2154 //first scan pass
2155
4/4
✓ Branch 0 taken 4326323 times.
✓ Branch 1 taken 266395 times.
✓ Branch 2 taken 4320460 times.
✓ Branch 3 taken 5863 times.
4592718 for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
2156 4320460 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2157 4320460 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2158 4320460 const int off = yc * tb->tb_width + xc;
2159 4320460 int *sig_coeff_flag = rc->sig_coeff_flag + off;
2160 4320460 int *abs_level_pass1 = rc->abs_level_pass1 + off;
2161 4320460 int *coeff_sign_level = rc->coeff_sign_level + off;
2162 4320460 int par_level_flag = 0;
2163
2164 4320460 abs_level_gtx_flag[n] = 0;
2165 4320460 last_scan_pos_pass1 = n;
2166
6/6
✓ Branch 0 taken 1643132 times.
✓ Branch 1 taken 2677328 times.
✓ Branch 2 taken 99053 times.
✓ Branch 3 taken 1544079 times.
✓ Branch 4 taken 93048 times.
✓ Branch 5 taken 6005 times.
4320460 if (*sb_coded_flag && (n != rc->num_sb_coeff - 1 || !infer_sb_sig_coeff_flag)) {
2167 1637127 *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
2168 1637127 rc->rem_bins_pass1--;
2169
2/2
✓ Branch 0 taken 366842 times.
✓ Branch 1 taken 1270285 times.
1637127 if (*sig_coeff_flag)
2170 366842 infer_sb_sig_coeff_flag = 0;
2171 } else {
2172
5/6
✓ Branch 0 taken 173347 times.
✓ Branch 1 taken 2509986 times.
✓ Branch 2 taken 173347 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6005 times.
✓ Branch 5 taken 167342 times.
2683333 *sig_coeff_flag = (n == rc->num_sb_coeff - 1) && infer_sb_sig_coeff_flag && *sb_coded_flag;
2173 }
2174 4320460 *coeff_sign_level = 0;
2175
2/2
✓ Branch 0 taken 372847 times.
✓ Branch 1 taken 3947613 times.
4320460 if (*sig_coeff_flag) {
2176 372847 *coeff_sign_level = 1 - 2 * coeff_sign_flag_ts_decode(lc, cu, rc, xc, yc);
2177 372847 abs_level_gtx_flag[n] = abs_level_gt1_flag_ts_decode(lc, cu, rc, xc, yc);
2178 372847 rc->rem_bins_pass1 -= 2;
2179
2/2
✓ Branch 0 taken 166154 times.
✓ Branch 1 taken 206693 times.
372847 if (abs_level_gtx_flag[n]) {
2180 166154 par_level_flag = par_level_flag_ts_decode(lc);
2181 166154 rc->rem_bins_pass1--;
2182 }
2183 }
2184 4320460 *abs_level_pass1 = *sig_coeff_flag + par_level_flag + abs_level_gtx_flag[n];
2185 }
2186
2187 //greater than x scan pass
2188
4/4
✓ Branch 0 taken 4235127 times.
✓ Branch 1 taken 263094 times.
✓ Branch 2 taken 4225963 times.
✓ Branch 3 taken 9164 times.
4498221 for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
2189 4225963 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2190 4225963 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2191 4225963 const int off = yc * tb->tb_width + xc;
2192
2193 4225963 abs_level_pass2[n] = rc->abs_level_pass1[off];
2194
4/4
✓ Branch 0 taken 4479779 times.
✓ Branch 1 taken 24753 times.
✓ Branch 2 taken 278569 times.
✓ Branch 3 taken 4201210 times.
4504532 for (int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) {
2195 278569 abs_level_gtx_flag[n] = abs_level_gtx_flag_ts_decode(lc, j);
2196 278569 abs_level_pass2[n] += abs_level_gtx_flag[n] << 1;
2197 278569 rc->rem_bins_pass1--;
2198 }
2199 4225963 last_scan_pos_pass2 = n;
2200 }
2201
2202 /* remainder scan pass */
2203
2/2
✓ Branch 0 taken 4355840 times.
✓ Branch 1 taken 272258 times.
4628098 for (n = 0; n < rc->num_sb_coeff; n++) {
2204 4355840 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2205 4355840 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2206 4355840 const int off = yc * tb->tb_width + xc;
2207 4355840 const int *abs_level_pass1 = rc->abs_level_pass1 + off;
2208 4355840 int *abs_level = rc->abs_level + off;
2209 4355840 int *coeff_sign_level = rc->coeff_sign_level + off;
2210 4355840 int abs_remainder = 0;
2211
2212
6/6
✓ Branch 0 taken 4225963 times.
✓ Branch 1 taken 129877 times.
✓ Branch 2 taken 4205553 times.
✓ Branch 3 taken 20410 times.
✓ Branch 4 taken 129877 times.
✓ Branch 5 taken 4205553 times.
4355840 if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) ||
2213
2/2
✓ Branch 0 taken 94497 times.
✓ Branch 1 taken 35380 times.
129877 (n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 &&
2214
4/4
✓ Branch 0 taken 75057 times.
✓ Branch 1 taken 19440 times.
✓ Branch 2 taken 35380 times.
✓ Branch 3 taken 4280610 times.
4335430 *abs_level_pass1 >= 2) ||
2215
2/2
✓ Branch 0 taken 28548 times.
✓ Branch 1 taken 6832 times.
35380 (n > last_scan_pos_pass1 && *sb_coded_flag))
2216 68398 abs_remainder = abs_remainder_ts_decode(lc, rc, xc, yc);
2217
2/2
✓ Branch 0 taken 4225963 times.
✓ Branch 1 taken 129877 times.
4355840 if (n <= last_scan_pos_pass2) {
2218 4225963 *abs_level = abs_level_pass2[n] + 2 * abs_remainder;
2219
2/2
✓ Branch 0 taken 94497 times.
✓ Branch 1 taken 35380 times.
129877 } else if (n <= last_scan_pos_pass1) {
2220 94497 *abs_level = *abs_level_pass1 + 2 * abs_remainder;
2221 } else {
2222 35380 *abs_level = abs_remainder;
2223
2/2
✓ Branch 0 taken 15497 times.
✓ Branch 1 taken 19883 times.
35380 if (abs_remainder) {
2224 //n > lastScanPosPass1
2225 15497 *coeff_sign_level = 1 - 2 * coeff_sign_flag_decode(lc);
2226 }
2227 }
2228
4/4
✓ Branch 0 taken 4023024 times.
✓ Branch 1 taken 332816 times.
✓ Branch 2 taken 3989159 times.
✓ Branch 3 taken 33865 times.
4355840 if (!bdpcm_flag && n <= last_scan_pos_pass1) {
2229
2/2
✓ Branch 0 taken 3537168 times.
✓ Branch 1 taken 451991 times.
3989159 const int left = xc > 0 ? abs_level[-1] : 0;
2230
2/2
✓ Branch 0 taken 3555948 times.
✓ Branch 1 taken 433211 times.
3989159 const int above = yc > 0 ? abs_level[-tb->tb_width] : 0;
2231 3989159 const int pred = FFMAX(left, above);
2232
2233
4/4
✓ Branch 0 taken 202319 times.
✓ Branch 1 taken 3786840 times.
✓ Branch 2 taken 124664 times.
✓ Branch 3 taken 77655 times.
3989159 if (*abs_level == 1 && pred > 0)
2234 124664 *abs_level = pred;
2235
4/4
✓ Branch 0 taken 235009 times.
✓ Branch 1 taken 3629486 times.
✓ Branch 2 taken 59647 times.
✓ Branch 3 taken 175362 times.
3864495 else if (*abs_level > 0 && *abs_level <= pred)
2236 59647 (*abs_level)--;
2237 }
2238
2/2
✓ Branch 0 taken 388344 times.
✓ Branch 1 taken 3967496 times.
4355840 if (*abs_level) {
2239 388344 tb->coeffs[off] = *coeff_sign_level * *abs_level;
2240 388344 tb->max_scan_x = FFMAX(xc, tb->max_scan_x);
2241 388344 tb->max_scan_y = FFMAX(yc, tb->max_scan_y);
2242 388344 tb->min_scan_x = FFMIN(xc, tb->min_scan_x);
2243 388344 tb->min_scan_y = FFMIN(yc, tb->min_scan_y);
2244 } else {
2245 3967496 tb->coeffs[off] = 0;
2246 }
2247 }
2248
2249 272258 return 0;
2250 }
2251
2252 56567 static int hls_residual_ts_coding(VVCLocalContext *lc, TransformBlock *tb)
2253 {
2254 ResidualCoding rc;
2255 56567 tb->min_scan_x = tb->min_scan_y = INT_MAX;
2256 56567 init_residual_coding(lc, &rc, tb->log2_tb_width, tb->log2_tb_height, tb);
2257
2/2
✓ Branch 0 taken 272258 times.
✓ Branch 1 taken 56567 times.
328825 for (int i = 0; i <= rc.last_sub_block; i++) {
2258 272258 int ret = residual_ts_coding_subblock(lc, &rc, i);
2259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 272258 times.
272258 if (ret < 0)
2260 ✗ return ret;
2261 }
2262
2263 56567 return 0;
2264 }
2265
2266 2199984 static inline int residual_coding_subblock(VVCLocalContext *lc, ResidualCoding *rc, const int i)
2267 {
2268 2199984 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2269 2199984 TransformBlock *tb = rc->tb;
2270 int first_sig_scan_pos_sb, last_sig_scan_pos_sb;
2271 int first_pos_mode0, first_pos_mode1;
2272 2199984 int infer_sb_dc_sig_coeff_flag = 0;
2273 2199984 int n, sig_hidden_flag, sum = 0;
2274 int abs_level_gt2_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];
2275 2199984 const int start_qstate_sb = rc->qstate;
2276 2199984 const int xs = rc->sb_scan_x_off[i];
2277 2199984 const int ys = rc->sb_scan_y_off[i];
2278 2199984 uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
2279
2280
2281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2199984 times.
2199984 av_assert0(rc->num_sb_coeff <= MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE);
2282
4/4
✓ Branch 0 taken 1231796 times.
✓ Branch 1 taken 968188 times.
✓ Branch 2 taken 951830 times.
✓ Branch 3 taken 279966 times.
2199984 if (i < rc->last_sub_block && i > 0) {
2283 951830 *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
2284 951830 infer_sb_dc_sig_coeff_flag = 1;
2285 } else {
2286 1248154 *sb_coded_flag = 1;
2287 }
2288
8/8
✓ Branch 0 taken 1854471 times.
✓ Branch 1 taken 345513 times.
✓ Branch 2 taken 1782772 times.
✓ Branch 3 taken 71699 times.
✓ Branch 4 taken 53914 times.
✓ Branch 5 taken 1728858 times.
✓ Branch 6 taken 72824 times.
✓ Branch 7 taken 52789 times.
2199984 if (*sb_coded_flag && (xs > 3 || ys > 3) && !tb->c_idx)
2289 72824 lc->parse.mts_zero_out_sig_coeff_flag = 0;
2290
2291
2/2
✓ Branch 0 taken 345513 times.
✓ Branch 1 taken 1854471 times.
2199984 if (!*sb_coded_flag)
2292 345513 return 0;
2293
2294 1854471 first_sig_scan_pos_sb = rc->num_sb_coeff;
2295 1854471 last_sig_scan_pos_sb = -1;
2296
2/2
✓ Branch 0 taken 968188 times.
✓ Branch 1 taken 886283 times.
1854471 first_pos_mode0 = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1);
2297 1854471 first_pos_mode1 = first_pos_mode0;
2298
4/4
✓ Branch 0 taken 19697750 times.
✓ Branch 1 taken 1786696 times.
✓ Branch 2 taken 19629975 times.
✓ Branch 3 taken 67775 times.
21484446 for (n = first_pos_mode0; n >= 0 && rc->rem_bins_pass1 >= 4; n--) {
2299 19629975 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2300 19629975 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2301
4/4
✓ Branch 0 taken 2968257 times.
✓ Branch 1 taken 16661718 times.
✓ Branch 2 taken 968188 times.
✓ Branch 3 taken 2000069 times.
19629975 const int last = (xc == rc->last_significant_coeff_x && yc == rc->last_significant_coeff_y);
2302 19629975 int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc;
2303 19629975 int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc;
2304
2305
6/6
✓ Branch 0 taken 1786696 times.
✓ Branch 1 taken 17843279 times.
✓ Branch 2 taken 1776548 times.
✓ Branch 3 taken 10148 times.
✓ Branch 4 taken 18651639 times.
✓ Branch 5 taken 968188 times.
19629975 if ((n > 0 || !infer_sb_dc_sig_coeff_flag ) && !last) {
2306 18651639 *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
2307 18651639 rc->rem_bins_pass1--;
2308
2/2
✓ Branch 0 taken 10267071 times.
✓ Branch 1 taken 8384568 times.
18651639 if (*sig_coeff_flag)
2309 10267071 infer_sb_dc_sig_coeff_flag = 0;
2310 } else {
2311
5/8
✓ Branch 0 taken 10148 times.
✓ Branch 1 taken 968188 times.
✓ Branch 2 taken 10148 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10148 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10148 times.
✗ Branch 7 not taken.
978336 *sig_coeff_flag = last || (!rc->scan_x_off[n] && !rc ->scan_y_off[n] &&
2312 infer_sb_dc_sig_coeff_flag);
2313 }
2314 19629975 *abs_level_pass1 = 0;
2315
2/2
✓ Branch 0 taken 11245407 times.
✓ Branch 1 taken 8384568 times.
19629975 if (*sig_coeff_flag) {
2316 11245407 int abs_level_gt1_flag, par_level_flag = 0;
2317 11245407 const int inc = get_gtx_flag_inc(rc, xc, yc, last);
2318 11245407 abs_level_gt1_flag = abs_level_gtx_flag_decode(lc, inc);
2319 11245407 rc->rem_bins_pass1--;
2320
2/2
✓ Branch 0 taken 2359026 times.
✓ Branch 1 taken 8886381 times.
11245407 if (abs_level_gt1_flag) {
2321 2359026 par_level_flag = par_level_flag_decode(lc, inc);
2322 2359026 abs_level_gt2_flag[n] = abs_level_gtx_flag_decode(lc, inc + 32);
2323 2359026 rc->rem_bins_pass1 -= 2;
2324 } else {
2325 8886381 abs_level_gt2_flag[n] = 0;
2326 }
2327
2/2
✓ Branch 0 taken 1837807 times.
✓ Branch 1 taken 9407600 times.
11245407 if (last_sig_scan_pos_sb == -1)
2328 1837807 last_sig_scan_pos_sb = n;
2329 11245407 first_sig_scan_pos_sb = n;
2330
2331 11245407 *abs_level_pass1 =
2332 11245407 1 + par_level_flag + abs_level_gt1_flag + (abs_level_gt2_flag[n] << 1);
2333 } else {
2334 8384568 abs_level_gt2_flag[n] = 0;
2335 }
2336
2337
2/2
✓ Branch 0 taken 18082140 times.
✓ Branch 1 taken 1547835 times.
19629975 if (rsh->sh_dep_quant_used_flag)
2338 18082140 rc->qstate = qstate_translate_table[rc->qstate][*abs_level_pass1 & 1];
2339
2340 19629975 first_pos_mode1 = n - 1;
2341 }
2342
2/2
✓ Branch 0 taken 19629975 times.
✓ Branch 1 taken 1854471 times.
21484446 for (n = first_pos_mode0; n > first_pos_mode1; n--) {
2343 19629975 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2344 19629975 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2345 19629975 const int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc;
2346 19629975 int *abs_level = rc->abs_level + yc * tb->tb_width + xc;
2347
2348 19629975 *abs_level = *abs_level_pass1;
2349
2/2
✓ Branch 0 taken 633634 times.
✓ Branch 1 taken 18996341 times.
19629975 if (abs_level_gt2_flag[n]) {
2350 633634 const int abs_remainder = abs_remainder_decode(lc, rc, xc, yc);
2351 633634 ep_update_hist(lc->ep, rc, abs_remainder, 2);
2352 633634 *abs_level += 2 * abs_remainder;
2353 }
2354 }
2355
2/2
✓ Branch 0 taken 382666 times.
✓ Branch 1 taken 1854471 times.
2237137 for (n = first_pos_mode1; n >= 0; n--) {
2356 382666 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2357 382666 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2358 382666 int *abs_level = rc->abs_level + yc * tb->tb_width + xc;
2359
2360
1/2
✓ Branch 0 taken 382666 times.
✗ Branch 1 not taken.
382666 if (*sb_coded_flag) {
2361 382666 const int dec_abs_level = dec_abs_level_decode(lc, rc, xc, yc, abs_level);
2362 382666 ep_update_hist(lc->ep, rc, dec_abs_level, 0);
2363 }
2364
2/2
✓ Branch 0 taken 346663 times.
✓ Branch 1 taken 36003 times.
382666 if (*abs_level > 0) {
2365
2/2
✓ Branch 0 taken 8583 times.
✓ Branch 1 taken 338080 times.
346663 if (last_sig_scan_pos_sb == -1)
2366 8583 last_sig_scan_pos_sb = n;
2367 346663 first_sig_scan_pos_sb = n;
2368 }
2369
2/2
✓ Branch 0 taken 291903 times.
✓ Branch 1 taken 90763 times.
382666 if (rsh->sh_dep_quant_used_flag)
2370 291903 rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1];
2371 }
2372
2/2
✓ Branch 0 taken 58763 times.
✓ Branch 1 taken 1795708 times.
1913234 sig_hidden_flag = rsh->sh_sign_data_hiding_used_flag &&
2373
2/2
✓ Branch 0 taken 40911 times.
✓ Branch 1 taken 17852 times.
58763 (last_sig_scan_pos_sb - first_sig_scan_pos_sb > 3 ? 1 : 0);
2374
2375
2/2
✓ Branch 0 taken 1709024 times.
✓ Branch 1 taken 145447 times.
1854471 if (rsh->sh_dep_quant_used_flag)
2376 1709024 rc->qstate = start_qstate_sb;
2377
2/2
✓ Branch 0 taken 968188 times.
✓ Branch 1 taken 886283 times.
1854471 n = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1);
2378
2/2
✓ Branch 0 taken 20012641 times.
✓ Branch 1 taken 1854471 times.
21867112 for (/* nothing */; n >= 0; n--) {
2379 int trans_coeff_level;
2380 20012641 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2381 20012641 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2382 20012641 const int off = yc * tb->tb_width + xc;
2383 20012641 const int *abs_level = rc->abs_level + off;
2384
2385
2/2
✓ Branch 0 taken 11592070 times.
✓ Branch 1 taken 8420571 times.
20012641 if (*abs_level > 0) {
2386 11592070 int sign = 1;
2387
4/4
✓ Branch 0 taken 325851 times.
✓ Branch 1 taken 11266219 times.
✓ Branch 2 taken 284940 times.
✓ Branch 3 taken 40911 times.
11592070 if (!sig_hidden_flag || (n != first_sig_scan_pos_sb))
2388 11551159 sign = 1 - 2 * coeff_sign_flag_decode(lc);
2389
2/2
✓ Branch 0 taken 10748587 times.
✓ Branch 1 taken 843483 times.
11592070 if (rsh->sh_dep_quant_used_flag) {
2390 10748587 trans_coeff_level = (2 * *abs_level - (rc->qstate > 1)) * sign;
2391 } else {
2392 843483 trans_coeff_level = *abs_level * sign;
2393
2/2
✓ Branch 0 taken 325851 times.
✓ Branch 1 taken 517632 times.
843483 if (sig_hidden_flag) {
2394 325851 sum += *abs_level;
2395
4/4
✓ Branch 0 taken 40911 times.
✓ Branch 1 taken 284940 times.
✓ Branch 2 taken 21117 times.
✓ Branch 3 taken 19794 times.
325851 if (n == first_sig_scan_pos_sb && (sum % 2))
2396 21117 trans_coeff_level = -trans_coeff_level;
2397 }
2398 }
2399 11592070 tb->coeffs[off] = trans_coeff_level;
2400 11592070 tb->max_scan_x = FFMAX(xc, tb->max_scan_x);
2401 11592070 tb->max_scan_y = FFMAX(yc, tb->max_scan_y);
2402 }
2403
2/2
✓ Branch 0 taken 18374043 times.
✓ Branch 1 taken 1638598 times.
20012641 if (rsh->sh_dep_quant_used_flag)
2404 18374043 rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1];
2405 }
2406
2407 1854471 return 0;
2408 }
2409
2410 968188 static void derive_last_scan_pos(ResidualCoding *rc)
2411 {
2412 int xc, yc, xs, ys;
2413 do {
2414
2/2
✓ Branch 0 taken 6537347 times.
✓ Branch 1 taken 108505164 times.
115042511 if (!rc->last_scan_pos) {
2415 6537347 rc->last_scan_pos = rc->num_sb_coeff;
2416 6537347 rc->last_sub_block--;
2417 }
2418 115042511 rc->last_scan_pos--;
2419 115042511 xs = rc->sb_scan_x_off[rc->last_sub_block];
2420 115042511 ys = rc->sb_scan_y_off[rc->last_sub_block];
2421 115042511 xc = (xs << rc->log2_sb_w) + rc->scan_x_off[rc->last_scan_pos];
2422 115042511 yc = (ys << rc->log2_sb_h) + rc->scan_y_off[rc->last_scan_pos];
2423
4/4
✓ Branch 0 taken 107633105 times.
✓ Branch 1 taken 7409406 times.
✓ Branch 2 taken 6441218 times.
✓ Branch 3 taken 968188 times.
115042511 } while ((xc != rc->last_significant_coeff_x) || (yc != rc->last_significant_coeff_y));
2424 968188 }
2425
2426 968188 static void last_significant_coeff_x_y_decode(ResidualCoding *rc, VVCLocalContext *lc,
2427 const int log2_zo_tb_width, const int log2_zo_tb_height)
2428 {
2429 968188 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2430 968188 const TransformBlock *tb = rc->tb;
2431 int last_significant_coeff_x, last_significant_coeff_y;
2432
2433 968188 last_significant_coeff_x = last_significant_coeff_x_prefix_decode(lc,
2434 968188 tb->log2_tb_width, log2_zo_tb_width, tb->c_idx);
2435
2436 968188 last_significant_coeff_y = last_significant_coeff_y_prefix_decode(lc,
2437 968188 tb->log2_tb_height, log2_zo_tb_height, tb->c_idx);
2438
2439
2/2
✓ Branch 0 taken 209380 times.
✓ Branch 1 taken 758808 times.
968188 if (last_significant_coeff_x > 3) {
2440 209380 int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_x);
2441 209380 last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
2442 209380 (2 + (last_significant_coeff_x & 1)) + suffix;
2443 }
2444
2/2
✓ Branch 0 taken 161050 times.
✓ Branch 1 taken 807138 times.
968188 if (last_significant_coeff_y > 3) {
2445 161050 int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_y);
2446 161050 last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
2447 161050 (2 + (last_significant_coeff_y & 1)) + suffix;
2448 }
2449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 968188 times.
968188 if (rsh->sh_reverse_last_sig_coeff_flag) {
2450 ✗ last_significant_coeff_x = (1 << log2_zo_tb_width) - 1 - last_significant_coeff_x;
2451 ✗ last_significant_coeff_y = (1 << log2_zo_tb_height) - 1 - last_significant_coeff_y;
2452 }
2453 968188 rc->last_significant_coeff_x = last_significant_coeff_x;
2454 968188 rc->last_significant_coeff_y = last_significant_coeff_y;
2455 968188 }
2456
2457 968188 static int hls_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
2458 {
2459 968188 const VVCSPS *sps = lc->fc->ps.sps;
2460 968188 const CodingUnit *cu = lc->cu;
2461 968188 const int log2_tb_width = tb->log2_tb_width;
2462 968188 const int log2_tb_height = tb->log2_tb_height;
2463 968188 const int c_idx = tb->c_idx;
2464 int log2_zo_tb_width, log2_zo_tb_height;
2465 ResidualCoding rc;
2466
2467
10/10
✓ Branch 0 taken 959961 times.
✓ Branch 1 taken 8227 times.
✓ Branch 2 taken 51961 times.
✓ Branch 3 taken 908000 times.
✓ Branch 4 taken 34956 times.
✓ Branch 5 taken 17005 times.
✓ Branch 6 taken 1722 times.
✓ Branch 7 taken 33234 times.
✓ Branch 8 taken 1619 times.
✓ Branch 9 taken 103 times.
968188 if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width == 5 && log2_tb_height < 6)
2468 1619 log2_zo_tb_width = 4;
2469 else
2470 966569 log2_zo_tb_width = FFMIN(log2_tb_width, 5 );
2471
2472
10/10
✓ Branch 0 taken 959961 times.
✓ Branch 1 taken 8227 times.
✓ Branch 2 taken 51961 times.
✓ Branch 3 taken 908000 times.
✓ Branch 4 taken 34956 times.
✓ Branch 5 taken 17005 times.
✓ Branch 6 taken 34709 times.
✓ Branch 7 taken 247 times.
✓ Branch 8 taken 2102 times.
✓ Branch 9 taken 32607 times.
968188 if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width < 6 && log2_tb_height == 5 )
2473 2102 log2_zo_tb_height = 4;
2474 else
2475 966086 log2_zo_tb_height = FFMIN(log2_tb_height, 5);
2476
2477 968188 init_residual_coding(lc, &rc, log2_zo_tb_width, log2_zo_tb_height, tb);
2478 968188 last_significant_coeff_x_y_decode(&rc, lc, log2_zo_tb_width, log2_zo_tb_height);
2479 968188 derive_last_scan_pos(&rc);
2480
2481
9/10
✓ Branch 0 taken 688222 times.
✓ Branch 1 taken 279966 times.
✓ Branch 2 taken 662678 times.
✓ Branch 3 taken 25544 times.
✓ Branch 4 taken 592363 times.
✓ Branch 5 taken 70315 times.
✓ Branch 6 taken 592363 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 450654 times.
✓ Branch 9 taken 141709 times.
968188 if (!rc.last_sub_block && log2_tb_width >= 2 && log2_tb_height >= 2 && !tb->ts && rc.last_scan_pos > 0)
2482 450654 lc->parse.lfnst_dc_only = 0;
2483
6/6
✓ Branch 0 taken 279966 times.
✓ Branch 1 taken 688222 times.
✓ Branch 2 taken 277970 times.
✓ Branch 3 taken 1996 times.
✓ Branch 4 taken 4609 times.
✓ Branch 5 taken 273361 times.
968188 if ((rc.last_sub_block > 0 && log2_tb_width >= 2 && log2_tb_height >= 2 ) ||
2484
8/8
✓ Branch 0 taken 157336 times.
✓ Branch 1 taken 537491 times.
✓ Branch 2 taken 87559 times.
✓ Branch 3 taken 69777 times.
✓ Branch 4 taken 43678 times.
✓ Branch 5 taken 43881 times.
✓ Branch 6 taken 55062 times.
✓ Branch 7 taken 58393 times.
694827 (rc.last_scan_pos > 7 && (log2_tb_width == 2 || log2_tb_width == 3 ) &&
2485 log2_tb_width == log2_tb_height))
2486 328423 lc->parse.lfnst_zero_out_sig_coeff_flag = 0;
2487
6/6
✓ Branch 0 taken 688222 times.
✓ Branch 1 taken 279966 times.
✓ Branch 2 taken 519272 times.
✓ Branch 3 taken 168950 times.
✓ Branch 4 taken 590666 times.
✓ Branch 5 taken 208572 times.
968188 if ((rc.last_sub_block > 0 || rc.last_scan_pos > 0 ) && !c_idx)
2488 590666 lc->parse.mts_dc_only = 0;
2489
2490 968188 memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs));
2491 968188 memset(rc.abs_level, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level[0]));
2492 968188 memset(rc.sb_coded_flag, 0, rc.nb_sbs);
2493 968188 memset(rc.abs_level_pass1, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level_pass1[0]));
2494 968188 memset(rc.sig_coeff_flag, 0, tb->tb_width * tb->tb_height * sizeof(rc.sig_coeff_flag[0]));
2495
2496
2/2
✓ Branch 0 taken 2199984 times.
✓ Branch 1 taken 968188 times.
3168172 for (int i = rc.last_sub_block; i >= 0; i--) {
2497 2199984 int ret = residual_coding_subblock(lc, &rc, i);
2498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2199984 times.
2199984 if (ret < 0)
2499 ✗ return ret;
2500 }
2501
2502 968188 return 0;
2503 }
2504
2505 1024755 int ff_vvc_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
2506 {
2507 1024755 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2508
3/4
✓ Branch 0 taken 1024755 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 56567 times.
✓ Branch 3 taken 968188 times.
1024755 const int ts = !rsh->sh_ts_residual_coding_disabled_flag && tb->ts;
2509
2510
2/2
✓ Branch 0 taken 56567 times.
✓ Branch 1 taken 968188 times.
1024755 return ts ? hls_residual_ts_coding(lc, tb) : hls_residual_coding(lc, tb);
2511 }
2512
2513 137186 int ff_vvc_cu_coded_flag(VVCLocalContext *lc)
2514 {
2515 137186 return GET_CABAC(CU_CODED_FLAG);
2516 }
2517
2518 135700 int ff_vvc_sbt_flag(VVCLocalContext *lc)
2519 {
2520 135700 const int w = lc->cu->cb_width;
2521 135700 const int h = lc->cu->cb_height;
2522 135700 const int inc = w * h <= 256;
2523 135700 return GET_CABAC(CU_SBT_FLAG + inc);
2524 }
2525
2526 32385 int ff_vvc_sbt_quad_flag(VVCLocalContext *lc)
2527 {
2528 32385 return GET_CABAC(CU_SBT_QUAD_FLAG);
2529 }
2530
2531 25537 int ff_vvc_sbt_horizontal_flag(VVCLocalContext *lc)
2532 {
2533 25537 const int w = lc->cu->cb_width;
2534 25537 const int h = lc->cu->cb_height;
2535
4/4
✓ Branch 0 taken 13683 times.
✓ Branch 1 taken 11854 times.
✓ Branch 2 taken 7401 times.
✓ Branch 3 taken 6282 times.
25537 const int inc = (w == h) ? 0 : ((w < h) ? 1 : 2);
2536 25537 return GET_CABAC(CU_SBT_HORIZONTAL_FLAG + inc);
2537 }
2538
2539 45453 int ff_vvc_sbt_pos_flag(VVCLocalContext *lc)
2540 {
2541 45453 return GET_CABAC(CU_SBT_POS_FLAG);
2542 }
2543
2544 190512 int ff_vvc_lfnst_idx(VVCLocalContext *lc, const int inc)
2545 {
2546
2/2
✓ Branch 1 taken 48740 times.
✓ Branch 2 taken 141772 times.
190512 if (!GET_CABAC(LFNST_IDX + inc))
2547 48740 return 0;
2548
2/2
✓ Branch 1 taken 86860 times.
✓ Branch 2 taken 54912 times.
141772 if (!GET_CABAC(LFNST_IDX + 2))
2549 86860 return 1;
2550 54912 return 2;
2551 }
2552
2553 253110 int ff_vvc_mts_idx(VVCLocalContext *lc)
2554 {
2555 int i;
2556
2/2
✓ Branch 0 taken 461226 times.
✓ Branch 1 taken 910 times.
462136 for (i = 0; i < 4; i++) {
2557
2/2
✓ Branch 1 taken 252200 times.
✓ Branch 2 taken 209026 times.
461226 if (!GET_CABAC(MTS_IDX + i))
2558 252200 return i;
2559 }
2560 910 return i;
2561 }
2562
2563 1901 int ff_vvc_end_of_slice_flag_decode(VVCLocalContext *lc)
2564 {
2565 1901 return get_cabac_terminate(&lc->ep->cc);
2566 }
2567
2568 527 int ff_vvc_end_of_tile_one_bit(VVCLocalContext *lc)
2569 {
2570 527 return get_cabac_terminate(&lc->ep->cc);
2571 }
2572
2573 153 int ff_vvc_end_of_subset_one_bit(VVCLocalContext *lc)
2574 {
2575 153 return get_cabac_terminate(&lc->ep->cc);
2576 }
2577