2013-09-24 01:35:40 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef MEDIA_MP4_BOX_DEFINITIONS_H_
|
|
|
|
#define MEDIA_MP4_BOX_DEFINITIONS_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "media/mp4/aac.h"
|
|
|
|
#include "media/mp4/box_reader.h"
|
|
|
|
#include "media/mp4/fourccs.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
enum TrackType {
|
|
|
|
kInvalid = 0,
|
|
|
|
kVideo,
|
|
|
|
kAudio,
|
|
|
|
kHint
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DECLARE_BOX_METHODS(T) \
|
|
|
|
T(); \
|
|
|
|
virtual ~T(); \
|
|
|
|
virtual bool Parse(BoxReader* reader) OVERRIDE; \
|
|
|
|
virtual FourCC BoxType() const OVERRIDE; \
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct FileType : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(FileType);
|
|
|
|
|
|
|
|
FourCC major_brand;
|
|
|
|
uint32 minor_version;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct ProtectionSystemSpecificHeader : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(ProtectionSystemSpecificHeader);
|
|
|
|
|
|
|
|
std::vector<uint8> system_id;
|
|
|
|
std::vector<uint8> raw_box;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct SampleAuxiliaryInformationOffset : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(SampleAuxiliaryInformationOffset);
|
|
|
|
|
|
|
|
std::vector<uint64> offsets;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct SampleAuxiliaryInformationSize : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(SampleAuxiliaryInformationSize);
|
|
|
|
|
|
|
|
uint8 default_sample_info_size;
|
|
|
|
uint32 sample_count;
|
|
|
|
std::vector<uint8> sample_info_sizes;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct OriginalFormat : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(OriginalFormat);
|
|
|
|
|
|
|
|
FourCC format;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct SchemeType : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(SchemeType);
|
|
|
|
|
|
|
|
FourCC type;
|
|
|
|
uint32 version;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct TrackEncryption : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(TrackEncryption);
|
|
|
|
|
|
|
|
// Note: this definition is specific to the CENC protection type.
|
|
|
|
bool is_encrypted;
|
|
|
|
uint8 default_iv_size;
|
|
|
|
std::vector<uint8> default_kid;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct SchemeInfo : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(SchemeInfo);
|
|
|
|
|
|
|
|
TrackEncryption track_encryption;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct ProtectionSchemeInfo : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(ProtectionSchemeInfo);
|
|
|
|
|
|
|
|
OriginalFormat format;
|
|
|
|
SchemeType type;
|
|
|
|
SchemeInfo info;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct MovieHeader : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(MovieHeader);
|
|
|
|
|
|
|
|
uint64 creation_time;
|
|
|
|
uint64 modification_time;
|
|
|
|
uint32 timescale;
|
|
|
|
uint64 duration;
|
|
|
|
int32 rate;
|
|
|
|
int16 volume;
|
|
|
|
uint32 next_track_id;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct TrackHeader : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(TrackHeader);
|
|
|
|
|
|
|
|
uint64 creation_time;
|
|
|
|
uint64 modification_time;
|
|
|
|
uint32 track_id;
|
|
|
|
uint64 duration;
|
|
|
|
int16 layer;
|
|
|
|
int16 alternate_group;
|
|
|
|
int16 volume;
|
|
|
|
uint32 width;
|
|
|
|
uint32 height;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct EditListEntry {
|
2013-09-24 01:35:40 +00:00
|
|
|
uint64 segment_duration;
|
|
|
|
int64 media_time;
|
|
|
|
int16 media_rate_integer;
|
|
|
|
int16 media_rate_fraction;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct EditList : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(EditList);
|
|
|
|
|
|
|
|
std::vector<EditListEntry> edits;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct Edit : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(Edit);
|
|
|
|
|
|
|
|
EditList list;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct HandlerReference : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(HandlerReference);
|
|
|
|
|
|
|
|
TrackType type;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct AVCDecoderConfigurationRecord : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(AVCDecoderConfigurationRecord);
|
2013-10-14 20:55:48 +00:00
|
|
|
bool ParseData(BufferReader* reader);
|
|
|
|
|
|
|
|
// Contains full avc decoder configuration record as defined in iso14496-15
|
|
|
|
// 5.2.4.1, including possible extension bytes described in paragraph 3.
|
|
|
|
// Known fields defined in the spec are also parsed and included in this
|
|
|
|
// structure.
|
|
|
|
std::vector<uint8> data;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
uint8 version;
|
|
|
|
uint8 profile_indication;
|
|
|
|
uint8 profile_compatibility;
|
|
|
|
uint8 avc_level;
|
|
|
|
uint8 length_size;
|
|
|
|
|
|
|
|
typedef std::vector<uint8> SPS;
|
|
|
|
typedef std::vector<uint8> PPS;
|
|
|
|
|
|
|
|
std::vector<SPS> sps_list;
|
|
|
|
std::vector<PPS> pps_list;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct PixelAspectRatioBox : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(PixelAspectRatioBox);
|
|
|
|
|
|
|
|
uint32 h_spacing;
|
|
|
|
uint32 v_spacing;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct VideoSampleEntry : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(VideoSampleEntry);
|
|
|
|
|
|
|
|
FourCC format;
|
|
|
|
uint16 data_reference_index;
|
|
|
|
uint16 width;
|
|
|
|
uint16 height;
|
|
|
|
|
|
|
|
PixelAspectRatioBox pixel_aspect;
|
|
|
|
ProtectionSchemeInfo sinf;
|
|
|
|
|
|
|
|
// Currently expected to be present regardless of format.
|
|
|
|
AVCDecoderConfigurationRecord avcc;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct ElementaryStreamDescriptor : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(ElementaryStreamDescriptor);
|
|
|
|
|
|
|
|
uint8 object_type;
|
|
|
|
AAC aac;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct AudioSampleEntry : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(AudioSampleEntry);
|
|
|
|
|
|
|
|
FourCC format;
|
|
|
|
uint16 data_reference_index;
|
|
|
|
uint16 channelcount;
|
|
|
|
uint16 samplesize;
|
|
|
|
uint32 samplerate;
|
|
|
|
|
|
|
|
ProtectionSchemeInfo sinf;
|
|
|
|
ElementaryStreamDescriptor esds;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct SampleDescription : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(SampleDescription);
|
|
|
|
|
|
|
|
TrackType type;
|
|
|
|
std::vector<VideoSampleEntry> video_entries;
|
|
|
|
std::vector<AudioSampleEntry> audio_entries;
|
|
|
|
};
|
|
|
|
|
2013-10-08 17:37:58 +00:00
|
|
|
struct DecodingTime {
|
|
|
|
uint32 sample_count;
|
|
|
|
uint32 sample_delta;
|
|
|
|
};
|
|
|
|
|
|
|
|
// stts.
|
|
|
|
struct DecodingTimeToSample : Box {
|
|
|
|
DECLARE_BOX_METHODS(DecodingTimeToSample);
|
|
|
|
|
|
|
|
std::vector<DecodingTime> decoding_time;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CompositionOffset {
|
|
|
|
uint32 sample_count;
|
|
|
|
// If version == 0, sample_offset is uint32;
|
|
|
|
// If version == 1, sample_offset is int32.
|
|
|
|
// Let us always use signed version, which should work unless the offset
|
|
|
|
// exceeds 31 bits, which shouldn't happen.
|
|
|
|
int32 sample_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ctts. Optional.
|
|
|
|
struct CompositionTimeToSample : Box {
|
|
|
|
DECLARE_BOX_METHODS(CompositionTimeToSample);
|
|
|
|
|
|
|
|
std::vector<CompositionOffset> composition_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChunkInfo {
|
|
|
|
uint32 first_chunk;
|
|
|
|
uint32 samples_per_chunk;
|
|
|
|
uint32 sample_description_index;
|
|
|
|
};
|
|
|
|
|
|
|
|
// stsc.
|
|
|
|
struct SampleToChunk : Box {
|
|
|
|
DECLARE_BOX_METHODS(SampleToChunk);
|
|
|
|
|
|
|
|
std::vector<ChunkInfo> chunk_info;
|
|
|
|
};
|
|
|
|
|
|
|
|
// stsz.
|
|
|
|
struct SampleSize : Box {
|
|
|
|
DECLARE_BOX_METHODS(SampleSize);
|
|
|
|
|
|
|
|
uint32 sample_size;
|
|
|
|
uint32 sample_count;
|
|
|
|
std::vector<uint32> sizes;
|
|
|
|
};
|
|
|
|
|
|
|
|
// stz2.
|
|
|
|
struct CompactSampleSize : SampleSize {
|
|
|
|
DECLARE_BOX_METHODS(CompactSampleSize);
|
|
|
|
};
|
|
|
|
|
|
|
|
// stco.
|
|
|
|
struct ChunkOffset : Box {
|
|
|
|
DECLARE_BOX_METHODS(ChunkOffset);
|
|
|
|
|
|
|
|
// Chunk byte offsets into mdat relative to the beginning of the file.
|
|
|
|
// Use 64 bits instead of 32 bits so it is large enough to hold
|
|
|
|
// ChunkLargeOffset data.
|
|
|
|
std::vector<uint64> offsets;
|
|
|
|
};
|
|
|
|
|
|
|
|
// co64.
|
|
|
|
struct ChunkLargeOffset : ChunkOffset {
|
|
|
|
DECLARE_BOX_METHODS(ChunkLargeOffset);
|
|
|
|
};
|
|
|
|
|
|
|
|
// stss. Optional.
|
|
|
|
struct SyncSample : Box {
|
|
|
|
DECLARE_BOX_METHODS(SyncSample);
|
|
|
|
|
|
|
|
std::vector<uint32> sample_number;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct SampleTable : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(SampleTable);
|
|
|
|
|
|
|
|
SampleDescription description;
|
2013-10-08 17:37:58 +00:00
|
|
|
DecodingTimeToSample decoding_time_to_sample;
|
|
|
|
CompositionTimeToSample composition_time_to_sample;
|
|
|
|
SampleToChunk sample_to_chunk;
|
|
|
|
// Either SampleSize or CompactSampleSize must present. Store in SampleSize.
|
|
|
|
SampleSize sample_size;
|
|
|
|
// Either ChunkOffset or ChunkLargeOffset must present. Store in ChunkOffset.
|
|
|
|
ChunkOffset chunk_offset;
|
|
|
|
SyncSample sync_sample;
|
2013-09-24 01:35:40 +00:00
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct MediaHeader : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(MediaHeader);
|
|
|
|
|
|
|
|
uint64 creation_time;
|
|
|
|
uint64 modification_time;
|
|
|
|
uint32 timescale;
|
|
|
|
uint64 duration;
|
2013-10-14 20:55:48 +00:00
|
|
|
// 3-char language code + 1 null terminating char.
|
|
|
|
char language[4];
|
2013-09-24 01:35:40 +00:00
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct MediaInformation : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(MediaInformation);
|
|
|
|
|
|
|
|
SampleTable sample_table;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct Media : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(Media);
|
|
|
|
|
|
|
|
MediaHeader header;
|
|
|
|
HandlerReference handler;
|
|
|
|
MediaInformation information;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct Track : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(Track);
|
|
|
|
|
|
|
|
TrackHeader header;
|
|
|
|
Media media;
|
|
|
|
Edit edit;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct MovieExtendsHeader : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(MovieExtendsHeader);
|
|
|
|
|
|
|
|
uint64 fragment_duration;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct TrackExtends : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(TrackExtends);
|
|
|
|
|
|
|
|
uint32 track_id;
|
|
|
|
uint32 default_sample_description_index;
|
|
|
|
uint32 default_sample_duration;
|
|
|
|
uint32 default_sample_size;
|
|
|
|
uint32 default_sample_flags;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct MovieExtends : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(MovieExtends);
|
|
|
|
|
|
|
|
MovieExtendsHeader header;
|
|
|
|
std::vector<TrackExtends> tracks;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct Movie : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(Movie);
|
|
|
|
|
|
|
|
bool fragmented;
|
|
|
|
MovieHeader header;
|
|
|
|
MovieExtends extends;
|
|
|
|
std::vector<Track> tracks;
|
|
|
|
std::vector<ProtectionSystemSpecificHeader> pssh;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct TrackFragmentDecodeTime : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(TrackFragmentDecodeTime);
|
|
|
|
|
|
|
|
uint64 decode_time;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct MovieFragmentHeader : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(MovieFragmentHeader);
|
|
|
|
|
|
|
|
uint32 sequence_number;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct TrackFragmentHeader : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(TrackFragmentHeader);
|
|
|
|
|
|
|
|
uint32 track_id;
|
|
|
|
|
|
|
|
uint32 sample_description_index;
|
|
|
|
uint32 default_sample_duration;
|
|
|
|
uint32 default_sample_size;
|
|
|
|
uint32 default_sample_flags;
|
|
|
|
|
|
|
|
// As 'flags' might be all zero, we cannot use zeroness alone to identify
|
|
|
|
// when default_sample_flags wasn't specified, unlike the other values.
|
|
|
|
bool has_default_sample_flags;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct TrackFragmentRun : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(TrackFragmentRun);
|
|
|
|
|
|
|
|
uint32 sample_count;
|
|
|
|
uint32 data_offset;
|
|
|
|
std::vector<uint32> sample_flags;
|
|
|
|
std::vector<uint32> sample_sizes;
|
|
|
|
std::vector<uint32> sample_durations;
|
|
|
|
std::vector<int32> sample_composition_time_offsets;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct TrackFragment : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(TrackFragment);
|
|
|
|
|
|
|
|
TrackFragmentHeader header;
|
|
|
|
std::vector<TrackFragmentRun> runs;
|
|
|
|
TrackFragmentDecodeTime decode_time;
|
|
|
|
SampleAuxiliaryInformationOffset auxiliary_offset;
|
|
|
|
SampleAuxiliaryInformationSize auxiliary_size;
|
|
|
|
};
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
struct MovieFragment : Box {
|
2013-09-24 01:35:40 +00:00
|
|
|
DECLARE_BOX_METHODS(MovieFragment);
|
|
|
|
|
|
|
|
MovieFragmentHeader header;
|
|
|
|
std::vector<TrackFragment> tracks;
|
|
|
|
std::vector<ProtectionSystemSpecificHeader> pssh;
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef DECLARE_BOX
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
|
|
|
|
|
|
|
#endif // MEDIA_MP4_BOX_DEFINITIONS_H_
|