FFmpeg
Loading...
Searching...
No Matches
cbs_h266_syntax_template.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
20 RWContext *rw)
21{
22 int err;
23
24 fixed(1, rbsp_stop_one_bit, 1);
25 while (byte_alignment(rw) != 0)
26 fixed(1, rbsp_alignment_zero_bit, 0);
27 return 0;
28}
29
32 int expected_nal_unit_type)
33{
34 int err;
35
36 fixed(1, forbidden_zero_bit, 0);
37 flag(nuh_reserved_zero_bit);
38
39 u(6, nuh_layer_id, 0, 55);
40
41 if (expected_nal_unit_type >= 0)
42 u(5, nal_unit_type, expected_nal_unit_type, expected_nal_unit_type);
43 else
44 ub(5, nal_unit_type);
45
46 u(3, nuh_temporal_id_plus1, 1, 7);
47 return 0;
48}
49
51{
52 int err;
53
54 fixed(1, byte_alignment_bit_equal_to_one, 1);
55 while (byte_alignment(rw) != 0)
56 fixed(1, byte_alignment_bit_equal_to_zero, 0);
57 return 0;
58}
59
61 RWContext *rw,
63{
64 int err, i, num_additional_bits_used;
65
66 flag(gci_present_flag);
67 if (current->gci_present_flag) {
68 /* general */
69 flag(gci_intra_only_constraint_flag);
70 flag(gci_all_layers_independent_constraint_flag);
71 flag(gci_one_au_only_constraint_flag);
72
73 /* picture format */
74 u(4, gci_sixteen_minus_max_bitdepth_constraint_idc, 0, 8);
75 ub(2, gci_three_minus_max_chroma_format_constraint_idc);
76
77 /* NAL unit type related */
78 flag(gci_no_mixed_nalu_types_in_pic_constraint_flag);
79 flag(gci_no_trail_constraint_flag);
80 flag(gci_no_stsa_constraint_flag);
81 flag(gci_no_rasl_constraint_flag);
82 flag(gci_no_radl_constraint_flag);
83 flag(gci_no_idr_constraint_flag);
84 flag(gci_no_cra_constraint_flag);
85 flag(gci_no_gdr_constraint_flag);
86 flag(gci_no_aps_constraint_flag);
87 flag(gci_no_idr_rpl_constraint_flag);
88
89 /* tile, slice, subpicture partitioning */
90 flag(gci_one_tile_per_pic_constraint_flag);
91 flag(gci_pic_header_in_slice_header_constraint_flag);
92 flag(gci_one_slice_per_pic_constraint_flag);
93 flag(gci_no_rectangular_slice_constraint_flag);
94 flag(gci_one_slice_per_subpic_constraint_flag);
95 flag(gci_no_subpic_info_constraint_flag);
96
97 /* CTU and block partitioning */
98 ub(2, gci_three_minus_max_log2_ctu_size_constraint_idc);
99 flag(gci_no_partition_constraints_override_constraint_flag);
100 flag(gci_no_mtt_constraint_flag);
101 flag(gci_no_qtbtt_dual_tree_intra_constraint_flag);
102
103 /* intra */
104 flag(gci_no_palette_constraint_flag);
105 flag(gci_no_ibc_constraint_flag);
106 flag(gci_no_isp_constraint_flag);
107 flag(gci_no_mrl_constraint_flag);
108 flag(gci_no_mip_constraint_flag);
109 flag(gci_no_cclm_constraint_flag);
110
111 /* inter */
112 flag(gci_no_ref_pic_resampling_constraint_flag);
113 flag(gci_no_res_change_in_clvs_constraint_flag);
114 flag(gci_no_weighted_prediction_constraint_flag);
115 flag(gci_no_ref_wraparound_constraint_flag);
116 flag(gci_no_temporal_mvp_constraint_flag);
117 flag(gci_no_sbtmvp_constraint_flag);
118 flag(gci_no_amvr_constraint_flag);
119 flag(gci_no_bdof_constraint_flag);
120 flag(gci_no_smvd_constraint_flag);
121 flag(gci_no_dmvr_constraint_flag);
122 flag(gci_no_mmvd_constraint_flag);
123 flag(gci_no_affine_motion_constraint_flag);
124 flag(gci_no_prof_constraint_flag);
125 flag(gci_no_bcw_constraint_flag);
126 flag(gci_no_ciip_constraint_flag);
127 flag(gci_no_gpm_constraint_flag);
128
129 /* transform, quantization, residual */
130 flag(gci_no_luma_transform_size_64_constraint_flag);
131 flag(gci_no_transform_skip_constraint_flag);
132 flag(gci_no_bdpcm_constraint_flag);
133 flag(gci_no_mts_constraint_flag);
134 flag(gci_no_lfnst_constraint_flag);
135 flag(gci_no_joint_cbcr_constraint_flag);
136 flag(gci_no_sbt_constraint_flag);
137 flag(gci_no_act_constraint_flag);
138 flag(gci_no_explicit_scaling_list_constraint_flag);
139 flag(gci_no_dep_quant_constraint_flag);
140 flag(gci_no_sign_data_hiding_constraint_flag);
141 flag(gci_no_cu_qp_delta_constraint_flag);
142 flag(gci_no_chroma_qp_offset_constraint_flag);
143
144 /* loop filter */
145 flag(gci_no_sao_constraint_flag);
146 flag(gci_no_alf_constraint_flag);
147 flag(gci_no_ccalf_constraint_flag);
148 flag(gci_no_lmcs_constraint_flag);
149 flag(gci_no_ladf_constraint_flag);
150 flag(gci_no_virtual_boundaries_constraint_flag);
151 ub(8, gci_num_additional_bits);
152 if (current->gci_num_additional_bits > 5) {
153 flag(gci_all_rap_pictures_constraint_flag);
154 flag(gci_no_extended_precision_processing_constraint_flag);
155 flag(gci_no_ts_residual_coding_rice_constraint_flag);
156 flag(gci_no_rrc_rice_extension_constraint_flag);
157 flag(gci_no_persistent_rice_adaptation_constraint_flag);
158 flag(gci_no_reverse_last_sig_coeff_constraint_flag);
159 num_additional_bits_used = 6;
160 } else {
161 infer(gci_all_rap_pictures_constraint_flag, 0);
162 infer(gci_no_extended_precision_processing_constraint_flag, 0);
163 infer(gci_no_ts_residual_coding_rice_constraint_flag, 0);
164 infer(gci_no_rrc_rice_extension_constraint_flag, 0);
165 infer(gci_no_persistent_rice_adaptation_constraint_flag, 0);
166 infer(gci_no_reverse_last_sig_coeff_constraint_flag, 0);
167 num_additional_bits_used = 0;
168 }
169
170 for (i = 0; i < current->gci_num_additional_bits - num_additional_bits_used; i++)
171 flags(gci_reserved_bit[i], 1, i);
172 }
173 while (byte_alignment(rw) != 0)
174 fixed(1, gci_alignment_zero_bit, 0);
175 return 0;
176}
177
179 RWContext *rw,
181 int profile_tier_present_flag,
182 int max_num_sub_layers_minus1)
183{
184 int err, i;
185
186 if (profile_tier_present_flag) {
187 ub(7, general_profile_idc);
188 flag(general_tier_flag);
189 }
190 ub(8, general_level_idc);
191 flag(ptl_frame_only_constraint_flag);
192 flag(ptl_multilayer_enabled_flag);
193 if (profile_tier_present_flag) {
195 &current->
197 }
198 for (i = max_num_sub_layers_minus1 - 1; i >= 0; i--)
199 flags(ptl_sublayer_level_present_flag[i], 1, i);
200 while (byte_alignment(rw) != 0)
201 flag(ptl_reserved_zero_bit);
202 for (i = max_num_sub_layers_minus1 - 1; i >= 0; i--)
203 if (current->ptl_sublayer_level_present_flag[i])
204 ubs(8, sublayer_level_idc[i], 1, i);
205 if (profile_tier_present_flag) {
206 ub(8, ptl_num_sub_profiles);
207 for (i = 0; i < current->ptl_num_sub_profiles; i++)
208 ubs(32, general_sub_profile_idc[i], 1, i);
209 }
210 return 0;
211}
212
215{
216 //defined in D.8
217 infer(vui_progressive_source_flag, 0);
218 infer(vui_interlaced_source_flag, 0);
219
220 infer(vui_non_packed_constraint_flag, 0);
221 infer(vui_non_projected_constraint_flag, 0);
222
223 infer(vui_aspect_ratio_constant_flag, 0);
224 infer(vui_aspect_ratio_idc, 0);
225
226 infer(vui_overscan_info_present_flag, 0);
227
228 infer(vui_colour_primaries, 2);
229 infer(vui_transfer_characteristics, 2);
230 infer(vui_matrix_coeffs, 2);
231 infer(vui_full_range_flag, 0);
232
233 infer(vui_chroma_sample_loc_type_frame, 6);
234 infer(vui_chroma_sample_loc_type_top_field, 6);
235 infer(vui_chroma_sample_loc_type_bottom_field, 6);
236 return 0;
237}
238
241 uint8_t chroma_format_idc)
242{
243 int err;
244
245 flag(vui_progressive_source_flag);
246 flag(vui_interlaced_source_flag);
247 flag(vui_non_packed_constraint_flag);
248 flag(vui_non_projected_constraint_flag);
249 flag(vui_aspect_ratio_info_present_flag);
250 if (current->vui_aspect_ratio_info_present_flag) {
251 flag(vui_aspect_ratio_constant_flag);
252 ub(8, vui_aspect_ratio_idc);
253 if (current->vui_aspect_ratio_idc == 255) {
254 ub(16, vui_sar_width);
255 ub(16, vui_sar_height);
256 }
257 } else {
258 infer(vui_aspect_ratio_constant_flag, 0);
259 infer(vui_aspect_ratio_idc, 0);
260 }
261 flag(vui_overscan_info_present_flag);
262 if (current->vui_overscan_info_present_flag)
263 flag(vui_overscan_appropriate_flag);
264 flag(vui_colour_description_present_flag);
265 if (current->vui_colour_description_present_flag) {
266 ub(8, vui_colour_primaries);
267 av_log(ctx->log_ctx, AV_LOG_DEBUG, "vui_colour_primaries == %d \n",
268 current->vui_colour_primaries);
269 ub(8, vui_transfer_characteristics);
270 av_log(ctx->log_ctx, AV_LOG_DEBUG,
271 "vui_transfer_characteristics == %d \n",
272 current->vui_transfer_characteristics);
273 ub(8, vui_matrix_coeffs);
274 av_log(ctx->log_ctx, AV_LOG_DEBUG, "vui_matrix_coeffs == %d \n",
275 current->vui_matrix_coeffs);
276 flag(vui_full_range_flag);
277 } else {
278 infer(vui_colour_primaries, 2);
279 infer(vui_transfer_characteristics, 2);
280 infer(vui_matrix_coeffs, 2);
281 infer(vui_full_range_flag, 0);
282 }
283 flag(vui_chroma_loc_info_present_flag);
284 if (chroma_format_idc != 1 && current->vui_chroma_loc_info_present_flag) {
285 av_log(ctx->log_ctx, AV_LOG_ERROR, "chroma_format_idc == %d,"
286 "vui_chroma_loc_info_present_flag can't not be true",
287 chroma_format_idc);
288 return AVERROR_INVALIDDATA;
289 }
290 if (current->vui_chroma_loc_info_present_flag) {
291 if (current->vui_progressive_source_flag &&
292 !current->vui_interlaced_source_flag) {
293 ue(vui_chroma_sample_loc_type_frame, 0, 6);
294 } else {
295 ue(vui_chroma_sample_loc_type_top_field, 0, 6);
296 ue(vui_chroma_sample_loc_type_bottom_field, 0, 6);
297 }
298 } else {
299 if (chroma_format_idc == 1) {
300 infer(vui_chroma_sample_loc_type_frame, 6);
301 infer(vui_chroma_sample_loc_type_top_field,
302 current->vui_chroma_sample_loc_type_frame);
303 infer(vui_chroma_sample_loc_type_bottom_field,
304 current->vui_chroma_sample_loc_type_frame);
305 }
306 }
307 return 0;
308}
309
312 uint32_t payload_size, int cur_pos)
313{
314 int err;
315 size_t byte_length, k;
316
317#ifdef READ
319 int bits_left, payload_zero_bits;
320
321 if (!ff_cbs_h2645_payload_extension_present(rw, payload_size, cur_pos))
322 return 0;
323
324 bits_left = 8 * payload_size - cur_pos;
325 tmp = *rw;
326 if (bits_left > 8)
328 payload_zero_bits = get_bits(&tmp, FFMIN(bits_left, 8));
329 if (!payload_zero_bits)
330 return AVERROR_INVALIDDATA;
331 payload_zero_bits = ff_ctz(payload_zero_bits);
332 current->bit_length = bits_left - payload_zero_bits - 1;
333 allocate(current->data, (current->bit_length + 7) / 8);
334#endif
335
336 byte_length = (current->bit_length + 7) / 8;
337 for (k = 0; k < byte_length; k++) {
338 int length = FFMIN(current->bit_length - k * 8, 8);
339 xu(length, reserved_payload_extension_data, current->data[k],
340 0, MAX_UINT_BITS(length), 0);
341 }
342
343 return 0;
344}
345
347 H266RawVUI *current, uint16_t vui_payload_size,
348 uint8_t chroma_format_idc)
349{
350 int err;
351 int start_position, current_position;
352
353 start_position = bit_position(rw);
354 CHECK(FUNC(vui_parameters) (ctx, rw, current, chroma_format_idc));
355 current_position = bit_position(rw) - start_position;
356
357 if (current_position < 8 * vui_payload_size) {
358 CHECK(FUNC(payload_extension) (ctx, rw, &current->extension_data,
359 vui_payload_size, current_position));
360 fixed(1, vui_payload_bit_equal_to_one, 1);
361 while (byte_alignment(rw) != 0)
362 fixed(1, vui_payload_bit_equal_to_zero, 0);
363 }
364 return 0;
365}
366
369{
370 int err;
371 size_t k;
372#ifdef READ
373 GetBitContext start;
374 uint8_t bit;
375 start = *rw;
376 for (k = 0; ff_cbs_h2645_read_more_rbsp_data(rw); k++)
377 skip_bits(rw, 1);
378 current->bit_length = k;
379 if (k > 0) {
380 *rw = start;
381 allocate(current->data, (current->bit_length + 7) / 8);
382 for (k = 0; k < current->bit_length; k++) {
383 xu(1, extension_data, bit, 0, 1, 0);
384 current->data[k / 8] |= bit << (7 - k % 8);
385 }
386 }
387#else
388 for (k = 0; k < current->bit_length; k++)
389 xu(1, extension_data, current->data[k / 8] >> (7 - k % 8) & 1, 0, 1, 0);
390#endif
391 return 0;
392}
393
396 uint8_t max_sublayers_minus1,
397 uint8_t sublayer_info_flag)
398{
399 int err, i;
400 for (i = (sublayer_info_flag ? 0 : max_sublayers_minus1);
401 i <= max_sublayers_minus1; i++) {
402 ues(dpb_max_dec_pic_buffering_minus1[i], 0, VVC_MAX_DPB_SIZE - 1, 1, i);
403 ues(dpb_max_num_reorder_pics[i],
404 0, current->dpb_max_dec_pic_buffering_minus1[i], 1, i);
405 ues(dpb_max_latency_increase_plus1[i], 0, UINT32_MAX - 1, 1, i);
406 }
407 return 0;
408}
409
411 RWContext *rw,
413 uint8_t list_idx, uint8_t rpls_idx,
414 const H266RawSPS *sps)
415{
416 CodedBitstreamH266Context *h266 = ctx->priv_data;
417 int err, i, j, general_layer_idx = -1, num_direct_ref_layers = 0;
418 const H266RawVPS *vps = h266->vps[sps->sps_video_parameter_set_id];
419
420 if (!vps) {
421 av_log(ctx->log_ctx, AV_LOG_ERROR,
422 "VPS id %d not available.\n", sps->sps_video_parameter_set_id);
423 return AVERROR_INVALIDDATA;
424 }
425 //7.4.3.3 (29)
426 for (i = 0; i <= vps->vps_max_layers_minus1; i++) {
427 if (sps->nal_unit_header.nuh_layer_id == vps->vps_layer_id[i]) {
428 general_layer_idx = i;
429 break;
430 }
431 }
432 if (general_layer_idx < 0) {
433 av_log(ctx->log_ctx, AV_LOG_ERROR, "vps_layer_id %d not available.\n",
434 sps->nal_unit_header.nuh_layer_id);
435 return AVERROR_INVALIDDATA;
436 }
437 //7.4.3.3 (28)
438 for (j = 0; j <= vps->vps_max_layers_minus1; j++) {
439 if (vps->vps_direct_ref_layer_flag[general_layer_idx][j])
440 num_direct_ref_layers++;
441 }
442
443 ue(num_ref_entries, 0, VVC_MAX_REF_ENTRIES);
444 if (sps->sps_long_term_ref_pics_flag &&
445 rpls_idx < sps->sps_num_ref_pic_lists[list_idx] &&
446 current->num_ref_entries > 0)
447 flag(ltrp_in_header_flag);
448 if (sps->sps_long_term_ref_pics_flag &&
449 rpls_idx == sps->sps_num_ref_pic_lists[list_idx])
450 infer(ltrp_in_header_flag, 1);
451 for (i = 0, j = 0; i < current->num_ref_entries; i++) {
452 if (sps->sps_inter_layer_prediction_enabled_flag)
453 flags(inter_layer_ref_pic_flag[i], 1, i);
454 else
455 infer(inter_layer_ref_pic_flag[i], 0);
456
457 if (!current->inter_layer_ref_pic_flag[i]) {
458 if (sps->sps_long_term_ref_pics_flag)
459 flags(st_ref_pic_flag[i], 1, i);
460 else
461 infer(st_ref_pic_flag[i], 1);
462 if (current->st_ref_pic_flag[i]) {
463 int abs_delta_poc_st;
464 ues(abs_delta_poc_st[i], 0, MAX_UINT_BITS(15), 1, i);
465 if ((sps->sps_weighted_pred_flag ||
466 sps->sps_weighted_bipred_flag) && i != 0)
467 abs_delta_poc_st = current->abs_delta_poc_st[i];
468 else
469 abs_delta_poc_st = current->abs_delta_poc_st[i] + 1;
470 if (abs_delta_poc_st > 0)
471 flags(strp_entry_sign_flag[i], 1, i);
472 } else {
473 if (!current->ltrp_in_header_flag) {
474 uint8_t bits = sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4;
475 ubs(bits, rpls_poc_lsb_lt[j], 1, j);
476 j++;
477 }
478 }
479 } else {
480 if (num_direct_ref_layers == 0) {
481 av_log(ctx->log_ctx, AV_LOG_ERROR,
482 "num_direct_ref_layers needs > 0.\n");
483 return AVERROR_INVALIDDATA;
484 }
485 ues(ilrp_idx[i], 0, num_direct_ref_layers - 1, 1, i);
486 }
487 }
488 return 0;
489}
490
492 const H266RawSPS *sps, const H266RawPPS *pps,
494 const H266RefPicListStruct * ref_list;
495 int err, i, j, num_ltrp_entries;
496 for (i = 0; i < 2; i++) {
497 if (sps->sps_num_ref_pic_lists[i] > 0 &&
498 (i == 0 || (i == 1 && pps->pps_rpl1_idx_present_flag))) {
499 flags(rpl_sps_flag[i], 1, i);
500 } else {
501 if (sps->sps_num_ref_pic_lists[i] == 0) {
502 infer(rpl_sps_flag[i], 0);
503 } else {
504 if (!pps->pps_rpl1_idx_present_flag && i == 1)
505 infer(rpl_sps_flag[1], current->rpl_sps_flag[0]);
506 }
507 }
508 if (current->rpl_sps_flag[i]) {
509 if (sps->sps_num_ref_pic_lists[i] > 1 &&
510 (i == 0 || (i == 1 && pps->pps_rpl1_idx_present_flag))) {
511 uint8_t bits = av_ceil_log2(sps->sps_num_ref_pic_lists[i]);
512 us(bits, rpl_idx[i], 0, sps->sps_num_ref_pic_lists[i] - 1, 1, i);
513 } else if (sps->sps_num_ref_pic_lists[i] == 1) {
514 infer(rpl_idx[i], 0);
515 } else if (i == 1 && !pps->pps_rpl1_idx_present_flag) {
516 infer(rpl_idx[1], current->rpl_idx[0]);
517 } else {
518 //how to handle this? or never happpend?
519 av_log(ctx->log_ctx, AV_LOG_ERROR,
520 "can't infer the rpl_idx[i]\n");
522 }
523 memcpy(&current->rpl_ref_list[i],
524 &sps->sps_ref_pic_list_struct[i][current->rpl_idx[i]],
525 sizeof(current->rpl_ref_list[i]));
526 } else {
527 CHECK(FUNC(ref_pic_list_struct) (ctx, rw, &current->rpl_ref_list[i],
528 i, sps->sps_num_ref_pic_lists[i],
529 sps));
530 }
531 ref_list = &current->rpl_ref_list[i];
532
533 num_ltrp_entries = 0;
534 for (int k = 0; k < ref_list->num_ref_entries; k++) {
535 if (!ref_list->inter_layer_ref_pic_flag[k]) {
536 if (!ref_list->st_ref_pic_flag[k]) {
537 num_ltrp_entries++;
538 }
539 }
540 }
541
542 for (j = 0; j < num_ltrp_entries; j++) {
543 if (ref_list->ltrp_in_header_flag) {
544 ubs(sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4,
545 poc_lsb_lt[i][j], 2, i, j);
546 }
547 flags(delta_poc_msb_cycle_present_flag[i][j], 2, i, j);
548 if (current->delta_poc_msb_cycle_present_flag[i][j]) {
549 uint32_t max =
550 1 << (32 - sps->sps_log2_max_pic_order_cnt_lsb_minus4 - 4);
551 ues(delta_poc_msb_cycle_lt[i][j], 0, max, 2, i, j);
552 }
553 }
554 }
555 return 0;
556}
557
559 RWContext *rw,
561{
562 int err;
563 ub(32, num_units_in_tick);
564 u(32, time_scale, 1, MAX_UINT_BITS(32));
565 flag(general_nal_hrd_params_present_flag);
566 flag(general_vcl_hrd_params_present_flag);
567
568 if (current->general_nal_hrd_params_present_flag ||
569 current->general_vcl_hrd_params_present_flag) {
570 flag(general_same_pic_timing_in_all_ols_flag);
571 flag(general_du_hrd_params_present_flag);
572 if (current->general_du_hrd_params_present_flag)
573 ub(8, tick_divisor_minus2);
574 ub(4, bit_rate_scale);
575 ub(4, cpb_size_scale);
576 if (current->general_du_hrd_params_present_flag)
577 ub(4, cpb_size_du_scale);
578 ue(hrd_cpb_cnt_minus1, 0, 31);
579 } else {
580 //infer general_same_pic_timing_in_all_ols_flag?
581 infer(general_du_hrd_params_present_flag, 0);
582 }
583 return 0;
584}
585
587 RWContext *rw,
589 int sublayer_id,
591{
592 int err, i;
593 for (i = 0; i <= general->hrd_cpb_cnt_minus1; i++) {
594 ues(bit_rate_value_minus1[sublayer_id][i], 0, UINT32_MAX - 1, 2,
595 sublayer_id, i);
596 ues(cpb_size_value_minus1[sublayer_id][i], 0, UINT32_MAX - 1, 2,
597 sublayer_id, i);
598 if (general->general_du_hrd_params_present_flag) {
599 ues(cpb_size_du_value_minus1[sublayer_id][i],
600 0, UINT32_MAX - 1, 2, sublayer_id, i);
601 ues(bit_rate_du_value_minus1[sublayer_id][i],
602 0, UINT32_MAX - 1, 2, sublayer_id, i);
603 }
604 flags(cbr_flag[sublayer_id][i], 2, sublayer_id, i);
605 }
606 return 0;
607}
608
611 uint8_t first_sublayer, uint8_t max_sublayers_minus1,
613{
614 int err, i;
615 for (i = first_sublayer; i <= max_sublayers_minus1; i++) {
616 flags(fixed_pic_rate_general_flag[i], 1, i);
617 if (!current->fixed_pic_rate_general_flag[i])
618 flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
619 else
620 infer(fixed_pic_rate_within_cvs_flag[i], 1);
621 if (current->fixed_pic_rate_within_cvs_flag[i]) {
622 ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
623 infer(low_delay_hrd_flag[i], 0);
624 } else if ((general->general_nal_hrd_params_present_flag ||
625 general->general_vcl_hrd_params_present_flag) &&
626 general->hrd_cpb_cnt_minus1 == 0) {
627 flags(low_delay_hrd_flag[i], 1, i);
628 } else {
629 infer(low_delay_hrd_flag[i], 0);
630 }
631 if (general->general_nal_hrd_params_present_flag)
633 &current->nal_sub_layer_hrd_parameters,
634 i, general));
635 if (general->general_vcl_hrd_params_present_flag)
637 &current->nal_sub_layer_hrd_parameters,
638 i, general));
639 }
640 return 0;
641}
642
645{
646 int err;
647
648 HEADER("Operating point information");
649
651 &current->nal_unit_header, VVC_OPI_NUT));
652
653 flag(opi_ols_info_present_flag);
654 flag(opi_htid_info_present_flag);
655
656 if(current->opi_ols_info_present_flag)
657 ue(opi_ols_idx, 0, VVC_MAX_TOTAL_NUM_OLSS - 1);
658
659 if(current->opi_htid_info_present_flag)
660 ub(3, opi_htid_plus1);
661
662 flag(opi_extension_flag);
663 if (current->opi_extension_flag)
664 CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
666
667 return 0;
668}
669
672{
673 int err, i;
674
675 HEADER("Decoding capability information");
676
678 &current->nal_unit_header, VVC_DCI_NUT));
679
680 ub(4, dci_reserved_zero_4bits);
681 ub(4, dci_num_ptls_minus1);
682 for (i = 0; i <= current->dci_num_ptls_minus1; i++)
684 current->dci_profile_tier_level + i, 1, 0));
685
686 flag(dci_extension_flag);
687 if (current->dci_extension_flag)
688 CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
690
691 return 0;
692}
693
696{
697 int err, i, j, k;
698 uint16_t total_num_olss = 0;
699 uint8_t ols_mode_idc = 0;
700 uint16_t num_multi_layer_olss = 0;
701 uint8_t layer_included_in_ols_flag[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_LAYERS];
702 uint8_t num_ref_layers[VVC_MAX_LAYERS];
703 uint8_t reference_layer_idx[VVC_MAX_LAYERS][VVC_MAX_LAYERS];
704
705 HEADER("Video Parameter Set");
706
708 &current->nal_unit_header, VVC_VPS_NUT));
709
710 u(4, vps_video_parameter_set_id, 1, VVC_MAX_VPS_COUNT - 1);
711 ub(6, vps_max_layers_minus1);
712 u(3, vps_max_sublayers_minus1, 0, 6);
713 if (current->vps_max_layers_minus1 > 0
714 && current->vps_max_sublayers_minus1 > 0)
715 flag(vps_default_ptl_dpb_hrd_max_tid_flag);
716 else
717 infer(vps_default_ptl_dpb_hrd_max_tid_flag, 1);
718
719 if (current->vps_max_layers_minus1 > 0)
720 flag(vps_all_independent_layers_flag);
721 else
722 infer(vps_all_independent_layers_flag, 1);
723
724 for (i = 0; i <= current->vps_max_layers_minus1; i++) {
725 ubs(6, vps_layer_id[i], 1, i);
726 if (i > 0 && current->vps_layer_id[i] <= current->vps_layer_id[i - 1]) {
727 av_log(ctx->log_ctx, AV_LOG_ERROR,
728 "vps_layer_id[%d](%d) should > vps_layer_id[%d](%d).\n",
729 i, current->vps_layer_id[i], i - 1,
730 current->vps_layer_id[i - 1]);
731 return AVERROR_INVALIDDATA;
732 }
733 if (i > 0 && !current->vps_all_independent_layers_flag) {
734 flags(vps_independent_layer_flag[i], 1, i);
735 if (!current->vps_independent_layer_flag[i]) {
736 flags(vps_max_tid_ref_present_flag[i], 1, i);
737 for (j = 0; j < i; j++) {
738 flags(vps_direct_ref_layer_flag[i][j], 2, i, j);
739 if (current->vps_max_tid_ref_present_flag[i] &&
740 current->vps_direct_ref_layer_flag[i][j]) {
741 ubs(3, vps_max_tid_il_ref_pics_plus1[i][j], 2, i, j);
742 } else {
743 infer(vps_max_tid_il_ref_pics_plus1[i][j],
744 current->vps_max_sublayers_minus1 + 1);
745 }
746 }
747 } else {
748 for (j = 0; j < i; j++) {
749 infer(vps_direct_ref_layer_flag[i][j], 0);
750 }
751 }
752 } else {
753 infer(vps_independent_layer_flag[i], 1);
754 for (j = 0; j < i; j++) {
755 infer(vps_direct_ref_layer_flag[i][j], 0);
756 }
757 }
758 }
759
760 if (current->vps_max_layers_minus1 > 0) {
761 if (current->vps_all_independent_layers_flag)
762 flag(vps_each_layer_is_an_ols_flag);
763 else
764 infer(vps_each_layer_is_an_ols_flag, 0);
765 if (!current->vps_each_layer_is_an_ols_flag) {
766 if (!current->vps_all_independent_layers_flag)
767 ub(2, vps_ols_mode_idc);
768 else
769 infer(vps_ols_mode_idc, 2);
770 if (current->vps_ols_mode_idc == 2) {
771 ub(8, vps_num_output_layer_sets_minus2);
772 for (i = 1; i <= current->vps_num_output_layer_sets_minus2 + 1;
773 i++)
774 for (j = 0; j <= current->vps_max_layers_minus1; j++)
775 flags(vps_ols_output_layer_flag[i][j], 2, i, j);
776 }
777 ols_mode_idc = current->vps_ols_mode_idc;
778 } else {
779 ols_mode_idc = 4;
780 }
781 if (ols_mode_idc == 4 || ols_mode_idc == 0 || ols_mode_idc == 1)
782 total_num_olss = current->vps_max_layers_minus1 + 1;
783 else if (ols_mode_idc == 2)
784 total_num_olss = current->vps_num_output_layer_sets_minus2 + 2;
785 else
786 av_log(ctx->log_ctx, AV_LOG_ERROR,
787 "ols_mode_idc == 3, patch welcome");
788 u(8, vps_num_ptls_minus1, 0, total_num_olss - 1);
789 } else {
790 infer(vps_each_layer_is_an_ols_flag, 1);
791 infer(vps_num_ptls_minus1, 0);
792 }
793
794 for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
795 if (i > 0)
796 flags(vps_pt_present_flag[i], 1, i);
797 else
798 infer(vps_pt_present_flag[i], 1);
799
800 if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
801 us(3, vps_ptl_max_tid[i], 0, current->vps_max_sublayers_minus1, 1, i);
802 else
803 infer(vps_ptl_max_tid[i], current->vps_max_sublayers_minus1);
804 }
805 while (byte_alignment(rw) != 0)
806 fixed(1, vps_ptl_alignment_zero_bit, 0);
807
808 {
809 //calc NumMultiLayerOlss
810 int m;
811 uint8_t dependency_flag[VVC_MAX_LAYERS][VVC_MAX_LAYERS];
812 uint16_t num_output_layers_in_ols[VVC_MAX_TOTAL_NUM_OLSS];
813 uint8_t num_sub_layers_in_layer_in_ols[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_TOTAL_NUM_OLSS];
814 uint8_t output_layer_idx[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_LAYERS];
815
816 //7.4.3.3 vps_direct_ref_layer_flag section
817 for (i = 0; i <= current->vps_max_layers_minus1; i++) {
818 for (j = 0; j <= current->vps_max_layers_minus1; j++) {
819 dependency_flag[i][j] = current->vps_direct_ref_layer_flag[i][j];
820 for (k = 0; k < i; k++) {
821 if (current->vps_direct_ref_layer_flag[i][k] &&
822 dependency_flag[k][j])
823 dependency_flag[i][j] = 1;
824 }
825 }
826 }
827 for (i = 0; i <= current->vps_max_layers_minus1; i++) {
828 int r;
829 for (j = 0, r = 0; j <= current->vps_max_layers_minus1; j++) {
830 if (dependency_flag[i][j])
831 reference_layer_idx[i][r++] = j;
832 }
833 num_ref_layers[i] = r;
834 }
835
836 //7.4.3.3 vps_ols_output_layer_flag section
837 num_output_layers_in_ols[0] = 1;
838 num_sub_layers_in_layer_in_ols[0][0] =
839 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[0]] + 1;
840 for (i = 1; i < total_num_olss; i++) {
841 if (ols_mode_idc == 4 || ols_mode_idc == 0) {
842 num_output_layers_in_ols[i] = 1;
843 if (current->vps_each_layer_is_an_ols_flag) {
844 num_sub_layers_in_layer_in_ols[i][0] =
845 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
846 } else {
847 num_sub_layers_in_layer_in_ols[i][i] =
848 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
849 for (k = i - 1; k >= 0; k--) {
850 num_sub_layers_in_layer_in_ols[i][k] = 0;
851 for (m = k + 1; m <= i; m++) {
852 uint8_t max_sublayer_needed =
853 FFMIN(num_sub_layers_in_layer_in_ols[i][m],
854 current->vps_max_tid_il_ref_pics_plus1[m][k]);
855 if (current->vps_direct_ref_layer_flag[m][k] &&
856 num_sub_layers_in_layer_in_ols[i][k] < max_sublayer_needed)
857 num_sub_layers_in_layer_in_ols[i][k] = max_sublayer_needed;
858 }
859 }
860 }
861 } else if (current->vps_ols_mode_idc == 1) {
862 num_output_layers_in_ols[i] = i + 1;
863 for (j = 0; j < num_output_layers_in_ols[i]; j++) {
864 num_sub_layers_in_layer_in_ols[i][j] =
865 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
866 }
867 } else if (current->vps_ols_mode_idc == 2) {
868 uint8_t highest_included_layer = 0;
869 for (j = 0; j <= current->vps_max_layers_minus1; j++) {
870 layer_included_in_ols_flag[i][j] = 0;
871 num_sub_layers_in_layer_in_ols[i][j] = 0;
872 }
873 for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++) {
874 if (current->vps_ols_output_layer_flag[i][k]) {
875 layer_included_in_ols_flag[i][k] = 1;
876 highest_included_layer = k;
877 output_layer_idx[i][j] = k;
878 num_sub_layers_in_layer_in_ols[i][k] =
879 current->vps_ptl_max_tid[current->
880 vps_ols_ptl_idx[i]] + 1;
881 j++;
882 }
883 }
884 num_output_layers_in_ols[i] = j;
885 for (j = 0; j < num_output_layers_in_ols[i]; j++) {
886 int idx = output_layer_idx[i][j];
887 for (k = 0; k < num_ref_layers[idx]; k++) {
888 if (!layer_included_in_ols_flag[i][reference_layer_idx[idx][k]])
889 layer_included_in_ols_flag[i][reference_layer_idx[idx][k]] = 1;
890 }
891 }
892 for (k = highest_included_layer - 1; k >= 0; k--) {
893 if (layer_included_in_ols_flag[i][k] &&
894 !current->vps_ols_output_layer_flag[i][k]) {
895 for (m = k + 1; m <= highest_included_layer; m++) {
896 uint8_t max_sublayer_needed =
897 FFMIN(num_sub_layers_in_layer_in_ols[i][m],
898 current->vps_max_tid_il_ref_pics_plus1[m][k]);
899 if (current->vps_direct_ref_layer_flag[m][k] &&
900 layer_included_in_ols_flag[i][m] &&
901 num_sub_layers_in_layer_in_ols[i][k] <
902 max_sublayer_needed)
903 num_sub_layers_in_layer_in_ols[i][k] =
904 max_sublayer_needed;
905 }
906 }
907 }
908 }
909 if (!num_output_layers_in_ols[i])
910 return AVERROR_INVALIDDATA;
911 }
912 for (i = 1; i < total_num_olss; i++) {
913 int num_layers_in_ols = 0;
914 if (current->vps_each_layer_is_an_ols_flag) {
915 num_layers_in_ols = 1;
916 } else if (current->vps_ols_mode_idc == 0 ||
917 current->vps_ols_mode_idc == 1) {
918 num_layers_in_ols = i + 1;
919 } else if (current->vps_ols_mode_idc == 2) {
920 for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++)
921 if (layer_included_in_ols_flag[i][k])
922 j++;
923 num_layers_in_ols = j;
924 }
925 if (num_layers_in_ols > 1) {
926 num_multi_layer_olss++;
927 }
928 }
929 if (!current->vps_each_layer_is_an_ols_flag && num_multi_layer_olss == 0)
930 return AVERROR_INVALIDDATA;
931 }
932
933 for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
935 current->vps_profile_tier_level + i,
936 current->vps_pt_present_flag[i],
937 current->vps_ptl_max_tid[i]));
938 }
939 for (i = 0; i < total_num_olss; i++) {
940 if (current->vps_num_ptls_minus1 > 0 &&
941 current->vps_num_ptls_minus1 + 1 != total_num_olss) {
942 us(8, vps_ols_ptl_idx[i], 0, current->vps_num_ptls_minus1, 1, i);
943 } else if (current->vps_num_ptls_minus1 == 0) {
944 infer(vps_ols_ptl_idx[i], 0);
945 } else {
946 infer(vps_ols_ptl_idx[i], i);
947 }
948 }
949
950 if (!current->vps_each_layer_is_an_ols_flag) {
951 uint16_t vps_num_dpb_params;
952 ue(vps_num_dpb_params_minus1, 0, num_multi_layer_olss - 1);
953 if (current->vps_each_layer_is_an_ols_flag)
954 vps_num_dpb_params = 0;
955 else
956 vps_num_dpb_params = current->vps_num_dpb_params_minus1 + 1;
957
958 if (current->vps_max_sublayers_minus1 > 0)
959 flag(vps_sublayer_dpb_params_present_flag);
960 else
961 infer(vps_sublayer_dpb_params_present_flag, 0);
962
963 for (i = 0; i < vps_num_dpb_params; i++) {
964 if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
965 us(3, vps_dpb_max_tid[i], 0, current->vps_max_sublayers_minus1,
966 1, i);
967 else
968 infer(vps_dpb_max_tid[i], current->vps_max_sublayers_minus1);
969 CHECK(FUNC(dpb_parameters) (ctx, rw, current->vps_dpb_params + i,
970 current->vps_dpb_max_tid[i],
971 current->
972 vps_sublayer_dpb_params_present_flag));
973 }
974 for (i = 0; i < num_multi_layer_olss; i++) {
975 ues(vps_ols_dpb_pic_width[i], 0, UINT16_MAX, 1, i);
976 ues(vps_ols_dpb_pic_height[i], 0, UINT16_MAX, 1, i);
977 ubs(2, vps_ols_dpb_chroma_format[i], 1, i);
978 ues(vps_ols_dpb_bitdepth_minus8[i], 0, 8, 1, i);
979 if (vps_num_dpb_params > 1
980 && vps_num_dpb_params != num_multi_layer_olss)
981 ues(vps_ols_dpb_params_idx[i], 0, vps_num_dpb_params - 1, 1, i);
982 else if (vps_num_dpb_params == 1)
983 infer(vps_ols_dpb_params_idx[i], 0);
984 else
985 infer(vps_ols_dpb_params_idx[i], i);
986 }
987 flag(vps_timing_hrd_params_present_flag);
988 if (current->vps_timing_hrd_params_present_flag) {
990 &current->
991 vps_general_timing_hrd_parameters));
992 if (current->vps_max_sublayers_minus1 > 0)
993 flag(vps_sublayer_cpb_params_present_flag);
994 else
995 infer(vps_sublayer_cpb_params_present_flag, 0);
996 ue(vps_num_ols_timing_hrd_params_minus1, 0,
997 num_multi_layer_olss - 1);
998 for (i = 0; i <= current->vps_num_ols_timing_hrd_params_minus1; i++) {
999 uint8_t first_sublayer;
1000 if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
1001 us(3, vps_hrd_max_tid[i], 0,
1002 current->vps_max_sublayers_minus1, 1, i);
1003 else
1004 infer(vps_hrd_max_tid[i],
1005 current->vps_max_sublayers_minus1);
1006 first_sublayer = current->vps_sublayer_cpb_params_present_flag ?
1007 0 : current->vps_hrd_max_tid[i];
1009 (ctx, rw, &current->vps_ols_timing_hrd_parameters,
1010 first_sublayer, current->vps_max_sublayers_minus1,
1011 &current->vps_general_timing_hrd_parameters));
1012
1013 }
1014 if (current->vps_num_ols_timing_hrd_params_minus1 > 0 &&
1015 current->vps_num_ols_timing_hrd_params_minus1 + 1 !=
1016 num_multi_layer_olss) {
1017 for (i = 0; i < num_multi_layer_olss; i++) {
1018 ues(vps_ols_timing_hrd_idx[i], 0,
1019 current->vps_num_ols_timing_hrd_params_minus1, 1, i);
1020 }
1021 } else if (current->vps_num_ols_timing_hrd_params_minus1 == 0) {
1022 for (i = 0; i < num_multi_layer_olss; i++)
1023 infer(vps_ols_timing_hrd_idx[i], 0);
1024 } else {
1025 for (i = 0; i < num_multi_layer_olss; i++)
1026 infer(vps_ols_timing_hrd_idx[i], i);
1027 }
1028 }
1029 }
1030
1031 flag(vps_extension_flag);
1032 if (current->vps_extension_flag)
1033 CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
1035
1036 return 0;
1037}
1038
1041{
1042 int err;
1043
1044 flag(sps_extended_precision_flag);
1045 if (current->sps_transform_skip_enabled_flag)
1046 flag(sps_ts_residual_coding_rice_present_in_sh_flag);
1047 else
1048 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1049 flag(sps_rrc_rice_extension_flag);
1050 flag(sps_persistent_rice_adaptation_enabled_flag);
1051 flag(sps_reverse_last_sig_coeff_enabled_flag);
1052
1053 return 0;
1054}
1055
1058{
1059 CodedBitstreamH266Context *h266 = ctx->priv_data;
1060 int err, i, j, max_width_minus1, max_height_minus1;
1061 unsigned int ctb_log2_size_y, min_cb_log2_size_y,
1062 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y,
1063 ctb_size_y, max_num_merge_cand, tmp_width_val, tmp_height_val;
1064 uint8_t qp_bd_offset, sub_width_c, sub_height_c;
1065
1066 static const uint8_t h266_sub_width_c[] = {
1067 1, 2, 2, 1
1068 };
1069 static const uint8_t h266_sub_height_c[] = {
1070 1, 2, 1, 1
1071 };
1072
1073 HEADER("Sequence Parameter Set");
1074
1076 &current->nal_unit_header, VVC_SPS_NUT));
1077
1078 ub(4, sps_seq_parameter_set_id);
1079 ub(4, sps_video_parameter_set_id);
1080 if (current->sps_video_parameter_set_id == 0 && !h266->vps[0]) {
1082 if (!vps)
1083 return AVERROR(ENOMEM);
1084 vps->vps_max_layers_minus1 = 0;
1085 vps->vps_independent_layer_flag[0] = 1;
1086 vps->vps_layer_id[0] = current->nal_unit_header.nuh_layer_id;
1087 h266->vps[0] = vps;
1088 }
1089
1090 u(3, sps_max_sublayers_minus1, 0, VVC_MAX_SUBLAYERS - 1);
1091 u(2, sps_chroma_format_idc, 0, 3);
1092 sub_width_c = h266_sub_width_c[current->sps_chroma_format_idc];
1093 sub_height_c = h266_sub_height_c[current->sps_chroma_format_idc];
1094
1095 u(2, sps_log2_ctu_size_minus5, 0, 3);
1096 ctb_log2_size_y = current->sps_log2_ctu_size_minus5 + 5;
1097 ctb_size_y = 1 << ctb_log2_size_y;
1098
1099 flag(sps_ptl_dpb_hrd_params_present_flag);
1100 if (current->sps_ptl_dpb_hrd_params_present_flag) {
1101 CHECK(FUNC(profile_tier_level) (ctx, rw, &current->profile_tier_level,
1102 1, current->sps_max_sublayers_minus1));
1103 }
1104 flag(sps_gdr_enabled_flag);
1105 flag(sps_ref_pic_resampling_enabled_flag);
1106 if (current->sps_ref_pic_resampling_enabled_flag)
1107 flag(sps_res_change_in_clvs_allowed_flag);
1108 else
1109 infer(sps_res_change_in_clvs_allowed_flag, 0);
1110
1111 ue(sps_pic_width_max_in_luma_samples, 1, VVC_MAX_WIDTH);
1112 ue(sps_pic_height_max_in_luma_samples, 1, VVC_MAX_HEIGHT);
1113
1114 flag(sps_conformance_window_flag);
1115 if (current->sps_conformance_window_flag) {
1116 uint16_t width = current->sps_pic_width_max_in_luma_samples / sub_width_c;
1117 uint16_t height = current->sps_pic_height_max_in_luma_samples / sub_height_c;
1118 ue(sps_conf_win_left_offset, 0, width);
1119 ue(sps_conf_win_right_offset, 0, width - current->sps_conf_win_left_offset);
1120 ue(sps_conf_win_top_offset, 0, height);
1121 ue(sps_conf_win_bottom_offset, 0, height - current->sps_conf_win_top_offset);
1122 } else {
1123 infer(sps_conf_win_left_offset, 0);
1124 infer(sps_conf_win_right_offset, 0);
1125 infer(sps_conf_win_top_offset, 0);
1126 infer(sps_conf_win_bottom_offset, 0);
1127 }
1128
1129 tmp_width_val = AV_CEIL_RSHIFT(current->sps_pic_width_max_in_luma_samples,
1130 ctb_log2_size_y);
1131 tmp_height_val = AV_CEIL_RSHIFT(current->sps_pic_height_max_in_luma_samples,
1132 ctb_log2_size_y);
1133 max_width_minus1 = tmp_width_val - 1;
1134 max_height_minus1 = tmp_height_val - 1;
1135
1136 u(1, sps_subpic_info_present_flag, 0, !current->sps_res_change_in_clvs_allowed_flag);
1137 if (current->sps_subpic_info_present_flag) {
1138 ue(sps_num_subpics_minus1, 0, VVC_MAX_SLICES - 1);
1139 if (current->sps_num_subpics_minus1 > 0) {
1140 flag(sps_independent_subpics_flag);
1141 flag(sps_subpic_same_size_flag);
1142 }
1143
1144 if (current->sps_num_subpics_minus1 > 0) {
1145 int wlen = av_ceil_log2(tmp_width_val);
1146 int hlen = av_ceil_log2(tmp_height_val);
1147 infer(sps_subpic_ctu_top_left_x[0], 0);
1148 infer(sps_subpic_ctu_top_left_y[0], 0);
1149 if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1150 us(wlen, sps_subpic_width_minus1[0], 0, max_width_minus1, 1, 0);
1151 else
1152 infer(sps_subpic_width_minus1[0], max_width_minus1);
1153 if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1154 us(hlen, sps_subpic_height_minus1[0], 0, max_height_minus1, 1, 0);
1155 else
1156 infer(sps_subpic_height_minus1[0], max_height_minus1);
1157 if (!current->sps_independent_subpics_flag) {
1158 flags(sps_subpic_treated_as_pic_flag[0], 1, 0);
1159 flags(sps_loop_filter_across_subpic_enabled_flag[0], 1, 0);
1160 } else {
1161 infer(sps_subpic_treated_as_pic_flag[0], 1);
1162 infer(sps_loop_filter_across_subpic_enabled_flag[0], 1);
1163 }
1164 for (i = 1; i <= current->sps_num_subpics_minus1; i++) {
1165 if (!current->sps_subpic_same_size_flag) {
1166 const int win_right_edge =
1167 current->sps_pic_width_max_in_luma_samples -
1168 current->sps_conf_win_right_offset * sub_width_c;
1169 const int win_bottom_edge =
1170 current->sps_pic_height_max_in_luma_samples -
1171 current->sps_conf_win_bottom_offset * sub_height_c;
1172 const int win_left_edge =
1173 current->sps_conf_win_left_offset * sub_width_c;
1174 const int win_top_edge =
1175 current->sps_conf_win_top_offset * sub_height_c;
1176 const int win_left_edge_ctus =
1177 AV_CEIL_RSHIFT(win_left_edge, ctb_log2_size_y);
1178 const int win_right_edge_ctus =
1179 AV_CEIL_RSHIFT(win_right_edge, ctb_log2_size_y);
1180 const int win_top_edge_ctus =
1181 AV_CEIL_RSHIFT(win_top_edge, ctb_log2_size_y);
1182 const int win_bottom_edge_ctus =
1183 AV_CEIL_RSHIFT(win_bottom_edge, ctb_log2_size_y);
1184 const int min_width =
1185 FFMAX(win_left_edge_ctus - current->sps_subpic_ctu_top_left_x[i], 0);
1186 const int min_height =
1187 FFMAX(win_top_edge_ctus - current->sps_subpic_ctu_top_left_y[i], 0);
1188
1189 if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1190 us(wlen, sps_subpic_ctu_top_left_x[i], 0, win_right_edge_ctus - 1, 1, i);
1191 else
1192 infer(sps_subpic_ctu_top_left_x[i], 0);
1193
1194 if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1195 us(hlen, sps_subpic_ctu_top_left_y[i], 0, win_bottom_edge_ctus - 1, 1, i);
1196 else
1197 infer(sps_subpic_ctu_top_left_y[i], 0);
1198
1199 max_width_minus1 = tmp_width_val - current->sps_subpic_ctu_top_left_x[i] - 1;
1200 max_height_minus1 = tmp_height_val - current->sps_subpic_ctu_top_left_y[i] - 1;
1201
1202 if (i < current->sps_num_subpics_minus1 &&
1203 current->sps_pic_width_max_in_luma_samples > ctb_size_y) {
1204 us(wlen, sps_subpic_width_minus1[i], min_width, max_width_minus1, 1, i);
1205 } else {
1206 infer(sps_subpic_width_minus1[i], max_width_minus1);
1207 }
1208
1209 if (i < current->sps_num_subpics_minus1 &&
1210 current->sps_pic_height_max_in_luma_samples > ctb_size_y) {
1211 us(hlen, sps_subpic_height_minus1[i], min_height, max_height_minus1, 1, i);
1212 } else {
1213 infer(sps_subpic_height_minus1[i], max_height_minus1);
1214 }
1215 } else {
1216 int num_subpic_cols = tmp_width_val /
1217 (current->sps_subpic_width_minus1[0] + 1);
1218 if (tmp_width_val % (current->sps_subpic_width_minus1[0] + 1) ||
1219 tmp_height_val % (current->sps_subpic_height_minus1[0] + 1) ||
1220 current->sps_num_subpics_minus1 !=
1221 (num_subpic_cols * tmp_height_val /
1222 (current->sps_subpic_height_minus1[0] + 1) - 1))
1223 return AVERROR_INVALIDDATA;
1224 infer(sps_subpic_ctu_top_left_x[i],
1225 (i % num_subpic_cols) *
1226 (current->sps_subpic_width_minus1[0] + 1));
1227 infer(sps_subpic_ctu_top_left_y[i],
1228 (i / num_subpic_cols) *
1229 (current->sps_subpic_height_minus1[0] + 1));
1230 infer(sps_subpic_width_minus1[i],
1231 current->sps_subpic_width_minus1[0]);
1232 infer(sps_subpic_height_minus1[i],
1233 current->sps_subpic_height_minus1[0]);
1234 }
1235 if (!current->sps_independent_subpics_flag) {
1236 flags(sps_subpic_treated_as_pic_flag[i], 1, i);
1237 flags(sps_loop_filter_across_subpic_enabled_flag[i], 1, i);
1238 } else {
1239 infer(sps_subpic_treated_as_pic_flag[i], 1);
1240 infer(sps_loop_filter_across_subpic_enabled_flag[i], 0);
1241 }
1242 }
1243 } else {
1244 infer(sps_subpic_ctu_top_left_x[0], 0);
1245 infer(sps_subpic_ctu_top_left_y[0], 0);
1246 infer(sps_subpic_width_minus1[0], max_width_minus1);
1247 infer(sps_subpic_height_minus1[0], max_height_minus1);
1248 }
1249 ue(sps_subpic_id_len_minus1, 0, 15);
1250 if ((1 << (current->sps_subpic_id_len_minus1 + 1)) <
1251 current->sps_num_subpics_minus1 + 1) {
1252 av_log(ctx->log_ctx, AV_LOG_ERROR,
1253 "sps_subpic_id_len_minus1(%d) is too small\n",
1254 current->sps_subpic_id_len_minus1);
1255 return AVERROR_INVALIDDATA;
1256 }
1257 flag(sps_subpic_id_mapping_explicitly_signalled_flag);
1258 if (current->sps_subpic_id_mapping_explicitly_signalled_flag) {
1259 flag(sps_subpic_id_mapping_present_flag);
1260 if (current->sps_subpic_id_mapping_present_flag) {
1261 for (i = 0; i <= current->sps_num_subpics_minus1; i++) {
1262 ubs(current->sps_subpic_id_len_minus1 + 1,
1263 sps_subpic_id[i], 1, i);
1264 }
1265 }
1266 }
1267 } else {
1268 infer(sps_num_subpics_minus1, 0);
1269 infer(sps_independent_subpics_flag, 1);
1270 infer(sps_subpic_same_size_flag, 0);
1271 infer(sps_subpic_id_mapping_explicitly_signalled_flag, 0);
1272 infer(sps_subpic_ctu_top_left_x[0], 0);
1273 infer(sps_subpic_ctu_top_left_y[0], 0);
1274 infer(sps_subpic_width_minus1[0], max_width_minus1);
1275 infer(sps_subpic_height_minus1[0], max_height_minus1);
1276 }
1277
1278
1279 ue(sps_bitdepth_minus8, 0, 8);
1280 qp_bd_offset = 6 * current->sps_bitdepth_minus8;
1281
1282 flag(sps_entropy_coding_sync_enabled_flag);
1283 flag(sps_entry_point_offsets_present_flag);
1284
1285 u(4, sps_log2_max_pic_order_cnt_lsb_minus4, 0, 12);
1286 flag(sps_poc_msb_cycle_flag);
1287 if (current->sps_poc_msb_cycle_flag)
1288 ue(sps_poc_msb_cycle_len_minus1,
1289 0, 32 - current->sps_log2_max_pic_order_cnt_lsb_minus4 - 5);
1290
1291 u(2, sps_num_extra_ph_bytes, 0, 2);
1292 for (i = 0; i < (current->sps_num_extra_ph_bytes * 8); i++) {
1293 flags(sps_extra_ph_bit_present_flag[i], 1, i);
1294 }
1295
1296 u(2, sps_num_extra_sh_bytes, 0, 2);
1297 for (i = 0; i < (current->sps_num_extra_sh_bytes * 8); i++) {
1298 flags(sps_extra_sh_bit_present_flag[i], 1, i);
1299 }
1300
1301 if (current->sps_ptl_dpb_hrd_params_present_flag) {
1302 if (current->sps_max_sublayers_minus1 > 0)
1303 flag(sps_sublayer_dpb_params_flag);
1304 else
1305 infer(sps_sublayer_dpb_params_flag, 0);
1306 CHECK(FUNC(dpb_parameters) (ctx, rw, &current->sps_dpb_params,
1307 current->sps_max_sublayers_minus1,
1308 current->sps_sublayer_dpb_params_flag));
1309 }
1310
1311 ue(sps_log2_min_luma_coding_block_size_minus2,
1312 0, FFMIN(4, current->sps_log2_ctu_size_minus5 + 3));
1313 min_cb_log2_size_y =
1314 current->sps_log2_min_luma_coding_block_size_minus2 + 2;
1315
1316 flag(sps_partition_constraints_override_enabled_flag);
1317
1318 ue(sps_log2_diff_min_qt_min_cb_intra_slice_luma,
1319 0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1320 min_qt_log2_size_intra_y =
1321 current->sps_log2_diff_min_qt_min_cb_intra_slice_luma +
1322 min_cb_log2_size_y;
1323
1324 ue(sps_max_mtt_hierarchy_depth_intra_slice_luma,
1325 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1326
1327 if (current->sps_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
1328 ue(sps_log2_diff_max_bt_min_qt_intra_slice_luma,
1329 0, ctb_log2_size_y - min_qt_log2_size_intra_y);
1330 ue(sps_log2_diff_max_tt_min_qt_intra_slice_luma,
1331 0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
1332 } else {
1333 infer(sps_log2_diff_max_bt_min_qt_intra_slice_luma, 0);
1334 infer(sps_log2_diff_max_tt_min_qt_intra_slice_luma, 0);
1335 }
1336
1337 if (current->sps_chroma_format_idc != 0) {
1338 flag(sps_qtbtt_dual_tree_intra_flag);
1339 } else {
1340 infer(sps_qtbtt_dual_tree_intra_flag, 0);
1341 }
1342
1343 if (current->sps_qtbtt_dual_tree_intra_flag) {
1344 ue(sps_log2_diff_min_qt_min_cb_intra_slice_chroma,
1345 0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1346 ue(sps_max_mtt_hierarchy_depth_intra_slice_chroma,
1347 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1348 if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
1349 unsigned int min_qt_log2_size_intra_c =
1350 current->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
1351 min_cb_log2_size_y;
1352 ue(sps_log2_diff_max_bt_min_qt_intra_slice_chroma,
1353 0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1354 ue(sps_log2_diff_max_tt_min_qt_intra_slice_chroma,
1355 0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1356 }
1357 } else {
1358 infer(sps_log2_diff_min_qt_min_cb_intra_slice_chroma, 0);
1359 infer(sps_max_mtt_hierarchy_depth_intra_slice_chroma, 0);
1360 }
1361 if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma == 0) {
1362 infer(sps_log2_diff_max_bt_min_qt_intra_slice_chroma, 0);
1363 infer(sps_log2_diff_max_tt_min_qt_intra_slice_chroma, 0);
1364 }
1365
1366 ue(sps_log2_diff_min_qt_min_cb_inter_slice,
1367 0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1368 min_qt_log2_size_inter_y =
1369 current->sps_log2_diff_min_qt_min_cb_inter_slice + min_cb_log2_size_y;
1370
1371 ue(sps_max_mtt_hierarchy_depth_inter_slice,
1372 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1373 if (current->sps_max_mtt_hierarchy_depth_inter_slice != 0) {
1374 ue(sps_log2_diff_max_bt_min_qt_inter_slice,
1375 0, ctb_log2_size_y - min_qt_log2_size_inter_y);
1376 ue(sps_log2_diff_max_tt_min_qt_inter_slice,
1377 0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
1378 } else {
1379 infer(sps_log2_diff_max_bt_min_qt_inter_slice, 0);
1380 infer(sps_log2_diff_max_tt_min_qt_inter_slice, 0);
1381 }
1382
1383 if (ctb_size_y > 32)
1384 flag(sps_max_luma_transform_size_64_flag);
1385 else
1386 infer(sps_max_luma_transform_size_64_flag, 0);
1387
1388 flag(sps_transform_skip_enabled_flag);
1389 if (current->sps_transform_skip_enabled_flag) {
1390 ue(sps_log2_transform_skip_max_size_minus2, 0, 3);
1391 flag(sps_bdpcm_enabled_flag);
1392 }
1393
1394 flag(sps_mts_enabled_flag);
1395 if (current->sps_mts_enabled_flag) {
1396 flag(sps_explicit_mts_intra_enabled_flag);
1397 flag(sps_explicit_mts_inter_enabled_flag);
1398 } else {
1399 infer(sps_explicit_mts_intra_enabled_flag, 0);
1400 infer(sps_explicit_mts_inter_enabled_flag, 0);
1401 }
1402
1403 flag(sps_lfnst_enabled_flag);
1404
1405 if (current->sps_chroma_format_idc != 0) {
1406 uint8_t num_qp_tables;
1407 flag(sps_joint_cbcr_enabled_flag);
1408 flag(sps_same_qp_table_for_chroma_flag);
1409 num_qp_tables = current->sps_same_qp_table_for_chroma_flag ?
1410 1 : (current->sps_joint_cbcr_enabled_flag ? 3 : 2);
1411 for (i = 0; i < num_qp_tables; i++) {
1412 ses(sps_qp_table_start_minus26[i], -26 - qp_bd_offset, 36, 1, i);
1413 ues(sps_num_points_in_qp_table_minus1[i],
1414 0, 36 - current->sps_qp_table_start_minus26[i], 1, i);
1415 for (j = 0; j <= current->sps_num_points_in_qp_table_minus1[i]; j++) {
1416 uint8_t max = MAX_UINT_BITS(8);
1417 ues(sps_delta_qp_in_val_minus1[i][j], 0, max, 2, i, j);
1418 ues(sps_delta_qp_diff_val[i][j], 0, max, 2, i, j);
1419 }
1420 }
1421 } else {
1422 infer(sps_joint_cbcr_enabled_flag, 0);
1423 infer(sps_same_qp_table_for_chroma_flag, 0);
1424 }
1425
1426 flag(sps_sao_enabled_flag);
1427 flag(sps_alf_enabled_flag);
1428 if (current->sps_alf_enabled_flag && current->sps_chroma_format_idc)
1429 flag(sps_ccalf_enabled_flag);
1430 else
1431 infer(sps_ccalf_enabled_flag, 0);
1432 flag(sps_lmcs_enabled_flag);
1433 flag(sps_weighted_pred_flag);
1434 flag(sps_weighted_bipred_flag);
1435 flag(sps_long_term_ref_pics_flag);
1436 if (current->sps_video_parameter_set_id > 0)
1437 flag(sps_inter_layer_prediction_enabled_flag);
1438 else
1439 infer(sps_inter_layer_prediction_enabled_flag, 0);
1440 flag(sps_idr_rpl_present_flag);
1441 flag(sps_rpl1_same_as_rpl0_flag);
1442
1443 for (i = 0; i < (current->sps_rpl1_same_as_rpl0_flag ? 1 : 2); i++) {
1444 ues(sps_num_ref_pic_lists[i], 0, VVC_MAX_REF_PIC_LISTS, 1, i);
1445 for (j = 0; j < current->sps_num_ref_pic_lists[i]; j++)
1447 &current->
1448 sps_ref_pic_list_struct[i][j], i,
1449 j, current));
1450 }
1451
1452 if (current->sps_rpl1_same_as_rpl0_flag) {
1453 current->sps_num_ref_pic_lists[1] = current->sps_num_ref_pic_lists[0];
1454 for (j = 0; j < current->sps_num_ref_pic_lists[0]; j++)
1455 memcpy(&current->sps_ref_pic_list_struct[1][j],
1456 &current->sps_ref_pic_list_struct[0][j],
1457 sizeof(current->sps_ref_pic_list_struct[0][j]));
1458 }
1459
1460 flag(sps_ref_wraparound_enabled_flag);
1461
1462 flag(sps_temporal_mvp_enabled_flag);
1463 if (current->sps_temporal_mvp_enabled_flag)
1464 flag(sps_sbtmvp_enabled_flag);
1465 else
1466 infer(sps_sbtmvp_enabled_flag, 0);
1467
1468 flag(sps_amvr_enabled_flag);
1469 flag(sps_bdof_enabled_flag);
1470 if (current->sps_bdof_enabled_flag)
1471 flag(sps_bdof_control_present_in_ph_flag);
1472 else
1473 infer(sps_bdof_control_present_in_ph_flag, 0);
1474
1475 flag(sps_smvd_enabled_flag);
1476 flag(sps_dmvr_enabled_flag);
1477 if (current->sps_dmvr_enabled_flag)
1478 flag(sps_dmvr_control_present_in_ph_flag);
1479 else
1480 infer(sps_dmvr_control_present_in_ph_flag, 0);
1481
1482 flag(sps_mmvd_enabled_flag);
1483 if (current->sps_mmvd_enabled_flag)
1484 flag(sps_mmvd_fullpel_only_enabled_flag);
1485 else
1486 infer(sps_mmvd_fullpel_only_enabled_flag, 0);
1487
1488 ue(sps_six_minus_max_num_merge_cand, 0, 5);
1489 max_num_merge_cand = 6 - current->sps_six_minus_max_num_merge_cand;
1490
1491 flag(sps_sbt_enabled_flag);
1492
1493 flag(sps_affine_enabled_flag);
1494 if (current->sps_affine_enabled_flag) {
1495 ue(sps_five_minus_max_num_subblock_merge_cand,
1496 0, 5 - current->sps_sbtmvp_enabled_flag);
1497 flag(sps_6param_affine_enabled_flag);
1498 if (current->sps_amvr_enabled_flag)
1499 flag(sps_affine_amvr_enabled_flag);
1500 else
1501 infer(sps_affine_amvr_enabled_flag, 0);
1502 flag(sps_affine_prof_enabled_flag);
1503 if (current->sps_affine_prof_enabled_flag)
1504 flag(sps_prof_control_present_in_ph_flag);
1505 else
1506 infer(sps_prof_control_present_in_ph_flag, 0);
1507 } else {
1508 infer(sps_6param_affine_enabled_flag, 0);
1509 infer(sps_affine_amvr_enabled_flag, 0);
1510 infer(sps_affine_prof_enabled_flag, 0);
1511 infer(sps_prof_control_present_in_ph_flag, 0);
1512 }
1513
1514 flag(sps_bcw_enabled_flag);
1515 flag(sps_ciip_enabled_flag);
1516
1517 if (max_num_merge_cand >= 2) {
1518 flag(sps_gpm_enabled_flag);
1519 if (current->sps_gpm_enabled_flag && max_num_merge_cand >= 3)
1520 ue(sps_max_num_merge_cand_minus_max_num_gpm_cand,
1521 0, max_num_merge_cand - 2);
1522 } else {
1523 infer(sps_gpm_enabled_flag, 0);
1524 }
1525
1526 ue(sps_log2_parallel_merge_level_minus2, 0, ctb_log2_size_y - 2);
1527
1528 flag(sps_isp_enabled_flag);
1529 flag(sps_mrl_enabled_flag);
1530 flag(sps_mip_enabled_flag);
1531
1532 if (current->sps_chroma_format_idc != 0)
1533 flag(sps_cclm_enabled_flag);
1534 else
1535 infer(sps_cclm_enabled_flag, 0);
1536 if (current->sps_chroma_format_idc == 1) {
1537 flag(sps_chroma_horizontal_collocated_flag);
1538 flag(sps_chroma_vertical_collocated_flag);
1539 } else {
1540 infer(sps_chroma_horizontal_collocated_flag, 1);
1541 infer(sps_chroma_vertical_collocated_flag, 1);
1542 }
1543
1544 flag(sps_palette_enabled_flag);
1545 if (current->sps_chroma_format_idc == 3 &&
1546 !current->sps_max_luma_transform_size_64_flag)
1547 flag(sps_act_enabled_flag);
1548 else
1549 infer(sps_act_enabled_flag, 0);
1550 if (current->sps_transform_skip_enabled_flag ||
1551 current->sps_palette_enabled_flag)
1552 ue(sps_min_qp_prime_ts, 0, 8);
1553
1554 flag(sps_ibc_enabled_flag);
1555 if (current->sps_ibc_enabled_flag)
1556 ue(sps_six_minus_max_num_ibc_merge_cand, 0, 5);
1557
1558 flag(sps_ladf_enabled_flag);
1559 if (current->sps_ladf_enabled_flag) {
1560 ub(2, sps_num_ladf_intervals_minus2);
1561 se(sps_ladf_lowest_interval_qp_offset, -63, 63);
1562 for (i = 0; i < current->sps_num_ladf_intervals_minus2 + 1; i++) {
1563 ses(sps_ladf_qp_offset[i], -63, 63, 1, i);
1564 ues(sps_ladf_delta_threshold_minus1[i],
1565 0, (2 << (8 + current->sps_bitdepth_minus8)) - 3, 1, i);
1566 }
1567 }
1568
1569 flag(sps_explicit_scaling_list_enabled_flag);
1570 if (current->sps_lfnst_enabled_flag &&
1571 current->sps_explicit_scaling_list_enabled_flag)
1572 flag(sps_scaling_matrix_for_lfnst_disabled_flag);
1573
1574 if (current->sps_act_enabled_flag &&
1575 current->sps_explicit_scaling_list_enabled_flag)
1576 flag(sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
1577 else
1578 infer(sps_scaling_matrix_for_alternative_colour_space_disabled_flag, 0);
1579 if (current->sps_scaling_matrix_for_alternative_colour_space_disabled_flag)
1580 flag(sps_scaling_matrix_designated_colour_space_flag);
1581
1582 flag(sps_dep_quant_enabled_flag);
1583 flag(sps_sign_data_hiding_enabled_flag);
1584
1585 flag(sps_virtual_boundaries_enabled_flag);
1586 if (current->sps_virtual_boundaries_enabled_flag) {
1587 flag(sps_virtual_boundaries_present_flag);
1588 if (current->sps_virtual_boundaries_present_flag) {
1589 ue(sps_num_ver_virtual_boundaries,
1590 0, current->sps_pic_width_max_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
1591 for (i = 0; i < current->sps_num_ver_virtual_boundaries; i++)
1592 ues(sps_virtual_boundary_pos_x_minus1[i],
1593 0, (current->sps_pic_width_max_in_luma_samples + 7) / 8 - 2,
1594 1, i);
1595 ue(sps_num_hor_virtual_boundaries,
1596 0, current->sps_pic_height_max_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
1597 for (i = 0; i < current->sps_num_hor_virtual_boundaries; i++)
1598 ues(sps_virtual_boundary_pos_y_minus1[i],
1599 0, (current->sps_pic_height_max_in_luma_samples + 7) /
1600 8 - 2, 1, i);
1601 }
1602 } else {
1603 infer(sps_virtual_boundaries_present_flag, 0);
1604 infer(sps_num_ver_virtual_boundaries, 0);
1605 infer(sps_num_hor_virtual_boundaries, 0);
1606 }
1607
1608 if (current->sps_ptl_dpb_hrd_params_present_flag) {
1609 flag(sps_timing_hrd_params_present_flag);
1610 if (current->sps_timing_hrd_params_present_flag) {
1611 uint8_t first_sublayer;
1613 &current->sps_general_timing_hrd_parameters));
1614 if (current->sps_max_sublayers_minus1 > 0)
1615 flag(sps_sublayer_cpb_params_present_flag);
1616 else
1617 infer(sps_sublayer_cpb_params_present_flag, 0);
1618 first_sublayer = current->sps_sublayer_cpb_params_present_flag ?
1619 0 : current->sps_max_sublayers_minus1;
1621 &current->sps_ols_timing_hrd_parameters, first_sublayer,
1622 current->sps_max_sublayers_minus1,
1623 &current->sps_general_timing_hrd_parameters));
1624 }
1625 }
1626
1627 flag(sps_field_seq_flag);
1628 flag(sps_vui_parameters_present_flag);
1629 if (current->sps_vui_parameters_present_flag) {
1630 ue(sps_vui_payload_size_minus1, 0, 1023);
1631 while (byte_alignment(rw) != 0)
1632 fixed(1, sps_vui_alignment_zero_bit, 0);
1633 CHECK(FUNC(vui_payload) (ctx, rw, &current->vui,
1634 current->sps_vui_payload_size_minus1 + 1,
1635 current->sps_chroma_format_idc));
1636 } else {
1638 }
1639
1640 flag(sps_extension_flag);
1641 if (current->sps_extension_flag) {
1642 flag(sps_range_extension_flag);
1643 ub(7, sps_extension_7bits);
1644
1645 if (current->sps_range_extension_flag) {
1646 if (current->sps_bitdepth_minus8 <= 10 - 8)
1647 return AVERROR_INVALIDDATA;
1649 } else {
1650 infer(sps_extended_precision_flag, 0);
1651 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1652 infer(sps_rrc_rice_extension_flag, 0);
1653 infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1654 infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1655 }
1656 } else {
1657 infer(sps_range_extension_flag, 0);
1658 infer(sps_extension_7bits, 0);
1659 infer(sps_extended_precision_flag, 0);
1660 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1661 infer(sps_rrc_rice_extension_flag, 0);
1662 infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1663 infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1664 }
1665
1666 if (current->sps_extension_7bits)
1667 CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1668
1670
1671 return 0;
1672}
1673
1676{
1677 CodedBitstreamH266Context *h266 = ctx->priv_data;
1678 const H266RawSPS *sps;
1679 int err, i;
1680 unsigned int min_cb_size_y, divisor, ctb_size_y,
1681 pic_width_in_ctbs_y, pic_height_in_ctbs_y;
1682 uint8_t sub_width_c, sub_height_c, qp_bd_offset;
1683
1684 static const uint8_t h266_sub_width_c[] = {
1685 1, 2, 2, 1
1686 };
1687 static const uint8_t h266_sub_height_c[] = {
1688 1, 2, 1, 1
1689 };
1690
1691 HEADER("Picture Parameter Set");
1692
1694 &current->nal_unit_header, VVC_PPS_NUT));
1695
1696 ub(6, pps_pic_parameter_set_id);
1697 ub(4, pps_seq_parameter_set_id);
1698 sps = h266->sps[current->pps_seq_parameter_set_id];
1699 if (!sps) {
1700 av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1701 current->pps_seq_parameter_set_id);
1702 return AVERROR_INVALIDDATA;
1703 }
1704
1705 flag(pps_mixed_nalu_types_in_pic_flag);
1706 ue(pps_pic_width_in_luma_samples,
1707 1, sps->sps_pic_width_max_in_luma_samples);
1708 ue(pps_pic_height_in_luma_samples,
1709 1, sps->sps_pic_height_max_in_luma_samples);
1710
1711 min_cb_size_y = 1 << (sps->sps_log2_min_luma_coding_block_size_minus2 + 2);
1712 divisor = FFMAX(min_cb_size_y, 8);
1713 if (current->pps_pic_width_in_luma_samples % divisor ||
1714 current->pps_pic_height_in_luma_samples % divisor) {
1715 av_log(ctx->log_ctx, AV_LOG_ERROR,
1716 "Invalid dimensions: %ux%u not divisible "
1717 "by %u, MinCbSizeY = %u.\n",
1718 current->pps_pic_width_in_luma_samples,
1719 current->pps_pic_height_in_luma_samples, divisor, min_cb_size_y);
1720 return AVERROR_INVALIDDATA;
1721 }
1722 if (!sps->sps_res_change_in_clvs_allowed_flag &&
1723 (current->pps_pic_width_in_luma_samples !=
1724 sps->sps_pic_width_max_in_luma_samples ||
1725 current->pps_pic_height_in_luma_samples !=
1726 sps->sps_pic_height_max_in_luma_samples)) {
1727 av_log(ctx->log_ctx, AV_LOG_ERROR,
1728 "Resolution change is not allowed, "
1729 "in max resolution (%ux%u) mismatched with pps(%ux%u).\n",
1730 sps->sps_pic_width_max_in_luma_samples,
1731 sps->sps_pic_height_max_in_luma_samples,
1732 current->pps_pic_width_in_luma_samples,
1733 current->pps_pic_height_in_luma_samples);
1734 return AVERROR_INVALIDDATA;
1735 }
1736
1737 ctb_size_y = 1 << (sps->sps_log2_ctu_size_minus5 + 5);
1738 if (sps->sps_ref_wraparound_enabled_flag) {
1739 if ((ctb_size_y / min_cb_size_y + 1) >
1740 (current->pps_pic_width_in_luma_samples / min_cb_size_y - 1)) {
1741 av_log(ctx->log_ctx, AV_LOG_ERROR,
1742 "Invalid width(%u), ctb_size_y = %u, min_cb_size_y = %u.\n",
1743 current->pps_pic_width_in_luma_samples,
1744 ctb_size_y, min_cb_size_y);
1745 return AVERROR_INVALIDDATA;
1746 }
1747 }
1748
1749 flag(pps_conformance_window_flag);
1750 if (current->pps_pic_width_in_luma_samples ==
1751 sps->sps_pic_width_max_in_luma_samples &&
1752 current->pps_pic_height_in_luma_samples ==
1753 sps->sps_pic_height_max_in_luma_samples &&
1754 current->pps_conformance_window_flag) {
1755 av_log(ctx->log_ctx, AV_LOG_ERROR,
1756 "Conformance window flag should not true.\n");
1757 return AVERROR_INVALIDDATA;
1758 }
1759
1760 sub_width_c = h266_sub_width_c[sps->sps_chroma_format_idc];
1761 sub_height_c = h266_sub_height_c[sps->sps_chroma_format_idc];
1762 if (current->pps_conformance_window_flag) {
1763 ue(pps_conf_win_left_offset, 0, current->pps_pic_width_in_luma_samples);
1764 ue(pps_conf_win_right_offset,
1765 0, current->pps_pic_width_in_luma_samples);
1766 ue(pps_conf_win_top_offset, 0, current->pps_pic_height_in_luma_samples);
1767 ue(pps_conf_win_bottom_offset,
1768 0, current->pps_pic_height_in_luma_samples);
1769 if (sub_width_c *
1770 (current->pps_conf_win_left_offset +
1771 current->pps_conf_win_right_offset) >=
1772 current->pps_pic_width_in_luma_samples ||
1773 sub_height_c *
1774 (current->pps_conf_win_top_offset +
1775 current->pps_conf_win_bottom_offset) >=
1776 current->pps_pic_height_in_luma_samples) {
1777 av_log(ctx->log_ctx, AV_LOG_ERROR,
1778 "Invalid pps conformance window: (%u, %u, %u, %u), "
1779 "resolution is %ux%u, sub wxh is %ux%u.\n",
1780 current->pps_conf_win_left_offset,
1781 current->pps_conf_win_right_offset,
1782 current->pps_conf_win_top_offset,
1783 current->pps_conf_win_bottom_offset,
1784 current->pps_pic_width_in_luma_samples,
1785 current->pps_pic_height_in_luma_samples,
1786 sub_width_c, sub_height_c);
1787 return AVERROR_INVALIDDATA;
1788 }
1789 } else {
1790 if (current->pps_pic_width_in_luma_samples ==
1791 sps->sps_pic_width_max_in_luma_samples &&
1792 current->pps_pic_height_in_luma_samples ==
1793 sps->sps_pic_height_max_in_luma_samples) {
1794 infer(pps_conf_win_left_offset, sps->sps_conf_win_left_offset);
1795 infer(pps_conf_win_right_offset, sps->sps_conf_win_right_offset);
1796 infer(pps_conf_win_top_offset, sps->sps_conf_win_top_offset);
1797 infer(pps_conf_win_bottom_offset, sps->sps_conf_win_bottom_offset);
1798 } else {
1799 infer(pps_conf_win_left_offset, 0);
1800 infer(pps_conf_win_right_offset, 0);
1801 infer(pps_conf_win_top_offset, 0);
1802 infer(pps_conf_win_bottom_offset, 0);
1803 }
1804
1805 }
1806
1807 flag(pps_scaling_window_explicit_signalling_flag);
1808 if (!sps->sps_ref_pic_resampling_enabled_flag &&
1809 current->pps_scaling_window_explicit_signalling_flag) {
1810 av_log(ctx->log_ctx, AV_LOG_ERROR,
1811 "Invalid data: sps_ref_pic_resampling_enabled_flag is false, "
1812 "but pps_scaling_window_explicit_signalling_flag is true.\n");
1813 return AVERROR_INVALIDDATA;
1814 }
1815 if (current->pps_scaling_window_explicit_signalling_flag) {
1816 se(pps_scaling_win_left_offset,
1817 -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1818 current->pps_pic_width_in_luma_samples / sub_width_c);
1819 se(pps_scaling_win_right_offset,
1820 -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1821 current->pps_pic_width_in_luma_samples / sub_width_c);
1822 se(pps_scaling_win_top_offset,
1823 -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1824 current->pps_pic_height_in_luma_samples / sub_height_c);
1825 se(pps_scaling_win_bottom_offset,
1826 -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1827 current->pps_pic_height_in_luma_samples / sub_height_c);
1828 } else {
1829 infer(pps_scaling_win_left_offset, current->pps_conf_win_left_offset);
1830 infer(pps_scaling_win_right_offset, current->pps_conf_win_right_offset);
1831 infer(pps_scaling_win_top_offset, current->pps_conf_win_top_offset);
1832 infer(pps_scaling_win_bottom_offset, current->pps_conf_win_bottom_offset);
1833 }
1834
1835 flag(pps_output_flag_present_flag);
1836 flag(pps_no_pic_partition_flag);
1837 flag(pps_subpic_id_mapping_present_flag);
1838
1839 if (current->pps_subpic_id_mapping_present_flag) {
1840 if (!current->pps_no_pic_partition_flag) {
1841 ue(pps_num_subpics_minus1,
1842 sps->sps_num_subpics_minus1, sps->sps_num_subpics_minus1);
1843 } else {
1844 infer(pps_num_subpics_minus1, 0);
1845 }
1846 ue(pps_subpic_id_len_minus1, sps->sps_subpic_id_len_minus1,
1847 sps->sps_subpic_id_len_minus1);
1848 for (i = 0; i <= current->pps_num_subpics_minus1; i++) {
1849 ubs(sps->sps_subpic_id_len_minus1 + 1, pps_subpic_id[i], 1, i);
1850 }
1851 }
1852
1853 for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
1854 if (sps->sps_subpic_id_mapping_explicitly_signalled_flag)
1855 current->sub_pic_id_val[i] = current->pps_subpic_id_mapping_present_flag
1856 ? current->pps_subpic_id[i]
1857 : sps->sps_subpic_id[i];
1858 else
1859 current->sub_pic_id_val[i] = i;
1860 }
1861
1862 pic_width_in_ctbs_y = AV_CEIL_RSHIFT
1863 (current->pps_pic_width_in_luma_samples, (sps->sps_log2_ctu_size_minus5 + 5));
1864 pic_height_in_ctbs_y = AV_CEIL_RSHIFT(
1865 current->pps_pic_height_in_luma_samples,(sps->sps_log2_ctu_size_minus5 + 5));
1866 if (!current->pps_no_pic_partition_flag) {
1867 unsigned int exp_tile_width = 0, exp_tile_height = 0;
1868 unsigned int unified_size, remaining_size;
1869
1870 u(2, pps_log2_ctu_size_minus5,
1871 sps->sps_log2_ctu_size_minus5, sps->sps_log2_ctu_size_minus5);
1872 ue(pps_num_exp_tile_columns_minus1,
1873 0, FFMIN(pic_width_in_ctbs_y - 1, VVC_MAX_TILE_COLUMNS - 1));
1874 ue(pps_num_exp_tile_rows_minus1,
1875 0, FFMIN(pic_height_in_ctbs_y - 1, VVC_MAX_TILE_ROWS - 1));
1876
1877 for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1878 ues(pps_tile_column_width_minus1[i],
1879 0, pic_width_in_ctbs_y - exp_tile_width - 1, 1, i);
1880 exp_tile_width += current->pps_tile_column_width_minus1[i] + 1;
1881 }
1882 for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1883 ues(pps_tile_row_height_minus1[i],
1884 0, pic_height_in_ctbs_y - exp_tile_height - 1, 1, i);
1885 exp_tile_height += current->pps_tile_row_height_minus1[i] + 1;
1886 }
1887
1888 remaining_size = pic_width_in_ctbs_y;
1889 for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1890 if (current->pps_tile_column_width_minus1[i] >= remaining_size) {
1891 av_log(ctx->log_ctx, AV_LOG_ERROR,
1892 "Tile column width(%d) exceeds picture width\n",i);
1893 return AVERROR_INVALIDDATA;
1894 }
1895 current->col_width_val[i] = current->pps_tile_column_width_minus1[i] + 1;
1896 remaining_size -= (current->pps_tile_column_width_minus1[i] + 1);
1897 }
1898 unified_size = current->pps_tile_column_width_minus1[i - 1] + 1;
1899 while (remaining_size > 0) {
1900 if (i == VVC_MAX_TILE_COLUMNS) {
1901 av_log(ctx->log_ctx, AV_LOG_ERROR,
1902 "Exceeded maximum tile columns (%d) (remaining size: %u)\n",
1903 VVC_MAX_TILE_COLUMNS, remaining_size);
1904 return AVERROR_INVALIDDATA;
1905 }
1906 unified_size = FFMIN(remaining_size, unified_size);
1907 current->col_width_val[i] = unified_size;
1908 remaining_size -= unified_size;
1909 i++;
1910 }
1911 current->num_tile_columns = i;
1912
1913 remaining_size = pic_height_in_ctbs_y;
1914 for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1915 if (current->pps_tile_row_height_minus1[i] >= remaining_size) {
1916 av_log(ctx->log_ctx, AV_LOG_ERROR,
1917 "Tile row height(%d) exceeds picture height\n",i);
1918 return AVERROR_INVALIDDATA;
1919 }
1920 current->row_height_val[i] = current->pps_tile_row_height_minus1[i] + 1;
1921 remaining_size -= (current->pps_tile_row_height_minus1[i] + 1);
1922 }
1923 unified_size = current->pps_tile_row_height_minus1[i - 1] + 1;
1924
1925 while (remaining_size > 0) {
1926 if (i == VVC_MAX_TILE_ROWS) {
1927 av_log(ctx->log_ctx, AV_LOG_ERROR,
1928 "Exceeded maximum tile rows (%d) (remaining size: %u)\n",
1929 VVC_MAX_TILE_ROWS, remaining_size);
1930 return AVERROR_INVALIDDATA;
1931 }
1932 unified_size = FFMIN(remaining_size, unified_size);
1933 current->row_height_val[i] = unified_size;
1934 remaining_size -= unified_size;
1935 i++;
1936 }
1937 current->num_tile_rows=i;
1938
1939 current->num_tiles_in_pic = current->num_tile_columns *
1940 current->num_tile_rows;
1941 if (current->num_tiles_in_pic > VVC_MAX_TILES_PER_AU) {
1942 av_log(ctx->log_ctx, AV_LOG_ERROR,
1943 "NumTilesInPic(%d) > than VVC_MAX_TILES_PER_AU(%d)\n",
1944 current->num_tiles_in_pic, VVC_MAX_TILES_PER_AU);
1945 return AVERROR_INVALIDDATA;
1946 }
1947
1948 if (current->num_tiles_in_pic > 1) {
1949 flag(pps_loop_filter_across_tiles_enabled_flag);
1950 flag(pps_rect_slice_flag);
1951 } else {
1952 infer(pps_loop_filter_across_tiles_enabled_flag, 0);
1953 infer(pps_rect_slice_flag, 1);
1954 }
1955 if (current->pps_rect_slice_flag)
1956 flag(pps_single_slice_per_subpic_flag);
1957 else
1958 infer(pps_single_slice_per_subpic_flag, 1);
1959 if (current->pps_rect_slice_flag &&
1960 !current->pps_single_slice_per_subpic_flag) {
1961 int j, num_slices = 0;
1962 uint16_t tile_idx = 0, tile_x, tile_y, ctu_x, ctu_y;
1963 uint16_t slice_top_left_ctu_x[VVC_MAX_SLICES];
1964 uint16_t slice_top_left_ctu_y[VVC_MAX_SLICES];
1965 ue(pps_num_slices_in_pic_minus1, 0, VVC_MAX_SLICES - 1);
1966 if (current->pps_num_slices_in_pic_minus1 > 1)
1967 flag(pps_tile_idx_delta_present_flag);
1968 else
1969 infer(pps_tile_idx_delta_present_flag, 0);
1970 for (i = 0; i < current->pps_num_slices_in_pic_minus1; i++) {
1971 current->slice_top_left_tile_idx[i] = tile_idx;
1972 tile_x = tile_idx % current->num_tile_columns;
1973 tile_y = tile_idx / current->num_tile_columns;
1974 if (tile_y >= current->num_tile_rows)
1975 return AVERROR_INVALIDDATA;
1976 if (tile_x != current->num_tile_columns - 1) {
1977 ues(pps_slice_width_in_tiles_minus1[i],
1978 0, current->num_tile_columns - 1 - tile_x, 1, i);
1979 } else {
1980 infer(pps_slice_width_in_tiles_minus1[i], 0);
1981 }
1982 if (tile_y != current->num_tile_rows - 1 &&
1983 (current->pps_tile_idx_delta_present_flag || tile_x == 0)) {
1984 ues(pps_slice_height_in_tiles_minus1[i],
1985 0, current->num_tile_rows - 1 - tile_y, 1, i);
1986 } else {
1987 if (tile_y == current->num_tile_rows - 1)
1988 infer(pps_slice_height_in_tiles_minus1[i], 0);
1989 else
1990 infer(pps_slice_height_in_tiles_minus1[i],
1991 current->pps_slice_height_in_tiles_minus1[i - 1]);
1992 }
1993
1994 ctu_x = ctu_y = 0;
1995 for (j = 0; j < tile_x; j++) {
1996 ctu_x += current->col_width_val[j];
1997 }
1998 for (j = 0; j < tile_y; j++) {
1999 ctu_y += current->row_height_val[j];
2000 }
2001 if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
2002 current->pps_slice_height_in_tiles_minus1[i] == 0 &&
2003 current->row_height_val[tile_y] > 1) {
2004 int uniform_slice_height, remaining_height_in_ctbs_y;
2005 remaining_height_in_ctbs_y =
2006 current->row_height_val[tile_y];
2007 ues(pps_num_exp_slices_in_tile[i],
2008 0, current->row_height_val[tile_y] - 1, 1, i);
2009 if (current->pps_num_exp_slices_in_tile[i] == 0) {
2010 current->num_slices_in_tile[i] = 1;
2011 current->slice_height_in_ctus[i] = current->row_height_val[tile_y];
2012 slice_top_left_ctu_x[i] = ctu_x;
2013 slice_top_left_ctu_y[i] = ctu_y;
2014 } else {
2015 uint16_t slice_height_in_ctus;
2016 int num_uniform_slices;
2017
2018 if (i + current->pps_num_exp_slices_in_tile[i] >
2019 current->pps_num_slices_in_pic_minus1 + 1)
2020 return AVERROR_INVALIDDATA;
2021
2022 for (j = 0; j < current->pps_num_exp_slices_in_tile[i];
2023 j++) {
2024 ues(pps_exp_slice_height_in_ctus_minus1[i][j], 0,
2025 remaining_height_in_ctbs_y - (current->pps_num_exp_slices_in_tile[i] - j), 2,
2026 i, j);
2027 slice_height_in_ctus =
2028 current->
2029 pps_exp_slice_height_in_ctus_minus1[i][j] + 1;
2030
2031 current->slice_height_in_ctus[i + j] =
2032 slice_height_in_ctus;
2033 slice_top_left_ctu_x[i + j] = ctu_x;
2034 slice_top_left_ctu_y[i + j] = ctu_y;
2035 ctu_y += slice_height_in_ctus;
2036
2037 remaining_height_in_ctbs_y -= slice_height_in_ctus;
2038 }
2039 uniform_slice_height = 1 +
2040 (j == 0 ? current->row_height_val[tile_y] - 1:
2041 current->pps_exp_slice_height_in_ctus_minus1[i][j-1]);
2042
2043 num_uniform_slices = (remaining_height_in_ctbs_y + uniform_slice_height - 1)
2044 / uniform_slice_height;
2045 if (i + current->pps_num_exp_slices_in_tile[i] + num_uniform_slices >
2046 current->pps_num_slices_in_pic_minus1 + 1)
2047 return AVERROR_INVALIDDATA;
2048
2049 while (remaining_height_in_ctbs_y > uniform_slice_height) {
2050 current->slice_height_in_ctus[i + j] =
2051 uniform_slice_height;
2052 slice_top_left_ctu_x[i + j] = ctu_x;
2053 slice_top_left_ctu_y[i + j] = ctu_y;
2054 ctu_y += uniform_slice_height;
2055
2056 remaining_height_in_ctbs_y -= uniform_slice_height;
2057 j++;
2058 }
2059 if (remaining_height_in_ctbs_y > 0) {
2060 current->slice_height_in_ctus[i + j] =
2061 remaining_height_in_ctbs_y;
2062 slice_top_left_ctu_x[i + j] = ctu_x;
2063 slice_top_left_ctu_y[i + j] = ctu_y;
2064 j++;
2065 }
2066 current->num_slices_in_tile[i] = j;
2067 }
2068 for (int k = 0; k < current->num_slices_in_tile[i]; k++)
2069 current->slice_top_left_tile_idx[i + k] = tile_idx;
2070 i += current->num_slices_in_tile[i] - 1;
2071 } else {
2072 uint16_t height = 0;
2073 infer(pps_num_exp_slices_in_tile[i], 0);
2074 if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
2075 current->pps_slice_height_in_tiles_minus1[i] == 0)
2076 current->num_slices_in_tile[i] = 1;
2077
2078 for (j = 0;
2079 j <= current->pps_slice_height_in_tiles_minus1[i];
2080 j++) {
2081 height +=
2082 current->row_height_val[tile_y + j];
2083 }
2084 current->slice_height_in_ctus[i] = height;
2085
2086 slice_top_left_ctu_x[i] = ctu_x;
2087 slice_top_left_ctu_y[i] = ctu_y;
2088 }
2089 if (i < current->pps_num_slices_in_pic_minus1) {
2090 if (current->pps_tile_idx_delta_present_flag) {
2091 // Two conditions must be met:
2092 // 1. −NumTilesInPic + 1 <= pps_tile_idx_delta_val[i] <= NumTilesInPic − 1
2093 // 2. 0 <= tile_idx + pps_tile_idx_delta_val[i] <= NumTilesInPic − 1
2094 // Combining these conditions yields: -tile_idx <= pps_tile_idx_delta_val[i] <= NumTilesInPic - 1 - tile_idx
2095 ses(pps_tile_idx_delta_val[i],
2096 -tile_idx, current->num_tiles_in_pic - 1 - tile_idx, 1, i);
2097 if (current->pps_tile_idx_delta_val[i] == 0) {
2098 av_log(ctx->log_ctx, AV_LOG_ERROR,
2099 "pps_tile_idx_delta_val[i] shall not be equal to 0.\n");
2100 }
2101 tile_idx += current->pps_tile_idx_delta_val[i];
2102 } else {
2103 infer(pps_tile_idx_delta_val[i], 0);
2104 tile_idx +=
2105 current->pps_slice_width_in_tiles_minus1[i] + 1;
2106 if (tile_idx % current->num_tile_columns == 0) {
2107 tile_idx +=
2108 current->pps_slice_height_in_tiles_minus1[i] *
2109 current->num_tile_columns;
2110 }
2111 }
2112 }
2113 }
2114 if (i == current->pps_num_slices_in_pic_minus1) {
2115 uint16_t height = 0;
2116
2117 current->slice_top_left_tile_idx[i] = tile_idx;
2118 current->num_slices_in_tile[i] = 1;
2119 tile_x = tile_idx % current->num_tile_columns;
2120 tile_y = tile_idx / current->num_tile_columns;
2121 if (tile_y >= current->num_tile_rows)
2122 return AVERROR_INVALIDDATA;
2123
2124 ctu_x = 0, ctu_y = 0;
2125 for (j = 0; j < tile_x; j++) {
2126 ctu_x += current->col_width_val[j];
2127 }
2128 for (j = 0; j < tile_y; j++) {
2129 ctu_y += current->row_height_val[j];
2130 }
2131 slice_top_left_ctu_x[i] = ctu_x;
2132 slice_top_left_ctu_y[i] = ctu_y;
2133
2134 current->pps_slice_width_in_tiles_minus1[i] =
2135 current->num_tile_columns - tile_x - 1;
2136 current->pps_slice_height_in_tiles_minus1[i] =
2137 current->num_tile_rows - tile_y - 1;
2138
2139 for (j = 0; j <= current->pps_slice_height_in_tiles_minus1[i];
2140 j++) {
2141 height +=
2142 current->row_height_val[tile_y + j];
2143 }
2144 current->slice_height_in_ctus[i] = height;
2145
2146 infer(pps_num_exp_slices_in_tile[i], 0);
2147 }
2148 //now, we got all slice information, let's resolve NumSlicesInSubpic
2149 for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
2150 current->num_slices_in_subpic[i] = 0;
2151 for (j = 0; j <= current->pps_num_slices_in_pic_minus1; j++) {
2152 uint16_t pos_x = 0, pos_y = 0;
2153 pos_x = slice_top_left_ctu_x[j];
2154 pos_y = slice_top_left_ctu_y[j];
2155 if ((pos_x >= sps->sps_subpic_ctu_top_left_x[i]) &&
2156 (pos_x <
2157 sps->sps_subpic_ctu_top_left_x[i] +
2158 sps->sps_subpic_width_minus1[i] + 1) &&
2159 (pos_y >= sps->sps_subpic_ctu_top_left_y[i]) &&
2160 (pos_y < sps->sps_subpic_ctu_top_left_y[i] +
2161 sps->sps_subpic_height_minus1[i] + 1)) {
2162 current->num_slices_in_subpic[i]++;
2163 }
2164 }
2165 num_slices += current->num_slices_in_subpic[i];
2166 }
2167 if (current->pps_num_slices_in_pic_minus1 + 1 != num_slices)
2168 return AVERROR_INVALIDDATA;
2169 } else {
2170 if (current->pps_no_pic_partition_flag)
2171 infer(pps_num_slices_in_pic_minus1, 0);
2172 else if (current->pps_single_slice_per_subpic_flag) {
2173 for (i = 0; i <= sps->sps_num_subpics_minus1; i++)
2174 current->num_slices_in_subpic[i] = 1;
2175 infer(pps_num_slices_in_pic_minus1,
2176 sps->sps_num_subpics_minus1);
2177 }
2178 // else?
2179 }
2180 if (!current->pps_rect_slice_flag ||
2181 current->pps_single_slice_per_subpic_flag ||
2182 current->pps_num_slices_in_pic_minus1 > 0)
2183 flag(pps_loop_filter_across_slices_enabled_flag);
2184 else
2185 infer(pps_loop_filter_across_slices_enabled_flag, 0);
2186 } else {
2187 infer(pps_num_exp_tile_columns_minus1, 0);
2188 infer(pps_tile_column_width_minus1[0], pic_width_in_ctbs_y - 1);
2189 infer(pps_num_exp_tile_rows_minus1, 0);
2190 infer(pps_tile_row_height_minus1[0], pic_height_in_ctbs_y - 1);
2191 current->col_width_val[0] = pic_width_in_ctbs_y;
2192 current->row_height_val[0] = pic_height_in_ctbs_y;
2193 current->num_tile_columns = 1;
2194 current->num_tile_rows = 1;
2195 current->num_tiles_in_pic = 1;
2196 }
2197
2198 flag(pps_cabac_init_present_flag);
2199 for (i = 0; i < 2; i++)
2200 ues(pps_num_ref_idx_default_active_minus1[i], 0, 14, 1, i);
2201 flag(pps_rpl1_idx_present_flag);
2202 flag(pps_weighted_pred_flag);
2203 flag(pps_weighted_bipred_flag);
2204 flag(pps_ref_wraparound_enabled_flag);
2205 if (current->pps_ref_wraparound_enabled_flag) {
2206 ue(pps_pic_width_minus_wraparound_offset,
2207 0, (current->pps_pic_width_in_luma_samples / min_cb_size_y)
2208 - (ctb_size_y / min_cb_size_y) - 2);
2209 }
2210
2211 qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2212 se(pps_init_qp_minus26, -(26 + qp_bd_offset), 37);
2213 flag(pps_cu_qp_delta_enabled_flag);
2214 flag(pps_chroma_tool_offsets_present_flag);
2215 if (current->pps_chroma_tool_offsets_present_flag) {
2216 se(pps_cb_qp_offset, -12, 12);
2217 se(pps_cr_qp_offset, -12, 12);
2218 flag(pps_joint_cbcr_qp_offset_present_flag);
2219 if (current->pps_joint_cbcr_qp_offset_present_flag)
2220 se(pps_joint_cbcr_qp_offset_value, -12, 12);
2221 else
2222 infer(pps_joint_cbcr_qp_offset_value, 0);
2223 flag(pps_slice_chroma_qp_offsets_present_flag);
2224 flag(pps_cu_chroma_qp_offset_list_enabled_flag);
2225 if (current->pps_cu_chroma_qp_offset_list_enabled_flag) {
2226 ue(pps_chroma_qp_offset_list_len_minus1, 0, 5);
2227 for (i = 0; i <= current->pps_chroma_qp_offset_list_len_minus1; i++) {
2228 ses(pps_cb_qp_offset_list[i], -12, 12, 1, i);
2229 ses(pps_cr_qp_offset_list[i], -12, 12, 1, i);
2230 if (current->pps_joint_cbcr_qp_offset_present_flag)
2231 ses(pps_joint_cbcr_qp_offset_list[i], -12, 12, 1, i);
2232 else
2233 infer(pps_joint_cbcr_qp_offset_list[i], 0);
2234 }
2235 }
2236 } else {
2237 infer(pps_cb_qp_offset, 0);
2238 infer(pps_cr_qp_offset, 0);
2239 infer(pps_joint_cbcr_qp_offset_present_flag, 0);
2240 infer(pps_joint_cbcr_qp_offset_value, 0);
2241 infer(pps_slice_chroma_qp_offsets_present_flag, 0);
2242 infer(pps_cu_chroma_qp_offset_list_enabled_flag, 0);
2243 }
2244 flag(pps_deblocking_filter_control_present_flag);
2245 if (current->pps_deblocking_filter_control_present_flag) {
2246 flag(pps_deblocking_filter_override_enabled_flag);
2247 flag(pps_deblocking_filter_disabled_flag);
2248 if (!current->pps_no_pic_partition_flag &&
2249 current->pps_deblocking_filter_override_enabled_flag)
2250 flag(pps_dbf_info_in_ph_flag);
2251 else
2252 infer(pps_dbf_info_in_ph_flag, 0);
2253 if (!current->pps_deblocking_filter_disabled_flag) {
2254 se(pps_luma_beta_offset_div2, -12, 12);
2255 se(pps_luma_tc_offset_div2, -12, 12);
2256 if (current->pps_chroma_tool_offsets_present_flag) {
2257 se(pps_cb_beta_offset_div2, -12, 12);
2258 se(pps_cb_tc_offset_div2, -12, 12);
2259 se(pps_cr_beta_offset_div2, -12, 12);
2260 se(pps_cr_tc_offset_div2, -12, 12);
2261 } else {
2262 infer(pps_cb_beta_offset_div2,
2263 current->pps_luma_beta_offset_div2);
2264 infer(pps_cb_tc_offset_div2, current->pps_luma_tc_offset_div2);
2265 infer(pps_cr_beta_offset_div2,
2266 current->pps_luma_beta_offset_div2);
2267 infer(pps_cr_tc_offset_div2, current->pps_luma_tc_offset_div2);
2268 }
2269 } else {
2270 infer(pps_luma_beta_offset_div2, 0);
2271 infer(pps_luma_tc_offset_div2, 0);
2272 infer(pps_cb_beta_offset_div2, 0);
2273 infer(pps_cb_tc_offset_div2, 0);
2274 infer(pps_cr_beta_offset_div2, 0);
2275 infer(pps_cr_tc_offset_div2, 0);
2276 }
2277 } else {
2278 infer(pps_deblocking_filter_override_enabled_flag, 0);
2279 infer(pps_deblocking_filter_disabled_flag, 0);
2280 infer(pps_dbf_info_in_ph_flag, 0);
2281 infer(pps_luma_beta_offset_div2, 0);
2282 infer(pps_luma_tc_offset_div2, 0);
2283 infer(pps_cb_beta_offset_div2, 0);
2284 infer(pps_cb_tc_offset_div2, 0);
2285 infer(pps_cr_beta_offset_div2, 0);
2286 infer(pps_cr_tc_offset_div2, 0);
2287 }
2288
2289 if (!current->pps_no_pic_partition_flag) {
2290 flag(pps_rpl_info_in_ph_flag);
2291 flag(pps_sao_info_in_ph_flag);
2292 flag(pps_alf_info_in_ph_flag);
2293 if ((current->pps_weighted_pred_flag ||
2294 current->pps_weighted_bipred_flag) &&
2295 current->pps_rpl_info_in_ph_flag)
2296 flag(pps_wp_info_in_ph_flag);
2297 flag(pps_qp_delta_info_in_ph_flag);
2298 }
2299 flag(pps_picture_header_extension_present_flag);
2300 flag(pps_slice_header_extension_present_flag);
2301
2302 flag(pps_extension_flag);
2303 if (current->pps_extension_flag)
2304 CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2305
2307 return 0;
2308}
2309
2312{
2313 int err, j, k;
2314
2315 flag(alf_luma_filter_signal_flag);
2316
2317 if (current->aps_chroma_present_flag) {
2318 flag(alf_chroma_filter_signal_flag);
2319 flag(alf_cc_cb_filter_signal_flag);
2320 flag(alf_cc_cr_filter_signal_flag);
2321 } else {
2322 infer(alf_chroma_filter_signal_flag, 0);
2323 infer(alf_cc_cb_filter_signal_flag, 0);
2324 infer(alf_cc_cr_filter_signal_flag, 0);
2325 }
2326
2327 if (current->alf_luma_filter_signal_flag) {
2328 flag(alf_luma_clip_flag);
2329 ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS - 1);
2330 if (current->alf_luma_num_filters_signalled_minus1 > 0) {
2331 unsigned int bits = av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
2332 for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS; filt_idx++)
2333 us(bits, alf_luma_coeff_delta_idx[filt_idx],
2334 0, current->alf_luma_num_filters_signalled_minus1,
2335 1, filt_idx);
2336 }
2337 for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
2338 for (j = 0; j < 12; j++) {
2339 ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
2340 if (current->alf_luma_coeff_abs[sf_idx][j])
2341 ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
2342 else
2343 infer(alf_luma_coeff_sign[sf_idx][j], 0);
2344 }
2345 } else {
2346 infer(alf_luma_clip_flag, 0);
2347 infer(alf_luma_num_filters_signalled_minus1, 0);
2348 }
2349 for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
2350 for (j = 0; j < 12; j++) {
2351 if (current->alf_luma_clip_flag)
2352 ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
2353 else
2354 infer(alf_luma_clip_idx[sf_idx][j], 0);
2355 }
2356 }
2357
2358 if (current->alf_chroma_filter_signal_flag) {
2359 flag(alf_chroma_clip_flag);
2360 ue(alf_chroma_num_alt_filters_minus1, 0, 7);
2361 } else {
2362 infer(alf_chroma_clip_flag, 0);
2363 infer(alf_chroma_num_alt_filters_minus1, 0);
2364 }
2365 for (int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
2366 for (j = 0; j < 6; j++) {
2367 if (current->alf_chroma_filter_signal_flag)
2368 ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
2369 else
2370 infer(alf_chroma_coeff_abs[alt_idx][j], 0);
2371 if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
2372 ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
2373 else
2374 infer(alf_chroma_coeff_sign[alt_idx][j], 0);
2375 }
2376 for (j = 0; j < 6; j++) {
2377 if (current->alf_chroma_clip_flag)
2378 ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
2379 else
2380 infer(alf_chroma_clip_idx[alt_idx][j], 0);
2381 }
2382 }
2383
2384 if (current->alf_cc_cb_filter_signal_flag)
2385 ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
2386 else
2387 infer(alf_cc_cb_filters_signalled_minus1, 0);
2388 for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
2389 for (j = 0; j < 7; j++) {
2390 if (current->alf_cc_cb_filter_signal_flag)
2391 ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
2392 else
2393 infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
2394 if (current->alf_cc_cb_mapped_coeff_abs[k][j])
2395 ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
2396 else
2397 infer(alf_cc_cb_coeff_sign[k][j], 0);
2398 }
2399 }
2400
2401 if (current->alf_cc_cr_filter_signal_flag)
2402 ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
2403 else
2404 infer(alf_cc_cr_filters_signalled_minus1, 0);
2405 for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
2406 for (j = 0; j < 7; j++) {
2407 if (current->alf_cc_cr_filter_signal_flag)
2408 ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
2409 else
2410 infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
2411 if (current->alf_cc_cr_mapped_coeff_abs[k][j])
2412 ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
2413 else
2414 infer(alf_cc_cr_coeff_sign[k][j], 0);
2415 }
2416 }
2417
2418 return 0;
2419}
2420
2423{
2424 int err, i, lmcs_max_bin_idx;
2425
2426 ue(lmcs_min_bin_idx, 0, 15);
2427 ue(lmcs_delta_max_bin_idx, 0, 15);
2428 ue(lmcs_delta_cw_prec_minus1, 0, 14);
2429
2430 lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
2431
2432 if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
2433 return AVERROR_INVALIDDATA;
2434
2435 for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
2436 ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i], 1, i);
2437 if (current->lmcs_delta_abs_cw[i] > 0)
2438 flags(lmcs_delta_sign_cw_flag[i], 1, i);
2439 else
2440 infer(lmcs_delta_sign_cw_flag[i], 0);
2441 }
2442
2443 if (current->aps_chroma_present_flag) {
2444 ub(3, lmcs_delta_abs_crs);
2445 if (current->lmcs_delta_abs_crs > 0)
2446 flag(lmcs_delta_sign_crs_flag);
2447 else
2448 infer(lmcs_delta_sign_crs_flag, 0);
2449 } else {
2450 infer(lmcs_delta_abs_crs, 0);
2451 infer(lmcs_delta_sign_crs_flag, 0);
2452 }
2453
2454 return 0;
2455}
2456
2459{
2460 // 7.4.3.4, deriving DiagScanOrder
2461 static const uint8_t diag_scan_order[64][2] = {
2462 { 0, 0, }, { 0, 1, }, { 1, 0, }, { 0, 2, }, { 1, 1, }, { 2, 0, }, { 0, 3, }, { 1, 2, },
2463 { 2, 1, }, { 3, 0, }, { 0, 4, }, { 1, 3, }, { 2, 2, }, { 3, 1, }, { 4, 0, }, { 0, 5, },
2464 { 1, 4, }, { 2, 3, }, { 3, 2, }, { 4, 1, }, { 5, 0, }, { 0, 6, }, { 1, 5, }, { 2, 4, },
2465 { 3, 3, }, { 4, 2, }, { 5, 1, }, { 6, 0, }, { 0, 7, }, { 1, 6, }, { 2, 5, }, { 3, 4, },
2466 { 4, 3, }, { 5, 2, }, { 6, 1, }, { 7, 0, }, { 1, 7, }, { 2, 6, }, { 3, 5, }, { 4, 4, },
2467 { 5, 3, }, { 6, 2, }, { 7, 1, }, { 2, 7, }, { 3, 6, }, { 4, 5, }, { 5, 4, }, { 6, 3, },
2468 { 7, 2, }, { 3, 7, }, { 4, 6, }, { 5, 5, }, { 6, 4, }, { 7, 3, }, { 4, 7, }, { 5, 6, },
2469 { 6, 5, }, { 7, 4, }, { 5, 7, }, { 6, 6, }, { 7, 5, }, { 6, 7, }, { 7, 6, }, { 7, 7, }, };
2470 int err;
2471
2472 for (int id = 0; id < 28; id ++) {
2473 if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
2474 flags(scaling_list_copy_mode_flag[id], 1, id);
2475 if (!current->scaling_list_copy_mode_flag[id])
2476 flags(scaling_list_pred_mode_flag[id], 1, id);
2477 else
2478 infer(scaling_list_pred_mode_flag[id], 0);
2479 if ((current->scaling_list_copy_mode_flag[id] ||
2480 current->scaling_list_pred_mode_flag[id]) &&
2481 id != 0 && id != 2 && id != 8) {
2482 int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) : (id - 8));
2483 ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1, id);
2484 }
2485 if (!current->scaling_list_copy_mode_flag[id]) {
2486 int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
2487 if (id > 13) {
2488 int idx = id - 14;
2489 ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
2490 }
2491 for (int i = 0; i < matrix_size * matrix_size; i++) {
2492 int x = diag_scan_order[i][0];
2493 int y = diag_scan_order[i][1];
2494 if (!(id > 25 && x >= 4 && y >= 4))
2495 ses(scaling_list_delta_coef[id][i], -128, 127, 2, id, i);
2496 }
2497 } else if (id > 13) {
2498 int idx = id - 14;
2499 infer(scaling_list_dc_coef[idx], 0);
2500 }
2501 } else {
2502 infer(scaling_list_copy_mode_flag[id], 1);
2503 infer(scaling_list_pred_mode_flag[id], 0);
2504 }
2505 }
2506
2507 return 0;
2508}
2509
2512{
2513 int aps_id_max = MAX_UINT_BITS(5);
2514 int err;
2515
2516 if (prefix)
2517 HEADER("Prefix Adaptation parameter set");
2518 else
2519 HEADER("Suffix Adaptation parameter set");
2520
2521 CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2524
2525 ub(3, aps_params_type);
2526 if (current->aps_params_type == VVC_ASP_TYPE_ALF ||
2527 current->aps_params_type == VVC_ASP_TYPE_SCALING)
2528 aps_id_max = 7;
2529 else if (current->aps_params_type == VVC_ASP_TYPE_LMCS)
2530 aps_id_max = 3;
2531 u(5, aps_adaptation_parameter_set_id, 0, aps_id_max);
2532 flag(aps_chroma_present_flag);
2533 if (current->aps_params_type == VVC_ASP_TYPE_ALF)
2534 CHECK(FUNC(alf_data)(ctx, rw, current));
2535 else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
2536 CHECK(FUNC(lmcs_data)(ctx, rw, current));
2537 else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
2539 flag(aps_extension_flag);
2540 if (current->aps_extension_flag)
2541 CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2543
2544 return 0;
2545}
2546
2549{
2550 int err;
2551
2552 HEADER("Access Unit Delimiter");
2553
2555 &current->nal_unit_header, VVC_AUD_NUT));
2556
2557 flag(aud_irap_or_gdr_flag);
2558 u(3, aud_pic_type, 0, 2);
2559
2561 return 0;
2562}
2563
2565 const H266RawSPS *sps,
2566 const H266RawPPS *pps,
2567 const H266RefPicLists *ref_lists,
2568 uint8_t num_ref_idx_active[2],
2570{
2571 int err, i, j;
2572 ue(luma_log2_weight_denom, 0, 7);
2573 if (sps->sps_chroma_format_idc != 0) {
2574 se(delta_chroma_log2_weight_denom,
2575 -current->luma_log2_weight_denom,
2576 7 - current->luma_log2_weight_denom);
2577 } else {
2578 infer(delta_chroma_log2_weight_denom, 0);
2579 }
2580 if (pps->pps_wp_info_in_ph_flag) {
2581 ue(num_l0_weights, 0,
2582 FFMIN(15, ref_lists->rpl_ref_list[0].num_ref_entries));
2583 infer(num_weights_l0, current->num_l0_weights);
2584 } else {
2585 infer(num_weights_l0, num_ref_idx_active[0]);
2586 }
2587 for (i = 0; i < current->num_weights_l0; i++) {
2588 flags(luma_weight_l0_flag[i], 1, i);
2589 }
2590 if (sps->sps_chroma_format_idc != 0) {
2591 for (i = 0; i < current->num_weights_l0; i++)
2592 flags(chroma_weight_l0_flag[i], 1, i);
2593 }
2594 for (i = 0; i < current->num_weights_l0; i++) {
2595 if (current->luma_weight_l0_flag[i]) {
2596 ses(delta_luma_weight_l0[i], -128, 127, 1, i);
2597 ses(luma_offset_l0[i], -128, 127, 1, i);
2598 } else {
2599 infer(delta_luma_weight_l0[i], 0);
2600 infer(luma_offset_l0[i], 0);
2601 }
2602 if (current->chroma_weight_l0_flag[i]) {
2603 for (j = 0; j < 2; j++) {
2604 ses(delta_chroma_weight_l0[i][j], -128, 127, 2, i, j);
2605 ses(delta_chroma_offset_l0[i][j], -4 * 128, 4 * 127, 2, i, j);
2606 }
2607 }
2608 }
2609
2610 if (pps->pps_weighted_bipred_flag &&
2611 ref_lists->rpl_ref_list[1].num_ref_entries > 0) {
2612 if (pps->pps_wp_info_in_ph_flag) {
2613 ue(num_l1_weights, 0,
2614 FFMIN(15, ref_lists->rpl_ref_list[1].num_ref_entries));
2615 infer(num_weights_l1, current->num_l1_weights);
2616 } else {
2617 infer(num_weights_l1, num_ref_idx_active[1]);
2618 }
2619 } else {
2620 infer(num_weights_l1, 0);
2621 }
2622
2623 for (i = 0; i < current->num_weights_l1; i++)
2624 flags(luma_weight_l1_flag[i], 1, i);
2625 if (sps->sps_chroma_format_idc != 0) {
2626 for (i = 0; i < current->num_weights_l1; i++)
2627 flags(chroma_weight_l1_flag[i], 1, i);
2628 }
2629 for (i = 0; i < current->num_weights_l1; i++) {
2630 if (current->luma_weight_l1_flag[i]) {
2631 ses(delta_luma_weight_l1[i], -128, 127, 1, i);
2632 ses(luma_offset_l1[i], -128, 127, 1, i);
2633 } else {
2634 infer(delta_luma_weight_l1[i], 0);
2635 infer(luma_offset_l1[i], 0);
2636 }
2637 if (current->chroma_weight_l1_flag[i]) {
2638 for (j = 0; j < 2; j++) {
2639 ses(delta_chroma_weight_l1[i][j], -128, 127, 2, i, j);
2640 ses(delta_chroma_offset_l1[i][j], -4 * 128, 4 * 127, 2, i, j);
2641 }
2642 }
2643 }
2644 return 0;
2645}
2646
2649 CodedBitstreamH266Context *h266 = ctx->priv_data;
2650 const H266RawVPS *vps;
2651 const H266RawSPS *sps;
2652 const H266RawPPS *pps;
2653 int err, i;
2654 unsigned int ctb_log2_size_y, min_cb_log2_size_y,
2655 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y;
2656 uint8_t qp_bd_offset;
2657
2658 flag(ph_gdr_or_irap_pic_flag);
2659 flag(ph_non_ref_pic_flag);
2660 if (current->ph_gdr_or_irap_pic_flag)
2661 flag(ph_gdr_pic_flag);
2662 else
2663 infer(ph_gdr_pic_flag, 0);
2664 flag(ph_inter_slice_allowed_flag);
2665 if (current->ph_inter_slice_allowed_flag)
2666 flag(ph_intra_slice_allowed_flag);
2667 else
2668 infer(ph_intra_slice_allowed_flag, 1);
2669 ue(ph_pic_parameter_set_id, 0, VVC_MAX_PPS_COUNT - 1);
2670 pps = h266->pps[current->ph_pic_parameter_set_id];
2671 if (!pps) {
2672 av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
2673 current->ph_pic_parameter_set_id);
2674 return AVERROR_INVALIDDATA;
2675 }
2676 sps = h266->sps[pps->pps_seq_parameter_set_id];
2677 if (!sps) {
2678 av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
2679 pps->pps_seq_parameter_set_id);
2680 return AVERROR_INVALIDDATA;
2681 }
2682 vps = h266->vps[sps->sps_video_parameter_set_id];
2683 if (!vps) {
2684 av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n",
2685 sps->sps_video_parameter_set_id);
2686 return AVERROR_INVALIDDATA;
2687 }
2688
2689 ub(sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4, ph_pic_order_cnt_lsb);
2690 if (current->ph_gdr_pic_flag)
2691 ue(ph_recovery_poc_cnt, 0,
2692 1 << (sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4));
2693
2694 for (i = 0; i < sps->sps_num_extra_ph_bytes * 8; i++) {
2695 if (sps->sps_extra_ph_bit_present_flag[i])
2696 flags(ph_extra_bit[i], 1, i);
2697 }
2698 if (sps->sps_poc_msb_cycle_flag) {
2699 flag(ph_poc_msb_cycle_present_flag);
2700 if (current->ph_poc_msb_cycle_present_flag)
2701 ub(sps->sps_poc_msb_cycle_len_minus1 + 1, ph_poc_msb_cycle_val);
2702 }
2703 if (sps->sps_alf_enabled_flag && pps->pps_alf_info_in_ph_flag) {
2704 flag(ph_alf_enabled_flag);
2705 if (current->ph_alf_enabled_flag) {
2706
2707 ub(3, ph_num_alf_aps_ids_luma);
2708 for (i = 0; i < current->ph_num_alf_aps_ids_luma; i++)
2709 ubs(3, ph_alf_aps_id_luma[i], 1, i);
2710
2711 if (sps->sps_chroma_format_idc != 0) {
2712 flag(ph_alf_cb_enabled_flag);
2713 flag(ph_alf_cr_enabled_flag);
2714 } else {
2715 infer(ph_alf_cb_enabled_flag, 0);
2716 infer(ph_alf_cr_enabled_flag, 0);
2717 }
2718
2719 if (current->ph_alf_cb_enabled_flag
2720 || current->ph_alf_cr_enabled_flag) {
2721 ub(3, ph_alf_aps_id_chroma);
2722 }
2723
2724 if (sps->sps_ccalf_enabled_flag) {
2725 flag(ph_alf_cc_cb_enabled_flag);
2726 if (current->ph_alf_cc_cb_enabled_flag)
2727 ub(3, ph_alf_cc_cb_aps_id);
2728 flag(ph_alf_cc_cr_enabled_flag);
2729 if (current->ph_alf_cc_cr_enabled_flag)
2730 ub(3, ph_alf_cc_cr_aps_id);
2731 }
2732 }
2733 } else {
2734 infer(ph_alf_enabled_flag, 0);
2735 }
2736 if (sps->sps_lmcs_enabled_flag) {
2737 flag(ph_lmcs_enabled_flag);
2738 if (current->ph_lmcs_enabled_flag) {
2739 ub(2, ph_lmcs_aps_id);
2740 if (sps->sps_chroma_format_idc != 0)
2741 flag(ph_chroma_residual_scale_flag);
2742 else
2743 infer(ph_chroma_residual_scale_flag, 0);
2744 }
2745 } else {
2746 infer(ph_lmcs_enabled_flag, 0);
2747 infer(ph_chroma_residual_scale_flag, 0);
2748 }
2749
2750 if (sps->sps_explicit_scaling_list_enabled_flag) {
2751 flag(ph_explicit_scaling_list_enabled_flag);
2752 if (current->ph_explicit_scaling_list_enabled_flag) {
2753 //todo: check the ph_scaling_list_aps_id range, when aps ready
2754 ub(3, ph_scaling_list_aps_id);
2755 }
2756 } else {
2757 infer(ph_explicit_scaling_list_enabled_flag, 0);
2758 }
2759 if (sps->sps_virtual_boundaries_enabled_flag &&
2760 !sps->sps_virtual_boundaries_present_flag) {
2761 flag(ph_virtual_boundaries_present_flag);
2762 if (current->ph_virtual_boundaries_present_flag) {
2763 ue(ph_num_ver_virtual_boundaries,
2764 0, pps->pps_pic_width_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
2765 for (i = 0; i < current->ph_num_ver_virtual_boundaries; i++) {
2766 ues(ph_virtual_boundary_pos_x_minus1[i],
2767 0, (pps->pps_pic_width_in_luma_samples + 7) / 8 - 2, 1, i);
2768 }
2769 ue(ph_num_hor_virtual_boundaries,
2770 0, pps->pps_pic_height_in_luma_samples <= 8 ? 0 : VVC_MAX_VBS);
2771 for (i = 0; i < current->ph_num_hor_virtual_boundaries; i++) {
2772 ues(ph_virtual_boundary_pos_y_minus1[i],
2773 0, (pps->pps_pic_height_in_luma_samples + 7) / 8 - 2, 1, i);
2774 }
2775 } else {
2776 infer(ph_num_ver_virtual_boundaries, 0);
2777 infer(ph_num_hor_virtual_boundaries, 0);
2778 }
2779 }
2780 if (pps->pps_output_flag_present_flag && !current->ph_non_ref_pic_flag)
2781 flag(ph_pic_output_flag);
2782 else
2783 infer(ph_pic_output_flag, 1);
2784 if (pps->pps_rpl_info_in_ph_flag) {
2786 (ctx, rw, sps, pps, &current->ph_ref_pic_lists));
2787 }
2788 if (sps->sps_partition_constraints_override_enabled_flag)
2789 flag(ph_partition_constraints_override_flag);
2790 else
2791 infer(ph_partition_constraints_override_flag, 0);
2792
2793 ctb_log2_size_y = sps->sps_log2_ctu_size_minus5 + 5;
2794 min_cb_log2_size_y = sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
2795 if (current->ph_intra_slice_allowed_flag) {
2796 if (current->ph_partition_constraints_override_flag) {
2797 ue(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2798 0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2799 ue(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2800 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2801 if (current->ph_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
2802 min_qt_log2_size_intra_y =
2803 current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2804 min_cb_log2_size_y;
2805 ue(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2806 0, (sps->sps_qtbtt_dual_tree_intra_flag ?
2807 FFMIN(6, ctb_log2_size_y) :
2808 ctb_log2_size_y) - min_qt_log2_size_intra_y);
2809 ue(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2810 0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
2811 } else {
2812 infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2813 sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2814 infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2815 sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2816 }
2817 if (sps->sps_qtbtt_dual_tree_intra_flag) {
2818 ue(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2819 0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2820 ue(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2821 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2822 if (current->ph_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
2823 unsigned int min_qt_log2_size_intra_c =
2824 current->ph_log2_diff_min_qt_min_cb_intra_slice_chroma +
2825 min_cb_log2_size_y;
2826 ue(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2827 0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2828 ue(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2829 0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2830 } else {
2831 infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2832 sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2833 infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2834 sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2835 }
2836 }
2837 } else {
2838 infer(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2839 sps->sps_log2_diff_min_qt_min_cb_intra_slice_luma);
2840 infer(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2841 sps->sps_max_mtt_hierarchy_depth_intra_slice_luma);
2842 infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2843 sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2844 infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2845 sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2846 infer(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2847 sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma);
2848 infer(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2849 sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma);
2850 infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2851 sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2852 infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2853 sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2854 }
2855
2856 min_qt_log2_size_intra_y =
2857 current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2858 min_cb_log2_size_y;
2859 if (pps->pps_cu_qp_delta_enabled_flag)
2860 ue(ph_cu_qp_delta_subdiv_intra_slice, 0,
2861 2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2862 current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2863 else
2864 infer(ph_cu_qp_delta_subdiv_intra_slice, 0);
2865
2866 if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2867 ue(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0,
2868 2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2869 current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2870 else
2871 infer(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0);
2872 }
2873 if (current->ph_inter_slice_allowed_flag) {
2874 if (current->ph_partition_constraints_override_flag) {
2875 ue(ph_log2_diff_min_qt_min_cb_inter_slice,
2876 0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2877 min_qt_log2_size_inter_y =
2878 current->ph_log2_diff_min_qt_min_cb_inter_slice +
2879 min_cb_log2_size_y;
2880 ue(ph_max_mtt_hierarchy_depth_inter_slice, 0,
2881 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2882 if (current->ph_max_mtt_hierarchy_depth_inter_slice != 0) {
2883 ue(ph_log2_diff_max_bt_min_qt_inter_slice,
2884 0, ctb_log2_size_y - min_qt_log2_size_inter_y);
2885 ue(ph_log2_diff_max_tt_min_qt_inter_slice,
2886 0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
2887 }
2888 } else {
2889 infer(ph_log2_diff_min_qt_min_cb_inter_slice,
2890 sps->sps_log2_diff_min_qt_min_cb_inter_slice);
2891 min_qt_log2_size_inter_y =
2892 current->ph_log2_diff_min_qt_min_cb_inter_slice +
2893 min_cb_log2_size_y;
2894 infer(ph_max_mtt_hierarchy_depth_inter_slice,
2895 sps->sps_max_mtt_hierarchy_depth_inter_slice);
2896 infer(ph_log2_diff_max_bt_min_qt_inter_slice,
2897 sps->sps_log2_diff_max_bt_min_qt_inter_slice);
2898 infer(ph_log2_diff_max_tt_min_qt_inter_slice,
2899 sps->sps_log2_diff_max_tt_min_qt_inter_slice);
2900 }
2901
2902 if (pps->pps_cu_qp_delta_enabled_flag)
2903 ue(ph_cu_qp_delta_subdiv_inter_slice, 0,
2904 2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2905 current->ph_max_mtt_hierarchy_depth_inter_slice));
2906 else
2907 infer(ph_cu_qp_delta_subdiv_inter_slice, 0);
2908
2909 if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2910 ue(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0,
2911 2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2912 current->ph_max_mtt_hierarchy_depth_inter_slice));
2913 else
2914 infer(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0);
2915 if (sps->sps_temporal_mvp_enabled_flag) {
2916 flag(ph_temporal_mvp_enabled_flag);
2917 if (current->ph_temporal_mvp_enabled_flag &&
2918 pps->pps_rpl_info_in_ph_flag) {
2919 if (current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0)
2920 flag(ph_collocated_from_l0_flag);
2921 else
2922 infer(ph_collocated_from_l0_flag, 1);
2923 if ((current->ph_collocated_from_l0_flag &&
2924 current->ph_ref_pic_lists.rpl_ref_list[0].num_ref_entries > 1)
2925 || (!current->ph_collocated_from_l0_flag &&
2926 current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 1)) {
2927 unsigned int idx =
2928 current->ph_collocated_from_l0_flag ? 0 : 1;
2929 ue(ph_collocated_ref_idx, 0,
2930 current->ph_ref_pic_lists.rpl_ref_list[idx].
2931 num_ref_entries - 1);
2932 } else {
2933 infer(ph_collocated_ref_idx, 0);
2934 }
2935 }
2936 }
2937 if (sps->sps_mmvd_fullpel_only_enabled_flag)
2938 flag(ph_mmvd_fullpel_only_flag);
2939 else
2940 infer(ph_mmvd_fullpel_only_flag, 0);
2941 if (!pps->pps_rpl_info_in_ph_flag ||
2942 current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0) {
2943 flag(ph_mvd_l1_zero_flag);
2944 if (sps->sps_bdof_control_present_in_ph_flag) {
2945 flag(ph_bdof_disabled_flag);
2946 } else {
2947 if (!sps->sps_bdof_control_present_in_ph_flag)
2948 infer(ph_bdof_disabled_flag,
2949 1 - sps->sps_bdof_enabled_flag);
2950 else
2951 infer(ph_bdof_disabled_flag, 1);
2952 }
2953 if (sps->sps_dmvr_control_present_in_ph_flag) {
2954 flag(ph_dmvr_disabled_flag);
2955 } else {
2956 if (!sps->sps_dmvr_control_present_in_ph_flag)
2957 infer(ph_dmvr_disabled_flag,
2958 1 - sps->sps_dmvr_enabled_flag);
2959 else
2960 infer(ph_dmvr_disabled_flag, 1);
2961 }
2962 } else {
2963 infer(ph_mvd_l1_zero_flag, 1);
2964 }
2965 if (sps->sps_prof_control_present_in_ph_flag)
2966 flag(ph_prof_disabled_flag);
2967 else
2968 infer(ph_prof_disabled_flag, !sps->sps_affine_prof_enabled_flag);
2969 if ((pps->pps_weighted_pred_flag ||
2970 pps->pps_weighted_bipred_flag) && pps->pps_wp_info_in_ph_flag) {
2971
2972 // if pps->pps_wp_info_in_ph_fla == 1
2973 // pred_weight_table will not use num_ref_idx_active
2974 uint8_t num_ref_idx_active[2] = { 0, 0 };
2976 (ctx, rw, sps, pps, &current->ph_ref_pic_lists,
2977 num_ref_idx_active, &current->ph_pred_weight_table));
2978 }
2979 }
2980
2981 qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2982 if (pps->pps_qp_delta_info_in_ph_flag)
2983 se(ph_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
2984 63 - (26 + pps->pps_init_qp_minus26));
2985
2986 if (sps->sps_joint_cbcr_enabled_flag)
2987 flag(ph_joint_cbcr_sign_flag);
2988 else
2989 infer(ph_joint_cbcr_sign_flag, 0);
2990 if (sps->sps_sao_enabled_flag && pps->pps_sao_info_in_ph_flag) {
2991 flag(ph_sao_luma_enabled_flag);
2992 if (sps->sps_chroma_format_idc != 0)
2993 flag(ph_sao_chroma_enabled_flag);
2994 else
2995 infer(ph_sao_chroma_enabled_flag, 0);
2996 } else {
2997 infer(ph_sao_luma_enabled_flag, 0);
2998 infer(ph_sao_chroma_enabled_flag, 0);
2999 }
3000
3001 if (pps->pps_dbf_info_in_ph_flag)
3002 flag(ph_deblocking_params_present_flag);
3003 else
3004 infer(ph_deblocking_params_present_flag, 0);
3005
3006 if (current->ph_deblocking_params_present_flag) {
3007 if (!pps->pps_deblocking_filter_disabled_flag) {
3008 flag(ph_deblocking_filter_disabled_flag);
3009 if (!current->ph_deblocking_filter_disabled_flag) {
3010 se(ph_luma_beta_offset_div2, -12, 12);
3011 se(ph_luma_tc_offset_div2, -12, 12);
3012 if (pps->pps_chroma_tool_offsets_present_flag) {
3013 se(ph_cb_beta_offset_div2, -12, 12);
3014 se(ph_cb_tc_offset_div2, -12, 12);
3015 se(ph_cr_beta_offset_div2, -12, 12);
3016 se(ph_cr_tc_offset_div2, -12, 12);
3017 } else {
3018 infer(ph_cb_beta_offset_div2,
3019 current->ph_luma_beta_offset_div2);
3020 infer(ph_cb_tc_offset_div2,
3021 current->ph_luma_tc_offset_div2);
3022 infer(ph_cr_beta_offset_div2,
3023 current->ph_luma_beta_offset_div2);
3024 infer(ph_cr_tc_offset_div2,
3025 current->ph_luma_tc_offset_div2);
3026 }
3027 }
3028 } else {
3029 infer(ph_deblocking_filter_disabled_flag, 0);
3030 }
3031 } else {
3032 infer(ph_deblocking_filter_disabled_flag, pps->pps_deblocking_filter_disabled_flag);
3033 if (!current->ph_deblocking_filter_disabled_flag) {
3034 infer(ph_luma_beta_offset_div2, pps->pps_luma_beta_offset_div2);
3035 infer(ph_luma_tc_offset_div2, pps->pps_luma_tc_offset_div2);
3036 infer(ph_cb_beta_offset_div2, pps->pps_cb_beta_offset_div2);
3037 infer(ph_cb_tc_offset_div2, pps->pps_cb_tc_offset_div2);
3038 infer(ph_cr_beta_offset_div2, pps->pps_cr_beta_offset_div2);
3039 infer(ph_cr_tc_offset_div2, pps->pps_cr_tc_offset_div2);
3040 }
3041 }
3042
3043 if (pps->pps_picture_header_extension_present_flag) {
3044 ue(ph_extension_length, 0, 256);
3045 for (i = 0; i < current->ph_extension_length; i++)
3046 us(8, ph_extension_data_byte[i], 0x00, 0xff, 1, i);
3047 }
3048
3049 return 0;
3050}
3051
3054{
3055 int err;
3056
3057 HEADER("Picture Header");
3058
3059 CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, VVC_PH_NUT));
3060 CHECK(FUNC(picture_header) (ctx, rw, &current->ph_picture_header));
3062 return 0;
3063}
3064
3067{
3068 CodedBitstreamH266Context *h266 = ctx->priv_data;
3069 const H266RawSPS *sps;
3070 const H266RawPPS *pps;
3071 const H266RawPictureHeader *ph;
3073 int err, i;
3074 uint8_t nal_unit_type, qp_bd_offset;
3075 uint16_t num_slices_in_subpic;
3076
3077 HEADER("Slice Header");
3078
3079 CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, -1));
3080
3081 flag(sh_picture_header_in_slice_header_flag);
3082 if (current->sh_picture_header_in_slice_header_flag) {
3083 // 7.4.8 if sh_picture_header_in_slice_header_flag is true, we do not have a PH NAL unit
3084 CHECK(FUNC(picture_header) (ctx, rw, &current->sh_picture_header));
3085 ph = &current->sh_picture_header;
3086 } else {
3087 ph = h266->ph;
3088 if (!ph) {
3089 av_log(ctx->log_ctx, AV_LOG_ERROR,
3090 "Picture header not available.\n");
3091 return AVERROR_INVALIDDATA;
3092 }
3093 }
3094
3095 pps = h266->pps[ph->ph_pic_parameter_set_id];
3096 if (!pps) {
3097 av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
3098 ph->ph_pic_parameter_set_id);
3099 return AVERROR_INVALIDDATA;
3100 }
3101 sps = h266->sps[pps->pps_seq_parameter_set_id];
3102 if (!sps) {
3103 av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
3104 pps->pps_seq_parameter_set_id);
3105 return AVERROR_INVALIDDATA;
3106 }
3107
3108 if (sps->sps_subpic_info_present_flag) {
3109 ub(sps->sps_subpic_id_len_minus1 + 1, sh_subpic_id);
3110 for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
3111 if (pps->sub_pic_id_val[i] == current->sh_subpic_id) {
3112 current->curr_subpic_idx = i;
3113 break;
3114 }
3115 }
3116 if (i > sps->sps_num_subpics_minus1) {
3117 av_log(ctx->log_ctx, AV_LOG_ERROR, "invalid CurrSubpicIdx %d\n", i);
3118 return AVERROR_INVALIDDATA;
3119 }
3120 } else {
3121 current->curr_subpic_idx = 0;
3122 }
3123
3124 num_slices_in_subpic = pps->num_slices_in_subpic[current->curr_subpic_idx];
3125
3126 if ((pps->pps_rect_slice_flag && num_slices_in_subpic > 1) ||
3127 (!pps->pps_rect_slice_flag && pps->num_tiles_in_pic > 1)) {
3128 unsigned int bits, max;
3129 if (!pps->pps_rect_slice_flag) {
3130 bits = av_ceil_log2(pps->num_tiles_in_pic);
3131 max = pps->num_tiles_in_pic - 1;
3132 } else {
3133 bits = av_ceil_log2(num_slices_in_subpic);
3134 max = num_slices_in_subpic - 1;
3135 }
3136 u(bits, sh_slice_address, 0, max);
3137 } else {
3139 }
3140
3141 for (i = 0; i < sps->sps_num_extra_sh_bytes * 8; i++) {
3142 if (sps->sps_extra_sh_bit_present_flag[i])
3143 flags(sh_extra_bit[i], 1, i);
3144 }
3145
3146 if (!pps->pps_rect_slice_flag &&
3147 pps->num_tiles_in_pic - current->sh_slice_address > 1)
3148 ue(sh_num_tiles_in_slice_minus1, 0, pps->num_tiles_in_pic - 1 - current->sh_slice_address);
3149 else
3150 infer(sh_num_tiles_in_slice_minus1, 0);
3151
3152 if (ph->ph_inter_slice_allowed_flag)
3153 ue(sh_slice_type, 0, 2);
3154 else
3155 infer(sh_slice_type, 2);
3156
3157 nal_unit_type = current->nal_unit_header.nal_unit_type;
3158 if (nal_unit_type == VVC_IDR_W_RADL || nal_unit_type == VVC_IDR_N_LP ||
3159 nal_unit_type == VVC_CRA_NUT || nal_unit_type == VVC_GDR_NUT)
3160 flag(sh_no_output_of_prior_pics_flag);
3161
3162 if (sps->sps_alf_enabled_flag) {
3163 if (!pps->pps_alf_info_in_ph_flag) {
3164 flag(sh_alf_enabled_flag);
3165 if (current->sh_alf_enabled_flag) {
3166 ub(3, sh_num_alf_aps_ids_luma);
3167 for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3168 ubs(3, sh_alf_aps_id_luma[i], 1, i);
3169
3170 if (sps->sps_chroma_format_idc != 0) {
3171 flag(sh_alf_cb_enabled_flag);
3172 flag(sh_alf_cr_enabled_flag);
3173 }
3174 if (current->sh_alf_cb_enabled_flag ||
3175 current->sh_alf_cr_enabled_flag) {
3176 ub(3, sh_alf_aps_id_chroma);
3177 }
3178
3179 if (sps->sps_ccalf_enabled_flag) {
3180 flag(sh_alf_cc_cb_enabled_flag);
3181 if (current->sh_alf_cc_cb_enabled_flag)
3182 ub(3, sh_alf_cc_cb_aps_id);
3183
3184 flag(sh_alf_cc_cr_enabled_flag);
3185 if (current->sh_alf_cc_cr_enabled_flag)
3186 ub(3, sh_alf_cc_cr_aps_id);
3187 }
3188 }
3189 } else {
3190 infer(sh_alf_enabled_flag, ph->ph_alf_enabled_flag);
3191 if (current->sh_alf_enabled_flag) {
3192 infer(sh_num_alf_aps_ids_luma, ph->ph_num_alf_aps_ids_luma);
3193 for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3194 infer(sh_alf_aps_id_luma[i], ph->ph_alf_aps_id_luma[i]);
3195
3196 infer(sh_alf_cb_enabled_flag, ph->ph_alf_cb_enabled_flag);
3197 infer(sh_alf_cr_enabled_flag, ph->ph_alf_cr_enabled_flag);
3198 if (current->sh_alf_cb_enabled_flag ||current->sh_alf_cr_enabled_flag)
3199 infer(sh_alf_aps_id_chroma, ph->ph_alf_aps_id_chroma);
3200
3201 if (sps->sps_ccalf_enabled_flag) {
3202 infer(sh_alf_cc_cb_enabled_flag, ph->ph_alf_cc_cb_enabled_flag);
3203 if (current->sh_alf_cc_cb_enabled_flag)
3204 infer(sh_alf_cc_cb_aps_id, ph->ph_alf_cc_cb_aps_id);
3205
3206 infer(sh_alf_cc_cr_enabled_flag, ph->ph_alf_cc_cr_enabled_flag);
3207 if (current->sh_alf_cc_cr_enabled_flag)
3208 infer(sh_alf_cc_cr_aps_id, ph->ph_alf_cc_cr_aps_id);
3209 }
3210 }
3211 }
3212 }
3213
3214 if (current->sh_picture_header_in_slice_header_flag) {
3215 infer(sh_lmcs_used_flag, ph->ph_lmcs_enabled_flag);
3216 infer(sh_explicit_scaling_list_used_flag,
3217 ph->ph_explicit_scaling_list_enabled_flag);
3218 } else {
3219 if (ph->ph_lmcs_enabled_flag)
3220 flag(sh_lmcs_used_flag);
3221 else
3222 infer(sh_lmcs_used_flag, 0);
3223
3224 if (ph->ph_explicit_scaling_list_enabled_flag)
3225 flag(sh_explicit_scaling_list_used_flag);
3226 else
3227 infer(sh_explicit_scaling_list_used_flag, 0);
3228 }
3229
3230 if (!pps->pps_rpl_info_in_ph_flag &&
3231 ((nal_unit_type != VVC_IDR_W_RADL &&
3232 nal_unit_type != VVC_IDR_N_LP) || sps->sps_idr_rpl_present_flag)) {
3234 (ctx, rw, sps, pps, &current->sh_ref_pic_lists));
3235 ref_pic_lists = &current->sh_ref_pic_lists;
3236 } else {
3237 ref_pic_lists = &ph->ph_ref_pic_lists;
3238 }
3239 if ((current->sh_slice_type != VVC_SLICE_TYPE_I &&
3240 ref_pic_lists->rpl_ref_list[0].num_ref_entries > 1) ||
3241 (current->sh_slice_type == VVC_SLICE_TYPE_B &&
3242 ref_pic_lists->rpl_ref_list[1].num_ref_entries > 1)) {
3243 flag(sh_num_ref_idx_active_override_flag);
3244 if (current->sh_num_ref_idx_active_override_flag) {
3245 for (i = 0;
3246 i < (current->sh_slice_type == VVC_SLICE_TYPE_B ? 2 : 1); i++)
3247 if (ref_pic_lists->rpl_ref_list[i].num_ref_entries > 1)
3248 ues(sh_num_ref_idx_active_minus1[i], 0, 14, 1, i);
3249 else
3250 infer(sh_num_ref_idx_active_minus1[i], 0);
3251 }
3252 } else {
3253 infer(sh_num_ref_idx_active_override_flag, 1);
3254 }
3255
3256 for (i = 0; i < 2; i++) {
3257 if (current->sh_slice_type == VVC_SLICE_TYPE_B ||
3258 (current->sh_slice_type == VVC_SLICE_TYPE_P && i == 0)) {
3259 if (current->sh_num_ref_idx_active_override_flag) {
3260 current->num_ref_idx_active[i] = current->sh_num_ref_idx_active_minus1[i] + 1;
3261 } else {
3262 current->num_ref_idx_active[i] =
3263 FFMIN(ref_pic_lists->rpl_ref_list[i].num_ref_entries,
3264 pps->pps_num_ref_idx_default_active_minus1[i] + 1);
3265 }
3266
3267 if (current->num_ref_idx_active[i] <= 0) {
3268 av_log(ctx->log_ctx, AV_LOG_ERROR,
3269 "Inter slice but no reference pictures available for RPL%d.\n", i);
3270 return AVERROR_INVALIDDATA;
3271 }
3272 } else {
3273 current->num_ref_idx_active[i] = 0;
3274 }
3275 }
3276
3277 if (current->sh_slice_type != VVC_SLICE_TYPE_I) {
3278 if (pps->pps_cabac_init_present_flag)
3279 flag(sh_cabac_init_flag);
3280 else
3281 infer(sh_cabac_init_flag, 0);
3282 if (ph->ph_temporal_mvp_enabled_flag) {
3283 if (!pps->pps_rpl_info_in_ph_flag) {
3284 if (current->sh_slice_type == VVC_SLICE_TYPE_B)
3285 flag(sh_collocated_from_l0_flag);
3286 else
3287 infer(sh_collocated_from_l0_flag, 1);
3288 if ((current->sh_collocated_from_l0_flag &&
3289 current->num_ref_idx_active[0] > 1) ||
3290 (!current->sh_collocated_from_l0_flag &&
3291 current->num_ref_idx_active[1] > 1)) {
3292 unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1;
3293 ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] - 1);
3294 } else {
3295 infer(sh_collocated_ref_idx, 0);
3296 }
3297 } else {
3298 if (current->sh_slice_type == VVC_SLICE_TYPE_B)
3299 infer(sh_collocated_from_l0_flag, ph->ph_collocated_from_l0_flag);
3300 else
3301 infer(sh_collocated_from_l0_flag, 1);
3302 infer(sh_collocated_ref_idx, ph->ph_collocated_ref_idx);
3303 }
3304 }
3305 if (!pps->pps_wp_info_in_ph_flag &&
3306 ((pps->pps_weighted_pred_flag &&
3307 current->sh_slice_type == VVC_SLICE_TYPE_P) ||
3308 (pps->pps_weighted_bipred_flag &&
3309 current->sh_slice_type == VVC_SLICE_TYPE_B))) {
3311 current->num_ref_idx_active,
3312 &current->sh_pred_weight_table));
3313 }
3314 }
3315 qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
3316 if (!pps->pps_qp_delta_info_in_ph_flag)
3317 se(sh_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
3318 63 - (26 + pps->pps_init_qp_minus26));
3319 if (pps->pps_slice_chroma_qp_offsets_present_flag) {
3320 int8_t off;
3321
3322 se(sh_cb_qp_offset, -12, 12);
3323 off = pps->pps_cb_qp_offset + current->sh_cb_qp_offset;
3324 if (off < -12 || off > 12) {
3325 av_log(ctx->log_ctx, AV_LOG_ERROR,
3326 "pps_cb_qp_offset + sh_cb_qp_offset (%d) not in range [-12, 12].\n",
3327 off);
3328 return AVERROR_INVALIDDATA;
3329 }
3330
3331 se(sh_cr_qp_offset, -12, 12);
3332 off = pps->pps_cr_qp_offset + current->sh_cr_qp_offset;
3333 if (off < -12 || off > 12) {
3334 av_log(ctx->log_ctx, AV_LOG_ERROR,
3335 "pps_cr_qp_offset + sh_cr_qp_offset (%d) not in range [-12, 12].\n",
3336 off);
3337 return AVERROR_INVALIDDATA;
3338 }
3339
3340 if (sps->sps_joint_cbcr_enabled_flag) {
3341 se(sh_joint_cbcr_qp_offset, -12, 12);
3342 off =
3343 pps->pps_joint_cbcr_qp_offset_value +
3344 current->sh_joint_cbcr_qp_offset;
3345 if (off < -12 || off > 12) {
3346 av_log(ctx->log_ctx, AV_LOG_ERROR,
3347 "pps_joint_cbcr_qp_offset_value + sh_joint_cbcr_qp_offset (%d)"
3348 "not in range [-12, 12]. \n", off);
3349 return AVERROR_INVALIDDATA;
3350 }
3351 } else {
3352 infer(sh_joint_cbcr_qp_offset, 0);
3353 }
3354 } else {
3355 infer(sh_cb_qp_offset, 0);
3356 infer(sh_cr_qp_offset, 0);
3357 infer(sh_joint_cbcr_qp_offset, 0);
3358 }
3359 if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
3360 flag(sh_cu_chroma_qp_offset_enabled_flag);
3361 else
3362 infer(sh_cu_chroma_qp_offset_enabled_flag, 0);
3363 if (sps->sps_sao_enabled_flag && !pps->pps_sao_info_in_ph_flag) {
3364 flag(sh_sao_luma_used_flag);
3365 if (sps->sps_chroma_format_idc != 0)
3366 flag(sh_sao_chroma_used_flag);
3367 else
3368 infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3369 } else {
3370 infer(sh_sao_luma_used_flag, ph->ph_sao_luma_enabled_flag);
3371 infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3372 }
3373
3374 if (pps->pps_deblocking_filter_override_enabled_flag &&
3375 !pps->pps_dbf_info_in_ph_flag)
3376 flag(sh_deblocking_params_present_flag);
3377 else
3378 infer(sh_deblocking_params_present_flag, 0);
3379 if (current->sh_deblocking_params_present_flag) {
3380 if (!pps->pps_deblocking_filter_disabled_flag)
3381 flag(sh_deblocking_filter_disabled_flag);
3382 else
3383 infer(sh_deblocking_filter_disabled_flag, 0);
3384 if (!current->sh_deblocking_filter_disabled_flag) {
3385 se(sh_luma_beta_offset_div2, -12, 12);
3386 se(sh_luma_tc_offset_div2, -12, 12);
3387 if (pps->pps_chroma_tool_offsets_present_flag) {
3388 se(sh_cb_beta_offset_div2, -12, 12);
3389 se(sh_cb_tc_offset_div2, -12, 12);
3390 se(sh_cr_beta_offset_div2, -12, 12);
3391 se(sh_cr_tc_offset_div2, -12, 12);
3392 } else {
3393 infer(sh_cb_beta_offset_div2,
3394 current->sh_luma_beta_offset_div2);
3395 infer(sh_cb_tc_offset_div2, current->sh_luma_tc_offset_div2);
3396 infer(sh_cr_beta_offset_div2,
3397 current->sh_luma_beta_offset_div2);
3398 infer(sh_cr_tc_offset_div2, current->sh_luma_tc_offset_div2);
3399 }
3400 }
3401 } else {
3402 infer(sh_deblocking_filter_disabled_flag, ph->ph_deblocking_filter_disabled_flag);
3403 if (!current->sh_deblocking_filter_disabled_flag) {
3404 infer(sh_luma_beta_offset_div2, ph->ph_luma_beta_offset_div2);
3405 infer(sh_luma_tc_offset_div2, ph->ph_luma_tc_offset_div2);
3406 infer(sh_cb_beta_offset_div2, ph->ph_cb_beta_offset_div2);
3407 infer(sh_cb_tc_offset_div2, ph->ph_cb_tc_offset_div2);
3408 infer(sh_cr_beta_offset_div2, ph->ph_cr_beta_offset_div2);
3409 infer(sh_cr_tc_offset_div2, ph->ph_cr_tc_offset_div2);
3410 }
3411 }
3412
3413 if (sps->sps_dep_quant_enabled_flag)
3414 flag(sh_dep_quant_used_flag);
3415 else
3416 infer(sh_dep_quant_used_flag, 0);
3417
3418 if (sps->sps_sign_data_hiding_enabled_flag &&
3419 !current->sh_dep_quant_used_flag)
3420 flag(sh_sign_data_hiding_used_flag);
3421 else
3422 infer(sh_sign_data_hiding_used_flag, 0);
3423
3424 if (sps->sps_transform_skip_enabled_flag &&
3425 !current->sh_dep_quant_used_flag &&
3426 !current->sh_sign_data_hiding_used_flag)
3427 flag(sh_ts_residual_coding_disabled_flag);
3428 else
3429 infer(sh_ts_residual_coding_disabled_flag, 0);
3430
3431 if (!current->sh_ts_residual_coding_disabled_flag &&
3432 sps->sps_ts_residual_coding_rice_present_in_sh_flag)
3433 ub(3, sh_ts_residual_coding_rice_idx_minus1);
3434 else
3435 infer(sh_ts_residual_coding_rice_idx_minus1, 0);
3436
3437 if (sps->sps_reverse_last_sig_coeff_enabled_flag)
3438 flag(sh_reverse_last_sig_coeff_flag);
3439 else
3440 infer(sh_reverse_last_sig_coeff_flag, 0);
3441
3442 if (pps->pps_slice_header_extension_present_flag) {
3443 ue(sh_slice_header_extension_length, 0, 256);
3444 for (i = 0; i < current->sh_slice_header_extension_length; i++)
3445 us(8, sh_slice_header_extension_data_byte[i], 0x00, 0xff, 1, i);
3446 }
3447
3448 current->num_entry_points = 0;
3449 if (sps->sps_entry_point_offsets_present_flag) {
3450 uint8_t entropy_sync = sps->sps_entropy_coding_sync_enabled_flag;
3451 int height;
3452 if (pps->pps_rect_slice_flag) {
3453 int width_in_tiles;
3454 int slice_idx = current->sh_slice_address;
3455 for (i = 0; i < current->curr_subpic_idx; i++) {
3456 slice_idx += pps->num_slices_in_subpic[i];
3457 }
3458
3459 if (pps->pps_single_slice_per_subpic_flag) {
3460 int width_in_ctus, height_in_ctus;
3461 if (sps->sps_subpic_info_present_flag) {
3462 width_in_ctus = sps->sps_subpic_width_minus1[slice_idx] + 1;
3463 height_in_ctus = sps->sps_subpic_height_minus1[slice_idx] + 1;
3464 } else {
3465 const int log2_ctb_size = sps->sps_log2_ctu_size_minus5 + 5;
3466 const int ctb_size = 1 << log2_ctb_size;
3467 width_in_ctus = (pps->pps_pic_width_in_luma_samples + ctb_size - 1) >> log2_ctb_size;
3468 height_in_ctus = (pps->pps_pic_height_in_luma_samples + ctb_size - 1) >> log2_ctb_size;
3469 }
3470
3471 const int subpic_l = sps->sps_subpic_ctu_top_left_x[slice_idx];
3472 const int subpic_r = subpic_l + width_in_ctus;
3473
3474 int ctb_x = 0, tile_x = 0;
3475 for (; ctb_x < subpic_l && tile_x < pps->num_tile_columns; tile_x++)
3476 ctb_x += pps->col_width_val[tile_x];
3477
3478 width_in_tiles = 0;
3479 for (; ctb_x < subpic_r && tile_x < pps->num_tile_columns; tile_x++) {
3480 ctb_x += pps->col_width_val[tile_x];
3481 width_in_tiles++;
3482 }
3483
3484 if (entropy_sync) {
3485 height = height_in_ctus;
3486 } else {
3487 const int subpic_t = sps->sps_subpic_ctu_top_left_y[slice_idx];
3488 const int subpic_b = subpic_t + height_in_ctus;
3489
3490 int ctb_y = 0, tile_y = 0, height_in_tiles;
3491 for (; ctb_y < subpic_t && tile_y < pps->num_tile_rows; tile_y++)
3492 ctb_y += pps->row_height_val[tile_y];
3493
3494 height_in_tiles = 0;
3495 for (; ctb_y < subpic_b && tile_y < pps->num_tile_rows; tile_y++) {
3496 ctb_y += pps->row_height_val[tile_y];
3497 height_in_tiles++;
3498 }
3499
3500 height = height_in_tiles;
3501 }
3502 } else {
3503 width_in_tiles =
3504 pps->pps_slice_width_in_tiles_minus1[slice_idx] + 1;
3505
3506 if (entropy_sync)
3507 height = pps->slice_height_in_ctus[slice_idx];
3508 else
3509 height = pps->pps_slice_height_in_tiles_minus1[slice_idx] + 1;
3510 }
3511
3512 current->num_entry_points = width_in_tiles * height;
3513 } else {
3514 int tile_idx;
3515 int tile_y;
3516 for (tile_idx = current->sh_slice_address;
3517 tile_idx <=
3518 current->sh_slice_address +
3519 current->sh_num_tiles_in_slice_minus1; tile_idx++) {
3520 tile_y = tile_idx / pps->num_tile_columns;
3521 height = pps->row_height_val[tile_y];
3522 current->num_entry_points += (entropy_sync ? height : 1);
3523 }
3524 }
3525 current->num_entry_points--;
3526 if (current->num_entry_points > VVC_MAX_ENTRY_POINTS) {
3527 av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
3528 "%" PRIu32 ".\n", current->num_entry_points);
3529 return AVERROR_PATCHWELCOME;
3530 }
3531 if (current->num_entry_points > 0) {
3532 ue(sh_entry_offset_len_minus1, 0, 31);
3533 for (i = 0; i < current->num_entry_points; i++) {
3534 ubs(current->sh_entry_offset_len_minus1 + 1,
3535 sh_entry_point_offset_minus1[i], 1, i);
3536 }
3537 }
3538 }
3539 CHECK(FUNC(byte_alignment) (ctx, rw));
3540
3541 return 0;
3542}
3543
3546{
3547 int err;
3548
3549 if (prefix)
3550 HEADER("Prefix Supplemental Enhancement Information");
3551 else
3552 HEADER("Suffix Supplemental Enhancement Information");
3553
3554 CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header,
3557
3558 CHECK(FUNC_SEI(message_list) (ctx, rw, &current->message_list, prefix));
3559
3561
3562 return 0;
3563}
#define FUNC(a)
#define bits_left
Definition bitstream.h:116
int ff_cbs_h2645_payload_extension_present(GetBitContext *gbc, uint32_t payload_size, int cur_pos)
payload_extension_present() - true if we are before the last 1-bit in the payload structure,...
Definition cbs_h2645.c:33
int ff_cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
Definition cbs_h2645.c:217
#define allocate(name, size)
Definition cbs_h264.c:140
#define flag(name)
Definition cbs_h264.c:60
#define ue(name, range_min, range_max)
Definition cbs_h264.c:61
#define ub(width, name)
Definition cbs_h264.c:95
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define infer(name, value)
Definition cbs_h264.c:131
#define bit_position(rw)
Definition cbs_h264.c:137
#define byte_alignment(rw)
Definition cbs_h264.c:138
#define ues(name, range_min, range_max, subs,...)
Definition cbs_h264.c:76
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define FUNC_SEI(name)
Definition cbs_h264.c:44
#define RWContext
Definition cbs_h264.c:93
#define ses(name, range_min, range_max, subs,...)
Definition cbs_h264.c:82
#define xu(width, name, var, range_min, range_max, subs,...)
Definition cbs_h264.c:101
#define se(name, range_min, range_max)
Definition cbs_h264.c:67
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC vui_parameters(CodedBitstreamContext *ctx, RWContext *rw, H264RawVUI *current, H264RawSPS *sps)
static int FUNC rbsp_trailing_bits(CodedBitstreamContext *ctx, RWContext *rw)
static int FUNC aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
static int FUNC nal_unit_header(CodedBitstreamContext *ctx, RWContext *rw, H264RawNALUnitHeader *current, uint32_t valid_type_mask)
static int FUNC pred_weight_table(CodedBitstreamContext *ctx, RWContext *rw, H264RawSliceHeader *current)
static int FUNC slice_header(CodedBitstreamContext *ctx, RWContext *rw, H264RawSliceHeader *current)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC vui_parameters_default(CodedBitstreamContext *ctx, RWContext *rw, H264RawVUI *current, H264RawSPS *sps)
static int FUNC vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static int FUNC profile_tier_level(CodedBitstreamContext *ctx, RWContext *rw, H265RawProfileTierLevel *current, int profile_present_flag, int max_num_sub_layers_minus1)
static int FUNC extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawExtensionData *current)
static int FUNC scaling_list_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawScalingList *current)
static int FUNC sps_range_extension(CodedBitstreamContext *ctx, RWContext *rw, H265RawSPS *current)
static int FUNC vui_payload(CodedBitstreamContext *ctx, RWContext *rw, H266RawVUI *current, uint16_t vui_payload_size, uint8_t chroma_format_idc)
static int FUNC payload_extension(CodedBitstreamContext *ctx, RWContext *rw, H266RawExtensionData *current, uint32_t payload_size, int cur_pos)
static int FUNC ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
static int FUNC general_constraints_info(CodedBitstreamContext *ctx, RWContext *rw, H266GeneralConstraintsInfo *current)
static int FUNC alf_data(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current)
static int FUNC aps(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current, int prefix)
static int FUNC lmcs_data(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current)
static int FUNC general_timing_hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H266RawGeneralTimingHrdParameters *current)
static int FUNC opi(CodedBitstreamContext *ctx, RWContext *rw, H266RawOPI *current)
static int FUNC ols_timing_hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H266RawOlsTimingHrdParameters *current, uint8_t first_sublayer, uint8_t max_sublayers_minus1, const H266RawGeneralTimingHrdParameters *general)
static int FUNC ref_pic_lists(CodedBitstreamContext *ctx, RWContext *rw, const H266RawSPS *sps, const H266RawPPS *pps, H266RefPicLists *current)
static int FUNC picture_header(CodedBitstreamContext *ctx, RWContext *rw, H266RawPictureHeader *current)
static int FUNC sublayer_hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H266RawSubLayerHRDParameters *current, int sublayer_id, const H266RawGeneralTimingHrdParameters *general)
static int FUNC dpb_parameters(CodedBitstreamContext *ctx, RWContext *rw, H266DpbParameters *current, uint8_t max_sublayers_minus1, uint8_t sublayer_info_flag)
static int FUNC dci(CodedBitstreamContext *ctx, RWContext *rw, H266RawDCI *current)
static int FUNC ref_pic_list_struct(CodedBitstreamContext *ctx, RWContext *rw, H266RefPicListStruct *current, uint8_t list_idx, uint8_t rpls_idx, const H266RawSPS *sps)
#define MAX_UINT_BITS(length)
#define bit(string, value)
Definition cbs_mpeg2.c:56
int FUNC message_list(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMessageList *current, int prefix)
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define av_ceil_log2
Definition common.h:97
#define max(a, b)
uint64_t pps
Definition dovi_rpuenc.c:36
static struct @111144215057303131116103221376075045141373005341 current
static const uint8_t bits[8]
Definition fastaudio.c:100
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition get_bits.h:280
static void skip_bits(GetBitContext *s, int n)
Definition get_bits.h:383
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define ff_ctz
Definition intmath.h:105
#define r
Definition input.c:42
#define fixed(width, name, value)
Definition cbs_apv.c:75
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68
#define us(width, name, range_min, range_max, subs,...)
Definition cbs_apv.c:70
#define ubs(width, name, subs,...)
Definition cbs_apv.c:72
#define CHECK(call)
Definition cbs_apv.c:59
#define HEADER(name)
Definition cbs_apv.c:55
@ VVC_SLICE_TYPE_I
Definition vvc.h:66
@ VVC_SLICE_TYPE_B
Definition vvc.h:64
@ VVC_SLICE_TYPE_P
Definition vvc.h:65
@ VVC_ASP_TYPE_LMCS
Definition vvc.h:71
@ VVC_ASP_TYPE_SCALING
Definition vvc.h:72
@ VVC_ASP_TYPE_ALF
Definition vvc.h:70
@ VVC_MAX_VPS_COUNT
Definition vvc.h:95
@ VVC_MAX_PPS_COUNT
Definition vvc.h:99
@ VVC_MAX_REF_PIC_LISTS
Definition vvc.h:112
@ VVC_MAX_LAYERS
Definition vvc.h:80
@ VVC_MAX_ENTRY_POINTS
Definition vvc.h:153
@ VVC_MAX_TOTAL_NUM_OLSS
Definition vvc.h:92
@ VVC_MAX_REF_ENTRIES
Definition vvc.h:115
@ VVC_MAX_SLICES
Definition vvc.h:144
@ VVC_MAX_WIDTH
Definition vvc.h:132
@ VVC_MAX_TILES_PER_AU
Definition vvc.h:136
@ VVC_MAX_SUBLAYERS
Definition vvc.h:83
@ VVC_MAX_DPB_SIZE
Definition vvc.h:109
@ VVC_NUM_ALF_FILTERS
Definition vvc.h:106
@ VVC_MAX_TILE_ROWS
Definition vvc.h:139
@ VVC_MAX_VBS
Definition vvc.h:156
@ VVC_MAX_TILE_COLUMNS
Definition vvc.h:141
@ VVC_MAX_HEIGHT
Definition vvc.h:133
@ VVC_SPS_NUT
Definition vvc.h:44
@ VVC_PREFIX_SEI_NUT
Definition vvc.h:52
@ VVC_CRA_NUT
Definition vvc.h:38
@ VVC_IDR_N_LP
Definition vvc.h:37
@ VVC_OPI_NUT
Definition vvc.h:41
@ VVC_SUFFIX_SEI_NUT
Definition vvc.h:53
@ VVC_DCI_NUT
Definition vvc.h:42
@ VVC_PH_NUT
Definition vvc.h:48
@ VVC_VPS_NUT
Definition vvc.h:43
@ VVC_IDR_W_RADL
Definition vvc.h:36
@ VVC_GDR_NUT
Definition vvc.h:39
@ VVC_AUD_NUT
Definition vvc.h:49
@ VVC_PREFIX_APS_NUT
Definition vvc.h:46
@ VVC_PPS_NUT
Definition vvc.h:45
@ VVC_SUFFIX_APS_NUT
Definition vvc.h:47
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition refstruct.h:105
Context structure for coded bitstream operations.
Definition cbs.h:226
H266RawSPS * sps[VVC_MAX_SPS_COUNT]
RefStruct references.
Definition cbs_h266.h:870
H266RawPPS * pps[VVC_MAX_PPS_COUNT]
RefStruct references.
Definition cbs_h266.h:871
H266RawPictureHeader * ph
Definition cbs_h266.h:872
H266RawVPS * vps[VVC_MAX_VPS_COUNT]
RefStruct references.
Definition cbs_h266.h:869
uint8_t num_ref_entries
Definition cbs_h266.h:161
uint8_t inter_layer_ref_pic_flag[VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:163
uint8_t st_ref_pic_flag[VVC_MAX_REF_ENTRIES]
Definition cbs_h266.h:164
uint8_t ltrp_in_header_flag
Definition cbs_h266.h:162
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
static AVFormatContext * ctx
Definition movenc.c:49
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
char prefix[8]
static int sh_slice_address(VVCSH *sh, const H266RawSPS *sps, const VVCPPS *pps)
Definition ps.c:1341