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

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 const PP_KeySystemFlags& key_system_flags) 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 const PP_KeySystemFlags& key_system_flags) {
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) {
DaleCurtis 2013/09/18 21:29:30 dmichael@ pointed out on my cl that every pp::VarA
jrummell 2013/09/19 00:37:28 It fails to compile as Map() is not const.
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) {
674 key_system_.clear(); // See comment above.
675 return;
676 }
677
678 key_system_ = key_system;
679 } 675 }
680 676
681 void CdmWrapper::AddKey(const std::string& session_id, 677 void CdmWrapper::AddKey(const std::string& session_id,
682 pp::VarArrayBuffer key, 678 pp::VarArrayBuffer key,
683 pp::VarArrayBuffer init_data) { 679 pp::VarArrayBuffer init_data) {
684 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 680 PP_DCHECK(cdm_); // Initialize() should have succeeded.
685 if (!cdm_) { 681 if (!cdm_) {
686 SendUnknownKeyError(key_system_, session_id); 682 SendUnknownKeyError(key_system_, session_id);
687 return; 683 return;
688 } 684 }
689 685
690 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); 686 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map());
691 int key_size = key.ByteLength(); 687 int key_size = key.ByteLength();
692 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); 688 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map());
693 int init_data_size = init_data.ByteLength(); 689 int init_data_size = init_data.ByteLength();
694 PP_DCHECK(!init_data_ptr == !init_data_size); 690 PP_DCHECK(!init_data_ptr == !init_data_size);
695 691
696 if (!key_ptr || key_size <= 0) { 692 if (!key_ptr || key_size <= 0) {
697 SendUnknownKeyError(key_system_, session_id); 693 SendUnknownKeyError(key_system_, session_id);
698 return; 694 return;
699 } 695 }
700 696
701 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), 697 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(),
702 key_ptr, key_size, 698 key_ptr, key_size,
703 init_data_ptr, init_data_size); 699 init_data_ptr, init_data_size);
704 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); 700 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError);
705 if (status != cdm::kSuccess) { 701 if (status != cdm::kSuccess) {
706 SendUnknownKeyError(key_system_, session_id); 702 SendUnknownKeyError(key_system_, session_id);
707 return; 703 return;
708 } 704 }
709 705
710 SendKeyAdded(key_system_, session_id); 706 SendKeyAdded(key_system_, session_id);
711 } 707 }
712 708
713 void CdmWrapper::CancelKeyRequest(const std::string& session_id) { 709 void CdmWrapper::CancelKeyRequest(const std::string& session_id) {
714 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 710 PP_DCHECK(cdm_); // Initialize() should have succeeded.
715 if (!cdm_) { 711 if (!cdm_) {
716 SendUnknownKeyError(key_system_, session_id); 712 SendUnknownKeyError(key_system_, session_id);
717 return; 713 return;
718 } 714 }
719 715
720 cdm::Status status = cdm_->CancelKeyRequest(session_id.data(), 716 cdm::Status status = cdm_->CancelKeyRequest(session_id.data(),
721 session_id.size()); 717 session_id.size());
722 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); 718 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError);
723 if (status != cdm::kSuccess) 719 if (status != cdm::kSuccess)
724 SendUnknownKeyError(key_system_, session_id); 720 SendUnknownKeyError(key_system_, session_id);
725 } 721 }
726 722
727 // Note: In the following decryption/decoding related functions, errors are NOT 723 // Note: In the following decryption/decoding related functions, errors are NOT
728 // reported via KeyError, but are reported via corresponding PPB calls. 724 // reported via KeyError, but are reported via corresponding PPB calls.
729 725
730 void CdmWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer, 726 void CdmWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer,
731 const PP_EncryptedBlockInfo& encrypted_block_info) { 727 const PP_EncryptedBlockInfo& encrypted_block_info) {
732 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 728 PP_DCHECK(cdm_); // Initialize() should have succeeded.
733 PP_DCHECK(!encrypted_buffer.is_null()); 729 PP_DCHECK(!encrypted_buffer.is_null());
734 730
735 // Release a buffer that the caller indicated it is finished with. 731 // Release a buffer that the caller indicated it is finished with.
736 allocator_.Release(encrypted_block_info.tracking_info.buffer_id); 732 allocator_.Release(encrypted_block_info.tracking_info.buffer_id);
737 733
738 cdm::Status status = cdm::kDecryptError; 734 cdm::Status status = cdm::kDecryptError;
739 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl()); 735 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl());
740 736
741 if (cdm_) { 737 if (cdm_) {
742 cdm::InputBuffer input_buffer; 738 cdm::InputBuffer input_buffer;
743 std::vector<cdm::SubsampleEntry> subsamples; 739 std::vector<cdm::SubsampleEntry> subsamples;
744 ConfigureInputBuffer(encrypted_buffer, encrypted_block_info, &subsamples, 740 ConfigureInputBuffer(encrypted_buffer, encrypted_block_info, &subsamples,
745 &input_buffer); 741 &input_buffer);
746 status = cdm_->Decrypt(input_buffer, decrypted_block.get()); 742 status = cdm_->Decrypt(input_buffer, decrypted_block.get());
747 PP_DCHECK(status != cdm::kSuccess || 743 PP_DCHECK(status != cdm::kSuccess ||
748 (decrypted_block->DecryptedBuffer() && 744 (decrypted_block->DecryptedBuffer() &&
749 decrypted_block->DecryptedBuffer()->Size())); 745 decrypted_block->DecryptedBuffer()->Size()));
750 } 746 }
751 747
752 CallOnMain(callback_factory_.NewCallback( 748 CallOnMain(callback_factory_.NewCallback(
753 &CdmWrapper::DeliverBlock, 749 &CdmWrapper::DeliverBlock,
754 status, 750 status,
755 decrypted_block, 751 decrypted_block,
756 encrypted_block_info.tracking_info)); 752 encrypted_block_info.tracking_info));
757 } 753 }
758 754
759 void CdmWrapper::InitializeAudioDecoder( 755 void CdmWrapper::InitializeAudioDecoder(
760 const PP_AudioDecoderConfig& decoder_config, 756 const PP_AudioDecoderConfig& decoder_config,
761 pp::Buffer_Dev extra_data_buffer) { 757 pp::Buffer_Dev extra_data_buffer) {
762 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 758 PP_DCHECK(cdm_); // Initialize() should have succeeded.
763 759
764 cdm::Status status = cdm::kSessionError; 760 cdm::Status status = cdm::kSessionError;
765 if (cdm_) { 761 if (cdm_) {
766 cdm::AudioDecoderConfig cdm_decoder_config; 762 cdm::AudioDecoderConfig cdm_decoder_config;
767 cdm_decoder_config.codec = 763 cdm_decoder_config.codec =
768 PpAudioCodecToCdmAudioCodec(decoder_config.codec); 764 PpAudioCodecToCdmAudioCodec(decoder_config.codec);
769 cdm_decoder_config.channel_count = decoder_config.channel_count; 765 cdm_decoder_config.channel_count = decoder_config.channel_count;
770 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel; 766 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel;
771 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second; 767 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second;
772 cdm_decoder_config.extra_data = 768 cdm_decoder_config.extra_data =
773 static_cast<uint8_t*>(extra_data_buffer.data()); 769 static_cast<uint8_t*>(extra_data_buffer.data());
774 cdm_decoder_config.extra_data_size = 770 cdm_decoder_config.extra_data_size =
775 static_cast<int32_t>(extra_data_buffer.size()); 771 static_cast<int32_t>(extra_data_buffer.size());
776 status = cdm_->InitializeAudioDecoder(cdm_decoder_config); 772 status = cdm_->InitializeAudioDecoder(cdm_decoder_config);
777 } 773 }
778 774
779 CallOnMain(callback_factory_.NewCallback( 775 CallOnMain(callback_factory_.NewCallback(
780 &CdmWrapper::DecoderInitializeDone, 776 &CdmWrapper::DecoderInitializeDone,
781 PP_DECRYPTORSTREAMTYPE_AUDIO, 777 PP_DECRYPTORSTREAMTYPE_AUDIO,
782 decoder_config.request_id, 778 decoder_config.request_id,
783 status == cdm::kSuccess)); 779 status == cdm::kSuccess));
784 } 780 }
785 781
786 void CdmWrapper::InitializeVideoDecoder( 782 void CdmWrapper::InitializeVideoDecoder(
787 const PP_VideoDecoderConfig& decoder_config, 783 const PP_VideoDecoderConfig& decoder_config,
788 pp::Buffer_Dev extra_data_buffer) { 784 pp::Buffer_Dev extra_data_buffer) {
789 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 785 PP_DCHECK(cdm_); // Initialize() should have succeeded.
790 786
791 cdm::Status status = cdm::kSessionError; 787 cdm::Status status = cdm::kSessionError;
792 if (cdm_) { 788 if (cdm_) {
793 cdm::VideoDecoderConfig cdm_decoder_config; 789 cdm::VideoDecoderConfig cdm_decoder_config;
794 cdm_decoder_config.codec = 790 cdm_decoder_config.codec =
795 PpVideoCodecToCdmVideoCodec(decoder_config.codec); 791 PpVideoCodecToCdmVideoCodec(decoder_config.codec);
796 cdm_decoder_config.profile = 792 cdm_decoder_config.profile =
797 PpVCProfileToCdmVCProfile(decoder_config.profile); 793 PpVCProfileToCdmVCProfile(decoder_config.profile);
798 cdm_decoder_config.format = 794 cdm_decoder_config.format =
799 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format); 795 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format);
800 cdm_decoder_config.coded_size.width = decoder_config.width; 796 cdm_decoder_config.coded_size.width = decoder_config.width;
801 cdm_decoder_config.coded_size.height = decoder_config.height; 797 cdm_decoder_config.coded_size.height = decoder_config.height;
802 cdm_decoder_config.extra_data = 798 cdm_decoder_config.extra_data =
803 static_cast<uint8_t*>(extra_data_buffer.data()); 799 static_cast<uint8_t*>(extra_data_buffer.data());
804 cdm_decoder_config.extra_data_size = 800 cdm_decoder_config.extra_data_size =
805 static_cast<int32_t>(extra_data_buffer.size()); 801 static_cast<int32_t>(extra_data_buffer.size());
806 status = cdm_->InitializeVideoDecoder(cdm_decoder_config); 802 status = cdm_->InitializeVideoDecoder(cdm_decoder_config);
807 } 803 }
808 804
809 CallOnMain(callback_factory_.NewCallback( 805 CallOnMain(callback_factory_.NewCallback(
810 &CdmWrapper::DecoderInitializeDone, 806 &CdmWrapper::DecoderInitializeDone,
811 PP_DECRYPTORSTREAMTYPE_VIDEO, 807 PP_DECRYPTORSTREAMTYPE_VIDEO,
812 decoder_config.request_id, 808 decoder_config.request_id,
813 status == cdm::kSuccess)); 809 status == cdm::kSuccess));
814 } 810 }
815 811
816 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type, 812 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type,
817 uint32_t request_id) { 813 uint32_t request_id) {
818 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 814 PP_DCHECK(cdm_); // Initialize() should have succeeded.
819 if (cdm_) { 815 if (cdm_) {
820 cdm_->DeinitializeDecoder( 816 cdm_->DeinitializeDecoder(
821 PpDecryptorStreamTypeToCdmStreamType(decoder_type)); 817 PpDecryptorStreamTypeToCdmStreamType(decoder_type));
822 } 818 }
823 819
824 CallOnMain(callback_factory_.NewCallback( 820 CallOnMain(callback_factory_.NewCallback(
825 &CdmWrapper::DecoderDeinitializeDone, 821 &CdmWrapper::DecoderDeinitializeDone,
826 decoder_type, 822 decoder_type,
827 request_id)); 823 request_id));
828 } 824 }
829 825
830 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type, 826 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type,
831 uint32_t request_id) { 827 uint32_t request_id) {
832 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 828 PP_DCHECK(cdm_); // Initialize() should have succeeded.
833 if (cdm_) 829 if (cdm_)
834 cdm_->ResetDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type)); 830 cdm_->ResetDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type));
835 831
836 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone, 832 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone,
837 decoder_type, 833 decoder_type,
838 request_id)); 834 request_id));
839 } 835 }
840 836
841 void CdmWrapper::DecryptAndDecode( 837 void CdmWrapper::DecryptAndDecode(
842 PP_DecryptorStreamType decoder_type, 838 PP_DecryptorStreamType decoder_type,
843 pp::Buffer_Dev encrypted_buffer, 839 pp::Buffer_Dev encrypted_buffer,
844 const PP_EncryptedBlockInfo& encrypted_block_info) { 840 const PP_EncryptedBlockInfo& encrypted_block_info) {
845 PP_DCHECK(cdm_); // GenerateKeyRequest() should have succeeded. 841 PP_DCHECK(cdm_); // Initialize() should have succeeded.
846 842
847 // Release a buffer that the caller indicated it is finished with. 843 // Release a buffer that the caller indicated it is finished with.
848 allocator_.Release(encrypted_block_info.tracking_info.buffer_id); 844 allocator_.Release(encrypted_block_info.tracking_info.buffer_id);
849 845
850 cdm::InputBuffer input_buffer; 846 cdm::InputBuffer input_buffer;
851 std::vector<cdm::SubsampleEntry> subsamples; 847 std::vector<cdm::SubsampleEntry> subsamples;
852 if (cdm_ && !encrypted_buffer.is_null()) { 848 if (cdm_ && !encrypted_buffer.is_null()) {
853 ConfigureInputBuffer(encrypted_buffer, 849 ConfigureInputBuffer(encrypted_buffer,
854 encrypted_block_info, 850 encrypted_block_info,
855 &subsamples, 851 &subsamples,
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 } // namespace media 1185 } // namespace media
1190 1186
1191 namespace pp { 1187 namespace pp {
1192 1188
1193 // Factory function for your specialization of the Module object. 1189 // Factory function for your specialization of the Module object.
1194 Module* CreateModule() { 1190 Module* CreateModule() {
1195 return new media::CdmWrapperModule(); 1191 return new media::CdmWrapperModule();
1196 } 1192 }
1197 1193
1198 } // namespace pp 1194 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698