OLD | NEW |
---|---|
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 return false; | 178 return false; |
178 } | 179 } |
179 | 180 |
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 const base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( |
188 (cluster_timecode_ + timecode) * timecode_multiplier_); | 189 (cluster_timecode_ + timecode) * timecode_multiplier_); |
xhwang
2012/06/06 20:54:06
I remember scherkus@ told me that in media stack c
fgalligan1
2012/06/08 21:02:38
Thanks for the info. Done.
| |
189 | 190 |
191 const bool encrypted = track_num == video_.track_num() && | |
192 video_encryption_key_id_.get(); | |
193 | |
194 // Every encrypted Block has an HMAC and IV prepended to every encrypted | |
195 // frame. | |
196 const uint8* const frame_data = | |
197 encrypted ? data + kIntegrityCheckSize + kIVSize : data; | |
198 const int frame_size = | |
199 encrypted ? size - (kIntegrityCheckSize + kIVSize) : size; | |
200 | |
190 // The first bit of the flags is set when the block contains only keyframes. | 201 // The first bit of the flags is set when the block contains only keyframes. |
191 // http://www.matroska.org/technical/specs/index.html | 202 // http://www.matroska.org/technical/specs/index.html |
192 bool is_keyframe = (flags & 0x80) != 0; | 203 const bool is_keyframe = (flags & 0x80) != 0; |
193 scoped_refptr<StreamParserBuffer> buffer = | 204 scoped_refptr<StreamParserBuffer> buffer = |
194 StreamParserBuffer::CopyFrom(data, size, is_keyframe); | 205 StreamParserBuffer::CopyFrom(frame_data, frame_size, is_keyframe); |
195 | 206 |
196 if (track_num == video_.track_num() && video_encryption_key_id_.get()) { | 207 if (encrypted) { |
208 uint64 network_iv; | |
209 memcpy(&network_iv, data + kIntegrityCheckSize, sizeof(network_iv)); | |
210 const uint64 iv = base::NetToHost64(network_iv); | |
197 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( | 211 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( |
212 data, kIntegrityCheckSize, iv, | |
198 video_encryption_key_id_.get(), video_encryption_key_id_size_))); | 213 video_encryption_key_id_.get(), video_encryption_key_id_size_))); |
199 } | 214 } |
200 | 215 |
201 buffer->SetTimestamp(timestamp); | 216 buffer->SetTimestamp(timestamp); |
202 | 217 |
203 if (block_duration >= 0) { | 218 if (block_duration >= 0) { |
204 buffer->SetDuration(base::TimeDelta::FromMicroseconds( | 219 buffer->SetDuration(base::TimeDelta::FromMicroseconds( |
205 block_duration * timecode_multiplier_)); | 220 block_duration * timecode_multiplier_)); |
206 } | 221 } |
207 | 222 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 void WebMClusterParser::Track::Reset() { | 273 void WebMClusterParser::Track::Reset() { |
259 buffers_.clear(); | 274 buffers_.clear(); |
260 delayed_buffer_ = NULL; | 275 delayed_buffer_ = NULL; |
261 } | 276 } |
262 | 277 |
263 void WebMClusterParser::Track::ClearBufferQueue() { | 278 void WebMClusterParser::Track::ClearBufferQueue() { |
264 buffers_.clear(); | 279 buffers_.clear(); |
265 } | 280 } |
266 | 281 |
267 } // namespace media | 282 } // namespace media |
OLD | NEW |