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 "media/base/key_systems.h" | 5 #include "media/base/key_systems.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 EmeMediaType media_type, | 195 EmeMediaType media_type, |
196 const std::string& codec, | 196 const std::string& codec, |
197 uint32 mask); | 197 uint32 mask); |
198 | 198 |
199 // Implementation of KeySystems interface. | 199 // Implementation of KeySystems interface. |
200 bool IsSupportedKeySystem(const std::string& key_system) const override; | 200 bool IsSupportedKeySystem(const std::string& key_system) const override; |
201 | 201 |
202 bool IsSupportedInitDataType(const std::string& key_system, | 202 bool IsSupportedInitDataType(const std::string& key_system, |
203 EmeInitDataType init_data_type) const override; | 203 EmeInitDataType init_data_type) const override; |
204 | 204 |
205 bool IsSupportedCodecCombination( | 205 EmeConfigRule GetContentTypeConfigRule( |
206 const std::string& key_system, | 206 const std::string& key_system, |
207 EmeMediaType media_type, | 207 EmeMediaType media_type, |
208 const std::string& container_mime_type, | 208 const std::string& container_mime_type, |
209 const std::vector<std::string>& codecs) const override; | 209 const std::vector<std::string>& codecs) const override; |
210 | 210 |
211 EmeConfigRule GetRobustnessConfigRule( | 211 EmeConfigRule GetRobustnessConfigRule( |
212 const std::string& key_system, | 212 const std::string& key_system, |
213 EmeMediaType media_type, | 213 EmeMediaType media_type, |
214 const std::string& requested_robustness) const override; | 214 const std::string& requested_robustness) const override; |
215 | 215 |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 } else { | 658 } else { |
659 video_codec_mask_ |= mask; | 659 video_codec_mask_ |= mask; |
660 } | 660 } |
661 } | 661 } |
662 | 662 |
663 bool KeySystemsImpl::IsSupportedKeySystem(const std::string& key_system) const { | 663 bool KeySystemsImpl::IsSupportedKeySystem(const std::string& key_system) const { |
664 DCHECK(thread_checker_.CalledOnValidThread()); | 664 DCHECK(thread_checker_.CalledOnValidThread()); |
665 return concrete_key_system_map_.count(key_system) != 0; | 665 return concrete_key_system_map_.count(key_system) != 0; |
666 } | 666 } |
667 | 667 |
668 bool KeySystemsImpl::IsSupportedCodecCombination( | 668 EmeConfigRule KeySystemsImpl::GetContentTypeConfigRule( |
669 const std::string& key_system, | 669 const std::string& key_system, |
670 EmeMediaType media_type, | 670 EmeMediaType media_type, |
671 const std::string& container_mime_type, | 671 const std::string& container_mime_type, |
672 const std::vector<std::string>& codecs) const { | 672 const std::vector<std::string>& codecs) const { |
673 DCHECK(thread_checker_.CalledOnValidThread()); | 673 DCHECK(thread_checker_.CalledOnValidThread()); |
674 | 674 |
675 // Make sure the container matches |media_type|. | 675 // Make sure the container matches |media_type|. |
676 SupportedCodecs media_type_codec_mask = EME_CODEC_NONE; | 676 SupportedCodecs media_type_codec_mask = EME_CODEC_NONE; |
677 switch (media_type) { | 677 switch (media_type) { |
678 case EmeMediaType::AUDIO: | 678 case EmeMediaType::AUDIO: |
679 if (!StartsWithASCII(container_mime_type, "audio/", true)) | 679 if (!StartsWithASCII(container_mime_type, "audio/", true)) |
680 return false; | 680 return EmeConfigRule::NOT_SUPPORTED; |
681 media_type_codec_mask = audio_codec_mask_; | 681 media_type_codec_mask = audio_codec_mask_; |
682 break; | 682 break; |
683 case EmeMediaType::VIDEO: | 683 case EmeMediaType::VIDEO: |
684 if (!StartsWithASCII(container_mime_type, "video/", true)) | 684 if (!StartsWithASCII(container_mime_type, "video/", true)) |
685 return false; | 685 return EmeConfigRule::NOT_SUPPORTED; |
686 media_type_codec_mask = video_codec_mask_; | 686 media_type_codec_mask = video_codec_mask_; |
687 break; | 687 break; |
688 } | 688 } |
689 | 689 |
690 // Look up the key system's supported codecs. | 690 // Look up the key system's supported codecs. |
691 KeySystemInfoMap::const_iterator key_system_iter = | 691 KeySystemInfoMap::const_iterator key_system_iter = |
692 concrete_key_system_map_.find(key_system); | 692 concrete_key_system_map_.find(key_system); |
693 if (key_system_iter == concrete_key_system_map_.end()) { | 693 if (key_system_iter == concrete_key_system_map_.end()) { |
694 NOTREACHED(); | 694 NOTREACHED(); |
695 return false; | 695 return EmeConfigRule::NOT_SUPPORTED; |
696 } | 696 } |
697 SupportedCodecs key_system_codec_mask = | 697 SupportedCodecs key_system_codec_mask = |
698 key_system_iter->second.supported_codecs; | 698 key_system_iter->second.supported_codecs; |
| 699 #if defined(OS_ANDROID) |
| 700 SupportedCodecs key_system_secure_codec_mask = |
| 701 key_system_iter->second.supported_secure_codecs; |
| 702 #endif // defined(OS_ANDROID) |
| 703 |
699 | 704 |
700 // Check that the container is supported by the key system. (This check is | 705 // Check that the container is supported by the key system. (This check is |
701 // necessary because |codecs| may be empty.) | 706 // necessary because |codecs| may be empty.) |
702 SupportedCodecs container_codec_mask = | 707 SupportedCodecs container_codec_mask = |
703 GetCodecMaskForContainer(container_mime_type) & media_type_codec_mask; | 708 GetCodecMaskForContainer(container_mime_type) & media_type_codec_mask; |
704 if ((key_system_codec_mask & container_codec_mask) == 0) | 709 if ((key_system_codec_mask & container_codec_mask) == 0) |
705 return false; | 710 return EmeConfigRule::NOT_SUPPORTED; |
706 | 711 |
707 // Check that the codecs are supported by the key system and container. | 712 // Check that the codecs are supported by the key system and container. |
| 713 EmeConfigRule support = EmeConfigRule::SUPPORTED; |
708 for (size_t i = 0; i < codecs.size(); i++) { | 714 for (size_t i = 0; i < codecs.size(); i++) { |
709 SupportedCodecs codec = GetCodecForString(codecs[i]); | 715 SupportedCodecs codec = GetCodecForString(codecs[i]); |
710 if ((codec & key_system_codec_mask & container_codec_mask) == 0) | 716 if ((codec & key_system_codec_mask & container_codec_mask) == 0) |
711 return false; | 717 return EmeConfigRule::NOT_SUPPORTED; |
| 718 #if defined(OS_ANDROID) |
| 719 // Check whether the codec supports a hardware-secure mode; if not, indicate |
| 720 // that hardware-secure codecs are not available for all listed codecs. |
| 721 // Because the check for regular codec support is early-exit, we don't have |
| 722 // to consider codecs that are only supported in hardware-secure mode. We |
| 723 // could do so, and make use of SECURE_CODECS_REQUIRED, if it turns out that |
| 724 // hardware-secure-only codecs actually exist and are useful. |
| 725 if ((codec & key_system_secure_codec_mask) == 0) |
| 726 support = EmeConfigRule::SECURE_CODECS_NOT_ALLOWED; |
| 727 #endif // defined(OS_ANDROID) |
| 728 |
712 } | 729 } |
713 | 730 |
714 return true; | 731 return support; |
715 } | 732 } |
716 | 733 |
717 EmeConfigRule KeySystemsImpl::GetRobustnessConfigRule( | 734 EmeConfigRule KeySystemsImpl::GetRobustnessConfigRule( |
718 const std::string& key_system, | 735 const std::string& key_system, |
719 EmeMediaType media_type, | 736 EmeMediaType media_type, |
720 const std::string& requested_robustness) const { | 737 const std::string& requested_robustness) const { |
721 DCHECK(thread_checker_.CalledOnValidThread()); | 738 DCHECK(thread_checker_.CalledOnValidThread()); |
722 | 739 |
723 EmeRobustness robustness = ConvertRobustness(requested_robustness); | 740 EmeRobustness robustness = ConvertRobustness(requested_robustness); |
724 if (robustness == EmeRobustness::INVALID) | 741 if (robustness == EmeRobustness::INVALID) |
(...skipping 22 matching lines...) Expand all Loading... |
747 // and SW_SECURE_DECODE in some order. If they are exactly those two then the | 764 // and SW_SECURE_DECODE in some order. If they are exactly those two then the |
748 // robustness requirement is not supported. | 765 // robustness requirement is not supported. |
749 if ((max_robustness == EmeRobustness::HW_SECURE_CRYPTO && | 766 if ((max_robustness == EmeRobustness::HW_SECURE_CRYPTO && |
750 robustness == EmeRobustness::SW_SECURE_DECODE) || | 767 robustness == EmeRobustness::SW_SECURE_DECODE) || |
751 (max_robustness == EmeRobustness::SW_SECURE_DECODE && | 768 (max_robustness == EmeRobustness::SW_SECURE_DECODE && |
752 robustness == EmeRobustness::HW_SECURE_CRYPTO) || | 769 robustness == EmeRobustness::HW_SECURE_CRYPTO) || |
753 robustness > max_robustness) { | 770 robustness > max_robustness) { |
754 return EmeConfigRule::NOT_SUPPORTED; | 771 return EmeConfigRule::NOT_SUPPORTED; |
755 } | 772 } |
756 | 773 |
| 774 if (key_system == kWidevineKeySystem) { |
757 #if defined(OS_CHROMEOS) | 775 #if defined(OS_CHROMEOS) |
758 if (key_system == kWidevineKeySystem) { | |
759 // Hardware security requires remote attestation. | 776 // Hardware security requires remote attestation. |
760 if (robustness >= EmeRobustness::HW_SECURE_CRYPTO) | 777 if (robustness >= EmeRobustness::HW_SECURE_CRYPTO) |
761 return EmeConfigRule::IDENTIFIER_REQUIRED; | 778 return EmeConfigRule::IDENTIFIER_REQUIRED; |
762 | 779 |
763 // For video, recommend remote attestation if HW_SECURE_ALL is available, | 780 // For video, recommend remote attestation if HW_SECURE_ALL is available, |
764 // because it enables hardware accelerated decoding. | 781 // because it enables hardware accelerated decoding. |
765 // TODO(sandersd): Only do this when hardware accelerated decoding is | 782 // TODO(sandersd): Only do this when hardware accelerated decoding is |
766 // available for the requested codecs. | 783 // available for the requested codecs. |
767 if (media_type == EmeMediaType::VIDEO && | 784 if (media_type == EmeMediaType::VIDEO && |
768 max_robustness == EmeRobustness::HW_SECURE_ALL) { | 785 max_robustness == EmeRobustness::HW_SECURE_ALL) { |
769 return EmeConfigRule::IDENTIFIER_RECOMMENDED; | 786 return EmeConfigRule::IDENTIFIER_RECOMMENDED; |
770 } | 787 } |
| 788 #elif defined(OS_ANDROID) |
| 789 if (robustness > EmeRobustness::SW_SECURE_CRYPTO) |
| 790 return EmeConfigRule::SECURE_CODECS_REQUIRED; |
| 791 #endif // defined(OS_CHROMEOS) |
771 } | 792 } |
772 #endif // defined(OS_CHROMEOS) | |
773 | 793 |
774 return EmeConfigRule::SUPPORTED; | 794 return EmeConfigRule::SUPPORTED; |
775 } | 795 } |
776 | 796 |
777 EmeSessionTypeSupport KeySystemsImpl::GetPersistentLicenseSessionSupport( | 797 EmeSessionTypeSupport KeySystemsImpl::GetPersistentLicenseSessionSupport( |
778 const std::string& key_system) const { | 798 const std::string& key_system) const { |
779 DCHECK(thread_checker_.CalledOnValidThread()); | 799 DCHECK(thread_checker_.CalledOnValidThread()); |
780 | 800 |
781 KeySystemInfoMap::const_iterator key_system_iter = | 801 KeySystemInfoMap::const_iterator key_system_iter = |
782 concrete_key_system_map_.find(key_system); | 802 concrete_key_system_map_.find(key_system); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 } | 932 } |
913 | 933 |
914 MEDIA_EXPORT void AddCodecMask( | 934 MEDIA_EXPORT void AddCodecMask( |
915 EmeMediaType media_type, | 935 EmeMediaType media_type, |
916 const std::string& codec, | 936 const std::string& codec, |
917 uint32 mask) { | 937 uint32 mask) { |
918 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); | 938 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); |
919 } | 939 } |
920 | 940 |
921 } // namespace media | 941 } // namespace media |
OLD | NEW |