Chromium Code Reviews| 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 // We don't support the inverse (only hardware-secure codecs allowed) for | |
|
ddorwin
2015/04/30 18:18:04
The subject of "the inverse" is not clearly specif
sandersd (OOO until July 31)
2015/04/30 19:57:44
Done.
| |
| 720 // simplicity, but such support could be added here. | |
|
ddorwin
2015/04/30 18:18:04
What do you mean "could be added"? Does this mean,
sandersd (OOO until July 31)
2015/04/30 19:57:45
Done.
| |
| 721 if ((codec & key_system_secure_codec_mask) == 0) | |
| 722 support = EmeConfigRule::SECURE_CODECS_NOT_ALLOWED; | |
|
jrummell
2015/04/30 02:08:37
If |codecs| contains 2 codecs, both of which are i
sandersd (OOO until July 31)
2015/04/30 18:19:34
I believe this is correct; and codec that does not
| |
| 723 #endif // defined(OS_ANDROID) | |
| 724 | |
| 712 } | 725 } |
| 713 | 726 |
| 714 return true; | 727 return support; |
| 715 } | 728 } |
| 716 | 729 |
| 717 EmeConfigRule KeySystemsImpl::GetRobustnessConfigRule( | 730 EmeConfigRule KeySystemsImpl::GetRobustnessConfigRule( |
| 718 const std::string& key_system, | 731 const std::string& key_system, |
| 719 EmeMediaType media_type, | 732 EmeMediaType media_type, |
| 720 const std::string& requested_robustness) const { | 733 const std::string& requested_robustness) const { |
| 721 DCHECK(thread_checker_.CalledOnValidThread()); | 734 DCHECK(thread_checker_.CalledOnValidThread()); |
| 722 | 735 |
| 723 EmeRobustness robustness = ConvertRobustness(requested_robustness); | 736 EmeRobustness robustness = ConvertRobustness(requested_robustness); |
| 724 if (robustness == EmeRobustness::INVALID) | 737 if (robustness == EmeRobustness::INVALID) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 748 // robustness requirement is not supported. | 761 // robustness requirement is not supported. |
| 749 if ((max_robustness == EmeRobustness::HW_SECURE_CRYPTO && | 762 if ((max_robustness == EmeRobustness::HW_SECURE_CRYPTO && |
| 750 robustness == EmeRobustness::SW_SECURE_DECODE) || | 763 robustness == EmeRobustness::SW_SECURE_DECODE) || |
| 751 (max_robustness == EmeRobustness::SW_SECURE_DECODE && | 764 (max_robustness == EmeRobustness::SW_SECURE_DECODE && |
| 752 robustness == EmeRobustness::HW_SECURE_CRYPTO) || | 765 robustness == EmeRobustness::HW_SECURE_CRYPTO) || |
| 753 robustness > max_robustness) { | 766 robustness > max_robustness) { |
| 754 return EmeConfigRule::NOT_SUPPORTED; | 767 return EmeConfigRule::NOT_SUPPORTED; |
| 755 } | 768 } |
| 756 | 769 |
| 757 #if defined(OS_CHROMEOS) | 770 #if defined(OS_CHROMEOS) |
| 758 if (key_system == kWidevineKeySystem) { | 771 if (key_system == kWidevineKeySystem) { |
|
ddorwin
2015/04/30 18:18:04
We might extract the WV logic into a function for
sandersd (OOO until July 31)
2015/04/30 19:57:44
Acknowledged.
| |
| 759 // Hardware security requires remote attestation. | 772 // Hardware security requires remote attestation. |
| 760 if (robustness >= EmeRobustness::HW_SECURE_CRYPTO) | 773 if (robustness >= EmeRobustness::HW_SECURE_CRYPTO) |
| 761 return EmeConfigRule::IDENTIFIER_REQUIRED; | 774 return EmeConfigRule::IDENTIFIER_REQUIRED; |
| 762 | 775 |
| 763 // For video, recommend remote attestation if HW_SECURE_ALL is available, | 776 // For video, recommend remote attestation if HW_SECURE_ALL is available, |
| 764 // because it enables hardware accelerated decoding. | 777 // because it enables hardware accelerated decoding. |
| 765 // TODO(sandersd): Only do this when hardware accelerated decoding is | 778 // TODO(sandersd): Only do this when hardware accelerated decoding is |
| 766 // available for the requested codecs. | 779 // available for the requested codecs. |
| 767 if (media_type == EmeMediaType::VIDEO && | 780 if (media_type == EmeMediaType::VIDEO && |
| 768 max_robustness == EmeRobustness::HW_SECURE_ALL) { | 781 max_robustness == EmeRobustness::HW_SECURE_ALL) { |
| 769 return EmeConfigRule::IDENTIFIER_RECOMMENDED; | 782 return EmeConfigRule::IDENTIFIER_RECOMMENDED; |
| 770 } | 783 } |
| 771 } | 784 } |
| 772 #endif // defined(OS_CHROMEOS) | 785 #endif // defined(OS_CHROMEOS) |
|
ddorwin
2015/04/30 18:18:04
#elif
sandersd (OOO until July 31)
2015/04/30 19:57:44
Done.
| |
| 773 | 786 |
| 787 #if defined(OS_ANDROID) | |
| 788 if (key_system == kWidevineKeySystem && | |
| 789 robustness > EmeRobustness::SW_SECURE_CRYPTO) { | |
| 790 return EmeConfigRule::SECURE_CODECS_REQUIRED; | |
| 791 } | |
| 792 #endif // defined(OS_ANDROID) | |
| 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); |
| 783 if (key_system_iter == concrete_key_system_map_.end()) { | 803 if (key_system_iter == concrete_key_system_map_.end()) { |
| (...skipping 128 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 |