Chromium Code Reviews| Index: media/base/key_systems.cc |
| diff --git a/media/base/key_systems.cc b/media/base/key_systems.cc |
| index 27b6875824e856bedaaa6626b10b87279abc05fc..be1a4137273feaed8f6cdebd298681c8280521d9 100644 |
| --- a/media/base/key_systems.cc |
| +++ b/media/base/key_systems.cc |
| @@ -51,6 +51,7 @@ struct NamedCodec { |
| // Mapping between containers and their codecs. |
| // Only audio codec can belong to a "audio/*" container. Both audio and video |
| // codecs can belong to a "video/*" container. |
| +// TODO(sandersd): This definition only makes sense for prefixed EME. |
|
ddorwin
2015/03/24 22:36:35
Are you planning to deal with this before removing
sandersd (OOO until July 31)
2015/03/24 23:26:36
Done.
|
| static NamedCodec kContainerToCodecMasks[] = { |
| {"audio/webm", EME_CODEC_WEBM_AUDIO_ALL}, |
| {"video/webm", EME_CODEC_WEBM_ALL}, |
| @@ -211,11 +212,6 @@ class KeySystemsImpl : public KeySystems { |
| const std::vector<std::string>& codecs, |
| const std::string& key_system); |
| - bool IsSupportedKeySystemWithMediaMimeType( |
| - const std::string& mime_type, |
| - const std::vector<std::string>& codecs, |
| - const std::string& key_system) const; |
| - |
| std::string GetKeySystemNameForUMA(const std::string& key_system) const; |
| bool UseAesDecryptor(const std::string& concrete_key_system) const; |
| @@ -225,7 +221,10 @@ class KeySystemsImpl : public KeySystems { |
| #endif |
| void AddContainerMask(const std::string& container, uint32 mask); |
| - void AddCodecMask(const std::string& codec, uint32 mask); |
| + void AddCodecMask( |
| + EmeMediaType media_type, |
| + const std::string& codec, |
| + uint32 mask); |
| // Implementation of KeySystems interface. |
| bool IsSupportedKeySystem(const std::string& key_system) const override; |
| @@ -313,6 +312,9 @@ class KeySystemsImpl : public KeySystems { |
| CodecsMap codec_string_map_; |
| KeySystemNameForUMAMap key_system_name_for_uma_map_; |
| + SupportedCodecs audio_codec_mask_; |
| + SupportedCodecs video_codec_mask_; |
| + |
| // Makes sure all methods are called from the same thread. |
| base::ThreadChecker thread_checker_; |
| @@ -346,6 +348,8 @@ KeySystemsImpl::KeySystemsImpl() { |
| DCHECK(!codec_string_map_.count(name)); |
| codec_string_map_[name] = kCodecStrings[i].type; |
| } |
| + audio_codec_mask_ = EME_CODEC_AUDIO_ALL; |
|
ddorwin
2015/03/24 22:36:35
Move to initializer list?
sandersd (OOO until July 31)
2015/03/24 23:26:36
Done.
|
| + video_codec_mask_ = EME_CODEC_VIDEO_ALL; |
| InitializeUMAInfo(); |
| @@ -554,8 +558,6 @@ bool KeySystemsImpl::IsSupportedContainerAndCodecs( |
| GetCodecMaskForContainer(container); |
| for (size_t i = 0; i < codecs.size(); ++i) { |
| - // TODO(sandersd): This should fail for isTypeSupported(). |
| - // http://crbug.com/417461 |
| if (codecs[i].empty()) |
| continue; |
| @@ -633,37 +635,6 @@ bool KeySystemsImpl::PrefixedIsSupportedKeySystemWithMediaMimeType( |
| return true; |
| } |
| -bool KeySystemsImpl::IsSupportedKeySystemWithMediaMimeType( |
| - const std::string& mime_type, |
| - const std::vector<std::string>& codecs, |
| - const std::string& key_system) const { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - |
| - KeySystemInfoMap::const_iterator key_system_iter = |
| - concrete_key_system_map_.find(key_system); |
| - if (key_system_iter == concrete_key_system_map_.end()) |
| - return false; |
| - |
| - if (mime_type.empty()) { |
| - DCHECK(codecs.empty()); |
| - return true; |
| - } |
| - |
| - SupportedCodecs key_system_supported_codecs = |
| - key_system_iter->second.supported_codecs; |
| - |
| - if (!IsSupportedContainer(mime_type, key_system_supported_codecs)) |
| - return false; |
| - |
| - if (!codecs.empty() && |
| - !IsSupportedContainerAndCodecs( |
| - mime_type, codecs, key_system_supported_codecs)) { |
| - return false; |
| - } |
| - |
| - return true; |
| -} |
| - |
| std::string KeySystemsImpl::GetKeySystemNameForUMA( |
| const std::string& key_system) const { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -708,17 +679,26 @@ std::string KeySystemsImpl::GetPepperType( |
| } |
| #endif |
| -void KeySystemsImpl::AddContainerMask(const std::string& container, |
| - uint32 mask) { |
| +void KeySystemsImpl::AddContainerMask( |
| + const std::string& container, |
| + uint32 mask) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(!container_to_codec_mask_map_.count(container)); |
| container_to_codec_mask_map_[container] = static_cast<EmeCodec>(mask); |
| } |
| -void KeySystemsImpl::AddCodecMask(const std::string& codec, uint32 mask) { |
| +void KeySystemsImpl::AddCodecMask( |
| + EmeMediaType media_type, |
| + const std::string& codec, |
| + uint32 mask) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(!codec_string_map_.count(codec)); |
| codec_string_map_[codec] = static_cast<EmeCodec>(mask); |
| + if (media_type == EmeMediaType::AUDIO) { |
| + audio_codec_mask_ |= mask; |
| + } else { |
| + video_codec_mask_ |= mask; |
| + } |
| } |
| bool KeySystemsImpl::IsSupportedKeySystem(const std::string& key_system) const { |
| @@ -726,26 +706,53 @@ bool KeySystemsImpl::IsSupportedKeySystem(const std::string& key_system) const { |
| return concrete_key_system_map_.count(key_system) != 0; |
| } |
| -// TODO(sandersd): Make sure that the codecs also match the |media_type|. |
| -// http://crbug.com/457386 |
| bool KeySystemsImpl::IsSupportedCodecCombination( |
| const std::string& key_system, |
| EmeMediaType media_type, |
| const std::string& container_mime_type, |
| const std::vector<std::string>& codecs) const { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + |
| // Make sure the container matches |media_type|. |
| + SupportedCodecs media_type_codec_mask = EME_CODEC_NONE; |
| switch (media_type) { |
| case EmeMediaType::AUDIO: |
| if (!StartsWithASCII(container_mime_type, "audio/", true)) |
| return false; |
| + media_type_codec_mask = audio_codec_mask_; |
| break; |
| case EmeMediaType::VIDEO: |
| if (!StartsWithASCII(container_mime_type, "video/", true)) |
| return false; |
| + media_type_codec_mask = video_codec_mask_; |
| break; |
| } |
| - return IsSupportedKeySystemWithMediaMimeType( |
| - container_mime_type, codecs, key_system); |
| + |
| + // Look up the key system's supported codecs. |
| + KeySystemInfoMap::const_iterator key_system_iter = |
| + concrete_key_system_map_.find(key_system); |
| + if (key_system_iter == concrete_key_system_map_.end()) { |
| + NOTREACHED(); |
| + return false; |
| + } |
| + SupportedCodecs key_system_codec_mask = |
| + key_system_iter->second.supported_codecs; |
| + |
| + // Check that the container is supported by the key system. (This check is |
| + // necessary because |codecs| may be empty.) |
| + SupportedCodecs container_codec_mask = |
| + GetCodecMaskForContainer(container_mime_type) & media_type_codec_mask; |
| + if ((key_system_codec_mask & container_codec_mask) == 0) |
| + return false; |
| + |
| + // Check that the codecs are supported by the key system and container. |
| + for (size_t i = 0; i < codecs.size(); i++) { |
| + SupportedCodecs codec = GetCodecForString(codecs[i]); |
| + if ((codec & key_system_codec_mask & container_codec_mask) == 0) |
| + return false; |
| + } |
| + |
| + return true; |
| } |
| EmeConfigRule KeySystemsImpl::GetRobustnessConfigRule( |
| @@ -980,14 +987,6 @@ bool IsSupportedKeySystemWithInitDataType( |
| key_system, init_data_type); |
| } |
| -bool IsSupportedKeySystemWithMediaMimeType( |
| - const std::string& mime_type, |
| - const std::vector<std::string>& codecs, |
| - const std::string& key_system) { |
| - return KeySystemsImpl::GetInstance().IsSupportedKeySystemWithMediaMimeType( |
| - mime_type, codecs, key_system); |
| -} |
| - |
| bool PrefixedIsSupportedKeySystemWithMediaMimeType( |
| const std::string& mime_type, |
| const std::vector<std::string>& codecs, |
| @@ -1021,8 +1020,11 @@ MEDIA_EXPORT void AddContainerMask(const std::string& container, uint32 mask) { |
| KeySystemsImpl::GetInstance().AddContainerMask(container, mask); |
| } |
| -MEDIA_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { |
| - KeySystemsImpl::GetInstance().AddCodecMask(codec, mask); |
| +MEDIA_EXPORT void AddCodecMask( |
| + EmeMediaType media_type, |
| + const std::string& codec, |
| + uint32 mask) { |
| + KeySystemsImpl::GetInstance().AddCodecMask(media_type, codec, mask); |
| } |
| } // namespace media |