Chromium Code Reviews| 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 "components/encrypted_media/renderer/widevine_key_systems.h" | |
| 15 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
| 16 | 17 |
| 17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 18 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 18 | 19 |
| 19 // The following must be after widevine_cdm_version.h. | 20 // The following must be after widevine_cdm_version.h. |
| 20 | 21 |
| 21 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 22 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
| 22 #include <gnu/libc-version.h> | 23 #include <gnu/libc-version.h> |
| 23 #include "base/version.h" | 24 #include "base/version.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 #if defined(OS_ANDROID) | |
| 27 #include "chrome/common/encrypted_media_messages_android.h" | |
| 28 #endif | |
| 29 | |
| 30 using content::KeySystemInfo; | 27 using content::KeySystemInfo; |
| 31 using content::SupportedCodecs; | 28 using content::SupportedCodecs; |
| 32 | 29 |
| 33 #if defined(ENABLE_PEPPER_CDMS) | 30 #if defined(ENABLE_PEPPER_CDMS) |
| 34 static bool IsPepperCdmRegistered( | 31 static bool IsPepperCdmRegistered( |
| 35 const std::string& pepper_type, | 32 const std::string& pepper_type, |
| 36 std::vector<base::string16>* additional_param_names, | 33 std::vector<base::string16>* additional_param_names, |
| 37 std::vector<base::string16>* additional_param_values) { | 34 std::vector<base::string16>* additional_param_values) { |
| 38 bool is_registered = false; | 35 bool is_registered = false; |
| 39 content::RenderThread::Get()->Send( | 36 content::RenderThread::Get()->Send( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 // failure case. | 91 // failure case. |
| 95 info.key_system = kExternalClearKeyInitializeFailKeySystem; | 92 info.key_system = kExternalClearKeyInitializeFailKeySystem; |
| 96 concrete_key_systems->push_back(info); | 93 concrete_key_systems->push_back(info); |
| 97 | 94 |
| 98 // A key system that triggers a crash in ClearKeyCdm. | 95 // A key system that triggers a crash in ClearKeyCdm. |
| 99 info.key_system = kExternalClearKeyCrashKeySystem; | 96 info.key_system = kExternalClearKeyCrashKeySystem; |
| 100 concrete_key_systems->push_back(info); | 97 concrete_key_systems->push_back(info); |
| 101 } | 98 } |
| 102 #endif // defined(ENABLE_PEPPER_CDMS) | 99 #endif // defined(ENABLE_PEPPER_CDMS) |
| 103 | 100 |
| 104 | 101 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) |
| 105 #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() { | 102 static bool IsWidevineHrSupported() { |
| 116 // TODO(jrummell): Need to call CheckPlatformState() but it is | 103 // TODO(jrummell): Need to call CheckPlatformState() but it is |
| 117 // asynchronous, and needs to be done in the browser. | 104 // asynchronous, and needs to be done in the browser. |
| 118 return false; | 105 return false; |
| 119 } | 106 } |
| 120 #endif | |
| 121 | 107 |
| 122 // Return |name|'s parent key system. | |
| 123 static std::string GetDirectParentName(std::string name) { | |
| 124 int last_period = name.find_last_of('.'); | |
| 125 DCHECK_GT(last_period, 0); | |
| 126 return name.substr(0, last_period); | |
| 127 } | |
| 128 | |
| 129 static void AddWidevineWithCodecs( | |
| 130 WidevineCdmType widevine_cdm_type, | |
| 131 SupportedCodecs supported_codecs, | |
| 132 std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 133 KeySystemInfo info(kWidevineKeySystem); | |
| 134 | |
| 135 switch (widevine_cdm_type) { | |
| 136 case WIDEVINE: | |
| 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 | |
| 152 // 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 | |
| 154 // initDataType. | |
| 155 info.supported_codecs = supported_codecs; | |
| 156 | |
| 157 #if defined(ENABLE_PEPPER_CDMS) | |
| 158 info.pepper_type = kWidevineCdmPluginMimeType; | |
| 159 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 160 | |
| 161 concrete_key_systems->push_back(info); | |
| 162 } | |
| 163 | |
| 164 #if defined(ENABLE_PEPPER_CDMS) | |
| 165 // When the adapter is registered, a name-value pair is inserted in | 108 // 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 | 109 // additional_param_* that lists the supported codecs. The name is "codecs" and |
| 167 // the value is a comma-delimited list of codecs. | 110 // the value is a comma-delimited list of codecs. |
| 168 // This function finds "codecs" and parses the value into the vector |codecs|. | 111 // 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 | 112 // 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. | 113 // this simplifies the rest of the code in this file. |
| 171 void GetSupportedCodecs( | 114 static void GetSupportedCodecs( |
| 172 const std::vector<base::string16>& additional_param_names, | 115 const std::vector<base::string16>& additional_param_names, |
| 173 const std::vector<base::string16>& additional_param_values, | 116 const std::vector<base::string16>& additional_param_values, |
| 174 std::vector<std::string>* codecs) { | 117 SupportedCodecs* result_supported_codecs) { |
| 175 DCHECK(codecs->empty()); | |
| 176 DCHECK_EQ(additional_param_names.size(), additional_param_values.size()); | 118 DCHECK_EQ(additional_param_names.size(), additional_param_values.size()); |
| 119 std::vector<std::string> codecs; | |
| 177 for (size_t i = 0; i < additional_param_names.size(); ++i) { | 120 for (size_t i = 0; i < additional_param_names.size(); ++i) { |
| 178 if (additional_param_names[i] == | 121 if (additional_param_names[i] == |
| 179 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)) { | 122 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)) { |
| 180 const base::string16& codecs_string16 = additional_param_values[i]; | 123 const base::string16& codecs_string16 = additional_param_values[i]; |
| 181 std::string codecs_string; | 124 std::string codecs_string; |
| 182 if (!base::UTF16ToUTF8(codecs_string16.c_str(), | 125 if (!base::UTF16ToUTF8(codecs_string16.c_str(), |
| 183 codecs_string16.length(), | 126 codecs_string16.length(), |
| 184 &codecs_string)) { | 127 &codecs_string)) { |
| 185 DLOG(WARNING) << "Non-UTF-8 codecs string."; | 128 DLOG(WARNING) << "Non-UTF-8 codecs string."; |
| 186 // Continue using the best effort conversion. | 129 // Continue using the best effort conversion. |
| 187 } | 130 } |
| 188 base::SplitString(codecs_string, | 131 base::SplitString(codecs_string, |
| 189 kCdmSupportedCodecsValueDelimiter, | 132 kCdmSupportedCodecsValueDelimiter, |
| 190 codecs); | 133 &codecs); |
| 191 break; | 134 break; |
| 192 } | 135 } |
| 193 } | 136 } |
| 194 } | |
| 195 | |
| 196 static void AddPepperBasedWidevine( | |
| 197 std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 198 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | |
| 199 Version glibc_version(gnu_get_libc_version()); | |
| 200 DCHECK(glibc_version.IsValid()); | |
| 201 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) | |
| 202 return; | |
| 203 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | |
| 204 | |
| 205 std::vector<base::string16> additional_param_names; | |
| 206 std::vector<base::string16> additional_param_values; | |
| 207 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, | |
| 208 &additional_param_names, | |
| 209 &additional_param_values)) { | |
| 210 DVLOG(1) << "Widevine CDM is not currently available."; | |
| 211 return; | |
| 212 } | |
| 213 | |
| 214 std::vector<std::string> codecs; | |
| 215 GetSupportedCodecs(additional_param_names, additional_param_values, &codecs); | |
| 216 | 137 |
| 217 SupportedCodecs supported_codecs = content::EME_CODEC_NONE; | 138 SupportedCodecs supported_codecs = content::EME_CODEC_NONE; |
| 218 for (size_t i = 0; i < codecs.size(); ++i) { | 139 for (size_t i = 0; i < codecs.size(); ++i) { |
| 219 if (codecs[i] == kCdmSupportedCodecVorbis) | 140 if (codecs[i] == kCdmSupportedCodecVorbis) |
|
ddorwin
2014/05/02 01:12:58
These constants are currently defined in widevine_
| |
| 220 supported_codecs |= content::EME_CODEC_WEBM_VORBIS; | 141 supported_codecs |= content::EME_CODEC_WEBM_VORBIS; |
| 221 if (codecs[i] == kCdmSupportedCodecVp8) | 142 if (codecs[i] == kCdmSupportedCodecVp8) |
| 222 supported_codecs |= content::EME_CODEC_WEBM_VP8; | 143 supported_codecs |= content::EME_CODEC_WEBM_VP8; |
| 223 #if defined(USE_PROPRIETARY_CODECS) | 144 #if defined(USE_PROPRIETARY_CODECS) |
| 224 if (codecs[i] == kCdmSupportedCodecAac) | 145 if (codecs[i] == kCdmSupportedCodecAac) |
| 225 supported_codecs |= content::EME_CODEC_MP4_AAC; | 146 supported_codecs |= content::EME_CODEC_MP4_AAC; |
| 226 if (codecs[i] == kCdmSupportedCodecAvc1) | 147 if (codecs[i] == kCdmSupportedCodecAvc1) |
| 227 supported_codecs |= content::EME_CODEC_MP4_AVC1; | 148 supported_codecs |= content::EME_CODEC_MP4_AVC1; |
| 228 #endif // defined(USE_PROPRIETARY_CODECS) | 149 #endif // defined(USE_PROPRIETARY_CODECS) |
| 229 } | 150 } |
| 151 *result_supported_codecs = supported_codecs; | |
| 152 } | |
| 230 | 153 |
| 231 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 154 static bool IsWidevineCdmAvailable(SupportedCodecs* supported_codecs) { |
|
xhwang
2014/05/01 22:41:22
The function name doesn't reflect what the functio
ycheo (away)
2014/05/01 23:27:32
Yes, the naming is difficult.
I have 3 options and
xhwang
2014/05/02 00:22:31
This is only used before calling AddPepperBasedWid
ycheo (away)
2014/05/02 00:30:26
That means I need to componentize PluginInfoMessag
ddorwin
2014/05/02 01:12:58
Since we have all the details in components, I thi
ycheo (away)
2014/05/02 10:05:46
I applied the second one.
| |
| 155 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | |
| 156 Version glibc_version(gnu_get_libc_version()); | |
| 157 DCHECK(glibc_version.IsValid()); | |
| 158 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) | |
| 159 return false; | |
| 160 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | |
| 232 | 161 |
| 233 if (IsWidevineHrSupported()) | 162 std::vector<base::string16> additional_param_names; |
| 234 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | 163 std::vector<base::string16> additional_param_values; |
| 235 } | 164 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, |
| 236 #elif defined(OS_ANDROID) | 165 &additional_param_names, |
| 237 static void AddAndroidWidevine( | 166 &additional_param_values)) { |
| 238 std::vector<KeySystemInfo>* concrete_key_systems) { | 167 DVLOG(1) << "Widevine CDM is not currently available."; |
| 239 SupportedKeySystemRequest request; | 168 return false; |
| 240 SupportedKeySystemResponse response; | |
| 241 | |
| 242 request.key_system = kWidevineKeySystem; | |
| 243 request.codecs = content::EME_CODEC_WEBM_ALL | content::EME_CODEC_MP4_ALL; | |
| 244 content::RenderThread::Get()->Send( | |
| 245 new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); | |
| 246 DCHECK(response.compositing_codecs & content::EME_CODEC_ALL) | |
| 247 << "unrecognized codec"; | |
| 248 DCHECK(response.non_compositing_codecs & content::EME_CODEC_ALL) | |
| 249 << "unrecognized codec"; | |
| 250 if (response.compositing_codecs != content::EME_CODEC_NONE) { | |
| 251 AddWidevineWithCodecs( | |
| 252 WIDEVINE, | |
| 253 static_cast<SupportedCodecs>(response.compositing_codecs), | |
| 254 concrete_key_systems); | |
| 255 } | 169 } |
| 256 | 170 |
| 257 if (response.non_compositing_codecs != content::EME_CODEC_NONE) { | 171 GetSupportedCodecs(additional_param_names, additional_param_values, |
| 258 AddWidevineWithCodecs( | 172 supported_codecs); |
| 259 WIDEVINE_HR_NON_COMPOSITING, | 173 return true; |
| 260 static_cast<SupportedCodecs>(response.non_compositing_codecs), | |
| 261 concrete_key_systems); | |
| 262 } | |
| 263 } | 174 } |
| 264 #endif // defined(ENABLE_PEPPER_CDMS) | 175 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(ENABLE_PEPPER_CDMS) |
| 265 #endif // defined(WIDEVINE_CDM_AVAILABLE) | |
| 266 | 176 |
| 267 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | 177 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
| 268 #if defined(ENABLE_PEPPER_CDMS) | 178 #if defined(ENABLE_PEPPER_CDMS) |
| 269 AddExternalClearKey(key_systems_info); | 179 AddExternalClearKey(key_systems_info); |
| 270 #endif | 180 #endif |
| 271 | 181 |
| 272 #if defined(WIDEVINE_CDM_AVAILABLE) | 182 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 273 #if defined(ENABLE_PEPPER_CDMS) | 183 #if defined(ENABLE_PEPPER_CDMS) |
| 274 AddPepperBasedWidevine(key_systems_info); | 184 SupportedCodecs supported_codecs; |
| 185 if (IsWidevineCdmAvailable(&supported_codecs)) { | |
| 186 encrypted_media::AddPepperBasedWidevine(key_systems_info, | |
| 187 IsWidevineHrSupported(), | |
| 188 supported_codecs); | |
| 189 } | |
| 275 #elif defined(OS_ANDROID) | 190 #elif defined(OS_ANDROID) |
| 276 AddAndroidWidevine(key_systems_info); | 191 encrypted_media::AddAndroidWidevine(key_systems_info); |
| 277 #endif | 192 #endif // defined(ENABLE_PEPPER_CDMS) |
| 278 #endif | 193 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 279 } | 194 } |
| OLD | NEW |