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
,
189 const scoped_refptr
<MediaLog
>& media_log
);
192 struct MEDIA_EXPORT PixelAspectRatioBox
: Box
{
193 DECLARE_BOX_METHODS(PixelAspectRatioBox
);
199 struct MEDIA_EXPORT VideoSampleEntry
: Box
{
200 DECLARE_BOX_METHODS(VideoSampleEntry
);
203 uint16 data_reference_index
;
207 PixelAspectRatioBox pixel_aspect
;
208 ProtectionSchemeInfo sinf
;
210 // Currently expected to be present regardless of format.
211 AVCDecoderConfigurationRecord avcc
;
213 bool IsFormatValid() const;
216 struct MEDIA_EXPORT ElementaryStreamDescriptor
: Box
{
217 DECLARE_BOX_METHODS(ElementaryStreamDescriptor
);
223 struct MEDIA_EXPORT AudioSampleEntry
: Box
{
224 DECLARE_BOX_METHODS(AudioSampleEntry
);
227 uint16 data_reference_index
;
232 ProtectionSchemeInfo sinf
;
233 ElementaryStreamDescriptor esds
;
236 struct MEDIA_EXPORT SampleDescription
: Box
{
237 DECLARE_BOX_METHODS(SampleDescription
);
240 std::vector
<VideoSampleEntry
> video_entries
;
241 std::vector
<AudioSampleEntry
> audio_entries
;
244 struct MEDIA_EXPORT SyncSample
: Box
{
245 DECLARE_BOX_METHODS(SyncSample
);
247 // Returns true if the |k|th sample is a sync sample (aka a random
248 // access point). Returns false if sample |k| is not a sync sample.
249 bool IsSyncSample(size_t k
) const;
252 std::vector
<uint32
> entries
;
255 struct MEDIA_EXPORT CencSampleEncryptionInfoEntry
{
256 CencSampleEncryptionInfoEntry();
257 ~CencSampleEncryptionInfoEntry();
261 std::vector
<uint8
> key_id
;
264 struct MEDIA_EXPORT SampleGroupDescription
: Box
{ // 'sgpd'.
265 DECLARE_BOX_METHODS(SampleGroupDescription
);
267 uint32 grouping_type
;
268 std::vector
<CencSampleEncryptionInfoEntry
> entries
;
271 struct MEDIA_EXPORT SampleTable
: Box
{
272 DECLARE_BOX_METHODS(SampleTable
);
274 // Media Source specific: we ignore many of the sub-boxes in this box,
275 // including some that are required to be present in the BMFF spec. This
276 // includes the 'stts', 'stsc', and 'stco' boxes, which must contain no
277 // samples in order to be compliant files.
278 SampleDescription description
;
279 SyncSample sync_sample
;
280 SampleGroupDescription sample_group_description
;
283 struct MEDIA_EXPORT MediaHeader
: Box
{
284 DECLARE_BOX_METHODS(MediaHeader
);
286 uint64 creation_time
;
287 uint64 modification_time
;
292 struct MEDIA_EXPORT MediaInformation
: Box
{
293 DECLARE_BOX_METHODS(MediaInformation
);
295 SampleTable sample_table
;
298 struct MEDIA_EXPORT Media
: Box
{
299 DECLARE_BOX_METHODS(Media
);
302 HandlerReference handler
;
303 MediaInformation information
;
306 struct MEDIA_EXPORT Track
: Box
{
307 DECLARE_BOX_METHODS(Track
);
314 struct MEDIA_EXPORT MovieExtendsHeader
: Box
{
315 DECLARE_BOX_METHODS(MovieExtendsHeader
);
317 uint64 fragment_duration
;
320 struct MEDIA_EXPORT TrackExtends
: Box
{
321 DECLARE_BOX_METHODS(TrackExtends
);
324 uint32 default_sample_description_index
;
325 uint32 default_sample_duration
;
326 uint32 default_sample_size
;
327 uint32 default_sample_flags
;
330 struct MEDIA_EXPORT MovieExtends
: Box
{
331 DECLARE_BOX_METHODS(MovieExtends
);
333 MovieExtendsHeader header
;
334 std::vector
<TrackExtends
> tracks
;
337 struct MEDIA_EXPORT Movie
: Box
{
338 DECLARE_BOX_METHODS(Movie
);
342 MovieExtends extends
;
343 std::vector
<Track
> tracks
;
344 std::vector
<ProtectionSystemSpecificHeader
> pssh
;
347 struct MEDIA_EXPORT TrackFragmentDecodeTime
: Box
{
348 DECLARE_BOX_METHODS(TrackFragmentDecodeTime
);
353 struct MEDIA_EXPORT MovieFragmentHeader
: Box
{
354 DECLARE_BOX_METHODS(MovieFragmentHeader
);
356 uint32 sequence_number
;
359 struct MEDIA_EXPORT TrackFragmentHeader
: Box
{
360 DECLARE_BOX_METHODS(TrackFragmentHeader
);
364 uint32 sample_description_index
;
365 uint32 default_sample_duration
;
366 uint32 default_sample_size
;
367 uint32 default_sample_flags
;
369 // As 'flags' might be all zero, we cannot use zeroness alone to identify
370 // when default_sample_flags wasn't specified, unlike the other values.
371 bool has_default_sample_flags
;
374 struct MEDIA_EXPORT TrackFragmentRun
: Box
{
375 DECLARE_BOX_METHODS(TrackFragmentRun
);
379 std::vector
<uint32
> sample_flags
;
380 std::vector
<uint32
> sample_sizes
;
381 std::vector
<uint32
> sample_durations
;
382 std::vector
<int32
> sample_composition_time_offsets
;
385 // sample_depends_on values in ISO/IEC 14496-12 Section 8.40.2.3.
386 enum SampleDependsOn
{
387 kSampleDependsOnUnknown
= 0,
388 kSampleDependsOnOthers
= 1,
389 kSampleDependsOnNoOther
= 2,
390 kSampleDependsOnReserved
= 3,
393 class MEDIA_EXPORT IndependentAndDisposableSamples
: public Box
{
395 DECLARE_BOX_METHODS(IndependentAndDisposableSamples
);
397 // Returns the SampleDependsOn value for the |i|'th value
398 // in the track. If no data was parsed for the |i|'th sample,
399 // then |kSampleDependsOnUnknown| is returned.
400 SampleDependsOn
sample_depends_on(size_t i
) const;
403 std::vector
<SampleDependsOn
> sample_depends_on_
;
406 struct MEDIA_EXPORT SampleToGroupEntry
{
407 enum GroupDescriptionIndexBase
{
408 kTrackGroupDescriptionIndexBase
= 0,
409 kFragmentGroupDescriptionIndexBase
= 0x10000,
413 uint32 group_description_index
;
416 struct MEDIA_EXPORT SampleToGroup
: Box
{ // 'sbgp'.
417 DECLARE_BOX_METHODS(SampleToGroup
);
419 uint32 grouping_type
;
420 uint32 grouping_type_parameter
; // Version 1 only.
421 std::vector
<SampleToGroupEntry
> entries
;
424 struct MEDIA_EXPORT TrackFragment
: Box
{
425 DECLARE_BOX_METHODS(TrackFragment
);
427 TrackFragmentHeader header
;
428 std::vector
<TrackFragmentRun
> runs
;
429 TrackFragmentDecodeTime decode_time
;
430 SampleAuxiliaryInformationOffset auxiliary_offset
;
431 SampleAuxiliaryInformationSize auxiliary_size
;
432 IndependentAndDisposableSamples sdtp
;
433 SampleGroupDescription sample_group_description
;
434 SampleToGroup sample_to_group
;
437 struct MEDIA_EXPORT MovieFragment
: Box
{
438 DECLARE_BOX_METHODS(MovieFragment
);
440 MovieFragmentHeader header
;
441 std::vector
<TrackFragment
> tracks
;
442 std::vector
<ProtectionSystemSpecificHeader
> pssh
;
450 #endif // MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_