Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / webkit / media / crypto / key_systems_info.cc
blob9b6c8d30904548d9dd48debea07a0cf236a69476
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "webkit/media/crypto/key_systems_info.h"
7 #include "base/basictypes.h"
9 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
11 #if defined(WIDEVINE_CDM_AVAILABLE) && \
12 defined(OS_LINUX) && !defined(OS_CHROMEOS)
13 #include <gnu/libc-version.h>
14 #include "base/logging.h"
15 #include "base/version.h"
16 #endif
18 namespace webkit_media {
20 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
22 static const char kExternalClearKeyKeySystem[] =
23 "org.chromium.externalclearkey";
25 // TODO(ddorwin): Automatically support parent systems: http://crbug.com/164303.
26 static const char kWidevineBaseKeySystem[] = "com.widevine";
28 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
29 // The supported codecs depend on what the CDM provides.
30 static const char kWidevineVideoMp4Codecs[] =
31 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) && \
32 defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
33 "avc1,mp4a";
34 #elif defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
35 "avc1";
36 #else
37 ""; // No codec strings are supported.
38 #endif
40 static const char kWidevineAudioMp4Codecs[] =
41 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
42 "mp4a";
43 #else
44 ""; // No codec strings are supported.
45 #endif
46 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
48 const MediaFormatAndKeySystem kSupportedFormatKeySystemCombinations[] = {
49 // Clear Key.
50 { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem },
51 { "audio/webm", "vorbis", kClearKeyKeySystem },
52 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
53 { "video/mp4", "avc1,mp4a", kClearKeyKeySystem },
54 { "audio/mp4", "mp4a", kClearKeyKeySystem },
55 #endif
57 // External Clear Key (used for testing).
58 { "video/webm", "vorbis,vp8,vp8.0", kExternalClearKeyKeySystem },
59 { "audio/webm", "vorbis", kExternalClearKeyKeySystem },
60 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
61 { "video/mp4", "avc1,mp4a", kExternalClearKeyKeySystem },
62 { "audio/mp4", "mp4a", kExternalClearKeyKeySystem },
63 #endif
65 #if defined(WIDEVINE_CDM_AVAILABLE)
66 // Widevine.
67 { "video/webm", "vorbis,vp8,vp8.0", kWidevineKeySystem },
68 { "audio/webm", "vorbis", kWidevineKeySystem },
69 { "video/webm", "vorbis,vp8,vp8.0", kWidevineBaseKeySystem },
70 { "audio/webm", "vorbis", kWidevineBaseKeySystem },
71 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
72 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
73 { "video/mp4", kWidevineVideoMp4Codecs, kWidevineKeySystem },
74 { "video/mp4", kWidevineVideoMp4Codecs, kWidevineBaseKeySystem },
75 { "audio/mp4", kWidevineAudioMp4Codecs, kWidevineKeySystem },
76 { "audio/mp4", kWidevineAudioMp4Codecs, kWidevineBaseKeySystem },
77 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
78 #endif // defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
79 #endif // WIDEVINE_CDM_AVAILABLE
82 const int kNumSupportedFormatKeySystemCombinations =
83 arraysize(kSupportedFormatKeySystemCombinations);
85 const KeySystemPluginTypePair kKeySystemToPluginTypeMapping[] = {
86 // TODO(xhwang): Update this with the real plugin name.
87 { kExternalClearKeyKeySystem, "application/x-ppapi-clearkey-cdm"},
88 #if defined(WIDEVINE_CDM_AVAILABLE)
89 { kWidevineKeySystem, kWidevineCdmPluginMimeType}
90 #endif // WIDEVINE_CDM_AVAILABLE
93 const int kNumKeySystemToPluginTypeMapping =
94 arraysize(kKeySystemToPluginTypeMapping);
96 bool IsSystemCompatible(const std::string& key_system) {
97 #if defined(WIDEVINE_CDM_AVAILABLE) && \
98 defined(OS_LINUX) && !defined(OS_CHROMEOS)
99 if (key_system == kWidevineKeySystem) {
100 Version glibc_version(gnu_get_libc_version());
101 DCHECK(glibc_version.IsValid());
102 return !glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION);
104 #endif
105 return true;
108 std::string KeySystemNameForUMAGeneric(const std::string& key_system) {
109 if (key_system == kClearKeyKeySystem)
110 return "ClearKey";
111 #if defined(WIDEVINE_CDM_AVAILABLE)
112 if (key_system == kWidevineKeySystem)
113 return "Widevine";
114 #endif // WIDEVINE_CDM_AVAILABLE
115 return "Unknown";
118 bool CanUseBuiltInAesDecryptor(const std::string& key_system) {
119 return key_system == kClearKeyKeySystem;
122 } // namespace webkit_media