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
31
32 #define MAX_SPATIAL_SEGMENTATION 4096 // max. value of u(12) field
33
34 enum {
41 };
42
43
44 #define FLAG_ARRAY_COMPLETENESS (1 << 0)
45 #define FLAG_IS_NALFF (1 << 1)
46 #define FLAG_IS_LHVC (1 << 2)
47
53
54 // VPS
57
64
85
88
97
100 {
101 /*
102 * The value of general_profile_space in all the parameter sets must be
103 * identical.
104 */
106
107 /*
108 * The level indication general_level_idc must indicate a level of
109 * capability equal to or greater than the highest level indicated for the
110 * highest tier in all the parameter sets.
111 */
114 else
116
117 /*
118 * The tier indication general_tier_flag must indicate a tier equal to or
119 * greater than the highest tier indicated in all the parameter sets.
120 */
122
123 /*
124 * The profile indication general_profile_idc must indicate a profile to
125 * which the stream associated with this configuration record conforms.
126 *
127 * If the sequence parameter sets are marked with different profiles, then
128 * the stream may need examination to determine which profile, if any, the
129 * entire stream conforms to. If the entire stream is not examined, or the
130 * examination reveals that there is no profile to which the entire stream
131 * conforms, then the entire stream must be split into two or more
132 * sub-streams with separate configuration records in which these rules can
133 * be met.
134 *
135 * Note: set the profile to the highest value for the sake of simplicity.
136 */
138
139 /*
140 * Each bit in general_profile_compatibility_flags may only be set if all
141 * the parameter sets set that bit.
142 */
144
145 /*
146 * Each bit in general_constraint_indicator_flags may only be set if all
147 * the parameter sets set that bit.
148 */
150 }
151
154 int profile_present_flag,
155 unsigned int max_sub_layers_minus1)
156 {
161
162 if (profile_present_flag) {
170 } else
172
173 for (
i = 0;
i < max_sub_layers_minus1;
i++) {
174 sub_layer_profile_present_flag[
i] =
get_bits1(gb);
175 sub_layer_level_present_flag[
i] =
get_bits1(gb);
176 }
177
178 if (max_sub_layers_minus1 > 0)
179 for (
i = max_sub_layers_minus1;
i < 8;
i++)
180 skip_bits(gb, 2);
// reserved_zero_2bits[i]
181
182 for (
i = 0;
i < max_sub_layers_minus1;
i++) {
183 if (sub_layer_profile_present_flag[
i]) {
184 /*
185 * sub_layer_profile_space[i] u(2)
186 * sub_layer_tier_flag[i] u(1)
187 * sub_layer_profile_idc[i] u(5)
188 * sub_layer_profile_compatibility_flag[i][0..31] u(32)
189 * sub_layer_progressive_source_flag[i] u(1)
190 * sub_layer_interlaced_source_flag[i] u(1)
191 * sub_layer_non_packed_constraint_flag[i] u(1)
192 * sub_layer_frame_only_constraint_flag[i] u(1)
193 * sub_layer_reserved_zero_44bits[i] u(44)
194 */
198 }
199
200 if (sub_layer_level_present_flag[
i])
202 }
203 }
204
206 unsigned int cpb_cnt_minus1,
207 uint8_t sub_pic_hrd_params_present_flag)
208 {
210
211 for (
i = 0;
i <= cpb_cnt_minus1;
i++) {
214
215 if (sub_pic_hrd_params_present_flag) {
218 }
219
221 }
222 }
223
225 unsigned int max_sub_layers_minus1)
226 {
228 uint8_t sub_pic_hrd_params_present_flag = 0;
229 uint8_t nal_hrd_parameters_present_flag = 0;
230 uint8_t vcl_hrd_parameters_present_flag = 0;
231
232 if (cprms_present_flag) {
233 nal_hrd_parameters_present_flag =
get_bits1(gb);
234 vcl_hrd_parameters_present_flag =
get_bits1(gb);
235
236 if (nal_hrd_parameters_present_flag ||
237 vcl_hrd_parameters_present_flag) {
238 sub_pic_hrd_params_present_flag =
get_bits1(gb);
239
240 if (sub_pic_hrd_params_present_flag)
241 /*
242 * tick_divisor_minus2 u(8)
243 * du_cpb_removal_delay_increment_length_minus1 u(5)
244 * sub_pic_cpb_params_in_pic_timing_sei_flag u(1)
245 * dpb_output_delay_du_length_minus1 u(5)
246 */
248
249 /*
250 * bit_rate_scale u(4)
251 * cpb_size_scale u(4)
252 */
254
255 if (sub_pic_hrd_params_present_flag)
257
258 /*
259 * initial_cpb_removal_delay_length_minus1 u(5)
260 * au_cpb_removal_delay_length_minus1 u(5)
261 * dpb_output_delay_length_minus1 u(5)
262 */
264 }
265 }
266
267 for (
i = 0;
i <= max_sub_layers_minus1;
i++) {
268 unsigned int cpb_cnt_minus1 = 0;
269 uint8_t low_delay_hrd_flag = 0;
270 uint8_t fixed_pic_rate_within_cvs_flag = 0;
271 uint8_t fixed_pic_rate_general_flag =
get_bits1(gb);
272
273 if (!fixed_pic_rate_general_flag)
274 fixed_pic_rate_within_cvs_flag =
get_bits1(gb);
275
276 if (fixed_pic_rate_within_cvs_flag)
278 else
280
281 if (!low_delay_hrd_flag) {
283 if (cpb_cnt_minus1 > 31)
285 }
286
287 if (nal_hrd_parameters_present_flag)
289 sub_pic_hrd_params_present_flag);
290
291 if (vcl_hrd_parameters_present_flag)
293 sub_pic_hrd_params_present_flag);
294 }
295
296 return 0;
297 }
298
300 {
303
304 if (
get_bits1(gb))
// poc_proportional_to_timing_flag
306 }
307
310 unsigned int max_sub_layers_minus1)
311 {
312 unsigned int min_spatial_segmentation_idc;
313
314 if (
get_bits1(gb))
// aspect_ratio_info_present_flag
315 if (
get_bits(gb, 8) == 255)
// aspect_ratio_idc
317
318 if (
get_bits1(gb))
// overscan_info_present_flag
320
321 if (
get_bits1(gb)) {
// video_signal_type_present_flag
322 skip_bits(gb, 4);
// video_format u(3), video_full_range_flag u(1)
323
324 if (
get_bits1(gb))
// colour_description_present_flag
325 /*
326 * colour_primaries u(8)
327 * transfer_characteristics u(8)
328 * matrix_coeffs u(8)
329 */
331 }
332
333 if (
get_bits1(gb)) {
// chroma_loc_info_present_flag
336 }
337
338 /*
339 * neutral_chroma_indication_flag u(1)
340 * field_seq_flag u(1)
341 * frame_field_info_present_flag u(1)
342 */
344
345 if (
get_bits1(gb)) {
// default_display_window_flag
350 }
351
352 if (
get_bits1(gb)) {
// vui_timing_info_present_flag
354
355 if (
get_bits1(gb))
// vui_hrd_parameters_present_flag
357 }
358
359 if (
get_bits1(gb)) {
// bitstream_restriction_flag
360 /*
361 * tiles_fixed_structure_flag u(1)
362 * motion_vectors_over_pic_boundaries_flag u(1)
363 * restricted_ref_pic_lists_flag u(1)
364 */
366
368
369 /*
370 * unsigned int(12) min_spatial_segmentation_idc;
371 *
372 * The min_spatial_segmentation_idc indication must indicate a level of
373 * spatial segmentation equal to or less than the lowest level of
374 * spatial segmentation indicated in all the parameter sets.
375 */
377 min_spatial_segmentation_idc);
378
383 }
384 }
385
387 {
391 }
392
395 uint8_t vps_max_layers_minus1,
396 uint8_t vps_base_layer_internal_flag)
397 {
398 uint8_t num_scalability_types = 0;
399 uint8_t max_layers_minus_1 =
FFMIN(62, vps_max_layers_minus1);
400 uint8_t splitting_flag, vps_nuh_layer_id_present_flag;
401 uint8_t scalability_mask_flag[16] = { 0 };
402 uint8_t dimension_id_len[16] = { 0 };
403 uint8_t layer_id_in_nuh[64] = { 0 };
405
406 if (vps_max_layers_minus1 > 0 && vps_base_layer_internal_flag)
408
410
411 for (
i = 0;
i < 16;
i++)
413 scalability_mask_flag[num_scalability_types++] =
i;
414
415 for (j = 0; j < (num_scalability_types - splitting_flag); j++)
416 dimension_id_len[j] =
get_bits(gb, 3) + 1;
417
418 vps_nuh_layer_id_present_flag =
get_bits(gb, 1);
419
420 for (
i = 1;
i <= max_layers_minus_1;
i++) {
421 if (vps_nuh_layer_id_present_flag)
423 else
424 layer_id_in_nuh[
i] =
i;
425
426 if (!splitting_flag) {
427 for (j = 0; j < num_scalability_types; j++) {
428 int dimension_id =
get_bits(gb, dimension_id_len[j]);
429
430 if (dimension_id == 1 /* AUX_ALPHA */ && scalability_mask_flag[j] == 3 /* AuxId */)
432 }
433 }
434 }
435
436 if (splitting_flag) {
437 uint8_t dim_bit_offset[17] = { 0 };
438
439 dim_bit_offset[0] = 0;
440 for (j = 1; j < num_scalability_types; j++)
441 dim_bit_offset[j] = dim_bit_offset[j-1] + dimension_id_len[j-1];
442 dim_bit_offset[num_scalability_types] = 6;
443
444 if (num_scalability_types > 0 && dim_bit_offset[num_scalability_types - 1] >= 6)
445 return -1; // invalid bitstream
446
447 for (
i = 1;
i <= max_layers_minus_1;
i++) {
448 for (j = 0; j < num_scalability_types; j++) {
449 int dimension_id = (layer_id_in_nuh[
i] & ((1 << dim_bit_offset[j+1]) - 1)) >> dim_bit_offset[j];
450
451 if (dimension_id == 1 /* AUX_ALPHA */ && scalability_mask_flag[j] == 3 /* AuxId */)
453 }
454 }
455 }
456
457 return 0;
458 }
459
462 {
463 uint8_t vps_base_layer_internal_flag, vps_max_layers_minus1;
464 uint8_t vps_sub_layer_ordering_info_present_flag, vps_max_layer_id;
465 int vps_num_layer_sets_minus1;
467
469
470 vps_base_layer_internal_flag =
get_bits(gb, 1);
471 skip_bits(gb, 1);
// vps_base_layer_available_flag
472 vps_max_layers_minus1 =
get_bits(gb, 6);
473
475
476 /*
477 * numTemporalLayers greater than 1 indicates that the stream to which this
478 * configuration record applies is temporally scalable and the contained
479 * number of temporal layers (also referred to as temporal sub-layer or
480 * sub-layer in ISO/IEC 23008-2) is equal to numTemporalLayers. Value 1
481 * indicates that the stream is not temporally scalable. Value 0 indicates
482 * that it is unknown whether the stream is temporally scalable.
483 */
486
487 /*
488 * vps_temporal_id_nesting_flag u(1)
489 * vps_reserved_0xffff_16bits u(16)
490 */
492
494
495 vps_sub_layer_ordering_info_present_flag =
get_bits(gb, 1);
497 i <= nal->vps_max_sub_layers_minus1;
i++) {
501 }
502
505 skip_bits_long(gb, (vps_max_layer_id + 1) * vps_num_layer_sets_minus1);
// layer_id_included_flag[i][j]
506
507 if (
get_bits(gb, 1)) {
// vps_timing_info_present_flag
508 int vps_num_hrd_parameters;
509
511
512 if (
get_bits(gb, 1))
// vps_poc_proportional_to_timing_flag
514
515 vps_num_hrd_parameters =
get_ue_golomb(gb);
// vps_num_hrd_parameters
516
517 for (
i = 0;
i < vps_num_hrd_parameters;
i++) {
518 int cprms_present_flag;
519
522 cprms_present_flag =
get_bits(gb, 1);
523 else
524 cprms_present_flag = 1;
525
527 }
528 }
529
530 if (
get_bits(gb, 1)) {
// vps_extension_flag
533 vps_max_layers_minus1,
534 vps_base_layer_internal_flag) < 0)
535 return 0;
536 }
537
538 /* nothing useful for hvcC past this point */
539 return 0;
540 }
541
543 {
544 int i, j, k, num_coeffs;
545
546 for (
i = 0;
i < 4;
i++)
547 for (j = 0; j < (
i == 3 ? 2 : 6); j++)
548 if (!
get_bits1(gb))
// scaling_list_pred_mode_flag[i][j]
550 else {
551 num_coeffs =
FFMIN(64, 1 << (4 + (
i << 1)));
552
555
556 for (k = 0; k < num_coeffs; k++)
558 }
559 }
560
562 unsigned int num_rps,
564 {
566
567 if (rps_idx &&
get_bits1(gb)) {
// inter_ref_pic_set_prediction_flag
568 /* this should only happen for slice headers, and this isn't one */
569 if (rps_idx >= num_rps)
571
574
575 num_delta_pocs[rps_idx] = 0;
576
577 /*
578 * From libavcodec/hevc_ps.c:
579 *
580 * if (is_slice_header) {
581 * //foo
582 * } else
583 * rps_ridx = &sps->st_rps[rps - sps->st_rps - 1];
584 *
585 * where:
586 * rps: &sps->st_rps[rps_idx]
587 * sps->st_rps: &sps->st_rps[0]
588 * is_slice_header: rps_idx == num_rps
589 *
590 * thus:
591 * if (num_rps != rps_idx)
592 * rps_ridx = &sps->st_rps[rps_idx - 1];
593 *
594 * NumDeltaPocs[RefRpsIdx]: num_delta_pocs[rps_idx - 1]
595 */
596 for (
i = 0;
i <= num_delta_pocs[rps_idx - 1];
i++) {
597 uint8_t use_delta_flag = 0;
598 uint8_t used_by_curr_pic_flag =
get_bits1(gb);
599 if (!used_by_curr_pic_flag)
601
602 if (used_by_curr_pic_flag || use_delta_flag)
603 num_delta_pocs[rps_idx]++;
604 }
605 } else {
608
609 if ((num_positive_pics + (uint64_t)num_negative_pics) * 2 >
get_bits_left(gb))
611
612 num_delta_pocs[rps_idx] = num_negative_pics + num_positive_pics;
613
614 for (
i = 0;
i < num_negative_pics;
i++) {
616 skip_bits1 (gb);
// used_by_curr_pic_s0_flag[rps_idx]
617 }
618
619 for (
i = 0;
i < num_positive_pics;
i++) {
621 skip_bits1 (gb);
// used_by_curr_pic_s1_flag[rps_idx]
622 }
623 }
624
625 return 0;
626 }
627
630 {
631 unsigned int i, sps_max_sub_layers_minus1, log2_max_pic_order_cnt_lsb_minus4;
633 unsigned int sps_ext_or_max_sub_layers_minus1, multi_layer_ext_sps_flag;
634
635 unsigned int sps_video_parameter_set_id =
get_bits(gb, 4);
636
638 sps_ext_or_max_sub_layers_minus1 = 0;
639 sps_max_sub_layers_minus1 =
get_bits(gb, 3);
640 } else {
641 sps_ext_or_max_sub_layers_minus1 =
get_bits(gb, 3);
642 if (sps_ext_or_max_sub_layers_minus1 == 7) {
645
646 for (
i = 0;
i <
array->numNalus;
i++)
647 if (sps_video_parameter_set_id ==
array->nal[
i].parameter_set_id) {
649 break;
650 }
653
654 sps_max_sub_layers_minus1 =
vps->vps_max_sub_layers_minus1;
655 } else
656 sps_max_sub_layers_minus1 = sps_ext_or_max_sub_layers_minus1;
657 }
659 sps_ext_or_max_sub_layers_minus1 == 7;
660
661 /*
662 * numTemporalLayers greater than 1 indicates that the stream to which this
663 * configuration record applies is temporally scalable and the contained
664 * number of temporal layers (also referred to as temporal sub-layer or
665 * sub-layer in ISO/IEC 23008-2) is equal to numTemporalLayers. Value 1
666 * indicates that the stream is not temporally scalable. Value 0 indicates
667 * that it is unknown whether the stream is temporally scalable.
668 */
670 sps_max_sub_layers_minus1 + 1);
671
672 if (!multi_layer_ext_sps_flag) {
675 }
676
678
679 if (multi_layer_ext_sps_flag) {
680 if (
get_bits1(gb))
// update_rep_format_flag
682 } else {
684
687
690
691 if (
get_bits1(gb)) {
// conformance_window_flag
696 }
697
700 }
702
703 if (!multi_layer_ext_sps_flag) {
704 /* sps_sub_layer_ordering_info_present_flag */
705 i =
get_bits1(gb) ? 0 : sps_max_sub_layers_minus1;
706 for (;
i <= sps_max_sub_layers_minus1;
i++)
708 }
709
716
717 if (
get_bits1(gb)) {
// scaling_list_enabled_flag
718 int sps_infer_scaling_list_flag = 0;
719 if (multi_layer_ext_sps_flag)
720 sps_infer_scaling_list_flag =
get_bits1(gb);
721 if (sps_infer_scaling_list_flag)
722 skip_bits(gb, 6);
// sps_scaling_list_ref_layer_id
723 else if (
get_bits1(gb))
// sps_scaling_list_data_present_flag
725 }
726
728 skip_bits1(gb);
// sample_adaptive_offset_enabled_flag
729
731 skip_bits (gb, 4);
// pcm_sample_bit_depth_luma_minus1
732 skip_bits (gb, 4);
// pcm_sample_bit_depth_chroma_minus1
735 skip_bits1 (gb);
// pcm_loop_filter_disabled_flag
736 }
737
741
742 for (
i = 0;
i < num_short_term_ref_pic_sets;
i++) {
743 int ret =
parse_rps(gb,
i, num_short_term_ref_pic_sets, num_delta_pocs);
746 }
747
748 if (
get_bits1(gb)) {
// long_term_ref_pics_present_flag
750 if (num_long_term_ref_pics_sps > 31
U)
752 for (
i = 0;
i < num_long_term_ref_pics_sps;
i++) {
// num_long_term_ref_pics_sps
753 int len =
FFMIN(log2_max_pic_order_cnt_lsb_minus4 + 4, 16);
755 skip_bits1(gb);
// used_by_curr_pic_lt_sps_flag[i]
756 }
757 }
758
759 skip_bits1(gb);
// sps_temporal_mvp_enabled_flag
760 skip_bits1(gb);
// strong_intra_smoothing_enabled_flag
761
762 if (
get_bits1(gb))
// vui_parameters_present_flag
764
765 /* nothing useful for hvcC past this point */
766 return 0;
767 }
768
771 {
772 uint8_t tiles_enabled_flag, entropy_coding_sync_enabled_flag;
773
776
777 /*
778 * dependent_slice_segments_enabled_flag u(1)
779 * output_flag_present_flag u(1)
780 * num_extra_slice_header_bits u(3)
781 * sign_data_hiding_enabled_flag u(1)
782 * cabac_init_present_flag u(1)
783 */
785
789
790 /*
791 * constrained_intra_pred_flag u(1)
792 * transform_skip_enabled_flag u(1)
793 */
795
796 if (
get_bits1(gb))
// cu_qp_delta_enabled_flag
798
801
802 /*
803 * pps_slice_chroma_qp_offsets_present_flag u(1)
804 * weighted_pred_flag u(1)
805 * weighted_bipred_flag u(1)
806 * transquant_bypass_enabled_flag u(1)
807 */
809
811 entropy_coding_sync_enabled_flag =
get_bits1(gb);
812
813 if (entropy_coding_sync_enabled_flag && tiles_enabled_flag)
815 else if (entropy_coding_sync_enabled_flag)
817 else if (tiles_enabled_flag)
819 else
821
822 /* nothing useful for hvcC past this point */
823 return 0;
824 }
825
827 uint8_t *nuh_layer_id)
828 {
830
833
834 /*
835 * nuh_temporal_id_plus1 u(3)
836 */
838 }
839
842 {
845 uint16_t numNalus =
array->numNalus;
846
850
851 nal = &
array->nal[numNalus];
855
856 return 0;
857 }
858
861 int flags,
unsigned array_idx)
862 {
870 uint8_t nal_type, nuh_layer_id;
871 uint8_t *rbsp_buf;
872 uint32_t rbsp_size;
873
875 if (!rbsp_buf) {
877 goto end;
878 }
879
882 goto end;
883
886 goto end;
887
888 /*
889 * Note: only 'declarative' SEI messages are allowed in
890 * hvcC. Perhaps the SEI playload type should be checked
891 * and non-declarative SEI messages discarded?
892 */
895 goto end;
896 if (
array->numNalus == 1) {
898 array->NAL_unit_type = nal_type;
899
900 /*
901 * When the sample entry name is ‘hvc1’, the default and mandatory value of
902 * array_completeness is 1 for arrays of all types of parameter sets, and 0
903 * for all other arrays. When the sample entry name is ‘hev1’, the default
904 * value of array_completeness is 0 for all arrays.
905 */
908 array->array_completeness = ps_array_completeness;
909 }
910
913
914 /* Don't parse parameter sets. We already have the needed information*/
915 if (is_nalff)
916 goto end;
917
925 goto end;
926
927 end:
930 }
931
933 {
937
938 /*
939 * The following fields have all their valid bits set by default,
940 * the ProfileTierLevel parsing code will unset them when needed.
941 */
944
945 /*
946 * Initialize this field with an invalid value which can be used to detect
947 * whether we didn't see any VUI (in which case it should be reset to zero).
948 */
950 }
951
953 {
958 }
959 }
960
963 {
966 int numOfArrays = 0;
967
968 /*
969 * We only support writing HEVCDecoderConfigurationRecord version 1.
970 */
972
973 /*
974 * If min_spatial_segmentation_idc is invalid, reset to 0 (unspecified).
975 */
978
979 /*
980 * parallelismType indicates the type of parallelism that is used to meet
981 * the restrictions imposed by min_spatial_segmentation_idc when the value
982 * of min_spatial_segmentation_idc is greater than 0.
983 */
986
987 /*
988 * It's unclear how to properly compute these fields, so
989 * let's always set them to values meaning 'unspecified'.
990 */
992 /*
993 * lhvC doesn't store this field. It instead reserves the bits, setting them
994 * to '11'b.
995 */
997
998 /*
999 * Skip all NALUs with nuh_layer_id == 0 if writing lhvC. We do it here and
1000 * not before parsing them as some parameter sets with nuh_layer_id > 0
1001 * may reference base layer parameters sets.
1002 */
1005
1006 if (
array->numNalus == 0)
1007 continue;
1008
1009 for (
unsigned j = 0; j <
array->numNalus; j++)
1010 numNalus[
i] += !is_lhvc || (
array->nal[j].nuh_layer_id != 0);
1011 numOfArrays += (numNalus[
i] > 0);
1012 }
1013
1017 if (!is_lhvc) {
1030 }
1035 if (!is_lhvc) {
1046 }
1054 numOfArrays);
1057
1058 if (numNalus[
i] == 0)
1059 continue;
1060
1062 j,
array->array_completeness);
1064 j,
array->NAL_unit_type);
1067 for (
unsigned k = 0; k <
array->numNalus; k++) {
1068 if (is_lhvc &&
array->nal[k].nuh_layer_id == 0)
1069 continue;
1070
1072 "nuh_layer_id[%u][%u]: %"PRIu8"\n",
1073 j, k,
array->nal[k].nuh_layer_id);
1075 "nalUnitLength[%u][%u]: %"PRIu16"\n",
1076 j, k,
array->nal[k].nalUnitLength);
1077 }
1078 j++;
1079 }
1080
1081 /*
1082 * We need at least one of each: VPS, SPS and PPS.
1083 */
1091
1092 /* unsigned int(8) configurationVersion = 1; */
1094
1095 if (!is_lhvc) {
1096 /*
1097 * unsigned int(2) general_profile_space;
1098 * unsigned int(1) general_tier_flag;
1099 * unsigned int(5) general_profile_idc;
1100 */
1104
1105 /* unsigned int(32) general_profile_compatibility_flags; */
1107
1108 /* unsigned int(48) general_constraint_indicator_flags; */
1111
1112 /* unsigned int(8) general_level_idc; */
1114 }
1115
1116 /*
1117 * bit(4) reserved = '1111'b;
1118 * unsigned int(12) min_spatial_segmentation_idc;
1119 */
1121
1122 /*
1123 * bit(6) reserved = '111111'b;
1124 * unsigned int(2) parallelismType;
1125 */
1127
1128 if (!is_lhvc) {
1129 /*
1130 * bit(6) reserved = '111111'b;
1131 * unsigned int(2) chromaFormat;
1132 */
1134
1135 /*
1136 * bit(5) reserved = '11111'b;
1137 * unsigned int(3) bitDepthLumaMinus8;
1138 */
1140
1141 /*
1142 * bit(5) reserved = '11111'b;
1143 * unsigned int(3) bitDepthChromaMinus8;
1144 */
1146
1147 /* bit(16) avgFrameRate; */
1149 }
1150
1151 /*
1152 * if (!is_lhvc)
1153 * bit(2) constantFrameRate;
1154 * else
1155 * bit(2) reserved = '11'b;
1156 * bit(3) numTemporalLayers;
1157 * bit(1) temporalIdNested;
1158 * unsigned int(2) lengthSizeMinusOne;
1159 */
1164
1165 /* unsigned int(8) numOfArrays; */
1167
1170
1172 continue;
1173 /*
1174 * bit(1) array_completeness;
1175 * unsigned int(1) reserved = 0;
1176 * unsigned int(6) NAL_unit_type;
1177 */
1179 array->NAL_unit_type & 0x3f);
1180
1181 /* unsigned int(16) numNalus; */
1183
1184 for (
unsigned j = 0; j <
array->numNalus; j++) {
1186
1188 continue;
1189
1190 /* unsigned int(16) nalUnitLength; */
1192
1193 /* bit(8*nalUnitLength) nalUnit; */
1195 }
1196 }
1197
1198 return 0;
1199 }
1200
1202 int size,
int filter_ps,
int *ps_count)
1203 {
1204 int num_ps = 0,
ret = 0;
1205 uint8_t *buf, *end, *start =
NULL;
1206
1207 if (!filter_ps) {
1209 goto end;
1210 }
1211
1214 goto end;
1215
1217 buf = start;
1219
1220 while (end - buf > 4) {
1222 uint8_t
type = (buf[4] >> 1) & 0x3f;
1223
1224 buf += 4;
1225
1230 num_ps++;
1231 break;
1232 default:
1236 break;
1237 }
1238
1240 }
1241
1242 end:
1244 if (ps_count)
1245 *ps_count = num_ps;
1247 }
1248
1250 int *
size,
int filter_ps,
int *ps_count)
1251 {
1254
1258
1263 }
1264
1266
1267 return 0;
1268 }
1269
1273 {
1275 static const uint8_t array_idx_to_type[] =
1278
1279 if (
type == array_idx_to_type[
i]) {
1283 break;
1284 }
1285 }
1286
1287 return 0;
1288 }
1289
1292 {
1294 uint8_t *buf, *end, *start =
NULL;
1296
1298 /* We can't write a valid hvcC from the provided data */
1300 }
else if (*
data == 1) {
1301 /* Data is already hvcC-formatted. Parse the arrays to skip any NALU
1302 with nuh_layer_id > 0 */
1304 int num_arrays;
1305
1308
1312
1314 skip_bits(&gbc, 8);
// hvcc.configurationVersion
1336
1338
1340 for (
int i = 0;
i < num_arrays;
i++) {
1341 int type, num_nalus;
1342
1346 for (int j = 0; j < num_nalus; j++) {
1348
1350 goto end;
1351
1355 goto end;
1356
1358 }
1359 }
1360
1362 goto end;
1364 /* Not a valid Annex B start code prefix */
1366 }
1367
1371
1373
1374 buf = start;
1376
1377 while (end - buf > 4) {
1379 uint8_t
type = (buf[4] >> 1) & 0x3f;
1380
1381 buf += 4;
1382
1385 goto end;
1386
1388 }
1389
1391
1392 end:
1396 }
1397
1399 int size,
int ps_array_completeness,
void *logctx)
1400 {
1403 }
1404
1406 int size,
int ps_array_completeness,
void *logctx)
1407 {
1410 }