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 bool FileType::Parse(BoxReader* reader) { | 14 bool FileType::Parse(BoxReader* reader) { |
15 RCHECK(reader->ReadFourCC(&major_brand) && reader->Read4(&minor_version)); | 15 RCHECK(reader->ReadFourCC(&major_brand) && reader->Read4(&minor_version)); |
16 size_t num_brands = (reader->size() - reader->pos()) / sizeof(FourCC); | 16 size_t num_brands = (reader->size() - reader->pos()) / sizeof(FourCC); |
17 return reader->SkipBytes(sizeof(FourCC) * num_brands); // compatible_brands | 17 return reader->SkipBytes(sizeof(FourCC) * num_brands); // compatible_brands |
18 } | 18 } |
19 | 19 |
20 ProtectionSystemSpecificHeader::ProtectionSystemSpecificHeader() {} | 20 ProtectionSystemSpecificHeader::ProtectionSystemSpecificHeader() {} |
21 ProtectionSystemSpecificHeader::~ProtectionSystemSpecificHeader() {} | 21 ProtectionSystemSpecificHeader::~ProtectionSystemSpecificHeader() {} |
22 FourCC ProtectionSystemSpecificHeader::BoxType() const { return FOURCC_PSSH; } | 22 FourCC ProtectionSystemSpecificHeader::BoxType() const { return FOURCC_PSSH; } |
23 | 23 |
24 bool ProtectionSystemSpecificHeader::Parse(BoxReader* reader) { | 24 bool ProtectionSystemSpecificHeader::Parse(BoxReader* reader) { |
25 uint32 size; | 25 uint32 size; |
26 return reader->SkipBytes(4) && | 26 return reader->ReadFullBoxHeader() && |
27 reader->ReadVec(&system_id, 16) && | 27 reader->ReadVec(&system_id, 16) && |
28 reader->Read4(&size) && | 28 reader->Read4(&size) && |
29 reader->ReadVec(&data, size); | 29 reader->ReadVec(&data, size); |
30 } | 30 } |
31 | 31 |
32 SampleAuxiliaryInformationOffset::SampleAuxiliaryInformationOffset() {} | 32 SampleAuxiliaryInformationOffset::SampleAuxiliaryInformationOffset() {} |
33 SampleAuxiliaryInformationOffset::~SampleAuxiliaryInformationOffset() {} | 33 SampleAuxiliaryInformationOffset::~SampleAuxiliaryInformationOffset() {} |
34 FourCC SampleAuxiliaryInformationOffset::BoxType() const { return FOURCC_SAIO; } | 34 FourCC SampleAuxiliaryInformationOffset::BoxType() const { return FOURCC_SAIO; } |
35 | 35 |
36 bool SampleAuxiliaryInformationOffset::Parse(BoxReader* reader) { | 36 bool SampleAuxiliaryInformationOffset::Parse(BoxReader* reader) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 | 77 |
78 bool OriginalFormat::Parse(BoxReader* reader) { | 78 bool OriginalFormat::Parse(BoxReader* reader) { |
79 return reader->ReadFourCC(&format); | 79 return reader->ReadFourCC(&format); |
80 } | 80 } |
81 | 81 |
82 SchemeType::SchemeType() : type(FOURCC_NULL), version(0) {} | 82 SchemeType::SchemeType() : type(FOURCC_NULL), version(0) {} |
83 SchemeType::~SchemeType() {} | 83 SchemeType::~SchemeType() {} |
84 FourCC SchemeType::BoxType() const { return FOURCC_SCHM; } | 84 FourCC SchemeType::BoxType() const { return FOURCC_SCHM; } |
85 | 85 |
86 bool SchemeType::Parse(BoxReader* reader) { | 86 bool SchemeType::Parse(BoxReader* reader) { |
87 RCHECK(reader->SkipBytes(4) && | 87 RCHECK(reader->ReadFullBoxHeader() && |
88 reader->ReadFourCC(&type) && | 88 reader->ReadFourCC(&type) && |
89 reader->Read4(&version)); | 89 reader->Read4(&version)); |
90 RCHECK(type == FOURCC_CENC); | 90 RCHECK(type == FOURCC_CENC); |
91 return true; | 91 return true; |
92 } | 92 } |
93 | 93 |
94 TrackEncryption::TrackEncryption() | 94 TrackEncryption::TrackEncryption() |
95 : is_encrypted(false), default_iv_size(0) { | 95 : is_encrypted(false), default_iv_size(0) { |
96 } | 96 } |
97 TrackEncryption::~TrackEncryption() {} | 97 TrackEncryption::~TrackEncryption() {} |
98 FourCC TrackEncryption::BoxType() const { return FOURCC_TENC; } | 98 FourCC TrackEncryption::BoxType() const { return FOURCC_TENC; } |
99 | 99 |
100 bool TrackEncryption::Parse(BoxReader* reader) { | 100 bool TrackEncryption::Parse(BoxReader* reader) { |
101 uint8 flag; | 101 uint8 flag; |
102 RCHECK(reader->SkipBytes(2) && | 102 RCHECK(reader->ReadFullBoxHeader() && |
103 reader->SkipBytes(2) && | |
103 reader->Read1(&flag) && | 104 reader->Read1(&flag) && |
104 reader->Read1(&default_iv_size) && | 105 reader->Read1(&default_iv_size) && |
105 reader->ReadVec(&default_kid, 16)); | 106 reader->ReadVec(&default_kid, 16)); |
106 is_encrypted = (flag != 0); | 107 is_encrypted = (flag != 0); |
107 if (is_encrypted) { | 108 if (is_encrypted) { |
108 RCHECK(default_iv_size == 8 || default_iv_size == 16); | 109 RCHECK(default_iv_size == 8 || default_iv_size == 16); |
109 } else { | 110 } else { |
110 RCHECK(default_iv_size == 0); | 111 RCHECK(default_iv_size == 0); |
111 } | 112 } |
112 return true; | 113 return true; |
113 } | 114 } |
114 | 115 |
115 SchemeInfo::SchemeInfo() {} | 116 SchemeInfo::SchemeInfo() {} |
116 SchemeInfo::~SchemeInfo() {} | 117 SchemeInfo::~SchemeInfo() {} |
117 FourCC SchemeInfo::BoxType() const { return FOURCC_SCHI; } | 118 FourCC SchemeInfo::BoxType() const { return FOURCC_SCHI; } |
118 | 119 |
119 bool SchemeInfo::Parse(BoxReader* reader) { | 120 bool SchemeInfo::Parse(BoxReader* reader) { |
120 return reader->ScanChildren() && reader->ReadChild(&track_encryption); | 121 return reader->ScanChildren() && reader->ReadChild(&track_encryption); |
121 } | 122 } |
122 | 123 |
123 ProtectionSchemeInfo::ProtectionSchemeInfo() {} | 124 ProtectionSchemeInfo::ProtectionSchemeInfo() {} |
124 ProtectionSchemeInfo::~ProtectionSchemeInfo() {} | 125 ProtectionSchemeInfo::~ProtectionSchemeInfo() {} |
125 FourCC ProtectionSchemeInfo::BoxType() const { return FOURCC_SINF; } | 126 FourCC ProtectionSchemeInfo::BoxType() const { return FOURCC_SINF; } |
126 | 127 |
127 bool ProtectionSchemeInfo::Parse(BoxReader* reader) { | 128 bool ProtectionSchemeInfo::Parse(BoxReader* reader) { |
128 return reader->ScanChildren() && | 129 RCHECK(reader->ScanChildren() && |
130 reader->ReadChild(&format) && | |
129 reader->ReadChild(&type) && | 131 reader->ReadChild(&type) && |
130 reader->ReadChild(&info); | 132 reader->ReadChild(&info)); |
133 return true; | |
131 } | 134 } |
132 | 135 |
133 MovieHeader::MovieHeader() | 136 MovieHeader::MovieHeader() |
134 : creation_time(0), | 137 : creation_time(0), |
135 modification_time(0), | 138 modification_time(0), |
136 timescale(0), | 139 timescale(0), |
137 duration(0), | 140 duration(0), |
138 rate(-1), | 141 rate(-1), |
139 volume(-1), | 142 volume(-1), |
140 next_track_id(0) {} | 143 next_track_id(0) {} |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 | 367 |
365 bool VideoSampleEntry::Parse(BoxReader* reader) { | 368 bool VideoSampleEntry::Parse(BoxReader* reader) { |
366 format = reader->type(); | 369 format = reader->type(); |
367 RCHECK(reader->SkipBytes(6) && | 370 RCHECK(reader->SkipBytes(6) && |
368 reader->Read2(&data_reference_index) && | 371 reader->Read2(&data_reference_index) && |
369 reader->SkipBytes(16) && | 372 reader->SkipBytes(16) && |
370 reader->Read2(&width) && | 373 reader->Read2(&width) && |
371 reader->Read2(&height) && | 374 reader->Read2(&height) && |
372 reader->SkipBytes(50)); | 375 reader->SkipBytes(50)); |
373 | 376 |
374 RCHECK(reader->ScanChildren()); | 377 RCHECK(reader->ScanChildren() && |
375 RCHECK(reader->MaybeReadChild(&pixel_aspect)); | 378 reader->MaybeReadChild(&pixel_aspect)); |
376 if (format == FOURCC_ENCV) { | 379 |
380 if (format == FOURCC_ENCV) | |
377 RCHECK(reader->ReadChild(&sinf)); | 381 RCHECK(reader->ReadChild(&sinf)); |
382 if (format == FOURCC_AVC1 || | |
383 (format == FOURCC_ENCV && sinf.format.format == FOURCC_AVC1)) { | |
384 RCHECK(reader->ReadChild(&avcc)); | |
378 } | 385 } |
379 | |
380 // TODO(strobe): finalize format signaling for encrypted media | |
381 // (http://crbug.com/132351) | |
382 // | |
383 // if (format == FOURCC_AVC1 || | |
384 // (format == FOURCC_ENCV && | |
385 // sinf.format.format == FOURCC_AVC1)) { | |
386 RCHECK(reader->ReadChild(&avcc)); | |
387 // } | |
388 return true; | 386 return true; |
389 } | 387 } |
390 | 388 |
391 ElementaryStreamDescriptor::ElementaryStreamDescriptor() {} | 389 ElementaryStreamDescriptor::ElementaryStreamDescriptor() {} |
392 | 390 |
393 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} | 391 ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {} |
394 | 392 |
395 FourCC ElementaryStreamDescriptor::BoxType() const { | 393 FourCC ElementaryStreamDescriptor::BoxType() const { |
396 return FOURCC_ESDS; | 394 return FOURCC_ESDS; |
397 } | 395 } |
398 | 396 |
399 bool ElementaryStreamDescriptor::Parse(BoxReader* reader) { | 397 bool ElementaryStreamDescriptor::Parse(BoxReader* reader) { |
400 std::vector<uint8> data; | 398 std::vector<uint8> data; |
401 ESDescriptor es_desc; | 399 ESDescriptor es_desc; |
402 | 400 |
403 RCHECK(reader->ReadFullBoxHeader()); | 401 RCHECK(reader->ReadFullBoxHeader()); |
404 RCHECK(reader->ReadVec(&data, reader->size() - reader->pos())); | 402 RCHECK(reader->ReadVec(&data, reader->size() - reader->pos())); |
ddorwin
2012/07/17 01:14:21
To verify, pos() is an index? index() might be a b
| |
405 RCHECK(es_desc.Parse(data)); | 403 RCHECK(es_desc.Parse(data)); |
406 | 404 |
407 object_type = es_desc.object_type(); | 405 object_type = es_desc.object_type(); |
408 | 406 |
409 RCHECK(aac.Parse(es_desc.decoder_specific_info())); | 407 RCHECK(aac.Parse(es_desc.decoder_specific_info())); |
410 | 408 |
411 return true; | 409 return true; |
412 } | 410 } |
413 | 411 |
414 AudioSampleEntry::AudioSampleEntry() | 412 AudioSampleEntry::AudioSampleEntry() |
(...skipping 17 matching lines...) Expand all Loading... | |
432 reader->Read2(&data_reference_index) && | 430 reader->Read2(&data_reference_index) && |
433 reader->SkipBytes(8) && | 431 reader->SkipBytes(8) && |
434 reader->Read2(&channelcount) && | 432 reader->Read2(&channelcount) && |
435 reader->Read2(&samplesize) && | 433 reader->Read2(&samplesize) && |
436 reader->SkipBytes(4) && | 434 reader->SkipBytes(4) && |
437 reader->Read4(&samplerate)); | 435 reader->Read4(&samplerate)); |
438 // Convert from 16.16 fixed point to integer | 436 // Convert from 16.16 fixed point to integer |
439 samplerate >>= 16; | 437 samplerate >>= 16; |
440 | 438 |
441 RCHECK(reader->ScanChildren()); | 439 RCHECK(reader->ScanChildren()); |
442 if (format == FOURCC_ENCA) { | 440 if (format == FOURCC_ENCA) |
443 RCHECK(reader->ReadChild(&sinf)); | 441 RCHECK(reader->ReadChild(&sinf)); |
444 } | |
445 RCHECK(reader->ReadChild(&esds)); | 442 RCHECK(reader->ReadChild(&esds)); |
446 return true; | 443 return true; |
447 } | 444 } |
448 | 445 |
449 MediaHeader::MediaHeader() | 446 MediaHeader::MediaHeader() |
450 : creation_time(0), | 447 : creation_time(0), |
451 modification_time(0), | 448 modification_time(0), |
452 timescale(0), | 449 timescale(0), |
453 duration(0) {} | 450 duration(0) {} |
454 MediaHeader::~MediaHeader() {} | 451 MediaHeader::~MediaHeader() {} |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 reader->MaybeReadChild(&edit)); | 509 reader->MaybeReadChild(&edit)); |
513 return true; | 510 return true; |
514 } | 511 } |
515 | 512 |
516 MovieExtendsHeader::MovieExtendsHeader() : fragment_duration(0) {} | 513 MovieExtendsHeader::MovieExtendsHeader() : fragment_duration(0) {} |
517 MovieExtendsHeader::~MovieExtendsHeader() {} | 514 MovieExtendsHeader::~MovieExtendsHeader() {} |
518 FourCC MovieExtendsHeader::BoxType() const { return FOURCC_MEHD; } | 515 FourCC MovieExtendsHeader::BoxType() const { return FOURCC_MEHD; } |
519 | 516 |
520 bool MovieExtendsHeader::Parse(BoxReader* reader) { | 517 bool MovieExtendsHeader::Parse(BoxReader* reader) { |
521 RCHECK(reader->ReadFullBoxHeader()); | 518 RCHECK(reader->ReadFullBoxHeader()); |
522 if (reader->version() == 1) { | 519 if (reader->version() == 1) { |
ddorwin
2012/07/17 01:14:21
Comment. V1 was... All other versions ...
strobe_
2012/07/19 02:43:35
Like most of this file, this is essentially a line
| |
523 RCHECK(reader->Read8(&fragment_duration)); | 520 RCHECK(reader->Read8(&fragment_duration)); |
524 } else { | 521 } else { |
525 RCHECK(reader->Read4Into8(&fragment_duration)); | 522 RCHECK(reader->Read4Into8(&fragment_duration)); |
526 } | 523 } |
527 return true; | 524 return true; |
528 } | 525 } |
529 | 526 |
530 TrackExtends::TrackExtends() | 527 TrackExtends::TrackExtends() |
531 : track_id(0), | 528 : track_id(0), |
532 default_sample_description_index(0), | 529 default_sample_description_index(0), |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 bool MovieFragment::Parse(BoxReader* reader) { | 715 bool MovieFragment::Parse(BoxReader* reader) { |
719 RCHECK(reader->ScanChildren() && | 716 RCHECK(reader->ScanChildren() && |
720 reader->ReadChild(&header) && | 717 reader->ReadChild(&header) && |
721 reader->ReadChildren(&tracks) && | 718 reader->ReadChildren(&tracks) && |
722 reader->MaybeReadChildren(&pssh)); | 719 reader->MaybeReadChildren(&pssh)); |
723 return true; | 720 return true; |
724 } | 721 } |
725 | 722 |
726 } // namespace mp4 | 723 } // namespace mp4 |
727 } // namespace media | 724 } // namespace media |
OLD | NEW |