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

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: Remove references to non-public encrypted files in tests Created 8 years, 6 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
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"
(...skipping 67 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() &&
ddorwin 2012/06/26 06:09:19 Why all the RCHECKs? Macros are discouraged, and t
strobe_ 2012/06/27 02:01:21 The alternatives were worse. ;) There are some tr
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() &&
130 reader->ReadChild(&type) && 131 reader->ReadChild(&type) &&
131 reader->ReadChild(&info); 132 reader->ReadChild(&info));
133 return true;
132 } 134 }
133 135
134 MovieHeader::MovieHeader() 136 MovieHeader::MovieHeader()
135 : creation_time(0), 137 : creation_time(0),
136 modification_time(0), 138 modification_time(0),
137 timescale(0), 139 timescale(0),
138 duration(0), 140 duration(0),
139 rate(-1), 141 rate(-1),
140 volume(-1), 142 volume(-1),
141 next_track_id(0) {} 143 next_track_id(0) {}
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 357
356 bool VideoSampleEntry::Parse(BoxReader* reader) { 358 bool VideoSampleEntry::Parse(BoxReader* reader) {
357 format = reader->type(); 359 format = reader->type();
358 RCHECK(reader->SkipBytes(6) && 360 RCHECK(reader->SkipBytes(6) &&
359 reader->Read2(&data_reference_index) && 361 reader->Read2(&data_reference_index) &&
360 reader->SkipBytes(16) && 362 reader->SkipBytes(16) &&
361 reader->Read2(&width) && 363 reader->Read2(&width) &&
362 reader->Read2(&height) && 364 reader->Read2(&height) &&
363 reader->SkipBytes(50)); 365 reader->SkipBytes(50));
364 366
367 // TODO(strobe): Finalize format signaling for encrypted media
368 // (http://crbug.com/132351). For now, we assume that every video track is
369 // AVC, and that any track may have a Common Encryption header regardless of
370 // format.
365 RCHECK(reader->ScanChildren()); 371 RCHECK(reader->ScanChildren());
366 if (format == FOURCC_ENCV) { 372 RCHECK(reader->ReadChild(&avcc) && reader->MaybeReadChild(&sinf));
367 RCHECK(reader->ReadChild(&sinf));
368 }
369
370 // TODO(strobe): finalize format signaling for encrypted media
371 // (http://crbug.com/132351)
372 //
373 // if (format == FOURCC_AVC1 ||
374 // (format == FOURCC_ENCV &&
375 // sinf.format.format == FOURCC_AVC1)) {
376 RCHECK(reader->ReadChild(&avcc));
377 // }
378 return true; 373 return true;
379 } 374 }
380 375
381 AudioSampleEntry::AudioSampleEntry() 376 AudioSampleEntry::AudioSampleEntry()
382 : format(FOURCC_NULL), 377 : format(FOURCC_NULL),
383 data_reference_index(0), 378 data_reference_index(0),
384 channelcount(0), 379 channelcount(0),
385 samplesize(0), 380 samplesize(0),
386 samplerate(0) {} 381 samplerate(0) {}
387 382
388 AudioSampleEntry::~AudioSampleEntry() {} 383 AudioSampleEntry::~AudioSampleEntry() {}
389 FourCC AudioSampleEntry::BoxType() const { 384 FourCC AudioSampleEntry::BoxType() const {
390 DCHECK(false) << "AudioSampleEntry should be parsed according to the " 385 DCHECK(false) << "AudioSampleEntry should be parsed according to the "
391 << "handler type recovered in its Media ancestor."; 386 << "handler type recovered in its Media ancestor.";
392 return FOURCC_NULL; 387 return FOURCC_NULL;
393 } 388 }
394 389
395 bool AudioSampleEntry::Parse(BoxReader* reader) { 390 bool AudioSampleEntry::Parse(BoxReader* reader) {
396 format = reader->type(); 391 format = reader->type();
397 RCHECK(reader->SkipBytes(6) && 392 RCHECK(reader->SkipBytes(6) &&
398 reader->Read2(&data_reference_index) && 393 reader->Read2(&data_reference_index) &&
399 reader->SkipBytes(8) && 394 reader->SkipBytes(8) &&
400 reader->Read2(&channelcount) && 395 reader->Read2(&channelcount) &&
401 reader->Read2(&samplesize) && 396 reader->Read2(&samplesize) &&
402 reader->SkipBytes(4) && 397 reader->SkipBytes(4) &&
403 reader->Read4(&samplerate)); 398 reader->Read4(&samplerate));
404 // Convert from 16.16 fixed point to integer 399 // Convert from 16.16 fixed point to integer
405 samplerate >>= 16; 400 samplerate >>= 16;
406 401
407 RCHECK(reader->ScanChildren()); 402 RCHECK(reader->ScanChildren() &&
408 if (format == FOURCC_ENCA) { 403 reader->MaybeReadChild(&sinf));
409 RCHECK(reader->ReadChild(&sinf));
410 }
411 return true; 404 return true;
412 } 405 }
413 406
414 MediaHeader::MediaHeader() 407 MediaHeader::MediaHeader()
415 : creation_time(0), 408 : creation_time(0),
416 modification_time(0), 409 modification_time(0),
417 timescale(0), 410 timescale(0),
418 duration(0) {} 411 duration(0) {}
419 MediaHeader::~MediaHeader() {} 412 MediaHeader::~MediaHeader() {}
420 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; } 413 FourCC MediaHeader::BoxType() const { return FOURCC_MDHD; }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 bool MovieFragment::Parse(BoxReader* reader) { 671 bool MovieFragment::Parse(BoxReader* reader) {
679 RCHECK(reader->ScanChildren() && 672 RCHECK(reader->ScanChildren() &&
680 reader->ReadChild(&header) && 673 reader->ReadChild(&header) &&
681 reader->ReadChildren(&tracks) && 674 reader->ReadChildren(&tracks) &&
682 reader->MaybeReadChildren(&pssh)); 675 reader->MaybeReadChildren(&pssh));
683 return true; 676 return true;
684 } 677 }
685 678
686 } // namespace mp4 679 } // namespace mp4
687 } // namespace media 680 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698