Infobar material design refresh: bg color
[chromium-blink-merge.git] / media / formats / mp4 / box_definitions.h
blob39a19b7fa0192376fe8377953f4a9c401c34387a
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/formats/mp4/aac.h"
16 #include "media/formats/mp4/avc.h"
17 #include "media/formats/mp4/box_reader.h"
18 #include "media/formats/mp4/fourccs.h"
20 namespace media {
21 namespace mp4 {
23 enum TrackType {
24 kInvalid = 0,
25 kVideo,
26 kAudio,
27 kHint
30 enum SampleFlags {
31 kSampleIsNonSyncSample = 0x10000
34 #define DECLARE_BOX_METHODS(T) \
35 T(); \
36 ~T() override; \
37 bool Parse(BoxReader* reader) override; \
38 FourCC BoxType() const override;
40 struct MEDIA_EXPORT FileType : Box {
41 DECLARE_BOX_METHODS(FileType);
43 FourCC major_brand;
44 uint32 minor_version;
47 // If only copying the 'pssh' boxes, use ProtectionSystemSpecificHeader.
48 // If access to the individual fields is needed, use
49 // FullProtectionSystemSpecificHeader.
50 struct MEDIA_EXPORT ProtectionSystemSpecificHeader : Box {
51 DECLARE_BOX_METHODS(ProtectionSystemSpecificHeader);
53 std::vector<uint8> raw_box;
56 struct MEDIA_EXPORT FullProtectionSystemSpecificHeader : Box {
57 DECLARE_BOX_METHODS(FullProtectionSystemSpecificHeader);
59 std::vector<uint8> system_id;
60 std::vector<std::vector<uint8>> key_ids;
61 std::vector<uint8> data;
64 struct MEDIA_EXPORT SampleAuxiliaryInformationOffset : Box {
65 DECLARE_BOX_METHODS(SampleAuxiliaryInformationOffset);
67 std::vector<uint64> offsets;
70 struct MEDIA_EXPORT SampleAuxiliaryInformationSize : Box {
71 DECLARE_BOX_METHODS(SampleAuxiliaryInformationSize);
73 uint8 default_sample_info_size;
74 uint32 sample_count;
75 std::vector<uint8> sample_info_sizes;
78 struct MEDIA_EXPORT OriginalFormat : Box {
79 DECLARE_BOX_METHODS(OriginalFormat);
81 FourCC format;
84 struct MEDIA_EXPORT SchemeType : Box {
85 DECLARE_BOX_METHODS(SchemeType);
87 FourCC type;
88 uint32 version;
91 struct MEDIA_EXPORT TrackEncryption : Box {
92 DECLARE_BOX_METHODS(TrackEncryption);
94 // Note: this definition is specific to the CENC protection type.
95 bool is_encrypted;
96 uint8 default_iv_size;
97 std::vector<uint8> default_kid;
100 struct MEDIA_EXPORT SchemeInfo : Box {
101 DECLARE_BOX_METHODS(SchemeInfo);
103 TrackEncryption track_encryption;
106 struct MEDIA_EXPORT ProtectionSchemeInfo : Box {
107 DECLARE_BOX_METHODS(ProtectionSchemeInfo);
109 OriginalFormat format;
110 SchemeType type;
111 SchemeInfo info;
114 struct MEDIA_EXPORT MovieHeader : Box {
115 DECLARE_BOX_METHODS(MovieHeader);
117 uint64 creation_time;
118 uint64 modification_time;
119 uint32 timescale;
120 uint64 duration;
121 int32 rate;
122 int16 volume;
123 uint32 next_track_id;
126 struct MEDIA_EXPORT TrackHeader : Box {
127 DECLARE_BOX_METHODS(TrackHeader);
129 uint64 creation_time;
130 uint64 modification_time;
131 uint32 track_id;
132 uint64 duration;
133 int16 layer;
134 int16 alternate_group;
135 int16 volume;
136 uint32 width;
137 uint32 height;
140 struct MEDIA_EXPORT EditListEntry {
141 uint64 segment_duration;
142 int64 media_time;
143 int16 media_rate_integer;
144 int16 media_rate_fraction;
147 struct MEDIA_EXPORT EditList : Box {
148 DECLARE_BOX_METHODS(EditList);
150 std::vector<EditListEntry> edits;
153 struct MEDIA_EXPORT Edit : Box {
154 DECLARE_BOX_METHODS(Edit);
156 EditList list;
159 struct MEDIA_EXPORT HandlerReference : Box {
160 DECLARE_BOX_METHODS(HandlerReference);
162 TrackType type;
165 struct MEDIA_EXPORT AVCDecoderConfigurationRecord : Box {
166 DECLARE_BOX_METHODS(AVCDecoderConfigurationRecord);
168 // Parses AVCDecoderConfigurationRecord data encoded in |data|.
169 // Note: This method is intended to parse data outside the MP4StreamParser
170 // context and therefore the box header is not expected to be present
171 // in |data|.
172 // Returns true if |data| was successfully parsed.
173 bool Parse(const uint8* data, int data_size);
175 uint8 version;
176 uint8 profile_indication;
177 uint8 profile_compatibility;
178 uint8 avc_level;
179 uint8 length_size;
181 typedef std::vector<uint8> SPS;
182 typedef std::vector<uint8> PPS;
184 std::vector<SPS> sps_list;
185 std::vector<PPS> pps_list;
187 private:
188 bool ParseInternal(BufferReader* reader,
189 const scoped_refptr<MediaLog>& media_log);
192 struct MEDIA_EXPORT PixelAspectRatioBox : Box {
193 DECLARE_BOX_METHODS(PixelAspectRatioBox);
195 uint32 h_spacing;
196 uint32 v_spacing;
199 struct MEDIA_EXPORT VideoSampleEntry : Box {
200 DECLARE_BOX_METHODS(VideoSampleEntry);
202 FourCC format;
203 uint16 data_reference_index;
204 uint16 width;
205 uint16 height;
207 PixelAspectRatioBox pixel_aspect;
208 ProtectionSchemeInfo sinf;
210 bool IsFormatValid() const;
212 scoped_refptr<BitstreamConverter> frame_bitstream_converter;
215 struct MEDIA_EXPORT ElementaryStreamDescriptor : Box {
216 DECLARE_BOX_METHODS(ElementaryStreamDescriptor);
218 uint8 object_type;
219 AAC aac;
222 struct MEDIA_EXPORT AudioSampleEntry : Box {
223 DECLARE_BOX_METHODS(AudioSampleEntry);
225 FourCC format;
226 uint16 data_reference_index;
227 uint16 channelcount;
228 uint16 samplesize;
229 uint32 samplerate;
231 ProtectionSchemeInfo sinf;
232 ElementaryStreamDescriptor esds;
235 struct MEDIA_EXPORT SampleDescription : Box {
236 DECLARE_BOX_METHODS(SampleDescription);
238 TrackType type;
239 std::vector<VideoSampleEntry> video_entries;
240 std::vector<AudioSampleEntry> audio_entries;
243 struct MEDIA_EXPORT CencSampleEncryptionInfoEntry {
244 CencSampleEncryptionInfoEntry();
245 ~CencSampleEncryptionInfoEntry();
247 bool is_encrypted;
248 uint8 iv_size;
249 std::vector<uint8> key_id;
252 struct MEDIA_EXPORT SampleGroupDescription : Box { // 'sgpd'.
253 DECLARE_BOX_METHODS(SampleGroupDescription);
255 uint32 grouping_type;
256 std::vector<CencSampleEncryptionInfoEntry> entries;
259 struct MEDIA_EXPORT SampleTable : Box {
260 DECLARE_BOX_METHODS(SampleTable);
262 // Media Source specific: we ignore many of the sub-boxes in this box,
263 // including some that are required to be present in the BMFF spec. This
264 // includes the 'stts', 'stsc', and 'stco' boxes, which must contain no
265 // samples in order to be compliant files.
266 SampleDescription description;
267 SampleGroupDescription sample_group_description;
270 struct MEDIA_EXPORT MediaHeader : Box {
271 DECLARE_BOX_METHODS(MediaHeader);
273 uint64 creation_time;
274 uint64 modification_time;
275 uint32 timescale;
276 uint64 duration;
279 struct MEDIA_EXPORT MediaInformation : Box {
280 DECLARE_BOX_METHODS(MediaInformation);
282 SampleTable sample_table;
285 struct MEDIA_EXPORT Media : Box {
286 DECLARE_BOX_METHODS(Media);
288 MediaHeader header;
289 HandlerReference handler;
290 MediaInformation information;
293 struct MEDIA_EXPORT Track : Box {
294 DECLARE_BOX_METHODS(Track);
296 TrackHeader header;
297 Media media;
298 Edit edit;
301 struct MEDIA_EXPORT MovieExtendsHeader : Box {
302 DECLARE_BOX_METHODS(MovieExtendsHeader);
304 uint64 fragment_duration;
307 struct MEDIA_EXPORT TrackExtends : Box {
308 DECLARE_BOX_METHODS(TrackExtends);
310 uint32 track_id;
311 uint32 default_sample_description_index;
312 uint32 default_sample_duration;
313 uint32 default_sample_size;
314 uint32 default_sample_flags;
317 struct MEDIA_EXPORT MovieExtends : Box {
318 DECLARE_BOX_METHODS(MovieExtends);
320 MovieExtendsHeader header;
321 std::vector<TrackExtends> tracks;
324 struct MEDIA_EXPORT Movie : Box {
325 DECLARE_BOX_METHODS(Movie);
327 bool fragmented;
328 MovieHeader header;
329 MovieExtends extends;
330 std::vector<Track> tracks;
331 std::vector<ProtectionSystemSpecificHeader> pssh;
334 struct MEDIA_EXPORT TrackFragmentDecodeTime : Box {
335 DECLARE_BOX_METHODS(TrackFragmentDecodeTime);
337 uint64 decode_time;
340 struct MEDIA_EXPORT MovieFragmentHeader : Box {
341 DECLARE_BOX_METHODS(MovieFragmentHeader);
343 uint32 sequence_number;
346 struct MEDIA_EXPORT TrackFragmentHeader : Box {
347 DECLARE_BOX_METHODS(TrackFragmentHeader);
349 uint32 track_id;
351 uint32 sample_description_index;
352 uint32 default_sample_duration;
353 uint32 default_sample_size;
354 uint32 default_sample_flags;
356 // As 'flags' might be all zero, we cannot use zeroness alone to identify
357 // when default_sample_flags wasn't specified, unlike the other values.
358 bool has_default_sample_flags;
361 struct MEDIA_EXPORT TrackFragmentRun : Box {
362 DECLARE_BOX_METHODS(TrackFragmentRun);
364 uint32 sample_count;
365 uint32 data_offset;
366 std::vector<uint32> sample_flags;
367 std::vector<uint32> sample_sizes;
368 std::vector<uint32> sample_durations;
369 std::vector<int32> sample_composition_time_offsets;
372 // sample_depends_on values in ISO/IEC 14496-12 Section 8.40.2.3.
373 enum SampleDependsOn {
374 kSampleDependsOnUnknown = 0,
375 kSampleDependsOnOthers = 1,
376 kSampleDependsOnNoOther = 2,
377 kSampleDependsOnReserved = 3,
380 class MEDIA_EXPORT IndependentAndDisposableSamples : public Box {
381 public:
382 DECLARE_BOX_METHODS(IndependentAndDisposableSamples);
384 // Returns the SampleDependsOn value for the |i|'th value
385 // in the track. If no data was parsed for the |i|'th sample,
386 // then |kSampleDependsOnUnknown| is returned.
387 SampleDependsOn sample_depends_on(size_t i) const;
389 private:
390 std::vector<SampleDependsOn> sample_depends_on_;
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_