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 "webkit/media/crypto/ppapi/clear_key_cdm.h" | 5 #include "webkit/media/crypto/ppapi/clear_key_cdm.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "media/base/decoder_buffer.h" | 12 #include "media/base/decoder_buffer.h" |
13 #include "webkit/media/crypto/ppapi/ffmpeg_cdm_video_decoder.h" | |
13 | 14 |
14 static const char kClearKeyCdmVersion[] = "0.1.0.0"; | 15 static const char kClearKeyCdmVersion[] = "0.1.0.0"; |
15 | 16 |
16 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 17 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
17 const cdm::InputBuffer& input_buffer) { | 18 const cdm::InputBuffer& input_buffer) { |
18 // TODO(tomfinegan): Get rid of this copy. | 19 // TODO(tomfinegan): Get rid of this copy. |
19 scoped_refptr<media::DecoderBuffer> output_buffer = | 20 scoped_refptr<media::DecoderBuffer> output_buffer = |
20 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); | 21 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); |
21 | 22 |
22 std::vector<media::SubsampleEntry> subsamples; | 23 std::vector<media::SubsampleEntry> subsamples; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 memcpy(reinterpret_cast<void*>(decrypted_block->buffer()->data()), | 229 memcpy(reinterpret_cast<void*>(decrypted_block->buffer()->data()), |
229 buffer->GetData(), | 230 buffer->GetData(), |
230 data_size); | 231 data_size); |
231 | 232 |
232 decrypted_block->set_timestamp(buffer->GetTimestamp().InMicroseconds()); | 233 decrypted_block->set_timestamp(buffer->GetTimestamp().InMicroseconds()); |
233 return cdm::kSuccess; | 234 return cdm::kSuccess; |
234 } | 235 } |
235 | 236 |
236 cdm::Status ClearKeyCdm::InitializeVideoDecoder( | 237 cdm::Status ClearKeyCdm::InitializeVideoDecoder( |
237 const cdm::VideoDecoderConfig& video_decoder_config) { | 238 const cdm::VideoDecoderConfig& video_decoder_config) { |
238 NOTIMPLEMENTED(); | 239 video_decoder_.reset(new webkit_media::FFmpegCdmVideoDecoder(allocator_)); |
ddorwin
2012/10/17 03:18:20
Per discussion in patch 18, shouldn't we only do t
Tom Finegan
2012/10/17 04:25:29
Thanks, missed it. Done.
| |
239 return cdm::kSessionError; | 240 if (!video_decoder_->Initialize(video_decoder_config)) |
241 return cdm::kSessionError; | |
242 | |
243 return cdm::kSuccess; | |
240 } | 244 } |
241 | 245 |
242 void ClearKeyCdm::ResetDecoder(cdm::StreamType) { | 246 void ClearKeyCdm::ResetDecoder(cdm::StreamType decoder_type) { |
243 NOTIMPLEMENTED(); | 247 DCHECK(decoder_type == cdm::kStreamTypeVideo); |
248 video_decoder_->Reset(); | |
244 } | 249 } |
245 | 250 |
246 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType) { | 251 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType decoder_type) { |
247 NOTIMPLEMENTED(); | 252 DCHECK(decoder_type == cdm::kStreamTypeVideo); |
253 video_decoder_->Deinitialize(); | |
248 } | 254 } |
249 | 255 |
250 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( | 256 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( |
251 const cdm::InputBuffer& encrypted_buffer, | 257 const cdm::InputBuffer& encrypted_buffer, |
252 cdm::VideoFrame* video_frame) { | 258 cdm::VideoFrame* decoded_frame) { |
253 NOTIMPLEMENTED(); | 259 scoped_refptr<media::DecoderBuffer> decoder_buffer = |
254 return cdm::kDecryptError; | 260 CopyDecoderBufferFrom(encrypted_buffer); |
261 | |
262 // Callback is called synchronously, so we can use variables on the stack. | |
263 media::Decryptor::Status status; | |
264 scoped_refptr<media::DecoderBuffer> buffer; | |
265 decryptor_.Decrypt(decoder_buffer, | |
266 base::Bind(&CopyDecryptResults, &status, &buffer)); | |
267 | |
268 if (status == media::Decryptor::kError) | |
269 return cdm::kDecryptError; | |
270 if (status == media::Decryptor::kNoKey) | |
271 return cdm::kNoKey; | |
272 | |
273 DCHECK(status == media::Decryptor::kSuccess); | |
274 | |
275 DCHECK(buffer); | |
276 return video_decoder_->DecodeFrame(buffer.get()->GetData(), | |
277 buffer->GetDataSize(), | |
278 encrypted_buffer.timestamp, | |
279 decoded_frame); | |
255 } | 280 } |
256 | 281 |
257 } // namespace webkit_media | 282 } // namespace webkit_media |
OLD | NEW |