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