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