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

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

Issue 10535029: Add support for encrypted WebM files as defined in the RFC. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updated encrypted WebM test data. 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/webm/webm_cluster_parser.h" 5 #include "media/webm/webm_cluster_parser.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/sys_byteorder.h"
8 #include "media/base/data_buffer.h" 9 #include "media/base/data_buffer.h"
9 #include "media/base/decrypt_config.h" 10 #include "media/base/decrypt_config.h"
10 #include "media/webm/webm_constants.h" 11 #include "media/webm/webm_constants.h"
11 12
12 namespace media { 13 namespace media {
13 14
14 WebMClusterParser::WebMClusterParser(int64 timecode_scale, 15 WebMClusterParser::WebMClusterParser(int64 timecode_scale,
15 int audio_track_num, 16 int audio_track_num,
16 int video_track_num, 17 int video_track_num,
17 const uint8* video_encryption_key_id, 18 const uint8* video_encryption_key_id,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) { 181 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) {
181 DVLOG(1) << "Got a block with a timecode before the previous block."; 182 DVLOG(1) << "Got a block with a timecode before the previous block.";
182 return false; 183 return false;
183 } 184 }
184 185
185 last_block_timecode_ = timecode; 186 last_block_timecode_ = timecode;
186 187
187 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( 188 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds(
188 (cluster_timecode_ + timecode) * timecode_multiplier_); 189 (cluster_timecode_ + timecode) * timecode_multiplier_);
189 190
191 bool encrypted = track_num == video_.track_num() &&
192 video_encryption_key_id_.get();
193
190 // The first bit of the flags is set when the block contains only keyframes. 194 // The first bit of the flags is set when the block contains only keyframes.
191 // http://www.matroska.org/technical/specs/index.html 195 // http://www.matroska.org/technical/specs/index.html
192 bool is_keyframe = (flags & 0x80) != 0; 196 bool is_keyframe = (flags & 0x80) != 0;
193 scoped_refptr<StreamParserBuffer> buffer = 197 scoped_refptr<StreamParserBuffer> buffer =
194 StreamParserBuffer::CopyFrom(data, size, is_keyframe); 198 StreamParserBuffer::CopyFrom(data, size, is_keyframe);
195 199
196 if (track_num == video_.track_num() && video_encryption_key_id_.get()) { 200 if (encrypted) {
201 // Every encrypted Block has an HMAC and IV prepended to it. Current WebM
202 // encrypted request for comments specification is here
203 // http://wiki.webmproject.org/encryption/webm-encryption-rfc.
204 uint64 network_iv;
205 memcpy(&network_iv,
206 data + DecryptConfig::kWebMIntegrityCheckSize,
207 sizeof(network_iv));
208 const uint64 iv = base::NetToHost64(network_iv);
xhwang 2012/06/14 19:42:27 Can we hide all these in the HmacAesDecryptor? 1,
ddorwin 2012/06/14 21:41:24 As mentioned earlier, we want DecryptConfig to be
fgalligan1 2012/07/03 22:00:15 So now I'm passing the IV and the frame data. I pu
197 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( 209 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig(
210 data, DecryptConfig::kWebMIntegrityCheckSize, iv,
198 video_encryption_key_id_.get(), video_encryption_key_id_size_))); 211 video_encryption_key_id_.get(), video_encryption_key_id_size_)));
199 } 212 }
200 213
201 buffer->SetTimestamp(timestamp); 214 buffer->SetTimestamp(timestamp);
202 215
203 if (block_duration >= 0) { 216 if (block_duration >= 0) {
204 buffer->SetDuration(base::TimeDelta::FromMicroseconds( 217 buffer->SetDuration(base::TimeDelta::FromMicroseconds(
205 block_duration * timecode_multiplier_)); 218 block_duration * timecode_multiplier_));
206 } 219 }
207 220
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 DVLOG(2) << "AddToBufferQueue() : " << track_num_ 310 DVLOG(2) << "AddToBufferQueue() : " << track_num_
298 << " ts " << buffer->GetTimestamp().InSecondsF() 311 << " ts " << buffer->GetTimestamp().InSecondsF()
299 << " dur " << buffer->GetDuration().InSecondsF() 312 << " dur " << buffer->GetDuration().InSecondsF()
300 << " kf " << buffer->IsKeyframe() 313 << " kf " << buffer->IsKeyframe()
301 << " size " << buffer->GetDataSize(); 314 << " size " << buffer->GetDataSize();
302 315
303 buffers_.push_back(buffer); 316 buffers_.push_back(buffer);
304 } 317 }
305 318
306 } // namespace media 319 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698