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 "chrome/renderer/media/chrome_key_systems.h" | 5 #include "chrome/renderer/media/chrome_key_systems.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
15 #include "content/public/renderer/render_thread.h" | 15 #include "content/public/renderer/render_thread.h" |
16 | 16 |
17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
18 | 18 |
19 // The following must be after widevine_cdm_version.h. | 19 // The following must be after widevine_cdm_version.h. |
20 | 20 |
21 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 21 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
22 #include <gnu/libc-version.h> | 22 #include <gnu/libc-version.h> |
23 #include "base/version.h" | 23 #include "base/version.h" |
24 #endif | 24 #endif |
25 | 25 |
26 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
27 #include "chrome/common/encrypted_media_messages_android.h" | 27 #include "components/cdm/renderer/widevine_key_systems.h" |
28 #endif | 28 #endif |
29 | 29 |
30 using content::KeySystemInfo; | 30 using content::KeySystemInfo; |
31 using content::SupportedCodecs; | 31 using content::SupportedCodecs; |
32 | 32 |
33 #if defined(ENABLE_PEPPER_CDMS) | 33 #if defined(ENABLE_PEPPER_CDMS) |
34 static bool IsPepperCdmRegistered( | 34 static bool IsPepperCdmRegistered( |
35 const std::string& pepper_type, | 35 const std::string& pepper_type, |
36 std::vector<base::string16>* additional_param_names, | 36 std::vector<base::string16>* additional_param_names, |
37 std::vector<base::string16>* additional_param_values) { | 37 std::vector<base::string16>* additional_param_values) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // A key system that Chrome thinks is supported by ClearKeyCdm, but actually | 92 // A key system that Chrome thinks is supported by ClearKeyCdm, but actually |
93 // will be refused by ClearKeyCdm. This is to test the CDM initialization | 93 // will be refused by ClearKeyCdm. This is to test the CDM initialization |
94 // failure case. | 94 // failure case. |
95 info.key_system = kExternalClearKeyInitializeFailKeySystem; | 95 info.key_system = kExternalClearKeyInitializeFailKeySystem; |
96 concrete_key_systems->push_back(info); | 96 concrete_key_systems->push_back(info); |
97 | 97 |
98 // A key system that triggers a crash in ClearKeyCdm. | 98 // A key system that triggers a crash in ClearKeyCdm. |
99 info.key_system = kExternalClearKeyCrashKeySystem; | 99 info.key_system = kExternalClearKeyCrashKeySystem; |
100 concrete_key_systems->push_back(info); | 100 concrete_key_systems->push_back(info); |
101 } | 101 } |
102 #endif // defined(ENABLE_PEPPER_CDMS) | |
103 | |
104 | 102 |
105 #if defined(WIDEVINE_CDM_AVAILABLE) | 103 #if defined(WIDEVINE_CDM_AVAILABLE) |
106 enum WidevineCdmType { | |
107 WIDEVINE, | |
108 WIDEVINE_HR, | |
109 #if defined(OS_ANDROID) | |
110 WIDEVINE_HR_NON_COMPOSITING, | |
111 #endif | |
112 }; | |
113 | |
114 #if !defined(OS_ANDROID) | |
115 static bool IsWidevineHrSupported() { | |
116 // TODO(jrummell): Need to call CheckPlatformState() but it is | |
117 // asynchronous, and needs to be done in the browser. | |
118 return false; | |
119 } | |
120 #endif | |
121 | |
122 // Return |name|'s parent key system. | 104 // Return |name|'s parent key system. |
123 static std::string GetDirectParentName(std::string name) { | 105 static std::string GetDirectParentName(std::string name) { |
124 int last_period = name.find_last_of('.'); | 106 int last_period = name.find_last_of('.'); |
125 DCHECK_GT(last_period, 0); | 107 DCHECK_GT(last_period, 0); |
126 return name.substr(0, last_period); | 108 return name.substr(0, last_period); |
127 } | 109 } |
128 | 110 |
129 static void AddWidevineWithCodecs( | 111 static void AddWidevineWithCodecs( |
130 WidevineCdmType widevine_cdm_type, | |
131 SupportedCodecs supported_codecs, | 112 SupportedCodecs supported_codecs, |
132 std::vector<KeySystemInfo>* concrete_key_systems) { | 113 std::vector<KeySystemInfo>* concrete_key_systems) { |
133 KeySystemInfo info(kWidevineKeySystem); | 114 KeySystemInfo info(kWidevineKeySystem); |
134 | 115 |
135 switch (widevine_cdm_type) { | 116 // For standard Widevine, add parent name. |
136 case WIDEVINE: | 117 info.parent_key_system = GetDirectParentName(kWidevineKeySystem); |
137 // For standard Widevine, add parent name. | |
138 info.parent_key_system = GetDirectParentName(kWidevineKeySystem); | |
139 break; | |
140 case WIDEVINE_HR: | |
141 info.key_system.append(".hr"); | |
142 break; | |
143 #if defined(OS_ANDROID) | |
144 case WIDEVINE_HR_NON_COMPOSITING: | |
145 info.key_system.append(".hrnoncompositing"); | |
146 break; | |
147 #endif | |
148 default: | |
149 NOTREACHED(); | |
150 } | |
151 | 118 |
152 // TODO(xhwang): A container or an initDataType may be supported even though | 119 // TODO(xhwang): A container or an initDataType may be supported even though |
153 // there are no codecs supported in that container. Fix this when we support | 120 // there are no codecs supported in that container. Fix this when we support |
154 // initDataType. | 121 // initDataType. |
155 info.supported_codecs = supported_codecs; | 122 info.supported_codecs = supported_codecs; |
156 | 123 |
157 #if defined(ENABLE_PEPPER_CDMS) | |
158 info.pepper_type = kWidevineCdmPluginMimeType; | 124 info.pepper_type = kWidevineCdmPluginMimeType; |
159 #endif // defined(ENABLE_PEPPER_CDMS) | |
160 | 125 |
161 concrete_key_systems->push_back(info); | 126 concrete_key_systems->push_back(info); |
162 } | 127 } |
163 | 128 |
164 #if defined(ENABLE_PEPPER_CDMS) | |
165 // When the adapter is registered, a name-value pair is inserted in | 129 // When the adapter is registered, a name-value pair is inserted in |
166 // additional_param_* that lists the supported codecs. The name is "codecs" and | 130 // additional_param_* that lists the supported codecs. The name is "codecs" and |
167 // the value is a comma-delimited list of codecs. | 131 // the value is a comma-delimited list of codecs. |
168 // This function finds "codecs" and parses the value into the vector |codecs|. | 132 // This function finds "codecs" and parses the value into the vector |codecs|. |
169 // Converts the codec strings to UTF-8 since we only expect ASCII strings and | 133 // Converts the codec strings to UTF-8 since we only expect ASCII strings and |
170 // this simplifies the rest of the code in this file. | 134 // this simplifies the rest of the code in this file. |
171 void GetSupportedCodecs( | 135 void GetSupportedCodecs( |
ddorwin
2014/05/02 17:58:55
Improvement: We should rename this to GetSupported
ycheo (away)
2014/05/05 10:15:08
Done.
Renamed it to GetSupportedCodecsForPepperCdm
| |
172 const std::vector<base::string16>& additional_param_names, | 136 const std::vector<base::string16>& additional_param_names, |
173 const std::vector<base::string16>& additional_param_values, | 137 const std::vector<base::string16>& additional_param_values, |
174 std::vector<std::string>* codecs) { | 138 std::vector<std::string>* codecs) { |
175 DCHECK(codecs->empty()); | 139 DCHECK(codecs->empty()); |
176 DCHECK_EQ(additional_param_names.size(), additional_param_values.size()); | 140 DCHECK_EQ(additional_param_names.size(), additional_param_values.size()); |
177 for (size_t i = 0; i < additional_param_names.size(); ++i) { | 141 for (size_t i = 0; i < additional_param_names.size(); ++i) { |
178 if (additional_param_names[i] == | 142 if (additional_param_names[i] == |
179 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)) { | 143 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)) { |
180 const base::string16& codecs_string16 = additional_param_values[i]; | 144 const base::string16& codecs_string16 = additional_param_values[i]; |
181 std::string codecs_string; | 145 std::string codecs_string; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 supported_codecs |= content::EME_CODEC_WEBM_VP9; | 188 supported_codecs |= content::EME_CODEC_WEBM_VP9; |
225 #if defined(USE_PROPRIETARY_CODECS) | 189 #if defined(USE_PROPRIETARY_CODECS) |
226 if (codecs[i] == kCdmSupportedCodecAac) | 190 if (codecs[i] == kCdmSupportedCodecAac) |
227 supported_codecs |= content::EME_CODEC_MP4_AAC; | 191 supported_codecs |= content::EME_CODEC_MP4_AAC; |
228 if (codecs[i] == kCdmSupportedCodecAvc1) | 192 if (codecs[i] == kCdmSupportedCodecAvc1) |
229 supported_codecs |= content::EME_CODEC_MP4_AVC1; | 193 supported_codecs |= content::EME_CODEC_MP4_AVC1; |
230 #endif // defined(USE_PROPRIETARY_CODECS) | 194 #endif // defined(USE_PROPRIETARY_CODECS) |
231 } | 195 } |
232 | 196 |
233 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 197 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); |
234 | |
235 if (IsWidevineHrSupported()) | |
236 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | |
237 } | 198 } |
238 #elif defined(OS_ANDROID) | 199 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
239 static void AddAndroidWidevine( | |
240 std::vector<KeySystemInfo>* concrete_key_systems) { | |
241 SupportedKeySystemRequest request; | |
242 SupportedKeySystemResponse response; | |
243 | |
244 request.key_system = kWidevineKeySystem; | |
245 request.codecs = content::EME_CODEC_WEBM_ALL | content::EME_CODEC_MP4_ALL; | |
246 content::RenderThread::Get()->Send( | |
247 new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); | |
248 DCHECK(response.compositing_codecs & content::EME_CODEC_ALL) | |
249 << "unrecognized codec"; | |
250 DCHECK(response.non_compositing_codecs & content::EME_CODEC_ALL) | |
251 << "unrecognized codec"; | |
252 if (response.compositing_codecs != content::EME_CODEC_NONE) { | |
253 AddWidevineWithCodecs( | |
254 WIDEVINE, | |
255 static_cast<SupportedCodecs>(response.compositing_codecs), | |
256 concrete_key_systems); | |
257 } | |
258 | |
259 if (response.non_compositing_codecs != content::EME_CODEC_NONE) { | |
260 AddWidevineWithCodecs( | |
261 WIDEVINE_HR_NON_COMPOSITING, | |
262 static_cast<SupportedCodecs>(response.non_compositing_codecs), | |
263 concrete_key_systems); | |
264 } | |
265 } | |
266 #endif // defined(ENABLE_PEPPER_CDMS) | 200 #endif // defined(ENABLE_PEPPER_CDMS) |
267 #endif // defined(WIDEVINE_CDM_AVAILABLE) | |
268 | 201 |
269 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | 202 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
270 #if defined(ENABLE_PEPPER_CDMS) | 203 #if defined(ENABLE_PEPPER_CDMS) |
ddorwin
2014/05/02 17:58:55
I wonder if we should move the ifdef logic to the
ycheo (away)
2014/05/05 10:15:08
Done.
| |
271 AddExternalClearKey(key_systems_info); | 204 AddExternalClearKey(key_systems_info); |
272 #endif | 205 #endif |
273 | 206 |
274 #if defined(WIDEVINE_CDM_AVAILABLE) | 207 #if defined(WIDEVINE_CDM_AVAILABLE) |
275 #if defined(ENABLE_PEPPER_CDMS) | 208 #if defined(ENABLE_PEPPER_CDMS) |
276 AddPepperBasedWidevine(key_systems_info); | 209 AddPepperBasedWidevine(key_systems_info); |
277 #elif defined(OS_ANDROID) | 210 #elif defined(OS_ANDROID) |
278 AddAndroidWidevine(key_systems_info); | 211 cdm::AddAndroidWidevine(key_systems_info); |
279 #endif | 212 #endif |
280 #endif | 213 #endif |
281 } | 214 } |
OLD | NEW |