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

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: Rebase to master Created 8 years, 5 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) { 187 if (last_block_timecode_ != -1 && timecode < last_block_timecode_) {
187 DVLOG(1) << "Got a block with a timecode before the previous block."; 188 DVLOG(1) << "Got a block with a timecode before the previous block.";
188 return false; 189 return false;
189 } 190 }
190 191
191 last_block_timecode_ = timecode; 192 last_block_timecode_ = timecode;
192 193
193 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( 194 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds(
194 (cluster_timecode_ + timecode) * timecode_multiplier_); 195 (cluster_timecode_ + timecode) * timecode_multiplier_);
195 196
197 // Every encrypted Block has an HMAC and IV prepended to it. Current WebM
ddorwin 2012/07/11 01:00:27 "encrypted WebM" or "WebM encryption"? Same in nex
fgalligan1 2012/07/11 22:06:33 Done.
198 // encrypted request for comments specification is here
ddorwin 2012/07/11 01:00:27 I suggest reiterating here that for encrypted bloc
fgalligan1 2012/07/11 22:06:33 Done.
199 // http://wiki.webmproject.org/encryption/webm-encryption-rfc
200 bool encrypted = track_num == video_.track_num() &&
201 video_encryption_key_id_.get();
xhwang 2012/07/10 06:31:25 indentation: should align with "track_num".
fgalligan1 2012/07/11 22:06:33 Done.
202 // If encrypted skip past the HMAC.
203 int data_offset = (encrypted) ? kWebMIntegrityCheckSize : 0;
204
196 // The first bit of the flags is set when the block contains only keyframes. 205 // The first bit of the flags is set when the block contains only keyframes.
197 // http://www.matroska.org/technical/specs/index.html 206 // http://www.matroska.org/technical/specs/index.html
198 bool is_keyframe = (flags & 0x80) != 0; 207 bool is_keyframe = (flags & 0x80) != 0;
199 scoped_refptr<StreamParserBuffer> buffer = 208 scoped_refptr<StreamParserBuffer> buffer =
200 StreamParserBuffer::CopyFrom(data, size, is_keyframe); 209 StreamParserBuffer::CopyFrom(data + data_offset,
210 size - data_offset,
211 is_keyframe);
201 212
202 if (track_num == video_.track_num() && video_encryption_key_id_.get()) { 213 if (encrypted) {
214 uint64 network_iv;
215 memcpy(&network_iv,
216 data + kWebMIntegrityCheckSize,
ddorwin 2012/07/11 01:00:27 local var iv_offset might help readability (and fi
fgalligan1 2012/07/11 22:06:33 It fits on one line (must have had a refactor). If
217 sizeof(network_iv));
218 const uint64 iv = base::NetToHost64(network_iv);
203 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( 219 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig(
204 video_encryption_key_id_.get(), video_encryption_key_id_size_))); 220 data, kWebMIntegrityCheckSize,
221 reinterpret_cast<const uint8*>(&iv), sizeof(iv),
222 video_encryption_key_id_.get(), video_encryption_key_id_size_,
223 sizeof(iv))));
205 } 224 }
206 225
207 buffer->SetTimestamp(timestamp); 226 buffer->SetTimestamp(timestamp);
208 if (cluster_start_time_ == kNoTimestamp()) 227 if (cluster_start_time_ == kNoTimestamp())
209 cluster_start_time_ = timestamp; 228 cluster_start_time_ = timestamp;
210 229
211 if (block_duration >= 0) { 230 if (block_duration >= 0) {
212 buffer->SetDuration(base::TimeDelta::FromMicroseconds( 231 buffer->SetDuration(base::TimeDelta::FromMicroseconds(
213 block_duration * timecode_multiplier_)); 232 block_duration * timecode_multiplier_));
214 } 233 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 DVLOG(2) << "AddToBufferQueue() : " << track_num_ 324 DVLOG(2) << "AddToBufferQueue() : " << track_num_
306 << " ts " << buffer->GetTimestamp().InSecondsF() 325 << " ts " << buffer->GetTimestamp().InSecondsF()
307 << " dur " << buffer->GetDuration().InSecondsF() 326 << " dur " << buffer->GetDuration().InSecondsF()
308 << " kf " << buffer->IsKeyframe() 327 << " kf " << buffer->IsKeyframe()
309 << " size " << buffer->GetDataSize(); 328 << " size " << buffer->GetDataSize();
310 329
311 buffers_.push_back(buffer); 330 buffers_.push_back(buffer);
312 } 331 }
313 332
314 } // namespace media 333 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698