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 | 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 WEBM_VP8_AND_VORBIS = 1 << 0, | 97 WEBM_VP8_AND_VORBIS = 1 << 0, |
| 94 #if defined(USE_PROPRIETARY_CODECS) | 98 #if defined(USE_PROPRIETARY_CODECS) |
| 95 MP4_AAC = 1 << 1, | 99 MP4_AAC = 1 << 1, |
| 96 MP4_AVC1 = 1 << 2, | 100 MP4_AVC1 = 1 << 2, |
| 97 #endif // defined(USE_PROPRIETARY_CODECS) | 101 #endif // defined(USE_PROPRIETARY_CODECS) |
| 98 }; | 102 }; |
| 99 | 103 |
| 100 enum WidevineCdmType { | 104 enum WidevineCdmType { |
| 101 WIDEVINE, | 105 WIDEVINE, |
| 102 WIDEVINE_HR, | 106 WIDEVINE_HR, |
| 107 WIDEVINE_HRSURFACE, | |
| 103 }; | 108 }; |
| 104 | 109 |
| 110 #if !defined(OS_ANDROID) | |
| 105 static bool IsWidevineHrSupported() { | 111 static bool IsWidevineHrSupported() { |
| 106 // TODO(jrummell): Need to call CheckPlatformState() but it is | 112 // TODO(jrummell): Need to call CheckPlatformState() but it is |
| 107 // asynchronous, and needs to be done in the browser. | 113 // asynchronous, and needs to be done in the browser. |
| 108 return false; | 114 return false; |
| 109 } | 115 } |
| 116 #endif | |
| 110 | 117 |
| 111 // Return |name|'s parent key system. | 118 // Return |name|'s parent key system. |
| 112 static std::string GetDirectParentName(std::string name) { | 119 static std::string GetDirectParentName(std::string name) { |
| 113 int last_period = name.find_last_of('.'); | 120 int last_period = name.find_last_of('.'); |
| 114 DCHECK_GT(last_period, 0); | 121 DCHECK_GT(last_period, 0); |
| 115 return name.substr(0, last_period); | 122 return name.substr(0, last_period); |
| 116 } | 123 } |
| 117 | 124 |
| 125 #if defined(OS_ANDROID) | |
|
ddorwin
2013/09/18 23:48:07
These should be up with the enum after the rebase.
qinmin
2013/09/19 00:02:55
Done.
| |
| 126 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | |
| 127 COMPILE_ASSERT(static_cast<int>(name) == \ | |
| 128 static_cast<int>(android::name), \ | |
| 129 mismatching_enums) | |
| 130 COMPILE_ASSERT_MATCHING_ENUM(WEBM_VP8_AND_VORBIS); | |
| 131 COMPILE_ASSERT_MATCHING_ENUM(MP4_AAC); | |
| 132 COMPILE_ASSERT_MATCHING_ENUM(MP4_AVC1); | |
| 133 #undef COMPILE_ASSERT_MATCHING_ENUM | |
| 134 | |
| 135 static const uint8 kWidevineUuid[16] = { | |
| 136 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | |
| 137 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | |
| 138 #endif | |
| 139 | |
| 118 static void AddWidevineWithCodecs( | 140 static void AddWidevineWithCodecs( |
| 119 WidevineCdmType widevine_cdm_type, | 141 WidevineCdmType widevine_cdm_type, |
| 120 SupportedCodecs supported_codecs, | 142 SupportedCodecs supported_codecs, |
| 121 std::vector<KeySystemInfo>* concrete_key_systems) { | 143 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 122 | 144 |
| 123 KeySystemInfo info(kWidevineKeySystem); | 145 KeySystemInfo info(kWidevineKeySystem); |
| 124 | 146 |
| 125 switch (widevine_cdm_type) { | 147 switch (widevine_cdm_type) { |
| 126 case WIDEVINE: | 148 case WIDEVINE: |
| 127 // For standard Widevine, add parent name. | 149 // For standard Widevine, add parent name. |
| 128 info.parent_key_system = GetDirectParentName(kWidevineKeySystem); | 150 info.parent_key_system = GetDirectParentName(kWidevineKeySystem); |
| 129 break; | 151 break; |
| 130 case WIDEVINE_HR: | 152 case WIDEVINE_HR: |
| 131 info.key_system.append(".hr"); | 153 info.key_system.append(".hr"); |
| 132 break; | 154 break; |
| 155 case WIDEVINE_HRSURFACE: | |
| 156 info.key_system.append(".hrsurface"); | |
| 157 break; | |
| 133 default: | 158 default: |
| 134 NOTREACHED(); | 159 NOTREACHED(); |
| 135 } | 160 } |
| 136 | 161 |
| 137 if (supported_codecs & WEBM_VP8_AND_VORBIS) { | 162 if (supported_codecs & WEBM_VP8_AND_VORBIS) { |
| 138 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | 163 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); |
| 139 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | 164 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); |
| 140 } | 165 } |
| 141 | 166 |
| 142 #if defined(USE_PROPRIETARY_CODECS) | 167 #if defined(USE_PROPRIETARY_CODECS) |
| 143 if (supported_codecs & MP4_AAC) | 168 if (supported_codecs & MP4_AAC) |
| 144 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); | 169 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); |
| 145 | 170 |
| 146 if (supported_codecs & MP4_AVC1) { | 171 if (supported_codecs & MP4_AVC1) { |
| 147 const char* video_codecs = (supported_codecs & MP4_AAC) ? kMp4aAvc1 : kAvc1; | 172 const char* video_codecs = (supported_codecs & MP4_AAC) ? kMp4aAvc1 : kAvc1; |
| 148 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs)); | 173 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs)); |
| 149 } | 174 } |
| 150 #endif // defined(USE_PROPRIETARY_CODECS) | 175 #endif // defined(USE_PROPRIETARY_CODECS) |
| 151 | 176 |
| 152 #if defined(ENABLE_PEPPER_CDMS) | 177 #if defined(ENABLE_PEPPER_CDMS) |
| 153 info.pepper_type = kWidevineCdmPluginMimeType; | 178 info.pepper_type = kWidevineCdmPluginMimeType; |
| 154 #elif defined(OS_ANDROID) | 179 #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)); | 180 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid)); |
| 159 #endif // defined(ENABLE_PEPPER_CDMS) | 181 #endif // defined(ENABLE_PEPPER_CDMS) |
| 160 | 182 |
| 161 concrete_key_systems->push_back(info); | 183 concrete_key_systems->push_back(info); |
| 162 } | 184 } |
| 163 | 185 |
| 164 #if defined(ENABLE_PEPPER_CDMS) | 186 #if defined(ENABLE_PEPPER_CDMS) |
| 165 // Supported types are determined at compile time. | 187 // Supported types are determined at compile time. |
| 166 static void AddPepperBasedWidevine( | 188 static void AddPepperBasedWidevine( |
| 167 std::vector<KeySystemInfo>* concrete_key_systems) { | 189 std::vector<KeySystemInfo>* concrete_key_systems) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 189 #endif // defined(USE_PROPRIETARY_CODECS) | 211 #endif // defined(USE_PROPRIETARY_CODECS) |
| 190 | 212 |
| 191 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 213 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); |
| 192 | 214 |
| 193 if (IsWidevineHrSupported()) | 215 if (IsWidevineHrSupported()) |
| 194 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | 216 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); |
| 195 } | 217 } |
| 196 #elif defined(OS_ANDROID) | 218 #elif defined(OS_ANDROID) |
| 197 static void AddAndroidWidevine( | 219 static void AddAndroidWidevine( |
| 198 std::vector<KeySystemInfo>* concrete_key_systems) { | 220 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 221 android::SupportedKeySystemRequest request; | |
| 222 android::SupportedKeySystemResponse response; | |
| 223 | |
| 224 request.uuid.insert(request.uuid.begin(), kWidevineUuid, | |
| 225 kWidevineUuid + arraysize(kWidevineUuid)); | |
| 199 #if defined(USE_PROPRIETARY_CODECS) | 226 #if defined(USE_PROPRIETARY_CODECS) |
| 200 SupportedCodecs supported_codecs = | 227 request.codecs = static_cast<android::SupportedCodecs>( |
| 201 static_cast<SupportedCodecs>(MP4_AAC | MP4_AVC1); | 228 android::MP4_AAC | android::MP4_AVC1); |
| 202 AddWidevineWithCodecs(WIDEVINE, supported_codecs, concrete_key_systems); | 229 #endif // defined(USE_PROPRIETARY_CODECS) |
| 230 content::RenderThread::Get()->Send( | |
| 231 new ChromeViewHostMsg_GetSupportedKeySystems(request, &response)); | |
| 232 DCHECK_EQ(response.compositing_codecs >> 3, 0) << "unrecognized codec"; | |
| 233 DCHECK_EQ(response.non_compositing_codecs >> 3, 0) << "unrecognized codec"; | |
| 234 AddWidevineWithCodecs( | |
|
ddorwin
2013/09/18 23:48:07
might not matter in practice, but we should only a
qinmin
2013/09/19 00:02:55
Added a if statement here to check if the returned
| |
| 235 WIDEVINE, | |
| 236 static_cast<SupportedCodecs>(response.compositing_codecs), | |
| 237 concrete_key_systems); | |
| 203 | 238 |
| 204 if (IsWidevineHrSupported()) | 239 AddWidevineWithCodecs( |
| 205 AddWidevineWithCodecs(WIDEVINE_HR, supported_codecs, concrete_key_systems); | 240 WIDEVINE_HRSURFACE, |
| 206 #endif // defined(USE_PROPRIETARY_CODECS) | 241 static_cast<SupportedCodecs>(response.non_compositing_codecs), |
| 242 concrete_key_systems); | |
| 207 } | 243 } |
| 208 #endif // defined(ENABLE_PEPPER_CDMS) | 244 #endif // defined(ENABLE_PEPPER_CDMS) |
| 209 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 245 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 210 | 246 |
| 211 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | 247 void AddChromeKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
| 212 AddClearKey(key_systems_info); | 248 AddClearKey(key_systems_info); |
| 213 | 249 |
| 214 #if defined(ENABLE_PEPPER_CDMS) | 250 #if defined(ENABLE_PEPPER_CDMS) |
| 215 AddExternalClearKey(key_systems_info); | 251 AddExternalClearKey(key_systems_info); |
| 216 #endif | 252 #endif |
| 217 | 253 |
| 218 #if defined(WIDEVINE_CDM_AVAILABLE) | 254 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 219 #if defined(ENABLE_PEPPER_CDMS) | 255 #if defined(ENABLE_PEPPER_CDMS) |
| 220 AddPepperBasedWidevine(key_systems_info); | 256 AddPepperBasedWidevine(key_systems_info); |
| 221 #elif defined(OS_ANDROID) | 257 #elif defined(OS_ANDROID) |
| 222 AddAndroidWidevine(key_systems_info); | 258 AddAndroidWidevine(key_systems_info); |
| 223 #endif | 259 #endif |
| 224 #endif | 260 #endif |
| 225 } | 261 } |
| OLD | NEW |