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 "content/renderer/media/crypto/key_systems.h" | 5 #include "content/renderer/media/crypto/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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
| 16 #include "content/public/common/eme_codec.h" | 16 #include "content/public/common/eme_constants.h" |
| 17 #include "content/public/renderer/content_renderer_client.h" | 17 #include "content/public/renderer/content_renderer_client.h" |
| 18 #include "content/public/renderer/key_system_info.h" | 18 #include "content/public/renderer/key_system_info.h" |
| 19 #include "content/renderer/media/crypto/key_systems_support_uma.h" | 19 #include "content/renderer/media/crypto/key_systems_support_uma.h" |
| 20 | 20 |
| 21 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
| 22 #include "media/base/android/media_codec_bridge.h" | 22 #include "media/base/android/media_codec_bridge.h" |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 25 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 const char kClearKeyKeySystem[] = "org.w3.clearkey"; | 29 const char kClearKeyKeySystem[] = "org.w3.clearkey"; |
| 30 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 30 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
| 31 const char kUnsupportedClearKeyKeySystem[] = "unsupported-org.w3.clearkey"; | 31 const char kUnsupportedClearKeyKeySystem[] = "unsupported-org.w3.clearkey"; |
| 32 | 32 |
| 33 struct CodecMask { | 33 struct NamedInitDataType { |
| 34 const char* type; | 34 const char* name; |
| 35 EmeCodec mask; | 35 EmeInitDataType type; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // Mapping between container types and the masks of associated codecs. | 38 // Mapping between initialization data types names and enum values. Make sure to |
|
ddorwin
2014/09/27 00:41:24
nit: When adding entries, update...
sandersd (OOO until July 31)
2014/09/29 17:49:23
Done.
| |
| 39 // update IsSaneInitDataTypeWithContainer() if necessary. | |
| 40 static NamedInitDataType kInitDataTypeNames[] = { | |
| 41 {"webm", EME_INIT_DATA_TYPE_WEBM}, | |
| 42 #if defined(USE_PROPRIETARY_CODECS) | |
| 43 {"cenc", EME_INIT_DATA_TYPE_CENC} | |
| 44 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 45 }; | |
| 46 | |
| 47 struct NamedCodec { | |
| 48 const char* name; | |
| 49 EmeCodec type; | |
| 50 }; | |
| 51 | |
| 52 // Mapping between containers and their codecs. | |
| 39 // Only audio codec can belong to a "audio/*" container. Both audio and video | 53 // Only audio codec can belong to a "audio/*" container. Both audio and video |
| 40 // codecs can belong to a "video/*" container. | 54 // codecs can belong to a "video/*" container. |
| 41 CodecMask kContainerCodecMasks[] = { | 55 static NamedCodec kContainerToCodecMasks[] = { |
| 42 {"audio/webm", EME_CODEC_WEBM_AUDIO_ALL}, | 56 {"audio/webm", EME_CODEC_WEBM_AUDIO_ALL}, |
| 43 {"video/webm", EME_CODEC_WEBM_ALL}, | 57 {"video/webm", EME_CODEC_WEBM_ALL}, |
| 44 #if defined(USE_PROPRIETARY_CODECS) | 58 #if defined(USE_PROPRIETARY_CODECS) |
| 45 {"audio/mp4", EME_CODEC_MP4_AUDIO_ALL}, | 59 {"audio/mp4", EME_CODEC_MP4_AUDIO_ALL}, |
| 46 {"video/mp4", EME_CODEC_MP4_ALL} | 60 {"video/mp4", EME_CODEC_MP4_ALL} |
| 47 #endif // defined(USE_PROPRIETARY_CODECS) | 61 #endif // defined(USE_PROPRIETARY_CODECS) |
| 48 }; | 62 }; |
| 49 | 63 |
| 50 // Mapping between codec types and their masks. | 64 // Mapping between codec names and enum values. |
| 51 CodecMask kCodecMasks[] = { | 65 static NamedCodec kCodecStrings[] = { |
| 52 {"vorbis", EME_CODEC_WEBM_VORBIS}, | 66 {"vorbis", EME_CODEC_WEBM_VORBIS}, |
| 53 {"vp8", EME_CODEC_WEBM_VP8}, | 67 {"vp8", EME_CODEC_WEBM_VP8}, |
| 54 {"vp8.0", EME_CODEC_WEBM_VP8}, | 68 {"vp8.0", EME_CODEC_WEBM_VP8}, |
| 55 {"vp9", EME_CODEC_WEBM_VP9}, | 69 {"vp9", EME_CODEC_WEBM_VP9}, |
| 56 {"vp9.0", EME_CODEC_WEBM_VP9}, | 70 {"vp9.0", EME_CODEC_WEBM_VP9}, |
| 57 #if defined(USE_PROPRIETARY_CODECS) | 71 #if defined(USE_PROPRIETARY_CODECS) |
| 58 {"mp4a", EME_CODEC_MP4_AAC}, | 72 {"mp4a", EME_CODEC_MP4_AAC}, |
| 59 {"avc1", EME_CODEC_MP4_AVC1}, | 73 {"avc1", EME_CODEC_MP4_AVC1}, |
| 60 {"avc3", EME_CODEC_MP4_AVC1} | 74 {"avc3", EME_CODEC_MP4_AVC1} |
| 61 #endif // defined(USE_PROPRIETARY_CODECS) | 75 #endif // defined(USE_PROPRIETARY_CODECS) |
| 62 }; | 76 }; |
| 63 | 77 |
| 64 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { | 78 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { |
| 65 KeySystemInfo info(kClearKeyKeySystem); | 79 KeySystemInfo info(kClearKeyKeySystem); |
| 66 | 80 |
| 67 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: | 81 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: |
| 68 // http://developer.android.com/guide/appendix/media-formats.html | 82 // http://developer.android.com/guide/appendix/media-formats.html |
| 69 // VP9 support is device dependent. | 83 // VP9 support is device dependent. |
| 70 | 84 |
| 85 info.supported_init_data_types = EME_INIT_DATA_TYPE_WEBM; | |
| 71 info.supported_codecs = EME_CODEC_WEBM_ALL; | 86 info.supported_codecs = EME_CODEC_WEBM_ALL; |
| 72 | 87 |
| 73 #if defined(OS_ANDROID) | 88 #if defined(OS_ANDROID) |
| 74 // Temporarily disable VP9 support for Android. | 89 // Temporarily disable VP9 support for Android. |
| 75 // 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. |
| 76 info.supported_codecs &= ~EME_CODEC_WEBM_VP9; | 91 info.supported_codecs &= ~EME_CODEC_WEBM_VP9; |
| 77 #endif // defined(OS_ANDROID) | 92 #endif // defined(OS_ANDROID) |
| 78 | 93 |
| 79 #if defined(USE_PROPRIETARY_CODECS) | 94 #if defined(USE_PROPRIETARY_CODECS) |
| 95 info.supported_init_data_types |= EME_INIT_DATA_TYPE_CENC; | |
| 80 info.supported_codecs |= EME_CODEC_MP4_ALL; | 96 info.supported_codecs |= EME_CODEC_MP4_ALL; |
| 81 #endif // defined(USE_PROPRIETARY_CODECS) | 97 #endif // defined(USE_PROPRIETARY_CODECS) |
| 82 | 98 |
| 83 info.use_aes_decryptor = true; | 99 info.use_aes_decryptor = true; |
| 84 | 100 |
| 85 concrete_key_systems->push_back(info); | 101 concrete_key_systems->push_back(info); |
| 86 } | 102 } |
| 87 | 103 |
| 88 class KeySystems { | 104 class KeySystems { |
| 89 public: | 105 public: |
| 90 static KeySystems& GetInstance(); | 106 static KeySystems& GetInstance(); |
| 91 | 107 |
| 92 void UpdateIfNeeded(); | 108 void UpdateIfNeeded(); |
| 93 | 109 |
| 94 bool IsConcreteSupportedKeySystem(const std::string& key_system); | 110 bool IsConcreteSupportedKeySystem(const std::string& key_system); |
| 95 | 111 |
| 112 bool IsSupportedKeySystem(const std::string& key_system); | |
| 113 | |
| 114 bool IsSupportedKeySystemWithInitDataType( | |
| 115 const std::string& key_system, | |
| 116 const std::string& init_data_type); | |
| 117 | |
| 96 bool IsSupportedKeySystemWithMediaMimeType( | 118 bool IsSupportedKeySystemWithMediaMimeType( |
| 97 const std::string& mime_type, | 119 const std::string& mime_type, |
| 98 const std::vector<std::string>& codecs, | 120 const std::vector<std::string>& codecs, |
| 99 const std::string& key_system); | 121 const std::string& key_system); |
| 100 | 122 |
| 101 bool UseAesDecryptor(const std::string& concrete_key_system); | 123 bool UseAesDecryptor(const std::string& concrete_key_system); |
| 102 | 124 |
| 103 #if defined(ENABLE_PEPPER_CDMS) | 125 #if defined(ENABLE_PEPPER_CDMS) |
| 104 std::string GetPepperType(const std::string& concrete_key_system); | 126 std::string GetPepperType(const std::string& concrete_key_system); |
| 105 #endif | 127 #endif |
| 106 | 128 |
| 107 void AddContainerMask(const std::string& container, uint32 mask); | 129 void AddContainerMask(const std::string& container, uint32 mask); |
| 108 void AddCodecMask(const std::string& codec, uint32 mask); | 130 void AddCodecMask(const std::string& codec, uint32 mask); |
| 109 | 131 |
| 110 private: | 132 private: |
| 111 void UpdateSupportedKeySystems(); | 133 void UpdateSupportedKeySystems(); |
| 112 | 134 |
| 113 void AddConcreteSupportedKeySystems( | 135 void AddConcreteSupportedKeySystems( |
| 114 const std::vector<KeySystemInfo>& concrete_key_systems); | 136 const std::vector<KeySystemInfo>& concrete_key_systems); |
| 115 | 137 |
| 116 void AddConcreteSupportedKeySystem( | 138 void AddConcreteSupportedKeySystem( |
| 117 const std::string& key_system, | 139 const std::string& key_system, |
| 118 bool use_aes_decryptor, | 140 bool use_aes_decryptor, |
| 119 #if defined(ENABLE_PEPPER_CDMS) | 141 #if defined(ENABLE_PEPPER_CDMS) |
| 120 const std::string& pepper_type, | 142 const std::string& pepper_type, |
| 121 #endif | 143 #endif |
| 144 SupportedInitDataTypes supported_init_data_types, | |
| 122 SupportedCodecs supported_codecs, | 145 SupportedCodecs supported_codecs, |
| 123 const std::string& parent_key_system); | 146 const std::string& parent_key_system); |
| 124 | 147 |
| 125 friend struct base::DefaultLazyInstanceTraits<KeySystems>; | 148 friend struct base::DefaultLazyInstanceTraits<KeySystems>; |
| 126 | 149 |
| 127 struct KeySystemProperties { | 150 struct KeySystemProperties { |
| 128 KeySystemProperties() | 151 KeySystemProperties() |
| 129 : use_aes_decryptor(false), supported_codecs(EME_CODEC_NONE) {} | 152 : use_aes_decryptor(false), supported_codecs(EME_CODEC_NONE) {} |
| 130 | 153 |
| 131 bool use_aes_decryptor; | 154 bool use_aes_decryptor; |
| 132 #if defined(ENABLE_PEPPER_CDMS) | 155 #if defined(ENABLE_PEPPER_CDMS) |
| 133 std::string pepper_type; | 156 std::string pepper_type; |
| 134 #endif | 157 #endif |
| 158 SupportedInitDataTypes supported_init_data_types; | |
| 135 SupportedCodecs supported_codecs; | 159 SupportedCodecs supported_codecs; |
| 136 }; | 160 }; |
| 137 | 161 |
| 138 typedef base::hash_map<std::string, KeySystemProperties> | 162 typedef base::hash_map<std::string, KeySystemProperties> |
|
ddorwin
2014/09/27 00:41:25
If you don't like these, you can use auto and for_
sandersd (OOO until July 31)
2014/09/29 17:49:23
Acknowledged.
| |
| 139 KeySystemPropertiesMap; | 163 KeySystemPropertiesMap; |
| 140 typedef base::hash_map<std::string, std::string> ParentKeySystemMap; | 164 typedef base::hash_map<std::string, std::string> ParentKeySystemMap; |
| 141 typedef base::hash_map<std::string, EmeCodec> CodecMaskMap; | 165 typedef base::hash_map<std::string, SupportedCodecs> ContainerCodecsMap; |
| 166 typedef base::hash_map<std::string, EmeCodec> CodecsMap; | |
| 167 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap; | |
| 142 | 168 |
| 143 KeySystems(); | 169 KeySystems(); |
| 144 ~KeySystems() {} | 170 ~KeySystems() {} |
| 145 | 171 |
| 172 EmeInitDataType GetInitDataTypeForName( | |
| 173 const std::string& init_data_type) const; | |
| 174 // TODO(sandersd): Separate container enum from codec mask value. | |
| 175 // http://crbug.com/417440 | |
| 176 SupportedCodecs GetCodecMaskForContainer( | |
| 177 const std::string& container) const; | |
| 178 EmeCodec GetCodecForString(const std::string& codec) const; | |
| 179 | |
| 180 const std::string& GetConcreteKeySystemName( | |
| 181 const std::string& key_system) const; | |
| 182 | |
| 146 // Returns whether a |container| type is supported by checking | 183 // Returns whether a |container| type is supported by checking |
| 147 // |key_system_supported_codecs|. | 184 // |key_system_supported_codecs|. |
| 148 // TODO(xhwang): Update this to actually check initDataType support. | 185 // TODO(xhwang): Update this to actually check initDataType support. |
| 149 bool IsSupportedContainer(const std::string& container, | 186 bool IsSupportedContainer(const std::string& container, |
| 150 SupportedCodecs key_system_supported_codecs) const; | 187 SupportedCodecs key_system_supported_codecs) const; |
| 151 | 188 |
| 152 // Returns true if all |codecs| are supported in |container| by checking | 189 // Returns true if all |codecs| are supported in |container| by checking |
| 153 // |key_system_supported_codecs|. | 190 // |key_system_supported_codecs|. |
| 154 bool IsSupportedContainerAndCodecs( | 191 bool IsSupportedContainerAndCodecs( |
| 155 const std::string& container, | 192 const std::string& container, |
| 156 const std::vector<std::string>& codecs, | 193 const std::vector<std::string>& codecs, |
| 157 SupportedCodecs key_system_supported_codecs) const; | 194 SupportedCodecs key_system_supported_codecs) const; |
| 158 | 195 |
| 159 // Map from key system string to capabilities. | 196 // Map from key system string to capabilities. |
| 160 KeySystemPropertiesMap concrete_key_system_map_; | 197 KeySystemPropertiesMap concrete_key_system_map_; |
| 161 | 198 |
| 162 // Map from parent key system to the concrete key system that should be used | 199 // Map from parent key system to the concrete key system that should be used |
| 163 // to represent its capabilities. | 200 // to represent its capabilities. |
| 164 ParentKeySystemMap parent_key_system_map_; | 201 ParentKeySystemMap parent_key_system_map_; |
| 165 | 202 |
| 166 KeySystemsSupportUMA key_systems_support_uma_; | 203 KeySystemsSupportUMA key_systems_support_uma_; |
| 167 | 204 |
| 168 CodecMaskMap container_codec_masks_; | 205 InitDataTypesMap init_data_type_name_map_; |
| 169 CodecMaskMap codec_masks_; | 206 ContainerCodecsMap container_to_codec_mask_map_; |
| 207 CodecsMap codec_string_map_; | |
| 170 | 208 |
| 171 bool needs_update_; | 209 bool needs_update_; |
| 172 base::Time last_update_time_; | 210 base::Time last_update_time_; |
| 173 | 211 |
| 174 // Makes sure all methods are called from the same thread. | 212 // Makes sure all methods are called from the same thread. |
| 175 base::ThreadChecker thread_checker_; | 213 base::ThreadChecker thread_checker_; |
| 176 | 214 |
| 177 DISALLOW_COPY_AND_ASSIGN(KeySystems); | 215 DISALLOW_COPY_AND_ASSIGN(KeySystems); |
| 178 }; | 216 }; |
| 179 | 217 |
| 180 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER; | 218 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER; |
| 181 | 219 |
| 182 KeySystems& KeySystems::GetInstance() { | 220 KeySystems& KeySystems::GetInstance() { |
| 183 KeySystems& key_systems = g_key_systems.Get(); | 221 KeySystems& key_systems = g_key_systems.Get(); |
| 184 key_systems.UpdateIfNeeded(); | 222 key_systems.UpdateIfNeeded(); |
| 185 return key_systems; | 223 return key_systems; |
| 186 } | 224 } |
| 187 | 225 |
| 188 // Because we use a LazyInstance, the key systems info must be populated when | 226 // Because we use a LazyInstance, the key systems info must be populated when |
| 189 // the instance is lazily initiated. | 227 // the instance is lazily initiated. |
| 190 KeySystems::KeySystems() : needs_update_(true) { | 228 KeySystems::KeySystems() : needs_update_(true) { |
| 191 // Build container and codec masks for quick look up. | 229 for (size_t i = 0; i < arraysize(kInitDataTypeNames); ++i) { |
| 192 for (size_t i = 0; i < arraysize(kContainerCodecMasks); ++i) { | 230 const std::string& name = kInitDataTypeNames[i].name; |
| 193 const CodecMask& container_codec_mask = kContainerCodecMasks[i]; | 231 DCHECK(!init_data_type_name_map_.count(name)); |
| 194 DCHECK(container_codec_masks_.find(container_codec_mask.type) == | 232 init_data_type_name_map_[name] = kInitDataTypeNames[i].type; |
| 195 container_codec_masks_.end()); | |
| 196 container_codec_masks_[container_codec_mask.type] = | |
| 197 container_codec_mask.mask; | |
| 198 } | 233 } |
| 199 for (size_t i = 0; i < arraysize(kCodecMasks); ++i) { | 234 for (size_t i = 0; i < arraysize(kContainerToCodecMasks); ++i) { |
| 200 const CodecMask& codec_mask = kCodecMasks[i]; | 235 const std::string& name = kContainerToCodecMasks[i].name; |
| 201 DCHECK(codec_masks_.find(codec_mask.type) == codec_masks_.end()); | 236 DCHECK(!container_to_codec_mask_map_.count(name)); |
| 202 codec_masks_[codec_mask.type] = codec_mask.mask; | 237 container_to_codec_mask_map_[name] = kContainerToCodecMasks[i].type; |
| 238 } | |
| 239 for (size_t i = 0; i < arraysize(kCodecStrings); ++i) { | |
| 240 const std::string& name = kCodecStrings[i].name; | |
| 241 DCHECK(!codec_string_map_.count(name)); | |
| 242 codec_string_map_[name] = kCodecStrings[i].type; | |
| 203 } | 243 } |
| 204 | 244 |
| 205 UpdateSupportedKeySystems(); | 245 UpdateSupportedKeySystems(); |
| 206 | 246 |
| 207 #if defined(WIDEVINE_CDM_AVAILABLE) | 247 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 208 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem); | 248 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem); |
| 209 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 249 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 210 } | 250 } |
| 211 | 251 |
| 252 EmeInitDataType KeySystems::GetInitDataTypeForName( | |
| 253 const std::string& init_data_type) const { | |
| 254 InitDataTypesMap::const_iterator iter = | |
| 255 init_data_type_name_map_.find(init_data_type); | |
| 256 if (iter != init_data_type_name_map_.end()) | |
| 257 return iter->second; | |
| 258 return EME_INIT_DATA_TYPE_NONE; | |
| 259 } | |
| 260 | |
| 261 SupportedCodecs KeySystems::GetCodecMaskForContainer( | |
| 262 const std::string& container) const { | |
| 263 ContainerCodecsMap::const_iterator iter = | |
| 264 container_to_codec_mask_map_.find(container); | |
| 265 if (iter != container_to_codec_mask_map_.end()) | |
| 266 return iter->second; | |
| 267 return EME_CODEC_NONE; | |
| 268 } | |
| 269 | |
| 270 EmeCodec KeySystems::GetCodecForString(const std::string& codec) const { | |
| 271 CodecsMap::const_iterator iter = codec_string_map_.find(codec); | |
| 272 if (iter != codec_string_map_.end()) | |
| 273 return iter->second; | |
| 274 return EME_CODEC_NONE; | |
| 275 } | |
| 276 | |
| 277 const std::string& KeySystems::GetConcreteKeySystemName( | |
| 278 const std::string& key_system) const { | |
| 279 ParentKeySystemMap::const_iterator iter = | |
| 280 parent_key_system_map_.find(key_system); | |
| 281 if (iter != parent_key_system_map_.end()) | |
| 282 return iter->second; | |
| 283 return key_system; | |
| 284 } | |
| 285 | |
| 212 void KeySystems::UpdateIfNeeded() { | 286 void KeySystems::UpdateIfNeeded() { |
| 213 #if defined(WIDEVINE_CDM_AVAILABLE) | 287 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 214 DCHECK(thread_checker_.CalledOnValidThread()); | 288 DCHECK(thread_checker_.CalledOnValidThread()); |
| 215 if (!needs_update_) | 289 if (!needs_update_) |
| 216 return; | 290 return; |
| 217 | 291 |
| 218 // The update could involve a sync IPC to the browser process. Use a minimum | 292 // The update could involve a sync IPC to the browser process. Use a minimum |
| 219 // update interval to avoid unnecessary frequent IPC to the browser. | 293 // update interval to avoid unnecessary frequent IPC to the browser. |
| 220 static const int kMinUpdateIntervalInSeconds = 1; | 294 static const int kMinUpdateIntervalInSeconds = 1; |
| 221 base::Time now = base::Time::Now(); | 295 base::Time now = base::Time::Now(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 DCHECK(parent_key_system_map_.empty()); | 331 DCHECK(parent_key_system_map_.empty()); |
| 258 | 332 |
| 259 for (size_t i = 0; i < concrete_key_systems.size(); ++i) { | 333 for (size_t i = 0; i < concrete_key_systems.size(); ++i) { |
| 260 const KeySystemInfo& key_system_info = concrete_key_systems[i]; | 334 const KeySystemInfo& key_system_info = concrete_key_systems[i]; |
| 261 AddConcreteSupportedKeySystem(key_system_info.key_system, | 335 AddConcreteSupportedKeySystem(key_system_info.key_system, |
| 262 key_system_info.use_aes_decryptor, | 336 key_system_info.use_aes_decryptor, |
| 263 #if defined(ENABLE_PEPPER_CDMS) | 337 #if defined(ENABLE_PEPPER_CDMS) |
| 264 key_system_info.pepper_type, | 338 key_system_info.pepper_type, |
| 265 #endif | 339 #endif |
| 266 key_system_info.supported_codecs, | 340 key_system_info.supported_codecs, |
| 341 key_system_info.supported_init_data_types, | |
|
ddorwin
2014/09/27 00:41:24
Move up. Yikes - the danger of using masks!
sandersd (OOO until July 31)
2014/09/29 17:49:23
Done.
| |
| 267 key_system_info.parent_key_system); | 342 key_system_info.parent_key_system); |
| 268 } | 343 } |
| 269 } | 344 } |
| 270 | 345 |
| 271 void KeySystems::AddConcreteSupportedKeySystem( | 346 void KeySystems::AddConcreteSupportedKeySystem( |
| 272 const std::string& concrete_key_system, | 347 const std::string& concrete_key_system, |
| 273 bool use_aes_decryptor, | 348 bool use_aes_decryptor, |
| 274 #if defined(ENABLE_PEPPER_CDMS) | 349 #if defined(ENABLE_PEPPER_CDMS) |
| 275 const std::string& pepper_type, | 350 const std::string& pepper_type, |
| 276 #endif | 351 #endif |
| 352 SupportedInitDataTypes supported_init_data_types, | |
| 277 SupportedCodecs supported_codecs, | 353 SupportedCodecs supported_codecs, |
| 278 const std::string& parent_key_system) { | 354 const std::string& parent_key_system) { |
| 279 DCHECK(thread_checker_.CalledOnValidThread()); | 355 DCHECK(thread_checker_.CalledOnValidThread()); |
| 280 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system)) | 356 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system)) |
| 281 << "Key system '" << concrete_key_system << "' already registered"; | 357 << "Key system '" << concrete_key_system << "' already registered"; |
| 282 DCHECK(parent_key_system_map_.find(concrete_key_system) == | 358 DCHECK(!parent_key_system_map_.count(concrete_key_system)) |
| 283 parent_key_system_map_.end()) | |
| 284 << "'" << concrete_key_system << " is already registered as a parent"; | 359 << "'" << concrete_key_system << " is already registered as a parent"; |
| 285 | 360 |
| 286 KeySystemProperties properties; | 361 KeySystemProperties properties; |
| 287 properties.use_aes_decryptor = use_aes_decryptor; | 362 properties.use_aes_decryptor = use_aes_decryptor; |
| 288 #if defined(ENABLE_PEPPER_CDMS) | 363 #if defined(ENABLE_PEPPER_CDMS) |
| 289 DCHECK_EQ(use_aes_decryptor, pepper_type.empty()); | 364 DCHECK_EQ(use_aes_decryptor, pepper_type.empty()); |
| 290 properties.pepper_type = pepper_type; | 365 properties.pepper_type = pepper_type; |
| 291 #endif | 366 #endif |
| 292 | 367 |
| 368 properties.supported_init_data_types = supported_init_data_types; | |
| 293 properties.supported_codecs = supported_codecs; | 369 properties.supported_codecs = supported_codecs; |
| 294 | 370 |
| 295 concrete_key_system_map_[concrete_key_system] = properties; | 371 concrete_key_system_map_[concrete_key_system] = properties; |
| 296 | 372 |
| 297 if (!parent_key_system.empty()) { | 373 if (!parent_key_system.empty()) { |
| 298 DCHECK(!IsConcreteSupportedKeySystem(parent_key_system)) | 374 DCHECK(!IsConcreteSupportedKeySystem(parent_key_system)) |
| 299 << "Parent '" << parent_key_system << "' already registered concrete"; | 375 << "Parent '" << parent_key_system << "' already registered concrete"; |
| 300 DCHECK(parent_key_system_map_.find(parent_key_system) == | 376 DCHECK(!parent_key_system_map_.count(parent_key_system)) |
| 301 parent_key_system_map_.end()) | |
| 302 << "Parent '" << parent_key_system << "' already registered"; | 377 << "Parent '" << parent_key_system << "' already registered"; |
| 303 parent_key_system_map_[parent_key_system] = concrete_key_system; | 378 parent_key_system_map_[parent_key_system] = concrete_key_system; |
| 304 } | 379 } |
| 305 } | 380 } |
| 306 | 381 |
| 307 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) { | 382 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) { |
| 308 DCHECK(thread_checker_.CalledOnValidThread()); | 383 DCHECK(thread_checker_.CalledOnValidThread()); |
| 309 return concrete_key_system_map_.find(key_system) != | 384 return concrete_key_system_map_.count(key_system); |
| 310 concrete_key_system_map_.end(); | |
| 311 } | 385 } |
| 312 | 386 |
| 313 bool KeySystems::IsSupportedContainer( | 387 bool KeySystems::IsSupportedContainer( |
| 314 const std::string& container, | 388 const std::string& container, |
| 315 SupportedCodecs key_system_supported_codecs) const { | 389 SupportedCodecs key_system_supported_codecs) const { |
| 316 DCHECK(thread_checker_.CalledOnValidThread()); | 390 DCHECK(thread_checker_.CalledOnValidThread()); |
| 317 DCHECK(!container.empty()); | 391 DCHECK(!container.empty()); |
| 318 | 392 |
| 319 // When checking container support for EME, "audio/foo" should be treated the | 393 // When checking container support for EME, "audio/foo" should be treated the |
| 320 // same as "video/foo". Convert the |container| to achieve this. | 394 // same as "video/foo". Convert the |container| to achieve this. |
| 321 // TODO(xhwang): Replace this with real checks against supported initDataTypes | 395 // TODO(xhwang): Replace this with real checks against supported initDataTypes |
| 322 // combined with supported demuxers. | 396 // combined with supported demuxers. |
| 323 std::string canonical_container = container; | 397 std::string canonical_container = container; |
| 324 if (container.find("audio/") == 0) | 398 if (container.find("audio/") == 0) |
| 325 canonical_container.replace(0, 6, "video/"); | 399 canonical_container.replace(0, 6, "video/"); |
| 326 | 400 |
| 327 CodecMaskMap::const_iterator container_iter = | |
| 328 container_codec_masks_.find(canonical_container); | |
| 329 // Unrecognized container. | |
| 330 if (container_iter == container_codec_masks_.end()) | |
| 331 return false; | |
| 332 | |
| 333 EmeCodec container_codec_mask = container_iter->second; | |
| 334 // A container is supported iif at least one codec in that container is | 401 // A container is supported iif at least one codec in that container is |
| 335 // supported. | 402 // supported. |
| 336 return (container_codec_mask & key_system_supported_codecs) != 0; | 403 SupportedCodecs supported_codecs = |
| 404 GetCodecMaskForContainer(canonical_container); | |
| 405 return (supported_codecs & key_system_supported_codecs) != 0; | |
| 337 } | 406 } |
| 338 | 407 |
| 339 bool KeySystems::IsSupportedContainerAndCodecs( | 408 bool KeySystems::IsSupportedContainerAndCodecs( |
| 340 const std::string& container, | 409 const std::string& container, |
| 341 const std::vector<std::string>& codecs, | 410 const std::vector<std::string>& codecs, |
| 342 SupportedCodecs key_system_supported_codecs) const { | 411 SupportedCodecs key_system_supported_codecs) const { |
| 343 DCHECK(thread_checker_.CalledOnValidThread()); | 412 DCHECK(thread_checker_.CalledOnValidThread()); |
| 344 DCHECK(!container.empty()); | 413 DCHECK(!container.empty()); |
| 345 DCHECK(!codecs.empty()); | 414 DCHECK(!codecs.empty()); |
| 346 DCHECK(IsSupportedContainer(container, key_system_supported_codecs)); | 415 DCHECK(IsSupportedContainer(container, key_system_supported_codecs)); |
| 347 | 416 |
| 348 CodecMaskMap::const_iterator container_iter = | 417 SupportedCodecs container_supported_codecs = |
| 349 container_codec_masks_.find(container); | 418 GetCodecMaskForContainer(container); |
| 350 EmeCodec container_codec_mask = container_iter->second; | |
| 351 | 419 |
| 352 for (size_t i = 0; i < codecs.size(); ++i) { | 420 for (size_t i = 0; i < codecs.size(); ++i) { |
| 353 const std::string& codec = codecs[i]; | 421 // TODO(sandersd): This should fail for isTypeSupported(). |
| 354 if (codec.empty()) | 422 // http://crbug.com/417461 |
| 423 if (codecs[i].empty()) | |
| 355 continue; | 424 continue; |
| 356 CodecMaskMap::const_iterator codec_iter = codec_masks_.find(codec); | |
| 357 if (codec_iter == codec_masks_.end()) // Unrecognized codec. | |
| 358 return false; | |
| 359 | 425 |
| 360 EmeCodec codec_mask = codec_iter->second; | 426 EmeCodec codec = GetCodecForString(codecs[i]); |
| 361 if (!(codec_mask & key_system_supported_codecs)) // Unsupported codec. | 427 |
| 428 // Unsupported codec. | |
| 429 if (!(codec & key_system_supported_codecs)) | |
| 362 return false; | 430 return false; |
| 363 | 431 |
| 364 // Unsupported codec/container combination, e.g. "video/webm" and "avc1". | 432 // Unsupported codec/container combination, e.g. "video/webm" and "avc1". |
| 365 if (!(codec_mask & container_codec_mask)) | 433 if (!(codec & container_supported_codecs)) |
| 366 return false; | 434 return false; |
| 367 } | 435 } |
| 368 | 436 |
| 369 return true; | 437 return true; |
| 370 } | 438 } |
| 371 | 439 |
| 440 // Note: Shouldn't be used for prefixed API as that old path reports UMAs. | |
| 441 bool KeySystems::IsSupportedKeySystem(const std::string& key_system) { | |
| 442 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 443 return (concrete_key_system_map_.count(key_system) || | |
| 444 parent_key_system_map_.count(key_system)); | |
| 445 } | |
| 446 | |
| 447 bool KeySystems::IsSupportedKeySystemWithInitDataType( | |
| 448 const std::string& key_system, | |
| 449 const std::string& init_data_type) { | |
| 450 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 451 | |
| 452 // If |key_system| is a parent key system, use its concrete child. | |
| 453 const std::string& concrete_key_system = GetConcreteKeySystemName(key_system); | |
| 454 | |
| 455 // Locate |concrete_key_system|. | |
| 456 KeySystemPropertiesMap::const_iterator key_system_iter = | |
| 457 concrete_key_system_map_.find(concrete_key_system); | |
| 458 if (key_system_iter == concrete_key_system_map_.end()) | |
| 459 return false; | |
| 460 | |
| 461 // Check |init_data_type| and |key_system| x |init_data_type|. | |
| 462 const KeySystemProperties& properties = key_system_iter->second; | |
| 463 EmeInitDataType eme_init_data_type = GetInitDataTypeForName(init_data_type); | |
| 464 return properties.supported_init_data_types & eme_init_data_type; | |
| 465 } | |
| 466 | |
| 467 // TODO(sandersd): Reforganize to be more similar to | |
|
ddorwin
2014/09/27 00:41:25
Reorganize
sandersd (OOO until July 31)
2014/09/29 17:49:23
Done.
| |
| 468 // IsKeySystemSupportedWithInitDataType(). Note that a fork may still be | |
| 469 // required; http://crbug.com/417461. | |
| 372 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( | 470 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( |
| 373 const std::string& mime_type, | 471 const std::string& mime_type, |
| 374 const std::vector<std::string>& codecs, | 472 const std::vector<std::string>& codecs, |
| 375 const std::string& key_system) { | 473 const std::string& key_system) { |
| 376 DCHECK(thread_checker_.CalledOnValidThread()); | 474 DCHECK(thread_checker_.CalledOnValidThread()); |
| 377 | 475 |
| 378 // If |key_system| is a parent key_system, use its concrete child. | 476 // If |key_system| is a parent key system, use its concrete child. |
| 379 // Otherwise, use |key_system|. | 477 const std::string& concrete_key_system = GetConcreteKeySystemName(key_system); |
| 380 std::string concrete_key_system; | |
| 381 ParentKeySystemMap::iterator parent_key_system_iter = | |
| 382 parent_key_system_map_.find(key_system); | |
| 383 if (parent_key_system_iter != parent_key_system_map_.end()) | |
| 384 concrete_key_system = parent_key_system_iter->second; | |
| 385 else | |
| 386 concrete_key_system = key_system; | |
| 387 | 478 |
| 388 bool has_type = !mime_type.empty(); | 479 bool has_type = !mime_type.empty(); |
| 389 | 480 |
| 390 key_systems_support_uma_.ReportKeySystemQuery(key_system, has_type); | 481 key_systems_support_uma_.ReportKeySystemQuery(key_system, has_type); |
| 391 | 482 |
| 392 // Check key system support. | 483 // Check key system support. |
| 393 KeySystemPropertiesMap::const_iterator key_system_iter = | 484 KeySystemPropertiesMap::const_iterator key_system_iter = |
| 394 concrete_key_system_map_.find(concrete_key_system); | 485 concrete_key_system_map_.find(concrete_key_system); |
| 395 if (key_system_iter == concrete_key_system_map_.end()) | 486 if (key_system_iter == concrete_key_system_map_.end()) |
| 396 return false; | 487 return false; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 414 return false; | 505 return false; |
| 415 } | 506 } |
| 416 | 507 |
| 417 key_systems_support_uma_.ReportKeySystemSupport(key_system, true); | 508 key_systems_support_uma_.ReportKeySystemSupport(key_system, true); |
| 418 return true; | 509 return true; |
| 419 } | 510 } |
| 420 | 511 |
| 421 bool KeySystems::UseAesDecryptor(const std::string& concrete_key_system) { | 512 bool KeySystems::UseAesDecryptor(const std::string& concrete_key_system) { |
| 422 DCHECK(thread_checker_.CalledOnValidThread()); | 513 DCHECK(thread_checker_.CalledOnValidThread()); |
| 423 | 514 |
| 424 KeySystemPropertiesMap::iterator key_system_iter = | 515 KeySystemPropertiesMap::const_iterator key_system_iter = |
| 425 concrete_key_system_map_.find(concrete_key_system); | 516 concrete_key_system_map_.find(concrete_key_system); |
| 426 if (key_system_iter == concrete_key_system_map_.end()) { | 517 if (key_system_iter == concrete_key_system_map_.end()) { |
| 427 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; | 518 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; |
| 428 return false; | 519 return false; |
| 429 } | 520 } |
| 430 | 521 |
| 431 return key_system_iter->second.use_aes_decryptor; | 522 return key_system_iter->second.use_aes_decryptor; |
| 432 } | 523 } |
| 433 | 524 |
| 434 #if defined(ENABLE_PEPPER_CDMS) | 525 #if defined(ENABLE_PEPPER_CDMS) |
| 435 std::string KeySystems::GetPepperType(const std::string& concrete_key_system) { | 526 std::string KeySystems::GetPepperType(const std::string& concrete_key_system) { |
| 436 DCHECK(thread_checker_.CalledOnValidThread()); | 527 DCHECK(thread_checker_.CalledOnValidThread()); |
| 437 | 528 |
| 438 KeySystemPropertiesMap::iterator key_system_iter = | 529 KeySystemPropertiesMap::const_iterator key_system_iter = |
| 439 concrete_key_system_map_.find(concrete_key_system); | 530 concrete_key_system_map_.find(concrete_key_system); |
| 440 if (key_system_iter == concrete_key_system_map_.end()) { | 531 if (key_system_iter == concrete_key_system_map_.end()) { |
| 441 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; | 532 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; |
| 442 return std::string(); | 533 return std::string(); |
| 443 } | 534 } |
| 444 | 535 |
| 445 const std::string& type = key_system_iter->second.pepper_type; | 536 const std::string& type = key_system_iter->second.pepper_type; |
| 446 DLOG_IF(FATAL, type.empty()) << concrete_key_system << " is not Pepper-based"; | 537 DLOG_IF(FATAL, type.empty()) << concrete_key_system << " is not Pepper-based"; |
| 447 return type; | 538 return type; |
| 448 } | 539 } |
| 449 #endif | 540 #endif |
| 450 | 541 |
| 451 void KeySystems::AddContainerMask(const std::string& container, uint32 mask) { | 542 void KeySystems::AddContainerMask(const std::string& container, uint32 mask) { |
| 452 DCHECK(thread_checker_.CalledOnValidThread()); | 543 DCHECK(thread_checker_.CalledOnValidThread()); |
| 453 DCHECK(container_codec_masks_.find(container) == | 544 DCHECK(!container_to_codec_mask_map_.count(container)); |
| 454 container_codec_masks_.end()); | 545 container_to_codec_mask_map_[container] = static_cast<EmeCodec>(mask); |
| 455 | |
| 456 container_codec_masks_[container] = static_cast<EmeCodec>(mask); | |
| 457 } | 546 } |
| 458 | 547 |
| 459 void KeySystems::AddCodecMask(const std::string& codec, uint32 mask) { | 548 void KeySystems::AddCodecMask(const std::string& codec, uint32 mask) { |
| 460 DCHECK(thread_checker_.CalledOnValidThread()); | 549 DCHECK(thread_checker_.CalledOnValidThread()); |
| 461 DCHECK(codec_masks_.find(codec) == codec_masks_.end()); | 550 DCHECK(!codec_string_map_.count(codec)); |
| 462 | 551 codec_string_map_[codec] = static_cast<EmeCodec>(mask); |
| 463 codec_masks_[codec] = static_cast<EmeCodec>(mask); | |
| 464 } | 552 } |
| 465 | 553 |
| 466 //------------------------------------------------------------------------------ | 554 //------------------------------------------------------------------------------ |
| 467 | 555 |
| 468 std::string GetUnprefixedKeySystemName(const std::string& key_system) { | 556 std::string GetUnprefixedKeySystemName(const std::string& key_system) { |
| 469 if (key_system == kClearKeyKeySystem) | 557 if (key_system == kClearKeyKeySystem) |
| 470 return kUnsupportedClearKeyKeySystem; | 558 return kUnsupportedClearKeyKeySystem; |
| 471 | 559 |
| 472 if (key_system == kPrefixedClearKeyKeySystem) | 560 if (key_system == kPrefixedClearKeyKeySystem) |
| 473 return kClearKeyKeySystem; | 561 return kClearKeyKeySystem; |
| 474 | 562 |
| 475 return key_system; | 563 return key_system; |
| 476 } | 564 } |
| 477 | 565 |
| 478 std::string GetPrefixedKeySystemName(const std::string& key_system) { | 566 std::string GetPrefixedKeySystemName(const std::string& key_system) { |
| 479 DCHECK_NE(key_system, kPrefixedClearKeyKeySystem); | 567 DCHECK_NE(key_system, kPrefixedClearKeyKeySystem); |
| 480 | 568 |
| 481 if (key_system == kClearKeyKeySystem) | 569 if (key_system == kClearKeyKeySystem) |
| 482 return kPrefixedClearKeyKeySystem; | 570 return kPrefixedClearKeyKeySystem; |
| 483 | 571 |
| 484 return key_system; | 572 return key_system; |
| 485 } | 573 } |
| 486 | 574 |
| 575 bool IsSaneInitDataTypeWithContainer( | |
| 576 const std::string& init_data_type, | |
| 577 const std::string& container) { | |
| 578 if (init_data_type == "cenc") { | |
| 579 return container == "audio/mp4" || container == "video/mp4"; | |
| 580 } else if (init_data_type == "webm") { | |
| 581 return container == "audio/webm" || container == "video/webm"; | |
| 582 } else { | |
| 583 NOTREACHED(); | |
|
ddorwin
2014/09/27 00:41:25
It's not clear whether we check for invalid IDTs e
sandersd (OOO until July 31)
2014/09/29 17:49:23
Done.
| |
| 584 return false; | |
| 585 } | |
| 586 } | |
| 587 | |
| 487 bool IsConcreteSupportedKeySystem(const std::string& key_system) { | 588 bool IsConcreteSupportedKeySystem(const std::string& key_system) { |
| 488 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system); | 589 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system); |
| 489 } | 590 } |
| 490 | 591 |
| 592 bool IsSupportedKeySystem(const std::string& key_system) { | |
|
ddorwin
2014/09/27 00:41:24
Hmm. Might be better in the header file since that
sandersd (OOO until July 31)
2014/09/29 17:49:23
Done.
| |
| 593 return KeySystems::GetInstance().IsSupportedKeySystem(key_system); | |
| 594 } | |
| 595 | |
| 596 bool IsSupportedKeySystemWithInitDataType( | |
| 597 const std::string& key_system, | |
| 598 const std::string& init_data_type) { | |
| 599 return KeySystems::GetInstance().IsSupportedKeySystemWithInitDataType( | |
| 600 key_system, init_data_type); | |
| 601 } | |
| 602 | |
| 491 bool IsSupportedKeySystemWithMediaMimeType( | 603 bool IsSupportedKeySystemWithMediaMimeType( |
| 492 const std::string& mime_type, | 604 const std::string& mime_type, |
| 493 const std::vector<std::string>& codecs, | 605 const std::vector<std::string>& codecs, |
| 494 const std::string& key_system) { | 606 const std::string& key_system) { |
| 495 return KeySystems::GetInstance().IsSupportedKeySystemWithMediaMimeType( | 607 return KeySystems::GetInstance().IsSupportedKeySystemWithMediaMimeType( |
| 496 mime_type, codecs, key_system); | 608 mime_type, codecs, key_system); |
| 497 } | 609 } |
| 498 | 610 |
| 499 std::string KeySystemNameForUMA(const std::string& key_system) { | 611 std::string KeySystemNameForUMA(const std::string& key_system) { |
| 500 if (key_system == kClearKeyKeySystem) | 612 if (key_system == kClearKeyKeySystem) |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 525 CONTENT_EXPORT void AddContainerMask(const std::string& container, | 637 CONTENT_EXPORT void AddContainerMask(const std::string& container, |
| 526 uint32 mask) { | 638 uint32 mask) { |
| 527 KeySystems::GetInstance().AddContainerMask(container, mask); | 639 KeySystems::GetInstance().AddContainerMask(container, mask); |
| 528 } | 640 } |
| 529 | 641 |
| 530 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { | 642 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { |
| 531 KeySystems::GetInstance().AddCodecMask(codec, mask); | 643 KeySystems::GetInstance().AddCodecMask(codec, mask); |
| 532 } | 644 } |
| 533 | 645 |
| 534 } // namespace content | 646 } // namespace content |
| OLD | NEW |