5 #ifndef PACKAGER_MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_
6 #define PACKAGER_MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_
10 #include "packager/media/base/decrypt_config.h"
11 #include "packager/media/base/fourccs.h"
12 #include "packager/media/codecs/aac_audio_specific_config.h"
13 #include "packager/media/codecs/es_descriptor.h"
14 #include "packager/media/formats/mp4/box.h"
34 #define DECLARE_BOX_METHODS(T) \
39 FourCC BoxType() const override; \
42 bool ReadWriteInternal(BoxBuffer* buffer) override; \
43 size_t ComputeSizeInternal() override; \
50 FourCC major_brand = FOURCC_NULL;
51 uint32_t minor_version = 0;
52 std::vector<FourCC> compatible_brands;
56 FourCC
BoxType()
const override;
62 std::vector<uint8_t> raw_box;
68 std::vector<uint64_t> offsets;
74 uint8_t default_sample_info_size = 0;
75 uint32_t sample_count = 0;
76 std::vector<uint8_t> sample_info_sizes;
102 std::vector<uint8_t> initialization_vector;
103 std::vector<SubsampleEntry> subsamples;
107 static const uint8_t kInvalidIvSize = 1;
109 enum SampleEncryptionFlags {
110 kUseSubsampleEncryption = 2,
121 std::vector<SampleEncryptionEntry>* sample_encryption_entries)
const;
127 uint8_t iv_size = kInvalidIvSize;
128 std::vector<SampleEncryptionEntry> sample_encryption_entries;
134 FourCC format = FOURCC_NULL;
140 FourCC type = FOURCC_NULL;
141 uint32_t version = 0u;
147 uint8_t default_is_protected = 0;
148 uint8_t default_per_sample_iv_size = 0;
150 std::vector<uint8_t> default_kid = std::vector<uint8_t>(16, 0);
153 uint8_t default_crypt_byte_block = 0;
154 uint8_t default_skip_byte_block = 0;
158 std::vector<uint8_t> default_constant_iv;
178 uint64_t creation_time = 0;
179 uint64_t modification_time = 0;
180 uint32_t timescale = 0;
181 uint64_t duration = 0;
182 int32_t rate = 1 << 16;
183 int16_t volume = 1 << 8;
184 uint32_t next_track_id = 0;
188 enum TrackHeaderFlags {
189 kTrackEnabled = 0x000001,
190 kTrackInMovie = 0x000002,
191 kTrackInPreview = 0x000004,
196 uint64_t creation_time = 0;
197 uint64_t modification_time = 0;
198 uint32_t track_id = 0;
199 uint64_t duration = 0;
201 int16_t alternate_group = 0;
210 uint64_t segment_duration = 0;
211 int64_t media_time = 0;
212 int16_t media_rate_integer = 0;
213 int16_t media_rate_fraction = 0;
219 std::vector<EditListEntry> edits;
223 DECLARE_BOX_METHODS(
Edit);
231 FourCC handler_type = FOURCC_NULL;
236 uint32_t ComputeSize()
const;
243 DECLARE_BOX_METHODS(
ID3v2);
246 std::vector<uint8_t> id3v2_data;
265 FourCC box_type = FOURCC_NULL;
268 std::vector<uint8_t> data;
274 uint32_t h_spacing = 0u;
275 uint32_t v_spacing = 0u;
282 FourCC GetActualFormat()
const {
283 return format == FOURCC_encv ? sinf.format.format : format;
286 FourCC GetCodecConfigurationBoxType(FourCC format)
const;
289 std::vector<uint8_t> ExtraCodecConfigsAsVector()
const;
291 bool ParseExtraCodecConfigsVector(
const std::vector<uint8_t>& data);
293 FourCC format = FOURCC_NULL;
296 uint16_t data_reference_index = 1u;
298 uint16_t height = 0u;
305 std::vector<CodecConfiguration> extra_codec_configs;
318 uint32_t sampling_frequency = 0u;
319 uint32_t max_bitrate = 0u;
320 uint32_t avg_bitrate = 0u;
321 uint8_t pcm_sample_depth = 0u;
322 std::vector<uint8_t> extra_data;
328 std::vector<uint8_t> data;
334 std::vector<uint8_t> data;
340 std::vector<uint8_t> data;
346 std::vector<uint8_t> opus_identification_header;
348 uint16_t preskip = 0u;
357 std::vector<uint8_t> data;
364 FourCC GetActualFormat()
const {
365 return format == FOURCC_enca ? sinf.format.format : format;
368 FourCC format = FOURCC_NULL;
371 uint16_t data_reference_index = 1u;
372 uint16_t channelcount = 2u;
373 uint16_t samplesize = 16u;
374 uint32_t samplerate = 0u;
396 std::string source_label;
405 FourCC format = FOURCC_NULL;
409 uint16_t data_reference_index = 1u;
412 std::string namespace_;
413 std::string schema_location;
425 TrackType type = kInvalid;
428 std::vector<VideoSampleEntry> video_entries;
429 std::vector<AudioSampleEntry> audio_entries;
430 std::vector<TextSampleEntry> text_entries;
434 uint32_t sample_count;
435 uint32_t sample_delta;
442 std::vector<DecodingTime> decoding_time;
446 uint32_t sample_count;
450 int64_t sample_offset;
457 std::vector<CompositionOffset> composition_offset;
461 uint32_t first_chunk;
462 uint32_t samples_per_chunk;
463 uint32_t sample_description_index;
470 std::vector<ChunkInfo> chunk_info;
477 uint32_t sample_size = 0u;
478 uint32_t sample_count = 0u;
479 std::vector<uint32_t> sizes;
486 uint8_t field_size = 0u;
487 std::vector<uint32_t> sizes;
494 std::vector<uint64_t> offsets;
506 std::vector<uint32_t> sample_number;
511 uint32_t ComputeSize()
const;
513 uint8_t is_protected = 0u;
514 uint8_t per_sample_iv_size = 0u;
515 std::vector<uint8_t> key_id;
518 uint8_t crypt_byte_block = 0u;
519 uint8_t skip_byte_block = 0u;
522 std::vector<uint8_t> constant_iv;
527 uint32_t ComputeSize()
const;
529 int16_t roll_distance = 0;
535 template <
typename T>
536 bool ReadWriteEntries(
BoxBuffer* buffer, std::vector<T>* entries);
538 uint32_t grouping_type = 0;
540 std::vector<CencSampleEncryptionInfoEntry>
541 cenc_sample_encryption_info_entries;
543 std::vector<AudioRollRecoveryEntry> audio_roll_recovery_entries;
547 enum GroupDescriptionIndexBase {
548 kTrackGroupDescriptionIndexBase = 0,
549 kTrackFragmentGroupDescriptionIndexBase = 0x10000,
552 uint32_t sample_count = 0u;
553 uint32_t group_description_index = 0u;
559 uint32_t grouping_type = 0u;
560 uint32_t grouping_type_parameter = 0u;
561 std::vector<SampleToGroupEntry> entries;
577 std::vector<SampleGroupDescription> sample_group_descriptions;
578 std::vector<SampleToGroup> sample_to_groups;
584 uint64_t creation_time = 0u;
585 uint64_t modification_time = 0u;
586 uint32_t timescale = 0u;
587 uint64_t duration = 0u;
594 uint16_t graphicsmode = 0u;
595 uint16_t opcolor_red = 0u;
596 uint16_t opcolor_green = 0u;
597 uint16_t opcolor_blue = 0u;
603 uint16_t balance = 0u;
617 std::vector<uint8_t> location;
624 std::vector<DataEntryUrl> data_entry = std::vector<DataEntryUrl>(1);
646 DECLARE_BOX_METHODS(
Media);
654 DECLARE_BOX_METHODS(
Track);
665 uint64_t fragment_duration = 0u;
671 uint32_t track_id = 0u;
672 uint32_t default_sample_description_index = 0u;
673 uint32_t default_sample_duration = 0u;
674 uint32_t default_sample_size = 0u;
675 uint32_t default_sample_flags = 0u;
682 std::vector<TrackExtends> tracks;
686 DECLARE_BOX_METHODS(
Movie);
691 std::vector<Track> tracks;
692 std::vector<ProtectionSystemSpecificHeader> pssh;
698 uint64_t decode_time = 0u;
704 uint32_t sequence_number = 0u;
708 enum TrackFragmentFlagsMasks {
709 kBaseDataOffsetPresentMask = 0x000001,
710 kSampleDescriptionIndexPresentMask = 0x000002,
711 kDefaultSampleDurationPresentMask = 0x000008,
712 kDefaultSampleSizePresentMask = 0x000010,
713 kDefaultSampleFlagsPresentMask = 0x000020,
714 kDurationIsEmptyMask = 0x010000,
715 kDefaultBaseIsMoofMask = 0x020000,
718 enum SampleFlagsMasks {
719 kReservedMask = 0xFC000000,
720 kSampleDependsOnMask = 0x03000000,
721 kSampleIsDependedOnMask = 0x00C00000,
722 kSampleHasRedundancyMask = 0x00300000,
723 kSamplePaddingValueMask = 0x000E0000,
724 kNonKeySampleMask = 0x00010000,
725 kSampleDegradationPriorityMask = 0x0000FFFF,
730 uint32_t track_id = 0u;
731 uint32_t sample_description_index = 0u;
732 uint32_t default_sample_duration = 0u;
733 uint32_t default_sample_size = 0u;
734 uint32_t default_sample_flags = 0u;
738 enum TrackFragmentFlagsMasks {
739 kDataOffsetPresentMask = 0x000001,
740 kFirstSampleFlagsPresentMask = 0x000004,
741 kSampleDurationPresentMask = 0x000100,
742 kSampleSizePresentMask = 0x000200,
743 kSampleFlagsPresentMask = 0x000400,
744 kSampleCompTimeOffsetsPresentMask = 0x000800,
749 uint32_t sample_count = 0u;
750 uint32_t data_offset = 0u;
751 std::vector<uint32_t> sample_flags;
752 std::vector<uint32_t> sample_sizes;
753 std::vector<uint32_t> sample_durations;
754 std::vector<int64_t> sample_composition_time_offsets;
761 std::vector<TrackFragmentRun> runs;
762 bool decode_time_absent =
false;
764 std::vector<SampleGroupDescription> sample_group_descriptions;
765 std::vector<SampleToGroup> sample_to_groups;
775 std::vector<TrackFragment> tracks;
776 std::vector<ProtectionSystemSpecificHeader> pssh;
790 bool reference_type =
false;
791 uint32_t referenced_size = 0u;
792 uint32_t subsegment_duration = 0u;
793 bool starts_with_sap =
false;
794 SAPType sap_type = TypeUnknown;
795 uint32_t sap_delta_time = 0u;
798 uint64_t earliest_presentation_time = 0u;
804 uint32_t reference_id = 0u;
805 uint32_t timescale = 0u;
806 uint64_t earliest_presentation_time = 0u;
807 uint64_t first_offset = 0u;
808 std::vector<SegmentReference> references;
815 uint32_t data_size = 0u;
820 const int kCueSourceIdNotSet = -1;
825 int32_t source_id = kCueSourceIdNotSet;
831 std::string cue_current_time;
843 std::string settings;
849 std::string cue_text;
859 std::string cue_additional_text;
878 #endif // PACKAGER_MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_