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 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 23 matching lines...) Expand all Loading... | |
| 78 | 75 |
| 79 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { | 76 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { |
| 80 KeySystemInfo info; | 77 KeySystemInfo info; |
| 81 info.key_system = kClearKeyKeySystem; | 78 info.key_system = kClearKeyKeySystem; |
| 82 | 79 |
| 83 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: | 80 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: |
| 84 // http://developer.android.com/guide/appendix/media-formats.html | 81 // http://developer.android.com/guide/appendix/media-formats.html |
| 85 // VP9 support is device dependent. | 82 // VP9 support is device dependent. |
| 86 | 83 |
| 87 info.supported_init_data_types = | 84 info.supported_init_data_types = |
| 88 EME_INIT_DATA_TYPE_WEBM | EME_INIT_DATA_TYPE_KEYIDS; | 85 kSupportedInitDataTypeWebM | kSupportedInitDataTypeKeyIds; |
| 89 info.supported_codecs = EME_CODEC_WEBM_ALL; | 86 info.supported_codecs = EME_CODEC_WEBM_ALL; |
| 90 | 87 |
| 91 #if defined(OS_ANDROID) | 88 #if defined(OS_ANDROID) |
| 92 // Temporarily disable VP9 support for Android. | 89 // Temporarily disable VP9 support for Android. |
| 93 // TODO(xhwang): Use mime_util.h to query VP9 support on Android. | 90 // TODO(xhwang): Use mime_util.h to query VP9 support on Android. |
| 94 info.supported_codecs &= ~EME_CODEC_WEBM_VP9; | 91 info.supported_codecs &= ~EME_CODEC_WEBM_VP9; |
| 95 | 92 |
| 96 // Opus is not supported on Android yet. http://crbug.com/318436. | 93 // Opus is not supported on Android yet. http://crbug.com/318436. |
| 97 // TODO(sandersd): Check for platform support to set this bit. | 94 // TODO(sandersd): Check for platform support to set this bit. |
| 98 info.supported_codecs &= ~EME_CODEC_WEBM_OPUS; | 95 info.supported_codecs &= ~EME_CODEC_WEBM_OPUS; |
| 99 #endif // defined(OS_ANDROID) | 96 #endif // defined(OS_ANDROID) |
| 100 | 97 |
| 101 #if defined(USE_PROPRIETARY_CODECS) | 98 #if defined(USE_PROPRIETARY_CODECS) |
| 102 info.supported_init_data_types |= EME_INIT_DATA_TYPE_CENC; | 99 info.supported_init_data_types |= kSupportedInitDataTypeCenc; |
| 103 info.supported_codecs |= EME_CODEC_MP4_ALL; | 100 info.supported_codecs |= EME_CODEC_MP4_ALL; |
| 104 #endif // defined(USE_PROPRIETARY_CODECS) | 101 #endif // defined(USE_PROPRIETARY_CODECS) |
| 105 | 102 |
| 106 info.persistent_license_support = EME_SESSION_TYPE_NOT_SUPPORTED; | 103 info.persistent_license_support = EME_SESSION_TYPE_NOT_SUPPORTED; |
| 107 info.persistent_release_message_support = EME_SESSION_TYPE_NOT_SUPPORTED; | 104 info.persistent_release_message_support = EME_SESSION_TYPE_NOT_SUPPORTED; |
| 108 info.persistent_state_support = EME_FEATURE_NOT_SUPPORTED; | 105 info.persistent_state_support = EME_FEATURE_NOT_SUPPORTED; |
| 109 info.distinctive_identifier_support = EME_FEATURE_NOT_SUPPORTED; | 106 info.distinctive_identifier_support = EME_FEATURE_NOT_SUPPORTED; |
| 110 | 107 |
| 111 info.use_aes_decryptor = true; | 108 info.use_aes_decryptor = true; |
| 112 | 109 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 // Always update supported key systems during construction. | 305 // Always update supported key systems during construction. |
| 309 UpdateSupportedKeySystems(); | 306 UpdateSupportedKeySystems(); |
| 310 } | 307 } |
| 311 | 308 |
| 312 EmeInitDataType KeySystems::GetInitDataTypeForName( | 309 EmeInitDataType KeySystems::GetInitDataTypeForName( |
| 313 const std::string& init_data_type) const { | 310 const std::string& init_data_type) const { |
| 314 InitDataTypesMap::const_iterator iter = | 311 InitDataTypesMap::const_iterator iter = |
| 315 init_data_type_name_map_.find(init_data_type); | 312 init_data_type_name_map_.find(init_data_type); |
| 316 if (iter != init_data_type_name_map_.end()) | 313 if (iter != init_data_type_name_map_.end()) |
| 317 return iter->second; | 314 return iter->second; |
| 318 return EME_INIT_DATA_TYPE_NONE; | 315 return EmeInitDataType::NONE; |
|
sandersd (OOO until July 31)
2015/03/23 21:27:30
This method is only used from one place, and it's
jrummell
2015/03/25 21:44:25
In the future calls to IsSupportedKeySystemWithIni
| |
| 319 } | 316 } |
| 320 | 317 |
| 321 SupportedCodecs KeySystems::GetCodecMaskForContainer( | 318 SupportedCodecs KeySystems::GetCodecMaskForContainer( |
| 322 const std::string& container) const { | 319 const std::string& container) const { |
| 323 ContainerCodecsMap::const_iterator iter = | 320 ContainerCodecsMap::const_iterator iter = |
| 324 container_to_codec_mask_map_.find(container); | 321 container_to_codec_mask_map_.find(container); |
| 325 if (iter != container_to_codec_mask_map_.end()) | 322 if (iter != container_to_codec_mask_map_.end()) |
| 326 return iter->second; | 323 return iter->second; |
| 327 return EME_CODEC_NONE; | 324 return EME_CODEC_NONE; |
| 328 } | 325 } |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 const std::string& key_system, | 509 const std::string& key_system, |
| 513 const std::string& init_data_type) { | 510 const std::string& init_data_type) { |
| 514 DCHECK(thread_checker_.CalledOnValidThread()); | 511 DCHECK(thread_checker_.CalledOnValidThread()); |
| 515 | 512 |
| 516 // Locate |key_system|. Only concrete key systems are supported in unprefixed. | 513 // Locate |key_system|. Only concrete key systems are supported in unprefixed. |
| 517 KeySystemInfoMap::const_iterator key_system_iter = | 514 KeySystemInfoMap::const_iterator key_system_iter = |
| 518 concrete_key_system_map_.find(key_system); | 515 concrete_key_system_map_.find(key_system); |
| 519 if (key_system_iter == concrete_key_system_map_.end()) | 516 if (key_system_iter == concrete_key_system_map_.end()) |
| 520 return false; | 517 return false; |
| 521 | 518 |
| 522 // Check |init_data_type| and |key_system| x |init_data_type|. | 519 // Check |init_data_type|. |
| 523 const KeySystemInfo& info = key_system_iter->second; | 520 SupportedInitDataTypes available_init_data_types = |
| 524 EmeInitDataType eme_init_data_type = GetInitDataTypeForName(init_data_type); | 521 key_system_iter->second.supported_init_data_types; |
| 525 return (info.supported_init_data_types & eme_init_data_type) != 0; | 522 switch (GetInitDataTypeForName(init_data_type)) { |
| 523 case EmeInitDataType::NONE: | |
| 524 return false; | |
| 525 case EmeInitDataType::WEBM: | |
| 526 return (available_init_data_types & kSupportedInitDataTypeWebM) != 0; | |
| 527 case EmeInitDataType::CENC: | |
| 528 return (available_init_data_types & kSupportedInitDataTypeCenc) != 0; | |
| 529 case EmeInitDataType::KEYIDS: | |
| 530 return (available_init_data_types & kSupportedInitDataTypeKeyIds) != 0; | |
| 531 } | |
| 532 NOTREACHED(); | |
| 533 return false; | |
| 526 } | 534 } |
| 527 | 535 |
| 528 // TODO(sandersd): Reorganize to be more similar to | 536 // TODO(sandersd): Reorganize to be more similar to |
| 529 // IsKeySystemSupportedWithInitDataType(). Note that a fork may still be | 537 // IsKeySystemSupportedWithInitDataType(). Note that a fork may still be |
| 530 // required; http://crbug.com/417461. | 538 // required; http://crbug.com/417461. |
| 531 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( | 539 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( |
| 532 const std::string& mime_type, | 540 const std::string& mime_type, |
| 533 const std::vector<std::string>& codecs, | 541 const std::vector<std::string>& codecs, |
| 534 const std::string& key_system, | 542 const std::string& key_system, |
| 535 bool is_prefixed) { | 543 bool is_prefixed) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 774 | 782 |
| 775 std::string GetPrefixedKeySystemName(const std::string& key_system) { | 783 std::string GetPrefixedKeySystemName(const std::string& key_system) { |
| 776 DCHECK_NE(key_system, kPrefixedClearKeyKeySystem); | 784 DCHECK_NE(key_system, kPrefixedClearKeyKeySystem); |
| 777 | 785 |
| 778 if (key_system == kClearKeyKeySystem) | 786 if (key_system == kClearKeyKeySystem) |
| 779 return kPrefixedClearKeyKeySystem; | 787 return kPrefixedClearKeyKeySystem; |
| 780 | 788 |
| 781 return key_system; | 789 return key_system; |
| 782 } | 790 } |
| 783 | 791 |
| 784 bool IsSaneInitDataTypeWithContainer( | |
| 785 const std::string& init_data_type, | |
| 786 const std::string& container) { | |
| 787 if (init_data_type == "cenc") { | |
| 788 return container == "audio/mp4" || container == "video/mp4"; | |
| 789 } else if (init_data_type == "webm") { | |
| 790 return container == "audio/webm" || container == "video/webm"; | |
| 791 } else { | |
| 792 return true; | |
| 793 } | |
| 794 } | |
| 795 | |
| 796 bool PrefixedIsSupportedConcreteKeySystem(const std::string& key_system) { | 792 bool PrefixedIsSupportedConcreteKeySystem(const std::string& key_system) { |
| 797 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system); | 793 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system); |
| 798 } | 794 } |
| 799 | 795 |
| 800 bool IsSupportedKeySystem(const std::string& key_system) { | 796 bool IsSupportedKeySystem(const std::string& key_system) { |
| 801 if (!KeySystems::GetInstance().IsSupportedKeySystem(key_system)) | 797 if (!KeySystems::GetInstance().IsSupportedKeySystem(key_system)) |
| 802 return false; | 798 return false; |
| 803 | 799 |
| 804 // TODO(ddorwin): Move this to where we add key systems when prefixed EME is | 800 // TODO(ddorwin): Move this to where we add key systems when prefixed EME is |
| 805 // removed (crbug.com/249976). | 801 // removed (crbug.com/249976). |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 | 884 |
| 889 MEDIA_EXPORT void AddContainerMask(const std::string& container, uint32 mask) { | 885 MEDIA_EXPORT void AddContainerMask(const std::string& container, uint32 mask) { |
| 890 KeySystems::GetInstance().AddContainerMask(container, mask); | 886 KeySystems::GetInstance().AddContainerMask(container, mask); |
| 891 } | 887 } |
| 892 | 888 |
| 893 MEDIA_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { | 889 MEDIA_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { |
| 894 KeySystems::GetInstance().AddCodecMask(codec, mask); | 890 KeySystems::GetInstance().AddCodecMask(codec, mask); |
| 895 } | 891 } |
| 896 | 892 |
| 897 } // namespace media | 893 } // namespace media |
| OLD | NEW |