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/at_exit.h" | |
10 #include "base/file_path.h" | |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/path_service.h" | |
11 #include "base/time.h" | 14 #include "base/time.h" |
12 #include "media/base/decoder_buffer.h" | 15 #include "media/base/decoder_buffer.h" |
16 #include "media/base/media.h" | |
17 #include "webkit/media/crypto/ppapi/ffmpeg_cdm_video_decoder.h" | |
13 | 18 |
14 static const char kClearKeyCdmVersion[] = "0.1.0.0"; | 19 static const char kClearKeyCdmVersion[] = "0.1.0.0"; |
15 | 20 |
16 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( | 21 static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( |
17 const cdm::InputBuffer& input_buffer) { | 22 const cdm::InputBuffer& input_buffer) { |
18 DCHECK(input_buffer.data); | 23 DCHECK(input_buffer.data); |
19 // TODO(tomfinegan): Get rid of this copy. | 24 // TODO(tomfinegan): Get rid of this copy. |
20 scoped_refptr<media::DecoderBuffer> output_buffer = | 25 scoped_refptr<media::DecoderBuffer> output_buffer = |
21 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); | 26 media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); |
22 | 27 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 template<typename Type> | 63 template<typename Type> |
59 static Type* AllocateAndCopy(const Type* data, int size) { | 64 static Type* AllocateAndCopy(const Type* data, int size) { |
60 COMPILE_ASSERT(sizeof(Type) == 1, type_size_is_not_one); | 65 COMPILE_ASSERT(sizeof(Type) == 1, type_size_is_not_one); |
61 Type* copy = new Type[size]; | 66 Type* copy = new Type[size]; |
62 memcpy(copy, data, size); | 67 memcpy(copy, data, size); |
63 return copy; | 68 return copy; |
64 } | 69 } |
65 | 70 |
66 cdm::ContentDecryptionModule* CreateCdmInstance( | 71 cdm::ContentDecryptionModule* CreateCdmInstance( |
67 cdm::Allocator* allocator, cdm::CdmHost* host) { | 72 cdm::Allocator* allocator, cdm::CdmHost* host) { |
73 DVLOG(1) << "CreateCdmInstance()"; | |
ddorwin
2012/10/21 22:10:53
This should all only be done once per module. That
Tom Finegan
2012/10/22 02:34:58
Discussed offline. Is this way OK, or do you want
ddorwin
2012/10/22 05:04:36
It's up to you. I'm fine with landing this then mo
| |
74 base::AtExitManager at_exit_manager; | |
75 | |
76 FilePath file_path; | |
77 CHECK(PathService::Get(base::DIR_EXE, &file_path)); | |
78 CHECK(media::InitializeMediaLibrary(file_path)); | |
79 | |
68 return new webkit_media::ClearKeyCdm(allocator, host); | 80 return new webkit_media::ClearKeyCdm(allocator, host); |
69 } | 81 } |
70 | 82 |
71 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) { | 83 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) { |
84 DVLOG(1) << "DestroyCdmInstance()"; | |
72 delete instance; | 85 delete instance; |
73 } | 86 } |
74 | 87 |
75 const char* GetCdmVersion() { | 88 const char* GetCdmVersion() { |
76 return kClearKeyCdmVersion; | 89 return kClearKeyCdmVersion; |
77 } | 90 } |
78 | 91 |
79 namespace webkit_media { | 92 namespace webkit_media { |
80 | 93 |
81 ClearKeyCdm::Client::Client() : status_(kKeyError), key_message_length_(0) {} | 94 ClearKeyCdm::Client::Client() : status_(kKeyError), key_message_length_(0) {} |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 | 251 |
239 cdm::Status ClearKeyCdm::InitializeAudioDecoder( | 252 cdm::Status ClearKeyCdm::InitializeAudioDecoder( |
240 const cdm::AudioDecoderConfig& audio_decoder_config) { | 253 const cdm::AudioDecoderConfig& audio_decoder_config) { |
241 NOTIMPLEMENTED(); | 254 NOTIMPLEMENTED(); |
242 return cdm::kSessionError; | 255 return cdm::kSessionError; |
243 } | 256 } |
244 | 257 |
245 cdm::Status ClearKeyCdm::InitializeVideoDecoder( | 258 cdm::Status ClearKeyCdm::InitializeVideoDecoder( |
246 const cdm::VideoDecoderConfig& video_decoder_config) { | 259 const cdm::VideoDecoderConfig& video_decoder_config) { |
247 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 260 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
248 NOTIMPLEMENTED(); | 261 if (!video_decoder_) |
249 return cdm::kSessionError; | 262 video_decoder_.reset(new webkit_media::FFmpegCdmVideoDecoder(allocator_)); |
263 | |
264 if (!video_decoder_->Initialize(video_decoder_config)) | |
265 return cdm::kSessionError; | |
250 #else | 266 #else |
251 video_size_ = video_decoder_config.coded_size; | 267 video_size_ = video_decoder_config.coded_size; |
268 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | |
252 return cdm::kSuccess; | 269 return cdm::kSuccess; |
253 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | |
254 } | 270 } |
255 | 271 |
256 void ClearKeyCdm::ResetDecoder(cdm::StreamType) { | 272 void ClearKeyCdm::ResetDecoder(cdm::StreamType decoder_type) { |
257 NOTIMPLEMENTED(); | 273 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
274 DCHECK(decoder_type == cdm::kStreamTypeVideo); | |
275 video_decoder_->Reset(); | |
276 #endif | |
258 } | 277 } |
259 | 278 |
260 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType) { | 279 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType decoder_type) { |
261 NOTIMPLEMENTED(); | 280 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
281 DCHECK(decoder_type == cdm::kStreamTypeVideo); | |
282 video_decoder_->Deinitialize(); | |
283 #endif | |
262 } | 284 } |
263 | 285 |
264 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( | 286 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( |
265 const cdm::InputBuffer& encrypted_buffer, | 287 const cdm::InputBuffer& encrypted_buffer, |
266 cdm::VideoFrame* video_frame) { | 288 cdm::VideoFrame* decoded_frame) { |
267 if (!encrypted_buffer.data) { | 289 if (!encrypted_buffer.data) { |
268 video_frame->set_format(cdm::kEmptyVideoFrame); | 290 decoded_frame->set_format(cdm::kEmptyVideoFrame); |
269 return cdm::kSuccess; | 291 return cdm::kSuccess; |
270 } | 292 } |
271 | 293 |
272 scoped_refptr<media::DecoderBuffer> decoder_buffer = | 294 scoped_refptr<media::DecoderBuffer> decoder_buffer = |
273 CopyDecoderBufferFrom(encrypted_buffer); | 295 CopyDecoderBufferFrom(encrypted_buffer); |
274 | 296 |
275 // Callback is called synchronously, so we can use variables on the stack. | 297 // Callback is called synchronously, so we can use variables on the stack. |
276 media::Decryptor::Status status; | 298 media::Decryptor::Status status; |
277 scoped_refptr<media::DecoderBuffer> buffer; | 299 scoped_refptr<media::DecoderBuffer> buffer; |
278 decryptor_.Decrypt(media::Decryptor::kVideo, | 300 decryptor_.Decrypt(media::Decryptor::kVideo, |
279 decoder_buffer, | 301 decoder_buffer, |
280 base::Bind(&CopyDecryptResults, &status, &buffer)); | 302 base::Bind(&CopyDecryptResults, &status, &buffer)); |
281 | 303 |
282 if (status == media::Decryptor::kError) | 304 if (status == media::Decryptor::kError) |
283 return cdm::kDecryptError; | 305 return cdm::kDecryptError; |
284 | 306 |
285 if (status == media::Decryptor::kNoKey) | 307 if (status == media::Decryptor::kNoKey) |
286 return cdm::kNoKey; | 308 return cdm::kNoKey; |
287 | 309 |
288 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 310 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
289 NOTIMPLEMENTED(); | 311 DCHECK(status == media::Decryptor::kSuccess); |
290 return cdm::kDecodeError; | 312 DCHECK(buffer); |
313 return video_decoder_->DecodeFrame(buffer.get()->GetData(), | |
314 buffer->GetDataSize(), | |
315 encrypted_buffer.timestamp, | |
316 decoded_frame); | |
291 #else | 317 #else |
292 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame); | 318 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), decoded_frame); |
293 return cdm::kSuccess; | 319 return cdm::kSuccess; |
294 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | 320 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
295 } | 321 } |
296 | 322 |
297 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 323 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
298 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, | 324 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, |
299 cdm::VideoFrame* video_frame) { | 325 cdm::VideoFrame* video_frame) { |
300 // Choose non-zero alignment and padding on purpose for testing. | 326 // Choose non-zero alignment and padding on purpose for testing. |
301 const int kAlignment = 8; | 327 const int kAlignment = 8; |
302 const int kPadding = 16; | 328 const int kPadding = 16; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | 363 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
338 | 364 |
339 cdm::Status ClearKeyCdm::DecryptAndDecodeSamples( | 365 cdm::Status ClearKeyCdm::DecryptAndDecodeSamples( |
340 const cdm::InputBuffer& encrypted_buffer, | 366 const cdm::InputBuffer& encrypted_buffer, |
341 cdm::Buffer* sample_buffer) { | 367 cdm::Buffer* sample_buffer) { |
342 NOTIMPLEMENTED(); | 368 NOTIMPLEMENTED(); |
343 return cdm::kDecryptError; | 369 return cdm::kDecryptError; |
344 } | 370 } |
345 | 371 |
346 } // namespace webkit_media | 372 } // namespace webkit_media |
OLD | NEW |