| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/mp4/box_definitions.h" | 5 #include "media/mp4/box_definitions.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/mp4/es_descriptor.h" | 8 #include "media/mp4/es_descriptor.h" |
| 9 #include "media/mp4/rcheck.h" | 9 #include "media/mp4/rcheck.h" |
| 10 | 10 |
| 11 namespace media { | 11 namespace media { |
| 12 namespace mp4 { | 12 namespace mp4 { |
| 13 | 13 |
| 14 FileType::FileType() {} | 14 FileType::FileType() {} |
| 15 FileType::~FileType() {} | 15 FileType::~FileType() {} |
| 16 FourCC FileType::BoxType() const { return FOURCC_FTYP; } | 16 FourCC FileType::BoxType() const { return FOURCC_FTYP; } |
| 17 | 17 |
| 18 bool FileType::Parse(BoxReader* reader) { | 18 bool FileType::Parse(BoxReader* reader) { |
| 19 RCHECK(reader->ReadFourCC(&major_brand) && reader->Read4(&minor_version)); | 19 RCHECK(reader->ReadFourCC(&major_brand) && reader->Read4(&minor_version)); |
| 20 size_t num_brands = (reader->size() - reader->pos()) / sizeof(FourCC); | 20 size_t num_brands = (reader->size() - reader->pos()) / sizeof(FourCC); |
| 21 return reader->SkipBytes(sizeof(FourCC) * num_brands); // compatible_brands | 21 return reader->SkipBytes(sizeof(FourCC) * num_brands); // compatible_brands |
| 22 } | 22 } |
| 23 | 23 |
| 24 ProtectionSystemSpecificHeader::ProtectionSystemSpecificHeader() {} | 24 ProtectionSystemSpecificHeader::ProtectionSystemSpecificHeader() {} |
| 25 ProtectionSystemSpecificHeader::~ProtectionSystemSpecificHeader() {} | 25 ProtectionSystemSpecificHeader::~ProtectionSystemSpecificHeader() {} |
| 26 FourCC ProtectionSystemSpecificHeader::BoxType() const { return FOURCC_PSSH; } | 26 FourCC ProtectionSystemSpecificHeader::BoxType() const { return FOURCC_PSSH; } |
| 27 | 27 |
| 28 bool ProtectionSystemSpecificHeader::Parse(BoxReader* reader) { | 28 bool ProtectionSystemSpecificHeader::Parse(BoxReader* reader) { |
| 29 uint32 size; | 29 uint32 size; |
| 30 return reader->SkipBytes(4) && | 30 return reader->ReadFullBoxHeader() && |
| 31 reader->ReadVec(&system_id, 16) && | 31 reader->ReadVec(&system_id, 16) && |
| 32 reader->Read4(&size) && | 32 reader->Read4(&size) && |
| 33 reader->ReadVec(&data, size); | 33 reader->ReadVec(&data, size); |
| 34 } | 34 } |
| 35 | 35 |
| 36 SampleAuxiliaryInformationOffset::SampleAuxiliaryInformationOffset() {} | 36 SampleAuxiliaryInformationOffset::SampleAuxiliaryInformationOffset() {} |
| 37 SampleAuxiliaryInformationOffset::~SampleAuxiliaryInformationOffset() {} | 37 SampleAuxiliaryInformationOffset::~SampleAuxiliaryInformationOffset() {} |
| 38 FourCC SampleAuxiliaryInformationOffset::BoxType() const { return FOURCC_SAIO; } | 38 FourCC SampleAuxiliaryInformationOffset::BoxType() const { return FOURCC_SAIO; } |
| 39 | 39 |
| 40 bool SampleAuxiliaryInformationOffset::Parse(BoxReader* reader) { | 40 bool SampleAuxiliaryInformationOffset::Parse(BoxReader* reader) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 bool OriginalFormat::Parse(BoxReader* reader) { | 82 bool OriginalFormat::Parse(BoxReader* reader) { |
| 83 return reader->ReadFourCC(&format); | 83 return reader->ReadFourCC(&format); |
| 84 } | 84 } |
| 85 | 85 |
| 86 SchemeType::SchemeType() : type(FOURCC_NULL), version(0) {} | 86 SchemeType::SchemeType() : type(FOURCC_NULL), version(0) {} |
| 87 SchemeType::~SchemeType() {} | 87 SchemeType::~SchemeType() {} |
| 88 FourCC SchemeType::BoxType() const { return FOURCC_SCHM; } | 88 FourCC SchemeType::BoxType() const { return FOURCC_SCHM; } |
| 89 | 89 |
| 90 bool SchemeType::Parse(BoxReader* reader) { | 90 bool SchemeType::Parse(BoxReader* reader) { |
| 91 RCHECK(reader->SkipBytes(4) && | 91 RCHECK(reader->ReadFullBoxHeader() && |
| 92 reader->ReadFourCC(&type) && | 92 reader->ReadFourCC(&type) && |
| 93 reader->Read4(&version)); | 93 reader->Read4(&version)); |
| 94 RCHECK(type == FOURCC_CENC); | 94 RCHECK(type == FOURCC_CENC); |
| 95 return true; | 95 return true; |
| 96 } | 96 } |
| 97 | 97 |
| 98 TrackEncryption::TrackEncryption() | 98 TrackEncryption::TrackEncryption() |
| 99 : is_encrypted(false), default_iv_size(0) { | 99 : is_encrypted(false), default_iv_size(0) { |
| 100 } | 100 } |
| 101 TrackEncryption::~TrackEncryption() {} | 101 TrackEncryption::~TrackEncryption() {} |
| 102 FourCC TrackEncryption::BoxType() const { return FOURCC_TENC; } | 102 FourCC TrackEncryption::BoxType() const { return FOURCC_TENC; } |
| 103 | 103 |
| 104 bool TrackEncryption::Parse(BoxReader* reader) { | 104 bool TrackEncryption::Parse(BoxReader* reader) { |
| 105 uint8 flag; | 105 uint8 flag; |
| 106 RCHECK(reader->SkipBytes(2) && | 106 RCHECK(reader->ReadFullBoxHeader() && |
| 107 reader->SkipBytes(2) && |
| 107 reader->Read1(&flag) && | 108 reader->Read1(&flag) && |
| 108 reader->Read1(&default_iv_size) && | 109 reader->Read1(&default_iv_size) && |
| 109 reader->ReadVec(&default_kid, 16)); | 110 reader->ReadVec(&default_kid, 16)); |
| 110 is_encrypted = (flag != 0); | 111 is_encrypted = (flag != 0); |
| 111 if (is_encrypted) { | 112 if (is_encrypted) { |
| 112 RCHECK(default_iv_size == 8 || default_iv_size == 16); | 113 RCHECK(default_iv_size == 8 || default_iv_size == 16); |
| 113 } else { | 114 } else { |
| 114 RCHECK(default_iv_size == 0); | 115 RCHECK(default_iv_size == 0); |
| 115 } | 116 } |
| 116 return true; | 117 return true; |
| 117 } | 118 } |
| 118 | 119 |
| 119 SchemeInfo::SchemeInfo() {} | 120 SchemeInfo::SchemeInfo() {} |
| 120 SchemeInfo::~SchemeInfo() {} | 121 SchemeInfo::~SchemeInfo() {} |
| 121 FourCC SchemeInfo::BoxType() const { return FOURCC_SCHI; } | 122 FourCC SchemeInfo::BoxType() const { return FOURCC_SCHI; } |
| 122 | 123 |
| 123 bool SchemeInfo::Parse(BoxReader* reader) { | 124 bool SchemeInfo::Parse(BoxReader* reader) { |
| 124 return reader->ScanChildren() && reader->ReadChild(&track_encryption); | 125 return reader->ScanChildren() && reader->ReadChild(&track_encryption); |
| 125 } | 126 } |
| 126 | 127 |
| 127 ProtectionSchemeInfo::ProtectionSchemeInfo() {} | 128 ProtectionSchemeInfo::ProtectionSchemeInfo() {} |
| 128 ProtectionSchemeInfo::~ProtectionSchemeInfo() {} | 129 ProtectionSchemeInfo::~ProtectionSchemeInfo() {} |
| 129 FourCC ProtectionSchemeInfo::BoxType() const { return FOURCC_SINF; } | 130 FourCC ProtectionSchemeInfo::BoxType() const { return FOURCC_SINF; } |
| 130 | 131 |
| 131 bool ProtectionSchemeInfo::Parse(BoxReader* reader) { | 132 bool ProtectionSchemeInfo::Parse(BoxReader* reader) { |
| 132 return reader->ScanChildren() && | 133 RCHECK(reader->ScanChildren() && |
| 134 reader->ReadChild(&format) && |
| 133 reader->ReadChild(&type) && | 135 reader->ReadChild(&type) && |
| 134 reader->ReadChild(&info); | 136 reader->ReadChild(&info)); |
| 137 return true; |
| 135 } | 138 } |
| 136 | 139 |
| 137 MovieHeader::MovieHeader() | 140 MovieHeader::MovieHeader() |
| 138 : creation_time(0), | 141 : creation_time(0), |
| 139 modification_time(0), | 142 modification_time(0), |
| 140 timescale(0), | 143 timescale(0), |
| 141 duration(0), | 144 duration(0), |
| 142 rate(-1), | 145 rate(-1), |
| 143 volume(-1), | 146 volume(-1), |
| 144 next_track_id(0) {} | 147 next_track_id(0) {} |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 371 |
| 369 bool VideoSampleEntry::Parse(BoxReader* reader) { | 372 bool VideoSampleEntry::Parse(BoxReader* reader) { |
| 370 format = reader->type(); | 373 format = reader->type(); |
| 371 RCHECK(reader->SkipBytes(6) && | 374 RCHECK(reader->SkipBytes(6) && |
| 372 reader->Read2(&data_reference_index) && | 375 reader->Read2(&data_reference_index) && |
| 373 reader->SkipBytes(16) && | 376 reader->SkipBytes(16) && |
| 374 reader->Read2(&width) && | 377 reader->Read2(&width) && |
| 375 reader->Read2(&height) && | 378 reader->Read2(&height) && |
| 376 reader->SkipBytes(50)); | 379 reader->SkipBytes(50)); |
| 377 | 380 |
| 378 RCHECK(reader->ScanChildren()); | 381 RCHECK(reader->ScanChildren() && |
| 379 RCHECK(reader->MaybeReadChild(&pixel_aspect)); | 382 reader->MaybeReadChild(&pixel_aspect)); |
| 380 if (format == FOURCC_ENCV) { | 383 |
| 384 if (format == FOURCC_ENCV) |
| 381 RCHECK(reader->ReadChild(&sinf)); | 385 RCHECK(reader->ReadChild(&sinf)); |
| 386 if (format == FOURCC_AVC1 || |
| 387 (format == FOURCC_ENCV && sinf.format.format == FOURCC_AVC1)) { |
| 388 RCHECK(reader->ReadChild(&avcc)); |
| 382 } | 389 } |
| 383 | |
| 384 // TODO(strobe): finalize format signaling for encrypted media | |
| 385 // (http://crbug.com/132351) | |
| 386 // | |
| 387 // if (format == FOURCC_AVC1 || | |
| 388 // (format == FOURCC_ENCV && | |
| 389 // sinf.format.format == FOURCC_AVC1)) { | |
| 390 RCHECK(reader->ReadChild(&avcc)); | |
| 391 // } | |
| 392 return true; | 390 return true; |
| 393 } | 391 } |
| 394 | 392 |
| 395 ElementaryStreamDescriptor::ElementaryStreamDescriptor() | 393 ElementaryStreamDescriptor::ElementaryStreamDescriptor() |
| 396 : object_type(kForbidden) {} | 394 : object_type(kForbidden) {} |
| 397 | 395 |
| 398 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} | 396 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} |
| 399 | 397 |
| 400 FourCC ElementaryStreamDescriptor::BoxType() const { | 398 FourCC ElementaryStreamDescriptor::BoxType() const { |
| 401 return FOURCC_ESDS; | 399 return FOURCC_ESDS; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 reader->Read2(&data_reference_index) && | 435 reader->Read2(&data_reference_index) && |
| 438 reader->SkipBytes(8) && | 436 reader->SkipBytes(8) && |
| 439 reader->Read2(&channelcount) && | 437 reader->Read2(&channelcount) && |
| 440 reader->Read2(&samplesize) && | 438 reader->Read2(&samplesize) && |
| 441 reader->SkipBytes(4) && | 439 reader->SkipBytes(4) && |
| 442 reader->Read4(&samplerate)); | 440 reader->Read4(&samplerate)); |
| 443 // Convert from 16.16 fixed point to integer | 441 // Convert from 16.16 fixed point to integer |
| 444 samplerate >>= 16; | 442 samplerate >>= 16; |
| 445 | 443 |
| 446 RCHECK(reader->ScanChildren()); | 444 RCHECK(reader->ScanChildren()); |
| 447 if (format == FOURCC_ENCA) { | 445 if (format == FOURCC_ENCA) |
| 448 RCHECK(reader->ReadChild(&sinf)); | 446 RCHECK(reader->ReadChild(&sinf)); |
| 449 } | |
| 450 RCHECK(reader->ReadChild(&esds)); | 447 RCHECK(reader->ReadChild(&esds)); |
| 451 return true; | 448 return true; |
| 452 } | 449 } |
| 453 | 450 |
| 454 MediaHeader::MediaHeader() | 451 MediaHeader::MediaHeader() |
| 455 : creation_time(0), | 452 : creation_time(0), |
| 456 modification_time(0), | 453 modification_time(0), |
| 457 timescale(0), | 454 timescale(0), |
| 458 duration(0) {} | 455 duration(0) {} |
| 459 MediaHeader::~MediaHeader() {} | 456 MediaHeader::~MediaHeader() {} |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 bool MovieFragment::Parse(BoxReader* reader) { | 723 bool MovieFragment::Parse(BoxReader* reader) { |
| 727 RCHECK(reader->ScanChildren() && | 724 RCHECK(reader->ScanChildren() && |
| 728 reader->ReadChild(&header) && | 725 reader->ReadChild(&header) && |
| 729 reader->ReadChildren(&tracks) && | 726 reader->ReadChildren(&tracks) && |
| 730 reader->MaybeReadChildren(&pssh)); | 727 reader->MaybeReadChildren(&pssh)); |
| 731 return true; | 728 return true; |
| 732 } | 729 } |
| 733 | 730 |
| 734 } // namespace mp4 | 731 } // namespace mp4 |
| 735 } // namespace media | 732 } // namespace media |
| OLD | NEW |