Shaka Packager SDK
box_definitions.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PACKAGER_MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_
6 #define PACKAGER_MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_
7 
8 #include <vector>
9 
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>
15 
16 namespace shaka {
17 namespace media {
18 
19 class BufferReader;
20 
21 namespace mp4 {
22 
23 enum TrackType {
24  kInvalid = 0,
25  kVideo,
26  kAudio,
27  kHint,
28  kText,
29  kSubtitle,
30 };
31 
32 class BoxBuffer;
33 
34 #define DECLARE_BOX_METHODS(T) \
35  public: \
36  T(); \
37  ~T() override; \
38  \
39  FourCC BoxType() const override; \
40  \
41  private: \
42  bool ReadWriteInternal(BoxBuffer* buffer) override; \
43  size_t ComputeSizeInternal() override; \
44  \
45  public:
46 
47 struct FileType : Box {
48  DECLARE_BOX_METHODS(FileType);
49 
50  FourCC major_brand = FOURCC_NULL;
51  uint32_t minor_version = 0;
52  std::vector<FourCC> compatible_brands;
53 };
54 
56  FourCC BoxType() const override;
57 };
58 
60  DECLARE_BOX_METHODS(ProtectionSystemSpecificHeader);
61 
62  std::vector<uint8_t> raw_box;
63 };
64 
66  DECLARE_BOX_METHODS(SampleAuxiliaryInformationOffset);
67 
68  std::vector<uint64_t> offsets;
69 };
70 
72  DECLARE_BOX_METHODS(SampleAuxiliaryInformationSize);
73 
74  uint8_t default_sample_info_size = 0;
75  uint32_t sample_count = 0;
76  std::vector<uint8_t> sample_info_sizes;
77 };
78 
86  bool ReadWrite(uint8_t iv_size, bool has_subsamples, BoxBuffer* buffer);
93  bool ParseFromBuffer(uint8_t iv_size,
94  bool has_subsamples,
95  BufferReader* reader);
97  uint32_t ComputeSize() const;
100  uint32_t GetTotalSizeOfSubsamples() const;
101 
102  std::vector<uint8_t> initialization_vector;
103  std::vector<SubsampleEntry> subsamples;
104 };
105 
107  static const uint8_t kInvalidIvSize = 1;
108 
109  enum SampleEncryptionFlags {
110  kUseSubsampleEncryption = 2,
111  };
112 
113  DECLARE_BOX_METHODS(SampleEncryption);
120  uint8_t l_iv_size,
121  std::vector<SampleEncryptionEntry>* l_sample_encryption_entries) const;
122 
125  std::vector<uint8_t> sample_encryption_data;
126 
127  uint8_t iv_size = kInvalidIvSize;
128  std::vector<SampleEncryptionEntry> sample_encryption_entries;
129 };
130 
131 struct OriginalFormat : Box {
132  DECLARE_BOX_METHODS(OriginalFormat);
133 
134  FourCC format = FOURCC_NULL;
135 };
136 
137 struct SchemeType : FullBox {
138  DECLARE_BOX_METHODS(SchemeType);
139 
140  FourCC type = FOURCC_NULL;
141  uint32_t version = 0u;
142 };
143 
145  DECLARE_BOX_METHODS(TrackEncryption);
146 
147  uint8_t default_is_protected = 0;
148  uint8_t default_per_sample_iv_size = 0;
149  // Default to a vector of 16 zeros.
150  std::vector<uint8_t> default_kid = std::vector<uint8_t>(16, 0);
151 
152  // For pattern-based encryption.
153  uint8_t default_crypt_byte_block = 0;
154  uint8_t default_skip_byte_block = 0;
155 
156  // Present only if
157  // |default_is_protected == 1 && default_per_sample_iv_size == 0|.
158  std::vector<uint8_t> default_constant_iv;
159 };
160 
161 struct SchemeInfo : Box {
162  DECLARE_BOX_METHODS(SchemeInfo);
163 
164  TrackEncryption track_encryption;
165 };
166 
168  DECLARE_BOX_METHODS(ProtectionSchemeInfo);
169 
170  OriginalFormat format;
171  SchemeType type;
172  SchemeInfo info;
173 };
174 
176  DECLARE_BOX_METHODS(MovieHeader);
177 
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;
185 };
186 
188  enum TrackHeaderFlags {
189  kTrackEnabled = 0x000001,
190  kTrackInMovie = 0x000002,
191  kTrackInPreview = 0x000004,
192  };
193 
194  DECLARE_BOX_METHODS(TrackHeader);
195 
196  uint64_t creation_time = 0;
197  uint64_t modification_time = 0;
198  uint32_t track_id = 0;
199  uint64_t duration = 0;
200  int16_t layer = 0;
201  int16_t alternate_group = 0;
202  int16_t volume = -1;
203  // width and height specify the track's visual presentation size as
204  // fixed-point 16.16 values.
205  uint32_t width = 0;
206  uint32_t height = 0;
207 };
208 
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;
214 };
215 
216 struct EditList : FullBox {
217  DECLARE_BOX_METHODS(EditList);
218 
219  std::vector<EditListEntry> edits;
220 };
221 
222 struct Edit : Box {
223  DECLARE_BOX_METHODS(Edit);
224 
225  EditList list;
226 };
227 
229  DECLARE_BOX_METHODS(HandlerReference);
230 
231  FourCC handler_type = FOURCC_NULL;
232 };
233 
234 struct Language {
235  bool ReadWrite(BoxBuffer* buffer);
236  uint32_t ComputeSize() const;
237 
238  std::string code;
239 };
240 
242 struct ID3v2 : FullBox {
243  DECLARE_BOX_METHODS(ID3v2);
244 
245  Language language;
246  std::vector<uint8_t> id3v2_data;
247 };
248 
249 struct Metadata : FullBox {
250  DECLARE_BOX_METHODS(Metadata);
251 
252  HandlerReference handler;
253  ID3v2 id3v2;
254 };
255 
256 // This defines a common structure for various CodecConfiguration boxes:
257 // AVCConfiguration, HEVCConfiguration and VPCodecConfiguration.
258 // Note that unlike the other two CodecConfiguration boxes, VPCodecConfiguration
259 // box inherits from FullBox instead of Box, according to VP Codec ISO Media
260 // File Format Binding specification. It will be handled properly in the
261 // implementation.
263  DECLARE_BOX_METHODS(CodecConfiguration);
264 
265  FourCC box_type = FOURCC_NULL;
266  // Contains full codec configuration record, including possible extension
267  // boxes.
268  std::vector<uint8_t> data;
269 };
270 
272  DECLARE_BOX_METHODS(ColorParameters);
273 
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;
280 };
281 
283  DECLARE_BOX_METHODS(PixelAspectRatio);
284 
285  uint32_t h_spacing = 0u;
286  uint32_t v_spacing = 0u;
287 };
288 
290  DECLARE_BOX_METHODS(VideoSampleEntry);
291 
292  // Returns actual format of this sample entry.
293  FourCC GetActualFormat() const {
294  return format == FOURCC_encv ? sinf.format.format : format;
295  }
296  // Returns the box type of codec configuration box from video format.
297  FourCC GetCodecConfigurationBoxType(FourCC l_format) const;
298 
299  // Convert |extra_codec_configs| to vector.
300  std::vector<uint8_t> ExtraCodecConfigsAsVector() const;
301  // Parse |extra_codec_configs| from vector.
302  bool ParseExtraCodecConfigsVector(const std::vector<uint8_t>& data);
303 
304  FourCC format = FOURCC_NULL;
305  // data_reference_index is 1-based and "dref" box is mandatory so it is
306  // always present.
307  uint16_t data_reference_index = 1u;
308  uint16_t width = 0u;
309  uint16_t height = 0u;
310 
311  ColorParameters colr;
312  PixelAspectRatio pixel_aspect;
314  CodecConfiguration codec_configuration;
315  // Some codecs, e.g. Dolby Vision, have extra codec configuration boxes that
316  // need to be propagated to muxers.
317  std::vector<CodecConfiguration> extra_codec_configs;
318 };
319 
321  DECLARE_BOX_METHODS(ElementaryStreamDescriptor);
322 
323  AACAudioSpecificConfig aac_audio_specific_config;
324  ESDescriptor es_descriptor;
325 };
326 
327 struct DTSSpecific : Box {
328  DECLARE_BOX_METHODS(DTSSpecific);
329 
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;
335 };
336 
337 struct UDTSSpecific : Box {
338  DECLARE_BOX_METHODS(UDTSSpecific);
339 
340  std::vector<uint8_t> data;
341 };
342 
343 struct AC3Specific : Box {
344  DECLARE_BOX_METHODS(AC3Specific);
345 
346  std::vector<uint8_t> data;
347 };
348 
350  DECLARE_BOX_METHODS(MHAConfiguration);
351 
352  std::vector<uint8_t> data;
353  uint8_t mpeg_h_3da_profile_level_indication;
354 };
355 
356 struct EC3Specific : Box {
357  DECLARE_BOX_METHODS(EC3Specific);
358 
359  std::vector<uint8_t> data;
360 };
361 
362 struct AC4Specific : Box {
363  DECLARE_BOX_METHODS(AC4Specific);
364 
365  std::vector<uint8_t> data;
366 };
367 
368 struct OpusSpecific : Box {
369  DECLARE_BOX_METHODS(OpusSpecific);
370 
371  std::vector<uint8_t> opus_identification_header;
372  // The number of priming samples. Extracted from |opus_identification_header|.
373  uint16_t preskip = 0u;
374 };
375 
376 struct IAMFSpecific : Box {
377  DECLARE_BOX_METHODS(IAMFSpecific);
378 
379  std::vector<uint8_t> data;
380 };
381 
382 // FLAC specific decoder configuration box:
383 // https://github.com/xiph/flac/blob/master/doc/isoflac.txt
384 // We do not care about the actual data inside, which is simply copied over.
386  DECLARE_BOX_METHODS(FlacSpecific);
387 
388  std::vector<uint8_t> data;
389 };
390 
391 // ALAC specific decoder configuration box:
392 // https://wiki.multimedia.cx/index.php/Apple_Lossless_Audio_Coding
393 // We do not care about the actual data inside, which is simply copied over.
395  DECLARE_BOX_METHODS(ALACSpecific);
396 
397  std::vector<uint8_t> data;
398 };
399 
401  DECLARE_BOX_METHODS(AudioSampleEntry);
402 
403  // Returns actual format of this sample entry.
404  FourCC GetActualFormat() const {
405  return format == FOURCC_enca ? sinf.format.format : format;
406  }
407 
408  FourCC format = FOURCC_NULL;
409  // data_reference_index is 1-based and "dref" box is mandatory so it is
410  // always present.
411  uint16_t data_reference_index = 1u;
412  uint16_t channelcount = 2u;
413  uint16_t samplesize = 16u;
414  uint32_t samplerate = 0u;
415 
417 
419  DTSSpecific ddts;
420  UDTSSpecific udts;
421  AC3Specific dac3;
422  EC3Specific dec3;
423  AC4Specific dac4;
424  OpusSpecific dops;
425  IAMFSpecific iacb;
426  FlacSpecific dfla;
427  MHAConfiguration mhac;
428  ALACSpecific alac;
429 };
430 
432  DECLARE_BOX_METHODS(WebVTTConfigurationBox);
433 
434  std::string config;
435 };
436 
438  DECLARE_BOX_METHODS(WebVTTSourceLabelBox);
439 
440  std::string source_label;
441 };
442 
444  DECLARE_BOX_METHODS(TextSampleEntry);
445 
446  // Specifies fourcc of this sample entry. It needs to be set on write, e.g.
447  // set to 'wvtt' to write WVTTSampleEntry; On read, it is recovered from box
448  // header.
449  FourCC format = FOURCC_NULL;
450 
451  // data_reference_index is 1-based and "dref" box is mandatory so it is
452  // always present.
453  uint16_t data_reference_index = 1u;
454 
455  // Sub fields for ttml text sample entry.
456  std::string namespace_;
457  std::string schema_location;
458  // Optional MPEG4BitRateBox.
459 
460  // Sub boxes for wvtt text sample entry.
461  WebVTTConfigurationBox config;
462  WebVTTSourceLabelBox label;
463  // Optional MPEG4BitRateBox.
464 };
465 
467  DECLARE_BOX_METHODS(SampleDescription);
468 
469  TrackType type = kInvalid;
470  // TODO(kqyang): Clean up the code to have one single member, e.g. by creating
471  // SampleEntry struct, std::vector<SampleEntry> sample_entries.
472  std::vector<VideoSampleEntry> video_entries;
473  std::vector<AudioSampleEntry> audio_entries;
474  std::vector<TextSampleEntry> text_entries;
475 };
476 
477 struct DecodingTime {
478  uint32_t sample_count;
479  uint32_t sample_delta;
480 };
481 
482 // stts.
484  DECLARE_BOX_METHODS(DecodingTimeToSample);
485 
486  std::vector<DecodingTime> decoding_time;
487 };
488 
490  uint32_t sample_count;
491  // If version == 0, sample_offset is uint32_t;
492  // If version == 1, sample_offset is int32_t.
493  // Use int64_t so both can be supported properly.
494  int64_t sample_offset;
495 };
496 
497 // ctts. Optional.
499  DECLARE_BOX_METHODS(CompositionTimeToSample);
500 
501  std::vector<CompositionOffset> composition_offset;
502 };
503 
504 struct ChunkInfo {
505  uint32_t first_chunk;
506  uint32_t samples_per_chunk;
507  uint32_t sample_description_index;
508 };
509 
510 // stsc.
512  DECLARE_BOX_METHODS(SampleToChunk);
513 
514  std::vector<ChunkInfo> chunk_info;
515 };
516 
517 // stsz.
518 struct SampleSize : FullBox {
519  DECLARE_BOX_METHODS(SampleSize);
520 
521  uint32_t sample_size = 0u;
522  uint32_t sample_count = 0u;
523  std::vector<uint32_t> sizes;
524 };
525 
526 // stz2.
528  DECLARE_BOX_METHODS(CompactSampleSize);
529 
530  uint8_t field_size = 0u;
531  std::vector<uint32_t> sizes;
532 };
533 
534 // co64.
536  DECLARE_BOX_METHODS(ChunkLargeOffset);
537 
538  std::vector<uint64_t> offsets;
539 };
540 
541 // stco.
543  DECLARE_BOX_METHODS(ChunkOffset);
544 };
545 
546 // stss. Optional.
547 struct SyncSample : FullBox {
548  DECLARE_BOX_METHODS(SyncSample);
549 
550  std::vector<uint32_t> sample_number;
551 };
552 
554  bool ReadWrite(BoxBuffer* buffer);
555  uint32_t ComputeSize() const;
556 
557  uint8_t is_protected = 0u;
558  uint8_t per_sample_iv_size = 0u;
559  std::vector<uint8_t> key_id;
560 
561  // For pattern-based encryption.
562  uint8_t crypt_byte_block = 0u;
563  uint8_t skip_byte_block = 0u;
564 
565  // Present only if |is_protected == 1 && per_sample_iv_size == 0|.
566  std::vector<uint8_t> constant_iv;
567 };
568 
570  bool ReadWrite(BoxBuffer* buffer);
571  uint32_t ComputeSize() const;
572 
573  int16_t roll_distance = 0;
574 };
575 
577  DECLARE_BOX_METHODS(SampleGroupDescription);
578 
579  template <typename T>
580  bool ReadWriteEntries(BoxBuffer* buffer, std::vector<T>* entries);
581 
582  uint32_t grouping_type = 0;
583  // Only present if grouping_type == 'seig'.
584  std::vector<CencSampleEncryptionInfoEntry>
585  cenc_sample_encryption_info_entries;
586  // Only present if grouping_type == 'roll'.
587  std::vector<AudioRollRecoveryEntry> audio_roll_recovery_entries;
588 };
589 
591  enum GroupDescriptionIndexBase {
592  kTrackGroupDescriptionIndexBase = 0,
593  kTrackFragmentGroupDescriptionIndexBase = 0x10000,
594  };
595 
596  uint32_t sample_count = 0u;
597  uint32_t group_description_index = 0u;
598 };
599 
601  DECLARE_BOX_METHODS(SampleToGroup);
602 
603  uint32_t grouping_type = 0u;
604  uint32_t grouping_type_parameter = 0u; // Version 1 only.
605  std::vector<SampleToGroupEntry> entries;
606 };
607 
608 struct SampleTable : Box {
609  DECLARE_BOX_METHODS(SampleTable);
610 
611  SampleDescription description;
612  DecodingTimeToSample decoding_time_to_sample;
613  CompositionTimeToSample composition_time_to_sample;
614  SampleToChunk sample_to_chunk;
615  // Either SampleSize or CompactSampleSize must present. Store in SampleSize.
616  SampleSize sample_size;
617  // Either ChunkOffset or ChunkLargeOffset must present. Store in
618  // ChunkLargeOffset.
619  ChunkLargeOffset chunk_large_offset;
620  SyncSample sync_sample;
621  std::vector<SampleGroupDescription> sample_group_descriptions;
622  std::vector<SampleToGroup> sample_to_groups;
623 };
624 
626  DECLARE_BOX_METHODS(MediaHeader);
627 
628  uint64_t creation_time = 0u;
629  uint64_t modification_time = 0u;
630  uint32_t timescale = 0u;
631  uint64_t duration = 0u;
632  Language language;
633 };
634 
636  DECLARE_BOX_METHODS(VideoMediaHeader);
637 
638  uint16_t graphicsmode = 0u;
639  uint16_t opcolor_red = 0u;
640  uint16_t opcolor_green = 0u;
641  uint16_t opcolor_blue = 0u;
642 };
643 
645  DECLARE_BOX_METHODS(SoundMediaHeader);
646 
647  uint16_t balance = 0u;
648 };
649 
651  DECLARE_BOX_METHODS(NullMediaHeader);
652 };
653 
655  DECLARE_BOX_METHODS(SubtitleMediaHeader);
656 };
657 
659  DECLARE_BOX_METHODS(DataEntryUrl);
660 
661  std::vector<uint8_t> location;
662 };
663 
665  DECLARE_BOX_METHODS(DataReference);
666 
667  // Can be either url or urn box. Fix to url box for now.
668  std::vector<DataEntryUrl> data_entry = std::vector<DataEntryUrl>(1);
669 };
670 
672  DECLARE_BOX_METHODS(DataInformation);
673 
674  DataReference dref;
675 };
676 
678  DECLARE_BOX_METHODS(MediaInformation);
679 
680  DataInformation dinf;
681  SampleTable sample_table;
682  // Exactly one specific meida header shall be present, vmhd, smhd, hmhd, nmhd.
683  VideoMediaHeader vmhd;
684  SoundMediaHeader smhd;
685  NullMediaHeader nmhd;
686  SubtitleMediaHeader sthd;
687 };
688 
689 struct Media : Box {
690  DECLARE_BOX_METHODS(Media);
691 
692  MediaHeader header;
693  HandlerReference handler;
694  MediaInformation information;
695 };
696 
697 struct Track : Box {
698  DECLARE_BOX_METHODS(Track);
699 
700  TrackHeader header;
701  Media media;
702  Edit edit;
703  SampleEncryption sample_encryption;
704 };
705 
707  DECLARE_BOX_METHODS(MovieExtendsHeader);
708 
709  uint64_t fragment_duration = 0u;
710 };
711 
713  DECLARE_BOX_METHODS(TrackExtends);
714 
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;
720 };
721 
722 struct MovieExtends : Box {
723  DECLARE_BOX_METHODS(MovieExtends);
724 
725  MovieExtendsHeader header;
726  std::vector<TrackExtends> tracks;
727 };
728 
729 struct Movie : Box {
730  DECLARE_BOX_METHODS(Movie);
731 
732  MovieHeader header;
733  Metadata metadata; // Used to hold version information.
734  MovieExtends extends;
735  std::vector<Track> tracks;
736  std::vector<ProtectionSystemSpecificHeader> pssh;
737 };
738 
740  DECLARE_BOX_METHODS(TrackFragmentDecodeTime);
741 
742  uint64_t decode_time = 0u;
743 };
744 
746  DECLARE_BOX_METHODS(MovieFragmentHeader);
747 
748  uint32_t sequence_number = 0u;
749 };
750 
752  enum TrackFragmentFlagsMasks {
753  kBaseDataOffsetPresentMask = 0x000001,
754  kSampleDescriptionIndexPresentMask = 0x000002,
755  kDefaultSampleDurationPresentMask = 0x000008,
756  kDefaultSampleSizePresentMask = 0x000010,
757  kDefaultSampleFlagsPresentMask = 0x000020,
758  kDurationIsEmptyMask = 0x010000,
759  kDefaultBaseIsMoofMask = 0x020000,
760  };
761 
762  enum SampleFlagsMasks {
763  kUnset = 0x00000000,
764  kReservedMask = 0xFC000000,
765  kSampleDependsOnMask = 0x03000000,
766  kSampleIsDependedOnMask = 0x00C00000,
767  kSampleHasRedundancyMask = 0x00300000,
768  kSamplePaddingValueMask = 0x000E0000,
769  kNonKeySampleMask = 0x00010000,
770  kSampleDegradationPriorityMask = 0x0000FFFF,
771  };
772 
773  DECLARE_BOX_METHODS(TrackFragmentHeader);
774 
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;
780 };
781 
783  enum TrackFragmentFlagsMasks {
784  kDataOffsetPresentMask = 0x000001,
785  kFirstSampleFlagsPresentMask = 0x000004,
786  kSampleDurationPresentMask = 0x000100,
787  kSampleSizePresentMask = 0x000200,
788  kSampleFlagsPresentMask = 0x000400,
789  kSampleCompTimeOffsetsPresentMask = 0x000800,
790  };
791 
792  DECLARE_BOX_METHODS(TrackFragmentRun);
793 
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;
800 };
801 
802 struct TrackFragment : Box {
803  DECLARE_BOX_METHODS(TrackFragment);
804 
805  TrackFragmentHeader header;
806  std::vector<TrackFragmentRun> runs;
807  bool decode_time_absent = false;
808  TrackFragmentDecodeTime decode_time;
809  std::vector<SampleGroupDescription> sample_group_descriptions;
810  std::vector<SampleToGroup> sample_to_groups;
811  SampleAuxiliaryInformationSize auxiliary_size;
812  SampleAuxiliaryInformationOffset auxiliary_offset;
813  SampleEncryption sample_encryption;
814 };
815 
816 struct MovieFragment : Box {
817  DECLARE_BOX_METHODS(MovieFragment);
818 
819  MovieFragmentHeader header;
820  std::vector<TrackFragment> tracks;
821  std::vector<ProtectionSystemSpecificHeader> pssh;
822 };
823 
825  enum SAPType {
826  TypeUnknown = 0,
827  Type1 = 1, // T(ept) = T(dec) = T(sap) = T(ptf)
828  Type2 = 2, // T(ept) = T(dec) = T(sap) < T(ptf)
829  Type3 = 3, // T(ept) < T(dec) = T(sap) <= T(ptf)
830  Type4 = 4, // T(ept) <= T(ptf) < T(dec) = T(sap)
831  Type5 = 5, // T(ept) = T(dec) < T(sap)
832  Type6 = 6, // T(ept) < T(dec) < T(sap)
833  };
834 
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;
841  // We add this field to keep track of earliest_presentation_time in this
842  // subsegment. It is not part of SegmentReference.
843  uint64_t earliest_presentation_time = 0u;
844 };
845 
847  DECLARE_BOX_METHODS(SegmentIndex);
848 
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;
854 };
855 
856 // The actual data is parsed and written separately.
857 struct MediaData : Box {
858  DECLARE_BOX_METHODS(MediaData);
859 
860  uint32_t data_size = 0u;
861 };
862 
863 // Using negative value as "not set". It is very unlikely that 2^31 cues happen
864 // at once.
865 const int kCueSourceIdNotSet = -1;
866 
867 struct CueSourceIDBox : Box {
868  DECLARE_BOX_METHODS(CueSourceIDBox);
869 
870  int32_t source_id = kCueSourceIdNotSet;
871 };
872 
873 struct CueTimeBox : Box {
874  DECLARE_BOX_METHODS(CueTimeBox);
875 
876  std::string cue_current_time;
877 };
878 
879 struct CueIDBox : Box {
880  DECLARE_BOX_METHODS(CueIDBox);
881 
882  std::string cue_id;
883 };
884 
885 struct CueSettingsBox : Box {
886  DECLARE_BOX_METHODS(CueSettingsBox);
887 
888  std::string settings;
889 };
890 
891 struct CuePayloadBox : Box {
892  DECLARE_BOX_METHODS(CuePayloadBox);
893 
894  std::string cue_text;
895 };
896 
897 struct VTTEmptyCueBox : Box {
898  DECLARE_BOX_METHODS(VTTEmptyCueBox);
899 };
900 
902  DECLARE_BOX_METHODS(VTTAdditionalTextBox);
903 
904  std::string cue_additional_text;
905 };
906 
907 struct VTTCueBox : Box {
908  DECLARE_BOX_METHODS(VTTCueBox);
909 
910  CueSourceIDBox cue_source_id;
911  CueIDBox cue_id;
912  CueTimeBox cue_time;
913  CueSettingsBox cue_settings;
914  CuePayloadBox cue_payload;
915 };
916 
917 #undef DECLARE_BOX
918 
919 } // namespace mp4
920 } // namespace media
921 } // namespace shaka
922 
923 #endif // PACKAGER_MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66
Implemented per http://mp4ra.org/#/references.
bool ParseFromBuffer(uint8_t iv_size, bool has_subsamples, BufferReader *reader)
bool ReadWrite(uint8_t iv_size, bool has_subsamples, BoxBuffer *buffer)
std::vector< uint8_t > sample_encryption_data
bool ParseFromSampleEncryptionData(uint8_t l_iv_size, std::vector< SampleEncryptionEntry > *l_sample_encryption_entries) const
FourCC BoxType() const override