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 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
12 | 12 |
13 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 13 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
14 | 14 |
15 // The following must be after widevine_cdm_version.h. | 15 // The following must be after widevine_cdm_version.h. |
16 | 16 |
17 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 17 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
18 #include <gnu/libc-version.h> | 18 #include <gnu/libc-version.h> |
19 #include "base/version.h" | 19 #include "base/version.h" |
20 #endif | 20 #endif |
21 | 21 |
22 #if defined(OS_ANDROID) | |
23 #include "chrome/common/encrypted_media_messages_android.h" | |
24 #endif | |
25 | |
22 using content::KeySystemInfo; | 26 using content::KeySystemInfo; |
23 | 27 |
24 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 28 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
25 | 29 |
26 static const char kAudioWebM[] = "audio/webm"; | 30 static const char kAudioWebM[] = "audio/webm"; |
27 static const char kVideoWebM[] = "video/webm"; | 31 static const char kVideoWebM[] = "video/webm"; |
28 static const char kVorbis[] = "vorbis"; | 32 static const char kVorbis[] = "vorbis"; |
29 static const char kVorbisVP8[] = "vorbis,vp8,vp8.0"; | 33 static const char kVorbisVP8[] = "vorbis,vp8,vp8.0"; |
30 | 34 |
31 static const char kAudioMp4[] = "audio/mp4"; | 35 static const char kAudioMp4[] = "audio/mp4"; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 #endif // defined(USE_PROPRIETARY_CODECS) | 84 #endif // defined(USE_PROPRIETARY_CODECS) |
81 | 85 |
82 info.pepper_type = kExternalClearKeyPepperType; | 86 info.pepper_type = kExternalClearKeyPepperType; |
83 | 87 |
84 concrete_key_systems->push_back(info); | 88 concrete_key_systems->push_back(info); |
85 } | 89 } |
86 #endif // defined(ENABLE_PEPPER_CDMS) | 90 #endif // defined(ENABLE_PEPPER_CDMS) |
87 | 91 |
88 | 92 |
89 #if defined(WIDEVINE_CDM_AVAILABLE) | 93 #if defined(WIDEVINE_CDM_AVAILABLE) |
94 enum WidevineCdmType { | |
95 WIDEVINE, | |
96 WIDEVINE_HR, | |
97 WIDEVINE_HRSURFACE, | |
98 }; | |
99 | |
90 // Defines bitmask values used to specify supported codecs. | 100 // Defines bitmask values used to specify supported codecs. |
91 // Each value represents a codec within a specific container. | 101 // Each value represents a codec within a specific container. |
92 enum SupportedCodecs { | 102 enum SupportedCodecs { |
93 WEBM_VP8_AND_VORBIS = 1 << 0, | 103 WEBM_VP8_AND_VORBIS = 1 << 0, |
94 #if defined(USE_PROPRIETARY_CODECS) | 104 #if defined(USE_PROPRIETARY_CODECS) |
95 MP4_AAC = 1 << 1, | 105 MP4_AAC = 1 << 1, |
96 MP4_AVC1 = 1 << 2, | 106 MP4_AVC1 = 1 << 2, |
97 #endif // defined(USE_PROPRIETARY_CODECS) | 107 #endif // defined(USE_PROPRIETARY_CODECS) |
98 }; | 108 }; |
99 | 109 |
100 enum WidevineCdmType { | 110 #if defined(OS_ANDROID) |
101 WIDEVINE, | 111 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
102 WIDEVINE_HR, | 112 COMPILE_ASSERT(static_cast<int>(name) == \ |
103 }; | 113 static_cast<int>(android::name), \ |
114 mismatching_enums) | |
115 COMPILE_ASSERT_MATCHING_ENUM(WEBM_VP8_AND_VORBIS); | |
116 COMPILE_ASSERT_MATCHING_ENUM(MP4_AAC); | |
117 COMPILE_ASSERT_MATCHING_ENUM(MP4_AVC1); | |
118 #undef COMPILE_ASSERT_MATCHING_ENUM | |
104 | 119 |
120 static const uint8 kWidevineUuid[16] = { | |
121 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | |
122 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | |
123 #else | |
105 static bool IsWidevineHrSupported() { | 124 static bool IsWidevineHrSupported() { |
106 // TODO(jrummell): Need to call CheckPlatformState() but it is | 125 // TODO(jrummell): Need to call CheckPlatformState() but it is |
107 // asynchronous, and needs to be done in the browser. | 126 // asynchronous, and needs to be done in the browser. |
108 return false; | 127 return false; |
109 } | 128 } |
129 #endif | |
110 | 130 |
111 // Return |name|'s parent key system. | 131 // Return |name|'s parent key system. |
112 static std::string GetDirectParentName(std::string name) { | 132 static std::string GetDirectParentName(std::string name) { |
113 int last_period = name.find_last_of('.'); | 133 int last_period = name.find_last_of('.'); |
114 DCHECK_GT(last_period, 0); | 134 DCHECK_GT(last_period, 0); |
115 return name.substr(0, last_period); | 135 return name.substr(0, last_period); |
116 } | 136 } |
117 | 137 |
118 static void AddWidevineWithCodecs( | 138 static void AddWidevineWithCodecs( |
119 WidevineCdmType widevine_cdm_type, | 139 WidevineCdmType widevine_cdm_type, |
120 SupportedCodecs supported_codecs, | 140 SupportedCodecs supported_codecs, |
121 std::vector<KeySystemInfo>* concrete_key_systems) { | 141 std::vector<KeySystemInfo>* concrete_key_systems) { |
122 | 142 |
123 KeySystemInfo info(kWidevineKeySystem); | 143 KeySystemInfo info(kWidevineKeySystem); |
124 | 144 |
125 switch (widevine_cdm_type) { | 145 switch (widevine_cdm_type) { |
126 case WIDEVINE: | 146 case WIDEVINE: |
127 // For standard Widevine, add parent name. | 147 // For standard Widevine, add parent name. |
128 info.parent_key_system = GetDirectParentName(kWidevineKeySystem); | 148 info.parent_key_system = GetDirectParentName(kWidevineKeySystem); |
129 break; | 149 break; |
130 case WIDEVINE_HR: | 150 case WIDEVINE_HR: |
131 info.key_system.append(".hr"); | 151 info.key_system.append(".hr"); |
132 break; | 152 break; |
153 case WIDEVINE_HRSURFACE: | |
ddorwin
2013/09/19 06:31:51
Should we ifdef ANDROID this since it only applies
qinmin
2013/09/19 14:37:29
hmm... so then we should also ifdef on the enum de
| |
154 info.key_system.append(".hrsurface"); | |
ddorwin
2013/09/19 06:31:51
We need to add an istypesupported test for this li
qinmin
2013/09/19 14:37:29
ok, will add that later.
On 2013/09/19 06:31:51, d
| |
155 break; | |
133 default: | 156 default: |
134 NOTREACHED(); | 157 NOTREACHED(); |
135 } | 158 } |
136 | 159 |
137 if (supported_codecs & WEBM_VP8_AND_VORBIS) { | 160 if (supported_codecs & WEBM_VP8_AND_VORBIS) { |
138 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | 161 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); |
139 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | 162 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); |
140 } | 163 } |
141 | 164 |
142 #if defined(USE_PROPRIETARY_CODECS) | 165 #if defined(USE_PROPRIETARY_CODECS) |
143 if (supported_codecs & MP4_AAC) | 166 if (supported_codecs & MP4_AAC) |
144 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); | 167 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); |
145 | 168 |
146 if (supported_codecs & MP4_AVC1) { | 169 if (supported_codecs & MP4_AVC1) { |
147 const char* video_codecs = (supported_codecs & MP4_AAC) ? kMp4aAvc1 : kAvc1; | 170 const char* video_codecs = (supported_codecs & MP4_AAC) ? kMp4aAvc1 : kAvc1; |
148 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs)); | 171 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs)); |
149 } | 172 } |
150 #endif // defined(USE_PROPRIETARY_CODECS) | 173 #endif // defined(USE_PROPRIETARY_CODECS) |
151 | 174 |
152 #if defined(ENABLE_PEPPER_CDMS) | 175 #if defined(ENABLE_PEPPER_CDMS) |
153 info.pepper_type = kWidevineCdmPluginMimeType; | 176 info.pepper_type = kWidevineCdmPluginMimeType; |
154 #elif defined(OS_ANDROID) | 177 #elif defined(OS_ANDROID) |
155 static const uint8 kWidevineUuid[16] = { | |
156 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | |
157 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | |
158 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid)); | 178 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid)); |
159 #endif // defined(ENABLE_PEPPER_CDMS) | 179 #endif // defined(ENABLE_PEPPER_CDMS) |
160 | 180 |
161 concrete_key_systems->push_back(info); | 181 concrete_key_systems->push_back(info); |
162 } | 182 } |
163 | 183 |
164 #if defined(ENABLE_PEPPER_CDMS) | 184 #if defined(ENABLE_PEPPER_CDMS) |
165 // Supported types are determined at compile time. | 185 // Supported types are determined at compile time. |
166 static void AddPepperBasedWidevine( | 186 static void AddPepperBasedWidevine( |
167 std::vector<KeySystemInfo>* concrete_key_systems) { | 187 std::vector<KeySystemInfo>* concrete_key_systems) { |
(...skipping 21 matching lines...) Expand all Loading... | |
189 #endif // defined(USE_PROPRIETARY_CODECS) | 209 #endif // defined(USE_PROPRIETARY_CODECS) |
190 | 210 |
191 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 211 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); |
192 | 212 |
193 if (IsWidevineHrSupported()) | 213 if (IsWidevineHrSupported()) |
194 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | 214 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); |
195 } | 215 } |
196 #elif defined(OS_ANDROID) | 216 #elif defined(OS_ANDROID) |
197 static void AddAndroidWidevine( | 217 static void AddAndroidWidevine( |
198 std::vector<KeySystemInfo>* concrete_key_systems) { | 218 std::vector<KeySystemInfo>* concrete_key_systems) { |
219 android::SupportedKeySystemRequest request; | |
220 android::SupportedKeySystemResponse response; | |
221 | |
222 request.uuid.insert(request.uuid.begin(), kWidevineUuid, | |
223 kWidevineUuid + arraysize(kWidevineUuid)); | |
199 #if defined(USE_PROPRIETARY_CODECS) | 224 #if defined(USE_PROPRIETARY_CODECS) |
200 SupportedCodecs supported_codecs = | 225 request.codecs = static_cast<android::SupportedCodecs>( |
201 static_cast<SupportedCodecs>(MP4_AAC | MP4_AVC1); | 226 android::MP4_AAC | android::MP4_AVC1); |
202 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 227 #endif // defined(USE_PROPRIETARY_CODECS) |
228 content::RenderThread::Get()->Send( | |
229 new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); | |
230 DCHECK_EQ(response.compositing_codecs >> 3, 0) << "unrecognized codec"; | |
231 DCHECK_EQ(response.non_compositing_codecs >> 3, 0) << "unrecognized codec"; | |
232 if (response.compositing_codecs > 0) { | |
ddorwin
2013/09/19 00:38:17
This should be !=, but we can fix that later.
qinmin
2013/09/19 14:37:29
makes sense, will change this
On 2013/09/19 00:38:
| |
233 AddWidevineWithCodecs( | |
234 WIDEVINE, | |
235 static_cast<SupportedCodecs>(response.compositing_codecs), | |
236 concrete_key_systems); | |
237 } | |
203 | 238 |
204 if (IsWidevineHrSupported()) | 239 if (response.non_compositing_codecs > 0) { |
205 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | 240 AddWidevineWithCodecs( |
206 #endif // defined(USE_PROPRIETARY_CODECS) | 241 WIDEVINE_HRSURFACE, |
242 static_cast<SupportedCodecs>(response.non_compositing_codecs), | |
243 concrete_key_systems); | |
244 } | |
207 } | 245 } |
208 #endif // defined(ENABLE_PEPPER_CDMS) | 246 #endif // defined(ENABLE_PEPPER_CDMS) |
209 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 247 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
210 | 248 |
211 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | 249 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
212 AddClearKey(key_systems_info); | 250 AddClearKey(key_systems_info); |
213 | 251 |
214 #if defined(ENABLE_PEPPER_CDMS) | 252 #if defined(ENABLE_PEPPER_CDMS) |
215 AddExternalClearKey(key_systems_info); | 253 AddExternalClearKey(key_systems_info); |
216 #endif | 254 #endif |
217 | 255 |
218 #if defined(WIDEVINE_CDM_AVAILABLE) | 256 #if defined(WIDEVINE_CDM_AVAILABLE) |
219 #if defined(ENABLE_PEPPER_CDMS) | 257 #if defined(ENABLE_PEPPER_CDMS) |
220 AddPepperBasedWidevine(key_systems_info); | 258 AddPepperBasedWidevine(key_systems_info); |
221 #elif defined(OS_ANDROID) | 259 #elif defined(OS_ANDROID) |
222 AddAndroidWidevine(key_systems_info); | 260 AddAndroidWidevine(key_systems_info); |
223 #endif | 261 #endif |
224 #endif | 262 #endif |
225 } | 263 } |
OLD | NEW |