Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <cstring> | 5 #include <cstring> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "build/build_config.h" | |
| 13 #include "media/cdm/ppapi/api/content_decryption_module.h" | 14 #include "media/cdm/ppapi/api/content_decryption_module.h" |
| 14 #include "media/cdm/ppapi/linked_ptr.h" | 15 #include "media/cdm/ppapi/linked_ptr.h" |
| 16 #include "ppapi/c/pp_completion_callback.h" | |
| 15 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
| 16 #include "ppapi/c/pp_stdint.h" | 18 #include "ppapi/c/pp_stdint.h" |
| 17 #include "ppapi/c/private/pp_content_decryptor.h" | 19 #include "ppapi/c/private/pp_content_decryptor.h" |
| 18 #include "ppapi/cpp/completion_callback.h" | 20 #include "ppapi/cpp/completion_callback.h" |
| 19 #include "ppapi/cpp/core.h" | 21 #include "ppapi/cpp/core.h" |
| 20 #include "ppapi/cpp/dev/buffer_dev.h" | 22 #include "ppapi/cpp/dev/buffer_dev.h" |
| 21 #include "ppapi/cpp/instance.h" | 23 #include "ppapi/cpp/instance.h" |
| 22 #include "ppapi/cpp/logging.h" | 24 #include "ppapi/cpp/logging.h" |
| 23 #include "ppapi/cpp/module.h" | 25 #include "ppapi/cpp/module.h" |
| 24 #include "ppapi/cpp/pass_ref.h" | 26 #include "ppapi/cpp/pass_ref.h" |
| 25 #include "ppapi/cpp/private/content_decryptor_private.h" | 27 #include "ppapi/cpp/private/content_decryptor_private.h" |
| 26 #include "ppapi/cpp/resource.h" | 28 #include "ppapi/cpp/resource.h" |
| 27 #include "ppapi/cpp/var.h" | 29 #include "ppapi/cpp/var.h" |
| 28 #include "ppapi/cpp/var_array_buffer.h" | 30 #include "ppapi/cpp/var_array_buffer.h" |
| 29 #include "ppapi/utility/completion_callback_factory.h" | 31 #include "ppapi/utility/completion_callback_factory.h" |
| 30 | 32 |
| 31 #if defined(CHECK_DOCUMENT_URL) | 33 #if defined(CHECK_DOCUMENT_URL) |
| 32 #include "ppapi/cpp/dev/url_util_dev.h" | 34 #include "ppapi/cpp/dev/url_util_dev.h" |
| 33 #include "ppapi/cpp/instance_handle.h" | 35 #include "ppapi/cpp/instance_handle.h" |
| 34 #endif // defined(CHECK_DOCUMENT_URL) | 36 #endif // defined(CHECK_DOCUMENT_URL) |
| 35 | 37 |
| 38 #if defined(OS_CHROMEOS) | |
| 39 #include "ppapi/cpp/private/output_protection_private.h" | |
| 40 #include "ppapi/cpp/private/platform_verification.h" | |
| 41 #endif | |
| 42 | |
| 36 namespace { | 43 namespace { |
| 37 | 44 |
| 38 bool IsMainThread() { | 45 bool IsMainThread() { |
| 39 return pp::Module::Get()->core()->IsMainThread(); | 46 return pp::Module::Get()->core()->IsMainThread(); |
| 40 } | 47 } |
| 41 | 48 |
| 42 // Posts a task to run |cb| on the main thread. The task is posted even if the | 49 // Posts a task to run |cb| on the main thread. The task is posted even if the |
| 43 // current thread is the main thread. | 50 // current thread is the main thread. |
| 44 void PostOnMain(pp::CompletionCallback cb) { | 51 void PostOnMain(pp::CompletionCallback cb) { |
| 45 pp::Module::Get()->core()->CallOnMainThread(0, cb, PP_OK); | 52 pp::Module::Get()->core()->CallOnMainThread(0, cb, PP_OK); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 plane_offsets_[i] = 0; | 456 plane_offsets_[i] = 0; |
| 450 strides_[i] = 0; | 457 strides_[i] = 0; |
| 451 } | 458 } |
| 452 } | 459 } |
| 453 | 460 |
| 454 VideoFrameImpl::~VideoFrameImpl() { | 461 VideoFrameImpl::~VideoFrameImpl() { |
| 455 if (frame_buffer_) | 462 if (frame_buffer_) |
| 456 frame_buffer_->Destroy(); | 463 frame_buffer_->Destroy(); |
| 457 } | 464 } |
| 458 | 465 |
| 459 class AudioFramesImpl : public cdm::AudioFrames { | 466 class AudioFramesImpl : public cdm::AudioFrames_1, |
| 467 public cdm::AudioFrames_2 { | |
| 460 public: | 468 public: |
| 461 AudioFramesImpl() : buffer_(NULL) {} | 469 AudioFramesImpl() : buffer_(NULL), format_(cdm::kAudioFormatS16) {} |
| 462 virtual ~AudioFramesImpl() { | 470 virtual ~AudioFramesImpl() { |
| 463 if (buffer_) | 471 if (buffer_) |
| 464 buffer_->Destroy(); | 472 buffer_->Destroy(); |
| 465 } | 473 } |
| 466 | 474 |
| 467 // AudioFrames implementation. | 475 // AudioFrames implementation. |
| 468 virtual void SetFrameBuffer(cdm::Buffer* buffer) OVERRIDE { | 476 virtual void SetFrameBuffer(cdm::Buffer* buffer) OVERRIDE { |
| 469 buffer_ = static_cast<PpbBuffer*>(buffer); | 477 buffer_ = static_cast<PpbBuffer*>(buffer); |
| 470 } | 478 } |
| 471 virtual cdm::Buffer* FrameBuffer() OVERRIDE { | 479 virtual cdm::Buffer* FrameBuffer() OVERRIDE { |
| 472 return buffer_; | 480 return buffer_; |
| 473 } | 481 } |
| 482 virtual void SetFormat(cdm::AudioFormat format) OVERRIDE { | |
| 483 format_ = format; | |
| 484 } | |
| 485 virtual cdm::AudioFormat Format() const OVERRIDE { | |
| 486 return format_; | |
| 487 } | |
| 474 | 488 |
| 475 private: | 489 private: |
| 476 PpbBuffer* buffer_; | 490 PpbBuffer* buffer_; |
| 491 cdm::AudioFormat format_; | |
| 477 | 492 |
| 478 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); | 493 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); |
| 479 }; | 494 }; |
| 480 | 495 |
| 481 // GetCdmHostFunc implementation. | 496 // GetCdmHostFunc implementation. |
| 482 void* GetCdmHost(int host_interface_version, void* user_data); | 497 void* GetCdmHost(int host_interface_version, void* user_data); |
| 483 | 498 |
| 484 // A wrapper class for abstracting away PPAPI interaction and threading for a | 499 // A wrapper class for abstracting away PPAPI interaction and threading for a |
| 485 // Content Decryption Module (CDM). | 500 // Content Decryption Module (CDM). |
| 486 class CdmWrapper : public pp::Instance, | 501 class CdmWrapper : public pp::Instance, |
| 487 public pp::ContentDecryptor_Private, | 502 public pp::ContentDecryptor_Private, |
| 488 public cdm::Host { | 503 public cdm::Host_1, |
| 504 public cdm::Host_2 { | |
| 489 public: | 505 public: |
| 490 CdmWrapper(PP_Instance instance, pp::Module* module); | 506 CdmWrapper(PP_Instance instance, pp::Module* module); |
| 491 virtual ~CdmWrapper(); | 507 virtual ~CdmWrapper(); |
| 492 | 508 |
| 493 // pp::Instance implementation. | 509 // pp::Instance implementation. |
| 494 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 510 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
| 495 return true; | 511 return true; |
| 496 } | 512 } |
| 497 | 513 |
| 498 // PPP_ContentDecryptor_Private implementation. | 514 // PPP_ContentDecryptor_Private implementation. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 517 pp::Buffer_Dev extra_data_buffer) OVERRIDE; | 533 pp::Buffer_Dev extra_data_buffer) OVERRIDE; |
| 518 virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type, | 534 virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type, |
| 519 uint32_t request_id) OVERRIDE; | 535 uint32_t request_id) OVERRIDE; |
| 520 virtual void ResetDecoder(PP_DecryptorStreamType decoder_type, | 536 virtual void ResetDecoder(PP_DecryptorStreamType decoder_type, |
| 521 uint32_t request_id) OVERRIDE; | 537 uint32_t request_id) OVERRIDE; |
| 522 virtual void DecryptAndDecode( | 538 virtual void DecryptAndDecode( |
| 523 PP_DecryptorStreamType decoder_type, | 539 PP_DecryptorStreamType decoder_type, |
| 524 pp::Buffer_Dev encrypted_buffer, | 540 pp::Buffer_Dev encrypted_buffer, |
| 525 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 541 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
| 526 | 542 |
| 527 // cdm::Host implementation. | 543 // cdm::Host_1 implementation. |
| 528 virtual cdm::Buffer* Allocate(int32_t capacity) OVERRIDE; | 544 virtual cdm::Buffer* Allocate(int32_t capacity) OVERRIDE; |
| 529 virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE; | 545 virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE; |
| 530 virtual double GetCurrentWallTimeInSeconds() OVERRIDE; | 546 virtual double GetCurrentWallTimeInSeconds() OVERRIDE; |
| 531 virtual void SendKeyMessage( | 547 virtual void SendKeyMessage( |
| 532 const char* session_id, int32_t session_id_length, | 548 const char* session_id, int32_t session_id_length, |
| 533 const char* message, int32_t message_length, | 549 const char* message, int32_t message_length, |
| 534 const char* default_url, int32_t default_url_length) OVERRIDE; | 550 const char* default_url, int32_t default_url_length) OVERRIDE; |
| 535 virtual void SendKeyError(const char* session_id, | 551 virtual void SendKeyError(const char* session_id, |
| 536 int32_t session_id_length, | 552 int32_t session_id_length, |
| 537 cdm::MediaKeyError error_code, | 553 cdm::MediaKeyError error_code, |
| 538 uint32_t system_code) OVERRIDE; | 554 uint32_t system_code) OVERRIDE; |
| 539 virtual void GetPrivateData(int32_t* instance, | 555 virtual void GetPrivateData(int32_t* instance, |
| 540 GetPrivateInterface* get_interface) OVERRIDE; | 556 GetPrivateInterface* get_interface) OVERRIDE; |
| 541 | 557 |
| 558 // cdm::Host_2 implementation. | |
| 559 virtual bool CanChallengePlatform() OVERRIDE; | |
| 560 virtual void SendPlatformChallenge( | |
| 561 const char* service_id, int32_t service_id_length, | |
| 562 const char* challenge, int32_t challenge_length) OVERRIDE; | |
| 563 virtual void EnableOutputProtection( | |
| 564 uint32_t desired_protection_mask) OVERRIDE; | |
| 565 virtual void QueryOutputProtectionStatus() OVERRIDE; | |
| 566 | |
| 542 private: | 567 private: |
| 543 struct SessionInfo { | 568 struct SessionInfo { |
| 544 SessionInfo(const std::string& key_system_in, | 569 SessionInfo(const std::string& key_system_in, |
| 545 const std::string& session_id_in) | 570 const std::string& session_id_in) |
| 546 : key_system(key_system_in), | 571 : key_system(key_system_in), |
| 547 session_id(session_id_in) {} | 572 session_id(session_id_in) {} |
| 548 const std::string key_system; | 573 const std::string key_system; |
| 549 const std::string session_id; | 574 const std::string session_id; |
| 550 }; | 575 }; |
| 551 | 576 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 void DeliverSamples(int32_t result, | 624 void DeliverSamples(int32_t result, |
| 600 const cdm::Status& status, | 625 const cdm::Status& status, |
| 601 const LinkedAudioFrames& audio_frames, | 626 const LinkedAudioFrames& audio_frames, |
| 602 const PP_DecryptTrackingInfo& tracking_info); | 627 const PP_DecryptTrackingInfo& tracking_info); |
| 603 | 628 |
| 604 // Helper for SetTimer(). | 629 // Helper for SetTimer(). |
| 605 void TimerExpired(int32_t result, void* context); | 630 void TimerExpired(int32_t result, void* context); |
| 606 | 631 |
| 607 bool IsValidVideoFrame(const LinkedVideoFrame& video_frame); | 632 bool IsValidVideoFrame(const LinkedVideoFrame& video_frame); |
| 608 | 633 |
| 634 #if defined(OS_CHROMEOS) | |
| 635 void CanChallengePlatformDone(int32_t result, bool can_challenge_platform); | |
| 636 void SendPlatformChallengeDone(int32_t result); | |
| 637 void EnableProtectionDone(int32_t result); | |
| 638 void QueryOutputProtectionStatusDone(int32_t result); | |
| 639 | |
| 640 pp::OutputProtection_Private output_protection_; | |
| 641 pp::PlatformVerification platform_verification_; | |
| 642 | |
| 643 // |can_challenge_platform_| is currently set asynchronously, return the value | |
| 644 // if we have it, otherwise guess "true" for the most common case... | |
| 645 // TODO(jrummell): This stinks. The value should be delivered via the | |
| 646 // Initialize() method once plumbed. | |
| 647 bool can_challenge_platform_; | |
| 648 | |
| 649 // Since PPAPI doesn't provide handlers for CompletionCallbacks w/ more than | |
| 650 // one output we need to manage our own. These values are only read by | |
| 651 // SendPlatformChallengeDone(). | |
| 652 pp::Var signed_data_output_; | |
| 653 pp::Var signed_data_signature_output_; | |
| 654 pp::Var platform_key_certificate_output_; | |
| 655 bool challenge_in_progress_; | |
| 656 | |
| 657 // Same as above, these are only read by QueryOutputProtectionStatusDone(). | |
| 658 uint32_t link_mask_; | |
| 659 uint32_t output_protection_mask_; | |
| 660 bool query_in_progress_; | |
| 661 #endif | |
| 662 | |
| 609 PpbBufferAllocator allocator_; | 663 PpbBufferAllocator allocator_; |
| 610 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_; | 664 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_; |
| 611 cdm::ContentDecryptionModule* cdm_; | 665 cdm::ContentDecryptionModule* cdm_; |
| 612 std::string key_system_; | 666 std::string key_system_; |
| 613 | 667 |
| 614 DISALLOW_COPY_AND_ASSIGN(CdmWrapper); | 668 DISALLOW_COPY_AND_ASSIGN(CdmWrapper); |
| 615 }; | 669 }; |
| 616 | 670 |
| 617 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) | 671 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) |
| 618 : pp::Instance(instance), | 672 : pp::Instance(instance), |
| 619 pp::ContentDecryptor_Private(this), | 673 pp::ContentDecryptor_Private(this), |
| 674 #if defined(OS_CHROMEOS) | |
| 675 output_protection_(this), | |
| 676 platform_verification_(this), | |
| 677 // Err on the side of the most common case... | |
| 678 can_challenge_platform_(true), | |
| 679 challenge_in_progress_(false), | |
| 680 link_mask_(0), | |
|
ddorwin
2013/10/05 21:39:36
output_... ?
DaleCurtis
2013/10/07 22:15:59
Done.
| |
| 681 output_protection_mask_(0), | |
| 682 query_in_progress_(false), | |
|
ddorwin
2013/10/05 21:39:36
nit: query is not very specific. query_output_prot
DaleCurtis
2013/10/07 22:15:59
Done.
| |
| 683 #endif | |
| 620 allocator_(this), | 684 allocator_(this), |
| 621 cdm_(NULL) { | 685 cdm_(NULL) { |
| 622 callback_factory_.Initialize(this); | 686 callback_factory_.Initialize(this); |
| 687 #if defined(OS_CHROMEOS) | |
| 688 // Preemptively retrieve the platform challenge status. It will not change. | |
| 689 platform_verification_.CanChallengePlatform( | |
| 690 callback_factory_.NewCallbackWithOutput( | |
| 691 &CdmWrapper::CanChallengePlatformDone)); | |
| 692 #endif | |
| 623 } | 693 } |
| 624 | 694 |
| 625 CdmWrapper::~CdmWrapper() { | 695 CdmWrapper::~CdmWrapper() { |
| 626 if (cdm_) | 696 if (cdm_) |
| 627 cdm_->Destroy(); | 697 cdm_->Destroy(); |
| 628 } | 698 } |
| 629 | 699 |
| 630 bool CdmWrapper::CreateCdmInstance(const std::string& key_system) { | 700 bool CdmWrapper::CreateCdmInstance(const std::string& key_system) { |
| 631 PP_DCHECK(!cdm_); | 701 PP_DCHECK(!cdm_); |
| 632 cdm_ = static_cast<cdm::ContentDecryptionModule*>( | 702 cdm_ = static_cast<cdm::ContentDecryptionModule*>( |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 929 int32_t session_id_length, | 999 int32_t session_id_length, |
| 930 cdm::MediaKeyError error_code, | 1000 cdm::MediaKeyError error_code, |
| 931 uint32_t system_code) { | 1001 uint32_t system_code) { |
| 932 SendKeyErrorInternal(key_system_, | 1002 SendKeyErrorInternal(key_system_, |
| 933 std::string(session_id, session_id_length), | 1003 std::string(session_id, session_id_length), |
| 934 error_code, | 1004 error_code, |
| 935 system_code); | 1005 system_code); |
| 936 } | 1006 } |
| 937 | 1007 |
| 938 void CdmWrapper::GetPrivateData(int32_t* instance, | 1008 void CdmWrapper::GetPrivateData(int32_t* instance, |
| 939 cdm::Host::GetPrivateInterface* get_interface) { | 1009 GetPrivateInterface* get_interface) { |
| 940 *instance = pp_instance(); | 1010 *instance = pp_instance(); |
| 941 *get_interface = pp::Module::Get()->get_browser_interface(); | 1011 *get_interface = pp::Module::Get()->get_browser_interface(); |
| 942 } | 1012 } |
| 943 | 1013 |
| 944 void CdmWrapper::SendUnknownKeyError(const std::string& key_system, | 1014 void CdmWrapper::SendUnknownKeyError(const std::string& key_system, |
| 945 const std::string& session_id) { | 1015 const std::string& session_id) { |
| 946 SendKeyErrorInternal(key_system, session_id, cdm::kUnknownError, 0); | 1016 SendKeyErrorInternal(key_system, session_id, cdm::kUnknownError, 0); |
| 947 } | 1017 } |
| 948 | 1018 |
| 949 void CdmWrapper::SendKeyAdded(const std::string& key_system, | 1019 void CdmWrapper::SendKeyAdded(const std::string& key_system, |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1148 static_cast<cdm::VideoFrame::VideoPlane>(i); | 1218 static_cast<cdm::VideoFrame::VideoPlane>(i); |
| 1149 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + | 1219 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + |
| 1150 plane_height * video_frame->Stride(plane)) { | 1220 plane_height * video_frame->Stride(plane)) { |
| 1151 return false; | 1221 return false; |
| 1152 } | 1222 } |
| 1153 } | 1223 } |
| 1154 | 1224 |
| 1155 return true; | 1225 return true; |
| 1156 } | 1226 } |
| 1157 | 1227 |
| 1228 bool CdmWrapper::CanChallengePlatform() { | |
| 1229 #if defined(OS_CHROMEOS) | |
| 1230 return can_challenge_platform_; | |
| 1231 #else | |
| 1232 return false; | |
| 1233 #endif | |
| 1234 } | |
| 1235 | |
| 1236 void CdmWrapper::SendPlatformChallenge( | |
| 1237 const char* service_id, int32_t service_id_length, | |
| 1238 const char* challenge, int32_t challenge_length) { | |
| 1239 #if defined(OS_CHROMEOS) | |
| 1240 PP_DCHECK(!challenge_in_progress_); | |
| 1241 | |
| 1242 // Ensure member variables set by the callback are in a clean state. | |
|
ddorwin
2013/10/05 21:39:36
Do we need to do the same for output protection?
DaleCurtis
2013/10/07 22:15:59
No, not since the outputs are simple types. We ne
| |
| 1243 signed_data_output_ = pp::Var(); | |
| 1244 signed_data_signature_output_ = pp::Var(); | |
| 1245 platform_key_certificate_output_ = pp::Var(); | |
| 1246 | |
| 1247 pp::VarArrayBuffer challenge_var(challenge_length); | |
| 1248 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); | |
| 1249 memcpy(var_data, challenge, challenge_length); | |
| 1250 | |
| 1251 std::string service_id_str(service_id, service_id_length); | |
| 1252 int32_t result = platform_verification_.ChallengePlatform( | |
| 1253 pp::Var(service_id_str), challenge_var, &signed_data_output_, | |
| 1254 &signed_data_signature_output_, &platform_key_certificate_output_, | |
| 1255 callback_factory_.NewCallback(&CdmWrapper::SendPlatformChallengeDone)); | |
| 1256 challenge_var.Unmap(); | |
| 1257 if (result == PP_OK_COMPLETIONPENDING) { | |
| 1258 challenge_in_progress_ = true; | |
| 1259 return; | |
| 1260 } | |
| 1261 | |
| 1262 // Fall through on error and issue an empty OnPlatformChallengeResponse(). | |
| 1263 PP_DCHECK(result != PP_OK); | |
| 1264 #endif | |
| 1265 | |
| 1266 cdm::PlatformChallengeResponse response = {}; | |
| 1267 cdm_->OnPlatformChallengeResponse(response); | |
| 1268 } | |
| 1269 | |
| 1270 void CdmWrapper::EnableOutputProtection(uint32_t desired_protection_mask) { | |
| 1271 #if defined(OS_CHROMEOS) | |
| 1272 output_protection_.EnableProtection( | |
| 1273 desired_protection_mask, callback_factory_.NewCallback( | |
| 1274 &CdmWrapper::EnableProtectionDone)); | |
| 1275 | |
| 1276 // Errors are ignored since clients must call QueryOutputProtectionStatus() to | |
| 1277 // inspect the protection status on a regular basis. | |
| 1278 // TODO(dalecurtis): It'd be nice to log a message or non-fatal error here... | |
|
ddorwin
2013/10/05 21:39:36
Won't we always get PENDING since we're OOP?
DaleCurtis
2013/10/07 22:15:59
Not if there's an error that prevents the call fro
| |
| 1279 #endif | |
| 1280 } | |
| 1281 | |
| 1282 void CdmWrapper::QueryOutputProtectionStatus() { | |
| 1283 #if defined(OS_CHROMEOS) | |
| 1284 PP_DCHECK(!query_in_progress_); | |
| 1285 | |
| 1286 link_mask_ = output_protection_mask_ = 0; | |
| 1287 int32_t result = output_protection_.QueryStatus( | |
| 1288 &link_mask_, &output_protection_mask_, callback_factory_.NewCallback( | |
| 1289 &CdmWrapper::QueryOutputProtectionStatusDone)); | |
| 1290 if (result == PP_OK_COMPLETIONPENDING) { | |
| 1291 query_in_progress_ = true; | |
| 1292 return; | |
| 1293 } | |
| 1294 | |
| 1295 // Fall through on error and issue an empty OnQueryOutputProtectionStatus(). | |
| 1296 PP_DCHECK(result != PP_OK); | |
| 1297 #endif | |
| 1298 | |
| 1299 cdm_->OnQueryOutputProtectionStatus(0, 0); | |
| 1300 } | |
| 1301 | |
| 1302 #if defined(OS_CHROMEOS) | |
| 1303 void CdmWrapper::CanChallengePlatformDone(int32_t result, | |
| 1304 bool can_challenge_platform) { | |
| 1305 can_challenge_platform_ = (result == PP_OK) ? can_challenge_platform : false; | |
| 1306 } | |
| 1307 | |
| 1308 void CdmWrapper::SendPlatformChallengeDone(int32_t result) { | |
| 1309 challenge_in_progress_ = false; | |
| 1310 | |
| 1311 if (result != PP_OK) { | |
| 1312 cdm::PlatformChallengeResponse response = {}; | |
| 1313 cdm_->OnPlatformChallengeResponse(response); | |
| 1314 return; | |
| 1315 } | |
| 1316 | |
| 1317 pp::VarArrayBuffer signed_data_var(signed_data_output_); | |
| 1318 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_); | |
| 1319 std::string platform_key_certificate_string = | |
| 1320 platform_key_certificate_output_.AsString(); | |
| 1321 | |
| 1322 cdm::PlatformChallengeResponse response = { | |
| 1323 static_cast<uint8_t*>(signed_data_var.Map()), | |
| 1324 signed_data_var.ByteLength(), | |
| 1325 | |
| 1326 static_cast<uint8_t*>(signed_data_signature_var.Map()), | |
| 1327 signed_data_signature_var.ByteLength(), | |
| 1328 | |
| 1329 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.c_str()), | |
| 1330 platform_key_certificate_string.length() | |
| 1331 }; | |
| 1332 cdm_->OnPlatformChallengeResponse(response); | |
| 1333 | |
| 1334 signed_data_var.Unmap(); | |
| 1335 signed_data_signature_var.Unmap(); | |
| 1336 } | |
| 1337 | |
| 1338 void CdmWrapper::EnableProtectionDone(int32_t result) { | |
| 1339 // Does nothing since clients must call QueryOutputProtectionStatus() to | |
| 1340 // inspect the protection status on a regular basis. | |
| 1341 // TODO(dalecurtis): It'd be nice to log a message or non-fatal error here... | |
| 1342 } | |
| 1343 | |
| 1344 void CdmWrapper::QueryOutputProtectionStatusDone(int32_t result) { | |
| 1345 query_in_progress_ = false; | |
|
ddorwin
2013/10/05 21:39:36
Should we add DCHECK(query_in_progress_); ?
DaleCurtis
2013/10/07 22:15:59
Done.
| |
| 1346 | |
| 1347 // Return a protection status of none on error. | |
| 1348 if (result != PP_OK) | |
| 1349 link_mask_ = output_protection_mask_ = 0; | |
| 1350 | |
| 1351 cdm_->OnQueryOutputProtectionStatus(link_mask_, output_protection_mask_); | |
| 1352 } | |
| 1353 #endif | |
| 1354 | |
| 1158 void* GetCdmHost(int host_interface_version, void* user_data) { | 1355 void* GetCdmHost(int host_interface_version, void* user_data) { |
| 1159 if (!host_interface_version || !user_data) | 1356 if (!host_interface_version || !user_data) |
| 1160 return NULL; | 1357 return NULL; |
| 1161 | 1358 |
| 1162 if (host_interface_version != cdm::kHostInterfaceVersion) | |
| 1163 return NULL; | |
| 1164 | |
| 1165 CdmWrapper* cdm_wrapper = static_cast<CdmWrapper*>(user_data); | 1359 CdmWrapper* cdm_wrapper = static_cast<CdmWrapper*>(user_data); |
| 1166 return static_cast<cdm::Host*>(cdm_wrapper); | 1360 switch (host_interface_version) { |
| 1361 case cdm::kHostInterfaceVersion_1: | |
| 1362 return static_cast<cdm::Host_1*>(cdm_wrapper); | |
| 1363 case cdm::kHostInterfaceVersion_2: | |
| 1364 return static_cast<cdm::Host_2*>(cdm_wrapper); | |
| 1365 default: | |
| 1366 PP_NOTREACHED(); | |
| 1367 return NULL; | |
| 1368 } | |
| 1167 } | 1369 } |
| 1168 | 1370 |
| 1169 // This object is the global object representing this plugin library as long | 1371 // This object is the global object representing this plugin library as long |
| 1170 // as it is loaded. | 1372 // as it is loaded. |
| 1171 class CdmWrapperModule : public pp::Module { | 1373 class CdmWrapperModule : public pp::Module { |
| 1172 public: | 1374 public: |
| 1173 CdmWrapperModule() : pp::Module() { | 1375 CdmWrapperModule() : pp::Module() { |
| 1174 // This function blocks the renderer thread (PluginInstance::Initialize()). | 1376 // This function blocks the renderer thread (PluginInstance::Initialize()). |
| 1175 // Move this call to other places if this may be a concern in the future. | 1377 // Move this call to other places if this may be a concern in the future. |
| 1176 INITIALIZE_CDM_MODULE(); | 1378 INITIALIZE_CDM_MODULE(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1187 } // namespace media | 1389 } // namespace media |
| 1188 | 1390 |
| 1189 namespace pp { | 1391 namespace pp { |
| 1190 | 1392 |
| 1191 // Factory function for your specialization of the Module object. | 1393 // Factory function for your specialization of the Module object. |
| 1192 Module* CreateModule() { | 1394 Module* CreateModule() { |
| 1193 return new media::CdmWrapperModule(); | 1395 return new media::CdmWrapperModule(); |
| 1194 } | 1396 } |
| 1195 | 1397 |
| 1196 } // namespace pp | 1398 } // namespace pp |
| OLD | NEW |