Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Unified Diff: content/renderer/media/crypto/key_systems.cc

Issue 246033002: Store SupportedCodecs in KeySystemInfo and KeySystems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/crypto/key_systems.cc
diff --git a/content/renderer/media/crypto/key_systems.cc b/content/renderer/media/crypto/key_systems.cc
index 381616ffe7b8053488aca28a917ffbe1f6613f50..0171d0173ec41fe5f3d80b02d2f59cf3410ec84b 100644
--- a/content/renderer/media/crypto/key_systems.cc
+++ b/content/renderer/media/crypto/key_systems.cc
@@ -4,9 +4,9 @@
#include "content/renderer/media/crypto/key_systems.h"
-#include <map>
#include <string>
+#include "base/containers/hash_tables.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
@@ -14,6 +14,7 @@
#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/key_system_info.h"
#include "content/renderer/media/crypto/key_systems_support_uma.h"
+#include "media/cdm/encrypted_media_codecs.h"
#if defined(OS_ANDROID)
#include "media/base/android/media_codec_bridge.h"
@@ -27,19 +28,38 @@ const char kClearKeyKeySystem[] = "org.w3.clearkey";
const char kPrefixedClearKeyKeySystem[] = "webkit-org.w3.clearkey";
const char kUnsupportedClearKeyKeySystem[] = "unsupported-org.w3.clearkey";
-const char kAudioWebM[] = "audio/webm";
-const char kVideoWebM[] = "video/webm";
-const char kVorbis[] = "vorbis";
-const char kVP8[] = "vp8";
-const char kVP80[] = "vp8.0";
+using media::SupportedCodecs;
+using media::SupportedCodecMask;
+struct CodecMaskMap {
+ const char* type;
+ SupportedCodecMask mask;
+};
+
+// Mapping between container types and the masks of associated codecs.
+// A container is supported iif a codec that belongs to it is supported.
+// Only audio codec can belong to a "audio/*" container. Both audio and video
+// codecs can belong to a "video/*" container.
+CodecMaskMap kContainerMasks[] = {
+ {"audio/webm", media::WEBM_AUDIO},
+ {"video/webm", media::WEBM_CODECS},
#if defined(USE_PROPRIETARY_CODECS)
-const char kAudioMp4[] = "audio/mp4";
-const char kVideoMp4[] = "video/mp4";
-const char kMp4a[] = "mp4a";
-const char kAvc1[] = "avc1";
-const char kAvc3[] = "avc3";
+ {"audio/mp4", media::MP4_AUDIO},
+ {"video/mp4", media::MP4_CODECS}
#endif // defined(USE_PROPRIETARY_CODECS)
+};
+
+// Mapping between codec types and their masks.
+CodecMaskMap kCodecMasks[] = {
+ {"vorbis", media::WEBM_VORBIS},
+ {"vp8", media::WEBM_VP8},
+ {"vp8.0", media::WEBM_VP8},
+#if defined(USE_PROPRIETARY_CODECS)
+ {"mp4a", media::MP4_AAC},
+ {"avc1", media::MP4_AVC1},
+ {"avc3", media::MP4_AVC1}
+#endif // defined(USE_PROPRIETARY_CODECS)
+};
static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) {
KeySystemInfo info(kClearKeyKeySystem);
@@ -52,15 +72,9 @@ static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) {
DCHECK(media::MediaCodecBridge::IsAvailable());
#endif
- info.supported_types[kAudioWebM].insert(kVorbis);
- info.supported_types[kVideoWebM] = info.supported_types[kAudioWebM];
- info.supported_types[kVideoWebM].insert(kVP8);
- info.supported_types[kVideoWebM].insert(kVP80);
+ info.supported_codecs = media::WEBM_CODECS;
#if defined(USE_PROPRIETARY_CODECS)
- info.supported_types[kAudioMp4].insert(kMp4a);
- info.supported_types[kVideoMp4] = info.supported_types[kAudioMp4];
- info.supported_types[kVideoMp4].insert(kAvc1);
- info.supported_types[kVideoMp4].insert(kAvc3);
+ info.supported_codecs |= media::MP4_CODECS;
#endif // defined(USE_PROPRIETARY_CODECS)
info.use_aes_decryptor = true;
@@ -85,10 +99,10 @@ class KeySystems {
std::string GetPepperType(const std::string& concrete_key_system);
#endif
- private:
- typedef KeySystemInfo::CodecSet CodecSet;
- typedef KeySystemInfo::ContainerCodecsMap ContainerCodecsMap;
+ void AddContainerMask(const std::string& container, uint32 mask);
+ void AddCodecMask(const std::string& codec, uint32 mask);
+ private:
void AddConcreteSupportedKeySystems(
const std::vector<KeySystemInfo>& concrete_key_systems);
@@ -98,10 +112,11 @@ class KeySystems {
#if defined(ENABLE_PEPPER_CDMS)
const std::string& pepper_type,
#endif
- const ContainerCodecsMap& supported_types,
+ const SupportedCodecs& supported_codecs,
const std::string& parent_key_system);
friend struct base::DefaultLazyInstanceTraits<KeySystems>;
+ friend class KeySystemsTest;
struct KeySystemProperties {
KeySystemProperties() : use_aes_decryptor(false) {}
@@ -110,12 +125,13 @@ class KeySystems {
#if defined(ENABLE_PEPPER_CDMS)
std::string pepper_type;
#endif
- ContainerCodecsMap supported_types;
+ SupportedCodecs supported_codecs;
};
- typedef std::map<std::string, KeySystemProperties> KeySystemPropertiesMap;
-
- typedef std::map<std::string, std::string> ParentKeySystemMap;
+ typedef base::hash_map<std::string, KeySystemProperties>
+ KeySystemPropertiesMap;
+ typedef base::hash_map<std::string, std::string> ParentKeySystemMap;
+ typedef base::hash_map<std::string, SupportedCodecMask> MaskMap;
KeySystems();
~KeySystems() {}
@@ -133,6 +149,9 @@ class KeySystems {
KeySystemsSupportUMA key_systems_support_uma_;
+ MaskMap container_masks_;
+ MaskMap codec_masks_;
xhwang 2014/04/21 23:12:19 Note: Use hash maps for quick look up.
+
DISALLOW_COPY_AND_ASSIGN(KeySystems);
};
@@ -145,6 +164,14 @@ KeySystems& KeySystems::GetInstance() {
// Because we use a LazyInstance, the key systems info must be populated when
// the instance is lazily initiated.
KeySystems::KeySystems() {
+ // Build container and codec masks for quick look up.
+ for (size_t i = 0; i < arraysize(kContainerMasks); ++i) {
+ container_masks_[kContainerMasks[i].type] = kContainerMasks[i].mask;
+ }
+ for (size_t i = 0; i < arraysize(kCodecMasks); ++i) {
+ codec_masks_[kCodecMasks[i].type] = kCodecMasks[i].mask;
+ }
+
std::vector<KeySystemInfo> key_systems_info;
GetContentClient()->renderer()->AddKeySystems(&key_systems_info);
// Clear Key is always supported.
@@ -164,7 +191,7 @@ void KeySystems::AddConcreteSupportedKeySystems(
#if defined(ENABLE_PEPPER_CDMS)
key_system_info.pepper_type,
#endif
- key_system_info.supported_types,
+ key_system_info.supported_codecs,
key_system_info.parent_key_system);
}
}
@@ -175,7 +202,7 @@ void KeySystems::AddConcreteSupportedKeySystem(
#if defined(ENABLE_PEPPER_CDMS)
const std::string& pepper_type,
#endif
- const ContainerCodecsMap& supported_types,
+ const SupportedCodecs& supported_codecs,
const std::string& parent_key_system) {
DCHECK(!IsConcreteSupportedKeySystem(concrete_key_system))
<< "Key system '" << concrete_key_system << "' already registered";
@@ -190,7 +217,7 @@ void KeySystems::AddConcreteSupportedKeySystem(
properties.pepper_type = pepper_type;
#endif
- properties.supported_types = supported_types;
+ properties.supported_codecs = supported_codecs;
concrete_key_system_map_[concrete_key_system] = properties;
@@ -228,19 +255,28 @@ bool KeySystems::IsSupportedKeySystemWithContainerAndCodec(
if (mime_type.empty())
return true;
- const ContainerCodecsMap& mime_types_map =
- key_system_iter->second.supported_types;
- ContainerCodecsMap::const_iterator mime_iter = mime_types_map.find(mime_type);
- if (mime_iter == mime_types_map.end())
+ const SupportedCodecs& supported_codecs =
+ key_system_iter->second.supported_codecs;
+
+ MaskMap::const_iterator container_iter = container_masks_.find(mime_type);
+ if (container_iter == container_masks_.end() ||
+ !(container_iter->second & supported_codecs)) {
return false;
+ }
if (codec.empty()) {
key_systems_support_uma_.ReportKeySystemSupport(key_system, true);
return true;
}
- const CodecSet& codecs = mime_iter->second;
- if (codecs.find(codec) == codecs.end())
+ MaskMap::const_iterator codec_iter = codec_masks_.find(codec);
+ if (codec_iter == codec_masks_.end() ||
+ !(codec_iter->second & supported_codecs)) {
+ return false;
+ }
+
+ // Unsupported codec/container combination, e.g. "video/webm" and "avc1".
+ if (!(codec_iter->second & container_iter->second))
return false;
key_systems_support_uma_.ReportKeySystemSupport(key_system, true);
@@ -302,6 +338,16 @@ std::string KeySystems::GetPepperType(const std::string& concrete_key_system) {
}
#endif
+void KeySystems::AddContainerMask(const std::string& container, uint32 mask) {
+ DCHECK(container_masks_.find(container) == container_masks_.end());
+ container_masks_[container] = static_cast<media::SupportedCodecMask>(mask);
+}
+
+void KeySystems::AddCodecMask(const std::string& codec, uint32 mask) {
+ DCHECK(codec_masks_.find(codec) == codec_masks_.end());
+ codec_masks_[codec] = static_cast<media::SupportedCodecMask>(mask);
+}
+
//------------------------------------------------------------------------------
std::string GetUnprefixedKeySystemName(const std::string& key_system) {
@@ -355,4 +401,12 @@ std::string GetPepperType(const std::string& concrete_key_system) {
}
#endif
+void AddContainerMask(const std::string& container, uint32 mask) {
+ KeySystems::GetInstance().AddContainerMask(container, mask);
+}
+
+void AddCodecMask(const std::string& codec, uint32 mask) {
+ KeySystems::GetInstance().AddCodecMask(codec, mask);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698