FFmpeg
hevc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Tim Walker <tdskywalker@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavcodec/get_bits.h"
22 #include "libavcodec/golomb.h"
23 #include "libavcodec/hevc/hevc.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem.h"
26 #include "avc.h"
27 #include "avio.h"
28 #include "avio_internal.h"
29 #include "hevc.h"
30 #include "nal.h"
31 
32 #define MAX_SPATIAL_SEGMENTATION 4096 // max. value of u(12) field
33 
34 enum {
41 };
42 
43 
44 #define FLAG_ARRAY_COMPLETENESS (1 << 0)
45 #define FLAG_IS_NALFF (1 << 1)
46 #define FLAG_IS_LHVC (1 << 2)
47 
48 typedef struct HVCCNALUnit {
49  uint8_t nuh_layer_id;
51  uint16_t nalUnitLength;
52  const uint8_t *nalUnit;
53 
54  // VPS
56 } HVCCNALUnit;
57 
58 typedef struct HVCCNALUnitArray {
60  uint8_t NAL_unit_type;
61  uint16_t numNalus;
64 
74  uint8_t parallelismType;
75  uint8_t chromaFormat;
78  uint16_t avgFrameRate;
83  uint8_t numOfArrays;
85 
88 
89 typedef struct HVCCProfileTierLevel {
90  uint8_t profile_space;
91  uint8_t tier_flag;
92  uint8_t profile_idc;
95  uint8_t level_idc;
97 
100 {
101  /*
102  * The value of general_profile_space in all the parameter sets must be
103  * identical.
104  */
105  hvcc->general_profile_space = ptl->profile_space;
106 
107  /*
108  * The level indication general_level_idc must indicate a level of
109  * capability equal to or greater than the highest level indicated for the
110  * highest tier in all the parameter sets.
111  */
112  if (hvcc->general_tier_flag < ptl->tier_flag)
113  hvcc->general_level_idc = ptl->level_idc;
114  else
115  hvcc->general_level_idc = FFMAX(hvcc->general_level_idc, ptl->level_idc);
116 
117  /*
118  * The tier indication general_tier_flag must indicate a tier equal to or
119  * greater than the highest tier indicated in all the parameter sets.
120  */
121  hvcc->general_tier_flag = FFMAX(hvcc->general_tier_flag, ptl->tier_flag);
122 
123  /*
124  * The profile indication general_profile_idc must indicate a profile to
125  * which the stream associated with this configuration record conforms.
126  *
127  * If the sequence parameter sets are marked with different profiles, then
128  * the stream may need examination to determine which profile, if any, the
129  * entire stream conforms to. If the entire stream is not examined, or the
130  * examination reveals that there is no profile to which the entire stream
131  * conforms, then the entire stream must be split into two or more
132  * sub-streams with separate configuration records in which these rules can
133  * be met.
134  *
135  * Note: set the profile to the highest value for the sake of simplicity.
136  */
137  hvcc->general_profile_idc = FFMAX(hvcc->general_profile_idc, ptl->profile_idc);
138 
139  /*
140  * Each bit in general_profile_compatibility_flags may only be set if all
141  * the parameter sets set that bit.
142  */
143  hvcc->general_profile_compatibility_flags &= ptl->profile_compatibility_flags;
144 
145  /*
146  * Each bit in general_constraint_indicator_flags may only be set if all
147  * the parameter sets set that bit.
148  */
149  hvcc->general_constraint_indicator_flags &= ptl->constraint_indicator_flags;
150 }
151 
154  int profile_present_flag,
155  unsigned int max_sub_layers_minus1)
156 {
157  unsigned int i;
158  HVCCProfileTierLevel general_ptl;
159  uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS];
160  uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS];
161 
162  if (profile_present_flag) {
163  general_ptl.profile_space = get_bits(gb, 2);
164  general_ptl.tier_flag = get_bits1(gb);
165  general_ptl.profile_idc = get_bits(gb, 5);
166  general_ptl.profile_compatibility_flags = get_bits_long(gb, 32);
167  general_ptl.constraint_indicator_flags = get_bits64(gb, 48);
168  general_ptl.level_idc = get_bits(gb, 8);
169  hvcc_update_ptl(hvcc, &general_ptl);
170  } else
171  skip_bits(gb, 8); // general_level_idc
172 
173  for (i = 0; i < max_sub_layers_minus1; i++) {
174  sub_layer_profile_present_flag[i] = get_bits1(gb);
175  sub_layer_level_present_flag[i] = get_bits1(gb);
176  }
177 
178  if (max_sub_layers_minus1 > 0)
179  for (i = max_sub_layers_minus1; i < 8; i++)
180  skip_bits(gb, 2); // reserved_zero_2bits[i]
181 
182  for (i = 0; i < max_sub_layers_minus1; i++) {
183  if (sub_layer_profile_present_flag[i]) {
184  /*
185  * sub_layer_profile_space[i] u(2)
186  * sub_layer_tier_flag[i] u(1)
187  * sub_layer_profile_idc[i] u(5)
188  * sub_layer_profile_compatibility_flag[i][0..31] u(32)
189  * sub_layer_progressive_source_flag[i] u(1)
190  * sub_layer_interlaced_source_flag[i] u(1)
191  * sub_layer_non_packed_constraint_flag[i] u(1)
192  * sub_layer_frame_only_constraint_flag[i] u(1)
193  * sub_layer_reserved_zero_44bits[i] u(44)
194  */
195  skip_bits_long(gb, 32);
196  skip_bits_long(gb, 32);
197  skip_bits (gb, 24);
198  }
199 
200  if (sub_layer_level_present_flag[i])
201  skip_bits(gb, 8);
202  }
203 }
204 
206  unsigned int cpb_cnt_minus1,
207  uint8_t sub_pic_hrd_params_present_flag)
208 {
209  unsigned int i;
210 
211  for (i = 0; i <= cpb_cnt_minus1; i++) {
212  get_ue_golomb_long(gb); // bit_rate_value_minus1
213  get_ue_golomb_long(gb); // cpb_size_value_minus1
214 
215  if (sub_pic_hrd_params_present_flag) {
216  get_ue_golomb_long(gb); // cpb_size_du_value_minus1
217  get_ue_golomb_long(gb); // bit_rate_du_value_minus1
218  }
219 
220  skip_bits1(gb); // cbr_flag
221  }
222 }
223 
224 static int skip_hrd_parameters(GetBitContext *gb, uint8_t cprms_present_flag,
225  unsigned int max_sub_layers_minus1)
226 {
227  unsigned int i;
228  uint8_t sub_pic_hrd_params_present_flag = 0;
229  uint8_t nal_hrd_parameters_present_flag = 0;
230  uint8_t vcl_hrd_parameters_present_flag = 0;
231 
232  if (cprms_present_flag) {
233  nal_hrd_parameters_present_flag = get_bits1(gb);
234  vcl_hrd_parameters_present_flag = get_bits1(gb);
235 
236  if (nal_hrd_parameters_present_flag ||
237  vcl_hrd_parameters_present_flag) {
238  sub_pic_hrd_params_present_flag = get_bits1(gb);
239 
240  if (sub_pic_hrd_params_present_flag)
241  /*
242  * tick_divisor_minus2 u(8)
243  * du_cpb_removal_delay_increment_length_minus1 u(5)
244  * sub_pic_cpb_params_in_pic_timing_sei_flag u(1)
245  * dpb_output_delay_du_length_minus1 u(5)
246  */
247  skip_bits(gb, 19);
248 
249  /*
250  * bit_rate_scale u(4)
251  * cpb_size_scale u(4)
252  */
253  skip_bits(gb, 8);
254 
255  if (sub_pic_hrd_params_present_flag)
256  skip_bits(gb, 4); // cpb_size_du_scale
257 
258  /*
259  * initial_cpb_removal_delay_length_minus1 u(5)
260  * au_cpb_removal_delay_length_minus1 u(5)
261  * dpb_output_delay_length_minus1 u(5)
262  */
263  skip_bits(gb, 15);
264  }
265  }
266 
267  for (i = 0; i <= max_sub_layers_minus1; i++) {
268  unsigned int cpb_cnt_minus1 = 0;
269  uint8_t low_delay_hrd_flag = 0;
270  uint8_t fixed_pic_rate_within_cvs_flag = 0;
271  uint8_t fixed_pic_rate_general_flag = get_bits1(gb);
272 
273  if (!fixed_pic_rate_general_flag)
274  fixed_pic_rate_within_cvs_flag = get_bits1(gb);
275 
276  if (fixed_pic_rate_within_cvs_flag)
277  get_ue_golomb_long(gb); // elemental_duration_in_tc_minus1
278  else
279  low_delay_hrd_flag = get_bits1(gb);
280 
281  if (!low_delay_hrd_flag) {
282  cpb_cnt_minus1 = get_ue_golomb_long(gb);
283  if (cpb_cnt_minus1 > 31)
284  return AVERROR_INVALIDDATA;
285  }
286 
287  if (nal_hrd_parameters_present_flag)
288  skip_sub_layer_hrd_parameters(gb, cpb_cnt_minus1,
289  sub_pic_hrd_params_present_flag);
290 
291  if (vcl_hrd_parameters_present_flag)
292  skip_sub_layer_hrd_parameters(gb, cpb_cnt_minus1,
293  sub_pic_hrd_params_present_flag);
294  }
295 
296  return 0;
297 }
298 
300 {
301  skip_bits_long(gb, 32); // num_units_in_tick
302  skip_bits_long(gb, 32); // time_scale
303 
304  if (get_bits1(gb)) // poc_proportional_to_timing_flag
305  get_ue_golomb_long(gb); // num_ticks_poc_diff_one_minus1
306 }
307 
310  unsigned int max_sub_layers_minus1)
311 {
312  unsigned int min_spatial_segmentation_idc;
313 
314  if (get_bits1(gb)) // aspect_ratio_info_present_flag
315  if (get_bits(gb, 8) == 255) // aspect_ratio_idc
316  skip_bits_long(gb, 32); // sar_width u(16), sar_height u(16)
317 
318  if (get_bits1(gb)) // overscan_info_present_flag
319  skip_bits1(gb); // overscan_appropriate_flag
320 
321  if (get_bits1(gb)) { // video_signal_type_present_flag
322  skip_bits(gb, 4); // video_format u(3), video_full_range_flag u(1)
323 
324  if (get_bits1(gb)) // colour_description_present_flag
325  /*
326  * colour_primaries u(8)
327  * transfer_characteristics u(8)
328  * matrix_coeffs u(8)
329  */
330  skip_bits(gb, 24);
331  }
332 
333  if (get_bits1(gb)) { // chroma_loc_info_present_flag
334  get_ue_golomb_long(gb); // chroma_sample_loc_type_top_field
335  get_ue_golomb_long(gb); // chroma_sample_loc_type_bottom_field
336  }
337 
338  /*
339  * neutral_chroma_indication_flag u(1)
340  * field_seq_flag u(1)
341  * frame_field_info_present_flag u(1)
342  */
343  skip_bits(gb, 3);
344 
345  if (get_bits1(gb)) { // default_display_window_flag
346  get_ue_golomb_long(gb); // def_disp_win_left_offset
347  get_ue_golomb_long(gb); // def_disp_win_right_offset
348  get_ue_golomb_long(gb); // def_disp_win_top_offset
349  get_ue_golomb_long(gb); // def_disp_win_bottom_offset
350  }
351 
352  if (get_bits1(gb)) { // vui_timing_info_present_flag
353  skip_timing_info(gb);
354 
355  if (get_bits1(gb)) // vui_hrd_parameters_present_flag
356  skip_hrd_parameters(gb, 1, max_sub_layers_minus1);
357  }
358 
359  if (get_bits1(gb)) { // bitstream_restriction_flag
360  /*
361  * tiles_fixed_structure_flag u(1)
362  * motion_vectors_over_pic_boundaries_flag u(1)
363  * restricted_ref_pic_lists_flag u(1)
364  */
365  skip_bits(gb, 3);
366 
367  min_spatial_segmentation_idc = get_ue_golomb_long(gb);
368 
369  /*
370  * unsigned int(12) min_spatial_segmentation_idc;
371  *
372  * The min_spatial_segmentation_idc indication must indicate a level of
373  * spatial segmentation equal to or less than the lowest level of
374  * spatial segmentation indicated in all the parameter sets.
375  */
377  min_spatial_segmentation_idc);
378 
379  get_ue_golomb_long(gb); // max_bytes_per_pic_denom
380  get_ue_golomb_long(gb); // max_bits_per_min_cu_denom
381  get_ue_golomb_long(gb); // log2_max_mv_length_horizontal
382  get_ue_golomb_long(gb); // log2_max_mv_length_vertical
383  }
384 }
385 
387 {
388  get_ue_golomb_long(gb); // max_dec_pic_buffering_minus1
389  get_ue_golomb_long(gb); // max_num_reorder_pics
390  get_ue_golomb_long(gb); // max_latency_increase_plus1
391 }
392 
395  uint8_t vps_max_layers_minus1,
396  uint8_t vps_base_layer_internal_flag)
397 {
398  uint8_t num_scalability_types = 0;
399  uint8_t max_layers_minus_1 = FFMIN(62, vps_max_layers_minus1);
400  uint8_t splitting_flag, vps_nuh_layer_id_present_flag;
401  uint8_t scalability_mask_flag[16] = { 0 };
402  uint8_t dimension_id_len[16] = { 0 };
403  uint8_t layer_id_in_nuh[64] = { 0 };
404  int i, j;
405 
406  if (vps_max_layers_minus1 > 0 && vps_base_layer_internal_flag)
407  hvcc_parse_ptl(gb, hvcc, 0, nal->vps_max_sub_layers_minus1);
408 
409  splitting_flag = get_bits(gb, 1);
410 
411  for (i = 0; i < 16; i++)
412  if (get_bits(gb, 1))
413  scalability_mask_flag[num_scalability_types++] = i;
414 
415  for (j = 0; j < (num_scalability_types - splitting_flag); j++)
416  dimension_id_len[j] = get_bits(gb, 3) + 1;
417 
418  vps_nuh_layer_id_present_flag = get_bits(gb, 1);
419 
420  for (i = 1; i <= max_layers_minus_1; i++) {
421  if (vps_nuh_layer_id_present_flag)
422  layer_id_in_nuh[i] = get_bits(gb, 6);
423  else
424  layer_id_in_nuh[i] = i;
425 
426  if (!splitting_flag) {
427  for (j = 0; j < num_scalability_types; j++) {
428  int dimension_id = get_bits(gb, dimension_id_len[j]);
429 
430  if (dimension_id == 1 /* AUX_ALPHA */ && scalability_mask_flag[j] == 3 /* AuxId */)
431  hvcc->alpha_layer_nuh_id = layer_id_in_nuh[i];
432  }
433  }
434  }
435 
436  if (splitting_flag) {
437  uint8_t dim_bit_offset[17] = { 0 };
438 
439  dim_bit_offset[0] = 0;
440  for (j = 1; j < num_scalability_types; j++)
441  dim_bit_offset[j] = dim_bit_offset[j-1] + dimension_id_len[j-1];
442  dim_bit_offset[num_scalability_types] = 6;
443 
444  if (num_scalability_types > 0 && dim_bit_offset[num_scalability_types - 1] >= 6)
445  return -1; // invalid bitstream
446 
447  for (i = 1; i <= max_layers_minus_1; i++) {
448  for (j = 0; j < num_scalability_types; j++) {
449  int dimension_id = (layer_id_in_nuh[i] & ((1 << dim_bit_offset[j+1]) - 1)) >> dim_bit_offset[j];
450 
451  if (dimension_id == 1 /* AUX_ALPHA */ && scalability_mask_flag[j] == 3 /* AuxId */)
452  hvcc->alpha_layer_nuh_id = layer_id_in_nuh[i];
453  }
454  }
455  }
456 
457  return 0;
458 }
459 
462 {
463  uint8_t vps_base_layer_internal_flag, vps_max_layers_minus1;
464  uint8_t vps_sub_layer_ordering_info_present_flag, vps_max_layer_id;
465  int vps_num_layer_sets_minus1;
466  int i;
467 
468  nal->parameter_set_id = get_bits(gb, 4);
469 
470  vps_base_layer_internal_flag = get_bits(gb, 1);
471  skip_bits(gb, 1); // vps_base_layer_available_flag
472  vps_max_layers_minus1 = get_bits(gb, 6);
473 
474  nal->vps_max_sub_layers_minus1 = get_bits(gb, 3);
475 
476  /*
477  * numTemporalLayers greater than 1 indicates that the stream to which this
478  * configuration record applies is temporally scalable and the contained
479  * number of temporal layers (also referred to as temporal sub-layer or
480  * sub-layer in ISO/IEC 23008-2) is equal to numTemporalLayers. Value 1
481  * indicates that the stream is not temporally scalable. Value 0 indicates
482  * that it is unknown whether the stream is temporally scalable.
483  */
485  nal->vps_max_sub_layers_minus1 + 1);
486 
487  /*
488  * vps_temporal_id_nesting_flag u(1)
489  * vps_reserved_0xffff_16bits u(16)
490  */
491  skip_bits(gb, 17);
492 
493  hvcc_parse_ptl(gb, hvcc, 1, nal->vps_max_sub_layers_minus1);
494 
495  vps_sub_layer_ordering_info_present_flag = get_bits(gb, 1);
496  for (i = (vps_sub_layer_ordering_info_present_flag ? 0 : nal->vps_max_sub_layers_minus1);
497  i <= nal->vps_max_sub_layers_minus1; i++) {
498  get_ue_golomb(gb); // vps_max_dec_pic_buffering_minus1
499  get_ue_golomb(gb); // vps_max_num_reorder_pics
500  get_ue_golomb(gb); // vps_max_latency_increase_plus1
501  }
502 
503  vps_max_layer_id = get_bits(gb, 6);
504  vps_num_layer_sets_minus1 = get_ue_golomb(gb);
505  skip_bits_long(gb, (vps_max_layer_id + 1) * vps_num_layer_sets_minus1); // layer_id_included_flag[i][j]
506 
507  if (get_bits(gb, 1)) { // vps_timing_info_present_flag
508  int vps_num_hrd_parameters;
509 
510  skip_bits_long(gb, 64); // vps_num_units_in_tick, vps_time_scale
511 
512  if (get_bits(gb, 1)) // vps_poc_proportional_to_timing_flag
513  get_ue_golomb(gb); // vps_num_ticks_poc_diff_one_minus1
514 
515  vps_num_hrd_parameters = get_ue_golomb(gb); // vps_num_hrd_parameters
516 
517  for (i = 0; i < vps_num_hrd_parameters; i++) {
518  int cprms_present_flag;
519 
520  get_ue_golomb(gb); // hrd_layer_set_idx[i]
521  if (i > 0)
522  cprms_present_flag = get_bits(gb, 1);
523  else
524  cprms_present_flag = 1;
525 
526  skip_hrd_parameters(gb, cprms_present_flag, nal->vps_max_sub_layers_minus1);
527  }
528  }
529 
530  if (get_bits(gb, 1)) { // vps_extension_flag
531  align_get_bits(gb);
532  if (hvcc_parse_vps_extension(gb, nal, hvcc,
533  vps_max_layers_minus1,
534  vps_base_layer_internal_flag) < 0)
535  return 0;
536  }
537 
538  /* nothing useful for hvcC past this point */
539  return 0;
540 }
541 
543 {
544  int i, j, k, num_coeffs;
545 
546  for (i = 0; i < 4; i++)
547  for (j = 0; j < (i == 3 ? 2 : 6); j++)
548  if (!get_bits1(gb)) // scaling_list_pred_mode_flag[i][j]
549  get_ue_golomb_long(gb); // scaling_list_pred_matrix_id_delta[i][j]
550  else {
551  num_coeffs = FFMIN(64, 1 << (4 + (i << 1)));
552 
553  if (i > 1)
554  get_se_golomb_long(gb); // scaling_list_dc_coef_minus8[i-2][j]
555 
556  for (k = 0; k < num_coeffs; k++)
557  get_se_golomb_long(gb); // scaling_list_delta_coef
558  }
559 }
560 
561 static int parse_rps(GetBitContext *gb, unsigned int rps_idx,
562  unsigned int num_rps,
563  unsigned int num_delta_pocs[HEVC_MAX_SHORT_TERM_REF_PIC_SETS])
564 {
565  unsigned int i;
566 
567  if (rps_idx && get_bits1(gb)) { // inter_ref_pic_set_prediction_flag
568  /* this should only happen for slice headers, and this isn't one */
569  if (rps_idx >= num_rps)
570  return AVERROR_INVALIDDATA;
571 
572  skip_bits1 (gb); // delta_rps_sign
573  get_ue_golomb_long(gb); // abs_delta_rps_minus1
574 
575  num_delta_pocs[rps_idx] = 0;
576 
577  /*
578  * From libavcodec/hevc_ps.c:
579  *
580  * if (is_slice_header) {
581  * //foo
582  * } else
583  * rps_ridx = &sps->st_rps[rps - sps->st_rps - 1];
584  *
585  * where:
586  * rps: &sps->st_rps[rps_idx]
587  * sps->st_rps: &sps->st_rps[0]
588  * is_slice_header: rps_idx == num_rps
589  *
590  * thus:
591  * if (num_rps != rps_idx)
592  * rps_ridx = &sps->st_rps[rps_idx - 1];
593  *
594  * NumDeltaPocs[RefRpsIdx]: num_delta_pocs[rps_idx - 1]
595  */
596  for (i = 0; i <= num_delta_pocs[rps_idx - 1]; i++) {
597  uint8_t use_delta_flag = 0;
598  uint8_t used_by_curr_pic_flag = get_bits1(gb);
599  if (!used_by_curr_pic_flag)
600  use_delta_flag = get_bits1(gb);
601 
602  if (used_by_curr_pic_flag || use_delta_flag)
603  num_delta_pocs[rps_idx]++;
604  }
605  } else {
606  unsigned int num_negative_pics = get_ue_golomb_long(gb);
607  unsigned int num_positive_pics = get_ue_golomb_long(gb);
608 
609  if ((num_positive_pics + (uint64_t)num_negative_pics) * 2 > get_bits_left(gb))
610  return AVERROR_INVALIDDATA;
611 
612  num_delta_pocs[rps_idx] = num_negative_pics + num_positive_pics;
613 
614  for (i = 0; i < num_negative_pics; i++) {
615  get_ue_golomb_long(gb); // delta_poc_s0_minus1[rps_idx]
616  skip_bits1 (gb); // used_by_curr_pic_s0_flag[rps_idx]
617  }
618 
619  for (i = 0; i < num_positive_pics; i++) {
620  get_ue_golomb_long(gb); // delta_poc_s1_minus1[rps_idx]
621  skip_bits1 (gb); // used_by_curr_pic_s1_flag[rps_idx]
622  }
623  }
624 
625  return 0;
626 }
627 
630 {
631  unsigned int i, sps_max_sub_layers_minus1, log2_max_pic_order_cnt_lsb_minus4;
632  unsigned int num_short_term_ref_pic_sets, num_delta_pocs[HEVC_MAX_SHORT_TERM_REF_PIC_SETS];
633  unsigned int sps_ext_or_max_sub_layers_minus1, multi_layer_ext_sps_flag;
634 
635  unsigned int sps_video_parameter_set_id = get_bits(gb, 4);
636 
637  if (nal->nuh_layer_id == 0) {
638  sps_ext_or_max_sub_layers_minus1 = 0;
639  sps_max_sub_layers_minus1 = get_bits(gb, 3);
640  } else {
641  sps_ext_or_max_sub_layers_minus1 = get_bits(gb, 3);
642  if (sps_ext_or_max_sub_layers_minus1 == 7) {
643  const HVCCNALUnitArray *array = &hvcc->arrays[VPS_INDEX];
644  const HVCCNALUnit *vps = NULL;
645 
646  for (i = 0; i < array->numNalus; i++)
647  if (sps_video_parameter_set_id == array->nal[i].parameter_set_id) {
648  vps = &array->nal[i];
649  break;
650  }
651  if (!vps)
652  return AVERROR_INVALIDDATA;
653 
654  sps_max_sub_layers_minus1 = vps->vps_max_sub_layers_minus1;
655  } else
656  sps_max_sub_layers_minus1 = sps_ext_or_max_sub_layers_minus1;
657  }
658  multi_layer_ext_sps_flag = nal->nuh_layer_id &&
659  sps_ext_or_max_sub_layers_minus1 == 7;
660 
661  /*
662  * numTemporalLayers greater than 1 indicates that the stream to which this
663  * configuration record applies is temporally scalable and the contained
664  * number of temporal layers (also referred to as temporal sub-layer or
665  * sub-layer in ISO/IEC 23008-2) is equal to numTemporalLayers. Value 1
666  * indicates that the stream is not temporally scalable. Value 0 indicates
667  * that it is unknown whether the stream is temporally scalable.
668  */
670  sps_max_sub_layers_minus1 + 1);
671 
672  if (!multi_layer_ext_sps_flag) {
673  hvcc->temporalIdNested = get_bits1(gb);
674  hvcc_parse_ptl(gb, hvcc, 1, sps_max_sub_layers_minus1);
675  }
676 
678 
679  if (multi_layer_ext_sps_flag) {
680  if (get_bits1(gb)) // update_rep_format_flag
681  skip_bits(gb, 8); // sps_rep_format_idx
682  } else {
683  hvcc->chromaFormat = get_ue_golomb_long(gb);
684 
685  if (hvcc->chromaFormat == 3)
686  skip_bits1(gb); // separate_colour_plane_flag
687 
688  get_ue_golomb_long(gb); // pic_width_in_luma_samples
689  get_ue_golomb_long(gb); // pic_height_in_luma_samples
690 
691  if (get_bits1(gb)) { // conformance_window_flag
692  get_ue_golomb_long(gb); // conf_win_left_offset
693  get_ue_golomb_long(gb); // conf_win_right_offset
694  get_ue_golomb_long(gb); // conf_win_top_offset
695  get_ue_golomb_long(gb); // conf_win_bottom_offset
696  }
697 
700  }
701  log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb_long(gb);
702 
703  if (!multi_layer_ext_sps_flag) {
704  /* sps_sub_layer_ordering_info_present_flag */
705  i = get_bits1(gb) ? 0 : sps_max_sub_layers_minus1;
706  for (; i <= sps_max_sub_layers_minus1; i++)
708  }
709 
710  get_ue_golomb_long(gb); // log2_min_luma_coding_block_size_minus3
711  get_ue_golomb_long(gb); // log2_diff_max_min_luma_coding_block_size
712  get_ue_golomb_long(gb); // log2_min_transform_block_size_minus2
713  get_ue_golomb_long(gb); // log2_diff_max_min_transform_block_size
714  get_ue_golomb_long(gb); // max_transform_hierarchy_depth_inter
715  get_ue_golomb_long(gb); // max_transform_hierarchy_depth_intra
716 
717  if (get_bits1(gb)) { // scaling_list_enabled_flag
718  int sps_infer_scaling_list_flag = 0;
719  if (multi_layer_ext_sps_flag)
720  sps_infer_scaling_list_flag = get_bits1(gb);
721  if (sps_infer_scaling_list_flag)
722  skip_bits(gb, 6); // sps_scaling_list_ref_layer_id
723  else if (get_bits1(gb)) // sps_scaling_list_data_present_flag
725  }
726 
727  skip_bits1(gb); // amp_enabled_flag
728  skip_bits1(gb); // sample_adaptive_offset_enabled_flag
729 
730  if (get_bits1(gb)) { // pcm_enabled_flag
731  skip_bits (gb, 4); // pcm_sample_bit_depth_luma_minus1
732  skip_bits (gb, 4); // pcm_sample_bit_depth_chroma_minus1
733  get_ue_golomb_long(gb); // log2_min_pcm_luma_coding_block_size_minus3
734  get_ue_golomb_long(gb); // log2_diff_max_min_pcm_luma_coding_block_size
735  skip_bits1 (gb); // pcm_loop_filter_disabled_flag
736  }
737 
738  num_short_term_ref_pic_sets = get_ue_golomb_long(gb);
739  if (num_short_term_ref_pic_sets > HEVC_MAX_SHORT_TERM_REF_PIC_SETS)
740  return AVERROR_INVALIDDATA;
741 
742  for (i = 0; i < num_short_term_ref_pic_sets; i++) {
743  int ret = parse_rps(gb, i, num_short_term_ref_pic_sets, num_delta_pocs);
744  if (ret < 0)
745  return ret;
746  }
747 
748  if (get_bits1(gb)) { // long_term_ref_pics_present_flag
749  unsigned num_long_term_ref_pics_sps = get_ue_golomb_long(gb);
750  if (num_long_term_ref_pics_sps > 31U)
751  return AVERROR_INVALIDDATA;
752  for (i = 0; i < num_long_term_ref_pics_sps; i++) { // num_long_term_ref_pics_sps
753  int len = FFMIN(log2_max_pic_order_cnt_lsb_minus4 + 4, 16);
754  skip_bits (gb, len); // lt_ref_pic_poc_lsb_sps[i]
755  skip_bits1(gb); // used_by_curr_pic_lt_sps_flag[i]
756  }
757  }
758 
759  skip_bits1(gb); // sps_temporal_mvp_enabled_flag
760  skip_bits1(gb); // strong_intra_smoothing_enabled_flag
761 
762  if (get_bits1(gb)) // vui_parameters_present_flag
763  hvcc_parse_vui(gb, hvcc, sps_max_sub_layers_minus1);
764 
765  /* nothing useful for hvcC past this point */
766  return 0;
767 }
768 
771 {
772  uint8_t tiles_enabled_flag, entropy_coding_sync_enabled_flag;
773 
774  nal->parameter_set_id = get_ue_golomb_long(gb); // pps_pic_parameter_set_id
775  get_ue_golomb_long(gb); // pps_seq_parameter_set_id
776 
777  /*
778  * dependent_slice_segments_enabled_flag u(1)
779  * output_flag_present_flag u(1)
780  * num_extra_slice_header_bits u(3)
781  * sign_data_hiding_enabled_flag u(1)
782  * cabac_init_present_flag u(1)
783  */
784  skip_bits(gb, 7);
785 
786  get_ue_golomb_long(gb); // num_ref_idx_l0_default_active_minus1
787  get_ue_golomb_long(gb); // num_ref_idx_l1_default_active_minus1
788  get_se_golomb_long(gb); // init_qp_minus26
789 
790  /*
791  * constrained_intra_pred_flag u(1)
792  * transform_skip_enabled_flag u(1)
793  */
794  skip_bits(gb, 2);
795 
796  if (get_bits1(gb)) // cu_qp_delta_enabled_flag
797  get_ue_golomb_long(gb); // diff_cu_qp_delta_depth
798 
799  get_se_golomb_long(gb); // pps_cb_qp_offset
800  get_se_golomb_long(gb); // pps_cr_qp_offset
801 
802  /*
803  * pps_slice_chroma_qp_offsets_present_flag u(1)
804  * weighted_pred_flag u(1)
805  * weighted_bipred_flag u(1)
806  * transquant_bypass_enabled_flag u(1)
807  */
808  skip_bits(gb, 4);
809 
810  tiles_enabled_flag = get_bits1(gb);
811  entropy_coding_sync_enabled_flag = get_bits1(gb);
812 
813  if (entropy_coding_sync_enabled_flag && tiles_enabled_flag)
814  hvcc->parallelismType = 0; // mixed-type parallel decoding
815  else if (entropy_coding_sync_enabled_flag)
816  hvcc->parallelismType = 3; // wavefront-based parallel decoding
817  else if (tiles_enabled_flag)
818  hvcc->parallelismType = 2; // tile-based parallel decoding
819  else
820  hvcc->parallelismType = 1; // slice-based parallel decoding
821 
822  /* nothing useful for hvcC past this point */
823  return 0;
824 }
825 
826 static void nal_unit_parse_header(GetBitContext *gb, uint8_t *nal_type,
827  uint8_t *nuh_layer_id)
828 {
829  skip_bits1(gb); // forbidden_zero_bit
830 
831  *nal_type = get_bits(gb, 6);
832  *nuh_layer_id = get_bits(gb, 6);
833 
834  /*
835  * nuh_temporal_id_plus1 u(3)
836  */
837  skip_bits(gb, 3);
838 }
839 
840 static int hvcc_array_add_nal_unit(const uint8_t *nal_buf, uint32_t nal_size,
842 {
843  HVCCNALUnit *nal;
844  int ret;
845  uint16_t numNalus = array->numNalus;
846 
847  ret = av_reallocp_array(&array->nal, numNalus + 1, sizeof(*array->nal));
848  if (ret < 0)
849  return ret;
850 
851  nal = &array->nal[numNalus];
852  nal->nalUnit = nal_buf;
853  nal->nalUnitLength = nal_size;
854  array->numNalus++;
855 
856  return 0;
857 }
858 
859 static int hvcc_add_nal_unit(const uint8_t *nal_buf, uint32_t nal_size,
861  int flags, unsigned array_idx)
862 {
863  int ret = 0;
864  int is_nalff = !!(flags & FLAG_IS_NALFF);
865  int is_lhvc = !!(flags & FLAG_IS_LHVC);
866  int ps_array_completeness = !!(flags & FLAG_ARRAY_COMPLETENESS);
867  HVCCNALUnitArray *const array = &hvcc->arrays[array_idx];
868  HVCCNALUnit *nal;
869  GetBitContext gbc;
870  uint8_t nal_type, nuh_layer_id;
871  uint8_t *rbsp_buf;
872  uint32_t rbsp_size;
873 
874  rbsp_buf = ff_nal_unit_extract_rbsp(nal_buf, nal_size, &rbsp_size, 2);
875  if (!rbsp_buf) {
876  ret = AVERROR(ENOMEM);
877  goto end;
878  }
879 
880  ret = init_get_bits8(&gbc, rbsp_buf, rbsp_size);
881  if (ret < 0)
882  goto end;
883 
884  nal_unit_parse_header(&gbc, &nal_type, &nuh_layer_id);
885  if (!is_lhvc && nuh_layer_id > 0 && nuh_layer_id != hvcc->alpha_layer_nuh_id)
886  goto end;
887 
888  /*
889  * Note: only 'declarative' SEI messages are allowed in
890  * hvcC. Perhaps the SEI playload type should be checked
891  * and non-declarative SEI messages discarded?
892  */
893  ret = hvcc_array_add_nal_unit(nal_buf, nal_size, array);
894  if (ret < 0)
895  goto end;
896  if (array->numNalus == 1) {
897  hvcc->numOfArrays++;
898  array->NAL_unit_type = nal_type;
899 
900  /*
901  * When the sample entry name is ‘hvc1’, the default and mandatory value of
902  * array_completeness is 1 for arrays of all types of parameter sets, and 0
903  * for all other arrays. When the sample entry name is ‘hev1’, the default
904  * value of array_completeness is 0 for all arrays.
905  */
906  if (nal_type == HEVC_NAL_VPS || nal_type == HEVC_NAL_SPS ||
907  nal_type == HEVC_NAL_PPS)
908  array->array_completeness = ps_array_completeness;
909  }
910 
911  nal = &array->nal[array->numNalus-1];
912  nal->nuh_layer_id = nuh_layer_id;
913 
914  /* Don't parse parameter sets. We already have the needed information*/
915  if (is_nalff)
916  goto end;
917 
918  if (nal_type == HEVC_NAL_VPS)
919  ret = hvcc_parse_vps(&gbc, nal, hvcc);
920  else if (nal_type == HEVC_NAL_SPS)
921  ret = hvcc_parse_sps(&gbc, nal, hvcc);
922  else if (nal_type == HEVC_NAL_PPS)
923  ret = hvcc_parse_pps(&gbc, nal, hvcc);
924  if (ret < 0)
925  goto end;
926 
927 end:
928  av_free(rbsp_buf);
929  return ret;
930 }
931 
933 {
934  memset(hvcc, 0, sizeof(HEVCDecoderConfigurationRecord));
935  hvcc->configurationVersion = 1;
936  hvcc->lengthSizeMinusOne = 3; // 4 bytes
937 
938  /*
939  * The following fields have all their valid bits set by default,
940  * the ProfileTierLevel parsing code will unset them when needed.
941  */
942  hvcc->general_profile_compatibility_flags = 0xffffffff;
943  hvcc->general_constraint_indicator_flags = 0xffffffffffff;
944 
945  /*
946  * Initialize this field with an invalid value which can be used to detect
947  * whether we didn't see any VUI (in which case it should be reset to zero).
948  */
950 }
951 
953 {
954  for (unsigned i = 0; i < FF_ARRAY_ELEMS(hvcc->arrays); i++) {
955  HVCCNALUnitArray *const array = &hvcc->arrays[i];
956  array->numNalus = 0;
957  av_freep(&array->nal);
958  }
959 }
960 
961 static int hvcc_write(void *logctx, AVIOContext *pb,
963 {
964  uint16_t numNalus[NB_ARRAYS] = { 0 };
965  int is_lhvc = !!(flags & FLAG_IS_LHVC);
966  int numOfArrays = 0;
967 
968  /*
969  * We only support writing HEVCDecoderConfigurationRecord version 1.
970  */
971  hvcc->configurationVersion = 1;
972 
973  /*
974  * If min_spatial_segmentation_idc is invalid, reset to 0 (unspecified).
975  */
978 
979  /*
980  * parallelismType indicates the type of parallelism that is used to meet
981  * the restrictions imposed by min_spatial_segmentation_idc when the value
982  * of min_spatial_segmentation_idc is greater than 0.
983  */
984  if (!hvcc->min_spatial_segmentation_idc)
985  hvcc->parallelismType = 0;
986 
987  /*
988  * It's unclear how to properly compute these fields, so
989  * let's always set them to values meaning 'unspecified'.
990  */
991  hvcc->avgFrameRate = 0;
992  /*
993  * lhvC doesn't store this field. It instead reserves the bits, setting them
994  * to '11'b.
995  */
996  hvcc->constantFrameRate = is_lhvc * 0x3;
997 
998  /*
999  * Skip all NALUs with nuh_layer_id == 0 if writing lhvC. We do it here and
1000  * not before parsing them as some parameter sets with nuh_layer_id > 0
1001  * may reference base layer parameters sets.
1002  */
1003  for (unsigned i = 0; i < FF_ARRAY_ELEMS(hvcc->arrays); i++) {
1004  const HVCCNALUnitArray *const array = &hvcc->arrays[i];
1005 
1006  if (array->numNalus == 0)
1007  continue;
1008 
1009  for (unsigned j = 0; j < array->numNalus; j++)
1010  numNalus[i] += !is_lhvc || (array->nal[j].nuh_layer_id != 0);
1011  numOfArrays += (numNalus[i] > 0);
1012  }
1013 
1014  av_log(logctx, AV_LOG_TRACE, "%s\n", is_lhvc ? "lhvC" : "hvcC");
1015  av_log(logctx, AV_LOG_TRACE, "configurationVersion: %"PRIu8"\n",
1016  hvcc->configurationVersion);
1017  if (!is_lhvc) {
1018  av_log(logctx, AV_LOG_TRACE, "general_profile_space: %"PRIu8"\n",
1019  hvcc->general_profile_space);
1020  av_log(logctx, AV_LOG_TRACE, "general_tier_flag: %"PRIu8"\n",
1021  hvcc->general_tier_flag);
1022  av_log(logctx, AV_LOG_TRACE, "general_profile_idc: %"PRIu8"\n",
1023  hvcc->general_profile_idc);
1024  av_log(logctx, AV_LOG_TRACE, "general_profile_compatibility_flags: 0x%08"PRIx32"\n",
1026  av_log(logctx, AV_LOG_TRACE, "general_constraint_indicator_flags: 0x%012"PRIx64"\n",
1028  av_log(logctx, AV_LOG_TRACE, "general_level_idc: %"PRIu8"\n",
1029  hvcc->general_level_idc);
1030  }
1031  av_log(logctx, AV_LOG_TRACE, "min_spatial_segmentation_idc: %"PRIu16"\n",
1033  av_log(logctx, AV_LOG_TRACE, "parallelismType: %"PRIu8"\n",
1034  hvcc->parallelismType);
1035  if (!is_lhvc) {
1036  av_log(logctx, AV_LOG_TRACE, "chromaFormat: %"PRIu8"\n",
1037  hvcc->chromaFormat);
1038  av_log(logctx, AV_LOG_TRACE, "bitDepthLumaMinus8: %"PRIu8"\n",
1039  hvcc->bitDepthLumaMinus8);
1040  av_log(logctx, AV_LOG_TRACE, "bitDepthChromaMinus8: %"PRIu8"\n",
1041  hvcc->bitDepthChromaMinus8);
1042  av_log(logctx, AV_LOG_TRACE, "avgFrameRate: %"PRIu16"\n",
1043  hvcc->avgFrameRate);
1044  av_log(logctx, AV_LOG_TRACE, "constantFrameRate: %"PRIu8"\n",
1045  hvcc->constantFrameRate);
1046  }
1047  av_log(logctx, AV_LOG_TRACE, "numTemporalLayers: %"PRIu8"\n",
1048  hvcc->numTemporalLayers);
1049  av_log(logctx, AV_LOG_TRACE, "temporalIdNested: %"PRIu8"\n",
1050  hvcc->temporalIdNested);
1051  av_log(logctx, AV_LOG_TRACE, "lengthSizeMinusOne: %"PRIu8"\n",
1052  hvcc->lengthSizeMinusOne);
1053  av_log(logctx, AV_LOG_TRACE, "numOfArrays: %"PRIu8"\n",
1054  numOfArrays);
1055  for (unsigned i = 0, j = 0; i < FF_ARRAY_ELEMS(hvcc->arrays); i++) {
1056  const HVCCNALUnitArray *const array = &hvcc->arrays[i];
1057 
1058  if (numNalus[i] == 0)
1059  continue;
1060 
1061  av_log(logctx, AV_LOG_TRACE, "array_completeness[%u]: %"PRIu8"\n",
1062  j, array->array_completeness);
1063  av_log(logctx, AV_LOG_TRACE, "NAL_unit_type[%u]: %"PRIu8"\n",
1064  j, array->NAL_unit_type);
1065  av_log(logctx, AV_LOG_TRACE, "numNalus[%u]: %"PRIu16"\n",
1066  j, numNalus[i]);
1067  for (unsigned k = 0; k < array->numNalus; k++) {
1068  if (is_lhvc && array->nal[k].nuh_layer_id == 0)
1069  continue;
1070 
1071  av_log(logctx, AV_LOG_TRACE,
1072  "nuh_layer_id[%u][%u]: %"PRIu8"\n",
1073  j, k, array->nal[k].nuh_layer_id);
1074  av_log(logctx, AV_LOG_TRACE,
1075  "nalUnitLength[%u][%u]: %"PRIu16"\n",
1076  j, k, array->nal[k].nalUnitLength);
1077  }
1078  j++;
1079  }
1080 
1081  /*
1082  * We need at least one of each: VPS, SPS and PPS.
1083  */
1084  if ((flags & FLAG_ARRAY_COMPLETENESS) &&
1085  (!numNalus[VPS_INDEX] || numNalus[VPS_INDEX] > HEVC_MAX_VPS_COUNT) && !is_lhvc)
1086  return AVERROR_INVALIDDATA;
1087  if ((flags & FLAG_ARRAY_COMPLETENESS) &&
1088  (!numNalus[SPS_INDEX] || numNalus[SPS_INDEX] > HEVC_MAX_SPS_COUNT ||
1089  !numNalus[PPS_INDEX] || numNalus[PPS_INDEX] > HEVC_MAX_PPS_COUNT))
1090  return AVERROR_INVALIDDATA;
1091 
1092  /* unsigned int(8) configurationVersion = 1; */
1093  avio_w8(pb, hvcc->configurationVersion);
1094 
1095  if (!is_lhvc) {
1096  /*
1097  * unsigned int(2) general_profile_space;
1098  * unsigned int(1) general_tier_flag;
1099  * unsigned int(5) general_profile_idc;
1100  */
1101  avio_w8(pb, hvcc->general_profile_space << 6 |
1102  hvcc->general_tier_flag << 5 |
1103  hvcc->general_profile_idc);
1104 
1105  /* unsigned int(32) general_profile_compatibility_flags; */
1107 
1108  /* unsigned int(48) general_constraint_indicator_flags; */
1111 
1112  /* unsigned int(8) general_level_idc; */
1113  avio_w8(pb, hvcc->general_level_idc);
1114  }
1115 
1116  /*
1117  * bit(4) reserved = '1111'b;
1118  * unsigned int(12) min_spatial_segmentation_idc;
1119  */
1120  avio_wb16(pb, hvcc->min_spatial_segmentation_idc | 0xf000);
1121 
1122  /*
1123  * bit(6) reserved = '111111'b;
1124  * unsigned int(2) parallelismType;
1125  */
1126  avio_w8(pb, hvcc->parallelismType | 0xfc);
1127 
1128  if (!is_lhvc) {
1129  /*
1130  * bit(6) reserved = '111111'b;
1131  * unsigned int(2) chromaFormat;
1132  */
1133  avio_w8(pb, hvcc->chromaFormat | 0xfc);
1134 
1135  /*
1136  * bit(5) reserved = '11111'b;
1137  * unsigned int(3) bitDepthLumaMinus8;
1138  */
1139  avio_w8(pb, hvcc->bitDepthLumaMinus8 | 0xf8);
1140 
1141  /*
1142  * bit(5) reserved = '11111'b;
1143  * unsigned int(3) bitDepthChromaMinus8;
1144  */
1145  avio_w8(pb, hvcc->bitDepthChromaMinus8 | 0xf8);
1146 
1147  /* bit(16) avgFrameRate; */
1148  avio_wb16(pb, hvcc->avgFrameRate);
1149  }
1150 
1151  /*
1152  * if (!is_lhvc)
1153  * bit(2) constantFrameRate;
1154  * else
1155  * bit(2) reserved = '11'b;
1156  * bit(3) numTemporalLayers;
1157  * bit(1) temporalIdNested;
1158  * unsigned int(2) lengthSizeMinusOne;
1159  */
1160  avio_w8(pb, hvcc->constantFrameRate << 6 |
1161  hvcc->numTemporalLayers << 3 |
1162  hvcc->temporalIdNested << 2 |
1163  hvcc->lengthSizeMinusOne);
1164 
1165  /* unsigned int(8) numOfArrays; */
1166  avio_w8(pb, numOfArrays);
1167 
1168  for (unsigned i = 0; i < FF_ARRAY_ELEMS(hvcc->arrays); i++) {
1169  const HVCCNALUnitArray *const array = &hvcc->arrays[i];
1170 
1171  if (!numNalus[i])
1172  continue;
1173  /*
1174  * bit(1) array_completeness;
1175  * unsigned int(1) reserved = 0;
1176  * unsigned int(6) NAL_unit_type;
1177  */
1178  avio_w8(pb, array->array_completeness << 7 |
1179  array->NAL_unit_type & 0x3f);
1180 
1181  /* unsigned int(16) numNalus; */
1182  avio_wb16(pb, numNalus[i]);
1183 
1184  for (unsigned j = 0; j < array->numNalus; j++) {
1185  HVCCNALUnit *nal = &array->nal[j];
1186 
1187  if (is_lhvc && nal->nuh_layer_id == 0)
1188  continue;
1189 
1190  /* unsigned int(16) nalUnitLength; */
1191  avio_wb16(pb, nal->nalUnitLength);
1192 
1193  /* bit(8*nalUnitLength) nalUnit; */
1194  avio_write(pb, nal->nalUnit, nal->nalUnitLength);
1195  }
1196  }
1197 
1198  return 0;
1199 }
1200 
1201 int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in,
1202  int size, int filter_ps, int *ps_count)
1203 {
1204  int num_ps = 0, ret = 0;
1205  uint8_t *buf, *end, *start = NULL;
1206 
1207  if (!filter_ps) {
1208  ret = ff_nal_parse_units(pb, buf_in, size);
1209  goto end;
1210  }
1211 
1212  ret = ff_nal_parse_units_buf(buf_in, &start, &size);
1213  if (ret < 0)
1214  goto end;
1215 
1216  ret = 0;
1217  buf = start;
1218  end = start + size;
1219 
1220  while (end - buf > 4) {
1221  uint32_t len = FFMIN(AV_RB32(buf), end - buf - 4);
1222  uint8_t type = (buf[4] >> 1) & 0x3f;
1223 
1224  buf += 4;
1225 
1226  switch (type) {
1227  case HEVC_NAL_VPS:
1228  case HEVC_NAL_SPS:
1229  case HEVC_NAL_PPS:
1230  num_ps++;
1231  break;
1232  default:
1233  ret += 4 + len;
1234  avio_wb32(pb, len);
1235  avio_write(pb, buf, len);
1236  break;
1237  }
1238 
1239  buf += len;
1240  }
1241 
1242 end:
1243  av_free(start);
1244  if (ps_count)
1245  *ps_count = num_ps;
1246  return ret;
1247 }
1248 
1249 int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out,
1250  int *size, int filter_ps, int *ps_count)
1251 {
1252  AVIOContext *pb;
1253  int ret;
1254 
1255  ret = avio_open_dyn_buf(&pb);
1256  if (ret < 0)
1257  return ret;
1258 
1259  ret = ff_hevc_annexb2mp4(pb, buf_in, *size, filter_ps, ps_count);
1260  if (ret < 0) {
1261  ffio_free_dyn_buf(&pb);
1262  return ret;
1263  }
1264 
1265  *size = avio_close_dyn_buf(pb, buf_out);
1266 
1267  return 0;
1268 }
1269 
1270 static int hvcc_parse_nal_unit(const uint8_t *buf, uint32_t len, int type,
1272  int flags)
1273 {
1274  for (unsigned i = 0; i < FF_ARRAY_ELEMS(hvcc->arrays); i++) {
1275  static const uint8_t array_idx_to_type[] =
1278 
1279  if (type == array_idx_to_type[i]) {
1280  int ret = hvcc_add_nal_unit(buf, len, hvcc, flags, i);
1281  if (ret < 0)
1282  return ret;
1283  break;
1284  }
1285  }
1286 
1287  return 0;
1288 }
1289 
1290 static int write_configuration_record(void *logctx, AVIOContext *pb, const uint8_t *data,
1291  int size, int flags)
1292 {
1294  uint8_t *buf, *end, *start = NULL;
1295  int ret;
1296 
1297  if (size < 6) {
1298  /* We can't write a valid hvcC from the provided data */
1299  return AVERROR_INVALIDDATA;
1300  } else if (*data == 1) {
1301  /* Data is already hvcC-formatted. Parse the arrays to skip any NALU
1302  with nuh_layer_id > 0 */
1303  GetBitContext gbc;
1304  int num_arrays;
1305 
1306  if (size < 23)
1307  return AVERROR_INVALIDDATA;
1308 
1309  ret = init_get_bits8(&gbc, data, size);
1310  if (ret < 0)
1311  return ret;
1312 
1313  hvcc_init(&hvcc);
1314  skip_bits(&gbc, 8); // hvcc.configurationVersion
1315  hvcc.general_profile_space = get_bits(&gbc, 2);
1316  hvcc.general_tier_flag = get_bits1(&gbc);
1317  hvcc.general_profile_idc = get_bits(&gbc, 5);
1320  hvcc.general_level_idc = get_bits(&gbc, 8);
1321  skip_bits(&gbc, 4); // reserved
1322  hvcc.min_spatial_segmentation_idc = get_bits(&gbc, 12);
1323  skip_bits(&gbc, 6); // reserved
1324  hvcc.parallelismType = get_bits(&gbc, 2);
1325  skip_bits(&gbc, 6); // reserved
1326  hvcc.chromaFormat = get_bits(&gbc, 2);
1327  skip_bits(&gbc, 5); // reserved
1328  hvcc.bitDepthLumaMinus8 = get_bits(&gbc, 3);
1329  skip_bits(&gbc, 5); // reserved
1330  hvcc.bitDepthChromaMinus8 = get_bits(&gbc, 3);
1331  hvcc.avgFrameRate = get_bits(&gbc, 16);
1332  hvcc.constantFrameRate = get_bits(&gbc, 2);
1333  hvcc.numTemporalLayers = get_bits(&gbc, 3);
1334  hvcc.temporalIdNested = get_bits1(&gbc);
1335  hvcc.lengthSizeMinusOne = get_bits(&gbc, 2);
1336 
1337  flags |= FLAG_IS_NALFF;
1338 
1339  num_arrays = get_bits(&gbc, 8);
1340  for (int i = 0; i < num_arrays; i++) {
1341  int type, num_nalus;
1342 
1343  skip_bits(&gbc, 2);
1344  type = get_bits(&gbc, 6);
1345  num_nalus = get_bits(&gbc, 16);
1346  for (int j = 0; j < num_nalus; j++) {
1347  int len = get_bits(&gbc, 16);
1348 
1349  if (len > (get_bits_left(&gbc) / 8))
1350  goto end;
1351 
1353  len, type, &hvcc, flags);
1354  if (ret < 0)
1355  goto end;
1356 
1357  skip_bits_long(&gbc, len * 8);
1358  }
1359  }
1360 
1361  ret = hvcc_write(logctx, pb, &hvcc, flags);
1362  goto end;
1363  } else if (!(AV_RB24(data) == 1 || AV_RB32(data) == 1)) {
1364  /* Not a valid Annex B start code prefix */
1365  return AVERROR_INVALIDDATA;
1366  }
1367 
1368  ret = ff_nal_parse_units_buf(data, &start, &size);
1369  if (ret < 0)
1370  return ret;
1371 
1372  hvcc_init(&hvcc);
1373 
1374  buf = start;
1375  end = start + size;
1376 
1377  while (end - buf > 4) {
1378  uint32_t len = FFMIN(AV_RB32(buf), end - buf - 4);
1379  uint8_t type = (buf[4] >> 1) & 0x3f;
1380 
1381  buf += 4;
1382 
1383  ret = hvcc_parse_nal_unit(buf, len, type, &hvcc, flags);
1384  if (ret < 0)
1385  goto end;
1386 
1387  buf += len;
1388  }
1389 
1390  ret = hvcc_write(logctx, pb, &hvcc, flags);
1391 
1392 end:
1393  hvcc_close(&hvcc);
1394  av_free(start);
1395  return ret;
1396 }
1397 
1398 int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data,
1399  int size, int ps_array_completeness, void *logctx)
1400 {
1401  return write_configuration_record(logctx, pb, data, size,
1402  !!ps_array_completeness * FLAG_ARRAY_COMPLETENESS);
1403 }
1404 
1405 int ff_isom_write_lhvc(AVIOContext *pb, const uint8_t *data,
1406  int size, int ps_array_completeness, void *logctx)
1407 {
1408  return write_configuration_record(logctx, pb, data, size,
1409  (!!ps_array_completeness * FLAG_ARRAY_COMPLETENESS) | FLAG_IS_LHVC);
1410 }
flags
const SwsFlags flags[]
Definition: swscale.c:61
HEVCDecoderConfigurationRecord::avgFrameRate
uint16_t avgFrameRate
Definition: hevc.c:78
hvcc_parse_vps
static int hvcc_parse_vps(GetBitContext *gb, HVCCNALUnit *nal, HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:460
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:276
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:689
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
HEVCDecoderConfigurationRecord::alpha_layer_nuh_id
uint8_t alpha_layer_nuh_id
Definition: hevc.c:86
NB_ARRAYS
@ NB_ARRAYS
Definition: hevc.c:40
get_se_golomb_long
static int get_se_golomb_long(GetBitContext *gb)
Definition: golomb.h:294
hvcc_parse_nal_unit
static int hvcc_parse_nal_unit(const uint8_t *buf, uint32_t len, int type, HEVCDecoderConfigurationRecord *hvcc, int flags)
Definition: hevc.c:1270
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:419
HEVC_MAX_PPS_COUNT
@ HEVC_MAX_PPS_COUNT
Definition: hevc.h:117
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:250
HEVCDecoderConfigurationRecord::temporalIdNested
uint8_t temporalIdNested
Definition: hevc.c:81
get_ue_golomb
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
Definition: golomb.h:53
hvcc_close
static void hvcc_close(HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:952
data
const char data[16]
Definition: mxf.c:149
HEVCDecoderConfigurationRecord::general_profile_idc
uint8_t general_profile_idc
Definition: hevc.c:69
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
VPS_INDEX
@ VPS_INDEX
Definition: hevc.c:35
HVCCProfileTierLevel::level_idc
uint8_t level_idc
Definition: hevc.c:95
hvcc_init
static void hvcc_init(HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:932
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:379
golomb.h
exp golomb vlc stuff
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:333
HVCCNALUnit::nuh_layer_id
uint8_t nuh_layer_id
Definition: hevc.c:49
GetBitContext
Definition: get_bits.h:109
skip_scaling_list_data
static void skip_scaling_list_data(GetBitContext *gb)
Definition: hevc.c:542
HEVC_NAL_SEI_SUFFIX
@ HEVC_NAL_SEI_SUFFIX
Definition: hevc.h:69
HEVCDecoderConfigurationRecord::numTemporalLayers
uint8_t numTemporalLayers
Definition: hevc.c:80
HEVC_MAX_SHORT_TERM_REF_PIC_SETS
@ HEVC_MAX_SHORT_TERM_REF_PIC_SETS
Definition: hevc.h:125
HVCCProfileTierLevel::profile_idc
uint8_t profile_idc
Definition: hevc.c:92
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
HVCCNALUnit::parameter_set_id
uint8_t parameter_set_id
Definition: hevc.c:50
parse_rps
static int parse_rps(GetBitContext *gb, unsigned int rps_idx, unsigned int num_rps, unsigned int num_delta_pocs[HEVC_MAX_SHORT_TERM_REF_PIC_SETS])
Definition: hevc.c:561
HEVC_NAL_SEI_PREFIX
@ HEVC_NAL_SEI_PREFIX
Definition: hevc.h:68
avio_close_dyn_buf
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1407
hvcc_add_nal_unit
static int hvcc_add_nal_unit(const uint8_t *nal_buf, uint32_t nal_size, HEVCDecoderConfigurationRecord *hvcc, int flags, unsigned array_idx)
Definition: hevc.c:859
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:236
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:539
SEI_SUFFIX_INDEX
@ SEI_SUFFIX_INDEX
Definition: hevc.c:39
HEVCDecoderConfigurationRecord::chromaFormat
uint8_t chromaFormat
Definition: hevc.c:75
FLAG_ARRAY_COMPLETENESS
#define FLAG_ARRAY_COMPLETENESS
Definition: hevc.c:44
ptl
const H265RawProfileTierLevel * ptl
Definition: h265_levels.c:170
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1362
HEVCDecoderConfigurationRecord::general_constraint_indicator_flags
uint64_t general_constraint_indicator_flags
Definition: hevc.c:71
intreadwrite.h
hvcc_parse_vui
static void hvcc_parse_vui(GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc, unsigned int max_sub_layers_minus1)
Definition: hevc.c:308
HEVC_NAL_VPS
@ HEVC_NAL_VPS
Definition: hevc.h:61
ff_nal_parse_units
int ff_nal_parse_units(AVIOContext *pb, const uint8_t *buf_in, int size)
Definition: nal.c:110
HEVC_MAX_VPS_COUNT
@ HEVC_MAX_VPS_COUNT
Definition: hevc.h:113
HEVCDecoderConfigurationRecord::general_profile_compatibility_flags
uint32_t general_profile_compatibility_flags
Definition: hevc.c:70
hevc.h
get_bits.h
HVCCProfileTierLevel::tier_flag
uint8_t tier_flag
Definition: hevc.c:91
NULL
#define NULL
Definition: coverity.c:32
skip_hrd_parameters
static int skip_hrd_parameters(GetBitContext *gb, uint8_t cprms_present_flag, unsigned int max_sub_layers_minus1)
Definition: hevc.c:224
ff_nal_unit_extract_rbsp
uint8_t * ff_nal_unit_extract_rbsp(const uint8_t *src, uint32_t src_len, uint32_t *dst_len, int header_len)
Definition: nal.c:160
ff_hevc_annexb2mp4_buf
int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out, int *size, int filter_ps, int *ps_count)
Writes Annex B formatted HEVC NAL units to a data buffer.
Definition: hevc.c:1249
nal_unit_parse_header
static void nal_unit_parse_header(GetBitContext *gb, uint8_t *nal_type, uint8_t *nuh_layer_id)
Definition: hevc.c:826
ff_isom_write_hvcc
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness, void *logctx)
Writes HEVC extradata (parameter sets and declarative SEI NAL units with nuh_layer_id == 0,...
Definition: hevc.c:1398
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:386
hvcc_parse_pps
static int hvcc_parse_pps(GetBitContext *gb, HVCCNALUnit *nal, HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:769
HEVCDecoderConfigurationRecord::arrays
HVCCNALUnitArray arrays[NB_ARRAYS]
Definition: hevc.c:84
avc.h
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:179
HEVCDecoderConfigurationRecord::lengthSizeMinusOne
uint8_t lengthSizeMinusOne
Definition: hevc.c:82
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
SPS_INDEX
@ SPS_INDEX
Definition: hevc.c:36
HVCCNALUnit::nalUnit
const uint8_t * nalUnit
Definition: hevc.c:52
skip_timing_info
static void skip_timing_info(GetBitContext *gb)
Definition: hevc.c:299
HEVCDecoderConfigurationRecord::bitDepthLumaMinus8
uint8_t bitDepthLumaMinus8
Definition: hevc.c:76
HVCCProfileTierLevel::profile_space
uint8_t profile_space
Definition: hevc.c:90
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
write_configuration_record
static int write_configuration_record(void *logctx, AVIOContext *pb, const uint8_t *data, int size, int flags)
Definition: hevc.c:1290
ff_nal_parse_units_buf
int ff_nal_parse_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
Definition: nal.c:130
HEVC_NAL_SPS
@ HEVC_NAL_SPS
Definition: hevc.h:62
size
int size
Definition: twinvq_data.h:10344
avio.h
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
HEVC_NAL_PPS
@ HEVC_NAL_PPS
Definition: hevc.h:63
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:201
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:365
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition: mem.c:225
HEVCDecoderConfigurationRecord::constantFrameRate
uint8_t constantFrameRate
Definition: hevc.c:79
FLAG_IS_LHVC
#define FLAG_IS_LHVC
Definition: hevc.c:46
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:411
HEVCDecoderConfigurationRecord::min_spatial_segmentation_idc
uint16_t min_spatial_segmentation_idc
Definition: hevc.c:73
HEVCDecoderConfigurationRecord::bitDepthChromaMinus8
uint8_t bitDepthChromaMinus8
Definition: hevc.c:77
get_bits64
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
Definition: get_bits.h:451
SEI_PREFIX_INDEX
@ SEI_PREFIX_INDEX
Definition: hevc.c:38
HEVCDecoderConfigurationRecord::numOfArrays
uint8_t numOfArrays
Definition: hevc.c:83
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
hvcc_parse_ptl
static void hvcc_parse_ptl(GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc, int profile_present_flag, unsigned int max_sub_layers_minus1)
Definition: hevc.c:152
avio_internal.h
HVCCProfileTierLevel::profile_compatibility_flags
uint32_t profile_compatibility_flags
Definition: hevc.c:93
HVCCNALUnitArray::numNalus
uint16_t numNalus
Definition: hevc.c:61
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
len
int len
Definition: vorbis_enc_data.h:426
hvcc_update_ptl
static void hvcc_update_ptl(HEVCDecoderConfigurationRecord *hvcc, HVCCProfileTierLevel *ptl)
Definition: hevc.c:98
nal.h
hvcc_array_add_nal_unit
static int hvcc_array_add_nal_unit(const uint8_t *nal_buf, uint32_t nal_size, HVCCNALUnitArray *array)
Definition: hevc.c:840
HEVCDecoderConfigurationRecord::general_tier_flag
uint8_t general_tier_flag
Definition: hevc.c:68
HEVCDecoderConfigurationRecord::general_level_idc
uint8_t general_level_idc
Definition: hevc.c:72
HVCCProfileTierLevel
Definition: hevc.c:89
HEVCDecoderConfigurationRecord::configurationVersion
uint8_t configurationVersion
Definition: hevc.c:66
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:116
ffio_free_dyn_buf
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1435
ret
ret
Definition: filter_design.txt:187
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:555
skip_sub_layer_hrd_parameters
static void skip_sub_layer_hrd_parameters(GetBitContext *gb, unsigned int cpb_cnt_minus1, uint8_t sub_pic_hrd_params_present_flag)
Definition: hevc.c:205
U
#define U(x)
Definition: vpx_arith.h:37
HVCCNALUnit
Definition: hevc.c:48
HEVCDecoderConfigurationRecord::parallelismType
uint8_t parallelismType
Definition: hevc.c:74
FLAG_IS_NALFF
#define FLAG_IS_NALFF
Definition: hevc.c:45
HVCCNALUnit::nalUnitLength
uint16_t nalUnitLength
Definition: hevc.c:51
HVCCNALUnitArray::array_completeness
uint8_t array_completeness
Definition: hevc.c:59
hvcc_parse_sps
static int hvcc_parse_sps(GetBitContext *gb, HVCCNALUnit *nal, HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:628
hvcc_write
static int hvcc_write(void *logctx, AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc, int flags)
Definition: hevc.c:961
mem.h
get_ue_golomb_long
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
Definition: golomb.h:104
HVCCProfileTierLevel::constraint_indicator_flags
uint64_t constraint_indicator_flags
Definition: hevc.c:94
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
HEVCDecoderConfigurationRecord
Definition: hevc.c:65
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:443
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_isom_write_lhvc
int ff_isom_write_lhvc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness, void *logctx)
Writes L-HEVC extradata (parameter sets with nuh_layer_id > 0, as a LHEVCDecoderConfigurationRecord) ...
Definition: hevc.c:1405
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
hvcc_parse_vps_extension
static int hvcc_parse_vps_extension(GetBitContext *gb, HVCCNALUnit *nal, HEVCDecoderConfigurationRecord *hvcc, uint8_t vps_max_layers_minus1, uint8_t vps_base_layer_internal_flag)
Definition: hevc.c:393
PPS_INDEX
@ PPS_INDEX
Definition: hevc.c:37
AV_RB24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
Definition: bytestream.h:97
MAX_SPATIAL_SEGMENTATION
#define MAX_SPATIAL_SEGMENTATION
Definition: hevc.c:32
HVCCNALUnitArray::nal
HVCCNALUnit * nal
Definition: hevc.c:62
HEVC_MAX_SUB_LAYERS
@ HEVC_MAX_SUB_LAYERS
Definition: hevc.h:105
HVCCNALUnitArray::NAL_unit_type
uint8_t NAL_unit_type
Definition: hevc.c:60
skip_sub_layer_ordering_info
static void skip_sub_layer_ordering_info(GetBitContext *gb)
Definition: hevc.c:386
HEVC_MAX_SPS_COUNT
@ HEVC_MAX_SPS_COUNT
Definition: hevc.h:115
ff_hevc_annexb2mp4
int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in, int size, int filter_ps, int *ps_count)
Writes Annex B formatted HEVC NAL units to the provided AVIOContext.
Definition: hevc.c:1201
HVCCNALUnit::vps_max_sub_layers_minus1
uint8_t vps_max_sub_layers_minus1
Definition: hevc.c:55
HEVCDecoderConfigurationRecord::general_profile_space
uint8_t general_profile_space
Definition: hevc.c:67
HVCCNALUnitArray
Definition: hevc.c:58