| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 return true; | 146 return true; |
| 147 if (key_system == kClearKey) | 147 if (key_system == kClearKey) |
| 148 return true; | 148 return true; |
| 149 | 149 |
| 150 // External Clear Key is known and supports suffixes for testing. | 150 // External Clear Key is known and supports suffixes for testing. |
| 151 if (IsExternalClearKey(key_system)) | 151 if (IsExternalClearKey(key_system)) |
| 152 return true; | 152 return true; |
| 153 | 153 |
| 154 // Chromecast defines behaviors for Cast clients within its reverse domain. | 154 // Chromecast defines behaviors for Cast clients within its reverse domain. |
| 155 const char kChromecastRoot[] = "com.chromecast"; | 155 const char kChromecastRoot[] = "com.chromecast"; |
| 156 if (IsParentKeySystemOf(kChromecastRoot, key_system)) | 156 if (IsChildKeySystemOf(key_system, kChromecastRoot)) |
| 157 return true; | 157 return true; |
| 158 | 158 |
| 159 // Implementations that do not have a specification or appropriate glue code | 159 // Implementations that do not have a specification or appropriate glue code |
| 160 // can use the "x-" prefix to avoid conflicting with and advertising support | 160 // can use the "x-" prefix to avoid conflicting with and advertising support |
| 161 // for real key system names. Use is discouraged. | 161 // for real key system names. Use is discouraged. |
| 162 const char kExcludedPrefix[] = "x-"; | 162 const char kExcludedPrefix[] = "x-"; |
| 163 if (key_system.find(kExcludedPrefix, 0, arraysize(kExcludedPrefix) - 1) == 0) | 163 if (key_system.find(kExcludedPrefix, 0, arraysize(kExcludedPrefix) - 1) == 0) |
| 164 return true; | 164 return true; |
| 165 | 165 |
| 166 return false; | 166 return false; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 void AddConcreteSupportedKeySystems( | 228 void AddConcreteSupportedKeySystems( |
| 229 const std::vector<KeySystemInfo>& concrete_key_systems); | 229 const std::vector<KeySystemInfo>& concrete_key_systems); |
| 230 | 230 |
| 231 void RegisterMimeType(const std::string& mime_type, EmeCodec codecs_mask); | 231 void RegisterMimeType(const std::string& mime_type, EmeCodec codecs_mask); |
| 232 bool IsValidMimeTypeCodecsCombination(const std::string& mime_type, | 232 bool IsValidMimeTypeCodecsCombination(const std::string& mime_type, |
| 233 SupportedCodecs codecs_mask) const; | 233 SupportedCodecs codecs_mask) const; |
| 234 | 234 |
| 235 friend struct base::DefaultLazyInstanceTraits<KeySystemsImpl>; | 235 friend struct base::DefaultLazyInstanceTraits<KeySystemsImpl>; |
| 236 | 236 |
| 237 typedef base::hash_map<std::string, KeySystemInfo> KeySystemInfoMap; | 237 typedef base::hash_map<std::string, KeySystemInfo> KeySystemInfoMap; |
| 238 typedef base::hash_map<std::string, std::string> ParentKeySystemMap; | |
| 239 typedef base::hash_map<std::string, SupportedCodecs> MimeTypeCodecsMap; | 238 typedef base::hash_map<std::string, SupportedCodecs> MimeTypeCodecsMap; |
| 240 typedef base::hash_map<std::string, EmeCodec> CodecsMap; | 239 typedef base::hash_map<std::string, EmeCodec> CodecsMap; |
| 241 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap; | 240 typedef base::hash_map<std::string, EmeInitDataType> InitDataTypesMap; |
| 242 typedef base::hash_map<std::string, std::string> KeySystemNameForUMAMap; | 241 typedef base::hash_map<std::string, std::string> KeySystemNameForUMAMap; |
| 243 | 242 |
| 244 // TODO(sandersd): Separate container enum from codec mask value. | 243 // TODO(sandersd): Separate container enum from codec mask value. |
| 245 // http://crbug.com/417440 | 244 // http://crbug.com/417440 |
| 246 // Potentially pass EmeMediaType and a container enum. | 245 // Potentially pass EmeMediaType and a container enum. |
| 247 SupportedCodecs GetCodecMaskForMimeType( | 246 SupportedCodecs GetCodecMaskForMimeType( |
| 248 const std::string& container_mime_type) const; | 247 const std::string& container_mime_type) const; |
| 249 EmeCodec GetCodecForString(const std::string& codec) const; | 248 EmeCodec GetCodecForString(const std::string& codec) const; |
| 250 | 249 |
| 251 // Map from key system string to capabilities. | 250 // Map from key system string to capabilities. |
| 252 KeySystemInfoMap concrete_key_system_map_; | 251 KeySystemInfoMap concrete_key_system_map_; |
| 253 | 252 |
| 254 // Map from parent key system to the concrete key system that should be used | |
| 255 // to represent its capabilities. | |
| 256 ParentKeySystemMap parent_key_system_map_; | |
| 257 | |
| 258 // This member should only be modified by RegisterMimeType(). | 253 // This member should only be modified by RegisterMimeType(). |
| 259 MimeTypeCodecsMap mime_type_to_codec_mask_map_; | 254 MimeTypeCodecsMap mime_type_to_codec_mask_map_; |
| 260 CodecsMap codec_string_map_; | 255 CodecsMap codec_string_map_; |
| 261 KeySystemNameForUMAMap key_system_name_for_uma_map_; | 256 KeySystemNameForUMAMap key_system_name_for_uma_map_; |
| 262 | 257 |
| 263 SupportedCodecs audio_codec_mask_; | 258 SupportedCodecs audio_codec_mask_; |
| 264 SupportedCodecs video_codec_mask_; | 259 SupportedCodecs video_codec_mask_; |
| 265 | 260 |
| 266 // Makes sure all methods are called from the same thread. | 261 // Makes sure all methods are called from the same thread. |
| 267 base::ThreadChecker thread_checker_; | 262 base::ThreadChecker thread_checker_; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 } | 334 } |
| 340 | 335 |
| 341 void KeySystemsImpl::UpdateIfNeeded() { | 336 void KeySystemsImpl::UpdateIfNeeded() { |
| 342 if (GetMediaClient() && GetMediaClient()->IsKeySystemsUpdateNeeded()) | 337 if (GetMediaClient() && GetMediaClient()->IsKeySystemsUpdateNeeded()) |
| 343 UpdateSupportedKeySystems(); | 338 UpdateSupportedKeySystems(); |
| 344 } | 339 } |
| 345 | 340 |
| 346 void KeySystemsImpl::UpdateSupportedKeySystems() { | 341 void KeySystemsImpl::UpdateSupportedKeySystems() { |
| 347 DCHECK(thread_checker_.CalledOnValidThread()); | 342 DCHECK(thread_checker_.CalledOnValidThread()); |
| 348 concrete_key_system_map_.clear(); | 343 concrete_key_system_map_.clear(); |
| 349 parent_key_system_map_.clear(); | |
| 350 | 344 |
| 351 // Build KeySystemInfo. | 345 // Build KeySystemInfo. |
| 352 std::vector<KeySystemInfo> key_systems_info; | 346 std::vector<KeySystemInfo> key_systems_info; |
| 353 | 347 |
| 354 // Add key systems supported by the MediaClient implementation. | 348 // Add key systems supported by the MediaClient implementation. |
| 355 if (GetMediaClient()) | 349 if (GetMediaClient()) |
| 356 GetMediaClient()->AddSupportedKeySystems(&key_systems_info); | 350 GetMediaClient()->AddSupportedKeySystems(&key_systems_info); |
| 357 | 351 |
| 358 // Clear Key is always supported. | 352 // Clear Key is always supported. |
| 359 AddClearKey(&key_systems_info); | 353 AddClearKey(&key_systems_info); |
| 360 | 354 |
| 361 AddConcreteSupportedKeySystems(key_systems_info); | 355 AddConcreteSupportedKeySystems(key_systems_info); |
| 362 } | 356 } |
| 363 | 357 |
| 364 void KeySystemsImpl::AddConcreteSupportedKeySystems( | 358 void KeySystemsImpl::AddConcreteSupportedKeySystems( |
| 365 const std::vector<KeySystemInfo>& concrete_key_systems) { | 359 const std::vector<KeySystemInfo>& concrete_key_systems) { |
| 366 DCHECK(thread_checker_.CalledOnValidThread()); | 360 DCHECK(thread_checker_.CalledOnValidThread()); |
| 367 DCHECK(concrete_key_system_map_.empty()); | 361 DCHECK(concrete_key_system_map_.empty()); |
| 368 DCHECK(parent_key_system_map_.empty()); | |
| 369 | 362 |
| 370 for (const KeySystemInfo& info : concrete_key_systems) { | 363 for (const KeySystemInfo& info : concrete_key_systems) { |
| 371 DCHECK(!info.key_system.empty()); | 364 DCHECK(!info.key_system.empty()); |
| 372 DCHECK(info.max_audio_robustness != EmeRobustness::INVALID); | 365 DCHECK(info.max_audio_robustness != EmeRobustness::INVALID); |
| 373 DCHECK(info.max_video_robustness != EmeRobustness::INVALID); | 366 DCHECK(info.max_video_robustness != EmeRobustness::INVALID); |
| 374 DCHECK(info.persistent_license_support != EmeSessionTypeSupport::INVALID); | 367 DCHECK(info.persistent_license_support != EmeSessionTypeSupport::INVALID); |
| 375 DCHECK(info.persistent_release_message_support != | 368 DCHECK(info.persistent_release_message_support != |
| 376 EmeSessionTypeSupport::INVALID); | 369 EmeSessionTypeSupport::INVALID); |
| 377 DCHECK(info.persistent_state_support != EmeFeatureSupport::INVALID); | 370 DCHECK(info.persistent_state_support != EmeFeatureSupport::INVALID); |
| 378 DCHECK(info.distinctive_identifier_support != EmeFeatureSupport::INVALID); | 371 DCHECK(info.distinctive_identifier_support != EmeFeatureSupport::INVALID); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 #endif | 406 #endif |
| 414 if (!can_block) { | 407 if (!can_block) { |
| 415 DCHECK(info.distinctive_identifier_support == | 408 DCHECK(info.distinctive_identifier_support == |
| 416 EmeFeatureSupport::ALWAYS_ENABLED); | 409 EmeFeatureSupport::ALWAYS_ENABLED); |
| 417 DCHECK(info.persistent_state_support == | 410 DCHECK(info.persistent_state_support == |
| 418 EmeFeatureSupport::ALWAYS_ENABLED); | 411 EmeFeatureSupport::ALWAYS_ENABLED); |
| 419 } | 412 } |
| 420 | 413 |
| 421 DCHECK(!IsConcreteSupportedKeySystem(info.key_system)) | 414 DCHECK(!IsConcreteSupportedKeySystem(info.key_system)) |
| 422 << "Key system '" << info.key_system << "' already registered"; | 415 << "Key system '" << info.key_system << "' already registered"; |
| 423 DCHECK(!parent_key_system_map_.count(info.key_system)) | |
| 424 << "'" << info.key_system << "' is already registered as a parent"; | |
| 425 concrete_key_system_map_[info.key_system] = info; | 416 concrete_key_system_map_[info.key_system] = info; |
| 426 if (!info.parent_key_system.empty()) { | |
| 427 DCHECK(!IsConcreteSupportedKeySystem(info.parent_key_system)) | |
| 428 << "Parent '" << info.parent_key_system << "' " | |
| 429 << "already registered concrete"; | |
| 430 DCHECK(!parent_key_system_map_.count(info.parent_key_system)) | |
| 431 << "Parent '" << info.parent_key_system << "' already registered"; | |
| 432 parent_key_system_map_[info.parent_key_system] = info.key_system; | |
| 433 } | |
| 434 } | 417 } |
| 435 } | 418 } |
| 436 | 419 |
| 437 // Adds the MIME type with the codec mask after verifying the validity. | 420 // Adds the MIME type with the codec mask after verifying the validity. |
| 438 // Only this function should modify |mime_type_to_codec_mask_map_|. | 421 // Only this function should modify |mime_type_to_codec_mask_map_|. |
| 439 void KeySystemsImpl::RegisterMimeType(const std::string& mime_type, | 422 void KeySystemsImpl::RegisterMimeType(const std::string& mime_type, |
| 440 EmeCodec codecs_mask) { | 423 EmeCodec codecs_mask) { |
| 441 DCHECK(thread_checker_.CalledOnValidThread()); | 424 DCHECK(thread_checker_.CalledOnValidThread()); |
| 442 DCHECK(!mime_type_to_codec_mask_map_.count(mime_type)); | 425 DCHECK(!mime_type_to_codec_mask_map_.count(mime_type)); |
| 443 DCHECK(IsValidMimeTypeCodecsCombination(mime_type, codecs_mask)); | 426 DCHECK(IsValidMimeTypeCodecsCombination(mime_type, codecs_mask)); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 uint32_t mask) { | 787 uint32_t mask) { |
| 805 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); | 788 KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask); |
| 806 } | 789 } |
| 807 | 790 |
| 808 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, | 791 MEDIA_EXPORT void AddMimeTypeCodecMask(const std::string& mime_type, |
| 809 uint32_t mask) { | 792 uint32_t mask) { |
| 810 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); | 793 KeySystemsImpl::GetInstance()->AddMimeTypeCodecMask(mime_type, mask); |
| 811 } | 794 } |
| 812 | 795 |
| 813 } // namespace media | 796 } // namespace media |
| OLD | NEW |