OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/key_systems.h" | 5 #include "media/base/key_systems.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 void RegisterMimeType(const std::string& mime_type, EmeCodec codecs_mask); | 228 void RegisterMimeType(const std::string& mime_type, EmeCodec codecs_mask); |
229 bool IsValidMimeTypeCodecsCombination(const std::string& mime_type, | 229 bool IsValidMimeTypeCodecsCombination(const std::string& mime_type, |
230 SupportedCodecs codecs_mask) const; | 230 SupportedCodecs codecs_mask) const; |
231 | 231 |
232 typedef base::hash_map<std::string, std::unique_ptr<KeySystemProperties>> | 232 typedef base::hash_map<std::string, std::unique_ptr<KeySystemProperties>> |
233 KeySystemPropertiesMap; | 233 KeySystemPropertiesMap; |
234 typedef base::hash_map<std::string, SupportedCodecs> MimeTypeCodecsMap; | 234 typedef base::hash_map<std::string, SupportedCodecs> MimeTypeCodecsMap; |
235 typedef base::hash_map<std::string, EmeCodec> CodecsMap; | 235 typedef base::hash_map<std::string, EmeCodec> CodecsMap; |
236 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap; | 236 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap; |
237 typedef base::hash_map<std::string, std::string> KeySystemNameForUMAMap; | |
238 | 237 |
239 // TODO(sandersd): Separate container enum from codec mask value. | 238 // TODO(sandersd): Separate container enum from codec mask value. |
240 // http://crbug.com/417440 | 239 // http://crbug.com/417440 |
241 // Potentially pass EmeMediaType and a container enum. | 240 // Potentially pass EmeMediaType and a container enum. |
242 SupportedCodecs GetCodecMaskForMimeType( | 241 SupportedCodecs GetCodecMaskForMimeType( |
243 const std::string& container_mime_type) const; | 242 const std::string& container_mime_type) const; |
244 EmeCodec GetCodecForString(const std::string& codec) const; | 243 EmeCodec GetCodecForString(const std::string& codec) const; |
245 | 244 |
246 // Map from key system string to KeySystemProperties instance. | 245 // Map from key system string to KeySystemProperties instance. |
247 KeySystemPropertiesMap key_system_properties_map_; | 246 KeySystemPropertiesMap key_system_properties_map_; |
248 | 247 |
249 // This member should only be modified by RegisterMimeType(). | 248 // This member should only be modified by RegisterMimeType(). |
250 MimeTypeCodecsMap mime_type_to_codec_mask_map_; | 249 MimeTypeCodecsMap mime_type_to_codec_mask_map_; |
251 CodecsMap codec_string_map_; | 250 CodecsMap codec_string_map_; |
252 KeySystemNameForUMAMap key_system_name_for_uma_map_; | |
253 | 251 |
254 SupportedCodecs audio_codec_mask_; | 252 SupportedCodecs audio_codec_mask_; |
255 SupportedCodecs video_codec_mask_; | 253 SupportedCodecs video_codec_mask_; |
256 | 254 |
257 // Makes sure all methods are called from the same thread. | 255 // Makes sure all methods are called from the same thread. |
258 base::ThreadChecker thread_checker_; | 256 base::ThreadChecker thread_checker_; |
259 | 257 |
260 DISALLOW_COPY_AND_ASSIGN(KeySystemsImpl); | 258 DISALLOW_COPY_AND_ASSIGN(KeySystemsImpl); |
261 }; | 259 }; |
262 | 260 |
(...skipping 11 matching lines...) Expand all Loading... |
274 for (size_t i = 0; i < arraysize(kCodecStrings); ++i) { | 272 for (size_t i = 0; i < arraysize(kCodecStrings); ++i) { |
275 const std::string& name = kCodecStrings[i].name; | 273 const std::string& name = kCodecStrings[i].name; |
276 DCHECK(!codec_string_map_.count(name)); | 274 DCHECK(!codec_string_map_.count(name)); |
277 codec_string_map_[name] = kCodecStrings[i].type; | 275 codec_string_map_[name] = kCodecStrings[i].type; |
278 } | 276 } |
279 for (size_t i = 0; i < arraysize(kMimeTypeToCodecMasks); ++i) { | 277 for (size_t i = 0; i < arraysize(kMimeTypeToCodecMasks); ++i) { |
280 RegisterMimeType(kMimeTypeToCodecMasks[i].name, | 278 RegisterMimeType(kMimeTypeToCodecMasks[i].name, |
281 kMimeTypeToCodecMasks[i].type); | 279 kMimeTypeToCodecMasks[i].type); |
282 } | 280 } |
283 | 281 |
284 InitializeUMAInfo(); | |
285 | |
286 // Always update supported key systems during construction. | 282 // Always update supported key systems during construction. |
287 UpdateSupportedKeySystems(); | 283 UpdateSupportedKeySystems(); |
288 } | 284 } |
289 | 285 |
290 KeySystemsImpl::~KeySystemsImpl() { | 286 KeySystemsImpl::~KeySystemsImpl() { |
291 } | 287 } |
292 | 288 |
293 SupportedCodecs KeySystemsImpl::GetCodecMaskForMimeType( | 289 SupportedCodecs KeySystemsImpl::GetCodecMaskForMimeType( |
294 const std::string& container_mime_type) const { | 290 const std::string& container_mime_type) const { |
295 MimeTypeCodecsMap::const_iterator iter = | 291 MimeTypeCodecsMap::const_iterator iter = |
296 mime_type_to_codec_mask_map_.find(container_mime_type); | 292 mime_type_to_codec_mask_map_.find(container_mime_type); |
297 if (iter == mime_type_to_codec_mask_map_.end()) | 293 if (iter == mime_type_to_codec_mask_map_.end()) |
298 return EME_CODEC_NONE; | 294 return EME_CODEC_NONE; |
299 | 295 |
300 DCHECK(IsValidMimeTypeCodecsCombination(container_mime_type, iter->second)); | 296 DCHECK(IsValidMimeTypeCodecsCombination(container_mime_type, iter->second)); |
301 return iter->second; | 297 return iter->second; |
302 } | 298 } |
303 | 299 |
304 EmeCodec KeySystemsImpl::GetCodecForString(const std::string& codec) const { | 300 EmeCodec KeySystemsImpl::GetCodecForString(const std::string& codec) const { |
305 CodecsMap::const_iterator iter = codec_string_map_.find(codec); | 301 CodecsMap::const_iterator iter = codec_string_map_.find(codec); |
306 if (iter != codec_string_map_.end()) | 302 if (iter != codec_string_map_.end()) |
307 return iter->second; | 303 return iter->second; |
308 return EME_CODEC_NONE; | 304 return EME_CODEC_NONE; |
309 } | 305 } |
310 | 306 |
311 void KeySystemsImpl::InitializeUMAInfo() { | |
312 DCHECK(thread_checker_.CalledOnValidThread()); | |
313 DCHECK(key_system_name_for_uma_map_.empty()); | |
314 | |
315 std::vector<KeySystemInfoForUMA> key_systems_info_for_uma; | |
316 if (GetMediaClient()) | |
317 GetMediaClient()->AddKeySystemsInfoForUMA(&key_systems_info_for_uma); | |
318 | |
319 for (const KeySystemInfoForUMA& info : key_systems_info_for_uma) { | |
320 key_system_name_for_uma_map_[info.key_system] = | |
321 info.key_system_name_for_uma; | |
322 } | |
323 | |
324 // Clear Key is always supported. | |
325 key_system_name_for_uma_map_[kClearKeyKeySystem] = | |
326 kClearKeyKeySystemNameForUMA; | |
327 } | |
328 | |
329 void KeySystemsImpl::UpdateIfNeeded() { | 307 void KeySystemsImpl::UpdateIfNeeded() { |
330 if (GetMediaClient() && GetMediaClient()->IsKeySystemsUpdateNeeded()) | 308 if (GetMediaClient() && GetMediaClient()->IsKeySystemsUpdateNeeded()) |
331 UpdateSupportedKeySystems(); | 309 UpdateSupportedKeySystems(); |
332 } | 310 } |
333 | 311 |
334 void KeySystemsImpl::UpdateSupportedKeySystems() { | 312 void KeySystemsImpl::UpdateSupportedKeySystems() { |
335 DCHECK(thread_checker_.CalledOnValidThread()); | 313 DCHECK(thread_checker_.CalledOnValidThread()); |
336 key_system_properties_map_.clear(); | 314 key_system_properties_map_.clear(); |
337 | 315 |
338 std::vector<std::unique_ptr<KeySystemProperties>> key_systems_properties; | 316 std::vector<std::unique_ptr<KeySystemProperties>> key_systems_properties; |
339 | 317 |
340 // Add key systems supported by the MediaClient implementation. | 318 // Add key systems supported by the MediaClient implementation. |
341 if (GetMediaClient()) | 319 if (GetMediaClient()) { |
342 GetMediaClient()->AddSupportedKeySystems(&key_systems_properties); | 320 GetMediaClient()->AddSupportedKeySystems(&key_systems_properties); |
| 321 } else { |
| 322 DVLOG(1) << __func__ << " No media client to provide key systems"; |
| 323 } |
343 | 324 |
344 // Clear Key is always supported. | 325 // Clear Key is always supported. |
345 key_systems_properties.emplace_back(new ClearKeyProperties()); | 326 key_systems_properties.emplace_back(new ClearKeyProperties()); |
346 | 327 |
347 AddSupportedKeySystems(&key_systems_properties); | 328 AddSupportedKeySystems(&key_systems_properties); |
348 } | 329 } |
349 | 330 |
350 // Returns whether distinctive identifiers and persistent state can be reliably | 331 // Returns whether distinctive identifiers and persistent state can be reliably |
351 // blocked for |properties| (and therefore be safely configurable). | 332 // blocked for |properties| (and therefore be safely configurable). |
352 static bool CanBlock(const KeySystemProperties& properties) { | 333 static bool CanBlock(const KeySystemProperties& properties) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 417 |
437 #if defined(OS_ANDROID) | 418 #if defined(OS_ANDROID) |
438 // Ensure that the renderer can access the decoders necessary to use the | 419 // Ensure that the renderer can access the decoders necessary to use the |
439 // key system. | 420 // key system. |
440 if (!properties->UseAesDecryptor() && !HasPlatformDecoderSupport()) { | 421 if (!properties->UseAesDecryptor() && !HasPlatformDecoderSupport()) { |
441 DLOG(WARNING) << properties->GetKeySystemName() << " not registered"; | 422 DLOG(WARNING) << properties->GetKeySystemName() << " not registered"; |
442 continue; | 423 continue; |
443 } | 424 } |
444 #endif // defined(OS_ANDROID) | 425 #endif // defined(OS_ANDROID) |
445 | 426 |
| 427 DVLOG(1) << __func__ |
| 428 << " Adding key system:" << properties->GetKeySystemName(); |
446 key_system_properties_map_[properties->GetKeySystemName()] = | 429 key_system_properties_map_[properties->GetKeySystemName()] = |
447 std::move(properties); | 430 std::move(properties); |
448 } | 431 } |
449 } | 432 } |
450 | 433 |
451 // Adds the MIME type with the codec mask after verifying the validity. | 434 // Adds the MIME type with the codec mask after verifying the validity. |
452 // Only this function should modify |mime_type_to_codec_mask_map_|. | 435 // Only this function should modify |mime_type_to_codec_mask_map_|. |
453 void KeySystemsImpl::RegisterMimeType(const std::string& mime_type, | 436 void KeySystemsImpl::RegisterMimeType(const std::string& mime_type, |
454 EmeCodec codecs_mask) { | 437 EmeCodec codecs_mask) { |
455 DCHECK(thread_checker_.CalledOnValidThread()); | 438 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 NOTREACHED(); | 470 NOTREACHED(); |
488 return false; | 471 return false; |
489 } | 472 } |
490 return key_system_iter->second->IsSupportedInitDataType(init_data_type); | 473 return key_system_iter->second->IsSupportedInitDataType(init_data_type); |
491 } | 474 } |
492 | 475 |
493 std::string KeySystemsImpl::GetKeySystemNameForUMA( | 476 std::string KeySystemsImpl::GetKeySystemNameForUMA( |
494 const std::string& key_system) const { | 477 const std::string& key_system) const { |
495 DCHECK(thread_checker_.CalledOnValidThread()); | 478 DCHECK(thread_checker_.CalledOnValidThread()); |
496 | 479 |
497 KeySystemNameForUMAMap::const_iterator iter = | 480 // Here we maintain a short list of known key systems to facilitate UMA |
498 key_system_name_for_uma_map_.find(key_system); | 481 // reporting. Mentioned key systems are not necessarily supported by |
499 if (iter == key_system_name_for_uma_map_.end()) | 482 // the current platform. |
500 return kUnknownKeySystemNameForUMA; | 483 if (key_system == kWidevineKeySystem) |
| 484 return kWidevineKeySystemNameForUMA; |
501 | 485 |
502 return iter->second; | 486 if (key_system == kClearKeyKeySystem) |
| 487 return kClearKeyKeySystemNameForUMA; |
| 488 |
| 489 return kUnknownKeySystemNameForUMA; |
503 } | 490 } |
504 | 491 |
505 bool KeySystemsImpl::UseAesDecryptor(const std::string& key_system) const { | 492 bool KeySystemsImpl::UseAesDecryptor(const std::string& key_system) const { |
506 DCHECK(thread_checker_.CalledOnValidThread()); | 493 DCHECK(thread_checker_.CalledOnValidThread()); |
507 | 494 |
508 KeySystemPropertiesMap::const_iterator key_system_iter = | 495 KeySystemPropertiesMap::const_iterator key_system_iter = |
509 key_system_properties_map_.find(key_system); | 496 key_system_properties_map_.find(key_system); |
510 if (key_system_iter == key_system_properties_map_.end()) { | 497 if (key_system_iter == key_system_properties_map_.end()) { |
511 DLOG(ERROR) << key_system << " is not a known system"; | 498 DLOG(ERROR) << key_system << " is not a known system"; |
512 return false; | 499 return false; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 uint32_t mask) { | 723 uint32_t mask) { |
737 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); | 724 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); |
738 } | 725 } |
739 | 726 |
740 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, | 727 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, |
741 uint32_t mask) { | 728 uint32_t mask) { |
742 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); | 729 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); |
743 } | 730 } |
744 | 731 |
745 } // namespace media | 732 } // namespace media |
OLD | NEW |