Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * VVC CABAC decoder | ||
3 | * | ||
4 | * Copyright (C) 2021 Nuo Mi | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | #include "libavcodec/cabac_functions.h" | ||
23 | |||
24 | #include "cabac.h" | ||
25 | #include "ctu.h" | ||
26 | #include "data.h" | ||
27 | |||
28 | #define CABAC_MAX_BIN 31 | ||
29 | |||
30 | #define CNU 35 | ||
31 | |||
32 | enum SyntaxElement { | ||
33 | ALF_CTB_FLAG = 0, | ||
34 | ALF_USE_APS_FLAG = ALF_CTB_FLAG + 9, | ||
35 | ALF_CTB_CC_CB_IDC, | ||
36 | ALF_CTB_CC_CR_IDC = ALF_CTB_CC_CB_IDC + 3, | ||
37 | ALF_CTB_FILTER_ALT_IDX = ALF_CTB_CC_CR_IDC + 3, | ||
38 | SAO_MERGE_FLAG = ALF_CTB_FILTER_ALT_IDX + 2, | ||
39 | SAO_TYPE_IDX, | ||
40 | SPLIT_CU_FLAG, | ||
41 | SPLIT_QT_FLAG = SPLIT_CU_FLAG + 9, | ||
42 | MTT_SPLIT_CU_VERTICAL_FLAG = SPLIT_QT_FLAG + 6, | ||
43 | MTT_SPLIT_CU_BINARY_FLAG = MTT_SPLIT_CU_VERTICAL_FLAG + 5, | ||
44 | NON_INTER_FLAG = MTT_SPLIT_CU_BINARY_FLAG + 4, | ||
45 | CU_SKIP_FLAG = NON_INTER_FLAG + 2, | ||
46 | PRED_MODE_IBC_FLAG = CU_SKIP_FLAG + 3, | ||
47 | PRED_MODE_FLAG = PRED_MODE_IBC_FLAG + 3, | ||
48 | PRED_MODE_PLT_FLAG = PRED_MODE_FLAG + 2, | ||
49 | CU_ACT_ENABLED_FLAG, | ||
50 | INTRA_BDPCM_LUMA_FLAG, | ||
51 | INTRA_BDPCM_LUMA_DIR_FLAG, | ||
52 | INTRA_MIP_FLAG, | ||
53 | INTRA_LUMA_REF_IDX = INTRA_MIP_FLAG + 4, | ||
54 | INTRA_SUBPARTITIONS_MODE_FLAG = INTRA_LUMA_REF_IDX + 2, | ||
55 | INTRA_SUBPARTITIONS_SPLIT_FLAG, | ||
56 | INTRA_LUMA_MPM_FLAG, | ||
57 | INTRA_LUMA_NOT_PLANAR_FLAG, | ||
58 | INTRA_BDPCM_CHROMA_FLAG = INTRA_LUMA_NOT_PLANAR_FLAG + 2, | ||
59 | INTRA_BDPCM_CHROMA_DIR_FLAG, | ||
60 | CCLM_MODE_FLAG, | ||
61 | CCLM_MODE_IDX, | ||
62 | INTRA_CHROMA_PRED_MODE, | ||
63 | GENERAL_MERGE_FLAG, | ||
64 | INTER_PRED_IDC, | ||
65 | INTER_AFFINE_FLAG = INTER_PRED_IDC + 6, | ||
66 | CU_AFFINE_TYPE_FLAG = INTER_AFFINE_FLAG + 3, | ||
67 | SYM_MVD_FLAG, | ||
68 | REF_IDX_LX, | ||
69 | MVP_LX_FLAG = REF_IDX_LX + 2, | ||
70 | AMVR_FLAG, | ||
71 | AMVR_PRECISION_IDX = AMVR_FLAG + 2, | ||
72 | BCW_IDX = AMVR_PRECISION_IDX + 3, | ||
73 | CU_CODED_FLAG, | ||
74 | CU_SBT_FLAG, | ||
75 | CU_SBT_QUAD_FLAG = CU_SBT_FLAG + 2, | ||
76 | CU_SBT_HORIZONTAL_FLAG, | ||
77 | CU_SBT_POS_FLAG = CU_SBT_HORIZONTAL_FLAG + 3, | ||
78 | LFNST_IDX, | ||
79 | MTS_IDX = LFNST_IDX + 3, | ||
80 | COPY_ABOVE_PALETTE_INDICES_FLAG = MTS_IDX + 4, | ||
81 | PALETTE_TRANSPOSE_FLAG, | ||
82 | RUN_COPY_FLAG, | ||
83 | REGULAR_MERGE_FLAG = RUN_COPY_FLAG + 8, | ||
84 | MMVD_MERGE_FLAG = REGULAR_MERGE_FLAG + 2, | ||
85 | MMVD_CAND_FLAG, | ||
86 | MMVD_DISTANCE_IDX, | ||
87 | CIIP_FLAG, | ||
88 | MERGE_SUBBLOCK_FLAG, | ||
89 | MERGE_SUBBLOCK_IDX = MERGE_SUBBLOCK_FLAG + 3, | ||
90 | MERGE_IDX, | ||
91 | ABS_MVD_GREATER0_FLAG, | ||
92 | ABS_MVD_GREATER1_FLAG, | ||
93 | TU_Y_CODED_FLAG, | ||
94 | TU_CB_CODED_FLAG = TU_Y_CODED_FLAG + 4, | ||
95 | TU_CR_CODED_FLAG = TU_CB_CODED_FLAG + 2, | ||
96 | CU_QP_DELTA_ABS = TU_CR_CODED_FLAG + 3, | ||
97 | CU_CHROMA_QP_OFFSET_FLAG = CU_QP_DELTA_ABS + 2, | ||
98 | CU_CHROMA_QP_OFFSET_IDX, | ||
99 | TRANSFORM_SKIP_FLAG, | ||
100 | TU_JOINT_CBCR_RESIDUAL_FLAG = TRANSFORM_SKIP_FLAG + 2, | ||
101 | LAST_SIG_COEFF_X_PREFIX = TU_JOINT_CBCR_RESIDUAL_FLAG + 3, | ||
102 | LAST_SIG_COEFF_Y_PREFIX = LAST_SIG_COEFF_X_PREFIX +23, | ||
103 | SB_CODED_FLAG = LAST_SIG_COEFF_Y_PREFIX +23, | ||
104 | SIG_COEFF_FLAG = SB_CODED_FLAG + 7, | ||
105 | PAR_LEVEL_FLAG = SIG_COEFF_FLAG +63, | ||
106 | ABS_LEVEL_GTX_FLAG = PAR_LEVEL_FLAG +33, | ||
107 | COEFF_SIGN_FLAG = ABS_LEVEL_GTX_FLAG +72, | ||
108 | SYNTAX_ELEMENT_LAST = COEFF_SIGN_FLAG + 6, | ||
109 | }; | ||
110 | |||
111 | static const uint8_t init_values[4][SYNTAX_ELEMENT_LAST] = { | ||
112 | { | ||
113 | //alf_ctb_flag | ||
114 | 62, 39, 39, 54, 39, 39, 31, 39, 39, | ||
115 | //alf_use_aps_flag | ||
116 | 46, | ||
117 | //alf_ctb_cc_cb_idc | ||
118 | 18, 30, 31, | ||
119 | //alf_ctb_cc_cr_idc | ||
120 | 18, 30, 31, | ||
121 | //alf_ctb_filter_alt_idx | ||
122 | 11, 11, | ||
123 | //sao_merge_left_flag and sao_merge_up_flag | ||
124 | 60, | ||
125 | //sao_type_idx_luma and sao_type_idx_chroma | ||
126 | 13, | ||
127 | //split_cu_flag | ||
128 | 19, 28, 38, 27, 29, 38, 20, 30, 31, | ||
129 | //split_qt_flag | ||
130 | 27, 6, 15, 25, 19, 37, | ||
131 | //mtt_split_cu_vertical_flag | ||
132 | 43, 42, 29, 27, 44, | ||
133 | //mtt_split_cu_binary_flag | ||
134 | 36, 45, 36, 45, | ||
135 | //non_inter_flag | ||
136 | CNU, CNU, | ||
137 | //cu_skip_flag | ||
138 | 0, 26, 28, | ||
139 | //pred_mode_ibc_flag | ||
140 | 17, 42, 36, | ||
141 | //pred_mode_flag | ||
142 | CNU, CNU, | ||
143 | //pred_mode_plt_flag | ||
144 | 25, | ||
145 | //cu_act_enabled_flag | ||
146 | 52, | ||
147 | //intra_bdpcm_luma_flag | ||
148 | 19, | ||
149 | //intra_bdpcm_luma_dir_flag | ||
150 | 35, | ||
151 | //intra_mip_flag | ||
152 | 33, 49, 50, 25, | ||
153 | //intra_luma_ref_idx | ||
154 | 25, 60, | ||
155 | //intra_subpartitions_mode_flag | ||
156 | 33, | ||
157 | //intra_subpartitions_split_flag | ||
158 | 43, | ||
159 | //intra_luma_mpm_flag | ||
160 | 45, | ||
161 | //intra_luma_not_planar_flag | ||
162 | 13, 28, | ||
163 | //intra_bdpcm_chroma_flag | ||
164 | 1, | ||
165 | //intra_bdpcm_chroma_dir_flag | ||
166 | 27, | ||
167 | //cclm_mode_flag | ||
168 | 59, | ||
169 | //cclm_mode_idx | ||
170 | 27, | ||
171 | //intra_chroma_pred_mode | ||
172 | 34, | ||
173 | //general_merge_flag | ||
174 | 26, | ||
175 | //inter_pred_idc | ||
176 | CNU, CNU, CNU, CNU, CNU, CNU, | ||
177 | //inter_affine_flag | ||
178 | CNU, CNU, CNU, | ||
179 | //cu_affine_type_flag | ||
180 | CNU, | ||
181 | //sym_mvd_flag | ||
182 | CNU, | ||
183 | //ref_idx_l0 and ref_idx_l1 | ||
184 | CNU, CNU, | ||
185 | //mvp_l0_flag and mvp_l1_flag | ||
186 | 42, | ||
187 | //amvr_flag | ||
188 | CNU, CNU, | ||
189 | //amvr_precision_idx | ||
190 | 35, 34, 35, | ||
191 | //bcw_idx | ||
192 | CNU, | ||
193 | //cu_coded_flag | ||
194 | 6, | ||
195 | //cu_sbt_flag | ||
196 | CNU, CNU, | ||
197 | //cu_sbt_quad_flag | ||
198 | CNU, | ||
199 | //cu_sbt_horizontal_flag | ||
200 | CNU, CNU, CNU, | ||
201 | //cu_sbt_pos_flag | ||
202 | CNU, | ||
203 | //lfnst_idx | ||
204 | 28, 52, 42, | ||
205 | //mts_idx | ||
206 | 29, 0, 28, 0, | ||
207 | //copy_above_palette_indices_flag | ||
208 | 42, | ||
209 | //palette_transpose_flag | ||
210 | 42, | ||
211 | //run_copy_flag | ||
212 | 50, 37, 45, 30, 46, 45, 38, 46, | ||
213 | //regular_merge_flag | ||
214 | CNU, CNU, | ||
215 | //mmvd_merge_flag | ||
216 | CNU, | ||
217 | //mmvd_cand_flag | ||
218 | CNU, | ||
219 | //mmvd_distance_idx | ||
220 | CNU, | ||
221 | //ciip_flag | ||
222 | CNU, | ||
223 | //merge_subblock_flag | ||
224 | CNU, CNU, CNU, | ||
225 | //merge_subblock_idx | ||
226 | CNU, | ||
227 | //merge_idx, merge_gpm_idx0, and merge_gpm_idx1 | ||
228 | 34, | ||
229 | //abs_mvd_greater0_flag | ||
230 | 14, | ||
231 | //abs_mvd_greater1_flag | ||
232 | 45, | ||
233 | //tu_y_coded_flag | ||
234 | 15, 12, 5, 7, | ||
235 | //tu_cb_coded_flag | ||
236 | 12, 21, | ||
237 | //tu_cr_coded_flag | ||
238 | 33, 28, 36, | ||
239 | //cu_qp_delta_abs | ||
240 | CNU, CNU, | ||
241 | //cu_chroma_qp_offset_flag | ||
242 | CNU, | ||
243 | //cu_chroma_qp_offset_idx | ||
244 | CNU, | ||
245 | //transform_skip_flag | ||
246 | 25, 9, | ||
247 | //tu_joint_cbcr_residual_flag | ||
248 | 12, 21, 35, | ||
249 | //last_sig_coeff_x_prefix | ||
250 | 13, 5, 4, 21, 14, 4, 6, 14, 21, 11, 14, 7, 14, 5, 11, 21, | ||
251 | 30, 22, 13, 42, 12, 4, 3, | ||
252 | //last_sig_coeff_y_prefix | ||
253 | 13, 5, 4, 6, 13, 11, 14, 6, 5, 3, 14, 22, 6, 4, 3, 6, | ||
254 | 22, 29, 20, 34, 12, 4, 3, | ||
255 | //sb_coded_flag | ||
256 | 18, 31, 25, 15, 18, 20, 38, | ||
257 | //sig_coeff_flag | ||
258 | 25, 19, 28, 14, 25, 20, 29, 30, 19, 37, 30, 38, 11, 38, 46, 54, | ||
259 | 27, 39, 39, 39, 44, 39, 39, 39, 18, 39, 39, 39, 27, 39, 39, 39, | ||
260 | 0, 39, 39, 39, 25, 27, 28, 37, 34, 53, 53, 46, 19, 46, 38, 39, | ||
261 | 52, 39, 39, 39, 11, 39, 39, 39, 19, 39, 39, 39, 25, 28, 38, | ||
262 | //par_level_flag | ||
263 | 33, 25, 18, 26, 34, 27, 25, 26, 19, 42, 35, 33, 19, 27, 35, 35, | ||
264 | 34, 42, 20, 43, 20, 33, 25, 26, 42, 19, 27, 26, 50, 35, 20, 43, | ||
265 | 11, | ||
266 | //abs_level_gtx_flag | ||
267 | 25, 25, 11, 27, 20, 21, 33, 12, 28, 21, 22, 34, 28, 29, 29, 30, | ||
268 | 36, 29, 45, 30, 23, 40, 33, 27, 28, 21, 37, 36, 37, 45, 38, 46, | ||
269 | 25, 1, 40, 25, 33, 11, 17, 25, 25, 18, 4, 17, 33, 26, 19, 13, | ||
270 | 33, 19, 20, 28, 22, 40, 9, 25, 18, 26, 35, 25, 26, 35, 28, 37, | ||
271 | 11, 5, 5, 14, 10, 3, 3, 3, | ||
272 | //coeff_sign_flag | ||
273 | 12, 17, 46, 28, 25, 46, | ||
274 | }, | ||
275 | { | ||
276 | //alf_ctb_flag | ||
277 | 13, 23, 46, 4, 61, 54, 19, 46, 54, | ||
278 | //alf_use_aps_flag | ||
279 | 46, | ||
280 | //alf_ctb_cc_cb_idc | ||
281 | 18, 21, 38, | ||
282 | //alf_ctb_cc_cr_idc | ||
283 | 18, 21, 38, | ||
284 | //alf_ctb_filter_alt_idx | ||
285 | 20, 12, | ||
286 | //sao_merge_left_flag and sao_merge_up_flag | ||
287 | 60, | ||
288 | //sao_type_idx_luma and sao_type_idx_chroma | ||
289 | 5, | ||
290 | //split_cu_flag | ||
291 | 11, 35, 53, 12, 6, 30, 13, 15, 31, | ||
292 | //split_qt_flag | ||
293 | 20, 14, 23, 18, 19, 6, | ||
294 | //mtt_split_cu_vertical_flag | ||
295 | 43, 35, 37, 34, 52, | ||
296 | //mtt_split_cu_binary_flag | ||
297 | 43, 37, 21, 22, | ||
298 | //non_inter_flag | ||
299 | 25, 12, | ||
300 | //cu_skip_flag | ||
301 | 57, 59, 45, | ||
302 | //pred_mode_ibc_flag | ||
303 | 0, 57, 44, | ||
304 | //pred_mode_flag | ||
305 | 40, 35, | ||
306 | //pred_mode_plt_flag | ||
307 | 0, | ||
308 | //cu_act_enabled_flag | ||
309 | 46, | ||
310 | //intra_bdpcm_luma_flag | ||
311 | 40, | ||
312 | //intra_bdpcm_luma_dir_flag | ||
313 | 36, | ||
314 | //intra_mip_flag | ||
315 | 41, 57, 58, 26, | ||
316 | //intra_luma_ref_idx | ||
317 | 25, 58, | ||
318 | //intra_subpartitions_mode_flag | ||
319 | 33, | ||
320 | //intra_subpartitions_split_flag | ||
321 | 36, | ||
322 | //intra_luma_mpm_flag | ||
323 | 36, | ||
324 | //intra_luma_not_planar_flag | ||
325 | 12, 20, | ||
326 | //intra_bdpcm_chroma_flag | ||
327 | 0, | ||
328 | //intra_bdpcm_chroma_dir_flag | ||
329 | 13, | ||
330 | //cclm_mode_flag | ||
331 | 34, | ||
332 | //cclm_mode_idx | ||
333 | 27, | ||
334 | //intra_chroma_pred_mode | ||
335 | 25, | ||
336 | //general_merge_flag | ||
337 | 21, | ||
338 | //inter_pred_idc | ||
339 | 7, 6, 5, 12, 4, 40, | ||
340 | //inter_affine_flag | ||
341 | 12, 13, 14, | ||
342 | //cu_affine_type_flag | ||
343 | 35, | ||
344 | //sym_mvd_flag | ||
345 | 28, | ||
346 | //ref_idx_l0 and ref_idx_l1 | ||
347 | 20, 35, | ||
348 | //mvp_l0_flag and mvp_l1_flag | ||
349 | 34, | ||
350 | //amvr_flag | ||
351 | 59, 58, | ||
352 | //amvr_precision_idx | ||
353 | 60, 48, 60, | ||
354 | //bcw_idx | ||
355 | 4, | ||
356 | //cu_coded_flag | ||
357 | 5, | ||
358 | //cu_sbt_flag | ||
359 | 56, 57, | ||
360 | //cu_sbt_quad_flag | ||
361 | 42, | ||
362 | //cu_sbt_horizontal_flag | ||
363 | 20, 43, 12, | ||
364 | //cu_sbt_pos_flag | ||
365 | 28, | ||
366 | //lfnst_idx | ||
367 | 37, 45, 27, | ||
368 | //mts_idx | ||
369 | 45, 40, 27, 0, | ||
370 | //copy_above_palette_indices_flag | ||
371 | 59, | ||
372 | //palette_transpose_flag | ||
373 | 42, | ||
374 | //run_copy_flag | ||
375 | 51, 30, 30, 38, 23, 38, 53, 46, | ||
376 | //regular_merge_flag | ||
377 | 38, 7, | ||
378 | //mmvd_merge_flag | ||
379 | 26, | ||
380 | //mmvd_cand_flag | ||
381 | 43, | ||
382 | //mmvd_distance_idx | ||
383 | 60, | ||
384 | //ciip_flag | ||
385 | 57, | ||
386 | //merge_subblock_flag | ||
387 | 48, 57, 44, | ||
388 | //merge_subblock_idx | ||
389 | 5, | ||
390 | //merge_idx, merge_gpm_idx0, and merge_gpm_idx1 | ||
391 | 20, | ||
392 | //abs_mvd_greater0_flag | ||
393 | 44, | ||
394 | //abs_mvd_greater1_flag | ||
395 | 43, | ||
396 | //tu_y_coded_flag | ||
397 | 23, 5, 20, 7, | ||
398 | //tu_cb_coded_flag | ||
399 | 25, 28, | ||
400 | //tu_cr_coded_flag | ||
401 | 25, 29, 45, | ||
402 | //cu_qp_delta_abs | ||
403 | CNU, CNU, | ||
404 | //cu_chroma_qp_offset_flag | ||
405 | CNU, | ||
406 | //cu_chroma_qp_offset_idx | ||
407 | CNU, | ||
408 | //transform_skip_flag | ||
409 | 25, 9, | ||
410 | //tu_joint_cbcr_residual_flag | ||
411 | 27, 36, 45, | ||
412 | //last_sig_coeff_x_prefix | ||
413 | 6, 13, 12, 6, 6, 12, 14, 14, 13, 12, 29, 7, 6, 13, 36, 28, | ||
414 | 14, 13, 5, 26, 12, 4, 18, | ||
415 | //last_sig_coeff_y_prefix | ||
416 | 5, 5, 12, 6, 6, 4, 6, 14, 5, 12, 14, 7, 13, 5, 13, 21, | ||
417 | 14, 20, 12, 34, 11, 4, 18, | ||
418 | //sb_coded_flag | ||
419 | 25, 30, 25, 45, 18, 12, 29, | ||
420 | //sig_coeff_flag | ||
421 | 17, 41, 42, 29, 25, 49, 43, 37, 33, 58, 51, 30, 19, 38, 38, 46, | ||
422 | 34, 54, 54, 39, 6, 39, 39, 39, 19, 39, 54, 39, 19, 39, 39, 39, | ||
423 | 56, 39, 39, 39, 17, 34, 35, 21, 41, 59, 60, 38, 35, 45, 53, 54, | ||
424 | 44, 39, 39, 39, 34, 38, 62, 39, 26, 39, 39, 39, 40, 35, 44, | ||
425 | //par_level_flag | ||
426 | 18, 17, 33, 18, 26, 42, 25, 33, 26, 42, 27, 25, 34, 42, 42, 35, | ||
427 | 26, 27, 42, 20, 20, 25, 25, 26, 11, 19, 27, 33, 42, 35, 35, 43, | ||
428 | 3, | ||
429 | //abs_level_gtx_flag | ||
430 | 0, 17, 26, 19, 35, 21, 25, 34, 20, 28, 29, 33, 27, 28, 29, 22, | ||
431 | 34, 28, 44, 37, 38, 0, 25, 19, 20, 13, 14, 57, 44, 30, 30, 23, | ||
432 | 17, 0, 1, 17, 25, 18, 0, 9, 25, 33, 34, 9, 25, 18, 26, 20, | ||
433 | 25, 18, 19, 27, 29, 17, 9, 25, 10, 18, 4, 17, 33, 19, 20, 29, | ||
434 | 18, 11, 4, 28, 2, 10, 3, 3, | ||
435 | //coeff_sign_flag | ||
436 | 5, 10, 53, 43, 25, 46, | ||
437 | }, | ||
438 | { | ||
439 | //alf_ctb_flag | ||
440 | 33, 52, 46, 25, 61, 54, 25, 61, 54, | ||
441 | //alf_use_aps_flag | ||
442 | 46, | ||
443 | //alf_ctb_cc_cb_idc | ||
444 | 25, 35, 38, | ||
445 | //alf_ctb_cc_cr_idc | ||
446 | 25, 28, 38, | ||
447 | //alf_ctb_filter_alt_idx | ||
448 | 11, 26, | ||
449 | //sao_merge_left_flag and sao_merge_up_flag | ||
450 | 2, | ||
451 | //sao_type_idx_luma and sao_type_idx_chroma | ||
452 | 2, | ||
453 | //split_cu_flag | ||
454 | 18, 27, 15, 18, 28, 45, 26, 7, 23, | ||
455 | //split_qt_flag | ||
456 | 26, 36, 38, 18, 34, 21, | ||
457 | //mtt_split_cu_vertical_flag | ||
458 | 43, 42, 37, 42, 44, | ||
459 | //mtt_split_cu_binary_flag | ||
460 | 28, 29, 28, 29, | ||
461 | //non_inter_flag | ||
462 | 25, 20, | ||
463 | //cu_skip_flag | ||
464 | 57, 60, 46, | ||
465 | //pred_mode_ibc_flag | ||
466 | 0, 43, 45, | ||
467 | //pred_mode_flag | ||
468 | 40, 35, | ||
469 | //pred_mode_plt_flag | ||
470 | 17, | ||
471 | //cu_act_enabled_flag | ||
472 | 46, | ||
473 | //intra_bdpcm_luma_flag | ||
474 | 19, | ||
475 | //intra_bdpcm_luma_dir_flag | ||
476 | 21, | ||
477 | //intra_mip_flag | ||
478 | 56, 57, 50, 26, | ||
479 | //intra_luma_ref_idx | ||
480 | 25, 59, | ||
481 | //intra_subpartitions_mode_flag | ||
482 | 33, | ||
483 | //intra_subpartitions_split_flag | ||
484 | 43, | ||
485 | //intra_luma_mpm_flag | ||
486 | 44, | ||
487 | //intra_luma_not_planar_flag | ||
488 | 13, 6, | ||
489 | //intra_bdpcm_chroma_flag | ||
490 | 0, | ||
491 | //intra_bdpcm_chroma_dir_flag | ||
492 | 28, | ||
493 | //cclm_mode_flag | ||
494 | 26, | ||
495 | //cclm_mode_idx | ||
496 | 27, | ||
497 | //intra_chroma_pred_mode | ||
498 | 25, | ||
499 | //general_merge_flag | ||
500 | 6, | ||
501 | //inter_pred_idc | ||
502 | 14, 13, 5, 4, 3, 40, | ||
503 | //inter_affine_flag | ||
504 | 19, 13, 6, | ||
505 | //cu_affine_type_flag | ||
506 | 35, | ||
507 | //sym_mvd_flag | ||
508 | 28, | ||
509 | //ref_idx_l0 and ref_idx_l1 | ||
510 | 5, 35, | ||
511 | //mvp_l0_flag and mvp_l1_flag | ||
512 | 34, | ||
513 | //amvr_flag | ||
514 | 59, 50, | ||
515 | //amvr_precision_idx | ||
516 | 38, 26, 60, | ||
517 | //bcw_idx | ||
518 | 5, | ||
519 | //cu_coded_flag | ||
520 | 12, | ||
521 | //cu_sbt_flag | ||
522 | 41, 57, | ||
523 | //cu_sbt_quad_flag | ||
524 | 42, | ||
525 | //cu_sbt_horizontal_flag | ||
526 | 35, 51, 27, | ||
527 | //cu_sbt_pos_flag | ||
528 | 28, | ||
529 | //lfnst_idx | ||
530 | 52, 37, 27, | ||
531 | //mts_idx | ||
532 | 45, 25, 27, 0, | ||
533 | //copy_above_palette_indices_flag | ||
534 | 50, | ||
535 | //palette_transpose_flag | ||
536 | 35, | ||
537 | //run_copy_flag | ||
538 | 58, 45, 45, 30, 38, 45, 38, 46, | ||
539 | //regular_merge_flag | ||
540 | 46, 15, | ||
541 | //mmvd_merge_flag | ||
542 | 25, | ||
543 | //mmvd_cand_flag | ||
544 | 43, | ||
545 | //mmvd_distance_idx | ||
546 | 59, | ||
547 | //ciip_flag | ||
548 | 57, | ||
549 | //merge_subblock_flag | ||
550 | 25, 58, 45, | ||
551 | //merge_subblock_idx | ||
552 | 4, | ||
553 | //merge_idx, merge_gpm_idx0, and merge_gpm_idx1 | ||
554 | 18, | ||
555 | //abs_mvd_greater0_flag | ||
556 | 51, | ||
557 | //abs_mvd_greater1_flag | ||
558 | 36, | ||
559 | //tu_y_coded_flag | ||
560 | 15, 6, 5, 14, | ||
561 | //tu_cb_coded_flag | ||
562 | 25, 37, | ||
563 | //tu_cr_coded_flag | ||
564 | 9, 36, 45, | ||
565 | //cu_qp_delta_abs | ||
566 | CNU, CNU, | ||
567 | //cu_chroma_qp_offset_flag | ||
568 | CNU, | ||
569 | //cu_chroma_qp_offset_idx | ||
570 | CNU, | ||
571 | //transform_skip_flag | ||
572 | 25, 17, | ||
573 | //tu_joint_cbcr_residual_flag | ||
574 | 42, 43, 52, | ||
575 | //last_sig_coeff_x_prefix | ||
576 | 6, 6, 12, 14, 6, 4, 14, 7, 6, 4, 29, 7, 6, 6, 12, 28, | ||
577 | 7, 13, 13, 35, 19, 5, 4, | ||
578 | //last_sig_coeff_y_prefix | ||
579 | 5, 5, 20, 13, 13, 19, 21, 6, 12, 12, 14, 14, 5, 4, 12, 13, | ||
580 | 7, 13, 12, 41, 11, 5, 27, | ||
581 | //sb_coded_flag | ||
582 | 25, 45, 25, 14, 18, 35, 45, | ||
583 | //sig_coeff_flag | ||
584 | 17, 41, 49, 36, 1, 49, 50, 37, 48, 51, 58, 45, 26, 45, 53, 46, | ||
585 | 49, 54, 61, 39, 35, 39, 39, 39, 19, 54, 39, 39, 50, 39, 39, 39, | ||
586 | 0, 39, 39, 39, 9, 49, 50, 36, 48, 59, 59, 38, 34, 45, 38, 31, | ||
587 | 58, 39, 39, 39, 34, 38, 54, 39, 41, 39, 39, 39, 25, 50, 37, | ||
588 | //par_level_flag | ||
589 | 33, 40, 25, 41, 26, 42, 25, 33, 26, 34, 27, 25, 41, 42, 42, 35, | ||
590 | 33, 27, 35, 42, 43, 33, 25, 26, 34, 19, 27, 33, 42, 43, 35, 43, | ||
591 | 11, | ||
592 | //abs_level_gtx_flag | ||
593 | 0, 0, 33, 34, 35, 21, 25, 34, 35, 28, 29, 40, 42, 43, 29, 30, | ||
594 | 49, 36, 37, 45, 38, 0, 40, 34, 43, 36, 37, 57, 52, 45, 38, 46, | ||
595 | 25, 0, 0, 17, 25, 26, 0, 9, 25, 33, 19, 0, 25, 33, 26, 20, | ||
596 | 25, 33, 27, 35, 22, 25, 1, 25, 33, 26, 12, 25, 33, 27, 28, 37, | ||
597 | 19, 11, 4, 6, 3, 4, 4, 5, | ||
598 | //coeff_sign_flag | ||
599 | 35, 25, 46, 28, 33, 38, | ||
600 | }, | ||
601 | //shiftIdx | ||
602 | { | ||
603 | //alf_ctb_flag | ||
604 | 0, 0, 0, 4, 0, 0, 1, 0, 0, | ||
605 | //alf_use_aps_flag | ||
606 | 0, | ||
607 | //alf_ctb_cc_cb_idc | ||
608 | 4, 1, 4, | ||
609 | //alf_ctb_cc_cr_idc | ||
610 | 4, 1, 4, | ||
611 | //alf_ctb_filter_alt_idx | ||
612 | 0, 0, | ||
613 | //sao_merge_left_flag and sao_merge_up_flag | ||
614 | 0, | ||
615 | //sao_type_idx_luma and sao_type_idx_chroma | ||
616 | 4, | ||
617 | //split_cu_flag | ||
618 | 12, 13, 8, 8, 13, 12, 5, 9, 9, | ||
619 | //split_qt_flag | ||
620 | 0, 8, 8, 12, 12, 8, | ||
621 | //mtt_split_cu_vertical_flag | ||
622 | 9, 8, 9, 8, 5, | ||
623 | //mtt_split_cu_binary_flag | ||
624 | 12, 13, 12, 13, | ||
625 | //non_inter_flag | ||
626 | 1, 0, | ||
627 | //cu_skip_flag | ||
628 | 5, 4, 8, | ||
629 | //pred_mode_ibc_flag | ||
630 | 1, 5, 8, | ||
631 | //pred_mode_flag | ||
632 | 5, 1, | ||
633 | //pred_mode_plt_flag | ||
634 | 1, | ||
635 | //cu_act_enabled_flag | ||
636 | 1, | ||
637 | //intra_bdpcm_luma_flag | ||
638 | 1, | ||
639 | //intra_bdpcm_luma_dir_flag | ||
640 | 4, | ||
641 | //intra_mip_flag | ||
642 | 9, 10, 9, 6, | ||
643 | //intra_luma_ref_idx | ||
644 | 5, 8, | ||
645 | //intra_subpartitions_mode_flag | ||
646 | 9, | ||
647 | //intra_subpartitions_split_flag | ||
648 | 2, | ||
649 | //intra_luma_mpm_flag | ||
650 | 6, | ||
651 | //intra_luma_not_planar_flag | ||
652 | 1, 5, | ||
653 | //intra_bdpcm_chroma_flag | ||
654 | 1, | ||
655 | //intra_bdpcm_chroma_dir_flag | ||
656 | 0, | ||
657 | //cclm_mode_flag | ||
658 | 4, | ||
659 | //cclm_mode_idx | ||
660 | 9, | ||
661 | //intra_chroma_pred_mode | ||
662 | 5, | ||
663 | //general_merge_flag | ||
664 | 4, | ||
665 | //inter_pred_idc | ||
666 | 0, 0, 1, 4, 4, 0, | ||
667 | //inter_affine_flag | ||
668 | 4, 0, 0, | ||
669 | //cu_affine_type_flag | ||
670 | 4, | ||
671 | //sym_mvd_flag | ||
672 | 5, | ||
673 | //ref_idx_l0 and ref_idx_l1 | ||
674 | 0, 4, | ||
675 | //mvp_l0_flag and mvp_l1_flag | ||
676 | 12, | ||
677 | //amvr_flag | ||
678 | 0, 0, | ||
679 | //amvr_precision_idx | ||
680 | 4, 5, 0, | ||
681 | //bcw_idx | ||
682 | 1, | ||
683 | //cu_coded_flag | ||
684 | 4, | ||
685 | //cu_sbt_flag | ||
686 | 1, 5, | ||
687 | //cu_sbt_quad_flag | ||
688 | 10, | ||
689 | //cu_sbt_horizontal_flag | ||
690 | 8, 4, 1, | ||
691 | //cu_sbt_pos_flag | ||
692 | 13, | ||
693 | //lfnst_idx | ||
694 | 9, 9, 10, | ||
695 | //mts_idx | ||
696 | 8, 0, 9, 0, | ||
697 | //copy_above_palette_indices_flag | ||
698 | 9, | ||
699 | //palette_transpose_flag | ||
700 | 5, | ||
701 | //run_copy_flag | ||
702 | 9, 6, 9, 10, 5, 0, 9, 5, | ||
703 | //regular_merge_flag | ||
704 | 5, 5, | ||
705 | //mmvd_merge_flag | ||
706 | 4, | ||
707 | //mmvd_cand_flag | ||
708 | 10, | ||
709 | //mmvd_distance_idx | ||
710 | 0, | ||
711 | //ciip_flag | ||
712 | 1, | ||
713 | //merge_subblock_flag | ||
714 | 4, 4, 4, | ||
715 | //merge_subblock_idx | ||
716 | 0, | ||
717 | //merge_idx, merge_gpm_idx0, and merge_gpm_idx1 | ||
718 | 4, | ||
719 | //abs_mvd_greater0_flag | ||
720 | 9, | ||
721 | //abs_mvd_greater1_flag | ||
722 | 5, | ||
723 | //tu_y_coded_flag | ||
724 | 5, 1, 8, 9, | ||
725 | //tu_cb_coded_flag | ||
726 | 5, 0, | ||
727 | //tu_cr_coded_flag | ||
728 | 2, 1, 0, | ||
729 | //cu_qp_delta_abs | ||
730 | 8, 8, | ||
731 | //cu_chroma_qp_offset_flag | ||
732 | 8, | ||
733 | //cu_chroma_qp_offset_idx | ||
734 | 8, | ||
735 | //transform_skip_flag | ||
736 | 1, 1, | ||
737 | //tu_joint_cbcr_residual_flag | ||
738 | 1, 1, 0, | ||
739 | //last_sig_coeff_x_prefix | ||
740 | 8, 5, 4, 5, 4, 4, 5, 4, 1, 0, 4, 1, 0, 0, 0, 0, | ||
741 | 1, 0, 0, 0, 5, 4, 4, | ||
742 | //last_sig_coeff_y_prefix | ||
743 | 8, 5, 8, 5, 5, 4, 5, 5, 4, 0, 5, 4, 1, 0, 0, 1, | ||
744 | 4, 0, 0, 0, 6, 5, 5, | ||
745 | //sb_coded_flag | ||
746 | 8, 5, 5, 8, 5, 8, 8, | ||
747 | //sig_coeff_flag | ||
748 | 12, 9, 9, 10, 9, 9, 9, 10, 8, 8, 8, 10, 9, 13, 8, 8, | ||
749 | 8, 8, 8, 5, 8, 0, 0, 0, 8, 8, 8, 8, 8, 0, 4, 4, | ||
750 | 0, 0, 0, 0, 12, 12, 9, 13, 4, 5, 8, 9, 8, 12, 12, 8, | ||
751 | 4, 0, 0, 0, 8, 8, 8, 8, 4, 0, 0, 0, 13, 13, 8, | ||
752 | //par_level_flag | ||
753 | 8, 9, 12, 13, 13, 13, 10, 13, 13, 13, 13, 13, 13, 13, 13, 13, | ||
754 | 10, 13, 13, 13, 13, 8, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, | ||
755 | 6, | ||
756 | //abs_level_gtx_flag | ||
757 | 9, 5, 10, 13, 13, 10, 9, 10, 13, 13, 13, 9, 10, 10, 10, 13, | ||
758 | 8, 9, 10, 10, 13, 8, 8, 9, 12, 12, 10, 5, 9, 9, 9, 13, | ||
759 | 1, 5, 9, 9, 9, 6, 5, 9, 10, 10, 9, 9, 9, 9, 9, 9, | ||
760 | 6, 8, 9, 9, 10, 1, 5, 8, 8, 9, 6, 6, 9, 8, 8, 9, | ||
761 | 4, 2, 1, 6, 1, 1, 1, 1, | ||
762 | //coeff_sign_flag | ||
763 | 1, 4, 4, 5, 8, 8, | ||
764 | } | ||
765 | }; | ||
766 | |||
767 | #define MAX_SUB_BLOCKS 16 | ||
768 | #define MAX_SUB_BLOCK_SIZE 4 | ||
769 | #define MAX_TB_SIZE 64 | ||
770 | |||
771 | typedef struct ResidualCoding { | ||
772 | //common for ts and non ts | ||
773 | TransformBlock *tb; | ||
774 | |||
775 | int log2_sb_w; | ||
776 | int log2_sb_h; | ||
777 | int last_sub_block; | ||
778 | int hist_value; | ||
779 | int update_hist; | ||
780 | int num_sb_coeff; | ||
781 | int rem_bins_pass1; | ||
782 | |||
783 | int width_in_sbs; | ||
784 | int height_in_sbs; | ||
785 | int nb_sbs; | ||
786 | |||
787 | const uint8_t *sb_scan_x_off; | ||
788 | const uint8_t *sb_scan_y_off; | ||
789 | const uint8_t *scan_x_off; | ||
790 | const uint8_t *scan_y_off; | ||
791 | |||
792 | uint8_t sb_coded_flag[MAX_SUB_BLOCKS * MAX_SUB_BLOCKS]; | ||
793 | int sig_coeff_flag[MAX_TB_SIZE * MAX_TB_SIZE]; | ||
794 | int abs_level_pass1[MAX_TB_SIZE * MAX_TB_SIZE]; ///< AbsLevelPass1[][] | ||
795 | int abs_level[MAX_TB_SIZE * MAX_TB_SIZE]; | ||
796 | |||
797 | //for ts only | ||
798 | uint8_t infer_sb_cbf; | ||
799 | int coeff_sign_level[MAX_TB_SIZE * MAX_TB_SIZE]; ///< CoeffSignLevel[][] | ||
800 | |||
801 | //for non ts only | ||
802 | int qstate; | ||
803 | int last_scan_pos; | ||
804 | int last_significant_coeff_x; | ||
805 | int last_significant_coeff_y; | ||
806 | } ResidualCoding; | ||
807 | |||
808 | ✗ | static int cabac_reinit(VVCLocalContext *lc) | |
809 | { | ||
810 | ✗ | return skip_bytes(&lc->ep->cc, 0) == NULL ? AVERROR_INVALIDDATA : 0; | |
811 | } | ||
812 | |||
813 | 1873 | static void cabac_init_state(VVCLocalContext *lc) | |
814 | { | ||
815 | 1873 | const VVCSPS *sps = lc->fc->ps.sps; | |
816 | 1873 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
817 | 1873 | const int qp = av_clip_uintp2(lc->sc->sh.slice_qp_y, 6); | |
818 | 1873 | int init_type = 2 - rsh->sh_slice_type; | |
819 | |||
820 | av_assert0(VVC_CONTEXTS == SYNTAX_ELEMENT_LAST); | ||
821 | |||
822 | 1873 | ff_vvc_ep_init_stat_coeff(lc->ep, sps->bit_depth, sps->r->sps_persistent_rice_adaptation_enabled_flag); | |
823 | |||
824 |
3/4✓ Branch 0 taken 485 times.
✓ Branch 1 taken 1388 times.
✓ Branch 2 taken 485 times.
✗ Branch 3 not taken.
|
1873 | if (rsh->sh_cabac_init_flag && !IS_I(rsh)) |
825 | 485 | init_type ^= 3; | |
826 | |||
827 |
2/2✓ Branch 0 taken 707994 times.
✓ Branch 1 taken 1873 times.
|
709867 | for (int i = 0; i < VVC_CONTEXTS; i++) { |
828 | 707994 | VVCCabacState *state = &lc->ep->cabac_state[i]; | |
829 | 707994 | const int init_value = init_values[init_type][i]; | |
830 | 707994 | const int shift_idx = init_values[3][i]; | |
831 | 707994 | const int m = (init_value >> 3) - 4; | |
832 | 707994 | const int n = ((init_value & 7) * 18) + 1; | |
833 | 707994 | const int pre = av_clip(((m * (qp - 16)) >> 1) + n, 1, 127); | |
834 | |||
835 | 707994 | state->state[0] = pre << 3; | |
836 | 707994 | state->state[1] = pre << 7; | |
837 | 707994 | state->shift[0] = (shift_idx >> 2 ) + 2; | |
838 | 707994 | state->shift[1] = (shift_idx & 3 ) + 3 + state->shift[0]; | |
839 | } | ||
840 | 1873 | } | |
841 | |||
842 | 45792 | int ff_vvc_cabac_init(VVCLocalContext *lc, | |
843 | const int ctu_idx, const int rx, const int ry) | ||
844 | { | ||
845 | 45792 | int ret = 0; | |
846 | 45792 | const VVCPPS *pps = lc->fc->ps.pps; | |
847 | 45792 | const int first_ctb_in_slice = !ctu_idx; | |
848 |
4/4✓ Branch 0 taken 5265 times.
✓ Branch 1 taken 40527 times.
✓ Branch 2 taken 1761 times.
✓ Branch 3 taken 3504 times.
|
45792 | const int first_ctb_in_tile = rx == pps->ctb_to_col_bd[rx] && ry == pps->ctb_to_row_bd[ry]; |
849 | |||
850 |
4/4✓ Branch 0 taken 44133 times.
✓ Branch 1 taken 1659 times.
✓ Branch 2 taken 214 times.
✓ Branch 3 taken 43919 times.
|
45792 | if (first_ctb_in_slice|| first_ctb_in_tile) { |
851 |
3/4✓ Branch 0 taken 1568 times.
✓ Branch 1 taken 305 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1568 times.
|
1873 | if (lc->sc->nb_eps == 1 && !first_ctb_in_slice) |
852 | ✗ | ret = cabac_reinit(lc); | |
853 |
1/2✓ Branch 0 taken 1873 times.
✗ Branch 1 not taken.
|
1873 | if (!ret) |
854 | 1873 | cabac_init_state(lc); | |
855 | } | ||
856 | 45792 | return ret; | |
857 | } | ||
858 | |||
859 | //fixme | ||
860 | 1768017 | 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 | 1768017 | i = ff_ctz(c->low) - CABAC_BITS; | |
868 | #endif | ||
869 | |||
870 | 1768017 | x = -CABAC_MASK; | |
871 | |||
872 | #if CABAC_BITS == 16 | ||
873 | 1768017 | x += (c->bytestream[0] << 9) + (c->bytestream[1] << 1); | |
874 | #else | ||
875 | x += c->bytestream[0] << 1; | ||
876 | #endif | ||
877 | |||
878 | 1768017 | c->low += x << i; | |
879 | #if !UNCHECKED_BITSTREAM_READER | ||
880 |
2/2✓ Branch 0 taken 1767907 times.
✓ Branch 1 taken 110 times.
|
1768017 | if (c->bytestream < c->bytestream_end) |
881 | #endif | ||
882 | 1767907 | c->bytestream += CABAC_BITS / 8; | |
883 | 1768017 | } | |
884 | |||
885 | 47182593 | static int inline vvc_get_cabac(CABACContext *c, VVCCabacState* base, const int ctx) | |
886 | { | ||
887 | 47182593 | VVCCabacState *s = base + ctx; | |
888 | 47182593 | const int qRangeIdx = c->range >> 5; | |
889 | 47182593 | const int pState = s->state[1] + (s->state[0] << 4); | |
890 | 47182593 | const int valMps = pState >> 14; | |
891 |
2/2✓ Branch 0 taken 19205880 times.
✓ Branch 1 taken 27976713 times.
|
47182593 | const int RangeLPS = (qRangeIdx * ((valMps ? 32767 - pState : pState) >> 9 ) >> 1) + 4; |
892 | int bit, lps_mask; | ||
893 | |||
894 | 47182593 | c->range -= RangeLPS; | |
895 | 47182593 | lps_mask = ((c->range<<(CABAC_BITS+1)) - c->low)>>31; | |
896 | |||
897 | 47182593 | c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask; | |
898 | 47182593 | c->range += (RangeLPS - c->range) & lps_mask; | |
899 | |||
900 | 47182593 | bit = valMps ^ (lps_mask & 1); | |
901 | |||
902 | 47182593 | lps_mask = ff_h264_norm_shift[c->range]; | |
903 | 47182593 | c->range <<= lps_mask; | |
904 | 47182593 | c->low <<= lps_mask; | |
905 | |||
906 |
2/2✓ Branch 0 taken 1768017 times.
✓ Branch 1 taken 45414576 times.
|
47182593 | if (!(c->low & CABAC_MASK)) |
907 | 1768017 | vvc_refill2(c); | |
908 | 47182593 | s->state[0] = s->state[0] - (s->state[0] >> s->shift[0]) + (1023 * bit >> s->shift[0]); | |
909 | 47182593 | s->state[1] = s->state[1] - (s->state[1] >> s->shift[1]) + (16383 * bit >> s->shift[1]); | |
910 | 47182593 | 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 | 208386 | static int truncated_binary_decode(VVCLocalContext *lc, const int c_max) | |
917 | { | ||
918 | 208386 | const int n = c_max + 1; | |
919 | 208386 | const int k = av_log2(n); | |
920 | 208386 | const int u = (1 << (k+1)) - n; | |
921 | 208386 | int v = 0; | |
922 |
2/2✓ Branch 0 taken 794455 times.
✓ Branch 1 taken 208386 times.
|
1002841 | for (int i = 0; i < k; i++) |
923 | 794455 | v = (v << 1) | get_cabac_bypass(&lc->ep->cc); | |
924 |
2/2✓ Branch 0 taken 116192 times.
✓ Branch 1 taken 92194 times.
|
208386 | if (v >= u) { |
925 | 116192 | v = (v << 1) | get_cabac_bypass(&lc->ep->cc); | |
926 | 116192 | v -= u; | |
927 | } | ||
928 | 208386 | return v; | |
929 | } | ||
930 | |||
931 | // 9.3.3.6 Limited k-th order Exp-Golomb binarization process | ||
932 | 83258 | static int limited_kth_order_egk_decode(CABACContext *c, const int k, const int max_pre_ext_len, const int trunc_suffix_len) | |
933 | { | ||
934 | 83258 | int pre_ext_len = 0; | |
935 | int escape_length; | ||
936 | 83258 | int val = 0; | |
937 |
3/4✓ Branch 0 taken 147956 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 64698 times.
✓ Branch 4 taken 83258 times.
|
147956 | while ((pre_ext_len < max_pre_ext_len) && get_cabac_bypass(c)) |
938 | 64698 | pre_ext_len++; | |
939 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 83258 times.
|
83258 | if (pre_ext_len == max_pre_ext_len) |
940 | ✗ | escape_length = trunc_suffix_len; | |
941 | else | ||
942 | 83258 | escape_length = pre_ext_len + k; | |
943 |
2/2✓ Branch 0 taken 156007 times.
✓ Branch 1 taken 83258 times.
|
239265 | while (escape_length-- > 0) { |
944 | 156007 | val = (val << 1) + get_cabac_bypass(c); | |
945 | } | ||
946 | 83258 | val += ((1 << pre_ext_len) - 1) << k; | |
947 | 83258 | return val; | |
948 | } | ||
949 | |||
950 | static av_always_inline | ||
951 | 3172196 | void get_left_top(const VVCLocalContext *lc, uint8_t *left, uint8_t *top, | |
952 | const int x0, const int y0, const uint8_t *left_ctx, const uint8_t *top_ctx) | ||
953 | { | ||
954 | 3172196 | const VVCFrameContext *fc = lc->fc; | |
955 | 3172196 | const VVCSPS *sps = fc->ps.sps; | |
956 | 3172196 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
957 | 3172196 | const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y); | |
958 | 3172196 | const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y); | |
959 | 3172196 | const int x_cb = x0 >> sps->min_cb_log2_size_y; | |
960 | 3172196 | const int y_cb = y0 >> sps->min_cb_log2_size_y; | |
961 | |||
962 |
4/4✓ Branch 0 taken 532748 times.
✓ Branch 1 taken 2639448 times.
✓ Branch 2 taken 434709 times.
✓ Branch 3 taken 98039 times.
|
3172196 | if (lc->ctb_left_flag || x0b) |
963 | 3074157 | *left = SAMPLE_CTB(left_ctx, x_cb - 1, y_cb); | |
964 |
4/4✓ Branch 0 taken 883611 times.
✓ Branch 1 taken 2288585 times.
✓ Branch 2 taken 732142 times.
✓ Branch 3 taken 151469 times.
|
3172196 | if (lc->ctb_up_flag || y0b) |
965 | 3020727 | *top = SAMPLE_CTB(top_ctx, x_cb, y_cb - 1); | |
966 | 3172196 | } | |
967 | |||
968 | static av_always_inline | ||
969 | 761876 | uint8_t get_inc(VVCLocalContext *lc, const uint8_t *ctx) | |
970 | { | ||
971 | 761876 | uint8_t left = 0, top = 0; | |
972 | 761876 | get_left_top(lc, &left, &top, lc->cu->x0, lc->cu->y0, ctx, ctx); | |
973 | 761876 | return left + top; | |
974 | } | ||
975 | |||
976 | 22687 | int ff_vvc_sao_merge_flag_decode(VVCLocalContext *lc) | |
977 | { | ||
978 | 22687 | return GET_CABAC(SAO_MERGE_FLAG); | |
979 | } | ||
980 | |||
981 | 12433 | int ff_vvc_sao_type_idx_decode(VVCLocalContext *lc) | |
982 | { | ||
983 |
2/2✓ Branch 1 taken 8774 times.
✓ Branch 2 taken 3659 times.
|
12433 | if (!GET_CABAC(SAO_TYPE_IDX)) |
984 | 8774 | return SAO_NOT_APPLIED; | |
985 | |||
986 |
2/2✓ Branch 1 taken 1049 times.
✓ Branch 2 taken 2610 times.
|
3659 | if (!get_cabac_bypass(&lc->ep->cc)) |
987 | 1049 | return SAO_BAND; | |
988 | 2610 | return SAO_EDGE; | |
989 | } | ||
990 | |||
991 | 1163 | int ff_vvc_sao_band_position_decode(VVCLocalContext *lc) | |
992 | { | ||
993 | 1163 | int value = get_cabac_bypass(&lc->ep->cc); | |
994 | |||
995 |
2/2✓ Branch 0 taken 4652 times.
✓ Branch 1 taken 1163 times.
|
5815 | for (int i = 0; i < 4; i++) |
996 | 4652 | value = (value << 1) | get_cabac_bypass(&lc->ep->cc); | |
997 | 1163 | return value; | |
998 | } | ||
999 | |||
1000 | 18364 | int ff_vvc_sao_offset_abs_decode(VVCLocalContext *lc) | |
1001 | { | ||
1002 | 18364 | int i = 0; | |
1003 | 18364 | const int length = (1 << (FFMIN(lc->fc->ps.sps->bit_depth, 10) - 5)) - 1; | |
1004 | |||
1005 |
4/4✓ Branch 0 taken 49059 times.
✓ Branch 1 taken 129 times.
✓ Branch 3 taken 30824 times.
✓ Branch 4 taken 18235 times.
|
49188 | while (i < length && get_cabac_bypass(&lc->ep->cc)) |
1006 | 30824 | i++; | |
1007 | 18364 | return i; | |
1008 | } | ||
1009 | |||
1010 | 1723 | int ff_vvc_sao_offset_sign_decode(VVCLocalContext *lc) | |
1011 | { | ||
1012 | 1723 | return get_cabac_bypass(&lc->ep->cc); | |
1013 | } | ||
1014 | |||
1015 | 2610 | int ff_vvc_sao_eo_class_decode(VVCLocalContext *lc) | |
1016 | { | ||
1017 | 2610 | int ret = get_cabac_bypass(&lc->ep->cc) << 1; | |
1018 | 2610 | ret |= get_cabac_bypass(&lc->ep->cc); | |
1019 | 2610 | return ret; | |
1020 | } | ||
1021 | |||
1022 | 57325 | int ff_vvc_alf_ctb_flag(VVCLocalContext *lc, const int rx, const int ry, const int c_idx) | |
1023 | { | ||
1024 | 57325 | int inc = c_idx * 3; | |
1025 | 57325 | const VVCFrameContext *fc = lc->fc; | |
1026 |
2/2✓ Branch 0 taken 49594 times.
✓ Branch 1 taken 7731 times.
|
57325 | if (lc->ctb_left_flag) { |
1027 | 49594 | const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry); | |
1028 | 49594 | inc += left->ctb_flag[c_idx]; | |
1029 | } | ||
1030 |
2/2✓ Branch 0 taken 43680 times.
✓ Branch 1 taken 13645 times.
|
57325 | if (lc->ctb_up_flag) { |
1031 | 43680 | const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1); | |
1032 | 43680 | inc += above->ctb_flag[c_idx]; | |
1033 | } | ||
1034 | 57325 | return GET_CABAC(ALF_CTB_FLAG + inc); | |
1035 | } | ||
1036 | |||
1037 | 18110 | int ff_vvc_alf_use_aps_flag(VVCLocalContext *lc) | |
1038 | { | ||
1039 | 18110 | return GET_CABAC(ALF_USE_APS_FLAG); | |
1040 | } | ||
1041 | |||
1042 | 4492 | int ff_vvc_alf_luma_prev_filter_idx(VVCLocalContext *lc) | |
1043 | { | ||
1044 | 4492 | return truncated_binary_decode(lc, lc->sc->sh.r->sh_num_alf_aps_ids_luma - 1); | |
1045 | } | ||
1046 | |||
1047 | 2496 | int ff_vvc_alf_luma_fixed_filter_idx(VVCLocalContext *lc) | |
1048 | { | ||
1049 | 2496 | return truncated_binary_decode(lc, 15); | |
1050 | } | ||
1051 | |||
1052 | 15333 | int ff_vvc_alf_ctb_filter_alt_idx(VVCLocalContext *lc, const int c_idx, const int num_chroma_filters) | |
1053 | { | ||
1054 | 15333 | int i = 0; | |
1055 | 15333 | const int length = num_chroma_filters - 1; | |
1056 | |||
1057 |
4/4✓ Branch 0 taken 27612 times.
✓ Branch 1 taken 2437 times.
✓ Branch 3 taken 14716 times.
✓ Branch 4 taken 12896 times.
|
30049 | while (i < length && GET_CABAC(ALF_CTB_FILTER_ALT_IDX + c_idx - 1)) |
1058 | 14716 | i++; | |
1059 | 15333 | return i; | |
1060 | } | ||
1061 | |||
1062 | 21273 | int ff_vvc_alf_ctb_cc_idc(VVCLocalContext *lc, const int rx, const int ry, const int idx, const int cc_filters_signalled) | |
1063 | { | ||
1064 |
2/2✓ Branch 0 taken 11453 times.
✓ Branch 1 taken 9820 times.
|
21273 | int inc = !idx ? ALF_CTB_CC_CB_IDC : ALF_CTB_CC_CR_IDC; |
1065 | 21273 | int i = 0; | |
1066 | 21273 | const VVCFrameContext *fc = lc->fc; | |
1067 |
2/2✓ Branch 0 taken 19344 times.
✓ Branch 1 taken 1929 times.
|
21273 | if (lc->ctb_left_flag) { |
1068 | 19344 | const ALFParams *left = &CTB(fc->tab.alf, rx - 1, ry); | |
1069 | 19344 | inc += left->ctb_cc_idc[idx] != 0; | |
1070 | } | ||
1071 |
2/2✓ Branch 0 taken 18133 times.
✓ Branch 1 taken 3140 times.
|
21273 | if (lc->ctb_up_flag) { |
1072 | 18133 | const ALFParams *above = &CTB(fc->tab.alf, rx, ry - 1); | |
1073 | 18133 | inc += above->ctb_cc_idc[idx] != 0; | |
1074 | } | ||
1075 | |||
1076 |
2/2✓ Branch 1 taken 11826 times.
✓ Branch 2 taken 9447 times.
|
21273 | if (!GET_CABAC(inc)) |
1077 | 11826 | return 0; | |
1078 | 9447 | i++; | |
1079 |
4/4✓ Branch 0 taken 16411 times.
✓ Branch 1 taken 1251 times.
✓ Branch 3 taken 8215 times.
✓ Branch 4 taken 8196 times.
|
17662 | while (i < cc_filters_signalled && get_cabac_bypass(&lc->ep->cc)) |
1080 | 8215 | i++; | |
1081 | 9447 | return i; | |
1082 | } | ||
1083 | |||
1084 | 1823471 | int ff_vvc_split_cu_flag(VVCLocalContext *lc, const int x0, const int y0, | |
1085 | const int cb_width, const int cb_height, const int is_chroma, const VVCAllowedSplit *a) | ||
1086 | { | ||
1087 | 1823471 | const VVCFrameContext *fc = lc->fc; | |
1088 | 1823471 | const VVCPPS *pps = fc->ps.pps; | |
1089 |
4/4✓ Branch 0 taken 1819266 times.
✓ Branch 1 taken 4205 times.
✓ Branch 2 taken 1772156 times.
✓ Branch 3 taken 47110 times.
|
1823471 | const int is_inside = (x0 + cb_width <= pps->width) && (y0 + cb_height <= pps->height); |
1090 | |||
1091 |
12/12✓ Branch 0 taken 688787 times.
✓ Branch 1 taken 1134684 times.
✓ Branch 2 taken 506000 times.
✓ Branch 3 taken 182787 times.
✓ Branch 4 taken 502041 times.
✓ Branch 5 taken 3959 times.
✓ Branch 6 taken 501930 times.
✓ Branch 7 taken 111 times.
✓ Branch 8 taken 49055 times.
✓ Branch 9 taken 452875 times.
✓ Branch 10 taken 1319281 times.
✓ Branch 11 taken 51315 times.
|
1823471 | if ((a->btv || a->bth || a->ttv || a->tth || a->qt) && is_inside) |
1092 | { | ||
1093 | 1319281 | uint8_t inc = 0, left_height = cb_height, top_width = cb_width; | |
1094 | |||
1095 | 1319281 | get_left_top(lc, &left_height, &top_width, x0, y0, fc->tab.cb_height[is_chroma], fc->tab.cb_width[is_chroma]); | |
1096 | 1319281 | inc += left_height < cb_height; | |
1097 | 1319281 | inc += top_width < cb_width; | |
1098 | 1319281 | inc += (a->btv + a->bth + a->ttv + a->tth + 2 * a->qt - 1) / 2 * 3; | |
1099 | |||
1100 | 1319281 | return GET_CABAC(SPLIT_CU_FLAG + inc); | |
1101 | |||
1102 | } | ||
1103 | 504190 | return !is_inside; | |
1104 | } | ||
1105 | |||
1106 | 260116 | static int split_qt_flag_decode(VVCLocalContext *lc, const int x0, const int y0, const int ch_type, const int cqt_depth) | |
1107 | { | ||
1108 | 260116 | const VVCFrameContext *fc = lc->fc; | |
1109 | 260116 | int inc = 0; | |
1110 | 260116 | uint8_t depth_left = 0, depth_top = 0; | |
1111 | |||
1112 | 260116 | get_left_top(lc, &depth_left, &depth_top, x0, y0, fc->tab.cqt_depth[ch_type], fc->tab.cqt_depth[ch_type]); | |
1113 | 260116 | inc += depth_left > cqt_depth; | |
1114 | 260116 | inc += depth_top > cqt_depth; | |
1115 |
2/2✓ Branch 0 taken 196010 times.
✓ Branch 1 taken 64106 times.
|
260116 | inc += (cqt_depth >= 2) * 3; |
1116 | |||
1117 | 260116 | return GET_CABAC(SPLIT_QT_FLAG + inc); | |
1118 | } | ||
1119 | |||
1120 | 616910 | static int mtt_split_cu_vertical_flag_decode(VVCLocalContext *lc, const int x0, const int y0, | |
1121 | const int cb_width, const int cb_height, const int ch_type, const VVCAllowedSplit* a) | ||
1122 | { | ||
1123 |
8/8✓ Branch 0 taken 54684 times.
✓ Branch 1 taken 562226 times.
✓ Branch 2 taken 12927 times.
✓ Branch 3 taken 41757 times.
✓ Branch 4 taken 90926 times.
✓ Branch 5 taken 484227 times.
✓ Branch 6 taken 11116 times.
✓ Branch 7 taken 79810 times.
|
616910 | if ((a->bth || a->tth) && (a->btv || a->ttv)) { |
1124 | int inc; | ||
1125 | 495343 | const int v = a->btv + a->ttv; | |
1126 | 495343 | const int h = a->bth + a->tth; | |
1127 |
2/2✓ Branch 0 taken 75348 times.
✓ Branch 1 taken 419995 times.
|
495343 | if (v > h) |
1128 | 75348 | inc = 4; | |
1129 |
2/2✓ Branch 0 taken 77924 times.
✓ Branch 1 taken 342071 times.
|
419995 | else if (v < h) |
1130 | 77924 | inc = 3; | |
1131 | else { | ||
1132 | 342071 | const VVCFrameContext *fc = lc->fc; | |
1133 | 342071 | const VVCSPS *sps = fc->ps.sps; | |
1134 | 342071 | const int min_cb_width = fc->ps.pps->min_cb_width; | |
1135 | 342071 | const int x0b = av_zero_extend(x0, sps->ctb_log2_size_y); | |
1136 | 342071 | const int y0b = av_zero_extend(y0, sps->ctb_log2_size_y); | |
1137 | 342071 | const int x_cb = x0 >> sps->min_cb_log2_size_y; | |
1138 | 342071 | const int y_cb = y0 >> sps->min_cb_log2_size_y; | |
1139 |
4/4✓ Branch 0 taken 96588 times.
✓ Branch 1 taken 245483 times.
✓ Branch 2 taken 79559 times.
✓ Branch 3 taken 17029 times.
|
342071 | const int available_a = lc->ctb_up_flag || y0b; |
1140 |
4/4✓ Branch 0 taken 57311 times.
✓ Branch 1 taken 284760 times.
✓ Branch 2 taken 45175 times.
✓ Branch 3 taken 12136 times.
|
342071 | const int available_l = lc->ctb_left_flag || x0b; |
1141 |
2/2✓ Branch 0 taken 325042 times.
✓ Branch 1 taken 17029 times.
|
342071 | const int da = cb_width / (available_a ? SAMPLE_CTB(fc->tab.cb_width[ch_type], x_cb, y_cb - 1) : 1); |
1142 |
2/2✓ Branch 0 taken 329935 times.
✓ Branch 1 taken 12136 times.
|
342071 | const int dl = cb_height / (available_l ? SAMPLE_CTB(fc->tab.cb_height[ch_type], x_cb - 1, y_cb) : 1); |
1143 | |||
1144 |
6/6✓ Branch 0 taken 248218 times.
✓ Branch 1 taken 93853 times.
✓ Branch 2 taken 232267 times.
✓ Branch 3 taken 15951 times.
✓ Branch 4 taken 10626 times.
✓ Branch 5 taken 221641 times.
|
342071 | if (da == dl || !available_a || !available_l) |
1145 | 120430 | inc = 0; | |
1146 |
2/2✓ Branch 0 taken 114386 times.
✓ Branch 1 taken 107255 times.
|
221641 | else if (da < dl) |
1147 | 114386 | inc = 1; | |
1148 | else | ||
1149 | 107255 | inc = 2; | |
1150 | } | ||
1151 | 495343 | return GET_CABAC(MTT_SPLIT_CU_VERTICAL_FLAG + inc); | |
1152 | } | ||
1153 |
4/4✓ Branch 0 taken 41779 times.
✓ Branch 1 taken 79788 times.
✓ Branch 2 taken 41757 times.
✓ Branch 3 taken 22 times.
|
121567 | return !(a->bth || a->tth); |
1154 | } | ||
1155 | |||
1156 | 426410 | static int mtt_split_cu_binary_flag_decode(VVCLocalContext *lc, const int mtt_split_cu_vertical_flag, const int mtt_depth) | |
1157 | { | ||
1158 | 426410 | const int inc = (2 * mtt_split_cu_vertical_flag) + ((mtt_depth <= 1) ? 1 : 0); | |
1159 | 426410 | return GET_CABAC(MTT_SPLIT_CU_BINARY_FLAG + inc); | |
1160 | } | ||
1161 | |||
1162 | 715594 | VVCSplitMode ff_vvc_split_mode(VVCLocalContext *lc, const int x0, const int y0, const int cb_width, const int cb_height, | |
1163 | const int cqt_depth, const int mtt_depth, const int ch_type, const VVCAllowedSplit *a) | ||
1164 | { | ||
1165 |
8/8✓ Branch 0 taken 130246 times.
✓ Branch 1 taken 585348 times.
✓ Branch 2 taken 36197 times.
✓ Branch 3 taken 94049 times.
✓ Branch 4 taken 32908 times.
✓ Branch 5 taken 3289 times.
✓ Branch 6 taken 22 times.
✓ Branch 7 taken 32886 times.
|
715594 | const int allow_no_qt = a->btv || a->bth || a->ttv || a->tth; |
1166 | int split_qt_flag; | ||
1167 | int mtt_split_cu_vertical_flag; | ||
1168 | int mtt_split_cu_binary_flag; | ||
1169 | 715594 | const VVCSplitMode mtt_split_modes[] = { | |
1170 | SPLIT_TT_HOR, SPLIT_BT_HOR, SPLIT_TT_VER, SPLIT_BT_VER, | ||
1171 | }; | ||
1172 |
4/4✓ Branch 0 taken 682708 times.
✓ Branch 1 taken 32886 times.
✓ Branch 2 taken 260116 times.
✓ Branch 3 taken 422592 times.
|
715594 | if (allow_no_qt && a->qt) { |
1173 | 260116 | split_qt_flag = split_qt_flag_decode(lc, x0, y0, ch_type, cqt_depth); | |
1174 | } else { | ||
1175 |
3/4✓ Branch 0 taken 422592 times.
✓ Branch 1 taken 32886 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 422592 times.
|
455478 | split_qt_flag = !allow_no_qt || a->qt; |
1176 | } | ||
1177 |
2/2✓ Branch 0 taken 98684 times.
✓ Branch 1 taken 616910 times.
|
715594 | if (split_qt_flag) |
1178 | 98684 | return SPLIT_QT; | |
1179 | 616910 | mtt_split_cu_vertical_flag = mtt_split_cu_vertical_flag_decode(lc, x0, y0, cb_width, cb_height, ch_type, a); | |
1180 |
6/6✓ Branch 0 taken 525963 times.
✓ Branch 1 taken 90947 times.
✓ Branch 2 taken 378496 times.
✓ Branch 3 taken 147467 times.
✓ Branch 4 taken 172704 times.
✓ Branch 5 taken 205792 times.
|
616910 | if ((a->btv && a->ttv && mtt_split_cu_vertical_flag) || |
1181 |
6/6✓ Branch 0 taken 389996 times.
✓ Branch 1 taken 21122 times.
✓ Branch 2 taken 247984 times.
✓ Branch 3 taken 142012 times.
✓ Branch 4 taken 220618 times.
✓ Branch 5 taken 27366 times.
|
411118 | (a->bth && a->tth && !mtt_split_cu_vertical_flag)) { |
1182 | 426410 | mtt_split_cu_binary_flag = mtt_split_cu_binary_flag_decode(lc, mtt_split_cu_vertical_flag, mtt_depth); | |
1183 | } else { | ||
1184 |
4/4✓ Branch 0 taken 58089 times.
✓ Branch 1 taken 132411 times.
✓ Branch 2 taken 673 times.
✓ Branch 3 taken 57416 times.
|
190500 | if (!a->btv && !a->bth) |
1185 | 673 | mtt_split_cu_binary_flag = 0; | |
1186 |
4/4✓ Branch 0 taken 157069 times.
✓ Branch 1 taken 32758 times.
✓ Branch 2 taken 131974 times.
✓ Branch 3 taken 25095 times.
|
189827 | else if (!a->ttv && !a->tth) |
1187 | 131974 | mtt_split_cu_binary_flag = 1; | |
1188 |
4/4✓ Branch 0 taken 52700 times.
✓ Branch 1 taken 5153 times.
✓ Branch 2 taken 28568 times.
✓ Branch 3 taken 24132 times.
|
57853 | else if (a->bth && a->ttv) |
1189 | 28568 | mtt_split_cu_binary_flag = 1 - mtt_split_cu_vertical_flag; | |
1190 | else | ||
1191 | 29285 | mtt_split_cu_binary_flag = mtt_split_cu_vertical_flag; | |
1192 | } | ||
1193 | 616910 | return mtt_split_modes[(mtt_split_cu_vertical_flag << 1) + mtt_split_cu_binary_flag]; | |
1194 | } | ||
1195 | |||
1196 | 27488 | int ff_vvc_non_inter_flag(VVCLocalContext *lc, const int x0, const int y0, const int ch_type) | |
1197 | { | ||
1198 | 27488 | const VVCFrameContext *fc = lc->fc; | |
1199 | 27488 | uint8_t inc, left = MODE_INTER, top = MODE_INTER; | |
1200 | |||
1201 | 27488 | get_left_top(lc, &left, &top, x0, y0, fc->tab.cpm[ch_type], fc->tab.cpm[ch_type]); | |
1202 |
4/4✓ Branch 0 taken 20554 times.
✓ Branch 1 taken 6934 times.
✓ Branch 2 taken 2764 times.
✓ Branch 3 taken 17790 times.
|
27488 | inc = left == MODE_INTRA || top == MODE_INTRA; |
1203 | 27488 | return GET_CABAC(NON_INTER_FLAG + inc); | |
1204 | } | ||
1205 | |||
1206 | 184737 | int ff_vvc_pred_mode_flag(VVCLocalContext *lc, const int is_chroma) | |
1207 | { | ||
1208 | 184737 | const VVCFrameContext *fc = lc->fc; | |
1209 | 184737 | const CodingUnit *cu = lc->cu; | |
1210 | 184737 | uint8_t inc, left = MODE_INTER, top = MODE_INTER; | |
1211 | |||
1212 | 184737 | get_left_top(lc, &left, &top, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]); | |
1213 |
4/4✓ Branch 0 taken 146160 times.
✓ Branch 1 taken 38577 times.
✓ Branch 2 taken 15040 times.
✓ Branch 3 taken 131120 times.
|
184737 | inc = left == MODE_INTRA || top == MODE_INTRA; |
1214 | 184737 | return GET_CABAC(PRED_MODE_FLAG + inc); | |
1215 | } | ||
1216 | |||
1217 | ✗ | int ff_vvc_pred_mode_plt_flag(VVCLocalContext *lc) | |
1218 | { | ||
1219 | ✗ | return GET_CABAC(PRED_MODE_PLT_FLAG); | |
1220 | } | ||
1221 | |||
1222 | 27878 | int ff_vvc_intra_bdpcm_luma_flag(VVCLocalContext *lc) | |
1223 | { | ||
1224 | 27878 | return GET_CABAC(INTRA_BDPCM_LUMA_FLAG); | |
1225 | } | ||
1226 | |||
1227 | 38 | int ff_vvc_intra_bdpcm_luma_dir_flag(VVCLocalContext *lc) | |
1228 | { | ||
1229 | 38 | return GET_CABAC(INTRA_BDPCM_LUMA_DIR_FLAG); | |
1230 | } | ||
1231 | |||
1232 | 24174 | int ff_vvc_intra_bdpcm_chroma_flag(VVCLocalContext *lc) | |
1233 | { | ||
1234 | 24174 | return GET_CABAC(INTRA_BDPCM_CHROMA_FLAG); | |
1235 | } | ||
1236 | |||
1237 | 3 | int ff_vvc_intra_bdpcm_chroma_dir_flag(VVCLocalContext *lc) | |
1238 | { | ||
1239 | 3 | return GET_CABAC(INTRA_BDPCM_CHROMA_DIR_FLAG); | |
1240 | } | ||
1241 | |||
1242 | 451292 | int ff_vvc_cu_skip_flag(VVCLocalContext *lc, const uint8_t *cu_skip_flag) | |
1243 | { | ||
1244 | 451292 | const int inc = get_inc(lc, cu_skip_flag); | |
1245 | 451292 | return GET_CABAC(CU_SKIP_FLAG + inc); | |
1246 | } | ||
1247 | |||
1248 | 3032 | int ff_vvc_pred_mode_ibc_flag(VVCLocalContext *lc, const int is_chroma) | |
1249 | { | ||
1250 | 3032 | const VVCFrameContext *fc = lc->fc; | |
1251 | 3032 | const CodingUnit *cu = lc->cu; | |
1252 | 3032 | uint8_t left_mode = MODE_INTER, top_mode = MODE_INTER; | |
1253 | int inc; | ||
1254 | |||
1255 | 3032 | get_left_top(lc, &left_mode, &top_mode, cu->x0, cu->y0, fc->tab.cpm[is_chroma], fc->tab.cpm[is_chroma]); | |
1256 | 3032 | inc = (left_mode == MODE_IBC) + (top_mode == MODE_IBC); | |
1257 | 3032 | return GET_CABAC(PRED_MODE_IBC_FLAG + inc); | |
1258 | } | ||
1259 | |||
1260 | 401168 | int ff_vvc_intra_mip_flag(VVCLocalContext *lc, const uint8_t *intra_mip_flag) | |
1261 | { | ||
1262 | 401168 | const int w = lc->cu->cb_width; | |
1263 | 401168 | const int h = lc->cu->cb_height; | |
1264 |
4/4✓ Branch 0 taken 333597 times.
✓ Branch 1 taken 67571 times.
✓ Branch 2 taken 310584 times.
✓ Branch 3 taken 23013 times.
|
401168 | const int inc = (w > h * 2 || h > w * 2) ? 3 : get_inc(lc, intra_mip_flag); |
1265 | 401168 | return GET_CABAC(INTRA_MIP_FLAG + inc); | |
1266 | } | ||
1267 | |||
1268 | 97983 | int ff_vvc_intra_mip_transposed_flag(VVCLocalContext *lc) | |
1269 | { | ||
1270 | 97983 | return get_cabac_bypass(&lc->ep->cc); | |
1271 | } | ||
1272 | |||
1273 | 97983 | int ff_vvc_intra_mip_mode(VVCLocalContext *lc) | |
1274 | { | ||
1275 | 97983 | const int w = lc->cu->cb_width; | |
1276 | 97983 | const int h = lc->cu->cb_height; | |
1277 |
4/4✓ Branch 0 taken 24174 times.
✓ Branch 1 taken 73809 times.
✓ Branch 2 taken 13815 times.
✓ Branch 3 taken 10359 times.
|
185607 | const int c_max = (w == 4 && h == 4) ? 15 : |
1278 |
8/8✓ Branch 0 taken 73809 times.
✓ Branch 1 taken 13815 times.
✓ Branch 2 taken 52644 times.
✓ Branch 3 taken 21165 times.
✓ Branch 4 taken 17280 times.
✓ Branch 5 taken 35364 times.
✓ Branch 6 taken 10167 times.
✓ Branch 7 taken 7113 times.
|
87624 | ((w == 4 || h == 4) || (w == 8 && h == 8)) ? 7: 5; |
1279 | 97983 | return truncated_binary_decode(lc, c_max); | |
1280 | } | ||
1281 | |||
1282 | 389011 | int ff_vvc_intra_luma_ref_idx(VVCLocalContext *lc) | |
1283 | { | ||
1284 | int i; | ||
1285 |
2/2✓ Branch 0 taken 419157 times.
✓ Branch 1 taken 18762 times.
|
437919 | for (i = 0; i < 2; i++) { |
1286 |
2/2✓ Branch 1 taken 370249 times.
✓ Branch 2 taken 48908 times.
|
419157 | if (!GET_CABAC(INTRA_LUMA_REF_IDX + i)) |
1287 | 370249 | return i; | |
1288 | } | ||
1289 | 18762 | return i; | |
1290 | } | ||
1291 | |||
1292 | 349125 | int ff_vvc_intra_subpartitions_mode_flag(VVCLocalContext *lc) | |
1293 | { | ||
1294 | 349125 | return GET_CABAC(INTRA_SUBPARTITIONS_MODE_FLAG); | |
1295 | } | ||
1296 | |||
1297 | 445017 | enum IspType ff_vvc_isp_split_type(VVCLocalContext *lc, const int intra_subpartitions_mode_flag) | |
1298 | { | ||
1299 |
2/2✓ Branch 0 taken 383408 times.
✓ Branch 1 taken 61609 times.
|
445017 | if (!intra_subpartitions_mode_flag) |
1300 | 383408 | return ISP_NO_SPLIT; | |
1301 | 61609 | return 1 + GET_CABAC(INTRA_SUBPARTITIONS_SPLIT_FLAG); | |
1302 | } | ||
1303 | |||
1304 | 414871 | int ff_vvc_intra_luma_mpm_flag(VVCLocalContext *lc) | |
1305 | { | ||
1306 | 414871 | return GET_CABAC(INTRA_LUMA_MPM_FLAG); | |
1307 | } | ||
1308 | |||
1309 | 311456 | int ff_vvc_intra_luma_not_planar_flag(VVCLocalContext *lc, const int intra_subpartitions_mode_flag) | |
1310 | { | ||
1311 |
2/2✓ Branch 0 taken 264404 times.
✓ Branch 1 taken 47052 times.
|
311456 | return GET_CABAC(INTRA_LUMA_NOT_PLANAR_FLAG + !intra_subpartitions_mode_flag); |
1312 | } | ||
1313 | |||
1314 | 171532 | int ff_vvc_intra_luma_mpm_idx(VVCLocalContext *lc) | |
1315 | { | ||
1316 | int i; | ||
1317 |
4/4✓ Branch 0 taken 307705 times.
✓ Branch 1 taken 10614 times.
✓ Branch 3 taken 146787 times.
✓ Branch 4 taken 160918 times.
|
318319 | for (i = 0; i < 4 && get_cabac_bypass(&lc->ep->cc); i++) |
1318 | /* nothing */; | ||
1319 | 171532 | return i; | |
1320 | } | ||
1321 | |||
1322 | 103415 | int ff_vvc_intra_luma_mpm_remainder(VVCLocalContext *lc) | |
1323 | { | ||
1324 | 103415 | return truncated_binary_decode(lc, 60); | |
1325 | } | ||
1326 | |||
1327 | 188650 | int ff_vvc_cclm_mode_flag(VVCLocalContext *lc) | |
1328 | { | ||
1329 | 188650 | return GET_CABAC(CCLM_MODE_FLAG); | |
1330 | } | ||
1331 | |||
1332 | 82776 | int ff_vvc_cclm_mode_idx(VVCLocalContext *lc) | |
1333 | { | ||
1334 |
2/2✓ Branch 1 taken 48258 times.
✓ Branch 2 taken 34518 times.
|
82776 | if (!GET_CABAC(CCLM_MODE_IDX)) |
1335 | 48258 | return 0; | |
1336 | 34518 | return get_cabac_bypass(&lc->ep->cc) + 1; | |
1337 | } | ||
1338 | |||
1339 | 120802 | int ff_vvc_intra_chroma_pred_mode(VVCLocalContext *lc) | |
1340 | { | ||
1341 |
2/2✓ Branch 1 taken 89644 times.
✓ Branch 2 taken 31158 times.
|
120802 | if (!GET_CABAC(INTRA_CHROMA_PRED_MODE)) |
1342 | 89644 | return 4; | |
1343 | 31158 | return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc); | |
1344 | } | ||
1345 | |||
1346 | 171688 | int ff_vvc_general_merge_flag(VVCLocalContext *lc) | |
1347 | { | ||
1348 | 171688 | return GET_CABAC(GENERAL_MERGE_FLAG); | |
1349 | } | ||
1350 | |||
1351 | 307833 | static int get_inter_flag_inc(VVCLocalContext *lc, const int x0, const int y0) | |
1352 | { | ||
1353 | 307833 | uint8_t left_merge = 0, top_merge = 0; | |
1354 | 307833 | uint8_t left_affine = 0, top_affine = 0; | |
1355 | 307833 | const VVCFrameContext *fc = lc->fc; | |
1356 | |||
1357 | 307833 | get_left_top(lc, &left_merge, &top_merge, x0, y0, fc->tab.msf, fc->tab.msf); | |
1358 | 307833 | get_left_top(lc, &left_affine, &top_affine, x0, y0, fc->tab.iaf, fc->tab.iaf); | |
1359 |
4/4✓ Branch 0 taken 267732 times.
✓ Branch 1 taken 40101 times.
✓ Branch 2 taken 9363 times.
✓ Branch 3 taken 258369 times.
|
307833 | return (left_merge || left_affine) + (top_merge + top_affine); |
1360 | } | ||
1361 | |||
1362 | 281484 | int ff_vvc_merge_subblock_flag(VVCLocalContext *lc) | |
1363 | { | ||
1364 | 281484 | const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0); | |
1365 | 281484 | return GET_CABAC(MERGE_SUBBLOCK_FLAG + inc); | |
1366 | } | ||
1367 | |||
1368 | 48822 | int ff_vvc_merge_subblock_idx(VVCLocalContext *lc, const int max_num_subblock_merge_cand) | |
1369 | { | ||
1370 | int i; | ||
1371 |
2/2✓ Branch 1 taken 29760 times.
✓ Branch 2 taken 19062 times.
|
48822 | if (!GET_CABAC(MERGE_SUBBLOCK_IDX)) |
1372 | 29760 | return 0; | |
1373 |
4/4✓ Branch 0 taken 32589 times.
✓ Branch 1 taken 1777 times.
✓ Branch 3 taken 15304 times.
✓ Branch 4 taken 17285 times.
|
34366 | for (i = 1; i < max_num_subblock_merge_cand - 1 && get_cabac_bypass(&lc->ep->cc); i++) |
1374 | /* nothing */; | ||
1375 | 19062 | return i; | |
1376 | } | ||
1377 | |||
1378 | 215698 | int ff_vvc_regular_merge_flag(VVCLocalContext *lc, const int cu_skip_flag) | |
1379 | { | ||
1380 | 215698 | int inc = !cu_skip_flag; | |
1381 | 215698 | return GET_CABAC(REGULAR_MERGE_FLAG + inc); | |
1382 | } | ||
1383 | |||
1384 | 250158 | int ff_vvc_mmvd_merge_flag(VVCLocalContext *lc) | |
1385 | { | ||
1386 | 250158 | return GET_CABAC(MMVD_MERGE_FLAG); | |
1387 | } | ||
1388 | |||
1389 | 54381 | int ff_vvc_mmvd_cand_flag(VVCLocalContext *lc) | |
1390 | { | ||
1391 | 54381 | return GET_CABAC(MMVD_CAND_FLAG); | |
1392 | } | ||
1393 | |||
1394 | 54381 | static int mmvd_distance_idx_decode(VVCLocalContext *lc) | |
1395 | { | ||
1396 | int i; | ||
1397 |
2/2✓ Branch 1 taken 14303 times.
✓ Branch 2 taken 40078 times.
|
54381 | if (!GET_CABAC(MMVD_DISTANCE_IDX)) |
1398 | 14303 | return 0; | |
1399 |
4/4✓ Branch 0 taken 75686 times.
✓ Branch 1 taken 5 times.
✓ Branch 3 taken 35613 times.
✓ Branch 4 taken 40073 times.
|
75691 | for (i = 1; i < 7 && get_cabac_bypass(&lc->ep->cc); i++) |
1400 | /* nothing */; | ||
1401 | 40078 | return i; | |
1402 | } | ||
1403 | |||
1404 | 54381 | static int mmvd_direction_idx_decode(VVCLocalContext *lc) | |
1405 | { | ||
1406 | 54381 | return (get_cabac_bypass(&lc->ep->cc) << 1) | get_cabac_bypass(&lc->ep->cc); | |
1407 | } | ||
1408 | |||
1409 | 54381 | void ff_vvc_mmvd_offset_coding(VVCLocalContext *lc, Mv *mmvd_offset, const int ph_mmvd_fullpel_only_flag) | |
1410 | { | ||
1411 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 54381 times.
|
54381 | const int shift = ph_mmvd_fullpel_only_flag ? 4 : 2; |
1412 | 54381 | const int mmvd_distance = 1 << (mmvd_distance_idx_decode(lc) + shift); | |
1413 | 54381 | const int mmvd_direction_idx = mmvd_direction_idx_decode(lc); | |
1414 | 54381 | const int mmvd_signs[][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} }; | |
1415 | 54381 | mmvd_offset->x = mmvd_distance * mmvd_signs[mmvd_direction_idx][0]; | |
1416 | 54381 | mmvd_offset->y = mmvd_distance * mmvd_signs[mmvd_direction_idx][1]; | |
1417 | 54381 | } | |
1418 | |||
1419 | 216458 | static PredMode get_luma_pred_mode(VVCLocalContext *lc) | |
1420 | { | ||
1421 | 216458 | const VVCFrameContext *fc = lc->fc; | |
1422 | 216458 | const CodingUnit *cu = lc->cu; | |
1423 | PredMode pred_mode; | ||
1424 | |||
1425 |
1/2✓ Branch 0 taken 216458 times.
✗ Branch 1 not taken.
|
216458 | if (cu->tree_type != DUAL_TREE_CHROMA) { |
1426 | 216458 | pred_mode = cu->pred_mode; | |
1427 | } else { | ||
1428 | ✗ | const int x_cb = cu->x0 >> fc->ps.sps->min_cb_log2_size_y; | |
1429 | ✗ | const int y_cb = cu->y0 >> fc->ps.sps->min_cb_log2_size_y; | |
1430 | ✗ | const int min_cb_width = fc->ps.pps->min_cb_width; | |
1431 | ✗ | pred_mode = SAMPLE_CTB(fc->tab.cpm[0], x_cb, y_cb); | |
1432 | } | ||
1433 | 216458 | return pred_mode; | |
1434 | } | ||
1435 | |||
1436 | 216458 | int ff_vvc_merge_idx(VVCLocalContext *lc) | |
1437 | { | ||
1438 | 216458 | const VVCSPS *sps = lc->fc->ps.sps; | |
1439 | 216458 | const int is_ibc = get_luma_pred_mode(lc) == MODE_IBC; | |
1440 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 216458 times.
|
216458 | const int c_max = (is_ibc ? sps->max_num_ibc_merge_cand : sps->max_num_merge_cand) - 1; |
1441 | int i; | ||
1442 | |||
1443 |
2/2✓ Branch 1 taken 128088 times.
✓ Branch 2 taken 88370 times.
|
216458 | if (!GET_CABAC(MERGE_IDX)) |
1444 | 128088 | return 0; | |
1445 | |||
1446 |
4/4✓ Branch 0 taken 170934 times.
✓ Branch 1 taken 9063 times.
✓ Branch 3 taken 91627 times.
✓ Branch 4 taken 79307 times.
|
179997 | for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++) |
1447 | /* nothing */; | ||
1448 | 88370 | return i; | |
1449 | } | ||
1450 | |||
1451 | 24737 | int ff_vvc_merge_gpm_partition_idx(VVCLocalContext *lc) | |
1452 | { | ||
1453 | 24737 | int i = 0; | |
1454 | |||
1455 |
2/2✓ Branch 0 taken 148422 times.
✓ Branch 1 taken 24737 times.
|
173159 | for (int j = 0; j < 6; j++) |
1456 | 148422 | i = (i << 1) | get_cabac_bypass(&lc->ep->cc); | |
1457 | |||
1458 | 24737 | return i; | |
1459 | } | ||
1460 | |||
1461 | 49474 | int ff_vvc_merge_gpm_idx(VVCLocalContext *lc, const int idx) | |
1462 | { | ||
1463 | 49474 | const int c_max = lc->fc->ps.sps->max_num_gpm_merge_cand - idx - 1; | |
1464 | int i; | ||
1465 | |||
1466 |
2/2✓ Branch 1 taken 27851 times.
✓ Branch 2 taken 21623 times.
|
49474 | if (!GET_CABAC(MERGE_IDX)) |
1467 | 27851 | return 0; | |
1468 | |||
1469 |
4/4✓ Branch 0 taken 37385 times.
✓ Branch 1 taken 3577 times.
✓ Branch 3 taken 19339 times.
✓ Branch 4 taken 18046 times.
|
40962 | for (i = 1; i < c_max && get_cabac_bypass(&lc->ep->cc); i++) |
1470 | /* nothing */; | ||
1471 | |||
1472 | 21623 | return i; | |
1473 | } | ||
1474 | |||
1475 | 18681 | int ff_vvc_ciip_flag(VVCLocalContext *lc) | |
1476 | { | ||
1477 | 18681 | return GET_CABAC(CIIP_FLAG); | |
1478 | } | ||
1479 | |||
1480 | 59578 | PredFlag ff_vvc_pred_flag(VVCLocalContext *lc, const int is_b) | |
1481 | { | ||
1482 | 59578 | const int w = lc->cu->cb_width; | |
1483 | 59578 | const int h = lc->cu->cb_height; | |
1484 |
2/2✓ Branch 0 taken 1938 times.
✓ Branch 1 taken 57640 times.
|
59578 | if (!is_b) |
1485 | 1938 | return PF_L0; | |
1486 |
2/2✓ Branch 0 taken 52067 times.
✓ Branch 1 taken 5573 times.
|
57640 | if (w + h > 12) { |
1487 | 52067 | const int log2 = av_log2(w) + av_log2(h); | |
1488 | 52067 | const int inc = 7 - ((1 + log2)>>1); | |
1489 |
2/2✓ Branch 1 taken 17911 times.
✓ Branch 2 taken 34156 times.
|
52067 | if (GET_CABAC(INTER_PRED_IDC + inc)) |
1490 | 17911 | return PF_BI; | |
1491 | } | ||
1492 | 39729 | return PF_L0 + GET_CABAC(INTER_PRED_IDC + 5); | |
1493 | } | ||
1494 | |||
1495 | 26349 | int ff_vvc_inter_affine_flag(VVCLocalContext *lc) | |
1496 | { | ||
1497 | 26349 | const int inc = get_inter_flag_inc(lc, lc->cu->x0, lc->cu->y0); | |
1498 | 26349 | return GET_CABAC(INTER_AFFINE_FLAG + inc); | |
1499 | } | ||
1500 | |||
1501 | 9109 | int ff_vvc_cu_affine_type_flag(VVCLocalContext *lc) | |
1502 | { | ||
1503 | 9109 | return GET_CABAC(CU_AFFINE_TYPE_FLAG); | |
1504 | } | ||
1505 | |||
1506 | 11430 | int ff_vvc_sym_mvd_flag(VVCLocalContext *lc) | |
1507 | { | ||
1508 | 11430 | return GET_CABAC(SYM_MVD_FLAG); | |
1509 | } | ||
1510 | |||
1511 | 49376 | int ff_vvc_ref_idx_lx(VVCLocalContext *lc, const uint8_t nb_refs) | |
1512 | { | ||
1513 | 49376 | const int c_max = nb_refs - 1; | |
1514 | 49376 | const int max_ctx = FFMIN(c_max, 2); | |
1515 | 49376 | int i = 0; | |
1516 | |||
1517 |
4/4✓ Branch 0 taken 50370 times.
✓ Branch 1 taken 10860 times.
✓ Branch 3 taken 11854 times.
✓ Branch 4 taken 38516 times.
|
61230 | while (i < max_ctx && GET_CABAC(REF_IDX_LX + i)) |
1518 | 11854 | i++; | |
1519 |
2/2✓ Branch 0 taken 654 times.
✓ Branch 1 taken 48722 times.
|
49376 | if (i == 2) { |
1520 |
4/4✓ Branch 0 taken 547 times.
✓ Branch 1 taken 470 times.
✓ Branch 3 taken 363 times.
✓ Branch 4 taken 184 times.
|
1017 | while (i < c_max && get_cabac_bypass(&lc->ep->cc)) |
1521 | 363 | i++; | |
1522 | } | ||
1523 | 49376 | return i; | |
1524 | } | ||
1525 | |||
1526 | 167130 | int ff_vvc_abs_mvd_greater0_flag(VVCLocalContext *lc) | |
1527 | { | ||
1528 | 167130 | return GET_CABAC(ABS_MVD_GREATER0_FLAG); | |
1529 | } | ||
1530 | |||
1531 | 116621 | int ff_vvc_abs_mvd_greater1_flag(VVCLocalContext *lc) | |
1532 | { | ||
1533 | 116621 | return GET_CABAC(ABS_MVD_GREATER1_FLAG); | |
1534 | } | ||
1535 | |||
1536 | 68543 | int ff_vvc_abs_mvd_minus2(VVCLocalContext *lc) | |
1537 | { | ||
1538 | 68543 | return limited_kth_order_egk_decode(&lc->ep->cc, 1, 15, 17); | |
1539 | } | ||
1540 | |||
1541 | 116621 | int ff_vvc_mvd_sign_flag(VVCLocalContext *lc) | |
1542 | { | ||
1543 | 116621 | return get_cabac_bypass(&lc->ep->cc); | |
1544 | } | ||
1545 | |||
1546 | 77489 | int ff_vvc_mvp_lx_flag(VVCLocalContext *lc) | |
1547 | { | ||
1548 | 77489 | return GET_CABAC(MVP_LX_FLAG); | |
1549 | } | ||
1550 | |||
1551 | 53921 | static int amvr_flag(VVCLocalContext *lc, const int inter_affine_flag) | |
1552 | { | ||
1553 | 53921 | return GET_CABAC(AMVR_FLAG + inter_affine_flag); | |
1554 | } | ||
1555 | |||
1556 | 32915 | static int amvr_precision_idx(VVCLocalContext *lc, const int inc, const int c_max) | |
1557 | { | ||
1558 | 32915 | int i = 0; | |
1559 |
2/2✓ Branch 1 taken 7266 times.
✓ Branch 2 taken 25649 times.
|
32915 | if (!GET_CABAC(AMVR_PRECISION_IDX + inc)) |
1560 | 7266 | return 0; | |
1561 | 25649 | i++; | |
1562 |
4/4✓ Branch 0 taken 22096 times.
✓ Branch 1 taken 3553 times.
✓ Branch 3 taken 3590 times.
✓ Branch 4 taken 18506 times.
|
25649 | if (i < c_max && GET_CABAC(AMVR_PRECISION_IDX + 1)) |
1563 | 3590 | i++; | |
1564 | 25649 | return i; | |
1565 | } | ||
1566 | |||
1567 | 60656 | int ff_vvc_amvr_shift(VVCLocalContext *lc, const int inter_affine_flag, | |
1568 | const PredMode pred_mode, const int has_amvr_flag) | ||
1569 | { | ||
1570 | 60656 | int amvr_shift = 2; | |
1571 |
2/2✓ Branch 0 taken 54999 times.
✓ Branch 1 taken 5657 times.
|
60656 | if (has_amvr_flag) { |
1572 |
4/4✓ Branch 0 taken 53921 times.
✓ Branch 1 taken 1078 times.
✓ Branch 3 taken 31837 times.
✓ Branch 4 taken 22084 times.
|
54999 | if (pred_mode == MODE_IBC || amvr_flag(lc, inter_affine_flag)) { |
1573 | int idx; | ||
1574 |
2/2✓ Branch 0 taken 3666 times.
✓ Branch 1 taken 29249 times.
|
32915 | if (inter_affine_flag) { |
1575 | 3666 | idx = amvr_precision_idx(lc, 2, 1); | |
1576 | 3666 | amvr_shift = idx * 4; | |
1577 |
2/2✓ Branch 0 taken 1078 times.
✓ Branch 1 taken 28171 times.
|
29249 | } else if (pred_mode == MODE_IBC) { |
1578 | 1078 | idx = amvr_precision_idx(lc, 1, 1); | |
1579 | 1078 | amvr_shift = 4 + idx * 2; | |
1580 | } else { | ||
1581 | static const int shifts[] = {3, 4, 6}; | ||
1582 | 28171 | idx = amvr_precision_idx(lc, 0, 2); | |
1583 | 28171 | amvr_shift = shifts[idx]; | |
1584 | } | ||
1585 | } | ||
1586 | } | ||
1587 | 60656 | return amvr_shift; | |
1588 | } | ||
1589 | |||
1590 | 11078 | int ff_vvc_bcw_idx(VVCLocalContext *lc, const int no_backward_pred_flag) | |
1591 | { | ||
1592 |
2/2✓ Branch 0 taken 2374 times.
✓ Branch 1 taken 8704 times.
|
11078 | const int c_max = no_backward_pred_flag ? 4 : 2; |
1593 | 11078 | int i = 1; | |
1594 |
2/2✓ Branch 1 taken 6514 times.
✓ Branch 2 taken 4564 times.
|
11078 | if (!GET_CABAC(BCW_IDX)) |
1595 | 6514 | return 0; | |
1596 |
4/4✓ Branch 0 taken 5364 times.
✓ Branch 1 taken 1785 times.
✓ Branch 3 taken 2585 times.
✓ Branch 4 taken 2779 times.
|
7149 | while (i < c_max && get_cabac_bypass(&lc->ep->cc)) |
1597 | 2585 | i++; | |
1598 | 4564 | return i; | |
1599 | } | ||
1600 | |||
1601 | 340077 | int ff_vvc_tu_cb_coded_flag(VVCLocalContext *lc) | |
1602 | { | ||
1603 | 340077 | return GET_CABAC(TU_CB_CODED_FLAG + lc->cu->bdpcm_flag[1]); | |
1604 | } | ||
1605 | |||
1606 | 340077 | int ff_vvc_tu_cr_coded_flag(VVCLocalContext *lc, int tu_cb_coded_flag) | |
1607 | { | ||
1608 |
2/2✓ Branch 0 taken 340074 times.
✓ Branch 1 taken 3 times.
|
340077 | return GET_CABAC(TU_CR_CODED_FLAG + (lc->cu->bdpcm_flag[1] ? 2 : tu_cb_coded_flag)); |
1609 | } | ||
1610 | |||
1611 | 713105 | int ff_vvc_tu_y_coded_flag(VVCLocalContext *lc) | |
1612 | { | ||
1613 | 713105 | const CodingUnit *cu = lc->cu; | |
1614 | int inc; | ||
1615 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 713067 times.
|
713105 | if (cu->bdpcm_flag[0]) |
1616 | 38 | inc = 1; | |
1617 |
2/2✓ Branch 0 taken 522809 times.
✓ Branch 1 taken 190258 times.
|
713067 | else if (cu->isp_split_type == ISP_NO_SPLIT) |
1618 | 522809 | inc = 0; | |
1619 | else | ||
1620 | 190258 | inc = 2 + lc->parse.prev_tu_cbf_y; | |
1621 | 713105 | lc->parse.prev_tu_cbf_y = GET_CABAC(TU_Y_CODED_FLAG + inc); | |
1622 | 713105 | return lc->parse.prev_tu_cbf_y; | |
1623 | } | ||
1624 | |||
1625 | 859 | int ff_vvc_cu_qp_delta_abs(VVCLocalContext *lc) | |
1626 | { | ||
1627 | int v, i, k; | ||
1628 |
2/2✓ Branch 1 taken 669 times.
✓ Branch 2 taken 190 times.
|
859 | if (!GET_CABAC(CU_QP_DELTA_ABS)) |
1629 | 669 | return 0; | |
1630 | |||
1631 | // prefixVal | ||
1632 |
4/4✓ Branch 0 taken 269 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 82 times.
✓ Branch 4 taken 187 times.
|
272 | for (v = 1; v < 5 && GET_CABAC(CU_QP_DELTA_ABS + 1); v++) |
1633 | /* nothing */; | ||
1634 |
2/2✓ Branch 0 taken 187 times.
✓ Branch 1 taken 3 times.
|
190 | if (v < 5) |
1635 | 187 | return v; | |
1636 | |||
1637 | // 9.3.3.5 k-th order Exp-Golomb binarization process | ||
1638 | // suffixVal | ||
1639 | |||
1640 | // CuQpDeltaVal shall in the range of −( 32 + QpBdOffset / 2 ) to +( 31 + QpBdOffset / 2 ) | ||
1641 | // so k = 6 should enough | ||
1642 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
|
3 | for (k = 0; k < 6 && get_cabac_bypass(&lc->ep->cc); k++) |
1643 | /* nothing */; | ||
1644 | 3 | i = (1 << k) - 1; | |
1645 | 3 | v = 0; | |
1646 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | while (k--) |
1647 | ✗ | v = (v << 1) + get_cabac_bypass(&lc->ep->cc); | |
1648 | 3 | v += i; | |
1649 | |||
1650 | 3 | return v + 5; | |
1651 | } | ||
1652 | |||
1653 | 190 | int ff_vvc_cu_qp_delta_sign_flag(VVCLocalContext *lc) | |
1654 | { | ||
1655 | 190 | return get_cabac_bypass(&lc->ep->cc); | |
1656 | } | ||
1657 | |||
1658 | ✗ | int ff_vvc_cu_chroma_qp_offset_flag(VVCLocalContext *lc) | |
1659 | { | ||
1660 | ✗ | return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG); | |
1661 | } | ||
1662 | |||
1663 | ✗ | int ff_vvc_cu_chroma_qp_offset_idx(VVCLocalContext *lc) | |
1664 | { | ||
1665 | ✗ | const int c_max = lc->fc->ps.pps->r->pps_chroma_qp_offset_list_len_minus1; | |
1666 | int i; | ||
1667 | ✗ | for (i = 0; i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX); i++) | |
1668 | /* nothing */; | ||
1669 | ✗ | return i; | |
1670 | } | ||
1671 | |||
1672 | 1669244 | static av_always_inline int last_significant_coeff_xy_prefix(VVCLocalContext *lc, | |
1673 | const int log2_tb_size, const int log2_zo_tb_size, const int c_idx, const int ctx) | ||
1674 | { | ||
1675 | 1669244 | int i = 0; | |
1676 | 1669244 | int max = (log2_zo_tb_size << 1) - 1; | |
1677 | int ctx_offset, ctx_shift; | ||
1678 |
2/2✓ Branch 0 taken 15823 times.
✓ Branch 1 taken 1653421 times.
|
1669244 | if (!log2_tb_size) |
1679 | 15823 | return 0; | |
1680 |
2/2✓ Branch 0 taken 1257327 times.
✓ Branch 1 taken 396094 times.
|
1653421 | if (!c_idx) { |
1681 | 1257327 | const int offset_y[] = {0, 0, 3, 6, 10, 15}; | |
1682 | 1257327 | ctx_offset = offset_y[log2_tb_size - 1]; | |
1683 | 1257327 | ctx_shift = (log2_tb_size + 1) >> 2; | |
1684 | } else { | ||
1685 | 396094 | const int shifts[] = {0, 0, 0, 1, 2, 2, 2}; | |
1686 | 396094 | ctx_offset = 20; | |
1687 | 396094 | ctx_shift = shifts[log2_tb_size]; | |
1688 | } | ||
1689 |
4/4✓ Branch 0 taken 4392416 times.
✓ Branch 1 taken 251772 times.
✓ Branch 3 taken 2990767 times.
✓ Branch 4 taken 1401649 times.
|
4644188 | while (i < max && GET_CABAC(ctx + (i >> ctx_shift) + ctx_offset)) |
1690 | 2990767 | i++; | |
1691 | 1653421 | return i; | |
1692 | } | ||
1693 | |||
1694 | 834622 | static av_always_inline int last_significant_coeff_x_prefix_decode(VVCLocalContext *lc, | |
1695 | const int log2_tb_width, const int log2_zo_tb_width, const int c_idx) | ||
1696 | { | ||
1697 | 834622 | return last_significant_coeff_xy_prefix(lc, log2_tb_width, log2_zo_tb_width, c_idx, LAST_SIG_COEFF_X_PREFIX); | |
1698 | } | ||
1699 | |||
1700 | 834622 | static av_always_inline int last_significant_coeff_y_prefix_decode(VVCLocalContext *lc, | |
1701 | const int log2_tb_height, const int log2_zo_tb_height, const int c_idx) | ||
1702 | { | ||
1703 | 834622 | return last_significant_coeff_xy_prefix(lc, log2_tb_height, log2_zo_tb_height, c_idx, LAST_SIG_COEFF_Y_PREFIX); | |
1704 | } | ||
1705 | |||
1706 | 328602 | static av_always_inline int last_sig_coeff_suffix_decode(VVCLocalContext *lc, | |
1707 | const int last_significant_coeff_y_prefix) | ||
1708 | { | ||
1709 | 328602 | const int length = (last_significant_coeff_y_prefix >> 1) - 1; | |
1710 | 328602 | int value = get_cabac_bypass(&lc->ep->cc); | |
1711 | |||
1712 |
2/2✓ Branch 0 taken 127995 times.
✓ Branch 1 taken 328602 times.
|
456597 | for (int i = 1; i < length; i++) |
1713 | 127995 | value = (value << 1) | get_cabac_bypass(&lc->ep->cc); | |
1714 | 328602 | return value; | |
1715 | } | ||
1716 | |||
1717 | 112278 | int ff_vvc_tu_joint_cbcr_residual_flag(VVCLocalContext *lc, const int tu_cb_coded_flag, const int tu_cr_coded_flag) | |
1718 | { | ||
1719 | 112278 | return GET_CABAC(TU_JOINT_CBCR_RESIDUAL_FLAG + 2 * tu_cb_coded_flag + tu_cr_coded_flag - 1); | |
1720 | } | ||
1721 | |||
1722 | 636882 | int ff_vvc_transform_skip_flag(VVCLocalContext *lc, const int inc) | |
1723 | { | ||
1724 | 636882 | return GET_CABAC(TRANSFORM_SKIP_FLAG + inc); | |
1725 | } | ||
1726 | |||
1727 | //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1 | ||
1728 | 34775836 | static int get_local_sum(const int *level, const int w, const int h, | |
1729 | const int xc, const int yc, const int hist_value) | ||
1730 | { | ||
1731 | 34775836 | int loc_sum = 3 * hist_value; | |
1732 | 34775836 | level += w * yc + xc; | |
1733 |
2/2✓ Branch 0 taken 33451008 times.
✓ Branch 1 taken 1324828 times.
|
34775836 | if (xc < w - 1) { |
1734 | 33451008 | loc_sum += level[1]; | |
1735 |
2/2✓ Branch 0 taken 31533547 times.
✓ Branch 1 taken 1917461 times.
|
33451008 | if (xc < w - 2) |
1736 | 31533547 | loc_sum += level[2] - hist_value; | |
1737 |
2/2✓ Branch 0 taken 30871932 times.
✓ Branch 1 taken 2579076 times.
|
33451008 | if (yc < h - 1) |
1738 | 30871932 | loc_sum += level[w + 1] - hist_value; | |
1739 | } | ||
1740 |
2/2✓ Branch 0 taken 32196619 times.
✓ Branch 1 taken 2579217 times.
|
34775836 | if (yc < h - 1) { |
1741 | 32196619 | loc_sum += level[w]; | |
1742 |
2/2✓ Branch 0 taken 29176080 times.
✓ Branch 1 taken 3020539 times.
|
32196619 | if (yc < h - 2) |
1743 | 29176080 | loc_sum += level[w << 1] - hist_value; | |
1744 | } | ||
1745 | 34775836 | return loc_sum; | |
1746 | } | ||
1747 | |||
1748 | //9.3.4.2.7 Derivation process for the variables locNumSig, locSumAbsPass1 | ||
1749 | 897048 | static int get_local_sum_ts(const int *level, const int w, const int h, const int xc, const int yc) | |
1750 | { | ||
1751 | 897048 | int loc_sum = 0; | |
1752 | 897048 | level += w * yc + xc; | |
1753 |
2/2✓ Branch 0 taken 785022 times.
✓ Branch 1 taken 112026 times.
|
897048 | if (xc > 0) |
1754 | 785022 | loc_sum += level[-1]; | |
1755 |
2/2✓ Branch 0 taken 784835 times.
✓ Branch 1 taken 112213 times.
|
897048 | if (yc > 0) |
1756 | 784835 | loc_sum += level[-w]; | |
1757 | 897048 | return loc_sum; | |
1758 | } | ||
1759 | |||
1760 | 9908971 | static int get_gtx_flag_inc(const ResidualCoding* rc, const int xc, const int yc, const int last) | |
1761 | { | ||
1762 | 9908971 | const TransformBlock *tb = rc->tb; | |
1763 | int inc; | ||
1764 |
2/2✓ Branch 0 taken 834622 times.
✓ Branch 1 taken 9074349 times.
|
9908971 | if (last) { |
1765 | 834622 | const int incs[] = {0, 21, 21}; | |
1766 | 834622 | inc = incs[tb->c_idx]; | |
1767 | } else { | ||
1768 | 9074349 | const int d = xc + yc; | |
1769 | 9074349 | const int local_sum_sig = get_local_sum(rc->sig_coeff_flag, | |
1770 | 9074349 | tb->tb_width,tb->tb_height, xc, yc, rc->hist_value); | |
1771 | 9074349 | const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1, | |
1772 | 9074349 | tb->tb_width, tb->tb_height, xc, yc, rc->hist_value); | |
1773 | 9074349 | const int offset = FFMIN(loc_sum_abs_pass1 - local_sum_sig, 4); | |
1774 | |||
1775 |
2/2✓ Branch 0 taken 6702751 times.
✓ Branch 1 taken 2371598 times.
|
9074349 | if (!tb->c_idx) |
1776 |
6/6✓ Branch 0 taken 6265334 times.
✓ Branch 1 taken 437417 times.
✓ Branch 2 taken 4888888 times.
✓ Branch 3 taken 1376446 times.
✓ Branch 4 taken 3137799 times.
✓ Branch 5 taken 1751089 times.
|
6702751 | inc = 1 + offset + (!d ? 15 : (d < 3 ? 10 : (d < 10 ? 5 : 0))); |
1777 | else | ||
1778 |
2/2✓ Branch 0 taken 124523 times.
✓ Branch 1 taken 2247075 times.
|
2371598 | inc = 22 + offset + (!d ? 5 : 0); |
1779 | } | ||
1780 | 9908971 | return inc; | |
1781 | } | ||
1782 | |||
1783 | 11632064 | static int abs_level_gtx_flag_decode(VVCLocalContext *lc, const int inc) | |
1784 | { | ||
1785 | 11632064 | return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc); | |
1786 | } | ||
1787 | |||
1788 | 1723093 | static int par_level_flag_decode(VVCLocalContext *lc, const int inc) | |
1789 | { | ||
1790 | 1723093 | return GET_CABAC(PAR_LEVEL_FLAG + inc); | |
1791 | } | ||
1792 | |||
1793 | 90239 | static int par_level_flag_ts_decode(VVCLocalContext *lc) | |
1794 | { | ||
1795 | 90239 | const int inc = 32; | |
1796 | 90239 | return GET_CABAC(PAR_LEVEL_FLAG + inc); | |
1797 | } | ||
1798 | |||
1799 | 870105 | static int sb_coded_flag_decode(VVCLocalContext *lc, const uint8_t *sb_coded_flag, | |
1800 | const ResidualCoding *rc, const int xs, const int ys) | ||
1801 | { | ||
1802 | 870105 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
1803 | 870105 | const TransformBlock *tb = rc->tb; | |
1804 | 870105 | const int w = rc->width_in_sbs; | |
1805 | 870105 | const int h = rc->height_in_sbs; | |
1806 | int inc; | ||
1807 | |||
1808 |
3/4✓ Branch 0 taken 131724 times.
✓ Branch 1 taken 738381 times.
✓ Branch 2 taken 131724 times.
✗ Branch 3 not taken.
|
870105 | if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) { |
1809 |
2/2✓ Branch 0 taken 79727 times.
✓ Branch 1 taken 51997 times.
|
131724 | const int left = xs > 0 ? sb_coded_flag[-1] : 0; |
1810 |
2/2✓ Branch 0 taken 79708 times.
✓ Branch 1 taken 52016 times.
|
131724 | const int above = ys > 0 ? sb_coded_flag[-w] : 0; |
1811 | 131724 | inc = left + above + 4; | |
1812 | } else { | ||
1813 |
2/2✓ Branch 0 taken 633660 times.
✓ Branch 1 taken 104721 times.
|
738381 | const int right = (xs < w - 1) ? sb_coded_flag[1] : 0; |
1814 |
2/2✓ Branch 0 taken 534831 times.
✓ Branch 1 taken 203550 times.
|
738381 | const int bottom = (ys < h - 1) ? sb_coded_flag[w] : 0; |
1815 |
2/2✓ Branch 0 taken 271539 times.
✓ Branch 1 taken 466842 times.
|
738381 | inc = (right | bottom) + (tb->c_idx ? 2 : 0); |
1816 | } | ||
1817 | 870105 | return GET_CABAC(SB_CODED_FLAG + inc); | |
1818 | } | ||
1819 | |||
1820 | 16953808 | static int sig_coeff_flag_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc) | |
1821 | { | ||
1822 | 16953808 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
1823 | 16953808 | const TransformBlock *tb = rc->tb; | |
1824 | int inc; | ||
1825 | |||
1826 |
3/4✓ Branch 0 taken 897048 times.
✓ Branch 1 taken 16056760 times.
✓ Branch 2 taken 897048 times.
✗ Branch 3 not taken.
|
16953808 | if (tb->ts && !rsh->sh_ts_residual_coding_disabled_flag) { |
1827 | 897048 | const int local_num_sig = get_local_sum_ts(rc->sig_coeff_flag, tb->tb_width, tb->tb_height, xc, yc); | |
1828 | 897048 | inc = 60 + local_num_sig; | |
1829 | } else { | ||
1830 | 16056760 | const int d = xc + yc; | |
1831 | 16056760 | const int loc_sum_abs_pass1 = get_local_sum(rc->abs_level_pass1, | |
1832 | 16056760 | tb->tb_width, tb->tb_height, xc, yc, 0); | |
1833 | |||
1834 |
2/2✓ Branch 0 taken 11637577 times.
✓ Branch 1 taken 4419183 times.
|
16056760 | if (!tb->c_idx) { |
1835 |
4/4✓ Branch 0 taken 10279811 times.
✓ Branch 1 taken 1357766 times.
✓ Branch 2 taken 3093900 times.
✓ Branch 3 taken 7185911 times.
|
11637577 | inc = 12 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + ((d < 2) ? 8 : (d < 5 ? 4 : 0)); |
1836 | } else { | ||
1837 |
2/2✓ Branch 0 taken 399371 times.
✓ Branch 1 taken 4019812 times.
|
4419183 | inc = 36 + 8 * FFMAX(0, rc->qstate - 1) + FFMIN((loc_sum_abs_pass1 + 1) >> 1, 3) + (d < 2 ? 4 : 0); |
1838 | } | ||
1839 | } | ||
1840 | 16953808 | return GET_CABAC(SIG_COEFF_FLAG + inc); | |
1841 | } | ||
1842 | |||
1843 | 570378 | static int abs_get_rice_param(VVCLocalContext *lc, const ResidualCoding* rc, | |
1844 | const int xc, const int yc, const int base_level) | ||
1845 | { | ||
1846 | 570378 | const VVCSPS *sps = lc->fc->ps.sps; | |
1847 | 570378 | const TransformBlock* tb = rc->tb; | |
1848 | 570378 | const int rice_params[] = { | |
1849 | 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, | ||
1850 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, | ||
1851 | }; | ||
1852 | int loc_sum_abs; | ||
1853 | int shift_val; | ||
1854 | |||
1855 | 570378 | loc_sum_abs = get_local_sum(rc->abs_level, tb->tb_width, tb->tb_height, xc, | |
1856 | 570378 | yc, rc->hist_value); | |
1857 | |||
1858 |
1/2✓ Branch 0 taken 570378 times.
✗ Branch 1 not taken.
|
570378 | if (!sps->r->sps_rrc_rice_extension_flag) { |
1859 | 570378 | shift_val = 0; | |
1860 | } else { | ||
1861 | ✗ | shift_val = (av_log2(FFMAX(FFMIN(loc_sum_abs, 2048), 8)) - 3) & ~1; | |
1862 | } | ||
1863 | |||
1864 | 570378 | loc_sum_abs = av_clip_uintp2((loc_sum_abs >> shift_val) - base_level * 5, 5); | |
1865 | |||
1866 | 570378 | return rice_params[loc_sum_abs] + shift_val; | |
1867 | } | ||
1868 | |||
1869 | 621045 | static int abs_decode(VVCLocalContext *lc, const int c_rice_param) | |
1870 | { | ||
1871 | 621045 | const VVCSPS *sps = lc->fc->ps.sps; | |
1872 | 621045 | const int MAX_BIN = 6; | |
1873 | 621045 | int prefix = 0; | |
1874 | 621045 | int suffix = 0; | |
1875 | |||
1876 |
4/4✓ Branch 0 taken 1210336 times.
✓ Branch 1 taken 14715 times.
✓ Branch 3 taken 604006 times.
✓ Branch 4 taken 606330 times.
|
1225051 | while (prefix < MAX_BIN && get_cabac_bypass(&lc->ep->cc)) |
1877 | 604006 | prefix++; | |
1878 |
2/2✓ Branch 0 taken 606330 times.
✓ Branch 1 taken 14715 times.
|
621045 | if (prefix < MAX_BIN) { |
1879 |
2/2✓ Branch 0 taken 327805 times.
✓ Branch 1 taken 606330 times.
|
934135 | for (int i = 0; i < c_rice_param; i++) { |
1880 | 327805 | suffix = (suffix << 1) | get_cabac_bypass(&lc->ep->cc); | |
1881 | } | ||
1882 | } else { | ||
1883 | 14715 | suffix = limited_kth_order_egk_decode(&lc->ep->cc, | |
1884 | c_rice_param + 1, | ||
1885 | 14715 | 26 - sps->log2_transform_range, | |
1886 | 14715 | sps->log2_transform_range); | |
1887 | } | ||
1888 | 621045 | return suffix + (prefix << c_rice_param); | |
1889 | } | ||
1890 | |||
1891 | 315475 | static int abs_remainder_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc) | |
1892 | { | ||
1893 | 315475 | const VVCSPS *sps = lc->fc->ps.sps; | |
1894 | 315475 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
1895 | 315475 | const int base_level[][2][2] = { | |
1896 | { {4, 4}, {4, 4} }, | ||
1897 | { {3, 2}, {2, 1} } | ||
1898 | }; | ||
1899 | 315475 | const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc, | |
1900 | 315475 | base_level[sps->r->sps_rrc_rice_extension_flag][sps->bit_depth > 12][IS_I(rsh)]); | |
1901 | 315475 | const int rem = abs_decode(lc, c_rice_param); | |
1902 | |||
1903 | 315475 | return rem; | |
1904 | } | ||
1905 | |||
1906 | 50667 | static int abs_remainder_ts_decode(VVCLocalContext *lc, const ResidualCoding* rc, const int xc, const int yc) | |
1907 | { | ||
1908 | 50667 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
1909 | 50667 | const int c_rice_param = rsh->sh_ts_residual_coding_rice_idx_minus1 + 1; | |
1910 | 50667 | const int rem = abs_decode(lc, c_rice_param); | |
1911 | |||
1912 | 50667 | return rem; | |
1913 | } | ||
1914 | |||
1915 | 10129588 | static int coeff_sign_flag_decode(VVCLocalContext *lc) | |
1916 | { | ||
1917 | 10129588 | return get_cabac_bypass(&lc->ep->cc); | |
1918 | } | ||
1919 | |||
1920 | //9.3.4.2.10 Derivation process of ctxInc for the syntax element coeff_sign_flag for transform skip mode | ||
1921 | 229595 | static int coeff_sign_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc) | |
1922 | { | ||
1923 | 229595 | const TransformBlock *tb = rc->tb; | |
1924 | 229595 | const int w = tb->tb_width; | |
1925 | 229595 | const int *level = rc->coeff_sign_level + yc * w + xc; | |
1926 |
2/2✓ Branch 0 taken 205387 times.
✓ Branch 1 taken 24208 times.
|
229595 | const int left_sign = xc ? level[-1] : 0; |
1927 |
2/2✓ Branch 0 taken 204811 times.
✓ Branch 1 taken 24784 times.
|
229595 | const int above_sign = yc ? level[-w] : 0; |
1928 | 229595 | const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx]; | |
1929 | int inc; | ||
1930 | |||
1931 |
2/2✓ Branch 0 taken 83291 times.
✓ Branch 1 taken 146304 times.
|
229595 | if (left_sign == -above_sign) |
1932 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 83272 times.
|
83291 | inc = bdpcm_flag ? 3 : 0; |
1933 |
4/4✓ Branch 0 taken 88811 times.
✓ Branch 1 taken 57493 times.
✓ Branch 2 taken 60312 times.
✓ Branch 3 taken 28499 times.
|
146304 | else if (left_sign >= 0 && above_sign >= 0) |
1934 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 60309 times.
|
60312 | inc = bdpcm_flag ? 4 : 1; |
1935 | else | ||
1936 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 85981 times.
|
85992 | inc = bdpcm_flag ? 5 : 2; |
1937 | 229595 | return GET_CABAC(COEFF_SIGN_FLAG + inc); | |
1938 | } | ||
1939 | |||
1940 | 229595 | static int abs_level_gt1_flag_ts_decode(VVCLocalContext *lc, const CodingUnit *cu, const ResidualCoding *rc, const int xc, const int yc) | |
1941 | { | ||
1942 | 229595 | const TransformBlock *tb = rc->tb; | |
1943 | 229595 | const int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc; | |
1944 | int inc; | ||
1945 | |||
1946 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 229562 times.
|
229595 | if (cu->bdpcm_flag[tb->c_idx]) { |
1947 | 33 | inc = 67; | |
1948 | } else { | ||
1949 |
2/2✓ Branch 0 taken 205356 times.
✓ Branch 1 taken 24206 times.
|
229562 | const int l = xc > 0 ? sig_coeff_flag[-1] : 0; |
1950 |
2/2✓ Branch 0 taken 204784 times.
✓ Branch 1 taken 24778 times.
|
229562 | const int a = yc > 0 ? sig_coeff_flag[-tb->tb_width] : 0; |
1951 | 229562 | inc = 64 + a + l; | |
1952 | } | ||
1953 | 229595 | return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc); | |
1954 | } | ||
1955 | |||
1956 | 162254 | static int abs_level_gtx_flag_ts_decode(VVCLocalContext *lc, const int j) | |
1957 | { | ||
1958 | 162254 | const int inc = 67 + j; | |
1959 | 162254 | return GET_CABAC(ABS_LEVEL_GTX_FLAG + inc); | |
1960 | } | ||
1961 | |||
1962 | static const uint8_t qstate_translate_table[][2] = { | ||
1963 | { 0, 2 }, { 2, 0 }, { 1, 3 }, { 3, 1 } | ||
1964 | }; | ||
1965 | |||
1966 | 254903 | static int dec_abs_level_decode(VVCLocalContext *lc, const ResidualCoding *rc, | |
1967 | const int xc, const int yc, int *abs_level) | ||
1968 | { | ||
1969 | 254903 | const int c_rice_param = abs_get_rice_param(lc, rc, xc, yc, 0); | |
1970 | 254903 | const int dec_abs_level = abs_decode(lc, c_rice_param); | |
1971 |
2/2✓ Branch 0 taken 137865 times.
✓ Branch 1 taken 117038 times.
|
254903 | const int zero_pos = (rc->qstate < 2 ? 1 : 2) << c_rice_param; |
1972 | |||
1973 | 254903 | *abs_level = 0; | |
1974 |
2/2✓ Branch 0 taken 231651 times.
✓ Branch 1 taken 23252 times.
|
254903 | if (dec_abs_level != zero_pos) { |
1975 | 231651 | *abs_level = dec_abs_level; | |
1976 |
2/2✓ Branch 0 taken 150928 times.
✓ Branch 1 taken 80723 times.
|
231651 | if (dec_abs_level < zero_pos) |
1977 | 150928 | *abs_level += 1; | |
1978 | } | ||
1979 | 254903 | return dec_abs_level; | |
1980 | } | ||
1981 | |||
1982 | 570378 | static void ep_update_hist(EntryPoint *ep, ResidualCoding *rc, | |
1983 | const int remainder, const int addin) | ||
1984 | { | ||
1985 | 570378 | int *stat = ep->stat_coeff + rc->tb->c_idx; | |
1986 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 570378 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
570378 | if (rc->update_hist && remainder > 0) { |
1987 | ✗ | *stat = (*stat + av_log2(remainder) + addin) >> 1; | |
1988 | ✗ | rc->update_hist = 0; | |
1989 | } | ||
1990 | 570378 | } | |
1991 | |||
1992 | 863219 | static void init_residual_coding(const VVCLocalContext *lc, ResidualCoding *rc, | |
1993 | const int log2_zo_tb_width, const int log2_zo_tb_height, | ||
1994 | TransformBlock *tb) | ||
1995 | { | ||
1996 | 863219 | const VVCSPS *sps = lc->fc->ps.sps; | |
1997 |
2/2✓ Branch 0 taken 77112 times.
✓ Branch 1 taken 786107 times.
|
863219 | int log2_sb_w = (FFMIN(log2_zo_tb_width, log2_zo_tb_height ) < 2 ? 1 : 2 ); |
1998 | 863219 | int log2_sb_h = log2_sb_w; | |
1999 | |||
2000 |
2/2✓ Branch 0 taken 861484 times.
✓ Branch 1 taken 1735 times.
|
863219 | if ( log2_zo_tb_width + log2_zo_tb_height > 3 ) { |
2001 |
2/2✓ Branch 0 taken 19423 times.
✓ Branch 1 taken 842061 times.
|
861484 | if ( log2_zo_tb_width < 2 ) { |
2002 | 19423 | log2_sb_w = log2_zo_tb_width; | |
2003 | 19423 | log2_sb_h = 4 - log2_sb_w; | |
2004 |
2/2✓ Branch 0 taken 55954 times.
✓ Branch 1 taken 786107 times.
|
842061 | } else if ( log2_zo_tb_height < 2 ) { |
2005 | 55954 | log2_sb_h = log2_zo_tb_height; | |
2006 | 55954 | log2_sb_w = 4 - log2_sb_h; | |
2007 | } | ||
2008 | } | ||
2009 | 863219 | rc->log2_sb_w = log2_sb_w; | |
2010 | 863219 | rc->log2_sb_h = log2_sb_h; | |
2011 | 863219 | rc->num_sb_coeff = 1 << (log2_sb_w + log2_sb_h); | |
2012 | 863219 | rc->last_sub_block = ( 1 << ( log2_zo_tb_width + log2_zo_tb_height - (log2_sb_w + log2_sb_h))) - 1; | |
2013 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 863219 times.
|
863219 | rc->hist_value = sps->r->sps_persistent_rice_adaptation_enabled_flag ? (1 << lc->ep->stat_coeff[tb->c_idx]) : 0; |
2014 | 863219 | rc->update_hist = sps->r->sps_persistent_rice_adaptation_enabled_flag ? 1 : 0; | |
2015 | 863219 | rc->rem_bins_pass1 = (( 1 << ( log2_zo_tb_width + log2_zo_tb_height)) * 7 ) >> 2; | |
2016 | |||
2017 | |||
2018 | 863219 | rc->sb_scan_x_off = ff_vvc_diag_scan_x[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h]; | |
2019 | 863219 | rc->sb_scan_y_off = ff_vvc_diag_scan_y[log2_zo_tb_width - log2_sb_w][log2_zo_tb_height - log2_sb_h]; | |
2020 | |||
2021 | 863219 | rc->scan_x_off = ff_vvc_diag_scan_x[log2_sb_w][log2_sb_h]; | |
2022 | 863219 | rc->scan_y_off = ff_vvc_diag_scan_y[log2_sb_w][log2_sb_h]; | |
2023 | |||
2024 | 863219 | rc->infer_sb_cbf = 1; | |
2025 | |||
2026 | 863219 | rc->width_in_sbs = (1 << (log2_zo_tb_width - log2_sb_w)); | |
2027 | 863219 | rc->height_in_sbs = (1 << (log2_zo_tb_height - log2_sb_h)); | |
2028 | 863219 | rc->nb_sbs = rc->width_in_sbs * rc->height_in_sbs; | |
2029 | |||
2030 | 863219 | rc->last_scan_pos = rc->num_sb_coeff; | |
2031 | 863219 | rc->qstate = 0; | |
2032 | |||
2033 | 863219 | rc->tb = tb; | |
2034 | 863219 | } | |
2035 | |||
2036 | 144825 | static int residual_ts_coding_subblock(VVCLocalContext *lc, ResidualCoding* rc, const int i) | |
2037 | { | ||
2038 | 144825 | const CodingUnit *cu = lc->cu; | |
2039 | 144825 | TransformBlock *tb = rc->tb; | |
2040 | 144825 | const int bdpcm_flag = cu->bdpcm_flag[tb->c_idx]; | |
2041 | 144825 | const int xs = rc->sb_scan_x_off[i]; | |
2042 | 144825 | const int ys = rc->sb_scan_y_off[i]; | |
2043 | 144825 | uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs; | |
2044 | 144825 | int infer_sb_sig_coeff_flag = 1; | |
2045 | 144825 | int last_scan_pos_pass1 = -1, last_scan_pos_pass2 = -1, n; | |
2046 | int abs_level_gtx_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; | ||
2047 | int abs_level_pass2[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; ///< AbsLevelPass2 | ||
2048 | |||
2049 |
4/4✓ Branch 0 taken 28597 times.
✓ Branch 1 taken 116228 times.
✓ Branch 2 taken 15496 times.
✓ Branch 3 taken 13101 times.
|
144825 | if (i != rc->last_sub_block || !rc->infer_sb_cbf) |
2050 | 131724 | *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys); | |
2051 | else | ||
2052 | 13101 | *sb_coded_flag = 1; | |
2053 |
4/4✓ Branch 0 taken 57490 times.
✓ Branch 1 taken 87335 times.
✓ Branch 2 taken 36938 times.
✓ Branch 3 taken 20552 times.
|
144825 | if (*sb_coded_flag && i < rc->last_sub_block) |
2054 | 36938 | rc->infer_sb_cbf = 0; | |
2055 | |||
2056 | //first scan pass | ||
2057 |
4/4✓ Branch 0 taken 2296588 times.
✓ Branch 1 taken 140893 times.
✓ Branch 2 taken 2292656 times.
✓ Branch 3 taken 3932 times.
|
2437481 | for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) { |
2058 | 2292656 | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; | |
2059 | 2292656 | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; | |
2060 | 2292656 | const int off = yc * tb->tb_width + xc; | |
2061 | 2292656 | int *sig_coeff_flag = rc->sig_coeff_flag + off; | |
2062 | 2292656 | int *abs_level_pass1 = rc->abs_level_pass1 + off; | |
2063 | 2292656 | int *coeff_sign_level = rc->coeff_sign_level + off; | |
2064 | 2292656 | int par_level_flag = 0; | |
2065 | |||
2066 | 2292656 | abs_level_gtx_flag[n] = 0; | |
2067 | 2292656 | last_scan_pos_pass1 = n; | |
2068 |
6/6✓ Branch 0 taken 900112 times.
✓ Branch 1 taken 1392544 times.
✓ Branch 2 taken 53850 times.
✓ Branch 3 taken 846262 times.
✓ Branch 4 taken 50786 times.
✓ Branch 5 taken 3064 times.
|
2292656 | if (*sb_coded_flag && (n != rc->num_sb_coeff - 1 || !infer_sb_sig_coeff_flag)) { |
2069 | 897048 | *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc); | |
2070 | 897048 | rc->rem_bins_pass1--; | |
2071 |
2/2✓ Branch 0 taken 226531 times.
✓ Branch 1 taken 670517 times.
|
897048 | if (*sig_coeff_flag) |
2072 | 226531 | infer_sb_sig_coeff_flag = 0; | |
2073 | } else { | ||
2074 |
5/6✓ Branch 0 taken 90107 times.
✓ Branch 1 taken 1305501 times.
✓ Branch 2 taken 90107 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3064 times.
✓ Branch 5 taken 87043 times.
|
1395608 | *sig_coeff_flag = (n == rc->num_sb_coeff - 1) && infer_sb_sig_coeff_flag && *sb_coded_flag; |
2075 | } | ||
2076 | 2292656 | *coeff_sign_level = 0; | |
2077 |
2/2✓ Branch 0 taken 229595 times.
✓ Branch 1 taken 2063061 times.
|
2292656 | if (*sig_coeff_flag) { |
2078 | 229595 | *coeff_sign_level = 1 - 2 * coeff_sign_flag_ts_decode(lc, cu, rc, xc, yc); | |
2079 | 229595 | abs_level_gtx_flag[n] = abs_level_gt1_flag_ts_decode(lc, cu, rc, xc, yc); | |
2080 | 229595 | rc->rem_bins_pass1 -= 2; | |
2081 |
2/2✓ Branch 0 taken 90239 times.
✓ Branch 1 taken 139356 times.
|
229595 | if (abs_level_gtx_flag[n]) { |
2082 | 90239 | par_level_flag = par_level_flag_ts_decode(lc); | |
2083 | 90239 | rc->rem_bins_pass1--; | |
2084 | } | ||
2085 | } | ||
2086 | 2292656 | *abs_level_pass1 = *sig_coeff_flag + par_level_flag + abs_level_gtx_flag[n]; | |
2087 | } | ||
2088 | |||
2089 | //greater than x scan pass | ||
2090 |
4/4✓ Branch 0 taken 2239269 times.
✓ Branch 1 taken 139034 times.
✓ Branch 2 taken 2233478 times.
✓ Branch 3 taken 5791 times.
|
2378303 | for (n = 0; n < rc->num_sb_coeff && rc->rem_bins_pass1 >= 4; n++) { |
2091 | 2233478 | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; | |
2092 | 2233478 | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; | |
2093 | 2233478 | const int off = yc * tb->tb_width + xc; | |
2094 | |||
2095 | 2233478 | abs_level_pass2[n] = rc->abs_level_pass1[off]; | |
2096 |
4/4✓ Branch 0 taken 2374707 times.
✓ Branch 1 taken 21025 times.
✓ Branch 2 taken 162254 times.
✓ Branch 3 taken 2212453 times.
|
2395732 | for (int j = 1; j < 5 && abs_level_gtx_flag[n]; j++) { |
2097 | 162254 | abs_level_gtx_flag[n] = abs_level_gtx_flag_ts_decode(lc, j); | |
2098 | 162254 | abs_level_pass2[n] += abs_level_gtx_flag[n] << 1; | |
2099 | 162254 | rc->rem_bins_pass1--; | |
2100 | } | ||
2101 | 2233478 | last_scan_pos_pass2 = n; | |
2102 | } | ||
2103 | |||
2104 | /* remainder scan pass */ | ||
2105 |
2/2✓ Branch 0 taken 2316912 times.
✓ Branch 1 taken 144825 times.
|
2461737 | for (n = 0; n < rc->num_sb_coeff; n++) { |
2106 | 2316912 | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; | |
2107 | 2316912 | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; | |
2108 | 2316912 | const int off = yc * tb->tb_width + xc; | |
2109 | 2316912 | const int *abs_level_pass1 = rc->abs_level_pass1 + off; | |
2110 | 2316912 | int *abs_level = rc->abs_level + off; | |
2111 | 2316912 | int *coeff_sign_level = rc->coeff_sign_level + off; | |
2112 | 2316912 | int abs_remainder = 0; | |
2113 | |||
2114 |
6/6✓ Branch 0 taken 2233478 times.
✓ Branch 1 taken 83434 times.
✓ Branch 2 taken 2215179 times.
✓ Branch 3 taken 18299 times.
✓ Branch 4 taken 83434 times.
✓ Branch 5 taken 2215179 times.
|
2316912 | if ((n <= last_scan_pos_pass2 && abs_level_pass2[n] >= 10) || |
2115 |
2/2✓ Branch 0 taken 59178 times.
✓ Branch 1 taken 24256 times.
|
83434 | (n > last_scan_pos_pass2 && n <= last_scan_pos_pass1 && |
2116 |
4/4✓ Branch 0 taken 46394 times.
✓ Branch 1 taken 12784 times.
✓ Branch 2 taken 24256 times.
✓ Branch 3 taken 2261573 times.
|
2298613 | *abs_level_pass1 >= 2) || |
2117 |
2/2✓ Branch 0 taken 19584 times.
✓ Branch 1 taken 4672 times.
|
24256 | (n > last_scan_pos_pass1 && *sb_coded_flag)) |
2118 | 50667 | abs_remainder = abs_remainder_ts_decode(lc, rc, xc, yc); | |
2119 |
2/2✓ Branch 0 taken 2233478 times.
✓ Branch 1 taken 83434 times.
|
2316912 | if (n <= last_scan_pos_pass2) { |
2120 | 2233478 | *abs_level = abs_level_pass2[n] + 2 * abs_remainder; | |
2121 |
2/2✓ Branch 0 taken 59178 times.
✓ Branch 1 taken 24256 times.
|
83434 | } else if (n <= last_scan_pos_pass1) { |
2122 | 59178 | *abs_level = *abs_level_pass1 + 2 * abs_remainder; | |
2123 | } else { | ||
2124 | 24256 | *abs_level = abs_remainder; | |
2125 |
2/2✓ Branch 0 taken 11413 times.
✓ Branch 1 taken 12843 times.
|
24256 | if (abs_remainder) { |
2126 | //n > lastScanPosPass1 | ||
2127 | 11413 | *coeff_sign_level = 1 - 2 * coeff_sign_flag_decode(lc); | |
2128 | } | ||
2129 | } | ||
2130 |
4/4✓ Branch 0 taken 2316576 times.
✓ Branch 1 taken 336 times.
✓ Branch 2 taken 2292320 times.
✓ Branch 3 taken 24256 times.
|
2316912 | if (!bdpcm_flag && n <= last_scan_pos_pass1) { |
2131 |
2/2✓ Branch 0 taken 2050354 times.
✓ Branch 1 taken 241966 times.
|
2292320 | const int left = xc > 0 ? abs_level[-1] : 0; |
2132 |
2/2✓ Branch 0 taken 2050117 times.
✓ Branch 1 taken 242203 times.
|
2292320 | const int above = yc > 0 ? abs_level[-tb->tb_width] : 0; |
2133 | 2292320 | const int pred = FFMAX(left, above); | |
2134 | |||
2135 |
4/4✓ Branch 0 taken 139333 times.
✓ Branch 1 taken 2152987 times.
✓ Branch 2 taken 82826 times.
✓ Branch 3 taken 56507 times.
|
2292320 | if (*abs_level == 1 && pred > 0) |
2136 | 82826 | *abs_level = pred; | |
2137 |
4/4✓ Branch 0 taken 146736 times.
✓ Branch 1 taken 2062758 times.
✓ Branch 2 taken 37308 times.
✓ Branch 3 taken 109428 times.
|
2209494 | else if (*abs_level > 0 && *abs_level <= pred) |
2138 | 37308 | (*abs_level)--; | |
2139 | } | ||
2140 |
2/2✓ Branch 0 taken 241008 times.
✓ Branch 1 taken 2075904 times.
|
2316912 | if (*abs_level) { |
2141 | 241008 | tb->coeffs[off] = *coeff_sign_level * *abs_level; | |
2142 | 241008 | tb->max_scan_x = FFMAX(xc, tb->max_scan_x); | |
2143 | 241008 | tb->max_scan_y = FFMAX(yc, tb->max_scan_y); | |
2144 | 241008 | tb->min_scan_x = FFMIN(xc, tb->min_scan_x); | |
2145 | 241008 | tb->min_scan_y = FFMIN(yc, tb->min_scan_y); | |
2146 | } else { | ||
2147 | 2075904 | tb->coeffs[off] = 0; | |
2148 | } | ||
2149 | } | ||
2150 | |||
2151 | 144825 | return 0; | |
2152 | } | ||
2153 | |||
2154 | 28597 | static int hls_residual_ts_coding(VVCLocalContext *lc, TransformBlock *tb) | |
2155 | { | ||
2156 | ResidualCoding rc; | ||
2157 | 28597 | tb->min_scan_x = tb->min_scan_y = INT_MAX; | |
2158 | 28597 | init_residual_coding(lc, &rc, tb->log2_tb_width, tb->log2_tb_height, tb); | |
2159 |
2/2✓ Branch 0 taken 144825 times.
✓ Branch 1 taken 28597 times.
|
173422 | for (int i = 0; i <= rc.last_sub_block; i++) { |
2160 | 144825 | int ret = residual_ts_coding_subblock(lc, &rc, i); | |
2161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 144825 times.
|
144825 | if (ret < 0) |
2162 | ✗ | return ret; | |
2163 | } | ||
2164 | |||
2165 | 28597 | return 0; | |
2166 | } | ||
2167 | |||
2168 | 1821198 | static inline int residual_coding_subblock(VVCLocalContext *lc, ResidualCoding *rc, const int i) | |
2169 | { | ||
2170 | 1821198 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
2171 | 1821198 | TransformBlock *tb = rc->tb; | |
2172 | int first_sig_scan_pos_sb, last_sig_scan_pos_sb; | ||
2173 | int first_pos_mode0, first_pos_mode1; | ||
2174 | 1821198 | int infer_sb_dc_sig_coeff_flag = 0; | |
2175 | 1821198 | int n, sig_hidden_flag, sum = 0; | |
2176 | int abs_level_gt2_flag[MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE]; | ||
2177 | 1821198 | const int start_qstate_sb = rc->qstate; | |
2178 | 1821198 | const int xs = rc->sb_scan_x_off[i]; | |
2179 | 1821198 | const int ys = rc->sb_scan_y_off[i]; | |
2180 | 1821198 | uint8_t *sb_coded_flag = rc->sb_coded_flag + ys * rc->width_in_sbs + xs; | |
2181 | |||
2182 | |||
2183 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1821198 times.
|
1821198 | av_assert0(rc->num_sb_coeff <= MAX_SUB_BLOCK_SIZE * MAX_SUB_BLOCK_SIZE); |
2184 |
4/4✓ Branch 0 taken 986576 times.
✓ Branch 1 taken 834622 times.
✓ Branch 2 taken 738381 times.
✓ Branch 3 taken 248195 times.
|
1821198 | if (i < rc->last_sub_block && i > 0) { |
2185 | 738381 | *sb_coded_flag = sb_coded_flag_decode(lc, sb_coded_flag, rc, xs, ys); | |
2186 | 738381 | infer_sb_dc_sig_coeff_flag = 1; | |
2187 | } else { | ||
2188 | 1082817 | *sb_coded_flag = 1; | |
2189 | } | ||
2190 |
8/8✓ Branch 0 taken 1591448 times.
✓ Branch 1 taken 229750 times.
✓ Branch 2 taken 1524614 times.
✓ Branch 3 taken 66834 times.
✓ Branch 4 taken 35872 times.
✓ Branch 5 taken 1488742 times.
✓ Branch 6 taken 50340 times.
✓ Branch 7 taken 52366 times.
|
1821198 | if (*sb_coded_flag && (xs > 3 || ys > 3) && !tb->c_idx) |
2191 | 50340 | lc->parse.mts_zero_out_sig_coeff_flag = 0; | |
2192 | |||
2193 |
2/2✓ Branch 0 taken 229750 times.
✓ Branch 1 taken 1591448 times.
|
1821198 | if (!*sb_coded_flag) |
2194 | 229750 | return 0; | |
2195 | |||
2196 | 1591448 | first_sig_scan_pos_sb = rc->num_sb_coeff; | |
2197 | 1591448 | last_sig_scan_pos_sb = -1; | |
2198 |
2/2✓ Branch 0 taken 834622 times.
✓ Branch 1 taken 756826 times.
|
1591448 | first_pos_mode0 = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1); |
2199 | 1591448 | first_pos_mode1 = first_pos_mode0; | |
2200 |
4/4✓ Branch 0 taken 16949756 times.
✓ Branch 1 taken 1540741 times.
✓ Branch 2 taken 16899049 times.
✓ Branch 3 taken 50707 times.
|
18490497 | for (n = first_pos_mode0; n >= 0 && rc->rem_bins_pass1 >= 4; n--) { |
2201 | 16899049 | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; | |
2202 | 16899049 | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; | |
2203 |
4/4✓ Branch 0 taken 2503367 times.
✓ Branch 1 taken 14395682 times.
✓ Branch 2 taken 834622 times.
✓ Branch 3 taken 1668745 times.
|
16899049 | const int last = (xc == rc->last_significant_coeff_x && yc == rc->last_significant_coeff_y); |
2204 | 16899049 | int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc; | |
2205 | 16899049 | int *sig_coeff_flag = rc->sig_coeff_flag + yc * tb->tb_width + xc; | |
2206 | |||
2207 |
6/6✓ Branch 0 taken 1540741 times.
✓ Branch 1 taken 15358308 times.
✓ Branch 2 taken 1533074 times.
✓ Branch 3 taken 7667 times.
✓ Branch 4 taken 16056760 times.
✓ Branch 5 taken 834622 times.
|
16899049 | if ((n > 0 || !infer_sb_dc_sig_coeff_flag ) && !last) { |
2208 | 16056760 | *sig_coeff_flag = sig_coeff_flag_decode(lc, rc, xc, yc); | |
2209 | 16056760 | rc->rem_bins_pass1--; | |
2210 |
2/2✓ Branch 0 taken 9066682 times.
✓ Branch 1 taken 6990078 times.
|
16056760 | if (*sig_coeff_flag) |
2211 | 9066682 | infer_sb_dc_sig_coeff_flag = 0; | |
2212 | } else { | ||
2213 |
5/8✓ Branch 0 taken 7667 times.
✓ Branch 1 taken 834622 times.
✓ Branch 2 taken 7667 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7667 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7667 times.
✗ Branch 7 not taken.
|
842289 | *sig_coeff_flag = last || (!rc->scan_x_off[n] && !rc ->scan_y_off[n] && |
2214 | infer_sb_dc_sig_coeff_flag); | ||
2215 | } | ||
2216 | 16899049 | *abs_level_pass1 = 0; | |
2217 |
2/2✓ Branch 0 taken 9908971 times.
✓ Branch 1 taken 6990078 times.
|
16899049 | if (*sig_coeff_flag) { |
2218 | 9908971 | int abs_level_gt1_flag, par_level_flag = 0; | |
2219 | 9908971 | const int inc = get_gtx_flag_inc(rc, xc, yc, last); | |
2220 | 9908971 | abs_level_gt1_flag = abs_level_gtx_flag_decode(lc, inc); | |
2221 | 9908971 | rc->rem_bins_pass1--; | |
2222 |
2/2✓ Branch 0 taken 1723093 times.
✓ Branch 1 taken 8185878 times.
|
9908971 | if (abs_level_gt1_flag) { |
2223 | 1723093 | par_level_flag = par_level_flag_decode(lc, inc); | |
2224 | 1723093 | abs_level_gt2_flag[n] = abs_level_gtx_flag_decode(lc, inc + 32); | |
2225 | 1723093 | rc->rem_bins_pass1 -= 2; | |
2226 | } else { | ||
2227 | 8185878 | abs_level_gt2_flag[n] = 0; | |
2228 | } | ||
2229 |
2/2✓ Branch 0 taken 1582515 times.
✓ Branch 1 taken 8326456 times.
|
9908971 | if (last_sig_scan_pos_sb == -1) |
2230 | 1582515 | last_sig_scan_pos_sb = n; | |
2231 | 9908971 | first_sig_scan_pos_sb = n; | |
2232 | |||
2233 | 9908971 | *abs_level_pass1 = | |
2234 | 9908971 | 1 + par_level_flag + abs_level_gt1_flag + (abs_level_gt2_flag[n] << 1); | |
2235 | } else { | ||
2236 | 6990078 | abs_level_gt2_flag[n] = 0; | |
2237 | } | ||
2238 | |||
2239 |
2/2✓ Branch 0 taken 16592816 times.
✓ Branch 1 taken 306233 times.
|
16899049 | if (rsh->sh_dep_quant_used_flag) |
2240 | 16592816 | rc->qstate = qstate_translate_table[rc->qstate][*abs_level_pass1 & 1]; | |
2241 | |||
2242 | 16899049 | first_pos_mode1 = n - 1; | |
2243 | } | ||
2244 |
2/2✓ Branch 0 taken 16899049 times.
✓ Branch 1 taken 1591448 times.
|
18490497 | for (n = first_pos_mode0; n > first_pos_mode1; n--) { |
2245 | 16899049 | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; | |
2246 | 16899049 | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; | |
2247 | 16899049 | const int *abs_level_pass1 = rc->abs_level_pass1 + yc * tb->tb_width + xc; | |
2248 | 16899049 | int *abs_level = rc->abs_level + yc * tb->tb_width + xc; | |
2249 | |||
2250 | 16899049 | *abs_level = *abs_level_pass1; | |
2251 |
2/2✓ Branch 0 taken 315475 times.
✓ Branch 1 taken 16583574 times.
|
16899049 | if (abs_level_gt2_flag[n]) { |
2252 | 315475 | const int abs_remainder = abs_remainder_decode(lc, rc, xc, yc); | |
2253 | 315475 | ep_update_hist(lc->ep, rc, abs_remainder, 2); | |
2254 | 315475 | *abs_level += 2 * abs_remainder; | |
2255 | } | ||
2256 | } | ||
2257 |
2/2✓ Branch 0 taken 254903 times.
✓ Branch 1 taken 1591448 times.
|
1846351 | for (n = first_pos_mode1; n >= 0; n--) { |
2258 | 254903 | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; | |
2259 | 254903 | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; | |
2260 | 254903 | int *abs_level = rc->abs_level + yc * tb->tb_width + xc; | |
2261 | |||
2262 |
1/2✓ Branch 0 taken 254903 times.
✗ Branch 1 not taken.
|
254903 | if (*sb_coded_flag) { |
2263 | 254903 | const int dec_abs_level = dec_abs_level_decode(lc, rc, xc, yc, abs_level); | |
2264 | 254903 | ep_update_hist(lc->ep, rc, dec_abs_level, 0); | |
2265 | } | ||
2266 |
2/2✓ Branch 0 taken 231651 times.
✓ Branch 1 taken 23252 times.
|
254903 | if (*abs_level > 0) { |
2267 |
2/2✓ Branch 0 taken 3100 times.
✓ Branch 1 taken 228551 times.
|
231651 | if (last_sig_scan_pos_sb == -1) |
2268 | 3100 | last_sig_scan_pos_sb = n; | |
2269 | 231651 | first_sig_scan_pos_sb = n; | |
2270 | } | ||
2271 |
2/2✓ Branch 0 taken 236183 times.
✓ Branch 1 taken 18720 times.
|
254903 | if (rsh->sh_dep_quant_used_flag) |
2272 | 236183 | rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1]; | |
2273 | } | ||
2274 |
2/2✓ Branch 0 taken 34562 times.
✓ Branch 1 taken 1556886 times.
|
1626010 | sig_hidden_flag = rsh->sh_sign_data_hiding_used_flag && |
2275 |
2/2✓ Branch 0 taken 22447 times.
✓ Branch 1 taken 12115 times.
|
34562 | (last_sig_scan_pos_sb - first_sig_scan_pos_sb > 3 ? 1 : 0); |
2276 | |||
2277 |
2/2✓ Branch 0 taken 1556210 times.
✓ Branch 1 taken 35238 times.
|
1591448 | if (rsh->sh_dep_quant_used_flag) |
2278 | 1556210 | rc->qstate = start_qstate_sb; | |
2279 |
2/2✓ Branch 0 taken 834622 times.
✓ Branch 1 taken 756826 times.
|
1591448 | n = (i == rc->last_sub_block ? rc->last_scan_pos : rc->num_sb_coeff -1); |
2280 |
2/2✓ Branch 0 taken 17153952 times.
✓ Branch 1 taken 1591448 times.
|
18745400 | for (/* nothing */; n >= 0; n--) { |
2281 | int trans_coeff_level; | ||
2282 | 17153952 | const int xc = (xs << rc->log2_sb_w) + rc->scan_x_off[n]; | |
2283 | 17153952 | const int yc = (ys << rc->log2_sb_h) + rc->scan_y_off[n]; | |
2284 | 17153952 | const int off = yc * tb->tb_width + xc; | |
2285 | 17153952 | const int *abs_level = rc->abs_level + off; | |
2286 | |||
2287 |
2/2✓ Branch 0 taken 10140622 times.
✓ Branch 1 taken 7013330 times.
|
17153952 | if (*abs_level > 0) { |
2288 | 10140622 | int sign = 1; | |
2289 |
4/4✓ Branch 0 taken 176798 times.
✓ Branch 1 taken 9963824 times.
✓ Branch 2 taken 154351 times.
✓ Branch 3 taken 22447 times.
|
10140622 | if (!sig_hidden_flag || (n != first_sig_scan_pos_sb)) |
2290 | 10118175 | sign = 1 - 2 * coeff_sign_flag_decode(lc); | |
2291 |
2/2✓ Branch 0 taken 9941437 times.
✓ Branch 1 taken 199185 times.
|
10140622 | if (rsh->sh_dep_quant_used_flag) { |
2292 | 9941437 | trans_coeff_level = (2 * *abs_level - (rc->qstate > 1)) * sign; | |
2293 | } else { | ||
2294 | 199185 | trans_coeff_level = *abs_level * sign; | |
2295 |
2/2✓ Branch 0 taken 176798 times.
✓ Branch 1 taken 22387 times.
|
199185 | if (sig_hidden_flag) { |
2296 | 176798 | sum += *abs_level; | |
2297 |
4/4✓ Branch 0 taken 22447 times.
✓ Branch 1 taken 154351 times.
✓ Branch 2 taken 11754 times.
✓ Branch 3 taken 10693 times.
|
176798 | if (n == first_sig_scan_pos_sb && (sum % 2)) |
2298 | 11754 | trans_coeff_level = -trans_coeff_level; | |
2299 | } | ||
2300 | } | ||
2301 | 10140622 | tb->coeffs[off] = trans_coeff_level; | |
2302 | 10140622 | tb->max_scan_x = FFMAX(xc, tb->max_scan_x); | |
2303 | 10140622 | tb->max_scan_y = FFMAX(yc, tb->max_scan_y); | |
2304 | } | ||
2305 |
2/2✓ Branch 0 taken 16828999 times.
✓ Branch 1 taken 324953 times.
|
17153952 | if (rsh->sh_dep_quant_used_flag) |
2306 | 16828999 | rc->qstate = qstate_translate_table[rc->qstate][*abs_level & 1]; | |
2307 | } | ||
2308 | |||
2309 | 1591448 | return 0; | |
2310 | } | ||
2311 | |||
2312 | 834622 | static void derive_last_scan_pos(ResidualCoding *rc) | |
2313 | { | ||
2314 | int xc, yc, xs, ys; | ||
2315 | do { | ||
2316 |
2/2✓ Branch 0 taken 5808227 times.
✓ Branch 1 taken 96229035 times.
|
102037262 | if (!rc->last_scan_pos) { |
2317 | 5808227 | rc->last_scan_pos = rc->num_sb_coeff; | |
2318 | 5808227 | rc->last_sub_block--; | |
2319 | } | ||
2320 | 102037262 | rc->last_scan_pos--; | |
2321 | 102037262 | xs = rc->sb_scan_x_off[rc->last_sub_block]; | |
2322 | 102037262 | ys = rc->sb_scan_y_off[rc->last_sub_block]; | |
2323 | 102037262 | xc = (xs << rc->log2_sb_w) + rc->scan_x_off[rc->last_scan_pos]; | |
2324 | 102037262 | yc = (ys << rc->log2_sb_h) + rc->scan_y_off[rc->last_scan_pos]; | |
2325 |
4/4✓ Branch 0 taken 95437842 times.
✓ Branch 1 taken 6599420 times.
✓ Branch 2 taken 5764798 times.
✓ Branch 3 taken 834622 times.
|
102037262 | } while ((xc != rc->last_significant_coeff_x) || (yc != rc->last_significant_coeff_y)); |
2326 | 834622 | } | |
2327 | |||
2328 | 834622 | static void last_significant_coeff_x_y_decode(ResidualCoding *rc, VVCLocalContext *lc, | |
2329 | const int log2_zo_tb_width, const int log2_zo_tb_height) | ||
2330 | { | ||
2331 | 834622 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
2332 | 834622 | const TransformBlock *tb = rc->tb; | |
2333 | int last_significant_coeff_x, last_significant_coeff_y; | ||
2334 | |||
2335 | 834622 | last_significant_coeff_x = last_significant_coeff_x_prefix_decode(lc, | |
2336 | 834622 | tb->log2_tb_width, log2_zo_tb_width, tb->c_idx); | |
2337 | |||
2338 | 834622 | last_significant_coeff_y = last_significant_coeff_y_prefix_decode(lc, | |
2339 | 834622 | tb->log2_tb_height, log2_zo_tb_height, tb->c_idx); | |
2340 | |||
2341 |
2/2✓ Branch 0 taken 188582 times.
✓ Branch 1 taken 646040 times.
|
834622 | if (last_significant_coeff_x > 3) { |
2342 | 188582 | int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_x); | |
2343 | 188582 | last_significant_coeff_x = (1 << ((last_significant_coeff_x >> 1) - 1)) * | |
2344 | 188582 | (2 + (last_significant_coeff_x & 1)) + suffix; | |
2345 | } | ||
2346 |
2/2✓ Branch 0 taken 140020 times.
✓ Branch 1 taken 694602 times.
|
834622 | if (last_significant_coeff_y > 3) { |
2347 | 140020 | int suffix = last_sig_coeff_suffix_decode(lc, last_significant_coeff_y); | |
2348 | 140020 | last_significant_coeff_y = (1 << ((last_significant_coeff_y >> 1) - 1)) * | |
2349 | 140020 | (2 + (last_significant_coeff_y & 1)) + suffix; | |
2350 | } | ||
2351 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 834622 times.
|
834622 | if (rsh->sh_reverse_last_sig_coeff_flag) { |
2352 | ✗ | last_significant_coeff_x = (1 << log2_zo_tb_width) - 1 - last_significant_coeff_x; | |
2353 | ✗ | last_significant_coeff_y = (1 << log2_zo_tb_height) - 1 - last_significant_coeff_y; | |
2354 | } | ||
2355 | 834622 | rc->last_significant_coeff_x = last_significant_coeff_x; | |
2356 | 834622 | rc->last_significant_coeff_y = last_significant_coeff_y; | |
2357 | 834622 | } | |
2358 | |||
2359 | 834622 | static int hls_residual_coding(VVCLocalContext *lc, TransformBlock *tb) | |
2360 | { | ||
2361 | 834622 | const VVCSPS *sps = lc->fc->ps.sps; | |
2362 | 834622 | const CodingUnit *cu = lc->cu; | |
2363 | 834622 | const int log2_tb_width = tb->log2_tb_width; | |
2364 | 834622 | const int log2_tb_height = tb->log2_tb_height; | |
2365 | 834622 | const int c_idx = tb->c_idx; | |
2366 | int log2_zo_tb_width, log2_zo_tb_height; | ||
2367 | ResidualCoding rc; | ||
2368 | |||
2369 |
10/10✓ Branch 0 taken 829909 times.
✓ Branch 1 taken 4713 times.
✓ Branch 2 taken 40189 times.
✓ Branch 3 taken 789720 times.
✓ Branch 4 taken 30793 times.
✓ Branch 5 taken 9396 times.
✓ Branch 6 taken 1500 times.
✓ Branch 7 taken 29293 times.
✓ Branch 8 taken 1397 times.
✓ Branch 9 taken 103 times.
|
834622 | if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width == 5 && log2_tb_height < 6) |
2370 | 1397 | log2_zo_tb_width = 4; | |
2371 | else | ||
2372 | 833225 | log2_zo_tb_width = FFMIN(log2_tb_width, 5 ); | |
2373 | |||
2374 |
10/10✓ Branch 0 taken 829909 times.
✓ Branch 1 taken 4713 times.
✓ Branch 2 taken 40189 times.
✓ Branch 3 taken 789720 times.
✓ Branch 4 taken 30793 times.
✓ Branch 5 taken 9396 times.
✓ Branch 6 taken 30603 times.
✓ Branch 7 taken 190 times.
✓ Branch 8 taken 1939 times.
✓ Branch 9 taken 28664 times.
|
834622 | if (sps->r->sps_mts_enabled_flag && cu->sbt_flag && !c_idx && log2_tb_width < 6 && log2_tb_height == 5 ) |
2375 | 1939 | log2_zo_tb_height = 4; | |
2376 | else | ||
2377 | 832683 | log2_zo_tb_height = FFMIN(log2_tb_height, 5); | |
2378 | |||
2379 | 834622 | init_residual_coding(lc, &rc, log2_zo_tb_width, log2_zo_tb_height, tb); | |
2380 | 834622 | last_significant_coeff_x_y_decode(&rc, lc, log2_zo_tb_width, log2_zo_tb_height); | |
2381 | 834622 | derive_last_scan_pos(&rc); | |
2382 | |||
2383 |
9/10✓ Branch 0 taken 586427 times.
✓ Branch 1 taken 248195 times.
✓ Branch 2 taken 566417 times.
✓ Branch 3 taken 20010 times.
✓ Branch 4 taken 513479 times.
✓ Branch 5 taken 52938 times.
✓ Branch 6 taken 513479 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 391962 times.
✓ Branch 9 taken 121517 times.
|
834622 | if (!rc.last_sub_block && log2_tb_width >= 2 && log2_tb_height >= 2 && !tb->ts && rc.last_scan_pos > 0) |
2384 | 391962 | lc->parse.lfnst_dc_only = 0; | |
2385 |
6/6✓ Branch 0 taken 248195 times.
✓ Branch 1 taken 586427 times.
✓ Branch 2 taken 247681 times.
✓ Branch 3 taken 514 times.
✓ Branch 4 taken 3331 times.
✓ Branch 5 taken 244350 times.
|
834622 | if ((rc.last_sub_block > 0 && log2_tb_width >= 2 && log2_tb_height >= 2 ) || |
2386 |
8/8✓ Branch 0 taken 135271 times.
✓ Branch 1 taken 455001 times.
✓ Branch 2 taken 78264 times.
✓ Branch 3 taken 57007 times.
✓ Branch 4 taken 37644 times.
✓ Branch 5 taken 40620 times.
✓ Branch 6 taken 47826 times.
✓ Branch 7 taken 46825 times.
|
590272 | (rc.last_scan_pos > 7 && (log2_tb_width == 2 || log2_tb_width == 3 ) && |
2387 | log2_tb_width == log2_tb_height)) | ||
2388 | 292176 | lc->parse.lfnst_zero_out_sig_coeff_flag = 0; | |
2389 |
6/6✓ Branch 0 taken 586427 times.
✓ Branch 1 taken 248195 times.
✓ Branch 2 taken 447047 times.
✓ Branch 3 taken 139380 times.
✓ Branch 4 taken 541139 times.
✓ Branch 5 taken 154103 times.
|
834622 | if ((rc.last_sub_block > 0 || rc.last_scan_pos > 0 ) && !c_idx) |
2390 | 541139 | lc->parse.mts_dc_only = 0; | |
2391 | |||
2392 | 834622 | memset(tb->coeffs, 0, tb->tb_width * tb->tb_height * sizeof(*tb->coeffs)); | |
2393 | 834622 | memset(rc.abs_level, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level[0])); | |
2394 | 834622 | memset(rc.sb_coded_flag, 0, rc.nb_sbs); | |
2395 | 834622 | memset(rc.abs_level_pass1, 0, tb->tb_width * tb->tb_height * sizeof(rc.abs_level_pass1[0])); | |
2396 | 834622 | memset(rc.sig_coeff_flag, 0, tb->tb_width * tb->tb_height * sizeof(rc.sig_coeff_flag[0])); | |
2397 | |||
2398 |
2/2✓ Branch 0 taken 1821198 times.
✓ Branch 1 taken 834622 times.
|
2655820 | for (int i = rc.last_sub_block; i >= 0; i--) { |
2399 | 1821198 | int ret = residual_coding_subblock(lc, &rc, i); | |
2400 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1821198 times.
|
1821198 | if (ret < 0) |
2401 | ✗ | return ret; | |
2402 | } | ||
2403 | |||
2404 | 834622 | return 0; | |
2405 | } | ||
2406 | |||
2407 | 863219 | int ff_vvc_residual_coding(VVCLocalContext *lc, TransformBlock *tb) | |
2408 | { | ||
2409 | 863219 | const H266RawSliceHeader *rsh = lc->sc->sh.r; | |
2410 |
3/4✓ Branch 0 taken 863219 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28597 times.
✓ Branch 3 taken 834622 times.
|
863219 | const int ts = !rsh->sh_ts_residual_coding_disabled_flag && tb->ts; |
2411 | |||
2412 |
2/2✓ Branch 0 taken 28597 times.
✓ Branch 1 taken 834622 times.
|
863219 | return ts ? hls_residual_ts_coding(lc, tb) : hls_residual_coding(lc, tb); |
2413 | } | ||
2414 | |||
2415 | 60920 | int ff_vvc_cu_coded_flag(VVCLocalContext *lc) | |
2416 | { | ||
2417 | 60920 | return GET_CABAC(CU_CODED_FLAG); | |
2418 | } | ||
2419 | |||
2420 | 116966 | int ff_vvc_sbt_flag(VVCLocalContext *lc) | |
2421 | { | ||
2422 | 116966 | const int w = lc->cu->cb_width; | |
2423 | 116966 | const int h = lc->cu->cb_height; | |
2424 | 116966 | const int inc = w * h <= 256; | |
2425 | 116966 | return GET_CABAC(CU_SBT_FLAG + inc); | |
2426 | } | ||
2427 | |||
2428 | 27567 | int ff_vvc_sbt_quad_flag(VVCLocalContext *lc) | |
2429 | { | ||
2430 | 27567 | return GET_CABAC(CU_SBT_QUAD_FLAG); | |
2431 | } | ||
2432 | |||
2433 | 22208 | int ff_vvc_sbt_horizontal_flag(VVCLocalContext *lc) | |
2434 | { | ||
2435 | 22208 | const int w = lc->cu->cb_width; | |
2436 | 22208 | const int h = lc->cu->cb_height; | |
2437 |
4/4✓ Branch 0 taken 11891 times.
✓ Branch 1 taken 10317 times.
✓ Branch 2 taken 6699 times.
✓ Branch 3 taken 5192 times.
|
22208 | const int inc = (w == h) ? 0 : ((w < h) ? 1 : 2); |
2438 | 22208 | return GET_CABAC(CU_SBT_HORIZONTAL_FLAG + inc); | |
2439 | } | ||
2440 | |||
2441 | 37306 | int ff_vvc_sbt_pos_flag(VVCLocalContext *lc) | |
2442 | { | ||
2443 | 37306 | return GET_CABAC(CU_SBT_POS_FLAG); | |
2444 | } | ||
2445 | |||
2446 | 164626 | int ff_vvc_lfnst_idx(VVCLocalContext *lc, const int inc) | |
2447 | { | ||
2448 |
2/2✓ Branch 1 taken 42593 times.
✓ Branch 2 taken 122033 times.
|
164626 | if (!GET_CABAC(LFNST_IDX + inc)) |
2449 | 42593 | return 0; | |
2450 |
2/2✓ Branch 1 taken 76260 times.
✓ Branch 2 taken 45773 times.
|
122033 | if (!GET_CABAC(LFNST_IDX + 2)) |
2451 | 76260 | return 1; | |
2452 | 45773 | return 2; | |
2453 | } | ||
2454 | |||
2455 | 244197 | int ff_vvc_mts_idx(VVCLocalContext *lc) | |
2456 | { | ||
2457 | int i; | ||
2458 |
1/2✓ Branch 0 taken 443876 times.
✗ Branch 1 not taken.
|
443876 | for (i = 0; i < 4; i++) { |
2459 |
2/2✓ Branch 1 taken 244197 times.
✓ Branch 2 taken 199679 times.
|
443876 | if (!GET_CABAC(MTS_IDX + i)) |
2460 | 244197 | return i; | |
2461 | } | ||
2462 | ✗ | return i; | |
2463 | } | ||
2464 | |||
2465 | 1659 | int ff_vvc_end_of_slice_flag_decode(VVCLocalContext *lc) | |
2466 | { | ||
2467 | 1659 | return get_cabac_terminate(&lc->ep->cc); | |
2468 | } | ||
2469 | |||
2470 | 214 | int ff_vvc_end_of_tile_one_bit(VVCLocalContext *lc) | |
2471 | { | ||
2472 | 214 | return get_cabac_terminate(&lc->ep->cc); | |
2473 | } | ||
2474 | |||
2475 | 153 | int ff_vvc_end_of_subset_one_bit(VVCLocalContext *lc) | |
2476 | { | ||
2477 | 153 | return get_cabac_terminate(&lc->ep->cc); | |
2478 | } | ||
2479 |