box_definitions.h revision 010d83a9304c5a91596085d917d248abff47903a
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. 4 5#ifndef MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_ 6#define MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_ 7 8#include <string> 9#include <vector> 10 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" 18 19namespace media { 20namespace mp4 { 21 22enum TrackType { 23 kInvalid = 0, 24 kVideo, 25 kAudio, 26 kHint 27}; 28 29#define DECLARE_BOX_METHODS(T) \ 30 T(); \ 31 virtual ~T(); \ 32 virtual bool Parse(BoxReader* reader) OVERRIDE; \ 33 virtual FourCC BoxType() const OVERRIDE; \ 34 35struct MEDIA_EXPORT FileType : Box { 36 DECLARE_BOX_METHODS(FileType); 37 38 FourCC major_brand; 39 uint32 minor_version; 40}; 41 42struct MEDIA_EXPORT ProtectionSystemSpecificHeader : Box { 43 DECLARE_BOX_METHODS(ProtectionSystemSpecificHeader); 44 45 std::vector<uint8> system_id; 46 std::vector<uint8> raw_box; 47}; 48 49struct MEDIA_EXPORT SampleAuxiliaryInformationOffset : Box { 50 DECLARE_BOX_METHODS(SampleAuxiliaryInformationOffset); 51 52 std::vector<uint64> offsets; 53}; 54 55struct MEDIA_EXPORT SampleAuxiliaryInformationSize : Box { 56 DECLARE_BOX_METHODS(SampleAuxiliaryInformationSize); 57 58 uint8 default_sample_info_size; 59 uint32 sample_count; 60 std::vector<uint8> sample_info_sizes; 61}; 62 63struct MEDIA_EXPORT OriginalFormat : Box { 64 DECLARE_BOX_METHODS(OriginalFormat); 65 66 FourCC format; 67}; 68 69struct MEDIA_EXPORT SchemeType : Box { 70 DECLARE_BOX_METHODS(SchemeType); 71 72 FourCC type; 73 uint32 version; 74}; 75 76struct MEDIA_EXPORT TrackEncryption : Box { 77 DECLARE_BOX_METHODS(TrackEncryption); 78 79 // Note: this definition is specific to the CENC protection type. 80 bool is_encrypted; 81 uint8 default_iv_size; 82 std::vector<uint8> default_kid; 83}; 84 85struct MEDIA_EXPORT SchemeInfo : Box { 86 DECLARE_BOX_METHODS(SchemeInfo); 87 88 TrackEncryption track_encryption; 89}; 90 91struct MEDIA_EXPORT ProtectionSchemeInfo : Box { 92 DECLARE_BOX_METHODS(ProtectionSchemeInfo); 93 94 OriginalFormat format; 95 SchemeType type; 96 SchemeInfo info; 97}; 98 99struct MEDIA_EXPORT MovieHeader : Box { 100 DECLARE_BOX_METHODS(MovieHeader); 101 102 uint64 creation_time; 103 uint64 modification_time; 104 uint32 timescale; 105 uint64 duration; 106 int32 rate; 107 int16 volume; 108 uint32 next_track_id; 109}; 110 111struct MEDIA_EXPORT TrackHeader : Box { 112 DECLARE_BOX_METHODS(TrackHeader); 113 114 uint64 creation_time; 115 uint64 modification_time; 116 uint32 track_id; 117 uint64 duration; 118 int16 layer; 119 int16 alternate_group; 120 int16 volume; 121 uint32 width; 122 uint32 height; 123}; 124 125struct MEDIA_EXPORT EditListEntry { 126 uint64 segment_duration; 127 int64 media_time; 128 int16 media_rate_integer; 129 int16 media_rate_fraction; 130}; 131 132struct MEDIA_EXPORT EditList : Box { 133 DECLARE_BOX_METHODS(EditList); 134 135 std::vector<EditListEntry> edits; 136}; 137 138struct MEDIA_EXPORT Edit : Box { 139 DECLARE_BOX_METHODS(Edit); 140 141 EditList list; 142}; 143 144struct MEDIA_EXPORT HandlerReference : Box { 145 DECLARE_BOX_METHODS(HandlerReference); 146 147 TrackType type; 148}; 149 150struct MEDIA_EXPORT AVCDecoderConfigurationRecord : Box { 151 DECLARE_BOX_METHODS(AVCDecoderConfigurationRecord); 152 153 // Parses AVCDecoderConfigurationRecord data encoded in |data|. 154 // Note: This method is intended to parse data outside the MP4StreamParser 155 // context and therefore the box header is not expected to be present 156 // in |data|. 157 // Returns true if |data| was successfully parsed. 158 bool Parse(const uint8* data, int data_size); 159 160 uint8 version; 161 uint8 profile_indication; 162 uint8 profile_compatibility; 163 uint8 avc_level; 164 uint8 length_size; 165 166 typedef std::vector<uint8> SPS; 167 typedef std::vector<uint8> PPS; 168 169 std::vector<SPS> sps_list; 170 std::vector<PPS> pps_list; 171 172 private: 173 bool ParseInternal(BufferReader* reader, const LogCB& log_cb); 174}; 175 176struct MEDIA_EXPORT PixelAspectRatioBox : Box { 177 DECLARE_BOX_METHODS(PixelAspectRatioBox); 178 179 uint32 h_spacing; 180 uint32 v_spacing; 181}; 182 183struct MEDIA_EXPORT VideoSampleEntry : Box { 184 DECLARE_BOX_METHODS(VideoSampleEntry); 185 186 FourCC format; 187 uint16 data_reference_index; 188 uint16 width; 189 uint16 height; 190 191 PixelAspectRatioBox pixel_aspect; 192 ProtectionSchemeInfo sinf; 193 194 // Currently expected to be present regardless of format. 195 AVCDecoderConfigurationRecord avcc; 196 197 bool IsFormatValid() const; 198}; 199 200struct MEDIA_EXPORT ElementaryStreamDescriptor : Box { 201 DECLARE_BOX_METHODS(ElementaryStreamDescriptor); 202 203 uint8 object_type; 204 AAC aac; 205}; 206 207struct MEDIA_EXPORT AudioSampleEntry : Box { 208 DECLARE_BOX_METHODS(AudioSampleEntry); 209 210 FourCC format; 211 uint16 data_reference_index; 212 uint16 channelcount; 213 uint16 samplesize; 214 uint32 samplerate; 215 216 ProtectionSchemeInfo sinf; 217 ElementaryStreamDescriptor esds; 218}; 219 220struct MEDIA_EXPORT SampleDescription : Box { 221 DECLARE_BOX_METHODS(SampleDescription); 222 223 TrackType type; 224 std::vector<VideoSampleEntry> video_entries; 225 std::vector<AudioSampleEntry> audio_entries; 226}; 227 228struct MEDIA_EXPORT SyncSample : Box { 229 DECLARE_BOX_METHODS(SyncSample); 230 231 bool is_present; 232}; 233 234struct MEDIA_EXPORT SampleTable : Box { 235 DECLARE_BOX_METHODS(SampleTable); 236 237 // Media Source specific: we ignore many of the sub-boxes in this box, 238 // including some that are required to be present in the BMFF spec. This 239 // includes the 'stts', 'stsc', and 'stco' boxes, which must contain no 240 // samples in order to be compliant files. 241 SampleDescription description; 242 SyncSample sync_sample; 243}; 244 245struct MEDIA_EXPORT MediaHeader : Box { 246 DECLARE_BOX_METHODS(MediaHeader); 247 248 uint64 creation_time; 249 uint64 modification_time; 250 uint32 timescale; 251 uint64 duration; 252}; 253 254struct MEDIA_EXPORT MediaInformation : Box { 255 DECLARE_BOX_METHODS(MediaInformation); 256 257 SampleTable sample_table; 258}; 259 260struct MEDIA_EXPORT Media : Box { 261 DECLARE_BOX_METHODS(Media); 262 263 MediaHeader header; 264 HandlerReference handler; 265 MediaInformation information; 266}; 267 268struct MEDIA_EXPORT Track : Box { 269 DECLARE_BOX_METHODS(Track); 270 271 TrackHeader header; 272 Media media; 273 Edit edit; 274}; 275 276struct MEDIA_EXPORT MovieExtendsHeader : Box { 277 DECLARE_BOX_METHODS(MovieExtendsHeader); 278 279 uint64 fragment_duration; 280}; 281 282struct MEDIA_EXPORT TrackExtends : Box { 283 DECLARE_BOX_METHODS(TrackExtends); 284 285 uint32 track_id; 286 uint32 default_sample_description_index; 287 uint32 default_sample_duration; 288 uint32 default_sample_size; 289 uint32 default_sample_flags; 290}; 291 292struct MEDIA_EXPORT MovieExtends : Box { 293 DECLARE_BOX_METHODS(MovieExtends); 294 295 MovieExtendsHeader header; 296 std::vector<TrackExtends> tracks; 297}; 298 299struct MEDIA_EXPORT Movie : Box { 300 DECLARE_BOX_METHODS(Movie); 301 302 bool fragmented; 303 MovieHeader header; 304 MovieExtends extends; 305 std::vector<Track> tracks; 306 std::vector<ProtectionSystemSpecificHeader> pssh; 307}; 308 309struct MEDIA_EXPORT TrackFragmentDecodeTime : Box { 310 DECLARE_BOX_METHODS(TrackFragmentDecodeTime); 311 312 uint64 decode_time; 313}; 314 315struct MEDIA_EXPORT MovieFragmentHeader : Box { 316 DECLARE_BOX_METHODS(MovieFragmentHeader); 317 318 uint32 sequence_number; 319}; 320 321struct MEDIA_EXPORT TrackFragmentHeader : Box { 322 DECLARE_BOX_METHODS(TrackFragmentHeader); 323 324 uint32 track_id; 325 326 uint32 sample_description_index; 327 uint32 default_sample_duration; 328 uint32 default_sample_size; 329 uint32 default_sample_flags; 330 331 // As 'flags' might be all zero, we cannot use zeroness alone to identify 332 // when default_sample_flags wasn't specified, unlike the other values. 333 bool has_default_sample_flags; 334}; 335 336struct MEDIA_EXPORT TrackFragmentRun : Box { 337 DECLARE_BOX_METHODS(TrackFragmentRun); 338 339 uint32 sample_count; 340 uint32 data_offset; 341 std::vector<uint32> sample_flags; 342 std::vector<uint32> sample_sizes; 343 std::vector<uint32> sample_durations; 344 std::vector<int32> sample_composition_time_offsets; 345}; 346 347// sample_depends_on values in ISO/IEC 14496-12 Section 8.40.2.3. 348enum SampleDependsOn { 349 kSampleDependsOnUnknown = 0, 350 kSampleDependsOnOthers = 1, 351 kSampleDependsOnNoOther = 2, 352 kSampleDependsOnReserved = 3, 353}; 354 355class MEDIA_EXPORT IndependentAndDisposableSamples : public Box { 356 public: 357 DECLARE_BOX_METHODS(IndependentAndDisposableSamples); 358 359 // Returns the SampleDependsOn value for the |i|'th value 360 // in the track. If no data was parsed for the |i|'th sample, 361 // then |kSampleDependsOnUnknown| is returned. 362 SampleDependsOn sample_depends_on(size_t i) const; 363 364 private: 365 std::vector<SampleDependsOn> sample_depends_on_; 366}; 367 368struct MEDIA_EXPORT CencSampleEncryptionInfoEntry { 369 CencSampleEncryptionInfoEntry(); 370 ~CencSampleEncryptionInfoEntry(); 371 372 bool is_encrypted; 373 uint8 iv_size; 374 std::vector<uint8> key_id; 375}; 376 377struct MEDIA_EXPORT SampleGroupDescription : Box { // 'sgpd'. 378 DECLARE_BOX_METHODS(SampleGroupDescription); 379 380 uint32 grouping_type; 381 std::vector<CencSampleEncryptionInfoEntry> entries; 382}; 383 384struct MEDIA_EXPORT SampleToGroupEntry { 385 enum GroupDescriptionIndexBase { 386 kTrackGroupDescriptionIndexBase = 0, 387 kFragmentGroupDescriptionIndexBase = 0x10000, 388 }; 389 390 uint32 sample_count; 391 uint32 group_description_index; 392}; 393 394struct MEDIA_EXPORT SampleToGroup : Box { // 'sbgp'. 395 DECLARE_BOX_METHODS(SampleToGroup); 396 397 uint32 grouping_type; 398 uint32 grouping_type_parameter; // Version 1 only. 399 std::vector<SampleToGroupEntry> entries; 400}; 401 402struct MEDIA_EXPORT TrackFragment : Box { 403 DECLARE_BOX_METHODS(TrackFragment); 404 405 TrackFragmentHeader header; 406 std::vector<TrackFragmentRun> runs; 407 TrackFragmentDecodeTime decode_time; 408 SampleAuxiliaryInformationOffset auxiliary_offset; 409 SampleAuxiliaryInformationSize auxiliary_size; 410 IndependentAndDisposableSamples sdtp; 411 SampleGroupDescription sample_group_description; 412 SampleToGroup sample_to_group; 413}; 414 415struct MEDIA_EXPORT MovieFragment : Box { 416 DECLARE_BOX_METHODS(MovieFragment); 417 418 MovieFragmentHeader header; 419 std::vector<TrackFragment> tracks; 420 std::vector<ProtectionSystemSpecificHeader> pssh; 421}; 422 423#undef DECLARE_BOX 424 425} // namespace mp4 426} // namespace media 427 428#endif // MEDIA_FORMATS_MP4_BOX_DEFINITIONS_H_ 429