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/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"
30 kSampleIsNonSyncSample
= 0x10000
33 #define DECLARE_BOX_METHODS(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
);
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
;
64 std::vector
<uint8
> sample_info_sizes
;
67 struct MEDIA_EXPORT OriginalFormat
: Box
{
68 DECLARE_BOX_METHODS(OriginalFormat
);
73 struct MEDIA_EXPORT SchemeType
: Box
{
74 DECLARE_BOX_METHODS(SchemeType
);
80 struct MEDIA_EXPORT TrackEncryption
: Box
{
81 DECLARE_BOX_METHODS(TrackEncryption
);
83 // Note: this definition is specific to the CENC protection type.
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
;
103 struct MEDIA_EXPORT MovieHeader
: Box
{
104 DECLARE_BOX_METHODS(MovieHeader
);
106 uint64 creation_time
;
107 uint64 modification_time
;
112 uint32 next_track_id
;
115 struct MEDIA_EXPORT TrackHeader
: Box
{
116 DECLARE_BOX_METHODS(TrackHeader
);
118 uint64 creation_time
;
119 uint64 modification_time
;
123 int16 alternate_group
;
129 struct MEDIA_EXPORT EditListEntry
{
130 uint64 segment_duration
;
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
);
148 struct MEDIA_EXPORT HandlerReference
: Box
{
149 DECLARE_BOX_METHODS(HandlerReference
);
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
161 // Returns true if |data| was successfully parsed.
162 bool Parse(const uint8
* data
, int data_size
);
165 uint8 profile_indication
;
166 uint8 profile_compatibility
;
170 typedef std::vector
<uint8
> SPS
;
171 typedef std::vector
<uint8
> PPS
;
173 std::vector
<SPS
> sps_list
;
174 std::vector
<PPS
> pps_list
;
177 bool ParseInternal(BufferReader
* reader
, const LogCB
& log_cb
);
180 struct MEDIA_EXPORT PixelAspectRatioBox
: Box
{
181 DECLARE_BOX_METHODS(PixelAspectRatioBox
);
187 struct MEDIA_EXPORT VideoSampleEntry
: Box
{
188 DECLARE_BOX_METHODS(VideoSampleEntry
);
191 uint16 data_reference_index
;
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
);
211 struct MEDIA_EXPORT AudioSampleEntry
: Box
{
212 DECLARE_BOX_METHODS(AudioSampleEntry
);
215 uint16 data_reference_index
;
220 ProtectionSchemeInfo sinf
;
221 ElementaryStreamDescriptor esds
;
224 struct MEDIA_EXPORT SampleDescription
: Box
{
225 DECLARE_BOX_METHODS(SampleDescription
);
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;
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
;
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
);
273 HandlerReference handler
;
274 MediaInformation information
;
277 struct MEDIA_EXPORT Track
: Box
{
278 DECLARE_BOX_METHODS(Track
);
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
);
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
);
313 MovieExtends extends
;
314 std::vector
<Track
> tracks
;
315 std::vector
<ProtectionSystemSpecificHeader
> pssh
;
318 struct MEDIA_EXPORT TrackFragmentDecodeTime
: Box
{
319 DECLARE_BOX_METHODS(TrackFragmentDecodeTime
);
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
);
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
);
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
{
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;
374 std::vector
<SampleDependsOn
> sample_depends_on_
;
377 struct MEDIA_EXPORT CencSampleEncryptionInfoEntry
{
378 CencSampleEncryptionInfoEntry();
379 ~CencSampleEncryptionInfoEntry();
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,
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
;
437 #endif // MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_