| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 // These names are used by UMA. Do not change them! | 28 // These names are used by UMA. Do not change them! |
| 29 const char kClearKeyKeySystemNameForUMA[] = "ClearKey"; | 29 const char kClearKeyKeySystemNameForUMA[] = "ClearKey"; |
| 30 const char kUnknownKeySystemNameForUMA[] = "Unknown"; | 30 const char kUnknownKeySystemNameForUMA[] = "Unknown"; |
| 31 | 31 |
| 32 struct NamedInitDataType { | 32 struct NamedInitDataType { |
| 33 const char* name; | 33 const char* name; |
| 34 EmeInitDataType type; | 34 EmeInitDataType type; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 // Mapping between initialization data types names and enum values. When adding | 37 // Mapping between initialization data types names and enum values. |
| 38 // entries, make sure to update IsSaneInitDataTypeWithContainer(). | |
| 39 static NamedInitDataType kInitDataTypeNames[] = { | 38 static NamedInitDataType kInitDataTypeNames[] = { |
| 40 {"webm", EME_INIT_DATA_TYPE_WEBM}, | 39 {"webm", EmeInitDataType::WEBM}, |
| 41 #if defined(USE_PROPRIETARY_CODECS) | 40 {"cenc", EmeInitDataType::CENC}, |
| 42 {"cenc", EME_INIT_DATA_TYPE_CENC}, | 41 {"keyids", EmeInitDataType::KEYIDS}, |
| 43 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 44 {"keyids", EME_INIT_DATA_TYPE_KEYIDS}, | |
| 45 }; | 42 }; |
| 46 | 43 |
| 47 struct NamedCodec { | 44 struct NamedCodec { |
| 48 const char* name; | 45 const char* name; |
| 49 EmeCodec type; | 46 EmeCodec type; |
| 50 }; | 47 }; |
| 51 | 48 |
| 52 // Mapping between containers and their codecs. | 49 // Mapping between containers and their codecs. |
| 53 // Only audio codec can belong to a "audio/*" container. Both audio and video | 50 // Only audio codec can belong to a "audio/*" container. Both audio and video |
| 54 // codecs can belong to a "video/*" container. | 51 // codecs can belong to a "video/*" container. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 108 |
| 112 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { | 109 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { |
| 113 KeySystemInfo info; | 110 KeySystemInfo info; |
| 114 info.key_system = kClearKeyKeySystem; | 111 info.key_system = kClearKeyKeySystem; |
| 115 | 112 |
| 116 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: | 113 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: |
| 117 // http://developer.android.com/guide/appendix/media-formats.html | 114 // http://developer.android.com/guide/appendix/media-formats.html |
| 118 // VP9 support is device dependent. | 115 // VP9 support is device dependent. |
| 119 | 116 |
| 120 info.supported_init_data_types = | 117 info.supported_init_data_types = |
| 121 EME_INIT_DATA_TYPE_WEBM | EME_INIT_DATA_TYPE_KEYIDS; | 118 kInitDataTypeMaskWebM | kInitDataTypeMaskKeyIds; |
| 122 info.supported_codecs = EME_CODEC_WEBM_ALL; | 119 info.supported_codecs = EME_CODEC_WEBM_ALL; |
| 123 | 120 |
| 124 #if defined(OS_ANDROID) | 121 #if defined(OS_ANDROID) |
| 125 // Temporarily disable VP9 support for Android. | 122 // Temporarily disable VP9 support for Android. |
| 126 // TODO(xhwang): Use mime_util.h to query VP9 support on Android. | 123 // TODO(xhwang): Use mime_util.h to query VP9 support on Android. |
| 127 info.supported_codecs &= ~EME_CODEC_WEBM_VP9; | 124 info.supported_codecs &= ~EME_CODEC_WEBM_VP9; |
| 128 | 125 |
| 129 // Opus is not supported on Android yet. http://crbug.com/318436. | 126 // Opus is not supported on Android yet. http://crbug.com/318436. |
| 130 // TODO(sandersd): Check for platform support to set this bit. | 127 // TODO(sandersd): Check for platform support to set this bit. |
| 131 info.supported_codecs &= ~EME_CODEC_WEBM_OPUS; | 128 info.supported_codecs &= ~EME_CODEC_WEBM_OPUS; |
| 132 #endif // defined(OS_ANDROID) | 129 #endif // defined(OS_ANDROID) |
| 133 | 130 |
| 134 #if defined(USE_PROPRIETARY_CODECS) | 131 #if defined(USE_PROPRIETARY_CODECS) |
| 135 info.supported_init_data_types |= EME_INIT_DATA_TYPE_CENC; | 132 info.supported_init_data_types |= kInitDataTypeMaskCenc; |
| 136 info.supported_codecs |= EME_CODEC_MP4_ALL; | 133 info.supported_codecs |= EME_CODEC_MP4_ALL; |
| 137 #endif // defined(USE_PROPRIETARY_CODECS) | 134 #endif // defined(USE_PROPRIETARY_CODECS) |
| 138 | 135 |
| 139 info.max_audio_robustness = EmeRobustness::EMPTY; | 136 info.max_audio_robustness = EmeRobustness::EMPTY; |
| 140 info.max_video_robustness = EmeRobustness::EMPTY; | 137 info.max_video_robustness = EmeRobustness::EMPTY; |
| 141 info.persistent_license_support = EME_SESSION_TYPE_NOT_SUPPORTED; | 138 info.persistent_license_support = EME_SESSION_TYPE_NOT_SUPPORTED; |
| 142 info.persistent_release_message_support = EME_SESSION_TYPE_NOT_SUPPORTED; | 139 info.persistent_release_message_support = EME_SESSION_TYPE_NOT_SUPPORTED; |
| 143 info.persistent_state_support = EME_FEATURE_NOT_SUPPORTED; | 140 info.persistent_state_support = EME_FEATURE_NOT_SUPPORTED; |
| 144 info.distinctive_identifier_support = EME_FEATURE_NOT_SUPPORTED; | 141 info.distinctive_identifier_support = EME_FEATURE_NOT_SUPPORTED; |
| 145 | 142 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // Always update supported key systems during construction. | 341 // Always update supported key systems during construction. |
| 345 UpdateSupportedKeySystems(); | 342 UpdateSupportedKeySystems(); |
| 346 } | 343 } |
| 347 | 344 |
| 348 EmeInitDataType KeySystems::GetInitDataTypeForName( | 345 EmeInitDataType KeySystems::GetInitDataTypeForName( |
| 349 const std::string& init_data_type) const { | 346 const std::string& init_data_type) const { |
| 350 InitDataTypesMap::const_iterator iter = | 347 InitDataTypesMap::const_iterator iter = |
| 351 init_data_type_name_map_.find(init_data_type); | 348 init_data_type_name_map_.find(init_data_type); |
| 352 if (iter != init_data_type_name_map_.end()) | 349 if (iter != init_data_type_name_map_.end()) |
| 353 return iter->second; | 350 return iter->second; |
| 354 return EME_INIT_DATA_TYPE_NONE; | 351 return EmeInitDataType::UNKNOWN; |
| 355 } | 352 } |
| 356 | 353 |
| 357 SupportedCodecs KeySystems::GetCodecMaskForContainer( | 354 SupportedCodecs KeySystems::GetCodecMaskForContainer( |
| 358 const std::string& container) const { | 355 const std::string& container) const { |
| 359 ContainerCodecsMap::const_iterator iter = | 356 ContainerCodecsMap::const_iterator iter = |
| 360 container_to_codec_mask_map_.find(container); | 357 container_to_codec_mask_map_.find(container); |
| 361 if (iter != container_to_codec_mask_map_.end()) | 358 if (iter != container_to_codec_mask_map_.end()) |
| 362 return iter->second; | 359 return iter->second; |
| 363 return EME_CODEC_NONE; | 360 return EME_CODEC_NONE; |
| 364 } | 361 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 const std::string& key_system, | 571 const std::string& key_system, |
| 575 const std::string& init_data_type) { | 572 const std::string& init_data_type) { |
| 576 DCHECK(thread_checker_.CalledOnValidThread()); | 573 DCHECK(thread_checker_.CalledOnValidThread()); |
| 577 | 574 |
| 578 // Locate |key_system|. Only concrete key systems are supported in unprefixed. | 575 // Locate |key_system|. Only concrete key systems are supported in unprefixed. |
| 579 KeySystemInfoMap::const_iterator key_system_iter = | 576 KeySystemInfoMap::const_iterator key_system_iter = |
| 580 concrete_key_system_map_.find(key_system); | 577 concrete_key_system_map_.find(key_system); |
| 581 if (key_system_iter == concrete_key_system_map_.end()) | 578 if (key_system_iter == concrete_key_system_map_.end()) |
| 582 return false; | 579 return false; |
| 583 | 580 |
| 584 // Check |init_data_type| and |key_system| x |init_data_type|. | 581 // Check |init_data_type|. |
| 585 const KeySystemInfo& info = key_system_iter->second; | 582 InitDataTypeMask available_init_data_types = |
| 586 EmeInitDataType eme_init_data_type = GetInitDataTypeForName(init_data_type); | 583 key_system_iter->second.supported_init_data_types; |
| 587 return (info.supported_init_data_types & eme_init_data_type) != 0; | 584 switch (GetInitDataTypeForName(init_data_type)) { |
| 585 case EmeInitDataType::UNKNOWN: |
| 586 return false; |
| 587 case EmeInitDataType::WEBM: |
| 588 return (available_init_data_types & kInitDataTypeMaskWebM) != 0; |
| 589 case EmeInitDataType::CENC: |
| 590 return (available_init_data_types & kInitDataTypeMaskCenc) != 0; |
| 591 case EmeInitDataType::KEYIDS: |
| 592 return (available_init_data_types & kInitDataTypeMaskKeyIds) != 0; |
| 593 } |
| 594 NOTREACHED(); |
| 595 return false; |
| 588 } | 596 } |
| 589 | 597 |
| 590 // TODO(sandersd): Reorganize to be more similar to | 598 // TODO(sandersd): Reorganize to be more similar to |
| 591 // IsKeySystemSupportedWithInitDataType(). Note that a fork may still be | 599 // IsKeySystemSupportedWithInitDataType(). Note that a fork may still be |
| 592 // required; http://crbug.com/417461. | 600 // required; http://crbug.com/417461. |
| 593 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( | 601 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( |
| 594 const std::string& mime_type, | 602 const std::string& mime_type, |
| 595 const std::vector<std::string>& codecs, | 603 const std::vector<std::string>& codecs, |
| 596 const std::string& key_system, | 604 const std::string& key_system, |
| 597 bool is_prefixed) { | 605 bool is_prefixed) { |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 | 884 |
| 877 std::string GetPrefixedKeySystemName(const std::string& key_system) { | 885 std::string GetPrefixedKeySystemName(const std::string& key_system) { |
| 878 DCHECK_NE(key_system, kPrefixedClearKeyKeySystem); | 886 DCHECK_NE(key_system, kPrefixedClearKeyKeySystem); |
| 879 | 887 |
| 880 if (key_system == kClearKeyKeySystem) | 888 if (key_system == kClearKeyKeySystem) |
| 881 return kPrefixedClearKeyKeySystem; | 889 return kPrefixedClearKeyKeySystem; |
| 882 | 890 |
| 883 return key_system; | 891 return key_system; |
| 884 } | 892 } |
| 885 | 893 |
| 886 bool IsSaneInitDataTypeWithContainer( | |
| 887 const std::string& init_data_type, | |
| 888 const std::string& container) { | |
| 889 if (init_data_type == "cenc") { | |
| 890 return container == "audio/mp4" || container == "video/mp4"; | |
| 891 } else if (init_data_type == "webm") { | |
| 892 return container == "audio/webm" || container == "video/webm"; | |
| 893 } else { | |
| 894 return true; | |
| 895 } | |
| 896 } | |
| 897 | |
| 898 bool PrefixedIsSupportedConcreteKeySystem(const std::string& key_system) { | 894 bool PrefixedIsSupportedConcreteKeySystem(const std::string& key_system) { |
| 899 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system); | 895 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system); |
| 900 } | 896 } |
| 901 | 897 |
| 902 bool IsSupportedKeySystem(const std::string& key_system) { | 898 bool IsSupportedKeySystem(const std::string& key_system) { |
| 903 if (!KeySystems::GetInstance().IsSupportedKeySystem(key_system)) | 899 if (!KeySystems::GetInstance().IsSupportedKeySystem(key_system)) |
| 904 return false; | 900 return false; |
| 905 | 901 |
| 906 // TODO(ddorwin): Move this to where we add key systems when prefixed EME is | 902 // TODO(ddorwin): Move this to where we add key systems when prefixed EME is |
| 907 // removed (crbug.com/249976). | 903 // removed (crbug.com/249976). |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 | 990 |
| 995 MEDIA_EXPORT void AddContainerMask(const std::string& container, uint32 mask) { | 991 MEDIA_EXPORT void AddContainerMask(const std::string& container, uint32 mask) { |
| 996 KeySystems::GetInstance().AddContainerMask(container, mask); | 992 KeySystems::GetInstance().AddContainerMask(container, mask); |
| 997 } | 993 } |
| 998 | 994 |
| 999 MEDIA_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { | 995 MEDIA_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { |
| 1000 KeySystems::GetInstance().AddCodecMask(codec, mask); | 996 KeySystems::GetInstance().AddCodecMask(codec, mask); |
| 1001 } | 997 } |
| 1002 | 998 |
| 1003 } // namespace media | 999 } // namespace media |
| OLD | NEW |