FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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.h"
24 #include "libavutil/intreadwrite.h"
25 #include "avc.h"
26 #include "avio.h"
27 #include "hevc.h"
28 
29 #define MAX_SPATIAL_SEGMENTATION 4096 // max. value of u(12) field
30 
31 typedef struct HVCCNALUnitArray {
34  uint16_t numNalus;
35  uint16_t *nalUnitLength;
38 
52  uint16_t avgFrameRate;
60 
61 typedef struct HVCCProfileTierLevel {
69 
72 {
73  /*
74  * The value of general_profile_space in all the parameter sets must be
75  * identical.
76  */
78 
79  /*
80  * The level indication general_level_idc must indicate a level of
81  * capability equal to or greater than the highest level indicated for the
82  * highest tier in all the parameter sets.
83  */
84  if (hvcc->general_tier_flag < ptl->tier_flag)
85  hvcc->general_level_idc = ptl->level_idc;
86  else
88 
89  /*
90  * The tier indication general_tier_flag must indicate a tier equal to or
91  * greater than the highest tier indicated in all the parameter sets.
92  */
94 
95  /*
96  * The profile indication general_profile_idc must indicate a profile to
97  * which the stream associated with this configuration record conforms.
98  *
99  * If the sequence parameter sets are marked with different profiles, then
100  * the stream may need examination to determine which profile, if any, the
101  * entire stream conforms to. If the entire stream is not examined, or the
102  * examination reveals that there is no profile to which the entire stream
103  * conforms, then the entire stream must be split into two or more
104  * sub-streams with separate configuration records in which these rules can
105  * be met.
106  *
107  * Note: set the profile to the highest value for the sake of simplicity.
108  */
110 
111  /*
112  * Each bit in general_profile_compatibility_flags may only be set if all
113  * the parameter sets set that bit.
114  */
116 
117  /*
118  * Each bit in general_constraint_indicator_flags may only be set if all
119  * the parameter sets set that bit.
120  */
122 }
123 
126  unsigned int max_sub_layers_minus1)
127 {
128  unsigned int i;
129  HVCCProfileTierLevel general_ptl;
130  uint8_t sub_layer_profile_present_flag[MAX_SUB_LAYERS];
131  uint8_t sub_layer_level_present_flag[MAX_SUB_LAYERS];
132 
133  general_ptl.profile_space = get_bits(gb, 2);
134  general_ptl.tier_flag = get_bits1(gb);
135  general_ptl.profile_idc = get_bits(gb, 5);
136  general_ptl.profile_compatibility_flags = get_bits_long(gb, 32);
137  general_ptl.constraint_indicator_flags = get_bits64(gb, 48);
138  general_ptl.level_idc = get_bits(gb, 8);
139  hvcc_update_ptl(hvcc, &general_ptl);
140 
141  for (i = 0; i < max_sub_layers_minus1; i++) {
142  sub_layer_profile_present_flag[i] = get_bits1(gb);
143  sub_layer_level_present_flag[i] = get_bits1(gb);
144  }
145 
146  if (max_sub_layers_minus1 > 0)
147  for (i = max_sub_layers_minus1; i < 8; i++)
148  skip_bits(gb, 2); // reserved_zero_2bits[i]
149 
150  for (i = 0; i < max_sub_layers_minus1; i++) {
151  if (sub_layer_profile_present_flag[i]) {
152  /*
153  * sub_layer_profile_space[i] u(2)
154  * sub_layer_tier_flag[i] u(1)
155  * sub_layer_profile_idc[i] u(5)
156  * sub_layer_profile_compatibility_flag[i][0..31] u(32)
157  * sub_layer_progressive_source_flag[i] u(1)
158  * sub_layer_interlaced_source_flag[i] u(1)
159  * sub_layer_non_packed_constraint_flag[i] u(1)
160  * sub_layer_frame_only_constraint_flag[i] u(1)
161  * sub_layer_reserved_zero_44bits[i] u(44)
162  */
163  skip_bits_long(gb, 32);
164  skip_bits_long(gb, 32);
165  skip_bits (gb, 24);
166  }
167 
168  if (sub_layer_level_present_flag[i])
169  skip_bits(gb, 8);
170  }
171 }
172 
174  unsigned int cpb_cnt_minus1,
175  uint8_t sub_pic_hrd_params_present_flag)
176 {
177  unsigned int i;
178 
179  for (i = 0; i <= cpb_cnt_minus1; i++) {
180  get_ue_golomb_long(gb); // bit_rate_value_minus1
181  get_ue_golomb_long(gb); // cpb_size_value_minus1
182 
183  if (sub_pic_hrd_params_present_flag) {
184  get_ue_golomb_long(gb); // cpb_size_du_value_minus1
185  get_ue_golomb_long(gb); // bit_rate_du_value_minus1
186  }
187 
188  skip_bits1(gb); // cbr_flag
189  }
190 }
191 
192 static int skip_hrd_parameters(GetBitContext *gb, uint8_t cprms_present_flag,
193  unsigned int max_sub_layers_minus1)
194 {
195  unsigned int i;
196  uint8_t sub_pic_hrd_params_present_flag = 0;
197  uint8_t nal_hrd_parameters_present_flag = 0;
198  uint8_t vcl_hrd_parameters_present_flag = 0;
199 
200  if (cprms_present_flag) {
201  nal_hrd_parameters_present_flag = get_bits1(gb);
202  vcl_hrd_parameters_present_flag = get_bits1(gb);
203 
204  if (nal_hrd_parameters_present_flag ||
205  vcl_hrd_parameters_present_flag) {
206  sub_pic_hrd_params_present_flag = get_bits1(gb);
207 
208  if (sub_pic_hrd_params_present_flag)
209  /*
210  * tick_divisor_minus2 u(8)
211  * du_cpb_removal_delay_increment_length_minus1 u(5)
212  * sub_pic_cpb_params_in_pic_timing_sei_flag u(1)
213  * dpb_output_delay_du_length_minus1 u(5)
214  */
215  skip_bits(gb, 19);
216 
217  /*
218  * bit_rate_scale u(4)
219  * cpb_size_scale u(4)
220  */
221  skip_bits(gb, 8);
222 
223  if (sub_pic_hrd_params_present_flag)
224  skip_bits(gb, 4); // cpb_size_du_scale
225 
226  /*
227  * initial_cpb_removal_delay_length_minus1 u(5)
228  * au_cpb_removal_delay_length_minus1 u(5)
229  * dpb_output_delay_length_minus1 u(5)
230  */
231  skip_bits(gb, 15);
232  }
233  }
234 
235  for (i = 0; i <= max_sub_layers_minus1; i++) {
236  unsigned int cpb_cnt_minus1 = 0;
237  uint8_t low_delay_hrd_flag = 0;
238  uint8_t fixed_pic_rate_within_cvs_flag = 0;
239  uint8_t fixed_pic_rate_general_flag = get_bits1(gb);
240 
241  if (!fixed_pic_rate_general_flag)
242  fixed_pic_rate_within_cvs_flag = get_bits1(gb);
243 
244  if (fixed_pic_rate_within_cvs_flag)
245  get_ue_golomb_long(gb); // elemental_duration_in_tc_minus1
246  else
247  low_delay_hrd_flag = get_bits1(gb);
248 
249  if (!low_delay_hrd_flag) {
250  cpb_cnt_minus1 = get_ue_golomb_long(gb);
251  if (cpb_cnt_minus1 > 31)
252  return AVERROR_INVALIDDATA;
253  }
254 
255  if (nal_hrd_parameters_present_flag)
256  skip_sub_layer_hrd_parameters(gb, cpb_cnt_minus1,
257  sub_pic_hrd_params_present_flag);
258 
259  if (vcl_hrd_parameters_present_flag)
260  skip_sub_layer_hrd_parameters(gb, cpb_cnt_minus1,
261  sub_pic_hrd_params_present_flag);
262  }
263 
264  return 0;
265 }
266 
268 {
269  skip_bits_long(gb, 32); // num_units_in_tick
270  skip_bits_long(gb, 32); // time_scale
271 
272  if (get_bits1(gb)) // poc_proportional_to_timing_flag
273  get_ue_golomb_long(gb); // num_ticks_poc_diff_one_minus1
274 }
275 
278  unsigned int max_sub_layers_minus1)
279 {
280  unsigned int min_spatial_segmentation_idc;
281 
282  if (get_bits1(gb)) // aspect_ratio_info_present_flag
283  if (get_bits(gb, 8) == 255) // aspect_ratio_idc
284  skip_bits_long(gb, 32); // sar_width u(16), sar_height u(16)
285 
286  if (get_bits1(gb)) // overscan_info_present_flag
287  skip_bits1(gb); // overscan_appropriate_flag
288 
289  if (get_bits1(gb)) { // video_signal_type_present_flag
290  skip_bits(gb, 4); // video_format u(3), video_full_range_flag u(1)
291 
292  if (get_bits1(gb)) // colour_description_present_flag
293  /*
294  * colour_primaries u(8)
295  * transfer_characteristics u(8)
296  * matrix_coeffs u(8)
297  */
298  skip_bits(gb, 24);
299  }
300 
301  if (get_bits1(gb)) { // chroma_loc_info_present_flag
302  get_ue_golomb_long(gb); // chroma_sample_loc_type_top_field
303  get_ue_golomb_long(gb); // chroma_sample_loc_type_bottom_field
304  }
305 
306  /*
307  * neutral_chroma_indication_flag u(1)
308  * field_seq_flag u(1)
309  * frame_field_info_present_flag u(1)
310  */
311  skip_bits(gb, 3);
312 
313  if (get_bits1(gb)) { // default_display_window_flag
314  get_ue_golomb_long(gb); // def_disp_win_left_offset
315  get_ue_golomb_long(gb); // def_disp_win_right_offset
316  get_ue_golomb_long(gb); // def_disp_win_top_offset
317  get_ue_golomb_long(gb); // def_disp_win_bottom_offset
318  }
319 
320  if (get_bits1(gb)) { // vui_timing_info_present_flag
321  skip_timing_info(gb);
322 
323  if (get_bits1(gb)) // vui_hrd_parameters_present_flag
324  skip_hrd_parameters(gb, 1, max_sub_layers_minus1);
325  }
326 
327  if (get_bits1(gb)) { // bitstream_restriction_flag
328  /*
329  * tiles_fixed_structure_flag u(1)
330  * motion_vectors_over_pic_boundaries_flag u(1)
331  * restricted_ref_pic_lists_flag u(1)
332  */
333  skip_bits(gb, 3);
334 
335  min_spatial_segmentation_idc = get_ue_golomb_long(gb);
336 
337  /*
338  * unsigned int(12) min_spatial_segmentation_idc;
339  *
340  * The min_spatial_segmentation_idc indication must indicate a level of
341  * spatial segmentation equal to or less than the lowest level of
342  * spatial segmentation indicated in all the parameter sets.
343  */
345  min_spatial_segmentation_idc);
346 
347  get_ue_golomb_long(gb); // max_bytes_per_pic_denom
348  get_ue_golomb_long(gb); // max_bits_per_min_cu_denom
349  get_ue_golomb_long(gb); // log2_max_mv_length_horizontal
350  get_ue_golomb_long(gb); // log2_max_mv_length_vertical
351  }
352 }
353 
355 {
356  get_ue_golomb_long(gb); // max_dec_pic_buffering_minus1
357  get_ue_golomb_long(gb); // max_num_reorder_pics
358  get_ue_golomb_long(gb); // max_latency_increase_plus1
359 }
360 
363 {
364  unsigned int vps_max_sub_layers_minus1;
365 
366  /*
367  * vps_video_parameter_set_id u(4)
368  * vps_reserved_three_2bits u(2)
369  * vps_max_layers_minus1 u(6)
370  */
371  skip_bits(gb, 12);
372 
373  vps_max_sub_layers_minus1 = get_bits(gb, 3);
374 
375  /*
376  * numTemporalLayers greater than 1 indicates that the stream to which this
377  * configuration record applies is temporally scalable and the contained
378  * number of temporal layers (also referred to as temporal sub-layer or
379  * sub-layer in ISO/IEC 23008-2) is equal to numTemporalLayers. Value 1
380  * indicates that the stream is not temporally scalable. Value 0 indicates
381  * that it is unknown whether the stream is temporally scalable.
382  */
384  vps_max_sub_layers_minus1 + 1);
385 
386  /*
387  * vps_temporal_id_nesting_flag u(1)
388  * vps_reserved_0xffff_16bits u(16)
389  */
390  skip_bits(gb, 17);
391 
392  hvcc_parse_ptl(gb, hvcc, vps_max_sub_layers_minus1);
393 
394  /* nothing useful for hvcC past this point */
395  return 0;
396 }
397 
399 {
400  int i, j, k, num_coeffs;
401 
402  for (i = 0; i < 4; i++)
403  for (j = 0; j < (i == 3 ? 2 : 6); j++)
404  if (!get_bits1(gb)) // scaling_list_pred_mode_flag[i][j]
405  get_ue_golomb_long(gb); // scaling_list_pred_matrix_id_delta[i][j]
406  else {
407  num_coeffs = FFMIN(64, 1 << (4 + (i << 1)));
408 
409  if (i > 1)
410  get_se_golomb_long(gb); // scaling_list_dc_coef_minus8[i-2][j]
411 
412  for (k = 0; k < num_coeffs; k++)
413  get_se_golomb_long(gb); // scaling_list_delta_coef
414  }
415 }
416 
417 static int parse_rps(GetBitContext *gb, unsigned int rps_idx,
418  unsigned int num_rps,
419  unsigned int num_delta_pocs[MAX_SHORT_TERM_RPS_COUNT])
420 {
421  unsigned int i;
422 
423  if (rps_idx && get_bits1(gb)) { // inter_ref_pic_set_prediction_flag
424  /* this should only happen for slice headers, and this isn't one */
425  if (rps_idx >= num_rps)
426  return AVERROR_INVALIDDATA;
427 
428  skip_bits1 (gb); // delta_rps_sign
429  get_ue_golomb_long(gb); // abs_delta_rps_minus1
430 
431  num_delta_pocs[rps_idx] = 0;
432 
433  /*
434  * From libavcodec/hevc_ps.c:
435  *
436  * if (is_slice_header) {
437  * //foo
438  * } else
439  * rps_ridx = &sps->st_rps[rps - sps->st_rps - 1];
440  *
441  * where:
442  * rps: &sps->st_rps[rps_idx]
443  * sps->st_rps: &sps->st_rps[0]
444  * is_slice_header: rps_idx == num_rps
445  *
446  * thus:
447  * if (num_rps != rps_idx)
448  * rps_ridx = &sps->st_rps[rps_idx - 1];
449  *
450  * NumDeltaPocs[RefRpsIdx]: num_delta_pocs[rps_idx - 1]
451  */
452  for (i = 0; i < num_delta_pocs[rps_idx - 1]; i++) {
453  uint8_t use_delta_flag = 0;
454  uint8_t used_by_curr_pic_flag = get_bits1(gb);
455  if (!used_by_curr_pic_flag)
456  use_delta_flag = get_bits1(gb);
457 
458  if (used_by_curr_pic_flag || use_delta_flag)
459  num_delta_pocs[rps_idx]++;
460  }
461  } else {
462  unsigned int num_negative_pics = get_ue_golomb_long(gb);
463  unsigned int num_positive_pics = get_ue_golomb_long(gb);
464 
465  if ((num_positive_pics + (uint64_t)num_negative_pics) * 2 > get_bits_left(gb))
466  return AVERROR_INVALIDDATA;
467 
468  num_delta_pocs[rps_idx] = num_negative_pics + num_positive_pics;
469 
470  for (i = 0; i < num_negative_pics; i++) {
471  get_ue_golomb_long(gb); // delta_poc_s0_minus1[rps_idx]
472  skip_bits1 (gb); // used_by_curr_pic_s0_flag[rps_idx]
473  }
474 
475  for (i = 0; i < num_positive_pics; i++) {
476  get_ue_golomb_long(gb); // delta_poc_s1_minus1[rps_idx]
477  skip_bits1 (gb); // used_by_curr_pic_s1_flag[rps_idx]
478  }
479  }
480 
481  return 0;
482 }
483 
486 {
487  unsigned int i, sps_max_sub_layers_minus1, log2_max_pic_order_cnt_lsb_minus4;
488  unsigned int num_short_term_ref_pic_sets, num_delta_pocs[MAX_SHORT_TERM_RPS_COUNT];
489 
490  skip_bits(gb, 4); // sps_video_parameter_set_id
491 
492  sps_max_sub_layers_minus1 = get_bits (gb, 3);
493 
494  /*
495  * numTemporalLayers greater than 1 indicates that the stream to which this
496  * configuration record applies is temporally scalable and the contained
497  * number of temporal layers (also referred to as temporal sub-layer or
498  * sub-layer in ISO/IEC 23008-2) is equal to numTemporalLayers. Value 1
499  * indicates that the stream is not temporally scalable. Value 0 indicates
500  * that it is unknown whether the stream is temporally scalable.
501  */
503  sps_max_sub_layers_minus1 + 1);
504 
505  hvcc->temporalIdNested = get_bits1(gb);
506 
507  hvcc_parse_ptl(gb, hvcc, sps_max_sub_layers_minus1);
508 
509  get_ue_golomb_long(gb); // sps_seq_parameter_set_id
510 
511  hvcc->chromaFormat = get_ue_golomb_long(gb);
512 
513  if (hvcc->chromaFormat == 3)
514  skip_bits1(gb); // separate_colour_plane_flag
515 
516  get_ue_golomb_long(gb); // pic_width_in_luma_samples
517  get_ue_golomb_long(gb); // pic_height_in_luma_samples
518 
519  if (get_bits1(gb)) { // conformance_window_flag
520  get_ue_golomb_long(gb); // conf_win_left_offset
521  get_ue_golomb_long(gb); // conf_win_right_offset
522  get_ue_golomb_long(gb); // conf_win_top_offset
523  get_ue_golomb_long(gb); // conf_win_bottom_offset
524  }
525 
528  log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb_long(gb);
529 
530  /* sps_sub_layer_ordering_info_present_flag */
531  i = get_bits1(gb) ? 0 : sps_max_sub_layers_minus1;
532  for (; i <= sps_max_sub_layers_minus1; i++)
534 
535  get_ue_golomb_long(gb); // log2_min_luma_coding_block_size_minus3
536  get_ue_golomb_long(gb); // log2_diff_max_min_luma_coding_block_size
537  get_ue_golomb_long(gb); // log2_min_transform_block_size_minus2
538  get_ue_golomb_long(gb); // log2_diff_max_min_transform_block_size
539  get_ue_golomb_long(gb); // max_transform_hierarchy_depth_inter
540  get_ue_golomb_long(gb); // max_transform_hierarchy_depth_intra
541 
542  if (get_bits1(gb) && // scaling_list_enabled_flag
543  get_bits1(gb)) // sps_scaling_list_data_present_flag
545 
546  skip_bits1(gb); // amp_enabled_flag
547  skip_bits1(gb); // sample_adaptive_offset_enabled_flag
548 
549  if (get_bits1(gb)) { // pcm_enabled_flag
550  skip_bits (gb, 4); // pcm_sample_bit_depth_luma_minus1
551  skip_bits (gb, 4); // pcm_sample_bit_depth_chroma_minus1
552  get_ue_golomb_long(gb); // log2_min_pcm_luma_coding_block_size_minus3
553  get_ue_golomb_long(gb); // log2_diff_max_min_pcm_luma_coding_block_size
554  skip_bits1 (gb); // pcm_loop_filter_disabled_flag
555  }
556 
557  num_short_term_ref_pic_sets = get_ue_golomb_long(gb);
558  if (num_short_term_ref_pic_sets > MAX_SHORT_TERM_RPS_COUNT)
559  return AVERROR_INVALIDDATA;
560 
561  for (i = 0; i < num_short_term_ref_pic_sets; i++) {
562  int ret = parse_rps(gb, i, num_short_term_ref_pic_sets, num_delta_pocs);
563  if (ret < 0)
564  return ret;
565  }
566 
567  if (get_bits1(gb)) { // long_term_ref_pics_present_flag
568  for (i = 0; i < get_ue_golomb_long(gb); i++) { // num_long_term_ref_pics_sps
569  int len = FFMIN(log2_max_pic_order_cnt_lsb_minus4 + 4, 16);
570  skip_bits (gb, len); // lt_ref_pic_poc_lsb_sps[i]
571  skip_bits1(gb); // used_by_curr_pic_lt_sps_flag[i]
572  }
573  }
574 
575  skip_bits1(gb); // sps_temporal_mvp_enabled_flag
576  skip_bits1(gb); // strong_intra_smoothing_enabled_flag
577 
578  if (get_bits1(gb)) // vui_parameters_present_flag
579  hvcc_parse_vui(gb, hvcc, sps_max_sub_layers_minus1);
580 
581  /* nothing useful for hvcC past this point */
582  return 0;
583 }
584 
587 {
588  uint8_t tiles_enabled_flag, entropy_coding_sync_enabled_flag;
589 
590  get_ue_golomb_long(gb); // pps_pic_parameter_set_id
591  get_ue_golomb_long(gb); // pps_seq_parameter_set_id
592 
593  /*
594  * dependent_slice_segments_enabled_flag u(1)
595  * output_flag_present_flag u(1)
596  * num_extra_slice_header_bits u(3)
597  * sign_data_hiding_enabled_flag u(1)
598  * cabac_init_present_flag u(1)
599  */
600  skip_bits(gb, 7);
601 
602  get_ue_golomb_long(gb); // num_ref_idx_l0_default_active_minus1
603  get_ue_golomb_long(gb); // num_ref_idx_l1_default_active_minus1
604  get_se_golomb_long(gb); // init_qp_minus26
605 
606  /*
607  * constrained_intra_pred_flag u(1)
608  * transform_skip_enabled_flag u(1)
609  */
610  skip_bits(gb, 2);
611 
612  if (get_bits1(gb)) // cu_qp_delta_enabled_flag
613  get_ue_golomb_long(gb); // diff_cu_qp_delta_depth
614 
615  get_se_golomb_long(gb); // pps_cb_qp_offset
616  get_se_golomb_long(gb); // pps_cr_qp_offset
617 
618  /*
619  * weighted_pred_flag u(1)
620  * weighted_bipred_flag u(1)
621  * transquant_bypass_enabled_flag u(1)
622  */
623  skip_bits(gb, 3);
624 
625  tiles_enabled_flag = get_bits1(gb);
626  entropy_coding_sync_enabled_flag = get_bits1(gb);
627 
628  if (entropy_coding_sync_enabled_flag && tiles_enabled_flag)
629  hvcc->parallelismType = 0; // mixed-type parallel decoding
630  else if (entropy_coding_sync_enabled_flag)
631  hvcc->parallelismType = 3; // wavefront-based parallel decoding
632  else if (tiles_enabled_flag)
633  hvcc->parallelismType = 2; // tile-based parallel decoding
634  else
635  hvcc->parallelismType = 1; // slice-based parallel decoding
636 
637  /* nothing useful for hvcC past this point */
638  return 0;
639 }
640 
641 static uint8_t *nal_unit_extract_rbsp(const uint8_t *src, uint32_t src_len,
642  uint32_t *dst_len)
643 {
644  uint8_t *dst;
645  uint32_t i, len;
646 
647  dst = av_malloc(src_len);
648  if (!dst)
649  return NULL;
650 
651  /* NAL unit header (2 bytes) */
652  i = len = 0;
653  while (i < 2 && i < src_len)
654  dst[len++] = src[i++];
655 
656  while (i + 2 < src_len)
657  if (!src[i] && !src[i + 1] && src[i + 2] == 3) {
658  dst[len++] = src[i++];
659  dst[len++] = src[i++];
660  i++; // remove emulation_prevention_three_byte
661  } else
662  dst[len++] = src[i++];
663 
664  while (i < src_len)
665  dst[len++] = src[i++];
666 
667  *dst_len = len;
668  return dst;
669 }
670 
671 
672 
673 static void nal_unit_parse_header(GetBitContext *gb, uint8_t *nal_type)
674 {
675  skip_bits1(gb); // forbidden_zero_bit
676 
677  *nal_type = get_bits(gb, 6);
678 
679  /*
680  * nuh_layer_id u(6)
681  * nuh_temporal_id_plus1 u(3)
682  */
683  skip_bits(gb, 9);
684 }
685 
686 static int hvcc_array_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size,
687  uint8_t nal_type, int ps_array_completeness,
689 {
690  int ret;
691  uint8_t index;
692  uint16_t numNalus;
693  HVCCNALUnitArray *array;
694 
695  for (index = 0; index < hvcc->numOfArrays; index++)
696  if (hvcc->array[index].NAL_unit_type == nal_type)
697  break;
698 
699  if (index >= hvcc->numOfArrays) {
700  uint8_t i;
701 
702  ret = av_reallocp_array(&hvcc->array, index + 1, sizeof(HVCCNALUnitArray));
703  if (ret < 0)
704  return ret;
705 
706  for (i = hvcc->numOfArrays; i <= index; i++)
707  memset(&hvcc->array[i], 0, sizeof(HVCCNALUnitArray));
708  hvcc->numOfArrays = index + 1;
709  }
710 
711  array = &hvcc->array[index];
712  numNalus = array->numNalus;
713 
714  ret = av_reallocp_array(&array->nalUnit, numNalus + 1, sizeof(uint8_t*));
715  if (ret < 0)
716  return ret;
717 
718  ret = av_reallocp_array(&array->nalUnitLength, numNalus + 1, sizeof(uint16_t));
719  if (ret < 0)
720  return ret;
721 
722  array->nalUnit [numNalus] = nal_buf;
723  array->nalUnitLength[numNalus] = nal_size;
724  array->NAL_unit_type = nal_type;
725  array->numNalus++;
726 
727  /*
728  * When the sample entry name is ‘hvc1’, the default and mandatory value of
729  * array_completeness is 1 for arrays of all types of parameter sets, and 0
730  * for all other arrays. When the sample entry name is ‘hev1’, the default
731  * value of array_completeness is 0 for all arrays.
732  */
733  if (nal_type == NAL_VPS || nal_type == NAL_SPS || nal_type == NAL_PPS)
734  array->array_completeness = ps_array_completeness;
735 
736  return 0;
737 }
738 
739 static int hvcc_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size,
740  int ps_array_completeness,
742 {
743  int ret = 0;
744  GetBitContext gbc;
745  uint8_t nal_type;
746  uint8_t *rbsp_buf;
747  uint32_t rbsp_size;
748 
749  rbsp_buf = nal_unit_extract_rbsp(nal_buf, nal_size, &rbsp_size);
750  if (!rbsp_buf) {
751  ret = AVERROR(ENOMEM);
752  goto end;
753  }
754 
755  ret = init_get_bits8(&gbc, rbsp_buf, rbsp_size);
756  if (ret < 0)
757  goto end;
758 
759  nal_unit_parse_header(&gbc, &nal_type);
760 
761  /*
762  * Note: only 'declarative' SEI messages are allowed in
763  * hvcC. Perhaps the SEI playload type should be checked
764  * and non-declarative SEI messages discarded?
765  */
766  switch (nal_type) {
767  case NAL_VPS:
768  case NAL_SPS:
769  case NAL_PPS:
770  case NAL_SEI_PREFIX:
771  case NAL_SEI_SUFFIX:
772  ret = hvcc_array_add_nal_unit(nal_buf, nal_size, nal_type,
773  ps_array_completeness, hvcc);
774  if (ret < 0)
775  goto end;
776  else if (nal_type == NAL_VPS)
777  ret = hvcc_parse_vps(&gbc, hvcc);
778  else if (nal_type == NAL_SPS)
779  ret = hvcc_parse_sps(&gbc, hvcc);
780  else if (nal_type == NAL_PPS)
781  ret = hvcc_parse_pps(&gbc, hvcc);
782  if (ret < 0)
783  goto end;
784  break;
785  default:
786  ret = AVERROR_INVALIDDATA;
787  goto end;
788  }
789 
790 end:
791  av_free(rbsp_buf);
792  return ret;
793 }
794 
796 {
797  memset(hvcc, 0, sizeof(HEVCDecoderConfigurationRecord));
798  hvcc->configurationVersion = 1;
799  hvcc->lengthSizeMinusOne = 3; // 4 bytes
800 
801  /*
802  * The following fields have all their valid bits set by default,
803  * the ProfileTierLevel parsing code will unset them when needed.
804  */
805  hvcc->general_profile_compatibility_flags = 0xffffffff;
806  hvcc->general_constraint_indicator_flags = 0xffffffffffff;
807 
808  /*
809  * Initialize this field with an invalid value which can be used to detect
810  * whether we didn't see any VUI (in which case it should be reset to zero).
811  */
813 }
814 
816 {
817  uint8_t i;
818 
819  for (i = 0; i < hvcc->numOfArrays; i++) {
820  hvcc->array[i].numNalus = 0;
821  av_freep(&hvcc->array[i].nalUnit);
822  av_freep(&hvcc->array[i].nalUnitLength);
823  }
824 
825  hvcc->numOfArrays = 0;
826  av_freep(&hvcc->array);
827 }
828 
830 {
831  uint8_t i;
832  uint16_t j, vps_count = 0, sps_count = 0, pps_count = 0;
833 
834  /*
835  * We only support writing HEVCDecoderConfigurationRecord version 1.
836  */
837  hvcc->configurationVersion = 1;
838 
839  /*
840  * If min_spatial_segmentation_idc is invalid, reset to 0 (unspecified).
841  */
844 
845  /*
846  * parallelismType indicates the type of parallelism that is used to meet
847  * the restrictions imposed by min_spatial_segmentation_idc when the value
848  * of min_spatial_segmentation_idc is greater than 0.
849  */
850  if (!hvcc->min_spatial_segmentation_idc)
851  hvcc->parallelismType = 0;
852 
853  /*
854  * It's unclear how to properly compute these fields, so
855  * let's always set them to values meaning 'unspecified'.
856  */
857  hvcc->avgFrameRate = 0;
858  hvcc->constantFrameRate = 0;
859 
860  av_log(NULL, AV_LOG_TRACE, "configurationVersion: %"PRIu8"\n",
861  hvcc->configurationVersion);
862  av_log(NULL, AV_LOG_TRACE, "general_profile_space: %"PRIu8"\n",
863  hvcc->general_profile_space);
864  av_log(NULL, AV_LOG_TRACE, "general_tier_flag: %"PRIu8"\n",
865  hvcc->general_tier_flag);
866  av_log(NULL, AV_LOG_TRACE, "general_profile_idc: %"PRIu8"\n",
867  hvcc->general_profile_idc);
868  av_log(NULL, AV_LOG_TRACE, "general_profile_compatibility_flags: 0x%08"PRIx32"\n",
870  av_log(NULL, AV_LOG_TRACE, "general_constraint_indicator_flags: 0x%012"PRIx64"\n",
872  av_log(NULL, AV_LOG_TRACE, "general_level_idc: %"PRIu8"\n",
873  hvcc->general_level_idc);
874  av_log(NULL, AV_LOG_TRACE, "min_spatial_segmentation_idc: %"PRIu16"\n",
876  av_log(NULL, AV_LOG_TRACE, "parallelismType: %"PRIu8"\n",
877  hvcc->parallelismType);
878  av_log(NULL, AV_LOG_TRACE, "chromaFormat: %"PRIu8"\n",
879  hvcc->chromaFormat);
880  av_log(NULL, AV_LOG_TRACE, "bitDepthLumaMinus8: %"PRIu8"\n",
881  hvcc->bitDepthLumaMinus8);
882  av_log(NULL, AV_LOG_TRACE, "bitDepthChromaMinus8: %"PRIu8"\n",
883  hvcc->bitDepthChromaMinus8);
884  av_log(NULL, AV_LOG_TRACE, "avgFrameRate: %"PRIu16"\n",
885  hvcc->avgFrameRate);
886  av_log(NULL, AV_LOG_TRACE, "constantFrameRate: %"PRIu8"\n",
887  hvcc->constantFrameRate);
888  av_log(NULL, AV_LOG_TRACE, "numTemporalLayers: %"PRIu8"\n",
889  hvcc->numTemporalLayers);
890  av_log(NULL, AV_LOG_TRACE, "temporalIdNested: %"PRIu8"\n",
891  hvcc->temporalIdNested);
892  av_log(NULL, AV_LOG_TRACE, "lengthSizeMinusOne: %"PRIu8"\n",
893  hvcc->lengthSizeMinusOne);
894  av_log(NULL, AV_LOG_TRACE, "numOfArrays: %"PRIu8"\n",
895  hvcc->numOfArrays);
896  for (i = 0; i < hvcc->numOfArrays; i++) {
897  av_log(NULL, AV_LOG_TRACE, "array_completeness[%"PRIu8"]: %"PRIu8"\n",
898  i, hvcc->array[i].array_completeness);
899  av_log(NULL, AV_LOG_TRACE, "NAL_unit_type[%"PRIu8"]: %"PRIu8"\n",
900  i, hvcc->array[i].NAL_unit_type);
901  av_log(NULL, AV_LOG_TRACE, "numNalus[%"PRIu8"]: %"PRIu16"\n",
902  i, hvcc->array[i].numNalus);
903  for (j = 0; j < hvcc->array[i].numNalus; j++)
905  "nalUnitLength[%"PRIu8"][%"PRIu16"]: %"PRIu16"\n",
906  i, j, hvcc->array[i].nalUnitLength[j]);
907  }
908 
909  /*
910  * We need at least one of each: VPS, SPS and PPS.
911  */
912  for (i = 0; i < hvcc->numOfArrays; i++)
913  switch (hvcc->array[i].NAL_unit_type) {
914  case NAL_VPS:
915  vps_count += hvcc->array[i].numNalus;
916  break;
917  case NAL_SPS:
918  sps_count += hvcc->array[i].numNalus;
919  break;
920  case NAL_PPS:
921  pps_count += hvcc->array[i].numNalus;
922  break;
923  default:
924  break;
925  }
926  if (!vps_count || vps_count > MAX_VPS_COUNT ||
927  !sps_count || sps_count > MAX_SPS_COUNT ||
928  !pps_count || pps_count > MAX_PPS_COUNT)
929  return AVERROR_INVALIDDATA;
930 
931  /* unsigned int(8) configurationVersion = 1; */
932  avio_w8(pb, hvcc->configurationVersion);
933 
934  /*
935  * unsigned int(2) general_profile_space;
936  * unsigned int(1) general_tier_flag;
937  * unsigned int(5) general_profile_idc;
938  */
939  avio_w8(pb, hvcc->general_profile_space << 6 |
940  hvcc->general_tier_flag << 5 |
941  hvcc->general_profile_idc);
942 
943  /* unsigned int(32) general_profile_compatibility_flags; */
945 
946  /* unsigned int(48) general_constraint_indicator_flags; */
949 
950  /* unsigned int(8) general_level_idc; */
951  avio_w8(pb, hvcc->general_level_idc);
952 
953  /*
954  * bit(4) reserved = ‘1111’b;
955  * unsigned int(12) min_spatial_segmentation_idc;
956  */
957  avio_wb16(pb, hvcc->min_spatial_segmentation_idc | 0xf000);
958 
959  /*
960  * bit(6) reserved = ‘111111’b;
961  * unsigned int(2) parallelismType;
962  */
963  avio_w8(pb, hvcc->parallelismType | 0xfc);
964 
965  /*
966  * bit(6) reserved = ‘111111’b;
967  * unsigned int(2) chromaFormat;
968  */
969  avio_w8(pb, hvcc->chromaFormat | 0xfc);
970 
971  /*
972  * bit(5) reserved = ‘11111’b;
973  * unsigned int(3) bitDepthLumaMinus8;
974  */
975  avio_w8(pb, hvcc->bitDepthLumaMinus8 | 0xf8);
976 
977  /*
978  * bit(5) reserved = ‘11111’b;
979  * unsigned int(3) bitDepthChromaMinus8;
980  */
981  avio_w8(pb, hvcc->bitDepthChromaMinus8 | 0xf8);
982 
983  /* bit(16) avgFrameRate; */
984  avio_wb16(pb, hvcc->avgFrameRate);
985 
986  /*
987  * bit(2) constantFrameRate;
988  * bit(3) numTemporalLayers;
989  * bit(1) temporalIdNested;
990  * unsigned int(2) lengthSizeMinusOne;
991  */
992  avio_w8(pb, hvcc->constantFrameRate << 6 |
993  hvcc->numTemporalLayers << 3 |
994  hvcc->temporalIdNested << 2 |
995  hvcc->lengthSizeMinusOne);
996 
997  /* unsigned int(8) numOfArrays; */
998  avio_w8(pb, hvcc->numOfArrays);
999 
1000  for (i = 0; i < hvcc->numOfArrays; i++) {
1001  /*
1002  * bit(1) array_completeness;
1003  * unsigned int(1) reserved = 0;
1004  * unsigned int(6) NAL_unit_type;
1005  */
1006  avio_w8(pb, hvcc->array[i].array_completeness << 7 |
1007  hvcc->array[i].NAL_unit_type & 0x3f);
1008 
1009  /* unsigned int(16) numNalus; */
1010  avio_wb16(pb, hvcc->array[i].numNalus);
1011 
1012  for (j = 0; j < hvcc->array[i].numNalus; j++) {
1013  /* unsigned int(16) nalUnitLength; */
1014  avio_wb16(pb, hvcc->array[i].nalUnitLength[j]);
1015 
1016  /* bit(8*nalUnitLength) nalUnit; */
1017  avio_write(pb, hvcc->array[i].nalUnit[j],
1018  hvcc->array[i].nalUnitLength[j]);
1019  }
1020  }
1021 
1022  return 0;
1023 }
1024 
1025 int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in,
1026  int size, int filter_ps, int *ps_count)
1027 {
1028  int num_ps = 0, ret = 0;
1029  uint8_t *buf, *end, *start = NULL;
1030 
1031  if (!filter_ps) {
1032  ret = ff_avc_parse_nal_units(pb, buf_in, size);
1033  goto end;
1034  }
1035 
1036  ret = ff_avc_parse_nal_units_buf(buf_in, &start, &size);
1037  if (ret < 0)
1038  goto end;
1039 
1040  ret = 0;
1041  buf = start;
1042  end = start + size;
1043 
1044  while (end - buf > 4) {
1045  uint32_t len = FFMIN(AV_RB32(buf), end - buf - 4);
1046  uint8_t type = (buf[4] >> 1) & 0x3f;
1047 
1048  buf += 4;
1049 
1050  switch (type) {
1051  case NAL_VPS:
1052  case NAL_SPS:
1053  case NAL_PPS:
1054  num_ps++;
1055  break;
1056  default:
1057  ret += 4 + len;
1058  avio_wb32(pb, len);
1059  avio_write(pb, buf, len);
1060  break;
1061  }
1062 
1063  buf += len;
1064  }
1065 
1066 end:
1067  av_free(start);
1068  if (ps_count)
1069  *ps_count = num_ps;
1070  return ret;
1071 }
1072 
1073 int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out,
1074  int *size, int filter_ps, int *ps_count)
1075 {
1076  AVIOContext *pb;
1077  int ret;
1078 
1079  ret = avio_open_dyn_buf(&pb);
1080  if (ret < 0)
1081  return ret;
1082 
1083  ret = ff_hevc_annexb2mp4(pb, buf_in, *size, filter_ps, ps_count);
1084  *size = avio_close_dyn_buf(pb, buf_out);
1085 
1086  return ret;
1087 }
1088 
1090  int size, int ps_array_completeness)
1091 {
1092  int ret = 0;
1093  uint8_t *buf, *end, *start = NULL;
1095 
1096  hvcc_init(&hvcc);
1097 
1098  if (size < 6) {
1099  /* We can't write a valid hvcC from the provided data */
1100  ret = AVERROR_INVALIDDATA;
1101  goto end;
1102  } else if (*data == 1) {
1103  /* Data is already hvcC-formatted */
1104  avio_write(pb, data, size);
1105  goto end;
1106  } else if (!(AV_RB24(data) == 1 || AV_RB32(data) == 1)) {
1107  /* Not a valid Annex B start code prefix */
1108  ret = AVERROR_INVALIDDATA;
1109  goto end;
1110  }
1111 
1112  ret = ff_avc_parse_nal_units_buf(data, &start, &size);
1113  if (ret < 0)
1114  goto end;
1115 
1116  buf = start;
1117  end = start + size;
1118 
1119  while (end - buf > 4) {
1120  uint32_t len = FFMIN(AV_RB32(buf), end - buf - 4);
1121  uint8_t type = (buf[4] >> 1) & 0x3f;
1122 
1123  buf += 4;
1124 
1125  switch (type) {
1126  case NAL_VPS:
1127  case NAL_SPS:
1128  case NAL_PPS:
1129  case NAL_SEI_PREFIX:
1130  case NAL_SEI_SUFFIX:
1131  ret = hvcc_add_nal_unit(buf, len, ps_array_completeness, &hvcc);
1132  if (ret < 0)
1133  goto end;
1134  break;
1135  default:
1136  break;
1137  }
1138 
1139  buf += len;
1140  }
1141 
1142  ret = hvcc_write(pb, &hvcc);
1143 
1144 end:
1145  hvcc_close(&hvcc);
1146  av_free(start);
1147  return ret;
1148 }
#define NULL
Definition: coverity.c:32
static int hvcc_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size, int ps_array_completeness, HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:739
Bytestream IO Context.
Definition: avio.h:111
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
Buffered I/O operations.
uint8_t tier_flag
Definition: hevc.c:63
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1125
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:260
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:217
#define MAX_PPS_COUNT
Definition: h264.h:50
uint8_t level_idc
Definition: hevc.c:67
HVCCNALUnitArray * array
Definition: hevc.c:58
uint8_t NAL_unit_type
Definition: hevc.c:33
uint16_t * nalUnitLength
Definition: hevc.c:35
uint64_t general_constraint_indicator_flags
Definition: hevc.c:45
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1113
static int hvcc_parse_vps(GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:361
Definition: h264.h:118
static int hvcc_parse_sps(GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:484
uint32_t general_profile_compatibility_flags
Definition: hevc.c:44
Definition: h264.h:119
uint8_t
#define av_malloc(s)
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:204
static int hvcc_parse_pps(GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:585
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
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:173
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:85
static void hvcc_parse_vui(GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc, unsigned int max_sub_layers_minus1)
Definition: hevc.c:276
bitstream reader API header.
ptrdiff_t size
Definition: opengl_enc.c:101
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:177
#define av_log(a,...)
uint32_t profile_compatibility_flags
Definition: hevc.c:65
static int hvcc_array_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size, uint8_t nal_type, int ps_array_completeness, HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:686
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:588
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
Definition: get_bits.h:357
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:213
#define AVERROR(e)
Definition: error.h:43
#define MAX_SHORT_TERM_RPS_COUNT
Definition: hevc.h:52
static void hvcc_init(HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:795
#define FFMAX(a, b)
Definition: common.h:64
int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
Definition: avc.c:92
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:1025
static void skip_scaling_list_data(GetBitContext *gb)
Definition: hevc.c:398
int ff_avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size)
Definition: avc.c:70
#define FFMIN(a, b)
Definition: common.h:66
static uint8_t * nal_unit_extract_rbsp(const uint8_t *src, uint32_t src_len, uint32_t *dst_len)
Definition: hevc.c:641
ret
Definition: avfilter.c:974
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:1073
#define MAX_SPS_COUNT
Definition: h264.h:49
static void skip_timing_info(GetBitContext *gb)
Definition: hevc.c:267
static void hvcc_parse_ptl(GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc, unsigned int max_sub_layers_minus1)
Definition: hevc.c:124
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:85
uint8_t profile_idc
Definition: hevc.c:64
static int get_se_golomb_long(GetBitContext *gb)
Definition: golomb.h:215
AVS_Value src
Definition: avisynth_c.h:482
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:85
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:441
#define MAX_VPS_COUNT
Definition: hevc.h:49
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:155
Definition: hevc.h:110
void * buf
Definition: avisynth_c.h:553
uint16_t numNalus
Definition: hevc.c:34
GLint GLenum type
Definition: opengl_enc.c:105
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:304
uint8_t ** nalUnit
Definition: hevc.c:36
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:329
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:297
int index
Definition: gxfenc.c:89
static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:829
#define MAX_SUB_LAYERS
7.4.2.1
Definition: hevc.h:48
uint8_t array_completeness
Definition: hevc.c:32
uint8_t profile_space
Definition: hevc.c:62
static int skip_hrd_parameters(GetBitContext *gb, uint8_t cprms_present_flag, unsigned int max_sub_layers_minus1)
Definition: hevc.c:192
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:337
static void hvcc_update_ptl(HEVCDecoderConfigurationRecord *hvcc, HVCCProfileTierLevel *ptl)
Definition: hevc.c:70
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:422
static void hvcc_close(HEVCDecoderConfigurationRecord *hvcc)
Definition: hevc.c:815
static void nal_unit_parse_header(GetBitContext *gb, uint8_t *nal_type)
Definition: hevc.c:673
static void skip_sub_layer_ordering_info(GetBitContext *gb)
Definition: hevc.c:354
#define av_free(p)
int len
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:326
#define av_freep(p)
void INT64 start
Definition: avisynth_c.h:553
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness)
Writes HEVC extradata (parameter sets, declarative SEI NAL units) to the provided AVIOContext...
Definition: hevc.c:1089
exp golomb vlc stuff
uint64_t constraint_indicator_flags
Definition: hevc.c:66
static int parse_rps(GetBitContext *gb, unsigned int rps_idx, unsigned int num_rps, unsigned int num_delta_pocs[MAX_SHORT_TERM_RPS_COUNT])
Definition: hevc.c:417
uint16_t min_spatial_segmentation_idc
Definition: hevc.c:47
#define MAX_SPATIAL_SEGMENTATION
Definition: hevc.c:29