Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 }; | 61 }; |
| 57 | 62 |
| 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 |
| 71 // This is required for running in the sandbox, and should no longer be required | |
| 72 // after http://crbug.com/91970 is fixed. | |
| 73 static bool InitializeFFmpegLibraries() { | |
| 74 FilePath file_path; | |
| 75 CHECK(PathService::Get(base::DIR_EXE, &file_path)); | |
| 76 CHECK(media::InitializeMediaLibrary(file_path)); | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 static base::AtExitManager g_at_exit_manager; | |
| 81 static bool g_cdm_module_initialized = InitializeFFmpegLibraries(); | |
| 82 | |
| 66 cdm::ContentDecryptionModule* CreateCdmInstance( | 83 cdm::ContentDecryptionModule* CreateCdmInstance( |
| 67 cdm::Allocator* allocator, cdm::CdmHost* host) { | 84 cdm::Allocator* allocator, cdm::CdmHost* host) { |
| 85 DVLOG(1) << "CreateCdmInstance()"; | |
| 86 CHECK(g_cdm_module_initialized); | |
|
ddorwin
2012/10/22 23:31:35
I don't think we need this.
Tom Finegan
2012/10/23 00:12:14
Done.
| |
| 68 return new webkit_media::ClearKeyCdm(allocator, host); | 87 return new webkit_media::ClearKeyCdm(allocator, host); |
| 69 } | 88 } |
| 70 | 89 |
| 71 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) { | 90 void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) { |
| 91 DVLOG(1) << "DestroyCdmInstance()"; | |
| 72 delete instance; | 92 delete instance; |
| 73 } | 93 } |
| 74 | 94 |
| 75 const char* GetCdmVersion() { | 95 const char* GetCdmVersion() { |
| 76 return kClearKeyCdmVersion; | 96 return kClearKeyCdmVersion; |
| 77 } | 97 } |
| 78 | 98 |
| 79 namespace webkit_media { | 99 namespace webkit_media { |
| 80 | 100 |
| 81 ClearKeyCdm::Client::Client() : status_(kKeyError), key_message_length_(0) {} | 101 ClearKeyCdm::Client::Client() : status_(kKeyError), key_message_length_(0) {} |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 } | 257 } |
| 238 | 258 |
| 239 cdm::Status ClearKeyCdm::InitializeAudioDecoder( | 259 cdm::Status ClearKeyCdm::InitializeAudioDecoder( |
| 240 const cdm::AudioDecoderConfig& audio_decoder_config) { | 260 const cdm::AudioDecoderConfig& audio_decoder_config) { |
| 241 NOTIMPLEMENTED(); | 261 NOTIMPLEMENTED(); |
| 242 return cdm::kSessionError; | 262 return cdm::kSessionError; |
| 243 } | 263 } |
| 244 | 264 |
| 245 cdm::Status ClearKeyCdm::InitializeVideoDecoder( | 265 cdm::Status ClearKeyCdm::InitializeVideoDecoder( |
| 246 const cdm::VideoDecoderConfig& video_decoder_config) { | 266 const cdm::VideoDecoderConfig& video_decoder_config) { |
| 247 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 267 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
|
ddorwin
2012/10/22 23:31:35
The correct fix for non-FFmpeg-using platforms is
Tom Finegan
2012/10/23 00:12:14
Done.
| |
| 248 NOTIMPLEMENTED(); | 268 if (!video_decoder_) |
| 249 return cdm::kSessionError; | 269 video_decoder_.reset(new webkit_media::FFmpegCdmVideoDecoder(allocator_)); |
| 270 | |
| 271 if (!video_decoder_->Initialize(video_decoder_config)) | |
| 272 return cdm::kSessionError; | |
| 250 #else | 273 #else |
| 251 video_size_ = video_decoder_config.coded_size; | 274 video_size_ = video_decoder_config.coded_size; |
| 275 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | |
| 252 return cdm::kSuccess; | 276 return cdm::kSuccess; |
| 253 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | |
| 254 } | 277 } |
| 255 | 278 |
| 256 void ClearKeyCdm::ResetDecoder(cdm::StreamType) { | 279 void ClearKeyCdm::ResetDecoder(cdm::StreamType decoder_type) { |
| 257 NOTIMPLEMENTED(); | 280 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
|
ddorwin
2012/10/22 23:31:35
These would be #if defined(ENABLE_DECODE_SUPPORT),
Tom Finegan
2012/10/23 00:12:14
Didn't do this yet. Ok to leave for another CL?
| |
| 281 DCHECK(decoder_type == cdm::kStreamTypeVideo); | |
| 282 video_decoder_->Reset(); | |
| 283 #endif | |
| 258 } | 284 } |
| 259 | 285 |
| 260 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType) { | 286 void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType decoder_type) { |
| 261 NOTIMPLEMENTED(); | 287 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
| 288 DCHECK(decoder_type == cdm::kStreamTypeVideo); | |
| 289 video_decoder_->Deinitialize(); | |
| 290 #endif | |
| 262 } | 291 } |
| 263 | 292 |
| 264 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( | 293 cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( |
| 265 const cdm::InputBuffer& encrypted_buffer, | 294 const cdm::InputBuffer& encrypted_buffer, |
| 266 cdm::VideoFrame* video_frame) { | 295 cdm::VideoFrame* decoded_frame) { |
| 267 if (!encrypted_buffer.data) { | 296 if (!encrypted_buffer.data) { |
| 268 video_frame->set_format(cdm::kEmptyVideoFrame); | 297 decoded_frame->set_format(cdm::kEmptyVideoFrame); |
| 269 return cdm::kSuccess; | 298 return cdm::kSuccess; |
| 270 } | 299 } |
| 271 | 300 |
| 272 scoped_refptr<media::DecoderBuffer> decoder_buffer = | 301 scoped_refptr<media::DecoderBuffer> decoder_buffer = |
| 273 CopyDecoderBufferFrom(encrypted_buffer); | 302 CopyDecoderBufferFrom(encrypted_buffer); |
| 274 | 303 |
| 275 // Callback is called synchronously, so we can use variables on the stack. | 304 // Callback is called synchronously, so we can use variables on the stack. |
| 276 media::Decryptor::Status status; | 305 media::Decryptor::Status status; |
| 277 scoped_refptr<media::DecoderBuffer> buffer; | 306 scoped_refptr<media::DecoderBuffer> buffer; |
| 278 decryptor_.Decrypt(media::Decryptor::kVideo, | 307 decryptor_.Decrypt(media::Decryptor::kVideo, |
| 279 decoder_buffer, | 308 decoder_buffer, |
| 280 base::Bind(&CopyDecryptResults, &status, &buffer)); | 309 base::Bind(&CopyDecryptResults, &status, &buffer)); |
| 281 | 310 |
| 282 if (status == media::Decryptor::kError) | 311 if (status == media::Decryptor::kError) |
| 283 return cdm::kDecryptError; | 312 return cdm::kDecryptError; |
| 284 | 313 |
| 285 if (status == media::Decryptor::kNoKey) | 314 if (status == media::Decryptor::kNoKey) |
| 286 return cdm::kNoKey; | 315 return cdm::kNoKey; |
| 287 | 316 |
| 288 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 317 #if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
| 289 NOTIMPLEMENTED(); | 318 DCHECK(status == media::Decryptor::kSuccess); |
| 290 return cdm::kDecodeError; | 319 DCHECK(buffer); |
| 320 return video_decoder_->DecodeFrame(buffer.get()->GetData(), | |
| 321 buffer->GetDataSize(), | |
| 322 encrypted_buffer.timestamp, | |
| 323 decoded_frame); | |
| 291 #else | 324 #else |
| 292 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame); | 325 GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), decoded_frame); |
| 293 return cdm::kSuccess; | 326 return cdm::kSuccess; |
| 294 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER | 327 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
| 295 } | 328 } |
| 296 | 329 |
| 297 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) | 330 #if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) |
| 298 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, | 331 void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, |
| 299 cdm::VideoFrame* video_frame) { | 332 cdm::VideoFrame* video_frame) { |
| 300 // Choose non-zero alignment and padding on purpose for testing. | 333 // Choose non-zero alignment and padding on purpose for testing. |
| 301 const int kAlignment = 8; | 334 const int kAlignment = 8; |
| 302 const int kPadding = 16; | 335 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 | 370 #endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER |
| 338 | 371 |
| 339 cdm::Status ClearKeyCdm::DecryptAndDecodeSamples( | 372 cdm::Status ClearKeyCdm::DecryptAndDecodeSamples( |
| 340 const cdm::InputBuffer& encrypted_buffer, | 373 const cdm::InputBuffer& encrypted_buffer, |
| 341 cdm::Buffer* sample_buffer) { | 374 cdm::Buffer* sample_buffer) { |
| 342 NOTIMPLEMENTED(); | 375 NOTIMPLEMENTED(); |
| 343 return cdm::kDecryptError; | 376 return cdm::kDecryptError; |
| 344 } | 377 } |
| 345 | 378 |
| 346 } // namespace webkit_media | 379 } // namespace webkit_media |
| OLD | NEW |