Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: media/mp4/box_definitions.cc

Issue 10651006: Add Common Encryption support to BMFF, including subsample decryption. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address phantom comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/mp4/box_definitions.h ('k') | media/mp4/cenc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/box_reader.h" 8 #include "media/mp4/box_reader.h"
9 #include "media/mp4/fourccs.h" 9 #include "media/mp4/fourccs.h"
10 #include "media/mp4/rcheck.h" 10 #include "media/mp4/rcheck.h"
11 11
12 namespace media { 12 namespace media {
13 namespace mp4 { 13 namespace mp4 {
14 14
15 bool FileType::Parse(BoxReader* reader) { 15 bool FileType::Parse(BoxReader* reader) {
16 RCHECK(reader->ReadFourCC(&major_brand) && reader->Read4(&minor_version)); 16 RCHECK(reader->ReadFourCC(&major_brand) && reader->Read4(&minor_version));
17 size_t num_brands = (reader->size() - reader->pos()) / sizeof(FourCC); 17 size_t num_brands = (reader->size() - reader->pos()) / sizeof(FourCC);
18 return reader->SkipBytes(sizeof(FourCC) * num_brands); // compatible_brands 18 return reader->SkipBytes(sizeof(FourCC) * num_brands); // compatible_brands
19 } 19 }
20 20
21 ProtectionSystemSpecificHeader::ProtectionSystemSpecificHeader() {} 21 ProtectionSystemSpecificHeader::ProtectionSystemSpecificHeader() {}
22 ProtectionSystemSpecificHeader::~ProtectionSystemSpecificHeader() {} 22 ProtectionSystemSpecificHeader::~ProtectionSystemSpecificHeader() {}
23 FourCC ProtectionSystemSpecificHeader::BoxType() const { return FOURCC_PSSH; } 23 FourCC ProtectionSystemSpecificHeader::BoxType() const { return FOURCC_PSSH; }
24 24
25 bool ProtectionSystemSpecificHeader::Parse(BoxReader* reader) { 25 bool ProtectionSystemSpecificHeader::Parse(BoxReader* reader) {
26 uint32 size; 26 uint32 size;
27 return reader->SkipBytes(4) && 27 return reader->ReadFullBoxHeader() &&
28 reader->ReadVec(&system_id, 16) && 28 reader->ReadVec(&system_id, 16) &&
29 reader->Read4(&size) && 29 reader->Read4(&size) &&
30 reader->ReadVec(&data, size); 30 reader->ReadVec(&data, size);
31 } 31 }
32 32
33 SampleAuxiliaryInformationOffset::SampleAuxiliaryInformationOffset() {} 33 SampleAuxiliaryInformationOffset::SampleAuxiliaryInformationOffset() {}
34 SampleAuxiliaryInformationOffset::~SampleAuxiliaryInformationOffset() {} 34 SampleAuxiliaryInformationOffset::~SampleAuxiliaryInformationOffset() {}
35 FourCC SampleAuxiliaryInformationOffset::BoxType() const { return FOURCC_SAIO; } 35 FourCC SampleAuxiliaryInformationOffset::BoxType() const { return FOURCC_SAIO; }
36 36
37 bool SampleAuxiliaryInformationOffset::Parse(BoxReader* reader) { 37 bool SampleAuxiliaryInformationOffset::Parse(BoxReader* reader) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 bool OriginalFormat::Parse(BoxReader* reader) { 79 bool OriginalFormat::Parse(BoxReader* reader) {
80 return reader->ReadFourCC(&format); 80 return reader->ReadFourCC(&format);
81 } 81 }
82 82
83 SchemeType::SchemeType() : type(FOURCC_NULL), version(0) {} 83 SchemeType::SchemeType() : type(FOURCC_NULL), version(0) {}
84 SchemeType::~SchemeType() {} 84 SchemeType::~SchemeType() {}
85 FourCC SchemeType::BoxType() const { return FOURCC_SCHM; } 85 FourCC SchemeType::BoxType() const { return FOURCC_SCHM; }
86 86
87 bool SchemeType::Parse(BoxReader* reader) { 87 bool SchemeType::Parse(BoxReader* reader) {
88 RCHECK(reader->SkipBytes(4) && 88 RCHECK(reader->ReadFullBoxHeader() &&
89 reader->ReadFourCC(&type) && 89 reader->ReadFourCC(&type) &&
90 reader->Read4(&version)); 90 reader->Read4(&version));
91 RCHECK(type == FOURCC_CENC); 91 RCHECK(type == FOURCC_CENC);
92 return true; 92 return true;
93 } 93 }
94 94
95 TrackEncryption::TrackEncryption() 95 TrackEncryption::TrackEncryption()
96 : is_encrypted(false), default_iv_size(0) { 96 : is_encrypted(false), default_iv_size(0) {
97 } 97 }
98 TrackEncryption::~TrackEncryption() {} 98 TrackEncryption::~TrackEncryption() {}
99 FourCC TrackEncryption::BoxType() const { return FOURCC_TENC; } 99 FourCC TrackEncryption::BoxType() const { return FOURCC_TENC; }
100 100
101 bool TrackEncryption::Parse(BoxReader* reader) { 101 bool TrackEncryption::Parse(BoxReader* reader) {
102 uint8 flag; 102 uint8 flag;
103 RCHECK(reader->SkipBytes(2) && 103 RCHECK(reader->ReadFullBoxHeader() &&
104 reader->SkipBytes(2) &&
104 reader->Read1(&flag) && 105 reader->Read1(&flag) &&
105 reader->Read1(&default_iv_size) && 106 reader->Read1(&default_iv_size) &&
106 reader->ReadVec(&default_kid, 16)); 107 reader->ReadVec(&default_kid, 16));
107 is_encrypted = (flag != 0); 108 is_encrypted = (flag != 0);
108 if (is_encrypted) { 109 if (is_encrypted) {
109 RCHECK(default_iv_size == 8 || default_iv_size == 16); 110 RCHECK(default_iv_size == 8 || default_iv_size == 16);
110 } else { 111 } else {
111 RCHECK(default_iv_size == 0); 112 RCHECK(default_iv_size == 0);
112 } 113 }
113 return true; 114 return true;
114 } 115 }
115 116
116 SchemeInfo::SchemeInfo() {} 117 SchemeInfo::SchemeInfo() {}
117 SchemeInfo::~SchemeInfo() {} 118 SchemeInfo::~SchemeInfo() {}
118 FourCC SchemeInfo::BoxType() const { return FOURCC_SCHI; } 119 FourCC SchemeInfo::BoxType() const { return FOURCC_SCHI; }
119 120
120 bool SchemeInfo::Parse(BoxReader* reader) { 121 bool SchemeInfo::Parse(BoxReader* reader) {
121 return reader->ScanChildren() && reader->ReadChild(&track_encryption); 122 return reader->ScanChildren() && reader->ReadChild(&track_encryption);
122 } 123 }
123 124
124 ProtectionSchemeInfo::ProtectionSchemeInfo() {} 125 ProtectionSchemeInfo::ProtectionSchemeInfo() {}
125 ProtectionSchemeInfo::~ProtectionSchemeInfo() {} 126 ProtectionSchemeInfo::~ProtectionSchemeInfo() {}
126 FourCC ProtectionSchemeInfo::BoxType() const { return FOURCC_SINF; } 127 FourCC ProtectionSchemeInfo::BoxType() const { return FOURCC_SINF; }
127 128
128 bool ProtectionSchemeInfo::Parse(BoxReader* reader) { 129 bool ProtectionSchemeInfo::Parse(BoxReader* reader) {
129 return reader->ScanChildren() && 130 RCHECK(reader->ScanChildren() &&
131 reader->ReadChild(&format) &&
130 reader->ReadChild(&type) && 132 reader->ReadChild(&type) &&
131 reader->ReadChild(&info); 133 reader->ReadChild(&info));
134 return true;
132 } 135 }
133 136
134 MovieHeader::MovieHeader() 137 MovieHeader::MovieHeader()
135 : creation_time(0), 138 : creation_time(0),
136 modification_time(0), 139 modification_time(0),
137 timescale(0), 140 timescale(0),
138 duration(0), 141 duration(0),
139 rate(-1), 142 rate(-1),
140 volume(-1), 143 volume(-1),
141 next_track_id(0) {} 144 next_track_id(0) {}
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 368
366 bool VideoSampleEntry::Parse(BoxReader* reader) { 369 bool VideoSampleEntry::Parse(BoxReader* reader) {
367 format = reader->type(); 370 format = reader->type();
368 RCHECK(reader->SkipBytes(6) && 371 RCHECK(reader->SkipBytes(6) &&
369 reader->Read2(&data_reference_index) && 372 reader->Read2(&data_reference_index) &&
370 reader->SkipBytes(16) && 373 reader->SkipBytes(16) &&
371 reader->Read2(&width) && 374 reader->Read2(&width) &&
372 reader->Read2(&height) && 375 reader->Read2(&height) &&
373 reader->SkipBytes(50)); 376 reader->SkipBytes(50));
374 377
375 RCHECK(reader->ScanChildren()); 378 RCHECK(reader->ScanChildren() &&
376 RCHECK(reader->MaybeReadChild(&pixel_aspect)); 379 reader->MaybeReadChild(&pixel_aspect));
377 if (format == FOURCC_ENCV) { 380
381 if (format == FOURCC_ENCV)
378 RCHECK(reader->ReadChild(&sinf)); 382 RCHECK(reader->ReadChild(&sinf));
383 if (format == FOURCC_AVC1 ||
384 (format == FOURCC_ENCV && sinf.format.format == FOURCC_AVC1)) {
385 RCHECK(reader->ReadChild(&avcc));
379 } 386 }
380
381 // TODO(strobe): finalize format signaling for encrypted media
382 // (http://crbug.com/132351)
383 //
384 // if (format == FOURCC_AVC1 ||
385 // (format == FOURCC_ENCV &&
386 // sinf.format.format == FOURCC_AVC1)) {
387 RCHECK(reader->ReadChild(&avcc));
388 // }
389 return true; 387 return true;
390 } 388 }
391 389
392 AudioSampleEntry::AudioSampleEntry() 390 AudioSampleEntry::AudioSampleEntry()
393 : format(FOURCC_NULL), 391 : format(FOURCC_NULL),
394 data_reference_index(0), 392 data_reference_index(0),
395 channelcount(0), 393 channelcount(0),
396 samplesize(0), 394 samplesize(0),
397 samplerate(0) {} 395 samplerate(0) {}
398 396
399 AudioSampleEntry::~AudioSampleEntry() {} 397 AudioSampleEntry::~AudioSampleEntry() {}
ddorwin 2012/07/19 06:11:10 restore empty line after
strobe_ 2012/07/19 16:55:02 Done.
400 FourCC AudioSampleEntry::BoxType() const { 398 FourCC AudioSampleEntry::BoxType() const {
401 DCHECK(false) << "AudioSampleEntry should be parsed according to the " 399 DCHECK(false) << "AudioSampleEntry should be parsed according to the "
402 << "handler type recovered in its Media ancestor."; 400 << "handler type recovered in its Media ancestor.";
403 return FOURCC_NULL; 401 return FOURCC_NULL;
404 } 402 }
405 403
406 bool AudioSampleEntry::Parse(BoxReader* reader) { 404 bool AudioSampleEntry::Parse(BoxReader* reader) {
407 format = reader->type(); 405 format = reader->type();
408 RCHECK(reader->SkipBytes(6) && 406 RCHECK(reader->SkipBytes(6) &&
409 reader->Read2(&data_reference_index) && 407 reader->Read2(&data_reference_index) &&
410 reader->SkipBytes(8) && 408 reader->SkipBytes(8) &&
411 reader->Read2(&channelcount) && 409 reader->Read2(&channelcount) &&
412 reader->Read2(&samplesize) && 410 reader->Read2(&samplesize) &&
413 reader->SkipBytes(4) && 411 reader->SkipBytes(4) &&
414 reader->Read4(&samplerate)); 412 reader->Read4(&samplerate));
415 // Convert from 16.16 fixed point to integer 413 // Convert from 16.16 fixed point to integer
416 samplerate >>= 16; 414 samplerate >>= 16;
417 415
418 RCHECK(reader->ScanChildren()); 416 RCHECK(reader->ScanChildren());
419 if (format == FOURCC_ENCA) { 417 if (format == FOURCC_ENCA)
420 RCHECK(reader->ReadChild(&sinf)); 418 RCHECK(reader->ReadChild(&sinf));
421 }
422 return true; 419 return true;
423 } 420 }
424 421
425 MediaHeader::MediaHeader() 422 MediaHeader::MediaHeader()
426 : creation_time(0), 423 : creation_time(0),
427 modification_time(0), 424 modification_time(0),
428 timescale(0), 425 timescale(0),
429 duration(0) {} 426 duration(0) {}
430 MediaHeader::~MediaHeader() {} 427 MediaHeader::~MediaHeader() {}
431 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; } 428 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 bool MovieFragment::Parse(BoxReader* reader) { 694 bool MovieFragment::Parse(BoxReader* reader) {
698 RCHECK(reader->ScanChildren() && 695 RCHECK(reader->ScanChildren() &&
699 reader->ReadChild(&header) && 696 reader->ReadChild(&header) &&
700 reader->ReadChildren(&tracks) && 697 reader->ReadChildren(&tracks) &&
701 reader->MaybeReadChildren(&pssh)); 698 reader->MaybeReadChildren(&pssh));
702 return true; 699 return true;
703 } 700 }
704 701
705 } // namespace mp4 702 } // namespace mp4
706 } // namespace media 703 } // namespace media
OLDNEW
« no previous file with comments | « media/mp4/box_definitions.h ('k') | media/mp4/cenc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698