Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1004)

Side by Side Diff: content/renderer/media/crypto/key_systems.cc

Issue 246033002: Store SupportedCodecs in KeySystemInfo and KeySystems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ready for review. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/encrypted_media_codecs.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 CodecMaskMap {
31 const char kVideoWebM[] = "video/webm"; 32 const char* type;
32 const char kVorbis[] = "vorbis"; 33 SupportedCodecMask 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 CodecMaskMap kContainerMasks[] = {
40 {"audio/webm", WEBM_AUDIO_CODECS},
41 {"video/webm", WEBM_ALL_CODECS},
36 #if defined(USE_PROPRIETARY_CODECS) 42 #if defined(USE_PROPRIETARY_CODECS)
37 const char kAudioMp4[] = "audio/mp4"; 43 {"audio/mp4", MP4_AUDIO_CODECS},
38 const char kVideoMp4[] = "video/mp4"; 44 {"video/mp4", MP4_ALL_CODECS}
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 CodecMaskMap kCodecMasks[] = {
50 {"vorbis", WEBM_VORBIS},
51 {"vp8", WEBM_VP8},
52 {"vp8.0", WEBM_VP8},
53 #if defined(USE_PROPRIETARY_CODECS)
54 {"mp4a", MP4_AAC},
55 {"avc1", MP4_AVC1},
56 {"avc3", 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 #if defined(OS_ANDROID) 63 #if defined(OS_ANDROID)
48 // If MediaCodecBridge is not available. EME should not be enabled at all. 64 // If MediaCodecBridge is not available. EME should not be enabled at all.
49 // See SetRuntimeFeatureDefaultsForPlatform(). 65 // See SetRuntimeFeatureDefaultsForPlatform().
50 // VP8 and AVC1 are supported on all MediaCodec implementations: 66 // VP8 and AVC1 are supported on all MediaCodec implementations:
51 // http://developer.android.com/guide/appendix/media-formats.html 67 // http://developer.android.com/guide/appendix/media-formats.html
52 DCHECK(media::MediaCodecBridge::IsAvailable()); 68 DCHECK(media::MediaCodecBridge::IsAvailable());
53 #endif 69 #endif
54 70
55 info.supported_types[kAudioWebM].insert(kVorbis); 71 info.supported_codecs = WEBM_ALL_CODECS;
56 info.supported_types[kVideoWebM] = info.supported_types[kAudioWebM];
57 info.supported_types[kVideoWebM].insert(kVP8);
58 info.supported_types[kVideoWebM].insert(kVP80);
59 #if defined(USE_PROPRIETARY_CODECS) 72 #if defined(USE_PROPRIETARY_CODECS)
60 info.supported_types[kAudioMp4].insert(kMp4a); 73 info.supported_codecs |= MP4_ALL_CODECS;
61 info.supported_types[kVideoMp4] = info.supported_types[kAudioMp4];
62 info.supported_types[kVideoMp4].insert(kAvc1);
63 info.supported_types[kVideoMp4].insert(kAvc3);
64 #endif // defined(USE_PROPRIETARY_CODECS) 74 #endif // defined(USE_PROPRIETARY_CODECS)
65 75
66 info.use_aes_decryptor = true; 76 info.use_aes_decryptor = true;
67 77
68 concrete_key_systems->push_back(info); 78 concrete_key_systems->push_back(info);
69 } 79 }
70 80
71 class KeySystems { 81 class KeySystems {
72 public: 82 public:
73 static KeySystems& GetInstance(); 83 static KeySystems& GetInstance();
74 84
75 bool IsConcreteSupportedKeySystem(const std::string& key_system); 85 bool IsConcreteSupportedKeySystem(const std::string& key_system);
76 86
77 bool IsSupportedKeySystemWithMediaMimeType( 87 bool IsSupportedKeySystemWithMediaMimeType(
78 const std::string& mime_type, 88 const std::string& mime_type,
79 const std::vector<std::string>& codecs, 89 const std::vector<std::string>& codecs,
80 const std::string& key_system); 90 const std::string& key_system);
81 91
82 bool UseAesDecryptor(const std::string& concrete_key_system); 92 bool UseAesDecryptor(const std::string& concrete_key_system);
83 93
84 #if defined(ENABLE_PEPPER_CDMS) 94 #if defined(ENABLE_PEPPER_CDMS)
85 std::string GetPepperType(const std::string& concrete_key_system); 95 std::string GetPepperType(const std::string& concrete_key_system);
86 #endif 96 #endif
87 97
98 void AddContainerMask(const std::string& container, uint32 mask);
99 void AddCodecMask(const std::string& codec, uint32 mask);
100
88 private: 101 private:
89 typedef KeySystemInfo::CodecSet CodecSet;
90 typedef KeySystemInfo::ContainerCodecsMap ContainerCodecsMap;
91
92 void AddConcreteSupportedKeySystems( 102 void AddConcreteSupportedKeySystems(
93 const std::vector<KeySystemInfo>& concrete_key_systems); 103 const std::vector<KeySystemInfo>& concrete_key_systems);
94 104
95 void AddConcreteSupportedKeySystem( 105 void AddConcreteSupportedKeySystem(
96 const std::string& key_system, 106 const std::string& key_system,
97 bool use_aes_decryptor, 107 bool use_aes_decryptor,
98 #if defined(ENABLE_PEPPER_CDMS) 108 #if defined(ENABLE_PEPPER_CDMS)
99 const std::string& pepper_type, 109 const std::string& pepper_type,
100 #endif 110 #endif
101 const ContainerCodecsMap& supported_types, 111 SupportedCodecs supported_codecs,
102 const std::string& parent_key_system); 112 const std::string& parent_key_system);
103 113
104 friend struct base::DefaultLazyInstanceTraits<KeySystems>; 114 friend struct base::DefaultLazyInstanceTraits<KeySystems>;
105 115
106 struct KeySystemProperties { 116 struct KeySystemProperties {
107 KeySystemProperties() : use_aes_decryptor(false) {} 117 KeySystemProperties() : use_aes_decryptor(false) {}
108 118
109 bool use_aes_decryptor; 119 bool use_aes_decryptor;
110 #if defined(ENABLE_PEPPER_CDMS) 120 #if defined(ENABLE_PEPPER_CDMS)
111 std::string pepper_type; 121 std::string pepper_type;
112 #endif 122 #endif
113 ContainerCodecsMap supported_types; 123 SupportedCodecs supported_codecs;
114 }; 124 };
115 125
116 typedef std::map<std::string, KeySystemProperties> KeySystemPropertiesMap; 126 typedef base::hash_map<std::string, KeySystemProperties>
117 127 KeySystemPropertiesMap;
118 typedef std::map<std::string, std::string> ParentKeySystemMap; 128 typedef base::hash_map<std::string, std::string> ParentKeySystemMap;
129 typedef base::hash_map<std::string, SupportedCodecMask> MaskMap;
119 130
120 KeySystems(); 131 KeySystems();
121 ~KeySystems() {} 132 ~KeySystems() {}
122 133
123 bool IsSupportedKeySystemWithContainerAndCodec(const std::string& mime_type, 134 // Returns whether a |container| type is supported by checking
124 const std::string& codec, 135 // |supported_codecs|.
125 const std::string& key_system); 136 // TODO(xhwang): Update this to actually check initDataType support.
137 bool IsSupportedContainer(const std::string& container,
138 SupportedCodecs supported_codecs) const;
139
140 // Returns true if all |codecs| are supported in |container| by checking
141 // |supported_codecs|.
142 bool IsSupportedContainerAndCodecs(const std::string& container,
143 const std::vector<std::string>& codecs,
144 SupportedCodecs supported_codecs) const;
126 145
127 // Map from key system string to capabilities. 146 // Map from key system string to capabilities.
128 KeySystemPropertiesMap concrete_key_system_map_; 147 KeySystemPropertiesMap concrete_key_system_map_;
129 148
130 // Map from parent key system to the concrete key system that should be used 149 // Map from parent key system to the concrete key system that should be used
131 // to represent its capabilities. 150 // to represent its capabilities.
132 ParentKeySystemMap parent_key_system_map_; 151 ParentKeySystemMap parent_key_system_map_;
133 152
134 KeySystemsSupportUMA key_systems_support_uma_; 153 KeySystemsSupportUMA key_systems_support_uma_;
135 154
155 MaskMap container_masks_;
156 MaskMap codec_masks_;
157
136 DISALLOW_COPY_AND_ASSIGN(KeySystems); 158 DISALLOW_COPY_AND_ASSIGN(KeySystems);
137 }; 159 };
138 160
139 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER; 161 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER;
140 162
141 KeySystems& KeySystems::GetInstance() { 163 KeySystems& KeySystems::GetInstance() {
142 return g_key_systems.Get(); 164 return g_key_systems.Get();
143 } 165 }
144 166
145 // Because we use a LazyInstance, the key systems info must be populated when 167 // Because we use a LazyInstance, the key systems info must be populated when
146 // the instance is lazily initiated. 168 // the instance is lazily initiated.
147 KeySystems::KeySystems() { 169 KeySystems::KeySystems() {
170 // Build container and codec masks for quick look up.
171 for (size_t i = 0; i < arraysize(kContainerMasks); ++i) {
172 const CodecMaskMap& codec_mask = kContainerMasks[i];
173 DCHECK(container_masks_.find(codec_mask.type) == container_masks_.end());
174 container_masks_[codec_mask.type] = codec_mask.mask;
175 }
176 for (size_t i = 0; i < arraysize(kCodecMasks); ++i) {
177 const CodecMaskMap& codec_mask = kCodecMasks[i];
178 DCHECK(codec_masks_.find(codec_mask.type) == codec_masks_.end());
179 codec_masks_[codec_mask.type] = codec_mask.mask;
180 }
181
148 std::vector<KeySystemInfo> key_systems_info; 182 std::vector<KeySystemInfo> key_systems_info;
149 GetContentClient()->renderer()->AddKeySystems(&key_systems_info); 183 GetContentClient()->renderer()->AddKeySystems(&key_systems_info);
150 // Clear Key is always supported. 184 // Clear Key is always supported.
151 AddClearKey(&key_systems_info); 185 AddClearKey(&key_systems_info);
152 AddConcreteSupportedKeySystems(key_systems_info); 186 AddConcreteSupportedKeySystems(key_systems_info);
153 #if defined(WIDEVINE_CDM_AVAILABLE) 187 #if defined(WIDEVINE_CDM_AVAILABLE)
154 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem); 188 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem);
155 #endif // defined(WIDEVINE_CDM_AVAILABLE) 189 #endif // defined(WIDEVINE_CDM_AVAILABLE)
156 } 190 }
157 191
158 void KeySystems::AddConcreteSupportedKeySystems( 192 void KeySystems::AddConcreteSupportedKeySystems(
159 const std::vector<KeySystemInfo>& concrete_key_systems) { 193 const std::vector<KeySystemInfo>& concrete_key_systems) {
160 for (size_t i = 0; i < concrete_key_systems.size(); ++i) { 194 for (size_t i = 0; i < concrete_key_systems.size(); ++i) {
161 const KeySystemInfo& key_system_info = concrete_key_systems[i]; 195 const KeySystemInfo& key_system_info = concrete_key_systems[i];
162 AddConcreteSupportedKeySystem(key_system_info.key_system, 196 AddConcreteSupportedKeySystem(key_system_info.key_system,
163 key_system_info.use_aes_decryptor, 197 key_system_info.use_aes_decryptor,
164 #if defined(ENABLE_PEPPER_CDMS) 198 #if defined(ENABLE_PEPPER_CDMS)
165 key_system_info.pepper_type, 199 key_system_info.pepper_type,
166 #endif 200 #endif
167 key_system_info.supported_types, 201 key_system_info.supported_codecs,
168 key_system_info.parent_key_system); 202 key_system_info.parent_key_system);
169 } 203 }
170 } 204 }
171 205
172 void KeySystems::AddConcreteSupportedKeySystem( 206 void KeySystems::AddConcreteSupportedKeySystem(
173 const std::string& concrete_key_system, 207 const std::string& concrete_key_system,
174 bool use_aes_decryptor, 208 bool use_aes_decryptor,
175 #if defined(ENABLE_PEPPER_CDMS) 209 #if defined(ENABLE_PEPPER_CDMS)
176 const std::string& pepper_type, 210 const std::string& pepper_type,
177 #endif 211 #endif
178 const ContainerCodecsMap& supported_types, 212 SupportedCodecs supported_codecs,
179 const std::string& parent_key_system) { 213 const std::string& parent_key_system) {
180 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system)) 214 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system))
181 << "Key system '" << concrete_key_system << "' already registered"; 215 << "Key system '" << concrete_key_system << "' already registered";
182 DCHECK(parent_key_system_map_.find(concrete_key_system) == 216 DCHECK(parent_key_system_map_.find(concrete_key_system) ==
183 parent_key_system_map_.end()) 217 parent_key_system_map_.end())
184 << "'" << concrete_key_system << " is already registered as a parent"; 218 << "'" << concrete_key_system << " is already registered as a parent";
185 219
186 KeySystemProperties properties; 220 KeySystemProperties properties;
187 properties.use_aes_decryptor = use_aes_decryptor; 221 properties.use_aes_decryptor = use_aes_decryptor;
188 #if defined(ENABLE_PEPPER_CDMS) 222 #if defined(ENABLE_PEPPER_CDMS)
189 DCHECK_EQ(use_aes_decryptor, pepper_type.empty()); 223 DCHECK_EQ(use_aes_decryptor, pepper_type.empty());
190 properties.pepper_type = pepper_type; 224 properties.pepper_type = pepper_type;
191 #endif 225 #endif
192 226
193 properties.supported_types = supported_types; 227 properties.supported_codecs = supported_codecs;
194 228
195 concrete_key_system_map_[concrete_key_system] = properties; 229 concrete_key_system_map_[concrete_key_system] = properties;
196 230
197 if (!parent_key_system.empty()) { 231 if (!parent_key_system.empty()) {
198 DCHECK(!IsConcreteSupportedKeySystem(parent_key_system)) 232 DCHECK(!IsConcreteSupportedKeySystem(parent_key_system))
199 << "Parent '" << parent_key_system << "' already registered concrete"; 233 << "Parent '" << parent_key_system << "' already registered concrete";
200 DCHECK(parent_key_system_map_.find(parent_key_system) == 234 DCHECK(parent_key_system_map_.find(parent_key_system) ==
201 parent_key_system_map_.end()) 235 parent_key_system_map_.end())
202 << "Parent '" << parent_key_system << "' already registered"; 236 << "Parent '" << parent_key_system << "' already registered";
203 parent_key_system_map_[parent_key_system] = concrete_key_system; 237 parent_key_system_map_[parent_key_system] = concrete_key_system;
204 } 238 }
205 } 239 }
206 240
207 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) { 241 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) {
208 return concrete_key_system_map_.find(key_system) != 242 return concrete_key_system_map_.find(key_system) !=
209 concrete_key_system_map_.end(); 243 concrete_key_system_map_.end();
210 } 244 }
211 245
212 bool KeySystems::IsSupportedKeySystemWithContainerAndCodec( 246 bool KeySystems::IsSupportedContainer(const std::string& container,
213 const std::string& mime_type, 247 SupportedCodecs supported_codecs) const {
214 const std::string& codec, 248 DCHECK(!container.empty());
215 const std::string& key_system) {
216 bool has_type = !mime_type.empty();
217 DCHECK(has_type || codec.empty());
218 249
219 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.
ddorwin 2014/04/23 21:07:20 Should we have a TODO to replace this with real ch
xhwang 2014/04/23 23:30:37 Done.
252 std::string canonical_container = container;
253 if (container.find("audio/") == 0)
ddorwin 2014/04/23 21:07:20 This would break down for audio/mpeg, but we don't
xhwang 2014/04/23 23:30:37 yeah, this is a hack :)
254 canonical_container.replace(0, 6, "video/");
220 255
221 KeySystemPropertiesMap::const_iterator key_system_iter = 256 MaskMap::const_iterator container_iter =
222 concrete_key_system_map_.find(key_system); 257 container_masks_.find(canonical_container);
223 if (key_system_iter == concrete_key_system_map_.end()) 258 if (container_iter == container_masks_.end()) // Unrecognized container.
224 return false; 259 return false;
225 260
226 key_systems_support_uma_.ReportKeySystemSupport(key_system, false); 261 SupportedCodecMask container_mask = container_iter->second;
262 // A container is supported iif at least one codec in that container is
263 // supported.
264 return (container_mask & supported_codecs);
265 }
227 266
228 if (mime_type.empty()) 267 bool KeySystems::IsSupportedContainerAndCodecs(
229 return true; 268 const std::string& container,
269 const std::vector<std::string>& codecs,
270 SupportedCodecs supported_codecs) const {
ddorwin 2014/04/23 21:07:20 nit: This might be easier to follow if this was ke
xhwang 2014/04/23 23:30:37 Done.
271 DCHECK(!container.empty());
272 DCHECK(!codecs.empty());
273 DCHECK(IsSupportedContainer(container, supported_codecs));
230 274
231 const ContainerCodecsMap& mime_types_map = 275 MaskMap::const_iterator container_iter = container_masks_.find(container);
232 key_system_iter->second.supported_types; 276 SupportedCodecMask container_mask = container_iter->second;
ddorwin 2014/04/23 21:07:20 container_CODEC_mask?
xhwang 2014/04/23 23:30:37 Done.
233 ContainerCodecsMap::const_iterator mime_iter = mime_types_map.find(mime_type);
234 if (mime_iter == mime_types_map.end())
235 return false;
236 277
237 if (codec.empty()) { 278 for (size_t i = 0; i < codecs.size(); ++i) {
238 key_systems_support_uma_.ReportKeySystemSupport(key_system, true); 279 const std::string& codec = codecs[i];
239 return true; 280 DCHECK(!codec.empty());
281 MaskMap::const_iterator codec_iter = codec_masks_.find(codec);
282 if (codec_iter == codec_masks_.end()) // Unrecognized codec.
283 return false;
284
285 SupportedCodecMask codec_mask = codec_iter->second;
286 if (!(codec_mask & supported_codecs)) // Unsupported codec.
287 return false;
288
289 // Unsupported codec/container combination, e.g. "video/webm" and "avc1".
290 if (!(codec_mask & container_mask))
291 return false;
240 } 292 }
241 293
242 const CodecSet& codecs = mime_iter->second;
243 if (codecs.find(codec) == codecs.end())
244 return false;
245
246 key_systems_support_uma_.ReportKeySystemSupport(key_system, true);
247 return true; 294 return true;
248 } 295 }
249 296
250 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( 297 bool KeySystems::IsSupportedKeySystemWithMediaMimeType(
251 const std::string& mime_type, 298 const std::string& mime_type,
252 const std::vector<std::string>& codecs, 299 const std::vector<std::string>& codecs,
253 const std::string& key_system) { 300 const std::string& key_system) {
254 // If |key_system| is a parent key_system, use its concrete child. 301 // If |key_system| is a parent key_system, use its concrete child.
255 // Otherwise, use |key_system|. 302 // Otherwise, use |key_system|.
256 std::string concrete_key_system; 303 std::string concrete_key_system;
257 ParentKeySystemMap::iterator parent_key_system_iter = 304 ParentKeySystemMap::iterator parent_key_system_iter =
258 parent_key_system_map_.find(key_system); 305 parent_key_system_map_.find(key_system);
259 if (parent_key_system_iter != parent_key_system_map_.end()) 306 if (parent_key_system_iter != parent_key_system_map_.end())
260 concrete_key_system = parent_key_system_iter->second; 307 concrete_key_system = parent_key_system_iter->second;
261 else 308 else
262 concrete_key_system = key_system; 309 concrete_key_system = key_system;
263 310
264 if (codecs.empty()) { 311 bool has_type = !mime_type.empty();
265 return IsSupportedKeySystemWithContainerAndCodec( 312
266 mime_type, std::string(), concrete_key_system); 313 key_systems_support_uma_.ReportKeySystemQuery(key_system, has_type);
314
315 // Check key system support.
316 KeySystemPropertiesMap::const_iterator key_system_iter =
317 concrete_key_system_map_.find(concrete_key_system);
318 if (key_system_iter == concrete_key_system_map_.end())
319 return false;
320
321 key_systems_support_uma_.ReportKeySystemSupport(key_system, false);
322
323 if (!has_type) {
324 DCHECK(codecs.empty());
325 return true;
267 } 326 }
268 327
269 for (size_t i = 0; i < codecs.size(); ++i) { 328 SupportedCodecs supported_codecs = key_system_iter->second.supported_codecs;
270 if (!IsSupportedKeySystemWithContainerAndCodec( 329
271 mime_type, codecs[i], concrete_key_system)) { 330 if (!IsSupportedContainer(mime_type, supported_codecs))
272 return false; 331 return false;
273 } 332
333 if (!codecs.empty() &&
334 !IsSupportedContainerAndCodecs(mime_type, codecs, supported_codecs)) {
335 return false;
274 } 336 }
275 337
338 key_systems_support_uma_.ReportKeySystemSupport(key_system, true);
276 return true; 339 return true;
277 } 340 }
278 341
279 bool KeySystems::UseAesDecryptor(const std::string& concrete_key_system) { 342 bool KeySystems::UseAesDecryptor(const std::string& concrete_key_system) {
280 KeySystemPropertiesMap::iterator key_system_iter = 343 KeySystemPropertiesMap::iterator key_system_iter =
281 concrete_key_system_map_.find(concrete_key_system); 344 concrete_key_system_map_.find(concrete_key_system);
282 if (key_system_iter == concrete_key_system_map_.end()) { 345 if (key_system_iter == concrete_key_system_map_.end()) {
283 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; 346 DLOG(FATAL) << concrete_key_system << " is not a known concrete system";
284 return false; 347 return false;
285 } 348 }
286 349
287 return key_system_iter->second.use_aes_decryptor; 350 return key_system_iter->second.use_aes_decryptor;
288 } 351 }
289 352
290 #if defined(ENABLE_PEPPER_CDMS) 353 #if defined(ENABLE_PEPPER_CDMS)
291 std::string KeySystems::GetPepperType(const std::string& concrete_key_system) { 354 std::string KeySystems::GetPepperType(const std::string& concrete_key_system) {
292 KeySystemPropertiesMap::iterator key_system_iter = 355 KeySystemPropertiesMap::iterator key_system_iter =
293 concrete_key_system_map_.find(concrete_key_system); 356 concrete_key_system_map_.find(concrete_key_system);
294 if (key_system_iter == concrete_key_system_map_.end()) { 357 if (key_system_iter == concrete_key_system_map_.end()) {
295 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; 358 DLOG(FATAL) << concrete_key_system << " is not a known concrete system";
296 return std::string(); 359 return std::string();
297 } 360 }
298 361
299 const std::string& type = key_system_iter->second.pepper_type; 362 const std::string& type = key_system_iter->second.pepper_type;
300 DLOG_IF(FATAL, type.empty()) << concrete_key_system << " is not Pepper-based"; 363 DLOG_IF(FATAL, type.empty()) << concrete_key_system << " is not Pepper-based";
301 return type; 364 return type;
302 } 365 }
303 #endif 366 #endif
304 367
368 void KeySystems::AddContainerMask(const std::string& container, uint32 mask) {
369 DCHECK(container_masks_.find(container) == container_masks_.end());
370 container_masks_[container] = static_cast<SupportedCodecMask>(mask);
371 }
372
373 void KeySystems::AddCodecMask(const std::string& codec, uint32 mask) {
374 DCHECK(codec_masks_.find(codec) == codec_masks_.end());
375 codec_masks_[codec] = static_cast<SupportedCodecMask>(mask);
376 }
377
305 //------------------------------------------------------------------------------ 378 //------------------------------------------------------------------------------
306 379
307 std::string GetUnprefixedKeySystemName(const std::string& key_system) { 380 std::string GetUnprefixedKeySystemName(const std::string& key_system) {
308 if (key_system == kClearKeyKeySystem) 381 if (key_system == kClearKeyKeySystem)
309 return kUnsupportedClearKeyKeySystem; 382 return kUnsupportedClearKeyKeySystem;
310 383
311 if (key_system == kPrefixedClearKeyKeySystem) 384 if (key_system == kPrefixedClearKeyKeySystem)
312 return kClearKeyKeySystem; 385 return kClearKeyKeySystem;
313 386
314 return key_system; 387 return key_system;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 bool CanUseAesDecryptor(const std::string& concrete_key_system) { 421 bool CanUseAesDecryptor(const std::string& concrete_key_system) {
349 return KeySystems::GetInstance().UseAesDecryptor(concrete_key_system); 422 return KeySystems::GetInstance().UseAesDecryptor(concrete_key_system);
350 } 423 }
351 424
352 #if defined(ENABLE_PEPPER_CDMS) 425 #if defined(ENABLE_PEPPER_CDMS)
353 std::string GetPepperType(const std::string& concrete_key_system) { 426 std::string GetPepperType(const std::string& concrete_key_system) {
354 return KeySystems::GetInstance().GetPepperType(concrete_key_system); 427 return KeySystems::GetInstance().GetPepperType(concrete_key_system);
355 } 428 }
356 #endif 429 #endif
357 430
431 // These two functions are for testing purpose only. The declaration in the
432 // header file is guarded by "#if defined(UNIT_TEST)" so that they can be used
433 // by tests but not non-test code. However, this .cc file is compiled as part of
434 // "content" where "UNIT_TEST" is not defined. So we need to specify
435 // "CONTENT_EXPORT" here again so that they are visible to tests.
436
437 CONTENT_EXPORT void AddContainerMask(const std::string& container,
438 uint32 mask) {
439 KeySystems::GetInstance().AddContainerMask(container, mask);
440 }
441
442 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) {
443 KeySystems::GetInstance().AddCodecMask(codec, mask);
444 }
445
358 } // namespace content 446 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698