| 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 <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" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 bool IsSupportedKeySystem(const std::string& key_system); | 114 bool IsSupportedKeySystem(const std::string& key_system); |
| 115 | 115 |
| 116 bool IsSupportedKeySystemWithInitDataType( | 116 bool IsSupportedKeySystemWithInitDataType( |
| 117 const std::string& key_system, | 117 const std::string& key_system, |
| 118 const std::string& init_data_type); | 118 const std::string& init_data_type); |
| 119 | 119 |
| 120 bool IsSupportedKeySystemWithMediaMimeType( | 120 bool IsSupportedKeySystemWithMediaMimeType( |
| 121 const std::string& mime_type, | 121 const std::string& mime_type, |
| 122 const std::vector<std::string>& codecs, | 122 const std::vector<std::string>& codecs, |
| 123 const std::string& key_system, | 123 const std::string& key_system, |
| 124 bool reportToUma); | 124 bool is_prefixed); |
| 125 | 125 |
| 126 std::string GetKeySystemNameForUMA(const std::string& key_system) const; | 126 std::string GetKeySystemNameForUMA(const std::string& key_system) const; |
| 127 | 127 |
| 128 bool UseAesDecryptor(const std::string& concrete_key_system); | 128 bool UseAesDecryptor(const std::string& concrete_key_system); |
| 129 | 129 |
| 130 #if defined(ENABLE_PEPPER_CDMS) | 130 #if defined(ENABLE_PEPPER_CDMS) |
| 131 std::string GetPepperType(const std::string& concrete_key_system); | 131 std::string GetPepperType(const std::string& concrete_key_system); |
| 132 #endif | 132 #endif |
| 133 | 133 |
| 134 void AddContainerMask(const std::string& container, uint32 mask); | 134 void AddContainerMask(const std::string& container, uint32 mask); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 ~KeySystems() {} | 178 ~KeySystems() {} |
| 179 | 179 |
| 180 EmeInitDataType GetInitDataTypeForName( | 180 EmeInitDataType GetInitDataTypeForName( |
| 181 const std::string& init_data_type) const; | 181 const std::string& init_data_type) const; |
| 182 // TODO(sandersd): Separate container enum from codec mask value. | 182 // TODO(sandersd): Separate container enum from codec mask value. |
| 183 // http://crbug.com/417440 | 183 // http://crbug.com/417440 |
| 184 SupportedCodecs GetCodecMaskForContainer( | 184 SupportedCodecs GetCodecMaskForContainer( |
| 185 const std::string& container) const; | 185 const std::string& container) const; |
| 186 EmeCodec GetCodecForString(const std::string& codec) const; | 186 EmeCodec GetCodecForString(const std::string& codec) const; |
| 187 | 187 |
| 188 const std::string& GetConcreteKeySystemName( | 188 const std::string& PrefixedGetConcreteKeySystemNameFor( |
| 189 const std::string& key_system) const; | 189 const std::string& key_system) const; |
| 190 | 190 |
| 191 // Returns whether a |container| type is supported by checking | 191 // Returns whether a |container| type is supported by checking |
| 192 // |key_system_supported_codecs|. | 192 // |key_system_supported_codecs|. |
| 193 // TODO(xhwang): Update this to actually check initDataType support. | 193 // TODO(xhwang): Update this to actually check initDataType support. |
| 194 bool IsSupportedContainer(const std::string& container, | 194 bool IsSupportedContainer(const std::string& container, |
| 195 SupportedCodecs key_system_supported_codecs) const; | 195 SupportedCodecs key_system_supported_codecs) const; |
| 196 | 196 |
| 197 // Returns true if all |codecs| are supported in |container| by checking | 197 // Returns true if all |codecs| are supported in |container| by checking |
| 198 // |key_system_supported_codecs|. | 198 // |key_system_supported_codecs|. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 return EME_CODEC_NONE; | 272 return EME_CODEC_NONE; |
| 273 } | 273 } |
| 274 | 274 |
| 275 EmeCodec KeySystems::GetCodecForString(const std::string& codec) const { | 275 EmeCodec KeySystems::GetCodecForString(const std::string& codec) const { |
| 276 CodecsMap::const_iterator iter = codec_string_map_.find(codec); | 276 CodecsMap::const_iterator iter = codec_string_map_.find(codec); |
| 277 if (iter != codec_string_map_.end()) | 277 if (iter != codec_string_map_.end()) |
| 278 return iter->second; | 278 return iter->second; |
| 279 return EME_CODEC_NONE; | 279 return EME_CODEC_NONE; |
| 280 } | 280 } |
| 281 | 281 |
| 282 const std::string& KeySystems::GetConcreteKeySystemName( | 282 const std::string& KeySystems::PrefixedGetConcreteKeySystemNameFor( |
| 283 const std::string& key_system) const { | 283 const std::string& key_system) const { |
| 284 ParentKeySystemMap::const_iterator iter = | 284 ParentKeySystemMap::const_iterator iter = |
| 285 parent_key_system_map_.find(key_system); | 285 parent_key_system_map_.find(key_system); |
| 286 if (iter != parent_key_system_map_.end()) | 286 if (iter != parent_key_system_map_.end()) |
| 287 return iter->second; | 287 return iter->second; |
| 288 return key_system; | 288 return key_system; |
| 289 } | 289 } |
| 290 | 290 |
| 291 void KeySystems::InitializeUMAInfo() { | 291 void KeySystems::InitializeUMAInfo() { |
| 292 DCHECK(thread_checker_.CalledOnValidThread()); | 292 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 // Unsupported codec/container combination, e.g. "video/webm" and "avc1". | 439 // Unsupported codec/container combination, e.g. "video/webm" and "avc1". |
| 440 if (!(codec & container_supported_codecs)) | 440 if (!(codec & container_supported_codecs)) |
| 441 return false; | 441 return false; |
| 442 } | 442 } |
| 443 | 443 |
| 444 return true; | 444 return true; |
| 445 } | 445 } |
| 446 | 446 |
| 447 bool KeySystems::IsSupportedKeySystem(const std::string& key_system) { | 447 bool KeySystems::IsSupportedKeySystem(const std::string& key_system) { |
| 448 DCHECK(thread_checker_.CalledOnValidThread()); | 448 DCHECK(thread_checker_.CalledOnValidThread()); |
| 449 return (concrete_key_system_map_.count(key_system) || | 449 // Unprefixed EME only supports concrete key systems. |
| 450 parent_key_system_map_.count(key_system)); | 450 return concrete_key_system_map_.count(key_system) != 0; |
| 451 } | 451 } |
| 452 | 452 |
| 453 bool KeySystems::IsSupportedKeySystemWithInitDataType( | 453 bool KeySystems::IsSupportedKeySystemWithInitDataType( |
| 454 const std::string& key_system, | 454 const std::string& key_system, |
| 455 const std::string& init_data_type) { | 455 const std::string& init_data_type) { |
| 456 DCHECK(thread_checker_.CalledOnValidThread()); | 456 DCHECK(thread_checker_.CalledOnValidThread()); |
| 457 | 457 |
| 458 // If |key_system| is a parent key system, use its concrete child. | 458 // Locate |key_system|. Only concrete key systems are supported in unprefixed. |
| 459 const std::string& concrete_key_system = GetConcreteKeySystemName(key_system); | |
| 460 | |
| 461 // Locate |concrete_key_system|. | |
| 462 KeySystemPropertiesMap::const_iterator key_system_iter = | 459 KeySystemPropertiesMap::const_iterator key_system_iter = |
| 463 concrete_key_system_map_.find(concrete_key_system); | 460 concrete_key_system_map_.find(key_system); |
| 464 if (key_system_iter == concrete_key_system_map_.end()) | 461 if (key_system_iter == concrete_key_system_map_.end()) |
| 465 return false; | 462 return false; |
| 466 | 463 |
| 467 // Check |init_data_type| and |key_system| x |init_data_type|. | 464 // Check |init_data_type| and |key_system| x |init_data_type|. |
| 468 const KeySystemProperties& properties = key_system_iter->second; | 465 const KeySystemProperties& properties = key_system_iter->second; |
| 469 EmeInitDataType eme_init_data_type = GetInitDataTypeForName(init_data_type); | 466 EmeInitDataType eme_init_data_type = GetInitDataTypeForName(init_data_type); |
| 470 return (properties.supported_init_data_types & eme_init_data_type) != 0; | 467 return (properties.supported_init_data_types & eme_init_data_type) != 0; |
| 471 } | 468 } |
| 472 | 469 |
| 473 // TODO(sandersd): Reorganize to be more similar to | 470 // TODO(sandersd): Reorganize to be more similar to |
| 474 // IsKeySystemSupportedWithInitDataType(). Note that a fork may still be | 471 // IsKeySystemSupportedWithInitDataType(). Note that a fork may still be |
| 475 // required; http://crbug.com/417461. | 472 // required; http://crbug.com/417461. |
| 476 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( | 473 bool KeySystems::IsSupportedKeySystemWithMediaMimeType( |
| 477 const std::string& mime_type, | 474 const std::string& mime_type, |
| 478 const std::vector<std::string>& codecs, | 475 const std::vector<std::string>& codecs, |
| 479 const std::string& key_system, | 476 const std::string& key_system, |
| 480 bool reportToUma) { | 477 bool is_prefixed) { |
| 481 DCHECK(thread_checker_.CalledOnValidThread()); | 478 DCHECK(thread_checker_.CalledOnValidThread()); |
| 479 const bool report_to_uma = is_prefixed; |
| 482 | 480 |
| 483 // If |key_system| is a parent key system, use its concrete child. | 481 // If |is_prefixed| and |key_system| is a parent key system, use its concrete |
| 484 const std::string& concrete_key_system = GetConcreteKeySystemName(key_system); | 482 // child. |
| 483 const std::string& concrete_key_system = is_prefixed ? |
| 484 PrefixedGetConcreteKeySystemNameFor(key_system) : |
| 485 key_system; |
| 485 | 486 |
| 486 bool has_type = !mime_type.empty(); | 487 bool has_type = !mime_type.empty(); |
| 487 | 488 |
| 488 if (reportToUma) | 489 if (report_to_uma) |
| 489 key_systems_support_uma_.ReportKeySystemQuery(key_system, has_type); | 490 key_systems_support_uma_.ReportKeySystemQuery(key_system, has_type); |
| 490 | 491 |
| 491 // Check key system support. | 492 // Check key system support. |
| 492 KeySystemPropertiesMap::const_iterator key_system_iter = | 493 KeySystemPropertiesMap::const_iterator key_system_iter = |
| 493 concrete_key_system_map_.find(concrete_key_system); | 494 concrete_key_system_map_.find(concrete_key_system); |
| 494 if (key_system_iter == concrete_key_system_map_.end()) | 495 if (key_system_iter == concrete_key_system_map_.end()) |
| 495 return false; | 496 return false; |
| 496 | 497 |
| 497 if (reportToUma) | 498 if (report_to_uma) |
| 498 key_systems_support_uma_.ReportKeySystemSupport(key_system, false); | 499 key_systems_support_uma_.ReportKeySystemSupport(key_system, false); |
| 499 | 500 |
| 500 if (!has_type) { | 501 if (!has_type) { |
| 501 DCHECK(codecs.empty()); | 502 DCHECK(codecs.empty()); |
| 502 return true; | 503 return true; |
| 503 } | 504 } |
| 504 | 505 |
| 505 SupportedCodecs key_system_supported_codecs = | 506 SupportedCodecs key_system_supported_codecs = |
| 506 key_system_iter->second.supported_codecs; | 507 key_system_iter->second.supported_codecs; |
| 507 | 508 |
| 508 if (!IsSupportedContainer(mime_type, key_system_supported_codecs)) | 509 if (!IsSupportedContainer(mime_type, key_system_supported_codecs)) |
| 509 return false; | 510 return false; |
| 510 | 511 |
| 511 if (!codecs.empty() && | 512 if (!codecs.empty() && |
| 512 !IsSupportedContainerAndCodecs( | 513 !IsSupportedContainerAndCodecs( |
| 513 mime_type, codecs, key_system_supported_codecs)) { | 514 mime_type, codecs, key_system_supported_codecs)) { |
| 514 return false; | 515 return false; |
| 515 } | 516 } |
| 516 | 517 |
| 517 if (reportToUma) | 518 if (report_to_uma) |
| 518 key_systems_support_uma_.ReportKeySystemSupport(key_system, true); | 519 key_systems_support_uma_.ReportKeySystemSupport(key_system, true); |
| 519 return true; | 520 return true; |
| 520 } | 521 } |
| 521 | 522 |
| 522 std::string KeySystems::GetKeySystemNameForUMA( | 523 std::string KeySystems::GetKeySystemNameForUMA( |
| 523 const std::string& key_system) const { | 524 const std::string& key_system) const { |
| 524 DCHECK(thread_checker_.CalledOnValidThread()); | 525 DCHECK(thread_checker_.CalledOnValidThread()); |
| 525 | 526 |
| 526 KeySystemNameForUMAMap::const_iterator iter = | 527 KeySystemNameForUMAMap::const_iterator iter = |
| 527 key_system_name_for_uma_map_.find(key_system); | 528 key_system_name_for_uma_map_.find(key_system); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 const std::string& container) { | 600 const std::string& container) { |
| 600 if (init_data_type == "cenc") { | 601 if (init_data_type == "cenc") { |
| 601 return container == "audio/mp4" || container == "video/mp4"; | 602 return container == "audio/mp4" || container == "video/mp4"; |
| 602 } else if (init_data_type == "webm") { | 603 } else if (init_data_type == "webm") { |
| 603 return container == "audio/webm" || container == "video/webm"; | 604 return container == "audio/webm" || container == "video/webm"; |
| 604 } else { | 605 } else { |
| 605 return true; | 606 return true; |
| 606 } | 607 } |
| 607 } | 608 } |
| 608 | 609 |
| 609 bool IsConcreteSupportedKeySystem(const std::string& key_system) { | 610 bool PrefixedIsSupportedConcreteKeySystem(const std::string& key_system) { |
| 610 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system); | 611 return KeySystems::GetInstance().IsConcreteSupportedKeySystem(key_system); |
| 611 } | 612 } |
| 612 | 613 |
| 613 bool IsSupportedKeySystem(const std::string& key_system) { | 614 bool IsSupportedKeySystem(const std::string& key_system) { |
| 614 return KeySystems::GetInstance().IsSupportedKeySystem(key_system); | 615 return KeySystems::GetInstance().IsSupportedKeySystem(key_system); |
| 615 } | 616 } |
| 616 | 617 |
| 617 bool IsSupportedKeySystemWithInitDataType( | 618 bool IsSupportedKeySystemWithInitDataType( |
| 618 const std::string& key_system, | 619 const std::string& key_system, |
| 619 const std::string& init_data_type) { | 620 const std::string& init_data_type) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 MEDIA_EXPORT void AddContainerMask(const std::string& container, | 661 MEDIA_EXPORT void AddContainerMask(const std::string& container, |
| 661 uint32 mask) { | 662 uint32 mask) { |
| 662 KeySystems::GetInstance().AddContainerMask(container, mask); | 663 KeySystems::GetInstance().AddContainerMask(container, mask); |
| 663 } | 664 } |
| 664 | 665 |
| 665 MEDIA_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { | 666 MEDIA_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { |
| 666 KeySystems::GetInstance().AddCodecMask(codec, mask); | 667 KeySystems::GetInstance().AddCodecMask(codec, mask); |
| 667 } | 668 } |
| 668 | 669 |
| 669 } // namespace media | 670 } // namespace media |
| OLD | NEW |