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>* l_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 FourCC color_parameter_type = FOURCC_NULL;
275 uint16_t color_primaries = 1;
276 uint16_t transfer_characteristics = 1;
277 uint16_t matrix_coefficients = 1;
278 uint8_t video_full_range_flag = 0;
279 std::vector<uint8_t> raw_box;
285 uint32_t h_spacing = 0u;
286 uint32_t v_spacing = 0u;
293 FourCC GetActualFormat()
const {
294 return format == FOURCC_encv ? sinf.format.format : format;
297 FourCC GetCodecConfigurationBoxType(FourCC l_format)
const;
300 std::vector<uint8_t> ExtraCodecConfigsAsVector()
const;
302 bool ParseExtraCodecConfigsVector(
const std::vector<uint8_t>& data);
304 FourCC format = FOURCC_NULL;
307 uint16_t data_reference_index = 1u;
309 uint16_t height = 0u;
317 std::vector<CodecConfiguration> extra_codec_configs;
330 uint32_t sampling_frequency = 0u;
331 uint32_t max_bitrate = 0u;
332 uint32_t avg_bitrate = 0u;
333 uint8_t pcm_sample_depth = 0u;
334 std::vector<uint8_t> extra_data;
340 std::vector<uint8_t> data;
346 std::vector<uint8_t> data;
352 std::vector<uint8_t> data;
353 uint8_t mpeg_h_3da_profile_level_indication;
359 std::vector<uint8_t> data;
365 std::vector<uint8_t> data;
371 std::vector<uint8_t> opus_identification_header;
373 uint16_t preskip = 0u;
379 std::vector<uint8_t> data;
388 std::vector<uint8_t> data;
397 std::vector<uint8_t> data;
404 FourCC GetActualFormat()
const {
405 return format == FOURCC_enca ? sinf.format.format : format;
408 FourCC format = FOURCC_NULL;
411 uint16_t data_reference_index = 1u;
412 uint16_t channelcount = 2u;
413 uint16_t samplesize = 16u;
414 uint32_t samplerate = 0u;
440 std::string source_label;
449 FourCC format = FOURCC_NULL;
453 uint16_t data_reference_index = 1u;
456 std::string namespace_;
457 std::string schema_location;
469 TrackType type = kInvalid;
472 std::vector<VideoSampleEntry> video_entries;
473 std::vector<AudioSampleEntry> audio_entries;
474 std::vector<TextSampleEntry> text_entries;
478 uint32_t sample_count;
479 uint32_t sample_delta;
486 std::vector<DecodingTime> decoding_time;
490 uint32_t sample_count;
494 int64_t sample_offset;
501 std::vector<CompositionOffset> composition_offset;
505 uint32_t first_chunk;
506 uint32_t samples_per_chunk;
507 uint32_t sample_description_index;
514 std::vector<ChunkInfo> chunk_info;
521 uint32_t sample_size = 0u;
522 uint32_t sample_count = 0u;
523 std::vector<uint32_t> sizes;
530 uint8_t field_size = 0u;
531 std::vector<uint32_t> sizes;
538 std::vector<uint64_t> offsets;
550 std::vector<uint32_t> sample_number;
555 uint32_t ComputeSize()
const;
557 uint8_t is_protected = 0u;
558 uint8_t per_sample_iv_size = 0u;
559 std::vector<uint8_t> key_id;
562 uint8_t crypt_byte_block = 0u;
563 uint8_t skip_byte_block = 0u;
566 std::vector<uint8_t> constant_iv;
571 uint32_t ComputeSize()
const;
573 int16_t roll_distance = 0;
579 template <
typename T>
580 bool ReadWriteEntries(
BoxBuffer* buffer, std::vector<T>* entries);
582 uint32_t grouping_type = 0;
584 std::vector<CencSampleEncryptionInfoEntry>
585 cenc_sample_encryption_info_entries;
587 std::vector<AudioRollRecoveryEntry> audio_roll_recovery_entries;
591 enum GroupDescriptionIndexBase {
592 kTrackGroupDescriptionIndexBase = 0,
593 kTrackFragmentGroupDescriptionIndexBase = 0x10000,
596 uint32_t sample_count = 0u;
597 uint32_t group_description_index = 0u;
603 uint32_t grouping_type = 0u;
604 uint32_t grouping_type_parameter = 0u;
605 std::vector<SampleToGroupEntry> entries;
621 std::vector<SampleGroupDescription> sample_group_descriptions;
622 std::vector<SampleToGroup> sample_to_groups;
628 uint64_t creation_time = 0u;
629 uint64_t modification_time = 0u;
630 uint32_t timescale = 0u;
631 uint64_t duration = 0u;
638 uint16_t graphicsmode = 0u;
639 uint16_t opcolor_red = 0u;
640 uint16_t opcolor_green = 0u;
641 uint16_t opcolor_blue = 0u;
647 uint16_t balance = 0u;
661 std::vector<uint8_t> location;
668 std::vector<DataEntryUrl> data_entry = std::vector<DataEntryUrl>(1);
690 DECLARE_BOX_METHODS(
Media);
698 DECLARE_BOX_METHODS(
Track);
709 uint64_t fragment_duration = 0u;
715 uint32_t track_id = 0u;
716 uint32_t default_sample_description_index = 0u;
717 uint32_t default_sample_duration = 0u;
718 uint32_t default_sample_size = 0u;
719 uint32_t default_sample_flags = 0u;
726 std::vector<TrackExtends> tracks;
730 DECLARE_BOX_METHODS(
Movie);
735 std::vector<Track> tracks;
736 std::vector<ProtectionSystemSpecificHeader> pssh;
742 uint64_t decode_time = 0u;
748 uint32_t sequence_number = 0u;
752 enum TrackFragmentFlagsMasks {
753 kBaseDataOffsetPresentMask = 0x000001,
754 kSampleDescriptionIndexPresentMask = 0x000002,
755 kDefaultSampleDurationPresentMask = 0x000008,
756 kDefaultSampleSizePresentMask = 0x000010,
757 kDefaultSampleFlagsPresentMask = 0x000020,
758 kDurationIsEmptyMask = 0x010000,
759 kDefaultBaseIsMoofMask = 0x020000,
762 enum SampleFlagsMasks {
764 kReservedMask = 0xFC000000,
765 kSampleDependsOnMask = 0x03000000,
766 kSampleIsDependedOnMask = 0x00C00000,
767 kSampleHasRedundancyMask = 0x00300000,
768 kSamplePaddingValueMask = 0x000E0000,
769 kNonKeySampleMask = 0x00010000,
770 kSampleDegradationPriorityMask = 0x0000FFFF,
775 uint32_t track_id = 0u;
776 uint32_t sample_description_index = 0u;
777 uint32_t default_sample_duration = 0u;
778 uint32_t default_sample_size = 0u;
779 uint32_t default_sample_flags = 0u;
783 enum TrackFragmentFlagsMasks {
784 kDataOffsetPresentMask = 0x000001,
785 kFirstSampleFlagsPresentMask = 0x000004,
786 kSampleDurationPresentMask = 0x000100,
787 kSampleSizePresentMask = 0x000200,
788 kSampleFlagsPresentMask = 0x000400,
789 kSampleCompTimeOffsetsPresentMask = 0x000800,
794 uint32_t sample_count = 0u;
795 uint32_t data_offset = 0u;
796 std::vector<uint32_t> sample_flags;
797 std::vector<uint32_t> sample_sizes;
798 std::vector<uint32_t> sample_durations;
799 std::vector<int64_t> sample_composition_time_offsets;
806 std::vector<TrackFragmentRun> runs;
807 bool decode_time_absent =
false;
809 std::vector<SampleGroupDescription> sample_group_descriptions;
810 std::vector<SampleToGroup> sample_to_groups;
820 std::vector<TrackFragment> tracks;
821 std::vector<ProtectionSystemSpecificHeader> pssh;
835 bool reference_type =
false;
836 uint32_t referenced_size = 0u;
837 uint32_t subsegment_duration = 0u;
838 bool starts_with_sap =
false;
839 SAPType sap_type = TypeUnknown;
840 uint32_t sap_delta_time = 0u;
843 uint64_t earliest_presentation_time = 0u;
849 uint32_t reference_id = 0u;
850 uint32_t timescale = 0u;
851 uint64_t earliest_presentation_time = 0u;
852 uint64_t first_offset = 0u;
853 std::vector<SegmentReference> references;
860 uint32_t data_size = 0u;
865 const int kCueSourceIdNotSet = -1;
870 int32_t source_id = kCueSourceIdNotSet;
876 std::string cue_current_time;
888 std::string settings;
894 std::string cue_text;
904 std::string cue_additional_text;
All the methods that are virtual are virtual for mocking.
bool ParseFromBuffer(uint8_t iv_size, bool has_subsamples, BufferReader *reader)
bool ReadWrite(uint8_t iv_size, bool has_subsamples, BoxBuffer *buffer)
uint32_t GetTotalSizeOfSubsamples() const
uint32_t ComputeSize() const