FFmpeg
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 
31  H266RawNALUnitHeader *current,
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,
180  H266RawProfileTierLevel *current,
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 
214  RWContext *rw, H266RawVUI *current)
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 
240  H266RawVUI *current,
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 
311  H266RawExtensionData *current,
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 (!cbs_h265_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 
368  H266RawExtensionData *current)
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; 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 
395  H266DpbParameters *current,
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,
412  H266RefPicListStruct *current,
413  uint8_t list_idx, uint8_t rpls_idx,
414  const H266RawSPS *sps)
415 {
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,
493  H266RefPicLists *current) {
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");
521  return AVERROR_PATCHWELCOME;
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,
590  const H266RawGeneralTimingHrdParameters *general)
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,
612  const H266RawGeneralTimingHrdParameters *general)
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 
644  H266RawOPI *current)
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 
671  H266RawDCI *current)
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 
695  H266RawVPS *current)
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  //calc NumMultiLayerOlss
795  int m;
796  uint8_t dependency_flag[VVC_MAX_LAYERS][VVC_MAX_LAYERS];
797  uint16_t num_output_layers_in_ols[VVC_MAX_TOTAL_NUM_OLSS];
798  uint8_t num_sub_layers_in_layer_in_ols[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_TOTAL_NUM_OLSS];
799  uint8_t output_layer_idx[VVC_MAX_TOTAL_NUM_OLSS][VVC_MAX_LAYERS];
800 
801  //7.4.3.3 vps_direct_ref_layer_flag section
802  for (i = 0; i <= current->vps_max_layers_minus1; i++) {
803  for (j = 0; j <= current->vps_max_layers_minus1; j++) {
804  dependency_flag[i][j] = current->vps_direct_ref_layer_flag[i][j];
805  for (k = 0; k < i; k++) {
806  if (current->vps_direct_ref_layer_flag[i][k] &&
807  dependency_flag[k][j])
808  dependency_flag[i][j] = 1;
809  }
810  }
811  }
812  for (i = 0; i <= current->vps_max_layers_minus1; i++) {
813  int r;
814  for (j = 0, r = 0; j <= current->vps_max_layers_minus1; j++) {
815  if (dependency_flag[i][j])
816  reference_layer_idx[i][r++] = j;
817  }
818  num_ref_layers[i] = r;
819  }
820 
821  //7.4.3.3 vps_ols_output_layer_flag section
822  num_output_layers_in_ols[0] = 1;
823  num_sub_layers_in_layer_in_ols[0][0] =
824  current->vps_ptl_max_tid[current->vps_ols_ptl_idx[0]] + 1;
825  for (i = 1; i < total_num_olss; i++) {
826  if (ols_mode_idc == 4 || ols_mode_idc == 0) {
827  num_output_layers_in_ols[i] = 1;
828  if (current->vps_each_layer_is_an_ols_flag) {
829  num_sub_layers_in_layer_in_ols[i][0] =
830  current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
831  } else {
832  num_sub_layers_in_layer_in_ols[i][i] =
833  current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
834  for (k = i - 1; k >= 0; k--) {
835  num_sub_layers_in_layer_in_ols[i][k] = 0;
836  for (m = k + 1; m <= i; m++) {
837  uint8_t max_sublayer_needed =
838  FFMIN(num_sub_layers_in_layer_in_ols[i][m],
839  current->vps_max_tid_il_ref_pics_plus1[m][k]);
840  if (current->vps_direct_ref_layer_flag[m][k] &&
841  num_sub_layers_in_layer_in_ols[i][k] < max_sublayer_needed)
842  num_sub_layers_in_layer_in_ols[i][k] = max_sublayer_needed;
843  }
844  }
845  }
846  } else if (current->vps_ols_mode_idc == 1) {
847  num_output_layers_in_ols[i] = i + 1;
848  for (j = 0; j < num_output_layers_in_ols[i]; j++) {
849  num_sub_layers_in_layer_in_ols[i][j] =
850  current->vps_ptl_max_tid[current->vps_ols_ptl_idx[i]] + 1;
851  }
852  } else if (current->vps_ols_mode_idc == 2) {
853  uint8_t highest_included_layer = 0;
854  for (j = 0; j <= current->vps_max_layers_minus1; j++) {
855  layer_included_in_ols_flag[i][j] = 0;
856  num_sub_layers_in_layer_in_ols[i][j] = 0;
857  }
858  for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++) {
859  if (current->vps_ols_output_layer_flag[i][k]) {
860  layer_included_in_ols_flag[i][k] = 1;
861  highest_included_layer = k;
862  output_layer_idx[i][j] = k;
863  num_sub_layers_in_layer_in_ols[i][k] =
864  current->vps_ptl_max_tid[current->
865  vps_ols_ptl_idx[i]] + 1;
866  j++;
867  }
868  }
869  num_output_layers_in_ols[i] = j;
870  for (j = 0; j < num_output_layers_in_ols[i]; j++) {
871  int idx = output_layer_idx[i][j];
872  for (k = 0; k < num_ref_layers[idx]; k++) {
873  if (!layer_included_in_ols_flag[i][reference_layer_idx[idx][k]])
874  layer_included_in_ols_flag[i][reference_layer_idx[idx][k]] = 1;
875  }
876  }
877  for (k = highest_included_layer - 1; k >= 0; k--) {
878  if (layer_included_in_ols_flag[i][k] &&
879  !current->vps_ols_output_layer_flag[i][k]) {
880  for (m = k + 1; m <= highest_included_layer; m++) {
881  uint8_t max_sublayer_needed =
882  FFMIN(num_sub_layers_in_layer_in_ols[i][m],
883  current->vps_max_tid_il_ref_pics_plus1[m][k]);
884  if (current->vps_direct_ref_layer_flag[m][k] &&
885  layer_included_in_ols_flag[i][m] &&
886  num_sub_layers_in_layer_in_ols[i][k] <
887  max_sublayer_needed)
888  num_sub_layers_in_layer_in_ols[i][k] =
889  max_sublayer_needed;
890  }
891  }
892  }
893  }
894  if (!num_output_layers_in_ols[i])
895  return AVERROR_INVALIDDATA;
896  }
897  for (i = 1; i < total_num_olss; i++) {
898  int num_layers_in_ols = 0;
899  if (current->vps_each_layer_is_an_ols_flag) {
900  num_layers_in_ols = 1;
901  } else if (current->vps_ols_mode_idc == 0 ||
902  current->vps_ols_mode_idc == 1) {
903  num_layers_in_ols = i + 1;
904  } else if (current->vps_ols_mode_idc == 2) {
905  for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++) {
906  if (layer_included_in_ols_flag[i][k])
907  j++;
908  num_layers_in_ols = j;
909  }
910  }
911  if (num_layers_in_ols > 1) {
912  num_multi_layer_olss++;
913  }
914  }
915  }
916 
917  for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
918  if (i > 0)
919  flags(vps_pt_present_flag[i], 1, i);
920  else
921  infer(vps_pt_present_flag[i], 1);
922 
923  if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
924  us(3, vps_ptl_max_tid[i], 0, current->vps_max_sublayers_minus1, 1, i);
925  else
926  infer(vps_ptl_max_tid[i], current->vps_max_sublayers_minus1);
927  }
928  while (byte_alignment(rw) != 0)
929  fixed(1, vps_ptl_alignment_zero_bit, 0);
930  for (i = 0; i <= current->vps_num_ptls_minus1; i++) {
932  current->vps_profile_tier_level + i,
933  current->vps_pt_present_flag[i],
934  current->vps_ptl_max_tid[i]));
935  }
936  for (i = 0; i < total_num_olss; i++) {
937  if (current->vps_num_ptls_minus1 > 0 &&
938  current->vps_num_ptls_minus1 + 1 != total_num_olss) {
939  us(8, vps_ols_ptl_idx[i], 0, current->vps_num_ptls_minus1, 1, i);
940  } else if (current->vps_num_ptls_minus1 == 0) {
941  infer(vps_ols_ptl_idx[i], 0);
942  } else {
943  infer(vps_ols_ptl_idx[i], i);
944  }
945  }
946 
947  if (!current->vps_each_layer_is_an_ols_flag) {
948  uint16_t vps_num_dpb_params;
949  ue(vps_num_dpb_params_minus1, 0, num_multi_layer_olss - 1);
950  if (current->vps_each_layer_is_an_ols_flag)
951  vps_num_dpb_params = 0;
952  else
953  vps_num_dpb_params = current->vps_num_dpb_params_minus1 + 1;
954 
955  if (current->vps_max_sublayers_minus1 > 0)
956  flag(vps_sublayer_dpb_params_present_flag);
957  else
958  infer(vps_sublayer_dpb_params_present_flag, 0);
959 
960  for (i = 0; i < vps_num_dpb_params; i++) {
961  if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
962  us(3, vps_dpb_max_tid[i], 0, current->vps_max_sublayers_minus1,
963  1, i);
964  else
965  infer(vps_dpb_max_tid[i], current->vps_max_sublayers_minus1);
966  CHECK(FUNC(dpb_parameters) (ctx, rw, current->vps_dpb_params + i,
967  current->vps_dpb_max_tid[i],
968  current->
969  vps_sublayer_dpb_params_present_flag));
970  }
971  for (i = 0; i < num_multi_layer_olss; i++) {
972  ues(vps_ols_dpb_pic_width[i], 0, UINT16_MAX, 1, i);
973  ues(vps_ols_dpb_pic_height[i], 0, UINT16_MAX, 1, i);
974  ubs(2, vps_ols_dpb_chroma_format[i], 1, i);
975  ues(vps_ols_dpb_bitdepth_minus8[i], 0, 8, 1, i);
976  if (vps_num_dpb_params > 1
977  && vps_num_dpb_params != num_multi_layer_olss)
978  ues(vps_ols_dpb_params_idx[i], 0, vps_num_dpb_params - 1, 1, i);
979  else if (vps_num_dpb_params == 1)
980  infer(vps_ols_dpb_params_idx[i], 0);
981  else
982  infer(vps_ols_dpb_params_idx[i], i);
983  }
984  flag(vps_timing_hrd_params_present_flag);
985  if (current->vps_timing_hrd_params_present_flag) {
987  &current->
988  vps_general_timing_hrd_parameters));
989  if (current->vps_max_sublayers_minus1 > 0)
990  flag(vps_sublayer_cpb_params_present_flag);
991  else
992  infer(vps_sublayer_cpb_params_present_flag, 0);
993  ue(vps_num_ols_timing_hrd_params_minus1, 0,
994  num_multi_layer_olss - 1);
995  for (i = 0; i <= current->vps_num_ols_timing_hrd_params_minus1; i++) {
996  uint8_t first_sublayer;
997  if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
998  us(3, vps_hrd_max_tid[i], 0,
999  current->vps_max_sublayers_minus1, 1, i);
1000  else
1001  infer(vps_hrd_max_tid[i],
1002  current->vps_max_sublayers_minus1);
1003  first_sublayer = current->vps_sublayer_cpb_params_present_flag ?
1004  0 : current->vps_hrd_max_tid[i];
1006  (ctx, rw, &current->vps_ols_timing_hrd_parameters,
1007  first_sublayer, current->vps_max_sublayers_minus1,
1008  &current->vps_general_timing_hrd_parameters));
1009 
1010  }
1011  if (current->vps_num_ols_timing_hrd_params_minus1 > 0 &&
1012  current->vps_num_ols_timing_hrd_params_minus1 + 1 !=
1013  num_multi_layer_olss) {
1014  for (i = 0; i < num_multi_layer_olss; i++) {
1015  ues(vps_ols_timing_hrd_idx[i], 0,
1016  current->vps_num_ols_timing_hrd_params_minus1, 1, i);
1017  }
1018  } else if (current->vps_num_ols_timing_hrd_params_minus1 == 0) {
1019  for (i = 0; i < num_multi_layer_olss; i++)
1020  infer(vps_ols_timing_hrd_idx[i], 0);
1021  } else {
1022  for (i = 0; i < num_multi_layer_olss; i++)
1023  infer(vps_ols_timing_hrd_idx[i], i);
1024  }
1025  }
1026  }
1027 
1028  flag(vps_extension_flag);
1029  if (current->vps_extension_flag)
1030  CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
1031  CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
1032 
1033  return 0;
1034 }
1035 
1037  H266RawSPS *current)
1038 {
1039  int err;
1040 
1041  flag(sps_extended_precision_flag);
1042  if (current->sps_transform_skip_enabled_flag)
1043  flag(sps_ts_residual_coding_rice_present_in_sh_flag);
1044  else
1045  infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1046  flag(sps_rrc_rice_extension_flag);
1047  flag(sps_persistent_rice_adaptation_enabled_flag);
1048  flag(sps_reverse_last_sig_coeff_enabled_flag);
1049 
1050  return 0;
1051 }
1052 
1054  H266RawSPS *current)
1055 {
1057  int err, i, j;
1058  unsigned int ctb_log2_size_y, min_cb_log2_size_y,
1059  min_qt_log2_size_intra_y, min_qt_log2_size_inter_y,
1060  ctb_size_y, max_num_merge_cand, tmp_width_val, tmp_height_val;
1061  uint8_t qp_bd_offset;
1062 
1063  static const uint8_t h266_sub_width_c[] = {
1064  1, 2, 2, 1
1065  };
1066  static const uint8_t h266_sub_height_c[] = {
1067  1, 2, 1, 1
1068  };
1069 
1070  HEADER("Sequence Parameter Set");
1071 
1072  CHECK(FUNC(nal_unit_header) (ctx, rw,
1073  &current->nal_unit_header, VVC_SPS_NUT));
1074 
1075  ub(4, sps_seq_parameter_set_id);
1076  ub(4, sps_video_parameter_set_id);
1077  if (current->sps_video_parameter_set_id == 0 && !h266->vps[0]) {
1078  H266RawVPS *vps = ff_refstruct_allocz(sizeof(*vps));
1079  if (!vps)
1080  return AVERROR(ENOMEM);
1081  vps->vps_max_layers_minus1 = 0;
1082  vps->vps_independent_layer_flag[0] = 1;
1083  vps->vps_layer_id[0] = current->nal_unit_header.nuh_layer_id;
1084  h266->vps[0] = vps;
1085  }
1086 
1087  u(3, sps_max_sublayers_minus1, 0, VVC_MAX_SUBLAYERS - 1);
1088  u(2, sps_chroma_format_idc, 0, 3);
1089  u(2, sps_log2_ctu_size_minus5, 0, 3);
1090  ctb_log2_size_y = current->sps_log2_ctu_size_minus5 + 5;
1091  ctb_size_y = 1 << ctb_log2_size_y;
1092 
1093  flag(sps_ptl_dpb_hrd_params_present_flag);
1094  if (current->sps_ptl_dpb_hrd_params_present_flag) {
1095  CHECK(FUNC(profile_tier_level) (ctx, rw, &current->profile_tier_level,
1096  1, current->sps_max_sublayers_minus1));
1097  }
1098  flag(sps_gdr_enabled_flag);
1099  flag(sps_ref_pic_resampling_enabled_flag);
1100  if (current->sps_ref_pic_resampling_enabled_flag)
1101  flag(sps_res_change_in_clvs_allowed_flag);
1102  else
1103  infer(sps_res_change_in_clvs_allowed_flag, 0);
1104 
1105  ue(sps_pic_width_max_in_luma_samples, 1, VVC_MAX_WIDTH);
1106  ue(sps_pic_height_max_in_luma_samples, 1, VVC_MAX_HEIGHT);
1107 
1108  flag(sps_conformance_window_flag);
1109  if (current->sps_conformance_window_flag) {
1110  uint8_t sub_width_c = h266_sub_width_c[current->sps_chroma_format_idc];
1111  uint8_t sub_height_c = h266_sub_height_c[current->sps_chroma_format_idc];
1112  uint16_t width = current->sps_pic_width_max_in_luma_samples / sub_width_c;
1113  uint16_t height = current->sps_pic_height_max_in_luma_samples / sub_height_c;
1114  ue(sps_conf_win_left_offset, 0, width);
1115  ue(sps_conf_win_right_offset, 0, width - current->sps_conf_win_left_offset);
1116  ue(sps_conf_win_top_offset, 0, height);
1117  ue(sps_conf_win_bottom_offset, 0, height - current->sps_conf_win_top_offset);
1118  } else {
1119  infer(sps_conf_win_left_offset, 0);
1120  infer(sps_conf_win_right_offset, 0);
1121  infer(sps_conf_win_top_offset, 0);
1122  infer(sps_conf_win_bottom_offset, 0);
1123  }
1124 
1125  tmp_width_val = AV_CEIL_RSHIFT(current->sps_pic_width_max_in_luma_samples,
1126  ctb_log2_size_y);
1127  tmp_height_val = AV_CEIL_RSHIFT(current->sps_pic_height_max_in_luma_samples,
1128  ctb_log2_size_y);
1129 
1130  flag(sps_subpic_info_present_flag);
1131  if (current->sps_subpic_info_present_flag) {
1132  ue(sps_num_subpics_minus1, 1, VVC_MAX_SLICES - 1);
1133  if (current->sps_num_subpics_minus1 > 0) {
1134  flag(sps_independent_subpics_flag);
1135  flag(sps_subpic_same_size_flag);
1136  }
1137 
1138  if (current->sps_num_subpics_minus1 > 0) {
1139  int wlen = av_ceil_log2(tmp_width_val);
1140  int hlen = av_ceil_log2(tmp_height_val);
1141  infer(sps_subpic_ctu_top_left_x[0], 0);
1142  infer(sps_subpic_ctu_top_left_y[0], 0);
1143  if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1144  ubs(wlen, sps_subpic_width_minus1[0], 1, 0);
1145  else
1146  infer(sps_subpic_width_minus1[0], tmp_width_val - 1);
1147  if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1148  ubs(hlen, sps_subpic_height_minus1[0], 1, 0);
1149  else
1150  infer(sps_subpic_height_minus1[0], tmp_height_val - 1);
1151  if (!current->sps_independent_subpics_flag) {
1152  flags(sps_subpic_treated_as_pic_flag[0], 1, 0);
1153  flags(sps_loop_filter_across_subpic_enabled_flag[0], 1, 0);
1154  } else {
1155  infer(sps_subpic_treated_as_pic_flag[0], 1);
1156  infer(sps_loop_filter_across_subpic_enabled_flag[0], 1);
1157  }
1158  for (i = 1; i <= current->sps_num_subpics_minus1; i++) {
1159  if (!current->sps_subpic_same_size_flag) {
1160  if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1161  ubs(wlen, sps_subpic_ctu_top_left_x[i], 1, i);
1162  else
1163  infer(sps_subpic_ctu_top_left_x[i], 0);
1164  if (current->sps_pic_height_max_in_luma_samples >
1165  ctb_size_y)
1166  ubs(hlen, sps_subpic_ctu_top_left_y[i], 1, i);
1167  else
1168  infer(sps_subpic_ctu_top_left_y[i], 0);
1169  if (i < current->sps_num_subpics_minus1 &&
1170  current->sps_pic_width_max_in_luma_samples >
1171  ctb_size_y) {
1172  ubs(wlen, sps_subpic_width_minus1[i], 1, i);
1173  } else {
1174  infer(sps_subpic_width_minus1[i],
1175  tmp_width_val -
1176  current->sps_subpic_ctu_top_left_x[i] - 1);
1177  }
1178  if (i < current->sps_num_subpics_minus1 &&
1179  current->sps_pic_height_max_in_luma_samples >
1180  ctb_size_y) {
1181  ubs(hlen, sps_subpic_height_minus1[i], 1, i);
1182  } else {
1183  infer(sps_subpic_height_minus1[i],
1184  tmp_height_val -
1185  current->sps_subpic_ctu_top_left_y[i] - 1);
1186  }
1187  } else {
1188  int num_subpic_cols = tmp_width_val /
1189  (current->sps_subpic_width_minus1[0] + 1);
1190  if (tmp_width_val % (current->sps_subpic_width_minus1[0] + 1) ||
1191  tmp_height_val % (current->sps_subpic_width_minus1[0] + 1) ||
1192  current->sps_num_subpics_minus1 !=
1193  (num_subpic_cols * tmp_height_val /
1194  (current->sps_subpic_height_minus1[0] + 1) - 1))
1195  return AVERROR_INVALIDDATA;
1196  infer(sps_subpic_ctu_top_left_x[i],
1197  (i % num_subpic_cols) *
1198  (current->sps_subpic_width_minus1[0] + 1));
1199  infer(sps_subpic_ctu_top_left_y[i],
1200  (i / num_subpic_cols) *
1201  (current->sps_subpic_height_minus1[0] + 1));
1202  infer(sps_subpic_width_minus1[i],
1203  current->sps_subpic_width_minus1[0]);
1204  infer(sps_subpic_height_minus1[i],
1205  current->sps_subpic_height_minus1[0]);
1206  }
1207  if (!current->sps_independent_subpics_flag) {
1208  flags(sps_subpic_treated_as_pic_flag[i], 1, i);
1209  flags(sps_loop_filter_across_subpic_enabled_flag[i], 1, i);
1210  } else {
1211  infer(sps_subpic_treated_as_pic_flag[i], 1);
1212  infer(sps_loop_filter_across_subpic_enabled_flag[i], 0);
1213  }
1214  }
1215  ue(sps_subpic_id_len_minus1, 0, 15);
1216  if ((1 << (current->sps_subpic_id_len_minus1 + 1)) <
1217  current->sps_num_subpics_minus1 + 1) {
1218  av_log(ctx->log_ctx, AV_LOG_ERROR,
1219  "sps_subpic_id_len_minus1(%d) is too small\n",
1220  current->sps_subpic_id_len_minus1);
1221  return AVERROR_INVALIDDATA;
1222  }
1223  flag(sps_subpic_id_mapping_explicitly_signalled_flag);
1224  if (current->sps_subpic_id_mapping_explicitly_signalled_flag) {
1225  flag(sps_subpic_id_mapping_present_flag);
1226  if (current->sps_subpic_id_mapping_present_flag) {
1227  for (i = 0; i <= current->sps_num_subpics_minus1; i++) {
1228  ubs(current->sps_subpic_id_len_minus1 + 1,
1229  sps_subpic_id[i], 1, i);
1230  }
1231  }
1232  }
1233  } else {
1234  infer(sps_subpic_ctu_top_left_x[0], 0);
1235  infer(sps_subpic_ctu_top_left_y[0], 0);
1236  infer(sps_subpic_width_minus1[0], tmp_width_val - 1);
1237  infer(sps_subpic_height_minus1[0], tmp_height_val - 1);
1238  }
1239  } else {
1240  infer(sps_num_subpics_minus1, 0);
1241  infer(sps_independent_subpics_flag, 1);
1242  infer(sps_subpic_same_size_flag, 0);
1243  infer(sps_subpic_id_mapping_explicitly_signalled_flag, 0);
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], tmp_width_val - 1);
1247  infer(sps_subpic_height_minus1[0], tmp_height_val - 1);
1248  }
1249 
1250 
1251  ue(sps_bitdepth_minus8, 0, 8);
1252  qp_bd_offset = 6 * current->sps_bitdepth_minus8;
1253 
1254  flag(sps_entropy_coding_sync_enabled_flag);
1255  flag(sps_entry_point_offsets_present_flag);
1256 
1257  u(4, sps_log2_max_pic_order_cnt_lsb_minus4, 0, 12);
1258  flag(sps_poc_msb_cycle_flag);
1259  if (current->sps_poc_msb_cycle_flag)
1260  ue(sps_poc_msb_cycle_len_minus1,
1261  0, 32 - current->sps_log2_max_pic_order_cnt_lsb_minus4 - 5);
1262 
1263  u(2, sps_num_extra_ph_bytes, 0, 2);
1264  for (i = 0; i < (current->sps_num_extra_ph_bytes * 8); i++) {
1265  flags(sps_extra_ph_bit_present_flag[i], 1, i);
1266  }
1267 
1268  u(2, sps_num_extra_sh_bytes, 0, 2);
1269  for (i = 0; i < (current->sps_num_extra_sh_bytes * 8); i++) {
1270  flags(sps_extra_sh_bit_present_flag[i], 1, i);
1271  }
1272 
1273  if (current->sps_ptl_dpb_hrd_params_present_flag) {
1274  if (current->sps_max_sublayers_minus1 > 0)
1275  flag(sps_sublayer_dpb_params_flag);
1276  else
1277  infer(sps_sublayer_dpb_params_flag, 0);
1278  CHECK(FUNC(dpb_parameters) (ctx, rw, &current->sps_dpb_params,
1279  current->sps_max_sublayers_minus1,
1280  current->sps_sublayer_dpb_params_flag));
1281  }
1282 
1283  ue(sps_log2_min_luma_coding_block_size_minus2,
1284  0, FFMIN(4, current->sps_log2_ctu_size_minus5 + 3));
1285  min_cb_log2_size_y =
1286  current->sps_log2_min_luma_coding_block_size_minus2 + 2;
1287 
1288  flag(sps_partition_constraints_override_enabled_flag);
1289 
1290  ue(sps_log2_diff_min_qt_min_cb_intra_slice_luma,
1291  0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1292  min_qt_log2_size_intra_y =
1293  current->sps_log2_diff_min_qt_min_cb_intra_slice_luma +
1294  min_cb_log2_size_y;
1295 
1296  ue(sps_max_mtt_hierarchy_depth_intra_slice_luma,
1297  0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1298 
1299  if (current->sps_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
1300  ue(sps_log2_diff_max_bt_min_qt_intra_slice_luma,
1301  0, ctb_log2_size_y - min_qt_log2_size_intra_y);
1302  ue(sps_log2_diff_max_tt_min_qt_intra_slice_luma,
1303  0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
1304  } else {
1305  infer(sps_log2_diff_max_bt_min_qt_intra_slice_luma, 0);
1306  infer(sps_log2_diff_max_tt_min_qt_intra_slice_luma, 0);
1307  }
1308 
1309  if (current->sps_chroma_format_idc != 0) {
1310  flag(sps_qtbtt_dual_tree_intra_flag);
1311  } else {
1312  infer(sps_qtbtt_dual_tree_intra_flag, 0);
1313  }
1314 
1315  if (current->sps_qtbtt_dual_tree_intra_flag) {
1316  ue(sps_log2_diff_min_qt_min_cb_intra_slice_chroma,
1317  0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1318  ue(sps_max_mtt_hierarchy_depth_intra_slice_chroma,
1319  0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1320  if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
1321  unsigned int min_qt_log2_size_intra_c =
1322  current->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
1323  min_cb_log2_size_y;
1324  ue(sps_log2_diff_max_bt_min_qt_intra_slice_chroma,
1325  0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1326  ue(sps_log2_diff_max_tt_min_qt_intra_slice_chroma,
1327  0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1328  }
1329  } else {
1330  infer(sps_log2_diff_min_qt_min_cb_intra_slice_chroma, 0);
1331  infer(sps_max_mtt_hierarchy_depth_intra_slice_chroma, 0);
1332  }
1333  if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma == 0) {
1334  infer(sps_log2_diff_max_bt_min_qt_intra_slice_chroma, 0);
1335  infer(sps_log2_diff_max_tt_min_qt_intra_slice_chroma, 0);
1336  }
1337 
1338  ue(sps_log2_diff_min_qt_min_cb_inter_slice,
1339  0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1340  min_qt_log2_size_inter_y =
1341  current->sps_log2_diff_min_qt_min_cb_inter_slice + min_cb_log2_size_y;
1342 
1343  ue(sps_max_mtt_hierarchy_depth_inter_slice,
1344  0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1345  if (current->sps_max_mtt_hierarchy_depth_inter_slice != 0) {
1346  ue(sps_log2_diff_max_bt_min_qt_inter_slice,
1347  0, ctb_log2_size_y - min_qt_log2_size_inter_y);
1348  ue(sps_log2_diff_max_tt_min_qt_inter_slice,
1349  0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
1350  } else {
1351  infer(sps_log2_diff_max_bt_min_qt_inter_slice, 0);
1352  infer(sps_log2_diff_max_tt_min_qt_inter_slice, 0);
1353  }
1354 
1355  if (ctb_size_y > 32)
1356  flag(sps_max_luma_transform_size_64_flag);
1357  else
1358  infer(sps_max_luma_transform_size_64_flag, 0);
1359 
1360  flag(sps_transform_skip_enabled_flag);
1361  if (current->sps_transform_skip_enabled_flag) {
1362  ue(sps_log2_transform_skip_max_size_minus2, 0, 3);
1363  flag(sps_bdpcm_enabled_flag);
1364  }
1365 
1366  flag(sps_mts_enabled_flag);
1367  if (current->sps_mts_enabled_flag) {
1368  flag(sps_explicit_mts_intra_enabled_flag);
1369  flag(sps_explicit_mts_inter_enabled_flag);
1370  } else {
1371  infer(sps_explicit_mts_intra_enabled_flag, 0);
1372  infer(sps_explicit_mts_inter_enabled_flag, 0);
1373  }
1374 
1375  flag(sps_lfnst_enabled_flag);
1376 
1377  if (current->sps_chroma_format_idc != 0) {
1378  uint8_t num_qp_tables;
1379  flag(sps_joint_cbcr_enabled_flag);
1380  flag(sps_same_qp_table_for_chroma_flag);
1381  num_qp_tables = current->sps_same_qp_table_for_chroma_flag ?
1382  1 : (current->sps_joint_cbcr_enabled_flag ? 3 : 2);
1383  for (i = 0; i < num_qp_tables; i++) {
1384  ses(sps_qp_table_start_minus26[i], -26 - qp_bd_offset, 36, 1, i);
1385  ues(sps_num_points_in_qp_table_minus1[i],
1386  0, 36 - current->sps_qp_table_start_minus26[i], 1, i);
1387  for (j = 0; j <= current->sps_num_points_in_qp_table_minus1[i]; j++) {
1388  uint8_t max = MAX_UINT_BITS(8);
1389  ues(sps_delta_qp_in_val_minus1[i][j], 0, max, 2, i, j);
1390  ues(sps_delta_qp_diff_val[i][j], 0, max, 2, i, j);
1391  }
1392  }
1393  } else {
1394  infer(sps_joint_cbcr_enabled_flag, 0);
1395  infer(sps_same_qp_table_for_chroma_flag, 0);
1396  }
1397 
1398  flag(sps_sao_enabled_flag);
1399  flag(sps_alf_enabled_flag);
1400  if (current->sps_alf_enabled_flag && current->sps_chroma_format_idc)
1401  flag(sps_ccalf_enabled_flag);
1402  else
1403  infer(sps_ccalf_enabled_flag, 0);
1404  flag(sps_lmcs_enabled_flag);
1405  flag(sps_weighted_pred_flag);
1406  flag(sps_weighted_bipred_flag);
1407  flag(sps_long_term_ref_pics_flag);
1408  if (current->sps_video_parameter_set_id > 0)
1409  flag(sps_inter_layer_prediction_enabled_flag);
1410  else
1411  infer(sps_inter_layer_prediction_enabled_flag, 0);
1412  flag(sps_idr_rpl_present_flag);
1413  flag(sps_rpl1_same_as_rpl0_flag);
1414 
1415  for (i = 0; i < (current->sps_rpl1_same_as_rpl0_flag ? 1 : 2); i++) {
1416  ues(sps_num_ref_pic_lists[i], 0, VVC_MAX_REF_PIC_LISTS, 1, i);
1417  for (j = 0; j < current->sps_num_ref_pic_lists[i]; j++)
1419  &current->
1420  sps_ref_pic_list_struct[i][j], i,
1421  j, current));
1422  }
1423 
1424  if (current->sps_rpl1_same_as_rpl0_flag) {
1425  current->sps_num_ref_pic_lists[1] = current->sps_num_ref_pic_lists[0];
1426  for (j = 0; j < current->sps_num_ref_pic_lists[0]; j++)
1427  memcpy(&current->sps_ref_pic_list_struct[1][j],
1428  &current->sps_ref_pic_list_struct[0][j],
1429  sizeof(current->sps_ref_pic_list_struct[0][j]));
1430  }
1431 
1432  flag(sps_ref_wraparound_enabled_flag);
1433 
1434  flag(sps_temporal_mvp_enabled_flag);
1435  if (current->sps_temporal_mvp_enabled_flag)
1436  flag(sps_sbtmvp_enabled_flag);
1437  else
1438  infer(sps_sbtmvp_enabled_flag, 0);
1439 
1440  flag(sps_amvr_enabled_flag);
1441  flag(sps_bdof_enabled_flag);
1442  if (current->sps_bdof_enabled_flag)
1443  flag(sps_bdof_control_present_in_ph_flag);
1444  else
1445  infer(sps_bdof_control_present_in_ph_flag, 0);
1446 
1447  flag(sps_smvd_enabled_flag);
1448  flag(sps_dmvr_enabled_flag);
1449  if (current->sps_dmvr_enabled_flag)
1450  flag(sps_dmvr_control_present_in_ph_flag);
1451  else
1452  infer(sps_dmvr_control_present_in_ph_flag, 0);
1453 
1454  flag(sps_mmvd_enabled_flag);
1455  if (current->sps_mmvd_enabled_flag)
1456  flag(sps_mmvd_fullpel_only_enabled_flag);
1457  else
1458  infer(sps_mmvd_fullpel_only_enabled_flag, 0);
1459 
1460  ue(sps_six_minus_max_num_merge_cand, 0, 5);
1461  max_num_merge_cand = 6 - current->sps_six_minus_max_num_merge_cand;
1462 
1463  flag(sps_sbt_enabled_flag);
1464 
1465  flag(sps_affine_enabled_flag);
1466  if (current->sps_affine_enabled_flag) {
1467  ue(sps_five_minus_max_num_subblock_merge_cand,
1468  0, 5 - current->sps_sbtmvp_enabled_flag);
1469  flag(sps_6param_affine_enabled_flag);
1470  if (current->sps_amvr_enabled_flag)
1471  flag(sps_affine_amvr_enabled_flag);
1472  else
1473  infer(sps_affine_amvr_enabled_flag, 0);
1474  flag(sps_affine_prof_enabled_flag);
1475  if (current->sps_affine_prof_enabled_flag)
1476  flag(sps_prof_control_present_in_ph_flag);
1477  else
1478  infer(sps_prof_control_present_in_ph_flag, 0);
1479  } else {
1480  infer(sps_6param_affine_enabled_flag, 0);
1481  infer(sps_affine_amvr_enabled_flag, 0);
1482  infer(sps_affine_prof_enabled_flag, 0);
1483  infer(sps_prof_control_present_in_ph_flag, 0);
1484  }
1485 
1486  flag(sps_bcw_enabled_flag);
1487  flag(sps_ciip_enabled_flag);
1488 
1489  if (max_num_merge_cand >= 2) {
1490  flag(sps_gpm_enabled_flag);
1491  if (current->sps_gpm_enabled_flag && max_num_merge_cand >= 3)
1492  ue(sps_max_num_merge_cand_minus_max_num_gpm_cand,
1493  0, max_num_merge_cand - 2);
1494  } else {
1495  infer(sps_gpm_enabled_flag, 0);
1496  }
1497 
1498  ue(sps_log2_parallel_merge_level_minus2, 0, ctb_log2_size_y - 2);
1499 
1500  flag(sps_isp_enabled_flag);
1501  flag(sps_mrl_enabled_flag);
1502  flag(sps_mip_enabled_flag);
1503 
1504  if (current->sps_chroma_format_idc != 0)
1505  flag(sps_cclm_enabled_flag);
1506  else
1507  infer(sps_cclm_enabled_flag, 0);
1508  if (current->sps_chroma_format_idc == 1) {
1509  flag(sps_chroma_horizontal_collocated_flag);
1510  flag(sps_chroma_vertical_collocated_flag);
1511  } else {
1512  infer(sps_chroma_horizontal_collocated_flag, 1);
1513  infer(sps_chroma_vertical_collocated_flag, 1);
1514  }
1515 
1516  flag(sps_palette_enabled_flag);
1517  if (current->sps_chroma_format_idc == 3 &&
1518  !current->sps_max_luma_transform_size_64_flag)
1519  flag(sps_act_enabled_flag);
1520  else
1521  infer(sps_act_enabled_flag, 0);
1522  if (current->sps_transform_skip_enabled_flag ||
1523  current->sps_palette_enabled_flag)
1524  ue(sps_min_qp_prime_ts, 0, 8);
1525 
1526  flag(sps_ibc_enabled_flag);
1527  if (current->sps_ibc_enabled_flag)
1528  ue(sps_six_minus_max_num_ibc_merge_cand, 0, 5);
1529 
1530  flag(sps_ladf_enabled_flag);
1531  if (current->sps_ladf_enabled_flag) {
1532  ub(2, sps_num_ladf_intervals_minus2);
1533  se(sps_ladf_lowest_interval_qp_offset, -63, 63);
1534  for (i = 0; i < current->sps_num_ladf_intervals_minus2 + 1; i++) {
1535  ses(sps_ladf_qp_offset[i], -63, 63, 1, i);
1536  ues(sps_ladf_delta_threshold_minus1[i],
1537  0, (2 << (8 + current->sps_bitdepth_minus8)) - 3, 1, i);
1538  }
1539  }
1540 
1541  flag(sps_explicit_scaling_list_enabled_flag);
1542  if (current->sps_lfnst_enabled_flag &&
1543  current->sps_explicit_scaling_list_enabled_flag)
1544  flag(sps_scaling_matrix_for_lfnst_disabled_flag);
1545 
1546  if (current->sps_act_enabled_flag &&
1547  current->sps_explicit_scaling_list_enabled_flag)
1548  flag(sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
1549  else
1550  infer(sps_scaling_matrix_for_alternative_colour_space_disabled_flag, 0);
1551  if (current->sps_scaling_matrix_for_alternative_colour_space_disabled_flag)
1552  flag(sps_scaling_matrix_designated_colour_space_flag);
1553 
1554  flag(sps_dep_quant_enabled_flag);
1555  flag(sps_sign_data_hiding_enabled_flag);
1556 
1557  flag(sps_virtual_boundaries_enabled_flag);
1558  if (current->sps_virtual_boundaries_enabled_flag) {
1559  flag(sps_virtual_boundaries_present_flag);
1560  if (current->sps_virtual_boundaries_present_flag) {
1561  ue(sps_num_ver_virtual_boundaries,
1562  0, current->sps_pic_width_max_in_luma_samples <= 8 ? 0 : 3);
1563  for (i = 0; i < current->sps_num_ver_virtual_boundaries; i++)
1564  ues(sps_virtual_boundary_pos_x_minus1[i],
1565  0, (current->sps_pic_width_max_in_luma_samples + 7) / 8 - 2,
1566  1, i);
1567  ue(sps_num_hor_virtual_boundaries,
1568  0, current->sps_pic_height_max_in_luma_samples <= 8 ? 0 : 3);
1569  for (i = 0; i < current->sps_num_hor_virtual_boundaries; i++)
1570  ues(sps_virtual_boundary_pos_y_minus1[i],
1571  0, (current->sps_pic_height_max_in_luma_samples + 7) /
1572  8 - 2, 1, i);
1573  }
1574  } else {
1575  infer(sps_virtual_boundaries_present_flag, 0);
1576  infer(sps_num_ver_virtual_boundaries, 0);
1577  infer(sps_num_hor_virtual_boundaries, 0);
1578  }
1579 
1580  if (current->sps_ptl_dpb_hrd_params_present_flag) {
1581  flag(sps_timing_hrd_params_present_flag);
1582  if (current->sps_timing_hrd_params_present_flag) {
1583  uint8_t first_sublayer;
1585  &current->sps_general_timing_hrd_parameters));
1586  if (current->sps_max_sublayers_minus1 > 0)
1587  flag(sps_sublayer_cpb_params_present_flag);
1588  else
1589  infer(sps_sublayer_cpb_params_present_flag, 0);
1590  first_sublayer = current->sps_sublayer_cpb_params_present_flag ?
1591  0 : current->sps_max_sublayers_minus1;
1593  &current->sps_ols_timing_hrd_parameters, first_sublayer,
1594  current->sps_max_sublayers_minus1,
1595  &current->sps_general_timing_hrd_parameters));
1596  }
1597  }
1598 
1599  flag(sps_field_seq_flag);
1600  flag(sps_vui_parameters_present_flag);
1601  if (current->sps_vui_parameters_present_flag) {
1602  ue(sps_vui_payload_size_minus1, 0, 1023);
1603  while (byte_alignment(rw) != 0)
1604  fixed(1, sps_vui_alignment_zero_bit, 0);
1605  CHECK(FUNC(vui_payload) (ctx, rw, &current->vui,
1606  current->sps_vui_payload_size_minus1 + 1,
1607  current->sps_chroma_format_idc));
1608  } else {
1609  CHECK(FUNC(vui_parameters_default) (ctx, rw, &current->vui));
1610  }
1611 
1612  flag(sps_extension_flag);
1613  if (current->sps_extension_flag) {
1614  flag(sps_range_extension_flag);
1615  ub(7, sps_extension_7bits);
1616 
1617  if (current->sps_range_extension_flag) {
1618  CHECK(FUNC(sps_range_extension)(ctx, rw, current));
1619  } else {
1620  infer(sps_extended_precision_flag, 0);
1621  infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1622  infer(sps_rrc_rice_extension_flag, 0);
1623  infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1624  infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1625  }
1626  } else {
1627  infer(sps_range_extension_flag, 0);
1628  infer(sps_extension_7bits, 0);
1629  infer(sps_extended_precision_flag, 0);
1630  infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1631  infer(sps_rrc_rice_extension_flag, 0);
1632  infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1633  infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1634  }
1635 
1636  if (current->sps_extension_7bits)
1637  CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1638 
1639  CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
1640 
1641  return 0;
1642 }
1643 
1645  H266RawPPS *current)
1646 {
1648  const H266RawSPS *sps;
1649  int err, i;
1650  unsigned int min_cb_size_y, divisor, ctb_size_y,
1651  pic_width_in_ctbs_y, pic_height_in_ctbs_y;
1652  uint8_t sub_width_c, sub_height_c, qp_bd_offset;
1653 
1654  static const uint8_t h266_sub_width_c[] = {
1655  1, 2, 2, 1
1656  };
1657  static const uint8_t h266_sub_height_c[] = {
1658  1, 2, 1, 1
1659  };
1660 
1661  HEADER("Picture Parameter Set");
1662 
1663  CHECK(FUNC(nal_unit_header) (ctx, rw,
1664  &current->nal_unit_header, VVC_PPS_NUT));
1665 
1666  ub(6, pps_pic_parameter_set_id);
1667  ub(4, pps_seq_parameter_set_id);
1668  sps = h266->sps[current->pps_seq_parameter_set_id];
1669  if (!sps) {
1670  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1671  current->pps_seq_parameter_set_id);
1672  return AVERROR_INVALIDDATA;
1673  }
1674 
1675  flag(pps_mixed_nalu_types_in_pic_flag);
1676  ue(pps_pic_width_in_luma_samples,
1677  1, sps->sps_pic_width_max_in_luma_samples);
1678  ue(pps_pic_height_in_luma_samples,
1679  1, sps->sps_pic_height_max_in_luma_samples);
1680 
1681  min_cb_size_y = 1 << (sps->sps_log2_min_luma_coding_block_size_minus2 + 2);
1682  divisor = FFMAX(min_cb_size_y, 8);
1683  if (current->pps_pic_width_in_luma_samples % divisor ||
1684  current->pps_pic_height_in_luma_samples % divisor) {
1685  av_log(ctx->log_ctx, AV_LOG_ERROR,
1686  "Invalid dimensions: %ux%u not divisible "
1687  "by %u, MinCbSizeY = %u.\n",
1688  current->pps_pic_width_in_luma_samples,
1689  current->pps_pic_height_in_luma_samples, divisor, min_cb_size_y);
1690  return AVERROR_INVALIDDATA;
1691  }
1692  if (!sps->sps_res_change_in_clvs_allowed_flag &&
1693  (current->pps_pic_width_in_luma_samples !=
1694  sps->sps_pic_width_max_in_luma_samples ||
1695  current->pps_pic_height_in_luma_samples !=
1696  sps->sps_pic_height_max_in_luma_samples)) {
1697  av_log(ctx->log_ctx, AV_LOG_ERROR,
1698  "Resoltuion change is not allowed, "
1699  "in max resolution (%ux%u) mismatched with pps(%ux%u).\n",
1700  sps->sps_pic_width_max_in_luma_samples,
1701  sps->sps_pic_height_max_in_luma_samples,
1702  current->pps_pic_width_in_luma_samples,
1703  current->pps_pic_height_in_luma_samples);
1704  return AVERROR_INVALIDDATA;
1705  }
1706 
1707  ctb_size_y = 1 << (sps->sps_log2_ctu_size_minus5 + 5);
1708  if (sps->sps_ref_wraparound_enabled_flag) {
1709  if ((ctb_size_y / min_cb_size_y + 1) >
1710  (current->pps_pic_width_in_luma_samples / min_cb_size_y - 1)) {
1711  av_log(ctx->log_ctx, AV_LOG_ERROR,
1712  "Invalid width(%u), ctb_size_y = %u, min_cb_size_y = %u.\n",
1713  current->pps_pic_width_in_luma_samples,
1714  ctb_size_y, min_cb_size_y);
1715  return AVERROR_INVALIDDATA;
1716  }
1717  }
1718 
1719  flag(pps_conformance_window_flag);
1720  if (current->pps_pic_width_in_luma_samples ==
1721  sps->sps_pic_width_max_in_luma_samples &&
1722  current->pps_pic_height_in_luma_samples ==
1723  sps->sps_pic_height_max_in_luma_samples &&
1724  current->pps_conformance_window_flag) {
1725  av_log(ctx->log_ctx, AV_LOG_ERROR,
1726  "Conformance window flag should not true.\n");
1727  return AVERROR_INVALIDDATA;
1728  }
1729 
1730  sub_width_c = h266_sub_width_c[sps->sps_chroma_format_idc];
1731  sub_height_c = h266_sub_height_c[sps->sps_chroma_format_idc];
1732  if (current->pps_conformance_window_flag) {
1733  ue(pps_conf_win_left_offset, 0, current->pps_pic_width_in_luma_samples);
1734  ue(pps_conf_win_right_offset,
1735  0, current->pps_pic_width_in_luma_samples);
1736  ue(pps_conf_win_top_offset, 0, current->pps_pic_height_in_luma_samples);
1737  ue(pps_conf_win_bottom_offset,
1738  0, current->pps_pic_height_in_luma_samples);
1739  if (sub_width_c *
1740  (current->pps_conf_win_left_offset +
1741  current->pps_conf_win_right_offset) >=
1742  current->pps_pic_width_in_luma_samples ||
1743  sub_height_c *
1744  (current->pps_conf_win_top_offset +
1745  current->pps_conf_win_bottom_offset) >=
1746  current->pps_pic_height_in_luma_samples) {
1747  av_log(ctx->log_ctx, AV_LOG_ERROR,
1748  "Invalid pps conformance window: (%u, %u, %u, %u), "
1749  "resolution is %ux%u, sub wxh is %ux%u.\n",
1750  current->pps_conf_win_left_offset,
1751  current->pps_conf_win_right_offset,
1752  current->pps_conf_win_top_offset,
1753  current->pps_conf_win_bottom_offset,
1754  current->pps_pic_width_in_luma_samples,
1755  current->pps_pic_height_in_luma_samples,
1756  sub_width_c, sub_height_c);
1757  return AVERROR_INVALIDDATA;
1758  }
1759  } else {
1760  if (current->pps_pic_width_in_luma_samples ==
1761  sps->sps_pic_width_max_in_luma_samples &&
1762  current->pps_pic_height_in_luma_samples ==
1763  sps->sps_pic_height_max_in_luma_samples) {
1764  infer(pps_conf_win_left_offset, sps->sps_conf_win_left_offset);
1765  infer(pps_conf_win_right_offset, sps->sps_conf_win_right_offset);
1766  infer(pps_conf_win_top_offset, sps->sps_conf_win_top_offset);
1767  infer(pps_conf_win_bottom_offset, sps->sps_conf_win_bottom_offset);
1768  } else {
1769  infer(pps_conf_win_left_offset, 0);
1770  infer(pps_conf_win_right_offset, 0);
1771  infer(pps_conf_win_top_offset, 0);
1772  infer(pps_conf_win_bottom_offset, 0);
1773  }
1774 
1775  }
1776 
1777  flag(pps_scaling_window_explicit_signalling_flag);
1778  if (!sps->sps_ref_pic_resampling_enabled_flag &&
1779  current->pps_scaling_window_explicit_signalling_flag) {
1780  av_log(ctx->log_ctx, AV_LOG_ERROR,
1781  "Invalid data: sps_ref_pic_resampling_enabled_flag is false, "
1782  "but pps_scaling_window_explicit_signalling_flag is true.\n");
1783  return AVERROR_INVALIDDATA;
1784  }
1785  if (current->pps_scaling_window_explicit_signalling_flag) {
1786  se(pps_scaling_win_left_offset,
1787  -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1788  current->pps_pic_width_in_luma_samples / sub_width_c);
1789  se(pps_scaling_win_right_offset,
1790  -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1791  current->pps_pic_width_in_luma_samples / sub_width_c);
1792  se(pps_scaling_win_top_offset,
1793  -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1794  current->pps_pic_height_in_luma_samples / sub_height_c);
1795  se(pps_scaling_win_bottom_offset,
1796  -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1797  current->pps_pic_height_in_luma_samples / sub_height_c);
1798  } else {
1799  infer(pps_scaling_win_left_offset, current->pps_conf_win_left_offset);
1800  infer(pps_scaling_win_right_offset, current->pps_conf_win_right_offset);
1801  infer(pps_scaling_win_top_offset, current->pps_conf_win_top_offset);
1802  infer(pps_scaling_win_bottom_offset, current->pps_conf_win_bottom_offset);
1803  }
1804 
1805  flag(pps_output_flag_present_flag);
1806  flag(pps_no_pic_partition_flag);
1807  flag(pps_subpic_id_mapping_present_flag);
1808 
1809  if (current->pps_subpic_id_mapping_present_flag) {
1810  if (!current->pps_no_pic_partition_flag) {
1811  ue(pps_num_subpics_minus1,
1812  sps->sps_num_subpics_minus1, sps->sps_num_subpics_minus1);
1813  } else {
1814  infer(pps_num_subpics_minus1, 0);
1815  }
1816  ue(pps_subpic_id_len_minus1, sps->sps_subpic_id_len_minus1,
1817  sps->sps_subpic_id_len_minus1);
1818  for (i = 0; i <= current->pps_num_subpics_minus1; i++) {
1819  ubs(sps->sps_subpic_id_len_minus1 + 1, pps_subpic_id[i], 1, i);
1820  }
1821  }
1822 
1823  for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
1824  if (sps->sps_subpic_id_mapping_explicitly_signalled_flag)
1825  current->sub_pic_id_val[i] = current->pps_subpic_id_mapping_present_flag
1826  ? current->pps_subpic_id[i]
1827  : sps->sps_subpic_id[i];
1828  else
1829  current->sub_pic_id_val[i] = i;
1830  }
1831 
1832  pic_width_in_ctbs_y = AV_CEIL_RSHIFT
1833  (current->pps_pic_width_in_luma_samples, (sps->sps_log2_ctu_size_minus5 + 5));
1834  pic_height_in_ctbs_y = AV_CEIL_RSHIFT(
1835  current->pps_pic_height_in_luma_samples,(sps->sps_log2_ctu_size_minus5 + 5));
1836  if (!current->pps_no_pic_partition_flag) {
1837  unsigned int exp_tile_width = 0, exp_tile_height = 0;
1838  unsigned int unified_size, remaining_size;
1839 
1840  u(2, pps_log2_ctu_size_minus5,
1841  sps->sps_log2_ctu_size_minus5, sps->sps_log2_ctu_size_minus5);
1842  ue(pps_num_exp_tile_columns_minus1,
1843  0, FFMIN(pic_width_in_ctbs_y - 1, VVC_MAX_TILE_COLUMNS - 1));
1844  ue(pps_num_exp_tile_rows_minus1,
1845  0, FFMIN(pic_height_in_ctbs_y - 1, VVC_MAX_TILE_ROWS - 1));
1846 
1847  for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1848  ues(pps_tile_column_width_minus1[i],
1849  0, pic_width_in_ctbs_y - exp_tile_width - 1, 1, i);
1850  exp_tile_width += current->pps_tile_column_width_minus1[i] + 1;
1851  }
1852  for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1853  ues(pps_tile_row_height_minus1[i],
1854  0, pic_height_in_ctbs_y - exp_tile_height - 1, 1, i);
1855  exp_tile_height += current->pps_tile_row_height_minus1[i] + 1;
1856  }
1857 
1858  remaining_size = pic_width_in_ctbs_y;
1859  for (i = 0; i <= current->pps_num_exp_tile_columns_minus1; i++) {
1860  if (current->pps_tile_column_width_minus1[i] >= remaining_size) {
1861  av_log(ctx->log_ctx, AV_LOG_ERROR,
1862  "Tile column width(%d) exceeds picture width\n",i);
1863  return AVERROR_INVALIDDATA;
1864  }
1865  current->col_width_val[i] = current->pps_tile_column_width_minus1[i] + 1;
1866  remaining_size -= (current->pps_tile_column_width_minus1[i] + 1);
1867  }
1868  unified_size = current->pps_tile_column_width_minus1[i - 1] + 1;
1869  while (remaining_size > 0) {
1870  if (current->num_tile_columns > VVC_MAX_TILE_COLUMNS) {
1871  av_log(ctx->log_ctx, AV_LOG_ERROR,
1872  "NumTileColumns(%d) > than VVC_MAX_TILE_COLUMNS(%d)\n",
1873  current->num_tile_columns, VVC_MAX_TILE_COLUMNS);
1874  return AVERROR_INVALIDDATA;
1875  }
1876  unified_size = FFMIN(remaining_size, unified_size);
1877  current->col_width_val[i] = unified_size;
1878  remaining_size -= unified_size;
1879  i++;
1880  }
1881  current->num_tile_columns = i;
1882  if (current->num_tile_columns > VVC_MAX_TILE_COLUMNS) {
1883  av_log(ctx->log_ctx, AV_LOG_ERROR,
1884  "NumTileColumns(%d) > than VVC_MAX_TILE_COLUMNS(%d)\n",
1885  current->num_tile_columns, VVC_MAX_TILE_COLUMNS);
1886  return AVERROR_INVALIDDATA;
1887  }
1888 
1889  remaining_size = pic_height_in_ctbs_y;
1890  for (i = 0; i <= current->pps_num_exp_tile_rows_minus1; i++) {
1891  if (current->pps_tile_row_height_minus1[i] >= remaining_size) {
1892  av_log(ctx->log_ctx, AV_LOG_ERROR,
1893  "Tile row height(%d) exceeds picture height\n",i);
1894  return AVERROR_INVALIDDATA;
1895  }
1896  current->row_height_val[i] = current->pps_tile_row_height_minus1[i] + 1;
1897  remaining_size -= (current->pps_tile_row_height_minus1[i] + 1);
1898  }
1899  unified_size = current->pps_tile_row_height_minus1[i - 1] + 1;
1900 
1901  while (remaining_size > 0) {
1902  unified_size = FFMIN(remaining_size, unified_size);
1903  current->row_height_val[i] = unified_size;
1904  remaining_size -= unified_size;
1905  i++;
1906  }
1907  current->num_tile_rows=i;
1908  if (current->num_tile_rows > VVC_MAX_TILE_ROWS) {
1909  av_log(ctx->log_ctx, AV_LOG_ERROR,
1910  "NumTileRows(%d) > than VVC_MAX_TILE_ROWS(%d)\n",
1911  current->num_tile_rows, VVC_MAX_TILE_ROWS);
1912  return AVERROR_INVALIDDATA;
1913  }
1914 
1915  current->num_tiles_in_pic = current->num_tile_columns *
1916  current->num_tile_rows;
1917  if (current->num_tiles_in_pic > VVC_MAX_TILES_PER_AU) {
1918  av_log(ctx->log_ctx, AV_LOG_ERROR,
1919  "NumTilesInPic(%d) > than VVC_MAX_TILES_PER_AU(%d)\n",
1920  current->num_tiles_in_pic, VVC_MAX_TILES_PER_AU);
1921  return AVERROR_INVALIDDATA;
1922  }
1923 
1924  if (current->num_tiles_in_pic > 1) {
1925  flag(pps_loop_filter_across_tiles_enabled_flag);
1926  flag(pps_rect_slice_flag);
1927  } else {
1928  infer(pps_loop_filter_across_tiles_enabled_flag, 0);
1929  infer(pps_rect_slice_flag, 1);
1930  }
1931  if (current->pps_rect_slice_flag)
1932  flag(pps_single_slice_per_subpic_flag);
1933  else
1934  infer(pps_single_slice_per_subpic_flag, 1);
1935  if (current->pps_rect_slice_flag &&
1936  !current->pps_single_slice_per_subpic_flag) {
1937  int j;
1938  uint16_t tile_idx = 0, tile_x, tile_y, ctu_x, ctu_y;
1939  uint16_t slice_top_left_ctu_x[VVC_MAX_SLICES];
1940  uint16_t slice_top_left_ctu_y[VVC_MAX_SLICES];
1941  ue(pps_num_slices_in_pic_minus1, 0, VVC_MAX_SLICES - 1);
1942  if (current->pps_num_slices_in_pic_minus1 > 1)
1943  flag(pps_tile_idx_delta_present_flag);
1944  else
1945  infer(pps_tile_idx_delta_present_flag, 0);
1946  for (i = 0; i < current->pps_num_slices_in_pic_minus1; i++) {
1947  tile_x = tile_idx % current->num_tile_columns;
1948  tile_y = tile_idx / current->num_tile_columns;
1949  if (tile_x != current->num_tile_columns - 1) {
1950  ues(pps_slice_width_in_tiles_minus1[i],
1951  0, current->num_tile_columns - 1, 1, i);
1952  } else {
1953  infer(pps_slice_width_in_tiles_minus1[i], 0);
1954  }
1955  if (tile_y != current->num_tile_rows - 1 &&
1956  (current->pps_tile_idx_delta_present_flag || tile_x == 0)) {
1957  ues(pps_slice_height_in_tiles_minus1[i],
1958  0, current->num_tile_rows - 1, 1, i);
1959  } else {
1960  if (tile_y == current->num_tile_rows - 1)
1961  infer(pps_slice_height_in_tiles_minus1[i], 0);
1962  else
1963  infer(pps_slice_height_in_tiles_minus1[i],
1964  current->pps_slice_height_in_tiles_minus1[i - 1]);
1965  }
1966 
1967  ctu_x = ctu_y = 0;
1968  for (j = 0; j < tile_x; j++) {
1969  ctu_x += current->col_width_val[j];
1970  }
1971  for (j = 0; j < tile_y; j++) {
1972  ctu_y += current->row_height_val[j];
1973  }
1974  if (current->pps_slice_width_in_tiles_minus1[i] == 0 &&
1975  current->pps_slice_height_in_tiles_minus1[i] == 0 &&
1976  current->row_height_val[tile_y] > 1) {
1977  int num_slices_in_tile,
1978  uniform_slice_height, remaining_height_in_ctbs_y;
1979  remaining_height_in_ctbs_y =
1980  current->row_height_val[tile_y];
1981  ues(pps_num_exp_slices_in_tile[i],
1982  0, current->row_height_val[tile_y] - 1, 1, i);
1983  if (current->pps_num_exp_slices_in_tile[i] == 0) {
1984  num_slices_in_tile = 1;
1985  current->slice_height_in_ctus[i] = current->row_height_val[tile_y];
1986  slice_top_left_ctu_x[i] = ctu_x;
1987  slice_top_left_ctu_y[i] = ctu_y;
1988  } else {
1989  uint16_t slice_height_in_ctus;
1990  for (j = 0; j < current->pps_num_exp_slices_in_tile[i];
1991  j++) {
1992  ues(pps_exp_slice_height_in_ctus_minus1[i][j], 0,
1993  current->row_height_val[tile_y] - 1, 2,
1994  i, j);
1995  slice_height_in_ctus =
1996  current->
1997  pps_exp_slice_height_in_ctus_minus1[i][j] + 1;
1998 
1999  current->slice_height_in_ctus[i + j] =
2000  slice_height_in_ctus;
2001  slice_top_left_ctu_x[i + j] = ctu_x;
2002  slice_top_left_ctu_y[i + j] = ctu_y;
2003  ctu_y += slice_height_in_ctus;
2004 
2005  remaining_height_in_ctbs_y -= slice_height_in_ctus;
2006  }
2007  uniform_slice_height = 1 +
2008  (j == 0 ? current->row_height_val[tile_y] - 1:
2009  current->pps_exp_slice_height_in_ctus_minus1[i][j-1]);
2010  while (remaining_height_in_ctbs_y > uniform_slice_height) {
2011  current->slice_height_in_ctus[i + j] =
2012  uniform_slice_height;
2013  slice_top_left_ctu_x[i + j] = ctu_x;
2014  slice_top_left_ctu_y[i + j] = ctu_y;
2015  ctu_y += uniform_slice_height;
2016 
2017  remaining_height_in_ctbs_y -= uniform_slice_height;
2018  j++;
2019  }
2020  if (remaining_height_in_ctbs_y > 0) {
2021  current->slice_height_in_ctus[i + j] =
2022  remaining_height_in_ctbs_y;
2023  slice_top_left_ctu_x[i + j] = ctu_x;
2024  slice_top_left_ctu_y[i + j] = ctu_y;
2025  j++;
2026  }
2027  num_slices_in_tile = j;
2028  }
2029  i += num_slices_in_tile - 1;
2030  } else {
2031  uint16_t height = 0;
2032  infer(pps_num_exp_slices_in_tile[i], 0);
2033  for (j = 0;
2034  j <= current->pps_slice_height_in_tiles_minus1[i];
2035  j++) {
2036  height +=
2037  current->row_height_val[tile_y + j];
2038  }
2039  current->slice_height_in_ctus[i] = height;
2040 
2041  slice_top_left_ctu_x[i] = ctu_x;
2042  slice_top_left_ctu_y[i] = ctu_y;
2043  }
2044  if (i < current->pps_num_slices_in_pic_minus1) {
2045  if (current->pps_tile_idx_delta_present_flag) {
2046  ses(pps_tile_idx_delta_val[i],
2047  -current->num_tiles_in_pic + 1,
2048  current->num_tiles_in_pic - 1, 1, i);
2049  if (current->pps_tile_idx_delta_val[i] == 0) {
2050  av_log(ctx->log_ctx, AV_LOG_ERROR,
2051  "pps_tile_idx_delta_val[i] shall not be equal to 0.\n");
2052  }
2053  tile_idx += current->pps_tile_idx_delta_val[i];
2054  } else {
2055  infer(pps_tile_idx_delta_val[i], 0);
2056  tile_idx +=
2057  current->pps_slice_width_in_tiles_minus1[i] + 1;
2058  if (tile_idx % current->num_tile_columns == 0) {
2059  tile_idx +=
2060  current->pps_slice_height_in_tiles_minus1[i] *
2061  current->num_tile_columns;
2062  }
2063  }
2064  }
2065  }
2066  if (i == current->pps_num_slices_in_pic_minus1) {
2067  uint16_t height = 0;
2068 
2069  tile_x = tile_idx % current->num_tile_columns;
2070  tile_y = tile_idx / current->num_tile_columns;
2071 
2072  ctu_x = 0, ctu_y = 0;
2073  for (j = 0; j < tile_x; j++) {
2074  ctu_x += current->col_width_val[j];
2075  }
2076  for (j = 0; j < tile_y; j++) {
2077  ctu_y += current->row_height_val[j];
2078  }
2079  slice_top_left_ctu_x[i] = ctu_x;
2080  slice_top_left_ctu_y[i] = ctu_y;
2081 
2082  current->pps_slice_width_in_tiles_minus1[i] =
2083  current->num_tile_columns - tile_x - 1;
2084  current->pps_slice_height_in_tiles_minus1[i] =
2085  current->num_tile_rows - tile_y - 1;
2086 
2087  for (j = 0; j <= current->pps_slice_height_in_tiles_minus1[i];
2088  j++) {
2089  height +=
2090  current->row_height_val[tile_y + j];
2091  }
2092  current->slice_height_in_ctus[i] = height;
2093 
2094  infer(pps_num_exp_slices_in_tile[i], 0);
2095  }
2096  //now, we got all slice information, let's resolve NumSlicesInSubpic
2097  for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
2098  current->num_slices_in_subpic[i] = 0;
2099  for (j = 0; j <= current->pps_num_slices_in_pic_minus1; j++) {
2100  uint16_t pos_x = 0, pos_y = 0;
2101  pos_x = slice_top_left_ctu_x[j];
2102  pos_y = slice_top_left_ctu_y[j];
2103  if ((pos_x >= sps->sps_subpic_ctu_top_left_x[i]) &&
2104  (pos_x <
2105  sps->sps_subpic_ctu_top_left_x[i] +
2106  sps->sps_subpic_width_minus1[i] + 1) &&
2107  (pos_y >= sps->sps_subpic_ctu_top_left_y[i]) &&
2108  (pos_y < sps->sps_subpic_ctu_top_left_y[i] +
2109  sps->sps_subpic_height_minus1[i] + 1)) {
2110  current->num_slices_in_subpic[i]++;
2111  }
2112  }
2113  }
2114  } else {
2115  if (current->pps_no_pic_partition_flag)
2116  infer(pps_num_slices_in_pic_minus1, 0);
2117  else if (current->pps_single_slice_per_subpic_flag)
2118  infer(pps_num_slices_in_pic_minus1,
2119  sps->sps_num_subpics_minus1);
2120  // else?
2121  }
2122  if (!current->pps_rect_slice_flag ||
2123  current->pps_single_slice_per_subpic_flag ||
2124  current->pps_num_slices_in_pic_minus1 > 0)
2125  flag(pps_loop_filter_across_slices_enabled_flag);
2126  else
2127  infer(pps_loop_filter_across_slices_enabled_flag, 0);
2128  } else {
2129  infer(pps_num_exp_tile_columns_minus1, 0);
2130  infer(pps_tile_column_width_minus1[0], pic_width_in_ctbs_y - 1);
2131  infer(pps_num_exp_tile_rows_minus1, 0);
2132  infer(pps_tile_row_height_minus1[0], pic_height_in_ctbs_y - 1);
2133  current->col_width_val[0] = pic_width_in_ctbs_y;
2134  current->row_height_val[0] = pic_height_in_ctbs_y;
2135  current->num_tile_columns = 1;
2136  current->num_tile_rows = 1;
2137  current->num_tiles_in_pic = 1;
2138  }
2139 
2140  flag(pps_cabac_init_present_flag);
2141  for (i = 0; i < 2; i++)
2142  ues(pps_num_ref_idx_default_active_minus1[i], 0, 14, 1, i);
2143  flag(pps_rpl1_idx_present_flag);
2144  flag(pps_weighted_pred_flag);
2145  flag(pps_weighted_bipred_flag);
2146  flag(pps_ref_wraparound_enabled_flag);
2147  if (current->pps_ref_wraparound_enabled_flag) {
2148  ue(pps_pic_width_minus_wraparound_offset,
2149  0, (current->pps_pic_width_in_luma_samples / min_cb_size_y)
2150  - (ctb_size_y / min_cb_size_y) - 2);
2151  }
2152 
2153  qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2154  se(pps_init_qp_minus26, -(26 + qp_bd_offset), 37);
2155  flag(pps_cu_qp_delta_enabled_flag);
2156  flag(pps_chroma_tool_offsets_present_flag);
2157  if (current->pps_chroma_tool_offsets_present_flag) {
2158  se(pps_cb_qp_offset, -12, 12);
2159  se(pps_cr_qp_offset, -12, 12);
2160  flag(pps_joint_cbcr_qp_offset_present_flag);
2161  if (current->pps_joint_cbcr_qp_offset_present_flag)
2162  se(pps_joint_cbcr_qp_offset_value, -12, 12);
2163  else
2164  infer(pps_joint_cbcr_qp_offset_value, 0);
2165  flag(pps_slice_chroma_qp_offsets_present_flag);
2166  flag(pps_cu_chroma_qp_offset_list_enabled_flag);
2167  if (current->pps_cu_chroma_qp_offset_list_enabled_flag) {
2168  ue(pps_chroma_qp_offset_list_len_minus1, 0, 5);
2169  for (i = 0; i <= current->pps_chroma_qp_offset_list_len_minus1; i++) {
2170  ses(pps_cb_qp_offset_list[i], -12, 12, 1, i);
2171  ses(pps_cr_qp_offset_list[i], -12, 12, 1, i);
2172  if (current->pps_joint_cbcr_qp_offset_present_flag)
2173  ses(pps_joint_cbcr_qp_offset_list[i], -12, 12, 1, i);
2174  else
2175  infer(pps_joint_cbcr_qp_offset_list[i], 0);
2176  }
2177  }
2178  } else {
2179  infer(pps_cb_qp_offset, 0);
2180  infer(pps_cr_qp_offset, 0);
2181  infer(pps_joint_cbcr_qp_offset_present_flag, 0);
2182  infer(pps_joint_cbcr_qp_offset_value, 0);
2183  infer(pps_slice_chroma_qp_offsets_present_flag, 0);
2184  infer(pps_cu_chroma_qp_offset_list_enabled_flag, 0);
2185  }
2186  flag(pps_deblocking_filter_control_present_flag);
2187  if (current->pps_deblocking_filter_control_present_flag) {
2188  flag(pps_deblocking_filter_override_enabled_flag);
2189  flag(pps_deblocking_filter_disabled_flag);
2190  if (!current->pps_no_pic_partition_flag &&
2191  current->pps_deblocking_filter_override_enabled_flag)
2192  flag(pps_dbf_info_in_ph_flag);
2193  else
2194  infer(pps_dbf_info_in_ph_flag, 0);
2195  if (!current->pps_deblocking_filter_disabled_flag) {
2196  se(pps_luma_beta_offset_div2, -12, 12);
2197  se(pps_luma_tc_offset_div2, -12, 12);
2198  if (current->pps_chroma_tool_offsets_present_flag) {
2199  se(pps_cb_beta_offset_div2, -12, 12);
2200  se(pps_cb_tc_offset_div2, -12, 12);
2201  se(pps_cr_beta_offset_div2, -12, 12);
2202  se(pps_cr_tc_offset_div2, -12, 12);
2203  } else {
2204  infer(pps_cb_beta_offset_div2,
2205  current->pps_luma_beta_offset_div2);
2206  infer(pps_cb_tc_offset_div2, current->pps_luma_tc_offset_div2);
2207  infer(pps_cr_beta_offset_div2,
2208  current->pps_luma_beta_offset_div2);
2209  infer(pps_cr_tc_offset_div2, current->pps_luma_tc_offset_div2);
2210  }
2211  } else {
2212  infer(pps_luma_beta_offset_div2, 0);
2213  infer(pps_luma_tc_offset_div2, 0);
2214  infer(pps_cb_beta_offset_div2, 0);
2215  infer(pps_cb_tc_offset_div2, 0);
2216  infer(pps_cr_beta_offset_div2, 0);
2217  infer(pps_cr_tc_offset_div2, 0);
2218  }
2219  } else {
2220  infer(pps_deblocking_filter_override_enabled_flag, 0);
2221  infer(pps_deblocking_filter_disabled_flag, 0);
2222  infer(pps_dbf_info_in_ph_flag, 0);
2223  infer(pps_luma_beta_offset_div2, 0);
2224  infer(pps_luma_tc_offset_div2, 0);
2225  infer(pps_cb_beta_offset_div2, 0);
2226  infer(pps_cb_tc_offset_div2, 0);
2227  infer(pps_cr_beta_offset_div2, 0);
2228  infer(pps_cr_tc_offset_div2, 0);
2229  }
2230 
2231  if (!current->pps_no_pic_partition_flag) {
2232  flag(pps_rpl_info_in_ph_flag);
2233  flag(pps_sao_info_in_ph_flag);
2234  flag(pps_alf_info_in_ph_flag);
2235  if ((current->pps_weighted_pred_flag ||
2236  current->pps_weighted_bipred_flag) &&
2237  current->pps_rpl_info_in_ph_flag)
2238  flag(pps_wp_info_in_ph_flag);
2239  flag(pps_qp_delta_info_in_ph_flag);
2240  }
2241  flag(pps_picture_header_extension_present_flag);
2242  flag(pps_slice_header_extension_present_flag);
2243 
2244  flag(pps_extension_flag);
2245  if (current->pps_extension_flag)
2246  CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2247 
2248  CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2249  return 0;
2250 }
2251 
2253  H266RawAPS *current)
2254 {
2255  int err, j, k;
2256 
2257  flag(alf_luma_filter_signal_flag);
2258 
2259  if (current->aps_chroma_present_flag) {
2260  flag(alf_chroma_filter_signal_flag);
2261  flag(alf_cc_cb_filter_signal_flag);
2262  flag(alf_cc_cr_filter_signal_flag);
2263  } else {
2264  infer(alf_chroma_filter_signal_flag, 0);
2265  infer(alf_cc_cb_filter_signal_flag, 0);
2266  infer(alf_cc_cr_filter_signal_flag, 0);
2267  }
2268 
2269  if (current->alf_luma_filter_signal_flag) {
2270  flag(alf_luma_clip_flag);
2271  ue(alf_luma_num_filters_signalled_minus1, 0, VVC_NUM_ALF_FILTERS - 1);
2272  if (current->alf_luma_num_filters_signalled_minus1 > 0) {
2273  unsigned int bits = av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
2274  for (int filt_idx = 0; filt_idx < VVC_NUM_ALF_FILTERS; filt_idx++)
2275  us(bits, alf_luma_coeff_delta_idx[filt_idx],
2276  0, current->alf_luma_num_filters_signalled_minus1,
2277  1, filt_idx);
2278  }
2279  for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
2280  for (j = 0; j < 12; j++) {
2281  ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
2282  if (current->alf_luma_coeff_abs[sf_idx][j])
2283  ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
2284  else
2285  infer(alf_luma_coeff_sign[sf_idx][j], 0);
2286  }
2287  } else {
2288  infer(alf_luma_clip_flag, 0);
2289  infer(alf_luma_num_filters_signalled_minus1, 0);
2290  }
2291  for (int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
2292  for (j = 0; j < 12; j++) {
2293  if (current->alf_luma_clip_flag)
2294  ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
2295  else
2296  infer(alf_luma_clip_idx[sf_idx][j], 0);
2297  }
2298  }
2299 
2300  if (current->alf_chroma_filter_signal_flag) {
2301  flag(alf_chroma_clip_flag);
2302  ue(alf_chroma_num_alt_filters_minus1, 0, 7);
2303  } else {
2304  infer(alf_chroma_clip_flag, 0);
2305  infer(alf_chroma_num_alt_filters_minus1, 0);
2306  }
2307  for (int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
2308  for (j = 0; j < 6; j++) {
2309  if (current->alf_chroma_filter_signal_flag)
2310  ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
2311  else
2312  infer(alf_chroma_coeff_abs[alt_idx][j], 0);
2313  if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
2314  ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
2315  else
2316  infer(alf_chroma_coeff_sign[alt_idx][j], 0);
2317  }
2318  for (j = 0; j < 6; j++) {
2319  if (current->alf_chroma_clip_flag)
2320  ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
2321  else
2322  infer(alf_chroma_clip_idx[alt_idx][j], 0);
2323  }
2324  }
2325 
2326  if (current->alf_cc_cb_filter_signal_flag)
2327  ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
2328  else
2329  infer(alf_cc_cb_filters_signalled_minus1, 0);
2330  for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
2331  for (j = 0; j < 7; j++) {
2332  if (current->alf_cc_cb_filter_signal_flag)
2333  ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
2334  else
2335  infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
2336  if (current->alf_cc_cb_mapped_coeff_abs[k][j])
2337  ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
2338  else
2339  infer(alf_cc_cb_coeff_sign[k][j], 0);
2340  }
2341  }
2342 
2343  if (current->alf_cc_cr_filter_signal_flag)
2344  ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
2345  else
2346  infer(alf_cc_cr_filters_signalled_minus1, 0);
2347  for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
2348  for (j = 0; j < 7; j++) {
2349  if (current->alf_cc_cr_filter_signal_flag)
2350  ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
2351  else
2352  infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
2353  if (current->alf_cc_cr_mapped_coeff_abs[k][j])
2354  ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
2355  else
2356  infer(alf_cc_cr_coeff_sign[k][j], 0);
2357  }
2358  }
2359 
2360  return 0;
2361 }
2362 
2364  H266RawAPS *current)
2365 {
2366  int err, i, lmcs_max_bin_idx;
2367 
2368  ue(lmcs_min_bin_idx, 0, 15);
2369  ue(lmcs_delta_max_bin_idx, 0, 15);
2370  ue(lmcs_delta_cw_prec_minus1, 0, 14);
2371 
2372  lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
2373 
2374  if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
2375  return AVERROR_INVALIDDATA;
2376 
2377  for (i = current->lmcs_min_bin_idx; i <= lmcs_max_bin_idx; i++) {
2378  ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[i], 1, i);
2379  if (current->lmcs_delta_abs_cw[i] > 0)
2380  flags(lmcs_delta_sign_cw_flag[i], 1, i);
2381  else
2382  infer(lmcs_delta_sign_cw_flag[i], 0);
2383  }
2384 
2385  if (current->aps_chroma_present_flag) {
2386  ub(3, lmcs_delta_abs_crs);
2387  if (current->lmcs_delta_abs_crs > 0)
2388  flag(lmcs_delta_sign_crs_flag);
2389  else
2390  infer(lmcs_delta_sign_crs_flag, 0);
2391  } else {
2392  infer(lmcs_delta_abs_crs, 0);
2393  infer(lmcs_delta_sign_crs_flag, 0);
2394  }
2395 
2396  return 0;
2397 }
2398 
2400  H266RawAPS *current)
2401 {
2402  // 7.4.3.4, deriving DiagScanOrder
2403  static const uint8_t diag_scan_order[64][2] = {
2404  { 0, 0, }, { 0, 1, }, { 1, 0, }, { 0, 2, }, { 1, 1, }, { 2, 0, }, { 0, 3, }, { 1, 2, },
2405  { 2, 1, }, { 3, 0, }, { 0, 4, }, { 1, 3, }, { 2, 2, }, { 3, 1, }, { 4, 0, }, { 0, 5, },
2406  { 1, 4, }, { 2, 3, }, { 3, 2, }, { 4, 1, }, { 5, 0, }, { 0, 6, }, { 1, 5, }, { 2, 4, },
2407  { 3, 3, }, { 4, 2, }, { 5, 1, }, { 6, 0, }, { 0, 7, }, { 1, 6, }, { 2, 5, }, { 3, 4, },
2408  { 4, 3, }, { 5, 2, }, { 6, 1, }, { 7, 0, }, { 1, 7, }, { 2, 6, }, { 3, 5, }, { 4, 4, },
2409  { 5, 3, }, { 6, 2, }, { 7, 1, }, { 2, 7, }, { 3, 6, }, { 4, 5, }, { 5, 4, }, { 6, 3, },
2410  { 7, 2, }, { 3, 7, }, { 4, 6, }, { 5, 5, }, { 6, 4, }, { 7, 3, }, { 4, 7, }, { 5, 6, },
2411  { 6, 5, }, { 7, 4, }, { 5, 7, }, { 6, 6, }, { 7, 5, }, { 6, 7, }, { 7, 6, }, { 7, 7, }, };
2412  int err;
2413 
2414  for (int id = 0; id < 28; id ++) {
2415  if (current->aps_chroma_present_flag || id % 3 == 2 || id == 27) {
2416  flags(scaling_list_copy_mode_flag[id], 1, id);
2417  if (!current->scaling_list_copy_mode_flag[id])
2418  flags(scaling_list_pred_mode_flag[id], 1, id);
2419  else
2420  infer(scaling_list_pred_mode_flag[id], 0);
2421  if ((current->scaling_list_copy_mode_flag[id] ||
2422  current->scaling_list_pred_mode_flag[id]) &&
2423  id != 0 && id != 2 && id != 8) {
2424  int max_id_delta = (id < 2) ? id : ((id < 8) ? (id - 2) : (id - 8));
2425  ues(scaling_list_pred_id_delta[id], 0, max_id_delta, 1, id);
2426  }
2427  if (!current->scaling_list_copy_mode_flag[id]) {
2428  int matrix_size = id < 2 ? 2 : (id < 8 ? 4 : 8);
2429  if (id > 13) {
2430  int idx = id - 14;
2431  ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
2432  }
2433  for (int i = 0; i < matrix_size * matrix_size; i++) {
2434  int x = diag_scan_order[i][0];
2435  int y = diag_scan_order[i][1];
2436  if (!(id > 25 && x >= 4 && y >= 4))
2437  ses(scaling_list_delta_coef[id][i], -128, 127, 2, id, i);
2438  }
2439  } else if (id > 13) {
2440  int idx = id - 14;
2441  infer(scaling_list_dc_coef[idx], 0);
2442  }
2443  } else {
2444  infer(scaling_list_copy_mode_flag[id], 1);
2445  infer(scaling_list_pred_mode_flag[id], 0);
2446  }
2447  }
2448 
2449  return 0;
2450 }
2451 
2453  H266RawAPS *current, int prefix)
2454 {
2455  int err;
2456 
2457  if (prefix)
2458  HEADER("Prefix Adaptation parameter set");
2459  else
2460  HEADER("Suffix Adaptation parameter set");
2461 
2462  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2463  prefix ? VVC_PREFIX_APS_NUT
2464  : VVC_SUFFIX_APS_NUT));
2465 
2466  ub(3, aps_params_type);
2467  ub(5, aps_adaptation_parameter_set_id);
2468  flag(aps_chroma_present_flag);
2469  if (current->aps_params_type == VVC_ASP_TYPE_ALF)
2470  CHECK(FUNC(alf_data)(ctx, rw, current));
2471  else if(current->aps_params_type == VVC_ASP_TYPE_LMCS)
2472  CHECK(FUNC(lmcs_data)(ctx, rw, current));
2473  else if (current->aps_params_type == VVC_ASP_TYPE_SCALING)
2474  CHECK(FUNC(scaling_list_data)(ctx, rw, current));
2475  flag(aps_extension_flag);
2476  if (current->aps_extension_flag)
2477  CHECK(FUNC(extension_data) (ctx, rw, &current->extension_data));
2478  CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2479 
2480  return 0;
2481 }
2482 
2484  H266RawAUD *current)
2485 {
2486  int err;
2487 
2488  HEADER("Access Unit Delimiter");
2489 
2490  CHECK(FUNC(nal_unit_header) (ctx, rw,
2491  &current->nal_unit_header, VVC_AUD_NUT));
2492 
2493  flag(aud_irap_or_gdr_flag);
2494  u(3, aud_pic_type, 0, 2);
2495 
2496  CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2497  return 0;
2498 }
2499 
2501  const H266RawSPS *sps,
2502  const H266RawPPS *pps,
2503  const H266RefPicLists *ref_lists,
2504  uint8_t num_ref_idx_active[2],
2505  H266RawPredWeightTable *current)
2506 {
2507  int err, i, j;
2508  ue(luma_log2_weight_denom, 0, 7);
2509  if (sps->sps_chroma_format_idc != 0) {
2510  se(delta_chroma_log2_weight_denom,
2511  -current->luma_log2_weight_denom,
2512  7 - current->luma_log2_weight_denom);
2513  } else {
2514  infer(delta_chroma_log2_weight_denom, 0);
2515  }
2516  if (pps->pps_wp_info_in_ph_flag) {
2517  ue(num_l0_weights, 0,
2518  FFMIN(15, ref_lists->rpl_ref_list[0].num_ref_entries));
2519  infer(num_weights_l0, current->num_l0_weights);
2520  } else {
2521  infer(num_weights_l0, num_ref_idx_active[0]);
2522  }
2523  for (i = 0; i < current->num_weights_l0; i++) {
2524  flags(luma_weight_l0_flag[i], 1, i);
2525  }
2526  if (sps->sps_chroma_format_idc != 0) {
2527  for (i = 0; i < current->num_weights_l0; i++)
2528  flags(chroma_weight_l0_flag[i], 1, i);
2529  }
2530  for (i = 0; i < current->num_weights_l0; i++) {
2531  if (current->luma_weight_l0_flag[i]) {
2532  ses(delta_luma_weight_l0[i], -128, 127, 1, i);
2533  ses(luma_offset_l0[i], -128, 127, 1, i);
2534  } else {
2535  infer(delta_luma_weight_l0[i], 0);
2536  infer(luma_offset_l0[i], 0);
2537  }
2538  if (current->chroma_weight_l0_flag[i]) {
2539  for (j = 0; j < 2; j++) {
2540  ses(delta_chroma_weight_l0[i][j], -128, 127, 2, i, j);
2541  ses(delta_chroma_offset_l0[i][j], -4 * 128, 4 * 127, 2, i, j);
2542  }
2543  }
2544  }
2545 
2546  if (pps->pps_weighted_bipred_flag &&
2547  ref_lists->rpl_ref_list[1].num_ref_entries > 0) {
2548  if (pps->pps_wp_info_in_ph_flag) {
2549  ue(num_l1_weights, 0,
2550  FFMIN(15, ref_lists->rpl_ref_list[1].num_ref_entries));
2551  infer(num_weights_l1, current->num_l1_weights);
2552  } else {
2553  infer(num_weights_l1, num_ref_idx_active[1]);
2554  }
2555  } else {
2556  infer(num_weights_l1, 0);
2557  }
2558 
2559  for (i = 0; i < current->num_weights_l1; i++)
2560  flags(luma_weight_l1_flag[i], 1, i);
2561  if (sps->sps_chroma_format_idc != 0) {
2562  for (i = 0; i < current->num_weights_l1; i++)
2563  flags(chroma_weight_l1_flag[i], 1, i);
2564  }
2565  for (i = 0; i < current->num_weights_l1; i++) {
2566  if (current->luma_weight_l1_flag[i]) {
2567  ses(delta_luma_weight_l1[i], -128, 127, 1, i);
2568  ses(luma_offset_l1[i], -128, 127, 1, i);
2569  } else {
2570  infer(delta_luma_weight_l1[i], 0);
2571  infer(luma_offset_l1[i], 0);
2572  }
2573  if (current->chroma_weight_l1_flag[i]) {
2574  for (j = 0; j < 2; j++) {
2575  ses(delta_chroma_weight_l1[i][j], -128, 127, 2, i, j);
2576  ses(delta_chroma_offset_l1[i][j], -4 * 128, 4 * 127, 2, i, j);
2577  }
2578  }
2579  }
2580  return 0;
2581 }
2582 
2584  H266RawPictureHeader *current) {
2586  const H266RawVPS *vps;
2587  const H266RawSPS *sps;
2588  const H266RawPPS *pps;
2589  int err, i;
2590  unsigned int ctb_log2_size_y, min_cb_log2_size_y,
2591  min_qt_log2_size_intra_y, min_qt_log2_size_inter_y;
2592  uint8_t qp_bd_offset;
2593 
2594  flag(ph_gdr_or_irap_pic_flag);
2595  flag(ph_non_ref_pic_flag);
2596  if (current->ph_gdr_or_irap_pic_flag)
2597  flag(ph_gdr_pic_flag);
2598  else
2599  infer(ph_gdr_pic_flag, 0);
2600  flag(ph_inter_slice_allowed_flag);
2601  if (current->ph_inter_slice_allowed_flag)
2602  flag(ph_intra_slice_allowed_flag);
2603  else
2604  infer(ph_intra_slice_allowed_flag, 1);
2605  ue(ph_pic_parameter_set_id, 0, VVC_MAX_PPS_COUNT - 1);
2606  pps = h266->pps[current->ph_pic_parameter_set_id];
2607  if (!pps) {
2608  av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
2609  current->ph_pic_parameter_set_id);
2610  return AVERROR_INVALIDDATA;
2611  }
2612  sps = h266->sps[pps->pps_seq_parameter_set_id];
2613  if (!sps) {
2614  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
2615  pps->pps_seq_parameter_set_id);
2616  return AVERROR_INVALIDDATA;
2617  }
2618  vps = h266->vps[sps->sps_video_parameter_set_id];
2619  if (!vps) {
2620  av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n",
2621  sps->sps_video_parameter_set_id);
2622  return AVERROR_INVALIDDATA;
2623  }
2624 
2625  ub(sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4, ph_pic_order_cnt_lsb);
2626  if (current->ph_gdr_pic_flag)
2627  ue(ph_recovery_poc_cnt, 0,
2628  1 << (sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4));
2629 
2630  for (i = 0; i < sps->sps_num_extra_ph_bytes * 8; i++) {
2631  if (sps->sps_extra_ph_bit_present_flag[i])
2632  flags(ph_extra_bit[i], 1, i);
2633  }
2634  if (sps->sps_poc_msb_cycle_flag) {
2635  flag(ph_poc_msb_cycle_present_flag);
2636  if (current->ph_poc_msb_cycle_present_flag)
2637  ub(sps->sps_poc_msb_cycle_len_minus1 + 1, ph_poc_msb_cycle_val);
2638  }
2639  if (sps->sps_alf_enabled_flag && pps->pps_alf_info_in_ph_flag) {
2640  flag(ph_alf_enabled_flag);
2641  if (current->ph_alf_enabled_flag) {
2642 
2643  ub(3, ph_num_alf_aps_ids_luma);
2644  for (i = 0; i < current->ph_num_alf_aps_ids_luma; i++)
2645  ubs(3, ph_alf_aps_id_luma[i], 1, i);
2646 
2647  if (sps->sps_chroma_format_idc != 0) {
2648  flag(ph_alf_cb_enabled_flag);
2649  flag(ph_alf_cr_enabled_flag);
2650  } else {
2651  infer(ph_alf_cb_enabled_flag, 0);
2652  infer(ph_alf_cr_enabled_flag, 0);
2653  }
2654 
2655  if (current->ph_alf_cb_enabled_flag
2656  || current->ph_alf_cr_enabled_flag) {
2657  ub(3, ph_alf_aps_id_chroma);
2658  }
2659 
2660  if (sps->sps_ccalf_enabled_flag) {
2661  flag(ph_alf_cc_cb_enabled_flag);
2662  if (current->ph_alf_cc_cb_enabled_flag)
2663  ub(3, ph_alf_cc_cb_aps_id);
2664  flag(ph_alf_cc_cr_enabled_flag);
2665  if (current->ph_alf_cc_cr_enabled_flag)
2666  ub(3, ph_alf_cc_cr_aps_id);
2667  }
2668  }
2669  } else {
2670  infer(ph_alf_enabled_flag, 0);
2671  }
2672  if (sps->sps_lmcs_enabled_flag) {
2673  flag(ph_lmcs_enabled_flag);
2674  if (current->ph_lmcs_enabled_flag) {
2675  ub(2, ph_lmcs_aps_id);
2676  if (sps->sps_chroma_format_idc != 0)
2677  flag(ph_chroma_residual_scale_flag);
2678  else
2679  infer(ph_chroma_residual_scale_flag, 0);
2680  }
2681  } else {
2682  infer(ph_lmcs_enabled_flag, 0);
2683  infer(ph_chroma_residual_scale_flag, 0);
2684  }
2685 
2686  if (sps->sps_explicit_scaling_list_enabled_flag) {
2687  flag(ph_explicit_scaling_list_enabled_flag);
2688  if (current->ph_explicit_scaling_list_enabled_flag) {
2689  //todo: check the ph_scaling_list_aps_id range, when aps ready
2690  ub(3, ph_scaling_list_aps_id);
2691  }
2692  } else {
2693  infer(ph_explicit_scaling_list_enabled_flag, 0);
2694  }
2695  if (sps->sps_virtual_boundaries_enabled_flag &&
2696  !sps->sps_virtual_boundaries_present_flag) {
2697  flag(ph_virtual_boundaries_present_flag);
2698  if (current->ph_virtual_boundaries_present_flag) {
2699  ue(ph_num_ver_virtual_boundaries,
2700  0, pps->pps_pic_width_in_luma_samples <= 8 ? 0 : 3);
2701  for (i = 0; i < current->ph_num_ver_virtual_boundaries; i++) {
2702  ues(ph_virtual_boundary_pos_x_minus1[i],
2703  0, (pps->pps_pic_width_in_luma_samples + 7) / 8 - 2, 1, i);
2704  }
2705  ue(ph_num_hor_virtual_boundaries,
2706  0, pps->pps_pic_height_in_luma_samples <= 8 ? 0 : 3);
2707  for (i = 0; i < current->ph_num_hor_virtual_boundaries; i++) {
2708  ues(ph_virtual_boundary_pos_y_minus1[i],
2709  0, (pps->pps_pic_height_in_luma_samples + 7) / 8 - 2, 1, i);
2710  }
2711  } else {
2712  infer(ph_num_ver_virtual_boundaries, 0);
2713  infer(ph_num_hor_virtual_boundaries, 0);
2714  }
2715  }
2716  if (pps->pps_output_flag_present_flag && !current->ph_non_ref_pic_flag)
2717  flag(ph_pic_output_flag);
2718  else
2719  infer(ph_pic_output_flag, 1);
2720  if (pps->pps_rpl_info_in_ph_flag) {
2722  (ctx, rw, sps, pps, &current->ph_ref_pic_lists));
2723  }
2724  if (sps->sps_partition_constraints_override_enabled_flag)
2725  flag(ph_partition_constraints_override_flag);
2726  else
2727  infer(ph_partition_constraints_override_flag, 0);
2728 
2729  ctb_log2_size_y = sps->sps_log2_ctu_size_minus5 + 5;
2730  min_cb_log2_size_y = sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
2731  if (current->ph_intra_slice_allowed_flag) {
2732  if (current->ph_partition_constraints_override_flag) {
2733  ue(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2734  0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2735  ue(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2736  0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2737  if (current->ph_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
2738  min_qt_log2_size_intra_y =
2739  current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2740  min_cb_log2_size_y;
2741  ue(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2742  0, (sps->sps_qtbtt_dual_tree_intra_flag ?
2743  FFMIN(6, ctb_log2_size_y) :
2744  ctb_log2_size_y) - min_qt_log2_size_intra_y);
2745  ue(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2746  0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
2747  } else {
2748  infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2749  sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2750  infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2751  sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2752  }
2753  if (sps->sps_qtbtt_dual_tree_intra_flag) {
2754  ue(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2755  0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2756  ue(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2757  0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2758  if (sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
2759  unsigned int min_qt_log2_size_intra_c =
2760  sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
2761  min_cb_log2_size_y;
2762  ue(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2763  0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2764  ue(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2765  0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2766  } else {
2767  infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2768  sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2769  infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2770  sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2771  }
2772  }
2773  } else {
2774  infer(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2775  sps->sps_log2_diff_min_qt_min_cb_intra_slice_luma);
2776  infer(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2777  sps->sps_max_mtt_hierarchy_depth_intra_slice_luma);
2778  infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2779  sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2780  infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2781  sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2782  infer(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2783  sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma);
2784  infer(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2785  sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma);
2786  infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2787  sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2788  infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2789  sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2790  }
2791 
2792  min_qt_log2_size_intra_y =
2793  current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2794  min_cb_log2_size_y;
2795  if (pps->pps_cu_qp_delta_enabled_flag)
2796  ue(ph_cu_qp_delta_subdiv_intra_slice, 0,
2797  2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2798  current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2799  else
2800  infer(ph_cu_qp_delta_subdiv_intra_slice, 0);
2801 
2802  if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2803  ue(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0,
2804  2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2805  current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2806  else
2807  infer(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0);
2808  }
2809  if (current->ph_inter_slice_allowed_flag) {
2810  if (current->ph_partition_constraints_override_flag) {
2811  ue(ph_log2_diff_min_qt_min_cb_inter_slice,
2812  0, FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2813  min_qt_log2_size_inter_y =
2814  current->ph_log2_diff_min_qt_min_cb_inter_slice +
2815  min_cb_log2_size_y;
2816  ue(ph_max_mtt_hierarchy_depth_inter_slice, 0,
2817  2 * (ctb_log2_size_y - min_cb_log2_size_y));
2818  if (current->ph_max_mtt_hierarchy_depth_inter_slice != 0) {
2819  ue(ph_log2_diff_max_bt_min_qt_inter_slice,
2820  0, ctb_log2_size_y - min_qt_log2_size_inter_y);
2821  ue(ph_log2_diff_max_tt_min_qt_inter_slice,
2822  0, FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
2823  }
2824  } else {
2825  infer(ph_log2_diff_min_qt_min_cb_inter_slice,
2826  sps->sps_log2_diff_min_qt_min_cb_inter_slice);
2827  min_qt_log2_size_inter_y =
2828  current->ph_log2_diff_min_qt_min_cb_inter_slice +
2829  min_cb_log2_size_y;
2830  infer(ph_max_mtt_hierarchy_depth_inter_slice,
2831  sps->sps_max_mtt_hierarchy_depth_inter_slice);
2832  infer(ph_log2_diff_max_bt_min_qt_inter_slice,
2833  sps->sps_log2_diff_max_bt_min_qt_inter_slice);
2834  infer(ph_log2_diff_max_tt_min_qt_inter_slice,
2835  sps->sps_log2_diff_max_tt_min_qt_inter_slice);
2836  }
2837 
2838  if (pps->pps_cu_qp_delta_enabled_flag)
2839  ue(ph_cu_qp_delta_subdiv_inter_slice, 0,
2840  2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2841  current->ph_max_mtt_hierarchy_depth_inter_slice));
2842  else
2843  infer(ph_cu_qp_delta_subdiv_inter_slice, 0);
2844 
2845  if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2846  ue(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0,
2847  2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2848  current->ph_max_mtt_hierarchy_depth_inter_slice));
2849  else
2850  infer(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0);
2851  if (sps->sps_temporal_mvp_enabled_flag) {
2852  flag(ph_temporal_mvp_enabled_flag);
2853  if (current->ph_temporal_mvp_enabled_flag &&
2854  pps->pps_rpl_info_in_ph_flag) {
2855  if (current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0)
2856  flag(ph_collocated_from_l0_flag);
2857  else
2858  infer(ph_collocated_from_l0_flag, 1);
2859  if ((current->ph_collocated_from_l0_flag &&
2860  current->ph_ref_pic_lists.rpl_ref_list[0].num_ref_entries > 1)
2861  || (!current->ph_collocated_from_l0_flag &&
2862  current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 1)) {
2863  unsigned int idx =
2864  current->ph_collocated_from_l0_flag ? 0 : 1;
2865  ue(ph_collocated_ref_idx, 0,
2866  current->ph_ref_pic_lists.rpl_ref_list[idx].
2867  num_ref_entries - 1);
2868  } else {
2869  infer(ph_collocated_ref_idx, 0);
2870  }
2871  }
2872  }
2873  if (sps->sps_mmvd_fullpel_only_enabled_flag)
2874  flag(ph_mmvd_fullpel_only_flag);
2875  else
2876  infer(ph_mmvd_fullpel_only_flag, 0);
2877  if (!pps->pps_rpl_info_in_ph_flag ||
2878  current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0) {
2879  flag(ph_mvd_l1_zero_flag);
2880  if (sps->sps_bdof_control_present_in_ph_flag) {
2881  flag(ph_bdof_disabled_flag);
2882  } else {
2883  if (!sps->sps_bdof_control_present_in_ph_flag)
2884  infer(ph_bdof_disabled_flag,
2885  1 - sps->sps_bdof_enabled_flag);
2886  else
2887  infer(ph_bdof_disabled_flag, 1);
2888  }
2889  if (sps->sps_dmvr_control_present_in_ph_flag) {
2890  flag(ph_dmvr_disabled_flag);
2891  } else {
2892  if (!sps->sps_dmvr_control_present_in_ph_flag)
2893  infer(ph_dmvr_disabled_flag,
2894  1 - sps->sps_dmvr_enabled_flag);
2895  else
2896  infer(ph_dmvr_disabled_flag, 1);
2897  }
2898  } else {
2899  infer(ph_mvd_l1_zero_flag, 1);
2900  }
2901  if (sps->sps_prof_control_present_in_ph_flag)
2902  flag(ph_prof_disabled_flag);
2903  else
2904  infer(ph_prof_disabled_flag, !sps->sps_affine_prof_enabled_flag);
2905  if ((pps->pps_weighted_pred_flag ||
2906  pps->pps_weighted_bipred_flag) && pps->pps_wp_info_in_ph_flag) {
2907 
2908  // if pps->pps_wp_info_in_ph_fla == 1
2909  // pred_weight_table will not use num_ref_idx_active
2910  uint8_t num_ref_idx_active[2] = { 0, 0 };
2912  (ctx, rw, sps, pps, &current->ph_ref_pic_lists,
2913  num_ref_idx_active, &current->ph_pred_weight_table));
2914  }
2915  }
2916 
2917  qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
2918  if (pps->pps_qp_delta_info_in_ph_flag)
2919  se(ph_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
2920  63 - (26 + pps->pps_init_qp_minus26));
2921 
2922  if (sps->sps_joint_cbcr_enabled_flag)
2923  flag(ph_joint_cbcr_sign_flag);
2924  else
2925  infer(ph_joint_cbcr_sign_flag, 0);
2926  if (sps->sps_sao_enabled_flag && pps->pps_sao_info_in_ph_flag) {
2927  flag(ph_sao_luma_enabled_flag);
2928  if (sps->sps_chroma_format_idc != 0)
2929  flag(ph_sao_chroma_enabled_flag);
2930  else
2931  infer(ph_sao_chroma_enabled_flag, 0);
2932  } else {
2933  infer(ph_sao_luma_enabled_flag, 0);
2934  infer(ph_sao_chroma_enabled_flag, 0);
2935  }
2936 
2937  if (pps->pps_dbf_info_in_ph_flag)
2938  flag(ph_deblocking_params_present_flag);
2939  else
2940  infer(ph_deblocking_params_present_flag, 0);
2941 
2942  if (current->ph_deblocking_params_present_flag) {
2943  if (!pps->pps_deblocking_filter_disabled_flag) {
2944  flag(ph_deblocking_filter_disabled_flag);
2945  if (!current->ph_deblocking_filter_disabled_flag) {
2946  se(ph_luma_beta_offset_div2, -12, 12);
2947  se(ph_luma_tc_offset_div2, -12, 12);
2948  if (pps->pps_chroma_tool_offsets_present_flag) {
2949  se(ph_cb_beta_offset_div2, -12, 12);
2950  se(ph_cb_tc_offset_div2, -12, 12);
2951  se(ph_cr_beta_offset_div2, -12, 12);
2952  se(ph_cr_tc_offset_div2, -12, 12);
2953  } else {
2954  infer(ph_cb_beta_offset_div2,
2955  current->ph_luma_beta_offset_div2);
2956  infer(ph_cb_tc_offset_div2,
2957  current->ph_luma_tc_offset_div2);
2958  infer(ph_cr_beta_offset_div2,
2959  current->ph_luma_beta_offset_div2);
2960  infer(ph_cr_tc_offset_div2,
2961  current->ph_luma_tc_offset_div2);
2962  }
2963  }
2964  } else {
2965  infer(ph_deblocking_filter_disabled_flag, 0);
2966  }
2967  } else {
2968  infer(ph_deblocking_filter_disabled_flag, pps->pps_deblocking_filter_disabled_flag);
2969  if (!current->ph_deblocking_filter_disabled_flag) {
2970  infer(ph_luma_beta_offset_div2, pps->pps_luma_beta_offset_div2);
2971  infer(ph_luma_tc_offset_div2, pps->pps_luma_tc_offset_div2);
2972  infer(ph_cb_beta_offset_div2, pps->pps_cb_beta_offset_div2);
2973  infer(ph_cb_tc_offset_div2, pps->pps_cb_tc_offset_div2);
2974  infer(ph_cr_beta_offset_div2, pps->pps_cr_beta_offset_div2);
2975  infer(ph_cr_tc_offset_div2, pps->pps_cr_tc_offset_div2);
2976  }
2977  }
2978 
2979  if (pps->pps_picture_header_extension_present_flag) {
2980  ue(ph_extension_length, 0, 256);
2981  for (i = 0; i < current->ph_extension_length; i++)
2982  us(8, ph_extension_data_byte[i], 0x00, 0xff, 1, i);
2983  }
2984 
2985  return 0;
2986 }
2987 
2989  H266RawPH *current)
2990 {
2991  int err;
2992 
2993  HEADER("Picture Header");
2994 
2995  CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, VVC_PH_NUT));
2996  CHECK(FUNC(picture_header) (ctx, rw, &current->ph_picture_header));
2997  CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
2998  return 0;
2999 }
3000 
3002  H266RawSliceHeader *current)
3003 {
3005  const H266RawSPS *sps;
3006  const H266RawPPS *pps;
3007  const H266RawPictureHeader *ph;
3009  int err, i;
3010  uint8_t nal_unit_type, qp_bd_offset;
3011  uint16_t num_slices_in_subpic;
3012 
3013  HEADER("Slice Header");
3014 
3015  CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header, -1));
3016 
3017  flag(sh_picture_header_in_slice_header_flag);
3018  if (current->sh_picture_header_in_slice_header_flag) {
3019  // 7.4.8 if sh_picture_header_in_slice_header_flag is true, we do not have a PH NAL unit
3020  CHECK(FUNC(picture_header) (ctx, rw, &current->sh_picture_header));
3021  ph = &current->sh_picture_header;
3022  } else {
3023  ph = h266->ph;
3024  if (!ph) {
3025  av_log(ctx->log_ctx, AV_LOG_ERROR,
3026  "Picture header not available.\n");
3027  return AVERROR_INVALIDDATA;
3028  }
3029  }
3030 
3031  pps = h266->pps[ph->ph_pic_parameter_set_id];
3032  if (!pps) {
3033  av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
3034  ph->ph_pic_parameter_set_id);
3035  return AVERROR_INVALIDDATA;
3036  }
3037  sps = h266->sps[pps->pps_seq_parameter_set_id];
3038  if (!sps) {
3039  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
3040  pps->pps_seq_parameter_set_id);
3041  return AVERROR_INVALIDDATA;
3042  }
3043 
3044  if (sps->sps_subpic_info_present_flag) {
3045  ub(sps->sps_subpic_id_len_minus1 + 1, sh_subpic_id);
3046  for (i = 0; i <= sps->sps_num_subpics_minus1; i++) {
3047  if (pps->sub_pic_id_val[i] == current->sh_subpic_id) {
3048  current->curr_subpic_idx = i;
3049  break;
3050  }
3051  }
3052  if (i > sps->sps_num_subpics_minus1) {
3053  av_log(ctx->log_ctx, AV_LOG_ERROR, "invalid CurrSubpicIdx %d\n", i);
3054  return AVERROR_INVALIDDATA;
3055  }
3056  } else {
3057  current->curr_subpic_idx = 0;
3058  }
3059 
3060  num_slices_in_subpic = pps->num_slices_in_subpic[current->curr_subpic_idx];
3061 
3062  if ((pps->pps_rect_slice_flag && num_slices_in_subpic > 1) ||
3063  (!pps->pps_rect_slice_flag && pps->num_tiles_in_pic > 1)) {
3064  unsigned int bits, max;
3065  if (!pps->pps_rect_slice_flag) {
3066  bits = av_ceil_log2(pps->num_tiles_in_pic);
3067  max = pps->num_tiles_in_pic - 1;
3068  } else {
3069  bits = av_ceil_log2(num_slices_in_subpic);
3070  max = num_slices_in_subpic - 1;
3071  }
3072  u(bits, sh_slice_address, 0, max);
3073  } else {
3074  infer(sh_slice_address, 0);
3075  }
3076 
3077  for (i = 0; i < sps->sps_num_extra_sh_bytes * 8; i++) {
3078  if (sps->sps_extra_sh_bit_present_flag[i])
3079  flags(sh_extra_bit[i], 1, i);
3080  }
3081 
3082  if (!pps->pps_rect_slice_flag &&
3083  pps->num_tiles_in_pic - current->sh_slice_address > 1)
3084  ue(sh_num_tiles_in_slice_minus1, 0, pps->num_tiles_in_pic - 1);
3085  else
3086  infer(sh_num_tiles_in_slice_minus1, 0);
3087 
3088  if (ph->ph_inter_slice_allowed_flag)
3089  ue(sh_slice_type, 0, 2);
3090  else
3091  infer(sh_slice_type, 2);
3092 
3093  nal_unit_type = current->nal_unit_header.nal_unit_type;
3094  if (nal_unit_type == VVC_IDR_W_RADL || nal_unit_type == VVC_IDR_N_LP ||
3095  nal_unit_type == VVC_CRA_NUT || nal_unit_type == VVC_GDR_NUT)
3096  flag(sh_no_output_of_prior_pics_flag);
3097 
3098  if (sps->sps_alf_enabled_flag) {
3099  if (!pps->pps_alf_info_in_ph_flag) {
3100  flag(sh_alf_enabled_flag);
3101  if (current->sh_alf_enabled_flag) {
3102  ub(3, sh_num_alf_aps_ids_luma);
3103  for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3104  ubs(3, sh_alf_aps_id_luma[i], 1, i);
3105 
3106  if (sps->sps_chroma_format_idc != 0) {
3107  flag(sh_alf_cb_enabled_flag);
3108  flag(sh_alf_cr_enabled_flag);
3109  }
3110  if (current->sh_alf_cb_enabled_flag ||
3111  current->sh_alf_cr_enabled_flag) {
3112  ub(3, sh_alf_aps_id_chroma);
3113  }
3114 
3115  if (sps->sps_ccalf_enabled_flag) {
3116  flag(sh_alf_cc_cb_enabled_flag);
3117  if (current->sh_alf_cc_cb_enabled_flag)
3118  ub(3, sh_alf_cc_cb_aps_id);
3119 
3120  flag(sh_alf_cc_cr_enabled_flag);
3121  if (current->sh_alf_cc_cr_enabled_flag)
3122  ub(3, sh_alf_cc_cr_aps_id);
3123  }
3124  }
3125  } else {
3126  infer(sh_alf_enabled_flag, ph->ph_alf_enabled_flag);
3127  if (current->sh_alf_enabled_flag) {
3128  infer(sh_num_alf_aps_ids_luma, ph->ph_num_alf_aps_ids_luma);
3129  for (i = 0; i < current->sh_num_alf_aps_ids_luma; i++)
3130  infer(sh_alf_aps_id_luma[i], ph->ph_alf_aps_id_luma[i]);
3131 
3132  infer(sh_alf_cb_enabled_flag, ph->ph_alf_cb_enabled_flag);
3133  infer(sh_alf_cr_enabled_flag, ph->ph_alf_cr_enabled_flag);
3134  if (current->sh_alf_cb_enabled_flag ||current->sh_alf_cr_enabled_flag)
3135  infer(sh_alf_aps_id_chroma, ph->ph_alf_aps_id_chroma);
3136 
3137  if (sps->sps_ccalf_enabled_flag) {
3138  infer(sh_alf_cc_cb_enabled_flag, ph->ph_alf_cc_cb_enabled_flag);
3139  if (current->sh_alf_cc_cb_enabled_flag)
3140  infer(sh_alf_cc_cb_aps_id, ph->ph_alf_cc_cb_aps_id);
3141 
3142  infer(sh_alf_cc_cr_enabled_flag, ph->ph_alf_cc_cr_enabled_flag);
3143  if (current->sh_alf_cc_cr_enabled_flag)
3144  infer(sh_alf_cc_cr_aps_id, ph->ph_alf_cc_cr_aps_id);
3145  }
3146  }
3147  }
3148  }
3149 
3150  if (current->sh_picture_header_in_slice_header_flag) {
3151  infer(sh_lmcs_used_flag, ph->ph_lmcs_enabled_flag);
3152  infer(sh_explicit_scaling_list_used_flag,
3153  ph->ph_explicit_scaling_list_enabled_flag);
3154  } else {
3155  if (ph->ph_lmcs_enabled_flag)
3156  flag(sh_lmcs_used_flag);
3157  else
3158  infer(sh_lmcs_used_flag, 0);
3159 
3160  if (ph->ph_explicit_scaling_list_enabled_flag)
3161  flag(sh_explicit_scaling_list_used_flag);
3162  else
3163  infer(sh_explicit_scaling_list_used_flag, 0);
3164  }
3165 
3166  if (!pps->pps_rpl_info_in_ph_flag &&
3167  ((nal_unit_type != VVC_IDR_W_RADL &&
3168  nal_unit_type != VVC_IDR_N_LP) || sps->sps_idr_rpl_present_flag)) {
3170  (ctx, rw, sps, pps, &current->sh_ref_pic_lists));
3171  ref_pic_lists = &current->sh_ref_pic_lists;
3172  } else {
3173  ref_pic_lists = &ph->ph_ref_pic_lists;
3174  }
3175  if ((current->sh_slice_type != VVC_SLICE_TYPE_I &&
3176  ref_pic_lists->rpl_ref_list[0].num_ref_entries > 1) ||
3177  (current->sh_slice_type == VVC_SLICE_TYPE_B &&
3178  ref_pic_lists->rpl_ref_list[1].num_ref_entries > 1)) {
3179  flag(sh_num_ref_idx_active_override_flag);
3180  if (current->sh_num_ref_idx_active_override_flag) {
3181  for (i = 0;
3182  i < (current->sh_slice_type == VVC_SLICE_TYPE_B ? 2 : 1); i++)
3183  if (ref_pic_lists->rpl_ref_list[i].num_ref_entries > 1)
3184  ues(sh_num_ref_idx_active_minus1[i], 0, 14, 1, i);
3185  else
3186  infer(sh_num_ref_idx_active_minus1[i], 0);
3187  }
3188  } else {
3189  infer(sh_num_ref_idx_active_override_flag, 1);
3190  }
3191 
3192  for (i = 0; i < 2; i++) {
3193  if (current->sh_slice_type == VVC_SLICE_TYPE_B ||
3194  (current->sh_slice_type == VVC_SLICE_TYPE_P && i == 0)) {
3195  if (current->sh_num_ref_idx_active_override_flag) {
3196  current->num_ref_idx_active[i] = current->sh_num_ref_idx_active_minus1[i] + 1;
3197  } else {
3198  current->num_ref_idx_active[i] =
3199  FFMIN(ref_pic_lists->rpl_ref_list[i].num_ref_entries,
3200  pps->pps_num_ref_idx_default_active_minus1[i] + 1);
3201  }
3202  } else {
3203  current->num_ref_idx_active[i] = 0;
3204  }
3205  }
3206 
3207  if (current->sh_slice_type != VVC_SLICE_TYPE_I) {
3208  if (pps->pps_cabac_init_present_flag)
3209  flag(sh_cabac_init_flag);
3210  else
3211  infer(sh_cabac_init_flag, 0);
3212  if (ph->ph_temporal_mvp_enabled_flag && !pps->pps_rpl_info_in_ph_flag) {
3213  if (current->sh_slice_type == VVC_SLICE_TYPE_B)
3214  flag(sh_collocated_from_l0_flag);
3215  else
3216  infer(sh_collocated_from_l0_flag, 1);
3217  if ((current->sh_collocated_from_l0_flag &&
3218  current->num_ref_idx_active[0] > 1) ||
3219  (!current->sh_collocated_from_l0_flag &&
3220  current->num_ref_idx_active[1] > 1)) {
3221  unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1;
3222  ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] - 1);
3223  } else {
3224  infer(sh_collocated_ref_idx, 0);
3225  }
3226  }
3227  if (!pps->pps_wp_info_in_ph_flag &&
3228  ((pps->pps_weighted_pred_flag &&
3229  current->sh_slice_type == VVC_SLICE_TYPE_P) ||
3230  (pps->pps_weighted_bipred_flag &&
3231  current->sh_slice_type == VVC_SLICE_TYPE_B))) {
3233  current->num_ref_idx_active,
3234  &current->sh_pred_weight_table));
3235  }
3236  }
3237  qp_bd_offset = 6 * sps->sps_bitdepth_minus8;
3238  if (!pps->pps_qp_delta_info_in_ph_flag)
3239  se(sh_qp_delta, -qp_bd_offset - (26 + pps->pps_init_qp_minus26),
3240  63 - (26 + pps->pps_init_qp_minus26));
3241  if (pps->pps_slice_chroma_qp_offsets_present_flag) {
3242  int8_t off;
3243 
3244  se(sh_cb_qp_offset, -12, 12);
3245  off = pps->pps_cb_qp_offset + current->sh_cb_qp_offset;
3246  if (off < -12 || off > 12) {
3247  av_log(ctx->log_ctx, AV_LOG_ERROR,
3248  "pps_cb_qp_offset + sh_cb_qp_offset (%d) not in range [-12, 12].\n",
3249  off);
3250  return AVERROR_INVALIDDATA;
3251  }
3252 
3253  se(sh_cr_qp_offset, -12, 12);
3254  off = pps->pps_cr_qp_offset + current->sh_cr_qp_offset;
3255  if (off < -12 || off > 12) {
3256  av_log(ctx->log_ctx, AV_LOG_ERROR,
3257  "pps_cr_qp_offset + sh_cr_qp_offset (%d) not in range [-12, 12].\n",
3258  off);
3259  return AVERROR_INVALIDDATA;
3260  }
3261 
3262  if (sps->sps_joint_cbcr_enabled_flag) {
3263  se(sh_joint_cbcr_qp_offset, -12, 12);
3264  off =
3265  pps->pps_joint_cbcr_qp_offset_value +
3266  current->sh_joint_cbcr_qp_offset;
3267  if (off < -12 || off > 12) {
3268  av_log(ctx->log_ctx, AV_LOG_ERROR,
3269  "pps_joint_cbcr_qp_offset_value + sh_joint_cbcr_qp_offset (%d)"
3270  "not in range [-12, 12]. \n", off);
3271  return AVERROR_INVALIDDATA;
3272  }
3273  } else {
3274  infer(sh_joint_cbcr_qp_offset, 0);
3275  }
3276  } else {
3277  infer(sh_cb_qp_offset, 0);
3278  infer(sh_cr_qp_offset, 0);
3279  infer(sh_joint_cbcr_qp_offset, 0);
3280  }
3281  if (pps->pps_cu_chroma_qp_offset_list_enabled_flag)
3282  flag(sh_cu_chroma_qp_offset_enabled_flag);
3283  else
3284  infer(sh_cu_chroma_qp_offset_enabled_flag, 0);
3285  if (sps->sps_sao_enabled_flag && !pps->pps_sao_info_in_ph_flag) {
3286  flag(sh_sao_luma_used_flag);
3287  if (sps->sps_chroma_format_idc != 0)
3288  flag(sh_sao_chroma_used_flag);
3289  else
3290  infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3291  } else {
3292  infer(sh_sao_luma_used_flag, ph->ph_sao_luma_enabled_flag);
3293  infer(sh_sao_chroma_used_flag, ph->ph_sao_chroma_enabled_flag);
3294  }
3295 
3296  if (pps->pps_deblocking_filter_override_enabled_flag &&
3297  !pps->pps_dbf_info_in_ph_flag)
3298  flag(sh_deblocking_params_present_flag);
3299  else
3300  infer(sh_deblocking_params_present_flag, 0);
3301  if (current->sh_deblocking_params_present_flag) {
3302  if (!pps->pps_deblocking_filter_disabled_flag)
3303  flag(sh_deblocking_filter_disabled_flag);
3304  else
3305  infer(sh_deblocking_filter_disabled_flag, 0);
3306  if (!current->sh_deblocking_filter_disabled_flag) {
3307  se(sh_luma_beta_offset_div2, -12, 12);
3308  se(sh_luma_tc_offset_div2, -12, 12);
3309  if (pps->pps_chroma_tool_offsets_present_flag) {
3310  se(sh_cb_beta_offset_div2, -12, 12);
3311  se(sh_cb_tc_offset_div2, -12, 12);
3312  se(sh_cr_beta_offset_div2, -12, 12);
3313  se(sh_cr_tc_offset_div2, -12, 12);
3314  } else {
3315  infer(sh_cb_beta_offset_div2,
3316  current->sh_luma_beta_offset_div2);
3317  infer(sh_cb_tc_offset_div2, current->sh_luma_tc_offset_div2);
3318  infer(sh_cr_beta_offset_div2,
3319  current->sh_luma_beta_offset_div2);
3320  infer(sh_cr_tc_offset_div2, current->sh_luma_tc_offset_div2);
3321  }
3322  }
3323  } else {
3324  infer(sh_deblocking_filter_disabled_flag, ph->ph_deblocking_filter_disabled_flag);
3325  if (!current->sh_deblocking_filter_disabled_flag) {
3326  infer(sh_luma_beta_offset_div2, ph->ph_luma_beta_offset_div2);
3327  infer(sh_luma_tc_offset_div2, ph->ph_luma_tc_offset_div2);
3328  infer(sh_cb_beta_offset_div2, ph->ph_cb_beta_offset_div2);
3329  infer(sh_cb_tc_offset_div2, ph->ph_cb_tc_offset_div2);
3330  infer(sh_cr_beta_offset_div2, ph->ph_cr_beta_offset_div2);
3331  infer(sh_cr_tc_offset_div2, ph->ph_cr_tc_offset_div2);
3332  }
3333  }
3334 
3335  if (sps->sps_dep_quant_enabled_flag)
3336  flag(sh_dep_quant_used_flag);
3337  else
3338  infer(sh_dep_quant_used_flag, 0);
3339 
3340  if (sps->sps_sign_data_hiding_enabled_flag &&
3341  !current->sh_dep_quant_used_flag)
3342  flag(sh_sign_data_hiding_used_flag);
3343  else
3344  infer(sh_sign_data_hiding_used_flag, 0);
3345 
3346  if (sps->sps_transform_skip_enabled_flag &&
3347  !current->sh_dep_quant_used_flag &&
3348  !current->sh_sign_data_hiding_used_flag)
3349  flag(sh_ts_residual_coding_disabled_flag);
3350  else
3351  infer(sh_ts_residual_coding_disabled_flag, 0);
3352 
3353  if (!current->sh_ts_residual_coding_disabled_flag &&
3354  sps->sps_ts_residual_coding_rice_present_in_sh_flag)
3355  ub(3, sh_ts_residual_coding_rice_idx_minus1);
3356  else
3357  infer(sh_ts_residual_coding_rice_idx_minus1, 0);
3358 
3359  if (sps->sps_reverse_last_sig_coeff_enabled_flag)
3360  flag(sh_reverse_last_sig_coeff_flag);
3361  else
3362  infer(sh_reverse_last_sig_coeff_flag, 0);
3363 
3364  if (pps->pps_slice_header_extension_present_flag) {
3365  ue(sh_slice_header_extension_length, 0, 256);
3366  for (i = 0; i < current->sh_slice_header_extension_length; i++)
3367  us(8, sh_slice_header_extension_data_byte[i], 0x00, 0xff, 1, i);
3368  }
3369 
3370  current->num_entry_points = 0;
3371  if (sps->sps_entry_point_offsets_present_flag) {
3372  uint8_t entropy_sync = sps->sps_entropy_coding_sync_enabled_flag;
3373  int height;
3374  if (pps->pps_rect_slice_flag) {
3375  int width_in_tiles;
3376  int slice_idx = current->sh_slice_address;
3377  for (i = 0; i < current->curr_subpic_idx; i++) {
3378  slice_idx += pps->num_slices_in_subpic[i];
3379  }
3380  width_in_tiles =
3381  pps->pps_slice_width_in_tiles_minus1[slice_idx] + 1;
3382 
3383  if (entropy_sync)
3384  height = pps->slice_height_in_ctus[slice_idx];
3385  else
3386  height = pps->pps_slice_height_in_tiles_minus1[slice_idx] + 1;
3387 
3388  current->num_entry_points = width_in_tiles * height;
3389  } else {
3390  int tile_idx;
3391  int tile_y;
3392  for (tile_idx = current->sh_slice_address;
3393  tile_idx <=
3394  current->sh_slice_address +
3395  current->sh_num_tiles_in_slice_minus1; tile_idx++) {
3396  tile_y = tile_idx / pps->num_tile_rows;
3397  height = pps->row_height_val[tile_y];
3398  current->num_entry_points += (entropy_sync ? height : 1);
3399  }
3400  }
3401  current->num_entry_points--;
3402  if (current->num_entry_points > VVC_MAX_ENTRY_POINTS) {
3403  av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
3404  "%" PRIu16 ".\n", current->num_entry_points);
3405  return AVERROR_PATCHWELCOME;
3406  }
3407  if (current->num_entry_points > 0) {
3408  ue(sh_entry_offset_len_minus1, 0, 31);
3409  for (i = 0; i < current->num_entry_points; i++) {
3410  ubs(current->sh_entry_offset_len_minus1 + 1,
3411  sh_entry_point_offset_minus1[i], 1, i);
3412  }
3413  }
3414  }
3415  CHECK(FUNC(byte_alignment) (ctx, rw));
3416 
3417  return 0;
3418 }
3419 
3421  RWContext *rw,
3423  current)
3424 {
3425  int err, c_idx, i;
3426 
3427  HEADER("Decoded Picture Hash");
3428 
3429  u(8, dph_sei_hash_type, 0, 2);
3430  flag(dph_sei_single_component_flag);
3431  ub(7, dph_sei_reserved_zero_7bits);
3432 
3433  for (c_idx = 0; c_idx < (current->dph_sei_single_component_flag ? 1 : 3);
3434  c_idx++) {
3435  if (current->dph_sei_hash_type == 0) {
3436  for (i = 0; i < 16; i++)
3437  us(8, dph_sei_picture_md5[c_idx][i], 0x00, 0xff, 2, c_idx, i);
3438  } else if (current->dph_sei_hash_type == 1) {
3439  us(16, dph_sei_picture_crc[c_idx], 0x0000, 0xffff, 1, c_idx);
3440  } else if (current->dph_sei_hash_type == 2) {
3441  us(32, dph_sei_picture_checksum[c_idx], 0x00000000, 0xffffffff, 1,
3442  c_idx);
3443  }
3444  }
3445  return 0;
3446 }
3447 
3449  H266RawSEI *current, int prefix)
3450 {
3451  int err;
3452 
3453  if (prefix)
3454  HEADER("Prefix Supplemental Enhancement Information");
3455  else
3456  HEADER("Suffix Supplemental Enhancement Information");
3457 
3458  CHECK(FUNC(nal_unit_header) (ctx, rw, &current->nal_unit_header,
3459  prefix ? VVC_PREFIX_SEI_NUT
3460  : VVC_SUFFIX_SEI_NUT));
3461 
3462  CHECK(FUNC_SEI(message_list) (ctx, rw, &current->message_list, prefix));
3463 
3464  CHECK(FUNC(rbsp_trailing_bits) (ctx, rw));
3465 
3466  return 0;
3467 }
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H266RawSEI *current, int prefix)
Definition: cbs_h266_syntax_template.c:3448
bit_position
#define bit_position(rw)
Definition: cbs_h2645.c:432
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
VVC_MAX_TILES_PER_AU
@ VVC_MAX_TILES_PER_AU
Definition: vvc.h:136
dpb_parameters
static int FUNC() dpb_parameters(CodedBitstreamContext *ctx, RWContext *rw, H266DpbParameters *current, uint8_t max_sublayers_minus1, uint8_t sublayer_info_flag)
Definition: cbs_h266_syntax_template.c:394
r
const char * r
Definition: vf_curves.c:126
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
H266RawDCI
Definition: cbs_h266.h:252
ff_ctz
#define ff_ctz
Definition: intmath.h:107
lmcs_data
static int FUNC() lmcs_data(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current)
Definition: cbs_h266_syntax_template.c:2363
VVC_MAX_VPS_COUNT
@ VVC_MAX_VPS_COUNT
Definition: vvc.h:95
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:240
VVC_SLICE_TYPE_P
@ VVC_SLICE_TYPE_P
Definition: vvc.h:65
VVC_PPS_NUT
@ VVC_PPS_NUT
Definition: vvc.h:45
sublayer_hrd_parameters
static int FUNC() sublayer_hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H266RawSubLayerHRDParameters *current, int sublayer_id, const H266RawGeneralTimingHrdParameters *general)
Definition: cbs_h266_syntax_template.c:586
VVC_MAX_SLICES
@ VVC_MAX_SLICES
Definition: vvc.h:144
se
#define se(name, range_min, range_max)
Definition: cbs_h2645.c:249
HEADER
#define HEADER(name)
Definition: cbs_av1.c:448
ref_pic_list_struct
static int FUNC() ref_pic_list_struct(CodedBitstreamContext *ctx, RWContext *rw, H266RefPicListStruct *current, uint8_t list_idx, uint8_t rpls_idx, const H266RawSPS *sps)
Definition: cbs_h266_syntax_template.c:410
infer
#define infer(name, value)
Definition: cbs_av1.c:635
ph
static int FUNC() ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
Definition: cbs_h266_syntax_template.c:2988
vui_parameters
static int FUNC() vui_parameters(CodedBitstreamContext *ctx, RWContext *rw, H266RawVUI *current, uint8_t chroma_format_idc)
Definition: cbs_h266_syntax_template.c:239
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
VVC_MAX_SUBLAYERS
@ VVC_MAX_SUBLAYERS
Definition: vvc.h:83
VVC_ASP_TYPE_SCALING
@ VVC_ASP_TYPE_SCALING
Definition: vvc.h:72
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
H266DpbParameters
Definition: cbs_h266.h:154
profile_tier_level
static int FUNC() profile_tier_level(CodedBitstreamContext *ctx, RWContext *rw, H266RawProfileTierLevel *current, int profile_tier_present_flag, int max_num_sub_layers_minus1)
Definition: cbs_h266_syntax_template.c:178
H266RefPicListStruct::st_ref_pic_flag
uint8_t st_ref_pic_flag[VVC_MAX_REF_ENTRIES]
Definition: cbs_h266.h:164
VVC_MAX_LAYERS
@ VVC_MAX_LAYERS
Definition: vvc.h:80
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H266RawVPS *current)
Definition: cbs_h266_syntax_template.c:694
allocate
#define allocate(name, size)
Definition: cbs_h2645.c:435
H266RefPicListStruct::ltrp_in_header_flag
uint8_t ltrp_in_header_flag
Definition: cbs_h266.h:162
max
#define max(a, b)
Definition: cuda_runtime.h:33
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
H266RawExtensionData
Definition: cbs_h266.h:148
H266RefPicListStruct::num_ref_entries
uint8_t num_ref_entries
Definition: cbs_h266.h:161
ses
#define ses(name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:264
VVC_CRA_NUT
@ VVC_CRA_NUT
Definition: vvc.h:38
VVC_MAX_PPS_COUNT
@ VVC_MAX_PPS_COUNT
Definition: vvc.h:99
aud
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H266RawAUD *current)
Definition: cbs_h266_syntax_template.c:2483
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:56
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
VVC_AUD_NUT
@ VVC_AUD_NUT
Definition: vvc.h:49
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
CodedBitstreamH266Context::pps
H266RawPPS * pps[VVC_MAX_PPS_COUNT]
RefStruct references.
Definition: cbs_h266.h:873
CodedBitstreamH266Context::vps
H266RawVPS * vps[VVC_MAX_VPS_COUNT]
RefStruct references.
Definition: cbs_h266.h:871
H266RawAUD
Definition: cbs_h266.h:644
slice_header
static int FUNC() slice_header(CodedBitstreamContext *ctx, RWContext *rw, H266RawSliceHeader *current)
Definition: cbs_h266_syntax_template.c:3001
VVC_ASP_TYPE_ALF
@ VVC_ASP_TYPE_ALF
Definition: vvc.h:70
CHECK
CHECK(-1) CHECK(-2) }} }} CHECK(1) CHECK(2) }} }} } if(diff0+diff1 > 0) temp -
VVC_SUFFIX_SEI_NUT
@ VVC_SUFFIX_SEI_NUT
Definition: vvc.h:53
VVC_MAX_REF_ENTRIES
@ VVC_MAX_REF_ENTRIES
Definition: vvc.h:115
sps_range_extension
static int FUNC() sps_range_extension(CodedBitstreamContext *ctx, RWContext *rw, H266RawSPS *current)
Definition: cbs_h266_syntax_template.c:1036
H266RefPicListStruct::inter_layer_ref_pic_flag
uint8_t inter_layer_ref_pic_flag[VVC_MAX_REF_ENTRIES]
Definition: cbs_h266.h:163
av_ceil_log2
#define av_ceil_log2
Definition: common.h:93
GetBitContext
Definition: get_bits.h:108
H266RawAPS
Definition: cbs_h266.h:598
ub
#define ub(width, name)
Definition: cbs_h2645.c:390
VVC_VPS_NUT
@ VVC_VPS_NUT
Definition: vvc.h:43
ue
#define ue(name, range_min, range_max)
Definition: cbs_h2645.c:243
H266GeneralConstraintsInfo
Definition: cbs_h266.h:36
us
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:252
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H266RawPPS *current)
Definition: cbs_h266_syntax_template.c:1644
H266RawProfileTierLevel
Definition: cbs_h266.h:133
sei_decoded_picture_hash
static int FUNC() sei_decoded_picture_hash(CodedBitstreamContext *ctx, RWContext *rw, H266RawSEIDecodedPictureHash *current)
Definition: cbs_h266_syntax_template.c:3420
message_list
static int FUNC() message_list(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMessageList *current, int prefix)
Definition: cbs_sei_syntax_template.c:252
VVC_SLICE_TYPE_B
@ VVC_SLICE_TYPE_B
Definition: vvc.h:64
VVC_PREFIX_SEI_NUT
@ VVC_PREFIX_SEI_NUT
Definition: vvc.h:52
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
H266RawVUI
Definition: cbs_h266.h:211
H266RawSEI
Definition: cbs_h266.h:860
width
#define width
VVC_GDR_NUT
@ VVC_GDR_NUT
Definition: vvc.h:39
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
bits
uint8_t bits
Definition: vp3data.h:128
rbsp_trailing_bits
static int FUNC() rbsp_trailing_bits(CodedBitstreamContext *ctx, RWContext *rw)
Definition: cbs_h266_syntax_template.c:19
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
H266RefPicLists
Definition: cbs_h266.h:171
FUNC_SEI
#define FUNC_SEI(name)
Definition: cbs_h2645.c:236
MAX_UINT_BITS
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:196
H266RawGeneralTimingHrdParameters
Definition: cbs_h266.h:180
VVC_MAX_HEIGHT
@ VVC_MAX_HEIGHT
Definition: vvc.h:133
cbs_h265_payload_extension_present
static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t payload_size, int cur_pos)
Definition: cbs_h2645.c:213
H266RawSPS
Definition: cbs_h266.h:308
H266RawVPS
Definition: cbs_h266.h:262
scaling_list_data
static int FUNC() scaling_list_data(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current)
Definition: cbs_h266_syntax_template.c:2399
H266RawPPS
Definition: cbs_h266.h:496
aps
static int FUNC() aps(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current, int prefix)
Definition: cbs_h266_syntax_template.c:2452
H266RawOPI
Definition: cbs_h266.h:241
VVC_DCI_NUT
@ VVC_DCI_NUT
Definition: vvc.h:42
H266RawPictureHeader
Definition: cbs_h266.h:674
bits_left
#define bits_left
Definition: bitstream.h:114
byte_alignment
static int FUNC() byte_alignment(CodedBitstreamContext *ctx, RWContext *rw)
Definition: cbs_h266_syntax_template.c:50
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
VVC_MAX_WIDTH
@ VVC_MAX_WIDTH
Definition: vvc.h:132
VVC_MAX_TILE_ROWS
@ VVC_MAX_TILE_ROWS
Definition: vvc.h:139
general_constraints_info
static int FUNC() general_constraints_info(CodedBitstreamContext *ctx, RWContext *rw, H266GeneralConstraintsInfo *current)
Definition: cbs_h266_syntax_template.c:60
H266RawPredWeightTable
Definition: cbs_h266.h:650
opi
static int FUNC() opi(CodedBitstreamContext *ctx, RWContext *rw, H266RawOPI *current)
Definition: cbs_h266_syntax_template.c:643
ff_refstruct_allocz
static void * ff_refstruct_allocz(size_t size)
Equivalent to ff_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition: refstruct.h:105
VVC_SUFFIX_APS_NUT
@ VVC_SUFFIX_APS_NUT
Definition: vvc.h:47
VVC_PH_NUT
@ VVC_PH_NUT
Definition: vvc.h:48
payload_extension
static int FUNC() payload_extension(CodedBitstreamContext *ctx, RWContext *rw, H266RawExtensionData *current, uint32_t payload_size, int cur_pos)
Definition: cbs_h266_syntax_template.c:310
VVC_MAX_TOTAL_NUM_OLSS
@ VVC_MAX_TOTAL_NUM_OLSS
Definition: vvc.h:92
VVC_IDR_W_RADL
@ VVC_IDR_W_RADL
Definition: vvc.h:36
CodedBitstreamH266Context::ph
H266RawPictureHeader * ph
Definition: cbs_h266.h:874
H266RefPicListStruct
Definition: cbs_h266.h:160
H266RawSubLayerHRDParameters
Definition: cbs_h266.h:194
height
#define height
VVC_MAX_DPB_SIZE
@ VVC_MAX_DPB_SIZE
Definition: vvc.h:109
CodedBitstreamH266Context
Definition: cbs_h266.h:865
vui_parameters_default
static int FUNC() vui_parameters_default(CodedBitstreamContext *ctx, RWContext *rw, H266RawVUI *current)
Definition: cbs_h266_syntax_template.c:213
alf_data
static int FUNC() alf_data(CodedBitstreamContext *ctx, RWContext *rw, H266RawAPS *current)
Definition: cbs_h266_syntax_template.c:2252
H266RawSliceHeader
Definition: cbs_h266.h:769
ols_timing_hrd_parameters
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)
Definition: cbs_h266_syntax_template.c:609
flag
#define flag(name)
Definition: cbs_av1.c:466
ubs
#define ubs(width, name, subs,...)
Definition: cbs_h2645.c:254
VVC_MAX_REF_PIC_LISTS
@ VVC_MAX_REF_PIC_LISTS
Definition: vvc.h:112
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:245
pred_weight_table
static int FUNC() pred_weight_table(CodedBitstreamContext *ctx, RWContext *rw, const H266RawSPS *sps, const H266RawPPS *pps, const H266RefPicLists *ref_lists, uint8_t num_ref_idx_active[2], H266RawPredWeightTable *current)
Definition: cbs_h266_syntax_template.c:2500
VVC_OPI_NUT
@ VVC_OPI_NUT
Definition: vvc.h:41
nal_unit_header
static int FUNC() nal_unit_header(CodedBitstreamContext *ctx, RWContext *rw, H266RawNALUnitHeader *current, int expected_nal_unit_type)
Definition: cbs_h266_syntax_template.c:30
CodedBitstreamH266Context::sps
H266RawSPS * sps[VVC_MAX_SPS_COUNT]
RefStruct references.
Definition: cbs_h266.h:872
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
general_timing_hrd_parameters
static int FUNC() general_timing_hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H266RawGeneralTimingHrdParameters *current)
Definition: cbs_h266_syntax_template.c:558
VVC_MAX_TILE_COLUMNS
@ VVC_MAX_TILE_COLUMNS
Definition: vvc.h:141
VVC_SPS_NUT
@ VVC_SPS_NUT
Definition: vvc.h:44
H266RawPH
Definition: cbs_h266.h:764
ref_pic_lists
static int FUNC() ref_pic_lists(CodedBitstreamContext *ctx, RWContext *rw, const H266RawSPS *sps, const H266RawPPS *pps, H266RefPicLists *current)
Definition: cbs_h266_syntax_template.c:491
FUNC
#define FUNC(a)
Definition: bit_depth_template.c:104
H266RawOlsTimingHrdParameters
Definition: cbs_h266.h:202
VVC_MAX_ENTRY_POINTS
@ VVC_MAX_ENTRY_POINTS
Definition: vvc.h:153
VVC_NUM_ALF_FILTERS
@ VVC_NUM_ALF_FILTERS
Definition: vvc.h:106
dci
static int FUNC() dci(CodedBitstreamContext *ctx, RWContext *rw, H266RawDCI *current)
Definition: cbs_h266_syntax_template.c:670
extension_data
static int FUNC() extension_data(CodedBitstreamContext *ctx, RWContext *rw, H266RawExtensionData *current)
Definition: cbs_h266_syntax_template.c:367
VVC_ASP_TYPE_LMCS
@ VVC_ASP_TYPE_LMCS
Definition: vvc.h:71
VVC_IDR_N_LP
@ VVC_IDR_N_LP
Definition: vvc.h:37
fixed
#define fixed(width, name, value)
Definition: cbs_av1.c:479
VVC_PREFIX_APS_NUT
@ VVC_PREFIX_APS_NUT
Definition: vvc.h:46
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
H266RawNALUnitHeader
Definition: cbs_h266.h:29
ues
#define ues(name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:258
H266RawSEIDecodedPictureHash
Definition: cbs_h266.h:850
xu
#define xu(width, name, var, range_min, range_max, subs,...)
Definition: cbs_h2645.c:395
vui_payload
static int FUNC() vui_payload(CodedBitstreamContext *ctx, RWContext *rw, H266RawVUI *current, uint16_t vui_payload_size, uint8_t chroma_format_idc)
Definition: cbs_h266_syntax_template.c:346
RWContext
#define RWContext
Definition: cbs_av1.c:583
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H266RawSPS *current)
Definition: cbs_h266_syntax_template.c:1053
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1143
cbs_h2645_read_more_rbsp_data
static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
Definition: cbs_h2645.c:317
picture_header
static int FUNC() picture_header(CodedBitstreamContext *ctx, RWContext *rw, H266RawPictureHeader *current)
Definition: cbs_h266_syntax_template.c:2583
VVC_SLICE_TYPE_I
@ VVC_SLICE_TYPE_I
Definition: vvc.h:66