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 <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_names.h" | 19 #include "media/base/key_system_names.h" |
20 #include "media/base/key_system_properties.h" | 20 #include "media/base/key_system_properties.h" |
21 #include "media/base/media.h" | 21 #include "media/base/media.h" |
| 22 #include "ppapi/features/features.h" |
22 #include "media/base/media_client.h" | 23 #include "media/base/media_client.h" |
23 #include "third_party/widevine/cdm/widevine_cdm_common.h" | 24 #include "third_party/widevine/cdm/widevine_cdm_common.h" |
24 | 25 |
25 namespace media { | 26 namespace media { |
26 | 27 |
27 const char kClearKeyKeySystem[] = "org.w3.clearkey"; | 28 const char kClearKeyKeySystem[] = "org.w3.clearkey"; |
28 | 29 |
29 // These names are used by UMA. Do not change them! | 30 // These names are used by UMA. Do not change them! |
30 const char kClearKeyKeySystemNameForUMA[] = "ClearKey"; | 31 const char kClearKeyKeySystemNameForUMA[] = "ClearKey"; |
31 const char kUnknownKeySystemNameForUMA[] = "Unknown"; | 32 const char kUnknownKeySystemNameForUMA[] = "Unknown"; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 class KeySystemsImpl : public KeySystems { | 167 class KeySystemsImpl : public KeySystems { |
167 public: | 168 public: |
168 static KeySystemsImpl* GetInstance(); | 169 static KeySystemsImpl* GetInstance(); |
169 | 170 |
170 void UpdateIfNeeded(); | 171 void UpdateIfNeeded(); |
171 | 172 |
172 std::string GetKeySystemNameForUMA(const std::string& key_system) const; | 173 std::string GetKeySystemNameForUMA(const std::string& key_system) const; |
173 | 174 |
174 bool UseAesDecryptor(const std::string& key_system) const; | 175 bool UseAesDecryptor(const std::string& key_system) const; |
175 | 176 |
176 #if defined(ENABLE_PEPPER_CDMS) | 177 #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
177 std::string GetPepperType(const std::string& key_system) const; | 178 std::string GetPepperType(const std::string& key_system) const; |
178 #endif | 179 #endif |
179 | 180 |
180 // These two functions are for testing purpose only. | 181 // These two functions are for testing purpose only. |
181 void AddCodecMask(EmeMediaType media_type, | 182 void AddCodecMask(EmeMediaType media_type, |
182 const std::string& codec, | 183 const std::string& codec, |
183 uint32_t mask); | 184 uint32_t mask); |
184 void AddMimeTypeCodecMask(const std::string& mime_type, uint32_t mask); | 185 void AddMimeTypeCodecMask(const std::string& mime_type, uint32_t mask); |
185 | 186 |
186 // Implementation of KeySystems interface. | 187 // Implementation of KeySystems interface. |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 EmeSessionTypeSupport::SUPPORTED_WITH_IDENTIFIER); | 399 EmeSessionTypeSupport::SUPPORTED_WITH_IDENTIFIER); |
399 } | 400 } |
400 | 401 |
401 // Distinctive identifiers and persistent state can only be reliably blocked | 402 // Distinctive identifiers and persistent state can only be reliably blocked |
402 // (and therefore be safely configurable) for Pepper-hosted key systems. For | 403 // (and therefore be safely configurable) for Pepper-hosted key systems. For |
403 // other platforms assume the CDM can and will do anything, except for the | 404 // other platforms assume the CDM can and will do anything, except for the |
404 // following two cases: | 405 // following two cases: |
405 // 1) AES decryptor, and | 406 // 1) AES decryptor, and |
406 // 2) External Clear Key key system on Android, only enabled for testing. | 407 // 2) External Clear Key key system on Android, only enabled for testing. |
407 bool can_block = properties->UseAesDecryptor(); | 408 bool can_block = properties->UseAesDecryptor(); |
408 #if defined(ENABLE_PEPPER_CDMS) | 409 #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
409 DCHECK_EQ(properties->UseAesDecryptor(), | 410 DCHECK_EQ(properties->UseAesDecryptor(), |
410 properties->GetPepperType().empty()); | 411 properties->GetPepperType().empty()); |
411 if (!properties->GetPepperType().empty()) | 412 if (!properties->GetPepperType().empty()) |
412 can_block = true; | 413 can_block = true; |
413 #elif defined(OS_ANDROID) | 414 #elif defined(OS_ANDROID) |
414 if (IsExternalClearKey(properties->GetKeySystemName())) | 415 if (IsExternalClearKey(properties->GetKeySystemName())) |
415 can_block = true; | 416 can_block = true; |
416 #endif | 417 #endif |
417 if (!can_block) { | 418 if (!can_block) { |
418 DCHECK(properties->GetDistinctiveIdentifierSupport() == | 419 DCHECK(properties->GetDistinctiveIdentifierSupport() == |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 500 |
500 KeySystemPropertiesMap::const_iterator key_system_iter = | 501 KeySystemPropertiesMap::const_iterator key_system_iter = |
501 key_system_properties_map_.find(key_system); | 502 key_system_properties_map_.find(key_system); |
502 if (key_system_iter == key_system_properties_map_.end()) { | 503 if (key_system_iter == key_system_properties_map_.end()) { |
503 DLOG(ERROR) << key_system << " is not a known system"; | 504 DLOG(ERROR) << key_system << " is not a known system"; |
504 return false; | 505 return false; |
505 } | 506 } |
506 return key_system_iter->second->UseAesDecryptor(); | 507 return key_system_iter->second->UseAesDecryptor(); |
507 } | 508 } |
508 | 509 |
509 #if defined(ENABLE_PEPPER_CDMS) | 510 #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
510 std::string KeySystemsImpl::GetPepperType(const std::string& key_system) const { | 511 std::string KeySystemsImpl::GetPepperType(const std::string& key_system) const { |
511 DCHECK(thread_checker_.CalledOnValidThread()); | 512 DCHECK(thread_checker_.CalledOnValidThread()); |
512 | 513 |
513 KeySystemPropertiesMap::const_iterator key_system_iter = | 514 KeySystemPropertiesMap::const_iterator key_system_iter = |
514 key_system_properties_map_.find(key_system); | 515 key_system_properties_map_.find(key_system); |
515 if (key_system_iter == key_system_properties_map_.end()) { | 516 if (key_system_iter == key_system_properties_map_.end()) { |
516 DLOG(FATAL) << key_system << " is not a known system"; | 517 DLOG(FATAL) << key_system << " is not a known system"; |
517 return std::string(); | 518 return std::string(); |
518 } | 519 } |
519 const std::string& type = key_system_iter->second->GetPepperType(); | 520 const std::string& type = key_system_iter->second->GetPepperType(); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 } | 699 } |
699 | 700 |
700 std::string GetKeySystemNameForUMA(const std::string& key_system) { | 701 std::string GetKeySystemNameForUMA(const std::string& key_system) { |
701 return KeySystemsImpl::GetInstance()->GetKeySystemNameForUMA(key_system); | 702 return KeySystemsImpl::GetInstance()->GetKeySystemNameForUMA(key_system); |
702 } | 703 } |
703 | 704 |
704 bool CanUseAesDecryptor(const std::string& key_system) { | 705 bool CanUseAesDecryptor(const std::string& key_system) { |
705 return KeySystemsImpl::GetInstance()->UseAesDecryptor(key_system); | 706 return KeySystemsImpl::GetInstance()->UseAesDecryptor(key_system); |
706 } | 707 } |
707 | 708 |
708 #if defined(ENABLE_PEPPER_CDMS) | 709 #if BUILDFLAG(ENABLE_PEPPER_CDMS) |
709 std::string GetPepperType(const std::string& key_system) { | 710 std::string GetPepperType(const std::string& key_system) { |
710 return KeySystemsImpl::GetInstance()->GetPepperType(key_system); | 711 return KeySystemsImpl::GetInstance()->GetPepperType(key_system); |
711 } | 712 } |
712 #endif | 713 #endif |
713 | 714 |
714 // These two functions are for testing purpose only. The declaration in the | 715 // These two functions are for testing purpose only. The declaration in the |
715 // header file is guarded by "#if defined(UNIT_TEST)" so that they can be used | 716 // header file is guarded by "#if defined(UNIT_TEST)" so that they can be used |
716 // by tests but not non-test code. However, this .cc file is compiled as part of | 717 // by tests but not non-test code. However, this .cc file is compiled as part of |
717 // "media" where "UNIT_TEST" is not defined. So we need to specify | 718 // "media" where "UNIT_TEST" is not defined. So we need to specify |
718 // "MEDIA_EXPORT" here again so that they are visible to tests. | 719 // "MEDIA_EXPORT" here again so that they are visible to tests. |
719 | 720 |
720 MEDIA_EXPORT void AddCodecMask(EmeMediaType media_type, | 721 MEDIA_EXPORT void AddCodecMask(EmeMediaType media_type, |
721 const std::string& codec, | 722 const std::string& codec, |
722 uint32_t mask) { | 723 uint32_t mask) { |
723 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); | 724 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); |
724 } | 725 } |
725 | 726 |
726 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, | 727 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, |
727 uint32_t mask) { | 728 uint32_t mask) { |
728 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); | 729 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); |
729 } | 730 } |
730 | 731 |
731 } // namespace media | 732 } // namespace media |
OLD | NEW |