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 <map> | |
8 #include <string> | 7 #include <string> |
9 | 8 |
| 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 "content/public/common/content_client.h" | 13 #include "content/public/common/content_client.h" |
| 14 #include "content/public/common/eme_codec.h" |
14 #include "content/public/renderer/content_renderer_client.h" | 15 #include "content/public/renderer/content_renderer_client.h" |
15 #include "content/public/renderer/key_system_info.h" | 16 #include "content/public/renderer/key_system_info.h" |
16 #include "content/renderer/media/crypto/key_systems_support_uma.h" | 17 #include "content/renderer/media/crypto/key_systems_support_uma.h" |
17 | 18 |
18 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
19 #include "media/base/android/media_codec_bridge.h" | 20 #include "media/base/android/media_codec_bridge.h" |
20 #endif | 21 #endif |
21 | 22 |
22 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 23 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
26 const char kClearKeyKeySystem[] = "org.w3.clearkey"; | 27 const char kClearKeyKeySystem[] = "org.w3.clearkey"; |
27 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 28 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
28 const char kUnsupportedClearKeyKeySystem[] = "unsupported-org.w3.clearkey"; | 29 const char kUnsupportedClearKeyKeySystem[] = "unsupported-org.w3.clearkey"; |
29 | 30 |
30 const char kAudioWebM[] = "audio/webm"; | 31 struct CodecMask { |
31 const char kVideoWebM[] = "video/webm"; | 32 const char* type; |
32 const char kVorbis[] = "vorbis"; | 33 EmeCodec mask; |
33 const char kVP8[] = "vp8"; | 34 }; |
34 const char kVP80[] = "vp8.0"; | |
35 | 35 |
| 36 // Mapping between container types and the masks of associated codecs. |
| 37 // Only audio codec can belong to a "audio/*" container. Both audio and video |
| 38 // codecs can belong to a "video/*" container. |
| 39 CodecMask kContainerCodecMasks[] = { |
| 40 {"audio/webm", EME_CODEC_WEBM_AUDIO_ALL}, |
| 41 {"video/webm", EME_CODEC_WEBM_ALL}, |
36 #if defined(USE_PROPRIETARY_CODECS) | 42 #if defined(USE_PROPRIETARY_CODECS) |
37 const char kAudioMp4[] = "audio/mp4"; | 43 {"audio/mp4", EME_CODEC_MP4_AUDIO_ALL}, |
38 const char kVideoMp4[] = "video/mp4"; | 44 {"video/mp4", EME_CODEC_MP4_ALL} |
39 const char kMp4a[] = "mp4a"; | |
40 const char kAvc1[] = "avc1"; | |
41 const char kAvc3[] = "avc3"; | |
42 #endif // defined(USE_PROPRIETARY_CODECS) | 45 #endif // defined(USE_PROPRIETARY_CODECS) |
| 46 }; |
| 47 |
| 48 // Mapping between codec types and their masks. |
| 49 CodecMask kCodecMasks[] = { |
| 50 {"vorbis", EME_CODEC_WEBM_VORBIS}, |
| 51 {"vp8", EME_CODEC_WEBM_VP8}, |
| 52 {"vp8.0", EME_CODEC_WEBM_VP8}, |
| 53 #if defined(USE_PROPRIETARY_CODECS) |
| 54 {"mp4a", EME_CODEC_MP4_AAC}, |
| 55 {"avc1", EME_CODEC_MP4_AVC1}, |
| 56 {"avc3", EME_CODEC_MP4_AVC1} |
| 57 #endif // defined(USE_PROPRIETARY_CODECS) |
| 58 }; |
43 | 59 |
44 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { | 60 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { |
45 KeySystemInfo info(kClearKeyKeySystem); | 61 KeySystemInfo info(kClearKeyKeySystem); |
46 | 62 |
47 // On Android, Vorbis, VP8, AAC and AVC1 are supported in all MediaCodec | 63 // On Android, Vorbis, VP8, AAC and AVC1 are supported in all MediaCodec |
48 // implementations: | 64 // implementations: |
49 // http://developer.android.com/guide/appendix/media-formats.html | 65 // http://developer.android.com/guide/appendix/media-formats.html |
50 | 66 |
51 info.supported_types[kAudioWebM].insert(kVorbis); | 67 info.supported_codecs = EME_CODEC_WEBM_ALL; |
52 info.supported_types[kVideoWebM] = info.supported_types[kAudioWebM]; | |
53 info.supported_types[kVideoWebM].insert(kVP8); | |
54 info.supported_types[kVideoWebM].insert(kVP80); | |
55 #if defined(USE_PROPRIETARY_CODECS) | 68 #if defined(USE_PROPRIETARY_CODECS) |
56 info.supported_types[kAudioMp4].insert(kMp4a); | 69 info.supported_codecs |= EME_CODEC_MP4_ALL; |
57 info.supported_types[kVideoMp4] = info.supported_types[kAudioMp4]; | |
58 info.supported_types[kVideoMp4].insert(kAvc1); | |
59 info.supported_types[kVideoMp4].insert(kAvc3); | |
60 #endif // defined(USE_PROPRIETARY_CODECS) | 70 #endif // defined(USE_PROPRIETARY_CODECS) |
61 | 71 |
62 info.use_aes_decryptor = true; | 72 info.use_aes_decryptor = true; |
63 | 73 |
64 concrete_key_systems->push_back(info); | 74 concrete_key_systems->push_back(info); |
65 } | 75 } |
66 | 76 |
67 class KeySystems { | 77 class KeySystems { |
68 public: | 78 public: |
69 static KeySystems& GetInstance(); | 79 static KeySystems& GetInstance(); |
70 | 80 |
71 bool IsConcreteSupportedKeySystem(const std::string& key_system); | 81 bool IsConcreteSupportedKeySystem(const std::string& key_system); |
72 | 82 |
73 bool IsSupportedKeySystemWithMediaMimeType( | 83 bool IsSupportedKeySystemWithMediaMimeType( |
74 const std::string& mime_type, | 84 const std::string& mime_type, |
75 const std::vector<std::string>& codecs, | 85 const std::vector<std::string>& codecs, |
76 const std::string& key_system); | 86 const std::string& key_system); |
77 | 87 |
78 bool UseAesDecryptor(const std::string& concrete_key_system); | 88 bool UseAesDecryptor(const std::string& concrete_key_system); |
79 | 89 |
80 #if defined(ENABLE_PEPPER_CDMS) | 90 #if defined(ENABLE_PEPPER_CDMS) |
81 std::string GetPepperType(const std::string& concrete_key_system); | 91 std::string GetPepperType(const std::string& concrete_key_system); |
82 #endif | 92 #endif |
83 | 93 |
| 94 void AddContainerMask(const std::string& container, uint32 mask); |
| 95 void AddCodecMask(const std::string& codec, uint32 mask); |
| 96 |
84 private: | 97 private: |
85 typedef KeySystemInfo::CodecSet CodecSet; | |
86 typedef KeySystemInfo::ContainerCodecsMap ContainerCodecsMap; | |
87 | |
88 void AddConcreteSupportedKeySystems( | 98 void AddConcreteSupportedKeySystems( |
89 const std::vector<KeySystemInfo>& concrete_key_systems); | 99 const std::vector<KeySystemInfo>& concrete_key_systems); |
90 | 100 |
91 void AddConcreteSupportedKeySystem( | 101 void AddConcreteSupportedKeySystem( |
92 const std::string& key_system, | 102 const std::string& key_system, |
93 bool use_aes_decryptor, | 103 bool use_aes_decryptor, |
94 #if defined(ENABLE_PEPPER_CDMS) | 104 #if defined(ENABLE_PEPPER_CDMS) |
95 const std::string& pepper_type, | 105 const std::string& pepper_type, |
96 #endif | 106 #endif |
97 const ContainerCodecsMap& supported_types, | 107 SupportedCodecs supported_codecs, |
98 const std::string& parent_key_system); | 108 const std::string& parent_key_system); |
99 | 109 |
100 friend struct base::DefaultLazyInstanceTraits<KeySystems>; | 110 friend struct base::DefaultLazyInstanceTraits<KeySystems>; |
101 | 111 |
102 struct KeySystemProperties { | 112 struct KeySystemProperties { |
103 KeySystemProperties() : use_aes_decryptor(false) {} | 113 KeySystemProperties() : use_aes_decryptor(false) {} |
104 | 114 |
105 bool use_aes_decryptor; | 115 bool use_aes_decryptor; |
106 #if defined(ENABLE_PEPPER_CDMS) | 116 #if defined(ENABLE_PEPPER_CDMS) |
107 std::string pepper_type; | 117 std::string pepper_type; |
108 #endif | 118 #endif |
109 ContainerCodecsMap supported_types; | 119 SupportedCodecs supported_codecs; |
110 }; | 120 }; |
111 | 121 |
112 typedef std::map<std::string, KeySystemProperties> KeySystemPropertiesMap; | 122 typedef base::hash_map<std::string, KeySystemProperties> |
113 | 123 KeySystemPropertiesMap; |
114 typedef std::map<std::string, std::string> ParentKeySystemMap; | 124 typedef base::hash_map<std::string, std::string> ParentKeySystemMap; |
| 125 typedef base::hash_map<std::string, EmeCodec> CodecMaskMap; |
115 | 126 |
116 KeySystems(); | 127 KeySystems(); |
117 ~KeySystems() {} | 128 ~KeySystems() {} |
118 | 129 |
119 bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type, | 130 // Returns whether a |container| type is supported by checking |
120 const std::string& codec, | 131 // |key_system_supported_codecs|. |
121 const std::string& key_system); | 132 // TODO(xhwang): Update this to actually check initDataType support. |
| 133 bool IsSupportedContainer(const std::string& container, |
| 134 SupportedCodecs key_system_supported_codecs) const; |
| 135 |
| 136 // Returns true if all |codecs| are supported in |container| by checking |
| 137 // |key_system_supported_codecs|. |
| 138 bool IsSupportedContainerAndCodecs( |
| 139 const std::string& container, |
| 140 const std::vector<std::string>& codecs, |
| 141 SupportedCodecs key_system_supported_codecs) const; |
122 | 142 |
123 // Map from key system string to capabilities. | 143 // Map from key system string to capabilities. |
124 KeySystemPropertiesMap concrete_key_system_map_; | 144 KeySystemPropertiesMap concrete_key_system_map_; |
125 | 145 |
126 // Map from parent key system to the concrete key system that should be used | 146 // Map from parent key system to the concrete key system that should be used |
127 // to represent its capabilities. | 147 // to represent its capabilities. |
128 ParentKeySystemMap parent_key_system_map_; | 148 ParentKeySystemMap parent_key_system_map_; |
129 | 149 |
130 KeySystemsSupportUMA key_systems_support_uma_; | 150 KeySystemsSupportUMA key_systems_support_uma_; |
131 | 151 |
| 152 CodecMaskMap container_codec_masks_; |
| 153 CodecMaskMap codec_masks_; |
| 154 |
132 DISALLOW_COPY_AND_ASSIGN(KeySystems); | 155 DISALLOW_COPY_AND_ASSIGN(KeySystems); |
133 }; | 156 }; |
134 | 157 |
135 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER; | 158 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER; |
136 | 159 |
137 KeySystems& KeySystems::GetInstance() { | 160 KeySystems& KeySystems::GetInstance() { |
138 return g_key_systems.Get(); | 161 return g_key_systems.Get(); |
139 } | 162 } |
140 | 163 |
141 // Because we use a LazyInstance, the key systems info must be populated when | 164 // Because we use a LazyInstance, the key systems info must be populated when |
142 // the instance is lazily initiated. | 165 // the instance is lazily initiated. |
143 KeySystems::KeySystems() { | 166 KeySystems::KeySystems() { |
| 167 // Build container and codec masks for quick look up. |
| 168 for (size_t i = 0; i < arraysize(kContainerCodecMasks); ++i) { |
| 169 const CodecMask& container_codec_mask = kContainerCodecMasks[i]; |
| 170 DCHECK(container_codec_masks_.find(container_codec_mask.type) == |
| 171 container_codec_masks_.end()); |
| 172 container_codec_masks_[container_codec_mask.type] = |
| 173 container_codec_mask.mask; |
| 174 } |
| 175 for (size_t i = 0; i < arraysize(kCodecMasks); ++i) { |
| 176 const CodecMask& codec_mask = kCodecMasks[i]; |
| 177 DCHECK(codec_masks_.find(codec_mask.type) == codec_masks_.end()); |
| 178 codec_masks_[codec_mask.type] = codec_mask.mask; |
| 179 } |
| 180 |
144 std::vector<KeySystemInfo> key_systems_info; | 181 std::vector<KeySystemInfo> key_systems_info; |
145 GetContentClient()->renderer()->AddKeySystems(&key_systems_info); | 182 GetContentClient()->renderer()->AddKeySystems(&key_systems_info); |
146 // Clear Key is always supported. | 183 // Clear Key is always supported. |
147 AddClearKey(&key_systems_info); | 184 AddClearKey(&key_systems_info); |
148 AddConcreteSupportedKeySystems(key_systems_info); | 185 AddConcreteSupportedKeySystems(key_systems_info); |
149 #if defined(WIDEVINE_CDM_AVAILABLE) | 186 #if defined(WIDEVINE_CDM_AVAILABLE) |
150 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem); | 187 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem); |
151 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 188 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
152 } | 189 } |
153 | 190 |
154 void KeySystems::AddConcreteSupportedKeySystems( | 191 void KeySystems::AddConcreteSupportedKeySystems( |
155 const std::vector<KeySystemInfo>& concrete_key_systems) { | 192 const std::vector<KeySystemInfo>& concrete_key_systems) { |
156 for (size_t i = 0; i < concrete_key_systems.size(); ++i) { | 193 for (size_t i = 0; i < concrete_key_systems.size(); ++i) { |
157 const KeySystemInfo& key_system_info = concrete_key_systems[i]; | 194 const KeySystemInfo& key_system_info = concrete_key_systems[i]; |
158 AddConcreteSupportedKeySystem(key_system_info.key_system, | 195 AddConcreteSupportedKeySystem(key_system_info.key_system, |
159 key_system_info.use_aes_decryptor, | 196 key_system_info.use_aes_decryptor, |
160 #if defined(ENABLE_PEPPER_CDMS) | 197 #if defined(ENABLE_PEPPER_CDMS) |
161 key_system_info.pepper_type, | 198 key_system_info.pepper_type, |
162 #endif | 199 #endif |
163 key_system_info.supported_types, | 200 key_system_info.supported_codecs, |
164 key_system_info.parent_key_system); | 201 key_system_info.parent_key_system); |
165 } | 202 } |
166 } | 203 } |
167 | 204 |
168 void KeySystems::AddConcreteSupportedKeySystem( | 205 void KeySystems::AddConcreteSupportedKeySystem( |
169 const std::string& concrete_key_system, | 206 const std::string& concrete_key_system, |
170 bool use_aes_decryptor, | 207 bool use_aes_decryptor, |
171 #if defined(ENABLE_PEPPER_CDMS) | 208 #if defined(ENABLE_PEPPER_CDMS) |
172 const std::string& pepper_type, | 209 const std::string& pepper_type, |
173 #endif | 210 #endif |
174 const ContainerCodecsMap& supported_types, | 211 SupportedCodecs supported_codecs, |
175 const std::string& parent_key_system) { | 212 const std::string& parent_key_system) { |
176 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system)) | 213 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system)) |
177 << "Key system '" << concrete_key_system << "' already registered"; | 214 << "Key system '" << concrete_key_system << "' already registered"; |
178 DCHECK(parent_key_system_map_.find(concrete_key_system) == | 215 DCHECK(parent_key_system_map_.find(concrete_key_system) == |
179 parent_key_system_map_.end()) | 216 parent_key_system_map_.end()) |
180 << "'" << concrete_key_system << " is already registered as a parent"; | 217 << "'" << concrete_key_system << " is already registered as a parent"; |
181 | 218 |
182 KeySystemProperties properties; | 219 KeySystemProperties properties; |
183 properties.use_aes_decryptor = use_aes_decryptor; | 220 properties.use_aes_decryptor = use_aes_decryptor; |
184 #if defined(ENABLE_PEPPER_CDMS) | 221 #if defined(ENABLE_PEPPER_CDMS) |
185 DCHECK_EQ(use_aes_decryptor, pepper_type.empty()); | 222 DCHECK_EQ(use_aes_decryptor, pepper_type.empty()); |
186 properties.pepper_type = pepper_type; | 223 properties.pepper_type = pepper_type; |
187 #endif | 224 #endif |
188 | 225 |
189 properties.supported_types = supported_types; | 226 properties.supported_codecs = supported_codecs; |
190 | 227 |
191 concrete_key_system_map_[concrete_key_system] = properties; | 228 concrete_key_system_map_[concrete_key_system] = properties; |
192 | 229 |
193 if (!parent_key_system.empty()) { | 230 if (!parent_key_system.empty()) { |
194 DCHECK(!IsConcreteSupportedKeySystem(parent_key_system)) | 231 DCHECK(!IsConcreteSupportedKeySystem(parent_key_system)) |
195 << "Parent '" << parent_key_system << "' already registered concrete"; | 232 << "Parent '" << parent_key_system << "' already registered concrete"; |
196 DCHECK(parent_key_system_map_.find(parent_key_system) == | 233 DCHECK(parent_key_system_map_.find(parent_key_system) == |
197 parent_key_system_map_.end()) | 234 parent_key_system_map_.end()) |
198 << "Parent '" << parent_key_system << "' already registered"; | 235 << "Parent '" << parent_key_system << "' already registered"; |
199 parent_key_system_map_[parent_key_system] = concrete_key_system; | 236 parent_key_system_map_[parent_key_system] = concrete_key_system; |
200 } | 237 } |
201 } | 238 } |
202 | 239 |
203 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) { | 240 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) { |
204 return concrete_key_system_map_.find(key_system) != | 241 return concrete_key_system_map_.find(key_system) != |
205 concrete_key_system_map_.end(); | 242 concrete_key_system_map_.end(); |
206 } | 243 } |
207 | 244 |
208 bool KeySystems::IsSupportedKeySystemWithContainerAndCodec( | 245 bool KeySystems::IsSupportedContainer( |
209 const std::string& mime_type, | 246 const std::string& container, |
210 const std::string& codec, | 247 SupportedCodecs key_system_supported_codecs) const { |
211 const std::string& key_system) { | 248 DCHECK(!container.empty()); |
212 bool has_type = !mime_type.empty(); | |
213 DCHECK(has_type || codec.empty()); | |
214 | 249 |
215 key_systems_support_uma_.ReportKeySystemQuery(key_system, has_type); | 250 // When checking container support for EME, "audio/foo" should be treated the |
| 251 // same as "video/foo". Convert the |container| to achieve this. |
| 252 // TODO(xhwang): Replace this with real checks against supported initDataTypes |
| 253 // combined with supported demuxers. |
| 254 std::string canonical_container = container; |
| 255 if (container.find("audio/") == 0) |
| 256 canonical_container.replace(0, 6, "video/"); |
216 | 257 |
217 KeySystemPropertiesMap::const_iterator key_system_iter = | 258 CodecMaskMap::const_iterator container_iter = |
218 concrete_key_system_map_.find(key_system); | 259 container_codec_masks_.find(canonical_container); |
219 if (key_system_iter == concrete_key_system_map_.end()) | 260 // Unrecognized container. |
| 261 if (container_iter == container_codec_masks_.end()) |
220 return false; | 262 return false; |
221 | 263 |
222 key_systems_support_uma_.ReportKeySystemSupport(key_system, false); | 264 EmeCodec container_codec_mask = container_iter->second; |
| 265 // A container is supported iif at least one codec in that container is |
| 266 // supported. |
| 267 return (container_codec_mask & key_system_supported_codecs) != 0; |
| 268 } |
223 | 269 |
224 if (mime_type.empty()) | 270 bool KeySystems::IsSupportedContainerAndCodecs( |
225 return true; | 271 const std::string& container, |
| 272 const std::vector<std::string>& codecs, |
| 273 SupportedCodecs key_system_supported_codecs) const { |
| 274 DCHECK(!container.empty()); |
| 275 DCHECK(!codecs.empty()); |
| 276 DCHECK(IsSupportedContainer(container, key_system_supported_codecs)); |
226 | 277 |
227 const ContainerCodecsMap& mime_types_map = | 278 CodecMaskMap::const_iterator container_iter = |
228 key_system_iter->second.supported_types; | 279 container_codec_masks_.find(container); |
229 ContainerCodecsMap::const_iterator mime_iter = mime_types_map.find(mime_type); | 280 EmeCodec container_codec_mask = container_iter->second; |
230 if (mime_iter == mime_types_map.end()) | |
231 return false; | |
232 | 281 |
233 if (codec.empty()) { | 282 for (size_t i = 0; i < codecs.size(); ++i) { |
234 key_systems_support_uma_.ReportKeySystemSupport(key_system, true); | 283 const std::string& codec = codecs[i]; |
235 return true; | 284 DCHECK(!codec.empty()); |
| 285 CodecMaskMap::const_iterator codec_iter = codec_masks_.find(codec); |
| 286 if (codec_iter == codec_masks_.end()) // Unrecognized codec. |
| 287 return false; |
| 288 |
| 289 EmeCodec codec_mask = codec_iter->second; |
| 290 if (!(codec_mask & key_system_supported_codecs)) // Unsupported codec. |
| 291 return false; |
| 292 |
| 293 // Unsupported codec/container combination, e.g. "video/webm" and "avc1". |
| 294 if (!(codec_mask & container_codec_mask)) |
| 295 return false; |
236 } | 296 } |
237 | 297 |
238 const CodecSet& codecs = mime_iter->second; | |
239 if (codecs.find(codec) == codecs.end()) | |
240 return false; | |
241 | |
242 key_systems_support_uma_.ReportKeySystemSupport(key_system, true); | |
243 return true; | 298 return true; |
244 } | 299 } |
245 | 300 |
246 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( | 301 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( |
247 const std::string& mime_type, | 302 const std::string& mime_type, |
248 const std::vector<std::string>& codecs, | 303 const std::vector<std::string>& codecs, |
249 const std::string& key_system) { | 304 const std::string& key_system) { |
250 // If |key_system| is a parent key_system, use its concrete child. | 305 // If |key_system| is a parent key_system, use its concrete child. |
251 // Otherwise, use |key_system|. | 306 // Otherwise, use |key_system|. |
252 std::string concrete_key_system; | 307 std::string concrete_key_system; |
253 ParentKeySystemMap::iterator parent_key_system_iter = | 308 ParentKeySystemMap::iterator parent_key_system_iter = |
254 parent_key_system_map_.find(key_system); | 309 parent_key_system_map_.find(key_system); |
255 if (parent_key_system_iter != parent_key_system_map_.end()) | 310 if (parent_key_system_iter != parent_key_system_map_.end()) |
256 concrete_key_system = parent_key_system_iter->second; | 311 concrete_key_system = parent_key_system_iter->second; |
257 else | 312 else |
258 concrete_key_system = key_system; | 313 concrete_key_system = key_system; |
259 | 314 |
260 if (codecs.empty()) { | 315 bool has_type = !mime_type.empty(); |
261 return IsSupportedKeySystemWithContainerAndCodec( | 316 |
262 mime_type, std::string(), concrete_key_system); | 317 key_systems_support_uma_.ReportKeySystemQuery(key_system, has_type); |
| 318 |
| 319 // Check key system support. |
| 320 KeySystemPropertiesMap::const_iterator key_system_iter = |
| 321 concrete_key_system_map_.find(concrete_key_system); |
| 322 if (key_system_iter == concrete_key_system_map_.end()) |
| 323 return false; |
| 324 |
| 325 key_systems_support_uma_.ReportKeySystemSupport(key_system, false); |
| 326 |
| 327 if (!has_type) { |
| 328 DCHECK(codecs.empty()); |
| 329 return true; |
263 } | 330 } |
264 | 331 |
265 for (size_t i = 0; i < codecs.size(); ++i) { | 332 SupportedCodecs key_system_supported_codecs = |
266 if (!IsSupportedKeySystemWithContainerAndCodec( | 333 key_system_iter->second.supported_codecs; |
267 mime_type, codecs[i], concrete_key_system)) { | 334 |
268 return false; | 335 if (!IsSupportedContainer(mime_type, key_system_supported_codecs)) |
269 } | 336 return false; |
| 337 |
| 338 if (!codecs.empty() && |
| 339 !IsSupportedContainerAndCodecs( |
| 340 mime_type, codecs, key_system_supported_codecs)) { |
| 341 return false; |
270 } | 342 } |
271 | 343 |
| 344 key_systems_support_uma_.ReportKeySystemSupport(key_system, true); |
272 return true; | 345 return true; |
273 } | 346 } |
274 | 347 |
275 bool KeySystems::UseAesDecryptor(const std::string& concrete_key_system) { | 348 bool KeySystems::UseAesDecryptor(const std::string& concrete_key_system) { |
276 KeySystemPropertiesMap::iterator key_system_iter = | 349 KeySystemPropertiesMap::iterator key_system_iter = |
277 concrete_key_system_map_.find(concrete_key_system); | 350 concrete_key_system_map_.find(concrete_key_system); |
278 if (key_system_iter == concrete_key_system_map_.end()) { | 351 if (key_system_iter == concrete_key_system_map_.end()) { |
279 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; | 352 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; |
280 return false; | 353 return false; |
281 } | 354 } |
282 | 355 |
283 return key_system_iter->second.use_aes_decryptor; | 356 return key_system_iter->second.use_aes_decryptor; |
284 } | 357 } |
285 | 358 |
286 #if defined(ENABLE_PEPPER_CDMS) | 359 #if defined(ENABLE_PEPPER_CDMS) |
287 std::string KeySystems::GetPepperType(const std::string& concrete_key_system) { | 360 std::string KeySystems::GetPepperType(const std::string& concrete_key_system) { |
288 KeySystemPropertiesMap::iterator key_system_iter = | 361 KeySystemPropertiesMap::iterator key_system_iter = |
289 concrete_key_system_map_.find(concrete_key_system); | 362 concrete_key_system_map_.find(concrete_key_system); |
290 if (key_system_iter == concrete_key_system_map_.end()) { | 363 if (key_system_iter == concrete_key_system_map_.end()) { |
291 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; | 364 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; |
292 return std::string(); | 365 return std::string(); |
293 } | 366 } |
294 | 367 |
295 const std::string& type = key_system_iter->second.pepper_type; | 368 const std::string& type = key_system_iter->second.pepper_type; |
296 DLOG_IF(FATAL, type.empty()) << concrete_key_system << " is not Pepper-based"; | 369 DLOG_IF(FATAL, type.empty()) << concrete_key_system << " is not Pepper-based"; |
297 return type; | 370 return type; |
298 } | 371 } |
299 #endif | 372 #endif |
300 | 373 |
| 374 void KeySystems::AddContainerMask(const std::string& container, uint32 mask) { |
| 375 DCHECK(container_codec_masks_.find(container) == |
| 376 container_codec_masks_.end()); |
| 377 container_codec_masks_[container] = static_cast<EmeCodec>(mask); |
| 378 } |
| 379 |
| 380 void KeySystems::AddCodecMask(const std::string& codec, uint32 mask) { |
| 381 DCHECK(codec_masks_.find(codec) == codec_masks_.end()); |
| 382 codec_masks_[codec] = static_cast<EmeCodec>(mask); |
| 383 } |
| 384 |
301 //------------------------------------------------------------------------------ | 385 //------------------------------------------------------------------------------ |
302 | 386 |
303 std::string GetUnprefixedKeySystemName(const std::string& key_system) { | 387 std::string GetUnprefixedKeySystemName(const std::string& key_system) { |
304 if (key_system == kClearKeyKeySystem) | 388 if (key_system == kClearKeyKeySystem) |
305 return kUnsupportedClearKeyKeySystem; | 389 return kUnsupportedClearKeyKeySystem; |
306 | 390 |
307 if (key_system == kPrefixedClearKeyKeySystem) | 391 if (key_system == kPrefixedClearKeyKeySystem) |
308 return kClearKeyKeySystem; | 392 return kClearKeyKeySystem; |
309 | 393 |
310 return key_system; | 394 return key_system; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 bool CanUseAesDecryptor(const std::string& concrete_key_system) { | 428 bool CanUseAesDecryptor(const std::string& concrete_key_system) { |
345 return KeySystems::GetInstance().UseAesDecryptor(concrete_key_system); | 429 return KeySystems::GetInstance().UseAesDecryptor(concrete_key_system); |
346 } | 430 } |
347 | 431 |
348 #if defined(ENABLE_PEPPER_CDMS) | 432 #if defined(ENABLE_PEPPER_CDMS) |
349 std::string GetPepperType(const std::string& concrete_key_system) { | 433 std::string GetPepperType(const std::string& concrete_key_system) { |
350 return KeySystems::GetInstance().GetPepperType(concrete_key_system); | 434 return KeySystems::GetInstance().GetPepperType(concrete_key_system); |
351 } | 435 } |
352 #endif | 436 #endif |
353 | 437 |
| 438 // These two functions are for testing purpose only. The declaration in the |
| 439 // header file is guarded by "#if defined(UNIT_TEST)" so that they can be used |
| 440 // by tests but not non-test code. However, this .cc file is compiled as part of |
| 441 // "content" where "UNIT_TEST" is not defined. So we need to specify |
| 442 // "CONTENT_EXPORT" here again so that they are visible to tests. |
| 443 |
| 444 CONTENT_EXPORT void AddContainerMask(const std::string& container, |
| 445 uint32 mask) { |
| 446 KeySystems::GetInstance().AddContainerMask(container, mask); |
| 447 } |
| 448 |
| 449 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { |
| 450 KeySystems::GetInstance().AddCodecMask(codec, mask); |
| 451 } |
| 452 |
354 } // namespace content | 453 } // namespace content |
OLD | NEW |