| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Every encrypted Block has an HMAC and IV prepended to it. Current WebM |
| 192 // encrypted request for comments specification is here |
| 193 // http://wiki.webmproject.org/encryption/webm-encryption-rfc |
| 194 bool encrypted = track_num == video_.track_num() && |
| 195 video_encryption_key_id_.get(); |
| 196 // If encrypted skip past the HMAC. |
| 197 int data_offset = (encrypted) ? kWebMIntegrityCheckSize : 0; |
| 198 |
| 190 // The first bit of the flags is set when the block contains only keyframes. | 199 // The first bit of the flags is set when the block contains only keyframes. |
| 191 // http://www.matroska.org/technical/specs/index.html | 200 // http://www.matroska.org/technical/specs/index.html |
| 192 bool is_keyframe = (flags & 0x80) != 0; | 201 bool is_keyframe = (flags & 0x80) != 0; |
| 193 scoped_refptr<StreamParserBuffer> buffer = | 202 scoped_refptr<StreamParserBuffer> buffer = |
| 194 StreamParserBuffer::CopyFrom(data, size, is_keyframe); | 203 StreamParserBuffer::CopyFrom(data + data_offset, |
| 204 size - data_offset, |
| 205 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, |
| 210 data + kWebMIntegrityCheckSize, |
| 211 sizeof(network_iv)); |
| 212 const uint64 iv = base::NetToHost64(network_iv); |
| 197 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( | 213 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( |
| 198 video_encryption_key_id_.get(), video_encryption_key_id_size_))); | 214 data, kWebMIntegrityCheckSize, |
| 215 reinterpret_cast<const uint8*>(&iv), sizeof(iv), |
| 216 video_encryption_key_id_.get(), video_encryption_key_id_size_, |
| 217 sizeof(iv)))); |
| 199 } | 218 } |
| 200 | 219 |
| 201 buffer->SetTimestamp(timestamp); | 220 buffer->SetTimestamp(timestamp); |
| 202 | 221 |
| 203 if (block_duration >= 0) { | 222 if (block_duration >= 0) { |
| 204 buffer->SetDuration(base::TimeDelta::FromMicroseconds( | 223 buffer->SetDuration(base::TimeDelta::FromMicroseconds( |
| 205 block_duration * timecode_multiplier_)); | 224 block_duration * timecode_multiplier_)); |
| 206 } | 225 } |
| 207 | 226 |
| 208 if (track_num == audio_.track_num()) { | 227 if (track_num == audio_.track_num()) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 DVLOG(2) << "AddToBufferQueue() : " << track_num_ | 316 DVLOG(2) << "AddToBufferQueue() : " << track_num_ |
| 298 << " ts " << buffer->GetTimestamp().InSecondsF() | 317 << " ts " << buffer->GetTimestamp().InSecondsF() |
| 299 << " dur " << buffer->GetDuration().InSecondsF() | 318 << " dur " << buffer->GetDuration().InSecondsF() |
| 300 << " kf " << buffer->IsKeyframe() | 319 << " kf " << buffer->IsKeyframe() |
| 301 << " size " << buffer->GetDataSize(); | 320 << " size " << buffer->GetDataSize(); |
| 302 | 321 |
| 303 buffers_.push_back(buffer); | 322 buffers_.push_back(buffer); |
| 304 } | 323 } |
| 305 | 324 |
| 306 } // namespace media | 325 } // namespace media |
| OLD | NEW |