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) | |
27 #include "chrome/common/encrypted_media_messages_android.h" | |
28 #endif | |
29 | |
30 using content::KeySystemInfo; | 26 using content::KeySystemInfo; |
31 | 27 using media::SupportedCodecs; |
32 const char kAudioWebM[] = "audio/webm"; | |
33 const char kVideoWebM[] = "video/webm"; | |
34 const char kVorbis[] = "vorbis"; | |
35 const char kVP8[] = "vp8"; | |
36 const char kVP80[] = "vp8.0"; | |
37 | |
38 #if defined(USE_PROPRIETARY_CODECS) | |
39 const char kAudioMp4[] = "audio/mp4"; | |
40 const char kVideoMp4[] = "video/mp4"; | |
41 const char kMp4a[] = "mp4a"; | |
42 const char kAvc1[] = "avc1"; | |
43 const char kAvc3[] = "avc3"; | |
44 #endif // defined(USE_PROPRIETARY_CODECS) | |
45 | 28 |
46 #if defined(ENABLE_PEPPER_CDMS) | 29 #if defined(ENABLE_PEPPER_CDMS) |
47 static bool IsPepperCdmRegistered( | 30 static bool IsPepperCdmRegistered( |
48 const std::string& pepper_type, | 31 const std::string& pepper_type, |
49 std::vector<base::string16>* additional_param_names, | 32 std::vector<base::string16>* additional_param_names, |
50 std::vector<base::string16>* additional_param_values) { | 33 std::vector<base::string16>* additional_param_values) { |
51 bool is_registered = false; | 34 bool is_registered = false; |
52 content::RenderThread::Get()->Send( | 35 content::RenderThread::Get()->Send( |
53 new ChromeViewHostMsg_IsInternalPluginRegisteredForMimeType( | 36 new ChromeViewHostMsg_IsInternalPluginRegisteredForMimeType( |
54 pepper_type, | 37 pepper_type, |
(...skipping 23 matching lines...) Expand all Loading... |
78 std::vector<base::string16> additional_param_names; | 61 std::vector<base::string16> additional_param_names; |
79 std::vector<base::string16> additional_param_values; | 62 std::vector<base::string16> additional_param_values; |
80 if (!IsPepperCdmRegistered(kExternalClearKeyPepperType, | 63 if (!IsPepperCdmRegistered(kExternalClearKeyPepperType, |
81 &additional_param_names, | 64 &additional_param_names, |
82 &additional_param_values)) { | 65 &additional_param_values)) { |
83 return; | 66 return; |
84 } | 67 } |
85 | 68 |
86 KeySystemInfo info(kExternalClearKeyKeySystem); | 69 KeySystemInfo info(kExternalClearKeyKeySystem); |
87 | 70 |
88 info.supported_types[kAudioWebM].insert(kVorbis); | 71 info.supported_codecs = media::WEBM_CODECS; |
89 info.supported_types[kVideoWebM] = info.supported_types[kAudioWebM]; | |
90 info.supported_types[kVideoWebM].insert(kVP8); | |
91 info.supported_types[kVideoWebM].insert(kVP80); | |
92 #if defined(USE_PROPRIETARY_CODECS) | 72 #if defined(USE_PROPRIETARY_CODECS) |
93 info.supported_types[kAudioMp4].insert(kMp4a); | 73 info.supported_codecs |= media::MP4_CODECS; |
94 info.supported_types[kVideoMp4] = info.supported_types[kAudioMp4]; | |
95 info.supported_types[kVideoMp4].insert(kAvc1); | |
96 info.supported_types[kVideoMp4].insert(kAvc3); | |
97 #endif // defined(USE_PROPRIETARY_CODECS) | 74 #endif // defined(USE_PROPRIETARY_CODECS) |
98 | 75 |
99 info.pepper_type = kExternalClearKeyPepperType; | 76 info.pepper_type = kExternalClearKeyPepperType; |
100 | 77 |
101 concrete_key_systems->push_back(info); | 78 concrete_key_systems->push_back(info); |
102 | 79 |
103 // Add support of decrypt-only mode in ClearKeyCdm. | 80 // Add support of decrypt-only mode in ClearKeyCdm. |
104 info.key_system = kExternalClearKeyDecryptOnlyKeySystem; | 81 info.key_system = kExternalClearKeyDecryptOnlyKeySystem; |
105 concrete_key_systems->push_back(info); | 82 concrete_key_systems->push_back(info); |
106 | 83 |
(...skipping 16 matching lines...) Expand all Loading... |
123 | 100 |
124 #if defined(WIDEVINE_CDM_AVAILABLE) | 101 #if defined(WIDEVINE_CDM_AVAILABLE) |
125 enum WidevineCdmType { | 102 enum WidevineCdmType { |
126 WIDEVINE, | 103 WIDEVINE, |
127 WIDEVINE_HR, | 104 WIDEVINE_HR, |
128 #if defined(OS_ANDROID) | 105 #if defined(OS_ANDROID) |
129 WIDEVINE_HR_NON_COMPOSITING, | 106 WIDEVINE_HR_NON_COMPOSITING, |
130 #endif | 107 #endif |
131 }; | 108 }; |
132 | 109 |
133 // Defines bitmask values used to specify supported codecs. | |
134 // Each value represents a codec within a specific container. | |
135 // The mask values are stored in a SupportedCodecs. | |
136 typedef uint32 SupportedCodecs; | |
137 enum SupportedCodecMasks { | |
138 NO_CODECS = 0, | |
139 WEBM_VORBIS = 1 << 0, | |
140 WEBM_VP8 = 1 << 1, | |
141 WEBM_CODECS = (WEBM_VORBIS | WEBM_VP8), | |
142 #if defined(USE_PROPRIETARY_CODECS) | |
143 MP4_AAC = 1 << 2, | |
144 MP4_AVC1 = 1 << 3, | |
145 MP4_CODECS = (MP4_AAC | MP4_AVC1), | |
146 ALL_CODECS = (WEBM_CODECS | MP4_CODECS), | |
147 #else | |
148 ALL_CODECS = WEBM_CODECS, | |
149 #endif // defined(USE_PROPRIETARY_CODECS) | |
150 INVALID_CODECS = ~ALL_CODECS | |
151 }; | |
152 | 110 |
153 #if defined(OS_ANDROID) | 111 #if !defined(OS_ANDROID) |
154 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | |
155 COMPILE_ASSERT(static_cast<int>(name) == \ | |
156 static_cast<int>(android::name), \ | |
157 mismatching_enums) | |
158 COMPILE_ASSERT_MATCHING_ENUM(NO_CODECS); | |
159 COMPILE_ASSERT_MATCHING_ENUM(WEBM_VORBIS); | |
160 COMPILE_ASSERT_MATCHING_ENUM(WEBM_VP8); | |
161 COMPILE_ASSERT_MATCHING_ENUM(WEBM_CODECS); | |
162 COMPILE_ASSERT_MATCHING_ENUM(MP4_AAC); | |
163 COMPILE_ASSERT_MATCHING_ENUM(MP4_AVC1); | |
164 COMPILE_ASSERT_MATCHING_ENUM(MP4_CODECS); | |
165 COMPILE_ASSERT_MATCHING_ENUM(ALL_CODECS); | |
166 COMPILE_ASSERT_MATCHING_ENUM(INVALID_CODECS); | |
167 #undef COMPILE_ASSERT_MATCHING_ENUM | |
168 #else | |
169 static bool IsWidevineHrSupported() { | 112 static bool IsWidevineHrSupported() { |
170 // TODO(jrummell): Need to call CheckPlatformState() but it is | 113 // TODO(jrummell): Need to call CheckPlatformState() but it is |
171 // asynchronous, and needs to be done in the browser. | 114 // asynchronous, and needs to be done in the browser. |
172 return false; | 115 return false; |
173 } | 116 } |
174 #endif | 117 #endif |
175 | 118 |
176 // Return |name|'s parent key system. | 119 // Return |name|'s parent key system. |
177 static std::string GetDirectParentName(std::string name) { | 120 static std::string GetDirectParentName(std::string name) { |
178 int last_period = name.find_last_of('.'); | 121 int last_period = name.find_last_of('.'); |
(...skipping 17 matching lines...) Expand all Loading... |
196 break; | 139 break; |
197 #if defined(OS_ANDROID) | 140 #if defined(OS_ANDROID) |
198 case WIDEVINE_HR_NON_COMPOSITING: | 141 case WIDEVINE_HR_NON_COMPOSITING: |
199 info.key_system.append(".hrnoncompositing"); | 142 info.key_system.append(".hrnoncompositing"); |
200 break; | 143 break; |
201 #endif | 144 #endif |
202 default: | 145 default: |
203 NOTREACHED(); | 146 NOTREACHED(); |
204 } | 147 } |
205 | 148 |
206 // TODO(xhwang): A container or an initDataType may be supported even though | 149 info.supported_codecs = supported_codecs; |
207 // there are no codecs supported in that container. Fix this when we support | |
208 // initDataType. | |
209 if (supported_codecs & WEBM_CODECS) { | |
210 if (supported_codecs & WEBM_VORBIS) | |
211 info.supported_types[kAudioWebM].insert(kVorbis); | |
212 | |
213 if (supported_codecs & WEBM_VP8) { | |
214 info.supported_types[kVideoWebM] = info.supported_types[kAudioWebM]; | |
215 info.supported_types[kVideoWebM].insert(kVP8); | |
216 info.supported_types[kVideoWebM].insert(kVP80); | |
217 } | |
218 } | |
219 | |
220 #if defined(USE_PROPRIETARY_CODECS) | |
221 if (supported_codecs & MP4_CODECS) { | |
222 if (supported_codecs & MP4_AAC) | |
223 info.supported_types[kAudioMp4].insert(kMp4a); | |
224 | |
225 if (supported_codecs & MP4_AVC1) { | |
226 info.supported_types[kVideoMp4] = info.supported_types[kAudioMp4]; | |
227 info.supported_types[kVideoMp4].insert(kAvc1); | |
228 info.supported_types[kVideoMp4].insert(kAvc3); | |
229 } | |
230 } | |
231 #endif // defined(USE_PROPRIETARY_CODECS) | |
232 | 150 |
233 #if defined(ENABLE_PEPPER_CDMS) | 151 #if defined(ENABLE_PEPPER_CDMS) |
234 info.pepper_type = kWidevineCdmPluginMimeType; | 152 info.pepper_type = kWidevineCdmPluginMimeType; |
235 #endif // defined(ENABLE_PEPPER_CDMS) | 153 #endif // defined(ENABLE_PEPPER_CDMS) |
236 | 154 |
237 concrete_key_systems->push_back(info); | 155 concrete_key_systems->push_back(info); |
238 } | 156 } |
239 | 157 |
240 #if defined(ENABLE_PEPPER_CDMS) | 158 #if defined(ENABLE_PEPPER_CDMS) |
241 // When the adapter is registered, a name-value pair is inserted in | 159 // When the adapter is registered, a name-value pair is inserted in |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, | 201 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, |
284 &additional_param_names, | 202 &additional_param_names, |
285 &additional_param_values)) { | 203 &additional_param_values)) { |
286 DVLOG(1) << "Widevine CDM is not currently available."; | 204 DVLOG(1) << "Widevine CDM is not currently available."; |
287 return; | 205 return; |
288 } | 206 } |
289 | 207 |
290 std::vector<std::string> codecs; | 208 std::vector<std::string> codecs; |
291 GetSupportedCodecs(additional_param_names, additional_param_values, &codecs); | 209 GetSupportedCodecs(additional_param_names, additional_param_values, &codecs); |
292 | 210 |
293 SupportedCodecs supported_codecs = NO_CODECS; | 211 SupportedCodecs supported_codecs = media::NO_CODECS; |
294 for (size_t i = 0; i < codecs.size(); ++i) { | 212 for (size_t i = 0; i < codecs.size(); ++i) { |
295 if (codecs[i] == kCdmSupportedCodecVorbis) | 213 if (codecs[i] == kCdmSupportedCodecVorbis) |
296 supported_codecs |= WEBM_VORBIS; | 214 supported_codecs |= media::WEBM_VORBIS; |
297 if (codecs[i] == kCdmSupportedCodecVp8) | 215 if (codecs[i] == kCdmSupportedCodecVp8) |
298 supported_codecs |= WEBM_VP8; | 216 supported_codecs |= media::WEBM_VP8; |
299 #if defined(USE_PROPRIETARY_CODECS) | 217 #if defined(USE_PROPRIETARY_CODECS) |
300 if (codecs[i] == kCdmSupportedCodecAac) | 218 if (codecs[i] == kCdmSupportedCodecAac) |
301 supported_codecs |= MP4_AAC; | 219 supported_codecs |= media::MP4_AAC; |
302 if (codecs[i] == kCdmSupportedCodecAvc1) | 220 if (codecs[i] == kCdmSupportedCodecAvc1) |
303 supported_codecs |= MP4_AVC1; | 221 supported_codecs |= media::MP4_AVC1; |
304 #endif // defined(USE_PROPRIETARY_CODECS) | 222 #endif // defined(USE_PROPRIETARY_CODECS) |
305 } | 223 } |
306 | 224 |
307 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 225 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); |
308 | 226 |
309 if (IsWidevineHrSupported()) | 227 if (IsWidevineHrSupported()) |
310 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | 228 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); |
311 } | 229 } |
312 #elif defined(OS_ANDROID) | 230 #elif defined(OS_ANDROID) |
313 static void AddAndroidWidevine( | 231 static void AddAndroidWidevine( |
314 std::vector<KeySystemInfo>* concrete_key_systems) { | 232 std::vector<KeySystemInfo>* concrete_key_systems) { |
315 SupportedKeySystemRequest request; | 233 SupportedKeySystemRequest request; |
316 SupportedKeySystemResponse response; | 234 SupportedKeySystemResponse response; |
317 | 235 |
318 request.key_system = kWidevineKeySystem; | 236 request.key_system = kWidevineKeySystem; |
319 request.codecs = static_cast<android::SupportedCodecs>(android::WEBM_CODECS | | 237 request.codecs = media::WEBM_CODECS | media::MP4_CODECS; |
320 android::MP4_CODECS); | |
321 content::RenderThread::Get()->Send( | 238 content::RenderThread::Get()->Send( |
322 new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); | 239 new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); |
323 DCHECK_EQ(response.compositing_codecs & android::INVALID_CODECS, | 240 DCHECK_EQ(response.compositing_codecs & media::INVALID_CODECS, |
324 android::NO_CODECS) | 241 media::NO_CODECS) |
325 << "unrecognized codec"; | 242 << "unrecognized codec"; |
326 DCHECK_EQ(response.non_compositing_codecs & android::INVALID_CODECS, | 243 DCHECK_EQ(response.non_compositing_codecs & media::INVALID_CODECS, |
327 android::NO_CODECS) | 244 media::NO_CODECS) |
328 << "unrecognized codec"; | 245 << "unrecognized codec"; |
329 if (response.compositing_codecs != android::NO_CODECS) { | 246 if (response.compositing_codecs != media::NO_CODECS) { |
330 AddWidevineWithCodecs( | 247 AddWidevineWithCodecs( |
331 WIDEVINE, | 248 WIDEVINE, |
332 static_cast<SupportedCodecs>(response.compositing_codecs), | 249 static_cast<SupportedCodecs>(response.compositing_codecs), |
333 concrete_key_systems); | 250 concrete_key_systems); |
334 } | 251 } |
335 | 252 |
336 if (response.non_compositing_codecs != android::NO_CODECS) { | 253 if (response.non_compositing_codecs != media::NO_CODECS) { |
337 AddWidevineWithCodecs( | 254 AddWidevineWithCodecs( |
338 WIDEVINE_HR_NON_COMPOSITING, | 255 WIDEVINE_HR_NON_COMPOSITING, |
339 static_cast<SupportedCodecs>(response.non_compositing_codecs), | 256 static_cast<SupportedCodecs>(response.non_compositing_codecs), |
340 concrete_key_systems); | 257 concrete_key_systems); |
341 } | 258 } |
342 } | 259 } |
343 #endif // defined(ENABLE_PEPPER_CDMS) | 260 #endif // defined(ENABLE_PEPPER_CDMS) |
344 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 261 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
345 | 262 |
346 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | 263 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
347 #if defined(ENABLE_PEPPER_CDMS) | 264 #if defined(ENABLE_PEPPER_CDMS) |
348 AddExternalClearKey(key_systems_info); | 265 AddExternalClearKey(key_systems_info); |
349 #endif | 266 #endif |
350 | 267 |
351 #if defined(WIDEVINE_CDM_AVAILABLE) | 268 #if defined(WIDEVINE_CDM_AVAILABLE) |
352 #if defined(ENABLE_PEPPER_CDMS) | 269 #if defined(ENABLE_PEPPER_CDMS) |
353 AddPepperBasedWidevine(key_systems_info); | 270 AddPepperBasedWidevine(key_systems_info); |
354 #elif defined(OS_ANDROID) | 271 #elif defined(OS_ANDROID) |
355 AddAndroidWidevine(key_systems_info); | 272 AddAndroidWidevine(key_systems_info); |
356 #endif | 273 #endif |
357 #endif | 274 #endif |
358 } | 275 } |
OLD | NEW |