Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(704)

Side by Side Diff: media/cdm/ppapi/cdm_wrapper.cc

Issue 24192004: Changes to the EME Pepper API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 virtual ~CdmWrapper(); 491 virtual ~CdmWrapper();
492 492
493 // pp::Instance implementation. 493 // pp::Instance implementation.
494 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { 494 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
495 return true; 495 return true;
496 } 496 }
497 497
498 // PPP_ContentDecryptor_Private implementation. 498 // PPP_ContentDecryptor_Private implementation.
499 // Note: Results of calls to these methods must be reported through the 499 // Note: Results of calls to these methods must be reported through the
500 // PPB_ContentDecryptor_Private interface. 500 // PPB_ContentDecryptor_Private interface.
501 virtual void GenerateKeyRequest(const std::string& key_system, 501 virtual void Initialize(const std::string& key_system,
502 const std::string& type, 502 bool can_challenge_platform) OVERRIDE;
503 virtual void GenerateKeyRequest(const std::string& type,
503 pp::VarArrayBuffer init_data) OVERRIDE; 504 pp::VarArrayBuffer init_data) OVERRIDE;
504 virtual void AddKey(const std::string& session_id, 505 virtual void AddKey(const std::string& session_id,
505 pp::VarArrayBuffer key, 506 pp::VarArrayBuffer key,
506 pp::VarArrayBuffer init_data) OVERRIDE; 507 pp::VarArrayBuffer init_data) OVERRIDE;
507 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; 508 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE;
508 virtual void Decrypt( 509 virtual void Decrypt(
509 pp::Buffer_Dev encrypted_buffer, 510 pp::Buffer_Dev encrypted_buffer,
510 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; 511 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
511 virtual void InitializeAudioDecoder( 512 virtual void InitializeAudioDecoder(
512 const PP_AudioDecoderConfig& decoder_config, 513 const PP_AudioDecoderConfig& decoder_config,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 bool CdmWrapper::CreateCdmInstance(const std::string& key_system) { 630 bool CdmWrapper::CreateCdmInstance(const std::string& key_system) {
630 PP_DCHECK(!cdm_); 631 PP_DCHECK(!cdm_);
631 cdm_ = static_cast<cdm::ContentDecryptionModule*>( 632 cdm_ = static_cast<cdm::ContentDecryptionModule*>(
632 ::CreateCdmInstance(cdm::kCdmInterfaceVersion, 633 ::CreateCdmInstance(cdm::kCdmInterfaceVersion,
633 key_system.data(), key_system.size(), 634 key_system.data(), key_system.size(),
634 GetCdmHost, this)); 635 GetCdmHost, this));
635 636
636 return (cdm_ != NULL); 637 return (cdm_ != NULL);
637 } 638 }
638 639
639 void CdmWrapper::GenerateKeyRequest(const std::string& key_system, 640 void CdmWrapper::Initialize(const std::string& key_system,
640 const std::string& type, 641 bool can_challenge_platform) {
642 PP_DCHECK(!key_system.empty());
643 PP_DCHECK(key_system_.empty() || (key_system_ == key_system && cdm_));
644
645 if (!cdm_) {
646 if (!CreateCdmInstance(key_system)) {
647 // TODO(jrummell): Is UnknownKeyError the correct response?
648 SendUnknownKeyError(key_system, std::string());
649 return;
650 }
651 }
652 PP_DCHECK(cdm_);
653 key_system_ = key_system;
654 }
655
656 void CdmWrapper::GenerateKeyRequest(const std::string& type,
641 pp::VarArrayBuffer init_data) { 657 pp::VarArrayBuffer init_data) {
642 PP_DCHECK(!key_system.empty()); 658 PP_DCHECK(cdm_); // Initialize() should have succeeded.
643 PP_DCHECK(key_system_.empty() || key_system_ == key_system);
644 659
645 #if defined(CHECK_DOCUMENT_URL) 660 #if defined(CHECK_DOCUMENT_URL)
646 PP_URLComponents_Dev url_components = {}; 661 PP_URLComponents_Dev url_components = {};
647 pp::Var href = pp::URLUtil_Dev::Get()->GetDocumentURL( 662 pp::Var href = pp::URLUtil_Dev::Get()->GetDocumentURL(
648 pp::InstanceHandle(pp_instance()), &url_components); 663 pp::InstanceHandle(pp_instance()), &url_components);
649 PP_DCHECK(href.is_string()); 664 PP_DCHECK(href.is_string());
650 PP_DCHECK(!href.AsString().empty()); 665 PP_DCHECK(!href.AsString().empty());
651 PP_DCHECK(url_components.host.begin); 666 PP_DCHECK(url_components.host.begin);
652 PP_DCHECK(0 < url_components.host.len); 667 PP_DCHECK(0 < url_components.host.len);
653 #endif // defined(CHECK_DOCUMENT_URL) 668 #endif // defined(CHECK_DOCUMENT_URL)
654 669
655 if (!cdm_) {
656 if (!CreateCdmInstance(key_system)) {
657 SendUnknownKeyError(key_system, std::string());
658 return;
659 }
660 }
661 PP_DCHECK(cdm_);
662
663 // Must be set here in case the CDM synchronously calls a cdm::Host method.
664 // Clear below on error.
665 // TODO(ddorwin): Set/clear key_system_ & cdm_ at same time; clear both on
666 // error below.
667 key_system_ = key_system;
668 cdm::Status status = cdm_->GenerateKeyRequest( 670 cdm::Status status = cdm_->GenerateKeyRequest(
669 type.data(), type.size(), 671 type.data(), type.size(),
670 static_cast<const uint8_t*>(init_data.Map()), 672 static_cast<const uint8_t*>(init_data.Map()),
671 init_data.ByteLength()); 673 init_data.ByteLength());
672 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); 674 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError);
673 if (status != cdm::kSuccess) { 675 if (status != cdm::kSuccess)
674 key_system_.clear(); // See comment above. 676 SendUnknownKeyError(key_system_, std::string());
675 return;
676 }
677
678 key_system_ = key_system;
679 } 677 }
680 678
681 void CdmWrapper::AddKey(const std::string& session_id, 679 void CdmWrapper::AddKey(const std::string& session_id,
682 pp::VarArrayBuffer key, 680 pp::VarArrayBuffer key,
683 pp::VarArrayBuffer init_data) { 681 pp::VarArrayBuffer init_data) {
684 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 682 PP_DCHECK(cdm_); // Initialize() should have succeeded.
685 if (!cdm_) { 683 if (!cdm_) {
686 SendUnknownKeyError(key_system_, session_id); 684 SendUnknownKeyError(key_system_, session_id);
687 return; 685 return;
688 } 686 }
689 687
690 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); 688 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map());
691 int key_size = key.ByteLength(); 689 int key_size = key.ByteLength();
692 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); 690 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map());
693 int init_data_size = init_data.ByteLength(); 691 int init_data_size = init_data.ByteLength();
694 PP_DCHECK(!init_data_ptr == !init_data_size); 692 PP_DCHECK(!init_data_ptr == !init_data_size);
695 693
696 if (!key_ptr || key_size <= 0) { 694 if (!key_ptr || key_size <= 0) {
697 SendUnknownKeyError(key_system_, session_id); 695 SendUnknownKeyError(key_system_, session_id);
698 return; 696 return;
699 } 697 }
700 698
701 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), 699 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(),
702 key_ptr, key_size, 700 key_ptr, key_size,
703 init_data_ptr, init_data_size); 701 init_data_ptr, init_data_size);
704 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); 702 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError);
705 if (status != cdm::kSuccess) { 703 if (status != cdm::kSuccess) {
706 SendUnknownKeyError(key_system_, session_id); 704 SendUnknownKeyError(key_system_, session_id);
707 return; 705 return;
708 } 706 }
709 707
710 SendKeyAdded(key_system_, session_id); 708 SendKeyAdded(key_system_, session_id);
711 } 709 }
712 710
713 void CdmWrapper::CancelKeyRequest(const std::string& session_id) { 711 void CdmWrapper::CancelKeyRequest(const std::string& session_id) {
714 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 712 PP_DCHECK(cdm_); // Initialize() should have succeeded.
715 if (!cdm_) { 713 if (!cdm_) {
716 SendUnknownKeyError(key_system_, session_id); 714 SendUnknownKeyError(key_system_, session_id);
717 return; 715 return;
718 } 716 }
719 717
720 cdm::Status status = cdm_->CancelKeyRequest(session_id.data(), 718 cdm::Status status = cdm_->CancelKeyRequest(session_id.data(),
721 session_id.size()); 719 session_id.size());
722 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); 720 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError);
723 if (status != cdm::kSuccess) 721 if (status != cdm::kSuccess)
724 SendUnknownKeyError(key_system_, session_id); 722 SendUnknownKeyError(key_system_, session_id);
725 } 723 }
726 724
727 // Note: In the following decryption/decoding related functions, errors are NOT 725 // Note: In the following decryption/decoding related functions, errors are NOT
728 // reported via KeyError, but are reported via corresponding PPB calls. 726 // reported via KeyError, but are reported via corresponding PPB calls.
729 727
730 void CdmWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer, 728 void CdmWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer,
731 const PP_EncryptedBlockInfo& encrypted_block_info) { 729 const PP_EncryptedBlockInfo& encrypted_block_info) {
732 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 730 PP_DCHECK(cdm_); // Initialize() should have succeeded.
733 PP_DCHECK(!encrypted_buffer.is_null()); 731 PP_DCHECK(!encrypted_buffer.is_null());
734 732
735 // Release a buffer that the caller indicated it is finished with. 733 // Release a buffer that the caller indicated it is finished with.
736 allocator_.Release(encrypted_block_info.tracking_info.buffer_id); 734 allocator_.Release(encrypted_block_info.tracking_info.buffer_id);
737 735
738 cdm::Status status = cdm::kDecryptError; 736 cdm::Status status = cdm::kDecryptError;
739 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl()); 737 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl());
740 738
741 if (cdm_) { 739 if (cdm_) {
742 cdm::InputBuffer input_buffer; 740 cdm::InputBuffer input_buffer;
743 std::vector<cdm::SubsampleEntry> subsamples; 741 std::vector<cdm::SubsampleEntry> subsamples;
744 ConfigureInputBuffer(encrypted_buffer, encrypted_block_info, &subsamples, 742 ConfigureInputBuffer(encrypted_buffer, encrypted_block_info, &subsamples,
745 &input_buffer); 743 &input_buffer);
746 status = cdm_->Decrypt(input_buffer, decrypted_block.get()); 744 status = cdm_->Decrypt(input_buffer, decrypted_block.get());
747 PP_DCHECK(status != cdm::kSuccess || 745 PP_DCHECK(status != cdm::kSuccess ||
748 (decrypted_block->DecryptedBuffer() && 746 (decrypted_block->DecryptedBuffer() &&
749 decrypted_block->DecryptedBuffer()->Size())); 747 decrypted_block->DecryptedBuffer()->Size()));
750 } 748 }
751 749
752 CallOnMain(callback_factory_.NewCallback( 750 CallOnMain(callback_factory_.NewCallback(
753 &CdmWrapper::DeliverBlock, 751 &CdmWrapper::DeliverBlock,
754 status, 752 status,
755 decrypted_block, 753 decrypted_block,
756 encrypted_block_info.tracking_info)); 754 encrypted_block_info.tracking_info));
757 } 755 }
758 756
759 void CdmWrapper::InitializeAudioDecoder( 757 void CdmWrapper::InitializeAudioDecoder(
760 const PP_AudioDecoderConfig& decoder_config, 758 const PP_AudioDecoderConfig& decoder_config,
761 pp::Buffer_Dev extra_data_buffer) { 759 pp::Buffer_Dev extra_data_buffer) {
762 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 760 PP_DCHECK(cdm_); // Initialize() should have succeeded.
763 761
764 cdm::Status status = cdm::kSessionError; 762 cdm::Status status = cdm::kSessionError;
765 if (cdm_) { 763 if (cdm_) {
766 cdm::AudioDecoderConfig cdm_decoder_config; 764 cdm::AudioDecoderConfig cdm_decoder_config;
767 cdm_decoder_config.codec = 765 cdm_decoder_config.codec =
768 PpAudioCodecToCdmAudioCodec(decoder_config.codec); 766 PpAudioCodecToCdmAudioCodec(decoder_config.codec);
769 cdm_decoder_config.channel_count = decoder_config.channel_count; 767 cdm_decoder_config.channel_count = decoder_config.channel_count;
770 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel; 768 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel;
771 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second; 769 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second;
772 cdm_decoder_config.extra_data = 770 cdm_decoder_config.extra_data =
773 static_cast<uint8_t*>(extra_data_buffer.data()); 771 static_cast<uint8_t*>(extra_data_buffer.data());
774 cdm_decoder_config.extra_data_size = 772 cdm_decoder_config.extra_data_size =
775 static_cast<int32_t>(extra_data_buffer.size()); 773 static_cast<int32_t>(extra_data_buffer.size());
776 status = cdm_->InitializeAudioDecoder(cdm_decoder_config); 774 status = cdm_->InitializeAudioDecoder(cdm_decoder_config);
777 } 775 }
778 776
779 CallOnMain(callback_factory_.NewCallback( 777 CallOnMain(callback_factory_.NewCallback(
780 &CdmWrapper::DecoderInitializeDone, 778 &CdmWrapper::DecoderInitializeDone,
781 PP_DECRYPTORSTREAMTYPE_AUDIO, 779 PP_DECRYPTORSTREAMTYPE_AUDIO,
782 decoder_config.request_id, 780 decoder_config.request_id,
783 status == cdm::kSuccess)); 781 status == cdm::kSuccess));
784 } 782 }
785 783
786 void CdmWrapper::InitializeVideoDecoder( 784 void CdmWrapper::InitializeVideoDecoder(
787 const PP_VideoDecoderConfig& decoder_config, 785 const PP_VideoDecoderConfig& decoder_config,
788 pp::Buffer_Dev extra_data_buffer) { 786 pp::Buffer_Dev extra_data_buffer) {
789 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 787 PP_DCHECK(cdm_); // Initialize() should have succeeded.
790 788
791 cdm::Status status = cdm::kSessionError; 789 cdm::Status status = cdm::kSessionError;
792 if (cdm_) { 790 if (cdm_) {
793 cdm::VideoDecoderConfig cdm_decoder_config; 791 cdm::VideoDecoderConfig cdm_decoder_config;
794 cdm_decoder_config.codec = 792 cdm_decoder_config.codec =
795 PpVideoCodecToCdmVideoCodec(decoder_config.codec); 793 PpVideoCodecToCdmVideoCodec(decoder_config.codec);
796 cdm_decoder_config.profile = 794 cdm_decoder_config.profile =
797 PpVCProfileToCdmVCProfile(decoder_config.profile); 795 PpVCProfileToCdmVCProfile(decoder_config.profile);
798 cdm_decoder_config.format = 796 cdm_decoder_config.format =
799 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format); 797 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format);
800 cdm_decoder_config.coded_size.width = decoder_config.width; 798 cdm_decoder_config.coded_size.width = decoder_config.width;
801 cdm_decoder_config.coded_size.height = decoder_config.height; 799 cdm_decoder_config.coded_size.height = decoder_config.height;
802 cdm_decoder_config.extra_data = 800 cdm_decoder_config.extra_data =
803 static_cast<uint8_t*>(extra_data_buffer.data()); 801 static_cast<uint8_t*>(extra_data_buffer.data());
804 cdm_decoder_config.extra_data_size = 802 cdm_decoder_config.extra_data_size =
805 static_cast<int32_t>(extra_data_buffer.size()); 803 static_cast<int32_t>(extra_data_buffer.size());
806 status = cdm_->InitializeVideoDecoder(cdm_decoder_config); 804 status = cdm_->InitializeVideoDecoder(cdm_decoder_config);
807 } 805 }
808 806
809 CallOnMain(callback_factory_.NewCallback( 807 CallOnMain(callback_factory_.NewCallback(
810 &CdmWrapper::DecoderInitializeDone, 808 &CdmWrapper::DecoderInitializeDone,
811 PP_DECRYPTORSTREAMTYPE_VIDEO, 809 PP_DECRYPTORSTREAMTYPE_VIDEO,
812 decoder_config.request_id, 810 decoder_config.request_id,
813 status == cdm::kSuccess)); 811 status == cdm::kSuccess));
814 } 812 }
815 813
816 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type, 814 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type,
817 uint32_t request_id) { 815 uint32_t request_id) {
818 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 816 PP_DCHECK(cdm_); // Initialize() should have succeeded.
819 if (cdm_) { 817 if (cdm_) {
820 cdm_->DeinitializeDecoder( 818 cdm_->DeinitializeDecoder(
821 PpDecryptorStreamTypeToCdmStreamType(decoder_type)); 819 PpDecryptorStreamTypeToCdmStreamType(decoder_type));
822 } 820 }
823 821
824 CallOnMain(callback_factory_.NewCallback( 822 CallOnMain(callback_factory_.NewCallback(
825 &CdmWrapper::DecoderDeinitializeDone, 823 &CdmWrapper::DecoderDeinitializeDone,
826 decoder_type, 824 decoder_type,
827 request_id)); 825 request_id));
828 } 826 }
829 827
830 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type, 828 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type,
831 uint32_t request_id) { 829 uint32_t request_id) {
832 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 830 PP_DCHECK(cdm_); // Initialize() should have succeeded.
833 if (cdm_) 831 if (cdm_)
834 cdm_->ResetDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type)); 832 cdm_->ResetDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type));
835 833
836 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone, 834 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone,
837 decoder_type, 835 decoder_type,
838 request_id)); 836 request_id));
839 } 837 }
840 838
841 void CdmWrapper::DecryptAndDecode( 839 void CdmWrapper::DecryptAndDecode(
842 PP_DecryptorStreamType decoder_type, 840 PP_DecryptorStreamType decoder_type,
843 pp::Buffer_Dev encrypted_buffer, 841 pp::Buffer_Dev encrypted_buffer,
844 const PP_EncryptedBlockInfo& encrypted_block_info) { 842 const PP_EncryptedBlockInfo& encrypted_block_info) {
845 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 843 PP_DCHECK(cdm_); // Initialize() should have succeeded.
846 844
847 // Release a buffer that the caller indicated it is finished with. 845 // Release a buffer that the caller indicated it is finished with.
848 allocator_.Release(encrypted_block_info.tracking_info.buffer_id); 846 allocator_.Release(encrypted_block_info.tracking_info.buffer_id);
849 847
850 cdm::InputBuffer input_buffer; 848 cdm::InputBuffer input_buffer;
851 std::vector<cdm::SubsampleEntry> subsamples; 849 std::vector<cdm::SubsampleEntry> subsamples;
852 if (cdm_ && !encrypted_buffer.is_null()) { 850 if (cdm_ && !encrypted_buffer.is_null()) {
853 ConfigureInputBuffer(encrypted_buffer, 851 ConfigureInputBuffer(encrypted_buffer,
854 encrypted_block_info, 852 encrypted_block_info,
855 &subsamples, 853 &subsamples,
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 } // namespace media 1187 } // namespace media
1190 1188
1191 namespace pp { 1189 namespace pp {
1192 1190
1193 // Factory function for your specialization of the Module object. 1191 // Factory function for your specialization of the Module object.
1194 Module* CreateModule() { 1192 Module* CreateModule() {
1195 return new media::CdmWrapperModule(); 1193 return new media::CdmWrapperModule();
1196 } 1194 }
1197 1195
1198 } // namespace pp 1196 } // namespace pp
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.cc ('k') | ppapi/api/private/ppb_content_decryptor_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698