Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: content/renderer/media/crypto/key_systems_info.cc

Issue 23464005: Explicitly register each key system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
8 #include "third_party/WebKit/public/platform/WebString.h" 9 #include "third_party/WebKit/public/platform/WebString.h"
9 10
10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 11 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
11 12
12 // The following must be after widevine_cdm_version.h. 13 // The following must be after widevine_cdm_version.h.
13 14
14 #if defined(WIDEVINE_CDM_AVAILABLE) && \ 15 #if defined(WIDEVINE_CDM_AVAILABLE) && \
15 defined(OS_LINUX) && !defined(OS_CHROMEOS) 16 defined(OS_LINUX) && !defined(OS_CHROMEOS)
16 #include <gnu/libc-version.h> 17 #include <gnu/libc-version.h>
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/version.h" 19 #include "base/version.h"
19 #endif 20 #endif
20 21
21 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 22 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
22 #include "base/command_line.h" 23 #include "base/command_line.h"
23 #include "media/base/media_switches.h" 24 #include "media/base/media_switches.h"
24 #endif 25 #endif
25 26
26 namespace content { 27 namespace content {
27 28
28 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; 29 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey";
29 30
30 #if defined(ENABLE_PEPPER_CDMS) 31 #if defined(ENABLE_PEPPER_CDMS)
31 static const char kExternalClearKeyKeySystem[] = 32 static const char kExternalClearKeyKeySystem[] =
32 "org.chromium.externalclearkey"; 33 "org.chromium.externalclearkey";
33 #endif // defined(ENABLE_PEPPER_CDMS) 34 #endif // defined(ENABLE_PEPPER_CDMS)
34 35
35 #if defined(WIDEVINE_CDM_AVAILABLE) 36 #if defined(WIDEVINE_CDM_AVAILABLE)
36 // TODO(ddorwin): Automatically support parent systems: http://crbug.com/164303.
37 static const char kWidevineBaseKeySystem[] = "com.widevine";
38 37
39 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) 38 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
40 // The supported codecs depend on what the CDM provides. 39 // The supported codecs depend on what the CDM provides.
41 static const char kWidevineVideoMp4Codecs[] = 40 static const char kWidevineVideoMp4Codecs[] =
42 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) && \ 41 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) && \
43 defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) 42 defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
44 "avc1,mp4a"; 43 "avc1,mp4a";
45 #elif defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) 44 #elif defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
46 "avc1"; 45 "avc1";
47 #else 46 #else
48 ""; // No codec strings are supported. 47 ""; // No codec strings are supported.
49 #endif 48 #endif
50 49
51 static const char kWidevineAudioMp4Codecs[] = 50 static const char kWidevineAudioMp4Codecs[] =
52 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) 51 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
53 "mp4a"; 52 "mp4a";
54 #else 53 #else
55 ""; // No codec strings are supported. 54 ""; // No codec strings are supported.
56 #endif 55 #endif
57 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) 56 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
58 57
59 static inline bool IsWidevine(const std::string& key_system) { 58 static void RegisterWidevine() {
xhwang 2013/08/29 21:45:26 I <3 this function!
ddorwin 2013/08/29 22:20:18 Done.
60 return key_system == kWidevineKeySystem || 59 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
61 key_system == kWidevineBaseKeySystem; 60 Version glibc_version(gnu_get_libc_version());
61 DCHECK(glibc_version.IsValid());
62 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION))
63 return;
64 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
65
66 AddConcreteSupportedKeySystem(
67 kWidevineKeySystem,
68 false,
69 #if defined(ENABLE_PEPPER_CDMS)
70 kWidevineCdmPluginMimeType,
71 #elif defined(OS_ANDROID)
72 { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
73 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED },
74 #endif // defined(ENABLE_PEPPER_CDMS)
75 "com.widevine");
76 AddSupportedType(kWidevineKeySystem, "video/webm", "vorbis,vp8,vp8.0");
77 AddSupportedType(kWidevineKeySystem, "audio/webm", "vorbis");
78 #if defined(USE_PROPRIETARY_CODECS) && \
79 defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
scherkus (not reviewing) 2013/08/29 20:11:47 indent by 2 more
ddorwin 2013/08/29 21:44:04 Done.
80 AddSupportedType(kWidevineKeySystem, "video/mp4", kWidevineVideoMp4Codecs);
81 AddSupportedType(kWidevineKeySystem, "audio/mp4", kWidevineAudioMp4Codecs);
82 #endif // defined(USE_PROPRIETARY_CODECS) &&
83 // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
62 } 84 }
63 #endif // defined(WIDEVINE_CDM_AVAILABLE) 85 #endif // WIDEVINE_CDM_AVAILABLE
64 86
65 const MediaFormatAndKeySystem kSupportedFormatKeySystemCombinations[] = { 87
88 void RegisterKeySystems() {
66 // Clear Key. 89 // Clear Key.
67 { "video/webm", "vorbis,vp8,vp8.0", kClearKeyKeySystem }, 90 AddConcreteSupportedKeySystem(
68 { "audio/webm", "vorbis", kClearKeyKeySystem }, 91 kClearKeyKeySystem,
92 true,
93 #if defined(ENABLE_PEPPER_CDMS)
94 "",
95 #elif defined(OS_ANDROID)
96 { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
97 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, },
98 #endif // defined(ENABLE_PEPPER_CDMS)
99 std::string());
scherkus (not reviewing) 2013/08/29 20:11:47 any reason why you use std::string() here but "" o
ddorwin 2013/08/29 21:44:04 Because I added this one later. :) Done.
100 AddSupportedType(kClearKeyKeySystem, "video/webm", "vorbis,vp8,vp8.0");
101 AddSupportedType(kClearKeyKeySystem, "audio/webm", "vorbis");
69 #if defined(USE_PROPRIETARY_CODECS) 102 #if defined(USE_PROPRIETARY_CODECS)
70 { "video/mp4", "avc1,mp4a", kClearKeyKeySystem }, 103 AddSupportedType(kClearKeyKeySystem, "video/mp4", "avc1,mp4a");
71 { "audio/mp4", "mp4a", kClearKeyKeySystem }, 104 AddSupportedType(kClearKeyKeySystem, "audio/mp4", "mp4a");
72 #endif // defined(USE_PROPRIETARY_CODECS) 105 #endif // defined(USE_PROPRIETARY_CODECS)
73 106
74 #if defined(ENABLE_PEPPER_CDMS) 107 #if defined(ENABLE_PEPPER_CDMS)
75 // External Clear Key (used for testing). 108 // External Clear Key (used for testing).
76 { "video/webm", "vorbis,vp8,vp8.0", kExternalClearKeyKeySystem }, 109 AddConcreteSupportedKeySystem(kExternalClearKeyKeySystem, false,
77 { "audio/webm", "vorbis", kExternalClearKeyKeySystem }, 110 "application/x-ppapi-clearkey-cdm",
111 std::string());
112 AddSupportedType(kExternalClearKeyKeySystem,
113 "video/webm", "vorbis,vp8,vp8.0");
114 AddSupportedType(kExternalClearKeyKeySystem, "audio/webm", "vorbis");
78 #if defined(USE_PROPRIETARY_CODECS) 115 #if defined(USE_PROPRIETARY_CODECS)
79 { "video/mp4", "avc1,mp4a", kExternalClearKeyKeySystem }, 116 AddSupportedType(kExternalClearKeyKeySystem, "video/mp4", "avc1,mp4a");
80 { "audio/mp4", "mp4a", kExternalClearKeyKeySystem }, 117 AddSupportedType(kExternalClearKeyKeySystem, "audio/mp4", "mp4a");
81 #endif // defined(USE_PROPRIETARY_CODECS) 118 #endif // defined(USE_PROPRIETARY_CODECS)
82 #endif // defined(ENABLE_PEPPER_CDMS) 119 #endif // defined(ENABLE_PEPPER_CDMS)
83 120
84 #if defined(WIDEVINE_CDM_AVAILABLE) 121 #if defined(WIDEVINE_CDM_AVAILABLE)
xhwang 2013/08/29 21:45:26 Does it make sense to wrap the above to RegisterCl
ddorwin 2013/08/29 22:20:18 Done. I had considered it and decided not to becau
85 // Widevine. 122 RegisterWidevine();
86 { "video/webm", "vorbis,vp8,vp8.0", kWidevineKeySystem },
87 { "audio/webm", "vorbis", kWidevineKeySystem },
88 #if defined(USE_PROPRIETARY_CODECS)
89 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
90 { "video/mp4", kWidevineVideoMp4Codecs, kWidevineKeySystem },
91 { "audio/mp4", kWidevineAudioMp4Codecs, kWidevineKeySystem },
92 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
93 #endif // defined(USE_PROPRIETARY_CODECS)
94 #endif // WIDEVINE_CDM_AVAILABLE 123 #endif // WIDEVINE_CDM_AVAILABLE
95 };
96
97 const int kNumSupportedFormatKeySystemCombinations =
98 arraysize(kSupportedFormatKeySystemCombinations);
99
100 #if defined(ENABLE_PEPPER_CDMS)
101 const KeySystemPepperTypePair kKeySystemToPepperTypeMapping[] = {
102 { kExternalClearKeyKeySystem, "application/x-ppapi-clearkey-cdm"},
103 #if defined(WIDEVINE_CDM_AVAILABLE)
104 { kWidevineKeySystem, kWidevineCdmPluginMimeType}
105 #endif // WIDEVINE_CDM_AVAILABLE
106 };
107
108 const int kNumKeySystemToPepperTypeMapping =
109 arraysize(kKeySystemToPepperTypeMapping);
110 #endif // defined(ENABLE_PEPPER_CDMS)
111
112 #if defined(OS_ANDROID)
113 // TODO(qinmin): add UUIDs for other key systems.
114 const KeySystemUUIDPair kKeySystemToUUIDMapping[] = {
115 #if defined(WIDEVINE_CDM_AVAILABLE)
116 { kWidevineKeySystem, { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE,
117 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }
118 }
119 #endif // defined(WIDEVINE_CDM_AVAILABLE)
120 };
121
122 // arraySize() does not work if the array is empty, so use ARRAYSIZE_UNSAFE().
123 const int kNumKeySystemToUUIDMapping =
124 ARRAYSIZE_UNSAFE(kKeySystemToUUIDMapping);
125 #endif // defined(OS_ANDROID)
126
127 bool IsOSIncompatible(const std::string& concrete_key_system) {
128 DCHECK(IsConcreteKeySystem(concrete_key_system))
129 << concrete_key_system << " is not a concrete system";
130 #if defined(WIDEVINE_CDM_AVAILABLE) && \
131 defined(OS_LINUX) && !defined(OS_CHROMEOS)
132 if (IsWidevine(concrete_key_system)) {
133 Version glibc_version(gnu_get_libc_version());
134 DCHECK(glibc_version.IsValid());
135 return glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION);
136 }
137 #endif
138 return false;
139 }
140
141 std::string EnsureConcreteKeySystem(const std::string& key_system) {
142 #if defined(WIDEVINE_CDM_AVAILABLE)
143 if (key_system == kWidevineKeySystem || key_system == kWidevineBaseKeySystem)
144 return kWidevineKeySystem;
145 #endif // WIDEVINE_CDM_AVAILABLE
146 // No parent names for Clear Key.
147 if (key_system == kClearKeyKeySystem)
148 return kClearKeyKeySystem;
149 #if defined(ENABLE_PEPPER_CDMS)
150 // No parent names for External Clear Key.
151 if (key_system == kExternalClearKeyKeySystem)
152 return kExternalClearKeyKeySystem;
153 #endif // defined(ENABLE_PEPPER_CDMS)
154 return std::string();
155 } 124 }
156 125
157 bool IsCanPlayTypeSuppressed(const std::string& key_system) { 126 bool IsCanPlayTypeSuppressed(const std::string& key_system) {
158 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) 127 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE)
159 // See http://crbug.com/237627. 128 // See http://crbug.com/237627.
160 if (IsWidevine(key_system) && 129 if (key_system == kWidevineKeySystem &&
161 !CommandLine::ForCurrentProcess()->HasSwitch( 130 !CommandLine::ForCurrentProcess()->HasSwitch(
162 switches::kOverrideEncryptedMediaCanPlayType)) 131 switches::kOverrideEncryptedMediaCanPlayType))
163 return true; 132 return true;
164 #endif 133 #endif
165 return false; 134 return false;
166 } 135 }
167 136
168 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { 137 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) {
169 if (key_system == kClearKeyKeySystem) 138 if (key_system == kClearKeyKeySystem)
170 return "ClearKey"; 139 return "ClearKey";
171 #if defined(WIDEVINE_CDM_AVAILABLE) 140 #if defined(WIDEVINE_CDM_AVAILABLE)
172 if (key_system == kWidevineKeySystem) 141 if (key_system == kWidevineKeySystem)
173 return "Widevine"; 142 return "Widevine";
174 #endif // WIDEVINE_CDM_AVAILABLE 143 #endif // WIDEVINE_CDM_AVAILABLE
175 return "Unknown"; 144 return "Unknown";
176 } 145 }
177 146
178 bool CanUseAesDecryptorInternal(const std::string& key_system) {
179 return key_system == kClearKeyKeySystem;
180 }
181
182 } // namespace content 147 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698