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