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

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

Issue 10917308: Remove the checksum/HMAC code from the decryptor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix proxy_decryptor_unittest. Created 8 years, 3 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/mp4/track_run_iterator.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" 10 #include "base/sys_byteorder.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) { 196 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) {
197 DVLOG(1) << "Got a block with a timecode before the previous block."; 197 DVLOG(1) << "Got a block with a timecode before the previous block.";
198 return false; 198 return false;
199 } 199 }
200 200
201 last_block_timecode_ = timecode; 201 last_block_timecode_ = timecode;
202 202
203 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( 203 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds(
204 (cluster_timecode_ + timecode) * timecode_multiplier_); 204 (cluster_timecode_ + timecode) * timecode_multiplier_);
205 205
206 // Every encrypted Block has an HMAC and IV prepended to it. Current encrypted 206 // Every encrypted Block has a signal byte and IV prepended to it. Current
207 // WebM request for comments specification is here 207 // encrypted WebM request for comments specification is here
208 // http://wiki.webmproject.org/encryption/webm-encryption-rfc 208 // http://wiki.webmproject.org/encryption/webm-encryption-rfc
209 bool is_track_encrypted = 209 bool is_track_encrypted =
210 track_num == video_.track_num() && !video_encryption_key_id_.empty(); 210 track_num == video_.track_num() && !video_encryption_key_id_.empty();
211 211
212 // If stream is encrypted skip past the HMAC. Encrypted buffers must include
213 // the signal byte, the IV (if frame is encrypted) and
214 // the frame because the decryptor will verify this data before decryption.
215 // The HMAC and IV will be copied into DecryptConfig.
216 int offset = (is_track_encrypted) ? kWebMHmacSize : 0;
217
218 // The first bit of the flags is set when the block contains only keyframes. 212 // The first bit of the flags is set when the block contains only keyframes.
219 // http://www.matroska.org/technical/specs/index.html 213 // http://www.matroska.org/technical/specs/index.html
220 bool is_keyframe = (flags & 0x80) != 0; 214 bool is_keyframe = (flags & 0x80) != 0;
221 scoped_refptr<StreamParserBuffer> buffer = 215 scoped_refptr<StreamParserBuffer> buffer =
222 StreamParserBuffer::CopyFrom(data + offset, size - offset, is_keyframe); 216 StreamParserBuffer::CopyFrom(data, size, is_keyframe);
223 217
224 if (is_track_encrypted) { 218 if (is_track_encrypted) {
225 uint8 signal_byte = data[kWebMHmacSize]; 219 uint8 signal_byte = data[0];
226 int data_offset = sizeof(signal_byte); 220 int data_offset = sizeof(signal_byte);
227 221
228 // Setting the DecryptConfig object of the buffer while leaving the 222 // Setting the DecryptConfig object of the buffer while leaving the
229 // initialization vector empty will tell the decryptor that the frame is 223 // initialization vector empty will tell the decryptor that the frame is
230 // unencrypted but integrity should still be checked. 224 // unencrypted.
231 std::string counter_block; 225 std::string counter_block;
232 226
233 if (signal_byte & kWebMFlagEncryptedFrame) { 227 if (signal_byte & kWebMFlagEncryptedFrame) {
234 uint64 network_iv; 228 uint64 network_iv;
235 memcpy(&network_iv, data + kWebMHmacSize + data_offset, 229 memcpy(&network_iv, data + data_offset, sizeof(network_iv));
236 sizeof(network_iv));
237 const uint64 iv = base::NetToHost64(network_iv); 230 const uint64 iv = base::NetToHost64(network_iv);
238 counter_block = GenerateCounterBlock(iv); 231 counter_block = GenerateCounterBlock(iv);
239 data_offset += sizeof(iv); 232 data_offset += sizeof(iv);
240 } 233 }
241 234
235 // TODO(fgalligan): Revisit if DecryptConfig needs to be set on unencrypted
236 // frames after the CDM API is finalized.
237 // Unencrypted frames of potentially encrypted streams currently set
238 // DecryptConfig.
242 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( 239 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig(
243 video_encryption_key_id_, 240 video_encryption_key_id_,
244 counter_block, 241 counter_block,
245 std::string(reinterpret_cast<const char*>(data), kWebMHmacSize),
246 data_offset, 242 data_offset,
247 std::vector<SubsampleEntry>()))); 243 std::vector<SubsampleEntry>())));
248 } 244 }
249 245
250 buffer->SetTimestamp(timestamp); 246 buffer->SetTimestamp(timestamp);
251 if (cluster_start_time_ == kNoTimestamp()) 247 if (cluster_start_time_ == kNoTimestamp())
252 cluster_start_time_ = timestamp; 248 cluster_start_time_ = timestamp;
253 249
254 if (block_duration >= 0) { 250 if (block_duration >= 0) {
255 buffer->SetDuration(base::TimeDelta::FromMicroseconds( 251 buffer->SetDuration(base::TimeDelta::FromMicroseconds(
(...skipping 26 matching lines...) Expand all
282 278
283 buffers_.push_back(buffer); 279 buffers_.push_back(buffer);
284 return true; 280 return true;
285 } 281 }
286 282
287 void WebMClusterParser::Track::Reset() { 283 void WebMClusterParser::Track::Reset() {
288 buffers_.clear(); 284 buffers_.clear();
289 } 285 }
290 286
291 } // namespace media 287 } // namespace media
OLDNEW
« no previous file with comments | « media/mp4/track_run_iterator.cc ('k') | media/webm/webm_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698