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

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: Addressing comments 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
« no previous file with comments | « media/filters/pipeline_integration_test.cc ('k') | media/webm/webm_constants.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/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"
11 #include "media/base/data_buffer.h" 10 #include "media/base/data_buffer.h"
12 #include "media/base/decrypt_config.h" 11 #include "media/base/decrypt_config.h"
13 #include "media/webm/webm_constants.h" 12 #include "media/webm/webm_constants.h"
14 13
15 namespace media { 14 namespace media {
16 15
17 // Generates a 16 byte CTR counter block. The CTR counter block format is a 16 // 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. 17 // CTR IV appended with a CTR block counter. |iv| is an 8 byte CTR IV.
19 // Returns a string of kDecryptionKeySize bytes. 18 // |iv_size| is the size of |iv| in btyes. Returns a string of
20 static std::string GenerateCounterBlock(uint64 iv) { 19 // kDecryptionKeySize bytes.
21 std::string counter_block(reinterpret_cast<char*>(&iv), sizeof(iv)); 20 static std::string GenerateCounterBlock(const uint8* iv, int iv_size) {
22 counter_block.append(DecryptConfig::kDecryptionKeySize - sizeof(iv), 0); 21 std::string counter_block(reinterpret_cast<const char*>(iv), iv_size);
22 counter_block.append(DecryptConfig::kDecryptionKeySize - iv_size, 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 block_data_.reset(new uint8[size]); 178 block_data_.reset(new uint8[size]);
179 memcpy(block_data_.get(), data, size); 179 memcpy(block_data_.get(), data, size);
180 block_data_size_ = size; 180 block_data_size_ = size;
181 return true; 181 return true;
182 } 182 }
183 183
184 bool WebMClusterParser::OnBlock(int track_num, int timecode, 184 bool WebMClusterParser::OnBlock(int track_num, int timecode,
185 int block_duration, 185 int block_duration,
186 int flags, 186 int flags,
187 const uint8* data, int size) { 187 const uint8* data, int size) {
188 DCHECK_GE(size, 0);
188 if (cluster_timecode_ == -1) { 189 if (cluster_timecode_ == -1) {
189 DVLOG(1) << "Got a block before cluster timecode."; 190 DVLOG(1) << "Got a block before cluster timecode.";
190 return false; 191 return false;
191 } 192 }
192 193
193 if (timecode < 0) { 194 if (timecode < 0) {
194 DVLOG(1) << "Got a block with negative timecode offset " << timecode; 195 DVLOG(1) << "Got a block with negative timecode offset " << timecode;
195 return false; 196 return false;
196 } 197 }
197 198
(...skipping 23 matching lines...) Expand all
221 // The first bit of the flags is set when the block contains only keyframes. 222 // The first bit of the flags is set when the block contains only keyframes.
222 // http://www.matroska.org/technical/specs/index.html 223 // http://www.matroska.org/technical/specs/index.html
223 bool is_keyframe = (flags & 0x80) != 0; 224 bool is_keyframe = (flags & 0x80) != 0;
224 scoped_refptr<StreamParserBuffer> buffer = 225 scoped_refptr<StreamParserBuffer> buffer =
225 StreamParserBuffer::CopyFrom(data, size, is_keyframe); 226 StreamParserBuffer::CopyFrom(data, size, is_keyframe);
226 227
227 // Every encrypted Block has a signal byte and IV prepended to it. Current 228 // Every encrypted Block has a signal byte and IV prepended to it. Current
228 // encrypted WebM request for comments specification is here 229 // encrypted WebM request for comments specification is here
229 // http://wiki.webmproject.org/encryption/webm-encryption-rfc 230 // http://wiki.webmproject.org/encryption/webm-encryption-rfc
230 if (!encryption_key_id.empty()) { 231 if (!encryption_key_id.empty()) {
232 DCHECK_EQ(kWebMSignalByteSize, 1);
233 if (size < kWebMSignalByteSize) {
234 DVLOG(1) << "Got a block from an encrypted stream with no data.";
235 return false;
236 }
231 uint8 signal_byte = data[0]; 237 uint8 signal_byte = data[0];
232 int data_offset = sizeof(signal_byte); 238 int data_offset = sizeof(signal_byte);
233 239
234 // Setting the DecryptConfig object of the buffer while leaving the 240 // Setting the DecryptConfig object of the buffer while leaving the
235 // initialization vector empty will tell the decryptor that the frame is 241 // initialization vector empty will tell the decryptor that the frame is
236 // unencrypted. 242 // unencrypted.
237 std::string counter_block; 243 std::string counter_block;
238 244
239 if (signal_byte & kWebMFlagEncryptedFrame) { 245 if (signal_byte & kWebMFlagEncryptedFrame) {
240 uint64 network_iv; 246 if (size < kWebMSignalByteSize + kWebMIvSize) {
241 memcpy(&network_iv, data + data_offset, sizeof(network_iv)); 247 DVLOG(1) << "Got an encrypted block with not enough data " << size;
242 data_offset += sizeof(network_iv); 248 return false;
243 counter_block = GenerateCounterBlock(base::NetToHost64(network_iv)); 249 }
250 counter_block = GenerateCounterBlock(data + data_offset, kWebMIvSize);
251 data_offset += kWebMIvSize;
244 } 252 }
245 253
246 // TODO(fgalligan): Revisit if DecryptConfig needs to be set on unencrypted 254 // TODO(fgalligan): Revisit if DecryptConfig needs to be set on unencrypted
247 // frames after the CDM API is finalized. 255 // frames after the CDM API is finalized.
248 // Unencrypted frames of potentially encrypted streams currently set 256 // Unencrypted frames of potentially encrypted streams currently set
249 // DecryptConfig. 257 // DecryptConfig.
250 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( 258 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig(
251 encryption_key_id, 259 encryption_key_id,
252 counter_block, 260 counter_block,
253 data_offset, 261 data_offset,
(...skipping 28 matching lines...) Expand all
282 290
283 buffers_.push_back(buffer); 291 buffers_.push_back(buffer);
284 return true; 292 return true;
285 } 293 }
286 294
287 void WebMClusterParser::Track::Reset() { 295 void WebMClusterParser::Track::Reset() {
288 buffers_.clear(); 296 buffers_.clear();
289 } 297 }
290 298
291 } // namespace media 299 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/pipeline_integration_test.cc ('k') | media/webm/webm_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698