FFmpeg  4.4.9
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  fixed(1, forbidden_zero_bit, 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  ub(6, nal_unit_type);
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  H265RawExtensionData *current)
63 {
64  int err;
65  size_t k;
66 #ifdef READ
67  GetBitContext start;
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  ub(5, general_profile_idc);
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  ub(8, general_level_idc);
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  us(2, sub_layer_profile_space[i], 0, 0, 1, i);
168  flags(sub_layer_tier_flag[i], 1, i);
169  ubs(5, sub_layer_profile_idc[i], 1, i);
170 
171  for (j = 0; j < 32; j++)
172  flags(sub_layer_profile_compatibility_flag[i][j], 2, i, j);
173 
174  flags(sub_layer_progressive_source_flag[i], 1, i);
175  flags(sub_layer_interlaced_source_flag[i], 1, i);
176  flags(sub_layer_non_packed_constraint_flag[i], 1, i);
177  flags(sub_layer_frame_only_constraint_flag[i], 1, i);
178 
179 #define profile_compatible(x) (current->sub_layer_profile_idc[i] == (x) || \
180  current->sub_layer_profile_compatibility_flag[i][x])
181  if (profile_compatible(4) || profile_compatible(5) ||
184  profile_compatible(10)) {
185  flags(sub_layer_max_12bit_constraint_flag[i], 1, i);
186  flags(sub_layer_max_10bit_constraint_flag[i], 1, i);
187  flags(sub_layer_max_8bit_constraint_flag[i], 1, i);
188  flags(sub_layer_max_422chroma_constraint_flag[i], 1, i);
189  flags(sub_layer_max_420chroma_constraint_flag[i], 1, i);
190  flags(sub_layer_max_monochrome_constraint_flag[i], 1, i);
191  flags(sub_layer_intra_constraint_flag[i], 1, i);
192  flags(sub_layer_one_picture_only_constraint_flag[i], 1, i);
193  flags(sub_layer_lower_bit_rate_constraint_flag[i], 1, i);
194 
195  if (profile_compatible(5)) {
196  flags(sub_layer_max_14bit_constraint_flag[i], 1, i);
197  fixed(24, sub_layer_reserved_zero_33bits, 0);
198  fixed( 9, sub_layer_reserved_zero_33bits, 0);
199  } else {
200  fixed(24, sub_layer_reserved_zero_34bits, 0);
201  fixed(10, sub_layer_reserved_zero_34bits, 0);
202  }
203  } else if (profile_compatible(2)) {
204  fixed(7, sub_layer_reserved_zero_7bits, 0);
205  flags(sub_layer_one_picture_only_constraint_flag[i], 1, i);
206  fixed(24, sub_layer_reserved_zero_43bits, 0);
207  fixed(11, sub_layer_reserved_zero_43bits, 0);
208  } else {
209  fixed(24, sub_layer_reserved_zero_43bits, 0);
210  fixed(19, sub_layer_reserved_zero_43bits, 0);
211  }
212 
213  if (profile_compatible(1) || profile_compatible(2) ||
216  flags(sub_layer_inbld_flag[i], 1, i);
217  } else {
218  fixed(1, sub_layer_reserved_zero_bit, 0);
219  }
220 #undef profile_compatible
221  }
222  if (current->sub_layer_level_present_flag[i])
223  ubs(8, sub_layer_level_idc[i], 1, i);
224  }
225 
226  return 0;
227 }
228 
231  int nal, int sub_layer_id)
232 {
234  int err, i;
235 
236  if (nal)
237  current = &hrd->nal_sub_layer_hrd_parameters[sub_layer_id];
238  else
239  current = &hrd->vcl_sub_layer_hrd_parameters[sub_layer_id];
240 
241  for (i = 0; i <= hrd->cpb_cnt_minus1[sub_layer_id]; i++) {
242  ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
243  ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
244  if (hrd->sub_pic_hrd_params_present_flag) {
245  ues(cpb_size_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
246  ues(bit_rate_du_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
247  }
248  flags(cbr_flag[i], 1, i);
249  }
250 
251  return 0;
252 }
253 
255  H265RawHRDParameters *current, int common_inf_present_flag,
256  int max_num_sub_layers_minus1)
257 {
258  int err, i;
259 
260  if (common_inf_present_flag) {
261  flag(nal_hrd_parameters_present_flag);
262  flag(vcl_hrd_parameters_present_flag);
263 
264  if (current->nal_hrd_parameters_present_flag ||
265  current->vcl_hrd_parameters_present_flag) {
266  flag(sub_pic_hrd_params_present_flag);
267  if (current->sub_pic_hrd_params_present_flag) {
268  ub(8, tick_divisor_minus2);
269  ub(5, du_cpb_removal_delay_increment_length_minus1);
270  flag(sub_pic_cpb_params_in_pic_timing_sei_flag);
271  ub(5, dpb_output_delay_du_length_minus1);
272  }
273 
274  ub(4, bit_rate_scale);
275  ub(4, cpb_size_scale);
276  if (current->sub_pic_hrd_params_present_flag)
277  ub(4, cpb_size_du_scale);
278 
279  ub(5, initial_cpb_removal_delay_length_minus1);
280  ub(5, au_cpb_removal_delay_length_minus1);
281  ub(5, dpb_output_delay_length_minus1);
282  } else {
283  infer(sub_pic_hrd_params_present_flag, 0);
284 
285  infer(initial_cpb_removal_delay_length_minus1, 23);
286  infer(au_cpb_removal_delay_length_minus1, 23);
287  infer(dpb_output_delay_length_minus1, 23);
288  }
289  }
290 
291  for (i = 0; i <= max_num_sub_layers_minus1; i++) {
292  flags(fixed_pic_rate_general_flag[i], 1, i);
293 
294  if (!current->fixed_pic_rate_general_flag[i])
295  flags(fixed_pic_rate_within_cvs_flag[i], 1, i);
296  else
297  infer(fixed_pic_rate_within_cvs_flag[i], 1);
298 
299  if (current->fixed_pic_rate_within_cvs_flag[i]) {
300  ues(elemental_duration_in_tc_minus1[i], 0, 2047, 1, i);
301  infer(low_delay_hrd_flag[i], 0);
302  } else
303  flags(low_delay_hrd_flag[i], 1, i);
304 
305  if (!current->low_delay_hrd_flag[i])
306  ues(cpb_cnt_minus1[i], 0, 31, 1, i);
307  else
308  infer(cpb_cnt_minus1[i], 0);
309 
310  if (current->nal_hrd_parameters_present_flag)
311  CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 0, i));
312  if (current->vcl_hrd_parameters_present_flag)
313  CHECK(FUNC(sub_layer_hrd_parameters)(ctx, rw, current, 1, i));
314  }
315 
316  return 0;
317 }
318 
320  H265RawVUI *current, const H265RawSPS *sps)
321 {
322  int err;
323 
324  flag(aspect_ratio_info_present_flag);
325  if (current->aspect_ratio_info_present_flag) {
326  ub(8, aspect_ratio_idc);
327  if (current->aspect_ratio_idc == 255) {
328  ub(16, sar_width);
329  ub(16, sar_height);
330  }
331  } else {
332  infer(aspect_ratio_idc, 0);
333  }
334 
335  flag(overscan_info_present_flag);
336  if (current->overscan_info_present_flag)
337  flag(overscan_appropriate_flag);
338 
339  flag(video_signal_type_present_flag);
340  if (current->video_signal_type_present_flag) {
341  ub(3, video_format);
342  flag(video_full_range_flag);
343  flag(colour_description_present_flag);
344  if (current->colour_description_present_flag) {
345  ub(8, colour_primaries);
347  ub(8, matrix_coefficients);
348  } else {
349  infer(colour_primaries, 2);
351  infer(matrix_coefficients, 2);
352  }
353  } else {
354  infer(video_format, 5);
355  infer(video_full_range_flag, 0);
356  infer(colour_primaries, 2);
358  infer(matrix_coefficients, 2);
359  }
360 
361  flag(chroma_loc_info_present_flag);
362  if (current->chroma_loc_info_present_flag) {
363  ue(chroma_sample_loc_type_top_field, 0, 5);
364  ue(chroma_sample_loc_type_bottom_field, 0, 5);
365  } else {
366  infer(chroma_sample_loc_type_top_field, 0);
367  infer(chroma_sample_loc_type_bottom_field, 0);
368  }
369 
370  flag(neutral_chroma_indication_flag);
371  flag(field_seq_flag);
372  flag(frame_field_info_present_flag);
373 
374  flag(default_display_window_flag);
375  if (current->default_display_window_flag) {
376  ue(def_disp_win_left_offset, 0, 16384);
377  ue(def_disp_win_right_offset, 0, 16384);
378  ue(def_disp_win_top_offset, 0, 16384);
379  ue(def_disp_win_bottom_offset, 0, 16384);
380  }
381 
382  flag(vui_timing_info_present_flag);
383  if (current->vui_timing_info_present_flag) {
384  u(32, vui_num_units_in_tick, 1, UINT32_MAX);
385  u(32, vui_time_scale, 1, UINT32_MAX);
386  flag(vui_poc_proportional_to_timing_flag);
387  if (current->vui_poc_proportional_to_timing_flag)
388  ue(vui_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
389 
390  flag(vui_hrd_parameters_present_flag);
391  if (current->vui_hrd_parameters_present_flag) {
392  CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters,
393  1, sps->sps_max_sub_layers_minus1));
394  }
395  }
396 
397  flag(bitstream_restriction_flag);
398  if (current->bitstream_restriction_flag) {
399  flag(tiles_fixed_structure_flag);
400  flag(motion_vectors_over_pic_boundaries_flag);
401  flag(restricted_ref_pic_lists_flag);
402  ue(min_spatial_segmentation_idc, 0, 4095);
403  ue(max_bytes_per_pic_denom, 0, 16);
404  ue(max_bits_per_min_cu_denom, 0, 16);
405  ue(log2_max_mv_length_horizontal, 0, 16);
406  ue(log2_max_mv_length_vertical, 0, 16);
407  } else {
408  infer(tiles_fixed_structure_flag, 0);
409  infer(motion_vectors_over_pic_boundaries_flag, 1);
410  infer(min_spatial_segmentation_idc, 0);
411  infer(max_bytes_per_pic_denom, 2);
412  infer(max_bits_per_min_cu_denom, 1);
413  infer(log2_max_mv_length_horizontal, 15);
414  infer(log2_max_mv_length_vertical, 15);
415  }
416 
417  return 0;
418 }
419 
421  H265RawVPS *current)
422 {
423  int err, i, j;
424 
425  HEADER("Video Parameter Set");
426 
427  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_VPS));
428 
429  ub(4, vps_video_parameter_set_id);
430 
431  flag(vps_base_layer_internal_flag);
432  flag(vps_base_layer_available_flag);
433  u(6, vps_max_layers_minus1, 0, HEVC_MAX_LAYERS - 1);
434  u(3, vps_max_sub_layers_minus1, 0, HEVC_MAX_SUB_LAYERS - 1);
435  flag(vps_temporal_id_nesting_flag);
436 
437  if (current->vps_max_sub_layers_minus1 == 0 &&
438  current->vps_temporal_id_nesting_flag != 1) {
439  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
440  "vps_temporal_id_nesting_flag must be 1 if "
441  "vps_max_sub_layers_minus1 is 0.\n");
442  return AVERROR_INVALIDDATA;
443  }
444 
445  fixed(16, vps_reserved_0xffff_16bits, 0xffff);
446 
447  CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
448  1, current->vps_max_sub_layers_minus1));
449 
450  flag(vps_sub_layer_ordering_info_present_flag);
451  for (i = (current->vps_sub_layer_ordering_info_present_flag ?
452  0 : current->vps_max_sub_layers_minus1);
453  i <= current->vps_max_sub_layers_minus1; i++) {
454  ues(vps_max_dec_pic_buffering_minus1[i],
455  0, HEVC_MAX_DPB_SIZE - 1, 1, i);
456  ues(vps_max_num_reorder_pics[i],
457  0, current->vps_max_dec_pic_buffering_minus1[i], 1, i);
458  ues(vps_max_latency_increase_plus1[i],
459  0, UINT32_MAX - 1, 1, i);
460  }
461  if (!current->vps_sub_layer_ordering_info_present_flag) {
462  for (i = 0; i < current->vps_max_sub_layers_minus1; i++) {
463  infer(vps_max_dec_pic_buffering_minus1[i],
464  current->vps_max_dec_pic_buffering_minus1[current->vps_max_sub_layers_minus1]);
465  infer(vps_max_num_reorder_pics[i],
466  current->vps_max_num_reorder_pics[current->vps_max_sub_layers_minus1]);
467  infer(vps_max_latency_increase_plus1[i],
468  current->vps_max_latency_increase_plus1[current->vps_max_sub_layers_minus1]);
469  }
470  }
471 
472  u(6, vps_max_layer_id, 0, HEVC_MAX_LAYERS - 1);
473  ue(vps_num_layer_sets_minus1, 0, HEVC_MAX_LAYER_SETS - 1);
474  for (i = 1; i <= current->vps_num_layer_sets_minus1; i++) {
475  for (j = 0; j <= current->vps_max_layer_id; j++)
476  flags(layer_id_included_flag[i][j], 2, i, j);
477  }
478  for (j = 0; j <= current->vps_max_layer_id; j++)
479  infer(layer_id_included_flag[0][j], j == 0);
480 
481  flag(vps_timing_info_present_flag);
482  if (current->vps_timing_info_present_flag) {
483  u(32, vps_num_units_in_tick, 1, UINT32_MAX);
484  u(32, vps_time_scale, 1, UINT32_MAX);
485  flag(vps_poc_proportional_to_timing_flag);
486  if (current->vps_poc_proportional_to_timing_flag)
487  ue(vps_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
488  ue(vps_num_hrd_parameters, 0, current->vps_num_layer_sets_minus1 + 1);
489  for (i = 0; i < current->vps_num_hrd_parameters; i++) {
490  ues(hrd_layer_set_idx[i],
491  current->vps_base_layer_internal_flag ? 0 : 1,
492  current->vps_num_layer_sets_minus1, 1, i);
493  if (i > 0)
494  flags(cprms_present_flag[i], 1, i);
495  else
496  infer(cprms_present_flag[0], 1);
497 
498  CHECK(FUNC(hrd_parameters)(ctx, rw, &current->hrd_parameters[i],
499  current->cprms_present_flag[i],
500  current->vps_max_sub_layers_minus1));
501  }
502  }
503 
504  flag(vps_extension_flag);
505  if (current->vps_extension_flag)
506  CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
507 
509 
510  return 0;
511 }
512 
514  H265RawSTRefPicSet *current, int st_rps_idx,
515  const H265RawSPS *sps)
516 {
517  int err, i, j;
518 
519  if (st_rps_idx != 0)
520  flag(inter_ref_pic_set_prediction_flag);
521  else
522  infer(inter_ref_pic_set_prediction_flag, 0);
523 
524  if (current->inter_ref_pic_set_prediction_flag) {
525  unsigned int ref_rps_idx, num_delta_pocs, num_ref_pics;
526  const H265RawSTRefPicSet *ref;
527  int delta_rps, d_poc;
528  int ref_delta_poc_s0[HEVC_MAX_REFS], ref_delta_poc_s1[HEVC_MAX_REFS];
529  int delta_poc_s0[HEVC_MAX_REFS], delta_poc_s1[HEVC_MAX_REFS];
530  uint8_t used_by_curr_pic_s0[HEVC_MAX_REFS],
531  used_by_curr_pic_s1[HEVC_MAX_REFS];
532 
533  if (st_rps_idx == sps->num_short_term_ref_pic_sets)
534  ue(delta_idx_minus1, 0, st_rps_idx - 1);
535  else
536  infer(delta_idx_minus1, 0);
537 
538  ref_rps_idx = st_rps_idx - (current->delta_idx_minus1 + 1);
539  ref = &sps->st_ref_pic_set[ref_rps_idx];
540  num_delta_pocs = ref->num_negative_pics + ref->num_positive_pics;
541  av_assert0(num_delta_pocs < HEVC_MAX_DPB_SIZE);
542 
543  flag(delta_rps_sign);
544  ue(abs_delta_rps_minus1, 0, INT16_MAX);
545  delta_rps = (1 - 2 * current->delta_rps_sign) *
546  (current->abs_delta_rps_minus1 + 1);
547 
548  num_ref_pics = 0;
549  for (j = 0; j <= num_delta_pocs; j++) {
550  flags(used_by_curr_pic_flag[j], 1, j);
551  if (!current->used_by_curr_pic_flag[j])
552  flags(use_delta_flag[j], 1, j);
553  else
554  infer(use_delta_flag[j], 1);
555  if (current->use_delta_flag[j])
556  ++num_ref_pics;
557  }
558  if (num_ref_pics >= HEVC_MAX_DPB_SIZE) {
559  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
560  "short-term ref pic set %d "
561  "contains too many pictures.\n", st_rps_idx);
562  return AVERROR_INVALIDDATA;
563  }
564 
565  // Since the stored form of an RPS here is actually the delta-step
566  // form used when inter_ref_pic_set_prediction_flag is not set, we
567  // need to reconstruct that here in order to be able to refer to
568  // the RPS later (which is required for parsing, because we don't
569  // even know what syntax elements appear without it). Therefore,
570  // this code takes the delta-step form of the reference set, turns
571  // it into the delta-array form, applies the prediction process of
572  // 7.4.8, converts the result back to the delta-step form, and
573  // stores that as the current set for future use. Note that the
574  // inferences here mean that writers using prediction will need
575  // to fill in the delta-step values correctly as well - since the
576  // whole RPS prediction process is somewhat overly sophisticated,
577  // this hopefully forms a useful check for them to ensure their
578  // predicted form actually matches what was intended rather than
579  // an onerous additional requirement.
580 
581  d_poc = 0;
582  for (i = 0; i < ref->num_negative_pics; i++) {
583  d_poc -= ref->delta_poc_s0_minus1[i] + 1;
584  ref_delta_poc_s0[i] = d_poc;
585  }
586  d_poc = 0;
587  for (i = 0; i < ref->num_positive_pics; i++) {
588  d_poc += ref->delta_poc_s1_minus1[i] + 1;
589  ref_delta_poc_s1[i] = d_poc;
590  }
591 
592  i = 0;
593  for (j = ref->num_positive_pics - 1; j >= 0; j--) {
594  d_poc = ref_delta_poc_s1[j] + delta_rps;
595  if (d_poc < 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
596  delta_poc_s0[i] = d_poc;
597  used_by_curr_pic_s0[i++] =
598  current->used_by_curr_pic_flag[ref->num_negative_pics + j];
599  }
600  }
601  if (delta_rps < 0 && current->use_delta_flag[num_delta_pocs]) {
602  delta_poc_s0[i] = delta_rps;
603  used_by_curr_pic_s0[i++] =
604  current->used_by_curr_pic_flag[num_delta_pocs];
605  }
606  for (j = 0; j < ref->num_negative_pics; j++) {
607  d_poc = ref_delta_poc_s0[j] + delta_rps;
608  if (d_poc < 0 && current->use_delta_flag[j]) {
609  delta_poc_s0[i] = d_poc;
610  used_by_curr_pic_s0[i++] = current->used_by_curr_pic_flag[j];
611  }
612  }
613 
614  infer(num_negative_pics, i);
615  for (i = 0; i < current->num_negative_pics; i++) {
616  infer(delta_poc_s0_minus1[i],
617  -(delta_poc_s0[i] - (i == 0 ? 0 : delta_poc_s0[i - 1])) - 1);
618  infer(used_by_curr_pic_s0_flag[i], used_by_curr_pic_s0[i]);
619  }
620 
621  i = 0;
622  for (j = ref->num_negative_pics - 1; j >= 0; j--) {
623  d_poc = ref_delta_poc_s0[j] + delta_rps;
624  if (d_poc > 0 && current->use_delta_flag[j]) {
625  delta_poc_s1[i] = d_poc;
626  used_by_curr_pic_s1[i++] = current->used_by_curr_pic_flag[j];
627  }
628  }
629  if (delta_rps > 0 && current->use_delta_flag[num_delta_pocs]) {
630  delta_poc_s1[i] = delta_rps;
631  used_by_curr_pic_s1[i++] =
632  current->used_by_curr_pic_flag[num_delta_pocs];
633  }
634  for (j = 0; j < ref->num_positive_pics; j++) {
635  d_poc = ref_delta_poc_s1[j] + delta_rps;
636  if (d_poc > 0 && current->use_delta_flag[ref->num_negative_pics + j]) {
637  delta_poc_s1[i] = d_poc;
638  used_by_curr_pic_s1[i++] =
639  current->used_by_curr_pic_flag[ref->num_negative_pics + j];
640  }
641  }
642 
643  infer(num_positive_pics, i);
644  for (i = 0; i < current->num_positive_pics; i++) {
645  infer(delta_poc_s1_minus1[i],
646  delta_poc_s1[i] - (i == 0 ? 0 : delta_poc_s1[i - 1]) - 1);
647  infer(used_by_curr_pic_s1_flag[i], used_by_curr_pic_s1[i]);
648  }
649 
650  } else {
651  ue(num_negative_pics, 0, 15);
652  ue(num_positive_pics, 0, 15 - current->num_negative_pics);
653 
654  for (i = 0; i < current->num_negative_pics; i++) {
655  ues(delta_poc_s0_minus1[i], 0, INT16_MAX, 1, i);
656  flags(used_by_curr_pic_s0_flag[i], 1, i);
657  }
658 
659  for (i = 0; i < current->num_positive_pics; i++) {
660  ues(delta_poc_s1_minus1[i], 0, INT16_MAX, 1, i);
661  flags(used_by_curr_pic_s1_flag[i], 1, i);
662  }
663  }
664 
665  return 0;
666 }
667 
669  H265RawScalingList *current)
670 {
671  int sizeId, matrixId;
672  int err, n, i;
673 
674  for (sizeId = 0; sizeId < 4; sizeId++) {
675  for (matrixId = 0; matrixId < 6; matrixId += (sizeId == 3 ? 3 : 1)) {
676  flags(scaling_list_pred_mode_flag[sizeId][matrixId],
677  2, sizeId, matrixId);
678  if (!current->scaling_list_pred_mode_flag[sizeId][matrixId]) {
679  ues(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
680  0, sizeId == 3 ? matrixId / 3 : matrixId,
681  2, sizeId, matrixId);
682  } else {
683  n = FFMIN(64, 1 << (4 + (sizeId << 1)));
684  if (sizeId > 1) {
685  ses(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247,
686  2, sizeId - 2, matrixId);
687  }
688  for (i = 0; i < n; i++) {
689  ses(scaling_list_delta_coeff[sizeId][matrixId][i],
690  -128, +127, 3, sizeId, matrixId, i);
691  }
692  }
693  }
694  }
695 
696  return 0;
697 }
698 
700  H265RawSPS *current)
701 {
702  int err;
703 
704  flag(transform_skip_rotation_enabled_flag);
705  flag(transform_skip_context_enabled_flag);
706  flag(implicit_rdpcm_enabled_flag);
707  flag(explicit_rdpcm_enabled_flag);
708  flag(extended_precision_processing_flag);
709  flag(intra_smoothing_disabled_flag);
710  flag(high_precision_offsets_enabled_flag);
711  flag(persistent_rice_adaptation_enabled_flag);
712  flag(cabac_bypass_alignment_enabled_flag);
713 
714  return 0;
715 }
716 
718  H265RawSPS *current)
719 {
720  int err, comp, i;
721 
722  flag(sps_curr_pic_ref_enabled_flag);
723 
724  flag(palette_mode_enabled_flag);
725  if (current->palette_mode_enabled_flag) {
726  ue(palette_max_size, 0, 64);
727  ue(delta_palette_max_predictor_size, 0, 128);
728 
729  flag(sps_palette_predictor_initializer_present_flag);
730  if (current->sps_palette_predictor_initializer_present_flag) {
731  ue(sps_num_palette_predictor_initializer_minus1, 0, 127);
732  for (comp = 0; comp < (current->chroma_format_idc ? 3 : 1); comp++) {
733  int bit_depth = comp == 0 ? current->bit_depth_luma_minus8 + 8
734  : current->bit_depth_chroma_minus8 + 8;
735  for (i = 0; i <= current->sps_num_palette_predictor_initializer_minus1; i++)
736  ubs(bit_depth, sps_palette_predictor_initializers[comp][i], 2, comp, i);
737  }
738  }
739  }
740 
741  u(2, motion_vector_resolution_control_idc, 0, 2);
742  flag(intra_boundary_filtering_disable_flag);
743 
744  return 0;
745 }
746 
748  RWContext *rw, H265RawVUI *current,
749  H265RawSPS *sps)
750 {
751  infer(aspect_ratio_idc, 0);
752 
753  infer(video_format, 5);
754  infer(video_full_range_flag, 0);
755  infer(colour_primaries, 2);
757  infer(matrix_coefficients, 2);
758 
759  infer(chroma_sample_loc_type_top_field, 0);
760  infer(chroma_sample_loc_type_bottom_field, 0);
761 
762  infer(tiles_fixed_structure_flag, 0);
763  infer(motion_vectors_over_pic_boundaries_flag, 1);
764  infer(min_spatial_segmentation_idc, 0);
765  infer(max_bytes_per_pic_denom, 2);
766  infer(max_bits_per_min_cu_denom, 1);
767  infer(log2_max_mv_length_horizontal, 15);
768  infer(log2_max_mv_length_vertical, 15);
769 
770  return 0;
771 }
772 
774  H265RawSPS *current)
775 {
777  const H265RawVPS *vps;
778  int err, i;
779  unsigned int min_cb_log2_size_y, ctb_log2_size_y,
780  min_cb_size_y, min_tb_log2_size_y;
781 
782  HEADER("Sequence Parameter Set");
783 
784  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_SPS));
785 
786  ub(4, sps_video_parameter_set_id);
787  h265->active_vps = vps = h265->vps[current->sps_video_parameter_set_id];
788  if (!vps) {
789  av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available.\n",
790  current->sps_video_parameter_set_id);
791  return AVERROR_INVALIDDATA;
792  }
793 
794  u(3, sps_max_sub_layers_minus1, 0, vps->vps_max_sub_layers_minus1);
795  flag(sps_temporal_id_nesting_flag);
796 
797  if (vps->vps_temporal_id_nesting_flag &&
798  !current->sps_temporal_id_nesting_flag) {
799  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
800  "sps_temporal_id_nesting_flag must be 1 if "
801  "vps_temporal_id_nesting_flag is 1.\n");
802  return AVERROR_INVALIDDATA;
803  }
804  if (current->sps_max_sub_layers_minus1 == 0 &&
805  current->sps_temporal_id_nesting_flag != 1) {
806  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
807  "sps_temporal_id_nesting_flag must be 1 if "
808  "sps_max_sub_layers_minus1 is 0.\n");
809  return AVERROR_INVALIDDATA;
810  }
811 
812  CHECK(FUNC(profile_tier_level)(ctx, rw, &current->profile_tier_level,
813  1, current->sps_max_sub_layers_minus1));
814 
815  ue(sps_seq_parameter_set_id, 0, 15);
816 
817  ue(chroma_format_idc, 0, 3);
818  if (current->chroma_format_idc == 3)
819  flag(separate_colour_plane_flag);
820  else
821  infer(separate_colour_plane_flag, 0);
822 
823  ue(pic_width_in_luma_samples, 1, HEVC_MAX_WIDTH);
824  ue(pic_height_in_luma_samples, 1, HEVC_MAX_HEIGHT);
825 
826  flag(conformance_window_flag);
827  if (current->conformance_window_flag) {
828  ue(conf_win_left_offset, 0, current->pic_width_in_luma_samples);
829  ue(conf_win_right_offset, 0, current->pic_width_in_luma_samples);
830  ue(conf_win_top_offset, 0, current->pic_height_in_luma_samples);
831  ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples);
832  } else {
833  infer(conf_win_left_offset, 0);
834  infer(conf_win_right_offset, 0);
835  infer(conf_win_top_offset, 0);
836  infer(conf_win_bottom_offset, 0);
837  }
838 
839  ue(bit_depth_luma_minus8, 0, 8);
840  ue(bit_depth_chroma_minus8, 0, 8);
841 
842  ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
843 
844  flag(sps_sub_layer_ordering_info_present_flag);
845  for (i = (current->sps_sub_layer_ordering_info_present_flag ?
846  0 : current->sps_max_sub_layers_minus1);
847  i <= current->sps_max_sub_layers_minus1; i++) {
848  ues(sps_max_dec_pic_buffering_minus1[i],
849  0, HEVC_MAX_DPB_SIZE - 1, 1, i);
850  ues(sps_max_num_reorder_pics[i],
851  0, current->sps_max_dec_pic_buffering_minus1[i], 1, i);
852  ues(sps_max_latency_increase_plus1[i],
853  0, UINT32_MAX - 1, 1, i);
854  }
855  if (!current->sps_sub_layer_ordering_info_present_flag) {
856  for (i = 0; i < current->sps_max_sub_layers_minus1; i++) {
857  infer(sps_max_dec_pic_buffering_minus1[i],
858  current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]);
859  infer(sps_max_num_reorder_pics[i],
860  current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]);
861  infer(sps_max_latency_increase_plus1[i],
862  current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]);
863  }
864  }
865 
866  ue(log2_min_luma_coding_block_size_minus3, 0, 3);
867  min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3;
868 
869  ue(log2_diff_max_min_luma_coding_block_size, 0, 3);
870  ctb_log2_size_y = min_cb_log2_size_y +
871  current->log2_diff_max_min_luma_coding_block_size;
872 
873  min_cb_size_y = 1 << min_cb_log2_size_y;
874  if (current->pic_width_in_luma_samples % min_cb_size_y ||
875  current->pic_height_in_luma_samples % min_cb_size_y) {
876  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid dimensions: %ux%u not divisible "
877  "by MinCbSizeY = %u.\n", current->pic_width_in_luma_samples,
878  current->pic_height_in_luma_samples, min_cb_size_y);
879  return AVERROR_INVALIDDATA;
880  }
881 
882  ue(log2_min_luma_transform_block_size_minus2, 0, min_cb_log2_size_y - 3);
883  min_tb_log2_size_y = current->log2_min_luma_transform_block_size_minus2 + 2;
884 
885  ue(log2_diff_max_min_luma_transform_block_size,
886  0, FFMIN(ctb_log2_size_y, 5) - min_tb_log2_size_y);
887 
888  ue(max_transform_hierarchy_depth_inter,
889  0, ctb_log2_size_y - min_tb_log2_size_y);
890  ue(max_transform_hierarchy_depth_intra,
891  0, ctb_log2_size_y - min_tb_log2_size_y);
892 
893  flag(scaling_list_enabled_flag);
894  if (current->scaling_list_enabled_flag) {
895  flag(sps_scaling_list_data_present_flag);
896  if (current->sps_scaling_list_data_present_flag)
897  CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
898  } else {
899  infer(sps_scaling_list_data_present_flag, 0);
900  }
901 
902  flag(amp_enabled_flag);
903  flag(sample_adaptive_offset_enabled_flag);
904 
905  flag(pcm_enabled_flag);
906  if (current->pcm_enabled_flag) {
907  u(4, pcm_sample_bit_depth_luma_minus1,
908  0, current->bit_depth_luma_minus8 + 8 - 1);
909  u(4, pcm_sample_bit_depth_chroma_minus1,
910  0, current->bit_depth_chroma_minus8 + 8 - 1);
911 
912  ue(log2_min_pcm_luma_coding_block_size_minus3,
913  FFMIN(min_cb_log2_size_y, 5) - 3, FFMIN(ctb_log2_size_y, 5) - 3);
914  ue(log2_diff_max_min_pcm_luma_coding_block_size,
915  0, FFMIN(ctb_log2_size_y, 5) - (current->log2_min_pcm_luma_coding_block_size_minus3 + 3));
916 
917  flag(pcm_loop_filter_disabled_flag);
918  }
919 
920  ue(num_short_term_ref_pic_sets, 0, HEVC_MAX_SHORT_TERM_REF_PIC_SETS);
921  for (i = 0; i < current->num_short_term_ref_pic_sets; i++)
922  CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->st_ref_pic_set[i], i, current));
923 
924  flag(long_term_ref_pics_present_flag);
925  if (current->long_term_ref_pics_present_flag) {
926  ue(num_long_term_ref_pics_sps, 0, HEVC_MAX_LONG_TERM_REF_PICS);
927  for (i = 0; i < current->num_long_term_ref_pics_sps; i++) {
928  ubs(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
929  lt_ref_pic_poc_lsb_sps[i], 1, i);
930  flags(used_by_curr_pic_lt_sps_flag[i], 1, i);
931  }
932  }
933 
934  flag(sps_temporal_mvp_enabled_flag);
935  flag(strong_intra_smoothing_enabled_flag);
936 
937  flag(vui_parameters_present_flag);
938  if (current->vui_parameters_present_flag)
939  CHECK(FUNC(vui_parameters)(ctx, rw, &current->vui, current));
940  else
941  CHECK(FUNC(vui_parameters_default)(ctx, rw, &current->vui, current));
942 
943  flag(sps_extension_present_flag);
944  if (current->sps_extension_present_flag) {
945  flag(sps_range_extension_flag);
946  flag(sps_multilayer_extension_flag);
947  flag(sps_3d_extension_flag);
948  flag(sps_scc_extension_flag);
949  ub(4, sps_extension_4bits);
950  }
951 
952  if (current->sps_range_extension_flag)
953  CHECK(FUNC(sps_range_extension)(ctx, rw, current));
954  if (current->sps_multilayer_extension_flag)
955  return AVERROR_PATCHWELCOME;
956  if (current->sps_3d_extension_flag)
957  return AVERROR_PATCHWELCOME;
958  if (current->sps_scc_extension_flag)
959  CHECK(FUNC(sps_scc_extension)(ctx, rw, current));
960  if (current->sps_extension_4bits)
961  CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
962 
964 
965  return 0;
966 }
967 
969  H265RawPPS *current)
970 {
972  const H265RawSPS *sps = h265->active_sps;
973  int err, i;
974 
975  if (current->transform_skip_enabled_flag)
976  ue(log2_max_transform_skip_block_size_minus2, 0, 3);
977  flag(cross_component_prediction_enabled_flag);
978 
979  flag(chroma_qp_offset_list_enabled_flag);
980  if (current->chroma_qp_offset_list_enabled_flag) {
981  ue(diff_cu_chroma_qp_offset_depth,
982  0, sps->log2_diff_max_min_luma_coding_block_size);
983  ue(chroma_qp_offset_list_len_minus1, 0, 5);
984  for (i = 0; i <= current->chroma_qp_offset_list_len_minus1; i++) {
985  ses(cb_qp_offset_list[i], -12, +12, 1, i);
986  ses(cr_qp_offset_list[i], -12, +12, 1, i);
987  }
988  }
989 
990  ue(log2_sao_offset_scale_luma, 0, FFMAX(0, sps->bit_depth_luma_minus8 - 2));
991  ue(log2_sao_offset_scale_chroma, 0, FFMAX(0, sps->bit_depth_chroma_minus8 - 2));
992 
993  return 0;
994 }
995 
997  H265RawPPS *current)
998 {
999  int err, comp, i;
1000 
1001  flag(pps_curr_pic_ref_enabled_flag);
1002 
1003  flag(residual_adaptive_colour_transform_enabled_flag);
1004  if (current->residual_adaptive_colour_transform_enabled_flag) {
1005  flag(pps_slice_act_qp_offsets_present_flag);
1006  se(pps_act_y_qp_offset_plus5, -7, +17);
1007  se(pps_act_cb_qp_offset_plus5, -7, +17);
1008  se(pps_act_cr_qp_offset_plus3, -9, +15);
1009  } else {
1010  infer(pps_slice_act_qp_offsets_present_flag, 0);
1011  infer(pps_act_y_qp_offset_plus5, 0);
1012  infer(pps_act_cb_qp_offset_plus5, 0);
1013  infer(pps_act_cr_qp_offset_plus3, 0);
1014  }
1015 
1016  flag(pps_palette_predictor_initializer_present_flag);
1017  if (current->pps_palette_predictor_initializer_present_flag) {
1018  ue(pps_num_palette_predictor_initializer, 0, 128);
1019  if (current->pps_num_palette_predictor_initializer > 0) {
1020  flag(monochrome_palette_flag);
1021  ue(luma_bit_depth_entry_minus8, 0, 8);
1022  if (!current->monochrome_palette_flag)
1023  ue(chroma_bit_depth_entry_minus8, 0, 8);
1024  for (comp = 0; comp < (current->monochrome_palette_flag ? 1 : 3); comp++) {
1025  int bit_depth = comp == 0 ? current->luma_bit_depth_entry_minus8 + 8
1026  : current->chroma_bit_depth_entry_minus8 + 8;
1027  for (i = 0; i < current->pps_num_palette_predictor_initializer; i++)
1028  ubs(bit_depth, pps_palette_predictor_initializers[comp][i], 2, comp, i);
1029  }
1030  }
1031  }
1032 
1033  return 0;
1034 }
1035 
1037  H265RawPPS *current)
1038 {
1040  const H265RawSPS *sps;
1041  int err, i;
1042 
1043  HEADER("Picture Parameter Set");
1044 
1045  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_PPS));
1046 
1047  ue(pps_pic_parameter_set_id, 0, 63);
1048  ue(pps_seq_parameter_set_id, 0, 15);
1049  sps = h265->sps[current->pps_seq_parameter_set_id];
1050  if (!sps) {
1051  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1052  current->pps_seq_parameter_set_id);
1053  return AVERROR_INVALIDDATA;
1054  }
1055  h265->active_sps = sps;
1056 
1057  flag(dependent_slice_segments_enabled_flag);
1058  flag(output_flag_present_flag);
1059  ub(3, num_extra_slice_header_bits);
1060  flag(sign_data_hiding_enabled_flag);
1061  flag(cabac_init_present_flag);
1062 
1063  ue(num_ref_idx_l0_default_active_minus1, 0, 14);
1064  ue(num_ref_idx_l1_default_active_minus1, 0, 14);
1065 
1066  se(init_qp_minus26, -(26 + 6 * sps->bit_depth_luma_minus8), +25);
1067 
1068  flag(constrained_intra_pred_flag);
1069  flag(transform_skip_enabled_flag);
1070  flag(cu_qp_delta_enabled_flag);
1071  if (current->cu_qp_delta_enabled_flag)
1072  ue(diff_cu_qp_delta_depth,
1073  0, sps->log2_diff_max_min_luma_coding_block_size);
1074  else
1075  infer(diff_cu_qp_delta_depth, 0);
1076 
1077  se(pps_cb_qp_offset, -12, +12);
1078  se(pps_cr_qp_offset, -12, +12);
1079  flag(pps_slice_chroma_qp_offsets_present_flag);
1080 
1081  flag(weighted_pred_flag);
1082  flag(weighted_bipred_flag);
1083 
1084  flag(transquant_bypass_enabled_flag);
1085  flag(tiles_enabled_flag);
1086  flag(entropy_coding_sync_enabled_flag);
1087 
1088  if (current->tiles_enabled_flag) {
1089  ue(num_tile_columns_minus1, 0, HEVC_MAX_TILE_COLUMNS);
1090  ue(num_tile_rows_minus1, 0, HEVC_MAX_TILE_ROWS);
1091  flag(uniform_spacing_flag);
1092  if (!current->uniform_spacing_flag) {
1093  for (i = 0; i < current->num_tile_columns_minus1; i++)
1094  ues(column_width_minus1[i], 0, sps->pic_width_in_luma_samples, 1, i);
1095  for (i = 0; i < current->num_tile_rows_minus1; i++)
1096  ues(row_height_minus1[i], 0, sps->pic_height_in_luma_samples, 1, i);
1097  }
1098  flag(loop_filter_across_tiles_enabled_flag);
1099  } else {
1100  infer(num_tile_columns_minus1, 0);
1101  infer(num_tile_rows_minus1, 0);
1102  }
1103 
1104  flag(pps_loop_filter_across_slices_enabled_flag);
1105  flag(deblocking_filter_control_present_flag);
1106  if (current->deblocking_filter_control_present_flag) {
1107  flag(deblocking_filter_override_enabled_flag);
1108  flag(pps_deblocking_filter_disabled_flag);
1109  if (!current->pps_deblocking_filter_disabled_flag) {
1110  se(pps_beta_offset_div2, -6, +6);
1111  se(pps_tc_offset_div2, -6, +6);
1112  } else {
1113  infer(pps_beta_offset_div2, 0);
1114  infer(pps_tc_offset_div2, 0);
1115  }
1116  } else {
1117  infer(deblocking_filter_override_enabled_flag, 0);
1118  infer(pps_deblocking_filter_disabled_flag, 0);
1119  infer(pps_beta_offset_div2, 0);
1120  infer(pps_tc_offset_div2, 0);
1121  }
1122 
1123  flag(pps_scaling_list_data_present_flag);
1124  if (current->pps_scaling_list_data_present_flag)
1125  CHECK(FUNC(scaling_list_data)(ctx, rw, &current->scaling_list));
1126 
1127  flag(lists_modification_present_flag);
1128 
1129  ue(log2_parallel_merge_level_minus2,
1130  0, (sps->log2_min_luma_coding_block_size_minus3 + 3 +
1131  sps->log2_diff_max_min_luma_coding_block_size - 2));
1132 
1133  flag(slice_segment_header_extension_present_flag);
1134 
1135  flag(pps_extension_present_flag);
1136  if (current->pps_extension_present_flag) {
1137  flag(pps_range_extension_flag);
1138  flag(pps_multilayer_extension_flag);
1139  flag(pps_3d_extension_flag);
1140  flag(pps_scc_extension_flag);
1141  ub(4, pps_extension_4bits);
1142  }
1143  if (current->pps_range_extension_flag)
1144  CHECK(FUNC(pps_range_extension)(ctx, rw, current));
1145  if (current->pps_multilayer_extension_flag)
1146  return AVERROR_PATCHWELCOME;
1147  if (current->pps_3d_extension_flag)
1148  return AVERROR_PATCHWELCOME;
1149  if (current->pps_scc_extension_flag)
1150  CHECK(FUNC(pps_scc_extension)(ctx, rw, current));
1151  if (current->pps_extension_4bits)
1152  CHECK(FUNC(extension_data)(ctx, rw, &current->extension_data));
1153 
1155 
1156  return 0;
1157 }
1158 
1160  H265RawAUD *current)
1161 {
1162  int err;
1163 
1164  HEADER("Access Unit Delimiter");
1165 
1166  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, HEVC_NAL_AUD));
1167 
1168  u(3, pic_type, 0, 2);
1169 
1171 
1172  return 0;
1173 }
1174 
1176  H265RawSliceHeader *current,
1177  unsigned int num_pic_total_curr)
1178 {
1179  unsigned int entry_size;
1180  int err, i;
1181 
1182  entry_size = av_log2(num_pic_total_curr - 1) + 1;
1183 
1184  flag(ref_pic_list_modification_flag_l0);
1185  if (current->ref_pic_list_modification_flag_l0) {
1186  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++)
1187  us(entry_size, list_entry_l0[i], 0, num_pic_total_curr - 1, 1, i);
1188  }
1189 
1190  if (current->slice_type == HEVC_SLICE_B) {
1191  flag(ref_pic_list_modification_flag_l1);
1192  if (current->ref_pic_list_modification_flag_l1) {
1193  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++)
1194  us(entry_size, list_entry_l1[i], 0, num_pic_total_curr - 1, 1, i);
1195  }
1196  }
1197 
1198  return 0;
1199 }
1200 
1202  H265RawSliceHeader *current)
1203 {
1205  const H265RawSPS *sps = h265->active_sps;
1206  int err, i, j;
1207  int chroma = !sps->separate_colour_plane_flag &&
1208  sps->chroma_format_idc != 0;
1209 
1210  ue(luma_log2_weight_denom, 0, 7);
1211  if (chroma)
1212  se(delta_chroma_log2_weight_denom, -7, 7);
1213  else
1214  infer(delta_chroma_log2_weight_denom, 0);
1215 
1216  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1217  if (1 /* is not same POC and same layer_id */)
1218  flags(luma_weight_l0_flag[i], 1, i);
1219  else
1220  infer(luma_weight_l0_flag[i], 0);
1221  }
1222  if (chroma) {
1223  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1224  if (1 /* is not same POC and same layer_id */)
1225  flags(chroma_weight_l0_flag[i], 1, i);
1226  else
1227  infer(chroma_weight_l0_flag[i], 0);
1228  }
1229  }
1230 
1231  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1232  if (current->luma_weight_l0_flag[i]) {
1233  ses(delta_luma_weight_l0[i], -128, +127, 1, i);
1234  ses(luma_offset_l0[i],
1235  -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1236  ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1237  } else {
1238  infer(delta_luma_weight_l0[i], 0);
1239  infer(luma_offset_l0[i], 0);
1240  }
1241  if (current->chroma_weight_l0_flag[i]) {
1242  for (j = 0; j < 2; j++) {
1243  ses(delta_chroma_weight_l0[i][j], -128, +127, 2, i, j);
1244  ses(chroma_offset_l0[i][j],
1245  -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1246  ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1247  }
1248  } else {
1249  for (j = 0; j < 2; j++) {
1250  infer(delta_chroma_weight_l0[i][j], 0);
1251  infer(chroma_offset_l0[i][j], 0);
1252  }
1253  }
1254  }
1255 
1256  if (current->slice_type == HEVC_SLICE_B) {
1257  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1258  if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1259  flags(luma_weight_l1_flag[i], 1, i);
1260  else
1261  infer(luma_weight_l1_flag[i], 0);
1262  }
1263  if (chroma) {
1264  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1265  if (1 /* RefPicList1[i] is not CurrPic, nor is it in a different layer */)
1266  flags(chroma_weight_l1_flag[i], 1, i);
1267  else
1268  infer(chroma_weight_l1_flag[i], 0);
1269  }
1270  }
1271 
1272  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1273  if (current->luma_weight_l1_flag[i]) {
1274  ses(delta_luma_weight_l1[i], -128, +127, 1, i);
1275  ses(luma_offset_l1[i],
1276  -(1 << (sps->bit_depth_luma_minus8 + 8 - 1)),
1277  ((1 << (sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1, i);
1278  } else {
1279  infer(delta_luma_weight_l1[i], 0);
1280  infer(luma_offset_l1[i], 0);
1281  }
1282  if (current->chroma_weight_l1_flag[i]) {
1283  for (j = 0; j < 2; j++) {
1284  ses(delta_chroma_weight_l1[i][j], -128, +127, 2, i, j);
1285  ses(chroma_offset_l1[i][j],
1286  -(4 << (sps->bit_depth_chroma_minus8 + 8 - 1)),
1287  ((4 << (sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2, i, j);
1288  }
1289  } else {
1290  for (j = 0; j < 2; j++) {
1291  infer(delta_chroma_weight_l1[i][j], 0);
1292  infer(chroma_offset_l1[i][j], 0);
1293  }
1294  }
1295  }
1296  }
1297 
1298  return 0;
1299 }
1300 
1302  H265RawSliceHeader *current)
1303 {
1305  const H265RawSPS *sps;
1306  const H265RawPPS *pps;
1307  unsigned int pic_width_in_ctbs_y, pic_height_in_ctbs_y, pic_size_in_ctbs_y;
1308  unsigned int num_pic_total_curr = 0;
1309  int err, i;
1310 
1311  HEADER("Slice Segment Header");
1312 
1313  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header, -1));
1314 
1315  flag(first_slice_segment_in_pic_flag);
1316 
1317  if (current->nal_unit_header.nal_unit_type >= HEVC_NAL_BLA_W_LP &&
1318  current->nal_unit_header.nal_unit_type <= HEVC_NAL_RSV_IRAP_VCL23)
1319  flag(no_output_of_prior_pics_flag);
1320 
1321  ue(slice_pic_parameter_set_id, 0, 63);
1322 
1323  pps = h265->pps[current->slice_pic_parameter_set_id];
1324  if (!pps) {
1325  av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
1326  current->slice_pic_parameter_set_id);
1327  return AVERROR_INVALIDDATA;
1328  }
1329  h265->active_pps = pps;
1330 
1331  sps = h265->sps[pps->pps_seq_parameter_set_id];
1332  if (!sps) {
1333  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1334  pps->pps_seq_parameter_set_id);
1335  return AVERROR_INVALIDDATA;
1336  }
1337  h265->active_sps = sps;
1338 
1339  cbs_h265_pic_size_in_ctbs(sps, &pic_width_in_ctbs_y, &pic_height_in_ctbs_y);
1340  pic_size_in_ctbs_y = pic_width_in_ctbs_y * pic_height_in_ctbs_y;
1341 
1342  if (!current->first_slice_segment_in_pic_flag) {
1343  unsigned int address_size = av_log2(pic_size_in_ctbs_y - 1) + 1;
1344  if (pps->dependent_slice_segments_enabled_flag)
1345  flag(dependent_slice_segment_flag);
1346  else
1347  infer(dependent_slice_segment_flag, 0);
1348  u(address_size, slice_segment_address, 0, pic_size_in_ctbs_y - 1);
1349  } else {
1350  infer(dependent_slice_segment_flag, 0);
1351  }
1352 
1353  if (!current->dependent_slice_segment_flag) {
1354  for (i = 0; i < pps->num_extra_slice_header_bits; i++)
1355  flags(slice_reserved_flag[i], 1, i);
1356 
1357  ue(slice_type, 0, 2);
1358 
1359  if (pps->output_flag_present_flag)
1360  flag(pic_output_flag);
1361 
1362  if (sps->separate_colour_plane_flag)
1363  u(2, colour_plane_id, 0, 2);
1364 
1365  if (current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_W_RADL &&
1366  current->nal_unit_header.nal_unit_type != HEVC_NAL_IDR_N_LP) {
1367  const H265RawSTRefPicSet *rps;
1368  int dpb_slots_remaining;
1369 
1370  ub(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, slice_pic_order_cnt_lsb);
1371 
1372  flag(short_term_ref_pic_set_sps_flag);
1373  if (!current->short_term_ref_pic_set_sps_flag) {
1374  CHECK(FUNC(st_ref_pic_set)(ctx, rw, &current->short_term_ref_pic_set,
1375  sps->num_short_term_ref_pic_sets, sps));
1376  rps = &current->short_term_ref_pic_set;
1377  } else if (sps->num_short_term_ref_pic_sets > 1) {
1378  unsigned int idx_size = av_log2(sps->num_short_term_ref_pic_sets - 1) + 1;
1379  u(idx_size, short_term_ref_pic_set_idx,
1380  0, sps->num_short_term_ref_pic_sets - 1);
1381  rps = &sps->st_ref_pic_set[current->short_term_ref_pic_set_idx];
1382  } else {
1383  infer(short_term_ref_pic_set_idx, 0);
1384  rps = &sps->st_ref_pic_set[0];
1385  }
1386 
1387  dpb_slots_remaining = HEVC_MAX_DPB_SIZE - 1 -
1389  if (pps->pps_curr_pic_ref_enabled_flag &&
1390  (sps->sample_adaptive_offset_enabled_flag ||
1391  !pps->pps_deblocking_filter_disabled_flag ||
1392  pps->deblocking_filter_override_enabled_flag)) {
1393  // This picture will occupy two DPB slots.
1394  if (dpb_slots_remaining == 0) {
1395  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid stream: "
1396  "short-term ref pic set contains too many pictures "
1397  "to use with current picture reference enabled.\n");
1398  return AVERROR_INVALIDDATA;
1399  }
1400  --dpb_slots_remaining;
1401  }
1402 
1403  num_pic_total_curr = 0;
1404  for (i = 0; i < rps->num_negative_pics; i++)
1405  if (rps->used_by_curr_pic_s0_flag[i])
1406  ++num_pic_total_curr;
1407  for (i = 0; i < rps->num_positive_pics; i++)
1408  if (rps->used_by_curr_pic_s1_flag[i])
1409  ++num_pic_total_curr;
1410 
1411  if (sps->long_term_ref_pics_present_flag) {
1412  unsigned int idx_size;
1413 
1414  if (sps->num_long_term_ref_pics_sps > 0) {
1415  ue(num_long_term_sps, 0, FFMIN(sps->num_long_term_ref_pics_sps,
1416  dpb_slots_remaining));
1417  idx_size = av_log2(sps->num_long_term_ref_pics_sps - 1) + 1;
1418  dpb_slots_remaining -= current->num_long_term_sps;
1419  } else {
1420  infer(num_long_term_sps, 0);
1421  idx_size = 0;
1422  }
1423  ue(num_long_term_pics, 0, dpb_slots_remaining);
1424 
1425  for (i = 0; i < current->num_long_term_sps +
1426  current->num_long_term_pics; i++) {
1427  if (i < current->num_long_term_sps) {
1428  if (sps->num_long_term_ref_pics_sps > 1)
1429  us(idx_size, lt_idx_sps[i],
1430  0, sps->num_long_term_ref_pics_sps - 1, 1, i);
1431  if (sps->used_by_curr_pic_lt_sps_flag[current->lt_idx_sps[i]])
1432  ++num_pic_total_curr;
1433  } else {
1434  ubs(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[i], 1, i);
1435  flags(used_by_curr_pic_lt_flag[i], 1, i);
1436  if (current->used_by_curr_pic_lt_flag[i])
1437  ++num_pic_total_curr;
1438  }
1439  flags(delta_poc_msb_present_flag[i], 1, i);
1440  if (current->delta_poc_msb_present_flag[i])
1441  ues(delta_poc_msb_cycle_lt[i], 0, UINT32_MAX - 1, 1, i);
1442  else
1443  infer(delta_poc_msb_cycle_lt[i], 0);
1444  }
1445  }
1446 
1447  if (sps->sps_temporal_mvp_enabled_flag)
1448  flag(slice_temporal_mvp_enabled_flag);
1449  else
1450  infer(slice_temporal_mvp_enabled_flag, 0);
1451 
1452  if (pps->pps_curr_pic_ref_enabled_flag)
1453  ++num_pic_total_curr;
1454  }
1455 
1456  if (sps->sample_adaptive_offset_enabled_flag) {
1457  flag(slice_sao_luma_flag);
1458  if (!sps->separate_colour_plane_flag && sps->chroma_format_idc != 0)
1459  flag(slice_sao_chroma_flag);
1460  else
1461  infer(slice_sao_chroma_flag, 0);
1462  } else {
1463  infer(slice_sao_luma_flag, 0);
1464  infer(slice_sao_chroma_flag, 0);
1465  }
1466 
1467  if (current->slice_type == HEVC_SLICE_P ||
1468  current->slice_type == HEVC_SLICE_B) {
1469  flag(num_ref_idx_active_override_flag);
1470  if (current->num_ref_idx_active_override_flag) {
1471  ue(num_ref_idx_l0_active_minus1, 0, 14);
1472  if (current->slice_type == HEVC_SLICE_B)
1473  ue(num_ref_idx_l1_active_minus1, 0, 14);
1474  else
1475  infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1476  } else {
1477  infer(num_ref_idx_l0_active_minus1, pps->num_ref_idx_l0_default_active_minus1);
1478  infer(num_ref_idx_l1_active_minus1, pps->num_ref_idx_l1_default_active_minus1);
1479  }
1480 
1481  if (pps->lists_modification_present_flag && num_pic_total_curr > 1)
1482  CHECK(FUNC(ref_pic_lists_modification)(ctx, rw, current,
1483  num_pic_total_curr));
1484 
1485  if (current->slice_type == HEVC_SLICE_B)
1486  flag(mvd_l1_zero_flag);
1487  if (pps->cabac_init_present_flag)
1488  flag(cabac_init_flag);
1489  else
1490  infer(cabac_init_flag, 0);
1491  if (current->slice_temporal_mvp_enabled_flag) {
1492  if (current->slice_type == HEVC_SLICE_B)
1493  flag(collocated_from_l0_flag);
1494  else
1495  infer(collocated_from_l0_flag, 1);
1496  if (current->collocated_from_l0_flag) {
1497  if (current->num_ref_idx_l0_active_minus1 > 0)
1498  ue(collocated_ref_idx, 0, current->num_ref_idx_l0_active_minus1);
1499  else
1500  infer(collocated_ref_idx, 0);
1501  } else {
1502  if (current->num_ref_idx_l1_active_minus1 > 0)
1503  ue(collocated_ref_idx, 0, current->num_ref_idx_l1_active_minus1);
1504  else
1505  infer(collocated_ref_idx, 0);
1506  }
1507  }
1508 
1509  if ((pps->weighted_pred_flag && current->slice_type == HEVC_SLICE_P) ||
1510  (pps->weighted_bipred_flag && current->slice_type == HEVC_SLICE_B))
1511  CHECK(FUNC(pred_weight_table)(ctx, rw, current));
1512 
1513  ue(five_minus_max_num_merge_cand, 0, 4);
1514  if (sps->motion_vector_resolution_control_idc == 2)
1515  flag(use_integer_mv_flag);
1516  else
1517  infer(use_integer_mv_flag, sps->motion_vector_resolution_control_idc);
1518  }
1519 
1520  se(slice_qp_delta,
1521  - 6 * sps->bit_depth_luma_minus8 - (pps->init_qp_minus26 + 26),
1522  + 51 - (pps->init_qp_minus26 + 26));
1523  if (pps->pps_slice_chroma_qp_offsets_present_flag) {
1524  se(slice_cb_qp_offset, -12, +12);
1525  se(slice_cr_qp_offset, -12, +12);
1526  } else {
1527  infer(slice_cb_qp_offset, 0);
1528  infer(slice_cr_qp_offset, 0);
1529  }
1530  if (pps->pps_slice_act_qp_offsets_present_flag) {
1531  se(slice_act_y_qp_offset,
1532  -12 - (pps->pps_act_y_qp_offset_plus5 - 5),
1533  +12 - (pps->pps_act_y_qp_offset_plus5 - 5));
1534  se(slice_act_cb_qp_offset,
1535  -12 - (pps->pps_act_cb_qp_offset_plus5 - 5),
1536  +12 - (pps->pps_act_cb_qp_offset_plus5 - 5));
1537  se(slice_act_cr_qp_offset,
1538  -12 - (pps->pps_act_cr_qp_offset_plus3 - 3),
1539  +12 - (pps->pps_act_cr_qp_offset_plus3 - 3));
1540  } else {
1541  infer(slice_act_y_qp_offset, 0);
1542  infer(slice_act_cb_qp_offset, 0);
1543  infer(slice_act_cr_qp_offset, 0);
1544  }
1545  if (pps->chroma_qp_offset_list_enabled_flag)
1546  flag(cu_chroma_qp_offset_enabled_flag);
1547  else
1548  infer(cu_chroma_qp_offset_enabled_flag, 0);
1549 
1550  if (pps->deblocking_filter_override_enabled_flag)
1551  flag(deblocking_filter_override_flag);
1552  else
1553  infer(deblocking_filter_override_flag, 0);
1554  if (current->deblocking_filter_override_flag) {
1555  flag(slice_deblocking_filter_disabled_flag);
1556  if (!current->slice_deblocking_filter_disabled_flag) {
1557  se(slice_beta_offset_div2, -6, +6);
1558  se(slice_tc_offset_div2, -6, +6);
1559  } else {
1560  infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1561  infer(slice_tc_offset_div2, pps->pps_tc_offset_div2);
1562  }
1563  } else {
1564  infer(slice_deblocking_filter_disabled_flag,
1565  pps->pps_deblocking_filter_disabled_flag);
1566  infer(slice_beta_offset_div2, pps->pps_beta_offset_div2);
1567  infer(slice_tc_offset_div2, pps->pps_tc_offset_div2);
1568  }
1569  if (pps->pps_loop_filter_across_slices_enabled_flag &&
1570  (current->slice_sao_luma_flag || current->slice_sao_chroma_flag ||
1571  !current->slice_deblocking_filter_disabled_flag))
1572  flag(slice_loop_filter_across_slices_enabled_flag);
1573  else
1574  infer(slice_loop_filter_across_slices_enabled_flag,
1575  pps->pps_loop_filter_across_slices_enabled_flag);
1576  }
1577 
1578  if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
1579  unsigned int num_entry_point_offsets_limit;
1580  if (!pps->tiles_enabled_flag && pps->entropy_coding_sync_enabled_flag)
1581  num_entry_point_offsets_limit = pic_height_in_ctbs_y - 1;
1582  else if (pps->tiles_enabled_flag && !pps->entropy_coding_sync_enabled_flag)
1583  num_entry_point_offsets_limit =
1584  (pps->num_tile_columns_minus1 + 1) * (pps->num_tile_rows_minus1 + 1);
1585  else
1586  num_entry_point_offsets_limit =
1587  (pps->num_tile_columns_minus1 + 1) * pic_height_in_ctbs_y - 1;
1588  ue(num_entry_point_offsets, 0, num_entry_point_offsets_limit);
1589 
1590  if (current->num_entry_point_offsets > HEVC_MAX_ENTRY_POINT_OFFSETS) {
1591  av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many entry points: "
1592  "%"PRIu16".\n", current->num_entry_point_offsets);
1593  return AVERROR_PATCHWELCOME;
1594  }
1595 
1596  if (current->num_entry_point_offsets > 0) {
1597  ue(offset_len_minus1, 0, 31);
1598  for (i = 0; i < current->num_entry_point_offsets; i++)
1599  ubs(current->offset_len_minus1 + 1, entry_point_offset_minus1[i], 1, i);
1600  }
1601  }
1602 
1603  if (pps->slice_segment_header_extension_present_flag) {
1604  ue(slice_segment_header_extension_length, 0, 256);
1605  for (i = 0; i < current->slice_segment_header_extension_length; i++)
1606  us(8, slice_segment_header_extension_data_byte[i], 0x00, 0xff, 1, i);
1607  }
1608 
1609  CHECK(FUNC(byte_alignment)(ctx, rw));
1610 
1611  return 0;
1612 }
1613 
1617 {
1619  const H265RawSPS *sps;
1620  const H265RawHRDParameters *hrd;
1621  int err, i, length;
1622 
1623 #ifdef READ
1624  int start_pos, end_pos;
1625  start_pos = get_bits_count(rw);
1626 #endif
1627 
1628  HEADER("Buffering Period");
1629 
1630  ue(bp_seq_parameter_set_id, 0, HEVC_MAX_SPS_COUNT - 1);
1631 
1632  sps = h265->sps[current->bp_seq_parameter_set_id];
1633  if (!sps) {
1634  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1635  current->bp_seq_parameter_set_id);
1636  return AVERROR_INVALIDDATA;
1637  }
1638  h265->active_sps = sps;
1639 
1640  if (!sps->vui_parameters_present_flag ||
1641  !sps->vui.vui_hrd_parameters_present_flag) {
1642  av_log(ctx->log_ctx, AV_LOG_ERROR, "Buffering period SEI requires "
1643  "HRD parameters to be present in SPS.\n");
1644  return AVERROR_INVALIDDATA;
1645  }
1646  hrd = &sps->vui.hrd_parameters;
1647  if (!hrd->nal_hrd_parameters_present_flag &&
1649  av_log(ctx->log_ctx, AV_LOG_ERROR, "Buffering period SEI requires "
1650  "NAL or VCL HRD parameters to be present.\n");
1651  return AVERROR_INVALIDDATA;
1652  }
1653 
1655  flag(irap_cpb_params_present_flag);
1656  else
1657  infer(irap_cpb_params_present_flag, 0);
1658  if (current->irap_cpb_params_present_flag) {
1659  length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1660  ub(length, cpb_delay_offset);
1661  length = hrd->dpb_output_delay_length_minus1 + 1;
1662  ub(length, dpb_delay_offset);
1663  } else {
1664  infer(cpb_delay_offset, 0);
1665  infer(dpb_delay_offset, 0);
1666  }
1667 
1668  flag(concatenation_flag);
1669 
1670  length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1671  ub(length, au_cpb_removal_delay_delta_minus1);
1672 
1674  for (i = 0; i <= hrd->cpb_cnt_minus1[0]; i++) {
1675  length = hrd->initial_cpb_removal_delay_length_minus1 + 1;
1676 
1677  ubs(length, nal_initial_cpb_removal_delay[i], 1, i);
1678  ubs(length, nal_initial_cpb_removal_offset[i], 1, i);
1679 
1681  current->irap_cpb_params_present_flag) {
1682  ubs(length, nal_initial_alt_cpb_removal_delay[i], 1, i);
1683  ubs(length, nal_initial_alt_cpb_removal_offset[i], 1, i);
1684  }
1685  }
1686  }
1688  for (i = 0; i <= hrd->cpb_cnt_minus1[0]; i++) {
1689  length = hrd->initial_cpb_removal_delay_length_minus1 + 1;
1690 
1691  ubs(length, vcl_initial_cpb_removal_delay[i], 1, i);
1692  ubs(length, vcl_initial_cpb_removal_offset[i], 1, i);
1693 
1695  current->irap_cpb_params_present_flag) {
1696  ubs(length, vcl_initial_alt_cpb_removal_delay[i], 1, i);
1697  ubs(length, vcl_initial_alt_cpb_removal_offset[i], 1, i);
1698  }
1699  }
1700  }
1701 
1702 #ifdef READ
1703  end_pos = get_bits_count(rw);
1704  if (cbs_h265_payload_extension_present(rw, sei->payload_size,
1705  end_pos - start_pos))
1706  flag(use_alt_cpb_params_flag);
1707  else
1708  infer(use_alt_cpb_params_flag, 0);
1709 #else
1710  // If unknown extension data exists, then use_alt_cpb_params_flag is
1711  // coded in the bitstream and must be written even if it's 0.
1712  if (current->use_alt_cpb_params_flag || sei->extension_present) {
1713  flag(use_alt_cpb_params_flag);
1714  // Ensure this bit is not the last in the payload by making the
1715  // more_data_in_payload() check evaluate to true, so it may not
1716  // be mistaken as something else by decoders.
1717  sei->extension_present = 1;
1718  }
1719 #endif
1720 
1721  return 0;
1722 }
1723 
1727 {
1729  const H265RawSPS *sps;
1730  const H265RawHRDParameters *hrd;
1731  int err, expected_source_scan_type, i, length;
1732 
1733  HEADER("Picture Timing");
1734 
1735  sps = h265->active_sps;
1736  if (!sps) {
1737  av_log(ctx->log_ctx, AV_LOG_ERROR,
1738  "No active SPS for pic_timing.\n");
1739  return AVERROR_INVALIDDATA;
1740  }
1741 
1742  expected_source_scan_type = 2 -
1743  2 * sps->profile_tier_level.general_interlaced_source_flag -
1744  sps->profile_tier_level.general_progressive_source_flag;
1745 
1746  if (sps->vui.frame_field_info_present_flag) {
1747  u(4, pic_struct, 0, 12);
1748  u(2, source_scan_type,
1749  expected_source_scan_type >= 0 ? expected_source_scan_type : 0,
1750  expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1751  flag(duplicate_flag);
1752  } else {
1753  infer(pic_struct, 0);
1754  infer(source_scan_type,
1755  expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1756  infer(duplicate_flag, 0);
1757  }
1758 
1759  if (sps->vui_parameters_present_flag &&
1760  sps->vui.vui_hrd_parameters_present_flag)
1761  hrd = &sps->vui.hrd_parameters;
1762  else
1763  hrd = NULL;
1764  if (hrd && (hrd->nal_hrd_parameters_present_flag ||
1766  length = hrd->au_cpb_removal_delay_length_minus1 + 1;
1767  ub(length, au_cpb_removal_delay_minus1);
1768 
1769  length = hrd->dpb_output_delay_length_minus1 + 1;
1770  ub(length, pic_dpb_output_delay);
1771 
1773  length = hrd->dpb_output_delay_du_length_minus1 + 1;
1774  ub(length, pic_dpb_output_du_delay);
1775  }
1776 
1779  unsigned int pic_width_in_ctbs_y, pic_height_in_ctbs_y;
1780  cbs_h265_pic_size_in_ctbs(sps, &pic_width_in_ctbs_y, &pic_height_in_ctbs_y);
1781  // D.3.3 bounds this by PicSizeInCtbsY - 1. A decoding unit holds at
1782  // least one VCL NAL unit (3.47) and no level allows a picture more
1783  // than HEVC_MAX_SLICE_SEGMENTS slice segments (A.4.2), which is also
1784  // the size of the arrays indexed by it.
1785  ue(num_decoding_units_minus1, 0,
1786  FFMIN(pic_width_in_ctbs_y * pic_height_in_ctbs_y - 1, HEVC_MAX_SLICE_SEGMENTS - 1));
1787  flag(du_common_cpb_removal_delay_flag);
1788 
1790  if (current->du_common_cpb_removal_delay_flag)
1791  ub(length, du_common_cpb_removal_delay_increment_minus1);
1792 
1793  for (i = 0; i <= current->num_decoding_units_minus1; i++) {
1794  ues(num_nalus_in_du_minus1[i],
1795  0, HEVC_MAX_SLICE_SEGMENTS, 1, i);
1796  if (!current->du_common_cpb_removal_delay_flag &&
1797  i < current->num_decoding_units_minus1)
1798  ubs(length, du_cpb_removal_delay_increment_minus1[i], 1, i);
1799  }
1800  }
1801  }
1802 
1803  return 0;
1804 }
1805 
1809 {
1810  int err, i;
1811 
1812  HEADER("Pan-Scan Rectangle");
1813 
1814  ue(pan_scan_rect_id, 0, UINT32_MAX - 1);
1815  flag(pan_scan_rect_cancel_flag);
1816 
1817  if (!current->pan_scan_rect_cancel_flag) {
1818  ue(pan_scan_cnt_minus1, 0, 2);
1819 
1820  for (i = 0; i <= current->pan_scan_cnt_minus1; i++) {
1821  ses(pan_scan_rect_left_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
1822  ses(pan_scan_rect_right_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
1823  ses(pan_scan_rect_top_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
1824  ses(pan_scan_rect_bottom_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
1825  }
1826 
1827  flag(pan_scan_rect_persistence_flag);
1828  }
1829 
1830  return 0;
1831 }
1832 
1836 {
1837  int err;
1838 
1839  HEADER("Recovery Point");
1840 
1841  se(recovery_poc_cnt, -32768, 32767);
1842 
1843  flag(exact_match_flag);
1844  flag(broken_link_flag);
1845 
1846  return 0;
1847 }
1848 
1852 {
1853  int err;
1854 
1855  HEADER("Display Orientation");
1856 
1857  flag(display_orientation_cancel_flag);
1858  if (!current->display_orientation_cancel_flag) {
1859  flag(hor_flip);
1860  flag(ver_flip);
1861  ub(16, anticlockwise_rotation);
1862  flag(display_orientation_persistence_flag);
1863  }
1864 
1865  return 0;
1866 }
1867 
1871 {
1873  const H265RawVPS *vps;
1874  int err, i;
1875 
1876  HEADER("Active Parameter Sets");
1877 
1878  u(4, active_video_parameter_set_id, 0, HEVC_MAX_VPS_COUNT);
1879  vps = h265->vps[current->active_video_parameter_set_id];
1880  if (!vps) {
1881  av_log(ctx->log_ctx, AV_LOG_ERROR, "VPS id %d not available for active "
1882  "parameter sets.\n", current->active_video_parameter_set_id);
1883  return AVERROR_INVALIDDATA;
1884  }
1885  h265->active_vps = vps;
1886 
1887  flag(self_contained_cvs_flag);
1888  flag(no_parameter_set_update_flag);
1889 
1890  ue(num_sps_ids_minus1, 0, HEVC_MAX_SPS_COUNT - 1);
1891  for (i = 0; i <= current->num_sps_ids_minus1; i++)
1892  ues(active_seq_parameter_set_id[i], 0, HEVC_MAX_SPS_COUNT - 1, 1, i);
1893 
1894  for (i = vps->vps_base_layer_internal_flag;
1895  i <= FFMIN(62, vps->vps_max_layers_minus1); i++) {
1896  ues(layer_sps_idx[i], 0, current->num_sps_ids_minus1, 1, i);
1897 
1898  if (i == 0)
1899  h265->active_sps = h265->sps[current->active_seq_parameter_set_id[current->layer_sps_idx[0]]];
1900  }
1901 
1902  return 0;
1903 }
1904 
1908 {
1910  const H265RawSPS *sps = h265->active_sps;
1911  int err, c, i;
1912 
1913  HEADER("Decoded Picture Hash");
1914 
1915  if (!sps) {
1916  av_log(ctx->log_ctx, AV_LOG_ERROR,
1917  "No active SPS for decoded picture hash.\n");
1918  return AVERROR_INVALIDDATA;
1919  }
1920 
1921  u(8, hash_type, 0, 2);
1922 
1923  for (c = 0; c < (sps->chroma_format_idc == 0 ? 1 : 3); c++) {
1924  if (current->hash_type == 0) {
1925  for (i = 0; i < 16; i++)
1926  us(8, picture_md5[c][i], 0x00, 0xff, 2, c, i);
1927  } else if (current->hash_type == 1) {
1928  us(16, picture_crc[c], 0x0000, 0xffff, 1, c);
1929  } else if (current->hash_type == 2) {
1930  us(32, picture_checksum[c], 0x00000000, 0xffffffff, 1, c);
1931  }
1932  }
1933 
1934  return 0;
1935 }
1936 
1937 static int FUNC(sei_time_code)
1940 {
1941  int err, i;
1942 
1943  HEADER("Time Code");
1944 
1945  u(2, num_clock_ts, 1, 3);
1946 
1947  for (i = 0; i < current->num_clock_ts; i++) {
1948  flags(clock_timestamp_flag[i], 1, i);
1949 
1950  if (current->clock_timestamp_flag[i]) {
1951  flags(units_field_based_flag[i], 1, i);
1952  us(5, counting_type[i], 0, 6, 1, i);
1953  flags(full_timestamp_flag[i], 1, i);
1954  flags(discontinuity_flag[i], 1, i);
1955  flags(cnt_dropped_flag[i], 1, i);
1956 
1957  ubs(9, n_frames[i], 1, i);
1958 
1959  if (current->full_timestamp_flag[i]) {
1960  us(6, seconds_value[i], 0, 59, 1, i);
1961  us(6, minutes_value[i], 0, 59, 1, i);
1962  us(5, hours_value[i], 0, 23, 1, i);
1963  } else {
1964  flags(seconds_flag[i], 1, i);
1965  if (current->seconds_flag[i]) {
1966  us(6, seconds_value[i], 0, 59, 1, i);
1967  flags(minutes_flag[i], 1, i);
1968  if (current->minutes_flag[i]) {
1969  us(6, minutes_value[i], 0, 59, 1, i);
1970  flags(hours_flag[i], 1, i);
1971  if (current->hours_flag[i])
1972  us(5, hours_value[i], 0, 23, 1, i);
1973  }
1974  }
1975  }
1976 
1977  ubs(5, time_offset_length[i], 1, i);
1978  if (current->time_offset_length[i] > 0)
1979  ibs(current->time_offset_length[i], time_offset_value[i], 1, i);
1980  else
1981  infer(time_offset_value[i], 0);
1982  }
1983  }
1984 
1985  return 0;
1986 }
1987 
1991 {
1992  int err, length;
1993 
1994  HEADER("Alpha Channel Information");
1995 
1996  flag(alpha_channel_cancel_flag);
1997  if (!current->alpha_channel_cancel_flag) {
1998  ub(3, alpha_channel_use_idc);
1999  ub(3, alpha_channel_bit_depth_minus8);
2000  length = current->alpha_channel_bit_depth_minus8 + 9;
2001  ub(length, alpha_transparent_value);
2002  ub(length, alpha_opaque_value);
2003  flag(alpha_channel_incr_flag);
2004  flag(alpha_channel_clip_flag);
2005  if (current->alpha_channel_clip_flag)
2006  flag(alpha_channel_clip_type_flag);
2007  } else {
2008  infer(alpha_channel_use_idc, 2);
2009  infer(alpha_channel_incr_flag, 0);
2010  infer(alpha_channel_clip_flag, 0);
2011  }
2012 
2013  return 0;
2014 }
2015 
2017  H265RawSEI *current, int prefix)
2018 {
2019  int err;
2020 
2021  if (prefix)
2022  HEADER("Prefix Supplemental Enhancement Information");
2023  else
2024  HEADER("Suffix Supplemental Enhancement Information");
2025 
2026  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
2027  prefix ? HEVC_NAL_SEI_PREFIX
2028  : HEVC_NAL_SEI_SUFFIX));
2029 
2030  CHECK(FUNC_SEI(message_list)(ctx, rw, &current->message_list, prefix));
2031 
2033 
2034  return 0;
2035 }
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:254
uint8_t
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define FUNC(a)
#define fixed(width, name, value)
Definition: cbs_av1.c:577
#define flag(name)
Definition: cbs_av1.c:564
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define infer(name, value)
Definition: cbs_av1.c:720
#define RWContext
Definition: cbs_av1.c:673
#define HEADER(name)
Definition: cbs_av1.c:544
#define allocate(name, size)
Definition: cbs_h2645.c:442
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:274
#define ue(name, range_min, range_max)
Definition: cbs_h2645.c:279
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:288
#define ub(width, name)
Definition: cbs_h2645.c:276
static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t payload_size, int cur_pos)
Definition: cbs_h2645.c:238
static void cbs_h265_pic_size_in_ctbs(const H265RawSPS *sps, unsigned int *width, unsigned int *height)
Definition: cbs_h2645.c:247
#define ubs(width, name, subs,...)
Definition: cbs_h2645.c:290
#define ues(name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:294
#define FUNC_SEI(name)
Definition: cbs_h2645.c:270
#define ibs(width, name, subs,...)
Definition: cbs_h2645.c:298
static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
Definition: cbs_h2645.c:347
#define ses(name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:300
#define xu(width, name, var, range_min, range_max, subs,...)
Definition: cbs_h2645.c:402
#define se(name, range_min, range_max)
Definition: cbs_h2645.c:285
static int FUNC() slice_segment_header(CodedBitstreamContext *ctx, RWContext *rw, H265RawSliceHeader *current)
static int FUNC() sei_decoded_picture_hash(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIDecodedPictureHash *current, SEIMessageState *sei)
static int FUNC() byte_alignment(CodedBitstreamContext *ctx, RWContext *rw)
static int FUNC() profile_tier_level(CodedBitstreamContext *ctx, RWContext *rw, H265RawProfileTierLevel *current, int profile_present_flag, int max_num_sub_layers_minus1)
static int FUNC() sei_active_parameter_sets(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIActiveParameterSets *current, SEIMessageState *sei)
static int FUNC() vui_parameters_default(CodedBitstreamContext *ctx, RWContext *rw, H265RawVUI *current, H265RawSPS *sps)
static int FUNC() scaling_list_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawScalingList *current)
static int FUNC() sei_alpha_channel_info(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIAlphaChannelInfo *current, SEIMessageState *sei)
static int FUNC() sei_buffering_period(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIBufferingPeriod *current, SEIMessageState *sei)
static int FUNC() pps_range_extension(CodedBitstreamContext *ctx, RWContext *rw, H265RawPPS *current)
static int FUNC() ref_pic_lists_modification(CodedBitstreamContext *ctx, RWContext *rw, H265RawSliceHeader *current, unsigned int num_pic_total_curr)
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static int FUNC() pps_scc_extension(CodedBitstreamContext *ctx, RWContext *rw, H265RawPPS *current)
static int FUNC() st_ref_pic_set(CodedBitstreamContext *ctx, RWContext *rw, H265RawSTRefPicSet *current, int st_rps_idx, const H265RawSPS *sps)
static int FUNC() vui_parameters(CodedBitstreamContext *ctx, RWContext *rw, H265RawVUI *current, const H265RawSPS *sps)
static int FUNC() sei_pan_scan_rect(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIPanScanRect *current, SEIMessageState *sei)
#define profile_compatible(x)
static int FUNC() nal_unit_header(CodedBitstreamContext *ctx, RWContext *rw, H265RawNALUnitHeader *current, int expected_nal_unit_type)
static int FUNC() sei_recovery_point(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIRecoveryPoint *current, SEIMessageState *sei)
static int FUNC() sei_pic_timing(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIPicTiming *current, SEIMessageState *sei)
static int FUNC() sei_display_orientation(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIDisplayOrientation *current, SEIMessageState *sei)
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEI *current, int prefix)
static int FUNC() sps_range_extension(CodedBitstreamContext *ctx, RWContext *rw, H265RawSPS *current)
static int FUNC() pred_weight_table(CodedBitstreamContext *ctx, RWContext *rw, H265RawSliceHeader *current)
static int FUNC() sub_layer_hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H265RawHRDParameters *hrd, int nal, int sub_layer_id)
static int FUNC() hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H265RawHRDParameters *current, int common_inf_present_flag, int max_num_sub_layers_minus1)
static int FUNC() extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawExtensionData *current)
static int FUNC() sei_time_code(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEITimeCode *current, SEIMessageState *sei)
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H265RawPPS *current)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H265RawSPS *current)
static int FUNC() rbsp_trailing_bits(CodedBitstreamContext *ctx, RWContext *rw)
static int FUNC() sps_scc_extension(CodedBitstreamContext *ctx, RWContext *rw, H265RawSPS *current)
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H265RawAUD *current)
#define bit(string, value)
Definition: cbs_mpeg2.c:58
static int FUNC() message_list(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMessageList *current, int prefix)
#define FFMIN(a, b)
Definition: common.h:105
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:85
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
int i
Definition: input.c:407
#define av_log2
Definition: intmath.h:83
@ HEVC_NAL_RSV_IRAP_VCL23
Definition: hevc.h:52
@ HEVC_NAL_BLA_W_LP
Definition: hevc.h:45
@ HEVC_NAL_AUD
Definition: hevc.h:64
@ HEVC_NAL_IDR_W_RADL
Definition: hevc.h:48
@ HEVC_NAL_IDR_N_LP
Definition: hevc.h:49
@ HEVC_NAL_SEI_SUFFIX
Definition: hevc.h:69
@ HEVC_NAL_SEI_PREFIX
Definition: hevc.h:68
@ HEVC_NAL_PPS
Definition: hevc.h:63
@ HEVC_NAL_VPS
Definition: hevc.h:61
@ HEVC_NAL_SPS
Definition: hevc.h:62
@ HEVC_SLICE_P
Definition: hevc.h:97
@ HEVC_SLICE_B
Definition: hevc.h:96
@ HEVC_MAX_ENTRY_POINT_OFFSETS
Definition: hevc.h:156
@ HEVC_MAX_LONG_TERM_REF_PICS
Definition: hevc.h:124
@ HEVC_MAX_WIDTH
Definition: hevc.h:138
@ HEVC_MAX_SPS_COUNT
Definition: hevc.h:112
@ HEVC_MAX_SLICE_SEGMENTS
Definition: hevc.h:147
@ HEVC_MAX_TILE_ROWS
Definition: hevc.h:142
@ HEVC_MAX_REFS
Definition: hevc.h:119
@ HEVC_MAX_TILE_COLUMNS
Definition: hevc.h:144
@ HEVC_MAX_HEIGHT
Definition: hevc.h:139
@ HEVC_MAX_LAYER_SETS
Definition: hevc.h:107
@ HEVC_MAX_SUB_LAYERS
Definition: hevc.h:105
@ HEVC_MAX_VPS_COUNT
Definition: hevc.h:110
@ HEVC_MAX_LAYERS
Definition: hevc.h:103
@ HEVC_MAX_SHORT_TERM_REF_PIC_SETS
Definition: hevc.h:122
@ HEVC_MAX_DPB_SIZE
Definition: hevc.h:117
static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
void * priv_data
Format private data.
Definition: avformat.h:1260
Context structure for coded bitstream operations.
Definition: cbs.h:170
const H265RawVPS * active_vps
Definition: cbs_h265.h:673
const H265RawSPS * active_sps
Definition: cbs_h265.h:674
H265RawVPS * vps[HEVC_MAX_VPS_COUNT]
Definition: cbs_h265.h:666
H265RawSPS * sps[HEVC_MAX_SPS_COUNT]
Definition: cbs_h265.h:667
const H265RawPPS * active_pps
Definition: cbs_h265.h:675
H265RawPPS * pps[HEVC_MAX_PPS_COUNT]
Definition: cbs_h265.h:668
uint8_t dpb_output_delay_length_minus1
Definition: cbs_h265.h:116
uint8_t sub_pic_cpb_params_in_pic_timing_sei_flag
Definition: cbs_h265.h:107
uint8_t initial_cpb_removal_delay_length_minus1
Definition: cbs_h265.h:114
uint8_t cpb_cnt_minus1[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:122
uint8_t du_cpb_removal_delay_increment_length_minus1
Definition: cbs_h265.h:106
uint8_t nal_hrd_parameters_present_flag
Definition: cbs_h265.h:101
uint8_t vcl_hrd_parameters_present_flag
Definition: cbs_h265.h:102
uint8_t au_cpb_removal_delay_length_minus1
Definition: cbs_h265.h:115
uint8_t sub_pic_hrd_params_present_flag
Definition: cbs_h265.h:104
uint8_t dpb_output_delay_du_length_minus1
Definition: cbs_h265.h:108
uint8_t num_positive_pics
Definition: cbs_h265.h:230
uint8_t num_negative_pics
Definition: cbs_h265.h:229
uint8_t used_by_curr_pic_s0_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:232
uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:234
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AVFormatContext * ctx
Definition: movenc.c:48
CHECK(-1) CHECK(-2) }} }} CHECK(1) CHECK(2) }} }} } if(diff0+diff1 > 0) temp -
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:1625
static double c[64]