| 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/cdm/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 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 | 89 // 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 | 90 // will be refused by ClearKeyCdm. This is to test the CDM initialization |
| 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) | |
| 103 | |
| 104 | 99 |
| 105 #if defined(WIDEVINE_CDM_AVAILABLE) | 100 #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() { | |
| 116 // TODO(jrummell): Need to call CheckPlatformState() but it is | |
| 117 // asynchronous, and needs to be done in the browser. | |
| 118 return false; | |
| 119 } | |
| 120 #endif | |
| 121 | |
| 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 | |
| 166 // additional_param_* that lists the supported codecs. The name is "codecs" and | |
| 167 // the value is a comma-delimited list of codecs. | |
| 168 // This function finds "codecs" and parses the value into the vector |codecs|. | 101 // 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 | 102 // 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. | 103 // this simplifies the rest of the code in this file. |
| 171 void GetSupportedCodecs( | 104 void GetSupportedCodecsForPepperCdm( |
| 172 const std::vector<base::string16>& additional_param_names, | 105 const std::vector<base::string16>& additional_param_names, |
| 173 const std::vector<base::string16>& additional_param_values, | 106 const std::vector<base::string16>& additional_param_values, |
| 174 std::vector<std::string>* codecs) { | 107 std::vector<std::string>* codecs) { |
| 175 DCHECK(codecs->empty()); | 108 DCHECK(codecs->empty()); |
| 176 DCHECK_EQ(additional_param_names.size(), additional_param_values.size()); | 109 DCHECK_EQ(additional_param_names.size(), additional_param_values.size()); |
| 177 for (size_t i = 0; i < additional_param_names.size(); ++i) { | 110 for (size_t i = 0; i < additional_param_names.size(); ++i) { |
| 178 if (additional_param_names[i] == | 111 if (additional_param_names[i] == |
| 179 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)) { | 112 base::ASCIIToUTF16(kCdmSupportedCodecsParamName)) { |
| 180 const base::string16& codecs_string16 = additional_param_values[i]; | 113 const base::string16& codecs_string16 = additional_param_values[i]; |
| 181 std::string codecs_string; | 114 std::string codecs_string; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 205 std::vector<base::string16> additional_param_names; | 138 std::vector<base::string16> additional_param_names; |
| 206 std::vector<base::string16> additional_param_values; | 139 std::vector<base::string16> additional_param_values; |
| 207 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, | 140 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, |
| 208 &additional_param_names, | 141 &additional_param_names, |
| 209 &additional_param_values)) { | 142 &additional_param_values)) { |
| 210 DVLOG(1) << "Widevine CDM is not currently available."; | 143 DVLOG(1) << "Widevine CDM is not currently available."; |
| 211 return; | 144 return; |
| 212 } | 145 } |
| 213 | 146 |
| 214 std::vector<std::string> codecs; | 147 std::vector<std::string> codecs; |
| 215 GetSupportedCodecs(additional_param_names, additional_param_values, &codecs); | 148 GetSupportedCodecsForPepperCdm(additional_param_names, |
| 149 additional_param_values, |
| 150 &codecs); |
| 216 | 151 |
| 217 SupportedCodecs supported_codecs = content::EME_CODEC_NONE; | 152 SupportedCodecs supported_codecs = content::EME_CODEC_NONE; |
| 218 for (size_t i = 0; i < codecs.size(); ++i) { | 153 for (size_t i = 0; i < codecs.size(); ++i) { |
| 219 if (codecs[i] == kCdmSupportedCodecVorbis) | 154 if (codecs[i] == kCdmSupportedCodecVorbis) |
| 220 supported_codecs |= content::EME_CODEC_WEBM_VORBIS; | 155 supported_codecs |= content::EME_CODEC_WEBM_VORBIS; |
| 221 if (codecs[i] == kCdmSupportedCodecVp8) | 156 if (codecs[i] == kCdmSupportedCodecVp8) |
| 222 supported_codecs |= content::EME_CODEC_WEBM_VP8; | 157 supported_codecs |= content::EME_CODEC_WEBM_VP8; |
| 223 if (codecs[i] == kCdmSupportedCodecVp9) | 158 if (codecs[i] == kCdmSupportedCodecVp9) |
| 224 supported_codecs |= content::EME_CODEC_WEBM_VP9; | 159 supported_codecs |= content::EME_CODEC_WEBM_VP9; |
| 225 #if defined(USE_PROPRIETARY_CODECS) | 160 #if defined(USE_PROPRIETARY_CODECS) |
| 226 if (codecs[i] == kCdmSupportedCodecAac) | 161 if (codecs[i] == kCdmSupportedCodecAac) |
| 227 supported_codecs |= content::EME_CODEC_MP4_AAC; | 162 supported_codecs |= content::EME_CODEC_MP4_AAC; |
| 228 if (codecs[i] == kCdmSupportedCodecAvc1) | 163 if (codecs[i] == kCdmSupportedCodecAvc1) |
| 229 supported_codecs |= content::EME_CODEC_MP4_AVC1; | 164 supported_codecs |= content::EME_CODEC_MP4_AVC1; |
| 230 #endif // defined(USE_PROPRIETARY_CODECS) | 165 #endif // defined(USE_PROPRIETARY_CODECS) |
| 231 } | 166 } |
| 232 | 167 |
| 233 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 168 cdm::AddWidevineWithCodecs(cdm::WIDEVINE, |
| 234 | 169 supported_codecs, |
| 235 if (IsWidevineHrSupported()) | 170 concrete_key_systems); |
| 236 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | |
| 237 } | 171 } |
| 238 #elif defined(OS_ANDROID) | 172 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 239 static void AddAndroidWidevine( | |
| 240 std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 241 SupportedKeySystemRequest request; | |
| 242 SupportedKeySystemResponse response; | |
| 243 | |
| 244 request.key_system = kWidevineKeySystem; | |
| 245 request.codecs = content::EME_CODEC_WEBM_ALL | content::EME_CODEC_MP4_ALL; | |
| 246 content::RenderThread::Get()->Send( | |
| 247 new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); | |
| 248 DCHECK(response.compositing_codecs & content::EME_CODEC_ALL) | |
| 249 << "unrecognized codec"; | |
| 250 DCHECK(response.non_compositing_codecs & content::EME_CODEC_ALL) | |
| 251 << "unrecognized codec"; | |
| 252 if (response.compositing_codecs != content::EME_CODEC_NONE) { | |
| 253 AddWidevineWithCodecs( | |
| 254 WIDEVINE, | |
| 255 static_cast<SupportedCodecs>(response.compositing_codecs), | |
| 256 concrete_key_systems); | |
| 257 } | |
| 258 | |
| 259 if (response.non_compositing_codecs != content::EME_CODEC_NONE) { | |
| 260 AddWidevineWithCodecs( | |
| 261 WIDEVINE_HR_NON_COMPOSITING, | |
| 262 static_cast<SupportedCodecs>(response.non_compositing_codecs), | |
| 263 concrete_key_systems); | |
| 264 } | |
| 265 } | |
| 266 #endif // defined(ENABLE_PEPPER_CDMS) | 173 #endif // defined(ENABLE_PEPPER_CDMS) |
| 267 #endif // defined(WIDEVINE_CDM_AVAILABLE) | |
| 268 | 174 |
| 269 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | 175 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
| 270 #if defined(ENABLE_PEPPER_CDMS) | 176 #if defined(ENABLE_PEPPER_CDMS) |
| 271 AddExternalClearKey(key_systems_info); | 177 AddExternalClearKey(key_systems_info); |
| 272 #endif | |
| 273 | 178 |
| 274 #if defined(WIDEVINE_CDM_AVAILABLE) | 179 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 275 #if defined(ENABLE_PEPPER_CDMS) | |
| 276 AddPepperBasedWidevine(key_systems_info); | 180 AddPepperBasedWidevine(key_systems_info); |
| 277 #elif defined(OS_ANDROID) | 181 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 278 AddAndroidWidevine(key_systems_info); | 182 #endif // defined(ENABLE_PEPPER_CDMS) |
| 279 #endif | 183 |
| 280 #endif | 184 #if defined(OS_ANDROID) |
| 185 cdm::AddAndroidWidevine(key_systems_info); |
| 186 #endif // defined(OS_ANDROID) |
| 281 } | 187 } |
| OLD | NEW |