FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vvc/cabac.c
Date: 2025-09-01 20:07:09
Exec Total Coverage
Lines: 1019 1032 98.7%
Functions: 139 139 100.0%
Branches: 670 696 96.3%

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 2309 static void cabac_init_state(VVCLocalContext *lc)
814 {
815 2309 const VVCSPS *sps = lc->fc->ps.sps;
816 2309 const H266RawSliceHeader *rsh = lc->sc->sh.r;
817 2309 const int qp = av_clip_uintp2(lc->sc->sh.slice_qp_y, 6);
818 2309 int init_type = 2 - rsh->sh_slice_type;
819
820 av_assert0(VVC_CONTEXTS == SYNTAX_ELEMENT_LAST);
821
822 2309 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 576 times.
✓ Branch 1 taken 1733 times.
✓ Branch 2 taken 576 times.
✗ Branch 3 not taken.
2309 if (rsh->sh_cabac_init_flag && !IS_I(rsh))
825 576 init_type ^= 3;
826
827
2/2
✓ Branch 0 taken 872802 times.
✓ Branch 1 taken 2309 times.
875111 for (int i = 0; i < VVC_CONTEXTS; i++) {
828 872802 VVCCabacState *state = &lc->ep->cabac_state[i];
829 872802 const int init_value = init_values[init_type][i];
830 872802 const int shift_idx = init_values[3][i];
831 872802 const int m = (init_value >> 3) - 4;
832 872802 const int n = ((init_value & 7) * 18) + 1;
833 872802 const int pre = av_clip(((m * (qp - 16)) >> 1) + n, 1, 127);
834
835 872802 state->state[0] = pre << 3;
836 872802 state->state[1] = pre << 7;
837 872802 state->shift[0] = (shift_idx >> 2 ) + 2;
838 872802 state->shift[1] = (shift_idx & 3 ) + 3 + state->shift[0];
839 }
840 2309 }
841
842 53355 int ff_vvc_cabac_init(VVCLocalContext *lc,
843 const int ctu_idx, const int rx, const int ry)
844 {
845 53355 int ret = 0;
846 53355 const VVCPPS *pps = lc->fc->ps.pps;
847 53355 const int first_ctb_in_slice = !ctu_idx;
848
4/4
✓ Branch 0 taken 6433 times.
✓ Branch 1 taken 46922 times.
✓ Branch 2 taken 2197 times.
✓ Branch 3 taken 4236 times.
53355 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 51539 times.
✓ Branch 1 taken 1816 times.
✓ Branch 2 taken 493 times.
✓ Branch 3 taken 51046 times.
53355 if (first_ctb_in_slice|| first_ctb_in_tile) {
851
4/4
✓ Branch 0 taken 1996 times.
✓ Branch 1 taken 313 times.
✓ Branch 2 taken 273 times.
✓ Branch 3 taken 1723 times.
2309 if (lc->sc->nb_eps == 1 && !first_ctb_in_slice)
852 273 ret = cabac_reinit(lc);
853
1/2
✓ Branch 0 taken 2309 times.
✗ Branch 1 not taken.
2309 if (!ret)
854 2309 cabac_init_state(lc);
855 }
856 53355 return ret;
857 }
858
859 //fixme
860 2172649 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 2172649 i = ff_ctz(c->low) - CABAC_BITS;
868 #endif
869
870 2172649 x = -CABAC_MASK;
871
872 #if CABAC_BITS == 16
873 2172649 x += (c->bytestream[0] << 9) + (c->bytestream[1] << 1);
874 #else
875 x += c->bytestream[0] << 1;
876 #endif
877
878 2172649 c->low += x << i;
879 #if !UNCHECKED_BITSTREAM_READER
880
2/2
✓ Branch 0 taken 2172530 times.
✓ Branch 1 taken 119 times.
2172649 if (c->bytestream < c->bytestream_end)
881 #endif
882 2172530 c->bytestream += CABAC_BITS / 8;
883 2172649 }
884
885 56496069 static int inline vvc_get_cabac(CABACContext *c, VVCCabacState* base, const int ctx)
886 {
887 56496069 VVCCabacState *s = base + ctx;
888 56496069 const int qRangeIdx = c->range >> 5;
889 56496069 const int pState = s->state[1] + (s->state[0] << 4);
890 56496069 const int valMps = pState >> 14;
891
2/2
✓ Branch 0 taken 23194263 times.
✓ Branch 1 taken 33301806 times.
56496069 const int RangeLPS = (qRangeIdx * ((valMps ? 32767 - pState : pState) >> 9 ) >> 1) + 4;
892 int bit, lps_mask;
893
894 56496069 c->range -= RangeLPS;
895 56496069 lps_mask = ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
896
897 56496069 c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
898 56496069 c->range += (RangeLPS - c->range) & lps_mask;
899
900 56496069 bit = valMps ^ (lps_mask & 1);
901
902 56496069 lps_mask = ff_h264_norm_shift[c->range];
903 56496069 c->range <<= lps_mask;
904 56496069 c->low <<= lps_mask;
905
906
2/2
✓ Branch 0 taken 2172649 times.
✓ Branch 1 taken 54323420 times.
56496069 if (!(c->low & CABAC_MASK))
907 2172649 vvc_refill2(c);
908 56496069 s->state[0] = s->state[0] - (s->state[0] >> s->shift[0]) + (1023 * bit >> s->shift[0]);
909 56496069 s->state[1] = s->state[1] - (s->state[1] >> s->shift[1]) + (16383 * bit >> s->shift[1]);
910 56496069 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 321441 static int truncated_binary_decode(VVCLocalContext *lc, const int c_max)
917 {
918 321441 const int n = c_max + 1;
919 321441 const int k = av_log2(n);
920 321441 const int u = (1 << (k+1)) - n;
921 321441 int v = 0;
922
2/2
✓ Branch 0 taken 1144867 times.
✓ Branch 1 taken 321441 times.
1466308 for (int i = 0; i < k; i++)
923 1144867 v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
924
2/2
✓ Branch 0 taken 169475 times.
✓ Branch 1 taken 151966 times.
321441 if (v >= u) {
925 169475 v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
926 169475 v -= u;
927 }
928 321441 return v;
929 }
930
931 // 9.3.3.5 k-th order Exp - Golomb binarization process
932 33156 static int kth_order_egk_decode(CABACContext *c, int k, const int max)
933 {
934 33156 int bit = 1;
935 33156 int value = 0;
936 33156 int symbol = 0;
937
938
2/2
✓ Branch 0 taken 60555 times.
✓ Branch 1 taken 33156 times.
93711 while (bit) {
939 60555 bit = get_cabac_bypass(c);
940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60555 times.
60555 if (max - value < (bit << k))
941 return AVERROR_INVALIDDATA;
942 60555 value += bit << k++;
943 }
944
945
2/2
✓ Branch 0 taken 15964 times.
✓ Branch 1 taken 17192 times.
33156 if (--k) {
946
2/2
✓ Branch 0 taken 28124 times.
✓ Branch 1 taken 15964 times.
44088 for (int i = 0; i < k; i++)
947 28124 symbol = (symbol << 1) | get_cabac_bypass(c);
948 15964 value += symbol;
949 }
950
951
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33156 times.
33156 if (value > max)
952 return AVERROR_INVALIDDATA;
953
954 33156 return value;
955 }
956
957 // 9.3.3.6 Limited k-th order Exp-Golomb binarization process
958 218017 static int limited_kth_order_egk_decode(CABACContext *c, const int k, const int max_pre_ext_len, const int trunc_suffix_len)
959 {
960 218017 int pre_ext_len = 0;
961 int escape_length;
962 218017 int val = 0;
963
4/4
✓ Branch 0 taken 670914 times.
✓ Branch 1 taken 110 times.
✓ Branch 3 taken 453007 times.
✓ Branch 4 taken 217907 times.
671024 while ((pre_ext_len < max_pre_ext_len) && get_cabac_bypass(c))
964 453007 pre_ext_len++;
965
2/2
✓ Branch 0 taken 110 times.
✓ Branch 1 taken 217907 times.
218017 if (pre_ext_len == max_pre_ext_len)
966 110 escape_length = trunc_suffix_len;
967 else
968 217907 escape_length = pre_ext_len + k;
969
2/2
✓ Branch 0 taken 739341 times.
✓ Branch 1 taken 218017 times.
957358 while (escape_length-- > 0) {
970 739341 val = (val << 1) + get_cabac_bypass(c);
971 }
972 218017 val += ((1 << pre_ext_len) - 1) << k;
973 218017 return val;
974 }
975
976 // 9.3.3.7 Fixed-length binarization process
977 32878 static int fixed_length_decode(CABACContext* c, const int len)
978 {
979 32878 int value = 0;
980
981
2/2
✓ Branch 0 taken 210251 times.
✓ Branch 1 taken 32878 times.
243129 for (int i = 0; i < len; i++)
982 210251 value = (value << 1) | get_cabac_bypass(c);
983
984 32878 return value;
985 }
986
987 static av_always_inline
988 3979308 void get_left_top(const VVCLocalContext *lc, uint8_t *left, uint8_t *top,
989 const int x0, const int y0, const uint8_t *left_ctx, const uint8_t *top_ctx)
990 {
991 3979308 const VVCFrameContext *fc = lc->fc;
992 3979308 const VVCSPS *sps = fc->ps.sps;
993 3979308 const int min_cb_width = fc->ps.pps->min_cb_width;
994 3979308 const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
995 3979308 const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
996 3979308 const int x_cb = x0 >> sps->min_cb_log2_size_y;
997 3979308 const int y_cb = y0 >> sps->min_cb_log2_size_y;
998
999
4/4
✓ Branch 0 taken 790820 times.
✓ Branch 1 taken 3188488 times.
✓ Branch 2 taken 659916 times.
✓ Branch 3 taken 130904 times.
3979308 if (lc->ctb_left_flag || x0b)
1000 3848404 *left = SAMPLE_CTB(left_ctx, x_cb - 1, y_cb);
1001
4/4
✓ Branch 0 taken 1215459 times.
✓ Branch 1 taken 2763849 times.
✓ Branch 2 taken 1029034 times.
✓ Branch 3 taken 186425 times.
3979308 if (lc->ctb_up_flag || y0b)
1002 3792883 *top = SAMPLE_CTB(top_ctx, x_cb, y_cb - 1);
1003 3979308 }
1004
1005 static av_always_inline
1006 649940 uint8_t get_inc(VVCLocalContext *lc, const uint8_t *ctx)
1007 {
1008 649940 uint8_t left = 0, top = 0;
1009 649940 get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx);
1010 649940 return left + top;
1011 }
1012
1013 24683 int ff_vvc_sao_merge_flag_decode(VVCLocalContext *lc)
1014 {
1015 24683 return GET_CABAC(SAO_MERGE_FLAG);
1016 }
1017
1018 14160 int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc)
1019 {
1020
2/2
✓ Branch 1 taken 9425 times.
✓ Branch 2 taken 4735 times.
14160 if (!GET_CABAC(SAO_TYPE_IDX))
1021 9425 return SAO_NOT_APPLIED;
1022
1023
2/2
✓ Branch 1 taken 1359 times.
✓ Branch 2 taken 3376 times.
4735 if (!get_cabac_bypass(&lc->ep->cc))
1024 1359 return SAO_BAND;
1025 3376 return SAO_EDGE;
1026 }
1027
1028 1633 int ff_vvc_sao_band_position_decode(VVCLocalContext *lc)
1029 {
1030 1633 return fixed_length_decode(&lc->ep->cc, 5);
1031 }
1032
1033 24836 int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc)
1034 {
1035 24836 int i = 0;
1036 24836 const int length = (1 << (FFMIN(lc->fc->ps.sps->bit_depth, 10) - 5)) - 1;
1037
1038
4/4
✓ Branch 0 taken 126925 times.
✓ Branch 1 taken 260 times.
✓ Branch 3 taken 102349 times.
✓ Branch 4 taken 24576 times.
127185 while (i < length && get_cabac_bypass(&lc->ep->cc))
1039 102349 i++;
1040 24836 return i;
1041 }
1042
1043 3042 int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc)
1044 {
1045 3042 return get_cabac_bypass(&lc->ep->cc);
1046 }
1047
1048 3376 int ff_vvc_sao_eo_class_decode(VVCLocalContext *lc)
1049 {
1050 3376 return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1051 }
1052
1053 64941 int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx)
1054 {
1055 64941 int inc = c_idx * 3;
1056 64941 const VVCFrameContext *fc = lc->fc;
1057
2/2
✓ Branch 0 taken 55485 times.
✓ Branch 1 taken 9456 times.
64941 if (lc->ctb_left_flag) {
1058 55485 const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry);
1059 55485 inc += left->ctb_flag[c_idx];
1060 }
1061
2/2
✓ Branch 0 taken 49134 times.
✓ Branch 1 taken 15807 times.
64941 if (lc->ctb_up_flag) {
1062 49134 const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1);
1063 49134 inc += above->ctb_flag[c_idx];
1064 }
1065 64941 return GET_CABAC(ALF_CTB_FLAG + inc);
1066 }
1067
1068 19987 int ff_vvc_alf_use_aps_flag(VVCLocalContext *lc)
1069 {
1070 19987 return GET_CABAC(ALF_USE_APS_FLAG);
1071 }
1072
1073 5167 int ff_vvc_alf_luma_prev_filter_idx(VVCLocalContext *lc)
1074 {
1075 5167 return truncated_binary_decode(lc, lc->sc->sh.r->sh_num_alf_aps_ids_luma - 1);
1076 }
1077
1078 2791 int ff_vvc_alf_luma_fixed_filter_idx(VVCLocalContext *lc)
1079 {
1080 2791 return truncated_binary_decode(lc, 15);
1081 }
1082
1083 17909 int ff_vvc_alf_ctb_filter_alt_idx(VVCLocalContext *lc, const int c_idx, const int num_chroma_filters)
1084 {
1085 17909 int i = 0;
1086 17909 const int length = num_chroma_filters - 1;
1087
1088
4/4
✓ Branch 0 taken 32961 times.
✓ Branch 1 taken 3086 times.
✓ Branch 3 taken 18138 times.
✓ Branch 4 taken 14823 times.
36047 while (i < length && GET_CABAC(ALF_CTB_FILTER_ALT_IDX + c_idx - 1))
1089 18138 i++;
1090 17909 return i;
1091 }
1092
1093 22625 int ff_vvc_alf_ctb_cc_idc(VVCLocalContext *lc, const int rx, const int ry, const int idx, const int cc_filters_signalled)
1094 {
1095
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;
1096 22625 int i = 0;
1097 22625 const VVCFrameContext *fc = lc->fc;
1098
2/2
✓ Branch 0 taken 19914 times.
✓ Branch 1 taken 2711 times.
22625 if (lc->ctb_left_flag) {
1099 19914 const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry);
1100 19914 inc += left->ctb_cc_idc[idx] != 0;
1101 }
1102
2/2
✓ Branch 0 taken 18700 times.
✓ Branch 1 taken 3925 times.
22625 if (lc->ctb_up_flag) {
1103 18700 const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1);
1104 18700 inc += above->ctb_cc_idc[idx] != 0;
1105 }
1106
1107
2/2
✓ Branch 1 taken 12098 times.
✓ Branch 2 taken 10527 times.
22625 if (!GET_CABAC(inc))
1108 12098 return 0;
1109 10527 i++;
1110
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))
1111 9189 i++;
1112 10527 return i;
1113 }
1114
1115 2211333 int ff_vvc_split_cu_flag(VVCLocalContext *lc, const int x0, const int y0,
1116 const int cb_width, const int cb_height, const int is_chroma, const VVCAllowedSplit *a)
1117 {
1118 2211333 const VVCFrameContext *fc = lc->fc;
1119 2211333 const VVCPPS *pps = fc->ps.pps;
1120
4/4
✓ Branch 0 taken 2206394 times.
✓ Branch 1 taken 4939 times.
✓ Branch 2 taken 2152243 times.
✓ Branch 3 taken 54151 times.
2211333 const int is_inside = (x0 + cb_width <= pps->width) && (y0 + cb_height <= pps->height);
1121
1122
12/12
✓ Branch 0 taken 876045 times.
✓ Branch 1 taken 1335288 times.
✓ Branch 2 taken 634543 times.
✓ Branch 3 taken 241502 times.
✓ Branch 4 taken 628718 times.
✓ Branch 5 taken 5825 times.
✓ Branch 6 taken 627133 times.
✓ Branch 7 taken 1585 times.
✓ Branch 8 taken 52779 times.
✓ Branch 9 taken 574354 times.
✓ Branch 10 taken 1577889 times.
✓ Branch 11 taken 59090 times.
2211333 if ((a->btv || a->bth || a->ttv || a->tth || a->qt) && is_inside)
1123 {
1124 1577889 uint8_t inc = 0, left_height = cb_height, top_width = cb_width;
1125
1126 1577889 get_left_top(lc, &left_height, &top_width, x0, y0, fc->tab.cb_height[is_chroma], fc->tab.cb_width[is_chroma]);
1127 1577889 inc += left_height < cb_height;
1128 1577889 inc += top_width < cb_width;
1129 1577889 inc += (a->btv + a->bth + a->ttv + a->tth + 2 * a->qt - 1) / 2 * 3;
1130
1131 1577889 return GET_CABAC(SPLIT_CU_FLAG + inc);
1132
1133 }
1134 633444 return !is_inside;
1135 }
1136
1137 287708 static int split_qt_flag_decode(VVCLocalContext *lc, const int x0, const int y0, const int ch_type, const int cqt_depth)
1138 {
1139 287708 const VVCFrameContext *fc = lc->fc;
1140 287708 int inc = 0;
1141 287708 uint8_t depth_left = 0, depth_top = 0;
1142
1143 287708 get_left_top(lc, &depth_left, &depth_top, x0, y0, fc->tab.cqt_depth[ch_type], fc->tab.cqt_depth[ch_type]);
1144 287708 inc += depth_left > cqt_depth;
1145 287708 inc += depth_top > cqt_depth;
1146
2/2
✓ Branch 0 taken 216474 times.
✓ Branch 1 taken 71234 times.
287708 inc += (cqt_depth >= 2) * 3;
1147
1148 287708 return GET_CABAC(SPLIT_QT_FLAG + inc);
1149 }
1150
1151 756978 static int mtt_split_cu_vertical_flag_decode(VVCLocalContext *lc, const int x0, const int y0,
1152 const int cb_width, const int cb_height, const int ch_type, const VVCAllowedSplit* a)
1153 {
1154
8/8
✓ Branch 0 taken 86747 times.
✓ Branch 1 taken 670231 times.
✓ Branch 2 taken 17850 times.
✓ Branch 3 taken 68897 times.
✓ Branch 4 taken 123953 times.
✓ Branch 5 taken 564128 times.
✓ Branch 6 taken 14758 times.
✓ Branch 7 taken 109195 times.
756978 if ((a->bth || a->tth) && (a->btv || a->ttv)) {
1155 int inc;
1156 578886 const int v = a->btv + a->ttv;
1157 578886 const int h = a->bth + a->tth;
1158
2/2
✓ Branch 0 taken 92840 times.
✓ Branch 1 taken 486046 times.
578886 if (v > h)
1159 92840 inc = 4;
1160
2/2
✓ Branch 0 taken 92957 times.
✓ Branch 1 taken 393089 times.
486046 else if (v < h)
1161 92957 inc = 3;
1162 else {
1163 393089 const VVCFrameContext *fc = lc->fc;
1164 393089 const VVCSPS *sps = fc->ps.sps;
1165 393089 const int min_cb_width = fc->ps.pps->min_cb_width;
1166 393089 const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
1167 393089 const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
1168 393089 const int x_cb = x0 >> sps->min_cb_log2_size_y;
1169 393089 const int y_cb = y0 >> sps->min_cb_log2_size_y;
1170
4/4
✓ Branch 0 taken 116934 times.
✓ Branch 1 taken 276155 times.
✓ Branch 2 taken 96001 times.
✓ Branch 3 taken 20933 times.
393089 const int available_a = lc->ctb_up_flag || y0b;
1171
4/4
✓ Branch 0 taken 72540 times.
✓ Branch 1 taken 320549 times.
✓ Branch 2 taken 57033 times.
✓ Branch 3 taken 15507 times.
393089 const int available_l = lc->ctb_left_flag || x0b;
1172
2/2
✓ Branch 0 taken 372156 times.
✓ Branch 1 taken 20933 times.
393089 const int da = cb_width / (available_a ? SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cb, y_cb - 1) : 1);
1173
2/2
✓ Branch 0 taken 377582 times.
✓ Branch 1 taken 15507 times.
393089 const int dl = cb_height / (available_l ? SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cb - 1, y_cb) : 1);
1174
1175
6/6
✓ Branch 0 taken 287078 times.
✓ Branch 1 taken 106011 times.
✓ Branch 2 taken 267627 times.
✓ Branch 3 taken 19451 times.
✓ Branch 4 taken 13371 times.
✓ Branch 5 taken 254256 times.
393089 if (da == dl || !available_a || !available_l)
1176 138833 inc = 0;
1177
2/2
✓ Branch 0 taken 133109 times.
✓ Branch 1 taken 121147 times.
254256 else if (da < dl)
1178 133109 inc = 1;
1179 else
1180 121147 inc = 2;
1181 }
1182 578886 return GET_CABAC(MTT_SPLIT_CU_VERTICAL_FLAG + inc);
1183 }
1184
4/4
✓ Branch 0 taken 69643 times.
✓ Branch 1 taken 108449 times.
✓ Branch 2 taken 68897 times.
✓ Branch 3 taken 746 times.
178092 return !(a->bth || a->tth);
1185 }
1186
1187 507423 static int mtt_split_cu_binary_flag_decode(VVCLocalContext *lc, const int mtt_split_cu_vertical_flag, const int mtt_depth)
1188 {
1189 507423 const int inc = (2 * mtt_split_cu_vertical_flag) + ((mtt_depth <= 1) ? 1 : 0);
1190 507423 return GET_CABAC(MTT_SPLIT_CU_BINARY_FLAG + inc);
1191 }
1192
1193 867185 VVCSplitMode ff_vvc_split_mode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height,
1194 const int cqt_depth, const int mtt_depth, const int ch_type, const VVCAllowedSplit *a)
1195 {
1196
8/8
✓ Branch 0 taken 168047 times.
✓ Branch 1 taken 699138 times.
✓ Branch 2 taken 41492 times.
✓ Branch 3 taken 126555 times.
✓ Branch 4 taken 37211 times.
✓ Branch 5 taken 4281 times.
✓ Branch 6 taken 746 times.
✓ Branch 7 taken 36465 times.
867185 const int allow_no_qt = a->btv || a->bth || a->ttv || a->tth;
1197 int split_qt_flag;
1198 int mtt_split_cu_vertical_flag;
1199 int mtt_split_cu_binary_flag;
1200 867185 const VVCSplitMode mtt_split_modes[] = {
1201 SPLIT_TT_HOR, SPLIT_BT_HOR, SPLIT_TT_VER, SPLIT_BT_VER,
1202 };
1203
4/4
✓ Branch 0 taken 830720 times.
✓ Branch 1 taken 36465 times.
✓ Branch 2 taken 287708 times.
✓ Branch 3 taken 543012 times.
867185 if (allow_no_qt && a->qt) {
1204 287708 split_qt_flag = split_qt_flag_decode(lc, x0, y0, ch_type, cqt_depth);
1205 } else {
1206
3/4
✓ Branch 0 taken 543012 times.
✓ Branch 1 taken 36465 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 543012 times.
579477 split_qt_flag = !allow_no_qt || a->qt;
1207 }
1208
2/2
✓ Branch 0 taken 110207 times.
✓ Branch 1 taken 756978 times.
867185 if (split_qt_flag)
1209 110207 return SPLIT_QT;
1210 756978 mtt_split_cu_vertical_flag = mtt_split_cu_vertical_flag_decode(lc, x0, y0, cb_width, cb_height, ch_type, a);
1211
6/6
✓ Branch 0 taken 632165 times.
✓ Branch 1 taken 124813 times.
✓ Branch 2 taken 445656 times.
✓ Branch 3 taken 186509 times.
✓ Branch 4 taken 199443 times.
✓ Branch 5 taken 246213 times.
756978 if ((a->btv && a->ttv && mtt_split_cu_vertical_flag) ||
1212
6/6
✓ Branch 0 taken 473302 times.
✓ Branch 1 taken 37463 times.
✓ Branch 2 taken 293891 times.
✓ Branch 3 taken 179411 times.
✓ Branch 4 taken 261210 times.
✓ Branch 5 taken 32681 times.
510765 (a->bth && a->tth && !mtt_split_cu_vertical_flag)) {
1213 507423 mtt_split_cu_binary_flag = mtt_split_cu_binary_flag_decode(lc, mtt_split_cu_vertical_flag, mtt_depth);
1214 } else {
1215
4/4
✓ Branch 0 taken 79465 times.
✓ Branch 1 taken 170090 times.
✓ Branch 2 taken 2339 times.
✓ Branch 3 taken 77126 times.
249555 if (!a->btv && !a->bth)
1216 2339 mtt_split_cu_binary_flag = 0;
1217
4/4
✓ Branch 0 taken 205660 times.
✓ Branch 1 taken 41556 times.
✓ Branch 2 taken 175216 times.
✓ Branch 3 taken 30444 times.
247216 else if (!a->ttv && !a->tth)
1218 175216 mtt_split_cu_binary_flag = 1;
1219
4/4
✓ Branch 0 taken 64605 times.
✓ Branch 1 taken 7395 times.
✓ Branch 2 taken 36112 times.
✓ Branch 3 taken 28493 times.
72000 else if (a->bth && a->ttv)
1220 36112 mtt_split_cu_binary_flag = 1 - mtt_split_cu_vertical_flag;
1221 else
1222 35888 mtt_split_cu_binary_flag = mtt_split_cu_vertical_flag;
1223 }
1224 756978 return mtt_split_modes[(mtt_split_cu_vertical_flag << 1) + mtt_split_cu_binary_flag];
1225 }
1226
1227 42486 int ff_vvc_non_inter_flag(VVCLocalContext *lc, const int x0, const int y0, const int ch_type)
1228 {
1229 42486 const VVCFrameContext *fc = lc->fc;
1230 42486 uint8_t inc, left = MODE_INTER, top = MODE_INTER;
1231
1232 42486 get_left_top(lc, &left, &top, x0, y0, fc->tab.cpm[ch_type], fc->tab.cpm[ch_type]);
1233
4/4
✓ Branch 0 taken 31276 times.
✓ Branch 1 taken 11210 times.
✓ Branch 2 taken 5716 times.
✓ Branch 3 taken 25560 times.
42486 inc = left == MODE_INTRA || top == MODE_INTRA;
1234 42486 return GET_CABAC(NON_INTER_FLAG + inc);
1235 }
1236
1237 211084 int ff_vvc_pred_mode_flag(VVCLocalContext *lc, const int is_chroma)
1238 {
1239 211084 const VVCFrameContext *fc = lc->fc;
1240 211084 const CodingUnit *cu = lc->cu;
1241 211084 uint8_t inc, left = MODE_INTER, top = MODE_INTER;
1242
1243 211084 get_left_top(lc, &left, &top, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]);
1244
4/4
✓ Branch 0 taken 167062 times.
✓ Branch 1 taken 44022 times.
✓ Branch 2 taken 18659 times.
✓ Branch 3 taken 148403 times.
211084 inc = left == MODE_INTRA || top == MODE_INTRA;
1245 211084 return GET_CABAC(PRED_MODE_FLAG + inc);
1246 }
1247
1248 21149 int ff_vvc_pred_mode_plt_flag(VVCLocalContext *lc)
1249 {
1250 21149 return GET_CABAC(PRED_MODE_PLT_FLAG);
1251 }
1252
1253 46942 int ff_vvc_intra_bdpcm_luma_flag(VVCLocalContext *lc)
1254 {
1255 46942 return GET_CABAC(INTRA_BDPCM_LUMA_FLAG);
1256 }
1257
1258 10719 int ff_vvc_intra_bdpcm_luma_dir_flag(VVCLocalContext *lc)
1259 {
1260 10719 return GET_CABAC(INTRA_BDPCM_LUMA_DIR_FLAG);
1261 }
1262
1263 38304 int ff_vvc_intra_bdpcm_chroma_flag(VVCLocalContext *lc)
1264 {
1265 38304 return GET_CABAC(INTRA_BDPCM_CHROMA_FLAG);
1266 }
1267
1268 132 int ff_vvc_intra_bdpcm_chroma_dir_flag(VVCLocalContext *lc)
1269 {
1270 132 return GET_CABAC(INTRA_BDPCM_CHROMA_DIR_FLAG);
1271 }
1272
1273 649940 int ff_vvc_cu_skip_flag(VVCLocalContext *lc, const uint8_t *cu_skip_flag)
1274 {
1275 649940 const int inc = get_inc(lc, cu_skip_flag);
1276 649940 return GET_CABAC(CU_SKIP_FLAG + inc);
1277 }
1278
1279 157419 int ff_vvc_pred_mode_ibc_flag(VVCLocalContext *lc, const int is_chroma)
1280 {
1281 157419 const VVCFrameContext *fc = lc->fc;
1282 157419 const CodingUnit *cu = lc->cu;
1283 157419 uint8_t left_mode = MODE_INTER, top_mode = MODE_INTER;
1284 int inc;
1285
1286 157419 get_left_top(lc, &left_mode, &top_mode, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]);
1287 157419 inc = (left_mode == MODE_IBC) + (top_mode == MODE_IBC);
1288 157419 return GET_CABAC(PRED_MODE_IBC_FLAG + inc);
1289 }
1290
1291 static av_always_inline
1292 372478 uint8_t get_mip_inc(VVCLocalContext *lc, const uint8_t *ctx)
1293 {
1294 372478 uint8_t left = 0, top = 0;
1295 372478 get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx);
1296 372478 return (left & 1) + (top & 1);
1297 }
1298
1299 471859 int ff_vvc_intra_mip_flag(VVCLocalContext *lc, const uint8_t *intra_mip_flag)
1300 {
1301 471859 const int w = lc->cu->cb_width;
1302 471859 const int h = lc->cu->cb_height;
1303
4/4
✓ Branch 0 taken 399907 times.
✓ Branch 1 taken 71952 times.
✓ Branch 2 taken 372478 times.
✓ Branch 3 taken 27429 times.
471859 const int inc = (w > h * 2 || h > w * 2) ? 3 : get_mip_inc(lc, intra_mip_flag);
1304 471859 return GET_CABAC(INTRA_MIP_FLAG + inc);
1305 }
1306
1307 111083 int ff_vvc_intra_mip_transposed_flag(VVCLocalContext *lc)
1308 {
1309 111083 return get_cabac_bypass(&lc->ep->cc);
1310 }
1311
1312 111083 int ff_vvc_intra_mip_mode(VVCLocalContext *lc)
1313 {
1314 111083 const int w = lc->cu->cb_width;
1315 111083 const int h = lc->cu->cb_height;
1316
4/4
✓ Branch 0 taken 32339 times.
✓ Branch 1 taken 78744 times.
✓ Branch 2 taken 16203 times.
✓ Branch 3 taken 16136 times.
206030 const int c_max = (w == 4 && h == 4) ? 15 :
1317
8/8
✓ Branch 0 taken 78744 times.
✓ Branch 1 taken 16203 times.
✓ Branch 2 taken 54667 times.
✓ Branch 3 taken 24077 times.
✓ Branch 4 taken 18257 times.
✓ Branch 5 taken 36410 times.
✓ Branch 6 taken 10839 times.
✓ Branch 7 taken 7418 times.
94947 ((w == 4 || h == 4) || (w == 8 && h == 8)) ? 7: 5;
1318 111083 return truncated_binary_decode(lc, c_max);
1319 }
1320
1321 443672 int ff_vvc_intra_luma_ref_idx(VVCLocalContext *lc)
1322 {
1323 int i;
1324
2/2
✓ Branch 0 taken 488338 times.
✓ Branch 1 taken 26339 times.
514677 for (i = 0; i < 2; i++) {
1325
2/2
✓ Branch 1 taken 417333 times.
✓ Branch 2 taken 71005 times.
488338 if (!GET_CABAC(INTRA_LUMA_REF_IDX + i))
1326 417333 return i;
1327 }
1328 26339 return i;
1329 }
1330
1331 369431 int ff_vvc_intra_subpartitions_mode_flag(VVCLocalContext *lc)
1332 {
1333 369431 return GET_CABAC(INTRA_SUBPARTITIONS_MODE_FLAG);
1334 }
1335
1336 503218 enum IspType ff_vvc_isp_split_type(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
1337 {
1338
2/2
✓ Branch 0 taken 438509 times.
✓ Branch 1 taken 64709 times.
503218 if (!intra_subpartitions_mode_flag)
1339 438509 return ISP_NO_SPLIT;
1340 64709 return 1 + GET_CABAC(INTRA_SUBPARTITIONS_SPLIT_FLAG);
1341 }
1342
1343 458552 int ff_vvc_intra_luma_mpm_flag(VVCLocalContext *lc)
1344 {
1345 458552 return GET_CABAC(INTRA_LUMA_MPM_FLAG);
1346 }
1347
1348 331139 int ff_vvc_intra_luma_not_planar_flag(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
1349 {
1350
2/2
✓ Branch 0 taken 281930 times.
✓ Branch 1 taken 49209 times.
331139 return GET_CABAC(INTRA_LUMA_NOT_PLANAR_FLAG + !intra_subpartitions_mode_flag);
1351 }
1352
1353 201212 int ff_vvc_intra_luma_mpm_idx(VVCLocalContext *lc)
1354 {
1355 int i;
1356
4/4
✓ Branch 0 taken 376566 times.
✓ Branch 1 taken 14546 times.
✓ Branch 3 taken 189900 times.
✓ Branch 4 taken 186666 times.
391112 for (i = 0; i < 4 && get_cabac_bypass(&lc->ep->cc); i++)
1357 /* nothing */;
1358 201212 return i;
1359 }
1360
1361 127413 int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc)
1362 {
1363 127413 return truncated_binary_decode(lc, 60);
1364 }
1365
1366 222322 int ff_vvc_cclm_mode_flag(VVCLocalContext *lc)
1367 {
1368 222322 return GET_CABAC(CCLM_MODE_FLAG);
1369 }
1370
1371 96828 int ff_vvc_cclm_mode_idx(VVCLocalContext *lc)
1372 {
1373
2/2
✓ Branch 1 taken 54540 times.
✓ Branch 2 taken 42288 times.
96828 if (!GET_CABAC(CCLM_MODE_IDX))
1374 54540 return 0;
1375 42288 return get_cabac_bypass(&lc->ep->cc) + 1;
1376 }
1377
1378 146924 int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc)
1379 {
1380
2/2
✓ Branch 1 taken 103178 times.
✓ Branch 2 taken 43746 times.
146924 if (!GET_CABAC(INTRA_CHROMA_PRED_MODE))
1381 103178 return 4;
1382 43746 return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1383 }
1384
1385 28514 int ff_vvc_palette_predictor_run(VVCLocalContext *lc, const int max)
1386 {
1387 28514 return kth_order_egk_decode(&lc->ep->cc, 0, max);
1388 }
1389
1390 4497 int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc, const int max)
1391 {
1392 4497 return kth_order_egk_decode(&lc->ep->cc, 0, max);
1393 }
1394
1395 3654 int ff_vvc_new_palette_entries(VVCLocalContext *lc, const int bit_depth)
1396 {
1397 3654 return fixed_length_decode(&lc->ep->cc, bit_depth);
1398 }
1399
1400 4497 bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc)
1401 {
1402 4497 return get_cabac_bypass(&lc->ep->cc);
1403 }
1404
1405 4046 bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc)
1406 {
1407 4046 return GET_CABAC(PALETTE_TRANSPOSE_FLAG);
1408 }
1409
1410 608210 bool ff_vvc_run_copy_flag(VVCLocalContext *lc, const int prev_run_type, const int prev_run_position, const int cur_pos)
1411 {
1412 608210 uint8_t run_left_lut[] = { 0, 1, 2, 3, 4 };
1413 608210 uint8_t run_top_lut[] = { 5, 6, 6, 7, 7 };
1414
1415 608210 int bin_dist = cur_pos - prev_run_position - 1;
1416
2/2
✓ Branch 0 taken 224058 times.
✓ Branch 1 taken 384152 times.
608210 uint8_t *run_lut = prev_run_type == 1 ? run_top_lut : run_left_lut;
1417
2/2
✓ Branch 0 taken 205881 times.
✓ Branch 1 taken 402329 times.
608210 uint8_t ctx_inc = bin_dist <= 4 ? run_lut[bin_dist] : run_lut[4];
1418
1419 608210 return GET_CABAC(RUN_COPY_FLAG + ctx_inc);
1420 }
1421
1422 68722 bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc)
1423 {
1424 68722 return GET_CABAC(COPY_ABOVE_PALETTE_INDICES_FLAG);
1425 }
1426
1427 74987 int ff_vvc_palette_idx_idc(VVCLocalContext *lc, const int max_palette_index, const bool adjust)
1428 {
1429 74987 return truncated_binary_decode(lc, max_palette_index - adjust);
1430 }
1431
1432 145 int ff_vvc_palette_escape_val(VVCLocalContext *lc, const int max)
1433 {
1434 145 return kth_order_egk_decode(&lc->ep->cc, 5, max);
1435 }
1436
1437 245106 int ff_vvc_general_merge_flag(VVCLocalContext *lc)
1438 {
1439 245106 return GET_CABAC(GENERAL_MERGE_FLAG);
1440 }
1441
1442 340152 static int get_inter_flag_inc(VVCLocalContext *lc, const int x0, const int y0)
1443 {
1444 340152 uint8_t left_merge = 0, top_merge = 0;
1445 340152 uint8_t left_affine = 0, top_affine = 0;
1446 340152 const VVCFrameContext *fc = lc->fc;
1447
1448 340152 get_left_top(lc, &left_merge, &top_merge, x0, y0, fc->tab.msf, fc->tab.msf);
1449 340152 get_left_top(lc, &left_affine, &top_affine, x0, y0, fc->tab.iaf, fc->tab.iaf);
1450
4/4
✓ Branch 0 taken 295941 times.
✓ Branch 1 taken 44211 times.
✓ Branch 2 taken 10007 times.
✓ Branch 3 taken 285934 times.
340152 return (left_merge || left_affine) + (top_merge + top_affine);
1451 }
1452
1453 309907 int ff_vvc_merge_subblock_flag(VVCLocalContext *lc)
1454 {
1455 309907 const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0);
1456 309907 return GET_CABAC(MERGE_SUBBLOCK_FLAG + inc);
1457 }
1458
1459 54562 int ff_vvc_merge_subblock_idx(VVCLocalContext *lc, const int max_num_subblock_merge_cand)
1460 {
1461 int i;
1462
2/2
✓ Branch 1 taken 33668 times.
✓ Branch 2 taken 20894 times.
54562 if (!GET_CABAC(MERGE_SUBBLOCK_IDX))
1463 33668 return 0;
1464
4/4
✓ Branch 0 taken 34764 times.
✓ Branch 1 taken 2770 times.
✓ Branch 3 taken 16640 times.
✓ Branch 4 taken 18124 times.
37534 for (i = 1; i < max_num_subblock_merge_cand - 1 && get_cabac_bypass(&lc->ep->cc); i++)
1465 /* nothing */;
1466 20894 return i;
1467 }
1468
1469 236092 int ff_vvc_regular_merge_flag(VVCLocalContext *lc, const int cu_skip_flag)
1470 {
1471 236092 int inc = !cu_skip_flag;
1472 236092 return GET_CABAC(REGULAR_MERGE_FLAG + inc);
1473 }
1474
1475 275841 int ff_vvc_mmvd_merge_flag(VVCLocalContext *lc)
1476 {
1477 275841 return GET_CABAC(MMVD_MERGE_FLAG);
1478 }
1479
1480 58025 int ff_vvc_mmvd_cand_flag(VVCLocalContext *lc)
1481 {
1482 58025 return GET_CABAC(MMVD_CAND_FLAG);
1483 }
1484
1485 58025 static int mmvd_distance_idx_decode(VVCLocalContext *lc)
1486 {
1487 int i;
1488
2/2
✓ Branch 1 taken 15128 times.
✓ Branch 2 taken 42897 times.
58025 if (!GET_CABAC(MMVD_DISTANCE_IDX))
1489 15128 return 0;
1490
4/4
✓ Branch 0 taken 84220 times.
✓ Branch 1 taken 225 times.
✓ Branch 3 taken 41548 times.
✓ Branch 4 taken 42672 times.
84445 for (i = 1; i < 7 && get_cabac_bypass(&lc->ep->cc); i++)
1491 /* nothing */;
1492 42897 return i;
1493 }
1494
1495 58025 static int mmvd_direction_idx_decode(VVCLocalContext *lc)
1496 {
1497 58025 return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1498 }
1499
1500 58025 void ff_vvc_mmvd_offset_coding(VVCLocalContext *lc, Mv *mmvd_offset, const int ph_mmvd_fullpel_only_flag)
1501 {
1502
2/2
✓ Branch 0 taken 660 times.
✓ Branch 1 taken 57365 times.
58025 const int shift = ph_mmvd_fullpel_only_flag ? 4 : 2;
1503 58025 const int mmvd_distance = 1 << (mmvd_distance_idx_decode(lc) + shift);
1504 58025 const int mmvd_direction_idx = mmvd_direction_idx_decode(lc);
1505 58025 const int mmvd_signs[][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
1506 58025 mmvd_offset->x = mmvd_distance * mmvd_signs[mmvd_direction_idx][0];
1507 58025 mmvd_offset->y = mmvd_distance * mmvd_signs[mmvd_direction_idx][1];
1508 58025 }
1509
1510 267257 static PredMode get_luma_pred_mode(VVCLocalContext *lc)
1511 {
1512 267257 const VVCFrameContext *fc = lc->fc;
1513 267257 const CodingUnit *cu = lc->cu;
1514 PredMode pred_mode;
1515
1516
1/2
✓ Branch 0 taken 267257 times.
✗ Branch 1 not taken.
267257 if (cu->tree_type != DUAL_TREE_CHROMA) {
1517 267257 pred_mode = cu->pred_mode;
1518 } else {
1519 const int x_cb = cu->x0 >> fc->ps.sps->min_cb_log2_size_y;
1520 const int y_cb = cu->y0 >> fc->ps.sps->min_cb_log2_size_y;
1521 const int min_cb_width = fc->ps.pps->min_cb_width;
1522 pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_cb, y_cb);
1523 }
1524 267257 return pred_mode;
1525 }
1526
1527 267257 int ff_vvc_merge_idx(VVCLocalContext *lc)
1528 {
1529 267257 const VVCSPS *sps = lc->fc->ps.sps;
1530 267257 const int is_ibc = get_luma_pred_mode(lc) == MODE_IBC;
1531
2/2
✓ Branch 0 taken 27950 times.
✓ Branch 1 taken 239307 times.
267257 const int c_max = (is_ibc ? sps->max_num_ibc_merge_cand : sps->max_num_merge_cand) - 1;
1532 int i;
1533
1534
2/2
✓ Branch 1 taken 163100 times.
✓ Branch 2 taken 104157 times.
267257 if (!GET_CABAC(MERGE_IDX))
1535 163100 return 0;
1536
1537
4/4
✓ Branch 0 taken 197752 times.
✓ Branch 1 taken 10811 times.
✓ Branch 3 taken 104406 times.
✓ Branch 4 taken 93346 times.
208563 for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++)
1538 /* nothing */;
1539 104157 return i;
1540 }
1541
1542 27591 int ff_vvc_merge_gpm_partition_idx(VVCLocalContext *lc)
1543 {
1544 27591 return fixed_length_decode(&lc->ep->cc, 6);
1545 }
1546
1547 55182 int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx)
1548 {
1549 55182 const int c_max = lc->fc->ps.sps->max_num_gpm_merge_cand - idx - 1;
1550 int i;
1551
1552
2/2
✓ Branch 1 taken 30813 times.
✓ Branch 2 taken 24369 times.
55182 if (!GET_CABAC(MERGE_IDX))
1553 30813 return 0;
1554
1555
4/4
✓ Branch 0 taken 43272 times.
✓ Branch 1 taken 4114 times.
✓ Branch 3 taken 23017 times.
✓ Branch 4 taken 20255 times.
47386 for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++)
1556 /* nothing */;
1557
1558 24369 return i;
1559 }
1560
1561 20147 int ff_vvc_ciip_flag(VVCLocalContext *lc)
1562 {
1563 20147 return GET_CABAC(CIIP_FLAG);
1564 }
1565
1566 80598 PredFlag ff_vvc_pred_flag(VVCLocalContext *lc, const int is_b)
1567 {
1568 80598 const int w = lc->cu->cb_width;
1569 80598 const int h = lc->cu->cb_height;
1570
2/2
✓ Branch 0 taken 7045 times.
✓ Branch 1 taken 73553 times.
80598 if (!is_b)
1571 7045 return PF_L0;
1572
2/2
✓ Branch 0 taken 64305 times.
✓ Branch 1 taken 9248 times.
73553 if (w + h > 12) {
1573 64305 const int log2 = av_log2(w) + av_log2(h);
1574 64305 const int inc = 7 - ((1 + log2)>>1);
1575
2/2
✓ Branch 1 taken 21767 times.
✓ Branch 2 taken 42538 times.
64305 if (GET_CABAC(INTER_PRED_IDC + inc))
1576 21767 return PF_BI;
1577 }
1578 51786 return PF_L0 + GET_CABAC(INTER_PRED_IDC + 5);
1579 }
1580
1581 30245 int ff_vvc_inter_affine_flag(VVCLocalContext *lc)
1582 {
1583 30245 const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0);
1584 30245 return GET_CABAC(INTER_AFFINE_FLAG + inc);
1585 }
1586
1587 9326 int ff_vvc_cu_affine_type_flag(VVCLocalContext *lc)
1588 {
1589 9326 return GET_CABAC(CU_AFFINE_TYPE_FLAG);
1590 }
1591
1592 12919 int ff_vvc_sym_mvd_flag(VVCLocalContext *lc)
1593 {
1594 12919 return GET_CABAC(SYM_MVD_FLAG);
1595 }
1596
1597 71726 int ff_vvc_ref_idx_lx(VVCLocalContext *lc, const uint8_t nb_refs)
1598 {
1599 71726 const int c_max = nb_refs - 1;
1600 71726 const int max_ctx = FFMIN(c_max, 2);
1601 71726 int i = 0;
1602
1603
4/4
✓ Branch 0 taken 88501 times.
✓ Branch 1 taken 27339 times.
✓ Branch 3 taken 44114 times.
✓ Branch 4 taken 44387 times.
115840 while (i < max_ctx && GET_CABAC(REF_IDX_LX + i))
1604 44114 i++;
1605
2/2
✓ Branch 0 taken 14956 times.
✓ Branch 1 taken 56770 times.
71726 if (i == 2) {
1606
4/4
✓ Branch 0 taken 45136 times.
✓ Branch 1 taken 10535 times.
✓ Branch 3 taken 40715 times.
✓ Branch 4 taken 4421 times.
55671 while (i < c_max && get_cabac_bypass(&lc->ep->cc))
1607 40715 i++;
1608 }
1609 71726 return i;
1610 }
1611
1612 293134 int ff_vvc_abs_mvd_greater0_flag(VVCLocalContext *lc)
1613 {
1614 293134 return GET_CABAC(ABS_MVD_GREATER0_FLAG);
1615 }
1616
1617 191303 int ff_vvc_abs_mvd_greater1_flag(VVCLocalContext *lc)
1618 {
1619 191303 return GET_CABAC(ABS_MVD_GREATER1_FLAG);
1620 }
1621
1622 134309 int ff_vvc_abs_mvd_minus2(VVCLocalContext *lc)
1623 {
1624 134309 return limited_kth_order_egk_decode(&lc->ep->cc, 1, 15, 17);
1625 }
1626
1627 191303 int ff_vvc_mvd_sign_flag(VVCLocalContext *lc)
1628 {
1629 191303 return get_cabac_bypass(&lc->ep->cc);
1630 }
1631
1632 140073 int ff_vvc_mvp_lx_flag(VVCLocalContext *lc)
1633 {
1634 140073 return GET_CABAC(MVP_LX_FLAG);
1635 }
1636
1637 74271 static int amvr_flag(VVCLocalContext *lc, const int inter_affine_flag)
1638 {
1639 74271 return GET_CABAC(AMVR_FLAG + inter_affine_flag);
1640 }
1641
1642 75521 static int amvr_precision_idx(VVCLocalContext *lc, const int inc, const int c_max)
1643 {
1644 75521 int i = 0;
1645
2/2
✓ Branch 1 taken 22272 times.
✓ Branch 2 taken 53249 times.
75521 if (!GET_CABAC(AMVR_PRECISION_IDX + inc))
1646 22272 return 0;
1647 53249 i++;
1648
4/4
✓ Branch 0 taken 36705 times.
✓ Branch 1 taken 16544 times.
✓ Branch 3 taken 13046 times.
✓ Branch 4 taken 23659 times.
53249 if (i < c_max && GET_CABAC(AMVR_PRECISION_IDX + 1))
1649 13046 i++;
1650 53249 return i;
1651 }
1652
1653 104773 int ff_vvc_amvr_shift(VVCLocalContext *lc, const int inter_affine_flag,
1654 const PredMode pred_mode, const int has_amvr_flag)
1655 {
1656 104773 int amvr_shift = 2;
1657
2/2
✓ Branch 0 taken 98446 times.
✓ Branch 1 taken 6327 times.
104773 if (has_amvr_flag) {
1658
4/4
✓ Branch 0 taken 74271 times.
✓ Branch 1 taken 24175 times.
✓ Branch 3 taken 51346 times.
✓ Branch 4 taken 22925 times.
98446 if (pred_mode == MODE_IBC || amvr_flag(lc, inter_affine_flag)) {
1659 int idx;
1660
2/2
✓ Branch 0 taken 4563 times.
✓ Branch 1 taken 70958 times.
75521 if (inter_affine_flag) {
1661 4563 idx = amvr_precision_idx(lc, 2, 1);
1662 4563 amvr_shift = idx * 4;
1663
2/2
✓ Branch 0 taken 24175 times.
✓ Branch 1 taken 46783 times.
70958 } else if (pred_mode == MODE_IBC) {
1664 24175 idx = amvr_precision_idx(lc, 1, 1);
1665 24175 amvr_shift = 4 + idx * 2;
1666 } else {
1667 static const int shifts[] = {3, 4, 6};
1668 46783 idx = amvr_precision_idx(lc, 0, 2);
1669 46783 amvr_shift = shifts[idx];
1670 }
1671 }
1672 }
1673 104773 return amvr_shift;
1674 }
1675
1676 12145 int ff_vvc_bcw_idx(VVCLocalContext *lc, const int no_backward_pred_flag)
1677 {
1678
2/2
✓ Branch 0 taken 2598 times.
✓ Branch 1 taken 9547 times.
12145 const int c_max = no_backward_pred_flag ? 4 : 2;
1679 12145 int i = 1;
1680
2/2
✓ Branch 1 taken 7116 times.
✓ Branch 2 taken 5029 times.
12145 if (!GET_CABAC(BCW_IDX))
1681 7116 return 0;
1682
4/4
✓ Branch 0 taken 5911 times.
✓ Branch 1 taken 1982 times.
✓ Branch 3 taken 2864 times.
✓ Branch 4 taken 3047 times.
7893 while (i < c_max && get_cabac_bypass(&lc->ep->cc))
1683 2864 i++;
1684 5029 return i;
1685 }
1686
1687 427568 int ff_vvc_tu_cb_coded_flag(VVCLocalContext *lc)
1688 {
1689 427568 return GET_CABAC(TU_CB_CODED_FLAG + lc->cu->bdpcm_flag[1]);
1690 }
1691
1692 427568 int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag)
1693 {
1694
2/2
✓ Branch 0 taken 427436 times.
✓ Branch 1 taken 132 times.
427568 return GET_CABAC(TU_CR_CODED_FLAG + (lc->cu->bdpcm_flag[1] ? 2 : tu_cb_coded_flag));
1695 }
1696
1697 827955 int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc)
1698 {
1699 827955 const CodingUnit *cu = lc->cu;
1700 int inc;
1701
2/2
✓ Branch 0 taken 10352 times.
✓ Branch 1 taken 817603 times.
827955 if (cu->bdpcm_flag[0])
1702 10352 inc = 1;
1703
2/2
✓ Branch 0 taken 619130 times.
✓ Branch 1 taken 198473 times.
817603 else if (cu->isp_split_type == ISP_NO_SPLIT)
1704 619130 inc = 0;
1705 else
1706 198473 inc = 2 + lc->parse.prev_tu_cbf_y;
1707 827955 lc->parse.prev_tu_cbf_y = GET_CABAC(TU_Y_CODED_FLAG + inc);
1708 827955 return lc->parse.prev_tu_cbf_y;
1709 }
1710
1711 15652 int ff_vvc_cu_act_enabled_flag(VVCLocalContext *lc)
1712 {
1713 15652 return GET_CABAC(CU_ACT_ENABLED_FLAG);
1714 }
1715
1716 1888 int ff_vvc_cu_qp_delta_abs(VVCLocalContext *lc)
1717 {
1718 int v, i, k;
1719
2/2
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 1106 times.
1888 if (!GET_CABAC(CU_QP_DELTA_ABS))
1720 782 return 0;
1721
1722 // prefixVal
1723
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++)
1724 /* nothing */;
1725
2/2
✓ Branch 0 taken 1071 times.
✓ Branch 1 taken 35 times.
1106 if (v < 5)
1726 1071 return v;
1727
1728 // 9.3.3.5 k-th order Exp-Golomb binarization process
1729 // suffixVal
1730
1731 // CuQpDeltaVal shall in the range of −( 32 + QpBdOffset / 2 ) to +( 31 + QpBdOffset / 2 )
1732 // so k = 6 should enough
1733
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++)
1734 /* nothing */;
1735 35 i = (1 << k) - 1;
1736 35 v = 0;
1737
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 35 times.
66 while (k--)
1738 31 v = (v << 1) + get_cabac_bypass(&lc->ep->cc);
1739 35 v += i;
1740
1741 35 return v + 5;
1742 }
1743
1744 1106 int ff_vvc_cu_qp_delta_sign_flag(VVCLocalContext *lc)
1745 {
1746 1106 return get_cabac_bypass(&lc->ep->cc);
1747 }
1748
1749 1029 int ff_vvc_cu_chroma_qp_offset_flag(VVCLocalContext *lc)
1750 {
1751 1029 return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG);
1752 }
1753
1754 931 int ff_vvc_cu_chroma_qp_offset_idx(VVCLocalContext *lc)
1755 {
1756 931 const int c_max = lc->fc->ps.pps->r->pps_chroma_qp_offset_list_len_minus1;
1757 int i;
1758
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++)
1759 /* nothing */;
1760 931 return i;
1761 }
1762
1763 1914794 static av_always_inline int last_significant_coeff_xy_prefix(VVCLocalContext *lc,
1764 const int log2_tb_size, const int log2_zo_tb_size, const int c_idx, const int ctx)
1765 {
1766 1914794 int i = 0;
1767 1914794 int max = (log2_zo_tb_size << 1) - 1;
1768 int ctx_offset, ctx_shift;
1769
2/2
✓ Branch 0 taken 16474 times.
✓ Branch 1 taken 1898320 times.
1914794 if (!log2_tb_size)
1770 16474 return 0;
1771
2/2
✓ Branch 0 taken 1369296 times.
✓ Branch 1 taken 529024 times.
1898320 if (!c_idx) {
1772 1369296 const int offset_y[] = {0, 0, 3, 6, 10, 15};
1773 1369296 ctx_offset = offset_y[log2_tb_size - 1];
1774 1369296 ctx_shift = (log2_tb_size + 1) >> 2;
1775 } else {
1776 529024 const int shifts[] = {0, 0, 0, 1, 2, 2, 2};
1777 529024 ctx_offset = 20;
1778 529024 ctx_shift = shifts[log2_tb_size];
1779 }
1780
4/4
✓ Branch 0 taken 4987435 times.
✓ Branch 1 taken 303147 times.
✓ Branch 3 taken 3392262 times.
✓ Branch 4 taken 1595173 times.
5290582 while (i < max && GET_CABAC(ctx + (i >> ctx_shift) + ctx_offset))
1781 3392262 i++;
1782 1898320 return i;
1783 }
1784
1785 957397 static av_always_inline int last_significant_coeff_x_prefix_decode(VVCLocalContext *lc,
1786 const int log2_tb_width, const int log2_zo_tb_width, const int c_idx)
1787 {
1788 957397 return last_significant_coeff_xy_prefix(lc, log2_tb_width, log2_zo_tb_width, c_idx, LAST_SIG_COEFF_X_PREFIX);
1789 }
1790
1791 957397 static av_always_inline int last_significant_coeff_y_prefix_decode(VVCLocalContext *lc,
1792 const int log2_tb_height, const int log2_zo_tb_height, const int c_idx)
1793 {
1794 957397 return last_significant_coeff_xy_prefix(lc, log2_tb_height, log2_zo_tb_height, c_idx, LAST_SIG_COEFF_Y_PREFIX);
1795 }
1796
1797 364732 static av_always_inline int last_sig_coeff_suffix_decode(VVCLocalContext *lc,
1798 const int last_significant_coeff_y_prefix)
1799 {
1800 364732 const int length = (last_significant_coeff_y_prefix >> 1) - 1;
1801 364732 int value = get_cabac_bypass(&lc->ep->cc);
1802
1803
2/2
✓ Branch 0 taken 151991 times.
✓ Branch 1 taken 364732 times.
516723 for (int i = 1; i < length; i++)
1804 151991 value = (value << 1) | get_cabac_bypass(&lc->ep->cc);
1805 364732 return value;
1806 }
1807
1808 157904 int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, const int tu_cb_coded_flag, const int tu_cr_coded_flag)
1809 {
1810 157904 return GET_CABAC(TU_JOINT_CBCR_RESIDUAL_FLAG + 2 * tu_cb_coded_flag + tu_cr_coded_flag - 1);
1811 }
1812
1813 682923 int ff_vvc_transform_skip_flag(VVCLocalContext *lc, const int inc)
1814 {
1815 682923 return GET_CABAC(TRANSFORM_SKIP_FLAG + inc);
1816 }
1817
1818 //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1
1819 39464227 static int get_local_sum(const int *level, const int w, const int h,
1820 const int xc, const int yc, const int hist_value)
1821 {
1822 39464227 int loc_sum = 3 * hist_value;
1823 39464227 level += w * yc + xc;
1824
2/2
✓ Branch 0 taken 38016101 times.
✓ Branch 1 taken 1448126 times.
39464227 if (xc < w - 1) {
1825 38016101 loc_sum += level[1];
1826
2/2
✓ Branch 0 taken 35869432 times.
✓ Branch 1 taken 2146669 times.
38016101 if (xc < w - 2)
1827 35869432 loc_sum += level[2] - hist_value;
1828
2/2
✓ Branch 0 taken 35124222 times.
✓ Branch 1 taken 2891879 times.
38016101 if (yc < h - 1)
1829 35124222 loc_sum += level[w + 1] - hist_value;
1830 }
1831
2/2
✓ Branch 0 taken 36571232 times.
✓ Branch 1 taken 2892995 times.
39464227 if (yc < h - 1) {
1832 36571232 loc_sum += level[w];
1833
2/2
✓ Branch 0 taken 33140692 times.
✓ Branch 1 taken 3430540 times.
36571232 if (yc < h - 2)
1834 33140692 loc_sum += level[w << 1] - hist_value;
1835 }
1836 39464227 return loc_sum;
1837 }
1838
1839 //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1
1840 1392981 static int get_local_sum_ts(const int *level, const int w, const int h, const int xc, const int yc)
1841 {
1842 1392981 int loc_sum = 0;
1843 1392981 level += w * yc + xc;
1844
2/2
✓ Branch 0 taken 1208259 times.
✓ Branch 1 taken 184722 times.
1392981 if (xc > 0)
1845 1208259 loc_sum += level[-1];
1846
2/2
✓ Branch 0 taken 1212190 times.
✓ Branch 1 taken 180791 times.
1392981 if (yc > 0)
1847 1212190 loc_sum += level[-w];
1848 1392981 return loc_sum;
1849 }
1850
1851 11074638 static int get_gtx_flag_inc(const ResidualCoding* rc, const int xc, const int yc, const int last)
1852 {
1853 11074638 const TransformBlock *tb = rc->tb;
1854 int inc;
1855
2/2
✓ Branch 0 taken 957397 times.
✓ Branch 1 taken 10117241 times.
11074638 if (last) {
1856 957397 const int incs[] = {0, 21, 21};
1857 957397 inc = incs[tb->c_idx];
1858 } else {
1859 10117241 const int d = xc + yc;
1860 10117241 const int local_sum_sig = get_local_sum(rc->sig_coeff_flag,
1861 10117241 tb->tb_width,tb->tb_height, xc, yc, rc->hist_value);
1862 10117241 const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1,
1863 10117241 tb->tb_width, tb->tb_height, xc, yc, rc->hist_value);
1864 10117241 const int offset = FFMIN(loc_sum_abs_pass1 - local_sum_sig, 4);
1865
1866
2/2
✓ Branch 0 taken 7243175 times.
✓ Branch 1 taken 2874066 times.
10117241 if (!tb->c_idx)
1867
6/6
✓ Branch 0 taken 6768957 times.
✓ Branch 1 taken 474218 times.
✓ Branch 2 taken 5286159 times.
✓ Branch 3 taken 1482798 times.
✓ Branch 4 taken 3303232 times.
✓ Branch 5 taken 1982927 times.
7243175 inc = 1 + offset + (!d ? 15 : (d < 3 ? 10 : (d < 10 ? 5 : 0)));
1868 else
1869
2/2
✓ Branch 0 taken 157360 times.
✓ Branch 1 taken 2716706 times.
2874066 inc = 22 + offset + (!d ? 5 : 0);
1870 }
1871 11074638 return inc;
1872 }
1873
1874 13389504 static int abs_level_gtx_flag_decode(VVCLocalContext *lc, const int inc)
1875 {
1876 13389504 return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
1877 }
1878
1879 2314866 static int par_level_flag_decode(VVCLocalContext *lc, const int inc)
1880 {
1881 2314866 return GET_CABAC(PAR_LEVEL_FLAG + inc);
1882 }
1883
1884 141904 static int par_level_flag_ts_decode(VVCLocalContext *lc)
1885 {
1886 141904 const int inc = 32;
1887 141904 return GET_CABAC(PAR_LEVEL_FLAG + inc);
1888 }
1889
1890 1135611 static int sb_coded_flag_decode(VVCLocalContext *lc, const uint8_t *sb_coded_flag,
1891 const ResidualCoding *rc, const int xs, const int ys)
1892 {
1893 1135611 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1894 1135611 const TransformBlock *tb = rc->tb;
1895 1135611 const int w = rc->width_in_sbs;
1896 1135611 const int h = rc->height_in_sbs;
1897 int inc;
1898
1899
3/4
✓ Branch 0 taken 208781 times.
✓ Branch 1 taken 926830 times.
✓ Branch 2 taken 208781 times.
✗ Branch 3 not taken.
1135611 if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) {
1900
2/2
✓ Branch 0 taken 121544 times.
✓ Branch 1 taken 87237 times.
208781 const int left = xs > 0 ? sb_coded_flag[-1] : 0;
1901
2/2
✓ Branch 0 taken 123566 times.
✓ Branch 1 taken 85215 times.
208781 const int above = ys > 0 ? sb_coded_flag[-w] : 0;
1902 208781 inc = left + above + 4;
1903 } else {
1904
2/2
✓ Branch 0 taken 807127 times.
✓ Branch 1 taken 119703 times.
926830 const int right = (xs < w - 1) ? sb_coded_flag[1] : 0;
1905
2/2
✓ Branch 0 taken 707634 times.
✓ Branch 1 taken 219196 times.
926830 const int bottom = (ys < h - 1) ? sb_coded_flag[w] : 0;
1906
2/2
✓ Branch 0 taken 337665 times.
✓ Branch 1 taken 589165 times.
926830 inc = (right | bottom) + (tb->c_idx ? 2 : 0);
1907 }
1908 1135611 return GET_CABAC(SB_CODED_FLAG + inc);
1909 }
1910
1911 19630974 static int sig_coeff_flag_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1912 {
1913 19630974 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1914 19630974 const TransformBlock *tb = rc->tb;
1915 int inc;
1916
1917
3/4
✓ Branch 0 taken 1392981 times.
✓ Branch 1 taken 18237993 times.
✓ Branch 2 taken 1392981 times.
✗ Branch 3 not taken.
19630974 if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) {
1918 1392981 const int local_num_sig = get_local_sum_ts(rc->sig_coeff_flag, tb->tb_width, tb->tb_height, xc, yc);
1919 1392981 inc = 60 + local_num_sig;
1920 } else {
1921 18237993 const int d = xc + yc;
1922 18237993 const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1,
1923 18237993 tb->tb_width, tb->tb_height, xc, yc, 0);
1924
1925
2/2
✓ Branch 0 taken 12760004 times.
✓ Branch 1 taken 5477989 times.
18237993 if (!tb->c_idx) {
1926
4/4
✓ Branch 0 taken 11282217 times.
✓ Branch 1 taken 1477787 times.
✓ Branch 2 taken 3337758 times.
✓ Branch 3 taken 7944459 times.
12760004 inc = 12 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + ((d < 2) ? 8 : (d < 5 ? 4 : 0));
1927 } else {
1928
2/2
✓ Branch 0 taken 514094 times.
✓ Branch 1 taken 4963895 times.
5477989 inc = 36 + 8 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + (d < 2 ? 4 : 0);
1929 }
1930 }
1931 19630974 return GET_CABAC(SIG_COEFF_FLAG + inc);
1932 }
1933
1934 991752 static int abs_get_rice_param(VVCLocalContext *lc, const ResidualCoding* rc,
1935 const int xc, const int yc, const int base_level)
1936 {
1937 991752 const VVCSPS *sps = lc->fc->ps.sps;
1938 991752 const TransformBlock* tb = rc->tb;
1939 991752 const int rice_params[] = {
1940 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2,
1941 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
1942 };
1943 int loc_sum_abs;
1944 int shift_val;
1945
1946 991752 loc_sum_abs = get_local_sum(rc->abs_level, tb->tb_width, tb->tb_height, xc,
1947 991752 yc, rc->hist_value);
1948
1949
1/2
✓ Branch 0 taken 991752 times.
✗ Branch 1 not taken.
991752 if (!sps->r->sps_rrc_rice_extension_flag) {
1950 991752 shift_val = 0;
1951 } else {
1952 shift_val = (av_log2(FFMAX(FFMIN(loc_sum_abs, 2048), 8)) - 3) & ~1;
1953 }
1954
1955 991752 loc_sum_abs = av_clip_uintp2((loc_sum_abs >> shift_val) - base_level * 5, 5);
1956
1957 991752 return rice_params[loc_sum_abs] + shift_val;
1958 }
1959
1960 1058028 static int abs_decode(VVCLocalContext *lc, const int c_rice_param)
1961 {
1962 1058028 const VVCSPS *sps = lc->fc->ps.sps;
1963 1058028 const int MAX_BIN = 6;
1964 1058028 int prefix = 0;
1965 1058028 int suffix = 0;
1966
1967
4/4
✓ Branch 0 taken 2427280 times.
✓ Branch 1 taken 83708 times.
✓ Branch 3 taken 1452960 times.
✓ Branch 4 taken 974320 times.
2510988 while (prefix < MAX_BIN && get_cabac_bypass(&lc->ep->cc))
1968 1452960 prefix++;
1969
2/2
✓ Branch 0 taken 974320 times.
✓ Branch 1 taken 83708 times.
1058028 if (prefix < MAX_BIN) {
1970
2/2
✓ Branch 0 taken 674145 times.
✓ Branch 1 taken 974320 times.
1648465 for (int i = 0; i < c_rice_param; i++) {
1971 674145 suffix = (suffix << 1) | get_cabac_bypass(&lc->ep->cc);
1972 }
1973 } else {
1974 83708 suffix = limited_kth_order_egk_decode(&lc->ep->cc,
1975 c_rice_param + 1,
1976 83708 26 - sps->log2_transform_range,
1977 83708 sps->log2_transform_range);
1978 }
1979 1058028 return suffix + (prefix << c_rice_param);
1980 }
1981
1982 627613 static int abs_remainder_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1983 {
1984 627613 const VVCSPS *sps = lc->fc->ps.sps;
1985 627613 const H266RawSliceHeader *rsh = lc->sc->sh.r;
1986 627613 const int base_level[][2][2] = {
1987 { {4, 4}, {4, 4} },
1988 { {3, 2}, {2, 1} }
1989 };
1990 627613 const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc,
1991 627613 base_level[sps->r->sps_rrc_rice_extension_flag][sps->bit_depth > 12][IS_I(rsh)]);
1992 627613 const int rem = abs_decode(lc, c_rice_param);
1993
1994 627613 return rem;
1995 }
1996
1997 66276 static int abs_remainder_ts_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1998 {
1999 66276 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2000 66276 const int c_rice_param = rsh->sh_ts_residual_coding_rice_idx_minus1 + 1;
2001 66276 const int rem = abs_decode(lc, c_rice_param);
2002
2003 66276 return rem;
2004 }
2005
2006 11398489 static int coeff_sign_flag_decode(VVCLocalContext *lc)
2007 {
2008 11398489 return get_cabac_bypass(&lc->ep->cc);
2009 }
2010
2011 //9.3.4.2.10 Derivation process of ctxInc for the syntax element coeff_sign_flag for transform skip mode
2012 328255 static int coeff_sign_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
2013 {
2014 328255 const TransformBlock *tb = rc->tb;
2015 328255 const int w = tb->tb_width;
2016 328255 const int *level = rc->coeff_sign_level + yc * w + xc;
2017
2/2
✓ Branch 0 taken 288584 times.
✓ Branch 1 taken 39671 times.
328255 const int left_sign = xc ? level[-1] : 0;
2018
2/2
✓ Branch 0 taken 291401 times.
✓ Branch 1 taken 36854 times.
328255 const int above_sign = yc ? level[-w] : 0;
2019 328255 const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx];
2020 int inc;
2021
2022
2/2
✓ Branch 0 taken 123186 times.
✓ Branch 1 taken 205069 times.
328255 if (left_sign == -above_sign)
2023
2/2
✓ Branch 0 taken 4480 times.
✓ Branch 1 taken 118706 times.
123186 inc = bdpcm_flag ? 3 : 0;
2024
4/4
✓ Branch 0 taken 123816 times.
✓ Branch 1 taken 81253 times.
✓ Branch 2 taken 79487 times.
✓ Branch 3 taken 44329 times.
205069 else if (left_sign >= 0 && above_sign >= 0)
2025
2/2
✓ Branch 0 taken 1350 times.
✓ Branch 1 taken 78137 times.
79487 inc = bdpcm_flag ? 4 : 1;
2026 else
2027
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 122954 times.
125582 inc = bdpcm_flag ? 5 : 2;
2028 328255 return GET_CABAC(COEFF_SIGN_FLAG + inc);
2029 }
2030
2031 328255 static int abs_level_gt1_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
2032 {
2033 328255 const TransformBlock *tb = rc->tb;
2034 328255 const int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc;
2035 int inc;
2036
2037
2/2
✓ Branch 0 taken 8458 times.
✓ Branch 1 taken 319797 times.
328255 if (cu->bdpcm_flag[tb->c_idx]) {
2038 8458 inc = 67;
2039 } else {
2040
2/2
✓ Branch 0 taken 281135 times.
✓ Branch 1 taken 38662 times.
319797 const int l = xc > 0 ? sig_coeff_flag[-1] : 0;
2041
2/2
✓ Branch 0 taken 284076 times.
✓ Branch 1 taken 35721 times.
319797 const int a = yc > 0 ? sig_coeff_flag[-tb->tb_width] : 0;
2042 319797 inc = 64 + a + l;
2043 }
2044 328255 return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
2045 }
2046
2047 241777 static int abs_level_gtx_flag_ts_decode(VVCLocalContext *lc, const int j)
2048 {
2049 241777 const int inc = 67 + j;
2050 241777 return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
2051 }
2052
2053 static const uint8_t qstate_translate_table[][2] = {
2054 { 0, 2 }, { 2, 0 }, { 1, 3 }, { 3, 1 }
2055 };
2056
2057 364139 static int dec_abs_level_decode(VVCLocalContext *lc, const ResidualCoding *rc,
2058 const int xc, const int yc, int *abs_level)
2059 {
2060 364139 const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc, 0);
2061 364139 const int dec_abs_level = abs_decode(lc, c_rice_param);
2062
2/2
✓ Branch 0 taken 219221 times.
✓ Branch 1 taken 144918 times.
364139 const int zero_pos = (rc->qstate < 2 ? 1 : 2) << c_rice_param;
2063
2064 364139 *abs_level = 0;
2065
2/2
✓ Branch 0 taken 331245 times.
✓ Branch 1 taken 32894 times.
364139 if (dec_abs_level != zero_pos) {
2066 331245 *abs_level = dec_abs_level;
2067
2/2
✓ Branch 0 taken 198043 times.
✓ Branch 1 taken 133202 times.
331245 if (dec_abs_level < zero_pos)
2068 198043 *abs_level += 1;
2069 }
2070 364139 return dec_abs_level;
2071 }
2072
2073 991752 static void ep_update_hist(EntryPoint *ep, ResidualCoding *rc,
2074 const int remainder, const int addin)
2075 {
2076 991752 int *stat = ep->stat_coeff + rc->tb->c_idx;
2077
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 991752 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
991752 if (rc->update_hist && remainder > 0) {
2078 *stat = (*stat + av_log2(remainder) + addin) >> 1;
2079 rc->update_hist = 0;
2080 }
2081 991752 }
2082
2083 1004918 static void init_residual_coding(const VVCLocalContext *lc, ResidualCoding *rc,
2084 const int log2_zo_tb_width, const int log2_zo_tb_height,
2085 TransformBlock *tb)
2086 {
2087 1004918 const VVCSPS *sps = lc->fc->ps.sps;
2088
2/2
✓ Branch 0 taken 102252 times.
✓ Branch 1 taken 902666 times.
1004918 int log2_sb_w = (FFMIN(log2_zo_tb_width, log2_zo_tb_height ) < 2 ? 1 : 2 );
2089 1004918 int log2_sb_h = log2_sb_w;
2090
2091
2/2
✓ Branch 0 taken 995892 times.
✓ Branch 1 taken 9026 times.
1004918 if ( log2_zo_tb_width + log2_zo_tb_height > 3 ) {
2092
2/2
✓ Branch 0 taken 21163 times.
✓ Branch 1 taken 974729 times.
995892 if ( log2_zo_tb_width < 2 ) {
2093 21163 log2_sb_w = log2_zo_tb_width;
2094 21163 log2_sb_h = 4 - log2_sb_w;
2095
2/2
✓ Branch 0 taken 72063 times.
✓ Branch 1 taken 902666 times.
974729 } else if ( log2_zo_tb_height < 2 ) {
2096 72063 log2_sb_h = log2_zo_tb_height;
2097 72063 log2_sb_w = 4 - log2_sb_h;
2098 }
2099 }
2100 1004918 rc->log2_sb_w = log2_sb_w;
2101 1004918 rc->log2_sb_h = log2_sb_h;
2102 1004918 rc->num_sb_coeff = 1 << (log2_sb_w + log2_sb_h);
2103 1004918 rc->last_sub_block = ( 1 << ( log2_zo_tb_width + log2_zo_tb_height - (log2_sb_w + log2_sb_h))) - 1;
2104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1004918 times.
1004918 rc->hist_value = sps->r->sps_persistent_rice_adaptation_enabled_flag ? (1 << lc->ep->stat_coeff[tb->c_idx]) : 0;
2105 1004918 rc->update_hist = sps->r->sps_persistent_rice_adaptation_enabled_flag ? 1 : 0;
2106 1004918 rc->rem_bins_pass1 = (( 1 << ( log2_zo_tb_width + log2_zo_tb_height)) * 7 ) >> 2;
2107
2108
2109 1004918 rc->sb_scan_x_off = ff_vvc_diag_scan_x[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h];
2110 1004918 rc->sb_scan_y_off = ff_vvc_diag_scan_y[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h];
2111
2112 1004918 rc->scan_x_off = ff_vvc_diag_scan_x[log2_sb_w][log2_sb_h];
2113 1004918 rc->scan_y_off = ff_vvc_diag_scan_y[log2_sb_w][log2_sb_h];
2114
2115 1004918 rc->infer_sb_cbf = 1;
2116
2117 1004918 rc->width_in_sbs = (1 << (log2_zo_tb_width - log2_sb_w));
2118 1004918 rc->height_in_sbs = (1 << (log2_zo_tb_height - log2_sb_h));
2119 1004918 rc->nb_sbs = rc->width_in_sbs * rc->height_in_sbs;
2120
2121 1004918 rc->last_scan_pos = rc->num_sb_coeff;
2122 1004918 rc->qstate = 0;
2123
2124 1004918 rc->tb = tb;
2125 1004918 }
2126
2127 229466 static int residual_ts_coding_subblock(VVCLocalContext *lc, ResidualCoding* rc, const int i)
2128 {
2129 229466 const CodingUnit *cu = lc->cu;
2130 229466 TransformBlock *tb = rc->tb;
2131 229466 const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx];
2132 229466 const int xs = rc->sb_scan_x_off[i];
2133 229466 const int ys = rc->sb_scan_y_off[i];
2134 229466 uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
2135 229466 int infer_sb_sig_coeff_flag = 1;
2136 229466 int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -1, n;
2137 int abs_level_gtx_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];
2138 int abs_level_pass2[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; ///< AbsLevelPass2
2139
2140
4/4
✓ Branch 0 taken 47521 times.
✓ Branch 1 taken 181945 times.
✓ Branch 2 taken 26836 times.
✓ Branch 3 taken 20685 times.
229466 if (i != rc->last_sub_block || !rc->infer_sb_cbf)
2141 208781 *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
2142 else
2143 20685 *sb_coded_flag = 1;
2144
4/4
✓ Branch 0 taken 89095 times.
✓ Branch 1 taken 140371 times.
✓ Branch 2 taken 56347 times.
✓ Branch 3 taken 32748 times.
229466 if (*sb_coded_flag && i < rc->last_sub_block)
2145 56347 rc->infer_sb_cbf = 0;
2146
2147 //first scan pass
2148
4/4
✓ Branch 0 taken 3642921 times.
✓ Branch 1 taken 223935 times.
✓ Branch 2 taken 3637390 times.
✓ Branch 3 taken 5531 times.
3866856 for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
2149 3637390 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2150 3637390 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2151 3637390 const int off = yc * tb->tb_width + xc;
2152 3637390 int *sig_coeff_flag = rc->sig_coeff_flag + off;
2153 3637390 int *abs_level_pass1 = rc->abs_level_pass1 + off;
2154 3637390 int *coeff_sign_level = rc->coeff_sign_level + off;
2155 3637390 int par_level_flag = 0;
2156
2157 3637390 abs_level_gtx_flag[n] = 0;
2158 3637390 last_scan_pos_pass1 = n;
2159
6/6
✓ Branch 0 taken 1397918 times.
✓ Branch 1 taken 2239472 times.
✓ Branch 2 taken 83959 times.
✓ Branch 3 taken 1313959 times.
✓ Branch 4 taken 79022 times.
✓ Branch 5 taken 4937 times.
3637390 if (*sb_coded_flag && (n != rc->num_sb_coeff - 1 || !infer_sb_sig_coeff_flag)) {
2160 1392981 *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
2161 1392981 rc->rem_bins_pass1--;
2162
2/2
✓ Branch 0 taken 323318 times.
✓ Branch 1 taken 1069663 times.
1392981 if (*sig_coeff_flag)
2163 323318 infer_sb_sig_coeff_flag = 0;
2164 } else {
2165
5/6
✓ Branch 0 taken 144913 times.
✓ Branch 1 taken 2099496 times.
✓ Branch 2 taken 144913 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4937 times.
✓ Branch 5 taken 139976 times.
2244409 *sig_coeff_flag = (n == rc->num_sb_coeff - 1) && infer_sb_sig_coeff_flag && *sb_coded_flag;
2166 }
2167 3637390 *coeff_sign_level = 0;
2168
2/2
✓ Branch 0 taken 328255 times.
✓ Branch 1 taken 3309135 times.
3637390 if (*sig_coeff_flag) {
2169 328255 *coeff_sign_level = 1 - 2 * coeff_sign_flag_ts_decode(lc, cu, rc, xc, yc);
2170 328255 abs_level_gtx_flag[n] = abs_level_gt1_flag_ts_decode(lc, cu, rc, xc, yc);
2171 328255 rc->rem_bins_pass1 -= 2;
2172
2/2
✓ Branch 0 taken 141904 times.
✓ Branch 1 taken 186351 times.
328255 if (abs_level_gtx_flag[n]) {
2173 141904 par_level_flag = par_level_flag_ts_decode(lc);
2174 141904 rc->rem_bins_pass1--;
2175 }
2176 }
2177 3637390 *abs_level_pass1 = *sig_coeff_flag + par_level_flag + abs_level_gtx_flag[n];
2178 }
2179
2180 //greater than x scan pass
2181
4/4
✓ Branch 0 taken 3558357 times.
✓ Branch 1 taken 220942 times.
✓ Branch 2 taken 3549833 times.
✓ Branch 3 taken 8524 times.
3779299 for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
2182 3549833 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2183 3549833 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2184 3549833 const int off = yc * tb->tb_width + xc;
2185
2186 3549833 abs_level_pass2[n] = rc->abs_level_pass1[off];
2187
4/4
✓ Branch 0 taken 3766857 times.
✓ Branch 1 taken 24753 times.
✓ Branch 2 taken 241777 times.
✓ Branch 3 taken 3525080 times.
3791610 for (int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) {
2188 241777 abs_level_gtx_flag[n] = abs_level_gtx_flag_ts_decode(lc, j);
2189 241777 abs_level_pass2[n] += abs_level_gtx_flag[n] << 1;
2190 241777 rc->rem_bins_pass1--;
2191 }
2192 3549833 last_scan_pos_pass2 = n;
2193 }
2194
2195 /* remainder scan pass */
2196
2/2
✓ Branch 0 taken 3671168 times.
✓ Branch 1 taken 229466 times.
3900634 for (n = 0; n < rc->num_sb_coeff; n++) {
2197 3671168 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2198 3671168 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2199 3671168 const int off = yc * tb->tb_width + xc;
2200 3671168 const int *abs_level_pass1 = rc->abs_level_pass1 + off;
2201 3671168 int *abs_level = rc->abs_level + off;
2202 3671168 int *coeff_sign_level = rc->coeff_sign_level + off;
2203 3671168 int abs_remainder = 0;
2204
2205
6/6
✓ Branch 0 taken 3549833 times.
✓ Branch 1 taken 121335 times.
✓ Branch 2 taken 3529423 times.
✓ Branch 3 taken 20410 times.
✓ Branch 4 taken 121335 times.
✓ Branch 5 taken 3529423 times.
3671168 if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) ||
2206
2/2
✓ Branch 0 taken 87557 times.
✓ Branch 1 taken 33778 times.
121335 (n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 &&
2207
4/4
✓ Branch 0 taken 69149 times.
✓ Branch 1 taken 18408 times.
✓ Branch 2 taken 33778 times.
✓ Branch 3 taken 3598572 times.
3650758 *abs_level_pass1 >= 2) ||
2208
2/2
✓ Branch 0 taken 27458 times.
✓ Branch 1 taken 6320 times.
33778 (n > last_scan_pos_pass1 && *sb_coded_flag))
2209 66276 abs_remainder = abs_remainder_ts_decode(lc, rc, xc, yc);
2210
2/2
✓ Branch 0 taken 3549833 times.
✓ Branch 1 taken 121335 times.
3671168 if (n <= last_scan_pos_pass2) {
2211 3549833 *abs_level = abs_level_pass2[n] + 2 * abs_remainder;
2212
2/2
✓ Branch 0 taken 87557 times.
✓ Branch 1 taken 33778 times.
121335 } else if (n <= last_scan_pos_pass1) {
2213 87557 *abs_level = *abs_level_pass1 + 2 * abs_remainder;
2214 } else {
2215 33778 *abs_level = abs_remainder;
2216
2/2
✓ Branch 0 taken 15053 times.
✓ Branch 1 taken 18725 times.
33778 if (abs_remainder) {
2217 //n > lastScanPosPass1
2218 15053 *coeff_sign_level = 1 - 2 * coeff_sign_flag_decode(lc);
2219 }
2220 }
2221
4/4
✓ Branch 0 taken 3482672 times.
✓ Branch 1 taken 188496 times.
✓ Branch 2 taken 3450269 times.
✓ Branch 3 taken 32403 times.
3671168 if (!bdpcm_flag && n <= last_scan_pos_pass1) {
2222
2/2
✓ Branch 0 taken 3067318 times.
✓ Branch 1 taken 382951 times.
3450269 const int left = xc > 0 ? abs_level[-1] : 0;
2223
2/2
✓ Branch 0 taken 3075238 times.
✓ Branch 1 taken 375031 times.
3450269 const int above = yc > 0 ? abs_level[-tb->tb_width] : 0;
2224 3450269 const int pred = FFMAX(left, above);
2225
2226
4/4
✓ Branch 0 taken 183615 times.
✓ Branch 1 taken 3266654 times.
✓ Branch 2 taken 112356 times.
✓ Branch 3 taken 71259 times.
3450269 if (*abs_level == 1 && pred > 0)
2227 112356 *abs_level = pred;
2228
4/4
✓ Branch 0 taken 207441 times.
✓ Branch 1 taken 3130472 times.
✓ Branch 2 taken 52925 times.
✓ Branch 3 taken 154516 times.
3337913 else if (*abs_level > 0 && *abs_level <= pred)
2229 52925 (*abs_level)--;
2230 }
2231
2/2
✓ Branch 0 taken 343308 times.
✓ Branch 1 taken 3327860 times.
3671168 if (*abs_level) {
2232 343308 tb->coeffs[off] = *coeff_sign_level * *abs_level;
2233 343308 tb->max_scan_x = FFMAX(xc, tb->max_scan_x);
2234 343308 tb->max_scan_y = FFMAX(yc, tb->max_scan_y);
2235 343308 tb->min_scan_x = FFMIN(xc, tb->min_scan_x);
2236 343308 tb->min_scan_y = FFMIN(yc, tb->min_scan_y);
2237 } else {
2238 3327860 tb->coeffs[off] = 0;
2239 }
2240 }
2241
2242 229466 return 0;
2243 }
2244
2245 47521 static int hls_residual_ts_coding(VVCLocalContext *lc, TransformBlock *tb)
2246 {
2247 ResidualCoding rc;
2248 47521 tb->min_scan_x = tb->min_scan_y = INT_MAX;
2249 47521 init_residual_coding(lc, &rc, tb->log2_tb_width, tb->log2_tb_height, tb);
2250
2/2
✓ Branch 0 taken 229466 times.
✓ Branch 1 taken 47521 times.
276987 for (int i = 0; i <= rc.last_sub_block; i++) {
2251 229466 int ret = residual_ts_coding_subblock(lc, &rc, i);
2252
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 229466 times.
229466 if (ret < 0)
2253 return ret;
2254 }
2255
2256 47521 return 0;
2257 }
2258
2259 2160246 static inline int residual_coding_subblock(VVCLocalContext *lc, ResidualCoding *rc, const int i)
2260 {
2261 2160246 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2262 2160246 TransformBlock *tb = rc->tb;
2263 int first_sig_scan_pos_sb, last_sig_scan_pos_sb;
2264 int first_pos_mode0, first_pos_mode1;
2265 2160246 int infer_sb_dc_sig_coeff_flag = 0;
2266 2160246 int n, sig_hidden_flag, sum = 0;
2267 int abs_level_gt2_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];
2268 2160246 const int start_qstate_sb = rc->qstate;
2269 2160246 const int xs = rc->sb_scan_x_off[i];
2270 2160246 const int ys = rc->sb_scan_y_off[i];
2271 2160246 uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
2272
2273
2274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2160246 times.
2160246 av_assert0(rc->num_sb_coeff <= MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE);
2275
4/4
✓ Branch 0 taken 1202849 times.
✓ Branch 1 taken 957397 times.
✓ Branch 2 taken 926830 times.
✓ Branch 3 taken 276019 times.
2160246 if (i < rc->last_sub_block && i > 0) {
2276 926830 *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
2277 926830 infer_sb_dc_sig_coeff_flag = 1;
2278 } else {
2279 1233416 *sb_coded_flag = 1;
2280 }
2281
8/8
✓ Branch 0 taken 1821092 times.
✓ Branch 1 taken 339154 times.
✓ Branch 2 taken 1750714 times.
✓ Branch 3 taken 70378 times.
✓ Branch 4 taken 53218 times.
✓ Branch 5 taken 1697496 times.
✓ Branch 6 taken 70807 times.
✓ Branch 7 taken 52789 times.
2160246 if (*sb_coded_flag && (xs > 3 || ys > 3) && !tb->c_idx)
2282 70807 lc->parse.mts_zero_out_sig_coeff_flag = 0;
2283
2284
2/2
✓ Branch 0 taken 339154 times.
✓ Branch 1 taken 1821092 times.
2160246 if (!*sb_coded_flag)
2285 339154 return 0;
2286
2287 1821092 first_sig_scan_pos_sb = rc->num_sb_coeff;
2288 1821092 last_sig_scan_pos_sb = -1;
2289
2/2
✓ Branch 0 taken 957397 times.
✓ Branch 1 taken 863695 times.
1821092 first_pos_mode0 = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1);
2290 1821092 first_pos_mode1 = first_pos_mode0;
2291
4/4
✓ Branch 0 taken 19271636 times.
✓ Branch 1 taken 1754789 times.
✓ Branch 2 taken 19205333 times.
✓ Branch 3 taken 66303 times.
21026425 for (n = first_pos_mode0; n >= 0 && rc->rem_bins_pass1 >= 4; n--) {
2292 19205333 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2293 19205333 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2294
4/4
✓ Branch 0 taken 2932445 times.
✓ Branch 1 taken 16272888 times.
✓ Branch 2 taken 957397 times.
✓ Branch 3 taken 1975048 times.
19205333 const int last = (xc == rc->last_significant_coeff_x && yc == rc->last_significant_coeff_y);
2295 19205333 int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc;
2296 19205333 int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc;
2297
2298
6/6
✓ Branch 0 taken 1754789 times.
✓ Branch 1 taken 17450544 times.
✓ Branch 2 taken 1744846 times.
✓ Branch 3 taken 9943 times.
✓ Branch 4 taken 18237993 times.
✓ Branch 5 taken 957397 times.
19205333 if ((n > 0 || !infer_sb_dc_sig_coeff_flag ) && !last) {
2299 18237993 *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
2300 18237993 rc->rem_bins_pass1--;
2301
2/2
✓ Branch 0 taken 10107298 times.
✓ Branch 1 taken 8130695 times.
18237993 if (*sig_coeff_flag)
2302 10107298 infer_sb_dc_sig_coeff_flag = 0;
2303 } else {
2304
5/8
✓ Branch 0 taken 9943 times.
✓ Branch 1 taken 957397 times.
✓ Branch 2 taken 9943 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9943 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9943 times.
✗ Branch 7 not taken.
967340 *sig_coeff_flag = last || (!rc->scan_x_off[n] && !rc ->scan_y_off[n] &&
2305 infer_sb_dc_sig_coeff_flag);
2306 }
2307 19205333 *abs_level_pass1 = 0;
2308
2/2
✓ Branch 0 taken 11074638 times.
✓ Branch 1 taken 8130695 times.
19205333 if (*sig_coeff_flag) {
2309 11074638 int abs_level_gt1_flag, par_level_flag = 0;
2310 11074638 const int inc = get_gtx_flag_inc(rc, xc, yc, last);
2311 11074638 abs_level_gt1_flag = abs_level_gtx_flag_decode(lc, inc);
2312 11074638 rc->rem_bins_pass1--;
2313
2/2
✓ Branch 0 taken 2314866 times.
✓ Branch 1 taken 8759772 times.
11074638 if (abs_level_gt1_flag) {
2314 2314866 par_level_flag = par_level_flag_decode(lc, inc);
2315 2314866 abs_level_gt2_flag[n] = abs_level_gtx_flag_decode(lc, inc + 32);
2316 2314866 rc->rem_bins_pass1 -= 2;
2317 } else {
2318 8759772 abs_level_gt2_flag[n] = 0;
2319 }
2320
2/2
✓ Branch 0 taken 1806166 times.
✓ Branch 1 taken 9268472 times.
11074638 if (last_sig_scan_pos_sb == -1)
2321 1806166 last_sig_scan_pos_sb = n;
2322 11074638 first_sig_scan_pos_sb = n;
2323
2324 11074638 *abs_level_pass1 =
2325 11074638 1 + par_level_flag + abs_level_gt1_flag + (abs_level_gt2_flag[n] << 1);
2326 } else {
2327 8130695 abs_level_gt2_flag[n] = 0;
2328 }
2329
2330
2/2
✓ Branch 0 taken 17997286 times.
✓ Branch 1 taken 1208047 times.
19205333 if (rsh->sh_dep_quant_used_flag)
2331 17997286 rc->qstate = qstate_translate_table[rc->qstate][*abs_level_pass1 & 1];
2332
2333 19205333 first_pos_mode1 = n - 1;
2334 }
2335
2/2
✓ Branch 0 taken 19205333 times.
✓ Branch 1 taken 1821092 times.
21026425 for (n = first_pos_mode0; n > first_pos_mode1; n--) {
2336 19205333 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2337 19205333 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2338 19205333 const int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc;
2339 19205333 int *abs_level = rc->abs_level + yc * tb->tb_width + xc;
2340
2341 19205333 *abs_level = *abs_level_pass1;
2342
2/2
✓ Branch 0 taken 627613 times.
✓ Branch 1 taken 18577720 times.
19205333 if (abs_level_gt2_flag[n]) {
2343 627613 const int abs_remainder = abs_remainder_decode(lc, rc, xc, yc);
2344 627613 ep_update_hist(lc->ep, rc, abs_remainder, 2);
2345 627613 *abs_level += 2 * abs_remainder;
2346 }
2347 }
2348
2/2
✓ Branch 0 taken 364139 times.
✓ Branch 1 taken 1821092 times.
2185231 for (n = first_pos_mode1; n >= 0; n--) {
2349 364139 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2350 364139 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2351 364139 int *abs_level = rc->abs_level + yc * tb->tb_width + xc;
2352
2353
1/2
✓ Branch 0 taken 364139 times.
✗ Branch 1 not taken.
364139 if (*sb_coded_flag) {
2354 364139 const int dec_abs_level = dec_abs_level_decode(lc, rc, xc, yc, abs_level);
2355 364139 ep_update_hist(lc->ep, rc, dec_abs_level, 0);
2356 }
2357
2/2
✓ Branch 0 taken 331245 times.
✓ Branch 1 taken 32894 times.
364139 if (*abs_level > 0) {
2358
2/2
✓ Branch 0 taken 7657 times.
✓ Branch 1 taken 323588 times.
331245 if (last_sig_scan_pos_sb == -1)
2359 7657 last_sig_scan_pos_sb = n;
2360 331245 first_sig_scan_pos_sb = n;
2361 }
2362
2/2
✓ Branch 0 taken 291449 times.
✓ Branch 1 taken 72690 times.
364139 if (rsh->sh_dep_quant_used_flag)
2363 291449 rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1];
2364 }
2365
2/2
✓ Branch 0 taken 34562 times.
✓ Branch 1 taken 1786530 times.
1855654 sig_hidden_flag = rsh->sh_sign_data_hiding_used_flag &&
2366
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);
2367
2368
2/2
✓ Branch 0 taken 1699846 times.
✓ Branch 1 taken 121246 times.
1821092 if (rsh->sh_dep_quant_used_flag)
2369 1699846 rc->qstate = start_qstate_sb;
2370
2/2
✓ Branch 0 taken 957397 times.
✓ Branch 1 taken 863695 times.
1821092 n = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1);
2371
2/2
✓ Branch 0 taken 19569472 times.
✓ Branch 1 taken 1821092 times.
21390564 for (/* nothing */; n >= 0; n--) {
2372 int trans_coeff_level;
2373 19569472 const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2374 19569472 const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2375 19569472 const int off = yc * tb->tb_width + xc;
2376 19569472 const int *abs_level = rc->abs_level + off;
2377
2378
2/2
✓ Branch 0 taken 11405883 times.
✓ Branch 1 taken 8163589 times.
19569472 if (*abs_level > 0) {
2379 11405883 int sign = 1;
2380
4/4
✓ Branch 0 taken 176798 times.
✓ Branch 1 taken 11229085 times.
✓ Branch 2 taken 154351 times.
✓ Branch 3 taken 22447 times.
11405883 if (!sig_hidden_flag || (n != first_sig_scan_pos_sb))
2381 11383436 sign = 1 - 2 * coeff_sign_flag_decode(lc);
2382
2/2
✓ Branch 0 taken 10718818 times.
✓ Branch 1 taken 687065 times.
11405883 if (rsh->sh_dep_quant_used_flag) {
2383 10718818 trans_coeff_level = (2 * *abs_level - (rc->qstate > 1)) * sign;
2384 } else {
2385 687065 trans_coeff_level = *abs_level * sign;
2386
2/2
✓ Branch 0 taken 176798 times.
✓ Branch 1 taken 510267 times.
687065 if (sig_hidden_flag) {
2387 176798 sum += *abs_level;
2388
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))
2389 11754 trans_coeff_level = -trans_coeff_level;
2390 }
2391 }
2392 11405883 tb->coeffs[off] = trans_coeff_level;
2393 11405883 tb->max_scan_x = FFMAX(xc, tb->max_scan_x);
2394 11405883 tb->max_scan_y = FFMAX(yc, tb->max_scan_y);
2395 }
2396
2/2
✓ Branch 0 taken 18288735 times.
✓ Branch 1 taken 1280737 times.
19569472 if (rsh->sh_dep_quant_used_flag)
2397 18288735 rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1];
2398 }
2399
2400 1821092 return 0;
2401 }
2402
2403 957397 static void derive_last_scan_pos(ResidualCoding *rc)
2404 {
2405 int xc, yc, xs, ys;
2406 do {
2407
2/2
✓ Branch 0 taken 6508293 times.
✓ Branch 1 taken 107967668 times.
114475961 if (!rc->last_scan_pos) {
2408 6508293 rc->last_scan_pos = rc->num_sb_coeff;
2409 6508293 rc->last_sub_block--;
2410 }
2411 114475961 rc->last_scan_pos--;
2412 114475961 xs = rc->sb_scan_x_off[rc->last_sub_block];
2413 114475961 ys = rc->sb_scan_y_off[rc->last_sub_block];
2414 114475961 xc = (xs << rc->log2_sb_w) + rc->scan_x_off[rc->last_scan_pos];
2415 114475961 yc = (ys << rc->log2_sb_h) + rc->scan_y_off[rc->last_scan_pos];
2416
4/4
✓ Branch 0 taken 107157100 times.
✓ Branch 1 taken 7318861 times.
✓ Branch 2 taken 6361464 times.
✓ Branch 3 taken 957397 times.
114475961 } while ((xc != rc->last_significant_coeff_x) || (yc != rc->last_significant_coeff_y));
2417 957397 }
2418
2419 957397 static void last_significant_coeff_x_y_decode(ResidualCoding *rc, VVCLocalContext *lc,
2420 const int log2_zo_tb_width, const int log2_zo_tb_height)
2421 {
2422 957397 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2423 957397 const TransformBlock *tb = rc->tb;
2424 int last_significant_coeff_x, last_significant_coeff_y;
2425
2426 957397 last_significant_coeff_x = last_significant_coeff_x_prefix_decode(lc,
2427 957397 tb->log2_tb_width, log2_zo_tb_width, tb->c_idx);
2428
2429 957397 last_significant_coeff_y = last_significant_coeff_y_prefix_decode(lc,
2430 957397 tb->log2_tb_height, log2_zo_tb_height, tb->c_idx);
2431
2432
2/2
✓ Branch 0 taken 205823 times.
✓ Branch 1 taken 751574 times.
957397 if (last_significant_coeff_x > 3) {
2433 205823 int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_x);
2434 205823 last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
2435 205823 (2 + (last_significant_coeff_x & 1)) + suffix;
2436 }
2437
2/2
✓ Branch 0 taken 158909 times.
✓ Branch 1 taken 798488 times.
957397 if (last_significant_coeff_y > 3) {
2438 158909 int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_y);
2439 158909 last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
2440 158909 (2 + (last_significant_coeff_y & 1)) + suffix;
2441 }
2442
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 957397 times.
957397 if (rsh->sh_reverse_last_sig_coeff_flag) {
2443 last_significant_coeff_x = (1 << log2_zo_tb_width) - 1 - last_significant_coeff_x;
2444 last_significant_coeff_y = (1 << log2_zo_tb_height) - 1 - last_significant_coeff_y;
2445 }
2446 957397 rc->last_significant_coeff_x = last_significant_coeff_x;
2447 957397 rc->last_significant_coeff_y = last_significant_coeff_y;
2448 957397 }
2449
2450 957397 static int hls_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
2451 {
2452 957397 const VVCSPS *sps = lc->fc->ps.sps;
2453 957397 const CodingUnit *cu = lc->cu;
2454 957397 const int log2_tb_width = tb->log2_tb_width;
2455 957397 const int log2_tb_height = tb->log2_tb_height;
2456 957397 const int c_idx = tb->c_idx;
2457 int log2_zo_tb_width, log2_zo_tb_height;
2458 ResidualCoding rc;
2459
2460
10/10
✓ Branch 0 taken 952684 times.
✓ Branch 1 taken 4713 times.
✓ Branch 2 taken 51959 times.
✓ Branch 3 taken 900725 times.
✓ Branch 4 taken 34954 times.
✓ Branch 5 taken 17005 times.
✓ Branch 6 taken 1720 times.
✓ Branch 7 taken 33234 times.
✓ Branch 8 taken 1617 times.
✓ Branch 9 taken 103 times.
957397 if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width == 5 && log2_tb_height < 6)
2461 1617 log2_zo_tb_width = 4;
2462 else
2463 955780 log2_zo_tb_width = FFMIN(log2_tb_width, 5 );
2464
2465
10/10
✓ Branch 0 taken 952684 times.
✓ Branch 1 taken 4713 times.
✓ Branch 2 taken 51959 times.
✓ Branch 3 taken 900725 times.
✓ Branch 4 taken 34954 times.
✓ Branch 5 taken 17005 times.
✓ Branch 6 taken 34707 times.
✓ Branch 7 taken 247 times.
✓ Branch 8 taken 2102 times.
✓ Branch 9 taken 32605 times.
957397 if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width < 6 && log2_tb_height == 5 )
2466 2102 log2_zo_tb_height = 4;
2467 else
2468 955295 log2_zo_tb_height = FFMIN(log2_tb_height, 5);
2469
2470 957397 init_residual_coding(lc, &rc, log2_zo_tb_width, log2_zo_tb_height, tb);
2471 957397 last_significant_coeff_x_y_decode(&rc, lc, log2_zo_tb_width, log2_zo_tb_height);
2472 957397 derive_last_scan_pos(&rc);
2473
2474
9/10
✓ Branch 0 taken 681378 times.
✓ Branch 1 taken 276019 times.
✓ Branch 2 taken 656136 times.
✓ Branch 3 taken 25242 times.
✓ Branch 4 taken 586049 times.
✓ Branch 5 taken 70087 times.
✓ Branch 6 taken 586049 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 445316 times.
✓ Branch 9 taken 140733 times.
957397 if (!rc.last_sub_block && log2_tb_width >= 2 && log2_tb_height >= 2 && !tb->ts && rc.last_scan_pos > 0)
2475 445316 lc->parse.lfnst_dc_only = 0;
2476
6/6
✓ Branch 0 taken 276019 times.
✓ Branch 1 taken 681378 times.
✓ Branch 2 taken 274031 times.
✓ Branch 3 taken 1988 times.
✓ Branch 4 taken 4605 times.
✓ Branch 5 taken 269426 times.
957397 if ((rc.last_sub_block > 0 && log2_tb_width >= 2 && log2_tb_height >= 2 ) ||
2477
8/8
✓ Branch 0 taken 154304 times.
✓ Branch 1 taken 533667 times.
✓ Branch 2 taken 87137 times.
✓ Branch 3 taken 67167 times.
✓ Branch 4 taken 43352 times.
✓ Branch 5 taken 43785 times.
✓ Branch 6 taken 54202 times.
✓ Branch 7 taken 56317 times.
687971 (rc.last_scan_pos > 7 && (log2_tb_width == 2 || log2_tb_width == 3 ) &&
2478 log2_tb_width == log2_tb_height))
2479 323628 lc->parse.lfnst_zero_out_sig_coeff_flag = 0;
2480
6/6
✓ Branch 0 taken 681378 times.
✓ Branch 1 taken 276019 times.
✓ Branch 2 taken 513596 times.
✓ Branch 3 taken 167782 times.
✓ Branch 4 taken 587602 times.
✓ Branch 5 taken 202013 times.
957397 if ((rc.last_sub_block > 0 || rc.last_scan_pos > 0 ) && !c_idx)
2481 587602 lc->parse.mts_dc_only = 0;
2482
2483 957397 memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs));
2484 957397 memset(rc.abs_level, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level[0]));
2485 957397 memset(rc.sb_coded_flag, 0, rc.nb_sbs);
2486 957397 memset(rc.abs_level_pass1, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level_pass1[0]));
2487 957397 memset(rc.sig_coeff_flag, 0, tb->tb_width * tb->tb_height * sizeof(rc.sig_coeff_flag[0]));
2488
2489
2/2
✓ Branch 0 taken 2160246 times.
✓ Branch 1 taken 957397 times.
3117643 for (int i = rc.last_sub_block; i >= 0; i--) {
2490 2160246 int ret = residual_coding_subblock(lc, &rc, i);
2491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2160246 times.
2160246 if (ret < 0)
2492 return ret;
2493 }
2494
2495 957397 return 0;
2496 }
2497
2498 1004918 int ff_vvc_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
2499 {
2500 1004918 const H266RawSliceHeader *rsh = lc->sc->sh.r;
2501
3/4
✓ Branch 0 taken 1004918 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47521 times.
✓ Branch 3 taken 957397 times.
1004918 const int ts = !rsh->sh_ts_residual_coding_disabled_flag && tb->ts;
2502
2503
2/2
✓ Branch 0 taken 47521 times.
✓ Branch 1 taken 957397 times.
1004918 return ts ? hls_residual_ts_coding(lc, tb) : hls_residual_coding(lc, tb);
2504 }
2505
2506 119648 int ff_vvc_cu_coded_flag(VVCLocalContext *lc)
2507 {
2508 119648 return GET_CABAC(CU_CODED_FLAG);
2509 }
2510
2511 135696 int ff_vvc_sbt_flag(VVCLocalContext *lc)
2512 {
2513 135696 const int w = lc->cu->cb_width;
2514 135696 const int h = lc->cu->cb_height;
2515 135696 const int inc = w * h <= 256;
2516 135696 return GET_CABAC(CU_SBT_FLAG + inc);
2517 }
2518
2519 32383 int ff_vvc_sbt_quad_flag(VVCLocalContext *lc)
2520 {
2521 32383 return GET_CABAC(CU_SBT_QUAD_FLAG);
2522 }
2523
2524 25535 int ff_vvc_sbt_horizontal_flag(VVCLocalContext *lc)
2525 {
2526 25535 const int w = lc->cu->cb_width;
2527 25535 const int h = lc->cu->cb_height;
2528
4/4
✓ Branch 0 taken 13683 times.
✓ Branch 1 taken 11852 times.
✓ Branch 2 taken 7401 times.
✓ Branch 3 taken 6282 times.
25535 const int inc = (w == h) ? 0 : ((w < h) ? 1 : 2);
2529 25535 return GET_CABAC(CU_SBT_HORIZONTAL_FLAG + inc);
2530 }
2531
2532 45451 int ff_vvc_sbt_pos_flag(VVCLocalContext *lc)
2533 {
2534 45451 return GET_CABAC(CU_SBT_POS_FLAG);
2535 }
2536
2537 189014 int ff_vvc_lfnst_idx(VVCLocalContext *lc, const int inc)
2538 {
2539
2/2
✓ Branch 1 taken 47686 times.
✓ Branch 2 taken 141328 times.
189014 if (!GET_CABAC(LFNST_IDX + inc))
2540 47686 return 0;
2541
2/2
✓ Branch 1 taken 86567 times.
✓ Branch 2 taken 54761 times.
141328 if (!GET_CABAC(LFNST_IDX + 2))
2542 86567 return 1;
2543 54761 return 2;
2544 }
2545
2546 252674 int ff_vvc_mts_idx(VVCLocalContext *lc)
2547 {
2548 int i;
2549
2/2
✓ Branch 0 taken 460640 times.
✓ Branch 1 taken 910 times.
461550 for (i = 0; i < 4; i++) {
2550
2/2
✓ Branch 1 taken 251764 times.
✓ Branch 2 taken 208876 times.
460640 if (!GET_CABAC(MTS_IDX + i))
2551 251764 return i;
2552 }
2553 910 return i;
2554 }
2555
2556 1816 int ff_vvc_end_of_slice_flag_decode(VVCLocalContext *lc)
2557 {
2558 1816 return get_cabac_terminate(&lc->ep->cc);
2559 }
2560
2561 493 int ff_vvc_end_of_tile_one_bit(VVCLocalContext *lc)
2562 {
2563 493 return get_cabac_terminate(&lc->ep->cc);
2564 }
2565
2566 153 int ff_vvc_end_of_subset_one_bit(VVCLocalContext *lc)
2567 {
2568 153 return get_cabac_terminate(&lc->ep->cc);
2569 }
2570