Home | History | Annotate | Download | only in mp4
      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 MEDIA_MP4_BOX_DEFINITIONS_H_
      6 #define MEDIA_MP4_BOX_DEFINITIONS_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/compiler_specific.h"
     13 #include "media/base/media_export.h"
     14 #include "media/mp4/aac.h"
     15 #include "media/mp4/avc.h"
     16 #include "media/mp4/box_reader.h"
     17 #include "media/mp4/fourccs.h"
     18 
     19 namespace media {
     20 namespace mp4 {
     21 
     22 enum TrackType {
     23   kInvalid = 0,
     24   kVideo,
     25   kAudio,
     26   kHint
     27 };
     28 
     29 #define DECLARE_BOX_METHODS(T) \
     30   T(); \
     31   virtual ~T(); \
     32   virtual bool Parse(BoxReader* reader) OVERRIDE; \
     33   virtual FourCC BoxType() const OVERRIDE; \
     34 
     35 struct MEDIA_EXPORT FileType : Box {
     36   DECLARE_BOX_METHODS(FileType);
     37 
     38   FourCC major_brand;
     39   uint32 minor_version;
     40 };
     41 
     42 struct MEDIA_EXPORT ProtectionSystemSpecificHeader : Box {
     43   DECLARE_BOX_METHODS(ProtectionSystemSpecificHeader);
     44 
     45   std::vector<uint8> system_id;
     46   std::vector<uint8> raw_box;
     47 };
     48 
     49 struct MEDIA_EXPORT SampleAuxiliaryInformationOffset : Box {
     50   DECLARE_BOX_METHODS(SampleAuxiliaryInformationOffset);
     51 
     52   std::vector<uint64> offsets;
     53 };
     54 
     55 struct MEDIA_EXPORT SampleAuxiliaryInformationSize : Box {
     56   DECLARE_BOX_METHODS(SampleAuxiliaryInformationSize);
     57 
     58   uint8 default_sample_info_size;
     59   uint32 sample_count;
     60   std::vector<uint8> sample_info_sizes;
     61 };
     62 
     63 struct MEDIA_EXPORT OriginalFormat : Box {
     64   DECLARE_BOX_METHODS(OriginalFormat);
     65 
     66   FourCC format;
     67 };
     68 
     69 struct MEDIA_EXPORT SchemeType : Box {
     70   DECLARE_BOX_METHODS(SchemeType);
     71 
     72   FourCC type;
     73   uint32 version;
     74 };
     75 
     76 struct MEDIA_EXPORT TrackEncryption : Box {
     77   DECLARE_BOX_METHODS(TrackEncryption);
     78 
     79   // Note: this definition is specific to the CENC protection type.
     80   bool is_encrypted;
     81   uint8 default_iv_size;
     82   std::vector<uint8> default_kid;
     83 };
     84 
     85 struct MEDIA_EXPORT SchemeInfo : Box {
     86   DECLARE_BOX_METHODS(SchemeInfo);
     87 
     88   TrackEncryption track_encryption;
     89 };
     90 
     91 struct MEDIA_EXPORT ProtectionSchemeInfo : Box {
     92   DECLARE_BOX_METHODS(ProtectionSchemeInfo);
     93 
     94   OriginalFormat format;
     95   SchemeType type;
     96   SchemeInfo info;
     97 };
     98 
     99 struct MEDIA_EXPORT MovieHeader : Box {
    100   DECLARE_BOX_METHODS(MovieHeader);
    101 
    102   uint64 creation_time;
    103   uint64 modification_time;
    104   uint32 timescale;
    105   uint64 duration;
    106   int32 rate;
    107   int16 volume;
    108   uint32 next_track_id;
    109 };
    110 
    111 struct MEDIA_EXPORT TrackHeader : Box {
    112   DECLARE_BOX_METHODS(TrackHeader);
    113 
    114   uint64 creation_time;
    115   uint64 modification_time;
    116   uint32 track_id;
    117   uint64 duration;
    118   int16 layer;
    119   int16 alternate_group;
    120   int16 volume;
    121   uint32 width;
    122   uint32 height;
    123 };
    124 
    125 struct MEDIA_EXPORT EditListEntry {
    126   uint64 segment_duration;
    127   int64 media_time;
    128   int16 media_rate_integer;
    129   int16 media_rate_fraction;
    130 };
    131 
    132 struct MEDIA_EXPORT EditList : Box {
    133   DECLARE_BOX_METHODS(EditList);
    134 
    135   std::vector<EditListEntry> edits;
    136 };
    137 
    138 struct MEDIA_EXPORT Edit : Box {
    139   DECLARE_BOX_METHODS(Edit);
    140 
    141   EditList list;
    142 };
    143 
    144 struct MEDIA_EXPORT HandlerReference : Box {
    145   DECLARE_BOX_METHODS(HandlerReference);
    146 
    147   TrackType type;
    148 };
    149 
    150 struct MEDIA_EXPORT AVCDecoderConfigurationRecord : Box {
    151   DECLARE_BOX_METHODS(AVCDecoderConfigurationRecord);
    152 
    153   uint8 version;
    154   uint8 profile_indication;
    155   uint8 profile_compatibility;
    156   uint8 avc_level;
    157   uint8 length_size;
    158 
    159   typedef std::vector<uint8> SPS;
    160   typedef std::vector<uint8> PPS;
    161 
    162   std::vector<SPS> sps_list;
    163   std::vector<PPS> pps_list;
    164 };
    165 
    166 struct MEDIA_EXPORT PixelAspectRatioBox : Box {
    167   DECLARE_BOX_METHODS(PixelAspectRatioBox);
    168 
    169   uint32 h_spacing;
    170   uint32 v_spacing;
    171 };
    172 
    173 struct MEDIA_EXPORT VideoSampleEntry : Box {
    174   DECLARE_BOX_METHODS(VideoSampleEntry);
    175 
    176   FourCC format;
    177   uint16 data_reference_index;
    178   uint16 width;
    179   uint16 height;
    180 
    181   PixelAspectRatioBox pixel_aspect;
    182   ProtectionSchemeInfo sinf;
    183 
    184   // Currently expected to be present regardless of format.
    185   AVCDecoderConfigurationRecord avcc;
    186 };
    187 
    188 struct MEDIA_EXPORT ElementaryStreamDescriptor : Box {
    189   DECLARE_BOX_METHODS(ElementaryStreamDescriptor);
    190 
    191   uint8 object_type;
    192   AAC aac;
    193 };
    194 
    195 struct MEDIA_EXPORT AudioSampleEntry : Box {
    196   DECLARE_BOX_METHODS(AudioSampleEntry);
    197 
    198   FourCC format;
    199   uint16 data_reference_index;
    200   uint16 channelcount;
    201   uint16 samplesize;
    202   uint32 samplerate;
    203 
    204   ProtectionSchemeInfo sinf;
    205   ElementaryStreamDescriptor esds;
    206 };
    207 
    208 struct MEDIA_EXPORT SampleDescription : Box {
    209   DECLARE_BOX_METHODS(SampleDescription);
    210 
    211   TrackType type;
    212   std::vector<VideoSampleEntry> video_entries;
    213   std::vector<AudioSampleEntry> audio_entries;
    214 };
    215 
    216 struct MEDIA_EXPORT SampleTable : Box {
    217   DECLARE_BOX_METHODS(SampleTable);
    218 
    219   // Media Source specific: we ignore many of the sub-boxes in this box,
    220   // including some that are required to be present in the BMFF spec. This
    221   // includes the 'stts', 'stsc', and 'stco' boxes, which must contain no
    222   // samples in order to be compliant files.
    223   SampleDescription description;
    224 };
    225 
    226 struct MEDIA_EXPORT MediaHeader : Box {
    227   DECLARE_BOX_METHODS(MediaHeader);
    228 
    229   uint64 creation_time;
    230   uint64 modification_time;
    231   uint32 timescale;
    232   uint64 duration;
    233 };
    234 
    235 struct MEDIA_EXPORT MediaInformation : Box {
    236   DECLARE_BOX_METHODS(MediaInformation);
    237 
    238   SampleTable sample_table;
    239 };
    240 
    241 struct MEDIA_EXPORT Media : Box {
    242   DECLARE_BOX_METHODS(Media);
    243 
    244   MediaHeader header;
    245   HandlerReference handler;
    246   MediaInformation information;
    247 };
    248 
    249 struct MEDIA_EXPORT Track : Box {
    250   DECLARE_BOX_METHODS(Track);
    251 
    252   TrackHeader header;
    253   Media media;
    254   Edit edit;
    255 };
    256 
    257 struct MEDIA_EXPORT MovieExtendsHeader : Box {
    258   DECLARE_BOX_METHODS(MovieExtendsHeader);
    259 
    260   uint64 fragment_duration;
    261 };
    262 
    263 struct MEDIA_EXPORT TrackExtends : Box {
    264   DECLARE_BOX_METHODS(TrackExtends);
    265 
    266   uint32 track_id;
    267   uint32 default_sample_description_index;
    268   uint32 default_sample_duration;
    269   uint32 default_sample_size;
    270   uint32 default_sample_flags;
    271 };
    272 
    273 struct MEDIA_EXPORT MovieExtends : Box {
    274   DECLARE_BOX_METHODS(MovieExtends);
    275 
    276   MovieExtendsHeader header;
    277   std::vector<TrackExtends> tracks;
    278 };
    279 
    280 struct MEDIA_EXPORT Movie : Box {
    281   DECLARE_BOX_METHODS(Movie);
    282 
    283   bool fragmented;
    284   MovieHeader header;
    285   MovieExtends extends;
    286   std::vector<Track> tracks;
    287   std::vector<ProtectionSystemSpecificHeader> pssh;
    288 };
    289 
    290 struct MEDIA_EXPORT TrackFragmentDecodeTime : Box {
    291   DECLARE_BOX_METHODS(TrackFragmentDecodeTime);
    292 
    293   uint64 decode_time;
    294 };
    295 
    296 struct MEDIA_EXPORT MovieFragmentHeader : Box {
    297   DECLARE_BOX_METHODS(MovieFragmentHeader);
    298 
    299   uint32 sequence_number;
    300 };
    301 
    302 struct MEDIA_EXPORT TrackFragmentHeader : Box {
    303   DECLARE_BOX_METHODS(TrackFragmentHeader);
    304 
    305   uint32 track_id;
    306 
    307   uint32 sample_description_index;
    308   uint32 default_sample_duration;
    309   uint32 default_sample_size;
    310   uint32 default_sample_flags;
    311 
    312   // As 'flags' might be all zero, we cannot use zeroness alone to identify
    313   // when default_sample_flags wasn't specified, unlike the other values.
    314   bool has_default_sample_flags;
    315 };
    316 
    317 struct MEDIA_EXPORT TrackFragmentRun : Box {
    318   DECLARE_BOX_METHODS(TrackFragmentRun);
    319 
    320   uint32 sample_count;
    321   uint32 data_offset;
    322   std::vector<uint32> sample_flags;
    323   std::vector<uint32> sample_sizes;
    324   std::vector<uint32> sample_durations;
    325   std::vector<int32> sample_composition_time_offsets;
    326 };
    327 
    328 struct MEDIA_EXPORT TrackFragment : Box {
    329   DECLARE_BOX_METHODS(TrackFragment);
    330 
    331   TrackFragmentHeader header;
    332   std::vector<TrackFragmentRun> runs;
    333   TrackFragmentDecodeTime decode_time;
    334   SampleAuxiliaryInformationOffset auxiliary_offset;
    335   SampleAuxiliaryInformationSize auxiliary_size;
    336 };
    337 
    338 struct MEDIA_EXPORT MovieFragment : Box {
    339   DECLARE_BOX_METHODS(MovieFragment);
    340 
    341   MovieFragmentHeader header;
    342   std::vector<TrackFragment> tracks;
    343   std::vector<ProtectionSystemSpecificHeader> pssh;
    344 };
    345 
    346 #undef DECLARE_BOX
    347 
    348 }  // namespace mp4
    349 }  // namespace media
    350 
    351 #endif  // MEDIA_MP4_BOX_DEFINITIONS_H_
    352