| 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 "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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 return EmeRobustness::SW_SECURE_DECODE; | 68 return EmeRobustness::SW_SECURE_DECODE; |
| 69 if (robustness == "HW_SECURE_CRYPTO") | 69 if (robustness == "HW_SECURE_CRYPTO") |
| 70 return EmeRobustness::HW_SECURE_CRYPTO; | 70 return EmeRobustness::HW_SECURE_CRYPTO; |
| 71 if (robustness == "HW_SECURE_DECODE") | 71 if (robustness == "HW_SECURE_DECODE") |
| 72 return EmeRobustness::HW_SECURE_DECODE; | 72 return EmeRobustness::HW_SECURE_DECODE; |
| 73 if (robustness == "HW_SECURE_ALL") | 73 if (robustness == "HW_SECURE_ALL") |
| 74 return EmeRobustness::HW_SECURE_ALL; | 74 return EmeRobustness::HW_SECURE_ALL; |
| 75 return EmeRobustness::INVALID; | 75 return EmeRobustness::INVALID; |
| 76 } | 76 } |
| 77 | 77 |
| 78 // TODO(ddorwin): Remove reference to "concrete" key systems. crbug.com/249976. | 78 static void AddClearKey(std::vector<KeySystemInfo>* key_systems) { |
| 79 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 80 KeySystemInfo info; | 79 KeySystemInfo info; |
| 81 info.key_system = kClearKeyKeySystem; | 80 info.key_system = kClearKeyKeySystem; |
| 82 | 81 |
| 83 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: | 82 // On Android, Vorbis, VP8, AAC and AVC1 are supported in MediaCodec: |
| 84 // http://developer.android.com/guide/appendix/media-formats.html | 83 // http://developer.android.com/guide/appendix/media-formats.html |
| 85 // VP9 support is device dependent. | 84 // VP9 support is device dependent. |
| 86 | 85 |
| 87 info.supported_init_data_types = | 86 info.supported_init_data_types = |
| 88 kInitDataTypeMaskWebM | kInitDataTypeMaskKeyIds; | 87 kInitDataTypeMaskWebM | kInitDataTypeMaskKeyIds; |
| 89 info.supported_codecs = EME_CODEC_WEBM_ALL; | 88 info.supported_codecs = EME_CODEC_WEBM_ALL; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 info.max_audio_robustness = EmeRobustness::EMPTY; | 105 info.max_audio_robustness = EmeRobustness::EMPTY; |
| 107 info.max_video_robustness = EmeRobustness::EMPTY; | 106 info.max_video_robustness = EmeRobustness::EMPTY; |
| 108 info.persistent_license_support = EmeSessionTypeSupport::NOT_SUPPORTED; | 107 info.persistent_license_support = EmeSessionTypeSupport::NOT_SUPPORTED; |
| 109 info.persistent_release_message_support = | 108 info.persistent_release_message_support = |
| 110 EmeSessionTypeSupport::NOT_SUPPORTED; | 109 EmeSessionTypeSupport::NOT_SUPPORTED; |
| 111 info.persistent_state_support = EmeFeatureSupport::NOT_SUPPORTED; | 110 info.persistent_state_support = EmeFeatureSupport::NOT_SUPPORTED; |
| 112 info.distinctive_identifier_support = EmeFeatureSupport::NOT_SUPPORTED; | 111 info.distinctive_identifier_support = EmeFeatureSupport::NOT_SUPPORTED; |
| 113 | 112 |
| 114 info.use_aes_decryptor = true; | 113 info.use_aes_decryptor = true; |
| 115 | 114 |
| 116 concrete_key_systems->push_back(info); | 115 key_systems->push_back(info); |
| 117 } | 116 } |
| 118 | 117 |
| 119 // Returns whether the |key_system| is known to Chromium and is thus likely to | 118 // Returns whether the |key_system| is known to Chromium and is thus likely to |
| 120 // be implemented in an interoperable way. | 119 // be implemented in an interoperable way. |
| 121 // True is always returned for a |key_system| that begins with "x-". | 120 // True is always returned for a |key_system| that begins with "x-". |
| 122 // | 121 // |
| 123 // As with other web platform features, advertising support for a key system | 122 // As with other web platform features, advertising support for a key system |
| 124 // implies that it adheres to a defined and interoperable specification. | 123 // implies that it adheres to a defined and interoperable specification. |
| 125 // | 124 // |
| 126 // To ensure interoperability, implementations of a specific |key_system| string | 125 // To ensure interoperability, implementations of a specific |key_system| string |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 164 |
| 166 return false; | 165 return false; |
| 167 } | 166 } |
| 168 | 167 |
| 169 class KeySystemsImpl : public KeySystems { | 168 class KeySystemsImpl : public KeySystems { |
| 170 public: | 169 public: |
| 171 static KeySystemsImpl* GetInstance(); | 170 static KeySystemsImpl* GetInstance(); |
| 172 | 171 |
| 173 void UpdateIfNeeded(); | 172 void UpdateIfNeeded(); |
| 174 | 173 |
| 175 bool IsConcreteSupportedKeySystem(const std::string& key_system) const; | |
| 176 | |
| 177 std::string GetKeySystemNameForUMA(const std::string& key_system) const; | 174 std::string GetKeySystemNameForUMA(const std::string& key_system) const; |
| 178 | 175 |
| 179 bool UseAesDecryptor(const std::string& concrete_key_system) const; | 176 bool UseAesDecryptor(const std::string& key_system) const; |
| 180 | 177 |
| 181 #if defined(ENABLE_PEPPER_CDMS) | 178 #if defined(ENABLE_PEPPER_CDMS) |
| 182 std::string GetPepperType(const std::string& concrete_key_system) const; | 179 std::string GetPepperType(const std::string& key_system) const; |
| 183 #endif | 180 #endif |
| 184 | 181 |
| 185 // These two functions are for testing purpose only. | 182 // These two functions are for testing purpose only. |
| 186 void AddCodecMask(EmeMediaType media_type, | 183 void AddCodecMask(EmeMediaType media_type, |
| 187 const std::string& codec, | 184 const std::string& codec, |
| 188 uint32_t mask); | 185 uint32_t mask); |
| 189 void AddMimeTypeCodecMask(const std::string& mime_type, uint32_t mask); | 186 void AddMimeTypeCodecMask(const std::string& mime_type, uint32_t mask); |
| 190 | 187 |
| 191 // Implementation of KeySystems interface. | 188 // Implementation of KeySystems interface. |
| 192 bool IsSupportedKeySystem(const std::string& key_system) const override; | 189 bool IsSupportedKeySystem(const std::string& key_system) const override; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 218 const std::string& key_system) const override; | 215 const std::string& key_system) const override; |
| 219 | 216 |
| 220 private: | 217 private: |
| 221 KeySystemsImpl(); | 218 KeySystemsImpl(); |
| 222 ~KeySystemsImpl() override; | 219 ~KeySystemsImpl() override; |
| 223 | 220 |
| 224 void InitializeUMAInfo(); | 221 void InitializeUMAInfo(); |
| 225 | 222 |
| 226 void UpdateSupportedKeySystems(); | 223 void UpdateSupportedKeySystems(); |
| 227 | 224 |
| 228 void AddConcreteSupportedKeySystems( | 225 void AddSupportedKeySystems(const std::vector<KeySystemInfo>& key_systems); |
| 229 const std::vector<KeySystemInfo>& concrete_key_systems); | |
| 230 | 226 |
| 231 void RegisterMimeType(const std::string& mime_type, EmeCodec codecs_mask); | 227 void RegisterMimeType(const std::string& mime_type, EmeCodec codecs_mask); |
| 232 bool IsValidMimeTypeCodecsCombination(const std::string& mime_type, | 228 bool IsValidMimeTypeCodecsCombination(const std::string& mime_type, |
| 233 SupportedCodecs codecs_mask) const; | 229 SupportedCodecs codecs_mask) const; |
| 234 | 230 |
| 235 friend struct base::DefaultLazyInstanceTraits<KeySystemsImpl>; | 231 friend struct base::DefaultLazyInstanceTraits<KeySystemsImpl>; |
| 236 | 232 |
| 237 typedef base::hash_map<std::string, KeySystemInfo> KeySystemInfoMap; | 233 typedef base::hash_map<std::string, KeySystemInfo> KeySystemInfoMap; |
| 238 typedef base::hash_map<std::string, SupportedCodecs> MimeTypeCodecsMap; | 234 typedef base::hash_map<std::string, SupportedCodecs> MimeTypeCodecsMap; |
| 239 typedef base::hash_map<std::string, EmeCodec> CodecsMap; | 235 typedef base::hash_map<std::string, EmeCodec> CodecsMap; |
| 240 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap; | 236 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap; |
| 241 typedef base::hash_map<std::string, std::string> KeySystemNameForUMAMap; | 237 typedef base::hash_map<std::string, std::string> KeySystemNameForUMAMap; |
| 242 | 238 |
| 243 // TODO(sandersd): Separate container enum from codec mask value. | 239 // TODO(sandersd): Separate container enum from codec mask value. |
| 244 // http://crbug.com/417440 | 240 // http://crbug.com/417440 |
| 245 // Potentially pass EmeMediaType and a container enum. | 241 // Potentially pass EmeMediaType and a container enum. |
| 246 SupportedCodecs GetCodecMaskForMimeType( | 242 SupportedCodecs GetCodecMaskForMimeType( |
| 247 const std::string& container_mime_type) const; | 243 const std::string& container_mime_type) const; |
| 248 EmeCodec GetCodecForString(const std::string& codec) const; | 244 EmeCodec GetCodecForString(const std::string& codec) const; |
| 249 | 245 |
| 250 // Map from key system string to capabilities. | 246 // Map from key system string to capabilities. |
| 251 KeySystemInfoMap concrete_key_system_map_; | 247 KeySystemInfoMap key_system_map_; |
| 252 | 248 |
| 253 // This member should only be modified by RegisterMimeType(). | 249 // This member should only be modified by RegisterMimeType(). |
| 254 MimeTypeCodecsMap mime_type_to_codec_mask_map_; | 250 MimeTypeCodecsMap mime_type_to_codec_mask_map_; |
| 255 CodecsMap codec_string_map_; | 251 CodecsMap codec_string_map_; |
| 256 KeySystemNameForUMAMap key_system_name_for_uma_map_; | 252 KeySystemNameForUMAMap key_system_name_for_uma_map_; |
| 257 | 253 |
| 258 SupportedCodecs audio_codec_mask_; | 254 SupportedCodecs audio_codec_mask_; |
| 259 SupportedCodecs video_codec_mask_; | 255 SupportedCodecs video_codec_mask_; |
| 260 | 256 |
| 261 // Makes sure all methods are called from the same thread. | 257 // Makes sure all methods are called from the same thread. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 kClearKeyKeySystemNameForUMA; | 329 kClearKeyKeySystemNameForUMA; |
| 334 } | 330 } |
| 335 | 331 |
| 336 void KeySystemsImpl::UpdateIfNeeded() { | 332 void KeySystemsImpl::UpdateIfNeeded() { |
| 337 if (GetMediaClient() && GetMediaClient()->IsKeySystemsUpdateNeeded()) | 333 if (GetMediaClient() && GetMediaClient()->IsKeySystemsUpdateNeeded()) |
| 338 UpdateSupportedKeySystems(); | 334 UpdateSupportedKeySystems(); |
| 339 } | 335 } |
| 340 | 336 |
| 341 void KeySystemsImpl::UpdateSupportedKeySystems() { | 337 void KeySystemsImpl::UpdateSupportedKeySystems() { |
| 342 DCHECK(thread_checker_.CalledOnValidThread()); | 338 DCHECK(thread_checker_.CalledOnValidThread()); |
| 343 concrete_key_system_map_.clear(); | 339 key_system_map_.clear(); |
| 344 | 340 |
| 345 // Build KeySystemInfo. | 341 // Build KeySystemInfo. |
| 346 std::vector<KeySystemInfo> key_systems_info; | 342 std::vector<KeySystemInfo> key_systems_info; |
| 347 | 343 |
| 348 // Add key systems supported by the MediaClient implementation. | 344 // Add key systems supported by the MediaClient implementation. |
| 349 if (GetMediaClient()) | 345 if (GetMediaClient()) |
| 350 GetMediaClient()->AddSupportedKeySystems(&key_systems_info); | 346 GetMediaClient()->AddSupportedKeySystems(&key_systems_info); |
| 351 | 347 |
| 352 // Clear Key is always supported. | 348 // Clear Key is always supported. |
| 353 AddClearKey(&key_systems_info); | 349 AddClearKey(&key_systems_info); |
| 354 | 350 |
| 355 AddConcreteSupportedKeySystems(key_systems_info); | 351 AddSupportedKeySystems(key_systems_info); |
| 356 } | 352 } |
| 357 | 353 |
| 358 void KeySystemsImpl::AddConcreteSupportedKeySystems( | 354 void KeySystemsImpl::AddSupportedKeySystems( |
| 359 const std::vector<KeySystemInfo>& concrete_key_systems) { | 355 const std::vector<KeySystemInfo>& key_systems) { |
| 360 DCHECK(thread_checker_.CalledOnValidThread()); | 356 DCHECK(thread_checker_.CalledOnValidThread()); |
| 361 DCHECK(concrete_key_system_map_.empty()); | 357 DCHECK(key_system_map_.empty()); |
| 362 | 358 |
| 363 for (const KeySystemInfo& info : concrete_key_systems) { | 359 for (const KeySystemInfo& info : key_systems) { |
| 364 DCHECK(!info.key_system.empty()); | 360 DCHECK(!info.key_system.empty()); |
| 365 DCHECK(info.max_audio_robustness != EmeRobustness::INVALID); | 361 DCHECK(info.max_audio_robustness != EmeRobustness::INVALID); |
| 366 DCHECK(info.max_video_robustness != EmeRobustness::INVALID); | 362 DCHECK(info.max_video_robustness != EmeRobustness::INVALID); |
| 367 DCHECK(info.persistent_license_support != EmeSessionTypeSupport::INVALID); | 363 DCHECK(info.persistent_license_support != EmeSessionTypeSupport::INVALID); |
| 368 DCHECK(info.persistent_release_message_support != | 364 DCHECK(info.persistent_release_message_support != |
| 369 EmeSessionTypeSupport::INVALID); | 365 EmeSessionTypeSupport::INVALID); |
| 370 DCHECK(info.persistent_state_support != EmeFeatureSupport::INVALID); | 366 DCHECK(info.persistent_state_support != EmeFeatureSupport::INVALID); |
| 371 DCHECK(info.distinctive_identifier_support != EmeFeatureSupport::INVALID); | 367 DCHECK(info.distinctive_identifier_support != EmeFeatureSupport::INVALID); |
| 372 | 368 |
| 373 // Supporting persistent state is a prerequsite for supporting persistent | 369 // Supporting persistent state is a prerequsite for supporting persistent |
| (...skipping 30 matching lines...) Expand all Loading... |
| 404 if (!info.pepper_type.empty()) | 400 if (!info.pepper_type.empty()) |
| 405 can_block = true; | 401 can_block = true; |
| 406 #endif | 402 #endif |
| 407 if (!can_block) { | 403 if (!can_block) { |
| 408 DCHECK(info.distinctive_identifier_support == | 404 DCHECK(info.distinctive_identifier_support == |
| 409 EmeFeatureSupport::ALWAYS_ENABLED); | 405 EmeFeatureSupport::ALWAYS_ENABLED); |
| 410 DCHECK(info.persistent_state_support == | 406 DCHECK(info.persistent_state_support == |
| 411 EmeFeatureSupport::ALWAYS_ENABLED); | 407 EmeFeatureSupport::ALWAYS_ENABLED); |
| 412 } | 408 } |
| 413 | 409 |
| 414 DCHECK(!IsConcreteSupportedKeySystem(info.key_system)) | 410 DCHECK_EQ(key_system_map_.count(info.key_system), 0u) |
| 415 << "Key system '" << info.key_system << "' already registered"; | 411 << "Key system '" << info.key_system << "' already registered"; |
| 416 concrete_key_system_map_[info.key_system] = info; | 412 key_system_map_[info.key_system] = info; |
| 417 } | 413 } |
| 418 } | 414 } |
| 419 | 415 |
| 420 // Adds the MIME type with the codec mask after verifying the validity. | 416 // Adds the MIME type with the codec mask after verifying the validity. |
| 421 // Only this function should modify |mime_type_to_codec_mask_map_|. | 417 // Only this function should modify |mime_type_to_codec_mask_map_|. |
| 422 void KeySystemsImpl::RegisterMimeType(const std::string& mime_type, | 418 void KeySystemsImpl::RegisterMimeType(const std::string& mime_type, |
| 423 EmeCodec codecs_mask) { | 419 EmeCodec codecs_mask) { |
| 424 DCHECK(thread_checker_.CalledOnValidThread()); | 420 DCHECK(thread_checker_.CalledOnValidThread()); |
| 425 DCHECK(!mime_type_to_codec_mask_map_.count(mime_type)); | 421 DCHECK(!mime_type_to_codec_mask_map_.count(mime_type)); |
| 426 DCHECK(IsValidMimeTypeCodecsCombination(mime_type, codecs_mask)); | 422 DCHECK(IsValidMimeTypeCodecsCombination(mime_type, codecs_mask)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 438 if (!codecs_mask) | 434 if (!codecs_mask) |
| 439 return false; | 435 return false; |
| 440 if (base::StartsWith(mime_type, "audio/", base::CompareCase::SENSITIVE)) | 436 if (base::StartsWith(mime_type, "audio/", base::CompareCase::SENSITIVE)) |
| 441 return !(codecs_mask & ~audio_codec_mask_); | 437 return !(codecs_mask & ~audio_codec_mask_); |
| 442 if (base::StartsWith(mime_type, "video/", base::CompareCase::SENSITIVE)) | 438 if (base::StartsWith(mime_type, "video/", base::CompareCase::SENSITIVE)) |
| 443 return !(codecs_mask & ~video_codec_mask_); | 439 return !(codecs_mask & ~video_codec_mask_); |
| 444 | 440 |
| 445 return false; | 441 return false; |
| 446 } | 442 } |
| 447 | 443 |
| 448 bool KeySystemsImpl::IsConcreteSupportedKeySystem( | |
| 449 const std::string& key_system) const { | |
| 450 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 451 return concrete_key_system_map_.count(key_system) != 0; | |
| 452 } | |
| 453 | |
| 454 bool KeySystemsImpl::IsSupportedInitDataType( | 444 bool KeySystemsImpl::IsSupportedInitDataType( |
| 455 const std::string& key_system, | 445 const std::string& key_system, |
| 456 EmeInitDataType init_data_type) const { | 446 EmeInitDataType init_data_type) const { |
| 457 DCHECK(thread_checker_.CalledOnValidThread()); | 447 DCHECK(thread_checker_.CalledOnValidThread()); |
| 458 | 448 |
| 459 // Locate |key_system|. Only concrete key systems are supported. | |
| 460 KeySystemInfoMap::const_iterator key_system_iter = | 449 KeySystemInfoMap::const_iterator key_system_iter = |
| 461 concrete_key_system_map_.find(key_system); | 450 key_system_map_.find(key_system); |
| 462 if (key_system_iter == concrete_key_system_map_.end()) { | 451 if (key_system_iter == key_system_map_.end()) { |
| 463 NOTREACHED(); | 452 NOTREACHED(); |
| 464 return false; | 453 return false; |
| 465 } | 454 } |
| 466 | 455 |
| 467 // Check |init_data_type|. | 456 // Check |init_data_type|. |
| 468 InitDataTypeMask available_init_data_types = | 457 InitDataTypeMask available_init_data_types = |
| 469 key_system_iter->second.supported_init_data_types; | 458 key_system_iter->second.supported_init_data_types; |
| 470 switch (init_data_type) { | 459 switch (init_data_type) { |
| 471 case EmeInitDataType::UNKNOWN: | 460 case EmeInitDataType::UNKNOWN: |
| 472 return false; | 461 return false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 486 DCHECK(thread_checker_.CalledOnValidThread()); | 475 DCHECK(thread_checker_.CalledOnValidThread()); |
| 487 | 476 |
| 488 KeySystemNameForUMAMap::const_iterator iter = | 477 KeySystemNameForUMAMap::const_iterator iter = |
| 489 key_system_name_for_uma_map_.find(key_system); | 478 key_system_name_for_uma_map_.find(key_system); |
| 490 if (iter == key_system_name_for_uma_map_.end()) | 479 if (iter == key_system_name_for_uma_map_.end()) |
| 491 return kUnknownKeySystemNameForUMA; | 480 return kUnknownKeySystemNameForUMA; |
| 492 | 481 |
| 493 return iter->second; | 482 return iter->second; |
| 494 } | 483 } |
| 495 | 484 |
| 496 bool KeySystemsImpl::UseAesDecryptor( | 485 bool KeySystemsImpl::UseAesDecryptor(const std::string& key_system) const { |
| 497 const std::string& concrete_key_system) const { | |
| 498 DCHECK(thread_checker_.CalledOnValidThread()); | 486 DCHECK(thread_checker_.CalledOnValidThread()); |
| 499 | 487 |
| 500 KeySystemInfoMap::const_iterator key_system_iter = | 488 KeySystemInfoMap::const_iterator key_system_iter = |
| 501 concrete_key_system_map_.find(concrete_key_system); | 489 key_system_map_.find(key_system); |
| 502 if (key_system_iter == concrete_key_system_map_.end()) { | 490 if (key_system_iter == key_system_map_.end()) { |
| 503 DLOG(ERROR) << concrete_key_system << " is not a known concrete system"; | 491 DLOG(ERROR) << key_system << " is not a known system"; |
| 504 return false; | 492 return false; |
| 505 } | 493 } |
| 506 | 494 |
| 507 return key_system_iter->second.use_aes_decryptor; | 495 return key_system_iter->second.use_aes_decryptor; |
| 508 } | 496 } |
| 509 | 497 |
| 510 #if defined(ENABLE_PEPPER_CDMS) | 498 #if defined(ENABLE_PEPPER_CDMS) |
| 511 std::string KeySystemsImpl::GetPepperType( | 499 std::string KeySystemsImpl::GetPepperType(const std::string& key_system) const { |
| 512 const std::string& concrete_key_system) const { | |
| 513 DCHECK(thread_checker_.CalledOnValidThread()); | 500 DCHECK(thread_checker_.CalledOnValidThread()); |
| 514 | 501 |
| 515 KeySystemInfoMap::const_iterator key_system_iter = | 502 KeySystemInfoMap::const_iterator key_system_iter = |
| 516 concrete_key_system_map_.find(concrete_key_system); | 503 key_system_map_.find(key_system); |
| 517 if (key_system_iter == concrete_key_system_map_.end()) { | 504 if (key_system_iter == key_system_map_.end()) { |
| 518 DLOG(FATAL) << concrete_key_system << " is not a known concrete system"; | 505 DLOG(FATAL) << key_system << " is not a known system"; |
| 519 return std::string(); | 506 return std::string(); |
| 520 } | 507 } |
| 521 | 508 |
| 522 const std::string& type = key_system_iter->second.pepper_type; | 509 const std::string& type = key_system_iter->second.pepper_type; |
| 523 DLOG_IF(FATAL, type.empty()) << concrete_key_system << " is not Pepper-based"; | 510 DLOG_IF(FATAL, type.empty()) << key_system << " is not Pepper-based"; |
| 524 return type; | 511 return type; |
| 525 } | 512 } |
| 526 #endif | 513 #endif |
| 527 | 514 |
| 528 void KeySystemsImpl::AddCodecMask(EmeMediaType media_type, | 515 void KeySystemsImpl::AddCodecMask(EmeMediaType media_type, |
| 529 const std::string& codec, | 516 const std::string& codec, |
| 530 uint32_t mask) { | 517 uint32_t mask) { |
| 531 DCHECK(thread_checker_.CalledOnValidThread()); | 518 DCHECK(thread_checker_.CalledOnValidThread()); |
| 532 DCHECK(!codec_string_map_.count(codec)); | 519 DCHECK(!codec_string_map_.count(codec)); |
| 533 codec_string_map_[codec] = static_cast<EmeCodec>(mask); | 520 codec_string_map_[codec] = static_cast<EmeCodec>(mask); |
| 534 if (media_type == EmeMediaType::AUDIO) { | 521 if (media_type == EmeMediaType::AUDIO) { |
| 535 audio_codec_mask_ |= mask; | 522 audio_codec_mask_ |= mask; |
| 536 } else { | 523 } else { |
| 537 video_codec_mask_ |= mask; | 524 video_codec_mask_ |= mask; |
| 538 } | 525 } |
| 539 } | 526 } |
| 540 | 527 |
| 541 void KeySystemsImpl::AddMimeTypeCodecMask(const std::string& mime_type, | 528 void KeySystemsImpl::AddMimeTypeCodecMask(const std::string& mime_type, |
| 542 uint32_t codecs_mask) { | 529 uint32_t codecs_mask) { |
| 543 RegisterMimeType(mime_type, static_cast<EmeCodec>(codecs_mask)); | 530 RegisterMimeType(mime_type, static_cast<EmeCodec>(codecs_mask)); |
| 544 } | 531 } |
| 545 | 532 |
| 546 bool KeySystemsImpl::IsSupportedKeySystem(const std::string& key_system) const { | 533 bool KeySystemsImpl::IsSupportedKeySystem(const std::string& key_system) const { |
| 547 DCHECK(thread_checker_.CalledOnValidThread()); | 534 DCHECK(thread_checker_.CalledOnValidThread()); |
| 548 | 535 |
| 549 if (!IsConcreteSupportedKeySystem(key_system)) | 536 if (!key_system_map_.count(key_system)) |
| 550 return false; | 537 return false; |
| 551 | 538 |
| 552 // TODO(ddorwin): Move this to where we add key systems when prefixed EME is | 539 // TODO(ddorwin): Move this to where we add key systems when prefixed EME is |
| 553 // removed (crbug.com/249976). | 540 // removed (crbug.com/249976). |
| 554 if (!IsPotentiallySupportedKeySystem(key_system)) { | 541 if (!IsPotentiallySupportedKeySystem(key_system)) { |
| 555 // If you encounter this path, see the comments for the above function. | 542 // If you encounter this path, see the comments for the above function. |
| 556 DLOG(ERROR) << "Unrecognized key system " << key_system | 543 DLOG(ERROR) << "Unrecognized key system " << key_system |
| 557 << ". See code comments."; | 544 << ". See code comments."; |
| 558 return false; | 545 return false; |
| 559 } | 546 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 577 break; | 564 break; |
| 578 case EmeMediaType::VIDEO: | 565 case EmeMediaType::VIDEO: |
| 579 if (!base::StartsWith(container_mime_type, "video/", | 566 if (!base::StartsWith(container_mime_type, "video/", |
| 580 base::CompareCase::SENSITIVE)) | 567 base::CompareCase::SENSITIVE)) |
| 581 return EmeConfigRule::NOT_SUPPORTED; | 568 return EmeConfigRule::NOT_SUPPORTED; |
| 582 break; | 569 break; |
| 583 } | 570 } |
| 584 | 571 |
| 585 // Look up the key system's supported codecs. | 572 // Look up the key system's supported codecs. |
| 586 KeySystemInfoMap::const_iterator key_system_iter = | 573 KeySystemInfoMap::const_iterator key_system_iter = |
| 587 concrete_key_system_map_.find(key_system); | 574 key_system_map_.find(key_system); |
| 588 if (key_system_iter == concrete_key_system_map_.end()) { | 575 if (key_system_iter == key_system_map_.end()) { |
| 589 NOTREACHED(); | 576 NOTREACHED(); |
| 590 return EmeConfigRule::NOT_SUPPORTED; | 577 return EmeConfigRule::NOT_SUPPORTED; |
| 591 } | 578 } |
| 592 SupportedCodecs key_system_codec_mask = | 579 SupportedCodecs key_system_codec_mask = |
| 593 key_system_iter->second.supported_codecs; | 580 key_system_iter->second.supported_codecs; |
| 594 #if defined(OS_ANDROID) | 581 #if defined(OS_ANDROID) |
| 595 SupportedCodecs key_system_secure_codec_mask = | 582 SupportedCodecs key_system_secure_codec_mask = |
| 596 key_system_iter->second.supported_secure_codecs; | 583 key_system_iter->second.supported_secure_codecs; |
| 597 #endif // defined(OS_ANDROID) | 584 #endif // defined(OS_ANDROID) |
| 598 | 585 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 const std::string& key_system, | 618 const std::string& key_system, |
| 632 EmeMediaType media_type, | 619 EmeMediaType media_type, |
| 633 const std::string& requested_robustness) const { | 620 const std::string& requested_robustness) const { |
| 634 DCHECK(thread_checker_.CalledOnValidThread()); | 621 DCHECK(thread_checker_.CalledOnValidThread()); |
| 635 | 622 |
| 636 EmeRobustness robustness = ConvertRobustness(requested_robustness); | 623 EmeRobustness robustness = ConvertRobustness(requested_robustness); |
| 637 if (robustness == EmeRobustness::INVALID) | 624 if (robustness == EmeRobustness::INVALID) |
| 638 return EmeConfigRule::NOT_SUPPORTED; | 625 return EmeConfigRule::NOT_SUPPORTED; |
| 639 | 626 |
| 640 KeySystemInfoMap::const_iterator key_system_iter = | 627 KeySystemInfoMap::const_iterator key_system_iter = |
| 641 concrete_key_system_map_.find(key_system); | 628 key_system_map_.find(key_system); |
| 642 if (key_system_iter == concrete_key_system_map_.end()) { | 629 if (key_system_iter == key_system_map_.end()) { |
| 643 NOTREACHED(); | 630 NOTREACHED(); |
| 644 return EmeConfigRule::NOT_SUPPORTED; | 631 return EmeConfigRule::NOT_SUPPORTED; |
| 645 } | 632 } |
| 646 | 633 |
| 647 EmeRobustness max_robustness = EmeRobustness::INVALID; | 634 EmeRobustness max_robustness = EmeRobustness::INVALID; |
| 648 switch (media_type) { | 635 switch (media_type) { |
| 649 case EmeMediaType::AUDIO: | 636 case EmeMediaType::AUDIO: |
| 650 max_robustness = key_system_iter->second.max_audio_robustness; | 637 max_robustness = key_system_iter->second.max_audio_robustness; |
| 651 break; | 638 break; |
| 652 case EmeMediaType::VIDEO: | 639 case EmeMediaType::VIDEO: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 #endif // defined(OS_CHROMEOS) | 683 #endif // defined(OS_CHROMEOS) |
| 697 | 684 |
| 698 return EmeConfigRule::SUPPORTED; | 685 return EmeConfigRule::SUPPORTED; |
| 699 } | 686 } |
| 700 | 687 |
| 701 EmeSessionTypeSupport KeySystemsImpl::GetPersistentLicenseSessionSupport( | 688 EmeSessionTypeSupport KeySystemsImpl::GetPersistentLicenseSessionSupport( |
| 702 const std::string& key_system) const { | 689 const std::string& key_system) const { |
| 703 DCHECK(thread_checker_.CalledOnValidThread()); | 690 DCHECK(thread_checker_.CalledOnValidThread()); |
| 704 | 691 |
| 705 KeySystemInfoMap::const_iterator key_system_iter = | 692 KeySystemInfoMap::const_iterator key_system_iter = |
| 706 concrete_key_system_map_.find(key_system); | 693 key_system_map_.find(key_system); |
| 707 if (key_system_iter == concrete_key_system_map_.end()) { | 694 if (key_system_iter == key_system_map_.end()) { |
| 708 NOTREACHED(); | 695 NOTREACHED(); |
| 709 return EmeSessionTypeSupport::INVALID; | 696 return EmeSessionTypeSupport::INVALID; |
| 710 } | 697 } |
| 711 return key_system_iter->second.persistent_license_support; | 698 return key_system_iter->second.persistent_license_support; |
| 712 } | 699 } |
| 713 | 700 |
| 714 EmeSessionTypeSupport KeySystemsImpl::GetPersistentReleaseMessageSessionSupport( | 701 EmeSessionTypeSupport KeySystemsImpl::GetPersistentReleaseMessageSessionSupport( |
| 715 const std::string& key_system) const { | 702 const std::string& key_system) const { |
| 716 DCHECK(thread_checker_.CalledOnValidThread()); | 703 DCHECK(thread_checker_.CalledOnValidThread()); |
| 717 | 704 |
| 718 KeySystemInfoMap::const_iterator key_system_iter = | 705 KeySystemInfoMap::const_iterator key_system_iter = |
| 719 concrete_key_system_map_.find(key_system); | 706 key_system_map_.find(key_system); |
| 720 if (key_system_iter == concrete_key_system_map_.end()) { | 707 if (key_system_iter == key_system_map_.end()) { |
| 721 NOTREACHED(); | 708 NOTREACHED(); |
| 722 return EmeSessionTypeSupport::INVALID; | 709 return EmeSessionTypeSupport::INVALID; |
| 723 } | 710 } |
| 724 return key_system_iter->second.persistent_release_message_support; | 711 return key_system_iter->second.persistent_release_message_support; |
| 725 } | 712 } |
| 726 | 713 |
| 727 EmeFeatureSupport KeySystemsImpl::GetPersistentStateSupport( | 714 EmeFeatureSupport KeySystemsImpl::GetPersistentStateSupport( |
| 728 const std::string& key_system) const { | 715 const std::string& key_system) const { |
| 729 DCHECK(thread_checker_.CalledOnValidThread()); | 716 DCHECK(thread_checker_.CalledOnValidThread()); |
| 730 | 717 |
| 731 KeySystemInfoMap::const_iterator key_system_iter = | 718 KeySystemInfoMap::const_iterator key_system_iter = |
| 732 concrete_key_system_map_.find(key_system); | 719 key_system_map_.find(key_system); |
| 733 if (key_system_iter == concrete_key_system_map_.end()) { | 720 if (key_system_iter == key_system_map_.end()) { |
| 734 NOTREACHED(); | 721 NOTREACHED(); |
| 735 return EmeFeatureSupport::INVALID; | 722 return EmeFeatureSupport::INVALID; |
| 736 } | 723 } |
| 737 return key_system_iter->second.persistent_state_support; | 724 return key_system_iter->second.persistent_state_support; |
| 738 } | 725 } |
| 739 | 726 |
| 740 EmeFeatureSupport KeySystemsImpl::GetDistinctiveIdentifierSupport( | 727 EmeFeatureSupport KeySystemsImpl::GetDistinctiveIdentifierSupport( |
| 741 const std::string& key_system) const { | 728 const std::string& key_system) const { |
| 742 DCHECK(thread_checker_.CalledOnValidThread()); | 729 DCHECK(thread_checker_.CalledOnValidThread()); |
| 743 | 730 |
| 744 KeySystemInfoMap::const_iterator key_system_iter = | 731 KeySystemInfoMap::const_iterator key_system_iter = |
| 745 concrete_key_system_map_.find(key_system); | 732 key_system_map_.find(key_system); |
| 746 if (key_system_iter == concrete_key_system_map_.end()) { | 733 if (key_system_iter == key_system_map_.end()) { |
| 747 NOTREACHED(); | 734 NOTREACHED(); |
| 748 return EmeFeatureSupport::INVALID; | 735 return EmeFeatureSupport::INVALID; |
| 749 } | 736 } |
| 750 return key_system_iter->second.distinctive_identifier_support; | 737 return key_system_iter->second.distinctive_identifier_support; |
| 751 } | 738 } |
| 752 | 739 |
| 753 KeySystems* KeySystems::GetInstance() { | 740 KeySystems* KeySystems::GetInstance() { |
| 754 return KeySystemsImpl::GetInstance(); | 741 return KeySystemsImpl::GetInstance(); |
| 755 } | 742 } |
| 756 | 743 |
| 757 //------------------------------------------------------------------------------ | 744 //------------------------------------------------------------------------------ |
| 758 | 745 |
| 759 bool IsSupportedKeySystemWithInitDataType(const std::string& key_system, | 746 bool IsSupportedKeySystemWithInitDataType(const std::string& key_system, |
| 760 EmeInitDataType init_data_type) { | 747 EmeInitDataType init_data_type) { |
| 761 return KeySystemsImpl::GetInstance()->IsSupportedInitDataType(key_system, | 748 return KeySystemsImpl::GetInstance()->IsSupportedInitDataType(key_system, |
| 762 init_data_type); | 749 init_data_type); |
| 763 } | 750 } |
| 764 | 751 |
| 765 std::string GetKeySystemNameForUMA(const std::string& key_system) { | 752 std::string GetKeySystemNameForUMA(const std::string& key_system) { |
| 766 return KeySystemsImpl::GetInstance()->GetKeySystemNameForUMA(key_system); | 753 return KeySystemsImpl::GetInstance()->GetKeySystemNameForUMA(key_system); |
| 767 } | 754 } |
| 768 | 755 |
| 769 bool CanUseAesDecryptor(const std::string& concrete_key_system) { | 756 bool CanUseAesDecryptor(const std::string& key_system) { |
| 770 return KeySystemsImpl::GetInstance()->UseAesDecryptor(concrete_key_system); | 757 return KeySystemsImpl::GetInstance()->UseAesDecryptor(key_system); |
| 771 } | 758 } |
| 772 | 759 |
| 773 #if defined(ENABLE_PEPPER_CDMS) | 760 #if defined(ENABLE_PEPPER_CDMS) |
| 774 std::string GetPepperType(const std::string& concrete_key_system) { | 761 std::string GetPepperType(const std::string& key_system) { |
| 775 return KeySystemsImpl::GetInstance()->GetPepperType(concrete_key_system); | 762 return KeySystemsImpl::GetInstance()->GetPepperType(key_system); |
| 776 } | 763 } |
| 777 #endif | 764 #endif |
| 778 | 765 |
| 779 // These two functions are for testing purpose only. The declaration in the | 766 // These two functions are for testing purpose only. The declaration in the |
| 780 // header file is guarded by "#if defined(UNIT_TEST)" so that they can be used | 767 // header file is guarded by "#if defined(UNIT_TEST)" so that they can be used |
| 781 // by tests but not non-test code. However, this .cc file is compiled as part of | 768 // by tests but not non-test code. However, this .cc file is compiled as part of |
| 782 // "media" where "UNIT_TEST" is not defined. So we need to specify | 769 // "media" where "UNIT_TEST" is not defined. So we need to specify |
| 783 // "MEDIA_EXPORT" here again so that they are visible to tests. | 770 // "MEDIA_EXPORT" here again so that they are visible to tests. |
| 784 | 771 |
| 785 MEDIA_EXPORT void AddCodecMask(EmeMediaType media_type, | 772 MEDIA_EXPORT void AddCodecMask(EmeMediaType media_type, |
| 786 const std::string& codec, | 773 const std::string& codec, |
| 787 uint32_t mask) { | 774 uint32_t mask) { |
| 788 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); | 775 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); |
| 789 } | 776 } |
| 790 | 777 |
| 791 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, | 778 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, |
| 792 uint32_t mask) { | 779 uint32_t mask) { |
| 793 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); | 780 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); |
| 794 } | 781 } |
| 795 | 782 |
| 796 } // namespace media | 783 } // namespace media |
| OLD | NEW |