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_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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 scoped_refptr<media::DecoderBuffer>* buffer_copy, | 198 scoped_refptr<media::DecoderBuffer>* buffer_copy, |
198 media::Decryptor::Status status, | 199 media::Decryptor::Status status, |
199 const scoped_refptr<media::DecoderBuffer>& buffer) { | 200 const scoped_refptr<media::DecoderBuffer>& buffer) { |
200 *status_copy = status; | 201 *status_copy = status; |
201 *buffer_copy = buffer; | 202 *buffer_copy = buffer; |
202 } | 203 } |
203 | 204 |
204 cdm::Status ClearKeyCdm::Decrypt( | 205 cdm::Status ClearKeyCdm::Decrypt( |
205 const cdm::InputBuffer& encrypted_buffer, | 206 const cdm::InputBuffer& encrypted_buffer, |
206 cdm::DecryptedBlock* decrypted_block) { | 207 cdm::DecryptedBlock* decrypted_block) { |
207 DVLOG(1) << "Decrypt()"; | 208 DVLOG(1) << "ClearKeyCdm::Decrypt()"; |
ddorwin
2012/10/13 03:54:42
Filename is already included in the log message.
Tom Finegan
2012/10/13 23:47:26
Done.
| |
208 | 209 |
209 scoped_refptr<media::DecoderBuffer> decoder_buffer = | 210 scoped_refptr<media::DecoderBuffer> decoder_buffer = |
210 CopyDecoderBufferFrom(encrypted_buffer); | 211 CopyDecoderBufferFrom(encrypted_buffer); |
211 | 212 |
212 // Callback is called synchronously, so we can use variables on the stack. | 213 // Callback is called synchronously, so we can use variables on the stack. |
213 media::Decryptor::Status status; | 214 media::Decryptor::Status status; |
214 scoped_refptr<media::DecoderBuffer> buffer; | 215 scoped_refptr<media::DecoderBuffer> buffer; |
215 decryptor_.Decrypt(decoder_buffer, | 216 decryptor_.Decrypt(decoder_buffer, |
216 base::Bind(&CopyDecryptResults, &status, &buffer)); | 217 base::Bind(&CopyDecryptResults, &status, &buffer)); |
217 | 218 |
(...skipping 10 matching lines...) Expand all 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::FFmpegVideoDecoder(allocator_)); |
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::kNoKey) | |
269 return cdm::kNoKey; | |
270 | |
ddorwin
2012/10/13 03:54:42
Need to handle kDecryptError. Then DCHECK(kSuccess
Tom Finegan
2012/10/13 23:47:26
Done.
| |
271 DCHECK(buffer); | |
272 int data_size = buffer->GetDataSize(); | |
ddorwin
2012/10/13 03:54:42
why do we need this?
Tom Finegan
2012/10/13 23:47:26
Removed.
| |
273 | |
274 if (!video_decoder_->DecodeFrame(buffer.get()->GetData(), data_size, | |
275 encrypted_buffer.timestamp, | |
276 decoded_frame)) { | |
277 LOG(ERROR) << "ClearKeyCdm::DecryptAndDecodeFrame() DecodeFrame failed"; | |
278 return cdm::kDecodeError; | |
279 } | |
280 | |
281 return cdm::kSuccess; | |
255 } | 282 } |
256 | 283 |
257 } // namespace webkit_media | 284 } // namespace webkit_media |
OLD | NEW |