Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / formats / mp4 / box_definitions.h
blob2dfab63b5d17c06ad1fc0dd56151ebd5057a2249
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, const LogCB& log_cb);
191 struct MEDIA_EXPORT PixelAspectRatioBox : Box {
192 DECLARE_BOX_METHODS(PixelAspectRatioBox);
194 uint32 h_spacing;
195 uint32 v_spacing;
198 struct MEDIA_EXPORT VideoSampleEntry : Box {
199 DECLARE_BOX_METHODS(VideoSampleEntry);
201 FourCC format;
202 uint16 data_reference_index;
203 uint16 width;
204 uint16 height;
206 PixelAspectRatioBox pixel_aspect;
207 ProtectionSchemeInfo sinf;
209 // Currently expected to be present regardless of format.
210 AVCDecoderConfigurationRecord avcc;
212 bool IsFormatValid() const;
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 SyncSample : Box {
244 DECLARE_BOX_METHODS(SyncSample);
246 // Returns true if the |k|th sample is a sync sample (aka a random
247 // access point). Returns false if sample |k| is not a sync sample.
248 bool IsSyncSample(size_t k) const;
250 bool is_present;
251 std::vector<uint32> entries;
254 struct MEDIA_EXPORT SampleTable : Box {
255 DECLARE_BOX_METHODS(SampleTable);
257 // Media Source specific: we ignore many of the sub-boxes in this box,
258 // including some that are required to be present in the BMFF spec. This
259 // includes the 'stts', 'stsc', and 'stco' boxes, which must contain no
260 // samples in order to be compliant files.
261 SampleDescription description;
262 SyncSample sync_sample;
265 struct MEDIA_EXPORT MediaHeader : Box {
266 DECLARE_BOX_METHODS(MediaHeader);
268 uint64 creation_time;
269 uint64 modification_time;
270 uint32 timescale;
271 uint64 duration;
274 struct MEDIA_EXPORT MediaInformation : Box {
275 DECLARE_BOX_METHODS(MediaInformation);
277 SampleTable sample_table;
280 struct MEDIA_EXPORT Media : Box {
281 DECLARE_BOX_METHODS(Media);
283 MediaHeader header;
284 HandlerReference handler;
285 MediaInformation information;
288 struct MEDIA_EXPORT Track : Box {
289 DECLARE_BOX_METHODS(Track);
291 TrackHeader header;
292 Media media;
293 Edit edit;
296 struct MEDIA_EXPORT MovieExtendsHeader : Box {
297 DECLARE_BOX_METHODS(MovieExtendsHeader);
299 uint64 fragment_duration;
302 struct MEDIA_EXPORT TrackExtends : Box {
303 DECLARE_BOX_METHODS(TrackExtends);
305 uint32 track_id;
306 uint32 default_sample_description_index;
307 uint32 default_sample_duration;
308 uint32 default_sample_size;
309 uint32 default_sample_flags;
312 struct MEDIA_EXPORT MovieExtends : Box {
313 DECLARE_BOX_METHODS(MovieExtends);
315 MovieExtendsHeader header;
316 std::vector<TrackExtends> tracks;
319 struct MEDIA_EXPORT Movie : Box {
320 DECLARE_BOX_METHODS(Movie);
322 bool fragmented;
323 MovieHeader header;
324 MovieExtends extends;
325 std::vector<Track> tracks;
326 std::vector<ProtectionSystemSpecificHeader> pssh;
329 struct MEDIA_EXPORT TrackFragmentDecodeTime : Box {
330 DECLARE_BOX_METHODS(TrackFragmentDecodeTime);
332 uint64 decode_time;
335 struct MEDIA_EXPORT MovieFragmentHeader : Box {
336 DECLARE_BOX_METHODS(MovieFragmentHeader);
338 uint32 sequence_number;
341 struct MEDIA_EXPORT TrackFragmentHeader : Box {
342 DECLARE_BOX_METHODS(TrackFragmentHeader);
344 uint32 track_id;
346 uint32 sample_description_index;
347 uint32 default_sample_duration;
348 uint32 default_sample_size;
349 uint32 default_sample_flags;
351 // As 'flags' might be all zero, we cannot use zeroness alone to identify
352 // when default_sample_flags wasn't specified, unlike the other values.
353 bool has_default_sample_flags;
356 struct MEDIA_EXPORT TrackFragmentRun : Box {
357 DECLARE_BOX_METHODS(TrackFragmentRun);
359 uint32 sample_count;
360 uint32 data_offset;
361 std::vector<uint32> sample_flags;
362 std::vector<uint32> sample_sizes;
363 std::vector<uint32> sample_durations;
364 std::vector<int32> sample_composition_time_offsets;
367 // sample_depends_on values in ISO/IEC 14496-12 Section 8.40.2.3.
368 enum SampleDependsOn {
369 kSampleDependsOnUnknown = 0,
370 kSampleDependsOnOthers = 1,
371 kSampleDependsOnNoOther = 2,
372 kSampleDependsOnReserved = 3,
375 class MEDIA_EXPORT IndependentAndDisposableSamples : public Box {
376 public:
377 DECLARE_BOX_METHODS(IndependentAndDisposableSamples);
379 // Returns the SampleDependsOn value for the |i|'th value
380 // in the track. If no data was parsed for the |i|'th sample,
381 // then |kSampleDependsOnUnknown| is returned.
382 SampleDependsOn sample_depends_on(size_t i) const;
384 private:
385 std::vector<SampleDependsOn> sample_depends_on_;
388 struct MEDIA_EXPORT CencSampleEncryptionInfoEntry {
389 CencSampleEncryptionInfoEntry();
390 ~CencSampleEncryptionInfoEntry();
392 bool is_encrypted;
393 uint8 iv_size;
394 std::vector<uint8> key_id;
397 struct MEDIA_EXPORT SampleGroupDescription : Box { // 'sgpd'.
398 DECLARE_BOX_METHODS(SampleGroupDescription);
400 uint32 grouping_type;
401 std::vector<CencSampleEncryptionInfoEntry> entries;
404 struct MEDIA_EXPORT SampleToGroupEntry {
405 enum GroupDescriptionIndexBase {
406 kTrackGroupDescriptionIndexBase = 0,
407 kFragmentGroupDescriptionIndexBase = 0x10000,
410 uint32 sample_count;
411 uint32 group_description_index;
414 struct MEDIA_EXPORT SampleToGroup : Box { // 'sbgp'.
415 DECLARE_BOX_METHODS(SampleToGroup);
417 uint32 grouping_type;
418 uint32 grouping_type_parameter; // Version 1 only.
419 std::vector<SampleToGroupEntry> entries;
422 struct MEDIA_EXPORT TrackFragment : Box {
423 DECLARE_BOX_METHODS(TrackFragment);
425 TrackFragmentHeader header;
426 std::vector<TrackFragmentRun> runs;
427 TrackFragmentDecodeTime decode_time;
428 SampleAuxiliaryInformationOffset auxiliary_offset;
429 SampleAuxiliaryInformationSize auxiliary_size;
430 IndependentAndDisposableSamples sdtp;
431 SampleGroupDescription sample_group_description;
432 SampleToGroup sample_to_group;
435 struct MEDIA_EXPORT MovieFragment : Box {
436 DECLARE_BOX_METHODS(MovieFragment);
438 MovieFragmentHeader header;
439 std::vector<TrackFragment> tracks;
440 std::vector<ProtectionSystemSpecificHeader> pssh;
443 #undef DECLARE_BOX
445 } // namespace mp4
446 } // namespace media
448 #endif // MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_