| 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 "content/renderer/media/crypto/key_systems_info.h" | 5 #include "content/renderer/media/crypto/key_systems_info.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 8 #include "third_party/WebKit/public/platform/WebString.h" | 7 #include "third_party/WebKit/public/platform/WebString.h" |
| 9 | 8 |
| 10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 9 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 11 | 10 |
| 12 // The following must be after widevine_cdm_version.h. | 11 // The following must be after widevine_cdm_version.h. |
| 13 | 12 |
| 14 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | |
| 15 #include <gnu/libc-version.h> | |
| 16 #include "base/version.h" | |
| 17 #endif | |
| 18 | |
| 19 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) | 13 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) |
| 20 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 21 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
| 22 #endif | 16 #endif |
| 23 | 17 |
| 24 namespace content { | 18 namespace content { |
| 25 | 19 |
| 26 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 20 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
| 27 | 21 |
| 28 static const char kAudioWebM[] = "audio/webm"; | |
| 29 static const char kVideoWebM[] = "video/webm"; | |
| 30 static const char kVorbis[] = "vorbis"; | |
| 31 static const char kVorbisVP8[] = "vorbis,vp8,vp8.0"; | |
| 32 | |
| 33 static const char kAudioMp4[] = "audio/mp4"; | |
| 34 static const char kVideoMp4[] = "video/mp4"; | |
| 35 static const char kMp4a[] = "mp4a"; | |
| 36 static const char kAvc1[] = "avc1"; | |
| 37 static const char kMp4aAvc1[] = "mp4a,avc1"; | |
| 38 | |
| 39 #if defined(WIDEVINE_CDM_AVAILABLE) | |
| 40 enum SupportedCodecs { | |
| 41 WEBM_VP8_AND_VORBIS = 1 << 0, | |
| 42 #if defined(USE_PROPRIETARY_CODECS) | |
| 43 MP4_AAC = 1 << 1, | |
| 44 MP4_AVC1 = 1 << 2, | |
| 45 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 46 }; | |
| 47 | |
| 48 static void AddWidevineForTypes( | |
| 49 SupportedCodecs supported_codecs, | |
| 50 std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 51 static const char kWidevineParentKeySystem[] = "com.widevine"; | |
| 52 #if defined(OS_ANDROID) | |
| 53 static const uint8 kWidevineUuid[16] = { | |
| 54 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | |
| 55 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | |
| 56 #endif | |
| 57 | |
| 58 #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | |
| 59 Version glibc_version(gnu_get_libc_version()); | |
| 60 DCHECK(glibc_version.IsValid()); | |
| 61 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) | |
| 62 return; | |
| 63 #endif // defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | |
| 64 | |
| 65 KeySystemInfo info(kWidevineKeySystem); | |
| 66 | |
| 67 if (supported_codecs & WEBM_VP8_AND_VORBIS) { | |
| 68 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | |
| 69 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | |
| 70 } | |
| 71 | |
| 72 #if defined(USE_PROPRIETARY_CODECS) | |
| 73 if (supported_codecs & MP4_AAC) | |
| 74 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); | |
| 75 | |
| 76 if (supported_codecs & MP4_AVC1) { | |
| 77 const char* video_codecs = (supported_codecs & MP4_AAC) ? kMp4aAvc1 : kAvc1; | |
| 78 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs)); | |
| 79 } | |
| 80 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 81 | |
| 82 info.parent_key_system = kWidevineParentKeySystem; | |
| 83 | |
| 84 #if defined(ENABLE_PEPPER_CDMS) | |
| 85 info.pepper_type = kWidevineCdmPluginMimeType; | |
| 86 #elif defined(OS_ANDROID) | |
| 87 info.uuid.assign(kWidevineUuid, kWidevineUuid + arraysize(kWidevineUuid)); | |
| 88 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 89 | |
| 90 concrete_key_systems->push_back(info); | |
| 91 } | |
| 92 | |
| 93 #if defined(ENABLE_PEPPER_CDMS) | |
| 94 // Supported types are determined at compile time. | |
| 95 static void AddPepperBasedWidevine( | |
| 96 std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 97 SupportedCodecs supported_codecs = WEBM_VP8_AND_VORBIS; | |
| 98 | |
| 99 #if defined(USE_PROPRIETARY_CODECS) | |
| 100 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) | |
| 101 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AAC); | |
| 102 #endif | |
| 103 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) | |
| 104 supported_codecs = static_cast<SupportedCodecs>(supported_codecs | MP4_AVC1); | |
| 105 #endif | |
| 106 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 107 | |
| 108 AddWidevineForTypes(supported_codecs, concrete_key_systems); | |
| 109 } | |
| 110 #elif defined(OS_ANDROID) | |
| 111 static void AddAndroidWidevine( | |
| 112 std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 113 SupportedCodecs supported_codecs = MP4_AAC | MP4_AVC1; | |
| 114 AddWidevineForTypes(supported_codecs, concrete_key_systems); | |
| 115 } | |
| 116 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 117 #endif // defined(WIDEVINE_CDM_AVAILABLE) | |
| 118 | |
| 119 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 120 KeySystemInfo info(kClearKeyKeySystem); | |
| 121 | |
| 122 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | |
| 123 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | |
| 124 #if defined(USE_PROPRIETARY_CODECS) | |
| 125 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); | |
| 126 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); | |
| 127 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 128 | |
| 129 info.use_aes_decryptor = true; | |
| 130 | |
| 131 concrete_key_systems->push_back(info); | |
| 132 } | |
| 133 | |
| 134 #if defined(ENABLE_PEPPER_CDMS) | |
| 135 // External Clear Key (used for testing). | |
| 136 static void AddExternalClearKey( | |
| 137 std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 138 static const char kExternalClearKeyKeySystem[] = | |
| 139 "org.chromium.externalclearkey"; | |
| 140 static const char kExternalClearKeyPepperType[] = | |
| 141 "application/x-ppapi-clearkey-cdm"; | |
| 142 | |
| 143 KeySystemInfo info(kExternalClearKeyKeySystem); | |
| 144 | |
| 145 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | |
| 146 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | |
| 147 #if defined(USE_PROPRIETARY_CODECS) | |
| 148 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); | |
| 149 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); | |
| 150 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 151 | |
| 152 info.pepper_type = kExternalClearKeyPepperType; | |
| 153 | |
| 154 concrete_key_systems->push_back(info); | |
| 155 } | |
| 156 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 157 | |
| 158 void AddKeySystems(std::vector<KeySystemInfo>* key_systems_info) { | |
| 159 AddClearKey(key_systems_info); | |
| 160 | |
| 161 #if defined(ENABLE_PEPPER_CDMS) | |
| 162 AddExternalClearKey(key_systems_info); | |
| 163 #endif | |
| 164 | |
| 165 #if defined(WIDEVINE_CDM_AVAILABLE) | |
| 166 #if defined(ENABLE_PEPPER_CDMS) | |
| 167 AddPepperBasedWidevine(key_systems_info); | |
| 168 #elif defined(OS_ANDROID) | |
| 169 AddAndroidWidevine(key_systems_info); | |
| 170 #endif | |
| 171 #endif | |
| 172 } | |
| 173 | |
| 174 bool IsCanPlayTypeSuppressed(const std::string& key_system) { | 22 bool IsCanPlayTypeSuppressed(const std::string& key_system) { |
| 175 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) | 23 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) |
| 176 // See http://crbug.com/237627. | 24 // See http://crbug.com/237627. |
| 177 if (key_system == kWidevineKeySystem && | 25 if (key_system == kWidevineKeySystem && |
| 178 !CommandLine::ForCurrentProcess()->HasSwitch( | 26 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 179 switches::kOverrideEncryptedMediaCanPlayType)) | 27 switches::kOverrideEncryptedMediaCanPlayType)) |
| 180 return true; | 28 return true; |
| 181 #endif | 29 #endif |
| 182 return false; | 30 return false; |
| 183 } | 31 } |
| 184 | 32 |
| 185 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { | 33 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { |
| 186 if (key_system == kClearKeyKeySystem) | 34 if (key_system == kClearKeyKeySystem) |
| 187 return "ClearKey"; | 35 return "ClearKey"; |
| 188 #if defined(WIDEVINE_CDM_AVAILABLE) | 36 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 189 if (key_system == kWidevineKeySystem) | 37 if (key_system == kWidevineKeySystem) |
| 190 return "Widevine"; | 38 return "Widevine"; |
| 191 #endif // WIDEVINE_CDM_AVAILABLE | 39 #endif // WIDEVINE_CDM_AVAILABLE |
| 192 return "Unknown"; | 40 return "Unknown"; |
| 193 } | 41 } |
| 194 | 42 |
| 195 } // namespace content | 43 } // namespace content |
| OLD | NEW |