FFmpeg
cabac.c
Go to the documentation of this file.
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  */
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 
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
774 
782 
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 
794  int abs_level_pass1[MAX_TB_SIZE * MAX_TB_SIZE]; ///< AbsLevelPass1[][]
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;
807 
809 {
810  return skip_bytes(&lc->ep->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
811 }
812 
814 {
815  const VVCSPS *sps = lc->fc->ps.sps;
816  const H266RawSliceHeader *rsh = lc->sc->sh.r;
817  const int qp = av_clip_uintp2(lc->sc->sh.slice_qp_y, 6);
818  int init_type = 2 - rsh->sh_slice_type;
819 
821 
822  ff_vvc_ep_init_stat_coeff(lc->ep, sps->bit_depth, sps->r->sps_persistent_rice_adaptation_enabled_flag);
823 
824  if (rsh->sh_cabac_init_flag && !IS_I(rsh))
825  init_type ^= 3;
826 
827  for (int i = 0; i < VVC_CONTEXTS; i++) {
828  VVCCabacState *state = &lc->ep->cabac_state[i];
829  const int init_value = init_values[init_type][i];
830  const int shift_idx = init_values[3][i];
831  const int m = (init_value >> 3) - 4;
832  const int n = ((init_value & 7) * 18) + 1;
833  const int pre = av_clip(((m * (qp - 16)) >> 1) + n, 1, 127);
834 
835  state->state[0] = pre << 3;
836  state->state[1] = pre << 7;
837  state->shift[0] = (shift_idx >> 2 ) + 2;
838  state->shift[1] = (shift_idx & 3 ) + 3 + state->shift[0];
839  }
840 }
841 
843  const int ctu_idx, const int rx, const int ry)
844 {
845  int ret = 0;
846  const VVCPPS *pps = lc->fc->ps.pps;
847  const int first_ctb_in_slice = !ctu_idx;
848  const int first_ctb_in_tile = rx == pps->ctb_to_col_bd[rx] && ry == pps->ctb_to_row_bd[ry];
849 
850  if (first_ctb_in_slice|| first_ctb_in_tile) {
851  if (lc->sc->nb_eps == 1 && !first_ctb_in_slice)
852  ret = cabac_reinit(lc);
853  if (!ret)
854  cabac_init_state(lc);
855  }
856  return ret;
857 }
858 
859 //fixme
860 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  i = ff_ctz(c->low) - CABAC_BITS;
868 #endif
869 
870  x = -CABAC_MASK;
871 
872 #if CABAC_BITS == 16
873  x += (c->bytestream[0] << 9) + (c->bytestream[1] << 1);
874 #else
875  x += c->bytestream[0] << 1;
876 #endif
877 
878  c->low += x << i;
879 #if !UNCHECKED_BITSTREAM_READER
880  if (c->bytestream < c->bytestream_end)
881 #endif
882  c->bytestream += CABAC_BITS / 8;
883 }
884 
885 static int inline vvc_get_cabac(CABACContext *c, VVCCabacState* base, const int ctx)
886 {
887  VVCCabacState *s = base + ctx;
888  const int qRangeIdx = c->range >> 5;
889  const int pState = s->state[1] + (s->state[0] << 4);
890  const int valMps = pState >> 14;
891  const int RangeLPS = (qRangeIdx * ((valMps ? 32767 - pState : pState) >> 9 ) >> 1) + 4;
892  int bit, lps_mask;
893 
894  c->range -= RangeLPS;
895  lps_mask = ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
896 
897  c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
898  c->range += (RangeLPS - c->range) & lps_mask;
899 
900  bit = valMps ^ (lps_mask & 1);
901 
902  lps_mask = ff_h264_norm_shift[c->range];
903  c->range <<= lps_mask;
904  c->low <<= lps_mask;
905 
906  if (!(c->low & CABAC_MASK))
907  vvc_refill2(c);
908  s->state[0] = s->state[0] - (s->state[0] >> s->shift[0]) + (1023 * bit >> s->shift[0]);
909  s->state[1] = s->state[1] - (s->state[1] >> s->shift[1]) + (16383 * bit >> s->shift[1]);
910  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 static int truncated_binary_decode(VVCLocalContext *lc, const int c_max)
917 {
918  const int n = c_max + 1;
919  const int k = av_log2(n);
920  const int u = (1 << (k+1)) - n;
921  int v = 0;
922  for (int i = 0; i < k; i++)
923  v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
924  if (v >= u) {
925  v = (v << 1) | get_cabac_bypass(&lc->ep->cc);
926  v -= u;
927  }
928  return v;
929 }
930 
931 // 9.3.3.5 k-th order Exp - Golomb binarization process
933 {
934  int bit = 1;
935  int value = 0;
936  int symbol = 0;
937 
938  while (bit) {
940  value += bit << k++;
941  }
942 
943  if (--k) {
944  for (int i = 0; i < k; i++)
945  symbol = (symbol << 1) | get_cabac_bypass(c);
946  value += symbol;
947  }
948 
949  return value;
950 }
951 
952 // 9.3.3.6 Limited k-th order Exp-Golomb binarization process
953 static int limited_kth_order_egk_decode(CABACContext *c, const int k, const int max_pre_ext_len, const int trunc_suffix_len)
954 {
955  int pre_ext_len = 0;
956  int escape_length;
957  int val = 0;
958  while ((pre_ext_len < max_pre_ext_len) && get_cabac_bypass(c))
959  pre_ext_len++;
960  if (pre_ext_len == max_pre_ext_len)
961  escape_length = trunc_suffix_len;
962  else
963  escape_length = pre_ext_len + k;
964  while (escape_length-- > 0) {
965  val = (val << 1) + get_cabac_bypass(c);
966  }
967  val += ((1 << pre_ext_len) - 1) << k;
968  return val;
969 }
970 
971 // 9.3.3.7 Fixed-length binarization process
972 static int fixed_length_decode(CABACContext* c, const int len)
973 {
974  int value = 0;
975 
976  for (int i = 0; i < len; i++)
977  value = (value << 1) | get_cabac_bypass(c);
978 
979  return value;
980 }
981 
982 static av_always_inline
983 void get_left_top(const VVCLocalContext *lc, uint8_t *left, uint8_t *top,
984  const int x0, const int y0, const uint8_t *left_ctx, const uint8_t *top_ctx)
985 {
986  const VVCFrameContext *fc = lc->fc;
987  const VVCSPS *sps = fc->ps.sps;
988  const int min_cb_width = fc->ps.pps->min_cb_width;
989  const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
990  const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
991  const int x_cb = x0 >> sps->min_cb_log2_size_y;
992  const int y_cb = y0 >> sps->min_cb_log2_size_y;
993 
994  if (lc->ctb_left_flag || x0b)
995  *left = SAMPLE_CTB(left_ctx, x_cb - 1, y_cb);
996  if (lc->ctb_up_flag || y0b)
997  *top = SAMPLE_CTB(top_ctx, x_cb, y_cb - 1);
998 }
999 
1000 static av_always_inline
1001 uint8_t get_inc(VVCLocalContext *lc, const uint8_t *ctx)
1002 {
1003  uint8_t left = 0, top = 0;
1004  get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx);
1005  return left + top;
1006 }
1007 
1009 {
1010  return GET_CABAC(SAO_MERGE_FLAG);
1011 }
1012 
1014 {
1015  if (!GET_CABAC(SAO_TYPE_IDX))
1016  return SAO_NOT_APPLIED;
1017 
1018  if (!get_cabac_bypass(&lc->ep->cc))
1019  return SAO_BAND;
1020  return SAO_EDGE;
1021 }
1022 
1024 {
1025  return fixed_length_decode(&lc->ep->cc, 5);
1026 }
1027 
1029 {
1030  int i = 0;
1031  const int length = (1 << (FFMIN(lc->fc->ps.sps->bit_depth, 10) - 5)) - 1;
1032 
1033  while (i < length && get_cabac_bypass(&lc->ep->cc))
1034  i++;
1035  return i;
1036 }
1037 
1039 {
1040  return get_cabac_bypass(&lc->ep->cc);
1041 }
1042 
1044 {
1045  return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1046 }
1047 
1048 int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx)
1049 {
1050  int inc = c_idx * 3;
1051  const VVCFrameContext *fc = lc->fc;
1052  if (lc->ctb_left_flag) {
1053  const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry);
1054  inc += left->ctb_flag[c_idx];
1055  }
1056  if (lc->ctb_up_flag) {
1057  const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1);
1058  inc += above->ctb_flag[c_idx];
1059  }
1060  return GET_CABAC(ALF_CTB_FLAG + inc);
1061 }
1062 
1064 {
1065  return GET_CABAC(ALF_USE_APS_FLAG);
1066 }
1067 
1069 {
1070  return truncated_binary_decode(lc, lc->sc->sh.r->sh_num_alf_aps_ids_luma - 1);
1071 }
1072 
1074 {
1075  return truncated_binary_decode(lc, 15);
1076 }
1077 
1078 int ff_vvc_alf_ctb_filter_alt_idx(VVCLocalContext *lc, const int c_idx, const int num_chroma_filters)
1079 {
1080  int i = 0;
1081  const int length = num_chroma_filters - 1;
1082 
1083  while (i < length && GET_CABAC(ALF_CTB_FILTER_ALT_IDX + c_idx - 1))
1084  i++;
1085  return i;
1086 }
1087 
1088 int ff_vvc_alf_ctb_cc_idc(VVCLocalContext *lc, const int rx, const int ry, const int idx, const int cc_filters_signalled)
1089 {
1090  int inc = !idx ? ALF_CTB_CC_CB_IDC : ALF_CTB_CC_CR_IDC;
1091  int i = 0;
1092  const VVCFrameContext *fc = lc->fc;
1093  if (lc->ctb_left_flag) {
1094  const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry);
1095  inc += left->ctb_cc_idc[idx] != 0;
1096  }
1097  if (lc->ctb_up_flag) {
1098  const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1);
1099  inc += above->ctb_cc_idc[idx] != 0;
1100  }
1101 
1102  if (!GET_CABAC(inc))
1103  return 0;
1104  i++;
1105  while (i < cc_filters_signalled && get_cabac_bypass(&lc->ep->cc))
1106  i++;
1107  return i;
1108 }
1109 
1110 int ff_vvc_split_cu_flag(VVCLocalContext *lc, const int x0, const int y0,
1111  const int cb_width, const int cb_height, const int is_chroma, const VVCAllowedSplit *a)
1112 {
1113  const VVCFrameContext *fc = lc->fc;
1114  const VVCPPS *pps = fc->ps.pps;
1115  const int is_inside = (x0 + cb_width <= pps->width) && (y0 + cb_height <= pps->height);
1116 
1117  if ((a->btv || a->bth || a->ttv || a->tth || a->qt) && is_inside)
1118  {
1119  uint8_t inc = 0, left_height = cb_height, top_width = cb_width;
1120 
1121  get_left_top(lc, &left_height, &top_width, x0, y0, fc->tab.cb_height[is_chroma], fc->tab.cb_width[is_chroma]);
1122  inc += left_height < cb_height;
1123  inc += top_width < cb_width;
1124  inc += (a->btv + a->bth + a->ttv + a->tth + 2 * a->qt - 1) / 2 * 3;
1125 
1126  return GET_CABAC(SPLIT_CU_FLAG + inc);
1127 
1128  }
1129  return !is_inside;
1130 }
1131 
1132 static int split_qt_flag_decode(VVCLocalContext *lc, const int x0, const int y0, const int ch_type, const int cqt_depth)
1133 {
1134  const VVCFrameContext *fc = lc->fc;
1135  int inc = 0;
1136  uint8_t depth_left = 0, depth_top = 0;
1137 
1138  get_left_top(lc, &depth_left, &depth_top, x0, y0, fc->tab.cqt_depth[ch_type], fc->tab.cqt_depth[ch_type]);
1139  inc += depth_left > cqt_depth;
1140  inc += depth_top > cqt_depth;
1141  inc += (cqt_depth >= 2) * 3;
1142 
1143  return GET_CABAC(SPLIT_QT_FLAG + inc);
1144 }
1145 
1146 static int mtt_split_cu_vertical_flag_decode(VVCLocalContext *lc, const int x0, const int y0,
1147  const int cb_width, const int cb_height, const int ch_type, const VVCAllowedSplit* a)
1148 {
1149  if ((a->bth || a->tth) && (a->btv || a->ttv)) {
1150  int inc;
1151  const int v = a->btv + a->ttv;
1152  const int h = a->bth + a->tth;
1153  if (v > h)
1154  inc = 4;
1155  else if (v < h)
1156  inc = 3;
1157  else {
1158  const VVCFrameContext *fc = lc->fc;
1159  const VVCSPS *sps = fc->ps.sps;
1160  const int min_cb_width = fc->ps.pps->min_cb_width;
1161  const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y);
1162  const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y);
1163  const int x_cb = x0 >> sps->min_cb_log2_size_y;
1164  const int y_cb = y0 >> sps->min_cb_log2_size_y;
1165  const int available_a = lc->ctb_up_flag || y0b;
1166  const int available_l = lc->ctb_left_flag || x0b;
1167  const int da = cb_width / (available_a ? SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cb, y_cb - 1) : 1);
1168  const int dl = cb_height / (available_l ? SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cb - 1, y_cb) : 1);
1169 
1170  if (da == dl || !available_a || !available_l)
1171  inc = 0;
1172  else if (da < dl)
1173  inc = 1;
1174  else
1175  inc = 2;
1176  }
1178  }
1179  return !(a->bth || a->tth);
1180 }
1181 
1182 static int mtt_split_cu_binary_flag_decode(VVCLocalContext *lc, const int mtt_split_cu_vertical_flag, const int mtt_depth)
1183 {
1184  const int inc = (2 * mtt_split_cu_vertical_flag) + ((mtt_depth <= 1) ? 1 : 0);
1186 }
1187 
1188 VVCSplitMode ff_vvc_split_mode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height,
1189  const int cqt_depth, const int mtt_depth, const int ch_type, const VVCAllowedSplit *a)
1190 {
1191  const int allow_no_qt = a->btv || a->bth || a->ttv || a->tth;
1192  int split_qt_flag;
1193  int mtt_split_cu_vertical_flag;
1194  int mtt_split_cu_binary_flag;
1195  const VVCSplitMode mtt_split_modes[] = {
1197  };
1198  if (allow_no_qt && a->qt) {
1199  split_qt_flag = split_qt_flag_decode(lc, x0, y0, ch_type, cqt_depth);
1200  } else {
1201  split_qt_flag = !allow_no_qt || a->qt;
1202  }
1203  if (split_qt_flag)
1204  return SPLIT_QT;
1205  mtt_split_cu_vertical_flag = mtt_split_cu_vertical_flag_decode(lc, x0, y0, cb_width, cb_height, ch_type, a);
1206  if ((a->btv && a->ttv && mtt_split_cu_vertical_flag) ||
1207  (a->bth && a->tth && !mtt_split_cu_vertical_flag)) {
1208  mtt_split_cu_binary_flag = mtt_split_cu_binary_flag_decode(lc, mtt_split_cu_vertical_flag, mtt_depth);
1209  } else {
1210  if (!a->btv && !a->bth)
1211  mtt_split_cu_binary_flag = 0;
1212  else if (!a->ttv && !a->tth)
1213  mtt_split_cu_binary_flag = 1;
1214  else if (a->bth && a->ttv)
1215  mtt_split_cu_binary_flag = 1 - mtt_split_cu_vertical_flag;
1216  else
1217  mtt_split_cu_binary_flag = mtt_split_cu_vertical_flag;
1218  }
1219  return mtt_split_modes[(mtt_split_cu_vertical_flag << 1) + mtt_split_cu_binary_flag];
1220 }
1221 
1222 int ff_vvc_non_inter_flag(VVCLocalContext *lc, const int x0, const int y0, const int ch_type)
1223 {
1224  const VVCFrameContext *fc = lc->fc;
1225  uint8_t inc, left = MODE_INTER, top = MODE_INTER;
1226 
1227  get_left_top(lc, &left, &top, x0, y0, fc->tab.cpm[ch_type], fc->tab.cpm[ch_type]);
1228  inc = left == MODE_INTRA || top == MODE_INTRA;
1229  return GET_CABAC(NON_INTER_FLAG + inc);
1230 }
1231 
1232 int ff_vvc_pred_mode_flag(VVCLocalContext *lc, const int is_chroma)
1233 {
1234  const VVCFrameContext *fc = lc->fc;
1235  const CodingUnit *cu = lc->cu;
1236  uint8_t inc, left = MODE_INTER, top = MODE_INTER;
1237 
1238  get_left_top(lc, &left, &top, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]);
1239  inc = left == MODE_INTRA || top == MODE_INTRA;
1240  return GET_CABAC(PRED_MODE_FLAG + inc);
1241 }
1242 
1244 {
1245  return GET_CABAC(PRED_MODE_PLT_FLAG);
1246 }
1247 
1249 {
1251 }
1252 
1254 {
1256 }
1257 
1259 {
1261 }
1262 
1264 {
1266 }
1267 
1268 int ff_vvc_cu_skip_flag(VVCLocalContext *lc, const uint8_t *cu_skip_flag)
1269 {
1270  const int inc = get_inc(lc, cu_skip_flag);
1271  return GET_CABAC(CU_SKIP_FLAG + inc);
1272 }
1273 
1274 int ff_vvc_pred_mode_ibc_flag(VVCLocalContext *lc, const int is_chroma)
1275 {
1276  const VVCFrameContext *fc = lc->fc;
1277  const CodingUnit *cu = lc->cu;
1278  uint8_t left_mode = MODE_INTER, top_mode = MODE_INTER;
1279  int inc;
1280 
1281  get_left_top(lc, &left_mode, &top_mode, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]);
1282  inc = (left_mode == MODE_IBC) + (top_mode == MODE_IBC);
1283  return GET_CABAC(PRED_MODE_IBC_FLAG + inc);
1284 }
1285 
1286 static av_always_inline
1287 uint8_t get_mip_inc(VVCLocalContext *lc, const uint8_t *ctx)
1288 {
1289  uint8_t left = 0, top = 0;
1290  get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx);
1291  return (left & 1) + (top & 1);
1292 }
1293 
1294 int ff_vvc_intra_mip_flag(VVCLocalContext *lc, const uint8_t *intra_mip_flag)
1295 {
1296  const int w = lc->cu->cb_width;
1297  const int h = lc->cu->cb_height;
1298  const int inc = (w > h * 2 || h > w * 2) ? 3 : get_mip_inc(lc, intra_mip_flag);
1299  return GET_CABAC(INTRA_MIP_FLAG + inc);
1300 }
1301 
1303 {
1304  return get_cabac_bypass(&lc->ep->cc);
1305 }
1306 
1308 {
1309  const int w = lc->cu->cb_width;
1310  const int h = lc->cu->cb_height;
1311  const int c_max = (w == 4 && h == 4) ? 15 :
1312  ((w == 4 || h == 4) || (w == 8 && h == 8)) ? 7: 5;
1313  return truncated_binary_decode(lc, c_max);
1314 }
1315 
1317 {
1318  int i;
1319  for (i = 0; i < 2; i++) {
1320  if (!GET_CABAC(INTRA_LUMA_REF_IDX + i))
1321  return i;
1322  }
1323  return i;
1324 }
1325 
1327 {
1329 }
1330 
1331 enum IspType ff_vvc_isp_split_type(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
1332 {
1333  if (!intra_subpartitions_mode_flag)
1334  return ISP_NO_SPLIT;
1336 }
1337 
1339 {
1341 }
1342 
1343 int ff_vvc_intra_luma_not_planar_flag(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
1344 {
1345  return GET_CABAC(INTRA_LUMA_NOT_PLANAR_FLAG + !intra_subpartitions_mode_flag);
1346 }
1347 
1349 {
1350  int i;
1351  for (i = 0; i < 4 && get_cabac_bypass(&lc->ep->cc); i++)
1352  /* nothing */;
1353  return i;
1354 }
1355 
1357 {
1358  return truncated_binary_decode(lc, 60);
1359 }
1360 
1362 {
1363  return GET_CABAC(CCLM_MODE_FLAG);
1364 }
1365 
1367 {
1368  if (!GET_CABAC(CCLM_MODE_IDX))
1369  return 0;
1370  return get_cabac_bypass(&lc->ep->cc) + 1;
1371 }
1372 
1374 {
1376  return 4;
1377  return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1378 }
1379 
1381 {
1382  return kth_order_egk_decode(&lc->ep->cc, 0);
1383 }
1384 
1386 {
1387  return kth_order_egk_decode(&lc->ep->cc, 0);
1388 }
1389 
1391 {
1392  return fixed_length_decode(&lc->ep->cc, bit_depth);
1393 }
1394 
1396 {
1397  return get_cabac_bypass(&lc->ep->cc);
1398 }
1399 
1401 {
1403 }
1404 
1405 bool ff_vvc_run_copy_flag(VVCLocalContext *lc, const int prev_run_type, const int prev_run_position, const int cur_pos)
1406 {
1407  uint8_t run_left_lut[] = { 0, 1, 2, 3, 4 };
1408  uint8_t run_top_lut[] = { 5, 6, 6, 7, 7 };
1409 
1410  int bin_dist = cur_pos - prev_run_position - 1;
1411  uint8_t *run_lut = prev_run_type == 1 ? run_top_lut : run_left_lut;
1412  uint8_t ctx_inc = bin_dist <= 4 ? run_lut[bin_dist] : run_lut[4];
1413 
1414  return GET_CABAC(RUN_COPY_FLAG + ctx_inc);
1415 }
1416 
1418 {
1420 }
1421 
1422 int ff_vvc_palette_idx_idc(VVCLocalContext *lc, const int max_palette_index, const bool adjust)
1423 {
1424  return truncated_binary_decode(lc, max_palette_index - adjust);
1425 }
1426 
1428 {
1429  return kth_order_egk_decode(&lc->ep->cc, 5);
1430 }
1431 
1433 {
1434  return GET_CABAC(GENERAL_MERGE_FLAG);
1435 }
1436 
1437 static int get_inter_flag_inc(VVCLocalContext *lc, const int x0, const int y0)
1438 {
1439  uint8_t left_merge = 0, top_merge = 0;
1440  uint8_t left_affine = 0, top_affine = 0;
1441  const VVCFrameContext *fc = lc->fc;
1442 
1443  get_left_top(lc, &left_merge, &top_merge, x0, y0, fc->tab.msf, fc->tab.msf);
1444  get_left_top(lc, &left_affine, &top_affine, x0, y0, fc->tab.iaf, fc->tab.iaf);
1445  return (left_merge || left_affine) + (top_merge + top_affine);
1446 }
1447 
1449 {
1450  const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0);
1451  return GET_CABAC(MERGE_SUBBLOCK_FLAG + inc);
1452 }
1453 
1454 int ff_vvc_merge_subblock_idx(VVCLocalContext *lc, const int max_num_subblock_merge_cand)
1455 {
1456  int i;
1458  return 0;
1459  for (i = 1; i < max_num_subblock_merge_cand - 1 && get_cabac_bypass(&lc->ep->cc); i++)
1460  /* nothing */;
1461  return i;
1462 }
1463 
1464 int ff_vvc_regular_merge_flag(VVCLocalContext *lc, const int cu_skip_flag)
1465 {
1466  int inc = !cu_skip_flag;
1467  return GET_CABAC(REGULAR_MERGE_FLAG + inc);
1468 }
1469 
1471 {
1472  return GET_CABAC(MMVD_MERGE_FLAG);
1473 }
1474 
1476 {
1477  return GET_CABAC(MMVD_CAND_FLAG);
1478 }
1479 
1481 {
1482  int i;
1484  return 0;
1485  for (i = 1; i < 7 && get_cabac_bypass(&lc->ep->cc); i++)
1486  /* nothing */;
1487  return i;
1488 }
1489 
1491 {
1492  return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc);
1493 }
1494 
1495 void ff_vvc_mmvd_offset_coding(VVCLocalContext *lc, Mv *mmvd_offset, const int ph_mmvd_fullpel_only_flag)
1496 {
1497  const int shift = ph_mmvd_fullpel_only_flag ? 4 : 2;
1498  const int mmvd_distance = 1 << (mmvd_distance_idx_decode(lc) + shift);
1499  const int mmvd_direction_idx = mmvd_direction_idx_decode(lc);
1500  const int mmvd_signs[][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
1501  mmvd_offset->x = mmvd_distance * mmvd_signs[mmvd_direction_idx][0];
1502  mmvd_offset->y = mmvd_distance * mmvd_signs[mmvd_direction_idx][1];
1503 }
1504 
1506 {
1507  const VVCFrameContext *fc = lc->fc;
1508  const CodingUnit *cu = lc->cu;
1509  PredMode pred_mode;
1510 
1511  if (cu->tree_type != DUAL_TREE_CHROMA) {
1512  pred_mode = cu->pred_mode;
1513  } else {
1514  const int x_cb = cu->x0 >> fc->ps.sps->min_cb_log2_size_y;
1515  const int y_cb = cu->y0 >> fc->ps.sps->min_cb_log2_size_y;
1516  const int min_cb_width = fc->ps.pps->min_cb_width;
1517  pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_cb, y_cb);
1518  }
1519  return pred_mode;
1520 }
1521 
1523 {
1524  const VVCSPS *sps = lc->fc->ps.sps;
1525  const int is_ibc = get_luma_pred_mode(lc) == MODE_IBC;
1526  const int c_max = (is_ibc ? sps->max_num_ibc_merge_cand : sps->max_num_merge_cand) - 1;
1527  int i;
1528 
1529  if (!GET_CABAC(MERGE_IDX))
1530  return 0;
1531 
1532  for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++)
1533  /* nothing */;
1534  return i;
1535 }
1536 
1538 {
1539  return fixed_length_decode(&lc->ep->cc, 6);
1540 }
1541 
1542 int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx)
1543 {
1544  const int c_max = lc->fc->ps.sps->max_num_gpm_merge_cand - idx - 1;
1545  int i;
1546 
1547  if (!GET_CABAC(MERGE_IDX))
1548  return 0;
1549 
1550  for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++)
1551  /* nothing */;
1552 
1553  return i;
1554 }
1555 
1557 {
1558  return GET_CABAC(CIIP_FLAG);
1559 }
1560 
1562 {
1563  const int w = lc->cu->cb_width;
1564  const int h = lc->cu->cb_height;
1565  if (!is_b)
1566  return PF_L0;
1567  if (w + h > 12) {
1568  const int log2 = av_log2(w) + av_log2(h);
1569  const int inc = 7 - ((1 + log2)>>1);
1570  if (GET_CABAC(INTER_PRED_IDC + inc))
1571  return PF_BI;
1572  }
1573  return PF_L0 + GET_CABAC(INTER_PRED_IDC + 5);
1574 }
1575 
1577 {
1578  const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0);
1579  return GET_CABAC(INTER_AFFINE_FLAG + inc);
1580 }
1581 
1583 {
1585 }
1586 
1588 {
1589  return GET_CABAC(SYM_MVD_FLAG);
1590 }
1591 
1592 int ff_vvc_ref_idx_lx(VVCLocalContext *lc, const uint8_t nb_refs)
1593 {
1594  const int c_max = nb_refs - 1;
1595  const int max_ctx = FFMIN(c_max, 2);
1596  int i = 0;
1597 
1598  while (i < max_ctx && GET_CABAC(REF_IDX_LX + i))
1599  i++;
1600  if (i == 2) {
1601  while (i < c_max && get_cabac_bypass(&lc->ep->cc))
1602  i++;
1603  }
1604  return i;
1605 }
1606 
1608 {
1610 }
1611 
1613 {
1615 }
1616 
1618 {
1619  return limited_kth_order_egk_decode(&lc->ep->cc, 1, 15, 17);
1620 }
1621 
1623 {
1624  return get_cabac_bypass(&lc->ep->cc);
1625 }
1626 
1628 {
1629  return GET_CABAC(MVP_LX_FLAG);
1630 }
1631 
1632 static int amvr_flag(VVCLocalContext *lc, const int inter_affine_flag)
1633 {
1634  return GET_CABAC(AMVR_FLAG + inter_affine_flag);
1635 }
1636 
1637 static int amvr_precision_idx(VVCLocalContext *lc, const int inc, const int c_max)
1638 {
1639  int i = 0;
1641  return 0;
1642  i++;
1643  if (i < c_max && GET_CABAC(AMVR_PRECISION_IDX + 1))
1644  i++;
1645  return i;
1646 }
1647 
1648 int ff_vvc_amvr_shift(VVCLocalContext *lc, const int inter_affine_flag,
1649  const PredMode pred_mode, const int has_amvr_flag)
1650 {
1651  int amvr_shift = 2;
1652  if (has_amvr_flag) {
1653  if (pred_mode == MODE_IBC || amvr_flag(lc, inter_affine_flag)) {
1654  int idx;
1655  if (inter_affine_flag) {
1656  idx = amvr_precision_idx(lc, 2, 1);
1657  amvr_shift = idx * 4;
1658  } else if (pred_mode == MODE_IBC) {
1659  idx = amvr_precision_idx(lc, 1, 1);
1660  amvr_shift = 4 + idx * 2;
1661  } else {
1662  static const int shifts[] = {3, 4, 6};
1663  idx = amvr_precision_idx(lc, 0, 2);
1664  amvr_shift = shifts[idx];
1665  }
1666  }
1667  }
1668  return amvr_shift;
1669 }
1670 
1671 int ff_vvc_bcw_idx(VVCLocalContext *lc, const int no_backward_pred_flag)
1672 {
1673  const int c_max = no_backward_pred_flag ? 4 : 2;
1674  int i = 1;
1675  if (!GET_CABAC(BCW_IDX))
1676  return 0;
1677  while (i < c_max && get_cabac_bypass(&lc->ep->cc))
1678  i++;
1679  return i;
1680 }
1681 
1683 {
1684  return GET_CABAC(TU_CB_CODED_FLAG + lc->cu->bdpcm_flag[1]);
1685 }
1686 
1687 int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag)
1688 {
1689  return GET_CABAC(TU_CR_CODED_FLAG + (lc->cu->bdpcm_flag[1] ? 2 : tu_cb_coded_flag));
1690 }
1691 
1693 {
1694  const CodingUnit *cu = lc->cu;
1695  int inc;
1696  if (cu->bdpcm_flag[0])
1697  inc = 1;
1698  else if (cu->isp_split_type == ISP_NO_SPLIT)
1699  inc = 0;
1700  else
1701  inc = 2 + lc->parse.prev_tu_cbf_y;
1703  return lc->parse.prev_tu_cbf_y;
1704 }
1705 
1707 {
1709 }
1710 
1712 {
1713  int v, i, k;
1714  if (!GET_CABAC(CU_QP_DELTA_ABS))
1715  return 0;
1716 
1717  // prefixVal
1718  for (v = 1; v < 5 && GET_CABAC(CU_QP_DELTA_ABS + 1); v++)
1719  /* nothing */;
1720  if (v < 5)
1721  return v;
1722 
1723  // 9.3.3.5 k-th order Exp-Golomb binarization process
1724  // suffixVal
1725 
1726  // CuQpDeltaVal shall in the range of −( 32 + QpBdOffset / 2 ) to +( 31 + QpBdOffset / 2 )
1727  // so k = 6 should enough
1728  for (k = 0; k < 6 && get_cabac_bypass(&lc->ep->cc); k++)
1729  /* nothing */;
1730  i = (1 << k) - 1;
1731  v = 0;
1732  while (k--)
1733  v = (v << 1) + get_cabac_bypass(&lc->ep->cc);
1734  v += i;
1735 
1736  return v + 5;
1737 }
1738 
1740 {
1741  return get_cabac_bypass(&lc->ep->cc);
1742 }
1743 
1745 {
1747 }
1748 
1750 {
1751  const int c_max = lc->fc->ps.pps->r->pps_chroma_qp_offset_list_len_minus1;
1752  int i;
1753  for (i = 0; i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX); i++)
1754  /* nothing */;
1755  return i;
1756 }
1757 
1759  const int log2_tb_size, const int log2_zo_tb_size, const int c_idx, const int ctx)
1760 {
1761  int i = 0;
1762  int max = (log2_zo_tb_size << 1) - 1;
1763  int ctx_offset, ctx_shift;
1764  if (!log2_tb_size)
1765  return 0;
1766  if (!c_idx) {
1767  const int offset_y[] = {0, 0, 3, 6, 10, 15};
1768  ctx_offset = offset_y[log2_tb_size - 1];
1769  ctx_shift = (log2_tb_size + 1) >> 2;
1770  } else {
1771  const int shifts[] = {0, 0, 0, 1, 2, 2, 2};
1772  ctx_offset = 20;
1773  ctx_shift = shifts[log2_tb_size];
1774  }
1775  while (i < max && GET_CABAC(ctx + (i >> ctx_shift) + ctx_offset))
1776  i++;
1777  return i;
1778 }
1779 
1781  const int log2_tb_width, const int log2_zo_tb_width, const int c_idx)
1782 {
1783  return last_significant_coeff_xy_prefix(lc, log2_tb_width, log2_zo_tb_width, c_idx, LAST_SIG_COEFF_X_PREFIX);
1784 }
1785 
1787  const int log2_tb_height, const int log2_zo_tb_height, const int c_idx)
1788 {
1789  return last_significant_coeff_xy_prefix(lc, log2_tb_height, log2_zo_tb_height, c_idx, LAST_SIG_COEFF_Y_PREFIX);
1790 }
1791 
1793  const int last_significant_coeff_y_prefix)
1794 {
1795  const int length = (last_significant_coeff_y_prefix >> 1) - 1;
1796  int value = get_cabac_bypass(&lc->ep->cc);
1797 
1798  for (int i = 1; i < length; i++)
1799  value = (value << 1) | get_cabac_bypass(&lc->ep->cc);
1800  return value;
1801 }
1802 
1803 int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, const int tu_cb_coded_flag, const int tu_cr_coded_flag)
1804 {
1805  return GET_CABAC(TU_JOINT_CBCR_RESIDUAL_FLAG + 2 * tu_cb_coded_flag + tu_cr_coded_flag - 1);
1806 }
1807 
1809 {
1810  return GET_CABAC(TRANSFORM_SKIP_FLAG + inc);
1811 }
1812 
1813 //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1
1814 static int get_local_sum(const int *level, const int w, const int h,
1815  const int xc, const int yc, const int hist_value)
1816 {
1817  int loc_sum = 3 * hist_value;
1818  level += w * yc + xc;
1819  if (xc < w - 1) {
1820  loc_sum += level[1];
1821  if (xc < w - 2)
1822  loc_sum += level[2] - hist_value;
1823  if (yc < h - 1)
1824  loc_sum += level[w + 1] - hist_value;
1825  }
1826  if (yc < h - 1) {
1827  loc_sum += level[w];
1828  if (yc < h - 2)
1829  loc_sum += level[w << 1] - hist_value;
1830  }
1831  return loc_sum;
1832 }
1833 
1834 //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1
1835 static int get_local_sum_ts(const int *level, const int w, const int h, const int xc, const int yc)
1836 {
1837  int loc_sum = 0;
1838  level += w * yc + xc;
1839  if (xc > 0)
1840  loc_sum += level[-1];
1841  if (yc > 0)
1842  loc_sum += level[-w];
1843  return loc_sum;
1844 }
1845 
1846 static int get_gtx_flag_inc(const ResidualCoding* rc, const int xc, const int yc, const int last)
1847 {
1848  const TransformBlock *tb = rc->tb;
1849  int inc;
1850  if (last) {
1851  const int incs[] = {0, 21, 21};
1852  inc = incs[tb->c_idx];
1853  } else {
1854  const int d = xc + yc;
1855  const int local_sum_sig = get_local_sum(rc->sig_coeff_flag,
1856  tb->tb_width,tb->tb_height, xc, yc, rc->hist_value);
1857  const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1,
1858  tb->tb_width, tb->tb_height, xc, yc, rc->hist_value);
1859  const int offset = FFMIN(loc_sum_abs_pass1 - local_sum_sig, 4);
1860 
1861  if (!tb->c_idx)
1862  inc = 1 + offset + (!d ? 15 : (d < 3 ? 10 : (d < 10 ? 5 : 0)));
1863  else
1864  inc = 22 + offset + (!d ? 5 : 0);
1865  }
1866  return inc;
1867 }
1868 
1870 {
1871  return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
1872 }
1873 
1874 static int par_level_flag_decode(VVCLocalContext *lc, const int inc)
1875 {
1876  return GET_CABAC(PAR_LEVEL_FLAG + inc);
1877 }
1878 
1880 {
1881  const int inc = 32;
1882  return GET_CABAC(PAR_LEVEL_FLAG + inc);
1883 }
1884 
1885 static int sb_coded_flag_decode(VVCLocalContext *lc, const uint8_t *sb_coded_flag,
1886  const ResidualCoding *rc, const int xs, const int ys)
1887 {
1888  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1889  const TransformBlock *tb = rc->tb;
1890  const int w = rc->width_in_sbs;
1891  const int h = rc->height_in_sbs;
1892  int inc;
1893 
1894  if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) {
1895  const int left = xs > 0 ? sb_coded_flag[-1] : 0;
1896  const int above = ys > 0 ? sb_coded_flag[-w] : 0;
1897  inc = left + above + 4;
1898  } else {
1899  const int right = (xs < w - 1) ? sb_coded_flag[1] : 0;
1900  const int bottom = (ys < h - 1) ? sb_coded_flag[w] : 0;
1901  inc = (right | bottom) + (tb->c_idx ? 2 : 0);
1902  }
1903  return GET_CABAC(SB_CODED_FLAG + inc);
1904 }
1905 
1906 static int sig_coeff_flag_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1907 {
1908  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1909  const TransformBlock *tb = rc->tb;
1910  int inc;
1911 
1912  if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) {
1913  const int local_num_sig = get_local_sum_ts(rc->sig_coeff_flag, tb->tb_width, tb->tb_height, xc, yc);
1914  inc = 60 + local_num_sig;
1915  } else {
1916  const int d = xc + yc;
1917  const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1,
1918  tb->tb_width, tb->tb_height, xc, yc, 0);
1919 
1920  if (!tb->c_idx) {
1921  inc = 12 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + ((d < 2) ? 8 : (d < 5 ? 4 : 0));
1922  } else {
1923  inc = 36 + 8 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + (d < 2 ? 4 : 0);
1924  }
1925  }
1926  return GET_CABAC(SIG_COEFF_FLAG + inc);
1927 }
1928 
1930  const int xc, const int yc, const int base_level)
1931 {
1932  const VVCSPS *sps = lc->fc->ps.sps;
1933  const TransformBlock* tb = rc->tb;
1934  const int rice_params[] = {
1935  0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2,
1936  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
1937  };
1938  int loc_sum_abs;
1939  int shift_val;
1940 
1941  loc_sum_abs = get_local_sum(rc->abs_level, tb->tb_width, tb->tb_height, xc,
1942  yc, rc->hist_value);
1943 
1944  if (!sps->r->sps_rrc_rice_extension_flag) {
1945  shift_val = 0;
1946  } else {
1947  shift_val = (av_log2(FFMAX(FFMIN(loc_sum_abs, 2048), 8)) - 3) & ~1;
1948  }
1949 
1950  loc_sum_abs = av_clip_uintp2((loc_sum_abs >> shift_val) - base_level * 5, 5);
1951 
1952  return rice_params[loc_sum_abs] + shift_val;
1953 }
1954 
1955 static int abs_decode(VVCLocalContext *lc, const int c_rice_param)
1956 {
1957  const VVCSPS *sps = lc->fc->ps.sps;
1958  const int MAX_BIN = 6;
1959  int prefix = 0;
1960  int suffix = 0;
1961 
1962  while (prefix < MAX_BIN && get_cabac_bypass(&lc->ep->cc))
1963  prefix++;
1964  if (prefix < MAX_BIN) {
1965  for (int i = 0; i < c_rice_param; i++) {
1966  suffix = (suffix << 1) | get_cabac_bypass(&lc->ep->cc);
1967  }
1968  } else {
1970  c_rice_param + 1,
1971  26 - sps->log2_transform_range,
1972  sps->log2_transform_range);
1973  }
1974  return suffix + (prefix << c_rice_param);
1975 }
1976 
1977 static int abs_remainder_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1978 {
1979  const VVCSPS *sps = lc->fc->ps.sps;
1980  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1981  const int base_level[][2][2] = {
1982  { {4, 4}, {4, 4} },
1983  { {3, 2}, {2, 1} }
1984  };
1985  const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc,
1986  base_level[sps->r->sps_rrc_rice_extension_flag][sps->bit_depth > 12][IS_I(rsh)]);
1987  const int rem = abs_decode(lc, c_rice_param);
1988 
1989  return rem;
1990 }
1991 
1992 static int abs_remainder_ts_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc)
1993 {
1994  const H266RawSliceHeader *rsh = lc->sc->sh.r;
1995  const int c_rice_param = rsh->sh_ts_residual_coding_rice_idx_minus1 + 1;
1996  const int rem = abs_decode(lc, c_rice_param);
1997 
1998  return rem;
1999 }
2000 
2002 {
2003  return get_cabac_bypass(&lc->ep->cc);
2004 }
2005 
2006 //9.3.4.2.10 Derivation process of ctxInc for the syntax element coeff_sign_flag for transform skip mode
2007 static int coeff_sign_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
2008 {
2009  const TransformBlock *tb = rc->tb;
2010  const int w = tb->tb_width;
2011  const int *level = rc->coeff_sign_level + yc * w + xc;
2012  const int left_sign = xc ? level[-1] : 0;
2013  const int above_sign = yc ? level[-w] : 0;
2014  const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx];
2015  int inc;
2016 
2017  if (left_sign == -above_sign)
2018  inc = bdpcm_flag ? 3 : 0;
2019  else if (left_sign >= 0 && above_sign >= 0)
2020  inc = bdpcm_flag ? 4 : 1;
2021  else
2022  inc = bdpcm_flag ? 5 : 2;
2023  return GET_CABAC(COEFF_SIGN_FLAG + inc);
2024 }
2025 
2026 static int abs_level_gt1_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
2027 {
2028  const TransformBlock *tb = rc->tb;
2029  const int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc;
2030  int inc;
2031 
2032  if (cu->bdpcm_flag[tb->c_idx]) {
2033  inc = 67;
2034  } else {
2035  const int l = xc > 0 ? sig_coeff_flag[-1] : 0;
2036  const int a = yc > 0 ? sig_coeff_flag[-tb->tb_width] : 0;
2037  inc = 64 + a + l;
2038  }
2039  return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
2040 }
2041 
2042 static int abs_level_gtx_flag_ts_decode(VVCLocalContext *lc, const int j)
2043 {
2044  const int inc = 67 + j;
2045  return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc);
2046 }
2047 
2048 static const uint8_t qstate_translate_table[][2] = {
2049  { 0, 2 }, { 2, 0 }, { 1, 3 }, { 3, 1 }
2050 };
2051 
2053  const int xc, const int yc, int *abs_level)
2054 {
2055  const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc, 0);
2056  const int dec_abs_level = abs_decode(lc, c_rice_param);
2057  const int zero_pos = (rc->qstate < 2 ? 1 : 2) << c_rice_param;
2058 
2059  *abs_level = 0;
2060  if (dec_abs_level != zero_pos) {
2061  *abs_level = dec_abs_level;
2062  if (dec_abs_level < zero_pos)
2063  *abs_level += 1;
2064  }
2065  return dec_abs_level;
2066 }
2067 
2069  const int remainder, const int addin)
2070 {
2071  int *stat = ep->stat_coeff + rc->tb->c_idx;
2072  if (rc->update_hist && remainder > 0) {
2073  *stat = (*stat + av_log2(remainder) + addin) >> 1;
2074  rc->update_hist = 0;
2075  }
2076 }
2077 
2079  const int log2_zo_tb_width, const int log2_zo_tb_height,
2080  TransformBlock *tb)
2081 {
2082  const VVCSPS *sps = lc->fc->ps.sps;
2083  int log2_sb_w = (FFMIN(log2_zo_tb_width, log2_zo_tb_height ) < 2 ? 1 : 2 );
2084  int log2_sb_h = log2_sb_w;
2085 
2086  if ( log2_zo_tb_width + log2_zo_tb_height > 3 ) {
2087  if ( log2_zo_tb_width < 2 ) {
2088  log2_sb_w = log2_zo_tb_width;
2089  log2_sb_h = 4 - log2_sb_w;
2090  } else if ( log2_zo_tb_height < 2 ) {
2091  log2_sb_h = log2_zo_tb_height;
2092  log2_sb_w = 4 - log2_sb_h;
2093  }
2094  }
2095  rc->log2_sb_w = log2_sb_w;
2096  rc->log2_sb_h = log2_sb_h;
2097  rc->num_sb_coeff = 1 << (log2_sb_w + log2_sb_h);
2098  rc->last_sub_block = ( 1 << ( log2_zo_tb_width + log2_zo_tb_height - (log2_sb_w + log2_sb_h))) - 1;
2099  rc->hist_value = sps->r->sps_persistent_rice_adaptation_enabled_flag ? (1 << lc->ep->stat_coeff[tb->c_idx]) : 0;
2100  rc->update_hist = sps->r->sps_persistent_rice_adaptation_enabled_flag ? 1 : 0;
2101  rc->rem_bins_pass1 = (( 1 << ( log2_zo_tb_width + log2_zo_tb_height)) * 7 ) >> 2;
2102 
2103 
2104  rc->sb_scan_x_off = ff_vvc_diag_scan_x[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h];
2105  rc->sb_scan_y_off = ff_vvc_diag_scan_y[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h];
2106 
2107  rc->scan_x_off = ff_vvc_diag_scan_x[log2_sb_w][log2_sb_h];
2108  rc->scan_y_off = ff_vvc_diag_scan_y[log2_sb_w][log2_sb_h];
2109 
2110  rc->infer_sb_cbf = 1;
2111 
2112  rc->width_in_sbs = (1 << (log2_zo_tb_width - log2_sb_w));
2113  rc->height_in_sbs = (1 << (log2_zo_tb_height - log2_sb_h));
2114  rc->nb_sbs = rc->width_in_sbs * rc->height_in_sbs;
2115 
2116  rc->last_scan_pos = rc->num_sb_coeff;
2117  rc->qstate = 0;
2118 
2119  rc->tb = tb;
2120 }
2121 
2123 {
2124  const CodingUnit *cu = lc->cu;
2125  TransformBlock *tb = rc->tb;
2126  const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx];
2127  const int xs = rc->sb_scan_x_off[i];
2128  const int ys = rc->sb_scan_y_off[i];
2129  uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
2130  int infer_sb_sig_coeff_flag = 1;
2131  int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -1, n;
2132  int abs_level_gtx_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];
2133  int abs_level_pass2[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; ///< AbsLevelPass2
2134 
2135  if (i != rc->last_sub_block || !rc->infer_sb_cbf)
2136  *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
2137  else
2138  *sb_coded_flag = 1;
2139  if (*sb_coded_flag && i < rc->last_sub_block)
2140  rc->infer_sb_cbf = 0;
2141 
2142  //first scan pass
2143  for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
2144  const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2145  const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2146  const int off = yc * tb->tb_width + xc;
2147  int *sig_coeff_flag = rc->sig_coeff_flag + off;
2148  int *abs_level_pass1 = rc->abs_level_pass1 + off;
2149  int *coeff_sign_level = rc->coeff_sign_level + off;
2150  int par_level_flag = 0;
2151 
2152  abs_level_gtx_flag[n] = 0;
2153  last_scan_pos_pass1 = n;
2154  if (*sb_coded_flag && (n != rc->num_sb_coeff - 1 || !infer_sb_sig_coeff_flag)) {
2155  *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
2156  rc->rem_bins_pass1--;
2157  if (*sig_coeff_flag)
2158  infer_sb_sig_coeff_flag = 0;
2159  } else {
2160  *sig_coeff_flag = (n == rc->num_sb_coeff - 1) && infer_sb_sig_coeff_flag && *sb_coded_flag;
2161  }
2162  *coeff_sign_level = 0;
2163  if (*sig_coeff_flag) {
2164  *coeff_sign_level = 1 - 2 * coeff_sign_flag_ts_decode(lc, cu, rc, xc, yc);
2165  abs_level_gtx_flag[n] = abs_level_gt1_flag_ts_decode(lc, cu, rc, xc, yc);
2166  rc->rem_bins_pass1 -= 2;
2167  if (abs_level_gtx_flag[n]) {
2168  par_level_flag = par_level_flag_ts_decode(lc);
2169  rc->rem_bins_pass1--;
2170  }
2171  }
2172  *abs_level_pass1 = *sig_coeff_flag + par_level_flag + abs_level_gtx_flag[n];
2173  }
2174 
2175  //greater than x scan pass
2176  for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) {
2177  const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2178  const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2179  const int off = yc * tb->tb_width + xc;
2180 
2181  abs_level_pass2[n] = rc->abs_level_pass1[off];
2182  for (int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) {
2183  abs_level_gtx_flag[n] = abs_level_gtx_flag_ts_decode(lc, j);
2184  abs_level_pass2[n] += abs_level_gtx_flag[n] << 1;
2185  rc->rem_bins_pass1--;
2186  }
2187  last_scan_pos_pass2 = n;
2188  }
2189 
2190  /* remainder scan pass */
2191  for (n = 0; n < rc->num_sb_coeff; n++) {
2192  const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2193  const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2194  const int off = yc * tb->tb_width + xc;
2195  const int *abs_level_pass1 = rc->abs_level_pass1 + off;
2196  int *abs_level = rc->abs_level + off;
2197  int *coeff_sign_level = rc->coeff_sign_level + off;
2198  int abs_remainder = 0;
2199 
2200  if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) ||
2201  (n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 &&
2202  *abs_level_pass1 >= 2) ||
2203  (n > last_scan_pos_pass1 && *sb_coded_flag))
2204  abs_remainder = abs_remainder_ts_decode(lc, rc, xc, yc);
2205  if (n <= last_scan_pos_pass2) {
2206  *abs_level = abs_level_pass2[n] + 2 * abs_remainder;
2207  } else if (n <= last_scan_pos_pass1) {
2208  *abs_level = *abs_level_pass1 + 2 * abs_remainder;
2209  } else {
2210  *abs_level = abs_remainder;
2211  if (abs_remainder) {
2212  //n > lastScanPosPass1
2213  *coeff_sign_level = 1 - 2 * coeff_sign_flag_decode(lc);
2214  }
2215  }
2216  if (!bdpcm_flag && n <= last_scan_pos_pass1) {
2217  const int left = xc > 0 ? abs_level[-1] : 0;
2218  const int above = yc > 0 ? abs_level[-tb->tb_width] : 0;
2219  const int pred = FFMAX(left, above);
2220 
2221  if (*abs_level == 1 && pred > 0)
2222  *abs_level = pred;
2223  else if (*abs_level > 0 && *abs_level <= pred)
2224  (*abs_level)--;
2225  }
2226  if (*abs_level) {
2227  tb->coeffs[off] = *coeff_sign_level * *abs_level;
2228  tb->max_scan_x = FFMAX(xc, tb->max_scan_x);
2229  tb->max_scan_y = FFMAX(yc, tb->max_scan_y);
2230  tb->min_scan_x = FFMIN(xc, tb->min_scan_x);
2231  tb->min_scan_y = FFMIN(yc, tb->min_scan_y);
2232  } else {
2233  tb->coeffs[off] = 0;
2234  }
2235  }
2236 
2237  return 0;
2238 }
2239 
2241 {
2242  ResidualCoding rc;
2243  tb->min_scan_x = tb->min_scan_y = INT_MAX;
2244  init_residual_coding(lc, &rc, tb->log2_tb_width, tb->log2_tb_height, tb);
2245  for (int i = 0; i <= rc.last_sub_block; i++) {
2246  int ret = residual_ts_coding_subblock(lc, &rc, i);
2247  if (ret < 0)
2248  return ret;
2249  }
2250 
2251  return 0;
2252 }
2253 
2254 static inline int residual_coding_subblock(VVCLocalContext *lc, ResidualCoding *rc, const int i)
2255 {
2256  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2257  TransformBlock *tb = rc->tb;
2258  int first_sig_scan_pos_sb, last_sig_scan_pos_sb;
2259  int first_pos_mode0, first_pos_mode1;
2260  int infer_sb_dc_sig_coeff_flag = 0;
2261  int n, sig_hidden_flag, sum = 0;
2262  int abs_level_gt2_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE];
2263  const int start_qstate_sb = rc->qstate;
2264  const int xs = rc->sb_scan_x_off[i];
2265  const int ys = rc->sb_scan_y_off[i];
2266  uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs;
2267 
2268 
2270  if (i < rc->last_sub_block && i > 0) {
2271  *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys);
2272  infer_sb_dc_sig_coeff_flag = 1;
2273  } else {
2274  *sb_coded_flag = 1;
2275  }
2276  if (*sb_coded_flag && (xs > 3 || ys > 3) && !tb->c_idx)
2278 
2279  if (!*sb_coded_flag)
2280  return 0;
2281 
2282  first_sig_scan_pos_sb = rc->num_sb_coeff;
2283  last_sig_scan_pos_sb = -1;
2284  first_pos_mode0 = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1);
2285  first_pos_mode1 = first_pos_mode0;
2286  for (n = first_pos_mode0; n >= 0 && rc->rem_bins_pass1 >= 4; n--) {
2287  const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2288  const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2289  const int last = (xc == rc->last_significant_coeff_x && yc == rc->last_significant_coeff_y);
2290  int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc;
2291  int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc;
2292 
2293  if ((n > 0 || !infer_sb_dc_sig_coeff_flag ) && !last) {
2294  *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc);
2295  rc->rem_bins_pass1--;
2296  if (*sig_coeff_flag)
2297  infer_sb_dc_sig_coeff_flag = 0;
2298  } else {
2299  *sig_coeff_flag = last || (!rc->scan_x_off[n] && !rc ->scan_y_off[n] &&
2300  infer_sb_dc_sig_coeff_flag);
2301  }
2302  *abs_level_pass1 = 0;
2303  if (*sig_coeff_flag) {
2304  int abs_level_gt1_flag, par_level_flag = 0;
2305  const int inc = get_gtx_flag_inc(rc, xc, yc, last);
2306  abs_level_gt1_flag = abs_level_gtx_flag_decode(lc, inc);
2307  rc->rem_bins_pass1--;
2308  if (abs_level_gt1_flag) {
2309  par_level_flag = par_level_flag_decode(lc, inc);
2310  abs_level_gt2_flag[n] = abs_level_gtx_flag_decode(lc, inc + 32);
2311  rc->rem_bins_pass1 -= 2;
2312  } else {
2313  abs_level_gt2_flag[n] = 0;
2314  }
2315  if (last_sig_scan_pos_sb == -1)
2316  last_sig_scan_pos_sb = n;
2317  first_sig_scan_pos_sb = n;
2318 
2319  *abs_level_pass1 =
2320  1 + par_level_flag + abs_level_gt1_flag + (abs_level_gt2_flag[n] << 1);
2321  } else {
2322  abs_level_gt2_flag[n] = 0;
2323  }
2324 
2325  if (rsh->sh_dep_quant_used_flag)
2326  rc->qstate = qstate_translate_table[rc->qstate][*abs_level_pass1 & 1];
2327 
2328  first_pos_mode1 = n - 1;
2329  }
2330  for (n = first_pos_mode0; n > first_pos_mode1; n--) {
2331  const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2332  const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2333  const int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc;
2334  int *abs_level = rc->abs_level + yc * tb->tb_width + xc;
2335 
2336  *abs_level = *abs_level_pass1;
2337  if (abs_level_gt2_flag[n]) {
2338  const int abs_remainder = abs_remainder_decode(lc, rc, xc, yc);
2339  ep_update_hist(lc->ep, rc, abs_remainder, 2);
2340  *abs_level += 2 * abs_remainder;
2341  }
2342  }
2343  for (n = first_pos_mode1; n >= 0; n--) {
2344  const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2345  const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2346  int *abs_level = rc->abs_level + yc * tb->tb_width + xc;
2347 
2348  if (*sb_coded_flag) {
2349  const int dec_abs_level = dec_abs_level_decode(lc, rc, xc, yc, abs_level);
2350  ep_update_hist(lc->ep, rc, dec_abs_level, 0);
2351  }
2352  if (*abs_level > 0) {
2353  if (last_sig_scan_pos_sb == -1)
2354  last_sig_scan_pos_sb = n;
2355  first_sig_scan_pos_sb = n;
2356  }
2357  if (rsh->sh_dep_quant_used_flag)
2358  rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1];
2359  }
2360  sig_hidden_flag = rsh->sh_sign_data_hiding_used_flag &&
2361  (last_sig_scan_pos_sb - first_sig_scan_pos_sb > 3 ? 1 : 0);
2362 
2363  if (rsh->sh_dep_quant_used_flag)
2364  rc->qstate = start_qstate_sb;
2365  n = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1);
2366  for (/* nothing */; n >= 0; n--) {
2367  int trans_coeff_level;
2368  const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n];
2369  const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n];
2370  const int off = yc * tb->tb_width + xc;
2371  const int *abs_level = rc->abs_level + off;
2372 
2373  if (*abs_level > 0) {
2374  int sign = 1;
2375  if (!sig_hidden_flag || (n != first_sig_scan_pos_sb))
2376  sign = 1 - 2 * coeff_sign_flag_decode(lc);
2377  if (rsh->sh_dep_quant_used_flag) {
2378  trans_coeff_level = (2 * *abs_level - (rc->qstate > 1)) * sign;
2379  } else {
2380  trans_coeff_level = *abs_level * sign;
2381  if (sig_hidden_flag) {
2382  sum += *abs_level;
2383  if (n == first_sig_scan_pos_sb && (sum % 2))
2384  trans_coeff_level = -trans_coeff_level;
2385  }
2386  }
2387  tb->coeffs[off] = trans_coeff_level;
2388  tb->max_scan_x = FFMAX(xc, tb->max_scan_x);
2389  tb->max_scan_y = FFMAX(yc, tb->max_scan_y);
2390  }
2391  if (rsh->sh_dep_quant_used_flag)
2392  rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1];
2393  }
2394 
2395  return 0;
2396 }
2397 
2399 {
2400  int xc, yc, xs, ys;
2401  do {
2402  if (!rc->last_scan_pos) {
2403  rc->last_scan_pos = rc->num_sb_coeff;
2404  rc->last_sub_block--;
2405  }
2406  rc->last_scan_pos--;
2407  xs = rc->sb_scan_x_off[rc->last_sub_block];
2408  ys = rc->sb_scan_y_off[rc->last_sub_block];
2409  xc = (xs << rc->log2_sb_w) + rc->scan_x_off[rc->last_scan_pos];
2410  yc = (ys << rc->log2_sb_h) + rc->scan_y_off[rc->last_scan_pos];
2411  } while ((xc != rc->last_significant_coeff_x) || (yc != rc->last_significant_coeff_y));
2412 }
2413 
2415  const int log2_zo_tb_width, const int log2_zo_tb_height)
2416 {
2417  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2418  const TransformBlock *tb = rc->tb;
2419  int last_significant_coeff_x, last_significant_coeff_y;
2420 
2421  last_significant_coeff_x = last_significant_coeff_x_prefix_decode(lc,
2422  tb->log2_tb_width, log2_zo_tb_width, tb->c_idx);
2423 
2424  last_significant_coeff_y = last_significant_coeff_y_prefix_decode(lc,
2425  tb->log2_tb_height, log2_zo_tb_height, tb->c_idx);
2426 
2427  if (last_significant_coeff_x > 3) {
2428  int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_x);
2429  last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) *
2430  (2 + (last_significant_coeff_x & 1)) + suffix;
2431  }
2432  if (last_significant_coeff_y > 3) {
2433  int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_y);
2434  last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) *
2435  (2 + (last_significant_coeff_y & 1)) + suffix;
2436  }
2437  if (rsh->sh_reverse_last_sig_coeff_flag) {
2438  last_significant_coeff_x = (1 << log2_zo_tb_width) - 1 - last_significant_coeff_x;
2439  last_significant_coeff_y = (1 << log2_zo_tb_height) - 1 - last_significant_coeff_y;
2440  }
2441  rc->last_significant_coeff_x = last_significant_coeff_x;
2442  rc->last_significant_coeff_y = last_significant_coeff_y;
2443 }
2444 
2446 {
2447  const VVCSPS *sps = lc->fc->ps.sps;
2448  const CodingUnit *cu = lc->cu;
2449  const int log2_tb_width = tb->log2_tb_width;
2450  const int log2_tb_height = tb->log2_tb_height;
2451  const int c_idx = tb->c_idx;
2452  int log2_zo_tb_width, log2_zo_tb_height;
2453  ResidualCoding rc;
2454 
2455  if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width == 5 && log2_tb_height < 6)
2456  log2_zo_tb_width = 4;
2457  else
2458  log2_zo_tb_width = FFMIN(log2_tb_width, 5 );
2459 
2460  if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width < 6 && log2_tb_height == 5 )
2461  log2_zo_tb_height = 4;
2462  else
2463  log2_zo_tb_height = FFMIN(log2_tb_height, 5);
2464 
2465  init_residual_coding(lc, &rc, log2_zo_tb_width, log2_zo_tb_height, tb);
2466  last_significant_coeff_x_y_decode(&rc, lc, log2_zo_tb_width, log2_zo_tb_height);
2467  derive_last_scan_pos(&rc);
2468 
2469  if (!rc.last_sub_block && log2_tb_width >= 2 && log2_tb_height >= 2 && !tb->ts && rc.last_scan_pos > 0)
2470  lc->parse.lfnst_dc_only = 0;
2471  if ((rc.last_sub_block > 0 && log2_tb_width >= 2 && log2_tb_height >= 2 ) ||
2472  (rc.last_scan_pos > 7 && (log2_tb_width == 2 || log2_tb_width == 3 ) &&
2473  log2_tb_width == log2_tb_height))
2475  if ((rc.last_sub_block > 0 || rc.last_scan_pos > 0 ) && !c_idx)
2476  lc->parse.mts_dc_only = 0;
2477 
2478  memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs));
2479  memset(rc.abs_level, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level[0]));
2480  memset(rc.sb_coded_flag, 0, rc.nb_sbs);
2481  memset(rc.abs_level_pass1, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level_pass1[0]));
2482  memset(rc.sig_coeff_flag, 0, tb->tb_width * tb->tb_height * sizeof(rc.sig_coeff_flag[0]));
2483 
2484  for (int i = rc.last_sub_block; i >= 0; i--) {
2485  int ret = residual_coding_subblock(lc, &rc, i);
2486  if (ret < 0)
2487  return ret;
2488  }
2489 
2490  return 0;
2491 }
2492 
2494 {
2495  const H266RawSliceHeader *rsh = lc->sc->sh.r;
2496  const int ts = !rsh->sh_ts_residual_coding_disabled_flag && tb->ts;
2497 
2498  return ts ? hls_residual_ts_coding(lc, tb) : hls_residual_coding(lc, tb);
2499 }
2500 
2502 {
2503  return GET_CABAC(CU_CODED_FLAG);
2504 }
2505 
2507 {
2508  const int w = lc->cu->cb_width;
2509  const int h = lc->cu->cb_height;
2510  const int inc = w * h <= 256;
2511  return GET_CABAC(CU_SBT_FLAG + inc);
2512 }
2513 
2515 {
2516  return GET_CABAC(CU_SBT_QUAD_FLAG);
2517 }
2518 
2520 {
2521  const int w = lc->cu->cb_width;
2522  const int h = lc->cu->cb_height;
2523  const int inc = (w == h) ? 0 : ((w < h) ? 1 : 2);
2525 }
2526 
2528 {
2529  return GET_CABAC(CU_SBT_POS_FLAG);
2530 }
2531 
2533 {
2534  if (!GET_CABAC(LFNST_IDX + inc))
2535  return 0;
2536  if (!GET_CABAC(LFNST_IDX + 2))
2537  return 1;
2538  return 2;
2539 }
2540 
2542 {
2543  int i;
2544  for (i = 0; i < 4; i++) {
2545  if (!GET_CABAC(MTS_IDX + i))
2546  return i;
2547  }
2548  return i;
2549 }
2550 
2552 {
2553  return get_cabac_terminate(&lc->ep->cc);
2554 }
2555 
2557 {
2558  return get_cabac_terminate(&lc->ep->cc);
2559 }
2560 
2562 {
2563  return get_cabac_terminate(&lc->ep->cc);
2564 }
LAST_SIG_COEFF_Y_PREFIX
@ LAST_SIG_COEFF_Y_PREFIX
Definition: cabac.c:102
is_inside
static int is_inside(int x, int y, int w, int h)
Definition: vf_floodfill.c:53
VVCCabacState
Definition: ctu.h:356
COPY_ABOVE_PALETTE_INDICES_FLAG
@ COPY_ABOVE_PALETTE_INDICES_FLAG
Definition: cabac.c:80
VVCSPS
Definition: ps.h:58
ff_vvc_residual_coding
int ff_vvc_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
Definition: cabac.c:2493
TU_Y_CODED_FLAG
@ TU_Y_CODED_FLAG
Definition: cabac.c:93
get_luma_pred_mode
static PredMode get_luma_pred_mode(VVCLocalContext *lc)
Definition: cabac.c:1505
ff_vvc_cu_chroma_qp_offset_idx
int ff_vvc_cu_chroma_qp_offset_idx(VVCLocalContext *lc)
Definition: cabac.c:1749
ff_vvc_mmvd_offset_coding
void ff_vvc_mmvd_offset_coding(VVCLocalContext *lc, Mv *mmvd_offset, const int ph_mmvd_fullpel_only_flag)
Definition: cabac.c:1495
get_inter_flag_inc
static int get_inter_flag_inc(VVCLocalContext *lc, const int x0, const int y0)
Definition: cabac.c:1437
dec_abs_level_decode
static int dec_abs_level_decode(VVCLocalContext *lc, const ResidualCoding *rc, const int xc, const int yc, int *abs_level)
Definition: cabac.c:2052
level
uint8_t level
Definition: svq3.c:205
VVCPPS
Definition: ps.h:92
ff_vvc_sao_eo_class_decode
int ff_vvc_sao_eo_class_decode(VVCLocalContext *lc)
Definition: cabac.c:1043
av_clip
#define av_clip
Definition: common.h:100
ABS_MVD_GREATER0_FLAG
@ ABS_MVD_GREATER0_FLAG
Definition: cabac.c:91
get_inc
static av_always_inline uint8_t get_inc(VVCLocalContext *lc, const uint8_t *ctx)
Definition: cabac.c:1001
ResidualCoding::log2_sb_h
int log2_sb_h
Definition: cabac.c:776
last_significant_coeff_y_prefix_decode
static av_always_inline int last_significant_coeff_y_prefix_decode(VVCLocalContext *lc, const int log2_tb_height, const int log2_zo_tb_height, const int c_idx)
Definition: cabac.c:1786
abs_remainder_ts_decode
static int abs_remainder_ts_decode(VVCLocalContext *lc, const ResidualCoding *rc, const int xc, const int yc)
Definition: cabac.c:1992
ResidualCoding::sb_scan_x_off
const uint8_t * sb_scan_x_off
Definition: cabac.c:787
VVCLocalContext::mts_zero_out_sig_coeff_flag
int mts_zero_out_sig_coeff_flag
MtsZeroOutSigCoeffFlag;.
Definition: ctu.h:419
TransformBlock::tb_width
int tb_width
Definition: ctu.h:149
ff_vvc_new_palette_entries
int ff_vvc_new_palette_entries(VVCLocalContext *lc, const int bit_depth)
Definition: cabac.c:1390
ff_vvc_num_signalled_palette_entries
int ff_vvc_num_signalled_palette_entries(VVCLocalContext *lc)
Definition: cabac.c:1385
VVCPPS::r
const H266RawPPS * r
RefStruct reference.
Definition: ps.h:93
abs_level_gt1_flag_ts_decode
static int abs_level_gt1_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
Definition: cabac.c:2026
ff_ctz
#define ff_ctz
Definition: intmath.h:107
SAO_BAND
@ SAO_BAND
Definition: hevcdec.h:166
split_qt_flag_decode
static int split_qt_flag_decode(VVCLocalContext *lc, const int x0, const int y0, const int ch_type, const int cqt_depth)
Definition: cabac.c:1132
ff_vvc_regular_merge_flag
int ff_vvc_regular_merge_flag(VVCLocalContext *lc, const int cu_skip_flag)
Definition: cabac.c:1464
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:124
coeff_sign_flag_ts_decode
static int coeff_sign_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc)
Definition: cabac.c:2007
PRED_MODE_FLAG
@ PRED_MODE_FLAG
Definition: cabac.c:47
CodingUnit
Definition: hevcdec.h:292
H266RawSliceHeader::sh_ts_residual_coding_disabled_flag
uint8_t sh_ts_residual_coding_disabled_flag
Definition: cbs_h266.h:827
amvr_flag
static int amvr_flag(VVCLocalContext *lc, const int inter_affine_flag)
Definition: cabac.c:1632
REGULAR_MERGE_FLAG
@ REGULAR_MERGE_FLAG
Definition: cabac.c:83
SB_CODED_FLAG
@ SB_CODED_FLAG
Definition: cabac.c:103
ff_vvc_ref_idx_lx
int ff_vvc_ref_idx_lx(VVCLocalContext *lc, const uint8_t nb_refs)
Definition: cabac.c:1592
CodingUnit::bdpcm_flag
int bdpcm_flag[VVC_MAX_SAMPLE_ARRAYS]
BdpcmFlag.
Definition: ctu.h:325
ff_vvc_end_of_slice_flag_decode
int ff_vvc_end_of_slice_flag_decode(VVCLocalContext *lc)
Definition: cabac.c:2551
INTER_AFFINE_FLAG
@ INTER_AFFINE_FLAG
Definition: cabac.c:65
TransformBlock::min_scan_y
int min_scan_y
Definition: ctu.h:157
MODE_IBC
@ MODE_IBC
Definition: ctu.h:194
ff_vvc_intra_luma_ref_idx
int ff_vvc_intra_luma_ref_idx(VVCLocalContext *lc)
Definition: cabac.c:1316
ff_vvc_inter_affine_flag
int ff_vvc_inter_affine_flag(VVCLocalContext *lc)
Definition: cabac.c:1576
vvc_refill2
static void vvc_refill2(CABACContext *c)
Definition: cabac.c:860
data.h
SAO_TYPE_IDX
@ SAO_TYPE_IDX
Definition: cabac.c:39
w
uint8_t w
Definition: llviddspenc.c:38
REF_IDX_LX
@ REF_IDX_LX
Definition: cabac.c:68
NON_INTER_FLAG
@ NON_INTER_FLAG
Definition: cabac.c:44
GENERAL_MERGE_FLAG
@ GENERAL_MERGE_FLAG
Definition: cabac.c:63
VVCLocalContext::mts_dc_only
int mts_dc_only
MtsDcOnly.
Definition: ctu.h:418
ff_vvc_intra_mip_flag
int ff_vvc_intra_mip_flag(VVCLocalContext *lc, const uint8_t *intra_mip_flag)
Definition: cabac.c:1294
VVCLocalContext::sc
SliceContext * sc
Definition: ctu.h:445
TRANSFORM_SKIP_FLAG
@ TRANSFORM_SKIP_FLAG
Definition: cabac.c:99
ABS_LEVEL_GTX_FLAG
@ ABS_LEVEL_GTX_FLAG
Definition: cabac.c:106
ff_vvc_lfnst_idx
int ff_vvc_lfnst_idx(VVCLocalContext *lc, const int inc)
Definition: cabac.c:2532
SPLIT_BT_HOR
@ SPLIT_BT_HOR
Definition: ctu.h:128
INTRA_LUMA_NOT_PLANAR_FLAG
@ INTRA_LUMA_NOT_PLANAR_FLAG
Definition: cabac.c:57
Mv::y
int16_t y
vertical component of motion vector
Definition: hevcdec.h:307
ff_vvc_cu_affine_type_flag
int ff_vvc_cu_affine_type_flag(VVCLocalContext *lc)
Definition: cabac.c:1582
SAO_EDGE
@ SAO_EDGE
Definition: hevcdec.h:167
VVCSH::r
const H266RawSliceHeader * r
RefStruct reference.
Definition: ps.h:239
SAO_MERGE_FLAG
@ SAO_MERGE_FLAG
Definition: cabac.c:38
ff_vvc_mmvd_merge_flag
int ff_vvc_mmvd_merge_flag(VVCLocalContext *lc)
Definition: cabac.c:1470
CU_SBT_FLAG
@ CU_SBT_FLAG
Definition: cabac.c:74
base
uint8_t base
Definition: vp3data.h:128
ff_vvc_palette_escape_val_present_flag
bool ff_vvc_palette_escape_val_present_flag(VVCLocalContext *lc)
Definition: cabac.c:1395
TransformBlock::min_scan_x
int min_scan_x
Definition: ctu.h:156
MTT_SPLIT_CU_VERTICAL_FLAG
@ MTT_SPLIT_CU_VERTICAL_FLAG
Definition: cabac.c:42
VVCSplitMode
VVCSplitMode
Definition: ctu.h:125
max
#define max(a, b)
Definition: cuda_runtime.h:33
CU_SBT_QUAD_FLAG
@ CU_SBT_QUAD_FLAG
Definition: cabac.c:75
ff_vvc_ciip_flag
int ff_vvc_ciip_flag(VVCLocalContext *lc)
Definition: cabac.c:1556
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
ff_vvc_intra_luma_mpm_idx
int ff_vvc_intra_luma_mpm_idx(VVCLocalContext *lc)
Definition: cabac.c:1348
ResidualCoding::infer_sb_cbf
uint8_t infer_sb_cbf
Definition: cabac.c:798
TransformBlock::max_scan_y
int max_scan_y
Definition: ctu.h:155
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
SPLIT_CU_FLAG
@ SPLIT_CU_FLAG
Definition: cabac.c:40
ff_vvc_abs_mvd_greater0_flag
int ff_vvc_abs_mvd_greater0_flag(VVCLocalContext *lc)
Definition: cabac.c:1607
ff_vvc_isp_split_type
enum IspType ff_vvc_isp_split_type(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
Definition: cabac.c:1331
abs_remainder_decode
static int abs_remainder_decode(VVCLocalContext *lc, const ResidualCoding *rc, const int xc, const int yc)
Definition: cabac.c:1977
ep_update_hist
static void ep_update_hist(EntryPoint *ep, ResidualCoding *rc, const int remainder, const int addin)
Definition: cabac.c:2068
ff_vvc_sbt_quad_flag
int ff_vvc_sbt_quad_flag(VVCLocalContext *lc)
Definition: cabac.c:2514
VVCLocalContext::lfnst_zero_out_sig_coeff_flag
int lfnst_zero_out_sig_coeff_flag
LfnstZeroOutSigCoeffFlag.
Definition: ctu.h:416
LAST_SIG_COEFF_X_PREFIX
@ LAST_SIG_COEFF_X_PREFIX
Definition: cabac.c:101
abs_get_rice_param
static int abs_get_rice_param(VVCLocalContext *lc, const ResidualCoding *rc, const int xc, const int yc, const int base_level)
Definition: cabac.c:1929
TransformBlock::max_scan_x
int max_scan_x
Definition: ctu.h:154
CU_SBT_HORIZONTAL_FLAG
@ CU_SBT_HORIZONTAL_FLAG
Definition: cabac.c:76
SPLIT_QT
@ SPLIT_QT
Definition: ctu.h:131
VVCLocalContext::lfnst_dc_only
int lfnst_dc_only
LfnstDcOnly.
Definition: ctu.h:415
ff_vvc_intra_mip_transposed_flag
int ff_vvc_intra_mip_transposed_flag(VVCLocalContext *lc)
Definition: cabac.c:1302
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:56
BCW_IDX
@ BCW_IDX
Definition: cabac.c:72
ff_vvc_palette_idx_idc
int ff_vvc_palette_idx_idc(VVCLocalContext *lc, const int max_palette_index, const bool adjust)
Definition: cabac.c:1422
GET_CABAC
#define GET_CABAC(ctx)
Definition: cabac.c:913
ResidualCoding::update_hist
int update_hist
Definition: cabac.c:779
SPLIT_BT_VER
@ SPLIT_BT_VER
Definition: ctu.h:130
ff_vvc_sao_offset_sign_decode
int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc)
Definition: cabac.c:1038
SYNTAX_ELEMENT_LAST
@ SYNTAX_ELEMENT_LAST
Definition: cabac.c:108
ff_vvc_intra_mip_mode
int ff_vvc_intra_mip_mode(VVCLocalContext *lc)
Definition: cabac.c:1307
VVCFrameParamSets::sps
const VVCSPS * sps
RefStruct reference.
Definition: ps.h:230
ResidualCoding::log2_sb_w
int log2_sb_w
Definition: cabac.c:775
CU_SBT_POS_FLAG
@ CU_SBT_POS_FLAG
Definition: cabac.c:77
u
#define u(width, name, range_min, range_max)
Definition: cbs_apv.c:83
VVCLocalContext::fc
VVCFrameContext * fc
Definition: ctu.h:446
CIIP_FLAG
@ CIIP_FLAG
Definition: cabac.c:87
EntryPoint::stat_coeff
int stat_coeff[VVC_MAX_SAMPLE_ARRAYS]
StatCoeff.
Definition: ctu.h:366
MODE_INTER
@ MODE_INTER
Definition: hevcdec.h:108
ResidualCoding::sb_coded_flag
uint8_t sb_coded_flag[MAX_SUB_BLOCKS *MAX_SUB_BLOCKS]
Definition: cabac.c:792
ff_vvc_cu_coded_flag
int ff_vvc_cu_coded_flag(VVCLocalContext *lc)
Definition: cabac.c:2501
TransformBlock::c_idx
uint8_t c_idx
Definition: ctu.h:144
ResidualCoding::sb_scan_y_off
const uint8_t * sb_scan_y_off
Definition: cabac.c:788
SPLIT_TT_VER
@ SPLIT_TT_VER
Definition: ctu.h:129
ResidualCoding::height_in_sbs
int height_in_sbs
Definition: cabac.c:784
SIG_COEFF_FLAG
@ SIG_COEFF_FLAG
Definition: cabac.c:104
val
static double val(void *priv, double ch)
Definition: aeval.c:77
H266RawPPS::pps_chroma_qp_offset_list_len_minus1
uint8_t pps_chroma_qp_offset_list_len_minus1
Definition: cbs_h266.h:560
CU_QP_DELTA_ABS
@ CU_QP_DELTA_ABS
Definition: cabac.c:96
ff_vvc_mvp_lx_flag
int ff_vvc_mvp_lx_flag(VVCLocalContext *lc)
Definition: cabac.c:1627
ABS_MVD_GREATER1_FLAG
@ ABS_MVD_GREATER1_FLAG
Definition: cabac.c:92
residual_coding_subblock
static int residual_coding_subblock(VVCLocalContext *lc, ResidualCoding *rc, const int i)
Definition: cabac.c:2254
CABAC_MASK
#define CABAC_MASK
Definition: cabac.h:39
CodingUnit::cb_width
int cb_width
Definition: ctu.h:291
mmvd_direction_idx_decode
static int mmvd_direction_idx_decode(VVCLocalContext *lc)
Definition: cabac.c:1490
last_sig_coeff_suffix_decode
static av_always_inline int last_sig_coeff_suffix_decode(VVCLocalContext *lc, const int last_significant_coeff_y_prefix)
Definition: cabac.c:1792
ff_vvc_split_cu_flag
int ff_vvc_split_cu_flag(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const int is_chroma, const VVCAllowedSplit *a)
Definition: cabac.c:1110
get_left_top
static av_always_inline void get_left_top(const VVCLocalContext *lc, uint8_t *left, uint8_t *top, const int x0, const int y0, const uint8_t *left_ctx, const uint8_t *top_ctx)
Definition: cabac.c:983
INTRA_BDPCM_LUMA_DIR_FLAG
@ INTRA_BDPCM_LUMA_DIR_FLAG
Definition: cabac.c:51
ff_h264_norm_shift
static const uint8_t *const ff_h264_norm_shift
Definition: cabac_functions.h:58
ResidualCoding::scan_x_off
const uint8_t * scan_x_off
Definition: cabac.c:789
ff_vvc_merge_gpm_idx
int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx)
Definition: cabac.c:1542
INTRA_BDPCM_CHROMA_FLAG
@ INTRA_BDPCM_CHROMA_FLAG
Definition: cabac.c:58
mmvd_distance_idx_decode
static int mmvd_distance_idx_decode(VVCLocalContext *lc)
Definition: cabac.c:1480
MAX_TB_SIZE
#define MAX_TB_SIZE
Definition: cabac.c:769
INTRA_LUMA_REF_IDX
@ INTRA_LUMA_REF_IDX
Definition: cabac.c:53
ff_vvc_tu_y_coded_flag
int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc)
Definition: cabac.c:1692
MTT_SPLIT_CU_BINARY_FLAG
@ MTT_SPLIT_CU_BINARY_FLAG
Definition: cabac.c:43
s
#define s(width, name)
Definition: cbs_vp9.c:198
EntryPoint::cabac_state
VVCCabacState cabac_state[VVC_CONTEXTS]
Definition: ctu.h:370
H266RawSliceHeader::sh_cabac_init_flag
uint8_t sh_cabac_init_flag
Definition: cbs_h266.h:801
SAO_NOT_APPLIED
@ SAO_NOT_APPLIED
Definition: hevcdec.h:165
MTS_IDX
@ MTS_IDX
Definition: cabac.c:79
RUN_COPY_FLAG
@ RUN_COPY_FLAG
Definition: cabac.c:82
adjust
static int adjust(int x, int size)
Definition: mobiclip.c:513
last_significant_coeff_x_prefix_decode
static av_always_inline int last_significant_coeff_x_prefix_decode(VVCLocalContext *lc, const int log2_tb_width, const int log2_zo_tb_width, const int c_idx)
Definition: cabac.c:1780
LFNST_IDX
@ LFNST_IDX
Definition: cabac.c:78
abs_level_gtx_flag_ts_decode
static int abs_level_gtx_flag_ts_decode(VVCLocalContext *lc, const int j)
Definition: cabac.c:2042
hls_residual_ts_coding
static int hls_residual_ts_coding(VVCLocalContext *lc, TransformBlock *tb)
Definition: cabac.c:2240
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:493
MMVD_DISTANCE_IDX
@ MMVD_DISTANCE_IDX
Definition: cabac.c:86
INTRA_CHROMA_PRED_MODE
@ INTRA_CHROMA_PRED_MODE
Definition: cabac.c:62
sb_coded_flag_decode
static int sb_coded_flag_decode(VVCLocalContext *lc, const uint8_t *sb_coded_flag, const ResidualCoding *rc, const int xs, const int ys)
Definition: cabac.c:1885
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
SyntaxElement
SyntaxElement
Definition: cabac.c:32
ResidualCoding::abs_level_pass1
int abs_level_pass1[MAX_TB_SIZE *MAX_TB_SIZE]
AbsLevelPass1[][].
Definition: cabac.c:794
MERGE_SUBBLOCK_FLAG
@ MERGE_SUBBLOCK_FLAG
Definition: cabac.c:88
ctx
AVFormatContext * ctx
Definition: movenc.c:49
ff_vvc_bcw_idx
int ff_vvc_bcw_idx(VVCLocalContext *lc, const int no_backward_pred_flag)
Definition: cabac.c:1671
CodingUnit::tree_type
VVCTreeType tree_type
Definition: ctu.h:288
vvc_get_cabac
static int vvc_get_cabac(CABACContext *c, VVCCabacState *base, const int ctx)
Definition: cabac.c:885
hls_residual_coding
static int hls_residual_coding(VVCLocalContext *lc, TransformBlock *tb)
Definition: cabac.c:2445
ff_vvc_sbt_pos_flag
int ff_vvc_sbt_pos_flag(VVCLocalContext *lc)
Definition: cabac.c:2527
AMVR_PRECISION_IDX
@ AMVR_PRECISION_IDX
Definition: cabac.c:71
CU_CODED_FLAG
@ CU_CODED_FLAG
Definition: cabac.c:73
ff_vvc_intra_luma_not_planar_flag
int ff_vvc_intra_luma_not_planar_flag(VVCLocalContext *lc, const int intra_subpartitions_mode_flag)
Definition: cabac.c:1343
VVCLocalContext::parse
struct VVCLocalContext::@313 parse
cabac_init_state
static void cabac_init_state(VVCLocalContext *lc)
Definition: cabac.c:813
kth_order_egk_decode
static int kth_order_egk_decode(CABACContext *c, int k)
Definition: cabac.c:932
ff_vvc_cu_skip_flag
int ff_vvc_cu_skip_flag(VVCLocalContext *lc, const uint8_t *cu_skip_flag)
Definition: cabac.c:1268
CCLM_MODE_IDX
@ CCLM_MODE_IDX
Definition: cabac.c:61
ResidualCoding::num_sb_coeff
int num_sb_coeff
Definition: cabac.c:780
cabac_reinit
static int cabac_reinit(VVCLocalContext *lc)
Definition: cabac.c:808
CodingUnit::sbt_flag
uint8_t sbt_flag
Definition: ctu.h:298
xs
#define xs(width, name, var, subs,...)
Definition: cbs_vp9.c:305
CNU
#define CNU
Definition: cabac.c:30
IspType
IspType
Definition: ctu.h:119
NULL
#define NULL
Definition: coverity.c:32
ff_vvc_pred_mode_plt_flag
int ff_vvc_pred_mode_plt_flag(VVCLocalContext *lc)
Definition: cabac.c:1243
VVCLocalContext
Definition: ctu.h:384
INTRA_LUMA_MPM_FLAG
@ INTRA_LUMA_MPM_FLAG
Definition: cabac.c:56
CU_CHROMA_QP_OFFSET_IDX
@ CU_CHROMA_QP_OFFSET_IDX
Definition: cabac.c:98
H266RawSliceHeader::sh_dep_quant_used_flag
uint8_t sh_dep_quant_used_flag
Definition: cbs_h266.h:824
get_local_sum_ts
static int get_local_sum_ts(const int *level, const int w, const int h, const int xc, const int yc)
Definition: cabac.c:1835
ff_vvc_cu_act_enabled_flag
int ff_vvc_cu_act_enabled_flag(VVCLocalContext *lc)
Definition: cabac.c:1706
ff_vvc_cu_chroma_qp_offset_flag
int ff_vvc_cu_chroma_qp_offset_flag(VVCLocalContext *lc)
Definition: cabac.c:1744
TransformBlock::log2_tb_width
int log2_tb_width
Definition: ctu.h:151
ff_vvc_sbt_horizontal_flag
int ff_vvc_sbt_horizontal_flag(VVCLocalContext *lc)
Definition: cabac.c:2519
ff_vvc_alf_ctb_filter_alt_idx
int ff_vvc_alf_ctb_filter_alt_idx(VVCLocalContext *lc, const int c_idx, const int num_chroma_filters)
Definition: cabac.c:1078
ff_vvc_palette_transpose_flag
bool ff_vvc_palette_transpose_flag(VVCLocalContext *lc)
Definition: cabac.c:1400
sig_coeff_flag_decode
static int sig_coeff_flag_decode(VVCLocalContext *lc, const ResidualCoding *rc, const int xc, const int yc)
Definition: cabac.c:1906
ResidualCoding::last_scan_pos
int last_scan_pos
Definition: cabac.c:803
VVCSPS::bit_depth
uint8_t bit_depth
BitDepth.
Definition: ps.h:69
SPLIT_TT_HOR
@ SPLIT_TT_HOR
Definition: ctu.h:127
Mv::x
int16_t x
horizontal component of motion vector
Definition: hevcdec.h:306
CTB
#define CTB(tab, x, y)
Definition: filter.c:267
ff_vvc_alf_use_aps_flag
int ff_vvc_alf_use_aps_flag(VVCLocalContext *lc)
Definition: cabac.c:1063
PF_BI
@ PF_BI
Definition: hevcdec.h:123
MERGE_IDX
@ MERGE_IDX
Definition: cabac.c:90
ff_vvc_diag_scan_y
const uint8_t ff_vvc_diag_scan_y[5][5][16 *16]
Definition: data.c:152
VVC_CONTEXTS
#define VVC_CONTEXTS
Definition: ctu.h:362
ff_vvc_tu_joint_cbcr_residual_flag
int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, const int tu_cb_coded_flag, const int tu_cr_coded_flag)
Definition: cabac.c:1803
ff_vvc_abs_mvd_minus2
int ff_vvc_abs_mvd_minus2(VVCLocalContext *lc)
Definition: cabac.c:1617
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
SAMPLE_CTB
#define SAMPLE_CTB(tab, x, y)
Definition: hevcdec.h:74
inc
static int inc(int num, int period)
Definition: perlin.c:34
ff_vvc_alf_luma_prev_filter_idx
int ff_vvc_alf_luma_prev_filter_idx(VVCLocalContext *lc)
Definition: cabac.c:1068
ResidualCoding::scan_y_off
const uint8_t * scan_y_off
Definition: cabac.c:790
cabac.h
ff_vvc_pred_mode_ibc_flag
int ff_vvc_pred_mode_ibc_flag(VVCLocalContext *lc, const int is_chroma)
Definition: cabac.c:1274
truncated_binary_decode
static int truncated_binary_decode(VVCLocalContext *lc, const int c_max)
Definition: cabac.c:916
H266RawSliceHeader::sh_reverse_last_sig_coeff_flag
uint8_t sh_reverse_last_sig_coeff_flag
Definition: cbs_h266.h:829
VVCFrameParamSets::pps
const VVCPPS * pps
RefStruct reference.
Definition: ps.h:231
TU_JOINT_CBCR_RESIDUAL_FLAG
@ TU_JOINT_CBCR_RESIDUAL_FLAG
Definition: cabac.c:100
limited_kth_order_egk_decode
static int limited_kth_order_egk_decode(CABACContext *c, const int k, const int max_pre_ext_len, const int trunc_suffix_len)
Definition: cabac.c:953
last_significant_coeff_x_y_decode
static void last_significant_coeff_x_y_decode(ResidualCoding *rc, VVCLocalContext *lc, const int log2_zo_tb_width, const int log2_zo_tb_height)
Definition: cabac.c:2414
ResidualCoding::rem_bins_pass1
int rem_bins_pass1
Definition: cabac.c:781
INTRA_MIP_FLAG
@ INTRA_MIP_FLAG
Definition: cabac.c:52
TransformBlock::tb_height
int tb_height
Definition: ctu.h:150
ff_vvc_intra_luma_mpm_remainder
int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc)
Definition: cabac.c:1356
TransformBlock::ts
uint8_t ts
transform_skip_flag
Definition: ctu.h:145
ff_vvc_intra_bdpcm_chroma_dir_flag
int ff_vvc_intra_bdpcm_chroma_dir_flag(VVCLocalContext *lc)
Definition: cabac.c:1263
ff_vvc_pred_flag
PredFlag ff_vvc_pred_flag(VVCLocalContext *lc, const int is_b)
Definition: cabac.c:1561
height
#define height
Definition: dsp.h:89
shift
static int shift(int a, int b)
Definition: bonk.c:261
ResidualCoding::hist_value
int hist_value
Definition: cabac.c:778
EntryPoint::cc
CABACContext cc
Definition: ctu.h:371
ff_vvc_merge_subblock_idx
int ff_vvc_merge_subblock_idx(VVCLocalContext *lc, const int max_num_subblock_merge_cand)
Definition: cabac.c:1454
get_cabac_bypass
#define get_cabac_bypass
Definition: cabac.h:149
ResidualCoding::coeff_sign_level
int coeff_sign_level[MAX_TB_SIZE *MAX_TB_SIZE]
CoeffSignLevel[][].
Definition: cabac.c:799
ff_vvc_merge_gpm_partition_idx
int ff_vvc_merge_gpm_partition_idx(VVCLocalContext *lc)
Definition: cabac.c:1537
INTRA_BDPCM_LUMA_FLAG
@ INTRA_BDPCM_LUMA_FLAG
Definition: cabac.c:50
init_residual_coding
static void init_residual_coding(const VVCLocalContext *lc, ResidualCoding *rc, const int log2_zo_tb_width, const int log2_zo_tb_height, TransformBlock *tb)
Definition: cabac.c:2078
ff_vvc_sym_mvd_flag
int ff_vvc_sym_mvd_flag(VVCLocalContext *lc)
Definition: cabac.c:1587
VVCLocalContext::ctb_up_flag
uint8_t ctb_up_flag
Definition: ctu.h:386
ff_vvc_end_of_tile_one_bit
int ff_vvc_end_of_tile_one_bit(VVCLocalContext *lc)
Definition: cabac.c:2556
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_vvc_intra_subpartitions_mode_flag
int ff_vvc_intra_subpartitions_mode_flag(VVCLocalContext *lc)
Definition: cabac.c:1326
mtt_split_cu_binary_flag_decode
static int mtt_split_cu_binary_flag_decode(VVCLocalContext *lc, const int mtt_split_cu_vertical_flag, const int mtt_depth)
Definition: cabac.c:1182
CU_CHROMA_QP_OFFSET_FLAG
@ CU_CHROMA_QP_OFFSET_FLAG
Definition: cabac.c:97
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
TU_CB_CODED_FLAG
@ TU_CB_CODED_FLAG
Definition: cabac.c:94
qstate_translate_table
static const uint8_t qstate_translate_table[][2]
Definition: cabac.c:2048
av_zero_extend
#define av_zero_extend
Definition: common.h:151
last_significant_coeff_xy_prefix
static av_always_inline int last_significant_coeff_xy_prefix(VVCLocalContext *lc, const int log2_tb_size, const int log2_zo_tb_size, const int c_idx, const int ctx)
Definition: cabac.c:1758
ff_vvc_sao_band_position_decode
int ff_vvc_sao_band_position_decode(VVCLocalContext *lc)
Definition: cabac.c:1023
PRED_MODE_IBC_FLAG
@ PRED_MODE_IBC_FLAG
Definition: cabac.c:46
TU_CR_CODED_FLAG
@ TU_CR_CODED_FLAG
Definition: cabac.c:95
ResidualCoding::width_in_sbs
int width_in_sbs
Definition: cabac.c:783
ff_vvc_merge_idx
int ff_vvc_merge_idx(VVCLocalContext *lc)
Definition: cabac.c:1522
ff_vvc_merge_subblock_flag
int ff_vvc_merge_subblock_flag(VVCLocalContext *lc)
Definition: cabac.c:1448
ALFParams::ctb_cc_idc
uint8_t ctb_cc_idc[2]
alf_ctb_cc_cb_idc, alf_ctb_cc_cr_idc
Definition: ctu.h:476
get_cabac_terminate
static int av_unused get_cabac_terminate(CABACContext *c)
Definition: cabac_functions.h:187
ff_vvc_split_mode
VVCSplitMode ff_vvc_split_mode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const int cqt_depth, const int mtt_depth, const int ch_type, const VVCAllowedSplit *a)
Definition: cabac.c:1188
H266RawSliceHeader
Definition: cbs_h266.h:771
AMVR_FLAG
@ AMVR_FLAG
Definition: cabac.c:70
COEFF_SIGN_FLAG
@ COEFF_SIGN_FLAG
Definition: cabac.c:107
MODE_INTRA
#define MODE_INTRA
Definition: vp3.c:84
VVCAllowedSplit
Definition: ctu.h:451
SliceContext::nb_eps
int nb_eps
Definition: dec.h:112
CU_AFFINE_TYPE_FLAG
@ CU_AFFINE_TYPE_FLAG
Definition: cabac.c:66
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ResidualCoding
Definition: cabac.c:771
ISP_NO_SPLIT
@ ISP_NO_SPLIT
Definition: ctu.h:120
ff_vvc_diag_scan_x
const uint8_t ff_vvc_diag_scan_x[5][5][16 *16]
Definition: data.c:27
ff_vvc_alf_ctb_flag
int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx)
Definition: cabac.c:1048
H266RawSliceHeader::sh_ts_residual_coding_rice_idx_minus1
uint8_t sh_ts_residual_coding_rice_idx_minus1
Definition: cbs_h266.h:828
ff_vvc_abs_mvd_greater1_flag
int ff_vvc_abs_mvd_greater1_flag(VVCLocalContext *lc)
Definition: cabac.c:1612
ff_vvc_transform_skip_flag
int ff_vvc_transform_skip_flag(VVCLocalContext *lc, const int inc)
Definition: cabac.c:1808
MAX_SUB_BLOCKS
#define MAX_SUB_BLOCKS
Definition: cabac.c:767
av_always_inline
#define av_always_inline
Definition: attributes.h:49
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_vvc_tu_cb_coded_flag
int ff_vvc_tu_cb_coded_flag(VVCLocalContext *lc)
Definition: cabac.c:1682
PF_L0
@ PF_L0
Definition: hevcdec.h:121
VVCLocalContext::prev_tu_cbf_y
int prev_tu_cbf_y
prevTuCbfY;
Definition: ctu.h:413
cabac_functions.h
CodingUnit::x0
int x0
Definition: ctu.h:289
EntryPoint
Definition: ctu.h:363
TransformBlock::coeffs
int * coeffs
Definition: ctu.h:164
len
int len
Definition: vorbis_enc_data.h:426
ResidualCoding::abs_level
int abs_level[MAX_TB_SIZE *MAX_TB_SIZE]
Definition: cabac.c:795
ff_vvc_end_of_subset_one_bit
int ff_vvc_end_of_subset_one_bit(VVCLocalContext *lc)
Definition: cabac.c:2561
ResidualCoding::sig_coeff_flag
int sig_coeff_flag[MAX_TB_SIZE *MAX_TB_SIZE]
Definition: cabac.c:793
fixed_length_decode
static int fixed_length_decode(CABACContext *c, const int len)
Definition: cabac.c:972
init_values
static const uint8_t init_values[4][SYNTAX_ELEMENT_LAST]
Definition: cabac.c:111
log2
#define log2(x)
Definition: libm.h:406
VVCLocalContext::cu
CodingUnit * cu
Definition: ctu.h:429
ff_vvc_sbt_flag
int ff_vvc_sbt_flag(VVCLocalContext *lc)
Definition: cabac.c:2506
ff_vvc_cu_qp_delta_abs
int ff_vvc_cu_qp_delta_abs(VVCLocalContext *lc)
Definition: cabac.c:1711
VVCSPS::max_num_gpm_merge_cand
uint8_t max_num_gpm_merge_cand
MaxNumGpmMergeCand.
Definition: ps.h:79
PRED_MODE_PLT_FLAG
@ PRED_MODE_PLT_FLAG
Definition: cabac.c:48
ResidualCoding::last_significant_coeff_x
int last_significant_coeff_x
Definition: cabac.c:804
ret
ret
Definition: filter_design.txt:187
pred
static const float pred[4]
Definition: siprdata.h:259
ff_vvc_pred_mode_flag
int ff_vvc_pred_mode_flag(VVCLocalContext *lc, const int is_chroma)
Definition: cabac.c:1232
ResidualCoding::last_significant_coeff_y
int last_significant_coeff_y
Definition: cabac.c:805
SPLIT_QT_FLAG
@ SPLIT_QT_FLAG
Definition: cabac.c:41
ff_vvc_alf_luma_fixed_filter_idx
int ff_vvc_alf_luma_fixed_filter_idx(VVCLocalContext *lc)
Definition: cabac.c:1073
H266RawSliceHeader::sh_slice_type
uint8_t sh_slice_type
Definition: cbs_h266.h:780
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
state
static struct @499 state
ff_vvc_mvd_sign_flag
int ff_vvc_mvd_sign_flag(VVCLocalContext *lc)
Definition: cabac.c:1622
CU_SKIP_FLAG
@ CU_SKIP_FLAG
Definition: cabac.c:45
CodingUnit::cb_height
int cb_height
Definition: ctu.h:292
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
ff_vvc_cu_qp_delta_sign_flag
int ff_vvc_cu_qp_delta_sign_flag(VVCLocalContext *lc)
Definition: cabac.c:1739
TransformBlock::log2_tb_height
int log2_tb_height
Definition: ctu.h:152
H266RawSliceHeader::sh_sign_data_hiding_used_flag
uint8_t sh_sign_data_hiding_used_flag
Definition: cbs_h266.h:826
ALF_CTB_CC_CR_IDC
@ ALF_CTB_CC_CR_IDC
Definition: cabac.c:36
suffix
const char * suffix
Definition: checkasm.c:315
CU_ACT_ENABLED_FLAG
@ CU_ACT_ENABLED_FLAG
Definition: cabac.c:49
DUAL_TREE_CHROMA
@ DUAL_TREE_CHROMA
Definition: ctu.h:170
ResidualCoding::nb_sbs
int nb_sbs
Definition: cabac.c:785
INTRA_SUBPARTITIONS_MODE_FLAG
@ INTRA_SUBPARTITIONS_MODE_FLAG
Definition: cabac.c:54
PredMode
PredMode
Definition: hevcdec.h:107
MERGE_SUBBLOCK_IDX
@ MERGE_SUBBLOCK_IDX
Definition: cabac.c:89
mtt_split_cu_vertical_flag_decode
static int mtt_split_cu_vertical_flag_decode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, const int ch_type, const VVCAllowedSplit *a)
Definition: cabac.c:1146
ff_vvc_cclm_mode_idx
int ff_vvc_cclm_mode_idx(VVCLocalContext *lc)
Definition: cabac.c:1366
TransformBlock
Definition: ctu.h:142
PALETTE_TRANSPOSE_FLAG
@ PALETTE_TRANSPOSE_FLAG
Definition: cabac.c:81
VVCSH::slice_qp_y
int8_t slice_qp_y
SliceQpY.
Definition: ps.h:251
CodingUnit::pred_mode
enum PredMode pred_mode
PredMode.
Definition: hevcdec.h:296
INTRA_SUBPARTITIONS_SPLIT_FLAG
@ INTRA_SUBPARTITIONS_SPLIT_FLAG
Definition: cabac.c:55
residual_ts_coding_subblock
static int residual_ts_coding_subblock(VVCLocalContext *lc, ResidualCoding *rc, const int i)
Definition: cabac.c:2122
ff_vvc_sao_type_idx_decode
int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc)
Definition: cabac.c:1013
ALF_CTB_FLAG
@ ALF_CTB_FLAG
Definition: cabac.c:33
ResidualCoding::qstate
int qstate
Definition: cabac.c:802
ff_vvc_cabac_init
int ff_vvc_cabac_init(VVCLocalContext *lc, const int ctu_idx, const int rx, const int ry)
Definition: cabac.c:842
ff_vvc_run_copy_flag
bool ff_vvc_run_copy_flag(VVCLocalContext *lc, const int prev_run_type, const int prev_run_position, const int cur_pos)
Definition: cabac.c:1405
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
PAR_LEVEL_FLAG
@ PAR_LEVEL_FLAG
Definition: cabac.c:105
MMVD_MERGE_FLAG
@ MMVD_MERGE_FLAG
Definition: cabac.c:84
SYM_MVD_FLAG
@ SYM_MVD_FLAG
Definition: cabac.c:67
ALF_USE_APS_FLAG
@ ALF_USE_APS_FLAG
Definition: cabac.c:34
get_local_sum
static int get_local_sum(const int *level, const int w, const int h, const int xc, const int yc, const int hist_value)
Definition: cabac.c:1814
ALFParams
Definition: ctu.h:472
ff_vvc_sao_merge_flag_decode
int ff_vvc_sao_merge_flag_decode(VVCLocalContext *lc)
Definition: cabac.c:1008
Mv
Definition: hevcdec.h:305
ff_vvc_mts_idx
int ff_vvc_mts_idx(VVCLocalContext *lc)
Definition: cabac.c:2541
ff_vvc_general_merge_flag
int ff_vvc_general_merge_flag(VVCLocalContext *lc)
Definition: cabac.c:1432
ResidualCoding::tb
TransformBlock * tb
Definition: cabac.c:773
VVCFrameContext::ps
VVCFrameParamSets ps
Definition: dec.h:126
INTER_PRED_IDC
@ INTER_PRED_IDC
Definition: cabac.c:64
INTRA_BDPCM_CHROMA_DIR_FLAG
@ INTRA_BDPCM_CHROMA_DIR_FLAG
Definition: cabac.c:59
ff_vvc_intra_chroma_pred_mode
int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc)
Definition: cabac.c:1373
ALF_CTB_CC_CB_IDC
@ ALF_CTB_CC_CB_IDC
Definition: cabac.c:35
PredFlag
PredFlag
Definition: hevcdec.h:119
H266RawSliceHeader::sh_num_alf_aps_ids_luma
uint8_t sh_num_alf_aps_ids_luma
Definition: cbs_h266.h:784
SliceContext::sh
VVCSH sh
Definition: dec.h:110
par_level_flag_decode
static int par_level_flag_decode(VVCLocalContext *lc, const int inc)
Definition: cabac.c:1874
get_gtx_flag_inc
static int get_gtx_flag_inc(const ResidualCoding *rc, const int xc, const int yc, const int last)
Definition: cabac.c:1846
ff_vvc_tu_cr_coded_flag
int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag)
Definition: cabac.c:1687
ResidualCoding::last_sub_block
int last_sub_block
Definition: cabac.c:777
ff_vvc_alf_ctb_cc_idc
int ff_vvc_alf_ctb_cc_idc(VVCLocalContext *lc, const int rx, const int ry, const int idx, const int cc_filters_signalled)
Definition: cabac.c:1088
CodingUnit::isp_split_type
enum IspType isp_split_type
IntraSubPartitionsSplitType.
Definition: ctu.h:315
VVCFrameContext
Definition: dec.h:117
ff_vvc_intra_luma_mpm_flag
int ff_vvc_intra_luma_mpm_flag(VVCLocalContext *lc)
Definition: cabac.c:1338
par_level_flag_ts_decode
static int par_level_flag_ts_decode(VVCLocalContext *lc)
Definition: cabac.c:1879
ALFParams::ctb_flag
uint8_t ctb_flag[3]
alf_ctb_flag[]
Definition: ctu.h:473
ff_vvc_sao_offset_abs_decode
int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc)
Definition: cabac.c:1028
IS_I
#define IS_I(rsh)
Definition: ps.h:38
ff_vvc_mmvd_cand_flag
int ff_vvc_mmvd_cand_flag(VVCLocalContext *lc)
Definition: cabac.c:1475
ALF_CTB_FILTER_ALT_IDX
@ ALF_CTB_FILTER_ALT_IDX
Definition: cabac.c:37
ff_vvc_amvr_shift
int ff_vvc_amvr_shift(VVCLocalContext *lc, const int inter_affine_flag, const PredMode pred_mode, const int has_amvr_flag)
Definition: cabac.c:1648
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
skip_bytes
static const av_unused uint8_t * skip_bytes(CABACContext *c, int n)
Skip n bytes and reset the decoder.
Definition: cabac_functions.h:203
MAX_SUB_BLOCK_SIZE
#define MAX_SUB_BLOCK_SIZE
Definition: cabac.c:768
ff_vvc_intra_bdpcm_luma_dir_flag
int ff_vvc_intra_bdpcm_luma_dir_flag(VVCLocalContext *lc)
Definition: cabac.c:1253
ff_vvc_intra_bdpcm_luma_flag
int ff_vvc_intra_bdpcm_luma_flag(VVCLocalContext *lc)
Definition: cabac.c:1248
h
h
Definition: vp9dsp_template.c:2070
ctu.h
amvr_precision_idx
static int amvr_precision_idx(VVCLocalContext *lc, const int inc, const int c_max)
Definition: cabac.c:1637
coeff_sign_flag_decode
static int coeff_sign_flag_decode(VVCLocalContext *lc)
Definition: cabac.c:2001
derive_last_scan_pos
static void derive_last_scan_pos(ResidualCoding *rc)
Definition: cabac.c:2398
VVCLocalContext::ep
EntryPoint * ep
Definition: ctu.h:447
CABAC_BITS
#define CABAC_BITS
Definition: cabac.h:38
ff_vvc_palette_predictor_run
int ff_vvc_palette_predictor_run(VVCLocalContext *lc)
Definition: cabac.c:1380
abs_decode
static int abs_decode(VVCLocalContext *lc, const int c_rice_param)
Definition: cabac.c:1955
ff_vvc_ep_init_stat_coeff
void ff_vvc_ep_init_stat_coeff(EntryPoint *ep, const int bit_depth, const int persistent_rice_adaptation_enabled_flag)
Definition: ctu.c:2873
ff_vvc_non_inter_flag
int ff_vvc_non_inter_flag(VVCLocalContext *lc, const int x0, const int y0, const int ch_type)
Definition: cabac.c:1222
ff_vvc_cclm_mode_flag
int ff_vvc_cclm_mode_flag(VVCLocalContext *lc)
Definition: cabac.c:1361
CCLM_MODE_FLAG
@ CCLM_MODE_FLAG
Definition: cabac.c:60
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
CABACContext
Definition: cabac.h:41
MMVD_CAND_FLAG
@ MMVD_CAND_FLAG
Definition: cabac.c:85
get_mip_inc
static av_always_inline uint8_t get_mip_inc(VVCLocalContext *lc, const uint8_t *ctx)
Definition: cabac.c:1287
ff_vvc_palette_escape_val
int ff_vvc_palette_escape_val(VVCLocalContext *lc)
Definition: cabac.c:1427
VVCLocalContext::ctb_left_flag
uint8_t ctb_left_flag
Definition: ctu.h:385
MVP_LX_FLAG
@ MVP_LX_FLAG
Definition: cabac.c:69
shifts
static const uint8_t shifts[2][12]
Definition: camellia.c:178
CodingUnit::y0
int y0
Definition: ctu.h:290
ff_vvc_intra_bdpcm_chroma_flag
int ff_vvc_intra_bdpcm_chroma_flag(VVCLocalContext *lc)
Definition: cabac.c:1258
ff_vvc_copy_above_palette_indices_flag
bool ff_vvc_copy_above_palette_indices_flag(VVCLocalContext *lc)
Definition: cabac.c:1417
abs_level_gtx_flag_decode
static int abs_level_gtx_flag_decode(VVCLocalContext *lc, const int inc)
Definition: cabac.c:1869