| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // for real key system names. Use is discouraged. | 180 // for real key system names. Use is discouraged. |
| 181 const char kExcludedPrefix[] = "x-"; | 181 const char kExcludedPrefix[] = "x-"; |
| 182 if (key_system.find(kExcludedPrefix, 0, arraysize(kExcludedPrefix) - 1) == 0) | 182 if (key_system.find(kExcludedPrefix, 0, arraysize(kExcludedPrefix) - 1) == 0) |
| 183 return true; | 183 return true; |
| 184 | 184 |
| 185 return false; | 185 return false; |
| 186 } | 186 } |
| 187 | 187 |
| 188 class KeySystemsImpl : public KeySystems { | 188 class KeySystemsImpl : public KeySystems { |
| 189 public: | 189 public: |
| 190 static KeySystemsImpl& GetInstance(); | 190 static KeySystemsImpl* GetInstance(); |
| 191 | 191 |
| 192 void UpdateIfNeeded(); | 192 void UpdateIfNeeded(); |
| 193 | 193 |
| 194 bool IsConcreteSupportedKeySystem(const std::string& key_system) const; | 194 bool IsConcreteSupportedKeySystem(const std::string& key_system) const; |
| 195 | 195 |
| 196 bool PrefixedIsSupportedKeySystemWithMediaMimeType( | 196 bool PrefixedIsSupportedKeySystemWithMediaMimeType( |
| 197 const std::string& mime_type, | 197 const std::string& mime_type, |
| 198 const std::vector<std::string>& codecs, | 198 const std::vector<std::string>& codecs, |
| 199 const std::string& key_system); | 199 const std::string& key_system); |
| 200 | 200 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 303 |
| 304 // Makes sure all methods are called from the same thread. | 304 // Makes sure all methods are called from the same thread. |
| 305 base::ThreadChecker thread_checker_; | 305 base::ThreadChecker thread_checker_; |
| 306 | 306 |
| 307 DISALLOW_COPY_AND_ASSIGN(KeySystemsImpl); | 307 DISALLOW_COPY_AND_ASSIGN(KeySystemsImpl); |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 static base::LazyInstance<KeySystemsImpl> g_key_systems = | 310 static base::LazyInstance<KeySystemsImpl> g_key_systems = |
| 311 LAZY_INSTANCE_INITIALIZER; | 311 LAZY_INSTANCE_INITIALIZER; |
| 312 | 312 |
| 313 KeySystemsImpl& KeySystemsImpl::GetInstance() { | 313 KeySystemsImpl* KeySystemsImpl::GetInstance() { |
| 314 KeySystemsImpl& key_systems = g_key_systems.Get(); | 314 KeySystemsImpl* key_systems = g_key_systems.Pointer(); |
| 315 key_systems.UpdateIfNeeded(); | 315 key_systems->UpdateIfNeeded(); |
| 316 return key_systems; | 316 return key_systems; |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Because we use a LazyInstance, the key systems info must be populated when | 319 // Because we use a LazyInstance, the key systems info must be populated when |
| 320 // the instance is lazily initiated. | 320 // the instance is lazily initiated. |
| 321 KeySystemsImpl::KeySystemsImpl() : | 321 KeySystemsImpl::KeySystemsImpl() : |
| 322 audio_codec_mask_(EME_CODEC_AUDIO_ALL), | 322 audio_codec_mask_(EME_CODEC_AUDIO_ALL), |
| 323 video_codec_mask_(EME_CODEC_VIDEO_ALL) { | 323 video_codec_mask_(EME_CODEC_VIDEO_ALL) { |
| 324 for (size_t i = 0; i < arraysize(kContainerToCodecMasks); ++i) { | 324 for (size_t i = 0; i < arraysize(kContainerToCodecMasks); ++i) { |
| 325 const std::string& name = kContainerToCodecMasks[i].name; | 325 const std::string& name = kContainerToCodecMasks[i].name; |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 requirement == EME_FEATURE_OPTIONAL) { | 899 requirement == EME_FEATURE_OPTIONAL) { |
| 900 return EmeConfigRule::SUPPORTED; | 900 return EmeConfigRule::SUPPORTED; |
| 901 } | 901 } |
| 902 if (support == EME_FEATURE_NOT_SUPPORTED || | 902 if (support == EME_FEATURE_NOT_SUPPORTED || |
| 903 requirement == EME_FEATURE_NOT_ALLOWED) { | 903 requirement == EME_FEATURE_NOT_ALLOWED) { |
| 904 return EmeConfigRule::IDENTIFIER_NOT_ALLOWED; | 904 return EmeConfigRule::IDENTIFIER_NOT_ALLOWED; |
| 905 } | 905 } |
| 906 return EmeConfigRule::IDENTIFIER_REQUIRED; | 906 return EmeConfigRule::IDENTIFIER_REQUIRED; |
| 907 } | 907 } |
| 908 | 908 |
| 909 KeySystems& KeySystems::GetInstance() { | 909 KeySystems* KeySystems::GetInstance() { |
| 910 return KeySystemsImpl::GetInstance(); | 910 return KeySystemsImpl::GetInstance(); |
| 911 } | 911 } |
| 912 | 912 |
| 913 //------------------------------------------------------------------------------ | 913 //------------------------------------------------------------------------------ |
| 914 | 914 |
| 915 std::string GetUnprefixedKeySystemName(const std::string& key_system) { | 915 std::string GetUnprefixedKeySystemName(const std::string& key_system) { |
| 916 if (key_system == kClearKeyKeySystem) | 916 if (key_system == kClearKeyKeySystem) |
| 917 return kUnsupportedClearKeyKeySystem; | 917 return kUnsupportedClearKeyKeySystem; |
| 918 | 918 |
| 919 if (key_system == kPrefixedClearKeyKeySystem) | 919 if (key_system == kPrefixedClearKeyKeySystem) |
| 920 return kClearKeyKeySystem; | 920 return kClearKeyKeySystem; |
| 921 | 921 |
| 922 return key_system; | 922 return key_system; |
| 923 } | 923 } |
| 924 | 924 |
| 925 std::string GetPrefixedKeySystemName(const std::string& key_system) { | 925 std::string GetPrefixedKeySystemName(const std::string& key_system) { |
| 926 DCHECK_NE(key_system, kPrefixedClearKeyKeySystem); | 926 DCHECK_NE(key_system, kPrefixedClearKeyKeySystem); |
| 927 | 927 |
| 928 if (key_system == kClearKeyKeySystem) | 928 if (key_system == kClearKeyKeySystem) |
| 929 return kPrefixedClearKeyKeySystem; | 929 return kPrefixedClearKeyKeySystem; |
| 930 | 930 |
| 931 return key_system; | 931 return key_system; |
| 932 } | 932 } |
| 933 | 933 |
| 934 bool PrefixedIsSupportedConcreteKeySystem(const std::string& key_system) { | 934 bool PrefixedIsSupportedConcreteKeySystem(const std::string& key_system) { |
| 935 return KeySystemsImpl::GetInstance().IsConcreteSupportedKeySystem(key_system); | 935 return KeySystemsImpl::GetInstance()->IsConcreteSupportedKeySystem( |
| 936 key_system); |
| 936 } | 937 } |
| 937 | 938 |
| 938 bool IsSupportedKeySystem(const std::string& key_system) { | 939 bool IsSupportedKeySystem(const std::string& key_system) { |
| 939 if (!KeySystemsImpl::GetInstance().IsSupportedKeySystem(key_system)) | 940 if (!KeySystemsImpl::GetInstance()->IsSupportedKeySystem(key_system)) |
| 940 return false; | 941 return false; |
| 941 | 942 |
| 942 // TODO(ddorwin): Move this to where we add key systems when prefixed EME is | 943 // TODO(ddorwin): Move this to where we add key systems when prefixed EME is |
| 943 // removed (crbug.com/249976). | 944 // removed (crbug.com/249976). |
| 944 if (!IsPotentiallySupportedKeySystem(key_system)) { | 945 if (!IsPotentiallySupportedKeySystem(key_system)) { |
| 945 // If you encounter this path, see the comments for the above function. | 946 // If you encounter this path, see the comments for the above function. |
| 946 NOTREACHED() << "Unrecognized key system " << key_system | 947 NOTREACHED() << "Unrecognized key system " << key_system |
| 947 << ". See code comments."; | 948 << ". See code comments."; |
| 948 return false; | 949 return false; |
| 949 } | 950 } |
| 950 | 951 |
| 951 return true; | 952 return true; |
| 952 } | 953 } |
| 953 | 954 |
| 954 bool IsSupportedKeySystemWithInitDataType(const std::string& key_system, | 955 bool IsSupportedKeySystemWithInitDataType(const std::string& key_system, |
| 955 EmeInitDataType init_data_type) { | 956 EmeInitDataType init_data_type) { |
| 956 return KeySystemsImpl::GetInstance().IsSupportedInitDataType(key_system, | 957 return KeySystemsImpl::GetInstance()->IsSupportedInitDataType(key_system, |
| 957 init_data_type); | 958 init_data_type); |
| 958 } | 959 } |
| 959 | 960 |
| 960 bool PrefixedIsSupportedKeySystemWithMediaMimeType( | 961 bool PrefixedIsSupportedKeySystemWithMediaMimeType( |
| 961 const std::string& mime_type, | 962 const std::string& mime_type, |
| 962 const std::vector<std::string>& codecs, | 963 const std::vector<std::string>& codecs, |
| 963 const std::string& key_system) { | 964 const std::string& key_system) { |
| 964 return KeySystemsImpl::GetInstance() | 965 return KeySystemsImpl::GetInstance() |
| 965 .PrefixedIsSupportedKeySystemWithMediaMimeType(mime_type, codecs, | 966 ->PrefixedIsSupportedKeySystemWithMediaMimeType(mime_type, codecs, |
| 966 key_system); | 967 key_system); |
| 967 } | 968 } |
| 968 | 969 |
| 969 std::string GetKeySystemNameForUMA(const std::string& key_system) { | 970 std::string GetKeySystemNameForUMA(const std::string& key_system) { |
| 970 return KeySystemsImpl::GetInstance().GetKeySystemNameForUMA(key_system); | 971 return KeySystemsImpl::GetInstance()->GetKeySystemNameForUMA(key_system); |
| 971 } | 972 } |
| 972 | 973 |
| 973 bool CanUseAesDecryptor(const std::string& concrete_key_system) { | 974 bool CanUseAesDecryptor(const std::string& concrete_key_system) { |
| 974 return KeySystemsImpl::GetInstance().UseAesDecryptor(concrete_key_system); | 975 return KeySystemsImpl::GetInstance()->UseAesDecryptor(concrete_key_system); |
| 975 } | 976 } |
| 976 | 977 |
| 977 #if defined(ENABLE_PEPPER_CDMS) | 978 #if defined(ENABLE_PEPPER_CDMS) |
| 978 std::string GetPepperType(const std::string& concrete_key_system) { | 979 std::string GetPepperType(const std::string& concrete_key_system) { |
| 979 return KeySystemsImpl::GetInstance().GetPepperType(concrete_key_system); | 980 return KeySystemsImpl::GetInstance()->GetPepperType(concrete_key_system); |
| 980 } | 981 } |
| 981 #endif | 982 #endif |
| 982 | 983 |
| 983 // These two functions are for testing purpose only. The declaration in the | 984 // These two functions are for testing purpose only. The declaration in the |
| 984 // header file is guarded by "#if defined(UNIT_TEST)" so that they can be used | 985 // header file is guarded by "#if defined(UNIT_TEST)" so that they can be used |
| 985 // by tests but not non-test code. However, this .cc file is compiled as part of | 986 // by tests but not non-test code. However, this .cc file is compiled as part of |
| 986 // "media" where "UNIT_TEST" is not defined. So we need to specify | 987 // "media" where "UNIT_TEST" is not defined. So we need to specify |
| 987 // "MEDIA_EXPORT" here again so that they are visible to tests. | 988 // "MEDIA_EXPORT" here again so that they are visible to tests. |
| 988 | 989 |
| 989 MEDIA_EXPORT void AddContainerMask(const std::string& container, uint32 mask) { | 990 MEDIA_EXPORT void AddContainerMask(const std::string& container, uint32 mask) { |
| 990 KeySystemsImpl::GetInstance().AddContainerMask(container, mask); | 991 KeySystemsImpl::GetInstance()->AddContainerMask(container, mask); |
| 991 } | 992 } |
| 992 | 993 |
| 993 MEDIA_EXPORT void AddCodecMask( | 994 MEDIA_EXPORT void AddCodecMask( |
| 994 EmeMediaType media_type, | 995 EmeMediaType media_type, |
| 995 const std::string& codec, | 996 const std::string& codec, |
| 996 uint32 mask) { | 997 uint32 mask) { |
| 997 KeySystemsImpl::GetInstance().AddCodecMask(media_type, codec, mask); | 998 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); |
| 998 } | 999 } |
| 999 | 1000 |
| 1000 } // namespace media | 1001 } // namespace media |
| OLD | NEW |