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" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 21 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
| 22 #include <gnu/libc-version.h> | 22 #include <gnu/libc-version.h> |
| 23 #include "base/version.h" | 23 #include "base/version.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
| 27 #include "chrome/common/encrypted_media_messages_android.h" | 27 #include "chrome/common/encrypted_media_messages_android.h" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 using content::KeySystemInfo; | 30 using content::KeySystemInfo; |
| 31 | 31 using media::SupportedCodecs; |
| 32 const char kAudioWebM[] = "audio/webm"; | |
| 33 const char kVideoWebM[] = "video/webm"; | |
| 34 const char kVorbis[] = "vorbis"; | |
| 35 const char kVP8[] = "vp8"; | |
| 36 const char kVP80[] = "vp8.0"; | |
| 37 | |
| 38 #if defined(USE_PROPRIETARY_CODECS) | |
| 39 const char kAudioMp4[] = "audio/mp4"; | |
| 40 const char kVideoMp4[] = "video/mp4"; | |
| 41 const char kMp4a[] = "mp4a"; | |
| 42 const char kAvc1[] = "avc1"; | |
| 43 const char kAvc3[] = "avc3"; | |
| 44 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 45 | 32 |
| 46 #if defined(ENABLE_PEPPER_CDMS) | 33 #if defined(ENABLE_PEPPER_CDMS) |
| 47 static bool IsPepperCdmRegistered( | 34 static bool IsPepperCdmRegistered( |
| 48 const std::string& pepper_type, | 35 const std::string& pepper_type, |
| 49 std::vector<base::string16>* additional_param_names, | 36 std::vector<base::string16>* additional_param_names, |
| 50 std::vector<base::string16>* additional_param_values) { | 37 std::vector<base::string16>* additional_param_values) { |
| 51 bool is_registered = false; | 38 bool is_registered = false; |
| 52 content::RenderThread::Get()->Send( | 39 content::RenderThread::Get()->Send( |
| 53 new ChromeViewHostMsg_IsInternalPluginRegisteredForMimeType( | 40 new ChromeViewHostMsg_IsInternalPluginRegisteredForMimeType( |
| 54 pepper_type, | 41 pepper_type, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 78 std::vector<base::string16> additional_param_names; | 65 std::vector<base::string16> additional_param_names; |
| 79 std::vector<base::string16> additional_param_values; | 66 std::vector<base::string16> additional_param_values; |
| 80 if (!IsPepperCdmRegistered(kExternalClearKeyPepperType, | 67 if (!IsPepperCdmRegistered(kExternalClearKeyPepperType, |
| 81 &additional_param_names, | 68 &additional_param_names, |
| 82 &additional_param_values)) { | 69 &additional_param_values)) { |
| 83 return; | 70 return; |
| 84 } | 71 } |
| 85 | 72 |
| 86 KeySystemInfo info(kExternalClearKeyKeySystem); | 73 KeySystemInfo info(kExternalClearKeyKeySystem); |
| 87 | 74 |
| 88 info.supported_types[kAudioWebM].insert(kVorbis); | 75 info.supported_codecs = media::WEBM_CODECS; |
| 89 info.supported_types[kVideoWebM] = info.supported_types[kAudioWebM]; | |
| 90 info.supported_types[kVideoWebM].insert(kVP8); | |
| 91 info.supported_types[kVideoWebM].insert(kVP80); | |
| 92 #if defined(USE_PROPRIETARY_CODECS) | 76 #if defined(USE_PROPRIETARY_CODECS) |
| 93 info.supported_types[kAudioMp4].insert(kMp4a); | 77 info.supported_codecs |= media::MP4_CODECS; |
| 94 info.supported_types[kVideoMp4] = info.supported_types[kAudioMp4]; | |
| 95 info.supported_types[kVideoMp4].insert(kAvc1); | |
| 96 info.supported_types[kVideoMp4].insert(kAvc3); | |
| 97 #endif // defined(USE_PROPRIETARY_CODECS) | 78 #endif // defined(USE_PROPRIETARY_CODECS) |
| 98 | 79 |
| 99 info.pepper_type = kExternalClearKeyPepperType; | 80 info.pepper_type = kExternalClearKeyPepperType; |
| 100 | 81 |
| 101 concrete_key_systems->push_back(info); | 82 concrete_key_systems->push_back(info); |
| 102 | 83 |
| 103 // Add support of decrypt-only mode in ClearKeyCdm. | 84 // Add support of decrypt-only mode in ClearKeyCdm. |
| 104 info.key_system = kExternalClearKeyDecryptOnlyKeySystem; | 85 info.key_system = kExternalClearKeyDecryptOnlyKeySystem; |
| 105 concrete_key_systems->push_back(info); | 86 concrete_key_systems->push_back(info); |
| 106 | 87 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 123 | 104 |
| 124 #if defined(WIDEVINE_CDM_AVAILABLE) | 105 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 125 enum WidevineCdmType { | 106 enum WidevineCdmType { |
| 126 WIDEVINE, | 107 WIDEVINE, |
| 127 WIDEVINE_HR, | 108 WIDEVINE_HR, |
| 128 #if defined(OS_ANDROID) | 109 #if defined(OS_ANDROID) |
| 129 WIDEVINE_HR_NON_COMPOSITING, | 110 WIDEVINE_HR_NON_COMPOSITING, |
| 130 #endif | 111 #endif |
| 131 }; | 112 }; |
| 132 | 113 |
| 133 // Defines bitmask values used to specify supported codecs. | |
| 134 // Each value represents a codec within a specific container. | |
| 135 // The mask values are stored in a SupportedCodecs. | |
| 136 typedef uint32 SupportedCodecs; | |
| 137 enum SupportedCodecMasks { | |
| 138 NO_CODECS = 0, | |
| 139 WEBM_VORBIS = 1 << 0, | |
| 140 WEBM_VP8 = 1 << 1, | |
| 141 WEBM_CODECS = (WEBM_VORBIS | WEBM_VP8), | |
| 142 #if defined(USE_PROPRIETARY_CODECS) | |
| 143 MP4_AAC = 1 << 2, | |
| 144 MP4_AVC1 = 1 << 3, | |
| 145 MP4_CODECS = (MP4_AAC | MP4_AVC1), | |
| 146 ALL_CODECS = (WEBM_CODECS | MP4_CODECS), | |
| 147 #else | |
| 148 ALL_CODECS = WEBM_CODECS, | |
| 149 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 150 INVALID_CODECS = ~ALL_CODECS | |
| 151 }; | |
| 152 | 114 |
| 153 #if defined(OS_ANDROID) | 115 #if !defined(OS_ANDROID) |
| 154 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | |
| 155 COMPILE_ASSERT(static_cast<int>(name) == \ | |
| 156 static_cast<int>(android::name), \ | |
| 157 mismatching_enums) | |
| 158 COMPILE_ASSERT_MATCHING_ENUM(NO_CODECS); | |
| 159 COMPILE_ASSERT_MATCHING_ENUM(WEBM_VORBIS); | |
| 160 COMPILE_ASSERT_MATCHING_ENUM(WEBM_VP8); | |
| 161 COMPILE_ASSERT_MATCHING_ENUM(WEBM_CODECS); | |
| 162 COMPILE_ASSERT_MATCHING_ENUM(MP4_AAC); | |
| 163 COMPILE_ASSERT_MATCHING_ENUM(MP4_AVC1); | |
| 164 COMPILE_ASSERT_MATCHING_ENUM(MP4_CODECS); | |
| 165 COMPILE_ASSERT_MATCHING_ENUM(ALL_CODECS); | |
| 166 COMPILE_ASSERT_MATCHING_ENUM(INVALID_CODECS); | |
| 167 #undef COMPILE_ASSERT_MATCHING_ENUM | |
| 168 #else | |
| 169 static bool IsWidevineHrSupported() { | 116 static bool IsWidevineHrSupported() { |
| 170 // TODO(jrummell): Need to call CheckPlatformState() but it is | 117 // TODO(jrummell): Need to call CheckPlatformState() but it is |
| 171 // asynchronous, and needs to be done in the browser. | 118 // asynchronous, and needs to be done in the browser. |
| 172 return false; | 119 return false; |
| 173 } | 120 } |
| 174 #endif | 121 #endif |
| 175 | 122 |
| 176 // Return |name|'s parent key system. | 123 // Return |name|'s parent key system. |
| 177 static std::string GetDirectParentName(std::string name) { | 124 static std::string GetDirectParentName(std::string name) { |
| 178 int last_period = name.find_last_of('.'); | 125 int last_period = name.find_last_of('.'); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 196 break; | 143 break; |
| 197 #if defined(OS_ANDROID) | 144 #if defined(OS_ANDROID) |
| 198 case WIDEVINE_HR_NON_COMPOSITING: | 145 case WIDEVINE_HR_NON_COMPOSITING: |
| 199 info.key_system.append(".hrnoncompositing"); | 146 info.key_system.append(".hrnoncompositing"); |
| 200 break; | 147 break; |
| 201 #endif | 148 #endif |
| 202 default: | 149 default: |
| 203 NOTREACHED(); | 150 NOTREACHED(); |
| 204 } | 151 } |
| 205 | 152 |
| 206 // TODO(xhwang): A container or an initDataType may be supported even though | 153 info.supported_codecs = supported_codecs; |
|
ddorwin
2014/04/22 21:24:41
The comment in the base revision is still valid an
xhwang
2014/04/23 17:29:14
Done.
| |
| 207 // there are no codecs supported in that container. Fix this when we support | |
| 208 // initDataType. | |
| 209 if (supported_codecs & WEBM_CODECS) { | |
| 210 if (supported_codecs & WEBM_VORBIS) | |
| 211 info.supported_types[kAudioWebM].insert(kVorbis); | |
| 212 | |
| 213 if (supported_codecs & WEBM_VP8) { | |
| 214 info.supported_types[kVideoWebM] = info.supported_types[kAudioWebM]; | |
| 215 info.supported_types[kVideoWebM].insert(kVP8); | |
| 216 info.supported_types[kVideoWebM].insert(kVP80); | |
| 217 } | |
| 218 } | |
| 219 | |
| 220 #if defined(USE_PROPRIETARY_CODECS) | |
| 221 if (supported_codecs & MP4_CODECS) { | |
| 222 if (supported_codecs & MP4_AAC) | |
| 223 info.supported_types[kAudioMp4].insert(kMp4a); | |
| 224 | |
| 225 if (supported_codecs & MP4_AVC1) { | |
| 226 info.supported_types[kVideoMp4] = info.supported_types[kAudioMp4]; | |
| 227 info.supported_types[kVideoMp4].insert(kAvc1); | |
| 228 info.supported_types[kVideoMp4].insert(kAvc3); | |
| 229 } | |
| 230 } | |
| 231 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 232 | 154 |
| 233 #if defined(ENABLE_PEPPER_CDMS) | 155 #if defined(ENABLE_PEPPER_CDMS) |
| 234 info.pepper_type = kWidevineCdmPluginMimeType; | 156 info.pepper_type = kWidevineCdmPluginMimeType; |
| 235 #endif // defined(ENABLE_PEPPER_CDMS) | 157 #endif // defined(ENABLE_PEPPER_CDMS) |
| 236 | 158 |
| 237 concrete_key_systems->push_back(info); | 159 concrete_key_systems->push_back(info); |
| 238 } | 160 } |
| 239 | 161 |
| 240 #if defined(ENABLE_PEPPER_CDMS) | 162 #if defined(ENABLE_PEPPER_CDMS) |
| 241 // When the adapter is registered, a name-value pair is inserted in | 163 // When the adapter is registered, a name-value pair is inserted in |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, | 205 if (!IsPepperCdmRegistered(kWidevineCdmPluginMimeType, |
| 284 &additional_param_names, | 206 &additional_param_names, |
| 285 &additional_param_values)) { | 207 &additional_param_values)) { |
| 286 DVLOG(1) << "Widevine CDM is not currently available."; | 208 DVLOG(1) << "Widevine CDM is not currently available."; |
| 287 return; | 209 return; |
| 288 } | 210 } |
| 289 | 211 |
| 290 std::vector<std::string> codecs; | 212 std::vector<std::string> codecs; |
| 291 GetSupportedCodecs(additional_param_names, additional_param_values, &codecs); | 213 GetSupportedCodecs(additional_param_names, additional_param_values, &codecs); |
| 292 | 214 |
| 293 SupportedCodecs supported_codecs = NO_CODECS; | 215 SupportedCodecs supported_codecs = media::NO_CODECS; |
| 294 for (size_t i = 0; i < codecs.size(); ++i) { | 216 for (size_t i = 0; i < codecs.size(); ++i) { |
| 295 if (codecs[i] == kCdmSupportedCodecVorbis) | 217 if (codecs[i] == kCdmSupportedCodecVorbis) |
| 296 supported_codecs |= WEBM_VORBIS; | 218 supported_codecs |= media::WEBM_VORBIS; |
| 297 if (codecs[i] == kCdmSupportedCodecVp8) | 219 if (codecs[i] == kCdmSupportedCodecVp8) |
| 298 supported_codecs |= WEBM_VP8; | 220 supported_codecs |= media::WEBM_VP8; |
| 299 #if defined(USE_PROPRIETARY_CODECS) | 221 #if defined(USE_PROPRIETARY_CODECS) |
| 300 if (codecs[i] == kCdmSupportedCodecAac) | 222 if (codecs[i] == kCdmSupportedCodecAac) |
| 301 supported_codecs |= MP4_AAC; | 223 supported_codecs |= media::MP4_AAC; |
| 302 if (codecs[i] == kCdmSupportedCodecAvc1) | 224 if (codecs[i] == kCdmSupportedCodecAvc1) |
| 303 supported_codecs |= MP4_AVC1; | 225 supported_codecs |= media::MP4_AVC1; |
| 304 #endif // defined(USE_PROPRIETARY_CODECS) | 226 #endif // defined(USE_PROPRIETARY_CODECS) |
| 305 } | 227 } |
| 306 | 228 |
| 307 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 229 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); |
| 308 | 230 |
| 309 if (IsWidevineHrSupported()) | 231 if (IsWidevineHrSupported()) |
| 310 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | 232 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); |
| 311 } | 233 } |
| 312 #elif defined(OS_ANDROID) | 234 #elif defined(OS_ANDROID) |
| 313 static void AddAndroidWidevine( | 235 static void AddAndroidWidevine( |
| 314 std::vector<KeySystemInfo>* concrete_key_systems) { | 236 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 315 SupportedKeySystemRequest request; | 237 SupportedKeySystemRequest request; |
| 316 SupportedKeySystemResponse response; | 238 SupportedKeySystemResponse response; |
| 317 | 239 |
| 318 request.key_system = kWidevineKeySystem; | 240 request.key_system = kWidevineKeySystem; |
| 319 request.codecs = static_cast<android::SupportedCodecs>(android::WEBM_CODECS | | 241 request.codecs = media::WEBM_CODECS | media::MP4_CODECS; |
| 320 android::MP4_CODECS); | |
| 321 content::RenderThread::Get()->Send( | 242 content::RenderThread::Get()->Send( |
| 322 new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); | 243 new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); |
| 323 DCHECK_EQ(response.compositing_codecs & android::INVALID_CODECS, | 244 DCHECK(!(response.compositing_codecs & media::INVALID_CODECS)) |
|
ddorwin
2014/04/22 21:24:41
ditto here and below.
xhwang
2014/04/23 17:29:14
Done.
| |
| 324 android::NO_CODECS) | |
| 325 << "unrecognized codec"; | 245 << "unrecognized codec"; |
| 326 DCHECK_EQ(response.non_compositing_codecs & android::INVALID_CODECS, | 246 DCHECK(!(response.non_compositing_codecs & media::INVALID_CODECS)) |
| 327 android::NO_CODECS) | |
| 328 << "unrecognized codec"; | 247 << "unrecognized codec"; |
| 329 if (response.compositing_codecs != android::NO_CODECS) { | 248 if (response.compositing_codecs != media::NO_CODECS) { |
| 330 AddWidevineWithCodecs( | 249 AddWidevineWithCodecs( |
| 331 WIDEVINE, | 250 WIDEVINE, |
| 332 static_cast<SupportedCodecs>(response.compositing_codecs), | 251 static_cast<SupportedCodecs>(response.compositing_codecs), |
| 333 concrete_key_systems); | 252 concrete_key_systems); |
| 334 } | 253 } |
| 335 | 254 |
| 336 if (response.non_compositing_codecs != android::NO_CODECS) { | 255 if (response.non_compositing_codecs != media::NO_CODECS) { |
| 337 AddWidevineWithCodecs( | 256 AddWidevineWithCodecs( |
| 338 WIDEVINE_HR_NON_COMPOSITING, | 257 WIDEVINE_HR_NON_COMPOSITING, |
| 339 static_cast<SupportedCodecs>(response.non_compositing_codecs), | 258 static_cast<SupportedCodecs>(response.non_compositing_codecs), |
| 340 concrete_key_systems); | 259 concrete_key_systems); |
| 341 } | 260 } |
| 342 } | 261 } |
| 343 #endif // defined(ENABLE_PEPPER_CDMS) | 262 #endif // defined(ENABLE_PEPPER_CDMS) |
| 344 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 263 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 345 | 264 |
| 346 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | 265 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
| 347 #if defined(ENABLE_PEPPER_CDMS) | 266 #if defined(ENABLE_PEPPER_CDMS) |
| 348 AddExternalClearKey(key_systems_info); | 267 AddExternalClearKey(key_systems_info); |
| 349 #endif | 268 #endif |
| 350 | 269 |
| 351 #if defined(WIDEVINE_CDM_AVAILABLE) | 270 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 352 #if defined(ENABLE_PEPPER_CDMS) | 271 #if defined(ENABLE_PEPPER_CDMS) |
| 353 AddPepperBasedWidevine(key_systems_info); | 272 AddPepperBasedWidevine(key_systems_info); |
| 354 #elif defined(OS_ANDROID) | 273 #elif defined(OS_ANDROID) |
| 355 AddAndroidWidevine(key_systems_info); | 274 AddAndroidWidevine(key_systems_info); |
| 356 #endif | 275 #endif |
| 357 #endif | 276 #endif |
| 358 } | 277 } |
| OLD | NEW |