1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
// Copyright 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 "chrome/renderer/media/chrome_key_systems.h"
#include <string>
#include "base/logging.h"
#include "base/strings/string16.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/render_messages.h"
#include "content/public/renderer/render_thread.h"
#include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
// The following must be after widevine_cdm_version.h.
#if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
#include <gnu/libc-version.h>
#include "base/version.h"
#endif
#if defined(OS_ANDROID)
#include "chrome/common/encrypted_media_messages_android.h"
#endif
using content::KeySystemInfo;
const char kAudioWebM[] = "audio/webm";
const char kVideoWebM[] = "video/webm";
const char kVorbis[] = "vorbis";
const char kVorbisVP8[] = "vorbis,vp8,vp8.0";
#if defined(USE_PROPRIETARY_CODECS)
const char kAudioMp4[] = "audio/mp4";
const char kVideoMp4[] = "video/mp4";
const char kMp4a[] = "mp4a";
#if defined(WIDEVINE_CDM_AVAILABLE)
const char kAvc1Avc3[] = "avc1,avc3";
#endif // WIDEVINE_CDM_AVAILABLE
const char kMp4aAvc1Avc3[] = "mp4a,avc1,avc3";
#endif // defined(USE_PROPRIETARY_CODECS)
#if defined(ENABLE_PEPPER_CDMS)
static bool IsPepperCdmRegistered(
const std::string& pepper_type,
std::vector<base::string16>* additional_param_names,
std::vector<base::string16>* additional_param_values) {
bool is_registered = false;
content::RenderThread::Get()->Send(
new ChromeViewHostMsg_IsInternalPluginRegisteredForMimeType(
pepper_type,
&is_registered,
additional_param_names,
additional_param_values));
return is_registered;
}
// External Clear Key (used for testing).
static void AddExternalClearKey(
std::vector<KeySystemInfo>* concrete_key_systems) {
static const char kExternalClearKeyKeySystem[] =
"org.chromium.externalclearkey";
static const char kExternalClearKeyDecryptOnlyKeySystem[] =
"org.chromium.externalclearkey.decryptonly";
static const char kExternalClearKeyFileIOTestKeySystem[] =
"org.chromium.externalclearkey.fileiotest";
static const char kExternalClearKeyInitializeFailKeySystem[] =
"org.chromium.externalclearkey.initializefail";
static const char kExternalClearKeyPepperType[] =
"application/x-ppapi-clearkey-cdm";
std::vector<base::string16> additional_param_names;
std::vector<base::string16> additional_param_values;
if (!IsPepperCdmRegistered(kExternalClearKeyPepperType,
&additional_param_names,
&additional_param_values)) {
return;
}
KeySystemInfo info(kExternalClearKeyKeySystem);
info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
#if defined(USE_PROPRIETARY_CODECS)
info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a));
info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1Avc3));
#endif // defined(USE_PROPRIETARY_CODECS)
info.pepper_type = kExternalClearKeyPepperType;
concrete_key_systems->push_back(info);
// Add support of decrypt-only mode in ClearKeyCdm.
info.key_system = kExternalClearKeyDecryptOnlyKeySystem;
concrete_key_systems->push_back(info);
// A key system that triggers FileIO test in ClearKeyCdm.
info.key_system = kExternalClearKeyFileIOTestKeySystem;
concrete_key_systems->push_back(info);
// A key system that Chrome thinks is supported by ClearKeyCdm, but actually
// will be refused by ClearKeyCdm. This is to test the CDM initialization
// failure case.
info.key_system = kExternalClearKeyInitializeFailKeySystem;
concrete_key_systems->push_back(info);
}
#endif // defined(ENABLE_PEPPER_CDMS)
#if defined(WIDEVINE_CDM_AVAILABLE)
enum WidevineCdmType {
WIDEVINE,
WIDEVINE_HR,
#if defined(OS_ANDROID)
WIDEVINE_HR_NON_COMPOSITING,
#endif
};
// Defines bitmask values used to specify supported codecs.
// Each value represents a codec within a specific container.
// The mask values are stored in a SupportedCodecs.
typedef uint32 SupportedCodecs;
enum SupportedCodecMasks {
NO_CODECS = 0,
WEBM_VP8_AND_VORBIS = 1 << 0,
#if defined(USE_PROPRIETARY_CODECS)
MP4_AAC = 1 << 1,
MP4_AVC1 = 1 << 2,
MP4_CODECS = (MP4_AAC | MP4_AVC1),
#endif // defined(USE_PROPRIETARY_CODECS)
};
#if defined(OS_ANDROID)
#define COMPILE_ASSERT_MATCHING_ENUM(name) \
COMPILE_ASSERT(static_cast<int>(name) == \
static_cast<int>(android::name), \
mismatching_enums)
COMPILE_ASSERT_MATCHING_ENUM(WEBM_VP8_AND_VORBIS);
COMPILE_ASSERT_MATCHING_ENUM(MP4_AAC);
COMPILE_ASSERT_MATCHING_ENUM(MP4_AVC1);
#undef COMPILE_ASSERT_MATCHING_ENUM
static const uint8 kWidevineUuid[16] = {
0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED };
#else
static bool IsWidevineHrSupported() {
// TODO(jrummell): Need to call CheckPlatformState() but it is
// asynchronous, and needs to be done in the browser.
return false;
}
#endif
// Return |name|'s parent key system.
static std::string GetDirectParentName(std::string name) {
int last_period = name.find_last_of('.');
DCHECK_GT(last_period, 0);
return name.substr(0, last_period);
}
static void AddWidevineWithCodecs(
WidevineCdmType widevine_cdm_type,
SupportedCodecs supported_codecs,
std::vector<KeySystemInfo>* concrete_key_systems) {
KeySystemInfo info(kWidevineKeySystem);
switch (widevine_cdm_type) {
case WIDEVINE:
// For standard Widevine, add parent name.
info.parent_key_system = GetDirectParentName(kWidevineKeySystem);
break;
case WIDEVINE_HR:
info.key_system.append(".hr");
break;
#if defined(OS_ANDROID)
case WIDEVINE_HR_NON_COMPOSITING:
info.key_system.append(".hrnoncompositing");
break;
#endif
default:
NOTREACHED();
}
if (supported_codecs & WEBM_VP8_AND_VORBIS) {
info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis));
info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8));
}
#if defined(USE_PROPRIETARY_CODECS)
if (supported_codecs & MP4_CODECS) {
// MP4 container is supported for audio and video if any codec is supported.
bool is_aac_supported = (supported_codecs & MP4_AAC) != NO_CODECS;
bool is_avc1_supported = (supported_codecs & MP4_AVC1) != NO_CODECS;
const char* video_codecs = is_avc1_supported ?
(is_aac_supported ? kMp4aAvc1Avc3 : kAvc1Avc3) :
"";
const char* audio_codecs = is_aac_supported ? kMp4a : "";
info.supported_types.push_back(std::make_pair(kAudioMp4, audio_codecs));
info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs));
}
#endif // defined(USE_PROPRIETARY_CODECS)
#if defined(ENABLE_PEPPER_CDMS)
info.pepper_type = kWidevineCdmPluginMimeType;
#elif defined(OS_ANDROID)
info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid));
#endif // defined(ENABLE_PEPPER_CDMS)
concrete_key_systems->push_back(info);
}
#if defined(ENABLE_PEPPER_CDMS)
// When the adapter is registered, a name-value pair is inserted in
// additional_param_* that lists the supported codecs. The name is "codecs" and
// the value is a comma-delimited list of codecs.
// This function finds "codecs" and parses the value into the vector |codecs|.
// Converts the codec strings to UTF-8 since we only expect ASCII strings and
// this simplifies the rest of the code in this file.
void GetSupportedCodecs(
const std::vector<base::string16>& additional_param_names,
const std::vector<base::string16>& additional_param_values,
std::vector<std::string>* codecs) {
DCHECK(codecs->empty());
DCHECK_EQ(additional_param_names.size(), additional_param_values.size());
for (size_t i = 0; i < additional_param_names.size(); ++i) {
if (additional_param_names[i] ==
base::ASCIIToUTF16(kCdmSupportedCodecsParamName)) {
const base::string16& codecs_string16 = additional_param_values[i];
std::string codecs_string;
if (!base::UTF16ToUTF8(codecs_string16.c_str(),
codecs_string16.length(),
&codecs_string)) {
DLOG(WARNING) << "Non-UTF-8 codecs string.";
// Continue using the best effort conversion.
}
base::SplitString(codecs_string,
kCdmSupportedCodecsValueDelimiter,
codecs);
break;
}
}
}
static void AddPepperBasedWidevine(
std::vector<KeySystemInfo>* concrete_key_systems) {
#if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
base::Version glibc_version(gnu_get_libc_version());
DCHECK(glibc_version.IsValid());
if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION))
return;
#endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
std::vector<base::string16> additional_param_names;
std::vector<base::string16> additional_param_values;
if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType,
&additional_param_names,
&additional_param_values)) {
DVLOG(1) << "Widevine CDM is not currently available.";
return;
}
std::vector<std::string> codecs;
GetSupportedCodecs(additional_param_names, additional_param_values, &codecs);
SupportedCodecs supported_codecs = NO_CODECS;
for (size_t i = 0; i < codecs.size(); ++i) {
// TODO(ddorwin): Break up VP8 and Vorbis. For now, "vp8" implies both.
if (codecs[i] == kCdmSupportedCodecVp8)
supported_codecs |= WEBM_VP8_AND_VORBIS;
#if defined(USE_PROPRIETARY_CODECS)
if (codecs[i] == kCdmSupportedCodecAac)
supported_codecs |= MP4_AAC;
if (codecs[i] == kCdmSupportedCodecAvc1)
supported_codecs |= MP4_AVC1;
#endif // defined(USE_PROPRIETARY_CODECS)
}
AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems);
if (IsWidevineHrSupported())
AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems);
}
#elif defined(OS_ANDROID)
static void AddAndroidWidevine(
std::vector<KeySystemInfo>* concrete_key_systems) {
SupportedKeySystemRequest request;
SupportedKeySystemResponse response;
request.uuid.insert(request.uuid.begin(), kWidevineUuid,
kWidevineUuid + arraysize(kWidevineUuid));
#if defined(USE_PROPRIETARY_CODECS)
request.codecs = static_cast<android::SupportedCodecs>(
android::MP4_AAC | android::MP4_AVC1);
#endif // defined(USE_PROPRIETARY_CODECS)
content::RenderThread::Get()->Send(
new ChromeViewHostMsg_GetSupportedKeySystems(request, &response));
DCHECK_EQ(response.compositing_codecs >> 3, 0) << "unrecognized codec";
DCHECK_EQ(response.non_compositing_codecs >> 3, 0) << "unrecognized codec";
if (response.compositing_codecs != android::NO_SUPPORTED_CODECS) {
AddWidevineWithCodecs(
WIDEVINE,
static_cast<SupportedCodecs>(response.compositing_codecs),
concrete_key_systems);
}
if (response.non_compositing_codecs != android::NO_SUPPORTED_CODECS) {
AddWidevineWithCodecs(
WIDEVINE_HR_NON_COMPOSITING,
static_cast<SupportedCodecs>(response.non_compositing_codecs),
concrete_key_systems);
}
}
#endif // defined(ENABLE_PEPPER_CDMS)
#endif // defined(WIDEVINE_CDM_AVAILABLE)
void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) {
#if defined(ENABLE_PEPPER_CDMS)
AddExternalClearKey(key_systems_info);
#endif
#if defined(WIDEVINE_CDM_AVAILABLE)
#if defined(ENABLE_PEPPER_CDMS)
AddPepperBasedWidevine(key_systems_info);
#elif defined(OS_ANDROID)
AddAndroidWidevine(key_systems_info);
#endif
#endif
}
|