Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / formats / mp4 / box_definitions.h
blobe1f17293e0c8d91fd35d5dd5901ad092fdbaf825
1 // Copyright 2014 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.
5 #ifndef MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_
6 #define MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "media/base/media_export.h"
14 #include "media/base/media_log.h"
15 #include "media/base/video_codecs.h"
16 #include "media/formats/mp4/aac.h"
17 #include "media/formats/mp4/avc.h"
18 #include "media/formats/mp4/box_reader.h"
19 #include "media/formats/mp4/fourccs.h"
21 namespace media {
22 namespace mp4 {
24 enum TrackType {
25 kInvalid = 0,
26 kVideo,
27 kAudio,
28 kHint
31 enum SampleFlags {
32 kSampleIsNonSyncSample = 0x10000
35 #define DECLARE_BOX_METHODS(T) \
36 T(); \
37 ~T() override; \
38 bool Parse(BoxReader* reader) override; \
39 FourCC BoxType() const override;
41 struct MEDIA_EXPORT FileType : Box {
42 DECLARE_BOX_METHODS(FileType);
44 FourCC major_brand;
45 uint32 minor_version;
48 // If only copying the 'pssh' boxes, use ProtectionSystemSpecificHeader.
49 // If access to the individual fields is needed, use
50 // FullProtectionSystemSpecificHeader.
51 struct MEDIA_EXPORT ProtectionSystemSpecificHeader : Box {
52 DECLARE_BOX_METHODS(ProtectionSystemSpecificHeader);
54 std::vector<uint8> raw_box;
57 struct MEDIA_EXPORT FullProtectionSystemSpecificHeader : Box {
58 DECLARE_BOX_METHODS(FullProtectionSystemSpecificHeader);
60 std::vector<uint8> system_id;
61 std::vector<std::vector<uint8>> key_ids;
62 std::vector<uint8> data;
65 struct MEDIA_EXPORT SampleAuxiliaryInformationOffset : Box {
66 DECLARE_BOX_METHODS(SampleAuxiliaryInformationOffset);
68 std::vector<uint64> offsets;
71 struct MEDIA_EXPORT SampleAuxiliaryInformationSize : Box {
72 DECLARE_BOX_METHODS(SampleAuxiliaryInformationSize);
74 uint8 default_sample_info_size;
75 uint32 sample_count;
76 std::vector<uint8> sample_info_sizes;
79 struct MEDIA_EXPORT OriginalFormat : Box {
80 DECLARE_BOX_METHODS(OriginalFormat);
82 FourCC format;
85 struct MEDIA_EXPORT SchemeType : Box {
86 DECLARE_BOX_METHODS(SchemeType);
88 FourCC type;
89 uint32 version;
92 struct MEDIA_EXPORT TrackEncryption : Box {
93 DECLARE_BOX_METHODS(TrackEncryption);
95 // Note: this definition is specific to the CENC protection type.
96 bool is_encrypted;
97 uint8 default_iv_size;
98 std::vector<uint8> default_kid;
101 struct MEDIA_EXPORT SchemeInfo : Box {
102 DECLARE_BOX_METHODS(SchemeInfo);
104 TrackEncryption track_encryption;
107 struct MEDIA_EXPORT ProtectionSchemeInfo : Box {
108 DECLARE_BOX_METHODS(ProtectionSchemeInfo);
110 OriginalFormat format;
111 SchemeType type;
112 SchemeInfo info;
115 struct MEDIA_EXPORT MovieHeader : Box {
116 DECLARE_BOX_METHODS(MovieHeader);
118 uint64 creation_time;
119 uint64 modification_time;
120 uint32 timescale;
121 uint64 duration;
122 int32 rate;
123 int16 volume;
124 uint32 next_track_id;
127 struct MEDIA_EXPORT TrackHeader : Box {
128 DECLARE_BOX_METHODS(TrackHeader);
130 uint64 creation_time;
131 uint64 modification_time;
132 uint32 track_id;
133 uint64 duration;
134 int16 layer;
135 int16 alternate_group;
136 int16 volume;
137 uint32 width;
138 uint32 height;
141 struct MEDIA_EXPORT EditListEntry {
142 uint64 segment_duration;
143 int64 media_time;
144 int16 media_rate_integer;
145 int16 media_rate_fraction;
148 struct MEDIA_EXPORT EditList : Box {
149 DECLARE_BOX_METHODS(EditList);
151 std::vector<EditListEntry> edits;
154 struct MEDIA_EXPORT Edit : Box {
155 DECLARE_BOX_METHODS(Edit);
157 EditList list;
160 struct MEDIA_EXPORT HandlerReference : Box {
161 DECLARE_BOX_METHODS(HandlerReference);
163 TrackType type;
166 struct MEDIA_EXPORT AVCDecoderConfigurationRecord : Box {
167 DECLARE_BOX_METHODS(AVCDecoderConfigurationRecord);
169 // Parses AVCDecoderConfigurationRecord data encoded in |data|.
170 // Note: This method is intended to parse data outside the MP4StreamParser
171 // context and therefore the box header is not expected to be present
172 // in |data|.
173 // Returns true if |data| was successfully parsed.
174 bool Parse(const uint8* data, int data_size);
176 uint8 version;
177 uint8 profile_indication;
178 uint8 profile_compatibility;
179 uint8 avc_level;
180 uint8 length_size;
182 typedef std::vector<uint8> SPS;
183 typedef std::vector<uint8> PPS;
185 std::vector<SPS> sps_list;
186 std::vector<PPS> pps_list;
188 private:
189 bool ParseInternal(BufferReader* reader,
190 const scoped_refptr<MediaLog>& media_log);
193 struct MEDIA_EXPORT PixelAspectRatioBox : Box {
194 DECLARE_BOX_METHODS(PixelAspectRatioBox);
196 uint32 h_spacing;
197 uint32 v_spacing;
200 struct MEDIA_EXPORT VideoSampleEntry : Box {
201 DECLARE_BOX_METHODS(VideoSampleEntry);
203 FourCC format;
204 uint16 data_reference_index;
205 uint16 width;
206 uint16 height;
208 PixelAspectRatioBox pixel_aspect;
209 ProtectionSchemeInfo sinf;
211 VideoCodec video_codec;
212 VideoCodecProfile video_codec_profile;
214 bool IsFormatValid() const;
216 scoped_refptr<BitstreamConverter> frame_bitstream_converter;
219 struct MEDIA_EXPORT ElementaryStreamDescriptor : Box {
220 DECLARE_BOX_METHODS(ElementaryStreamDescriptor);
222 uint8 object_type;
223 AAC aac;
226 struct MEDIA_EXPORT AudioSampleEntry : Box {
227 DECLARE_BOX_METHODS(AudioSampleEntry);
229 FourCC format;
230 uint16 data_reference_index;
231 uint16 channelcount;
232 uint16 samplesize;
233 uint32 samplerate;
235 ProtectionSchemeInfo sinf;
236 ElementaryStreamDescriptor esds;
239 struct MEDIA_EXPORT SampleDescription : Box {
240 DECLARE_BOX_METHODS(SampleDescription);
242 TrackType type;
243 std::vector<VideoSampleEntry> video_entries;
244 std::vector<AudioSampleEntry> audio_entries;
247 struct MEDIA_EXPORT CencSampleEncryptionInfoEntry {
248 CencSampleEncryptionInfoEntry();
249 ~CencSampleEncryptionInfoEntry();
251 bool is_encrypted;
252 uint8 iv_size;
253 std::vector<uint8> key_id;
256 struct MEDIA_EXPORT SampleGroupDescription : Box { // 'sgpd'.
257 DECLARE_BOX_METHODS(SampleGroupDescription);
259 uint32 grouping_type;
260 std::vector<CencSampleEncryptionInfoEntry> entries;
263 struct MEDIA_EXPORT SampleTable : Box {
264 DECLARE_BOX_METHODS(SampleTable);
266 // Media Source specific: we ignore many of the sub-boxes in this box,
267 // including some that are required to be present in the BMFF spec. This
268 // includes the 'stts', 'stsc', and 'stco' boxes, which must contain no
269 // samples in order to be compliant files.
270 SampleDescription description;
271 SampleGroupDescription sample_group_description;
274 struct MEDIA_EXPORT MediaHeader : Box {
275 DECLARE_BOX_METHODS(MediaHeader);
277 uint64 creation_time;
278 uint64 modification_time;
279 uint32 timescale;
280 uint64 duration;
283 struct MEDIA_EXPORT MediaInformation : Box {
284 DECLARE_BOX_METHODS(MediaInformation);
286 SampleTable sample_table;
289 struct MEDIA_EXPORT Media : Box {
290 DECLARE_BOX_METHODS(Media);
292 MediaHeader header;
293 HandlerReference handler;
294 MediaInformation information;
297 struct MEDIA_EXPORT Track : Box {
298 DECLARE_BOX_METHODS(Track);
300 TrackHeader header;
301 Media media;
302 Edit edit;
305 struct MEDIA_EXPORT MovieExtendsHeader : Box {
306 DECLARE_BOX_METHODS(MovieExtendsHeader);
308 uint64 fragment_duration;
311 struct MEDIA_EXPORT TrackExtends : Box {
312 DECLARE_BOX_METHODS(TrackExtends);
314 uint32 track_id;
315 uint32 default_sample_description_index;
316 uint32 default_sample_duration;
317 uint32 default_sample_size;
318 uint32 default_sample_flags;
321 struct MEDIA_EXPORT MovieExtends : Box {
322 DECLARE_BOX_METHODS(MovieExtends);
324 MovieExtendsHeader header;
325 std::vector<TrackExtends> tracks;
328 struct MEDIA_EXPORT Movie : Box {
329 DECLARE_BOX_METHODS(Movie);
331 bool fragmented;
332 MovieHeader header;
333 MovieExtends extends;
334 std::vector<Track> tracks;
335 std::vector<ProtectionSystemSpecificHeader> pssh;
338 struct MEDIA_EXPORT TrackFragmentDecodeTime : Box {
339 DECLARE_BOX_METHODS(TrackFragmentDecodeTime);
341 uint64 decode_time;
344 struct MEDIA_EXPORT MovieFragmentHeader : Box {
345 DECLARE_BOX_METHODS(MovieFragmentHeader);
347 uint32 sequence_number;
350 struct MEDIA_EXPORT TrackFragmentHeader : Box {
351 DECLARE_BOX_METHODS(TrackFragmentHeader);
353 uint32 track_id;
355 uint32 sample_description_index;
356 uint32 default_sample_duration;
357 uint32 default_sample_size;
358 uint32 default_sample_flags;
360 // As 'flags' might be all zero, we cannot use zeroness alone to identify
361 // when default_sample_flags wasn't specified, unlike the other values.
362 bool has_default_sample_flags;
365 struct MEDIA_EXPORT TrackFragmentRun : Box {
366 DECLARE_BOX_METHODS(TrackFragmentRun);
368 uint32 sample_count;
369 uint32 data_offset;
370 std::vector<uint32> sample_flags;
371 std::vector<uint32> sample_sizes;
372 std::vector<uint32> sample_durations;
373 std::vector<int32> sample_composition_time_offsets;
376 // sample_depends_on values in ISO/IEC 14496-12 Section 8.40.2.3.
377 enum SampleDependsOn {
378 kSampleDependsOnUnknown = 0,
379 kSampleDependsOnOthers = 1,
380 kSampleDependsOnNoOther = 2,
381 kSampleDependsOnReserved = 3,
384 class MEDIA_EXPORT IndependentAndDisposableSamples : public Box {
385 public:
386 DECLARE_BOX_METHODS(IndependentAndDisposableSamples);
388 // Returns the SampleDependsOn value for the |i|'th value
389 // in the track. If no data was parsed for the |i|'th sample,
390 // then |kSampleDependsOnUnknown| is returned.
391 SampleDependsOn sample_depends_on(size_t i) const;
393 private:
394 std::vector<SampleDependsOn> sample_depends_on_;
397 struct MEDIA_EXPORT SampleToGroupEntry {
398 enum GroupDescriptionIndexBase {
399 kTrackGroupDescriptionIndexBase = 0,
400 kFragmentGroupDescriptionIndexBase = 0x10000,
403 uint32 sample_count;
404 uint32 group_description_index;
407 struct MEDIA_EXPORT SampleToGroup : Box { // 'sbgp'.
408 DECLARE_BOX_METHODS(SampleToGroup);
410 uint32 grouping_type;
411 uint32 grouping_type_parameter; // Version 1 only.
412 std::vector<SampleToGroupEntry> entries;
415 struct MEDIA_EXPORT TrackFragment : Box {
416 DECLARE_BOX_METHODS(TrackFragment);
418 TrackFragmentHeader header;
419 std::vector<TrackFragmentRun> runs;
420 TrackFragmentDecodeTime decode_time;
421 SampleAuxiliaryInformationOffset auxiliary_offset;
422 SampleAuxiliaryInformationSize auxiliary_size;
423 IndependentAndDisposableSamples sdtp;
424 SampleGroupDescription sample_group_description;
425 SampleToGroup sample_to_group;
428 struct MEDIA_EXPORT MovieFragment : Box {
429 DECLARE_BOX_METHODS(MovieFragment);
431 MovieFragmentHeader header;
432 std::vector<TrackFragment> tracks;
433 std::vector<ProtectionSystemSpecificHeader> pssh;
436 #undef DECLARE_BOX
438 } // namespace mp4
439 } // namespace media
441 #endif // MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_