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 <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 |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 virtual void SendKeyMessage( | 515 virtual void SendKeyMessage( |
| 516 const char* session_id, int32_t session_id_length, | 516 const char* session_id, int32_t session_id_length, |
| 517 const char* message, int32_t message_length, | 517 const char* message, int32_t message_length, |
| 518 const char* default_url, int32_t default_url_length) OVERRIDE; | 518 const char* default_url, int32_t default_url_length) OVERRIDE; |
| 519 virtual void SendKeyError(const char* session_id, | 519 virtual void SendKeyError(const char* session_id, |
| 520 int32_t session_id_length, | 520 int32_t session_id_length, |
| 521 cdm::MediaKeyError error_code, | 521 cdm::MediaKeyError error_code, |
| 522 uint32_t system_code) OVERRIDE; | 522 uint32_t system_code) OVERRIDE; |
| 523 | 523 |
| 524 private: | 524 private: |
| 525 struct SessionInfo { | |
|
xhwang
2013/01/10 07:16:25
OOC, did you ask pepper team why we can't add supp
ddorwin
2013/01/10 07:39:55
No. I realize we could add another override, but y
| |
| 526 SessionInfo(const std::string& key_system_in, | |
| 527 const std::string& session_id_in) | |
| 528 : key_system(key_system_in), | |
| 529 session_id(session_id_in) {} | |
| 530 const std::string key_system; | |
| 531 const std::string session_id; | |
| 532 }; | |
| 533 | |
| 525 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; | 534 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; |
| 526 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; | 535 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; |
| 527 typedef linked_ptr<AudioFramesImpl> LinkedAudioFrames; | 536 typedef linked_ptr<AudioFramesImpl> LinkedAudioFrames; |
| 528 | 537 |
| 529 void SendUnknownKeyError(const std::string& session_id); | 538 void SendUnknownKeyError(const std::string& key_system, |
| 539 const std::string& session_id); | |
| 530 | 540 |
| 531 void SendKeyAdded(const std::string& session_id); | 541 void SendKeyAdded(const std::string& key_system, |
| 542 const std::string& session_id); | |
| 543 | |
| 544 void SendKeyErrorInternal(const std::string& key_system, | |
| 545 const std::string& session_id, | |
| 546 cdm::MediaKeyError error_code, | |
| 547 uint32_t system_code); | |
| 532 | 548 |
| 533 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to | 549 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to |
| 534 // <code>callback_factory_</code> to ensure that calls into | 550 // <code>callback_factory_</code> to ensure that calls into |
| 535 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. | 551 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. |
| 536 void KeyAdded(int32_t result, const std::string& session_id); | 552 void KeyAdded(int32_t result, const SessionInfo& session_info); |
| 537 void KeyMessage(int32_t result, | 553 void KeyMessage(int32_t result, |
| 538 const std::string& session_id, | 554 const SessionInfo& session_info, |
| 539 const std::string& message, | 555 const std::string& message, |
| 540 const std::string& default_url); | 556 const std::string& default_url); |
| 541 void KeyError(int32_t result, | 557 void KeyError(int32_t result, |
| 542 const std::string& session_id, | 558 const SessionInfo& session_info, |
| 543 cdm::MediaKeyError error_code, | 559 cdm::MediaKeyError error_code, |
| 544 uint32_t system_code); | 560 uint32_t system_code); |
| 545 void DeliverBlock(int32_t result, | 561 void DeliverBlock(int32_t result, |
| 546 const cdm::Status& status, | 562 const cdm::Status& status, |
| 547 const LinkedDecryptedBlock& decrypted_block, | 563 const LinkedDecryptedBlock& decrypted_block, |
| 548 const PP_DecryptTrackingInfo& tracking_info); | 564 const PP_DecryptTrackingInfo& tracking_info); |
| 549 void DecoderInitializeDone(int32_t result, | 565 void DecoderInitializeDone(int32_t result, |
| 550 PP_DecryptorStreamType decoder_type, | 566 PP_DecryptorStreamType decoder_type, |
| 551 uint32_t request_id, | 567 uint32_t request_id, |
| 552 bool success); | 568 bool success); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 } | 603 } |
| 588 | 604 |
| 589 CdmWrapper::~CdmWrapper() { | 605 CdmWrapper::~CdmWrapper() { |
| 590 if (cdm_) | 606 if (cdm_) |
| 591 DestroyCdmInstance(cdm_); | 607 DestroyCdmInstance(cdm_); |
| 592 } | 608 } |
| 593 | 609 |
| 594 void CdmWrapper::GenerateKeyRequest(const std::string& key_system, | 610 void CdmWrapper::GenerateKeyRequest(const std::string& key_system, |
| 595 const std::string& type, | 611 const std::string& type, |
| 596 pp::VarArrayBuffer init_data) { | 612 pp::VarArrayBuffer init_data) { |
| 613 PP_DCHECK(!key_system.empty()); | |
| 597 PP_DCHECK(key_system_.empty() || key_system_ == key_system); | 614 PP_DCHECK(key_system_.empty() || key_system_ == key_system); |
| 598 | 615 |
| 599 if (!cdm_) { | 616 if (!cdm_) { |
| 600 cdm_ = CreateCdmInstance(key_system.data(), key_system.size(), | 617 cdm_ = CreateCdmInstance(key_system.data(), key_system.size(), |
| 601 &allocator_, this); | 618 &allocator_, this); |
| 602 PP_DCHECK(cdm_); | 619 PP_DCHECK(cdm_); |
| 603 if (!cdm_) { | 620 if (!cdm_) { |
| 604 SendUnknownKeyError(""); | 621 SendUnknownKeyError(key_system, ""); |
| 605 return; | 622 return; |
| 606 } | 623 } |
| 607 } | 624 } |
| 608 | 625 |
| 626 // Must be set here in case the CDM synchronously calls a cdm::Host method. | |
| 627 // Clear below on error. | |
| 628 // TODO(ddorwin): Remove this when key_system is added to cdm::Host methods. | |
| 629 key_system_ = key_system; | |
| 609 cdm::Status status = cdm_->GenerateKeyRequest( | 630 cdm::Status status = cdm_->GenerateKeyRequest( |
| 610 type.data(), type.size(), | 631 type.data(), type.size(), |
| 611 static_cast<const uint8_t*>(init_data.Map()), | 632 static_cast<const uint8_t*>(init_data.Map()), |
| 612 init_data.ByteLength()); | 633 init_data.ByteLength()); |
| 613 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); | 634 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); |
| 614 if (status != cdm::kSuccess) | 635 if (status != cdm::kSuccess) { |
| 636 key_system_.clear(); // See comment above. | |
| 615 return; | 637 return; |
| 638 } | |
| 616 | 639 |
| 617 key_system_ = key_system; | 640 key_system_ = key_system; |
|
xhwang
2013/01/10 07:16:25
do we still need this line?
ddorwin
2013/01/10 07:39:55
No. My intent was to leave the code in working ord
xhwang
2013/01/10 18:21:30
sg since we already have a TODO to remove line 629
| |
| 618 } | 641 } |
| 619 | 642 |
| 620 void CdmWrapper::AddKey(const std::string& session_id, | 643 void CdmWrapper::AddKey(const std::string& session_id, |
| 621 pp::VarArrayBuffer key, | 644 pp::VarArrayBuffer key, |
| 622 pp::VarArrayBuffer init_data) { | 645 pp::VarArrayBuffer init_data) { |
| 623 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. | 646 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. |
| 624 if (!cdm_) { | 647 if (!cdm_) { |
| 625 SendUnknownKeyError(session_id); | 648 SendUnknownKeyError(key_system_, session_id); |
| 626 return; | 649 return; |
| 627 } | 650 } |
| 628 | 651 |
| 629 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); | 652 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); |
| 630 int key_size = key.ByteLength(); | 653 int key_size = key.ByteLength(); |
| 631 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); | 654 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); |
| 632 int init_data_size = init_data.ByteLength(); | 655 int init_data_size = init_data.ByteLength(); |
| 633 | 656 |
| 634 if (!key_ptr || key_size <= 0 || !init_data_ptr || init_data_size <= 0) { | 657 if (!key_ptr || key_size <= 0 || !init_data_ptr || init_data_size <= 0) { |
| 635 SendUnknownKeyError(session_id); | 658 SendUnknownKeyError(key_system_, session_id); |
| 636 return; | 659 return; |
| 637 } | 660 } |
| 638 | 661 |
| 639 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), | 662 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), |
| 640 key_ptr, key_size, | 663 key_ptr, key_size, |
| 641 init_data_ptr, init_data_size); | 664 init_data_ptr, init_data_size); |
| 642 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); | 665 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); |
| 643 if (status != cdm::kSuccess) { | 666 if (status != cdm::kSuccess) { |
| 644 SendUnknownKeyError(session_id); | 667 SendUnknownKeyError(key_system_, session_id); |
| 645 return; | 668 return; |
| 646 } | 669 } |
| 647 | 670 |
| 648 SendKeyAdded(session_id); | 671 SendKeyAdded(key_system_, session_id); |
| 649 } | 672 } |
| 650 | 673 |
| 651 void CdmWrapper::CancelKeyRequest(const std::string& session_id) { | 674 void CdmWrapper::CancelKeyRequest(const std::string& session_id) { |
| 652 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. | 675 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. |
| 653 if (!cdm_) { | 676 if (!cdm_) { |
| 654 SendUnknownKeyError(session_id); | 677 SendUnknownKeyError(key_system_, session_id); |
| 655 return; | 678 return; |
| 656 } | 679 } |
| 657 | 680 |
| 658 cdm::Status status = cdm_->CancelKeyRequest(session_id.data(), | 681 cdm::Status status = cdm_->CancelKeyRequest(session_id.data(), |
| 659 session_id.size()); | 682 session_id.size()); |
| 660 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); | 683 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); |
| 661 if (status != cdm::kSuccess) | 684 if (status != cdm::kSuccess) |
| 662 SendUnknownKeyError(session_id); | 685 SendUnknownKeyError(key_system_, session_id); |
| 663 } | 686 } |
| 664 | 687 |
| 665 // Note: In the following decryption/decoding related functions, errors are NOT | 688 // Note: In the following decryption/decoding related functions, errors are NOT |
| 666 // reported via KeyError, but are reported via corresponding PPB calls. | 689 // reported via KeyError, but are reported via corresponding PPB calls. |
| 667 | 690 |
| 668 void CdmWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer, | 691 void CdmWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer, |
| 669 const PP_EncryptedBlockInfo& encrypted_block_info) { | 692 const PP_EncryptedBlockInfo& encrypted_block_info) { |
| 670 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. | 693 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. |
| 671 PP_DCHECK(!encrypted_buffer.is_null()); | 694 PP_DCHECK(!encrypted_buffer.is_null()); |
| 672 | 695 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 } | 868 } |
| 846 | 869 |
| 847 double CdmWrapper::GetCurrentWallTimeInSeconds() { | 870 double CdmWrapper::GetCurrentWallTimeInSeconds() { |
| 848 return pp::Module::Get()->core()->GetTime(); | 871 return pp::Module::Get()->core()->GetTime(); |
| 849 } | 872 } |
| 850 | 873 |
| 851 void CdmWrapper::SendKeyMessage( | 874 void CdmWrapper::SendKeyMessage( |
| 852 const char* session_id, int32_t session_id_length, | 875 const char* session_id, int32_t session_id_length, |
| 853 const char* message, int32_t message_length, | 876 const char* message, int32_t message_length, |
| 854 const char* default_url, int32_t default_url_length) { | 877 const char* default_url, int32_t default_url_length) { |
| 878 PP_DCHECK(!key_system_.empty()); | |
| 855 PostOnMain(callback_factory_.NewCallback( | 879 PostOnMain(callback_factory_.NewCallback( |
| 856 &CdmWrapper::KeyMessage, | 880 &CdmWrapper::KeyMessage, |
| 857 std::string(session_id, session_id_length), | 881 SessionInfo(key_system_, |
| 882 std::string(session_id, session_id_length)), | |
| 858 std::string(message, message_length), | 883 std::string(message, message_length), |
| 859 std::string(default_url, default_url_length))); | 884 std::string(default_url, default_url_length))); |
| 860 } | 885 } |
| 861 | 886 |
| 862 void CdmWrapper::SendKeyError(const char* session_id, | 887 void CdmWrapper::SendKeyError(const char* session_id, |
| 863 int32_t session_id_length, | 888 int32_t session_id_length, |
| 864 cdm::MediaKeyError error_code, | 889 cdm::MediaKeyError error_code, |
| 865 uint32_t system_code) { | 890 uint32_t system_code) { |
| 866 PostOnMain(callback_factory_.NewCallback( | 891 SendKeyErrorInternal(key_system_, |
| 867 &CdmWrapper::KeyError, | 892 std::string(session_id, session_id_length), |
| 868 std::string(session_id, session_id_length), | 893 error_code, |
| 869 error_code, | 894 system_code); |
| 870 system_code)); | |
| 871 } | 895 } |
| 872 | 896 |
| 873 void CdmWrapper::SendUnknownKeyError(const std::string& session_id) { | 897 void CdmWrapper::SendUnknownKeyError(const std::string& key_system, |
| 874 SendKeyError(session_id.data(), session_id.size(), cdm::kUnknownError, 0); | 898 const std::string& session_id) { |
| 899 SendKeyErrorInternal(key_system, session_id, cdm::kUnknownError, 0); | |
| 875 } | 900 } |
| 876 | 901 |
| 877 void CdmWrapper::SendKeyAdded(const std::string& session_id) { | 902 |
| 878 PostOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyAdded,session_id)); | 903 void CdmWrapper::SendKeyAdded(const std::string& key_system, |
| 904 const std::string& session_id) { | |
| 905 PostOnMain(callback_factory_.NewCallback( | |
| 906 &CdmWrapper::KeyAdded, | |
| 907 SessionInfo(key_system_, session_id))); | |
| 879 } | 908 } |
| 880 | 909 |
| 881 void CdmWrapper::KeyAdded(int32_t result, const std::string& session_id) { | 910 void CdmWrapper::SendKeyErrorInternal(const std::string& key_system, |
| 911 const std::string& session_id, | |
| 912 cdm::MediaKeyError error_code, | |
| 913 uint32_t system_code) { | |
| 914 PP_DCHECK(!key_system.empty()); | |
| 915 PostOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyError, | |
| 916 SessionInfo(key_system_, session_id), | |
| 917 error_code, | |
| 918 system_code)); | |
| 919 | |
|
xhwang
2013/01/10 07:16:25
remove extra line?
ddorwin
2013/01/10 07:39:55
Will do.
ddorwin
2013/01/10 18:13:28
Done.
| |
| 920 } | |
| 921 | |
| 922 void CdmWrapper::KeyAdded(int32_t result, const SessionInfo& session_info) { | |
| 882 PP_DCHECK(result == PP_OK); | 923 PP_DCHECK(result == PP_OK); |
| 883 PP_DCHECK(!key_system_.empty()); | 924 PP_DCHECK(!session_info.key_system.empty()); |
| 884 pp::ContentDecryptor_Private::KeyAdded(key_system_, session_id); | 925 pp::ContentDecryptor_Private::KeyAdded(session_info.key_system, |
| 926 session_info.session_id); | |
| 885 } | 927 } |
| 886 | 928 |
| 887 void CdmWrapper::KeyMessage(int32_t result, | 929 void CdmWrapper::KeyMessage(int32_t result, |
| 888 const std::string& session_id, | 930 const SessionInfo& session_info, |
| 889 const std::string& message, | 931 const std::string& message, |
| 890 const std::string& default_url) { | 932 const std::string& default_url) { |
| 891 PP_DCHECK(result == PP_OK); | 933 PP_DCHECK(result == PP_OK); |
| 934 PP_DCHECK(!session_info.key_system.empty()); | |
| 892 | 935 |
| 893 pp::VarArrayBuffer message_array_buffer(message.size()); | 936 pp::VarArrayBuffer message_array_buffer(message.size()); |
| 894 if (message.size() > 0) { | 937 if (message.size() > 0) { |
| 895 memcpy(message_array_buffer.Map(), message.data(), message.size()); | 938 memcpy(message_array_buffer.Map(), message.data(), message.size()); |
| 896 } | 939 } |
| 897 | 940 |
| 898 PP_DCHECK(!key_system_.empty()); | |
| 899 pp::ContentDecryptor_Private::KeyMessage( | 941 pp::ContentDecryptor_Private::KeyMessage( |
| 900 key_system_, session_id, message_array_buffer, default_url); | 942 session_info.key_system, session_info.session_id, |
| 943 message_array_buffer, default_url); | |
| 901 } | 944 } |
| 902 | 945 |
| 903 void CdmWrapper::KeyError(int32_t result, | 946 void CdmWrapper::KeyError(int32_t result, |
| 904 const std::string& session_id, | 947 const SessionInfo& session_info, |
| 905 cdm::MediaKeyError error_code, | 948 cdm::MediaKeyError error_code, |
| 906 uint32_t system_code) { | 949 uint32_t system_code) { |
| 907 PP_DCHECK(result == PP_OK); | 950 PP_DCHECK(result == PP_OK); |
| 908 PP_DCHECK(!key_system_.empty()); | 951 PP_DCHECK(!session_info.key_system.empty()); |
| 909 pp::ContentDecryptor_Private::KeyError( | 952 pp::ContentDecryptor_Private::KeyError( |
| 910 key_system_, session_id, error_code, system_code); | 953 session_info.key_system, session_info.session_id, |
| 954 error_code, system_code); | |
| 911 } | 955 } |
| 912 | 956 |
| 913 void CdmWrapper::DeliverBlock(int32_t result, | 957 void CdmWrapper::DeliverBlock(int32_t result, |
| 914 const cdm::Status& status, | 958 const cdm::Status& status, |
| 915 const LinkedDecryptedBlock& decrypted_block, | 959 const LinkedDecryptedBlock& decrypted_block, |
| 916 const PP_DecryptTrackingInfo& tracking_info) { | 960 const PP_DecryptTrackingInfo& tracking_info) { |
| 917 PP_DCHECK(result == PP_OK); | 961 PP_DCHECK(result == PP_OK); |
| 918 PP_DecryptedBlockInfo decrypted_block_info; | 962 PP_DecryptedBlockInfo decrypted_block_info; |
| 919 decrypted_block_info.tracking_info = tracking_info; | 963 decrypted_block_info.tracking_info = tracking_info; |
| 920 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); | 964 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1087 } // namespace webkit_media | 1131 } // namespace webkit_media |
| 1088 | 1132 |
| 1089 namespace pp { | 1133 namespace pp { |
| 1090 | 1134 |
| 1091 // Factory function for your specialization of the Module object. | 1135 // Factory function for your specialization of the Module object. |
| 1092 Module* CreateModule() { | 1136 Module* CreateModule() { |
| 1093 return new webkit_media::CdmWrapperModule(); | 1137 return new webkit_media::CdmWrapperModule(); |
| 1094 } | 1138 } |
| 1095 | 1139 |
| 1096 } // namespace pp | 1140 } // namespace pp |
| OLD | NEW |