FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/cabac.c
Date: 2025-06-01 09:29:47
Exec Total Coverage
Lines: 978 1028 95.1%
Functions: 127 139 91.4%
Branches: 658 692 95.1%

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 #include "libavcodec/cabac_functions.h"
23
24 #include "cabac.h"
25 #include "ctu.h"
26 #include "data.h"
27
28 #define CABAC_MAX_BIN 31
29
30 #define CNU 35
31
32 enum SyntaxElement {
33 ALF_CTB_FLAG = 0,
34 ALF_USE_APS_FLAG = ALF_CTB_FLAG + 9,
35 ALF_CTB_CC_CB_IDC,
36 ALF_CTB_CC_CR_IDC = ALF_CTB_CC_CB_IDC + 3,
37 ALF_CTB_FILTER_ALT_IDX = ALF_CTB_CC_CR_IDC + 3,
38 SAO_MERGE_FLAG = ALF_CTB_FILTER_ALT_IDX + 2,
39 SAO_TYPE_IDX,
40 SPLIT_CU_FLAG,
41 SPLIT_QT_FLAG = SPLIT_CU_FLAG + 9,
42 MTT_SPLIT_CU_VERTICAL_FLAG = SPLIT_QT_FLAG + 6,
43 MTT_SPLIT_CU_BINARY_FLAG = MTT_SPLIT_CU_VERTICAL_FLAG + 5,
44 NON_INTER_FLAG = MTT_SPLIT_CU_BINARY_FLAG + 4,
45 CU_SKIP_FLAG = NON_INTER_FLAG + 2,
46 PRED_MODE_IBC_FLAG = CU_SKIP_FLAG + 3,
47 PRED_MODE_FLAG = PRED_MODE_IBC_FLAG + 3,
48 PRED_MODE_PLT_FLAG = PRED_MODE_FLAG + 2,
49 CU_ACT_ENABLED_FLAG,
50 INTRA_BDPCM_LUMA_FLAG,
51 INTRA_BDPCM_LUMA_DIR_FLAG,
52 INTRA_MIP_FLAG,
53 INTRA_LUMA_REF_IDX = INTRA_MIP_FLAG + 4,
54 INTRA_SUBPARTITIONS_MODE_FLAG = INTRA_LUMA_REF_IDX + 2,
55 INTRA_SUBPARTITIONS_SPLIT_FLAG,
56 INTRA_LUMA_MPM_FLAG,
57 INTRA_LUMA_NOT_PLANAR_FLAG,
58 INTRA_BDPCM_CHROMA_FLAG = INTRA_LUMA_NOT_PLANAR_FLAG + 2,
59 INTRA_BDPCM_CHROMA_DIR_FLAG,
60 CCLM_MODE_FLAG,
61 CCLM_MODE_IDX,
62 INTRA_CHROMA_PRED_MODE,
63 GENERAL_MERGE_FLAG,
64 INTER_PRED_IDC,
65 INTER_AFFINE_FLAG = INTER_PRED_IDC + 6,
66 CU_AFFINE_TYPE_FLAG = INTER_AFFINE_FLAG + 3,
67 SYM_MVD_FLAG,
68 REF_IDX_LX,
69 MVP_LX_FLAG = REF_IDX_LX + 2,
70 AMVR_FLAG,
71 AMVR_PRECISION_IDX = AMVR_FLAG + 2,
72 BCW_IDX = AMVR_PRECISION_IDX + 3,
73 CU_CODED_FLAG,
74 CU_SBT_FLAG,
75 CU_SBT_QUAD_FLAG = CU_SBT_FLAG + 2,
76 CU_SBT_HORIZONTAL_FLAG,
77 CU_SBT_POS_FLAG = CU_SBT_HORIZONTAL_FLAG + 3,
78 LFNST_IDX,
79 MTS_IDX = LFNST_IDX + 3,
80 COPY_ABOVE_PALETTE_INDICES_FLAG = MTS_IDX + 4,
81 PALETTE_TRANSPOSE_FLAG,
82 RUN_COPY_FLAG,
83 REGULAR_MERGE_FLAG = RUN_COPY_FLAG + 8,
84 MMVD_MERGE_FLAG = REGULAR_MERGE_FLAG + 2,
85 MMVD_CAND_FLAG,
86 MMVD_DISTANCE_IDX,
87 CIIP_FLAG,
88 MERGE_SUBBLOCK_FLAG,
89 MERGE_SUBBLOCK_IDX = MERGE_SUBBLOCK_FLAG + 3,
90 MERGE_IDX,
91 ABS_MVD_GREATER0_FLAG,
92 ABS_MVD_GREATER1_FLAG,
93 TU_Y_CODED_FLAG,
94 TU_CB_CODED_FLAG = TU_Y_CODED_FLAG + 4,
95 TU_CR_CODED_FLAG = TU_CB_CODED_FLAG + 2,
96 CU_QP_DELTA_ABS = TU_CR_CODED_FLAG + 3,
97 CU_CHROMA_QP_OFFSET_FLAG = CU_QP_DELTA_ABS + 2,
98 CU_CHROMA_QP_OFFSET_IDX,
99 TRANSFORM_SKIP_FLAG,
100 TU_JOINT_CBCR_RESIDUAL_FLAG = TRANSFORM_SKIP_FLAG + 2,
101 LAST_SIG_COEFF_X_PREFIX = TU_JOINT_CBCR_RESIDUAL_FLAG + 3,
102 LAST_SIG_COEFF_Y_PREFIX = LAST_SIG_COEFF_X_PREFIX +23,
103 SB_CODED_FLAG = LAST_SIG_COEFF_Y_PREFIX +23,
104 SIG_COEFF_FLAG = SB_CODED_FLAG + 7,
105 PAR_LEVEL_FLAG = SIG_COEFF_FLAG +63,
106 ABS_LEVEL_GTX_FLAG = PAR_LEVEL_FLAG +33,
107 COEFF_SIGN_FLAG = ABS_LEVEL_GTX_FLAG +72,
108 SYNTAX_ELEMENT_LAST = COEFF_SIGN_FLAG + 6,
109 };
110
111 static const uint8_t init_values[4][SYNTAX_ELEMENT_LAST] = {
112 {
113 //alf_ctb_flag
114 62, 39, 39, 54, 39, 39, 31, 39, 39,
115 //alf_use_aps_flag
116 46,
117 //alf_ctb_cc_cb_idc
118 18, 30, 31,
119 //alf_ctb_cc_cr_idc
120 18, 30, 31,
121 //alf_ctb_filter_alt_idx
122 11, 11,
123 //sao_merge_left_flag and sao_merge_up_flag
124 60,
125 //sao_type_idx_luma and sao_type_idx_chroma
126 13,
127 //split_cu_flag
128 19, 28, 38, 27, 29, 38, 20, 30, 31,
129 //split_qt_flag
130 27, 6, 15, 25, 19, 37,
131 //mtt_split_cu_vertical_flag
132 43, 42, 29, 27, 44,
133 //mtt_split_cu_binary_flag
134 36, 45, 36, 45,
135 //non_inter_flag
136 CNU, CNU,
137 //cu_skip_flag
138 0, 26, 28,
139 //pred_mode_ibc_flag
140 17, 42, 36,
141 //pred_mode_flag
142 CNU, CNU,
143 //pred_mode_plt_flag
144 25,
145 //cu_act_enabled_flag
146 52,
147 //intra_bdpcm_luma_flag
148 19,
149 //intra_bdpcm_luma_dir_flag
150 35,
151 //intra_mip_flag
152 33, 49, 50, 25,
153 //intra_luma_ref_idx
154 25, 60,
155 //intra_subpartitions_mode_flag
156 33,
157 //intra_subpartitions_split_flag
158 43,
159 //intra_luma_mpm_flag
160 45,
161 //intra_luma_not_planar_flag
162 13, 28,
163 //intra_bdpcm_chroma_flag
164 1,
165 //intra_bdpcm_chroma_dir_flag
166 27,
167 //cclm_mode_flag
168 59,
169 //cclm_mode_idx
170 27,
171 //intra_chroma_pred_mode
172 34,
173 //general_merge_flag
174 26,
175 //inter_pred_idc
176 CNU, CNU, CNU, CNU, CNU, CNU,
177 //inter_affine_flag
178 CNU, CNU, CNU,
179 //cu_affine_type_flag
180 CNU,
181 //sym_mvd_flag
182 CNU,
183 //ref_idx_l0 and ref_idx_l1
184 CNU, CNU,
185 //mvp_l0_flag and mvp_l1_flag
186 42,
187 //amvr_flag
188 CNU, CNU,
189 //amvr_precision_idx
190 35, 34, 35,
191 //bcw_idx
192 CNU,
193 //cu_coded_flag
194 6,
195 //cu_sbt_flag
196 CNU, CNU,
197 //cu_sbt_quad_flag
198 CNU,
199 //cu_sbt_horizontal_flag
200 CNU, CNU, CNU,
201 //cu_sbt_pos_flag
202 CNU,
203 //lfnst_idx
204 28, 52, 42,
205 //mts_idx
206 29, 0, 28, 0,
207 //copy_above_palette_indices_flag
208 42,
209 //palette_transpose_flag
210 42,
211 //run_copy_flag
212 50, 37, 45, 30, 46, 45, 38, 46,
213 //regular_merge_flag
214 CNU, CNU,
215 //mmvd_merge_flag
216 CNU,
217 //mmvd_cand_flag
218 CNU,
219 //mmvd_distance_idx
220 CNU,
221 //ciip_flag
222 CNU,
223 //merge_subblock_flag
224 CNU, CNU, CNU,
225 //merge_subblock_idx
226 CNU,
227 //merge_idx, merge_gpm_idx0, and merge_gpm_idx1
228 34,
229 //abs_mvd_greater0_flag
230 14,
231 //abs_mvd_greater1_flag
232 45,
233 //tu_y_coded_flag
234 15, 12, 5, 7,
235 //tu_cb_coded_flag
236 12, 21,
237 //tu_cr_coded_flag
238 33, 28, 36,
239 //cu_qp_delta_abs
240 CNU, CNU,
241 //cu_chroma_qp_offset_flag
242 CNU,
243 //cu_chroma_qp_offset_idx
244 CNU,
245 //transform_skip_flag
246 25, 9,
247 //tu_joint_cbcr_residual_flag
248 12, 21, 35,
249 //last_sig_coeff_x_prefix
250 13, 5, 4, 21, 14, 4, 6, 14, 21, 11, 14, 7, 14, 5, 11, 21,
251 30, 22, 13, 42, 12, 4, 3,
252 //last_sig_coeff_y_prefix
253 13, 5, 4, 6, 13, 11, 14, 6, 5, 3, 14, 22, 6, 4, 3, 6,
254 22, 29, 20, 34, 12, 4, 3,
255 //sb_coded_flag
256 18, 31, 25, 15, 18, 20, 38,
257 //sig_coeff_flag
258 25, 19, 28, 14, 25, 20, 29, 30, 19, 37, 30, 38, 11, 38, 46, 54,
259 27, 39, 39, 39, 44, 39, 39, 39, 18, 39, 39, 39, 27, 39, 39, 39,
260 0, 39, 39, 39, 25, 27, 28, 37, 34, 53, 53, 46, 19, 46, 38, 39,
261 52, 39, 39, 39, 11, 39, 39, 39, 19, 39, 39, 39, 25, 28, 38,
262 //par_level_flag
263 33, 25, 18, 26, 34, 27, 25, 26, 19, 42, 35, 33, 19, 27, 35, 35,
264 34, 42, 20, 43, 20, 33, 25, 26, 42, 19, 27, 26, 50, 35, 20, 43,
265 11,
266 //abs_level_gtx_flag
267 25, 25, 11, 27, 20, 21, 33, 12, 28, 21, 22, 34, 28, 29, 29, 30,
268 36, 29, 45, 30, 23, 40, 33, 27, 28, 21, 37, 36, 37, 45, 38, 46,
269 25, 1, 40, 25, 33, 11, 17, 25, 25, 18, 4, 17, 33, 26, 19, 13,
270 33, 19, 20, 28, 22, 40, 9, 25, 18, 26, 35, 25, 26, 35, 28, 37,
271 11, 5, 5, 14, 10, 3, 3, 3,
272 //coeff_sign_flag
273 12, 17, 46, 28, 25, 46,
274 },
275 {
276 //alf_ctb_flag
277 13, 23, 46, 4, 61, 54, 19, 46, 54,
278 //alf_use_aps_flag
279 46,
280 //alf_ctb_cc_cb_idc
281 18, 21, 38,
282 //alf_ctb_cc_cr_idc
283 18, 21, 38,
284 //alf_ctb_filter_alt_idx
285 20, 12,
286 //sao_merge_left_flag and sao_merge_up_flag
287 60,
288 //sao_type_idx_luma and sao_type_idx_chroma
289 5,
290 //split_cu_flag
291 11, 35, 53, 12, 6, 30, 13, 15, 31,
292 //split_qt_flag
293 20, 14, 23, 18, 19, 6,
294 //mtt_split_cu_vertical_flag
295 43, 35, 37, 34, 52,
296 //mtt_split_cu_binary_flag
297 43, 37, 21, 22,
298 //non_inter_flag
299 25, 12,
300 //cu_skip_flag
301 57, 59, 45,
302 //pred_mode_ibc_flag
303 0, 57, 44,
304 //pred_mode_flag
305 40, 35,
306 //pred_mode_plt_flag
307 0,
308 //cu_act_enabled_flag
309 46,
310 //intra_bdpcm_luma_flag
311 40,
312 //intra_bdpcm_luma_dir_flag
313 36,
314 //intra_mip_flag
315 41, 57, 58, 26,
316 //intra_luma_ref_idx
317 25, 58,
318 //intra_subpartitions_mode_flag
319 33,
320 //intra_subpartitions_split_flag
321 36,
322 //intra_luma_mpm_flag
323 36,
324 //intra_luma_not_planar_flag
325 12, 20,
326 //intra_bdpcm_chroma_flag
327 0,
328 //intra_bdpcm_chroma_dir_flag
329 13,
330 //cclm_mode_flag
331 34,
332 //cclm_mode_idx
333 27,
334 //intra_chroma_pred_mode
335 25,
336 //general_merge_flag
337 21,
338 //inter_pred_idc
339 7, 6, 5, 12, 4, 40,
340 //inter_affine_flag
341 12, 13, 14,
342 //cu_affine_type_flag
343 35,
344 //sym_mvd_flag
345 28,
346 //ref_idx_l0 and ref_idx_l1
347 20, 35,
348 //mvp_l0_flag and mvp_l1_flag
349 34,
350 //amvr_flag
351 59, 58,
352 //amvr_precision_idx
353 60, 48, 60,
354 //bcw_idx
355 4,
356 //cu_coded_flag
357 5,
358 //cu_sbt_flag
359 56, 57,
360 //cu_sbt_quad_flag
361 42,
362 //cu_sbt_horizontal_flag
363 20, 43, 12,
364 //cu_sbt_pos_flag
365 28,
366 //lfnst_idx
367 37, 45, 27,
368 //mts_idx
369 45, 40, 27, 0,
370 //copy_above_palette_indices_flag
371 59,
372 //palette_transpose_flag
373 42,
374 //run_copy_flag
375 51, 30, 30, 38, 23, 38, 53, 46,
376 //regular_merge_flag
377 38, 7,
378 //mmvd_merge_flag
379 26,
380 //mmvd_cand_flag
381 43,
382 //mmvd_distance_idx
383 60,
384 //ciip_flag
385 57,
386 //merge_subblock_flag
387 48, 57, 44,
388 //merge_subblock_idx
389 5,
390 //merge_idx, merge_gpm_idx0, and merge_gpm_idx1
391 20,
392 //abs_mvd_greater0_flag
393 44,
394 //abs_mvd_greater1_flag
395 43,
396 //tu_y_coded_flag
397 23, 5, 20, 7,
398 //tu_cb_coded_flag
399 25, 28,
400 //tu_cr_coded_flag
401 25, 29, 45,
402 //cu_qp_delta_abs
403 CNU, CNU,
404 //cu_chroma_qp_offset_flag
405 CNU,
406 //cu_chroma_qp_offset_idx
407 CNU,
408 //transform_skip_flag
409 25, 9,
410 //tu_joint_cbcr_residual_flag
411 27, 36, 45,
412 //last_sig_coeff_x_prefix
413 6, 13, 12, 6, 6, 12, 14, 14, 13, 12, 29, 7, 6, 13, 36, 28,
414 14, 13, 5, 26, 12, 4, 18,
415 //last_sig_coeff_y_prefix
416 5, 5, 12, 6, 6, 4, 6, 14, 5, 12, 14, 7, 13, 5, 13, 21,
417 14, 20, 12, 34, 11, 4, 18,
418 //sb_coded_flag
419 25, 30, 25, 45, 18, 12, 29,
420 //sig_coeff_flag
421 17, 41, 42, 29, 25, 49, 43, 37, 33, 58, 51, 30, 19, 38, 38, 46,
422 34, 54, 54, 39, 6, 39, 39, 39, 19, 39, 54, 39, 19, 39, 39, 39,
423 56, 39, 39, 39, 17, 34, 35, 21, 41, 59, 60, 38, 35, 45, 53, 54,
424 44, 39, 39, 39, 34, 38, 62, 39, 26, 39, 39, 39, 40, 35, 44,
425 //par_level_flag
426 18, 17, 33, 18, 26, 42, 25, 33, 26, 42, 27, 25, 34, 42, 42, 35,
427 26, 27, 42, 20, 20, 25, 25, 26, 11, 19, 27, 33, 42, 35, 35, 43,
428 3,
429 //abs_level_gtx_flag
430 0, 17, 26, 19, 35, 21, 25, 34, 20, 28, 29, 33, 27, 28, 29, 22,
431 34, 28, 44, 37, 38, 0, 25, 19, 20, 13, 14, 57, 44, 30, 30, 23,
432 17, 0, 1, 17, 25, 18, 0, 9, 25, 33, 34, 9, 25, 18, 26, 20,
433 25, 18, 19, 27, 29, 17, 9, 25, 10, 18, 4, 17, 33, 19, 20, 29,
434 18, 11, 4, 28, 2, 10, 3, 3,
435 //coeff_sign_flag
436 5, 10, 53, 43, 25, 46,
437 },
438 {
439 //alf_ctb_flag
440 33, 52, 46, 25, 61, 54, 25, 61, 54,
441 //alf_use_aps_flag
442 46,
443 //alf_ctb_cc_cb_idc
444 25, 35, 38,
445 //alf_ctb_cc_cr_idc
446 25, 28, 38,
447 //alf_ctb_filter_alt_idx
448 11, 26,
449 //sao_merge_left_flag and sao_merge_up_flag
450 2,
451 //sao_type_idx_luma and sao_type_idx_chroma
452 2,
453 //split_cu_flag
454 18, 27, 15, 18, 28, 45, 26, 7, 23,
455 //split_qt_flag
456 26, 36, 38, 18, 34, 21,
457 //mtt_split_cu_vertical_flag
458 43, 42, 37, 42, 44,
459 //mtt_split_cu_binary_flag
460 28, 29, 28, 29,
461 //non_inter_flag
462 25, 20,
463 //cu_skip_flag
464 57, 60, 46,
465 //pred_mode_ibc_flag
466 0, 43, 45,
467 //pred_mode_flag
468 40, 35,
469 //pred_mode_plt_flag
470 17,
471 //cu_act_enabled_flag
472 46,
473 //intra_bdpcm_luma_flag
474 19,
475 //intra_bdpcm_luma_dir_flag
476 21,
477 //intra_mip_flag
478 56, 57, 50, 26,
479 //intra_luma_ref_idx
480 25, 59,
481 //intra_subpartitions_mode_flag
482 33,
483 //intra_subpartitions_split_flag
484 43,
485 //intra_luma_mpm_flag
486 44,
487 //intra_luma_not_planar_flag
488 13, 6,
489 //intra_bdpcm_chroma_flag
490 0,
491 //intra_bdpcm_chroma_dir_flag
492 28,
493 //cclm_mode_flag
494 26,
495 //cclm_mode_idx
496 27,
497 //intra_chroma_pred_mode
498 25,
499 //general_merge_flag
500 6,
501 //inter_pred_idc
502 14, 13, 5, 4, 3, 40,
503 //inter_affine_flag
504 19, 13, 6,
505 //cu_affine_type_flag
506 35,
507 //sym_mvd_flag
508 28,
509 //ref_idx_l0 and ref_idx_l1
510 5, 35,
511 //mvp_l0_flag and mvp_l1_flag
512 34,
513 //amvr_flag
514 59, 50,
515 //amvr_precision_idx
516 38, 26, 60,
517 //bcw_idx
518 5,
519 //cu_coded_flag
520 12,
521 //cu_sbt_flag
522 41, 57,
523 //cu_sbt_quad_flag
524 42,
525 //cu_sbt_horizontal_flag
526 35, 51, 27,
527 //cu_sbt_pos_flag
528 28,
529 //lfnst_idx
530 52, 37, 27,
531 //mts_idx
532 45, 25, 27, 0,
533 //copy_above_palette_indices_flag
534 50,
535 //palette_transpose_flag
536 35,
537 //run_copy_flag
538 58, 45, 45, 30, 38, 45, 38, 46,
539 //regular_merge_flag
540 46, 15,
541 //mmvd_merge_flag
542 25,
543 //mmvd_cand_flag
544 43,
545 //mmvd_distance_idx
546 59,
547 //ciip_flag
548 57,
549 //merge_subblock_flag
550 25, 58, 45,
551 //merge_subblock_idx
552 4,
553 //merge_idx, merge_gpm_idx0, and merge_gpm_idx1
554 18,
555 //abs_mvd_greater0_flag
556 51,
557 //abs_mvd_greater1_flag
558 36,
559 //tu_y_coded_flag
560 15, 6, 5, 14,
561 //tu_cb_coded_flag
562 25, 37,
563 //tu_cr_coded_flag
564 9, 36, 45,
565 //cu_qp_delta_abs
566 CNU, CNU,
567 //cu_chroma_qp_offset_flag
568 CNU,
569 //cu_chroma_qp_offset_idx
570 CNU,
571 //transform_skip_flag
572 25, 17,
573 //tu_joint_cbcr_residual_flag
574 42, 43, 52,
575 //last_sig_coeff_x_prefix
576 6, 6, 12, 14, 6, 4, 14, 7, 6, 4, 29, 7, 6, 6, 12, 28,
577 7, 13, 13, 35, 19, 5, 4,
578 //last_sig_coeff_y_prefix
579 5, 5, 20, 13, 13, 19, 21, 6, 12, 12, 14, 14, 5, 4, 12, 13,
580 7, 13, 12, 41, 11, 5, 27,
581 //sb_coded_flag
582 25, 45, 25, 14, 18, 35, 45,
583 //sig_coeff_flag
584 17, 41, 49, 36, 1, 49, 50, 37, 48, 51, 58, 45, 26, 45, 53, 46,
585 49, 54, 61, 39, 35, 39, 39, 39, 19, 54, 39, 39, 50, 39, 39, 39,
586 0, 39, 39, 39, 9, 49, 50, 36, 48, 59, 59, 38, 34, 45, 38, 31,
587 58, 39, 39, 39, 34, 38, 54, 39, 41, 39, 39, 39, 25, 50, 37,
588 //par_level_flag
589 33, 40, 25, 41, 26, 42, 25, 33, 26, 34, 27, 25, 41, 42, 42, 35,
590 33, 27, 35, 42, 43, 33, 25, 26, 34, 19, 27, 33, 42, 43, 35, 43,
591 11,
592 //abs_level_gtx_flag
593 0, 0, 33, 34, 35, 21, 25, 34, 35, 28, 29, 40, 42, 43, 29, 30,
594 49, 36, 37, 45, 38, 0, 40, 34, 43, 36, 37, 57, 52, 45, 38, 46,
595 25, 0, 0, 17, 25, 26, 0, 9, 25, 33, 19, 0, 25, 33, 26, 20,
596 25, 33, 27, 35, 22, 25, 1, 25, 33, 26, 12, 25, 33, 27, 28, 37,
597 19, 11, 4, 6, 3, 4, 4, 5,
598 //coeff_sign_flag
599 35, 25, 46, 28, 33, 38,
600 },
601 //shiftIdx
602 {
603 //alf_ctb_flag
604 0, 0, 0, 4, 0, 0, 1, 0, 0,
605 //alf_use_aps_flag
606 0,
607 //alf_ctb_cc_cb_idc
608 4, 1, 4,
609 //alf_ctb_cc_cr_idc
610 4, 1, 4,
611 //alf_ctb_filter_alt_idx
612 0, 0,
613 //sao_merge_left_flag and sao_merge_up_flag
614 0,
615 //sao_type_idx_luma and sao_type_idx_chroma
616 4,
617 //split_cu_flag
618 12, 13, 8, 8, 13, 12, 5, 9, 9,
619 //split_qt_flag
620 0, 8, 8, 12, 12, 8,
621 //mtt_split_cu_vertical_flag
622 9, 8, 9, 8, 5,
623 //mtt_split_cu_binary_flag
624 12, 13, 12, 13,
625 //non_inter_flag
626 1, 0,
627 //cu_skip_flag
628 5, 4, 8,
629 //pred_mode_ibc_flag
630 1, 5, 8,
631 //pred_mode_flag
632 5, 1,
633 //pred_mode_plt_flag
634 1,
635 //cu_act_enabled_flag
636 1,
637 //intra_bdpcm_luma_flag
638 1,
639 //intra_bdpcm_luma_dir_flag
640 4,
641 //intra_mip_flag
642 9, 10, 9, 6,
643 //intra_luma_ref_idx
644 5, 8,
645 //intra_subpartitions_mode_flag
646 9,
647 //intra_subpartitions_split_flag
648 2,
649 //intra_luma_mpm_flag
650 6,
651 //intra_luma_not_planar_flag
652 1, 5,
653 //intra_bdpcm_chroma_flag
654 1,
655 //intra_bdpcm_chroma_dir_flag
656 0,
657 //cclm_mode_flag
658 4,
659 //cclm_mode_idx
660 9,
661 //intra_chroma_pred_mode
662 5,
663 //general_merge_flag
664 4,
665 //inter_pred_idc
666 0, 0, 1, 4, 4, 0,
667 //inter_affine_flag
668 4, 0, 0,
669 //cu_affine_type_flag
670 4,
671 //sym_mvd_flag
672 5,
673 //ref_idx_l0 and ref_idx_l1
674 0, 4,
675 //mvp_l0_flag and mvp_l1_flag
676 12,
677 //amvr_flag
678 0, 0,
679 //amvr_precision_idx
680 4, 5, 0,
681 //bcw_idx
682 1,
683 //cu_coded_flag
684 4,
685 //cu_sbt_flag
686 1, 5,
687 //cu_sbt_quad_flag
688 10,
689 //cu_sbt_horizontal_flag
690 8, 4, 1,
691 //cu_sbt_pos_flag
692 13,
693 //lfnst_idx
694 9, 9, 10,
695 //mts_idx
696 8, 0, 9, 0,
697 //copy_above_palette_indices_flag
698 9,
699 //palette_transpose_flag
700 5,
701 //run_copy_flag
702 9, 6, 9, 10, 5, 0, 9, 5,
703 //regular_merge_flag
704 5, 5,
705 //mmvd_merge_flag
706 4,
707 //mmvd_cand_flag
708 10,
709 //mmvd_distance_idx
710 0,
711 //ciip_flag
712 1,
713 //merge_subblock_flag
714 4, 4, 4,
715 //merge_subblock_idx
716 0,
717 //merge_idx, merge_gpm_idx0, and merge_gpm_idx1
718 4,
719 //abs_mvd_greater0_flag
720 9,
721 //abs_mvd_greater1_flag
722 5,
723 //tu_y_coded_flag
724 5, 1, 8, 9,
725 //tu_cb_coded_flag
726 5, 0,
727 //tu_cr_coded_flag
728 2, 1, 0,
729 //cu_qp_delta_abs
730 8, 8,
731 //cu_chroma_qp_offset_flag
732 8,
733 //cu_chroma_qp_offset_idx
734 8,
735 //transform_skip_flag
736 1, 1,
737 //tu_joint_cbcr_residual_flag
738 1, 1, 0,
739 //last_sig_coeff_x_prefix
740 8, 5, 4, 5, 4, 4, 5, 4, 1, 0, 4, 1, 0, 0, 0, 0,
741 1, 0, 0, 0, 5, 4, 4,
742 //last_sig_coeff_y_prefix
743 8, 5, 8, 5, 5, 4, 5, 5, 4, 0, 5, 4, 1, 0, 0, 1,
744 4, 0, 0, 0, 6, 5, 5,
745 //sb_coded_flag
746 8, 5, 5, 8, 5, 8, 8,
747 //sig_coeff_flag
748 12, 9, 9, 10, 9, 9, 9, 10, 8, 8, 8, 10, 9, 13, 8, 8,
749 8, 8, 8, 5, 8, 0, 0, 0, 8, 8, 8, 8, 8, 0, 4, 4,
750 0, 0, 0, 0, 12, 12, 9, 13, 4, 5, 8, 9, 8, 12, 12, 8,
751 4, 0, 0, 0, 8, 8, 8, 8, 4, 0, 0, 0, 13, 13, 8,
752 //par_level_flag
753 8, 9, 12, 13, 13, 13, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13,
754 10, 13, 13, 13, 13, 8, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13,
755 6,
756 //abs_level_gtx_flag
757 9, 5, 10, 13, 13, 10, 9, 10, 13, 13, 13, 9, 10, 10, 10, 13,
758 8, 9, 10, 10, 13, 8, 8, 9, 12, 12, 10, 5, 9, 9, 9, 13,
759 1, 5, 9, 9, 9, 6, 5, 9, 10, 10, 9, 9, 9, 9, 9, 9,
760 6, 8, 9, 9, 10, 1, 5, 8, 8, 9, 6, 6, 9, 8, 8, 9,
761 4, 2, 1, 6, 1, 1, 1, 1,
762 //coeff_sign_flag
763 1, 4, 4, 5, 8, 8,
764 }
765 };
766
767 #define MAX_SUB_BLOCKS 16
768 #define MAX_SUB_BLOCK_SIZE 4
769 #define MAX_TB_SIZE 64
770
771 typedef struct ResidualCoding {
772 //common for ts and non ts
773 TransformBlock *tb;
774
775 int log2_sb_w;
776 int log2_sb_h;
777 int last_sub_block;
778 int hist_value;
779 int update_hist;
780 int num_sb_coeff;
781 int rem_bins_pass1;
782
783 int width_in_sbs;
784 int height_in_sbs;
785 int nb_sbs;
786
787 const uint8_t *sb_scan_x_off;
788 const uint8_t *sb_scan_y_off;
789 const uint8_t *scan_x_off;
790 const uint8_t *scan_y_off;
791
792 uint8_t sb_coded_flag[MAX_SUB_BLOCKS * MAX_SUB_BLOCKS];
793 int sig_coeff_flag[MAX_TB_SIZE * MAX_TB_SIZE];
794 int abs_level_pass1[MAX_TB_SIZE * MAX_TB_SIZE]; ///< AbsLevelPass1[][]
795 int abs_level[MAX_TB_SIZE * MAX_TB_SIZE];
796
797 //for ts only
798 uint8_t infer_sb_cbf;
799 int coeff_sign_level[MAX_TB_SIZE * MAX_TB_SIZE]; ///< CoeffSignLevel[][]
800
801 //for non ts only
802 int qstate;
803 int last_scan_pos;
804 int last_significant_coeff_x;
805 int last_significant_coeff_y;
806 } ResidualCoding;
807
808 273 static int cabac_reinit(VVCLocalContext *lc)
809 {
810
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 273 times.
273 return skip_bytes(&lc->ep->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
811 }
812
813 2204 static void cabac_init_state(VVCLocalContext *lc)
814 {
815 2204 const VVCSPS *sps = lc->fc->ps.sps;
816 2204 const H266RawSliceHeader *rsh = lc->sc->sh.r;
817 2204 const int qp = av_clip_uintp2(lc->sc->sh.slice_qp_y, 6);
818 2204 int init_type = 2 - rsh->sh_slice_type;
819
820 av_assert0(VVC_CONTEXTS == SYNTAX_ELEMENT_LAST);
821
822 2204 ff_vvc_ep_init_stat_coeff(lc->ep, sps->bit_depth, sps->r->sps_persistent_rice_adaptation_enabled_flag);
823
824
3/4
✓ Branch 0 taken 559 times.
✓ Branch 1 taken 1645 times.
✓ Branch 2 taken 559 times.
✗ Branch 3 not taken.
2204 if (rsh->sh_cabac_init_flag && !IS_I(rsh))
825 559 init_type ^= 3;
826
827
2/2
✓ Branch 0 taken 833112 times.
✓ Branch 1 taken 2204 times.
835316 for (int i = 0; i < VVC_CONTEXTS; i++) {
828 833112 VVCCabacState *state = &lc->ep->cabac_state[i];
829 833112 const int init_value = init_values[init_type][i];
830 833112 const int shift_idx = init_values[3][i];
831 833112 const int m = (init_value >> 3) - 4;
832 833112 const int n = ((init_value & 7) * 18) + 1;
833 833112 const int pre = av_clip(((m * (qp - 16)) >> 1) + n, 1, 127);
834
835 833112 state->state[0] = pre << 3;
836 833112 state->state[1] = pre << 7;
837 833112 state->shift[0] = (shift_idx >> 2 ) + 2;
838 833112 state->shift[1] = (shift_idx & 3 ) + 3 + state->shift[0];
839 }
840 2204 }
841
842 46713 int ff_vvc_cabac_init(VVCLocalContext *lc,
843 const int ctu_idx, const int rx, const int ry)
844 {
845 46713 int ret = 0;
846 46713 const VVCPPS *pps = lc->fc->ps.pps;
847 46713 const int first_ctb_in_slice = !ctu_idx;
848
4/4
✓ Branch 0 taken 5833 times.
✓ Branch 1 taken 40880 times.
✓ Branch 2 taken 2092 times.
✓ Branch 3 taken 3741 times.
46713 const int first_ctb_in_tile = rx == pps->ctb_to_col_bd[rx] && ry == pps->ctb_to_row_bd[ry];
849
850
4/4
✓ Branch 0 taken 45002 times.
✓ Branch 1 taken 1711 times.
✓ Branch 2 taken 493 times.
✓ Branch 3 taken 44509 times.
46713 if (first_ctb_in_slice|| first_ctb_in_tile) {
851
4/4
✓ Branch 0 taken 1891 times.
✓ Branch 1 taken 313 times.
✓ Branch 2 taken 273 times.
✓ Branch 3 taken 1618 times.
2204 if (lc->sc->nb_eps == 1 && !first_ctb_in_slice)
852 273 ret = cabac_reinit(lc);
853
1/2
✓ Branch 0 taken 2204 times.
✗ Branch 1 not taken.
2204 if (!ret)
854 2204 cabac_init_state(lc);
855 }
856 46713 return ret;
857 }
858
859 //fixme
860 2047753 static void vvc_refill2(CABACContext* c) {
861 int i;
862 unsigned x;
863 #if !HAVE_FAST_CLZ
864 x = c->low ^ (c->low - 1);
865 i = 7 - ff_h264_norm_shift[x >> (CABAC_BITS - 1)];
866 #else
867 2047753 i = ff_ctz(c->low) - CABAC_BITS;
868 #endif
869
870 2047753 x = -CABAC_MASK;
871
872 #if CABAC_BITS == 16
873 2047753 x += (c->bytestream[0] << 9) + (c->bytestream[1] << 1);
874 #else
875 x += c->bytestream[0] << 1;
876 #endif
877
878 2047753 c->low += x << i;
879 #if !UNCHECKED_BITSTREAM_READER
880
2/2
✓ Branch 0 taken 2047643 times.
✓ Branch 1 taken 110 times.
2047753 if (c->bytestream < c->bytestream_end)
881 #endif
882 2047643 c->bytestream += CABAC_BITS / 8;
883 2047753 }
884
885 53108287 static int inline vvc_get_cabac(CABACContext *c, VVCCabacState* base, const int ctx)
886 {
887 53108287 VVCCabacState *s = base + ctx;
888 53108287 const int qRangeIdx = c->range >> 5;
889 53108287 const int pState = s->state[1] + (s->state[0] << 4);
890 53108287 const int valMps = pState >> 14;
891
2/2
✓ Branch 0 taken 21788272 times.
✓ Branch 1 taken 31320015 times.
53108287 const int RangeLPS = (qRangeIdx * ((valMps ? 32767 - pState : pState) >> 9 ) >> 1) + 4;
892 int bit, lps_mask;
893
894 53108287 c->range -= RangeLPS;
895 53108287 lps_mask = ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
896
897 53108287 c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
898 53108287 c->range += (RangeLPS - c->range) & lps_mask;
899
900 53108287 bit = valMps ^ (lps_mask & 1);
901
902 53108287 lps_mask = ff_h264_norm_shift[c->range];
903 53108287 c->range <<= lps_mask;
904 53108287 c->low <<= lps_mask;
905
906
2/2
✓ Branch 0 taken 2047753 times.
✓ Branch 1 taken 51060534 times.
53108287 if (!(c->low & CABAC_MASK))
907 2047753 vvc_refill2(c);
908 53108287 s->state[0] = s->state[0] - (s->state[0] >> s->shift[0]) + (1023 * bit >> s->shift[0]);
909 53108287 s->state[1] = s->state[1] - (s->state[1] >> s->shift[1]) + (16383 * bit >> s->shift[1]);
910 53108287 return bit;
911 }
912
913 #define GET_CABAC(ctx) vvc_get_cabac(&lc->ep->cc, lc->ep->cabac_state, ctx)
914
915 //9.3.3.4 Truncated binary (TB) binarization process
916 239740 static int truncated_binary_decode(VVCLocalContext *lc, const int c_max)
917 {
918 239740 const int n = c_max + 1;
919 239740 const int k = av_log2(n);
920 239740 const int u = (1 << (k+1)) - n;
921 239740 int v = 0;
922
2/2
✓ Branch 0 taken 933308 times.
✓ Branch 1 taken 239740 times.
1173048 for (int i = 0; i < k; i++)
923 933308 v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
924
2/2
✓ Branch 0 taken 136819 times.
✓ Branch 1 taken 102921 times.
239740 if (v >= u) {
925 136819 v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
926 136819 v -= u;
927 }
928 239740 return v;
929 }
930
931 // 9.3.3.5 k-th order Exp - Golomb binarization process
932 static int kth_order_egk_decode(CABACContext *c, int k)
933 {
934 int bit = 1;
935 int value = 0;
936 int symbol = 0;
937
938 while (bit) {
939 bit = get_cabac_bypass(c);
940 value += bit << k++;
941 }
942
943 if (--k) {
944 for (int i = 0; i < k; i++)
945 symbol = (symbol << 1) | get_cabac_bypass(c);
946 value += symbol;
947 }
948
949 return value;
950 }
951
952 // 9.3.3.6 Limited k-th order Exp-Golomb binarization process
953 194807 static int limited_kth_order_egk_decode(CABACContext *c, const int k, const int max_pre_ext_len, const int trunc_suffix_len)
954 {
955 194807 int pre_ext_len = 0;
956 int escape_length;
957 194807 int val = 0;
958
4/4
✓ Branch 0 taken 603181 times.
✓ Branch 1 taken 110 times.
✓ Branch 3 taken 408484 times.
✓ Branch 4 taken 194697 times.
603291 while ((pre_ext_len < max_pre_ext_len) && get_cabac_bypass(c))
959 408484 pre_ext_len++;
960
2/2
✓ Branch 0 taken 110 times.
✓ Branch 1 taken 194697 times.
194807 if (pre_ext_len == max_pre_ext_len)
961 110 escape_length = trunc_suffix_len;
962 else
963 194697 escape_length = pre_ext_len + k;
964
2/2
✓ Branch 0 taken 671480 times.
✓ Branch 1 taken 194807 times.
866287 while (escape_length-- > 0) {
965 671480 val = (val << 1) + get_cabac_bypass(c);
966 }
967 194807 val += ((1 << pre_ext_len) - 1) << k;
968 194807 return val;
969 }
970
971 // 9.3.3.7 Fixed-length binarization process
972 26972 static int fixed_length_decode(CABACContext* c, const int len)
973 {
974 26972 int value = 0;
975
976
2/2
✓ Branch 0 taken 160475 times.
✓ Branch 1 taken 26972 times.
187447 for (int i = 0; i < len; i++)
977 160475 value = (value << 1) | get_cabac_bypass(c);
978
979 26972 return value;
980 }
981
982 static av_always_inline
983 3573710 void get_left_top(const VVCLocalContext *lc, uint8_t *left, uint8_t *top,
984 const int x0, const int y0, const uint8_t *left_ctx, const uint8_t *top_ctx)
985 {
986 3573710 const VVCFrameContext *fc = lc->fc;
987 3573710 const VVCSPS *sps = fc->ps.sps;
988 3573710 const int min_cb_width = fc->ps.pps->min_cb_width;
989 3573710 const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
990 3573710 const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
991 3573710 const int x_cb = x0 >> sps->min_cb_log2_size_y;
992 3573710 const int y_cb = y0 >> sps->min_cb_log2_size_y;
993
994
4/4
✓ Branch 0 taken 751933 times.
✓ Branch 1 taken 2821777 times.
✓ Branch 2 taken 628260 times.
✓ Branch 3 taken 123673 times.
3573710 if (lc->ctb_left_flag || x0b)
995 3450037 *left = SAMPLE_CTB(left_ctx, x_cb - 1, y_cb);
996
4/4
✓ Branch 0 taken 1121145 times.
✓ Branch 1 taken 2452565 times.
✓ Branch 2 taken 947882 times.
✓ Branch 3 taken 173263 times.
3573710 if (lc->ctb_up_flag || y0b)
997 3400447 *top = SAMPLE_CTB(top_ctx, x_cb, y_cb - 1);
998 3573710 }
999
1000 static av_always_inline
1001 553394 uint8_t get_inc(VVCLocalContext *lc, const uint8_t *ctx)
1002 {
1003 553394 uint8_t left = 0, top = 0;
1004 553394 get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx);
1005 553394 return left + top;
1006 }
1007
1008 23166 int ff_vvc_sao_merge_flag_decode(VVCLocalContext *lc)
1009 {
1010 23166 return GET_CABAC(SAO_MERGE_FLAG);
1011 }
1012
1013 13142 int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc)
1014 {
1015
2/2
✓ Branch 1 taken 8784 times.
✓ Branch 2 taken 4358 times.
13142 if (!GET_CABAC(SAO_TYPE_IDX))
1016 8784 return SAO_NOT_APPLIED;
1017
1018
2/2
✓ Branch 1 taken 1179 times.
✓ Branch 2 taken 3179 times.
4358 if (!get_cabac_bypass(&lc->ep->cc))
1019 1179 return SAO_BAND;
1020 3179 return SAO_EDGE;
1021 }
1022
1023 1357 int ff_vvc_sao_band_position_decode(VVCLocalContext *lc)
1024 {
1025 1357 return fixed_length_decode(&lc->ep->cc, 5);
1026 }
1027
1028 22592 int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc)
1029 {
1030 22592 int i = 0;
1031 22592 const int length = (1 << (FFMIN(lc->fc->ps.sps->bit_depth, 10) - 5)) - 1;
1032
1033
4/4
✓ Branch 0 taken 117663 times.
✓ Branch 1 taken 257 times.
✓ Branch 3 taken 95328 times.
✓ Branch 4 taken 22335 times.
117920 while (i < length && get_cabac_bypass(&lc->ep->cc))
1034 95328 i++;
1035 22592 return i;
1036 }
1037
1038 2475 int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc)
1039 {
1040 2475 return get_cabac_bypass(&lc->ep->cc);
1041 }
1042
1043 3179 int ff_vvc_sao_eo_class_decode(VVCLocalContext *lc)
1044 {
1045 3179 return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1046 }
1047
1048 59442 int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx)
1049 {
1050 59442 int inc = c_idx * 3;
1051 59442 const VVCFrameContext *fc = lc->fc;
1052
2/2
✓ Branch 0 taken 50499 times.
✓ Branch 1 taken 8943 times.
59442 if (lc->ctb_left_flag) {
1053 50499 const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry);
1054 50499 inc += left->ctb_flag[c_idx];
1055 }
1056
2/2
✓ Branch 0 taken 44562 times.
✓ Branch 1 taken 14880 times.
59442 if (lc->ctb_up_flag) {
1057 44562 const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1);
1058 44562 inc += above->ctb_flag[c_idx];
1059 }
1060 59442 return GET_CABAC(ALF_CTB_FLAG + inc);
1061 }
1062
1063 18747 int ff_vvc_alf_use_aps_flag(VVCLocalContext *lc)
1064 {
1065 18747 return GET_CABAC(ALF_USE_APS_FLAG);
1066 }
1067
1068 4928 int ff_vvc_alf_luma_prev_filter_idx(VVCLocalContext *lc)
1069 {
1070 4928 return truncated_binary_decode(lc, lc->sc->sh.r->sh_num_alf_aps_ids_luma - 1);
1071 }
1072
1073 2775 int ff_vvc_alf_luma_fixed_filter_idx(VVCLocalContext *lc)
1074 {
1075 2775 return truncated_binary_decode(lc, 15);
1076 }
1077
1078 16033 int ff_vvc_alf_ctb_filter_alt_idx(VVCLocalContext *lc, const int c_idx, const int num_chroma_filters)
1079 {
1080 16033 int i = 0;
1081 16033 const int length = num_chroma_filters - 1;
1082
1083
4/4
✓ Branch 0 taken 29261 times.
✓ Branch 1 taken 2861 times.
✓ Branch 3 taken 16089 times.
✓ Branch 4 taken 13172 times.
32122 while (i < length && GET_CABAC(ALF_CTB_FILTER_ALT_IDX + c_idx - 1))
1084 16089 i++;
1085 16033 return i;
1086 }
1087
1088 22625 int ff_vvc_alf_ctb_cc_idc(VVCLocalContext *lc, const int rx, const int ry, const int idx, const int cc_filters_signalled)
1089 {
1090
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;
1091 22625 int i = 0;
1092 22625 const VVCFrameContext *fc = lc->fc;
1093
2/2
✓ Branch 0 taken 19914 times.
✓ Branch 1 taken 2711 times.
22625 if (lc->ctb_left_flag) {
1094 19914 const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry);
1095 19914 inc += left->ctb_cc_idc[idx] != 0;
1096 }
1097
2/2
✓ Branch 0 taken 18700 times.
✓ Branch 1 taken 3925 times.
22625 if (lc->ctb_up_flag) {
1098 18700 const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1);
1099 18700 inc += above->ctb_cc_idc[idx] != 0;
1100 }
1101
1102
2/2
✓ Branch 1 taken 12098 times.
✓ Branch 2 taken 10527 times.
22625 if (!GET_CABAC(inc))
1103 12098 return 0;
1104 10527 i++;
1105
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))
1106 9189 i++;
1107 10527 return i;
1108 }
1109
1110 2032313 int ff_vvc_split_cu_flag(VVCLocalContext *lc, const int x0, const int y0,
1111 const int cb_width, const int cb_height, const int is_chroma, const VVCAllowedSplit *a)
1112 {
1113 2032313 const VVCFrameContext *fc = lc->fc;
1114 2032313 const VVCPPS *pps = fc->ps.pps;
1115
4/4
✓ Branch 0 taken 2027649 times.
✓ Branch 1 taken 4664 times.
✓ Branch 2 taken 1979677 times.
✓ Branch 3 taken 47972 times.
2032313 const int is_inside = (x0 + cb_width <= pps->width) && (y0 + cb_height <= pps->height);
1116
1117
12/12
✓ Branch 0 taken 811194 times.
✓ Branch 1 taken 1221119 times.
✓ Branch 2 taken 588624 times.
✓ Branch 3 taken 222570 times.
✓ Branch 4 taken 582868 times.
✓ Branch 5 taken 5756 times.
✓ Branch 6 taken 581283 times.
✓ Branch 7 taken 1585 times.
✓ Branch 8 taken 49332 times.
✓ Branch 9 taken 531951 times.
✓ Branch 10 taken 1447726 times.
✓ Branch 11 taken 52636 times.
2032313 if ((a->btv || a->bth || a->ttv || a->tth || a->qt) && is_inside)
1118 {
1119 1447726 uint8_t inc = 0, left_height = cb_height, top_width = cb_width;
1120
1121 1447726 get_left_top(lc, &left_height, &top_width, x0, y0, fc->tab.cb_height[is_chroma], fc->tab.cb_width[is_chroma]);
1122 1447726 inc += left_height < cb_height;
1123 1447726 inc += top_width < cb_width;
1124 1447726 inc += (a->btv + a->bth + a->ttv + a->tth + 2 * a->qt - 1) / 2 * 3;
1125
1126 1447726 return GET_CABAC(SPLIT_CU_FLAG + inc);
1127
1128 }
1129 584587 return !is_inside;
1130 }
1131
1132 262332 static int split_qt_flag_decode(VVCLocalContext *lc, const int x0, const int y0, const int ch_type, const int cqt_depth)
1133 {
1134 262332 const VVCFrameContext *fc = lc->fc;
1135 262332 int inc = 0;
1136 262332 uint8_t depth_left = 0, depth_top = 0;
1137
1138 262332 get_left_top(lc, &depth_left, &depth_top, x0, y0, fc->tab.cqt_depth[ch_type], fc->tab.cqt_depth[ch_type]);
1139 262332 inc += depth_left > cqt_depth;
1140 262332 inc += depth_top > cqt_depth;
1141
2/2
✓ Branch 0 taken 197180 times.
✓ Branch 1 taken 65152 times.
262332 inc += (cqt_depth >= 2) * 3;
1142
1143 262332 return GET_CABAC(SPLIT_QT_FLAG + inc);
1144 }
1145
1146 699617 static int mtt_split_cu_vertical_flag_decode(VVCLocalContext *lc, const int x0, const int y0,
1147 const int cb_width, const int cb_height, const int ch_type, const VVCAllowedSplit* a)
1148 {
1149
8/8
✓ Branch 0 taken 79500 times.
✓ Branch 1 taken 620117 times.
✓ Branch 2 taken 16497 times.
✓ Branch 3 taken 63003 times.
✓ Branch 4 taken 114790 times.
✓ Branch 5 taken 521824 times.
✓ Branch 6 taken 13827 times.
✓ Branch 7 taken 100963 times.
699617 if ((a->bth || a->tth) && (a->btv || a->ttv)) {
1150 int inc;
1151 535651 const int v = a->btv + a->ttv;
1152 535651 const int h = a->bth + a->tth;
1153
2/2
✓ Branch 0 taken 84410 times.
✓ Branch 1 taken 451241 times.
535651 if (v > h)
1154 84410 inc = 4;
1155
2/2
✓ Branch 0 taken 86772 times.
✓ Branch 1 taken 364469 times.
451241 else if (v < h)
1156 86772 inc = 3;
1157 else {
1158 364469 const VVCFrameContext *fc = lc->fc;
1159 364469 const VVCSPS *sps = fc->ps.sps;
1160 364469 const int min_cb_width = fc->ps.pps->min_cb_width;
1161 364469 const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
1162 364469 const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
1163 364469 const int x_cb = x0 >> sps->min_cb_log2_size_y;
1164 364469 const int y_cb = y0 >> sps->min_cb_log2_size_y;
1165
4/4
✓ Branch 0 taken 109767 times.
✓ Branch 1 taken 254702 times.
✓ Branch 2 taken 90025 times.
✓ Branch 3 taken 19742 times.
364469 const int available_a = lc->ctb_up_flag || y0b;
1166
4/4
✓ Branch 0 taken 69536 times.
✓ Branch 1 taken 294933 times.
✓ Branch 2 taken 54503 times.
✓ Branch 3 taken 15033 times.
364469 const int available_l = lc->ctb_left_flag || x0b;
1167
2/2
✓ Branch 0 taken 344727 times.
✓ Branch 1 taken 19742 times.
364469 const int da = cb_width / (available_a ? SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cb, y_cb - 1) : 1);
1168
2/2
✓ Branch 0 taken 349436 times.
✓ Branch 1 taken 15033 times.
364469 const int dl = cb_height / (available_l ? SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cb - 1, y_cb) : 1);
1169
1170
6/6
✓ Branch 0 taken 266218 times.
✓ Branch 1 taken 98251 times.
✓ Branch 2 taken 247931 times.
✓ Branch 3 taken 18287 times.
✓ Branch 4 taken 12932 times.
✓ Branch 5 taken 234999 times.
364469 if (da == dl || !available_a || !available_l)
1171 129470 inc = 0;
1172
2/2
✓ Branch 0 taken 121051 times.
✓ Branch 1 taken 113948 times.
234999 else if (da < dl)
1173 121051 inc = 1;
1174 else
1175 113948 inc = 2;
1176 }
1177 535651 return GET_CABAC(MTT_SPLIT_CU_VERTICAL_FLAG + inc);
1178 }
1179
4/4
✓ Branch 0 taken 63749 times.
✓ Branch 1 taken 100217 times.
✓ Branch 2 taken 63003 times.
✓ Branch 3 taken 746 times.
163966 return !(a->bth || a->tth);
1180 }
1181
1182 470228 static int mtt_split_cu_binary_flag_decode(VVCLocalContext *lc, const int mtt_split_cu_vertical_flag, const int mtt_depth)
1183 {
1184 470228 const int inc = (2 * mtt_split_cu_vertical_flag) + ((mtt_depth <= 1) ? 1 : 0);
1185 470228 return GET_CABAC(MTT_SPLIT_CU_BINARY_FLAG + inc);
1186 }
1187
1188 799192 VVCSplitMode ff_vvc_split_mode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height,
1189 const int cqt_depth, const int mtt_depth, const int ch_type, const VVCAllowedSplit *a)
1190 {
1191
8/8
✓ Branch 0 taken 155294 times.
✓ Branch 1 taken 643898 times.
✓ Branch 2 taken 38128 times.
✓ Branch 3 taken 117166 times.
✓ Branch 4 taken 33888 times.
✓ Branch 5 taken 4240 times.
✓ Branch 6 taken 746 times.
✓ Branch 7 taken 33142 times.
799192 const int allow_no_qt = a->btv || a->bth || a->ttv || a->tth;
1192 int split_qt_flag;
1193 int mtt_split_cu_vertical_flag;
1194 int mtt_split_cu_binary_flag;
1195 799192 const VVCSplitMode mtt_split_modes[] = {
1196 SPLIT_TT_HOR, SPLIT_BT_HOR, SPLIT_TT_VER, SPLIT_BT_VER,
1197 };
1198
4/4
✓ Branch 0 taken 766050 times.
✓ Branch 1 taken 33142 times.
✓ Branch 2 taken 262332 times.
✓ Branch 3 taken 503718 times.
799192 if (allow_no_qt && a->qt) {
1199 262332 split_qt_flag = split_qt_flag_decode(lc, x0, y0, ch_type, cqt_depth);
1200 } else {
1201
3/4
✓ Branch 0 taken 503718 times.
✓ Branch 1 taken 33142 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 503718 times.
536860 split_qt_flag = !allow_no_qt || a->qt;
1202 }
1203
2/2
✓ Branch 0 taken 99575 times.
✓ Branch 1 taken 699617 times.
799192 if (split_qt_flag)
1204 99575 return SPLIT_QT;
1205 699617 mtt_split_cu_vertical_flag = mtt_split_cu_vertical_flag_decode(lc, x0, y0, cb_width, cb_height, ch_type, a);
1206
6/6
✓ Branch 0 taken 583976 times.
✓ Branch 1 taken 115641 times.
✓ Branch 2 taken 410562 times.
✓ Branch 3 taken 173414 times.
✓ Branch 4 taken 182274 times.
✓ Branch 5 taken 228288 times.
699617 if ((a->btv && a->ttv && mtt_split_cu_vertical_flag) ||
1207
6/6
✓ Branch 0 taken 436660 times.
✓ Branch 1 taken 34669 times.
✓ Branch 2 taken 272316 times.
✓ Branch 3 taken 164344 times.
✓ Branch 4 taken 241940 times.
✓ Branch 5 taken 30376 times.
471329 (a->bth && a->tth && !mtt_split_cu_vertical_flag)) {
1208 470228 mtt_split_cu_binary_flag = mtt_split_cu_binary_flag_decode(lc, mtt_split_cu_vertical_flag, mtt_depth);
1209 } else {
1210
4/4
✓ Branch 0 taken 72678 times.
✓ Branch 1 taken 156711 times.
✓ Branch 2 taken 2322 times.
✓ Branch 3 taken 70356 times.
229389 if (!a->btv && !a->bth)
1211 2322 mtt_split_cu_binary_flag = 0;
1212
4/4
✓ Branch 0 taken 189744 times.
✓ Branch 1 taken 37323 times.
✓ Branch 2 taken 161312 times.
✓ Branch 3 taken 28432 times.
227067 else if (!a->ttv && !a->tth)
1213 161312 mtt_split_cu_binary_flag = 1;
1214
4/4
✓ Branch 0 taken 59077 times.
✓ Branch 1 taken 6678 times.
✓ Branch 2 taken 32524 times.
✓ Branch 3 taken 26553 times.
65755 else if (a->bth && a->ttv)
1215 32524 mtt_split_cu_binary_flag = 1 - mtt_split_cu_vertical_flag;
1216 else
1217 33231 mtt_split_cu_binary_flag = mtt_split_cu_vertical_flag;
1218 }
1219 699617 return mtt_split_modes[(mtt_split_cu_vertical_flag << 1) + mtt_split_cu_binary_flag];
1220 }
1221
1222 41362 int ff_vvc_non_inter_flag(VVCLocalContext *lc, const int x0, const int y0, const int ch_type)
1223 {
1224 41362 const VVCFrameContext *fc = lc->fc;
1225 41362 uint8_t inc, left = MODE_INTER, top = MODE_INTER;
1226
1227 41362 get_left_top(lc, &left, &top, x0, y0, fc->tab.cpm[ch_type], fc->tab.cpm[ch_type]);
1228
4/4
✓ Branch 0 taken 30263 times.
✓ Branch 1 taken 11099 times.
✓ Branch 2 taken 5667 times.
✓ Branch 3 taken 24596 times.
41362 inc = left == MODE_INTRA || top == MODE_INTRA;
1229 41362 return GET_CABAC(NON_INTER_FLAG + inc);
1230 }
1231
1232 199114 int ff_vvc_pred_mode_flag(VVCLocalContext *lc, const int is_chroma)
1233 {
1234 199114 const VVCFrameContext *fc = lc->fc;
1235 199114 const CodingUnit *cu = lc->cu;
1236 199114 uint8_t inc, left = MODE_INTER, top = MODE_INTER;
1237
1238 199114 get_left_top(lc, &left, &top, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]);
1239
4/4
✓ Branch 0 taken 156650 times.
✓ Branch 1 taken 42464 times.
✓ Branch 2 taken 17811 times.
✓ Branch 3 taken 138839 times.
199114 inc = left == MODE_INTRA || top == MODE_INTRA;
1240 199114 return GET_CABAC(PRED_MODE_FLAG + inc);
1241 }
1242
1243 int ff_vvc_pred_mode_plt_flag(VVCLocalContext *lc)
1244 {
1245 return GET_CABAC(PRED_MODE_PLT_FLAG);
1246 }
1247
1248 27878 int ff_vvc_intra_bdpcm_luma_flag(VVCLocalContext *lc)
1249 {
1250 27878 return GET_CABAC(INTRA_BDPCM_LUMA_FLAG);
1251 }
1252
1253 38 int ff_vvc_intra_bdpcm_luma_dir_flag(VVCLocalContext *lc)
1254 {
1255 38 return GET_CABAC(INTRA_BDPCM_LUMA_DIR_FLAG);
1256 }
1257
1258 24174 int ff_vvc_intra_bdpcm_chroma_flag(VVCLocalContext *lc)
1259 {
1260 24174 return GET_CABAC(INTRA_BDPCM_CHROMA_FLAG);
1261 }
1262
1263 3 int ff_vvc_intra_bdpcm_chroma_dir_flag(VVCLocalContext *lc)
1264 {
1265 3 return GET_CABAC(INTRA_BDPCM_CHROMA_DIR_FLAG);
1266 }
1267
1268 553394 int ff_vvc_cu_skip_flag(VVCLocalContext *lc, const uint8_t *cu_skip_flag)
1269 {
1270 553394 const int inc = get_inc(lc, cu_skip_flag);
1271 553394 return GET_CABAC(CU_SKIP_FLAG + inc);
1272 }
1273
1274 84747 int ff_vvc_pred_mode_ibc_flag(VVCLocalContext *lc, const int is_chroma)
1275 {
1276 84747 const VVCFrameContext *fc = lc->fc;
1277 84747 const CodingUnit *cu = lc->cu;
1278 84747 uint8_t left_mode = MODE_INTER, top_mode = MODE_INTER;
1279 int inc;
1280
1281 84747 get_left_top(lc, &left_mode, &top_mode, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]);
1282 84747 inc = (left_mode == MODE_IBC) + (top_mode == MODE_IBC);
1283 84747 return GET_CABAC(PRED_MODE_IBC_FLAG + inc);
1284 }
1285
1286 static av_always_inline
1287 358587 uint8_t get_mip_inc(VVCLocalContext *lc, const uint8_t *ctx)
1288 {
1289 358587 uint8_t left = 0, top = 0;
1290 358587 get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx);
1291 358587 return (left & 1) + (top & 1);
1292 }
1293
1294 454236 int ff_vvc_intra_mip_flag(VVCLocalContext *lc, const uint8_t *intra_mip_flag)
1295 {
1296 454236 const int w = lc->cu->cb_width;
1297 454236 const int h = lc->cu->cb_height;
1298
4/4
✓ Branch 0 taken 384862 times.
✓ Branch 1 taken 69374 times.
✓ Branch 2 taken 358587 times.
✓ Branch 3 taken 26275 times.
454236 const int inc = (w > h * 2 || h > w * 2) ? 3 : get_mip_inc(lc, intra_mip_flag);
1299 454236 return GET_CABAC(INTRA_MIP_FLAG + inc);
1300 }
1301
1302 108054 int ff_vvc_intra_mip_transposed_flag(VVCLocalContext *lc)
1303 {
1304 108054 return get_cabac_bypass(&lc->ep->cc);
1305 }
1306
1307 108054 int ff_vvc_intra_mip_mode(VVCLocalContext *lc)
1308 {
1309 108054 const int w = lc->cu->cb_width;
1310 108054 const int h = lc->cu->cb_height;
1311
4/4
✓ Branch 0 taken 31064 times.
✓ Branch 1 taken 76990 times.
✓ Branch 2 taken 15745 times.
✓ Branch 3 taken 15319 times.
200789 const int c_max = (w == 4 && h == 4) ? 15 :
1312
8/8
✓ Branch 0 taken 76990 times.
✓ Branch 1 taken 15745 times.
✓ Branch 2 taken 54021 times.
✓ Branch 3 taken 22969 times.
✓ Branch 4 taken 17926 times.
✓ Branch 5 taken 36095 times.
✓ Branch 6 taken 10587 times.
✓ Branch 7 taken 7339 times.
92735 ((w == 4 || h == 4) || (w == 8 && h == 8)) ? 7: 5;
1313 108054 return truncated_binary_decode(lc, c_max);
1314 }
1315
1316 430156 int ff_vvc_intra_luma_ref_idx(VVCLocalContext *lc)
1317 {
1318 int i;
1319
2/2
✓ Branch 0 taken 473623 times.
✓ Branch 1 taken 25483 times.
499106 for (i = 0; i < 2; i++) {
1320
2/2
✓ Branch 1 taken 404673 times.
✓ Branch 2 taken 68950 times.
473623 if (!GET_CABAC(INTRA_LUMA_REF_IDX + i))
1321 404673 return i;
1322 }
1323 25483 return i;
1324 }
1325
1326 362432 int ff_vvc_intra_subpartitions_mode_flag(VVCLocalContext *lc)
1327 {
1328 362432 return GET_CABAC(INTRA_SUBPARTITIONS_MODE_FLAG);
1329 }
1330
1331 488624 enum IspType ff_vvc_isp_split_type(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
1332 {
1333
2/2
✓ Branch 0 taken 426194 times.
✓ Branch 1 taken 62430 times.
488624 if (!intra_subpartitions_mode_flag)
1334 426194 return ISP_NO_SPLIT;
1335 62430 return 1 + GET_CABAC(INTRA_SUBPARTITIONS_SPLIT_FLAG);
1336 }
1337
1338 445157 int ff_vvc_intra_luma_mpm_flag(VVCLocalContext *lc)
1339 {
1340 445157 return GET_CABAC(INTRA_LUMA_MPM_FLAG);
1341 }
1342
1343 321174 int ff_vvc_intra_luma_not_planar_flag(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
1344 {
1345
2/2
✓ Branch 0 taken 273661 times.
✓ Branch 1 taken 47513 times.
321174 return GET_CABAC(INTRA_LUMA_NOT_PLANAR_FLAG + !intra_subpartitions_mode_flag);
1346 }
1347
1348 192694 int ff_vvc_intra_luma_mpm_idx(VVCLocalContext *lc)
1349 {
1350 int i;
1351
4/4
✓ Branch 0 taken 362290 times.
✓ Branch 1 taken 14233 times.
✓ Branch 3 taken 183829 times.
✓ Branch 4 taken 178461 times.
376523 for (i = 0; i < 4 && get_cabac_bypass(&lc->ep->cc); i++)
1352 /* nothing */;
1353 192694 return i;
1354 }
1355
1356 123983 int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc)
1357 {
1358 123983 return truncated_binary_decode(lc, 60);
1359 }
1360
1361 205954 int ff_vvc_cclm_mode_flag(VVCLocalContext *lc)
1362 {
1363 205954 return GET_CABAC(CCLM_MODE_FLAG);
1364 }
1365
1366 91531 int ff_vvc_cclm_mode_idx(VVCLocalContext *lc)
1367 {
1368
2/2
✓ Branch 1 taken 51262 times.
✓ Branch 2 taken 40269 times.
91531 if (!GET_CABAC(CCLM_MODE_IDX))
1369 51262 return 0;
1370 40269 return get_cabac_bypass(&lc->ep->cc) + 1;
1371 }
1372
1373 135849 int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc)
1374 {
1375
2/2
✓ Branch 1 taken 92837 times.
✓ Branch 2 taken 43012 times.
135849 if (!GET_CABAC(INTRA_CHROMA_PRED_MODE))
1376 92837 return 4;
1377 43012 return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1378 }
1379
1380 int ff_vvc_palette_predictor_run(VVCLocalContext *lc)
1381 {
1382 return kth_order_egk_decode(&lc->ep->cc, 0);
1383 }
1384
1385 int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc)
1386 {
1387 return kth_order_egk_decode(&lc->ep->cc, 0);
1388 }
1389
1390 int ff_vvc_new_palette_entries(VVCLocalContext *lc, const int bit_depth)
1391 {
1392 return fixed_length_decode(&lc->ep->cc, bit_depth);
1393 }
1394
1395 bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc)
1396 {
1397 return get_cabac_bypass(&lc->ep->cc);
1398 }
1399
1400 bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc)
1401 {
1402 return GET_CABAC(PALETTE_TRANSPOSE_FLAG);
1403 }
1404
1405 bool ff_vvc_run_copy_flag(VVCLocalContext *lc, const int prev_run_type, const int prev_run_position, const int cur_pos)
1406 {
1407 uint8_t run_left_lut[] = { 0, 1, 2, 3, 4 };
1408 uint8_t run_top_lut[] = { 5, 6, 6, 7, 7 };
1409
1410 int bin_dist = cur_pos - prev_run_position - 1;
1411 uint8_t *run_lut = prev_run_type == 1 ? run_top_lut : run_left_lut;
1412 uint8_t ctx_inc = bin_dist <= 4 ? run_lut[bin_dist] : run_lut[4];
1413
1414 return GET_CABAC(RUN_COPY_FLAG + ctx_inc);
1415 }
1416
1417 bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc)
1418 {
1419 return GET_CABAC(COPY_ABOVE_PALETTE_INDICES_FLAG);
1420 }
1421
1422 int ff_vvc_palette_idx_idc(VVCLocalContext *lc, const int max_palette_index, const bool adjust)
1423 {
1424 return truncated_binary_decode(lc, max_palette_index - adjust);
1425 }
1426
1427 int ff_vvc_palette_escape_val(VVCLocalContext *lc)
1428 {
1429 return kth_order_egk_decode(&lc->ep->cc, 5);
1430 }
1431
1432 209686 int ff_vvc_general_merge_flag(VVCLocalContext *lc)
1433 {
1434 209686 return GET_CABAC(GENERAL_MERGE_FLAG);
1435 }
1436
1437 313224 static int get_inter_flag_inc(VVCLocalContext *lc, const int x0, const int y0)
1438 {
1439 313224 uint8_t left_merge = 0, top_merge = 0;
1440 313224 uint8_t left_affine = 0, top_affine = 0;
1441 313224 const VVCFrameContext *fc = lc->fc;
1442
1443 313224 get_left_top(lc, &left_merge, &top_merge, x0, y0, fc->tab.msf, fc->tab.msf);
1444 313224 get_left_top(lc, &left_affine, &top_affine, x0, y0, fc->tab.iaf, fc->tab.iaf);
1445
4/4
✓ Branch 0 taken 272925 times.
✓ Branch 1 taken 40299 times.
✓ Branch 2 taken 9757 times.
✓ Branch 3 taken 263168 times.
313224 return (left_merge || left_affine) + (top_merge + top_affine);
1446 }
1447
1448 284568 int ff_vvc_merge_subblock_flag(VVCLocalContext *lc)
1449 {
1450 284568 const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0);
1451 284568 return GET_CABAC(MERGE_SUBBLOCK_FLAG + inc);
1452 }
1453
1454 50089 int ff_vvc_merge_subblock_idx(VVCLocalContext *lc, const int max_num_subblock_merge_cand)
1455 {
1456 int i;
1457
2/2
✓ Branch 1 taken 29855 times.
✓ Branch 2 taken 20234 times.
50089 if (!GET_CABAC(MERGE_SUBBLOCK_IDX))
1458 29855 return 0;
1459
4/4
✓ Branch 0 taken 33758 times.
✓ Branch 1 taken 2730 times.
✓ Branch 3 taken 16254 times.
✓ Branch 4 taken 17504 times.
36488 for (i = 1; i < max_num_subblock_merge_cand - 1 && get_cabac_bypass(&lc->ep->cc); i++)
1460 /* nothing */;
1461 20234 return i;
1462 }
1463
1464 218011 int ff_vvc_regular_merge_flag(VVCLocalContext *lc, const int cu_skip_flag)
1465 {
1466 218011 int inc = !cu_skip_flag;
1467 218011 return GET_CABAC(REGULAR_MERGE_FLAG + inc);
1468 }
1469
1470 252561 int ff_vvc_mmvd_merge_flag(VVCLocalContext *lc)
1471 {
1472 252561 return GET_CABAC(MMVD_MERGE_FLAG);
1473 }
1474
1475 55977 int ff_vvc_mmvd_cand_flag(VVCLocalContext *lc)
1476 {
1477 55977 return GET_CABAC(MMVD_CAND_FLAG);
1478 }
1479
1480 55977 static int mmvd_distance_idx_decode(VVCLocalContext *lc)
1481 {
1482 int i;
1483
2/2
✓ Branch 1 taken 14503 times.
✓ Branch 2 taken 41474 times.
55977 if (!GET_CABAC(MMVD_DISTANCE_IDX))
1484 14503 return 0;
1485
4/4
✓ Branch 0 taken 81142 times.
✓ Branch 1 taken 225 times.
✓ Branch 3 taken 39893 times.
✓ Branch 4 taken 41249 times.
81367 for (i = 1; i < 7 && get_cabac_bypass(&lc->ep->cc); i++)
1486 /* nothing */;
1487 41474 return i;
1488 }
1489
1490 55977 static int mmvd_direction_idx_decode(VVCLocalContext *lc)
1491 {
1492 55977 return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1493 }
1494
1495 55977 void ff_vvc_mmvd_offset_coding(VVCLocalContext *lc, Mv *mmvd_offset, const int ph_mmvd_fullpel_only_flag)
1496 {
1497
2/2
✓ Branch 0 taken 660 times.
✓ Branch 1 taken 55317 times.
55977 const int shift = ph_mmvd_fullpel_only_flag ? 4 : 2;
1498 55977 const int mmvd_distance = 1 << (mmvd_distance_idx_decode(lc) + shift);
1499 55977 const int mmvd_direction_idx = mmvd_direction_idx_decode(lc);
1500 55977 const int mmvd_signs[][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
1501 55977 mmvd_offset->x = mmvd_distance * mmvd_signs[mmvd_direction_idx][0];
1502 55977 mmvd_offset->y = mmvd_distance * mmvd_signs[mmvd_direction_idx][1];
1503 55977 }
1504
1505 231340 static PredMode get_luma_pred_mode(VVCLocalContext *lc)
1506 {
1507 231340 const VVCFrameContext *fc = lc->fc;
1508 231340 const CodingUnit *cu = lc->cu;
1509 PredMode pred_mode;
1510
1511
1/2
✓ Branch 0 taken 231340 times.
✗ Branch 1 not taken.
231340 if (cu->tree_type != DUAL_TREE_CHROMA) {
1512 231340 pred_mode = cu->pred_mode;
1513 } else {
1514 const int x_cb = cu->x0 >> fc->ps.sps->min_cb_log2_size_y;
1515 const int y_cb = cu->y0 >> fc->ps.sps->min_cb_log2_size_y;
1516 const int min_cb_width = fc->ps.pps->min_cb_width;
1517 pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_cb, y_cb);
1518 }
1519 231340 return pred_mode;
1520 }
1521
1522 231340 int ff_vvc_merge_idx(VVCLocalContext *lc)
1523 {
1524 231340 const VVCSPS *sps = lc->fc->ps.sps;
1525 231340 const int is_ibc = get_luma_pred_mode(lc) == MODE_IBC;
1526
2/2
✓ Branch 0 taken 13906 times.
✓ Branch 1 taken 217434 times.
231340 const int c_max = (is_ibc ? sps->max_num_ibc_merge_cand : sps->max_num_merge_cand) - 1;
1527 int i;
1528
1529
2/2
✓ Branch 1 taken 136794 times.
✓ Branch 2 taken 94546 times.
231340 if (!GET_CABAC(MERGE_IDX))
1530 136794 return 0;
1531
1532
4/4
✓ Branch 0 taken 181312 times.
✓ Branch 1 taken 10385 times.
✓ Branch 3 taken 97151 times.
✓ Branch 4 taken 84161 times.
191697 for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++)
1533 /* nothing */;
1534 94546 return i;
1535 }
1536
1537 25615 int ff_vvc_merge_gpm_partition_idx(VVCLocalContext *lc)
1538 {
1539 25615 return fixed_length_decode(&lc->ep->cc, 6);
1540 }
1541
1542 51230 int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx)
1543 {
1544 51230 const int c_max = lc->fc->ps.sps->max_num_gpm_merge_cand - idx - 1;
1545 int i;
1546
1547
2/2
✓ Branch 1 taken 28165 times.
✓ Branch 2 taken 23065 times.
51230 if (!GET_CABAC(MERGE_IDX))
1548 28165 return 0;
1549
1550
4/4
✓ Branch 0 taken 41020 times.
✓ Branch 1 taken 3879 times.
✓ Branch 3 taken 21834 times.
✓ Branch 4 taken 19186 times.
44899 for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++)
1551 /* nothing */;
1552
1553 23065 return i;
1554 }
1555
1556 19469 int ff_vvc_ciip_flag(VVCLocalContext *lc)
1557 {
1558 19469 return GET_CABAC(CIIP_FLAG);
1559 }
1560
1561 74951 PredFlag ff_vvc_pred_flag(VVCLocalContext *lc, const int is_b)
1562 {
1563 74951 const int w = lc->cu->cb_width;
1564 74951 const int h = lc->cu->cb_height;
1565
2/2
✓ Branch 0 taken 7045 times.
✓ Branch 1 taken 67906 times.
74951 if (!is_b)
1566 7045 return PF_L0;
1567
2/2
✓ Branch 0 taken 59238 times.
✓ Branch 1 taken 8668 times.
67906 if (w + h > 12) {
1568 59238 const int log2 = av_log2(w) + av_log2(h);
1569 59238 const int inc = 7 - ((1 + log2)>>1);
1570
2/2
✓ Branch 1 taken 20574 times.
✓ Branch 2 taken 38664 times.
59238 if (GET_CABAC(INTER_PRED_IDC + inc))
1571 20574 return PF_BI;
1572 }
1573 47332 return PF_L0 + GET_CABAC(INTER_PRED_IDC + 5);
1574 }
1575
1576 28656 int ff_vvc_inter_affine_flag(VVCLocalContext *lc)
1577 {
1578 28656 const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0);
1579 28656 return GET_CABAC(INTER_AFFINE_FLAG + inc);
1580 }
1581
1582 9103 int ff_vvc_cu_affine_type_flag(VVCLocalContext *lc)
1583 {
1584 9103 return GET_CABAC(CU_AFFINE_TYPE_FLAG);
1585 }
1586
1587 12092 int ff_vvc_sym_mvd_flag(VVCLocalContext *lc)
1588 {
1589 12092 return GET_CABAC(SYM_MVD_FLAG);
1590 }
1591
1592 66272 int ff_vvc_ref_idx_lx(VVCLocalContext *lc, const uint8_t nb_refs)
1593 {
1594 66272 const int c_max = nb_refs - 1;
1595 66272 const int max_ctx = FFMIN(c_max, 2);
1596 66272 int i = 0;
1597
1598
4/4
✓ Branch 0 taken 82333 times.
✓ Branch 1 taken 25615 times.
✓ Branch 3 taken 41676 times.
✓ Branch 4 taken 40657 times.
107948 while (i < max_ctx && GET_CABAC(REF_IDX_LX + i))
1599 41676 i++;
1600
2/2
✓ Branch 0 taken 14657 times.
✓ Branch 1 taken 51615 times.
66272 if (i == 2) {
1601
4/4
✓ Branch 0 taken 44898 times.
✓ Branch 1 taken 10367 times.
✓ Branch 3 taken 40608 times.
✓ Branch 4 taken 4290 times.
55265 while (i < c_max && get_cabac_bypass(&lc->ep->cc))
1602 40608 i++;
1603 }
1604 66272 return i;
1605 }
1606
1607 235848 int ff_vvc_abs_mvd_greater0_flag(VVCLocalContext *lc)
1608 {
1609 235848 return GET_CABAC(ABS_MVD_GREATER0_FLAG);
1610 }
1611
1612 164462 int ff_vvc_abs_mvd_greater1_flag(VVCLocalContext *lc)
1613 {
1614 164462 return GET_CABAC(ABS_MVD_GREATER1_FLAG);
1615 }
1616
1617 111369 int ff_vvc_abs_mvd_minus2(VVCLocalContext *lc)
1618 {
1619 111369 return limited_kth_order_egk_decode(&lc->ep->cc, 1, 15, 17);
1620 }
1621
1622 164462 int ff_vvc_mvd_sign_flag(VVCLocalContext *lc)
1623 {
1624 164462 return get_cabac_bypass(&lc->ep->cc);
1625 }
1626
1627 111219 int ff_vvc_mvp_lx_flag(VVCLocalContext *lc)
1628 {
1629 111219 return GET_CABAC(MVP_LX_FLAG);
1630 }
1631
1632 69293 static int amvr_flag(VVCLocalContext *lc, const int inter_affine_flag)
1633 {
1634 69293 return GET_CABAC(AMVR_FLAG + inter_affine_flag);
1635 }
1636
1637 57086 static int amvr_precision_idx(VVCLocalContext *lc, const int inc, const int c_max)
1638 {
1639 57086 int i = 0;
1640
2/2
✓ Branch 1 taken 13229 times.
✓ Branch 2 taken 43857 times.
57086 if (!GET_CABAC(AMVR_PRECISION_IDX + inc))
1641 13229 return 0;
1642 43857 i++;
1643
4/4
✓ Branch 0 taken 32761 times.
✓ Branch 1 taken 11096 times.
✓ Branch 3 taken 10704 times.
✓ Branch 4 taken 22057 times.
43857 if (i < c_max && GET_CABAC(AMVR_PRECISION_IDX + 1))
1644 10704 i++;
1645 43857 return i;
1646 }
1647
1648 84834 int ff_vvc_amvr_shift(VVCLocalContext *lc, const int inter_affine_flag,
1649 const PredMode pred_mode, const int has_amvr_flag)
1650 {
1651 84834 int amvr_shift = 2;
1652
2/2
✓ Branch 0 taken 79176 times.
✓ Branch 1 taken 5658 times.
84834 if (has_amvr_flag) {
1653
4/4
✓ Branch 0 taken 69293 times.
✓ Branch 1 taken 9883 times.
✓ Branch 3 taken 47203 times.
✓ Branch 4 taken 22090 times.
79176 if (pred_mode == MODE_IBC || amvr_flag(lc, inter_affine_flag)) {
1654 int idx;
1655
2/2
✓ Branch 0 taken 4504 times.
✓ Branch 1 taken 52582 times.
57086 if (inter_affine_flag) {
1656 4504 idx = amvr_precision_idx(lc, 2, 1);
1657 4504 amvr_shift = idx * 4;
1658
2/2
✓ Branch 0 taken 9883 times.
✓ Branch 1 taken 42699 times.
52582 } else if (pred_mode == MODE_IBC) {
1659 9883 idx = amvr_precision_idx(lc, 1, 1);
1660 9883 amvr_shift = 4 + idx * 2;
1661 } else {
1662 static const int shifts[] = {3, 4, 6};
1663 42699 idx = amvr_precision_idx(lc, 0, 2);
1664 42699 amvr_shift = shifts[idx];
1665 }
1666 }
1667 }
1668 84834 return amvr_shift;
1669 }
1670
1671 11245 int ff_vvc_bcw_idx(VVCLocalContext *lc, const int no_backward_pred_flag)
1672 {
1673
2/2
✓ Branch 0 taken 2438 times.
✓ Branch 1 taken 8807 times.
11245 const int c_max = no_backward_pred_flag ? 4 : 2;
1674 11245 int i = 1;
1675
2/2
✓ Branch 1 taken 6572 times.
✓ Branch 2 taken 4673 times.
11245 if (!GET_CABAC(BCW_IDX))
1676 6572 return 0;
1677
4/4
✓ Branch 0 taken 5525 times.
✓ Branch 1 taken 1836 times.
✓ Branch 3 taken 2688 times.
✓ Branch 4 taken 2837 times.
7361 while (i < c_max && get_cabac_bypass(&lc->ep->cc))
1678 2688 i++;
1679 4673 return i;
1680 }
1681
1682 388522 int ff_vvc_tu_cb_coded_flag(VVCLocalContext *lc)
1683 {
1684 388522 return GET_CABAC(TU_CB_CODED_FLAG + lc->cu->bdpcm_flag[1]);
1685 }
1686
1687 388522 int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag)
1688 {
1689
2/2
✓ Branch 0 taken 388519 times.
✓ Branch 1 taken 3 times.
388522 return GET_CABAC(TU_CR_CODED_FLAG + (lc->cu->bdpcm_flag[1] ? 2 : tu_cb_coded_flag));
1690 }
1691
1692 791398 int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc)
1693 {
1694 791398 const CodingUnit *cu = lc->cu;
1695 int inc;
1696
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 791360 times.
791398 if (cu->bdpcm_flag[0])
1697 38 inc = 1;
1698
2/2
✓ Branch 0 taken 599023 times.
✓ Branch 1 taken 192337 times.
791360 else if (cu->isp_split_type == ISP_NO_SPLIT)
1699 599023 inc = 0;
1700 else
1701 192337 inc = 2 + lc->parse.prev_tu_cbf_y;
1702 791398 lc->parse.prev_tu_cbf_y = GET_CABAC(TU_Y_CODED_FLAG + inc);
1703 791398 return lc->parse.prev_tu_cbf_y;
1704 }
1705
1706 int ff_vvc_cu_act_enabled_flag(VVCLocalContext *lc)
1707 {
1708 return GET_CABAC(CU_ACT_ENABLED_FLAG);
1709 }
1710
1711 1888 int ff_vvc_cu_qp_delta_abs(VVCLocalContext *lc)
1712 {
1713 int v, i, k;
1714
2/2
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 1106 times.
1888 if (!GET_CABAC(CU_QP_DELTA_ABS))
1715 782 return 0;
1716
1717 // prefixVal
1718
4/4
✓ Branch 0 taken 2334 times.
✓ Branch 1 taken 35 times.
✓ Branch 3 taken 1263 times.
✓ Branch 4 taken 1071 times.
2369 for (v = 1; v < 5 && GET_CABAC(CU_QP_DELTA_ABS + 1); v++)
1719 /* nothing */;
1720
2/2
✓ Branch 0 taken 1071 times.
✓ Branch 1 taken 35 times.
1106 if (v < 5)
1721 1071 return v;
1722
1723 // 9.3.3.5 k-th order Exp-Golomb binarization process
1724 // suffixVal
1725
1726 // CuQpDeltaVal shall in the range of −( 32 + QpBdOffset / 2 ) to +( 31 + QpBdOffset / 2 )
1727 // so k = 6 should enough
1728
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++)
1729 /* nothing */;
1730 35 i = (1 << k) - 1;
1731 35 v = 0;
1732
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 35 times.
66 while (k--)
1733 31 v = (v << 1) + get_cabac_bypass(&lc->ep->cc);
1734 35 v += i;
1735
1736 35 return v + 5;
1737 }
1738
1739 1106 int ff_vvc_cu_qp_delta_sign_flag(VVCLocalContext *lc)
1740 {
1741 1106 return get_cabac_bypass(&lc->ep->cc);
1742 }
1743
1744 1029 int ff_vvc_cu_chroma_qp_offset_flag(VVCLocalContext *lc)
1745 {
1746 1029 return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG);
1747 }
1748
1749 931 int ff_vvc_cu_chroma_qp_offset_idx(VVCLocalContext *lc)
1750 {
1751 931 const int c_max = lc->fc->ps.pps->r->pps_chroma_qp_offset_list_len_minus1;
1752 int i;
1753
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++)
1754 /* nothing */;
1755 931 return i;
1756 }
1757
1758 1846578 static av_always_inline int last_significant_coeff_xy_prefix(VVCLocalContext *lc,
1759 const int log2_tb_size, const int log2_zo_tb_size, const int c_idx, const int ctx)
1760 {
1761 1846578 int i = 0;
1762 1846578 int max = (log2_zo_tb_size << 1) - 1;
1763 int ctx_offset, ctx_shift;
1764
2/2
✓ Branch 0 taken 15847 times.
✓ Branch 1 taken 1830731 times.
1846578 if (!log2_tb_size)
1765 15847 return 0;
1766
2/2
✓ Branch 0 taken 1328125 times.
✓ Branch 1 taken 502606 times.
1830731 if (!c_idx) {
1767 1328125 const int offset_y[] = {0, 0, 3, 6, 10, 15};
1768 1328125 ctx_offset = offset_y[log2_tb_size - 1];
1769 1328125 ctx_shift = (log2_tb_size + 1) >> 2;
1770 } else {
1771 502606 const int shifts[] = {0, 0, 0, 1, 2, 2, 2};
1772 502606 ctx_offset = 20;
1773 502606 ctx_shift = shifts[log2_tb_size];
1774 }
1775
4/4
✓ Branch 0 taken 4845007 times.
✓ Branch 1 taken 290083 times.
✓ Branch 3 taken 3304359 times.
✓ Branch 4 taken 1540648 times.
5135090 while (i < max && GET_CABAC(ctx + (i >> ctx_shift) + ctx_offset))
1776 3304359 i++;
1777 1830731 return i;
1778 }
1779
1780 923289 static av_always_inline int last_significant_coeff_x_prefix_decode(VVCLocalContext *lc,
1781 const int log2_tb_width, const int log2_zo_tb_width, const int c_idx)
1782 {
1783 923289 return last_significant_coeff_xy_prefix(lc, log2_tb_width, log2_zo_tb_width, c_idx, LAST_SIG_COEFF_X_PREFIX);
1784 }
1785
1786 923289 static av_always_inline int last_significant_coeff_y_prefix_decode(VVCLocalContext *lc,
1787 const int log2_tb_height, const int log2_zo_tb_height, const int c_idx)
1788 {
1789 923289 return last_significant_coeff_xy_prefix(lc, log2_tb_height, log2_zo_tb_height, c_idx, LAST_SIG_COEFF_Y_PREFIX);
1790 }
1791
1792 357417 static av_always_inline int last_sig_coeff_suffix_decode(VVCLocalContext *lc,
1793 const int last_significant_coeff_y_prefix)
1794 {
1795 357417 const int length = (last_significant_coeff_y_prefix >> 1) - 1;
1796 357417 int value = get_cabac_bypass(&lc->ep->cc);
1797
1798
2/2
✓ Branch 0 taken 150810 times.
✓ Branch 1 taken 357417 times.
508227 for (int i = 1; i < length; i++)
1799 150810 value = (value << 1) | get_cabac_bypass(&lc->ep->cc);
1800 357417 return value;
1801 }
1802
1803 149811 int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, const int tu_cb_coded_flag, const int tu_cr_coded_flag)
1804 {
1805 149811 return GET_CABAC(TU_JOINT_CBCR_RESIDUAL_FLAG + 2 * tu_cb_coded_flag + tu_cr_coded_flag - 1);
1806 }
1807
1808 637997 int ff_vvc_transform_skip_flag(VVCLocalContext *lc, const int inc)
1809 {
1810 637997 return GET_CABAC(TRANSFORM_SKIP_FLAG + inc);
1811 }
1812
1813 //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1
1814 38897497 static int get_local_sum(const int *level, const int w, const int h,
1815 const int xc, const int yc, const int hist_value)
1816 {
1817 38897497 int loc_sum = 3 * hist_value;
1818 38897497 level += w * yc + xc;
1819
2/2
✓ Branch 0 taken 37473513 times.
✓ Branch 1 taken 1423984 times.
38897497 if (xc < w - 1) {
1820 37473513 loc_sum += level[1];
1821
2/2
✓ Branch 0 taken 35380664 times.
✓ Branch 1 taken 2092849 times.
37473513 if (xc < w - 2)
1822 35380664 loc_sum += level[2] - hist_value;
1823
2/2
✓ Branch 0 taken 34637012 times.
✓ Branch 1 taken 2836501 times.
37473513 if (yc < h - 1)
1824 34637012 loc_sum += level[w + 1] - hist_value;
1825 }
1826
2/2
✓ Branch 0 taken 36059884 times.
✓ Branch 1 taken 2837613 times.
38897497 if (yc < h - 1) {
1827 36059884 loc_sum += level[w];
1828
2/2
✓ Branch 0 taken 32702148 times.
✓ Branch 1 taken 3357736 times.
36059884 if (yc < h - 2)
1829 32702148 loc_sum += level[w << 1] - hist_value;
1830 }
1831 38897497 return loc_sum;
1832 }
1833
1834 //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1
1835 903166 static int get_local_sum_ts(const int *level, const int w, const int h, const int xc, const int yc)
1836 {
1837 903166 int loc_sum = 0;
1838 903166 level += w * yc + xc;
1839
2/2
✓ Branch 0 taken 790176 times.
✓ Branch 1 taken 112990 times.
903166 if (xc > 0)
1840 790176 loc_sum += level[-1];
1841
2/2
✓ Branch 0 taken 790105 times.
✓ Branch 1 taken 113061 times.
903166 if (yc > 0)
1842 790105 loc_sum += level[-w];
1843 903166 return loc_sum;
1844 }
1845
1846 10906479 static int get_gtx_flag_inc(const ResidualCoding* rc, const int xc, const int yc, const int last)
1847 {
1848 10906479 const TransformBlock *tb = rc->tb;
1849 int inc;
1850
2/2
✓ Branch 0 taken 923289 times.
✓ Branch 1 taken 9983190 times.
10906479 if (last) {
1851 923289 const int incs[] = {0, 21, 21};
1852 923289 inc = incs[tb->c_idx];
1853 } else {
1854 9983190 const int d = xc + yc;
1855 9983190 const int local_sum_sig = get_local_sum(rc->sig_coeff_flag,
1856 9983190 tb->tb_width,tb->tb_height, xc, yc, rc->hist_value);
1857 9983190 const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1,
1858 9983190 tb->tb_width, tb->tb_height, xc, yc, rc->hist_value);
1859 9983190 const int offset = FFMIN(loc_sum_abs_pass1 - local_sum_sig, 4);
1860
1861
2/2
✓ Branch 0 taken 7146448 times.
✓ Branch 1 taken 2836742 times.
9983190 if (!tb->c_idx)
1862
6/6
✓ Branch 0 taken 6683734 times.
✓ Branch 1 taken 462714 times.
✓ Branch 2 taken 5230063 times.
✓ Branch 3 taken 1453671 times.
✓ Branch 4 taken 3254928 times.
✓ Branch 5 taken 1975135 times.
7146448 inc = 1 + offset + (!d ? 15 : (d < 3 ? 10 : (d < 10 ? 5 : 0)));
1863 else
1864
2/2
✓ Branch 0 taken 150176 times.
✓ Branch 1 taken 2686566 times.
2836742 inc = 22 + offset + (!d ? 5 : 0);
1865 }
1866 10906479 return inc;
1867 }
1868
1869 13185889 static int abs_level_gtx_flag_decode(VVCLocalContext *lc, const int inc)
1870 {
1871 13185889 return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
1872 }
1873
1874 2279410 static int par_level_flag_decode(VVCLocalContext *lc, const int inc)
1875 {
1876 2279410 return GET_CABAC(PAR_LEVEL_FLAG + inc);
1877 }
1878
1879 90673 static int par_level_flag_ts_decode(VVCLocalContext *lc)
1880 {
1881 90673 const int inc = 32;
1882 90673 return GET_CABAC(PAR_LEVEL_FLAG + inc);
1883 }
1884
1885 1049472 static int sb_coded_flag_decode(VVCLocalContext *lc, const uint8_t *sb_coded_flag,
1886 const ResidualCoding *rc, const int xs, const int ys)
1887 {
1888 1049472 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1889 1049472 const TransformBlock *tb = rc->tb;
1890 1049472 const int w = rc->width_in_sbs;
1891 1049472 const int h = rc->height_in_sbs;
1892 int inc;
1893
1894
3/4
✓ Branch 0 taken 132390 times.
✓ Branch 1 taken 917082 times.
✓ Branch 2 taken 132390 times.
✗ Branch 3 not taken.
1049472 if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) {
1895
2/2
✓ Branch 0 taken 80035 times.
✓ Branch 1 taken 52355 times.
132390 const int left = xs > 0 ? sb_coded_flag[-1] : 0;
1896
2/2
✓ Branch 0 taken 80048 times.
✓ Branch 1 taken 52342 times.
132390 const int above = ys > 0 ? sb_coded_flag[-w] : 0;
1897 132390 inc = left + above + 4;
1898 } else {
1899
2/2
✓ Branch 0 taken 797952 times.
✓ Branch 1 taken 119130 times.
917082 const int right = (xs < w - 1) ? sb_coded_flag[1] : 0;
1900
2/2
✓ Branch 0 taken 700144 times.
✓ Branch 1 taken 216938 times.
917082 const int bottom = (ys < h - 1) ? sb_coded_flag[w] : 0;
1901
2/2
✓ Branch 0 taken 330985 times.
✓ Branch 1 taken 586097 times.
917082 inc = (right | bottom) + (tb->c_idx ? 2 : 0);
1902 }
1903 1049472 return GET_CABAC(SB_CODED_FLAG + inc);
1904 }
1905
1906 18855954 static int sig_coeff_flag_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1907 {
1908 18855954 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1909 18855954 const TransformBlock *tb = rc->tb;
1910 int inc;
1911
1912
3/4
✓ Branch 0 taken 903166 times.
✓ Branch 1 taken 17952788 times.
✓ Branch 2 taken 903166 times.
✗ Branch 3 not taken.
18855954 if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) {
1913 903166 const int local_num_sig = get_local_sum_ts(rc->sig_coeff_flag, tb->tb_width, tb->tb_height, xc, yc);
1914 903166 inc = 60 + local_num_sig;
1915 } else {
1916 17952788 const int d = xc + yc;
1917 17952788 const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1,
1918 17952788 tb->tb_width, tb->tb_height, xc, yc, 0);
1919
1920
2/2
✓ Branch 0 taken 12589895 times.
✓ Branch 1 taken 5362893 times.
17952788 if (!tb->c_idx) {
1921
4/4
✓ Branch 0 taken 11147940 times.
✓ Branch 1 taken 1441955 times.
✓ Branch 2 taken 3266696 times.
✓ Branch 3 taken 7881244 times.
12589895 inc = 12 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + ((d < 2) ? 8 : (d < 5 ? 4 : 0));
1922 } else {
1923
2/2
✓ Branch 0 taken 486087 times.
✓ Branch 1 taken 4876806 times.
5362893 inc = 36 + 8 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + (d < 2 ? 4 : 0);
1924 }
1925 }
1926 18855954 return GET_CABAC(SIG_COEFF_FLAG + inc);
1927 }
1928
1929 978329 static int abs_get_rice_param(VVCLocalContext *lc, const ResidualCoding* rc,
1930 const int xc, const int yc, const int base_level)
1931 {
1932 978329 const VVCSPS *sps = lc->fc->ps.sps;
1933 978329 const TransformBlock* tb = rc->tb;
1934 978329 const int rice_params[] = {
1935 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2,
1936 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
1937 };
1938 int loc_sum_abs;
1939 int shift_val;
1940
1941 978329 loc_sum_abs = get_local_sum(rc->abs_level, tb->tb_width, tb->tb_height, xc,
1942 978329 yc, rc->hist_value);
1943
1944
1/2
✓ Branch 0 taken 978329 times.
✗ Branch 1 not taken.
978329 if (!sps->r->sps_rrc_rice_extension_flag) {
1945 978329 shift_val = 0;
1946 } else {
1947 shift_val = (av_log2(FFMAX(FFMIN(loc_sum_abs, 2048), 8)) - 3) & ~1;
1948 }
1949
1950 978329 loc_sum_abs = av_clip_uintp2((loc_sum_abs >> shift_val) - base_level * 5, 5);
1951
1952 978329 return rice_params[loc_sum_abs] + shift_val;
1953 }
1954
1955 1029134 static int abs_decode(VVCLocalContext *lc, const int c_rice_param)
1956 {
1957 1029134 const VVCSPS *sps = lc->fc->ps.sps;
1958 1029134 const int MAX_BIN = 6;
1959 1029134 int prefix = 0;
1960 1029134 int suffix = 0;
1961
1962
4/4
✓ Branch 0 taken 2378751 times.
✓ Branch 1 taken 83438 times.
✓ Branch 3 taken 1433055 times.
✓ Branch 4 taken 945696 times.
2462189 while (prefix < MAX_BIN && get_cabac_bypass(&lc->ep->cc))
1963 1433055 prefix++;
1964
2/2
✓ Branch 0 taken 945696 times.
✓ Branch 1 taken 83438 times.
1029134 if (prefix < MAX_BIN) {
1965
2/2
✓ Branch 0 taken 654007 times.
✓ Branch 1 taken 945696 times.
1599703 for (int i = 0; i < c_rice_param; i++) {
1966 654007 suffix = (suffix << 1) | get_cabac_bypass(&lc->ep->cc);
1967 }
1968 } else {
1969 83438 suffix = limited_kth_order_egk_decode(&lc->ep->cc,
1970 c_rice_param + 1,
1971 83438 26 - sps->log2_transform_range,
1972 83438 sps->log2_transform_range);
1973 }
1974 1029134 return suffix + (prefix << c_rice_param);
1975 }
1976
1977 622554 static int abs_remainder_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1978 {
1979 622554 const VVCSPS *sps = lc->fc->ps.sps;
1980 622554 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1981 622554 const int base_level[][2][2] = {
1982 { {4, 4}, {4, 4} },
1983 { {3, 2}, {2, 1} }
1984 };
1985 622554 const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc,
1986 622554 base_level[sps->r->sps_rrc_rice_extension_flag][sps->bit_depth > 12][IS_I(rsh)]);
1987 622554 const int rem = abs_decode(lc, c_rice_param);
1988
1989 622554 return rem;
1990 }
1991
1992 50805 static int abs_remainder_ts_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1993 {
1994 50805 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1995 50805 const int c_rice_param = rsh->sh_ts_residual_coding_rice_idx_minus1 + 1;
1996 50805 const int rem = abs_decode(lc, c_rice_param);
1997
1998 50805 return rem;
1999 }
2000
2001 11219470 static int coeff_sign_flag_decode(VVCLocalContext *lc)
2002 {
2003 11219470 return get_cabac_bypass(&lc->ep->cc);
2004 }
2005
2006 //9.3.4.2.10 Derivation process of ctxInc for the syntax element coeff_sign_flag for transform skip mode
2007 231525 static int coeff_sign_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
2008 {
2009 231525 const TransformBlock *tb = rc->tb;
2010 231525 const int w = tb->tb_width;
2011 231525 const int *level = rc->coeff_sign_level + yc * w + xc;
2012
2/2
✓ Branch 0 taken 207101 times.
✓ Branch 1 taken 24424 times.
231525 const int left_sign = xc ? level[-1] : 0;
2013
2/2
✓ Branch 0 taken 206531 times.
✓ Branch 1 taken 24994 times.
231525 const int above_sign = yc ? level[-w] : 0;
2014 231525 const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx];
2015 int inc;
2016
2017
2/2
✓ Branch 0 taken 83717 times.
✓ Branch 1 taken 147808 times.
231525 if (left_sign == -above_sign)
2018
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 83698 times.
83717 inc = bdpcm_flag ? 3 : 0;
2019
4/4
✓ Branch 0 taken 89881 times.
✓ Branch 1 taken 57927 times.
✓ Branch 2 taken 61208 times.
✓ Branch 3 taken 28673 times.
147808 else if (left_sign >= 0 && above_sign >= 0)
2020
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 61205 times.
61208 inc = bdpcm_flag ? 4 : 1;
2021 else
2022
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 86589 times.
86600 inc = bdpcm_flag ? 5 : 2;
2023 231525 return GET_CABAC(COEFF_SIGN_FLAG + inc);
2024 }
2025
2026 231525 static int abs_level_gt1_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
2027 {
2028 231525 const TransformBlock *tb = rc->tb;
2029 231525 const int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc;
2030 int inc;
2031
2032
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 231492 times.
231525 if (cu->bdpcm_flag[tb->c_idx]) {
2033 33 inc = 67;
2034 } else {
2035
2/2
✓ Branch 0 taken 207070 times.
✓ Branch 1 taken 24422 times.
231492 const int l = xc > 0 ? sig_coeff_flag[-1] : 0;
2036
2/2
✓ Branch 0 taken 206504 times.
✓ Branch 1 taken 24988 times.
231492 const int a = yc > 0 ? sig_coeff_flag[-tb->tb_width] : 0;
2037 231492 inc = 64 + a + l;
2038 }
2039 231525 return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
2040 }
2041
2042 162808 static int abs_level_gtx_flag_ts_decode(VVCLocalContext *lc, const int j)
2043 {
2044 162808 const int inc = 67 + j;
2045 162808 return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
2046 }
2047
2048 static const uint8_t qstate_translate_table[][2] = {
2049 { 0, 2 }, { 2, 0 }, { 1, 3 }, { 3, 1 }
2050 };
2051
2052 355775 static int dec_abs_level_decode(VVCLocalContext *lc, const ResidualCoding *rc,
2053 const int xc, const int yc, int *abs_level)
2054 {
2055 355775 const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc, 0);
2056 355775 const int dec_abs_level = abs_decode(lc, c_rice_param);
2057
2/2
✓ Branch 0 taken 215040 times.
✓ Branch 1 taken 140735 times.
355775 const int zero_pos = (rc->qstate < 2 ? 1 : 2) << c_rice_param;
2058
2059 355775 *abs_level = 0;
2060
2/2
✓ Branch 0 taken 323999 times.
✓ Branch 1 taken 31776 times.
355775 if (dec_abs_level != zero_pos) {
2061 323999 *abs_level = dec_abs_level;
2062
2/2
✓ Branch 0 taken 192723 times.
✓ Branch 1 taken 131276 times.
323999 if (dec_abs_level < zero_pos)
2063 192723 *abs_level += 1;
2064 }
2065 355775 return dec_abs_level;
2066 }
2067
2068 978329 static void ep_update_hist(EntryPoint *ep, ResidualCoding *rc,
2069 const int remainder, const int addin)
2070 {
2071 978329 int *stat = ep->stat_coeff + rc->tb->c_idx;
2072
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 978329 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
978329 if (rc->update_hist && remainder > 0) {
2073 *stat = (*stat + av_log2(remainder) + addin) >> 1;
2074 rc->update_hist = 0;
2075 }
2076 978329 }
2077
2078 952114 static void init_residual_coding(const VVCLocalContext *lc, ResidualCoding *rc,
2079 const int log2_zo_tb_width, const int log2_zo_tb_height,
2080 TransformBlock *tb)
2081 {
2082 952114 const VVCSPS *sps = lc->fc->ps.sps;
2083
2/2
✓ Branch 0 taken 99029 times.
✓ Branch 1 taken 853085 times.
952114 int log2_sb_w = (FFMIN(log2_zo_tb_width, log2_zo_tb_height ) < 2 ? 1 : 2 );
2084 952114 int log2_sb_h = log2_sb_w;
2085
2086
2/2
✓ Branch 0 taken 943095 times.
✓ Branch 1 taken 9019 times.
952114 if ( log2_zo_tb_width + log2_zo_tb_height > 3 ) {
2087
2/2
✓ Branch 0 taken 20532 times.
✓ Branch 1 taken 922563 times.
943095 if ( log2_zo_tb_width < 2 ) {
2088 20532 log2_sb_w = log2_zo_tb_width;
2089 20532 log2_sb_h = 4 - log2_sb_w;
2090
2/2
✓ Branch 0 taken 69478 times.
✓ Branch 1 taken 853085 times.
922563 } else if ( log2_zo_tb_height < 2 ) {
2091 69478 log2_sb_h = log2_zo_tb_height;
2092 69478 log2_sb_w = 4 - log2_sb_h;
2093 }
2094 }
2095 952114 rc->log2_sb_w = log2_sb_w;
2096 952114 rc->log2_sb_h = log2_sb_h;
2097 952114 rc->num_sb_coeff = 1 << (log2_sb_w + log2_sb_h);
2098 952114 rc->last_sub_block = ( 1 << ( log2_zo_tb_width + log2_zo_tb_height - (log2_sb_w + log2_sb_h))) - 1;
2099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 952114 times.
952114 rc->hist_value = sps->r->sps_persistent_rice_adaptation_enabled_flag ? (1 << lc->ep->stat_coeff[tb->c_idx]) : 0;
2100 952114 rc->update_hist = sps->r->sps_persistent_rice_adaptation_enabled_flag ? 1 : 0;
2101 952114 rc->rem_bins_pass1 = (( 1 << ( log2_zo_tb_width + log2_zo_tb_height)) * 7 ) >> 2;
2102
2103
2104 952114 rc->sb_scan_x_off = ff_vvc_diag_scan_x[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h];
2105 952114 rc->sb_scan_y_off = ff_vvc_diag_scan_y[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h];
2106
2107 952114 rc->scan_x_off = ff_vvc_diag_scan_x[log2_sb_w][log2_sb_h];
2108 952114 rc->scan_y_off = ff_vvc_diag_scan_y[log2_sb_w][log2_sb_h];
2109
2110 952114 rc->infer_sb_cbf = 1;
2111
2112 952114 rc->width_in_sbs = (1 << (log2_zo_tb_width - log2_sb_w));
2113 952114 rc->height_in_sbs = (1 << (log2_zo_tb_height - log2_sb_h));
2114 952114 rc->nb_sbs = rc->width_in_sbs * rc->height_in_sbs;
2115
2116 952114 rc->last_scan_pos = rc->num_sb_coeff;
2117 952114 rc->qstate = 0;
2118
2119 952114 rc->tb = tb;
2120 952114 }
2121
2122 145593 static int residual_ts_coding_subblock(VVCLocalContext *lc, ResidualCoding* rc, const int i)
2123 {
2124 145593 const CodingUnit *cu = lc->cu;
2125 145593 TransformBlock *tb = rc->tb;
2126 145593 const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx];
2127 145593 const int xs = rc->sb_scan_x_off[i];
2128 145593 const int ys = rc->sb_scan_y_off[i];
2129 145593 uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
2130 145593 int infer_sb_sig_coeff_flag = 1;
2131 145593 int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -1, n;
2132 int abs_level_gtx_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];
2133 int abs_level_pass2[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; ///< AbsLevelPass2
2134
2135
4/4
✓ Branch 0 taken 28825 times.
✓ Branch 1 taken 116768 times.
✓ Branch 2 taken 15622 times.
✓ Branch 3 taken 13203 times.
145593 if (i != rc->last_sub_block || !rc->infer_sb_cbf)
2136 132390 *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
2137 else
2138 13203 *sb_coded_flag = 1;
2139
4/4
✓ Branch 0 taken 57878 times.
✓ Branch 1 taken 87715 times.
✓ Branch 2 taken 37152 times.
✓ Branch 3 taken 20726 times.
145593 if (*sb_coded_flag && i < rc->last_sub_block)
2140 37152 rc->infer_sb_cbf = 0;
2141
2142 //first scan pass
2143
4/4
✓ Branch 0 taken 2308810 times.
✓ Branch 1 taken 141641 times.
✓ Branch 2 taken 2304858 times.
✓ Branch 3 taken 3952 times.
2450451 for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
2144 2304858 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2145 2304858 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2146 2304858 const int off = yc * tb->tb_width + xc;
2147 2304858 int *sig_coeff_flag = rc->sig_coeff_flag + off;
2148 2304858 int *abs_level_pass1 = rc->abs_level_pass1 + off;
2149 2304858 int *coeff_sign_level = rc->coeff_sign_level + off;
2150 2304858 int par_level_flag = 0;
2151
2152 2304858 abs_level_gtx_flag[n] = 0;
2153 2304858 last_scan_pos_pass1 = n;
2154
6/6
✓ Branch 0 taken 906234 times.
✓ Branch 1 taken 1398624 times.
✓ Branch 2 taken 54218 times.
✓ Branch 3 taken 852016 times.
✓ Branch 4 taken 51150 times.
✓ Branch 5 taken 3068 times.
2304858 if (*sb_coded_flag && (n != rc->num_sb_coeff - 1 || !infer_sb_sig_coeff_flag)) {
2155 903166 *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
2156 903166 rc->rem_bins_pass1--;
2157
2/2
✓ Branch 0 taken 228457 times.
✓ Branch 1 taken 674709 times.
903166 if (*sig_coeff_flag)
2158 228457 infer_sb_sig_coeff_flag = 0;
2159 } else {
2160
5/6
✓ Branch 0 taken 90491 times.
✓ Branch 1 taken 1311201 times.
✓ Branch 2 taken 90491 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3068 times.
✓ Branch 5 taken 87423 times.
1401692 *sig_coeff_flag = (n == rc->num_sb_coeff - 1) && infer_sb_sig_coeff_flag && *sb_coded_flag;
2161 }
2162 2304858 *coeff_sign_level = 0;
2163
2/2
✓ Branch 0 taken 231525 times.
✓ Branch 1 taken 2073333 times.
2304858 if (*sig_coeff_flag) {
2164 231525 *coeff_sign_level = 1 - 2 * coeff_sign_flag_ts_decode(lc, cu, rc, xc, yc);
2165 231525 abs_level_gtx_flag[n] = abs_level_gt1_flag_ts_decode(lc, cu, rc, xc, yc);
2166 231525 rc->rem_bins_pass1 -= 2;
2167
2/2
✓ Branch 0 taken 90673 times.
✓ Branch 1 taken 140852 times.
231525 if (abs_level_gtx_flag[n]) {
2168 90673 par_level_flag = par_level_flag_ts_decode(lc);
2169 90673 rc->rem_bins_pass1--;
2170 }
2171 }
2172 2304858 *abs_level_pass1 = *sig_coeff_flag + par_level_flag + abs_level_gtx_flag[n];
2173 }
2174
2175 //greater than x scan pass
2176
4/4
✓ Branch 0 taken 2250839 times.
✓ Branch 1 taken 139754 times.
✓ Branch 2 taken 2245000 times.
✓ Branch 3 taken 5839 times.
2390593 for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
2177 2245000 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2178 2245000 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2179 2245000 const int off = yc * tb->tb_width + xc;
2180
2181 2245000 abs_level_pass2[n] = rc->abs_level_pass1[off];
2182
4/4
✓ Branch 0 taken 2386781 times.
✓ Branch 1 taken 21027 times.
✓ Branch 2 taken 162808 times.
✓ Branch 3 taken 2223973 times.
2407808 for (int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) {
2183 162808 abs_level_gtx_flag[n] = abs_level_gtx_flag_ts_decode(lc, j);
2184 162808 abs_level_pass2[n] += abs_level_gtx_flag[n] << 1;
2185 162808 rc->rem_bins_pass1--;
2186 }
2187 2245000 last_scan_pos_pass2 = n;
2188 }
2189
2190 /* remainder scan pass */
2191
2/2
✓ Branch 0 taken 2329200 times.
✓ Branch 1 taken 145593 times.
2474793 for (n = 0; n < rc->num_sb_coeff; n++) {
2192 2329200 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2193 2329200 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2194 2329200 const int off = yc * tb->tb_width + xc;
2195 2329200 const int *abs_level_pass1 = rc->abs_level_pass1 + off;
2196 2329200 int *abs_level = rc->abs_level + off;
2197 2329200 int *coeff_sign_level = rc->coeff_sign_level + off;
2198 2329200 int abs_remainder = 0;
2199
2200
6/6
✓ Branch 0 taken 2245000 times.
✓ Branch 1 taken 84200 times.
✓ Branch 2 taken 2226701 times.
✓ Branch 3 taken 18299 times.
✓ Branch 4 taken 84200 times.
✓ Branch 5 taken 2226701 times.
2329200 if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) ||
2201
2/2
✓ Branch 0 taken 59858 times.
✓ Branch 1 taken 24342 times.
84200 (n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 &&
2202
4/4
✓ Branch 0 taken 47022 times.
✓ Branch 1 taken 12836 times.
✓ Branch 2 taken 24342 times.
✓ Branch 3 taken 2273723 times.
2310901 *abs_level_pass1 >= 2) ||
2203
2/2
✓ Branch 0 taken 19670 times.
✓ Branch 1 taken 4672 times.
24342 (n > last_scan_pos_pass1 && *sb_coded_flag))
2204 50805 abs_remainder = abs_remainder_ts_decode(lc, rc, xc, yc);
2205
2/2
✓ Branch 0 taken 2245000 times.
✓ Branch 1 taken 84200 times.
2329200 if (n <= last_scan_pos_pass2) {
2206 2245000 *abs_level = abs_level_pass2[n] + 2 * abs_remainder;
2207
2/2
✓ Branch 0 taken 59858 times.
✓ Branch 1 taken 24342 times.
84200 } else if (n <= last_scan_pos_pass1) {
2208 59858 *abs_level = *abs_level_pass1 + 2 * abs_remainder;
2209 } else {
2210 24342 *abs_level = abs_remainder;
2211
2/2
✓ Branch 0 taken 11439 times.
✓ Branch 1 taken 12903 times.
24342 if (abs_remainder) {
2212 //n > lastScanPosPass1
2213 11439 *coeff_sign_level = 1 - 2 * coeff_sign_flag_decode(lc);
2214 }
2215 }
2216
4/4
✓ Branch 0 taken 2328864 times.
✓ Branch 1 taken 336 times.
✓ Branch 2 taken 2304522 times.
✓ Branch 3 taken 24342 times.
2329200 if (!bdpcm_flag && n <= last_scan_pos_pass1) {
2217
2/2
✓ Branch 0 taken 2060836 times.
✓ Branch 1 taken 243686 times.
2304522 const int left = xc > 0 ? abs_level[-1] : 0;
2218
2/2
✓ Branch 0 taken 2060679 times.
✓ Branch 1 taken 243843 times.
2304522 const int above = yc > 0 ? abs_level[-tb->tb_width] : 0;
2219 2304522 const int pred = FFMAX(left, above);
2220
2221
4/4
✓ Branch 0 taken 140829 times.
✓ Branch 1 taken 2163693 times.
✓ Branch 2 taken 84234 times.
✓ Branch 3 taken 56595 times.
2304522 if (*abs_level == 1 && pred > 0)
2222 84234 *abs_level = pred;
2223
4/4
✓ Branch 0 taken 147258 times.
✓ Branch 1 taken 2073030 times.
✓ Branch 2 taken 37350 times.
✓ Branch 3 taken 109908 times.
2220288 else if (*abs_level > 0 && *abs_level <= pred)
2224 37350 (*abs_level)--;
2225 }
2226
2/2
✓ Branch 0 taken 242964 times.
✓ Branch 1 taken 2086236 times.
2329200 if (*abs_level) {
2227 242964 tb->coeffs[off] = *coeff_sign_level * *abs_level;
2228 242964 tb->max_scan_x = FFMAX(xc, tb->max_scan_x);
2229 242964 tb->max_scan_y = FFMAX(yc, tb->max_scan_y);
2230 242964 tb->min_scan_x = FFMIN(xc, tb->min_scan_x);
2231 242964 tb->min_scan_y = FFMIN(yc, tb->min_scan_y);
2232 } else {
2233 2086236 tb->coeffs[off] = 0;
2234 }
2235 }
2236
2237 145593 return 0;
2238 }
2239
2240 28825 static int hls_residual_ts_coding(VVCLocalContext *lc, TransformBlock *tb)
2241 {
2242 ResidualCoding rc;
2243 28825 tb->min_scan_x = tb->min_scan_y = INT_MAX;
2244 28825 init_residual_coding(lc, &rc, tb->log2_tb_width, tb->log2_tb_height, tb);
2245
2/2
✓ Branch 0 taken 145593 times.
✓ Branch 1 taken 28825 times.
174418 for (int i = 0; i <= rc.last_sub_block; i++) {
2246 145593 int ret = residual_ts_coding_subblock(lc, &rc, i);
2247
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 145593 times.
145593 if (ret < 0)
2248 return ret;
2249 }
2250
2251 28825 return 0;
2252 }
2253
2254 2110617 static inline int residual_coding_subblock(VVCLocalContext *lc, ResidualCoding *rc, const int i)
2255 {
2256 2110617 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2257 2110617 TransformBlock *tb = rc->tb;
2258 int first_sig_scan_pos_sb, last_sig_scan_pos_sb;
2259 int first_pos_mode0, first_pos_mode1;
2260 2110617 int infer_sb_dc_sig_coeff_flag = 0;
2261 2110617 int n, sig_hidden_flag, sum = 0;
2262 int abs_level_gt2_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];
2263 2110617 const int start_qstate_sb = rc->qstate;
2264 2110617 const int xs = rc->sb_scan_x_off[i];
2265 2110617 const int ys = rc->sb_scan_y_off[i];
2266 2110617 uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
2267
2268
2269
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2110617 times.
2110617 av_assert0(rc->num_sb_coeff <= MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE);
2270
4/4
✓ Branch 0 taken 1187328 times.
✓ Branch 1 taken 923289 times.
✓ Branch 2 taken 917082 times.
✓ Branch 3 taken 270246 times.
2110617 if (i < rc->last_sub_block && i > 0) {
2271 917082 *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
2272 917082 infer_sb_dc_sig_coeff_flag = 1;
2273 } else {
2274 1193535 *sb_coded_flag = 1;
2275 }
2276
8/8
✓ Branch 0 taken 1778854 times.
✓ Branch 1 taken 331763 times.
✓ Branch 2 taken 1708991 times.
✓ Branch 3 taken 69863 times.
✓ Branch 4 taken 53185 times.
✓ Branch 5 taken 1655806 times.
✓ Branch 6 taken 70682 times.
✓ Branch 7 taken 52366 times.
2110617 if (*sb_coded_flag && (xs > 3 || ys > 3) && !tb->c_idx)
2277 70682 lc->parse.mts_zero_out_sig_coeff_flag = 0;
2278
2279
2/2
✓ Branch 0 taken 331763 times.
✓ Branch 1 taken 1778854 times.
2110617 if (!*sb_coded_flag)
2280 331763 return 0;
2281
2282 1778854 first_sig_scan_pos_sb = rc->num_sb_coeff;
2283 1778854 last_sig_scan_pos_sb = -1;
2284
2/2
✓ Branch 0 taken 923289 times.
✓ Branch 1 taken 855565 times.
1778854 first_pos_mode0 = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1);
2285 1778854 first_pos_mode1 = first_pos_mode0;
2286
4/4
✓ Branch 0 taken 18950334 times.
✓ Branch 1 taken 1714463 times.
✓ Branch 2 taken 18885943 times.
✓ Branch 3 taken 64391 times.
20664797 for (n = first_pos_mode0; n >= 0 && rc->rem_bins_pass1 >= 4; n--) {
2287 18885943 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2288 18885943 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2289
4/4
✓ Branch 0 taken 2861138 times.
✓ Branch 1 taken 16024805 times.
✓ Branch 2 taken 923289 times.
✓ Branch 3 taken 1937849 times.
18885943 const int last = (xc == rc->last_significant_coeff_x && yc == rc->last_significant_coeff_y);
2290 18885943 int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc;
2291 18885943 int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc;
2292
2293
6/6
✓ Branch 0 taken 1714463 times.
✓ Branch 1 taken 17171480 times.
✓ Branch 2 taken 1704597 times.
✓ Branch 3 taken 9866 times.
✓ Branch 4 taken 17952788 times.
✓ Branch 5 taken 923289 times.
18885943 if ((n > 0 || !infer_sb_dc_sig_coeff_flag ) && !last) {
2294 17952788 *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
2295 17952788 rc->rem_bins_pass1--;
2296
2/2
✓ Branch 0 taken 9973324 times.
✓ Branch 1 taken 7979464 times.
17952788 if (*sig_coeff_flag)
2297 9973324 infer_sb_dc_sig_coeff_flag = 0;
2298 } else {
2299
5/8
✓ Branch 0 taken 9866 times.
✓ Branch 1 taken 923289 times.
✓ Branch 2 taken 9866 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9866 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9866 times.
✗ Branch 7 not taken.
933155 *sig_coeff_flag = last || (!rc->scan_x_off[n] && !rc ->scan_y_off[n] &&
2300 infer_sb_dc_sig_coeff_flag);
2301 }
2302 18885943 *abs_level_pass1 = 0;
2303
2/2
✓ Branch 0 taken 10906479 times.
✓ Branch 1 taken 7979464 times.
18885943 if (*sig_coeff_flag) {
2304 10906479 int abs_level_gt1_flag, par_level_flag = 0;
2305 10906479 const int inc = get_gtx_flag_inc(rc, xc, yc, last);
2306 10906479 abs_level_gt1_flag = abs_level_gtx_flag_decode(lc, inc);
2307 10906479 rc->rem_bins_pass1--;
2308
2/2
✓ Branch 0 taken 2279410 times.
✓ Branch 1 taken 8627069 times.
10906479 if (abs_level_gt1_flag) {
2309 2279410 par_level_flag = par_level_flag_decode(lc, inc);
2310 2279410 abs_level_gt2_flag[n] = abs_level_gtx_flag_decode(lc, inc + 32);
2311 2279410 rc->rem_bins_pass1 -= 2;
2312 } else {
2313 8627069 abs_level_gt2_flag[n] = 0;
2314 }
2315
2/2
✓ Branch 0 taken 1764772 times.
✓ Branch 1 taken 9141707 times.
10906479 if (last_sig_scan_pos_sb == -1)
2316 1764772 last_sig_scan_pos_sb = n;
2317 10906479 first_sig_scan_pos_sb = n;
2318
2319 10906479 *abs_level_pass1 =
2320 10906479 1 + par_level_flag + abs_level_gt1_flag + (abs_level_gt2_flag[n] << 1);
2321 } else {
2322 7979464 abs_level_gt2_flag[n] = 0;
2323 }
2324
2325
2/2
✓ Branch 0 taken 17677896 times.
✓ Branch 1 taken 1208047 times.
18885943 if (rsh->sh_dep_quant_used_flag)
2326 17677896 rc->qstate = qstate_translate_table[rc->qstate][*abs_level_pass1 & 1];
2327
2328 18885943 first_pos_mode1 = n - 1;
2329 }
2330
2/2
✓ Branch 0 taken 18885943 times.
✓ Branch 1 taken 1778854 times.
20664797 for (n = first_pos_mode0; n > first_pos_mode1; n--) {
2331 18885943 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2332 18885943 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2333 18885943 const int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc;
2334 18885943 int *abs_level = rc->abs_level + yc * tb->tb_width + xc;
2335
2336 18885943 *abs_level = *abs_level_pass1;
2337
2/2
✓ Branch 0 taken 622554 times.
✓ Branch 1 taken 18263389 times.
18885943 if (abs_level_gt2_flag[n]) {
2338 622554 const int abs_remainder = abs_remainder_decode(lc, rc, xc, yc);
2339 622554 ep_update_hist(lc->ep, rc, abs_remainder, 2);
2340 622554 *abs_level += 2 * abs_remainder;
2341 }
2342 }
2343
2/2
✓ Branch 0 taken 355775 times.
✓ Branch 1 taken 1778854 times.
2134629 for (n = first_pos_mode1; n >= 0; n--) {
2344 355775 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2345 355775 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2346 355775 int *abs_level = rc->abs_level + yc * tb->tb_width + xc;
2347
2348
1/2
✓ Branch 0 taken 355775 times.
✗ Branch 1 not taken.
355775 if (*sb_coded_flag) {
2349 355775 const int dec_abs_level = dec_abs_level_decode(lc, rc, xc, yc, abs_level);
2350 355775 ep_update_hist(lc->ep, rc, dec_abs_level, 0);
2351 }
2352
2/2
✓ Branch 0 taken 323999 times.
✓ Branch 1 taken 31776 times.
355775 if (*abs_level > 0) {
2353
2/2
✓ Branch 0 taken 7607 times.
✓ Branch 1 taken 316392 times.
323999 if (last_sig_scan_pos_sb == -1)
2354 7607 last_sig_scan_pos_sb = n;
2355 323999 first_sig_scan_pos_sb = n;
2356 }
2357
2/2
✓ Branch 0 taken 283085 times.
✓ Branch 1 taken 72690 times.
355775 if (rsh->sh_dep_quant_used_flag)
2358 283085 rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1];
2359 }
2360
2/2
✓ Branch 0 taken 34562 times.
✓ Branch 1 taken 1744292 times.
1813416 sig_hidden_flag = rsh->sh_sign_data_hiding_used_flag &&
2361
2/2
✓ Branch 0 taken 22447 times.
✓ Branch 1 taken 12115 times.
34562 (last_sig_scan_pos_sb - first_sig_scan_pos_sb > 3 ? 1 : 0);
2362
2363
2/2
✓ Branch 0 taken 1657608 times.
✓ Branch 1 taken 121246 times.
1778854 if (rsh->sh_dep_quant_used_flag)
2364 1657608 rc->qstate = start_qstate_sb;
2365
2/2
✓ Branch 0 taken 923289 times.
✓ Branch 1 taken 855565 times.
1778854 n = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1);
2366
2/2
✓ Branch 0 taken 19241718 times.
✓ Branch 1 taken 1778854 times.
21020572 for (/* nothing */; n >= 0; n--) {
2367 int trans_coeff_level;
2368 19241718 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2369 19241718 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2370 19241718 const int off = yc * tb->tb_width + xc;
2371 19241718 const int *abs_level = rc->abs_level + off;
2372
2373
2/2
✓ Branch 0 taken 11230478 times.
✓ Branch 1 taken 8011240 times.
19241718 if (*abs_level > 0) {
2374 11230478 int sign = 1;
2375
4/4
✓ Branch 0 taken 176798 times.
✓ Branch 1 taken 11053680 times.
✓ Branch 2 taken 154351 times.
✓ Branch 3 taken 22447 times.
11230478 if (!sig_hidden_flag || (n != first_sig_scan_pos_sb))
2376 11208031 sign = 1 - 2 * coeff_sign_flag_decode(lc);
2377
2/2
✓ Branch 0 taken 10543413 times.
✓ Branch 1 taken 687065 times.
11230478 if (rsh->sh_dep_quant_used_flag) {
2378 10543413 trans_coeff_level = (2 * *abs_level - (rc->qstate > 1)) * sign;
2379 } else {
2380 687065 trans_coeff_level = *abs_level * sign;
2381
2/2
✓ Branch 0 taken 176798 times.
✓ Branch 1 taken 510267 times.
687065 if (sig_hidden_flag) {
2382 176798 sum += *abs_level;
2383
4/4
✓ Branch 0 taken 22447 times.
✓ Branch 1 taken 154351 times.
✓ Branch 2 taken 11754 times.
✓ Branch 3 taken 10693 times.
176798 if (n == first_sig_scan_pos_sb && (sum % 2))
2384 11754 trans_coeff_level = -trans_coeff_level;
2385 }
2386 }
2387 11230478 tb->coeffs[off] = trans_coeff_level;
2388 11230478 tb->max_scan_x = FFMAX(xc, tb->max_scan_x);
2389 11230478 tb->max_scan_y = FFMAX(yc, tb->max_scan_y);
2390 }
2391
2/2
✓ Branch 0 taken 17960981 times.
✓ Branch 1 taken 1280737 times.
19241718 if (rsh->sh_dep_quant_used_flag)
2392 17960981 rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1];
2393 }
2394
2395 1778854 return 0;
2396 }
2397
2398 923289 static void derive_last_scan_pos(ResidualCoding *rc)
2399 {
2400 int xc, yc, xs, ys;
2401 do {
2402
2/2
✓ Branch 0 taken 6256183 times.
✓ Branch 1 taken 103804024 times.
110060207 if (!rc->last_scan_pos) {
2403 6256183 rc->last_scan_pos = rc->num_sb_coeff;
2404 6256183 rc->last_sub_block--;
2405 }
2406 110060207 rc->last_scan_pos--;
2407 110060207 xs = rc->sb_scan_x_off[rc->last_sub_block];
2408 110060207 ys = rc->sb_scan_y_off[rc->last_sub_block];
2409 110060207 xc = (xs << rc->log2_sb_w) + rc->scan_x_off[rc->last_scan_pos];
2410 110060207 yc = (ys << rc->log2_sb_h) + rc->scan_y_off[rc->last_scan_pos];
2411
4/4
✓ Branch 0 taken 103040218 times.
✓ Branch 1 taken 7019989 times.
✓ Branch 2 taken 6096700 times.
✓ Branch 3 taken 923289 times.
110060207 } while ((xc != rc->last_significant_coeff_x) || (yc != rc->last_significant_coeff_y));
2412 923289 }
2413
2414 923289 static void last_significant_coeff_x_y_decode(ResidualCoding *rc, VVCLocalContext *lc,
2415 const int log2_zo_tb_width, const int log2_zo_tb_height)
2416 {
2417 923289 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2418 923289 const TransformBlock *tb = rc->tb;
2419 int last_significant_coeff_x, last_significant_coeff_y;
2420
2421 923289 last_significant_coeff_x = last_significant_coeff_x_prefix_decode(lc,
2422 923289 tb->log2_tb_width, log2_zo_tb_width, tb->c_idx);
2423
2424 923289 last_significant_coeff_y = last_significant_coeff_y_prefix_decode(lc,
2425 923289 tb->log2_tb_height, log2_zo_tb_height, tb->c_idx);
2426
2427
2/2
✓ Branch 0 taken 200577 times.
✓ Branch 1 taken 722712 times.
923289 if (last_significant_coeff_x > 3) {
2428 200577 int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_x);
2429 200577 last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
2430 200577 (2 + (last_significant_coeff_x & 1)) + suffix;
2431 }
2432
2/2
✓ Branch 0 taken 156840 times.
✓ Branch 1 taken 766449 times.
923289 if (last_significant_coeff_y > 3) {
2433 156840 int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_y);
2434 156840 last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
2435 156840 (2 + (last_significant_coeff_y & 1)) + suffix;
2436 }
2437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 923289 times.
923289 if (rsh->sh_reverse_last_sig_coeff_flag) {
2438 last_significant_coeff_x = (1 << log2_zo_tb_width) - 1 - last_significant_coeff_x;
2439 last_significant_coeff_y = (1 << log2_zo_tb_height) - 1 - last_significant_coeff_y;
2440 }
2441 923289 rc->last_significant_coeff_x = last_significant_coeff_x;
2442 923289 rc->last_significant_coeff_y = last_significant_coeff_y;
2443 923289 }
2444
2445 923289 static int hls_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
2446 {
2447 923289 const VVCSPS *sps = lc->fc->ps.sps;
2448 923289 const CodingUnit *cu = lc->cu;
2449 923289 const int log2_tb_width = tb->log2_tb_width;
2450 923289 const int log2_tb_height = tb->log2_tb_height;
2451 923289 const int c_idx = tb->c_idx;
2452 int log2_zo_tb_width, log2_zo_tb_height;
2453 ResidualCoding rc;
2454
2455
10/10
✓ Branch 0 taken 918576 times.
✓ Branch 1 taken 4713 times.
✓ Branch 2 taken 51033 times.
✓ Branch 3 taken 867543 times.
✓ Branch 4 taken 34142 times.
✓ Branch 5 taken 16891 times.
✓ Branch 6 taken 1636 times.
✓ Branch 7 taken 32506 times.
✓ Branch 8 taken 1533 times.
✓ Branch 9 taken 103 times.
923289 if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width == 5 && log2_tb_height < 6)
2456 1533 log2_zo_tb_width = 4;
2457 else
2458 921756 log2_zo_tb_width = FFMIN(log2_tb_width, 5 );
2459
2460
10/10
✓ Branch 0 taken 918576 times.
✓ Branch 1 taken 4713 times.
✓ Branch 2 taken 51033 times.
✓ Branch 3 taken 867543 times.
✓ Branch 4 taken 34142 times.
✓ Branch 5 taken 16891 times.
✓ Branch 6 taken 33952 times.
✓ Branch 7 taken 190 times.
✓ Branch 8 taken 2051 times.
✓ Branch 9 taken 31901 times.
923289 if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width < 6 && log2_tb_height == 5 )
2461 2051 log2_zo_tb_height = 4;
2462 else
2463 921238 log2_zo_tb_height = FFMIN(log2_tb_height, 5);
2464
2465 923289 init_residual_coding(lc, &rc, log2_zo_tb_width, log2_zo_tb_height, tb);
2466 923289 last_significant_coeff_x_y_decode(&rc, lc, log2_zo_tb_width, log2_zo_tb_height);
2467 923289 derive_last_scan_pos(&rc);
2468
2469
9/10
✓ Branch 0 taken 653043 times.
✓ Branch 1 taken 270246 times.
✓ Branch 2 taken 628423 times.
✓ Branch 3 taken 24620 times.
✓ Branch 4 taken 560871 times.
✓ Branch 5 taken 67552 times.
✓ Branch 6 taken 560871 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 427952 times.
✓ Branch 9 taken 132919 times.
923289 if (!rc.last_sub_block && log2_tb_width >= 2 && log2_tb_height >= 2 && !tb->ts && rc.last_scan_pos > 0)
2470 427952 lc->parse.lfnst_dc_only = 0;
2471
6/6
✓ Branch 0 taken 270246 times.
✓ Branch 1 taken 653043 times.
✓ Branch 2 taken 268268 times.
✓ Branch 3 taken 1978 times.
✓ Branch 4 taken 4552 times.
✓ Branch 5 taken 263716 times.
923289 if ((rc.last_sub_block > 0 && log2_tb_width >= 2 && log2_tb_height >= 2 ) ||
2472
8/8
✓ Branch 0 taken 146874 times.
✓ Branch 1 taken 512699 times.
✓ Branch 2 taken 84916 times.
✓ Branch 3 taken 61958 times.
✓ Branch 4 taken 41837 times.
✓ Branch 5 taken 43079 times.
✓ Branch 6 taken 51767 times.
✓ Branch 7 taken 52028 times.
659573 (rc.last_scan_pos > 7 && (log2_tb_width == 2 || log2_tb_width == 3 ) &&
2473 log2_tb_width == log2_tb_height))
2474 315483 lc->parse.lfnst_zero_out_sig_coeff_flag = 0;
2475
6/6
✓ Branch 0 taken 653043 times.
✓ Branch 1 taken 270246 times.
✓ Branch 2 taken 493803 times.
✓ Branch 3 taken 159240 times.
✓ Branch 4 taken 572240 times.
✓ Branch 5 taken 191809 times.
923289 if ((rc.last_sub_block > 0 || rc.last_scan_pos > 0 ) && !c_idx)
2476 572240 lc->parse.mts_dc_only = 0;
2477
2478 923289 memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs));
2479 923289 memset(rc.abs_level, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level[0]));
2480 923289 memset(rc.sb_coded_flag, 0, rc.nb_sbs);
2481 923289 memset(rc.abs_level_pass1, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level_pass1[0]));
2482 923289 memset(rc.sig_coeff_flag, 0, tb->tb_width * tb->tb_height * sizeof(rc.sig_coeff_flag[0]));
2483
2484
2/2
✓ Branch 0 taken 2110617 times.
✓ Branch 1 taken 923289 times.
3033906 for (int i = rc.last_sub_block; i >= 0; i--) {
2485 2110617 int ret = residual_coding_subblock(lc, &rc, i);
2486
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2110617 times.
2110617 if (ret < 0)
2487 return ret;
2488 }
2489
2490 923289 return 0;
2491 }
2492
2493 952114 int ff_vvc_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
2494 {
2495 952114 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2496
3/4
✓ Branch 0 taken 952114 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28825 times.
✓ Branch 3 taken 923289 times.
952114 const int ts = !rsh->sh_ts_residual_coding_disabled_flag && tb->ts;
2497
2498
2/2
✓ Branch 0 taken 28825 times.
✓ Branch 1 taken 923289 times.
952114 return ts ? hls_residual_ts_coding(lc, tb) : hls_residual_coding(lc, tb);
2499 }
2500
2501 91987 int ff_vvc_cu_coded_flag(VVCLocalContext *lc)
2502 {
2503 91987 return GET_CABAC(CU_CODED_FLAG);
2504 }
2505
2506 130991 int ff_vvc_sbt_flag(VVCLocalContext *lc)
2507 {
2508 130991 const int w = lc->cu->cb_width;
2509 130991 const int h = lc->cu->cb_height;
2510 130991 const int inc = w * h <= 256;
2511 130991 return GET_CABAC(CU_SBT_FLAG + inc);
2512 }
2513
2514 31711 int ff_vvc_sbt_quad_flag(VVCLocalContext *lc)
2515 {
2516 31711 return GET_CABAC(CU_SBT_QUAD_FLAG);
2517 }
2518
2519 24966 int ff_vvc_sbt_horizontal_flag(VVCLocalContext *lc)
2520 {
2521 24966 const int w = lc->cu->cb_width;
2522 24966 const int h = lc->cu->cb_height;
2523
4/4
✓ Branch 0 taken 13306 times.
✓ Branch 1 taken 11660 times.
✓ Branch 2 taken 7290 times.
✓ Branch 3 taken 6016 times.
24966 const int inc = (w == h) ? 0 : ((w < h) ? 1 : 2);
2524 24966 return GET_CABAC(CU_SBT_HORIZONTAL_FLAG + inc);
2525 }
2526
2527 44595 int ff_vvc_sbt_pos_flag(VVCLocalContext *lc)
2528 {
2529 44595 return GET_CABAC(CU_SBT_POS_FLAG);
2530 }
2531
2532 182927 int ff_vvc_lfnst_idx(VVCLocalContext *lc, const int inc)
2533 {
2534
2/2
✓ Branch 1 taken 44813 times.
✓ Branch 2 taken 138114 times.
182927 if (!GET_CABAC(LFNST_IDX + inc))
2535 44813 return 0;
2536
2/2
✓ Branch 1 taken 84339 times.
✓ Branch 2 taken 53775 times.
138114 if (!GET_CABAC(LFNST_IDX + 2))
2537 84339 return 1;
2538 53775 return 2;
2539 }
2540
2541 246997 int ff_vvc_mts_idx(VVCLocalContext *lc)
2542 {
2543 int i;
2544
2/2
✓ Branch 0 taken 452164 times.
✓ Branch 1 taken 910 times.
453074 for (i = 0; i < 4; i++) {
2545
2/2
✓ Branch 1 taken 246087 times.
✓ Branch 2 taken 206077 times.
452164 if (!GET_CABAC(MTS_IDX + i))
2546 246087 return i;
2547 }
2548 910 return i;
2549 }
2550
2551 1711 int ff_vvc_end_of_slice_flag_decode(VVCLocalContext *lc)
2552 {
2553 1711 return get_cabac_terminate(&lc->ep->cc);
2554 }
2555
2556 493 int ff_vvc_end_of_tile_one_bit(VVCLocalContext *lc)
2557 {
2558 493 return get_cabac_terminate(&lc->ep->cc);
2559 }
2560
2561 153 int ff_vvc_end_of_subset_one_bit(VVCLocalContext *lc)
2562 {
2563 153 return get_cabac_terminate(&lc->ep->cc);
2564 }
2565