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_
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"
31 kSampleIsNonSyncSample
= 0x10000
34 #define DECLARE_BOX_METHODS(T) \
37 bool Parse(BoxReader* reader) override; \
38 FourCC BoxType() const override;
40 struct MEDIA_EXPORT FileType
: Box
{
41 DECLARE_BOX_METHODS(FileType
);
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
;
75 std::vector
<uint8
> sample_info_sizes
;
78 struct MEDIA_EXPORT OriginalFormat
: Box
{
79 DECLARE_BOX_METHODS(OriginalFormat
);
84 struct MEDIA_EXPORT SchemeType
: Box
{
85 DECLARE_BOX_METHODS(SchemeType
);
91 struct MEDIA_EXPORT TrackEncryption
: Box
{
92 DECLARE_BOX_METHODS(TrackEncryption
);
94 // Note: this definition is specific to the CENC protection type.
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
;
114 struct MEDIA_EXPORT MovieHeader
: Box
{
115 DECLARE_BOX_METHODS(MovieHeader
);
117 uint64 creation_time
;
118 uint64 modification_time
;
123 uint32 next_track_id
;
126 struct MEDIA_EXPORT TrackHeader
: Box
{
127 DECLARE_BOX_METHODS(TrackHeader
);
129 uint64 creation_time
;
130 uint64 modification_time
;
134 int16 alternate_group
;
140 struct MEDIA_EXPORT EditListEntry
{
141 uint64 segment_duration
;
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
);
159 struct MEDIA_EXPORT HandlerReference
: Box
{
160 DECLARE_BOX_METHODS(HandlerReference
);
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
172 // Returns true if |data| was successfully parsed.
173 bool Parse(const uint8
* data
, int data_size
);
176 uint8 profile_indication
;
177 uint8 profile_compatibility
;
181 typedef std::vector
<uint8
> SPS
;
182 typedef std::vector
<uint8
> PPS
;
184 std::vector
<SPS
> sps_list
;
185 std::vector
<PPS
> pps_list
;
188 bool ParseInternal(BufferReader
* reader
, const LogCB
& log_cb
);
191 struct MEDIA_EXPORT PixelAspectRatioBox
: Box
{
192 DECLARE_BOX_METHODS(PixelAspectRatioBox
);
198 struct MEDIA_EXPORT VideoSampleEntry
: Box
{
199 DECLARE_BOX_METHODS(VideoSampleEntry
);
202 uint16 data_reference_index
;
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
);
222 struct MEDIA_EXPORT AudioSampleEntry
: Box
{
223 DECLARE_BOX_METHODS(AudioSampleEntry
);
226 uint16 data_reference_index
;
231 ProtectionSchemeInfo sinf
;
232 ElementaryStreamDescriptor esds
;
235 struct MEDIA_EXPORT SampleDescription
: Box
{
236 DECLARE_BOX_METHODS(SampleDescription
);
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;
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
;
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
);
284 HandlerReference handler
;
285 MediaInformation information
;
288 struct MEDIA_EXPORT Track
: Box
{
289 DECLARE_BOX_METHODS(Track
);
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
);
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
);
324 MovieExtends extends
;
325 std::vector
<Track
> tracks
;
326 std::vector
<ProtectionSystemSpecificHeader
> pssh
;
329 struct MEDIA_EXPORT TrackFragmentDecodeTime
: Box
{
330 DECLARE_BOX_METHODS(TrackFragmentDecodeTime
);
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
);
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
);
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
{
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;
385 std::vector
<SampleDependsOn
> sample_depends_on_
;
388 struct MEDIA_EXPORT CencSampleEncryptionInfoEntry
{
389 CencSampleEncryptionInfoEntry();
390 ~CencSampleEncryptionInfoEntry();
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,
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
;
448 #endif // MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_