FFmpeg  4.1.11
cbs_h265_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 {
21  int err;
22 
23  fixed(1, rbsp_stop_one_bit, 1);
24  while (byte_alignment(rw) != 0)
25  fixed(1, rbsp_alignment_zero_bit, 0);
26 
27  return 0;
28 }
29 
31  H265RawNALUnitHeader *current,
32  int expected_nal_unit_type)
33 {
34  int err;
35 
36  u(1, forbidden_zero_bit, 0, 0);
37 
38  if (expected_nal_unit_type >= 0)
39  u(6, nal_unit_type, expected_nal_unit_type,
40  expected_nal_unit_type);
41  else
42  u(6, nal_unit_type, 0, 63);
43 
44  u(6, nuh_layer_id, 0, 62);
45  u(3, nuh_temporal_id_plus1, 1, 7);
46 
47  return 0;
48 }
49 
51 {
52  int err;
53 
54  fixed(1, alignment_bit_equal_to_one, 1);
55  while (byte_alignment(rw) != 0)
56  fixed(1, alignment_bit_equal_to_zero, 0);
57 
58  return 0;
59 }
60 
62  H265RawPSExtensionData *current)
63 {
64  int err;
65  size_t k;
66 #ifdef READ
68  uint8_t bit;
69  start = *rw;
70  for (k = 0; cbs_h2645_read_more_rbsp_data(rw); k++)
71  skip_bits(rw, 1);
72  current->bit_length = k;
73  if (k > 0) {
74  *rw = start;
75  allocate(current->data, (current->bit_length + 7) / 8);
76  for (k = 0; k < current->bit_length; k++) {
77  xu(1, extension_data, bit, 0, 1, 0);
78  current->data[k / 8] |= bit << (7 - k % 8);
79  }
80  }
81 #else
82  for (k = 0; k < current->bit_length; k++)
83  xu(1, extension_data, current->data[k / 8] >> (7 - k % 8) & 1, 0, 1, 0);
84 #endif
85  return 0;
86 }
87 
89  H265RawProfileTierLevel *current,
90  int profile_present_flag,
91  int max_num_sub_layers_minus1)
92 {
93  int err, i, j;
94 
95  if (profile_present_flag) {
96  u(2, general_profile_space, 0, 0);
97  flag(general_tier_flag);
98  u(5, general_profile_idc, 0, 31);
99 
100  for (j = 0; j < 32; j++)
101  flags(general_profile_compatibility_flag[j], 1, j);
102 
103  flag(general_progressive_source_flag);
104  flag(general_interlaced_source_flag);
105  flag(general_non_packed_constraint_flag);
106  flag(general_frame_only_constraint_flag);
107 
108 #define profile_compatible(x) (current->general_profile_idc == (x) || \
109  current->general_profile_compatibility_flag[x])
110  if (profile_compatible(4) || profile_compatible(5) ||
113  profile_compatible(10)) {
114  flag(general_max_12bit_constraint_flag);
115  flag(general_max_10bit_constraint_flag);
116  flag(general_max_8bit_constraint_flag);
117  flag(general_max_422chroma_constraint_flag);
118  flag(general_max_420chroma_constraint_flag);
119  flag(general_max_monochrome_constraint_flag);
120  flag(general_intra_constraint_flag);
121  flag(general_one_picture_only_constraint_flag);
122  flag(general_lower_bit_rate_constraint_flag);
123 
124  if (profile_compatible(5) || profile_compatible(9) ||
125  profile_compatible(10)) {
126  flag(general_max_14bit_constraint_flag);
127  fixed(24, general_reserved_zero_33bits, 0);
128  fixed( 9, general_reserved_zero_33bits, 0);
129  } else {
130  fixed(24, general_reserved_zero_34bits, 0);
131  fixed(10, general_reserved_zero_34bits, 0);
132  }
133  } else if (profile_compatible(2)) {
134  fixed(7, general_reserved_zero_7bits, 0);
135  flag(general_one_picture_only_constraint_flag);
136  fixed(24, general_reserved_zero_35bits, 0);
137  fixed(11, general_reserved_zero_35bits, 0);
138  } else {
139  fixed(24, general_reserved_zero_43bits, 0);
140  fixed(19, general_reserved_zero_43bits, 0);
141  }
142 
143  if (profile_compatible(1) || profile_compatible(2) ||
146  flag(general_inbld_flag);
147  } else {
148  fixed(1, general_reserved_zero_bit, 0);
149  }
150 #undef profile_compatible
151  }
152 
153  u(8, general_level_idc, 0, 255);
154 
155  for (i = 0; i < max_num_sub_layers_minus1; i++) {
156  flags(sub_layer_profile_present_flag[i], 1, i);
157  flags(sub_layer_level_present_flag[i], 1, i);
158  }
159 
160  if (max_num_sub_layers_minus1 > 0) {
161  for (i = max_num_sub_layers_minus1; i < 8; i++)
162  fixed(2, reserved_zero_2bits, 0);
163  }
164 
165  for (i = 0; i < max_num_sub_layers_minus1; i++) {
166  if (current->sub_layer_profile_present_flag[i])
167  return AVERROR_PATCHWELCOME;
168  if (current->sub_layer_level_present_flag[i])
169  return AVERROR_PATCHWELCOME;
170  }
171 
172  return 0;
173 }
174 
177  int nal, int sub_layer_id)
178 {
180  int err, i;
181 
182  if (nal)
183  current = &hrd->nal_sub_layer_hrd_parameters[sub_layer_id];
184  else
185  current = &hrd->vcl_sub_layer_hrd_parameters[sub_layer_id];
186 
187  for (i = 0; i <= hrd->cpb_cnt_minus1[sub_layer_id]; i++) {
188  ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
189  ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
190  if (hrd->sub_pic_hrd_params_present_flag) {
191  ues(cpb_size_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
192  ues(bit_rate_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
193  }
194  flags(cbr_flag[i], 1, i);
195  }
196 
197  return 0;
198 }
199 
201  H265RawHRDParameters *current, int common_inf_present_flag,
202  int max_num_sub_layers_minus1)
203 {
204  int err, i;
205 
206  if (common_inf_present_flag) {
207  flag(nal_hrd_parameters_present_flag);
208  flag(vcl_hrd_parameters_present_flag);
209 
210  if (current->nal_hrd_parameters_present_flag ||
211  current->vcl_hrd_parameters_present_flag) {
212  flag(sub_pic_hrd_params_present_flag);
213  if (current->sub_pic_hrd_params_present_flag) {
214  u(8, tick_divisor_minus2, 0, 255);
215  u(5, du_cpb_removal_delay_increment_length_minus1, 0, 31);
216  flag(sub_pic_cpb_params_in_pic_timing_sei_flag);
217  u(5, dpb_output_delay_du_length_minus1, 0, 31);
218  }
219 
220  u(4, bit_rate_scale, 0, 15);
221  u(4, cpb_size_scale, 0, 15);
222  if (current->sub_pic_hrd_params_present_flag)
223  u(4, cpb_size_du_scale, 0, 15);
224 
225  u(5, initial_cpb_removal_delay_length_minus1, 0, 31);
226  u(5, au_cpb_removal_delay_length_minus1, 0, 31);
227  u(5, dpb_output_delay_length_minus1, 0, 31);
228  } else {
229  infer(sub_pic_hrd_params_present_flag, 0);
230 
231  infer(initial_cpb_removal_delay_length_minus1, 23);
232  infer(au_cpb_removal_delay_length_minus1, 23);
233  infer(dpb_output_delay_length_minus1, 23);
234  }
235  }
236 
237  for (i = 0; i <= max_num_sub_layers_minus1; i++) {
238  flags(fixed_pic_rate_general_flag[i], 1, i);
239 
240  if (!current->fixed_pic_rate_general_flag[i])
241  flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
242  else
243  infer(fixed_pic_rate_within_cvs_flag[i], 1);
244 
245  if (current->fixed_pic_rate_within_cvs_flag[i]) {
246  ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
247  infer(low_delay_hrd_flag[i], 0);
248  } else
249  flags(low_delay_hrd_flag[i], 1, i);
250 
251  if (!current->low_delay_hrd_flag[i])
252  ues(cpb_cnt_minus1[i], 0, 31, 1, i);
253  else
254  infer(cpb_cnt_minus1[i], 0);
255 
256  if (current->nal_hrd_parameters_present_flag)
257  CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 0, i));
258  if (current->vcl_hrd_parameters_present_flag)
259  CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 1, i));
260  }
261 
262  return 0;
263 }
264 
266  H265RawVUI *current, const H265RawSPS *sps)
267 {
268  int err;
269 
270  flag(aspect_ratio_info_present_flag);
271  if (current->aspect_ratio_info_present_flag) {
272  u(8, aspect_ratio_idc, 0, 255);
273  if (current->aspect_ratio_idc == 255) {
274  u(16, sar_width, 0, 65535);
275  u(16, sar_height, 0, 65535);
276  }
277  } else {
278  infer(aspect_ratio_idc, 0);
279  }
280 
281  flag(overscan_info_present_flag);
282  if (current->overscan_info_present_flag)
283  flag(overscan_appropriate_flag);
284 
285  flag(video_signal_type_present_flag);
286  if (current->video_signal_type_present_flag) {
287  u(3, video_format, 0, 7);
288  flag(video_full_range_flag);
289  flag(colour_description_present_flag);
290  if (current->colour_description_present_flag) {
291  u(8, colour_primaries, 0, 255);
292  u(8, transfer_characteristics, 0, 255);
293  u(8, matrix_coefficients, 0, 255);
294  } else {
295  infer(colour_primaries, 2);
297  infer(matrix_coefficients, 2);
298  }
299  } else {
300  infer(video_format, 5);
301  infer(video_full_range_flag, 0);
302  infer(colour_primaries, 2);
304  infer(matrix_coefficients, 2);
305  }
306 
307  flag(chroma_loc_info_present_flag);
308  if (current->chroma_loc_info_present_flag) {
309  ue(chroma_sample_loc_type_top_field, 0, 5);
310  ue(chroma_sample_loc_type_bottom_field, 0, 5);
311  } else {
312  infer(chroma_sample_loc_type_top_field, 0);
313  infer(chroma_sample_loc_type_bottom_field, 0);
314  }
315 
316  flag(neutral_chroma_indication_flag);
317  flag(field_seq_flag);
318  flag(frame_field_info_present_flag);
319 
320  flag(default_display_window_flag);
321  if (current->default_display_window_flag) {
322  ue(def_disp_win_left_offset, 0, 16384);
323  ue(def_disp_win_right_offset, 0, 16384);
324  ue(def_disp_win_top_offset, 0, 16384);
325  ue(def_disp_win_bottom_offset, 0, 16384);
326  }
327 
328  flag(vui_timing_info_present_flag);
329  if (current->vui_timing_info_present_flag) {
330  u(32, vui_num_units_in_tick, 1, UINT32_MAX);
331  u(32, vui_time_scale, 1, UINT32_MAX);
332  flag(vui_poc_proportional_to_timing_flag);
333  if (current->vui_poc_proportional_to_timing_flag)
334  ue(vui_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
335 
336  flag(vui_hrd_parameters_present_flag);
337  if (current->vui_hrd_parameters_present_flag) {
338  CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters,
339  1, sps->sps_max_sub_layers_minus1));
340  }
341  }
342 
343  flag(bitstream_restriction_flag);
344  if (current->bitstream_restriction_flag) {
345  flag(tiles_fixed_structure_flag);
346  flag(motion_vectors_over_pic_boundaries_flag);
347  flag(restricted_ref_pic_lists_flag);
348  ue(min_spatial_segmentation_idc, 0, 4095);
349  ue(max_bytes_per_pic_denom, 0, 16);
350  ue(max_bits_per_min_cu_denom, 0, 16);
351  ue(log2_max_mv_length_horizontal, 0, 16);
352  ue(log2_max_mv_length_vertical, 0, 16);
353  } else {
354  infer(tiles_fixed_structure_flag, 0);
355  infer(motion_vectors_over_pic_boundaries_flag, 1);
356  infer(min_spatial_segmentation_idc, 0);
357  infer(max_bytes_per_pic_denom, 2);
358  infer(max_bits_per_min_cu_denom, 1);
359  infer(log2_max_mv_length_horizontal, 15);
360  infer(log2_max_mv_length_vertical, 15);
361  }
362 
363  return 0;
364 }
365 
367  H265RawVPS *current)
368 {
369  int err, i, j;
370 
371  HEADER("Video Parameter Set");
372 
373  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_VPS));
374 
375  u(4, vps_video_parameter_set_id, 0, 15);
376 
377  flag(vps_base_layer_internal_flag);
378  flag(vps_base_layer_available_flag);
379  u(6, vps_max_layers_minus1, 0, HEVC_MAX_LAYERS - 1);
380  u(3, vps_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS - 1);
381  flag(vps_temporal_id_nesting_flag);
382 
383  if (current->vps_max_sub_layers_minus1 == 0 &&
384  current->vps_temporal_id_nesting_flag != 1) {
385  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
386  "vps_temporal_id_nesting_flag must be 1 if "
387  "vps_max_sub_layers_minus1 is 0.\n");
388  return AVERROR_INVALIDDATA;
389  }
390 
391  fixed(16, vps_reserved_0xffff_16bits, 0xffff);
392 
393  CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
394  1, current->vps_max_sub_layers_minus1));
395 
396  flag(vps_sub_layer_ordering_info_present_flag);
397  for (i = (current->vps_sub_layer_ordering_info_present_flag ?
398  0 : current->vps_max_sub_layers_minus1);
399  i <= current->vps_max_sub_layers_minus1; i++) {
400  ues(vps_max_dec_pic_buffering_minus1[i],
401  0, HEVC_MAX_DPB_SIZE - 1, 1, i);
402  ues(vps_max_num_reorder_pics[i],
403  0, current->vps_max_dec_pic_buffering_minus1[i], 1, i);
404  ues(vps_max_latency_increase_plus1[i],
405  0, UINT32_MAX - 1, 1, i);
406  }
407  if (!current->vps_sub_layer_ordering_info_present_flag) {
408  for (i = 0; i < current->vps_max_sub_layers_minus1; i++) {
409  infer(vps_max_dec_pic_buffering_minus1[i],
410  current->vps_max_dec_pic_buffering_minus1[current->vps_max_sub_layers_minus1]);
411  infer(vps_max_num_reorder_pics[i],
412  current->vps_max_num_reorder_pics[current->vps_max_sub_layers_minus1]);
413  infer(vps_max_latency_increase_plus1[i],
414  current->vps_max_latency_increase_plus1[current->vps_max_sub_layers_minus1]);
415  }
416  }
417 
418  u(6, vps_max_layer_id, 0, HEVC_MAX_LAYERS - 1);
419  ue(vps_num_layer_sets_minus1, 0, HEVC_MAX_LAYER_SETS - 1);
420  for (i = 1; i <= current->vps_num_layer_sets_minus1; i++) {
421  for (j = 0; j <= current->vps_max_layer_id; j++)
422  flags(layer_id_included_flag[i][j], 2, i, j);
423  }
424  for (j = 0; j <= current->vps_max_layer_id; j++)
425  infer(layer_id_included_flag[0][j], j == 0);
426 
427  flag(vps_timing_info_present_flag);
428  if (current->vps_timing_info_present_flag) {
429  u(32, vps_num_units_in_tick, 1, UINT32_MAX);
430  u(32, vps_time_scale, 1, UINT32_MAX);
431  flag(vps_poc_proportional_to_timing_flag);
432  if (current->vps_poc_proportional_to_timing_flag)
433  ue(vps_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
434  ue(vps_num_hrd_parameters, 0, current->vps_num_layer_sets_minus1 + 1);
435  for (i = 0; i < current->vps_num_hrd_parameters; i++) {
436  ues(hrd_layer_set_idx[i],
437  current->vps_base_layer_internal_flag ? 0 : 1,
438  current->vps_num_layer_sets_minus1, 1, i);
439  if (i > 0)
440  flags(cprms_present_flag[i], 1, i);
441  else
442  infer(cprms_present_flag[0], 1);
443 
444  CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters[i],
445  current->cprms_present_flag[i],
446  current->vps_max_sub_layers_minus1));
447  }
448  }
449 
450  flag(vps_extension_flag);
451  if (current->vps_extension_flag)
452  CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
453 
455 
456  return 0;
457 }
458 
460  H265RawSTRefPicSet *current, int st_rps_idx,
461  const H265RawSPS *sps)
462 {
463  int err, i, j;
464 
465  if (st_rps_idx != 0)
466  flag(inter_ref_pic_set_prediction_flag);
467  else
468  infer(inter_ref_pic_set_prediction_flag, 0);
469 
470  if (current->inter_ref_pic_set_prediction_flag) {
471  unsigned int ref_rps_idx, num_delta_pocs;
472  const H265RawSTRefPicSet *ref;
473  int delta_rps, d_poc;
474  int ref_delta_poc_s0[HEVC_MAX_REFS], ref_delta_poc_s1[HEVC_MAX_REFS];
475  int delta_poc_s0[HEVC_MAX_REFS], delta_poc_s1[HEVC_MAX_REFS];
476  uint8_t used_by_curr_pic_s0[HEVC_MAX_REFS],
477  used_by_curr_pic_s1[HEVC_MAX_REFS];
478 
479  if (st_rps_idx == sps->num_short_term_ref_pic_sets)
480  ue(delta_idx_minus1, 0, st_rps_idx - 1);
481  else
482  infer(delta_idx_minus1, 0);
483 
484  ref_rps_idx = st_rps_idx - (current->delta_idx_minus1 + 1);
485  ref = &sps->st_ref_pic_set[ref_rps_idx];
486  num_delta_pocs = ref->num_negative_pics + ref->num_positive_pics;
487 
488  flag(delta_rps_sign);
489  ue(abs_delta_rps_minus1, 0, INT16_MAX);
490  delta_rps = (1 - 2 * current->delta_rps_sign) *
491  (current->abs_delta_rps_minus1 + 1);
492 
493  for (j = 0; j <= num_delta_pocs; j++) {
494  flags(used_by_curr_pic_flag[j], 1, j);
495  if (!current->used_by_curr_pic_flag[j])
496  flags(use_delta_flag[j], 1, j);
497  else
498  infer(use_delta_flag[j], 1);
499  }
500 
501  // Since the stored form of an RPS here is actually the delta-step
502  // form used when inter_ref_pic_set_prediction_flag is not set, we
503  // need to reconstruct that here in order to be able to refer to
504  // the RPS later (which is required for parsing, because we don't
505  // even know what syntax elements appear without it). Therefore,
506  // this code takes the delta-step form of the reference set, turns
507  // it into the delta-array form, applies the prediction process of
508  // 7.4.8, converts the result back to the delta-step form, and
509  // stores that as the current set for future use. Note that the
510  // inferences here mean that writers using prediction will need
511  // to fill in the delta-step values correctly as well - since the
512  // whole RPS prediction process is somewhat overly sophisticated,
513  // this hopefully forms a useful check for them to ensure their
514  // predicted form actually matches what was intended rather than
515  // an onerous additional requirement.
516 
517  d_poc = 0;
518  for (i = 0; i < ref->num_negative_pics; i++) {
519  d_poc -= ref->delta_poc_s0_minus1[i] + 1;
520  ref_delta_poc_s0[i] = d_poc;
521  }
522  d_poc = 0;
523  for (i = 0; i < ref->num_positive_pics; i++) {
524  d_poc += ref->delta_poc_s1_minus1[i] + 1;
525  ref_delta_poc_s1[i] = d_poc;
526  }
527 
528  i = 0;
529  for (j = ref->num_positive_pics - 1; j >= 0; j--) {
530  d_poc = ref_delta_poc_s1[j] + delta_rps;
531  if (d_poc < 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
532  delta_poc_s0[i] = d_poc;
533  used_by_curr_pic_s0[i++] =
534  current->used_by_curr_pic_flag[ref->num_negative_pics + j];
535  }
536  }
537  if (delta_rps < 0 && current->use_delta_flag[num_delta_pocs]) {
538  delta_poc_s0[i] = delta_rps;
539  used_by_curr_pic_s0[i++] =
540  current->used_by_curr_pic_flag[num_delta_pocs];
541  }
542  for (j = 0; j < ref->num_negative_pics; j++) {
543  d_poc = ref_delta_poc_s0[j] + delta_rps;
544  if (d_poc < 0 && current->use_delta_flag[j]) {
545  delta_poc_s0[i] = d_poc;
546  used_by_curr_pic_s0[i++] = current->used_by_curr_pic_flag[j];
547  }
548  }
549 
550  if (i > 15)
551  return AVERROR_INVALIDDATA;
552  infer(num_negative_pics, i);
553  for (i = 0; i < current->num_negative_pics; i++) {
554  infer(delta_poc_s0_minus1[i],
555  -(delta_poc_s0[i] - (i == 0 ? 0 : delta_poc_s0[i - 1])) - 1);
556  infer(used_by_curr_pic_s0_flag[i], used_by_curr_pic_s0[i]);
557  }
558 
559  i = 0;
560  for (j = ref->num_negative_pics - 1; j >= 0; j--) {
561  d_poc = ref_delta_poc_s0[j] + delta_rps;
562  if (d_poc > 0 && current->use_delta_flag[j]) {
563  delta_poc_s1[i] = d_poc;
564  used_by_curr_pic_s1[i++] = current->used_by_curr_pic_flag[j];
565  }
566  }
567  if (delta_rps > 0 && current->use_delta_flag[num_delta_pocs]) {
568  delta_poc_s1[i] = delta_rps;
569  used_by_curr_pic_s1[i++] =
570  current->used_by_curr_pic_flag[num_delta_pocs];
571  }
572  for (j = 0; j < ref->num_positive_pics; j++) {
573  d_poc = ref_delta_poc_s1[j] + delta_rps;
574  if (d_poc > 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
575  delta_poc_s1[i] = d_poc;
576  used_by_curr_pic_s1[i++] =
577  current->used_by_curr_pic_flag[ref->num_negative_pics + j];
578  }
579  }
580 
581  if (i + current->num_negative_pics > 15)
582  return AVERROR_INVALIDDATA;
583  infer(num_positive_pics, i);
584  for (i = 0; i < current->num_positive_pics; i++) {
585  infer(delta_poc_s1_minus1[i],
586  delta_poc_s1[i] - (i == 0 ? 0 : delta_poc_s1[i - 1]) - 1);
587  infer(used_by_curr_pic_s1_flag[i], used_by_curr_pic_s1[i]);
588  }
589 
590  } else {
591  ue(num_negative_pics, 0, 15);
592  ue(num_positive_pics, 0, 15 - current->num_negative_pics);
593 
594  for (i = 0; i < current->num_negative_pics; i++) {
595  ues(delta_poc_s0_minus1[i], 0, INT16_MAX, 1, i);
596  flags(used_by_curr_pic_s0_flag[i], 1, i);
597  }
598 
599  for (i = 0; i < current->num_positive_pics; i++) {
600  ues(delta_poc_s1_minus1[i], 0, INT16_MAX, 1, i);
601  flags(used_by_curr_pic_s1_flag[i], 1, i);
602  }
603  }
604 
605  return 0;
606 }
607 
609  H265RawScalingList *current)
610 {
611  int sizeId, matrixId;
612  int err, n, i;
613 
614  for (sizeId = 0; sizeId < 4; sizeId++) {
615  for (matrixId = 0; matrixId < 6; matrixId += (sizeId == 3 ? 3 : 1)) {
616  flags(scaling_list_pred_mode_flag[sizeId][matrixId],
617  2, sizeId, matrixId);
618  if (!current->scaling_list_pred_mode_flag[sizeId][matrixId]) {
619  ues(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
620  0, sizeId == 3 ? matrixId / 3 : matrixId,
621  2, sizeId, matrixId);
622  } else {
623  n = FFMIN(64, 1 << (4 + (sizeId << 1)));
624  if (sizeId > 1) {
625  ses(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247,
626  2, sizeId - 2, matrixId);
627  }
628  for (i = 0; i < n; i++) {
629  ses(scaling_list_delta_coeff[sizeId][matrixId][i],
630  -128, +127, 3, sizeId, matrixId, i);
631  }
632  }
633  }
634  }
635 
636  return 0;
637 }
638 
640  H265RawSPS *current)
641 {
642  int err;
643 
644  flag(transform_skip_rotation_enabled_flag);
645  flag(transform_skip_context_enabled_flag);
646  flag(implicit_rdpcm_enabled_flag);
647  flag(explicit_rdpcm_enabled_flag);
648  flag(extended_precision_processing_flag);
649  flag(intra_smoothing_disabled_flag);
650  flag(high_precision_offsets_enabled_flag);
651  flag(persistent_rice_adaptation_enabled_flag);
652  flag(cabac_bypass_alignment_enabled_flag);
653 
654  return 0;
655 }
656 
658  H265RawSPS *current)
659 {
660  int err, comp, i;
661 
662  flag(sps_curr_pic_ref_enabled_flag);
663 
664  flag(palette_mode_enabled_flag);
665  if (current->palette_mode_enabled_flag) {
666  ue(palette_max_size, 0, 64);
667  ue(delta_palette_max_predictor_size, 0, 128);
668 
669  flag(sps_palette_predictor_initializer_present_flag);
670  if (current->sps_palette_predictor_initializer_present_flag) {
671  ue(sps_num_palette_predictor_initializer_minus1, 0, 127);
672  for (comp = 0; comp < (current->chroma_format_idc ? 3 : 1); comp++) {
673  int bit_depth = comp == 0 ? current->bit_depth_luma_minus8 + 8
674  : current->bit_depth_chroma_minus8 + 8;
675  for (i = 0; i <= current->sps_num_palette_predictor_initializer_minus1; i++)
676  us(bit_depth, sps_palette_predictor_initializers[comp][i],
677  0, MAX_UINT_BITS(bit_depth), 2, comp, i);
678  }
679  }
680  }
681 
682  u(2, motion_vector_resolution_control_idc, 0, 2);
683  flag(intra_boundary_filtering_disable_flag);
684 
685  return 0;
686 }
687 
689  H265RawSPS *current)
690 {
692  const H265RawVPS *vps;
693  int err, i;
694  unsigned int min_cb_log2_size_y, ctb_log2_size_y,
695  min_cb_size_y, min_tb_log2_size_y;
696 
697  HEADER("Sequence Parameter Set");
698 
699  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_SPS));
700 
701  u(4, sps_video_parameter_set_id, 0, 15);
702  h265->active_vps = vps = h265->vps[current->sps_video_parameter_set_id];
703 
704  u(3, sps_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS - 1);
705  flag(sps_temporal_id_nesting_flag);
706  if (vps) {
707  if (vps->vps_max_sub_layers_minus1 > current->sps_max_sub_layers_minus1) {
708  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
709  "sps_max_sub_layers_minus1 (%d) must be less than or equal to "
710  "vps_max_sub_layers_minus1 (%d).\n",
712  current->sps_max_sub_layers_minus1);
713  return AVERROR_INVALIDDATA;
714  }
715  if (vps->vps_temporal_id_nesting_flag &&
716  !current->sps_temporal_id_nesting_flag) {
717  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
718  "sps_temporal_id_nesting_flag must be 1 if "
719  "vps_temporal_id_nesting_flag is 1.\n");
720  return AVERROR_INVALIDDATA;
721  }
722  }
723 
724  CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
725  1, current->sps_max_sub_layers_minus1));
726 
727  ue(sps_seq_parameter_set_id, 0, 15);
728 
729  ue(chroma_format_idc, 0, 3);
730  if (current->chroma_format_idc == 3)
731  flag(separate_colour_plane_flag);
732  else
733  infer(separate_colour_plane_flag, 0);
734 
735  ue(pic_width_in_luma_samples, 1, HEVC_MAX_WIDTH);
736  ue(pic_height_in_luma_samples, 1, HEVC_MAX_HEIGHT);
737 
738  flag(conformance_window_flag);
739  if (current->conformance_window_flag) {
740  ue(conf_win_left_offset, 0, current->pic_width_in_luma_samples);
741  ue(conf_win_right_offset, 0, current->pic_width_in_luma_samples);
742  ue(conf_win_top_offset, 0, current->pic_height_in_luma_samples);
743  ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples);
744  } else {
745  infer(conf_win_left_offset, 0);
746  infer(conf_win_right_offset, 0);
747  infer(conf_win_top_offset, 0);
748  infer(conf_win_bottom_offset, 0);
749  }
750 
751  ue(bit_depth_luma_minus8, 0, 8);
752  ue(bit_depth_chroma_minus8, 0, 8);
753 
754  ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
755 
756  flag(sps_sub_layer_ordering_info_present_flag);
757  for (i = (current->sps_sub_layer_ordering_info_present_flag ?
758  0 : current->sps_max_sub_layers_minus1);
759  i <= current->sps_max_sub_layers_minus1; i++) {
760  ues(sps_max_dec_pic_buffering_minus1[i],
761  0, HEVC_MAX_DPB_SIZE - 1, 1, i);
762  ues(sps_max_num_reorder_pics[i],
763  0, current->sps_max_dec_pic_buffering_minus1[i], 1, i);
764  ues(sps_max_latency_increase_plus1[i],
765  0, UINT32_MAX - 1, 1, i);
766  }
767  if (!current->sps_sub_layer_ordering_info_present_flag) {
768  for (i = 0; i < current->sps_max_sub_layers_minus1; i++) {
769  infer(sps_max_dec_pic_buffering_minus1[i],
770  current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]);
771  infer(sps_max_num_reorder_pics[i],
772  current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]);
773  infer(sps_max_latency_increase_plus1[i],
774  current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]);
775  }
776  }
777 
778  ue(log2_min_luma_coding_block_size_minus3, 0, 3);
779  min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3;
780 
781  ue(log2_diff_max_min_luma_coding_block_size, 0, 3);
782  ctb_log2_size_y = min_cb_log2_size_y +
783  current->log2_diff_max_min_luma_coding_block_size;
784 
785  min_cb_size_y = 1 << min_cb_log2_size_y;
786  if (current->pic_width_in_luma_samples % min_cb_size_y ||
787  current->pic_height_in_luma_samples % min_cb_size_y) {
788  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid dimensions: %ux%u not divisible "
789  "by MinCbSizeY = %u.\n", current->pic_width_in_luma_samples,
790  current->pic_height_in_luma_samples, min_cb_size_y);
791  return AVERROR_INVALIDDATA;
792  }
793 
794  ue(log2_min_luma_transform_block_size_minus2, 0, min_cb_log2_size_y - 3);
795  min_tb_log2_size_y = current->log2_min_luma_transform_block_size_minus2 + 2;
796 
797  ue(log2_diff_max_min_luma_transform_block_size,
798  0, FFMIN(ctb_log2_size_y, 5) - min_tb_log2_size_y);
799 
800  ue(max_transform_hierarchy_depth_inter,
801  0, ctb_log2_size_y - min_tb_log2_size_y);
802  ue(max_transform_hierarchy_depth_intra,
803  0, ctb_log2_size_y - min_tb_log2_size_y);
804 
805  flag(scaling_list_enabled_flag);
806  if (current->scaling_list_enabled_flag) {
807  flag(sps_scaling_list_data_present_flag);
808  if (current->sps_scaling_list_data_present_flag)
809  CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
810  } else {
811  infer(sps_scaling_list_data_present_flag, 0);
812  }
813 
814  flag(amp_enabled_flag);
815  flag(sample_adaptive_offset_enabled_flag);
816 
817  flag(pcm_enabled_flag);
818  if (current->pcm_enabled_flag) {
819  u(4, pcm_sample_bit_depth_luma_minus1,
820  0, current->bit_depth_luma_minus8 + 8 - 1);
821  u(4, pcm_sample_bit_depth_chroma_minus1,
822  0, current->bit_depth_chroma_minus8 + 8 - 1);
823 
824  ue(log2_min_pcm_luma_coding_block_size_minus3,
825  FFMIN(min_cb_log2_size_y, 5) - 3, FFMIN(ctb_log2_size_y, 5) - 3);
826  ue(log2_diff_max_min_pcm_luma_coding_block_size,
827  0, FFMIN(ctb_log2_size_y, 5) - (current->log2_min_pcm_luma_coding_block_size_minus3 + 3));
828 
829  flag(pcm_loop_filter_disabled_flag);
830  }
831 
832  ue(num_short_term_ref_pic_sets, 0, HEVC_MAX_SHORT_TERM_REF_PIC_SETS);
833  for (i = 0; i < current->num_short_term_ref_pic_sets; i++)
834  CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->st_ref_pic_set[i], i, current));
835 
836  flag(long_term_ref_pics_present_flag);
837  if (current->long_term_ref_pics_present_flag) {
838  ue(num_long_term_ref_pics_sps, 0, HEVC_MAX_LONG_TERM_REF_PICS);
839  for (i = 0; i < current->num_long_term_ref_pics_sps; i++) {
840  us(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
841  lt_ref_pic_poc_lsb_sps[i],
842  0, MAX_UINT_BITS(current->log2_max_pic_order_cnt_lsb_minus4 + 4), 1, i);
843  flags(used_by_curr_pic_lt_sps_flag[i], 1, i);
844  }
845  }
846 
847  flag(sps_temporal_mvp_enabled_flag);
848  flag(strong_intra_smoothing_enabled_flag);
849 
850  flag(vui_parameters_present_flag);
851  if (current->vui_parameters_present_flag)
852  CHECK(FUNC(vui_parameters)(ctx, rw, &current->vui, current));
853 
854  flag(sps_extension_present_flag);
855  if (current->sps_extension_present_flag) {
856  flag(sps_range_extension_flag);
857  flag(sps_multilayer_extension_flag);
858  flag(sps_3d_extension_flag);
859  flag(sps_scc_extension_flag);
860  u(4, sps_extension_4bits, 0, MAX_UINT_BITS(4));
861  }
862 
863  if (current->sps_range_extension_flag)
864  CHECK(FUNC(sps_range_extension)(ctx, rw, current));
865  if (current->sps_multilayer_extension_flag)
866  return AVERROR_PATCHWELCOME;
867  if (current->sps_3d_extension_flag)
868  return AVERROR_PATCHWELCOME;
869  if (current->sps_scc_extension_flag)
870  CHECK(FUNC(sps_scc_extension)(ctx, rw, current));
871  if (current->sps_extension_4bits)
872  CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
873 
875 
876  return 0;
877 }
878 
880  H265RawPPS *current)
881 {
883  const H265RawSPS *sps = h265->active_sps;
884  int err, i;
885 
886  if (current->transform_skip_enabled_flag)
887  ue(log2_max_transform_skip_block_size_minus2, 0, 3);
888  flag(cross_component_prediction_enabled_flag);
889 
890  flag(chroma_qp_offset_list_enabled_flag);
891  if (current->chroma_qp_offset_list_enabled_flag) {
892  ue(diff_cu_chroma_qp_offset_depth,
894  ue(chroma_qp_offset_list_len_minus1, 0, 5);
895  for (i = 0; i <= current->chroma_qp_offset_list_len_minus1; i++) {
896  ses(cb_qp_offset_list[i], -12, +12, 1, i);
897  ses(cr_qp_offset_list[i], -12, +12, 1, i);
898  }
899  }
900 
901  ue(log2_sao_offset_scale_luma, 0, FFMAX(0, sps->bit_depth_luma_minus8 - 2));
902  ue(log2_sao_offset_scale_chroma, 0, FFMAX(0, sps->bit_depth_chroma_minus8 - 2));
903 
904  return 0;
905 }
906 
908  H265RawPPS *current)
909 {
910  int err, comp, i;
911 
912  flag(pps_curr_pic_ref_enabled_flag);
913 
914  flag(residual_adaptive_colour_transform_enabled_flag);
915  if (current->residual_adaptive_colour_transform_enabled_flag) {
916  flag(pps_slice_act_qp_offsets_present_flag);
917  se(pps_act_y_qp_offset_plus5, -7, +17);
918  se(pps_act_cb_qp_offset_plus5, -7, +17);
919  se(pps_act_cr_qp_offset_plus3, -9, +15);
920  } else {
921  infer(pps_slice_act_qp_offsets_present_flag, 0);
922  infer(pps_act_y_qp_offset_plus5, 0);
923  infer(pps_act_cb_qp_offset_plus5, 0);
924  infer(pps_act_cr_qp_offset_plus3, 0);
925  }
926 
927  flag(pps_palette_predictor_initializer_present_flag);
928  if (current->pps_palette_predictor_initializer_present_flag) {
929  ue(pps_num_palette_predictor_initializer, 0, 128);
930  if (current->pps_num_palette_predictor_initializer > 0) {
931  flag(monochrome_palette_flag);
932  ue(luma_bit_depth_entry_minus8, 0, 8);
933  if (!current->monochrome_palette_flag)
934  ue(chroma_bit_depth_entry_minus8, 0, 8);
935  for (comp = 0; comp < (current->monochrome_palette_flag ? 1 : 3); comp++) {
936  int bit_depth = comp == 0 ? current->luma_bit_depth_entry_minus8 + 8
937  : current->chroma_bit_depth_entry_minus8 + 8;
938  for (i = 0; i < current->pps_num_palette_predictor_initializer; i++)
939  us(bit_depth, pps_palette_predictor_initializers[comp][i],
940  0, MAX_UINT_BITS(bit_depth), 2, comp, i);
941  }
942  }
943  }
944 
945  return 0;
946 }
947 
949  H265RawPPS *current)
950 {
952  const H265RawSPS *sps;
953  int err, i;
954 
955  HEADER("Picture Parameter Set");
956 
957  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_PPS));
958 
959  ue(pps_pic_parameter_set_id, 0, 63);
960  ue(pps_seq_parameter_set_id, 0, 15);
961  sps = h265->sps[current->pps_seq_parameter_set_id];
962  if (!sps) {
963  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
964  current->pps_seq_parameter_set_id);
965  return AVERROR_INVALIDDATA;
966  }
967  h265->active_sps = sps;
968 
969  flag(dependent_slice_segments_enabled_flag);
970  flag(output_flag_present_flag);
971  u(3, num_extra_slice_header_bits, 0, 7);
972  flag(sign_data_hiding_enabled_flag);
973  flag(cabac_init_present_flag);
974 
975  ue(num_ref_idx_l0_default_active_minus1, 0, 14);
976  ue(num_ref_idx_l1_default_active_minus1, 0, 14);
977 
978  se(init_qp_minus26, -(26 + 6 * sps->bit_depth_luma_minus8), +25);
979 
980  flag(constrained_intra_pred_flag);
981  flag(transform_skip_enabled_flag);
982  flag(cu_qp_delta_enabled_flag);
983  if (current->cu_qp_delta_enabled_flag)
984  ue(diff_cu_qp_delta_depth,
986  else
987  infer(diff_cu_qp_delta_depth, 0);
988 
989  se(pps_cb_qp_offset, -12, +12);
990  se(pps_cr_qp_offset, -12, +12);
991  flag(pps_slice_chroma_qp_offsets_present_flag);
992 
993  flag(weighted_pred_flag);
994  flag(weighted_bipred_flag);
995 
996  flag(transquant_bypass_enabled_flag);
997  flag(tiles_enabled_flag);
998  flag(entropy_coding_sync_enabled_flag);
999 
1000  if (current->tiles_enabled_flag) {
1001  ue(num_tile_columns_minus1, 0, HEVC_MAX_TILE_COLUMNS);
1002  ue(num_tile_rows_minus1, 0, HEVC_MAX_TILE_ROWS);
1003  flag(uniform_spacing_flag);
1004  if (!current->uniform_spacing_flag) {
1005  for (i = 0; i < current->num_tile_columns_minus1; i++)
1006  ues(column_width_minus1[i], 0, sps->pic_width_in_luma_samples, 1, i);
1007  for (i = 0; i < current->num_tile_rows_minus1; i++)
1008  ues(row_height_minus1[i], 0, sps->pic_height_in_luma_samples, 1, i);
1009  }
1010  flag(loop_filter_across_tiles_enabled_flag);
1011  } else {
1012  infer(num_tile_columns_minus1, 0);
1013  infer(num_tile_rows_minus1, 0);
1014  }
1015 
1016  flag(pps_loop_filter_across_slices_enabled_flag);
1017  flag(deblocking_filter_control_present_flag);
1018  if (current->deblocking_filter_control_present_flag) {
1019  flag(deblocking_filter_override_enabled_flag);
1020  flag(pps_deblocking_filter_disabled_flag);
1021  if (!current->pps_deblocking_filter_disabled_flag) {
1022  se(pps_beta_offset_div2, -6, +6);
1023  se(pps_tc_offset_div2, -6, +6);
1024  } else {
1025  infer(pps_beta_offset_div2, 0);
1026  infer(pps_tc_offset_div2, 0);
1027  }
1028  } else {
1029  infer(deblocking_filter_override_enabled_flag, 0);
1030  infer(pps_deblocking_filter_disabled_flag, 0);
1031  infer(pps_beta_offset_div2, 0);
1032  infer(pps_tc_offset_div2, 0);
1033  }
1034 
1035  flag(pps_scaling_list_data_present_flag);
1036  if (current->pps_scaling_list_data_present_flag)
1037  CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
1038 
1039  flag(lists_modification_present_flag);
1040 
1041  ue(log2_parallel_merge_level_minus2,
1044 
1045  flag(slice_segment_header_extension_present_flag);
1046 
1047  flag(pps_extension_present_flag);
1048  if (current->pps_extension_present_flag) {
1049  flag(pps_range_extension_flag);
1050  flag(pps_multilayer_extension_flag);
1051  flag(pps_3d_extension_flag);
1052  flag(pps_scc_extension_flag);
1053  u(4, pps_extension_4bits, 0, MAX_UINT_BITS(4));
1054  }
1055  if (current->pps_range_extension_flag)
1056  CHECK(FUNC(pps_range_extension)(ctx, rw, current));
1057  if (current->pps_multilayer_extension_flag)
1058  return AVERROR_PATCHWELCOME;
1059  if (current->pps_3d_extension_flag)
1060  return AVERROR_PATCHWELCOME;
1061  if (current->pps_scc_extension_flag)
1062  CHECK(FUNC(pps_scc_extension)(ctx, rw, current));
1063  if (current->pps_extension_4bits)
1064  CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1065 
1067 
1068  return 0;
1069 }
1070 
1072  H265RawAUD *current)
1073 {
1074  int err;
1075 
1076  HEADER("Access Unit Delimiter");
1077 
1078  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_AUD));
1079 
1080  u(3, pic_type, 0, 2);
1081 
1083 
1084  return 0;
1085 }
1086 
1088  H265RawSliceHeader *current,
1089  unsigned int num_pic_total_curr)
1090 {
1091  unsigned int entry_size;
1092  int err, i;
1093 
1094  entry_size = av_log2(num_pic_total_curr - 1) + 1;
1095 
1096  flag(ref_pic_list_modification_flag_l0);
1097  if (current->ref_pic_list_modification_flag_l0) {
1098  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++)
1099  us(entry_size, list_entry_l0[i], 0, num_pic_total_curr - 1, 1, i);
1100  }
1101 
1102  if (current->slice_type == HEVC_SLICE_B) {
1103  flag(ref_pic_list_modification_flag_l1);
1104  if (current->ref_pic_list_modification_flag_l1) {
1105  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++)
1106  us(entry_size, list_entry_l1[i], 0, num_pic_total_curr - 1, 1, i);
1107  }
1108  }
1109 
1110  return 0;
1111 }
1112 
1114  H265RawSliceHeader *current)
1115 {
1117  const H265RawSPS *sps = h265->active_sps;
1118  int err, i, j;
1119  int chroma = !sps->separate_colour_plane_flag &&
1120  sps->chroma_format_idc != 0;
1121 
1122  ue(luma_log2_weight_denom, 0, 7);
1123  if (chroma)
1124  se(delta_chroma_log2_weight_denom, -7, 7);
1125  else
1126  infer(delta_chroma_log2_weight_denom, 0);
1127 
1128  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1129  if (1 /* is not same POC and same layer_id */)
1130  flags(luma_weight_l0_flag[i], 1, i);
1131  else
1132  infer(luma_weight_l0_flag[i], 0);
1133  }
1134  if (chroma) {
1135  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1136  if (1 /* is not same POC and same layer_id */)
1137  flags(chroma_weight_l0_flag[i], 1, i);
1138  else
1139  infer(chroma_weight_l0_flag[i], 0);
1140  }
1141  }
1142 
1143  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1144  if (current->luma_weight_l0_flag[i]) {
1145  ses(delta_luma_weight_l0[i], -128, +127, 1, i);
1146  ses(luma_offset_l0[i],
1147  -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1148  ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1149  } else {
1150  infer(delta_luma_weight_l0[i], 0);
1151  infer(luma_offset_l0[i], 0);
1152  }
1153  if (current->chroma_weight_l0_flag[i]) {
1154  for (j = 0; j < 2; j++) {
1155  ses(delta_chroma_weight_l0[i][j], -128, +127, 2, i, j);
1156  ses(chroma_offset_l0[i][j],
1157  -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1158  ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1159  }
1160  } else {
1161  for (j = 0; j < 2; j++) {
1162  infer(delta_chroma_weight_l0[i][j], 0);
1163  infer(chroma_offset_l0[i][j], 0);
1164  }
1165  }
1166  }
1167 
1168  if (current->slice_type == HEVC_SLICE_B) {
1169  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1170  if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1171  flags(luma_weight_l1_flag[i], 1, i);
1172  else
1173  infer(luma_weight_l1_flag[i], 0);
1174  }
1175  if (chroma) {
1176  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1177  if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1178  flags(chroma_weight_l1_flag[i], 1, i);
1179  else
1180  infer(chroma_weight_l1_flag[i], 0);
1181  }
1182  }
1183 
1184  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1185  if (current->luma_weight_l1_flag[i]) {
1186  ses(delta_luma_weight_l1[i], -128, +127, 1, i);
1187  ses(luma_offset_l1[i],
1188  -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1189  ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1190  } else {
1191  infer(delta_luma_weight_l1[i], 0);
1192  infer(luma_offset_l1[i], 0);
1193  }
1194  if (current->chroma_weight_l1_flag[i]) {
1195  for (j = 0; j < 2; j++) {
1196  ses(delta_chroma_weight_l1[i][j], -128, +127, 2, i, j);
1197  ses(chroma_offset_l1[i][j],
1198  -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1199  ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1200  }
1201  } else {
1202  for (j = 0; j < 2; j++) {
1203  infer(delta_chroma_weight_l1[i][j], 0);
1204  infer(chroma_offset_l1[i][j], 0);
1205  }
1206  }
1207  }
1208  }
1209 
1210  return 0;
1211 }
1212 
1214  H265RawSliceHeader *current)
1215 {
1217  const H265RawSPS *sps;
1218  const H265RawPPS *pps;
1219  unsigned int min_cb_log2_size_y, ctb_log2_size_y, ctb_size_y;
1220  unsigned int pic_width_in_ctbs_y, pic_height_in_ctbs_y, pic_size_in_ctbs_y;
1221  unsigned int num_pic_total_curr = 0;
1222  int err, i;
1223 
1224  HEADER("Slice Segment Header");
1225 
1226  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, -1));
1227 
1228  flag(first_slice_segment_in_pic_flag);
1229 
1230  if (current->nal_unit_header.nal_unit_type >= HEVC_NAL_BLA_W_LP &&
1231  current->nal_unit_header.nal_unit_type <= HEVC_NAL_IRAP_VCL23)
1232  flag(no_output_of_prior_pics_flag);
1233 
1234  ue(slice_pic_parameter_set_id, 0, 63);
1235 
1236  pps = h265->pps[current->slice_pic_parameter_set_id];
1237  if (!pps) {
1238  av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
1239  current->slice_pic_parameter_set_id);
1240  return AVERROR_INVALIDDATA;
1241  }
1242  h265->active_pps = pps;
1243 
1244  sps = h265->sps[pps->pps_seq_parameter_set_id];
1245  if (!sps) {
1246  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1248  return AVERROR_INVALIDDATA;
1249  }
1250  h265->active_sps = sps;
1251 
1252  min_cb_log2_size_y = sps->log2_min_luma_coding_block_size_minus3 + 3;
1253  ctb_log2_size_y = min_cb_log2_size_y + sps->log2_diff_max_min_luma_coding_block_size;
1254  ctb_size_y = 1 << ctb_log2_size_y;
1255  pic_width_in_ctbs_y =
1256  (sps->pic_width_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1257  pic_height_in_ctbs_y =
1258  (sps->pic_height_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1259  pic_size_in_ctbs_y = pic_width_in_ctbs_y * pic_height_in_ctbs_y;
1260 
1261  if (!current->first_slice_segment_in_pic_flag) {
1262  unsigned int address_size = av_log2(pic_size_in_ctbs_y - 1) + 1;
1264  flag(dependent_slice_segment_flag);
1265  else
1266  infer(dependent_slice_segment_flag, 0);
1267  u(address_size, slice_segment_address, 0, pic_size_in_ctbs_y - 1);
1268  } else {
1269  infer(dependent_slice_segment_flag, 0);
1270  }
1271 
1272  if (!current->dependent_slice_segment_flag) {
1273  for (i = 0; i < pps->num_extra_slice_header_bits; i++)
1274  flags(slice_reserved_flag[i], 1, i);
1275 
1276  ue(slice_type, 0, 2);
1277 
1278  if (pps->output_flag_present_flag)
1279  flag(pic_output_flag);
1280 
1281  if (sps->separate_colour_plane_flag)
1282  u(2, colour_plane_id, 0, 2);
1283 
1284  if (current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_W_RADL &&
1285  current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_N_LP) {
1286  const H265RawSTRefPicSet *rps;
1287 
1288  u(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, slice_pic_order_cnt_lsb,
1290 
1291  flag(short_term_ref_pic_set_sps_flag);
1292  if (!current->short_term_ref_pic_set_sps_flag) {
1293  CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->short_term_ref_pic_set,
1294  sps->num_short_term_ref_pic_sets, sps));
1295  rps = &current->short_term_ref_pic_set;
1296  } else if (sps->num_short_term_ref_pic_sets > 1) {
1297  unsigned int idx_size = av_log2(sps->num_short_term_ref_pic_sets - 1) + 1;
1298  u(idx_size, short_term_ref_pic_set_idx,
1299  0, sps->num_short_term_ref_pic_sets - 1);
1300  rps = &sps->st_ref_pic_set[current->short_term_ref_pic_set_idx];
1301  } else {
1302  infer(short_term_ref_pic_set_idx, 0);
1303  rps = &sps->st_ref_pic_set[0];
1304  }
1305 
1306  num_pic_total_curr = 0;
1307  for (i = 0; i < rps->num_negative_pics; i++)
1308  if (rps->used_by_curr_pic_s0_flag[i])
1309  ++num_pic_total_curr;
1310  for (i = 0; i < rps->num_positive_pics; i++)
1311  if (rps->used_by_curr_pic_s1_flag[i])
1312  ++num_pic_total_curr;
1313 
1315  unsigned int idx_size;
1316 
1317  if (sps->num_long_term_ref_pics_sps > 0) {
1318  ue(num_long_term_sps, 0, sps->num_long_term_ref_pics_sps);
1319  idx_size = av_log2(sps->num_long_term_ref_pics_sps - 1) + 1;
1320  } else {
1321  infer(num_long_term_sps, 0);
1322  idx_size = 0;
1323  }
1324  ue(num_long_term_pics, 0, HEVC_MAX_REFS - current->num_long_term_sps);
1325 
1326  for (i = 0; i < current->num_long_term_sps +
1327  current->num_long_term_pics; i++) {
1328  if (i < current->num_long_term_sps) {
1329  if (sps->num_long_term_ref_pics_sps > 1)
1330  us(idx_size, lt_idx_sps[i],
1331  0, sps->num_long_term_ref_pics_sps - 1, 1, i);
1332  if (sps->used_by_curr_pic_lt_sps_flag[current->lt_idx_sps[i]])
1333  ++num_pic_total_curr;
1334  } else {
1335  us(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[i],
1337  flags(used_by_curr_pic_lt_flag[i], 1, i);
1338  if (current->used_by_curr_pic_lt_flag[i])
1339  ++num_pic_total_curr;
1340  }
1341  flags(delta_poc_msb_present_flag[i], 1, i);
1342  if (current->delta_poc_msb_present_flag[i])
1343  ues(delta_poc_msb_cycle_lt[i], 0, UINT32_MAX - 1, 1, i);
1344  else
1345  infer(delta_poc_msb_cycle_lt[i], 0);
1346  }
1347  }
1348 
1350  flag(slice_temporal_mvp_enabled_flag);
1351  else
1352  infer(slice_temporal_mvp_enabled_flag, 0);
1353 
1355  ++num_pic_total_curr;
1356  }
1357 
1359  flag(slice_sao_luma_flag);
1360  if (!sps->separate_colour_plane_flag && sps->chroma_format_idc != 0)
1361  flag(slice_sao_chroma_flag);
1362  else
1363  infer(slice_sao_chroma_flag, 0);
1364  } else {
1365  infer(slice_sao_luma_flag, 0);
1366  infer(slice_sao_chroma_flag, 0);
1367  }
1368 
1369  if (current->slice_type == HEVC_SLICE_P ||
1370  current->slice_type == HEVC_SLICE_B) {
1371  flag(num_ref_idx_active_override_flag);
1372  if (current->num_ref_idx_active_override_flag) {
1373  ue(num_ref_idx_l0_active_minus1, 0, 14);
1374  if (current->slice_type == HEVC_SLICE_B)
1375  ue(num_ref_idx_l1_active_minus1, 0, 14);
1376  else
1377  infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1378  } else {
1379  infer(num_ref_idx_l0_active_minus1, pps->num_ref_idx_l0_default_active_minus1);
1380  infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1381  }
1382 
1383  if (pps->lists_modification_present_flag && num_pic_total_curr > 1)
1384  CHECK(FUNC(ref_pic_lists_modification)(ctx, rw, current,
1385  num_pic_total_curr));
1386 
1387  if (current->slice_type == HEVC_SLICE_B)
1388  flag(mvd_l1_zero_flag);
1389  if (pps->cabac_init_present_flag)
1390  flag(cabac_init_flag);
1391  else
1392  infer(cabac_init_flag, 0);
1393  if (current->slice_temporal_mvp_enabled_flag) {
1394  if (current->slice_type == HEVC_SLICE_B)
1395  flag(collocated_from_l0_flag);
1396  else
1397  infer(collocated_from_l0_flag, 1);
1398  if (current->collocated_from_l0_flag) {
1399  if (current->num_ref_idx_l0_active_minus1 > 0)
1400  ue(collocated_ref_idx, 0, current->num_ref_idx_l0_active_minus1);
1401  else
1402  infer(collocated_ref_idx, 0);
1403  } else {
1404  if (current->num_ref_idx_l1_active_minus1 > 0)
1405  ue(collocated_ref_idx, 0, current->num_ref_idx_l1_active_minus1);
1406  else
1407  infer(collocated_ref_idx, 0);
1408  }
1409  }
1410 
1411  if ((pps->weighted_pred_flag && current->slice_type == HEVC_SLICE_P) ||
1412  (pps->weighted_bipred_flag && current->slice_type == HEVC_SLICE_B))
1413  CHECK(FUNC(pred_weight_table)(ctx, rw, current));
1414 
1415  ue(five_minus_max_num_merge_cand, 0, 4);
1417  flag(use_integer_mv_flag);
1418  else
1419  infer(use_integer_mv_flag, sps->motion_vector_resolution_control_idc);
1420  }
1421 
1422  se(slice_qp_delta,
1423  - 6 * sps->bit_depth_luma_minus8 - (pps->init_qp_minus26 + 26),
1424  + 51 - (pps->init_qp_minus26 + 26));
1426  se(slice_cb_qp_offset, -12, +12);
1427  se(slice_cr_qp_offset, -12, +12);
1428  } else {
1429  infer(slice_cb_qp_offset, 0);
1430  infer(slice_cr_qp_offset, 0);
1431  }
1433  se(slice_act_y_qp_offset,
1434  -12 - (pps->pps_act_y_qp_offset_plus5 - 5),
1435  +12 - (pps->pps_act_y_qp_offset_plus5 - 5));
1436  se(slice_act_cb_qp_offset,
1437  -12 - (pps->pps_act_cb_qp_offset_plus5 - 5),
1438  +12 - (pps->pps_act_cb_qp_offset_plus5 - 5));
1439  se(slice_act_cr_qp_offset,
1440  -12 - (pps->pps_act_cr_qp_offset_plus3 - 3),
1441  +12 - (pps->pps_act_cr_qp_offset_plus3 - 3));
1442  } else {
1443  infer(slice_act_y_qp_offset, 0);
1444  infer(slice_act_cb_qp_offset, 0);
1445  infer(slice_act_cr_qp_offset, 0);
1446  }
1448  flag(cu_chroma_qp_offset_enabled_flag);
1449  else
1450  infer(cu_chroma_qp_offset_enabled_flag, 0);
1451 
1453  flag(deblocking_filter_override_flag);
1454  else
1455  infer(deblocking_filter_override_flag, 0);
1456  if (current->deblocking_filter_override_flag) {
1457  flag(slice_deblocking_filter_disabled_flag);
1458  if (!current->slice_deblocking_filter_disabled_flag) {
1459  se(slice_beta_offset_div2, -6, +6);
1460  se(slice_tc_offset_div2, -6, +6);
1461  } else {
1462  infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1463  infer(slice_tc_offset_div2, pps->pps_tc_offset_div2);
1464  }
1465  } else {
1466  infer(slice_deblocking_filter_disabled_flag,
1468  infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1469  infer(slice_tc_offset_div2, pps->pps_tc_offset_div2);
1470  }
1472  (current->slice_sao_luma_flag || current->slice_sao_chroma_flag ||
1473  !current->slice_deblocking_filter_disabled_flag))
1474  flag(slice_loop_filter_across_slices_enabled_flag);
1475  else
1476  infer(slice_loop_filter_across_slices_enabled_flag,
1478  }
1479 
1481  unsigned int num_entry_point_offsets_limit;
1483  num_entry_point_offsets_limit = pic_height_in_ctbs_y - 1;
1485  num_entry_point_offsets_limit =
1486  (pps->num_tile_columns_minus1 + 1) * (pps->num_tile_rows_minus1 + 1);
1487  else
1488  num_entry_point_offsets_limit =
1489  (pps->num_tile_columns_minus1 + 1) * pic_height_in_ctbs_y - 1;
1490  ue(num_entry_point_offsets, 0, num_entry_point_offsets_limit);
1491 
1492  if (current->num_entry_point_offsets > HEVC_MAX_ENTRY_POINT_OFFSETS) {
1493  av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
1494  "%"PRIu16".\n", current->num_entry_point_offsets);
1495  return AVERROR_PATCHWELCOME;
1496  }
1497 
1498  if (current->num_entry_point_offsets > 0) {
1499  ue(offset_len_minus1, 0, 31);
1500  for (i = 0; i < current->num_entry_point_offsets; i++)
1501  us(current->offset_len_minus1 + 1, entry_point_offset_minus1[i],
1502  0, MAX_UINT_BITS(current->offset_len_minus1 + 1), 1, i);
1503  }
1504  }
1505 
1507  ue(slice_segment_header_extension_length, 0, 256);
1508  for (i = 0; i < current->slice_segment_header_extension_length; i++)
1509  us(8, slice_segment_header_extension_data_byte[i], 0x00, 0xff, 1, i);
1510  }
1511 
1512  CHECK(FUNC(byte_alignment)(ctx, rw));
1513 
1514  return 0;
1515 }
1516 
1519 {
1520  int err, c;
1521 
1522  for (c = 0; c < 3; c++) {
1523  us(16, display_primaries_x[c], 0, 50000, 1, c);
1524  us(16, display_primaries_y[c], 0, 50000, 1, c);
1525  }
1526 
1527  u(16, white_point_x, 0, 50000);
1528  u(16, white_point_y, 0, 50000);
1529 
1530  u(32, max_display_mastering_luminance,
1531  1, MAX_UINT_BITS(32));
1532  u(32, min_display_mastering_luminance,
1533  0, current->max_display_mastering_luminance - 1);
1534 
1535  return 0;
1536 }
1537 
1540 {
1541  int err;
1542 
1543  u(16, max_content_light_level, 0, MAX_UINT_BITS(16));
1544  u(16, max_pic_average_light_level, 0, MAX_UINT_BITS(16));
1545 
1546  return 0;
1547 }
1548 
1550  H265RawSEIPayload *current)
1551 {
1552  int err, i;
1553  int start_position, end_position;
1554 
1555 #ifdef READ
1556  start_position = get_bits_count(rw);
1557 #else
1558  start_position = put_bits_count(rw);
1559 #endif
1560 
1561  switch (current->payload_type) {
1564  (ctx, rw, &current->payload.mastering_display));
1565 
1566  break;
1567 
1570  (ctx, rw, &current->payload.content_light_level));
1571 
1572  break;
1573 
1574  default:
1575  {
1576 #ifdef READ
1577  current->payload.other.data_length = current->payload_size;
1578 #endif
1579  allocate(current->payload.other.data, current->payload.other.data_length);
1580 
1581  for (i = 0; i < current->payload_size; i++)
1582  xu(8, payload_byte[i], current->payload.other.data[i], 0, 255,
1583  1, i);
1584  }
1585  }
1586 
1587  if (byte_alignment(rw)) {
1588  fixed(1, bit_equal_to_one, 1);
1589  while (byte_alignment(rw))
1590  fixed(1, bit_equal_to_zero, 0);
1591  }
1592 
1593 #ifdef READ
1594  end_position = get_bits_count(rw);
1595  if (end_position < start_position + 8 * current->payload_size) {
1596  av_log(ctx->log_ctx, AV_LOG_ERROR, "Incorrect SEI payload length: "
1597  "header %"PRIu32" bits, actually %d bits.\n",
1598  8 * current->payload_size,
1599  end_position - start_position);
1600  return AVERROR_INVALIDDATA;
1601  }
1602 #else
1603  end_position = put_bits_count(rw);
1604  current->payload_size = (end_position - start_position) >> 3;
1605 #endif
1606 
1607  return 0;
1608 }
1609 
1611  H265RawSEI *current)
1612 {
1613  int err, k;
1614 
1615  HEADER("Supplemental Enhancement Information");
1616 
1617  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
1619 
1620 #ifdef READ
1621  for (k = 0; k < H265_MAX_SEI_PAYLOADS; k++) {
1622  uint32_t payload_type = 0;
1623  uint32_t payload_size = 0;
1624  uint32_t tmp;
1625 
1626  while (show_bits(rw, 8) == 0xff) {
1627  fixed(8, ff_byte, 0xff);
1628  payload_type += 255;
1629  }
1630  xu(8, last_payload_type_byte, tmp, 0, 254, 0);
1631  payload_type += tmp;
1632 
1633  while (show_bits(rw, 8) == 0xff) {
1634  fixed(8, ff_byte, 0xff);
1635  payload_size += 255;
1636  }
1637  xu(8, last_payload_size_byte, tmp, 0, 254, 0);
1638  payload_size += tmp;
1639 
1640  current->payload[k].payload_type = payload_type;
1641  current->payload[k].payload_size = payload_size;
1642 
1643  CHECK(FUNC(sei_payload)(ctx, rw, &current->payload[k]));
1644 
1646  break;
1647  }
1648  if (k >= H265_MAX_SEI_PAYLOADS) {
1649  av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many payloads in "
1650  "SEI message: found %d.\n", k);
1651  return AVERROR_INVALIDDATA;
1652  }
1653  current->payload_count = k + 1;
1654 #else
1655  for (k = 0; k < current->payload_count; k++) {
1656  PutBitContext start_state;
1657  uint32_t tmp;
1658  int need_size, i;
1659 
1660  // Somewhat clumsy: we write the payload twice when
1661  // we don't know the size in advance. This will mess
1662  // with trace output, but is otherwise harmless.
1663  start_state = *rw;
1664  need_size = !current->payload[k].payload_size;
1665  for (i = 0; i < 1 + need_size; i++) {
1666  *rw = start_state;
1667 
1668  tmp = current->payload[k].payload_type;
1669  while (tmp >= 255) {
1670  fixed(8, ff_byte, 0xff);
1671  tmp -= 255;
1672  }
1673  xu(8, last_payload_type_byte, tmp, 0, 254, 0);
1674 
1675  tmp = current->payload[k].payload_size;
1676  while (tmp >= 255) {
1677  fixed(8, ff_byte, 0xff);
1678  tmp -= 255;
1679  }
1680  xu(8, last_payload_size_byte, tmp, 0, 254, 0);
1681 
1682  CHECK(FUNC(sei_payload)(ctx, rw, &current->payload[k]));
1683  }
1684  }
1685 #endif
1686 
1688 
1689  return 0;
1690 }
#define allocate(name, size)
Definition: cbs_h2645.c:405
H265RawPPS * pps[HEVC_MAX_PPS_COUNT]
Definition: cbs_h265.h:573
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static int FUNC() byte_alignment(CodedBitstreamContext *ctx, RWContext *rw)
#define se(name, range_min, range_max)
Definition: cbs_h2645.c:260
uint8_t deblocking_filter_override_enabled_flag
Definition: cbs_h265.h:373
static int FUNC() sei_content_light_level(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIContentLightLevelInfo *current)
uint8_t num_ref_idx_l0_default_active_minus1
Definition: cbs_h265.h:343
#define fixed(width, name, value)
Definition: cbs_av1.c:615
static int FUNC() sub_layer_hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H265RawHRDParameters *hrd, int nal, int sub_layer_id)
uint8_t chroma_qp_offset_list_enabled_flag
Definition: cbs_h265.h:398
uint8_t bit_depth_luma_minus8
Definition: cbs_h265.h:253
static int FUNC() sps_scc_extension(CodedBitstreamContext *ctx, RWContext *rw, H265RawSPS *current)
static int FUNC() pred_weight_table(CodedBitstreamContext *ctx, RWContext *rw, H265RawSliceHeader *current)
int8_t pps_act_y_qp_offset_plus5
Definition: cbs_h265.h:410
#define RWContext
Definition: cbs_av1.c:710
static int FUNC() hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H265RawHRDParameters *current, int common_inf_present_flag, int max_num_sub_layers_minus1)
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:263
uint8_t tiles_enabled_flag
Definition: cbs_h265.h:361
H265RawSTRefPicSet st_ref_pic_set[HEVC_MAX_SHORT_TERM_REF_PIC_SETS]
Definition: cbs_h265.h:285
static int FUNC() slice_segment_header(CodedBitstreamContext *ctx, RWContext *rw, H265RawSliceHeader *current)
uint8_t pps_slice_chroma_qp_offsets_present_flag
Definition: cbs_h265.h:355
static int FUNC() pps_scc_extension(CodedBitstreamContext *ctx, RWContext *rw, H265RawPPS *current)
uint8_t sample_adaptive_offset_enabled_flag
Definition: cbs_h265.h:275
uint8_t bit_depth_chroma_minus8
Definition: cbs_h265.h:254
uint8_t used_by_curr_pic_s0_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:217
static int FUNC() extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawPSExtensionData *current)
uint16_t pic_height_in_luma_samples
Definition: cbs_h265.h:245
static int FUNC() pps_range_extension(CodedBitstreamContext *ctx, RWContext *rw, H265RawPPS *current)
uint8_t
static int FUNC() ref_pic_lists_modification(CodedBitstreamContext *ctx, RWContext *rw, H265RawSliceHeader *current, unsigned int num_pic_total_curr)
#define HEADER(name)
Definition: cbs_av1.c:582
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:96
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:253
uint8_t log2_max_pic_order_cnt_lsb_minus4
Definition: cbs_h265.h:256
H265RawSPS * sps[HEVC_MAX_SPS_COUNT]
Definition: cbs_h265.h:572
static int FUNC() vui_parameters(CodedBitstreamContext *ctx, RWContext *rw, H265RawVUI *current, const H265RawSPS *sps)
#define ses(name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:271
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
uint8_t vps_max_sub_layers_minus1
Definition: cbs_h265.h:176
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEI *current)
#define av_log(a,...)
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:258
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
uint8_t pps_slice_act_qp_offsets_present_flag
Definition: cbs_h265.h:409
static int FUNC() st_ref_pic_set(CodedBitstreamContext *ctx, RWContext *rw, H265RawSTRefPicSet *current, int st_rps_idx, const H265RawSPS *sps)
#define FUNC(a)
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)
Definition: vf_waveform.c:1511
#define ue(name, range_min, range_max)
Definition: cbs_h2645.c:256
uint8_t num_negative_pics
Definition: cbs_h265.h:214
#define FFMAX(a, b)
Definition: common.h:94
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
uint8_t motion_vector_resolution_control_idc
Definition: cbs_h265.h:327
static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
#define FFMIN(a, b)
Definition: common.h:96
#define profile_compatible(x)
static int FUNC() sei_mastering_display(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIMasteringDisplayColourVolume *current)
uint8_t num_long_term_ref_pics_sps
Definition: cbs_h265.h:288
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:155
int8_t pps_beta_offset_div2
Definition: cbs_h265.h:375
uint8_t pps_deblocking_filter_disabled_flag
Definition: cbs_h265.h:374
AVFormatContext * ctx
Definition: movenc.c:48
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H265RawPPS *current)
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:443
uint16_t pic_width_in_luma_samples
Definition: cbs_h265.h:244
int n
Definition: avisynth_c.h:684
uint8_t lists_modification_present_flag
Definition: cbs_h265.h:381
uint8_t log2_min_luma_coding_block_size_minus3
Definition: cbs_h265.h:263
uint8_t pps_seq_parameter_set_id
Definition: cbs_h265.h:335
uint8_t cabac_init_present_flag
Definition: cbs_h265.h:341
#define av_log2
Definition: intmath.h:83
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:83
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H265RawAUD *current)
uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:219
uint8_t num_extra_slice_header_bits
Definition: cbs_h265.h:339
const H265RawSPS * active_sps
Definition: cbs_h265.h:579
static int FUNC() scaling_list_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawScalingList *current)
uint8_t entropy_coding_sync_enabled_flag
Definition: cbs_h265.h:362
uint8_t output_flag_present_flag
Definition: cbs_h265.h:338
uint8_t weighted_bipred_flag
Definition: cbs_h265.h:358
uint8_t dependent_slice_segments_enabled_flag
Definition: cbs_h265.h:337
uint8_t sps_temporal_mvp_enabled_flag
Definition: cbs_h265.h:292
#define xu(width, name, var, range_min, range_max, subs,...)
Definition: cbs_h2645.c:367
uint8_t pps_loop_filter_across_slices_enabled_flag
Definition: cbs_h265.h:371
uint8_t weighted_pred_flag
Definition: cbs_h265.h:357
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:460
Context structure for coded bitstream operations.
Definition: cbs.h:159
CHECK(-1) CHECK(-2) }} }} CHECK(1) CHECK(2) }} }} } if(diff0+diff1 > 0) temp -
const H265RawVPS * active_vps
Definition: cbs_h265.h:578
static int FUNC() profile_tier_level(CodedBitstreamContext *ctx, RWContext *rw, H265RawProfileTierLevel *current, int profile_present_flag, int max_num_sub_layers_minus1)
uint8_t chroma_format_idc
Definition: cbs_h265.h:241
static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
Definition: cbs_h2645.c:318
const H265RawPPS * active_pps
Definition: cbs_h265.h:580
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
#define flags(name, subs,...)
Definition: cbs_av1.c:610
uint8_t num_positive_pics
Definition: cbs_h265.h:215
static int FUNC() sei_payload(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIPayload *current)
static int FUNC() nal_unit_header(CodedBitstreamContext *ctx, RWContext *rw, H265RawNALUnitHeader *current, int expected_nal_unit_type)
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
#define flag(name)
Definition: cbs_av1.c:602
static double c[64]
uint8_t num_tile_rows_minus1
Definition: cbs_h265.h:365
int8_t pps_act_cb_qp_offset_plus5
Definition: cbs_h265.h:411
uint8_t num_tile_columns_minus1
Definition: cbs_h265.h:364
uint8_t log2_diff_max_min_luma_coding_block_size
Definition: cbs_h265.h:264
uint8_t used_by_curr_pic_lt_sps_flag[HEVC_MAX_LONG_TERM_REF_PICS]
Definition: cbs_h265.h:290
void * priv_data
Format private data.
Definition: avformat.h:1379
uint8_t num_short_term_ref_pic_sets
Definition: cbs_h265.h:284
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H265RawSPS *current)
uint8_t vps_temporal_id_nesting_flag
Definition: cbs_h265.h:177
int8_t pps_tc_offset_div2
Definition: cbs_h265.h:376
void INT64 start
Definition: avisynth_c.h:690
static int FUNC() sps_range_extension(CodedBitstreamContext *ctx, RWContext *rw, H265RawSPS *current)
int8_t init_qp_minus26
Definition: cbs_h265.h:346
uint8_t pps_curr_pic_ref_enabled_flag
Definition: cbs_h265.h:407
uint8_t slice_segment_header_extension_present_flag
Definition: cbs_h265.h:384
#define infer(name, value)
Definition: cbs_av1.c:755
H265RawVPS * vps[HEVC_MAX_VPS_COUNT]
Definition: cbs_h265.h:571
uint8_t separate_colour_plane_flag
Definition: cbs_h265.h:242
static int FUNC() rbsp_trailing_bits(CodedBitstreamContext *ctx, RWContext *rw)
uint8_t long_term_ref_pics_present_flag
Definition: cbs_h265.h:287
#define ues(name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:267
int8_t pps_act_cr_qp_offset_plus3
Definition: cbs_h265.h:412
uint8_t num_ref_idx_l1_default_active_minus1
Definition: cbs_h265.h:344
static uint8_t tmp[11]
Definition: aes_ctr.c:26