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

Side by Side Diff: media/base/key_systems.cc

Issue 1953803002: Remove remaining uses of KeySystemInfo and InitDataTypeMask (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 7 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
« no previous file with comments | « media/base/key_system_properties.h ('k') | media/blink/key_system_config_selector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/base/key_systems.h" 5 #include "media/base/key_systems.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "media/base/key_system_info.h"
20 #include "media/base/key_system_names.h" 19 #include "media/base/key_system_names.h"
21 #include "media/base/key_system_properties.h" 20 #include "media/base/key_system_properties.h"
22 #include "media/base/media.h" 21 #include "media/base/media.h"
23 #include "media/base/media_client.h" 22 #include "media/base/media_client.h"
24 #include "media/media_features.h" 23 #include "media/media_features.h"
25 #include "third_party/widevine/cdm/widevine_cdm_common.h" 24 #include "third_party/widevine/cdm/widevine_cdm_common.h"
26 25
27 namespace media { 26 namespace media {
28 27
29 const char kClearKeyKeySystem[] = "org.w3.clearkey"; 28 const char kClearKeyKeySystem[] = "org.w3.clearkey";
(...skipping 30 matching lines...) Expand all
60 #if defined(USE_PROPRIETARY_CODECS) 59 #if defined(USE_PROPRIETARY_CODECS)
61 #if BUILDFLAG(ENABLE_MP4_VP9_DEMUXING) 60 #if BUILDFLAG(ENABLE_MP4_VP9_DEMUXING)
62 {"vp09", EME_CODEC_MP4_VP9}, // VP9 in MP4. 61 {"vp09", EME_CODEC_MP4_VP9}, // VP9 in MP4.
63 #endif 62 #endif
64 {"mp4a", EME_CODEC_MP4_AAC}, // AAC. 63 {"mp4a", EME_CODEC_MP4_AAC}, // AAC.
65 {"avc1", EME_CODEC_MP4_AVC1}, // AVC1. 64 {"avc1", EME_CODEC_MP4_AVC1}, // AVC1.
66 {"avc3", EME_CODEC_MP4_AVC1} // AVC3. 65 {"avc3", EME_CODEC_MP4_AVC1} // AVC3.
67 #endif // defined(USE_PROPRIETARY_CODECS) 66 #endif // defined(USE_PROPRIETARY_CODECS)
68 }; 67 };
69 68
70 static EmeRobustness ConvertRobustness(const std::string& robustness) {
71 if (robustness.empty())
72 return EmeRobustness::EMPTY;
73 if (robustness == "SW_SECURE_CRYPTO")
74 return EmeRobustness::SW_SECURE_CRYPTO;
75 if (robustness == "SW_SECURE_DECODE")
76 return EmeRobustness::SW_SECURE_DECODE;
77 if (robustness == "HW_SECURE_CRYPTO")
78 return EmeRobustness::HW_SECURE_CRYPTO;
79 if (robustness == "HW_SECURE_DECODE")
80 return EmeRobustness::HW_SECURE_DECODE;
81 if (robustness == "HW_SECURE_ALL")
82 return EmeRobustness::HW_SECURE_ALL;
83 return EmeRobustness::INVALID;
84 }
85
86 class ClearKeyProperties : public KeySystemProperties { 69 class ClearKeyProperties : public KeySystemProperties {
87 public: 70 public:
88 std::string GetKeySystemName() const override { return kClearKeyKeySystem; } 71 std::string GetKeySystemName() const override { return kClearKeyKeySystem; }
89 72
90 bool IsSupportedInitDataType(EmeInitDataType init_data_type) const override { 73 bool IsSupportedInitDataType(EmeInitDataType init_data_type) const override {
91 #if defined(USE_PROPRIETARY_CODECS) 74 #if defined(USE_PROPRIETARY_CODECS)
92 if (init_data_type == EmeInitDataType::CENC) 75 if (init_data_type == EmeInitDataType::CENC)
93 return true; 76 return true;
94 #endif 77 #endif
95 return init_data_type == EmeInitDataType::WEBM || 78 return init_data_type == EmeInitDataType::WEBM ||
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // Implementations that do not have a specification or appropriate glue code 167 // Implementations that do not have a specification or appropriate glue code
185 // can use the "x-" prefix to avoid conflicting with and advertising support 168 // can use the "x-" prefix to avoid conflicting with and advertising support
186 // for real key system names. Use is discouraged. 169 // for real key system names. Use is discouraged.
187 const char kExcludedPrefix[] = "x-"; 170 const char kExcludedPrefix[] = "x-";
188 if (key_system.find(kExcludedPrefix, 0, arraysize(kExcludedPrefix) - 1) == 0) 171 if (key_system.find(kExcludedPrefix, 0, arraysize(kExcludedPrefix) - 1) == 0)
189 return true; 172 return true;
190 173
191 return false; 174 return false;
192 } 175 }
193 176
194 InfoBasedKeySystemProperties::InfoBasedKeySystemProperties(
195 const KeySystemInfo& info)
196 : info_(info) {
197 DCHECK(info.max_audio_robustness != EmeRobustness::INVALID);
198 DCHECK(info.max_video_robustness != EmeRobustness::INVALID);
199 }
200
201 std::string InfoBasedKeySystemProperties::GetKeySystemName() const {
202 return info_.key_system;
203 }
204
205 SupportedCodecs InfoBasedKeySystemProperties::GetSupportedCodecs() const {
206 return info_.supported_codecs;
207 }
208 #if defined(OS_ANDROID)
209 SupportedCodecs InfoBasedKeySystemProperties::GetSupportedSecureCodecs() const {
210 return info_.supported_secure_codecs;
211 }
212 #endif
213
214 class KeySystemsImpl : public KeySystems { 177 class KeySystemsImpl : public KeySystems {
215 public: 178 public:
216 static KeySystemsImpl* GetInstance(); 179 static KeySystemsImpl* GetInstance();
217 180
218 void UpdateIfNeeded(); 181 void UpdateIfNeeded();
219 182
220 std::string GetKeySystemNameForUMA(const std::string& key_system) const; 183 std::string GetKeySystemNameForUMA(const std::string& key_system) const;
221 184
222 bool UseAesDecryptor(const std::string& key_system) const; 185 bool UseAesDecryptor(const std::string& key_system) const;
223 186
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 474
512 KeySystemPropertiesMap::const_iterator key_system_iter = 475 KeySystemPropertiesMap::const_iterator key_system_iter =
513 key_system_properties_map_.find(key_system); 476 key_system_properties_map_.find(key_system);
514 if (key_system_iter == key_system_properties_map_.end()) { 477 if (key_system_iter == key_system_properties_map_.end()) {
515 NOTREACHED(); 478 NOTREACHED();
516 return false; 479 return false;
517 } 480 }
518 return key_system_iter->second->IsSupportedInitDataType(init_data_type); 481 return key_system_iter->second->IsSupportedInitDataType(init_data_type);
519 } 482 }
520 483
521 bool InfoBasedKeySystemProperties::IsSupportedInitDataType(
522 EmeInitDataType init_data_type) const {
523 // Check |init_data_type|.
524 InitDataTypeMask available_init_data_types = info_.supported_init_data_types;
525
526 switch (init_data_type) {
527 case EmeInitDataType::UNKNOWN:
528 return false;
529 case EmeInitDataType::WEBM:
530 return (available_init_data_types & kInitDataTypeMaskWebM) != 0;
531 case EmeInitDataType::CENC:
532 return (available_init_data_types & kInitDataTypeMaskCenc) != 0;
533 case EmeInitDataType::KEYIDS:
534 return (available_init_data_types & kInitDataTypeMaskKeyIds) != 0;
535 }
536 NOTREACHED();
537 return false;
538 }
539
540 std::string KeySystemsImpl::GetKeySystemNameForUMA( 484 std::string KeySystemsImpl::GetKeySystemNameForUMA(
541 const std::string& key_system) const { 485 const std::string& key_system) const {
542 DCHECK(thread_checker_.CalledOnValidThread()); 486 DCHECK(thread_checker_.CalledOnValidThread());
543 487
544 KeySystemNameForUMAMap::const_iterator iter = 488 KeySystemNameForUMAMap::const_iterator iter =
545 key_system_name_for_uma_map_.find(key_system); 489 key_system_name_for_uma_map_.find(key_system);
546 if (iter == key_system_name_for_uma_map_.end()) 490 if (iter == key_system_name_for_uma_map_.end())
547 return kUnknownKeySystemNameForUMA; 491 return kUnknownKeySystemNameForUMA;
548 492
549 return iter->second; 493 return iter->second;
550 } 494 }
551 495
552 bool KeySystemsImpl::UseAesDecryptor(const std::string& key_system) const { 496 bool KeySystemsImpl::UseAesDecryptor(const std::string& key_system) const {
553 DCHECK(thread_checker_.CalledOnValidThread()); 497 DCHECK(thread_checker_.CalledOnValidThread());
554 498
555 KeySystemPropertiesMap::const_iterator key_system_iter = 499 KeySystemPropertiesMap::const_iterator key_system_iter =
556 key_system_properties_map_.find(key_system); 500 key_system_properties_map_.find(key_system);
557 if (key_system_iter == key_system_properties_map_.end()) { 501 if (key_system_iter == key_system_properties_map_.end()) {
558 DLOG(ERROR) << key_system << " is not a known system"; 502 DLOG(ERROR) << key_system << " is not a known system";
559 return false; 503 return false;
560 } 504 }
561 return key_system_iter->second->UseAesDecryptor(); 505 return key_system_iter->second->UseAesDecryptor();
562 } 506 }
563 507
564 bool InfoBasedKeySystemProperties::UseAesDecryptor() const {
565 return info_.use_aes_decryptor;
566 }
567
568 #if defined(ENABLE_PEPPER_CDMS) 508 #if defined(ENABLE_PEPPER_CDMS)
569 std::string KeySystemsImpl::GetPepperType(const std::string& key_system) const { 509 std::string KeySystemsImpl::GetPepperType(const std::string& key_system) const {
570 DCHECK(thread_checker_.CalledOnValidThread()); 510 DCHECK(thread_checker_.CalledOnValidThread());
571 511
572 KeySystemPropertiesMap::const_iterator key_system_iter = 512 KeySystemPropertiesMap::const_iterator key_system_iter =
573 key_system_properties_map_.find(key_system); 513 key_system_properties_map_.find(key_system);
574 if (key_system_iter == key_system_properties_map_.end()) { 514 if (key_system_iter == key_system_properties_map_.end()) {
575 DLOG(FATAL) << key_system << " is not a known system"; 515 DLOG(FATAL) << key_system << " is not a known system";
576 return std::string(); 516 return std::string();
577 } 517 }
578 const std::string& type = key_system_iter->second->GetPepperType(); 518 const std::string& type = key_system_iter->second->GetPepperType();
579 DLOG_IF(FATAL, type.empty()) << key_system_iter->second->GetKeySystemName() 519 DLOG_IF(FATAL, type.empty()) << key_system_iter->second->GetKeySystemName()
580 << " is not Pepper-based"; 520 << " is not Pepper-based";
581 return type; 521 return type;
582 } 522 }
583 523
584 std::string InfoBasedKeySystemProperties::GetPepperType() const {
585 return info_.pepper_type;
586 }
587 #endif 524 #endif
588 525
589 void KeySystemsImpl::AddCodecMask(EmeMediaType media_type, 526 void KeySystemsImpl::AddCodecMask(EmeMediaType media_type,
590 const std::string& codec, 527 const std::string& codec,
591 uint32_t mask) { 528 uint32_t mask) {
592 DCHECK(thread_checker_.CalledOnValidThread()); 529 DCHECK(thread_checker_.CalledOnValidThread());
593 DCHECK(!codec_string_map_.count(codec)); 530 DCHECK(!codec_string_map_.count(codec));
594 codec_string_map_[codec] = static_cast<EmeCodec>(mask); 531 codec_string_map_[codec] = static_cast<EmeCodec>(mask);
595 if (media_type == EmeMediaType::AUDIO) { 532 if (media_type == EmeMediaType::AUDIO) {
596 audio_codec_mask_ |= mask; 533 audio_codec_mask_ |= mask;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 KeySystemPropertiesMap::const_iterator key_system_iter = 634 KeySystemPropertiesMap::const_iterator key_system_iter =
698 key_system_properties_map_.find(key_system); 635 key_system_properties_map_.find(key_system);
699 if (key_system_iter == key_system_properties_map_.end()) { 636 if (key_system_iter == key_system_properties_map_.end()) {
700 NOTREACHED(); 637 NOTREACHED();
701 return EmeConfigRule::NOT_SUPPORTED; 638 return EmeConfigRule::NOT_SUPPORTED;
702 } 639 }
703 return key_system_iter->second->GetRobustnessConfigRule(media_type, 640 return key_system_iter->second->GetRobustnessConfigRule(media_type,
704 requested_robustness); 641 requested_robustness);
705 } 642 }
706 643
707 EmeConfigRule InfoBasedKeySystemProperties::GetRobustnessConfigRule(
708 EmeMediaType media_type,
709 const std::string& requested_robustness) const {
710 EmeRobustness robustness = ConvertRobustness(requested_robustness);
711 if (robustness == EmeRobustness::INVALID)
712 return EmeConfigRule::NOT_SUPPORTED;
713
714 EmeRobustness max_robustness = EmeRobustness::INVALID;
715 switch (media_type) {
716 case EmeMediaType::AUDIO:
717 max_robustness = info_.max_audio_robustness;
718 break;
719 case EmeMediaType::VIDEO:
720 max_robustness = info_.max_video_robustness;
721 break;
722 }
723
724 // We can compare robustness levels whenever they are not HW_SECURE_CRYPTO
725 // and SW_SECURE_DECODE in some order. If they are exactly those two then the
726 // robustness requirement is not supported.
727 if ((max_robustness == EmeRobustness::HW_SECURE_CRYPTO &&
728 robustness == EmeRobustness::SW_SECURE_DECODE) ||
729 (max_robustness == EmeRobustness::SW_SECURE_DECODE &&
730 robustness == EmeRobustness::HW_SECURE_CRYPTO) ||
731 robustness > max_robustness) {
732 return EmeConfigRule::NOT_SUPPORTED;
733 }
734
735 #if defined(OS_CHROMEOS)
736 if (info_.key_system == kWidevineKeySystem) {
737 // TODO(ddorwin): Remove this once we have confirmed it is not necessary.
738 // See https://crbug.com/482277
739 if (robustness == EmeRobustness::EMPTY)
740 return EmeConfigRule::SUPPORTED;
741
742 // Hardware security requires remote attestation.
743 if (robustness >= EmeRobustness::HW_SECURE_CRYPTO)
744 return EmeConfigRule::IDENTIFIER_REQUIRED;
745
746 // For video, recommend remote attestation if HW_SECURE_ALL is available,
747 // because it enables hardware accelerated decoding.
748 // TODO(sandersd): Only do this when hardware accelerated decoding is
749 // available for the requested codecs.
750 if (media_type == EmeMediaType::VIDEO &&
751 max_robustness == EmeRobustness::HW_SECURE_ALL) {
752 return EmeConfigRule::IDENTIFIER_RECOMMENDED;
753 }
754 }
755 #elif defined(OS_ANDROID)
756 // Require hardware secure codecs for Widevine when SW_SECURE_DECODE or above
757 // is specified, or for all other key systems (excluding Clear Key).
758 if ((info_.key_system == kWidevineKeySystem &&
759 robustness >= EmeRobustness::SW_SECURE_DECODE) ||
760 !IsClearKey(info_.key_system)) {
761 return EmeConfigRule::HW_SECURE_CODECS_REQUIRED;
762 }
763 #endif // defined(OS_CHROMEOS)
764
765 return EmeConfigRule::SUPPORTED;
766 }
767
768 EmeSessionTypeSupport KeySystemsImpl::GetPersistentLicenseSessionSupport( 644 EmeSessionTypeSupport KeySystemsImpl::GetPersistentLicenseSessionSupport(
769 const std::string& key_system) const { 645 const std::string& key_system) const {
770 DCHECK(thread_checker_.CalledOnValidThread()); 646 DCHECK(thread_checker_.CalledOnValidThread());
771 647
772 KeySystemPropertiesMap::const_iterator key_system_iter = 648 KeySystemPropertiesMap::const_iterator key_system_iter =
773 key_system_properties_map_.find(key_system); 649 key_system_properties_map_.find(key_system);
774 if (key_system_iter == key_system_properties_map_.end()) { 650 if (key_system_iter == key_system_properties_map_.end()) {
775 NOTREACHED(); 651 NOTREACHED();
776 return EmeSessionTypeSupport::INVALID; 652 return EmeSessionTypeSupport::INVALID;
777 } 653 }
778 return key_system_iter->second->GetPersistentLicenseSessionSupport(); 654 return key_system_iter->second->GetPersistentLicenseSessionSupport();
779 } 655 }
780 656
781 EmeSessionTypeSupport
782 InfoBasedKeySystemProperties::GetPersistentLicenseSessionSupport() const {
783 return info_.persistent_license_support;
784 }
785
786 EmeSessionTypeSupport KeySystemsImpl::GetPersistentReleaseMessageSessionSupport( 657 EmeSessionTypeSupport KeySystemsImpl::GetPersistentReleaseMessageSessionSupport(
787 const std::string& key_system) const { 658 const std::string& key_system) const {
788 DCHECK(thread_checker_.CalledOnValidThread()); 659 DCHECK(thread_checker_.CalledOnValidThread());
789 660
790 KeySystemPropertiesMap::const_iterator key_system_iter = 661 KeySystemPropertiesMap::const_iterator key_system_iter =
791 key_system_properties_map_.find(key_system); 662 key_system_properties_map_.find(key_system);
792 if (key_system_iter == key_system_properties_map_.end()) { 663 if (key_system_iter == key_system_properties_map_.end()) {
793 NOTREACHED(); 664 NOTREACHED();
794 return EmeSessionTypeSupport::INVALID; 665 return EmeSessionTypeSupport::INVALID;
795 } 666 }
796 return key_system_iter->second->GetPersistentReleaseMessageSessionSupport(); 667 return key_system_iter->second->GetPersistentReleaseMessageSessionSupport();
797 } 668 }
798 669
799 EmeSessionTypeSupport
800 InfoBasedKeySystemProperties::GetPersistentReleaseMessageSessionSupport()
801 const {
802 return info_.persistent_release_message_support;
803 }
804
805 EmeFeatureSupport KeySystemsImpl::GetPersistentStateSupport( 670 EmeFeatureSupport KeySystemsImpl::GetPersistentStateSupport(
806 const std::string& key_system) const { 671 const std::string& key_system) const {
807 DCHECK(thread_checker_.CalledOnValidThread()); 672 DCHECK(thread_checker_.CalledOnValidThread());
808 673
809 KeySystemPropertiesMap::const_iterator key_system_iter = 674 KeySystemPropertiesMap::const_iterator key_system_iter =
810 key_system_properties_map_.find(key_system); 675 key_system_properties_map_.find(key_system);
811 if (key_system_iter == key_system_properties_map_.end()) { 676 if (key_system_iter == key_system_properties_map_.end()) {
812 NOTREACHED(); 677 NOTREACHED();
813 return EmeFeatureSupport::INVALID; 678 return EmeFeatureSupport::INVALID;
814 } 679 }
815 return key_system_iter->second->GetPersistentStateSupport(); 680 return key_system_iter->second->GetPersistentStateSupport();
816 } 681 }
817 682
818 EmeFeatureSupport InfoBasedKeySystemProperties::GetPersistentStateSupport()
819 const {
820 return info_.persistent_state_support;
821 }
822
823 EmeFeatureSupport KeySystemsImpl::GetDistinctiveIdentifierSupport( 683 EmeFeatureSupport KeySystemsImpl::GetDistinctiveIdentifierSupport(
824 const std::string& key_system) const { 684 const std::string& key_system) const {
825 DCHECK(thread_checker_.CalledOnValidThread()); 685 DCHECK(thread_checker_.CalledOnValidThread());
826 686
827 KeySystemPropertiesMap::const_iterator key_system_iter = 687 KeySystemPropertiesMap::const_iterator key_system_iter =
828 key_system_properties_map_.find(key_system); 688 key_system_properties_map_.find(key_system);
829 if (key_system_iter == key_system_properties_map_.end()) { 689 if (key_system_iter == key_system_properties_map_.end()) {
830 NOTREACHED(); 690 NOTREACHED();
831 return EmeFeatureSupport::INVALID; 691 return EmeFeatureSupport::INVALID;
832 } 692 }
833 return key_system_iter->second->GetDistinctiveIdentifierSupport(); 693 return key_system_iter->second->GetDistinctiveIdentifierSupport();
834 } 694 }
835 695
836 EmeFeatureSupport
837 InfoBasedKeySystemProperties::GetDistinctiveIdentifierSupport() const {
838 return info_.distinctive_identifier_support;
839 }
840
841 KeySystems* KeySystems::GetInstance() { 696 KeySystems* KeySystems::GetInstance() {
842 return KeySystemsImpl::GetInstance(); 697 return KeySystemsImpl::GetInstance();
843 } 698 }
844 699
845 //------------------------------------------------------------------------------ 700 //------------------------------------------------------------------------------
846 701
847 bool IsSupportedKeySystemWithInitDataType(const std::string& key_system, 702 bool IsSupportedKeySystemWithInitDataType(const std::string& key_system,
848 EmeInitDataType init_data_type) { 703 EmeInitDataType init_data_type) {
849 return KeySystemsImpl::GetInstance()->IsSupportedInitDataType(key_system, 704 return KeySystemsImpl::GetInstance()->IsSupportedInitDataType(key_system,
850 init_data_type); 705 init_data_type);
(...skipping 24 matching lines...) Expand all
875 uint32_t mask) { 730 uint32_t mask) {
876 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); 731 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask);
877 } 732 }
878 733
879 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, 734 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type,
880 uint32_t mask) { 735 uint32_t mask) {
881 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); 736 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask);
882 } 737 }
883 738
884 } // namespace media 739 } // namespace media
OLDNEW
« no previous file with comments | « media/base/key_system_properties.h ('k') | media/blink/key_system_config_selector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698