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 "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" | 7 #include "base/logging.h" |
| 8 #include "content/renderer/media/crypto/key_systems.h" | |
| 9 #include "third_party/WebKit/public/platform/WebString.h" | 8 #include "third_party/WebKit/public/platform/WebString.h" |
| 10 | 9 |
| 11 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 12 | 11 |
| 13 // The following must be after widevine_cdm_version.h. | 12 // The following must be after widevine_cdm_version.h. |
| 14 | 13 |
| 15 #if defined(WIDEVINE_CDM_AVAILABLE) && \ | 14 #if defined(WIDEVINE_CDM_AVAILABLE) && \ |
| 16 defined(OS_LINUX) && !defined(OS_CHROMEOS) | 15 defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 17 #include <gnu/libc-version.h> | 16 #include <gnu/libc-version.h> |
| 18 #include "base/logging.h" | 17 #include "base/logging.h" |
| 19 #include "base/version.h" | 18 #include "base/version.h" |
| 20 #endif | 19 #endif |
| 21 | 20 |
| 22 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) | 21 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) |
| 23 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| 24 #include "media/base/media_switches.h" | 23 #include "media/base/media_switches.h" |
| 25 #endif | 24 #endif |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 | 27 |
| 29 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; | 28 static const char kClearKeyKeySystem[] = "webkit-org.w3.clearkey"; |
| 30 | 29 |
| 31 #if defined(ENABLE_PEPPER_CDMS) | 30 static const char kAudioWebM[] = "audio/webm"; |
| 32 static const char kExternalClearKeyKeySystem[] = | 31 static const char kVideoWebM[] = "video/webm"; |
| 33 "org.chromium.externalclearkey"; | 32 static const char kVorbis[] = "vorbis"; |
| 34 #elif defined(OS_ANDROID) | 33 static const char kVorbisVP8[] = "vorbis,vp8,vp8.0"; |
| 35 static const uint8 kEmptyUuid[16] = | 34 |
| 36 { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | 35 static const char kAudioMp4[] = "audio/mp4"; |
| 37 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; | 36 static const char kVideoMp4[] = "video/mp4"; |
| 38 #endif | 37 static const char kMp4a[] = "mp4a"; |
| 38 static const char kAvc1[] = "avc1"; | |
| 39 static const char kMp4aAvc1[] = "mp4a,avc1"; | |
| 39 | 40 |
| 40 #if defined(WIDEVINE_CDM_AVAILABLE) | 41 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 42 static void AddWidevineForTypes(bool is_webm_vp8_and_vorbis_supported, | |
| 43 bool is_mp4_supported, | |
|
scherkus (not reviewing)
2013/09/03 22:22:08
fix indenting here
ddorwin
2013/09/04 00:41:55
Done. (4 spaces since aligned makes 46 too long)
| |
| 44 bool is_aac_supported, | |
| 45 bool is_avc1_supported, | |
| 46 std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 47 static const char kWidevineParentKeySystem[] = "com.widevine"; | |
| 41 | 48 |
| 42 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) | |
| 43 // The supported codecs depend on what the CDM provides. | |
| 44 static const char kWidevineVideoMp4Codecs[] = | |
| 45 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) && \ | |
| 46 defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) | |
| 47 "avc1,mp4a"; | |
| 48 #elif defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) | |
| 49 "avc1"; | |
| 50 #else | |
| 51 ""; // No codec strings are supported. | |
| 52 #endif | |
| 53 | |
| 54 static const char kWidevineAudioMp4Codecs[] = | |
| 55 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) | |
| 56 "mp4a"; | |
| 57 #else | |
| 58 ""; // No codec strings are supported. | |
| 59 #endif | |
| 60 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) | |
| 61 | |
| 62 static void RegisterWidevine() { | |
| 63 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 49 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 64 Version glibc_version(gnu_get_libc_version()); | 50 Version glibc_version(gnu_get_libc_version()); |
| 65 DCHECK(glibc_version.IsValid()); | 51 DCHECK(glibc_version.IsValid()); |
| 66 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) | 52 if (glibc_version.IsOlderThan(WIDEVINE_CDM_MIN_GLIBC_VERSION)) |
| 67 return; | 53 return; |
| 68 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) | 54 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 69 | 55 |
| 70 AddConcreteSupportedKeySystem( | 56 KeySystemInfo info(kWidevineKeySystem); |
| 71 kWidevineKeySystem, | 57 |
| 72 false, | 58 if (is_webm_vp8_and_vorbis_supported) { |
| 59 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | |
| 60 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | |
| 61 } | |
| 62 | |
| 63 DCHECK(!is_mp4_supported || (!is_aac_supported && !is_aac_supported)); | |
| 64 #if defined(USE_PROPRIETARY_CODECS) | |
|
scherkus (not reviewing)
2013/09/03 22:22:08
this seems confusing
if this isn't defined but I
ddorwin
2013/09/04 00:41:55
I can add:
#else
DCHECK(!is_mp4_supported);
OR
| |
| 65 if (is_mp4_supported) { | |
| 66 const char* video_codecs = is_avc1_supported ? | |
| 67 (is_aac_supported ? kMp4aAvc1 : kAvc1) : | |
| 68 ""; | |
| 69 const char* audio_codecs = is_aac_supported ? kMp4a : ""; | |
| 70 | |
| 71 info.supported_types.push_back(std::make_pair(kAudioMp4, audio_codecs)); | |
| 72 info.supported_types.push_back(std::make_pair(kVideoMp4, video_codecs)); | |
| 73 } | |
| 74 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 75 | |
| 76 info.parent_key_system = kWidevineParentKeySystem; | |
| 77 | |
| 73 #if defined(ENABLE_PEPPER_CDMS) | 78 #if defined(ENABLE_PEPPER_CDMS) |
| 74 kWidevineCdmPluginMimeType, | 79 info.pepper_type = kWidevineCdmPluginMimeType; |
| 75 #elif defined(OS_ANDROID) | 80 #elif defined(OS_ANDROID) |
| 81 static const uint8 WidevineUuid[16] = | |
| 76 { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 82 { 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
| 77 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }, | 83 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
| 84 info.uuid.assign(WidevineUuid, WidevineUuid + arraysize(WidevineUuid)); | |
| 78 #endif // defined(ENABLE_PEPPER_CDMS) | 85 #endif // defined(ENABLE_PEPPER_CDMS) |
| 79 "com.widevine"); | |
| 80 AddSupportedType(kWidevineKeySystem, "video/webm", "vorbis,vp8,vp8.0"); | |
| 81 AddSupportedType(kWidevineKeySystem, "audio/webm", "vorbis"); | |
| 82 #if defined(USE_PROPRIETARY_CODECS) && \ | |
| 83 defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) | |
| 84 AddSupportedType(kWidevineKeySystem, "video/mp4", kWidevineVideoMp4Codecs); | |
| 85 AddSupportedType(kWidevineKeySystem, "audio/mp4", kWidevineAudioMp4Codecs); | |
| 86 #endif // defined(USE_PROPRIETARY_CODECS) && | |
| 87 // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) | |
| 88 } | |
| 89 #endif // WIDEVINE_CDM_AVAILABLE | |
| 90 | 86 |
| 91 | 87 concrete_key_systems->push_back(info); |
| 92 static void RegisterClearKey() { | |
| 93 // Clear Key. | |
| 94 AddConcreteSupportedKeySystem( | |
| 95 kClearKeyKeySystem, | |
| 96 true, | |
| 97 #if defined(ENABLE_PEPPER_CDMS) | |
| 98 std::string(), | |
| 99 #elif defined(OS_ANDROID) | |
| 100 kEmptyUuid, | |
| 101 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 102 std::string()); | |
| 103 AddSupportedType(kClearKeyKeySystem, "video/webm", "vorbis,vp8,vp8.0"); | |
| 104 AddSupportedType(kClearKeyKeySystem, "audio/webm", "vorbis"); | |
| 105 #if defined(USE_PROPRIETARY_CODECS) | |
| 106 AddSupportedType(kClearKeyKeySystem, "video/mp4", "avc1,mp4a"); | |
| 107 AddSupportedType(kClearKeyKeySystem, "audio/mp4", "mp4a"); | |
| 108 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 109 } | 88 } |
| 110 | 89 |
| 111 #if defined(ENABLE_PEPPER_CDMS) | 90 #if defined(ENABLE_PEPPER_CDMS) |
| 112 static void RegisterExternalClearKey() { | 91 // Supported types are determined at compile time. |
| 113 // External Clear Key (used for testing). | 92 static void AddPepperBasedWidevine( |
| 114 AddConcreteSupportedKeySystem(kExternalClearKeyKeySystem, false, | 93 std::vector<KeySystemInfo>* concrete_key_systems) { |
| 115 "application/x-ppapi-clearkey-cdm", | 94 AddWidevineForTypes(true, // WebM, VP8 & Vorbis. |
| 116 std::string()); | 95 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) |
| 117 AddSupportedType(kExternalClearKeyKeySystem, | 96 true, // MP4. |
| 118 "video/webm", "vorbis,vp8,vp8.0"); | 97 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE) |
| 119 AddSupportedType(kExternalClearKeyKeySystem, "audio/webm", "vorbis"); | 98 true, // AAC. |
| 99 #else | |
| 100 false, // No AAC. | |
| 101 #endif | |
| 102 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE) | |
| 103 true, // AVC1. | |
| 104 #else | |
| 105 false, // No AVC1. | |
|
scherkus (not reviewing)
2013/09/03 22:25:06
I still wonder if we can clarify this code somehow
ddorwin
2013/09/04 00:41:55
We will have this code next week (Android). (I was
| |
| 106 #endif | |
| 107 #else | |
| 108 false, false, false, // No MP4 codecs. | |
| 109 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE) | |
| 110 concrete_key_systems); | |
| 111 } | |
| 112 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 113 #endif // WIDEVINE_CDM_AVAILABLE | |
|
scherkus (not reviewing)
2013/09/03 22:22:08
missing defined()
ddorwin
2013/09/04 00:41:55
Done.
| |
| 114 | |
| 115 static void AddClearKey(std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 116 KeySystemInfo info(kClearKeyKeySystem); | |
| 117 | |
| 118 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | |
| 119 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | |
| 120 #if defined(USE_PROPRIETARY_CODECS) | 120 #if defined(USE_PROPRIETARY_CODECS) |
| 121 AddSupportedType(kExternalClearKeyKeySystem, "video/mp4", "avc1,mp4a"); | 121 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); |
| 122 AddSupportedType(kExternalClearKeyKeySystem, "audio/mp4", "mp4a"); | 122 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); |
| 123 #endif // defined(USE_PROPRIETARY_CODECS) | 123 #endif // defined(USE_PROPRIETARY_CODECS) |
| 124 | |
| 125 info.use_aes_decryptor = true; | |
| 126 | |
| 127 concrete_key_systems->push_back(info); | |
| 128 } | |
| 129 | |
| 130 #if defined(ENABLE_PEPPER_CDMS) | |
| 131 // External Clear Key (used for testing). | |
| 132 static void AddExternalClearKey( | |
| 133 std::vector<KeySystemInfo>* concrete_key_systems) { | |
| 134 static const char kExternalClearKeyKeySystem[] = | |
| 135 "org.chromium.externalclearkey"; | |
| 136 static const char kExternalClearKeyPepperType[] = | |
| 137 "application/x-ppapi-clearkey-cdm"; | |
| 138 | |
| 139 KeySystemInfo info(kExternalClearKeyKeySystem); | |
| 140 | |
| 141 info.supported_types.push_back(std::make_pair(kAudioWebM, kVorbis)); | |
| 142 info.supported_types.push_back(std::make_pair(kVideoWebM, kVorbisVP8)); | |
| 143 #if defined(USE_PROPRIETARY_CODECS) | |
| 144 info.supported_types.push_back(std::make_pair(kAudioMp4, kMp4a)); | |
| 145 info.supported_types.push_back(std::make_pair(kVideoMp4, kMp4aAvc1)); | |
| 146 #endif // defined(USE_PROPRIETARY_CODECS) | |
| 147 | |
| 148 info.pepper_type = kExternalClearKeyPepperType; | |
| 149 | |
| 150 concrete_key_systems->push_back(info); | |
| 124 } | 151 } |
| 125 #endif // defined(ENABLE_PEPPER_CDMS) | 152 #endif // defined(ENABLE_PEPPER_CDMS) |
| 126 | 153 |
| 127 void RegisterKeySystems() { | 154 void AddKeySystems(std::vector<KeySystemInfo>* key_systems_info) { |
| 128 RegisterClearKey(); | 155 AddClearKey(key_systems_info); |
| 129 | 156 |
| 130 #if defined(ENABLE_PEPPER_CDMS) | 157 #if defined(ENABLE_PEPPER_CDMS) |
| 131 RegisterExternalClearKey(); | 158 AddExternalClearKey(key_systems_info); |
| 132 #endif | 159 #endif |
| 133 | 160 |
| 134 #if defined(WIDEVINE_CDM_AVAILABLE) | 161 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 135 RegisterWidevine(); | 162 #if defined(ENABLE_PEPPER_CDMS) |
| 163 AddPepperBasedWidevine(key_systems_info); | |
| 164 #else | |
| 165 #error TODO(ddorwin): Need to check the platform | |
| 166 #endif | |
| 136 #endif | 167 #endif |
| 137 } | 168 } |
| 138 | 169 |
| 139 bool IsCanPlayTypeSuppressed(const std::string& key_system) { | 170 bool IsCanPlayTypeSuppressed(const std::string& key_system) { |
| 140 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) | 171 #if defined(DISABLE_WIDEVINE_CDM_CANPLAYTYPE) |
| 141 // See http://crbug.com/237627. | 172 // See http://crbug.com/237627. |
| 142 if (key_system == kWidevineKeySystem && | 173 if (key_system == kWidevineKeySystem && |
| 143 !CommandLine::ForCurrentProcess()->HasSwitch( | 174 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 144 switches::kOverrideEncryptedMediaCanPlayType)) | 175 switches::kOverrideEncryptedMediaCanPlayType)) |
| 145 return true; | 176 return true; |
| 146 #endif | 177 #endif |
| 147 return false; | 178 return false; |
| 148 } | 179 } |
| 149 | 180 |
| 150 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { | 181 std::string KeySystemNameForUMAInternal(const WebKit::WebString& key_system) { |
| 151 if (key_system == kClearKeyKeySystem) | 182 if (key_system == kClearKeyKeySystem) |
| 152 return "ClearKey"; | 183 return "ClearKey"; |
| 153 #if defined(WIDEVINE_CDM_AVAILABLE) | 184 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 154 if (key_system == kWidevineKeySystem) | 185 if (key_system == kWidevineKeySystem) |
| 155 return "Widevine"; | 186 return "Widevine"; |
| 156 #endif // WIDEVINE_CDM_AVAILABLE | 187 #endif // WIDEVINE_CDM_AVAILABLE |
| 157 return "Unknown"; | 188 return "Unknown"; |
| 158 } | 189 } |
| 159 | 190 |
| 160 } // namespace content | 191 } // namespace content |
| OLD | NEW |