diff options
author | kjyoun@google.com <kjyoun@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-03 01:02:42 +0000 |
---|---|---|
committer | kjyoun@google.com <kjyoun@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-03 01:02:42 +0000 |
commit | 8d43482e16c5b30c30f71ef619f475b0a6de0bc9 (patch) | |
tree | b36b59010c995326c83d837efd3e95d1c72f293a | |
parent | 561c37211b16fe1566c7b93d908903d121008d4b (diff) | |
download | chromium_src-8d43482e16c5b30c30f71ef619f475b0a6de0bc9.zip chromium_src-8d43482e16c5b30c30f71ef619f475b0a6de0bc9.tar.gz chromium_src-8d43482e16c5b30c30f71ef619f475b0a6de0bc9.tar.bz2 |
Move key system constants to separate file.
As a result, in order to override key systems/plugin mapping, only constant table in a separate file has to be replaced.
BUG=179769
TEST=content_unittests
Review URL: https://chromiumcodereview.appspot.com/13470004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191950 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/media/crypto/key_systems.cc | 129 | ||||
-rw-r--r-- | webkit/media/crypto/key_systems_info.cc | 122 | ||||
-rw-r--r-- | webkit/media/crypto/key_systems_info.h | 49 | ||||
-rw-r--r-- | webkit/media/webkit_media.gypi | 9 |
4 files changed, 184 insertions, 125 deletions
diff --git a/webkit/media/crypto/key_systems.cc b/webkit/media/crypto/key_systems.cc index 4a841fc..b9c79d0 100644 --- a/webkit/media/crypto/key_systems.cc +++ b/webkit/media/crypto/key_systems.cc @@ -12,14 +12,7 @@ #include "net/base/mime_util.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" - -#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. - -#if defined(WIDEVINE_CDM_AVAILABLE) && \ - defined(OS_LINUX) && !defined(OS_CHROMEOS) -#include <gnu/libc-version.h> -#include "base/version.h" -#endif +#include "webkit/media/crypto/key_systems_info.h" namespace webkit_media { @@ -29,93 +22,6 @@ static std::string ToASCIIOrEmpty(const WebKit::WebString& string) { return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); } -static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; -static const char kExternalClearKeyKeySystem[] = - "org.chromium.externalclearkey"; - -struct MediaFormatAndKeySystem { - const char* mime_type; - const char* codecs_list; - const char* key_system; -}; - -struct KeySystemPluginTypePair { - const char* key_system; - const char* plugin_type; -}; - -// TODO(ddorwin): Automatically support parent systems: http://crbug.com/164303. -static const char kWidevineBaseKeySystem[] = "com.widevine"; - - -#if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) -// The supported codecs depend on what the CDM provides. -static const char kWidevineVideoMp4Codecs[] = -#if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) && \ - defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) - "avc1,mp4a"; -#elif defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) - "avc1"; -#else - ""; // No codec strings are supported. -#endif - -static const char kWidevineAudioMp4Codecs[] = -#if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) - "mp4a"; -#else - ""; // No codec strings are supported. -#endif -#endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) - -// Specifies the container and codec combinations supported by individual -// key systems. Each line is a container-codecs combination and the key system -// that supports it. Multiple codecs can be listed. In all cases, the container -// without a codec is also supported. -// This list is converted at runtime into individual container-codec-key system -// entries in KeySystems::key_system_map_. -static const MediaFormatAndKeySystem kSupportedFormatKeySystemCombinations[] = { - // Clear Key. - { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, - { "audio/webm", "vorbis", kClearKeyKeySystem }, -#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) - { "video/mp4", "avc1,mp4a", kClearKeyKeySystem }, - { "audio/mp4", "mp4a", kClearKeyKeySystem }, -#endif - - // External Clear Key (used for testing). - { "video/webm", "vorbis,vp8,vp8.0", kExternalClearKeyKeySystem }, - { "audio/webm", "vorbis", kExternalClearKeyKeySystem }, -#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) - { "video/mp4", "avc1,mp4a", kExternalClearKeyKeySystem }, - { "audio/mp4", "mp4a", kExternalClearKeyKeySystem }, -#endif - -#if defined(WIDEVINE_CDM_AVAILABLE) - // Widevine. - { "video/webm", "vorbis,vp8,vp8.0", kWidevineKeySystem }, - { "audio/webm", "vorbis", kWidevineKeySystem }, - { "video/webm", "vorbis,vp8,vp8.0", kWidevineBaseKeySystem }, - { "audio/webm", "vorbis", kWidevineBaseKeySystem }, -#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) -#if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) - { "video/mp4", kWidevineVideoMp4Codecs, kWidevineKeySystem }, - { "video/mp4", kWidevineVideoMp4Codecs, kWidevineBaseKeySystem }, - { "audio/mp4", kWidevineAudioMp4Codecs, kWidevineKeySystem }, - { "audio/mp4", kWidevineAudioMp4Codecs, kWidevineBaseKeySystem }, -#endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) -#endif // defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) -#endif // WIDEVINE_CDM_AVAILABLE -}; - -static const KeySystemPluginTypePair kKeySystemToPluginTypeMapping[] = { - // TODO(xhwang): Update this with the real plugin name. - { kExternalClearKeyKeySystem, "application/x-ppapi-clearkey-cdm" }, -#if defined(WIDEVINE_CDM_AVAILABLE) - { kWidevineKeySystem, kWidevineCdmPluginMimeType } -#endif // WIDEVINE_CDM_AVAILABLE -}; - class KeySystems { public: bool IsSupportedKeySystem(const std::string& key_system); @@ -148,9 +54,7 @@ static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER; KeySystems::KeySystems() { // Initialize the supported media type/key system combinations. - for (size_t i = 0; - i < arraysize(kSupportedFormatKeySystemCombinations); - ++i) { + for (int i = 0; i < kNumSupportedFormatKeySystemCombinations; ++i) { const MediaFormatAndKeySystem& combination = kSupportedFormatKeySystemCombinations[i]; std::vector<std::string> mime_type_codecs; @@ -181,18 +85,6 @@ KeySystems::KeySystems() { } } -static inline bool IsSystemCompatible(const std::string& key_system) { -#if defined(WIDEVINE_CDM_AVAILABLE) && \ - defined(OS_LINUX) && !defined(OS_CHROMEOS) - if (key_system == kWidevineKeySystem) { - Version glibc_version(gnu_get_libc_version()); - DCHECK(glibc_version.IsValid()); - return !glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION); - } -#endif - return true; -} - bool KeySystems::IsSupportedKeySystem(const std::string& key_system) { bool is_supported = key_system_map_.find(key_system) != key_system_map_.end(); return is_supported && IsSystemCompatible(key_system); @@ -244,31 +136,20 @@ bool IsSupportedKeySystemWithMediaMimeType( mime_type, codecs, key_system); } -template<typename T> // T is a stringish type. -static std::string KeySystemNameForUMAGeneric(const T& key_system) { - if (key_system == kClearKeyKeySystem) - return "ClearKey"; -#if defined(WIDEVINE_CDM_AVAILABLE) - if (key_system == kWidevineKeySystem) - return "Widevine"; -#endif // WIDEVINE_CDM_AVAILABLE - return "Unknown"; -} - std::string KeySystemNameForUMA(const std::string& key_system) { return KeySystemNameForUMAGeneric(key_system); } std::string KeySystemNameForUMA(const WebKit::WebString& key_system) { - return KeySystemNameForUMAGeneric(key_system); + return KeySystemNameForUMAGeneric(std::string(key_system.utf8().data())); } bool CanUseAesDecryptor(const std::string& key_system) { - return key_system == kClearKeyKeySystem; + return CanUseBuiltInAesDecryptor(key_system); } std::string GetPluginType(const std::string& key_system) { - for (size_t i = 0; i < arraysize(kKeySystemToPluginTypeMapping); ++i) { + for (int i = 0; i < kNumKeySystemToPluginTypeMapping; ++i) { if (kKeySystemToPluginTypeMapping[i].key_system == key_system) return kKeySystemToPluginTypeMapping[i].plugin_type; } diff --git a/webkit/media/crypto/key_systems_info.cc b/webkit/media/crypto/key_systems_info.cc new file mode 100644 index 0000000..9b6c8d3 --- /dev/null +++ b/webkit/media/crypto/key_systems_info.cc @@ -0,0 +1,122 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/media/crypto/key_systems_info.h" + +#include "base/basictypes.h" + +#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. + +#if defined(WIDEVINE_CDM_AVAILABLE) && \ + defined(OS_LINUX) && !defined(OS_CHROMEOS) +#include <gnu/libc-version.h> +#include "base/logging.h" +#include "base/version.h" +#endif + +namespace webkit_media { + +static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; + +static const char kExternalClearKeyKeySystem[] = + "org.chromium.externalclearkey"; + +// TODO(ddorwin): Automatically support parent systems: http://crbug.com/164303. +static const char kWidevineBaseKeySystem[] = "com.widevine"; + +#if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) +// The supported codecs depend on what the CDM provides. +static const char kWidevineVideoMp4Codecs[] = +#if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) && \ + defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) + "avc1,mp4a"; +#elif defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) + "avc1"; +#else + ""; // No codec strings are supported. +#endif + +static const char kWidevineAudioMp4Codecs[] = +#if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) + "mp4a"; +#else + ""; // No codec strings are supported. +#endif +#endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) + +const MediaFormatAndKeySystem kSupportedFormatKeySystemCombinations[] = { + // Clear Key. + { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, + { "audio/webm", "vorbis", kClearKeyKeySystem }, +#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) + { "video/mp4", "avc1,mp4a", kClearKeyKeySystem }, + { "audio/mp4", "mp4a", kClearKeyKeySystem }, +#endif + + // External Clear Key (used for testing). + { "video/webm", "vorbis,vp8,vp8.0", kExternalClearKeyKeySystem }, + { "audio/webm", "vorbis", kExternalClearKeyKeySystem }, +#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) + { "video/mp4", "avc1,mp4a", kExternalClearKeyKeySystem }, + { "audio/mp4", "mp4a", kExternalClearKeyKeySystem }, +#endif + +#if defined(WIDEVINE_CDM_AVAILABLE) + // Widevine. + { "video/webm", "vorbis,vp8,vp8.0", kWidevineKeySystem }, + { "audio/webm", "vorbis", kWidevineKeySystem }, + { "video/webm", "vorbis,vp8,vp8.0", kWidevineBaseKeySystem }, + { "audio/webm", "vorbis", kWidevineBaseKeySystem }, +#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) +#if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) + { "video/mp4", kWidevineVideoMp4Codecs, kWidevineKeySystem }, + { "video/mp4", kWidevineVideoMp4Codecs, kWidevineBaseKeySystem }, + { "audio/mp4", kWidevineAudioMp4Codecs, kWidevineKeySystem }, + { "audio/mp4", kWidevineAudioMp4Codecs, kWidevineBaseKeySystem }, +#endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) +#endif // defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS) +#endif // WIDEVINE_CDM_AVAILABLE +}; + +const int kNumSupportedFormatKeySystemCombinations = + arraysize(kSupportedFormatKeySystemCombinations); + +const KeySystemPluginTypePair kKeySystemToPluginTypeMapping[] = { + // TODO(xhwang): Update this with the real plugin name. + { kExternalClearKeyKeySystem, "application/x-ppapi-clearkey-cdm"}, +#if defined(WIDEVINE_CDM_AVAILABLE) + { kWidevineKeySystem, kWidevineCdmPluginMimeType} +#endif // WIDEVINE_CDM_AVAILABLE +}; + +const int kNumKeySystemToPluginTypeMapping = + arraysize(kKeySystemToPluginTypeMapping); + +bool IsSystemCompatible(const std::string& key_system) { +#if defined(WIDEVINE_CDM_AVAILABLE) && \ + defined(OS_LINUX) && !defined(OS_CHROMEOS) + if (key_system == kWidevineKeySystem) { + Version glibc_version(gnu_get_libc_version()); + DCHECK(glibc_version.IsValid()); + return !glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION); + } +#endif + return true; +} + +std::string KeySystemNameForUMAGeneric(const std::string& key_system) { + if (key_system == kClearKeyKeySystem) + return "ClearKey"; +#if defined(WIDEVINE_CDM_AVAILABLE) + if (key_system == kWidevineKeySystem) + return "Widevine"; +#endif // WIDEVINE_CDM_AVAILABLE + return "Unknown"; +} + +bool CanUseBuiltInAesDecryptor(const std::string& key_system) { + return key_system == kClearKeyKeySystem; +} + +} // namespace webkit_media diff --git a/webkit/media/crypto/key_systems_info.h b/webkit/media/crypto/key_systems_info.h new file mode 100644 index 0000000..f02abaf --- /dev/null +++ b/webkit/media/crypto/key_systems_info.h @@ -0,0 +1,49 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_MEDIA_CRYPTO_KEY_SYSTEMS_INFO_H_ +#define WEBKIT_MEDIA_CRYPTO_KEY_SYSTEMS_INFO_H_ + +#include <string> + +namespace webkit_media { + +struct MediaFormatAndKeySystem { + const char* mime_type; + const char* codecs_list; + const char* key_system; +}; + +struct KeySystemPluginTypePair { + const char* key_system; + const char* plugin_type; +}; + +// Specifies the container and codec combinations supported by individual +// key systems. Each line is a container-codecs combination and the key system +// that supports it. Multiple codecs can be listed. In all cases, the container +// without a codec is also supported. +// This list is converted at runtime into individual container-codec-key system +// entries in KeySystems::key_system_map_. +extern const MediaFormatAndKeySystem kSupportedFormatKeySystemCombinations[]; +extern const int kNumSupportedFormatKeySystemCombinations; + +// There should be one entry for each key system. +extern const KeySystemPluginTypePair kKeySystemToPluginTypeMapping[]; +extern const int kNumKeySystemToPluginTypeMapping; + +// Returns whether |key_system| is compatible with the user's system. +bool IsSystemCompatible(const std::string& key_system); + +// Returns the name that UMA will use for the given |key_system|. +// This function can be called frequently. Hence this function should be +// implemented not to impact performance. +std::string KeySystemNameForUMAGeneric(const std::string& key_system); + +// Returns whether built-in AesDecryptor can be used for the given |key_system|. +bool CanUseBuiltInAesDecryptor(const std::string& key_system); + +} // namespace webkit_media + +#endif // WEBKIT_MEDIA_CRYPTO_KEY_SYSTEMS_INFO_H_ diff --git a/webkit/media/webkit_media.gypi b/webkit/media/webkit_media.gypi index 827a11a..19e6e23 100644 --- a/webkit/media/webkit_media.gypi +++ b/webkit/media/webkit_media.gypi @@ -29,7 +29,7 @@ 'type': 'static_library', 'variables': { 'enable_wexit_time_destructors': 1, }, 'include_dirs': [ - '<(SHARED_INTERMEDIATE_DIR)', # Needed by key_systems.cc. + '<(SHARED_INTERMEDIATE_DIR)', # Needed by key_systems_info.cc. ], 'dependencies': [ '<(DEPTH)/base/base.gyp:base', @@ -68,6 +68,8 @@ 'cache_util.h', 'crypto/key_systems.cc', 'crypto/key_systems.h', + 'crypto/key_systems_info.cc', + 'crypto/key_systems_info.h', 'crypto/ppapi_decryptor.cc', 'crypto/ppapi_decryptor.h', 'crypto/proxy_decryptor.cc', @@ -125,6 +127,11 @@ ['exclude', '^android/'], ], }], + ['google_tv == 1', { + 'sources!': [ + 'crypto/key_systems_info.cc', + ], + }], ], # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. 'msvs_disabled_warnings': [ 4267, ], |