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. This nesting | |
ddorwin
2015/05/01 20:39:11
Is it really nesting or the fact that we check eac
sandersd (OOO until July 31)
2015/05/01 21:57:01
Really it's that failing the regular codec test is
| |
720 // ensures that only codecs that also support the regular mode are allowed; | |
ddorwin
2015/05/01 20:39:12
This is a bit confusing to me. Do we mean "ensures
sandersd (OOO until July 31)
2015/05/01 21:57:01
Acknowledged.
| |
721 // it would be possible to separate the checks and return | |
722 // SECURE_CODECS_REQUIRED when the regular mode is not available, if it | |
ddorwin
2015/05/01 20:39:12
Wouldn't we need to then check that all codecs sup
sandersd (OOO until July 31)
2015/05/01 21:57:01
Done.
| |
723 // turns out that that is a useful feature. | |
ddorwin
2015/05/01 20:39:12
Define the second "that".
Allowing only hardware-s
sandersd (OOO until July 31)
2015/05/01 21:57:01
Done.
| |
724 if ((codec & key_system_secure_codec_mask) == 0) | |
725 support = EmeConfigRule::SECURE_CODECS_NOT_ALLOWED; | |
726 #endif // defined(OS_ANDROID) | |
727 | |
712 } | 728 } |
713 | 729 |
714 return true; | 730 return support; |
715 } | 731 } |
716 | 732 |
717 EmeConfigRule KeySystemsImpl::GetRobustnessConfigRule( | 733 EmeConfigRule KeySystemsImpl::GetRobustnessConfigRule( |
718 const std::string& key_system, | 734 const std::string& key_system, |
719 EmeMediaType media_type, | 735 EmeMediaType media_type, |
720 const std::string& requested_robustness) const { | 736 const std::string& requested_robustness) const { |
721 DCHECK(thread_checker_.CalledOnValidThread()); | 737 DCHECK(thread_checker_.CalledOnValidThread()); |
722 | 738 |
723 EmeRobustness robustness = ConvertRobustness(requested_robustness); | 739 EmeRobustness robustness = ConvertRobustness(requested_robustness); |
724 if (robustness == EmeRobustness::INVALID) | 740 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 | 763 // and SW_SECURE_DECODE in some order. If they are exactly those two then the |
748 // robustness requirement is not supported. | 764 // robustness requirement is not supported. |
749 if ((max_robustness == EmeRobustness::HW_SECURE_CRYPTO && | 765 if ((max_robustness == EmeRobustness::HW_SECURE_CRYPTO && |
750 robustness == EmeRobustness::SW_SECURE_DECODE) || | 766 robustness == EmeRobustness::SW_SECURE_DECODE) || |
751 (max_robustness == EmeRobustness::SW_SECURE_DECODE && | 767 (max_robustness == EmeRobustness::SW_SECURE_DECODE && |
752 robustness == EmeRobustness::HW_SECURE_CRYPTO) || | 768 robustness == EmeRobustness::HW_SECURE_CRYPTO) || |
753 robustness > max_robustness) { | 769 robustness > max_robustness) { |
754 return EmeConfigRule::NOT_SUPPORTED; | 770 return EmeConfigRule::NOT_SUPPORTED; |
755 } | 771 } |
756 | 772 |
773 if (key_system == kWidevineKeySystem) { | |
757 #if defined(OS_CHROMEOS) | 774 #if defined(OS_CHROMEOS) |
758 if (key_system == kWidevineKeySystem) { | |
759 // Hardware security requires remote attestation. | 775 // Hardware security requires remote attestation. |
760 if (robustness >= EmeRobustness::HW_SECURE_CRYPTO) | 776 if (robustness >= EmeRobustness::HW_SECURE_CRYPTO) |
761 return EmeConfigRule::IDENTIFIER_REQUIRED; | 777 return EmeConfigRule::IDENTIFIER_REQUIRED; |
762 | 778 |
763 // For video, recommend remote attestation if HW_SECURE_ALL is available, | 779 // For video, recommend remote attestation if HW_SECURE_ALL is available, |
764 // because it enables hardware accelerated decoding. | 780 // because it enables hardware accelerated decoding. |
765 // TODO(sandersd): Only do this when hardware accelerated decoding is | 781 // TODO(sandersd): Only do this when hardware accelerated decoding is |
766 // available for the requested codecs. | 782 // available for the requested codecs. |
767 if (media_type == EmeMediaType::VIDEO && | 783 if (media_type == EmeMediaType::VIDEO && |
768 max_robustness == EmeRobustness::HW_SECURE_ALL) { | 784 max_robustness == EmeRobustness::HW_SECURE_ALL) { |
769 return EmeConfigRule::IDENTIFIER_RECOMMENDED; | 785 return EmeConfigRule::IDENTIFIER_RECOMMENDED; |
770 } | 786 } |
787 #elif defined(OS_ANDROID) | |
788 if (robustness > EmeRobustness::SW_SECURE_CRYPTO) | |
789 return EmeConfigRule::SECURE_CODECS_REQUIRED; | |
790 #endif // defined(OS_CHROMEOS) | |
771 } | 791 } |
772 #endif // defined(OS_CHROMEOS) | |
773 | 792 |
774 return EmeConfigRule::SUPPORTED; | 793 return EmeConfigRule::SUPPORTED; |
775 } | 794 } |
776 | 795 |
777 EmeSessionTypeSupport KeySystemsImpl::GetPersistentLicenseSessionSupport( | 796 EmeSessionTypeSupport KeySystemsImpl::GetPersistentLicenseSessionSupport( |
778 const std::string& key_system) const { | 797 const std::string& key_system) const { |
779 DCHECK(thread_checker_.CalledOnValidThread()); | 798 DCHECK(thread_checker_.CalledOnValidThread()); |
780 | 799 |
781 KeySystemInfoMap::const_iterator key_system_iter = | 800 KeySystemInfoMap::const_iterator key_system_iter = |
782 concrete_key_system_map_.find(key_system); | 801 concrete_key_system_map_.find(key_system); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 } | 931 } |
913 | 932 |
914 MEDIA_EXPORT void AddCodecMask( | 933 MEDIA_EXPORT void AddCodecMask( |
915 EmeMediaType media_type, | 934 EmeMediaType media_type, |
916 const std::string& codec, | 935 const std::string& codec, |
917 uint32 mask) { | 936 uint32 mask) { |
918 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); | 937 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); |
919 } | 938 } |
920 | 939 |
921 } // namespace media | 940 } // namespace media |
OLD | NEW |