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

Side by Side Diff: media/webm/webm_cluster_parser.cc

Issue 11139008: Change WebM parser to treat IVs from encrypted WebM as raw data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
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/webm/webm_cluster_parser.h" 5 #include "media/webm/webm_cluster_parser.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
11 #include "media/base/data_buffer.h" 11 #include "media/base/data_buffer.h"
12 #include "media/base/decrypt_config.h" 12 #include "media/base/decrypt_config.h"
13 #include "media/webm/webm_constants.h" 13 #include "media/webm/webm_constants.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 // Generates a 16 byte CTR counter block. The CTR counter block format is a 17 // Generates a 16 byte CTR counter block. The CTR counter block format is a
18 // CTR IV appended with a CTR block counter. |iv| is an 8 byte CTR IV. 18 // CTR IV appended with a CTR block counter. |iv| is an 8 byte CTR IV.
19 // Returns a string of kDecryptionKeySize bytes. 19 // Returns a string of kDecryptionKeySize bytes.
20 static std::string GenerateCounterBlock(uint64 iv) { 20 static std::string GenerateCounterBlock(const std::string& iv) {
21 std::string counter_block(reinterpret_cast<char*>(&iv), sizeof(iv)); 21 std::string counter_block(iv);
22 counter_block.append(DecryptConfig::kDecryptionKeySize - sizeof(iv), 0); 22 counter_block.append(DecryptConfig::kDecryptionKeySize - kWebMIvSize, 0);
23 return counter_block; 23 return counter_block;
24 } 24 }
25 25
26 WebMClusterParser::WebMClusterParser(int64 timecode_scale, 26 WebMClusterParser::WebMClusterParser(int64 timecode_scale,
27 int audio_track_num, 27 int audio_track_num,
28 int video_track_num, 28 int video_track_num,
29 const std::string& audio_encryption_key_id, 29 const std::string& audio_encryption_key_id,
30 const std::string& video_encryption_key_id) 30 const std::string& video_encryption_key_id)
31 : timecode_multiplier_(timecode_scale / 1000.0), 31 : timecode_multiplier_(timecode_scale / 1000.0),
32 audio_encryption_key_id_(audio_encryption_key_id), 32 audio_encryption_key_id_(audio_encryption_key_id),
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (!encryption_key_id.empty()) { 230 if (!encryption_key_id.empty()) {
231 uint8 signal_byte = data[0]; 231 uint8 signal_byte = data[0];
232 int data_offset = sizeof(signal_byte); 232 int data_offset = sizeof(signal_byte);
233 233
234 // Setting the DecryptConfig object of the buffer while leaving the 234 // Setting the DecryptConfig object of the buffer while leaving the
235 // initialization vector empty will tell the decryptor that the frame is 235 // initialization vector empty will tell the decryptor that the frame is
236 // unencrypted. 236 // unencrypted.
237 std::string counter_block; 237 std::string counter_block;
238 238
239 if (signal_byte & kWebMFlagEncryptedFrame) { 239 if (signal_byte & kWebMFlagEncryptedFrame) {
240 uint64 network_iv; 240 const std::string iv(reinterpret_cast<const char*>(data + data_offset),
ddorwin 2012/10/13 00:26:17 nit: We create a string just to then copy it to an
fgalligan1 2012/10/13 06:20:31 Done.
241 memcpy(&network_iv, data + data_offset, sizeof(network_iv)); 241 kWebMIvSize);
242 data_offset += sizeof(network_iv); 242 data_offset += kWebMIvSize;
243 counter_block = GenerateCounterBlock(base::NetToHost64(network_iv)); 243 counter_block = GenerateCounterBlock(iv);
244 } 244 }
245 245
246 // TODO(fgalligan): Revisit if DecryptConfig needs to be set on unencrypted 246 // TODO(fgalligan): Revisit if DecryptConfig needs to be set on unencrypted
247 // frames after the CDM API is finalized. 247 // frames after the CDM API is finalized.
248 // Unencrypted frames of potentially encrypted streams currently set 248 // Unencrypted frames of potentially encrypted streams currently set
249 // DecryptConfig. 249 // DecryptConfig.
250 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( 250 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig(
251 encryption_key_id, 251 encryption_key_id,
252 counter_block, 252 counter_block,
253 data_offset, 253 data_offset,
(...skipping 28 matching lines...) Expand all
282 282
283 buffers_.push_back(buffer); 283 buffers_.push_back(buffer);
284 return true; 284 return true;
285 } 285 }
286 286
287 void WebMClusterParser::Track::Reset() { 287 void WebMClusterParser::Track::Reset() {
288 buffers_.clear(); 288 buffers_.clear();
289 } 289 }
290 290
291 } // namespace media 291 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698