FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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), 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  infer(num_negative_pics, i);
551  for (i = 0; i < current->num_negative_pics; i++) {
552  infer(delta_poc_s0_minus1[i],
553  -(delta_poc_s0[i] - (i == 0 ? 0 : delta_poc_s0[i - 1])) - 1);
554  infer(used_by_curr_pic_s0_flag[i], used_by_curr_pic_s0[i]);
555  }
556 
557  i = 0;
558  for (j = ref->num_negative_pics - 1; j >= 0; j--) {
559  d_poc = ref_delta_poc_s0[j] + delta_rps;
560  if (d_poc > 0 && current->use_delta_flag[j]) {
561  delta_poc_s1[i] = d_poc;
562  used_by_curr_pic_s1[i++] = current->used_by_curr_pic_flag[j];
563  }
564  }
565  if (delta_rps > 0 && current->use_delta_flag[num_delta_pocs]) {
566  delta_poc_s1[i] = delta_rps;
567  used_by_curr_pic_s1[i++] =
568  current->used_by_curr_pic_flag[num_delta_pocs];
569  }
570  for (j = 0; j < ref->num_positive_pics; j++) {
571  d_poc = ref_delta_poc_s1[j] + delta_rps;
572  if (d_poc > 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
573  delta_poc_s1[i] = d_poc;
574  used_by_curr_pic_s1[i++] =
575  current->used_by_curr_pic_flag[ref->num_negative_pics + j];
576  }
577  }
578 
579  infer(num_positive_pics, i);
580  for (i = 0; i < current->num_positive_pics; i++) {
581  infer(delta_poc_s1_minus1[i],
582  delta_poc_s1[i] - (i == 0 ? 0 : delta_poc_s1[i - 1]) - 1);
583  infer(used_by_curr_pic_s1_flag[i], used_by_curr_pic_s1[i]);
584  }
585 
586  } else {
587  ue(num_negative_pics, 0, 15);
588  ue(num_positive_pics, 0, 15 - current->num_negative_pics);
589 
590  for (i = 0; i < current->num_negative_pics; i++) {
591  ues(delta_poc_s0_minus1[i], 0, INT16_MAX, 1, i);
592  flags(used_by_curr_pic_s0_flag[i], 1, i);
593  }
594 
595  for (i = 0; i < current->num_positive_pics; i++) {
596  ues(delta_poc_s1_minus1[i], 0, INT16_MAX, 1, i);
597  flags(used_by_curr_pic_s1_flag[i], 1, i);
598  }
599  }
600 
601  return 0;
602 }
603 
605  H265RawScalingList *current)
606 {
607  int sizeId, matrixId;
608  int err, n, i;
609 
610  for (sizeId = 0; sizeId < 4; sizeId++) {
611  for (matrixId = 0; matrixId < 6; matrixId += (sizeId == 3 ? 3 : 1)) {
612  flags(scaling_list_pred_mode_flag[sizeId][matrixId],
613  2, sizeId, matrixId);
614  if (!current->scaling_list_pred_mode_flag[sizeId][matrixId]) {
615  ues(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
616  0, sizeId == 3 ? matrixId / 3 : matrixId,
617  2, sizeId, matrixId);
618  } else {
619  n = FFMIN(64, 1 << (4 + (sizeId << 1)));
620  if (sizeId > 1) {
621  ses(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247,
622  2, sizeId - 2, matrixId);
623  }
624  for (i = 0; i < n; i++) {
625  ses(scaling_list_delta_coeff[sizeId][matrixId][i],
626  -128, +127, 3, sizeId, matrixId, i);
627  }
628  }
629  }
630  }
631 
632  return 0;
633 }
634 
636  H265RawSPS *current)
637 {
638  int err;
639 
640  flag(transform_skip_rotation_enabled_flag);
641  flag(transform_skip_context_enabled_flag);
642  flag(implicit_rdpcm_enabled_flag);
643  flag(explicit_rdpcm_enabled_flag);
644  flag(extended_precision_processing_flag);
645  flag(intra_smoothing_disabled_flag);
646  flag(high_precision_offsets_enabled_flag);
647  flag(persistent_rice_adaptation_enabled_flag);
648  flag(cabac_bypass_alignment_enabled_flag);
649 
650  return 0;
651 }
652 
654  H265RawSPS *current)
655 {
656  int err, comp, i;
657 
658  flag(sps_curr_pic_ref_enabled_flag);
659 
660  flag(palette_mode_enabled_flag);
661  if (current->palette_mode_enabled_flag) {
662  ue(palette_max_size, 0, 64);
663  ue(delta_palette_max_predictor_size, 0, 128);
664 
665  flag(sps_palette_predictor_initializer_present_flag);
666  if (current->sps_palette_predictor_initializer_present_flag) {
667  ue(sps_num_palette_predictor_initializer_minus1, 0, 128);
668  for (comp = 0; comp < (current->chroma_format_idc ? 3 : 1); comp++) {
669  int bit_depth = comp == 0 ? current->bit_depth_luma_minus8 + 8
670  : current->bit_depth_chroma_minus8 + 8;
671  for (i = 0; i <= current->sps_num_palette_predictor_initializer_minus1; i++)
672  us(bit_depth, sps_palette_predictor_initializers[comp][i],
673  0, MAX_UINT_BITS(bit_depth), 2, comp, i);
674  }
675  }
676  }
677 
678  u(2, motion_vector_resolution_control_idc, 0, 2);
679  flag(intra_boundary_filtering_disable_flag);
680 
681  return 0;
682 }
683 
685  H265RawSPS *current)
686 {
688  const H265RawVPS *vps;
689  int err, i;
690  unsigned int min_cb_log2_size_y, ctb_log2_size_y,
691  min_cb_size_y, min_tb_log2_size_y;
692 
693  HEADER("Sequence Parameter Set");
694 
695  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_SPS));
696 
697  u(4, sps_video_parameter_set_id, 0, 15);
698  h265->active_vps = vps = h265->vps[current->sps_video_parameter_set_id];
699 
700  u(3, sps_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS - 1);
701  flag(sps_temporal_id_nesting_flag);
702  if (vps) {
703  if (vps->vps_max_sub_layers_minus1 > current->sps_max_sub_layers_minus1) {
704  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
705  "sps_max_sub_layers_minus1 (%d) must be less than or equal to "
706  "vps_max_sub_layers_minus1 (%d).\n",
708  current->sps_max_sub_layers_minus1);
709  return AVERROR_INVALIDDATA;
710  }
711  if (vps->vps_temporal_id_nesting_flag &&
712  !current->sps_temporal_id_nesting_flag) {
713  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
714  "sps_temporal_id_nesting_flag must be 1 if "
715  "vps_temporal_id_nesting_flag is 1.\n");
716  return AVERROR_INVALIDDATA;
717  }
718  }
719 
720  CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
721  1, current->sps_max_sub_layers_minus1));
722 
723  ue(sps_seq_parameter_set_id, 0, 15);
724 
725  ue(chroma_format_idc, 0, 3);
726  if (current->chroma_format_idc == 3)
727  flag(separate_colour_plane_flag);
728  else
729  infer(separate_colour_plane_flag, 0);
730 
731  ue(pic_width_in_luma_samples, 1, HEVC_MAX_WIDTH);
732  ue(pic_height_in_luma_samples, 1, HEVC_MAX_HEIGHT);
733 
734  flag(conformance_window_flag);
735  if (current->conformance_window_flag) {
736  ue(conf_win_left_offset, 0, current->pic_width_in_luma_samples);
737  ue(conf_win_right_offset, 0, current->pic_width_in_luma_samples);
738  ue(conf_win_top_offset, 0, current->pic_height_in_luma_samples);
739  ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples);
740  } else {
741  infer(conf_win_left_offset, 0);
742  infer(conf_win_right_offset, 0);
743  infer(conf_win_top_offset, 0);
744  infer(conf_win_bottom_offset, 0);
745  }
746 
747  ue(bit_depth_luma_minus8, 0, 8);
748  ue(bit_depth_chroma_minus8, 0, 8);
749 
750  ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
751 
752  flag(sps_sub_layer_ordering_info_present_flag);
753  for (i = (current->sps_sub_layer_ordering_info_present_flag ?
754  0 : current->sps_max_sub_layers_minus1);
755  i <= current->sps_max_sub_layers_minus1; i++) {
756  ues(sps_max_dec_pic_buffering_minus1[i],
757  0, HEVC_MAX_DPB_SIZE - 1, 1, i);
758  ues(sps_max_num_reorder_pics[i],
759  0, current->sps_max_dec_pic_buffering_minus1[i], 1, i);
760  ues(sps_max_latency_increase_plus1[i],
761  0, UINT32_MAX - 1, 1, i);
762  }
763  if (!current->sps_sub_layer_ordering_info_present_flag) {
764  for (i = 0; i < current->sps_max_sub_layers_minus1; i++) {
765  infer(sps_max_dec_pic_buffering_minus1[i],
766  current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]);
767  infer(sps_max_num_reorder_pics[i],
768  current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]);
769  infer(sps_max_latency_increase_plus1[i],
770  current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]);
771  }
772  }
773 
774  ue(log2_min_luma_coding_block_size_minus3, 0, 3);
775  min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3;
776 
777  ue(log2_diff_max_min_luma_coding_block_size, 0, 3);
778  ctb_log2_size_y = min_cb_log2_size_y +
779  current->log2_diff_max_min_luma_coding_block_size;
780 
781  min_cb_size_y = 1 << min_cb_log2_size_y;
782  if (current->pic_width_in_luma_samples % min_cb_size_y ||
783  current->pic_height_in_luma_samples % min_cb_size_y) {
784  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid dimensions: %ux%u not divisible "
785  "by MinCbSizeY = %u.\n", current->pic_width_in_luma_samples,
786  current->pic_height_in_luma_samples, min_cb_size_y);
787  return AVERROR_INVALIDDATA;
788  }
789 
790  ue(log2_min_luma_transform_block_size_minus2, 0, min_cb_log2_size_y - 3);
791  min_tb_log2_size_y = current->log2_min_luma_transform_block_size_minus2 + 2;
792 
793  ue(log2_diff_max_min_luma_transform_block_size,
794  0, FFMIN(ctb_log2_size_y, 5) - min_tb_log2_size_y);
795 
796  ue(max_transform_hierarchy_depth_inter,
797  0, ctb_log2_size_y - min_tb_log2_size_y);
798  ue(max_transform_hierarchy_depth_intra,
799  0, ctb_log2_size_y - min_tb_log2_size_y);
800 
801  flag(scaling_list_enabled_flag);
802  if (current->scaling_list_enabled_flag) {
803  flag(sps_scaling_list_data_present_flag);
804  if (current->sps_scaling_list_data_present_flag)
805  CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
806  } else {
807  infer(sps_scaling_list_data_present_flag, 0);
808  }
809 
810  flag(amp_enabled_flag);
811  flag(sample_adaptive_offset_enabled_flag);
812 
813  flag(pcm_enabled_flag);
814  if (current->pcm_enabled_flag) {
815  u(4, pcm_sample_bit_depth_luma_minus1,
816  0, current->bit_depth_luma_minus8 + 8 - 1);
817  u(4, pcm_sample_bit_depth_chroma_minus1,
818  0, current->bit_depth_chroma_minus8 + 8 - 1);
819 
820  ue(log2_min_pcm_luma_coding_block_size_minus3,
821  FFMIN(min_cb_log2_size_y, 5) - 3, FFMIN(ctb_log2_size_y, 5) - 3);
822  ue(log2_diff_max_min_pcm_luma_coding_block_size,
823  0, FFMIN(ctb_log2_size_y, 5) - (current->log2_min_pcm_luma_coding_block_size_minus3 + 3));
824 
825  flag(pcm_loop_filter_disabled_flag);
826  }
827 
828  ue(num_short_term_ref_pic_sets, 0, HEVC_MAX_SHORT_TERM_REF_PIC_SETS);
829  for (i = 0; i < current->num_short_term_ref_pic_sets; i++)
830  CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->st_ref_pic_set[i], i, current));
831 
832  flag(long_term_ref_pics_present_flag);
833  if (current->long_term_ref_pics_present_flag) {
834  ue(num_long_term_ref_pics_sps, 0, HEVC_MAX_LONG_TERM_REF_PICS);
835  for (i = 0; i < current->num_long_term_ref_pics_sps; i++) {
836  us(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
837  lt_ref_pic_poc_lsb_sps[i],
838  0, MAX_UINT_BITS(current->log2_max_pic_order_cnt_lsb_minus4 + 4), 1, i);
839  flags(used_by_curr_pic_lt_sps_flag[i], 1, i);
840  }
841  }
842 
843  flag(sps_temporal_mvp_enabled_flag);
844  flag(strong_intra_smoothing_enabled_flag);
845 
846  flag(vui_parameters_present_flag);
847  if (current->vui_parameters_present_flag)
848  CHECK(FUNC(vui_parameters)(ctx, rw, &current->vui, current));
849 
850  flag(sps_extension_present_flag);
851  if (current->sps_extension_present_flag) {
852  flag(sps_range_extension_flag);
853  flag(sps_multilayer_extension_flag);
854  flag(sps_3d_extension_flag);
855  flag(sps_scc_extension_flag);
856  u(4, sps_extension_4bits, 0, MAX_UINT_BITS(4));
857  }
858 
859  if (current->sps_range_extension_flag)
860  CHECK(FUNC(sps_range_extension)(ctx, rw, current));
861  if (current->sps_multilayer_extension_flag)
862  return AVERROR_PATCHWELCOME;
863  if (current->sps_3d_extension_flag)
864  return AVERROR_PATCHWELCOME;
865  if (current->sps_scc_extension_flag)
866  CHECK(FUNC(sps_scc_extension)(ctx, rw, current));
867  if (current->sps_extension_4bits)
868  CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
869 
871 
872  return 0;
873 }
874 
876  H265RawPPS *current)
877 {
879  const H265RawSPS *sps = h265->active_sps;
880  int err, i;
881 
882  if (current->transform_skip_enabled_flag)
883  ue(log2_max_transform_skip_block_size_minus2, 0, 3);
884  flag(cross_component_prediction_enabled_flag);
885 
886  flag(chroma_qp_offset_list_enabled_flag);
887  if (current->chroma_qp_offset_list_enabled_flag) {
888  ue(diff_cu_chroma_qp_offset_depth,
890  ue(chroma_qp_offset_list_len_minus1, 0, 5);
891  for (i = 0; i <= current->chroma_qp_offset_list_len_minus1; i++) {
892  ses(cb_qp_offset_list[i], -12, +12, 1, i);
893  ses(cr_qp_offset_list[i], -12, +12, 1, i);
894  }
895  }
896 
897  ue(log2_sao_offset_scale_luma, 0, FFMAX(0, sps->bit_depth_luma_minus8 - 2));
898  ue(log2_sao_offset_scale_chroma, 0, FFMAX(0, sps->bit_depth_chroma_minus8 - 2));
899 
900  return 0;
901 }
902 
904  H265RawPPS *current)
905 {
906  int err, comp, i;
907 
908  flag(pps_curr_pic_ref_enabled_flag);
909 
910  flag(residual_adaptive_colour_transform_enabled_flag);
911  if (current->residual_adaptive_colour_transform_enabled_flag) {
912  flag(pps_slice_act_qp_offsets_present_flag);
913  se(pps_act_y_qp_offset_plus5, -7, +17);
914  se(pps_act_cb_qp_offset_plus5, -7, +17);
915  se(pps_act_cr_qp_offset_plus3, -9, +15);
916  } else {
917  infer(pps_slice_act_qp_offsets_present_flag, 0);
918  infer(pps_act_y_qp_offset_plus5, 0);
919  infer(pps_act_cb_qp_offset_plus5, 0);
920  infer(pps_act_cr_qp_offset_plus3, 0);
921  }
922 
923  flag(pps_palette_predictor_initializer_present_flag);
924  if (current->pps_palette_predictor_initializer_present_flag) {
925  ue(pps_num_palette_predictor_initializer, 0, 128);
926  if (current->pps_num_palette_predictor_initializer > 0) {
927  flag(monochrome_palette_flag);
928  ue(luma_bit_depth_entry_minus8, 0, 8);
929  if (!current->monochrome_palette_flag)
930  ue(chroma_bit_depth_entry_minus8, 0, 8);
931  for (comp = 0; comp < (current->monochrome_palette_flag ? 1 : 3); comp++) {
932  int bit_depth = comp == 0 ? current->luma_bit_depth_entry_minus8 + 8
933  : current->chroma_bit_depth_entry_minus8 + 8;
934  for (i = 0; i < current->pps_num_palette_predictor_initializer; i++)
935  us(bit_depth, pps_palette_predictor_initializers[comp][i],
936  0, MAX_UINT_BITS(bit_depth), 2, comp, i);
937  }
938  }
939  }
940 
941  return 0;
942 }
943 
945  H265RawPPS *current)
946 {
948  const H265RawSPS *sps;
949  int err, i;
950 
951  HEADER("Picture Parameter Set");
952 
953  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_PPS));
954 
955  ue(pps_pic_parameter_set_id, 0, 63);
956  ue(pps_seq_parameter_set_id, 0, 15);
957  sps = h265->sps[current->pps_seq_parameter_set_id];
958  if (!sps) {
959  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
960  current->pps_seq_parameter_set_id);
961  return AVERROR_INVALIDDATA;
962  }
963  h265->active_sps = sps;
964 
965  flag(dependent_slice_segments_enabled_flag);
966  flag(output_flag_present_flag);
967  u(3, num_extra_slice_header_bits, 0, 7);
968  flag(sign_data_hiding_enabled_flag);
969  flag(cabac_init_present_flag);
970 
971  ue(num_ref_idx_l0_default_active_minus1, 0, 14);
972  ue(num_ref_idx_l1_default_active_minus1, 0, 14);
973 
974  se(init_qp_minus26, -(26 + 6 * sps->bit_depth_luma_minus8), +25);
975 
976  flag(constrained_intra_pred_flag);
977  flag(transform_skip_enabled_flag);
978  flag(cu_qp_delta_enabled_flag);
979  if (current->cu_qp_delta_enabled_flag)
980  ue(diff_cu_qp_delta_depth,
982  else
983  infer(diff_cu_qp_delta_depth, 0);
984 
985  se(pps_cb_qp_offset, -12, +12);
986  se(pps_cr_qp_offset, -12, +12);
987  flag(pps_slice_chroma_qp_offsets_present_flag);
988 
989  flag(weighted_pred_flag);
990  flag(weighted_bipred_flag);
991 
992  flag(transquant_bypass_enabled_flag);
993  flag(tiles_enabled_flag);
994  flag(entropy_coding_sync_enabled_flag);
995 
996  if (current->tiles_enabled_flag) {
997  ue(num_tile_columns_minus1, 0, HEVC_MAX_TILE_COLUMNS);
998  ue(num_tile_rows_minus1, 0, HEVC_MAX_TILE_ROWS);
999  flag(uniform_spacing_flag);
1000  if (!current->uniform_spacing_flag) {
1001  for (i = 0; i < current->num_tile_columns_minus1; i++)
1002  ues(column_width_minus1[i], 0, sps->pic_width_in_luma_samples, 1, i);
1003  for (i = 0; i < current->num_tile_rows_minus1; i++)
1004  ues(row_height_minus1[i], 0, sps->pic_height_in_luma_samples, 1, i);
1005  }
1006  flag(loop_filter_across_tiles_enabled_flag);
1007  } else {
1008  infer(num_tile_columns_minus1, 0);
1009  infer(num_tile_rows_minus1, 0);
1010  }
1011 
1012  flag(pps_loop_filter_across_slices_enabled_flag);
1013  flag(deblocking_filter_control_present_flag);
1014  if (current->deblocking_filter_control_present_flag) {
1015  flag(deblocking_filter_override_enabled_flag);
1016  flag(pps_deblocking_filter_disabled_flag);
1017  if (!current->pps_deblocking_filter_disabled_flag) {
1018  se(pps_beta_offset_div2, -6, +6);
1019  se(pps_tc_offset_div2, -6, +6);
1020  } else {
1021  infer(pps_beta_offset_div2, 0);
1022  infer(pps_tc_offset_div2, 0);
1023  }
1024  } else {
1025  infer(deblocking_filter_override_enabled_flag, 0);
1026  infer(pps_deblocking_filter_disabled_flag, 0);
1027  infer(pps_beta_offset_div2, 0);
1028  infer(pps_tc_offset_div2, 0);
1029  }
1030 
1031  flag(pps_scaling_list_data_present_flag);
1032  if (current->pps_scaling_list_data_present_flag)
1033  CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
1034 
1035  flag(lists_modification_present_flag);
1036 
1037  ue(log2_parallel_merge_level_minus2,
1040 
1041  flag(slice_segment_header_extension_present_flag);
1042 
1043  flag(pps_extension_present_flag);
1044  if (current->pps_extension_present_flag) {
1045  flag(pps_range_extension_flag);
1046  flag(pps_multilayer_extension_flag);
1047  flag(pps_3d_extension_flag);
1048  flag(pps_scc_extension_flag);
1049  u(4, pps_extension_4bits, 0, MAX_UINT_BITS(4));
1050  }
1051  if (current->pps_range_extension_flag)
1052  CHECK(FUNC(pps_range_extension)(ctx, rw, current));
1053  if (current->pps_multilayer_extension_flag)
1054  return AVERROR_PATCHWELCOME;
1055  if (current->pps_3d_extension_flag)
1056  return AVERROR_PATCHWELCOME;
1057  if (current->pps_scc_extension_flag)
1058  CHECK(FUNC(pps_scc_extension)(ctx, rw, current));
1059  if (current->pps_extension_4bits)
1060  CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1061 
1063 
1064  return 0;
1065 }
1066 
1068  H265RawAUD *current)
1069 {
1070  int err;
1071 
1072  HEADER("Access Unit Delimiter");
1073 
1074  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_AUD));
1075 
1076  u(3, pic_type, 0, 2);
1077 
1079 
1080  return 0;
1081 }
1082 
1084  H265RawSliceHeader *current,
1085  unsigned int num_pic_total_curr)
1086 {
1087  unsigned int entry_size;
1088  int err, i;
1089 
1090  entry_size = av_log2(num_pic_total_curr - 1) + 1;
1091 
1092  flag(ref_pic_list_modification_flag_l0);
1093  if (current->ref_pic_list_modification_flag_l0) {
1094  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++)
1095  us(entry_size, list_entry_l0[i], 0, num_pic_total_curr - 1, 1, i);
1096  }
1097 
1098  if (current->slice_type == HEVC_SLICE_B) {
1099  flag(ref_pic_list_modification_flag_l1);
1100  if (current->ref_pic_list_modification_flag_l1) {
1101  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++)
1102  us(entry_size, list_entry_l1[i], 0, num_pic_total_curr - 1, 1, i);
1103  }
1104  }
1105 
1106  return 0;
1107 }
1108 
1110  H265RawSliceHeader *current)
1111 {
1113  const H265RawSPS *sps = h265->active_sps;
1114  int err, i, j;
1115  int chroma = !sps->separate_colour_plane_flag &&
1116  sps->chroma_format_idc != 0;
1117 
1118  ue(luma_log2_weight_denom, 0, 7);
1119  if (chroma)
1120  se(delta_chroma_log2_weight_denom, -7, 7);
1121  else
1122  infer(delta_chroma_log2_weight_denom, 0);
1123 
1124  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1125  if (1 /* is not same POC and same layer_id */)
1126  flags(luma_weight_l0_flag[i], 1, i);
1127  else
1128  infer(luma_weight_l0_flag[i], 0);
1129  }
1130  if (chroma) {
1131  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1132  if (1 /* is not same POC and same layer_id */)
1133  flags(chroma_weight_l0_flag[i], 1, i);
1134  else
1135  infer(chroma_weight_l0_flag[i], 0);
1136  }
1137  }
1138 
1139  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1140  if (current->luma_weight_l0_flag[i]) {
1141  ses(delta_luma_weight_l0[i], -128, +127, 1, i);
1142  ses(luma_offset_l0[i],
1143  -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1144  ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1145  } else {
1146  infer(delta_luma_weight_l0[i], 0);
1147  infer(luma_offset_l0[i], 0);
1148  }
1149  if (current->chroma_weight_l0_flag[i]) {
1150  for (j = 0; j < 2; j++) {
1151  ses(delta_chroma_weight_l0[i][j], -128, +127, 2, i, j);
1152  ses(chroma_offset_l0[i][j],
1153  -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1154  ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1155  }
1156  } else {
1157  for (j = 0; j < 2; j++) {
1158  infer(delta_chroma_weight_l0[i][j], 0);
1159  infer(chroma_offset_l0[i][j], 0);
1160  }
1161  }
1162  }
1163 
1164  if (current->slice_type == HEVC_SLICE_B) {
1165  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1166  if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1167  flags(luma_weight_l1_flag[i], 1, i);
1168  else
1169  infer(luma_weight_l1_flag[i], 0);
1170  }
1171  if (chroma) {
1172  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1173  if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1174  flags(chroma_weight_l1_flag[i], 1, i);
1175  else
1176  infer(chroma_weight_l1_flag[i], 0);
1177  }
1178  }
1179 
1180  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1181  if (current->luma_weight_l1_flag[i]) {
1182  ses(delta_luma_weight_l1[i], -128, +127, 1, i);
1183  ses(luma_offset_l1[i],
1184  -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1185  ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1186  } else {
1187  infer(delta_luma_weight_l1[i], 0);
1188  infer(luma_offset_l1[i], 0);
1189  }
1190  if (current->chroma_weight_l1_flag[i]) {
1191  for (j = 0; j < 2; j++) {
1192  ses(delta_chroma_weight_l1[i][j], -128, +127, 2, i, j);
1193  ses(chroma_offset_l1[i][j],
1194  -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1195  ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1196  }
1197  } else {
1198  for (j = 0; j < 2; j++) {
1199  infer(delta_chroma_weight_l1[i][j], 0);
1200  infer(chroma_offset_l1[i][j], 0);
1201  }
1202  }
1203  }
1204  }
1205 
1206  return 0;
1207 }
1208 
1210  H265RawSliceHeader *current)
1211 {
1213  const H265RawSPS *sps;
1214  const H265RawPPS *pps;
1215  unsigned int min_cb_log2_size_y, ctb_log2_size_y, ctb_size_y;
1216  unsigned int pic_width_in_ctbs_y, pic_height_in_ctbs_y, pic_size_in_ctbs_y;
1217  unsigned int num_pic_total_curr = 0;
1218  int err, i;
1219 
1220  HEADER("Slice Segment Header");
1221 
1222  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, -1));
1223 
1224  flag(first_slice_segment_in_pic_flag);
1225 
1226  if (current->nal_unit_header.nal_unit_type >= HEVC_NAL_BLA_W_LP &&
1227  current->nal_unit_header.nal_unit_type <= HEVC_NAL_IRAP_VCL23)
1228  flag(no_output_of_prior_pics_flag);
1229 
1230  ue(slice_pic_parameter_set_id, 0, 63);
1231 
1232  pps = h265->pps[current->slice_pic_parameter_set_id];
1233  if (!pps) {
1234  av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
1235  current->slice_pic_parameter_set_id);
1236  return AVERROR_INVALIDDATA;
1237  }
1238  h265->active_pps = pps;
1239 
1240  sps = h265->sps[pps->pps_seq_parameter_set_id];
1241  if (!sps) {
1242  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1244  return AVERROR_INVALIDDATA;
1245  }
1246  h265->active_sps = sps;
1247 
1248  min_cb_log2_size_y = sps->log2_min_luma_coding_block_size_minus3 + 3;
1249  ctb_log2_size_y = min_cb_log2_size_y + sps->log2_diff_max_min_luma_coding_block_size;
1250  ctb_size_y = 1 << ctb_log2_size_y;
1251  pic_width_in_ctbs_y =
1252  (sps->pic_width_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1253  pic_height_in_ctbs_y =
1254  (sps->pic_height_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1255  pic_size_in_ctbs_y = pic_width_in_ctbs_y * pic_height_in_ctbs_y;
1256 
1257  if (!current->first_slice_segment_in_pic_flag) {
1258  unsigned int address_size = av_log2(pic_size_in_ctbs_y - 1) + 1;
1260  flag(dependent_slice_segment_flag);
1261  else
1262  infer(dependent_slice_segment_flag, 0);
1263  u(address_size, slice_segment_address, 0, pic_size_in_ctbs_y - 1);
1264  } else {
1265  infer(dependent_slice_segment_flag, 0);
1266  }
1267 
1268  if (!current->dependent_slice_segment_flag) {
1269  for (i = 0; i < pps->num_extra_slice_header_bits; i++)
1270  flags(slice_reserved_flag[i], 1, i);
1271 
1272  ue(slice_type, 0, 2);
1273 
1274  if (pps->output_flag_present_flag)
1275  flag(pic_output_flag);
1276 
1277  if (sps->separate_colour_plane_flag)
1278  u(2, colour_plane_id, 0, 2);
1279 
1280  if (current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_W_RADL &&
1281  current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_N_LP) {
1282  const H265RawSTRefPicSet *rps;
1283 
1284  u(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, slice_pic_order_cnt_lsb,
1286 
1287  flag(short_term_ref_pic_set_sps_flag);
1288  if (!current->short_term_ref_pic_set_sps_flag) {
1289  CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->short_term_ref_pic_set,
1290  sps->num_short_term_ref_pic_sets, sps));
1291  rps = &current->short_term_ref_pic_set;
1292  } else if (sps->num_short_term_ref_pic_sets > 1) {
1293  unsigned int idx_size = av_log2(sps->num_short_term_ref_pic_sets - 1) + 1;
1294  u(idx_size, short_term_ref_pic_set_idx,
1295  0, sps->num_short_term_ref_pic_sets - 1);
1296  rps = &sps->st_ref_pic_set[current->short_term_ref_pic_set_idx];
1297  } else {
1298  infer(short_term_ref_pic_set_idx, 0);
1299  rps = &sps->st_ref_pic_set[0];
1300  }
1301 
1302  num_pic_total_curr = 0;
1303  for (i = 0; i < rps->num_negative_pics; i++)
1304  if (rps->used_by_curr_pic_s0_flag[i])
1305  ++num_pic_total_curr;
1306  for (i = 0; i < rps->num_positive_pics; i++)
1307  if (rps->used_by_curr_pic_s1_flag[i])
1308  ++num_pic_total_curr;
1309 
1311  unsigned int idx_size;
1312 
1313  if (sps->num_long_term_ref_pics_sps > 0) {
1314  ue(num_long_term_sps, 0, sps->num_long_term_ref_pics_sps);
1315  idx_size = av_log2(sps->num_long_term_ref_pics_sps - 1) + 1;
1316  } else {
1317  infer(num_long_term_sps, 0);
1318  idx_size = 0;
1319  }
1320  ue(num_long_term_pics, 0, HEVC_MAX_LONG_TERM_REF_PICS);
1321 
1322  for (i = 0; i < current->num_long_term_sps +
1323  current->num_long_term_pics; i++) {
1324  if (i < current->num_long_term_sps) {
1325  if (sps->num_long_term_ref_pics_sps > 1)
1326  us(idx_size, lt_idx_sps[i],
1327  0, sps->num_long_term_ref_pics_sps - 1, 1, i);
1328  if (sps->used_by_curr_pic_lt_sps_flag[current->lt_idx_sps[i]])
1329  ++num_pic_total_curr;
1330  } else {
1331  us(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[i],
1333  flags(used_by_curr_pic_lt_flag[i], 1, i);
1334  if (current->used_by_curr_pic_lt_flag[i])
1335  ++num_pic_total_curr;
1336  }
1337  flags(delta_poc_msb_present_flag[i], 1, i);
1338  if (current->delta_poc_msb_present_flag[i])
1339  ues(delta_poc_msb_cycle_lt[i], 0, UINT32_MAX - 1, 1, i);
1340  else
1341  infer(delta_poc_msb_cycle_lt[i], 0);
1342  }
1343  }
1344 
1346  flag(slice_temporal_mvp_enabled_flag);
1347  else
1348  infer(slice_temporal_mvp_enabled_flag, 0);
1349 
1351  ++num_pic_total_curr;
1352  }
1353 
1355  flag(slice_sao_luma_flag);
1356  if (!sps->separate_colour_plane_flag && sps->chroma_format_idc != 0)
1357  flag(slice_sao_chroma_flag);
1358  else
1359  infer(slice_sao_chroma_flag, 0);
1360  } else {
1361  infer(slice_sao_luma_flag, 0);
1362  infer(slice_sao_chroma_flag, 0);
1363  }
1364 
1365  if (current->slice_type == HEVC_SLICE_P ||
1366  current->slice_type == HEVC_SLICE_B) {
1367  flag(num_ref_idx_active_override_flag);
1368  if (current->num_ref_idx_active_override_flag) {
1369  ue(num_ref_idx_l0_active_minus1, 0, 14);
1370  if (current->slice_type == HEVC_SLICE_B)
1371  ue(num_ref_idx_l1_active_minus1, 0, 14);
1372  else
1373  infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1374  } else {
1375  infer(num_ref_idx_l0_active_minus1, pps->num_ref_idx_l0_default_active_minus1);
1376  infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1377  }
1378 
1379  if (pps->lists_modification_present_flag && num_pic_total_curr > 1)
1380  CHECK(FUNC(ref_pic_lists_modification)(ctx, rw, current,
1381  num_pic_total_curr));
1382 
1383  if (current->slice_type == HEVC_SLICE_B)
1384  flag(mvd_l1_zero_flag);
1385  if (pps->cabac_init_present_flag)
1386  flag(cabac_init_flag);
1387  else
1388  infer(cabac_init_flag, 0);
1389  if (current->slice_temporal_mvp_enabled_flag) {
1390  if (current->slice_type == HEVC_SLICE_B)
1391  flag(collocated_from_l0_flag);
1392  else
1393  infer(collocated_from_l0_flag, 1);
1394  if (current->collocated_from_l0_flag) {
1395  if (current->num_ref_idx_l0_active_minus1 > 0)
1396  ue(collocated_ref_idx, 0, current->num_ref_idx_l0_active_minus1);
1397  else
1398  infer(collocated_ref_idx, 0);
1399  } else {
1400  if (current->num_ref_idx_l1_active_minus1 > 0)
1401  ue(collocated_ref_idx, 0, current->num_ref_idx_l1_active_minus1);
1402  else
1403  infer(collocated_ref_idx, 0);
1404  }
1405  }
1406 
1407  if ((pps->weighted_pred_flag && current->slice_type == HEVC_SLICE_P) ||
1408  (pps->weighted_bipred_flag && current->slice_type == HEVC_SLICE_B))
1409  CHECK(FUNC(pred_weight_table)(ctx, rw, current));
1410 
1411  ue(five_minus_max_num_merge_cand, 0, 4);
1413  flag(use_integer_mv_flag);
1414  else
1415  infer(use_integer_mv_flag, sps->motion_vector_resolution_control_idc);
1416  }
1417 
1418  se(slice_qp_delta,
1419  - 6 * sps->bit_depth_luma_minus8 - (pps->init_qp_minus26 + 26),
1420  + 51 - (pps->init_qp_minus26 + 26));
1422  se(slice_cb_qp_offset, -12, +12);
1423  se(slice_cr_qp_offset, -12, +12);
1424  } else {
1425  infer(slice_cb_qp_offset, 0);
1426  infer(slice_cr_qp_offset, 0);
1427  }
1429  se(slice_act_y_qp_offset,
1430  -12 - (pps->pps_act_y_qp_offset_plus5 - 5),
1431  +12 - (pps->pps_act_y_qp_offset_plus5 - 5));
1432  se(slice_act_cb_qp_offset,
1433  -12 - (pps->pps_act_cb_qp_offset_plus5 - 5),
1434  +12 - (pps->pps_act_cb_qp_offset_plus5 - 5));
1435  se(slice_act_cr_qp_offset,
1436  -12 - (pps->pps_act_cr_qp_offset_plus3 - 3),
1437  +12 - (pps->pps_act_cr_qp_offset_plus3 - 3));
1438  } else {
1439  infer(slice_act_y_qp_offset, 0);
1440  infer(slice_act_cb_qp_offset, 0);
1441  infer(slice_act_cr_qp_offset, 0);
1442  }
1444  flag(cu_chroma_qp_offset_enabled_flag);
1445  else
1446  infer(cu_chroma_qp_offset_enabled_flag, 0);
1447 
1449  flag(deblocking_filter_override_flag);
1450  else
1451  infer(deblocking_filter_override_flag, 0);
1452  if (current->deblocking_filter_override_flag) {
1453  flag(slice_deblocking_filter_disabled_flag);
1454  if (!current->slice_deblocking_filter_disabled_flag) {
1455  se(slice_beta_offset_div2, -6, +6);
1456  se(slice_tc_offset_div2, -6, +6);
1457  } else {
1458  infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1459  infer(slice_tc_offset_div2, pps->pps_tc_offset_div2);
1460  }
1461  } else {
1462  infer(slice_deblocking_filter_disabled_flag,
1464  infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1465  infer(slice_tc_offset_div2, pps->pps_tc_offset_div2);
1466  }
1468  (current->slice_sao_luma_flag || current->slice_sao_chroma_flag ||
1469  !current->slice_deblocking_filter_disabled_flag))
1470  flag(slice_loop_filter_across_slices_enabled_flag);
1471  else
1472  infer(slice_loop_filter_across_slices_enabled_flag,
1474  }
1475 
1477  unsigned int num_entry_point_offsets_limit;
1479  num_entry_point_offsets_limit = pic_height_in_ctbs_y - 1;
1481  num_entry_point_offsets_limit =
1482  (pps->num_tile_columns_minus1 + 1) * (pps->num_tile_rows_minus1 + 1);
1483  else
1484  num_entry_point_offsets_limit =
1485  (pps->num_tile_columns_minus1 + 1) * pic_height_in_ctbs_y - 1;
1486  ue(num_entry_point_offsets, 0, num_entry_point_offsets_limit);
1487 
1488  if (current->num_entry_point_offsets > HEVC_MAX_ENTRY_POINT_OFFSETS) {
1489  av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
1490  "%"PRIu16".\n", current->num_entry_point_offsets);
1491  return AVERROR_PATCHWELCOME;
1492  }
1493 
1494  if (current->num_entry_point_offsets > 0) {
1495  ue(offset_len_minus1, 0, 31);
1496  for (i = 0; i < current->num_entry_point_offsets; i++)
1497  us(current->offset_len_minus1 + 1, entry_point_offset_minus1[i],
1498  0, MAX_UINT_BITS(current->offset_len_minus1 + 1), 1, i);
1499  }
1500  }
1501 
1503  ue(slice_segment_header_extension_length, 0, 256);
1504  for (i = 0; i < current->slice_segment_header_extension_length; i++)
1505  us(8, slice_segment_header_extension_data_byte[i], 0x00, 0xff, 1, i);
1506  }
1507 
1508  CHECK(FUNC(byte_alignment)(ctx, rw));
1509 
1510  return 0;
1511 }
1512 
1515 {
1516  int err, c;
1517 
1518  for (c = 0; c < 3; c++) {
1519  us(16, display_primaries_x[c], 0, 50000, 1, c);
1520  us(16, display_primaries_y[c], 0, 50000, 1, c);
1521  }
1522 
1523  u(16, white_point_x, 0, 50000);
1524  u(16, white_point_y, 0, 50000);
1525 
1526  u(32, max_display_mastering_luminance,
1527  1, MAX_UINT_BITS(32));
1528  u(32, min_display_mastering_luminance,
1529  0, current->max_display_mastering_luminance - 1);
1530 
1531  return 0;
1532 }
1533 
1536 {
1537  int err;
1538 
1539  u(16, max_content_light_level, 0, MAX_UINT_BITS(16));
1540  u(16, max_pic_average_light_level, 0, MAX_UINT_BITS(16));
1541 
1542  return 0;
1543 }
1544 
1546  H265RawSEIPayload *current)
1547 {
1548  int err, i;
1549  int start_position, end_position;
1550 
1551 #ifdef READ
1552  start_position = get_bits_count(rw);
1553 #else
1554  start_position = put_bits_count(rw);
1555 #endif
1556 
1557  switch (current->payload_type) {
1560  (ctx, rw, &current->payload.mastering_display));
1561 
1562  break;
1563 
1566  (ctx, rw, &current->payload.content_light_level));
1567 
1568  break;
1569 
1570  default:
1571  {
1572 #ifdef READ
1573  current->payload.other.data_length = current->payload_size;
1574 #endif
1575  allocate(current->payload.other.data, current->payload.other.data_length);
1576 
1577  for (i = 0; i < current->payload_size; i++)
1578  xu(8, payload_byte[i], current->payload.other.data[i], 0, 255,
1579  1, i);
1580  }
1581  }
1582 
1583  if (byte_alignment(rw)) {
1584  fixed(1, bit_equal_to_one, 1);
1585  while (byte_alignment(rw))
1586  fixed(1, bit_equal_to_zero, 0);
1587  }
1588 
1589 #ifdef READ
1590  end_position = get_bits_count(rw);
1591  if (end_position < start_position + 8 * current->payload_size) {
1592  av_log(ctx->log_ctx, AV_LOG_ERROR, "Incorrect SEI payload length: "
1593  "header %"PRIu32" bits, actually %d bits.\n",
1594  8 * current->payload_size,
1595  end_position - start_position);
1596  return AVERROR_INVALIDDATA;
1597  }
1598 #else
1599  end_position = put_bits_count(rw);
1600  current->payload_size = (end_position - start_position) >> 3;
1601 #endif
1602 
1603  return 0;
1604 }
1605 
1607  H265RawSEI *current)
1608 {
1609  int err, k;
1610 
1611  HEADER("Supplemental Enhancement Information");
1612 
1613  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
1615 
1616 #ifdef READ
1617  for (k = 0; k < H265_MAX_SEI_PAYLOADS; k++) {
1618  uint32_t payload_type = 0;
1619  uint32_t payload_size = 0;
1620  uint32_t tmp;
1621 
1622  while (show_bits(rw, 8) == 0xff) {
1623  fixed(8, ff_byte, 0xff);
1624  payload_type += 255;
1625  }
1626  xu(8, last_payload_type_byte, tmp, 0, 254, 0);
1627  payload_type += tmp;
1628 
1629  while (show_bits(rw, 8) == 0xff) {
1630  fixed(8, ff_byte, 0xff);
1631  payload_size += 255;
1632  }
1633  xu(8, last_payload_size_byte, tmp, 0, 254, 0);
1634  payload_size += tmp;
1635 
1636  current->payload[k].payload_type = payload_type;
1637  current->payload[k].payload_size = payload_size;
1638 
1639  CHECK(FUNC(sei_payload)(ctx, rw, &current->payload[k]));
1640 
1642  break;
1643  }
1644  if (k >= H265_MAX_SEI_PAYLOADS) {
1645  av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many payloads in "
1646  "SEI message: found %d.\n", k);
1647  return AVERROR_INVALIDDATA;
1648  }
1649  current->payload_count = k + 1;
1650 #else
1651  for (k = 0; k < current->payload_count; k++) {
1652  PutBitContext start_state;
1653  uint32_t tmp;
1654  int need_size, i;
1655 
1656  // Somewhat clumsy: we write the payload twice when
1657  // we don't know the size in advance. This will mess
1658  // with trace output, but is otherwise harmless.
1659  start_state = *rw;
1660  need_size = !current->payload[k].payload_size;
1661  for (i = 0; i < 1 + need_size; i++) {
1662  *rw = start_state;
1663 
1664  tmp = current->payload[k].payload_type;
1665  while (tmp >= 255) {
1666  fixed(8, ff_byte, 0xff);
1667  tmp -= 255;
1668  }
1669  xu(8, last_payload_type_byte, tmp, 0, 254, 0);
1670 
1671  tmp = current->payload[k].payload_size;
1672  while (tmp >= 255) {
1673  fixed(8, ff_byte, 0xff);
1674  tmp -= 255;
1675  }
1676  xu(8, last_payload_size_byte, tmp, 0, 254, 0);
1677 
1678  CHECK(FUNC(sei_payload)(ctx, rw, &current->payload[k]));
1679  }
1680  }
1681 #endif
1682 
1684 
1685  return 0;
1686 }
#define allocate(name, size)
Definition: cbs_h2645.c:385
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:258
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:601
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:696
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:261
int av_log2(unsigned v)
Definition: intmath.c:26
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:568
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:86
#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)
CHECK(-1) CHECK(-2)}}}}CHECK(1) CHECK(2)}}}}}if(diff0+diff1 > 0) temp-
#define ses(name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:267
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 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
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:353
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
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:307
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:596
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:588
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:741
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:265
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