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