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" | |
| 11 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 15 #include "content/public/renderer/render_thread.h" | 14 #include "content/public/renderer/render_thread.h" |
| 16 | 15 |
| 17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 16 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 18 | 17 |
| 19 // The following must be after widevine_cdm_version.h. | 18 // The following must be after widevine_cdm_version.h. |
| 20 | 19 |
| 21 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 20 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
| 22 #include <gnu/libc-version.h> | 21 #include <gnu/libc-version.h> |
| 23 #include "base/version.h" | 22 #include "base/version.h" |
| 24 #endif | 23 #endif |
| 25 | 24 |
| 26 #if defined(OS_ANDROID) | |
| 27 #include "chrome/common/encrypted_media_messages_android.h" | |
| 28 #endif | |
| 29 | |
| 30 using content::KeySystemInfo; | 25 using content::KeySystemInfo; |
| 31 using content::SupportedCodecs; | 26 using content::SupportedCodecs; |
| 32 | 27 |
| 33 #if defined(ENABLE_PEPPER_CDMS) | 28 #if defined(ENABLE_PEPPER_CDMS) |
| 34 static bool IsPepperCdmRegistered( | 29 static bool IsPepperCdmRegistered( |
| 35 const std::string& pepper_type, | 30 const std::string& pepper_type, |
| 36 std::vector<base::string16>* additional_param_names, | 31 std::vector<base::string16>* additional_param_names, |
| 37 std::vector<base::string16>* additional_param_values) { | 32 std::vector<base::string16>* additional_param_values) { |
| 38 bool is_registered = false; | 33 bool is_registered = false; |
| 39 content::RenderThread::Get()->Send( | 34 content::RenderThread::Get()->Send( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 // A key system that Chrome thinks is supported by ClearKeyCdm, but actually | 87 // A key system that Chrome thinks is supported by ClearKeyCdm, but actually |
| 93 // will be refused by ClearKeyCdm. This is to test the CDM initialization | 88 // will be refused by ClearKeyCdm. This is to test the CDM initialization |
| 94 // failure case. | 89 // failure case. |
| 95 info.key_system = kExternalClearKeyInitializeFailKeySystem; | 90 info.key_system = kExternalClearKeyInitializeFailKeySystem; |
| 96 concrete_key_systems->push_back(info); | 91 concrete_key_systems->push_back(info); |
| 97 | 92 |
| 98 // A key system that triggers a crash in ClearKeyCdm. | 93 // A key system that triggers a crash in ClearKeyCdm. |
| 99 info.key_system = kExternalClearKeyCrashKeySystem; | 94 info.key_system = kExternalClearKeyCrashKeySystem; |
| 100 concrete_key_systems->push_back(info); | 95 concrete_key_systems->push_back(info); |
| 101 } | 96 } |
| 102 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 103 | |
| 104 | 97 |
| 105 #if defined(WIDEVINE_CDM_AVAILABLE) | 98 #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) | 99 #if !defined(OS_ANDROID) |
| 115 static bool IsWidevineHrSupported() { | 100 static bool IsWidevineHrSupported() { |
| 116 // TODO(jrummell): Need to call CheckPlatformState() but it is | 101 // TODO(jrummell): Need to call CheckPlatformState() but it is |
| 117 // asynchronous, and needs to be done in the browser. | 102 // asynchronous, and needs to be done in the browser. |
| 118 return false; | 103 return false; |
| 119 } | 104 } |
| 120 #endif | 105 #endif |
| 121 | 106 |
| 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 | 107 // 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 | 108 // additional_param_* that lists the supported codecs. The name is "codecs" and |
| 167 // the value is a comma-delimited list of codecs. | 109 // the value is a comma-delimited list of codecs. |
| 168 // This function finds "codecs" and parses the value into the vector |codecs|. | 110 // 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 | 111 // 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. | 112 // this simplifies the rest of the code in this file. |
| 171 void GetSupportedCodecs( | 113 void GetSupportedCodecs( |
| 172 const std::vector<base::string16>& additional_param_names, | 114 const std::vector<base::string16>& additional_param_names, |
| 173 const std::vector<base::string16>& additional_param_values, | 115 const std::vector<base::string16>& additional_param_values, |
| 174 std::vector<std::string>* codecs) { | 116 std::vector<std::string>* codecs) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 188 base::SplitString(codecs_string, | 130 base::SplitString(codecs_string, |
| 189 kCdmSupportedCodecsValueDelimiter, | 131 kCdmSupportedCodecsValueDelimiter, |
| 190 codecs); | 132 codecs); |
| 191 break; | 133 break; |
| 192 } | 134 } |
| 193 } | 135 } |
| 194 } | 136 } |
| 195 | 137 |
| 196 static void AddPepperBasedWidevine( | 138 static void AddPepperBasedWidevine( |
| 197 std::vector<KeySystemInfo>* concrete_key_systems) { | 139 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 140 static const char kKeySystemSuffixHr[] = ".hr"; | |
| 198 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 141 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
| 199 Version glibc_version(gnu_get_libc_version()); | 142 Version glibc_version(gnu_get_libc_version()); |
| 200 DCHECK(glibc_version.IsValid()); | 143 DCHECK(glibc_version.IsValid()); |
| 201 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) | 144 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) |
| 202 return; | 145 return; |
| 203 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 146 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
| 204 | 147 |
| 205 std::vector<base::string16> additional_param_names; | 148 std::vector<base::string16> additional_param_names; |
| 206 std::vector<base::string16> additional_param_values; | 149 std::vector<base::string16> additional_param_values; |
| 207 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, | 150 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 221 if (codecs[i] == kCdmSupportedCodecVp8) | 164 if (codecs[i] == kCdmSupportedCodecVp8) |
| 222 supported_codecs |= content::EME_CODEC_WEBM_VP8; | 165 supported_codecs |= content::EME_CODEC_WEBM_VP8; |
| 223 #if defined(USE_PROPRIETARY_CODECS) | 166 #if defined(USE_PROPRIETARY_CODECS) |
| 224 if (codecs[i] == kCdmSupportedCodecAac) | 167 if (codecs[i] == kCdmSupportedCodecAac) |
| 225 supported_codecs |= content::EME_CODEC_MP4_AAC; | 168 supported_codecs |= content::EME_CODEC_MP4_AAC; |
| 226 if (codecs[i] == kCdmSupportedCodecAvc1) | 169 if (codecs[i] == kCdmSupportedCodecAvc1) |
| 227 supported_codecs |= content::EME_CODEC_MP4_AVC1; | 170 supported_codecs |= content::EME_CODEC_MP4_AVC1; |
| 228 #endif // defined(USE_PROPRIETARY_CODECS) | 171 #endif // defined(USE_PROPRIETARY_CODECS) |
| 229 } | 172 } |
| 230 | 173 |
| 231 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 174 concrete_key_systems->push_back(KeySystemInfo::Build( |
| 175 kWidevineKeySystem, | |
| 176 true, // has_parent | |
| 177 NULL, // suffix | |
| 178 kWidevineCdmPluginMimeType, | |
| 179 supported_codecs)); | |
| 232 | 180 |
| 233 if (IsWidevineHrSupported()) | 181 if (IsWidevineHrSupported()) { |
| 234 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | 182 concrete_key_systems->push_back(KeySystemInfo::Build( |
| 235 } | 183 kWidevineKeySystem, |
| 236 #elif defined(OS_ANDROID) | 184 false, // has_parent |
| 237 static void AddAndroidWidevine( | 185 kKeySystemSuffixHr, // suffix |
| 238 std::vector<KeySystemInfo>* concrete_key_systems) { | 186 kWidevineCdmPluginMimeType, |
| 239 SupportedKeySystemRequest request; | 187 supported_codecs)); |
| 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 } | |
| 256 | |
| 257 if (response.non_compositing_codecs != content::EME_CODEC_NONE) { | |
| 258 AddWidevineWithCodecs( | |
| 259 WIDEVINE_HR_NON_COMPOSITING, | |
| 260 static_cast<SupportedCodecs>(response.non_compositing_codecs), | |
| 261 concrete_key_systems); | |
| 262 } | 188 } |
| 263 } | 189 } |
| 190 #endif // defined(WIDEVINE_CDM_AVAILABLE) | |
| 264 #endif // defined(ENABLE_PEPPER_CDMS) | 191 #endif // defined(ENABLE_PEPPER_CDMS) |
| 265 #endif // defined(WIDEVINE_CDM_AVAILABLE) | |
| 266 | 192 |
| 267 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | 193 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
| 268 #if defined(ENABLE_PEPPER_CDMS) | 194 #if defined(ENABLE_PEPPER_CDMS) |
| 269 AddExternalClearKey(key_systems_info); | 195 AddExternalClearKey(key_systems_info); |
| 270 #endif | |
| 271 | |
| 272 #if defined(WIDEVINE_CDM_AVAILABLE) | 196 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 273 #if defined(ENABLE_PEPPER_CDMS) | |
| 274 AddPepperBasedWidevine(key_systems_info); | 197 AddPepperBasedWidevine(key_systems_info); |
| 275 #elif defined(OS_ANDROID) | |
| 276 AddAndroidWidevine(key_systems_info); | |
| 277 #endif | 198 #endif |
|
Tom Sepez
2014/04/28 18:21:52
nit: // defined ... while you're at it, since you'
| |
| 278 #endif | 199 #endif |
| 279 } | 200 } |
| OLD | NEW |