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

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

Issue 557723003: Implement Chromium side of MediaKeys.isTypeSupported(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DEP from components/cdm/renderer to content/public/common. Created 6 years, 3 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
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 <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_codec.h"
17 #include "content/public/common/eme_init_data_type.h"
17 #include "content/public/renderer/content_renderer_client.h" 18 #include "content/public/renderer/content_renderer_client.h"
18 #include "content/public/renderer/key_system_info.h" 19 #include "content/public/renderer/key_system_info.h"
19 #include "content/renderer/media/crypto/key_systems_support_uma.h" 20 #include "content/renderer/media/crypto/key_systems_support_uma.h"
20 21
21 #if defined(OS_ANDROID) 22 #if defined(OS_ANDROID)
22 #include "media/base/android/media_codec_bridge.h" 23 #include "media/base/android/media_codec_bridge.h"
23 #endif 24 #endif
24 25
25 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 26 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
26 27
27 namespace content { 28 namespace content {
28 29
29 const char kClearKeyKeySystem[] = "org.w3.clearkey"; 30 const char kClearKeyKeySystem[] = "org.w3.clearkey";
30 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey"; 31 const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey";
31 const char kUnsupportedClearKeyKeySystem[] = "unsupported-org.w3.clearkey"; 32 const char kUnsupportedClearKeyKeySystem[] = "unsupported-org.w3.clearkey";
32 33
33 struct CodecMask { 34 struct CodecMask {
34 const char* type; 35 const char* type;
35 EmeCodec mask; 36 EmeCodec mask;
36 }; 37 };
37 38
39 struct InitDataTypeMask {
ddorwin 2014/09/13 01:20:45 nit: move IDT stuff before container and codec to
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
40 const char* type;
41 EmeInitDataType mask;
ddorwin 2014/09/13 01:20:45 This seems like more of a type string to enum map.
sandersd (OOO until July 31) 2014/09/22 23:45:52 I had a go at renaming these, hopefully it's bette
42 };
43
38 // Mapping between container types and the masks of associated codecs. 44 // Mapping between container types and the masks of associated codecs.
39 // Only audio codec can belong to a "audio/*" container. Both audio and video 45 // Only audio codec can belong to a "audio/*" container. Both audio and video
40 // codecs can belong to a "video/*" container. 46 // codecs can belong to a "video/*" container.
41 CodecMask kContainerCodecMasks[] = { 47 CodecMask kContainerCodecMasks[] = {
42 {"audio/webm", EME_CODEC_WEBM_AUDIO_ALL}, 48 {"audio/webm", EME_CODEC_WEBM_AUDIO_ALL},
ddorwin 2014/09/13 03:51:05 I wonder if we should just convert these to conver
sandersd (OOO until July 31) 2014/09/22 23:45:53 They are mutable so that unit tests can inject new
ddorwin 2014/09/23 22:48:15 :( Okay, let's keep this in mind. If we enabled co
43 {"video/webm", EME_CODEC_WEBM_ALL}, 49 {"video/webm", EME_CODEC_WEBM_ALL},
44 #if defined(USE_PROPRIETARY_CODECS) 50 #if defined(USE_PROPRIETARY_CODECS)
45 {"audio/mp4", EME_CODEC_MP4_AUDIO_ALL}, 51 {"audio/mp4", EME_CODEC_MP4_AUDIO_ALL},
46 {"video/mp4", EME_CODEC_MP4_ALL} 52 {"video/mp4", EME_CODEC_MP4_ALL}
47 #endif // defined(USE_PROPRIETARY_CODECS) 53 #endif // defined(USE_PROPRIETARY_CODECS)
48 }; 54 };
49 55
50 // Mapping between codec types and their masks. 56 // Mapping between codec types and their masks.
51 CodecMask kCodecMasks[] = { 57 CodecMask kCodecMasks[] = {
52 {"vorbis", EME_CODEC_WEBM_VORBIS}, 58 {"vorbis", EME_CODEC_WEBM_VORBIS},
53 {"vp8", EME_CODEC_WEBM_VP8}, 59 {"vp8", EME_CODEC_WEBM_VP8},
54 {"vp8.0", EME_CODEC_WEBM_VP8}, 60 {"vp8.0", EME_CODEC_WEBM_VP8},
55 {"vp9", EME_CODEC_WEBM_VP9}, 61 {"vp9", EME_CODEC_WEBM_VP9},
56 {"vp9.0", EME_CODEC_WEBM_VP9}, 62 {"vp9.0", EME_CODEC_WEBM_VP9},
57 #if defined(USE_PROPRIETARY_CODECS) 63 #if defined(USE_PROPRIETARY_CODECS)
58 {"mp4a", EME_CODEC_MP4_AAC}, 64 {"mp4a", EME_CODEC_MP4_AAC},
59 {"avc1", EME_CODEC_MP4_AVC1}, 65 {"avc1", EME_CODEC_MP4_AVC1},
60 {"avc3", EME_CODEC_MP4_AVC1} 66 {"avc3", EME_CODEC_MP4_AVC1}
61 #endif // defined(USE_PROPRIETARY_CODECS) 67 #endif // defined(USE_PROPRIETARY_CODECS)
62 }; 68 };
63 69
70 // Mapping between initialization data types and their masks.
ddorwin 2014/09/13 01:20:45 ditto on moving
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
71 InitDataTypeMask kInitDataTypeMasks[] = {
72 {"cenc", EME_INIT_DATA_TYPE_CENC},
ddorwin 2014/09/13 03:51:05 This is a straight conversion and never depends on
sandersd (OOO until July 31) 2014/09/22 23:45:53 We can, but then blink needs to know what the supp
ddorwin 2014/09/23 22:48:15 I think it's probably reasonable for Blink to know
73 {"webm", EME_INIT_DATA_TYPE_WEBM},
74 {"keyids", EME_INIT_DATA_TYPE_KEYIDS},
75 };
76
64 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { 77 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) {
65 KeySystemInfo info(kClearKeyKeySystem); 78 KeySystemInfo info(kClearKeyKeySystem);
66 79
67 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: 80 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec:
68 // http://developer.android.com/guide/appendix/media-formats.html 81 // http://developer.android.com/guide/appendix/media-formats.html
69 // VP9 support is device dependent. 82 // VP9 support is device dependent.
70 83
71 info.supported_codecs = EME_CODEC_WEBM_ALL; 84 info.supported_codecs = EME_CODEC_WEBM_ALL;
72 85
73 #if defined(OS_ANDROID) 86 #if defined(OS_ANDROID)
74 // Temporarily disable VP9 support for Android. 87 // Temporarily disable VP9 support for Android.
75 // TODO(xhwang): Use mime_util.h to query VP9 support on Android. 88 // TODO(xhwang): Use mime_util.h to query VP9 support on Android.
76 info.supported_codecs &= ~EME_CODEC_WEBM_VP9; 89 info.supported_codecs &= ~EME_CODEC_WEBM_VP9;
77 #endif // defined(OS_ANDROID) 90 #endif // defined(OS_ANDROID)
78 91
79 #if defined(USE_PROPRIETARY_CODECS) 92 #if defined(USE_PROPRIETARY_CODECS)
80 info.supported_codecs |= EME_CODEC_MP4_ALL; 93 info.supported_codecs |= EME_CODEC_MP4_ALL;
81 #endif // defined(USE_PROPRIETARY_CODECS) 94 #endif // defined(USE_PROPRIETARY_CODECS)
82 95
96 info.supported_init_data_types = EME_INIT_DATA_TYPE_ALL;
ddorwin 2014/09/13 01:20:46 ditto on moving (also in other files)
sandersd (OOO until July 31) 2014/09/22 23:45:52 Done.
97
83 info.use_aes_decryptor = true; 98 info.use_aes_decryptor = true;
84 99
85 concrete_key_systems->push_back(info); 100 concrete_key_systems->push_back(info);
86 } 101 }
87 102
88 class KeySystems { 103 class KeySystems {
89 public: 104 public:
90 static KeySystems& GetInstance(); 105 static KeySystems& GetInstance();
91 106
92 void UpdateIfNeeded(); 107 void UpdateIfNeeded();
93 108
94 bool IsConcreteSupportedKeySystem(const std::string& key_system); 109 bool IsConcreteSupportedKeySystem(const std::string& key_system);
95 110
111 bool IsSupportedKeySystem(const std::string& key_system);
112
113 bool IsSupportedKeySystemWithInitDataType(
114 const std::string& key_system,
115 const std::string& init_data_type);
116
96 bool IsSupportedKeySystemWithMediaMimeType( 117 bool IsSupportedKeySystemWithMediaMimeType(
97 const std::string& mime_type, 118 const std::string& mime_type,
98 const std::vector<std::string>& codecs, 119 const std::vector<std::string>& codecs,
99 const std::string& key_system); 120 const std::string& key_system);
100 121
101 bool UseAesDecryptor(const std::string& concrete_key_system); 122 bool UseAesDecryptor(const std::string& concrete_key_system);
102 123
103 #if defined(ENABLE_PEPPER_CDMS) 124 #if defined(ENABLE_PEPPER_CDMS)
104 std::string GetPepperType(const std::string& concrete_key_system); 125 std::string GetPepperType(const std::string& concrete_key_system);
105 #endif 126 #endif
106 127
107 void AddContainerMask(const std::string& container, uint32 mask); 128 void AddContainerMask(const std::string& container, uint32 mask);
108 void AddCodecMask(const std::string& codec, uint32 mask); 129 void AddCodecMask(const std::string& codec, uint32 mask);
109 130
110 private: 131 private:
111 void UpdateSupportedKeySystems(); 132 void UpdateSupportedKeySystems();
112 133
113 void AddConcreteSupportedKeySystems( 134 void AddConcreteSupportedKeySystems(
114 const std::vector<KeySystemInfo>& concrete_key_systems); 135 const std::vector<KeySystemInfo>& concrete_key_systems);
115 136
116 void AddConcreteSupportedKeySystem( 137 void AddConcreteSupportedKeySystem(
117 const std::string& key_system, 138 const std::string& key_system,
118 bool use_aes_decryptor, 139 bool use_aes_decryptor,
119 #if defined(ENABLE_PEPPER_CDMS) 140 #if defined(ENABLE_PEPPER_CDMS)
120 const std::string& pepper_type, 141 const std::string& pepper_type,
121 #endif 142 #endif
122 SupportedCodecs supported_codecs, 143 SupportedCodecs supported_codecs,
144 SupportedInitDataTypes supported_init_data_types,
ddorwin 2014/09/13 01:20:45 nit: move up one line to match ITS order.
sandersd (OOO until July 31) 2014/09/22 23:45:52 Done.
123 const std::string& parent_key_system); 145 const std::string& parent_key_system);
124 146
125 friend struct base::DefaultLazyInstanceTraits<KeySystems>; 147 friend struct base::DefaultLazyInstanceTraits<KeySystems>;
126 148
127 struct KeySystemProperties { 149 struct KeySystemProperties {
128 KeySystemProperties() 150 KeySystemProperties()
129 : use_aes_decryptor(false), supported_codecs(EME_CODEC_NONE) {} 151 : use_aes_decryptor(false), supported_codecs(EME_CODEC_NONE) {}
130 152
131 bool use_aes_decryptor; 153 bool use_aes_decryptor;
132 #if defined(ENABLE_PEPPER_CDMS) 154 #if defined(ENABLE_PEPPER_CDMS)
133 std::string pepper_type; 155 std::string pepper_type;
134 #endif 156 #endif
135 SupportedCodecs supported_codecs; 157 SupportedCodecs supported_codecs;
158 SupportedInitDataTypes supported_init_data_types;
ddorwin 2014/09/13 01:20:45 ditto
sandersd (OOO until July 31) 2014/09/22 23:45:52 Done.
136 }; 159 };
137 160
138 typedef base::hash_map<std::string, KeySystemProperties> 161 typedef base::hash_map<std::string, KeySystemProperties>
139 KeySystemPropertiesMap; 162 KeySystemPropertiesMap;
140 typedef base::hash_map<std::string, std::string> ParentKeySystemMap; 163 typedef base::hash_map<std::string, std::string> ParentKeySystemMap;
141 typedef base::hash_map<std::string, EmeCodec> CodecMaskMap; 164 typedef base::hash_map<std::string, EmeCodec> CodecMaskMap;
165 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypeMaskMap;
ddorwin 2014/09/13 01:20:46 ditto
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
142 166
143 KeySystems(); 167 KeySystems();
144 ~KeySystems() {} 168 ~KeySystems() {}
145 169
146 // Returns whether a |container| type is supported by checking 170 // Returns whether a |container| type is supported by checking
147 // |key_system_supported_codecs|. 171 // |key_system_supported_codecs|.
148 // TODO(xhwang): Update this to actually check initDataType support. 172 // TODO(xhwang): Update this to actually check initDataType support.
149 bool IsSupportedContainer(const std::string& container, 173 bool IsSupportedContainer(const std::string& container,
150 SupportedCodecs key_system_supported_codecs) const; 174 SupportedCodecs key_system_supported_codecs) const;
151 175
152 // Returns true if all |codecs| are supported in |container| by checking 176 // Returns true if all |codecs| are supported in |container| by checking
153 // |key_system_supported_codecs|. 177 // |key_system_supported_codecs|.
154 bool IsSupportedContainerAndCodecs( 178 bool IsSupportedContainerAndCodecs(
155 const std::string& container, 179 const std::string& container,
156 const std::vector<std::string>& codecs, 180 const std::vector<std::string>& codecs,
157 SupportedCodecs key_system_supported_codecs) const; 181 SupportedCodecs key_system_supported_codecs) const;
158 182
159 // Map from key system string to capabilities. 183 // Map from key system string to capabilities.
160 KeySystemPropertiesMap concrete_key_system_map_; 184 KeySystemPropertiesMap concrete_key_system_map_;
161 185
162 // Map from parent key system to the concrete key system that should be used 186 // Map from parent key system to the concrete key system that should be used
163 // to represent its capabilities. 187 // to represent its capabilities.
164 ParentKeySystemMap parent_key_system_map_; 188 ParentKeySystemMap parent_key_system_map_;
165 189
166 KeySystemsSupportUMA key_systems_support_uma_; 190 KeySystemsSupportUMA key_systems_support_uma_;
167 191
168 CodecMaskMap container_codec_masks_; 192 CodecMaskMap container_codec_masks_;
169 CodecMaskMap codec_masks_; 193 CodecMaskMap codec_masks_;
194 InitDataTypeMaskMap init_data_type_masks_;
ddorwin 2014/09/13 01:20:45 ditto
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
170 195
171 bool needs_update_; 196 bool needs_update_;
172 base::Time last_update_time_; 197 base::Time last_update_time_;
173 198
174 // Makes sure all methods are called from the same thread. 199 // Makes sure all methods are called from the same thread.
175 base::ThreadChecker thread_checker_; 200 base::ThreadChecker thread_checker_;
176 201
177 DISALLOW_COPY_AND_ASSIGN(KeySystems); 202 DISALLOW_COPY_AND_ASSIGN(KeySystems);
178 }; 203 };
179 204
180 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER; 205 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER;
181 206
182 KeySystems& KeySystems::GetInstance() { 207 KeySystems& KeySystems::GetInstance() {
183 KeySystems& key_systems = g_key_systems.Get(); 208 KeySystems& key_systems = g_key_systems.Get();
184 key_systems.UpdateIfNeeded(); 209 key_systems.UpdateIfNeeded();
185 return key_systems; 210 return key_systems;
186 } 211 }
187 212
188 // Because we use a LazyInstance, the key systems info must be populated when 213 // Because we use a LazyInstance, the key systems info must be populated when
189 // the instance is lazily initiated. 214 // the instance is lazily initiated.
190 KeySystems::KeySystems() : needs_update_(true) { 215 KeySystems::KeySystems() : needs_update_(true) {
191 // Build container and codec masks for quick look up. 216 // Build container and codec masks for quick look up.
192 for (size_t i = 0; i < arraysize(kContainerCodecMasks); ++i) { 217 #define BUILD_MASK(dst, src) \
ddorwin 2014/09/13 01:20:45 Macros aren't allowed. Would a template function w
sandersd (OOO until July 31) 2014/09/22 23:45:52 I've expanded the macro, but I do think the macro
193 const CodecMask& container_codec_mask = kContainerCodecMasks[i]; 218 for (size_t i = 0; i < arraysize(src); ++i) { \
194 DCHECK(container_codec_masks_.find(container_codec_mask.type) == 219 DCHECK(dst.find(src[i].type) == dst.end()); \
195 container_codec_masks_.end()); 220 dst[src[i].type] = src[i].mask; \
196 container_codec_masks_[container_codec_mask.type] =
197 container_codec_mask.mask;
198 } 221 }
199 for (size_t i = 0; i < arraysize(kCodecMasks); ++i) { 222 BUILD_MASK(container_codec_masks_, kContainerCodecMasks);
200 const CodecMask& codec_mask = kCodecMasks[i]; 223 BUILD_MASK(codec_masks_, kCodecMasks);
201 DCHECK(codec_masks_.find(codec_mask.type) == codec_masks_.end()); 224 BUILD_MASK(init_data_type_masks_, kInitDataTypeMasks);
202 codec_masks_[codec_mask.type] = codec_mask.mask; 225 #undef BUILD_MASK
203 }
204 226
205 UpdateSupportedKeySystems(); 227 UpdateSupportedKeySystems();
206 228
207 #if defined(WIDEVINE_CDM_AVAILABLE) 229 #if defined(WIDEVINE_CDM_AVAILABLE)
208 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem); 230 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem);
209 #endif // defined(WIDEVINE_CDM_AVAILABLE) 231 #endif // defined(WIDEVINE_CDM_AVAILABLE)
210 } 232 }
211 233
212 void KeySystems::UpdateIfNeeded() { 234 void KeySystems::UpdateIfNeeded() {
213 #if defined(WIDEVINE_CDM_AVAILABLE) 235 #if defined(WIDEVINE_CDM_AVAILABLE)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 DCHECK(parent_key_system_map_.empty()); 279 DCHECK(parent_key_system_map_.empty());
258 280
259 for (size_t i = 0; i < concrete_key_systems.size(); ++i) { 281 for (size_t i = 0; i < concrete_key_systems.size(); ++i) {
260 const KeySystemInfo& key_system_info = concrete_key_systems[i]; 282 const KeySystemInfo& key_system_info = concrete_key_systems[i];
261 AddConcreteSupportedKeySystem(key_system_info.key_system, 283 AddConcreteSupportedKeySystem(key_system_info.key_system,
262 key_system_info.use_aes_decryptor, 284 key_system_info.use_aes_decryptor,
263 #if defined(ENABLE_PEPPER_CDMS) 285 #if defined(ENABLE_PEPPER_CDMS)
264 key_system_info.pepper_type, 286 key_system_info.pepper_type,
265 #endif 287 #endif
266 key_system_info.supported_codecs, 288 key_system_info.supported_codecs,
289 key_system_info.supported_init_data_types,
267 key_system_info.parent_key_system); 290 key_system_info.parent_key_system);
268 } 291 }
269 } 292 }
270 293
271 void KeySystems::AddConcreteSupportedKeySystem( 294 void KeySystems::AddConcreteSupportedKeySystem(
272 const std::string& concrete_key_system, 295 const std::string& concrete_key_system,
273 bool use_aes_decryptor, 296 bool use_aes_decryptor,
274 #if defined(ENABLE_PEPPER_CDMS) 297 #if defined(ENABLE_PEPPER_CDMS)
275 const std::string& pepper_type, 298 const std::string& pepper_type,
276 #endif 299 #endif
277 SupportedCodecs supported_codecs, 300 SupportedCodecs supported_codecs,
301 SupportedInitDataTypes supported_init_data_types,
278 const std::string& parent_key_system) { 302 const std::string& parent_key_system) {
279 DCHECK(thread_checker_.CalledOnValidThread()); 303 DCHECK(thread_checker_.CalledOnValidThread());
280 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system)) 304 DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system))
281 << "Key system '" << concrete_key_system << "' already registered"; 305 << "Key system '" << concrete_key_system << "' already registered";
282 DCHECK(parent_key_system_map_.find(concrete_key_system) == 306 DCHECK(parent_key_system_map_.find(concrete_key_system) ==
283 parent_key_system_map_.end()) 307 parent_key_system_map_.end())
284 << "'" << concrete_key_system << " is already registered as a parent"; 308 << "'" << concrete_key_system << " is already registered as a parent";
285 309
286 KeySystemProperties properties; 310 KeySystemProperties properties;
287 properties.use_aes_decryptor = use_aes_decryptor; 311 properties.use_aes_decryptor = use_aes_decryptor;
288 #if defined(ENABLE_PEPPER_CDMS) 312 #if defined(ENABLE_PEPPER_CDMS)
289 DCHECK_EQ(use_aes_decryptor, pepper_type.empty()); 313 DCHECK_EQ(use_aes_decryptor, pepper_type.empty());
290 properties.pepper_type = pepper_type; 314 properties.pepper_type = pepper_type;
291 #endif 315 #endif
292 316
293 properties.supported_codecs = supported_codecs; 317 properties.supported_codecs = supported_codecs;
318 properties.supported_init_data_types = supported_init_data_types;
294 319
295 concrete_key_system_map_[concrete_key_system] = properties; 320 concrete_key_system_map_[concrete_key_system] = properties;
296 321
297 if (!parent_key_system.empty()) { 322 if (!parent_key_system.empty()) {
298 DCHECK(!IsConcreteSupportedKeySystem(parent_key_system)) 323 DCHECK(!IsConcreteSupportedKeySystem(parent_key_system))
299 << "Parent '" << parent_key_system << "' already registered concrete"; 324 << "Parent '" << parent_key_system << "' already registered concrete";
300 DCHECK(parent_key_system_map_.find(parent_key_system) == 325 DCHECK(parent_key_system_map_.find(parent_key_system) ==
301 parent_key_system_map_.end()) 326 parent_key_system_map_.end())
302 << "Parent '" << parent_key_system << "' already registered"; 327 << "Parent '" << parent_key_system << "' already registered";
303 parent_key_system_map_[parent_key_system] = concrete_key_system; 328 parent_key_system_map_[parent_key_system] = concrete_key_system;
304 } 329 }
305 } 330 }
306 331
307 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) { 332 bool KeySystems::IsConcreteSupportedKeySystem(const std::string& key_system) {
308 DCHECK(thread_checker_.CalledOnValidThread()); 333 DCHECK(thread_checker_.CalledOnValidThread());
309 return concrete_key_system_map_.find(key_system) != 334 return concrete_key_system_map_.count(key_system);
ddorwin 2014/09/13 01:20:45 Is there a reason you made this change? Not that i
sandersd (OOO until July 31) 2014/09/22 23:45:53 It's a hash_map.
310 concrete_key_system_map_.end();
311 } 335 }
312 336
313 bool KeySystems::IsSupportedContainer( 337 bool KeySystems::IsSupportedContainer(
314 const std::string& container, 338 const std::string& container,
315 SupportedCodecs key_system_supported_codecs) const { 339 SupportedCodecs key_system_supported_codecs) const {
316 DCHECK(thread_checker_.CalledOnValidThread()); 340 DCHECK(thread_checker_.CalledOnValidThread());
317 DCHECK(!container.empty()); 341 DCHECK(!container.empty());
318 342
319 // When checking container support for EME, "audio/foo" should be treated the 343 // When checking container support for EME, "audio/foo" should be treated the
320 // same as "video/foo". Convert the |container| to achieve this. 344 // same as "video/foo". Convert the |container| to achieve this.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 return false; 386 return false;
363 387
364 // Unsupported codec/container combination, e.g. "video/webm" and "avc1". 388 // Unsupported codec/container combination, e.g. "video/webm" and "avc1".
365 if (!(codec_mask & container_codec_mask)) 389 if (!(codec_mask & container_codec_mask))
366 return false; 390 return false;
367 } 391 }
368 392
369 return true; 393 return true;
370 } 394 }
371 395
396 bool KeySystems::IsSupportedKeySystem(const std::string& key_system) {
397 DCHECK(thread_checker_.CalledOnValidThread());
398 return (parent_key_system_map_.count(key_system) ||
ddorwin 2014/09/13 01:20:45 ditto.
sandersd (OOO until July 31) 2014/09/22 23:45:53 Acknowledged.
399 concrete_key_system_map_.count(key_system));
ddorwin 2014/09/13 01:20:45 minor: We're more likely to see concrete key syste
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
400 }
401
402 bool KeySystems::IsSupportedKeySystemWithInitDataType(
403 const std::string& key_system,
404 const std::string& init_data_type) {
405 DCHECK(thread_checker_.CalledOnValidThread());
406
407 // If |key_system| is a parent key system, use its concrete child.
408 std::string concrete_key_system = key_system;
409 ParentKeySystemMap::const_iterator parent_key_system_iter =
410 parent_key_system_map_.find(key_system);
411 if (parent_key_system_iter != parent_key_system_map_.end())
412 concrete_key_system = parent_key_system_iter->second;
413
414 // Locate |concrete_key_system|.
415 KeySystemPropertiesMap::const_iterator key_system_iter =
416 concrete_key_system_map_.find(concrete_key_system);
417 if (key_system_iter == concrete_key_system_map_.end())
418 return false;
419
420 // Check |init_data_type|.
421 InitDataTypeMaskMap::const_iterator init_data_type_iter =
422 init_data_type_masks_.find(init_data_type);
423 if (init_data_type_iter == init_data_type_masks_.end())
424 return false;
425
426 // Check |key_system| x |init_data_type|.
427 const KeySystemProperties& properties = key_system_iter->second;
428 const EmeInitDataType& init_data_type_mask = init_data_type_iter->second;
429 if (!(properties.supported_init_data_types & init_data_type_mask))
430 return false;
431
432 return true;
433 }
434
372 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( 435 bool KeySystems::IsSupportedKeySystemWithMediaMimeType(
373 const std::string& mime_type, 436 const std::string& mime_type,
374 const std::vector<std::string>& codecs, 437 const std::vector<std::string>& codecs,
375 const std::string& key_system) { 438 const std::string& key_system) {
ddorwin 2014/09/13 01:20:45 note: This ordering is odd (probably to match CPT)
sandersd (OOO until July 31) 2014/09/22 23:45:52 I agree, and some of the Is____ methods are probab
376 DCHECK(thread_checker_.CalledOnValidThread()); 439 DCHECK(thread_checker_.CalledOnValidThread());
377 440
378 // If |key_system| is a parent key_system, use its concrete child. 441 // If |key_system| is a parent key_system, use its concrete child.
ddorwin 2014/09/13 01:20:45 Please remove second '_'
sandersd (OOO until July 31) 2014/09/22 23:45:53 Done.
379 // Otherwise, use |key_system|. 442 // Otherwise, use |key_system|.
ddorwin 2014/09/13 01:20:45 442-449 are different from 408-412. The code shoul
sandersd (OOO until July 31) 2014/09/22 23:45:52 Done.
380 std::string concrete_key_system; 443 std::string concrete_key_system;
381 ParentKeySystemMap::iterator parent_key_system_iter = 444 ParentKeySystemMap::iterator parent_key_system_iter =
382 parent_key_system_map_.find(key_system); 445 parent_key_system_map_.find(key_system);
383 if (parent_key_system_iter != parent_key_system_map_.end()) 446 if (parent_key_system_iter != parent_key_system_map_.end())
384 concrete_key_system = parent_key_system_iter->second; 447 concrete_key_system = parent_key_system_iter->second;
385 else 448 else
386 concrete_key_system = key_system; 449 concrete_key_system = key_system;
387 450
388 bool has_type = !mime_type.empty(); 451 bool has_type = !mime_type.empty();
389 452
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 if (key_system == kClearKeyKeySystem) 544 if (key_system == kClearKeyKeySystem)
482 return kPrefixedClearKeyKeySystem; 545 return kPrefixedClearKeyKeySystem;
483 546
484 return key_system; 547 return key_system;
485 } 548 }
486 549
487 bool IsConcreteSupportedKeySystem(const std::string& key_system) { 550 bool IsConcreteSupportedKeySystem(const std::string& key_system) {
488 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system); 551 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system);
489 } 552 }
490 553
554 bool IsSupportedKeySystem(const std::string& key_system) {
555 return KeySystems::GetInstance().IsSupportedKeySystem(key_system);
556 }
557
558 bool IsSupportedKeySystemWithInitDataType(
559 const std::string& key_system,
560 const std::string& init_data_type) {
561 return KeySystems::GetInstance().IsSupportedKeySystemWithInitDataType(
562 key_system, init_data_type);
563 }
564
491 bool IsSupportedKeySystemWithMediaMimeType( 565 bool IsSupportedKeySystemWithMediaMimeType(
492 const std::string& mime_type, 566 const std::string& mime_type,
493 const std::vector<std::string>& codecs, 567 const std::vector<std::string>& codecs,
494 const std::string& key_system) { 568 const std::string& key_system) {
495 return KeySystems::GetInstance().IsSupportedKeySystemWithMediaMimeType( 569 return KeySystems::GetInstance().IsSupportedKeySystemWithMediaMimeType(
496 mime_type, codecs, key_system); 570 mime_type, codecs, key_system);
497 } 571 }
498 572
499 std::string KeySystemNameForUMA(const std::string& key_system) { 573 std::string KeySystemNameForUMA(const std::string& key_system) {
500 if (key_system == kClearKeyKeySystem) 574 if (key_system == kClearKeyKeySystem)
(...skipping 24 matching lines...) Expand all
525 CONTENT_EXPORT void AddContainerMask(const std::string& container, 599 CONTENT_EXPORT void AddContainerMask(const std::string& container,
526 uint32 mask) { 600 uint32 mask) {
527 KeySystems::GetInstance().AddContainerMask(container, mask); 601 KeySystems::GetInstance().AddContainerMask(container, mask);
528 } 602 }
529 603
530 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { 604 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) {
531 KeySystems::GetInstance().AddCodecMask(codec, mask); 605 KeySystems::GetInstance().AddCodecMask(codec, mask);
532 } 606 }
533 607
534 } // namespace content 608 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698