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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
18 #include "components/cdm/renderer/widevine_key_system_properties.h" | 18 #include "components/cdm/renderer/widevine_key_system_properties.h" |
19 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
20 #include "media/base/eme_constants.h" | 20 #include "media/base/eme_constants.h" |
21 #include "media/base/key_system_info.h" | |
22 #include "media/base/key_system_properties.h" | 21 #include "media/base/key_system_properties.h" |
23 | 22 |
24 #include "media/media_features.h" | 23 #include "media/media_features.h" |
25 | 24 |
26 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
27 #include "components/cdm/renderer/android_key_systems.h" | 26 #include "components/cdm/renderer/android_key_systems.h" |
28 #endif | 27 #endif |
29 | 28 |
30 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 29 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
31 | 30 |
32 // The following must be after widevine_cdm_version.h. | 31 // The following must be after widevine_cdm_version.h. |
33 | 32 |
34 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) | 33 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_MIN_GLIBC_VERSION) |
35 #include <gnu/libc-version.h> | 34 #include <gnu/libc-version.h> |
36 #include "base/version.h" | 35 #include "base/version.h" |
37 #endif | 36 #endif |
38 | 37 |
39 using media::KeySystemInfo; | |
40 using media::KeySystemProperties; | 38 using media::KeySystemProperties; |
41 using media::SupportedCodecs; | 39 using media::SupportedCodecs; |
42 | 40 |
43 #if defined(ENABLE_PEPPER_CDMS) | 41 #if defined(ENABLE_PEPPER_CDMS) |
| 42 static const char kExternalClearKeyPepperType[] = |
| 43 "application/x-ppapi-clearkey-cdm"; |
| 44 |
44 static bool IsPepperCdmAvailable( | 45 static bool IsPepperCdmAvailable( |
45 const std::string& pepper_type, | 46 const std::string& pepper_type, |
46 std::vector<base::string16>* additional_param_names, | 47 std::vector<base::string16>* additional_param_names, |
47 std::vector<base::string16>* additional_param_values) { | 48 std::vector<base::string16>* additional_param_values) { |
48 bool is_available = false; | 49 bool is_available = false; |
49 content::RenderThread::Get()->Send( | 50 content::RenderThread::Get()->Send( |
50 new ChromeViewHostMsg_IsInternalPluginAvailableForMimeType( | 51 new ChromeViewHostMsg_IsInternalPluginAvailableForMimeType( |
51 pepper_type, | 52 pepper_type, |
52 &is_available, | 53 &is_available, |
53 additional_param_names, | 54 additional_param_names, |
54 additional_param_values)); | 55 additional_param_values)); |
55 | 56 |
56 return is_available; | 57 return is_available; |
57 } | 58 } |
58 | 59 |
| 60 // KeySystemProperties implementation for external Clear Key systems. |
| 61 class ExternalClearKeyProperties : public KeySystemProperties { |
| 62 public: |
| 63 explicit ExternalClearKeyProperties(const std::string& key_system_name) |
| 64 : key_system_name_(key_system_name) {} |
| 65 |
| 66 std::string GetKeySystemName() const override { return key_system_name_; } |
| 67 bool IsSupportedInitDataType( |
| 68 media::EmeInitDataType init_data_type) const override { |
| 69 switch (init_data_type) { |
| 70 case media::EmeInitDataType::WEBM: |
| 71 case media::EmeInitDataType::KEYIDS: |
| 72 return true; |
| 73 |
| 74 case media::EmeInitDataType::CENC: |
| 75 #if defined(USE_PROPRIETARY_CODECS) |
| 76 return true; |
| 77 #else |
| 78 return false; |
| 79 #endif // defined(USE_PROPRIETARY_CODECS) |
| 80 |
| 81 case media::EmeInitDataType::UNKNOWN: |
| 82 return false; |
| 83 } |
| 84 NOTREACHED(); |
| 85 return false; |
| 86 } |
| 87 |
| 88 SupportedCodecs GetSupportedCodecs() const override { |
| 89 #if defined(USE_PROPRIETARY_CODECS) |
| 90 return media::EME_CODEC_MP4_ALL | media::EME_CODEC_WEBM_ALL; |
| 91 #else |
| 92 return media::EME_CODEC_WEBM_ALL; |
| 93 #endif |
| 94 } |
| 95 |
| 96 media::EmeConfigRule GetRobustnessConfigRule( |
| 97 media::EmeMediaType media_type, |
| 98 const std::string& requested_robustness) const override { |
| 99 return requested_robustness.empty() ? media::EmeConfigRule::SUPPORTED |
| 100 : media::EmeConfigRule::NOT_SUPPORTED; |
| 101 } |
| 102 |
| 103 // Persistent license sessions are faked. |
| 104 media::EmeSessionTypeSupport GetPersistentLicenseSessionSupport() |
| 105 const override { |
| 106 return media::EmeSessionTypeSupport::SUPPORTED; |
| 107 } |
| 108 |
| 109 media::EmeSessionTypeSupport GetPersistentReleaseMessageSessionSupport() |
| 110 const override { |
| 111 return media::EmeSessionTypeSupport::NOT_SUPPORTED; |
| 112 } |
| 113 |
| 114 media::EmeFeatureSupport GetPersistentStateSupport() const override { |
| 115 return media::EmeFeatureSupport::REQUESTABLE; |
| 116 } |
| 117 |
| 118 media::EmeFeatureSupport GetDistinctiveIdentifierSupport() const override { |
| 119 return media::EmeFeatureSupport::NOT_SUPPORTED; |
| 120 } |
| 121 |
| 122 std::string GetPepperType() const override { |
| 123 return kExternalClearKeyPepperType; |
| 124 } |
| 125 |
| 126 private: |
| 127 const std::string key_system_name_; |
| 128 }; |
| 129 |
59 // External Clear Key (used for testing). | 130 // External Clear Key (used for testing). |
60 static void AddExternalClearKey( | 131 static void AddExternalClearKey( |
61 std::vector<KeySystemInfo>* concrete_key_systems) { | 132 std::vector<std::unique_ptr<KeySystemProperties>>* concrete_key_systems) { |
62 static const char kExternalClearKeyKeySystem[] = | 133 static const char kExternalClearKeyKeySystem[] = |
63 "org.chromium.externalclearkey"; | 134 "org.chromium.externalclearkey"; |
64 static const char kExternalClearKeyDecryptOnlyKeySystem[] = | 135 static const char kExternalClearKeyDecryptOnlyKeySystem[] = |
65 "org.chromium.externalclearkey.decryptonly"; | 136 "org.chromium.externalclearkey.decryptonly"; |
66 static const char kExternalClearKeyFileIOTestKeySystem[] = | 137 static const char kExternalClearKeyFileIOTestKeySystem[] = |
67 "org.chromium.externalclearkey.fileiotest"; | 138 "org.chromium.externalclearkey.fileiotest"; |
68 static const char kExternalClearKeyInitializeFailKeySystem[] = | 139 static const char kExternalClearKeyInitializeFailKeySystem[] = |
69 "org.chromium.externalclearkey.initializefail"; | 140 "org.chromium.externalclearkey.initializefail"; |
70 static const char kExternalClearKeyCrashKeySystem[] = | 141 static const char kExternalClearKeyCrashKeySystem[] = |
71 "org.chromium.externalclearkey.crash"; | 142 "org.chromium.externalclearkey.crash"; |
72 static const char kExternalClearKeyPepperType[] = | |
73 "application/x-ppapi-clearkey-cdm"; | |
74 | 143 |
75 std::vector<base::string16> additional_param_names; | 144 std::vector<base::string16> additional_param_names; |
76 std::vector<base::string16> additional_param_values; | 145 std::vector<base::string16> additional_param_values; |
77 if (!IsPepperCdmAvailable(kExternalClearKeyPepperType, | 146 if (!IsPepperCdmAvailable(kExternalClearKeyPepperType, |
78 &additional_param_names, | 147 &additional_param_names, |
79 &additional_param_values)) { | 148 &additional_param_values)) { |
80 return; | 149 return; |
81 } | 150 } |
82 | 151 |
83 KeySystemInfo info; | 152 concrete_key_systems->emplace_back( |
84 info.key_system = kExternalClearKeyKeySystem; | 153 new ExternalClearKeyProperties(kExternalClearKeyKeySystem)); |
85 | |
86 info.supported_init_data_types = | |
87 media::kInitDataTypeMaskWebM | media::kInitDataTypeMaskKeyIds; | |
88 info.supported_codecs = media::EME_CODEC_WEBM_ALL; | |
89 #if defined(USE_PROPRIETARY_CODECS) | |
90 info.supported_init_data_types |= media::kInitDataTypeMaskCenc; | |
91 info.supported_codecs |= media::EME_CODEC_MP4_ALL; | |
92 #endif // defined(USE_PROPRIETARY_CODECS) | |
93 | |
94 info.max_audio_robustness = media::EmeRobustness::EMPTY; | |
95 info.max_video_robustness = media::EmeRobustness::EMPTY; | |
96 | |
97 // Persistent sessions are faked. | |
98 info.persistent_license_support = media::EmeSessionTypeSupport::SUPPORTED; | |
99 info.persistent_release_message_support = | |
100 media::EmeSessionTypeSupport::NOT_SUPPORTED; | |
101 info.persistent_state_support = media::EmeFeatureSupport::REQUESTABLE; | |
102 info.distinctive_identifier_support = media::EmeFeatureSupport::NOT_SUPPORTED; | |
103 | |
104 info.pepper_type = kExternalClearKeyPepperType; | |
105 | |
106 concrete_key_systems->push_back(info); | |
107 | 154 |
108 // Add support of decrypt-only mode in ClearKeyCdm. | 155 // Add support of decrypt-only mode in ClearKeyCdm. |
109 info.key_system = kExternalClearKeyDecryptOnlyKeySystem; | 156 concrete_key_systems->emplace_back( |
110 concrete_key_systems->push_back(info); | 157 new ExternalClearKeyProperties(kExternalClearKeyDecryptOnlyKeySystem)); |
111 | 158 |
112 // A key system that triggers FileIO test in ClearKeyCdm. | 159 // A key system that triggers FileIO test in ClearKeyCdm. |
113 info.key_system = kExternalClearKeyFileIOTestKeySystem; | 160 concrete_key_systems->emplace_back( |
114 concrete_key_systems->push_back(info); | 161 new ExternalClearKeyProperties(kExternalClearKeyFileIOTestKeySystem)); |
115 | 162 |
116 // A key system that Chrome thinks is supported by ClearKeyCdm, but actually | 163 // A key system that Chrome thinks is supported by ClearKeyCdm, but actually |
117 // will be refused by ClearKeyCdm. This is to test the CDM initialization | 164 // will be refused by ClearKeyCdm. This is to test the CDM initialization |
118 // failure case. | 165 // failure case. |
119 info.key_system = kExternalClearKeyInitializeFailKeySystem; | 166 concrete_key_systems->emplace_back( |
120 concrete_key_systems->push_back(info); | 167 new ExternalClearKeyProperties(kExternalClearKeyInitializeFailKeySystem)); |
121 | 168 |
122 // A key system that triggers a crash in ClearKeyCdm. | 169 // A key system that triggers a crash in ClearKeyCdm. |
123 info.key_system = kExternalClearKeyCrashKeySystem; | 170 concrete_key_systems->emplace_back( |
124 concrete_key_systems->push_back(info); | 171 new ExternalClearKeyProperties(kExternalClearKeyCrashKeySystem)); |
125 } | 172 } |
126 | 173 |
127 #if defined(WIDEVINE_CDM_AVAILABLE) | 174 #if defined(WIDEVINE_CDM_AVAILABLE) |
128 // This function finds "codecs" and parses the value into the vector |codecs|. | 175 // This function finds "codecs" and parses the value into the vector |codecs|. |
129 // Converts the codec strings to UTF-8 since we only expect ASCII strings and | 176 // Converts the codec strings to UTF-8 since we only expect ASCII strings and |
130 // this simplifies the rest of the code in this file. | 177 // this simplifies the rest of the code in this file. |
131 void GetSupportedCodecsForPepperCdm( | 178 void GetSupportedCodecsForPepperCdm( |
132 const std::vector<base::string16>& additional_param_names, | 179 const std::vector<base::string16>& additional_param_names, |
133 const std::vector<base::string16>& additional_param_values, | 180 const std::vector<base::string16>& additional_param_values, |
134 std::vector<std::string>* codecs) { | 181 std::vector<std::string>* codecs) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 media::EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license. | 266 media::EmeSessionTypeSupport::NOT_SUPPORTED, // persistent-license. |
220 media::EmeSessionTypeSupport:: | 267 media::EmeSessionTypeSupport:: |
221 NOT_SUPPORTED, // persistent-release-message. | 268 NOT_SUPPORTED, // persistent-release-message. |
222 media::EmeFeatureSupport::REQUESTABLE, // Persistent state. | 269 media::EmeFeatureSupport::REQUESTABLE, // Persistent state. |
223 media::EmeFeatureSupport::NOT_SUPPORTED)); // Distinctive identifier. | 270 media::EmeFeatureSupport::NOT_SUPPORTED)); // Distinctive identifier. |
224 #endif // defined(OS_CHROMEOS) | 271 #endif // defined(OS_CHROMEOS) |
225 } | 272 } |
226 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 273 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
227 #endif // defined(ENABLE_PEPPER_CDMS) | 274 #endif // defined(ENABLE_PEPPER_CDMS) |
228 | 275 |
229 void AddChromeKeySystemsInfo(std::vector<KeySystemInfo>* key_systems_info) { | |
230 #if defined(ENABLE_PEPPER_CDMS) | |
231 AddExternalClearKey(key_systems_info); | |
232 #endif | |
233 } | |
234 | |
235 void AddChromeKeySystems( | 276 void AddChromeKeySystems( |
236 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems_properties) { | 277 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems_properties) { |
237 #if defined(ENABLE_PEPPER_CDMS) | 278 #if defined(ENABLE_PEPPER_CDMS) |
| 279 AddExternalClearKey(key_systems_properties); |
| 280 |
238 #if defined(WIDEVINE_CDM_AVAILABLE) | 281 #if defined(WIDEVINE_CDM_AVAILABLE) |
239 AddPepperBasedWidevine(key_systems_properties); | 282 AddPepperBasedWidevine(key_systems_properties); |
240 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 283 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 284 |
241 #endif // defined(ENABLE_PEPPER_CDMS) | 285 #endif // defined(ENABLE_PEPPER_CDMS) |
242 | 286 |
243 #if defined(OS_ANDROID) | 287 #if defined(OS_ANDROID) |
244 cdm::AddAndroidWidevine(key_systems_properties); | 288 cdm::AddAndroidWidevine(key_systems_properties); |
245 #endif // defined(OS_ANDROID) | 289 #endif // defined(OS_ANDROID) |
246 } | 290 } |
OLD | NEW |