Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / media / formats / mp4 / box_definitions.h
blob89522a18656166b77f0ced4b59a2047954865abf
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/formats/mp4/aac.h"
15 #include "media/formats/mp4/avc.h"
16 #include "media/formats/mp4/box_reader.h"
17 #include "media/formats/mp4/fourccs.h"
19 namespace media {
20 namespace mp4 {
22 enum TrackType {
23 kInvalid = 0,
24 kVideo,
25 kAudio,
26 kHint
29 enum SampleFlags {
30 kSampleIsNonSyncSample = 0x10000
33 #define DECLARE_BOX_METHODS(T) \
34 T(); \
35 virtual ~T(); \
36 virtual bool Parse(BoxReader* reader) override; \
37 virtual FourCC BoxType() const override; \
39 struct MEDIA_EXPORT FileType : Box {
40 DECLARE_BOX_METHODS(FileType);
42 FourCC major_brand;
43 uint32 minor_version;
46 struct MEDIA_EXPORT ProtectionSystemSpecificHeader : Box {
47 DECLARE_BOX_METHODS(ProtectionSystemSpecificHeader);
49 std::vector<uint8> system_id;
50 std::vector<uint8> raw_box;
53 struct MEDIA_EXPORT SampleAuxiliaryInformationOffset : Box {
54 DECLARE_BOX_METHODS(SampleAuxiliaryInformationOffset);
56 std::vector<uint64> offsets;
59 struct MEDIA_EXPORT SampleAuxiliaryInformationSize : Box {
60 DECLARE_BOX_METHODS(SampleAuxiliaryInformationSize);
62 uint8 default_sample_info_size;
63 uint32 sample_count;
64 std::vector<uint8> sample_info_sizes;
67 struct MEDIA_EXPORT OriginalFormat : Box {
68 DECLARE_BOX_METHODS(OriginalFormat);
70 FourCC format;
73 struct MEDIA_EXPORT SchemeType : Box {
74 DECLARE_BOX_METHODS(SchemeType);
76 FourCC type;
77 uint32 version;
80 struct MEDIA_EXPORT TrackEncryption : Box {
81 DECLARE_BOX_METHODS(TrackEncryption);
83 // Note: this definition is specific to the CENC protection type.
84 bool is_encrypted;
85 uint8 default_iv_size;
86 std::vector<uint8> default_kid;
89 struct MEDIA_EXPORT SchemeInfo : Box {
90 DECLARE_BOX_METHODS(SchemeInfo);
92 TrackEncryption track_encryption;
95 struct MEDIA_EXPORT ProtectionSchemeInfo : Box {
96 DECLARE_BOX_METHODS(ProtectionSchemeInfo);
98 OriginalFormat format;
99 SchemeType type;
100 SchemeInfo info;
103 struct MEDIA_EXPORT MovieHeader : Box {
104 DECLARE_BOX_METHODS(MovieHeader);
106 uint64 creation_time;
107 uint64 modification_time;
108 uint32 timescale;
109 uint64 duration;
110 int32 rate;
111 int16 volume;
112 uint32 next_track_id;
115 struct MEDIA_EXPORT TrackHeader : Box {
116 DECLARE_BOX_METHODS(TrackHeader);
118 uint64 creation_time;
119 uint64 modification_time;
120 uint32 track_id;
121 uint64 duration;
122 int16 layer;
123 int16 alternate_group;
124 int16 volume;
125 uint32 width;
126 uint32 height;
129 struct MEDIA_EXPORT EditListEntry {
130 uint64 segment_duration;
131 int64 media_time;
132 int16 media_rate_integer;
133 int16 media_rate_fraction;
136 struct MEDIA_EXPORT EditList : Box {
137 DECLARE_BOX_METHODS(EditList);
139 std::vector<EditListEntry> edits;
142 struct MEDIA_EXPORT Edit : Box {
143 DECLARE_BOX_METHODS(Edit);
145 EditList list;
148 struct MEDIA_EXPORT HandlerReference : Box {
149 DECLARE_BOX_METHODS(HandlerReference);
151 TrackType type;
154 struct MEDIA_EXPORT AVCDecoderConfigurationRecord : Box {
155 DECLARE_BOX_METHODS(AVCDecoderConfigurationRecord);
157 // Parses AVCDecoderConfigurationRecord data encoded in |data|.
158 // Note: This method is intended to parse data outside the MP4StreamParser
159 // context and therefore the box header is not expected to be present
160 // in |data|.
161 // Returns true if |data| was successfully parsed.
162 bool Parse(const uint8* data, int data_size);
164 uint8 version;
165 uint8 profile_indication;
166 uint8 profile_compatibility;
167 uint8 avc_level;
168 uint8 length_size;
170 typedef std::vector<uint8> SPS;
171 typedef std::vector<uint8> PPS;
173 std::vector<SPS> sps_list;
174 std::vector<PPS> pps_list;
176 private:
177 bool ParseInternal(BufferReader* reader, const LogCB& log_cb);
180 struct MEDIA_EXPORT PixelAspectRatioBox : Box {
181 DECLARE_BOX_METHODS(PixelAspectRatioBox);
183 uint32 h_spacing;
184 uint32 v_spacing;
187 struct MEDIA_EXPORT VideoSampleEntry : Box {
188 DECLARE_BOX_METHODS(VideoSampleEntry);
190 FourCC format;
191 uint16 data_reference_index;
192 uint16 width;
193 uint16 height;
195 PixelAspectRatioBox pixel_aspect;
196 ProtectionSchemeInfo sinf;
198 // Currently expected to be present regardless of format.
199 AVCDecoderConfigurationRecord avcc;
201 bool IsFormatValid() const;
204 struct MEDIA_EXPORT ElementaryStreamDescriptor : Box {
205 DECLARE_BOX_METHODS(ElementaryStreamDescriptor);
207 uint8 object_type;
208 AAC aac;
211 struct MEDIA_EXPORT AudioSampleEntry : Box {
212 DECLARE_BOX_METHODS(AudioSampleEntry);
214 FourCC format;
215 uint16 data_reference_index;
216 uint16 channelcount;
217 uint16 samplesize;
218 uint32 samplerate;
220 ProtectionSchemeInfo sinf;
221 ElementaryStreamDescriptor esds;
224 struct MEDIA_EXPORT SampleDescription : Box {
225 DECLARE_BOX_METHODS(SampleDescription);
227 TrackType type;
228 std::vector<VideoSampleEntry> video_entries;
229 std::vector<AudioSampleEntry> audio_entries;
232 struct MEDIA_EXPORT SyncSample : Box {
233 DECLARE_BOX_METHODS(SyncSample);
235 // Returns true if the |k|th sample is a sync sample (aka a random
236 // access point). Returns false if sample |k| is not a sync sample.
237 bool IsSyncSample(size_t k) const;
239 bool is_present;
240 std::vector<uint32> entries;
243 struct MEDIA_EXPORT SampleTable : Box {
244 DECLARE_BOX_METHODS(SampleTable);
246 // Media Source specific: we ignore many of the sub-boxes in this box,
247 // including some that are required to be present in the BMFF spec. This
248 // includes the 'stts', 'stsc', and 'stco' boxes, which must contain no
249 // samples in order to be compliant files.
250 SampleDescription description;
251 SyncSample sync_sample;
254 struct MEDIA_EXPORT MediaHeader : Box {
255 DECLARE_BOX_METHODS(MediaHeader);
257 uint64 creation_time;
258 uint64 modification_time;
259 uint32 timescale;
260 uint64 duration;
263 struct MEDIA_EXPORT MediaInformation : Box {
264 DECLARE_BOX_METHODS(MediaInformation);
266 SampleTable sample_table;
269 struct MEDIA_EXPORT Media : Box {
270 DECLARE_BOX_METHODS(Media);
272 MediaHeader header;
273 HandlerReference handler;
274 MediaInformation information;
277 struct MEDIA_EXPORT Track : Box {
278 DECLARE_BOX_METHODS(Track);
280 TrackHeader header;
281 Media media;
282 Edit edit;
285 struct MEDIA_EXPORT MovieExtendsHeader : Box {
286 DECLARE_BOX_METHODS(MovieExtendsHeader);
288 uint64 fragment_duration;
291 struct MEDIA_EXPORT TrackExtends : Box {
292 DECLARE_BOX_METHODS(TrackExtends);
294 uint32 track_id;
295 uint32 default_sample_description_index;
296 uint32 default_sample_duration;
297 uint32 default_sample_size;
298 uint32 default_sample_flags;
301 struct MEDIA_EXPORT MovieExtends : Box {
302 DECLARE_BOX_METHODS(MovieExtends);
304 MovieExtendsHeader header;
305 std::vector<TrackExtends> tracks;
308 struct MEDIA_EXPORT Movie : Box {
309 DECLARE_BOX_METHODS(Movie);
311 bool fragmented;
312 MovieHeader header;
313 MovieExtends extends;
314 std::vector<Track> tracks;
315 std::vector<ProtectionSystemSpecificHeader> pssh;
318 struct MEDIA_EXPORT TrackFragmentDecodeTime : Box {
319 DECLARE_BOX_METHODS(TrackFragmentDecodeTime);
321 uint64 decode_time;
324 struct MEDIA_EXPORT MovieFragmentHeader : Box {
325 DECLARE_BOX_METHODS(MovieFragmentHeader);
327 uint32 sequence_number;
330 struct MEDIA_EXPORT TrackFragmentHeader : Box {
331 DECLARE_BOX_METHODS(TrackFragmentHeader);
333 uint32 track_id;
335 uint32 sample_description_index;
336 uint32 default_sample_duration;
337 uint32 default_sample_size;
338 uint32 default_sample_flags;
340 // As 'flags' might be all zero, we cannot use zeroness alone to identify
341 // when default_sample_flags wasn't specified, unlike the other values.
342 bool has_default_sample_flags;
345 struct MEDIA_EXPORT TrackFragmentRun : Box {
346 DECLARE_BOX_METHODS(TrackFragmentRun);
348 uint32 sample_count;
349 uint32 data_offset;
350 std::vector<uint32> sample_flags;
351 std::vector<uint32> sample_sizes;
352 std::vector<uint32> sample_durations;
353 std::vector<int32> sample_composition_time_offsets;
356 // sample_depends_on values in ISO/IEC 14496-12 Section 8.40.2.3.
357 enum SampleDependsOn {
358 kSampleDependsOnUnknown = 0,
359 kSampleDependsOnOthers = 1,
360 kSampleDependsOnNoOther = 2,
361 kSampleDependsOnReserved = 3,
364 class MEDIA_EXPORT IndependentAndDisposableSamples : public Box {
365 public:
366 DECLARE_BOX_METHODS(IndependentAndDisposableSamples);
368 // Returns the SampleDependsOn value for the |i|'th value
369 // in the track. If no data was parsed for the |i|'th sample,
370 // then |kSampleDependsOnUnknown| is returned.
371 SampleDependsOn sample_depends_on(size_t i) const;
373 private:
374 std::vector<SampleDependsOn> sample_depends_on_;
377 struct MEDIA_EXPORT CencSampleEncryptionInfoEntry {
378 CencSampleEncryptionInfoEntry();
379 ~CencSampleEncryptionInfoEntry();
381 bool is_encrypted;
382 uint8 iv_size;
383 std::vector<uint8> key_id;
386 struct MEDIA_EXPORT SampleGroupDescription : Box { // 'sgpd'.
387 DECLARE_BOX_METHODS(SampleGroupDescription);
389 uint32 grouping_type;
390 std::vector<CencSampleEncryptionInfoEntry> entries;
393 struct MEDIA_EXPORT SampleToGroupEntry {
394 enum GroupDescriptionIndexBase {
395 kTrackGroupDescriptionIndexBase = 0,
396 kFragmentGroupDescriptionIndexBase = 0x10000,
399 uint32 sample_count;
400 uint32 group_description_index;
403 struct MEDIA_EXPORT SampleToGroup : Box { // 'sbgp'.
404 DECLARE_BOX_METHODS(SampleToGroup);
406 uint32 grouping_type;
407 uint32 grouping_type_parameter; // Version 1 only.
408 std::vector<SampleToGroupEntry> entries;
411 struct MEDIA_EXPORT TrackFragment : Box {
412 DECLARE_BOX_METHODS(TrackFragment);
414 TrackFragmentHeader header;
415 std::vector<TrackFragmentRun> runs;
416 TrackFragmentDecodeTime decode_time;
417 SampleAuxiliaryInformationOffset auxiliary_offset;
418 SampleAuxiliaryInformationSize auxiliary_size;
419 IndependentAndDisposableSamples sdtp;
420 SampleGroupDescription sample_group_description;
421 SampleToGroup sample_to_group;
424 struct MEDIA_EXPORT MovieFragment : Box {
425 DECLARE_BOX_METHODS(MovieFragment);
427 MovieFragmentHeader header;
428 std::vector<TrackFragment> tracks;
429 std::vector<ProtectionSystemSpecificHeader> pssh;
432 #undef DECLARE_BOX
434 } // namespace mp4
435 } // namespace media
437 #endif // MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_