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

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

Issue 10826098: Use std::string for decryption key ID in webm parser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
9 #include "media/base/data_buffer.h" 11 #include "media/base/data_buffer.h"
10 #include "media/base/decrypt_config.h" 12 #include "media/base/decrypt_config.h"
11 #include "media/webm/webm_constants.h" 13 #include "media/webm/webm_constants.h"
12 14
13 namespace media { 15 namespace media {
14 16
15 // 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
16 // 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.
17 // Always returns a valid pointer to a buffer of kDecryptionKeySize bytes. 19 // Always returns a valid pointer to a buffer of kDecryptionKeySize bytes.
18 static scoped_array<uint8> GenerateCounterBlock(uint64 iv) { 20 static scoped_array<uint8> GenerateCounterBlock(uint64 iv) {
19 scoped_array<uint8> counter_block_data( 21 scoped_array<uint8> counter_block_data(
20 new uint8[DecryptConfig::kDecryptionKeySize]); 22 new uint8[DecryptConfig::kDecryptionKeySize]);
21 23
22 // Set the IV. 24 // Set the IV.
23 memcpy(counter_block_data.get(), &iv, sizeof(iv)); 25 memcpy(counter_block_data.get(), &iv, sizeof(iv));
24 26
25 // Set block counter to all 0's. 27 // Set block counter to all 0's.
26 memset(counter_block_data.get() + sizeof(iv), 28 memset(counter_block_data.get() + sizeof(iv),
27 0, 29 0,
28 DecryptConfig::kDecryptionKeySize - sizeof(iv)); 30 DecryptConfig::kDecryptionKeySize - sizeof(iv));
29 31
30 return counter_block_data.Pass(); 32 return counter_block_data.Pass();
31 } 33 }
32 34
33 WebMClusterParser::WebMClusterParser(int64 timecode_scale, 35 WebMClusterParser::WebMClusterParser(int64 timecode_scale,
34 int audio_track_num, 36 int audio_track_num,
35 int video_track_num, 37 int video_track_num,
36 const uint8* video_encryption_key_id, 38 const std::string& video_encryption_key_id)
37 int video_encryption_key_id_size)
38 : timecode_multiplier_(timecode_scale / 1000.0), 39 : timecode_multiplier_(timecode_scale / 1000.0),
39 video_encryption_key_id_size_(video_encryption_key_id_size), 40 video_encryption_key_id_(video_encryption_key_id),
40 parser_(kWebMIdCluster, this), 41 parser_(kWebMIdCluster, this),
41 last_block_timecode_(-1), 42 last_block_timecode_(-1),
42 block_data_size_(-1), 43 block_data_size_(-1),
43 block_duration_(-1), 44 block_duration_(-1),
44 cluster_timecode_(-1), 45 cluster_timecode_(-1),
45 cluster_start_time_(kNoTimestamp()), 46 cluster_start_time_(kNoTimestamp()),
46 cluster_ended_(false), 47 cluster_ended_(false),
47 audio_(audio_track_num), 48 audio_(audio_track_num),
48 video_(video_track_num) { 49 video_(video_track_num) {
49 CHECK_GE(video_encryption_key_id_size, 0);
50 if (video_encryption_key_id_size > 0) {
51 video_encryption_key_id_.reset(new uint8[video_encryption_key_id_size]);
52 memcpy(video_encryption_key_id_.get(), video_encryption_key_id,
53 video_encryption_key_id_size);
54 }
55 } 50 }
56 51
57 WebMClusterParser::~WebMClusterParser() {} 52 WebMClusterParser::~WebMClusterParser() {}
58 53
59 void WebMClusterParser::Reset() { 54 void WebMClusterParser::Reset() {
60 last_block_timecode_ = -1; 55 last_block_timecode_ = -1;
61 cluster_timecode_ = -1; 56 cluster_timecode_ = -1;
62 cluster_start_time_ = kNoTimestamp(); 57 cluster_start_time_ = kNoTimestamp();
63 cluster_ended_ = false; 58 cluster_ended_ = false;
64 parser_.Reset(); 59 parser_.Reset();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 209
215 last_block_timecode_ = timecode; 210 last_block_timecode_ = timecode;
216 211
217 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( 212 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds(
218 (cluster_timecode_ + timecode) * timecode_multiplier_); 213 (cluster_timecode_ + timecode) * timecode_multiplier_);
219 214
220 // Every encrypted Block has an HMAC and IV prepended to it. Current encrypted 215 // Every encrypted Block has an HMAC and IV prepended to it. Current encrypted
221 // WebM request for comments specification is here 216 // WebM request for comments specification is here
222 // http://wiki.webmproject.org/encryption/webm-encryption-rfc 217 // http://wiki.webmproject.org/encryption/webm-encryption-rfc
223 bool encrypted = track_num == video_.track_num() && 218 bool encrypted = track_num == video_.track_num() &&
224 video_encryption_key_id_.get(); 219 !video_encryption_key_id_.empty();
scherkus (not reviewing) 2012/08/01 21:39:28 this should be 4-space indent
xhwang 2012/08/01 22:01:10 Done.
225 // If encrypted skip past the HMAC. Encrypted buffers must include the IV and 220 // If encrypted skip past the HMAC. Encrypted buffers must include the IV and
226 // the encrypted frame because the decryptor will verify this data before 221 // the encrypted frame because the decryptor will verify this data before
227 // decryption. The HMAC and IV will be copied into DecryptConfig. 222 // decryption. The HMAC and IV will be copied into DecryptConfig.
228 int offset = (encrypted) ? kWebMHmacSize : 0; 223 int offset = (encrypted) ? kWebMHmacSize : 0;
229 224
230 // The first bit of the flags is set when the block contains only keyframes. 225 // The first bit of the flags is set when the block contains only keyframes.
231 // http://www.matroska.org/technical/specs/index.html 226 // http://www.matroska.org/technical/specs/index.html
232 bool is_keyframe = (flags & 0x80) != 0; 227 bool is_keyframe = (flags & 0x80) != 0;
233 scoped_refptr<StreamParserBuffer> buffer = 228 scoped_refptr<StreamParserBuffer> buffer =
234 StreamParserBuffer::CopyFrom(data + offset, size - offset, is_keyframe); 229 StreamParserBuffer::CopyFrom(data + offset, size - offset, is_keyframe);
235 230
236 if (encrypted) { 231 if (encrypted) {
237 uint64 network_iv; 232 uint64 network_iv;
238 memcpy(&network_iv, data + kWebMHmacSize, sizeof(network_iv)); 233 memcpy(&network_iv, data + kWebMHmacSize, sizeof(network_iv));
239 const uint64 iv = base::NetToHost64(network_iv); 234 const uint64 iv = base::NetToHost64(network_iv);
240 235
241 scoped_array<uint8> counter_block(GenerateCounterBlock(iv)); 236 scoped_array<uint8> counter_block(GenerateCounterBlock(iv));
242 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( 237 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig(
243 std::string( 238 video_encryption_key_id_,
244 reinterpret_cast<const char*>(video_encryption_key_id_.get()),
245 video_encryption_key_id_size_),
246 std::string( 239 std::string(
247 reinterpret_cast<const char*>(counter_block.get()), 240 reinterpret_cast<const char*>(counter_block.get()),
248 DecryptConfig::kDecryptionKeySize), 241 DecryptConfig::kDecryptionKeySize),
249 std::string(reinterpret_cast<const char*>(data), kWebMHmacSize), 242 std::string(reinterpret_cast<const char*>(data), kWebMHmacSize),
250 sizeof(iv), 243 sizeof(iv),
251 std::vector<SubsampleEntry>()))); 244 std::vector<SubsampleEntry>())));
252 } 245 }
253 246
254 buffer->SetTimestamp(timestamp); 247 buffer->SetTimestamp(timestamp);
255 if (cluster_start_time_ == kNoTimestamp()) 248 if (cluster_start_time_ == kNoTimestamp())
(...skipping 30 matching lines...) Expand all
286 279
287 buffers_.push_back(buffer); 280 buffers_.push_back(buffer);
288 return true; 281 return true;
289 } 282 }
290 283
291 void WebMClusterParser::Track::Reset() { 284 void WebMClusterParser::Track::Reset() {
292 buffers_.clear(); 285 buffers_.clear();
293 } 286 }
294 287
295 } // namespace media 288 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698