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 "content/renderer/media/crypto/key_systems_info.h" | 5 #include "content/renderer/media/crypto/key_systems_info.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/renderer/media/crypto/key_systems.h" | |
9 #include "third_party/WebKit/public/platform/WebString.h" | 8 #include "third_party/WebKit/public/platform/WebString.h" |
10 | 9 |
11 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
12 | 11 |
13 // The following must be after widevine_cdm_version.h. | 12 // The following must be after widevine_cdm_version.h. |
14 | 13 |
15 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 14 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
16 #include <gnu/libc-version.h> | 15 #include <gnu/libc-version.h> |
17 #include "base/version.h" | 16 #include "base/version.h" |
18 #endif | 17 #endif |
19 | 18 |
20 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) | 19 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) |
21 #include "base/command_line.h" | 20 #include "base/command_line.h" |
22 #include "media/base/media_switches.h" | 21 #include "media/base/media_switches.h" |
23 #endif | 22 #endif |
24 | 23 |
25 namespace content { | 24 namespace content { |
26 | 25 |
27 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 26 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
28 | 27 |
29 #if defined(ENABLE_PEPPER_CDMS) | 28 static const char kAudioWebM[] = "audio/webm"; |
30 static const char kExternalClearKeyKeySystem[] = | 29 static const char kVideoWebM[] = "video/webm"; |
31 "org.chromium.externalclearkey"; | 30 static const char kVorbis[] = "vorbis"; |
32 #elif defined(OS_ANDROID) | 31 static const char kVorbisVP8[] = "vorbis,vp8,vp8.0"; |
33 static const uint8 kEmptyUuid[16] = | 32 |
34 { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | 33 static const char kAudioMp4[] = "audio/mp4"; |
35 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; | 34 static const char kVideoMp4[] = "video/mp4"; |
36 static const uint8 kWidevineUuid[16] = | 35 static const char kMp4a[] = "mp4a"; |
37 { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 36 static const char kAvc1[] = "avc1"; |
| 37 static const char kMp4aAvc1[] = "mp4a,avc1"; |
| 38 |
| 39 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 40 enum SupportedCodecs { |
| 41 WEBM_VP8_AND_VORBIS = 1 << 0, |
| 42 #if defined(USE_PROPRIETARY_CODECS) |
| 43 MP4_AAC = 1 << 1, |
| 44 MP4_AVC1 = 1 << 2, |
| 45 #endif // defined(USE_PROPRIETARY_CODECS) |
| 46 }; |
| 47 |
| 48 static void AddWidevineForTypes( |
| 49 SupportedCodecs supported_codecs, |
| 50 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 51 static const char kWidevineParentKeySystem[] = "com.widevine"; |
| 52 #if defined(OS_ANDROID) |
| 53 static const uint8 kWidevineUuid[16] = { |
| 54 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
38 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | 55 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
39 #endif | 56 #endif |
40 | 57 |
41 #if defined(WIDEVINE_CDM_AVAILABLE) | |
42 | |
43 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) | |
44 // The supported codecs depend on what the CDM provides. | |
45 static const char kWidevineVideoMp4Codecs[] = | |
46 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) && \ | |
47 defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) | |
48 "avc1,mp4a"; | |
49 #elif defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) | |
50 "avc1"; | |
51 #else | |
52 ""; // No codec strings are supported. | |
53 #endif | |
54 | |
55 static const char kWidevineAudioMp4Codecs[] = | |
56 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) | |
57 "mp4a"; | |
58 #else | |
59 ""; // No codec strings are supported. | |
60 #endif | |
61 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) | |
62 | |
63 static void RegisterWidevine() { | |
64 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 58 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
65 Version glibc_version(gnu_get_libc_version()); | 59 Version glibc_version(gnu_get_libc_version()); |
66 DCHECK(glibc_version.IsValid()); | 60 DCHECK(glibc_version.IsValid()); |
67 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) | 61 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) |
68 return; | 62 return; |
69 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 63 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
70 | 64 |
71 AddConcreteSupportedKeySystem( | 65 KeySystemInfo info(kWidevineKeySystem); |
72 kWidevineKeySystem, | 66 |
73 false, | 67 if (supported_codecs & WEBM_VP8_AND_VORBIS) { |
| 68 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); |
| 69 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); |
| 70 } |
| 71 |
| 72 #if defined(USE_PROPRIETARY_CODECS) |
| 73 if (supported_codecs & MP4_AAC) |
| 74 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); |
| 75 |
| 76 if (supported_codecs & MP4_AVC1) { |
| 77 const char* video_codecs = (supported_codecs & MP4_AAC) ? kMp4aAvc1 : kAvc1; |
| 78 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs)); |
| 79 } |
| 80 #endif // defined(USE_PROPRIETARY_CODECS) |
| 81 |
| 82 info.parent_key_system = kWidevineParentKeySystem; |
| 83 |
74 #if defined(ENABLE_PEPPER_CDMS) | 84 #if defined(ENABLE_PEPPER_CDMS) |
75 kWidevineCdmPluginMimeType, | 85 info.pepper_type = kWidevineCdmPluginMimeType; |
76 #elif defined(OS_ANDROID) | 86 #elif defined(OS_ANDROID) |
77 kWidevineUuid, | 87 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid)); |
78 #endif // defined(ENABLE_PEPPER_CDMS) | 88 #endif // defined(ENABLE_PEPPER_CDMS) |
79 "com.widevine"); | |
80 #if !defined(OS_ANDROID) | |
81 AddSupportedType(kWidevineKeySystem, "video/webm", "vorbis,vp8,vp8.0"); | |
82 AddSupportedType(kWidevineKeySystem, "audio/webm", "vorbis"); | |
83 #endif // !defined(OS_ANDROID) | |
84 #if defined(USE_PROPRIETARY_CODECS) && \ | |
85 defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) | |
86 AddSupportedType(kWidevineKeySystem, "video/mp4", kWidevineVideoMp4Codecs); | |
87 AddSupportedType(kWidevineKeySystem, "audio/mp4", kWidevineAudioMp4Codecs); | |
88 #endif // defined(USE_PROPRIETARY_CODECS) && | |
89 // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) | |
90 } | |
91 #endif // WIDEVINE_CDM_AVAILABLE | |
92 | 89 |
93 | 90 concrete_key_systems->push_back(info); |
94 static void RegisterClearKey() { | |
95 // Clear Key. | |
96 AddConcreteSupportedKeySystem( | |
97 kClearKeyKeySystem, | |
98 true, | |
99 #if defined(ENABLE_PEPPER_CDMS) | |
100 std::string(), | |
101 #elif defined(OS_ANDROID) | |
102 kEmptyUuid, | |
103 #endif // defined(ENABLE_PEPPER_CDMS) | |
104 std::string()); | |
105 AddSupportedType(kClearKeyKeySystem, "video/webm", "vorbis,vp8,vp8.0"); | |
106 AddSupportedType(kClearKeyKeySystem, "audio/webm", "vorbis"); | |
107 #if defined(USE_PROPRIETARY_CODECS) | |
108 AddSupportedType(kClearKeyKeySystem, "video/mp4", "avc1,mp4a"); | |
109 AddSupportedType(kClearKeyKeySystem, "audio/mp4", "mp4a"); | |
110 #endif // defined(USE_PROPRIETARY_CODECS) | |
111 } | 91 } |
112 | 92 |
113 #if defined(ENABLE_PEPPER_CDMS) | 93 #if defined(ENABLE_PEPPER_CDMS) |
114 static void RegisterExternalClearKey() { | 94 // Supported types are determined at compile time. |
115 // External Clear Key (used for testing). | 95 static void AddPepperBasedWidevine( |
116 AddConcreteSupportedKeySystem(kExternalClearKeyKeySystem, false, | 96 std::vector<KeySystemInfo>* concrete_key_systems) { |
117 "application/x-ppapi-clearkey-cdm", | 97 SupportedCodecs supported_codecs = WEBM_VP8_AND_VORBIS; |
118 std::string()); | 98 |
119 AddSupportedType(kExternalClearKeyKeySystem, | |
120 "video/webm", "vorbis,vp8,vp8.0"); | |
121 AddSupportedType(kExternalClearKeyKeySystem, "audio/webm", "vorbis"); | |
122 #if defined(USE_PROPRIETARY_CODECS) | 99 #if defined(USE_PROPRIETARY_CODECS) |
123 AddSupportedType(kExternalClearKeyKeySystem, "video/mp4", "avc1,mp4a"); | 100 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) |
124 AddSupportedType(kExternalClearKeyKeySystem, "audio/mp4", "mp4a"); | 101 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AAC); |
| 102 #endif |
| 103 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) |
| 104 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AVC1); |
| 105 #endif |
125 #endif // defined(USE_PROPRIETARY_CODECS) | 106 #endif // defined(USE_PROPRIETARY_CODECS) |
| 107 |
| 108 AddWidevineForTypes(supported_codecs, concrete_key_systems); |
| 109 } |
| 110 #elif defined(OS_ANDROID) |
| 111 static void AddAndroidWidevine( |
| 112 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 113 SupportedCodecs supported_codecs = MP4_AAC | MP4_AVC1; |
| 114 AddWidevineForTypes(supported_codecs, concrete_key_systems); |
| 115 } |
| 116 #endif // defined(ENABLE_PEPPER_CDMS) |
| 117 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 118 |
| 119 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { |
| 120 KeySystemInfo info(kClearKeyKeySystem); |
| 121 |
| 122 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); |
| 123 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); |
| 124 #if defined(USE_PROPRIETARY_CODECS) |
| 125 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); |
| 126 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); |
| 127 #endif // defined(USE_PROPRIETARY_CODECS) |
| 128 |
| 129 info.use_aes_decryptor = true; |
| 130 |
| 131 concrete_key_systems->push_back(info); |
| 132 } |
| 133 |
| 134 #if defined(ENABLE_PEPPER_CDMS) |
| 135 // External Clear Key (used for testing). |
| 136 static void AddExternalClearKey( |
| 137 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 138 static const char kExternalClearKeyKeySystem[] = |
| 139 "org.chromium.externalclearkey"; |
| 140 static const char kExternalClearKeyPepperType[] = |
| 141 "application/x-ppapi-clearkey-cdm"; |
| 142 |
| 143 KeySystemInfo info(kExternalClearKeyKeySystem); |
| 144 |
| 145 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); |
| 146 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); |
| 147 #if defined(USE_PROPRIETARY_CODECS) |
| 148 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); |
| 149 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); |
| 150 #endif // defined(USE_PROPRIETARY_CODECS) |
| 151 |
| 152 info.pepper_type = kExternalClearKeyPepperType; |
| 153 |
| 154 concrete_key_systems->push_back(info); |
126 } | 155 } |
127 #endif // defined(ENABLE_PEPPER_CDMS) | 156 #endif // defined(ENABLE_PEPPER_CDMS) |
128 | 157 |
129 void RegisterKeySystems() { | 158 void AddKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
130 RegisterClearKey(); | 159 AddClearKey(key_systems_info); |
131 | 160 |
132 #if defined(ENABLE_PEPPER_CDMS) | 161 #if defined(ENABLE_PEPPER_CDMS) |
133 RegisterExternalClearKey(); | 162 AddExternalClearKey(key_systems_info); |
134 #endif | 163 #endif |
135 | 164 |
136 #if defined(WIDEVINE_CDM_AVAILABLE) | 165 #if defined(WIDEVINE_CDM_AVAILABLE) |
137 RegisterWidevine(); | 166 #if defined(ENABLE_PEPPER_CDMS) |
| 167 AddPepperBasedWidevine(key_systems_info); |
| 168 #elif defined(OS_ANDROID) |
| 169 AddAndroidWidevine(key_systems_info); |
| 170 #endif |
138 #endif | 171 #endif |
139 } | 172 } |
140 | 173 |
141 bool IsCanPlayTypeSuppressed(const std::string& key_system) { | 174 bool IsCanPlayTypeSuppressed(const std::string& key_system) { |
142 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) | 175 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) |
143 // See http://crbug.com/237627. | 176 // See http://crbug.com/237627. |
144 if (key_system == kWidevineKeySystem && | 177 if (key_system == kWidevineKeySystem && |
145 !CommandLine::ForCurrentProcess()->HasSwitch( | 178 !CommandLine::ForCurrentProcess()->HasSwitch( |
146 switches::kOverrideEncryptedMediaCanPlayType)) | 179 switches::kOverrideEncryptedMediaCanPlayType)) |
147 return true; | 180 return true; |
148 #endif | 181 #endif |
149 return false; | 182 return false; |
150 } | 183 } |
151 | 184 |
152 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { | 185 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { |
153 if (key_system == kClearKeyKeySystem) | 186 if (key_system == kClearKeyKeySystem) |
154 return "ClearKey"; | 187 return "ClearKey"; |
155 #if defined(WIDEVINE_CDM_AVAILABLE) | 188 #if defined(WIDEVINE_CDM_AVAILABLE) |
156 if (key_system == kWidevineKeySystem) | 189 if (key_system == kWidevineKeySystem) |
157 return "Widevine"; | 190 return "Widevine"; |
158 #endif // WIDEVINE_CDM_AVAILABLE | 191 #endif // WIDEVINE_CDM_AVAILABLE |
159 return "Unknown"; | 192 return "Unknown"; |
160 } | 193 } |
161 | 194 |
162 } // namespace content | 195 } // namespace content |
OLD | NEW |