Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: content/renderer/media/crypto/key_systems.cc

Issue 404613003: Update supported key system info from browser process if needed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "content/renderer/media/crypto/key_systems.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/time/time.h"
13 #include "content/public/common/content_client.h" 14 #include "content/public/common/content_client.h"
14 #include "content/public/common/eme_codec.h" 15 #include "content/public/common/eme_codec.h"
15 #include "content/public/renderer/content_renderer_client.h" 16 #include "content/public/renderer/content_renderer_client.h"
16 #include "content/public/renderer/key_system_info.h" 17 #include "content/public/renderer/key_system_info.h"
17 #include "content/renderer/media/crypto/key_systems_support_uma.h" 18 #include "content/renderer/media/crypto/key_systems_support_uma.h"
18 19
19 #if defined(OS_ANDROID) 20 #if defined(OS_ANDROID)
20 #include "media/base/android/media_codec_bridge.h" 21 #include "media/base/android/media_codec_bridge.h"
21 #endif 22 #endif
22 23
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 81
81 info.use_aes_decryptor = true; 82 info.use_aes_decryptor = true;
82 83
83 concrete_key_systems->push_back(info); 84 concrete_key_systems->push_back(info);
84 } 85 }
85 86
86 class KeySystems { 87 class KeySystems {
87 public: 88 public:
88 static KeySystems& GetInstance(); 89 static KeySystems& GetInstance();
89 90
91 void UpdateIfNeeded();
92
90 bool IsConcreteSupportedKeySystem(const std::string& key_system); 93 bool IsConcreteSupportedKeySystem(const std::string& key_system);
91 94
92 bool IsSupportedKeySystemWithMediaMimeType( 95 bool IsSupportedKeySystemWithMediaMimeType(
93 const std::string& mime_type, 96 const std::string& mime_type,
94 const std::vector<std::string>& codecs, 97 const std::vector<std::string>& codecs,
95 const std::string& key_system); 98 const std::string& key_system);
96 99
97 bool UseAesDecryptor(const std::string& concrete_key_system); 100 bool UseAesDecryptor(const std::string& concrete_key_system);
98 101
99 #if defined(ENABLE_PEPPER_CDMS) 102 #if defined(ENABLE_PEPPER_CDMS)
100 std::string GetPepperType(const std::string& concrete_key_system); 103 std::string GetPepperType(const std::string& concrete_key_system);
101 #endif 104 #endif
102 105
103 void AddContainerMask(const std::string& container, uint32 mask); 106 void AddContainerMask(const std::string& container, uint32 mask);
104 void AddCodecMask(const std::string& codec, uint32 mask); 107 void AddCodecMask(const std::string& codec, uint32 mask);
105 108
106 private: 109 private:
110 void UpdateSupportedKeySystems();
111
107 void AddConcreteSupportedKeySystems( 112 void AddConcreteSupportedKeySystems(
108 const std::vector<KeySystemInfo>& concrete_key_systems); 113 const std::vector<KeySystemInfo>& concrete_key_systems);
109 114
110 void AddConcreteSupportedKeySystem( 115 void AddConcreteSupportedKeySystem(
111 const std::string& key_system, 116 const std::string& key_system,
112 bool use_aes_decryptor, 117 bool use_aes_decryptor,
113 #if defined(ENABLE_PEPPER_CDMS) 118 #if defined(ENABLE_PEPPER_CDMS)
114 const std::string& pepper_type, 119 const std::string& pepper_type,
115 #endif 120 #endif
116 SupportedCodecs supported_codecs, 121 SupportedCodecs supported_codecs,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 159
155 // Map from parent key system to the concrete key system that should be used 160 // Map from parent key system to the concrete key system that should be used
156 // to represent its capabilities. 161 // to represent its capabilities.
157 ParentKeySystemMap parent_key_system_map_; 162 ParentKeySystemMap parent_key_system_map_;
158 163
159 KeySystemsSupportUMA key_systems_support_uma_; 164 KeySystemsSupportUMA key_systems_support_uma_;
160 165
161 CodecMaskMap container_codec_masks_; 166 CodecMaskMap container_codec_masks_;
162 CodecMaskMap codec_masks_; 167 CodecMaskMap codec_masks_;
163 168
169 base::Time last_update_time_;
170
164 DISALLOW_COPY_AND_ASSIGN(KeySystems); 171 DISALLOW_COPY_AND_ASSIGN(KeySystems);
165 }; 172 };
166 173
167 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER; 174 static base::LazyInstance<KeySystems> g_key_systems = LAZY_INSTANCE_INITIALIZER;
168 175
169 KeySystems& KeySystems::GetInstance() { 176 KeySystems& KeySystems::GetInstance() {
177 g_key_systems.Get().UpdateIfNeeded();
170 return g_key_systems.Get(); 178 return g_key_systems.Get();
171 } 179 }
172 180
173 // Because we use a LazyInstance, the key systems info must be populated when 181 // Because we use a LazyInstance, the key systems info must be populated when
174 // the instance is lazily initiated. 182 // the instance is lazily initiated.
175 KeySystems::KeySystems() { 183 KeySystems::KeySystems() {
176 // Build container and codec masks for quick look up. 184 // Build container and codec masks for quick look up.
177 for (size_t i = 0; i < arraysize(kContainerCodecMasks); ++i) { 185 for (size_t i = 0; i < arraysize(kContainerCodecMasks); ++i) {
178 const CodecMask& container_codec_mask = kContainerCodecMasks[i]; 186 const CodecMask& container_codec_mask = kContainerCodecMasks[i];
179 DCHECK(container_codec_masks_.find(container_codec_mask.type) == 187 DCHECK(container_codec_masks_.find(container_codec_mask.type) ==
180 container_codec_masks_.end()); 188 container_codec_masks_.end());
181 container_codec_masks_[container_codec_mask.type] = 189 container_codec_masks_[container_codec_mask.type] =
182 container_codec_mask.mask; 190 container_codec_mask.mask;
183 } 191 }
184 for (size_t i = 0; i < arraysize(kCodecMasks); ++i) { 192 for (size_t i = 0; i < arraysize(kCodecMasks); ++i) {
185 const CodecMask& codec_mask = kCodecMasks[i]; 193 const CodecMask& codec_mask = kCodecMasks[i];
186 DCHECK(codec_masks_.find(codec_mask.type) == codec_masks_.end()); 194 DCHECK(codec_masks_.find(codec_mask.type) == codec_masks_.end());
187 codec_masks_[codec_mask.type] = codec_mask.mask; 195 codec_masks_[codec_mask.type] = codec_mask.mask;
188 } 196 }
189 197
190 std::vector<KeySystemInfo> key_systems_info; 198 UpdateSupportedKeySystems();
191 GetContentClient()->renderer()->AddKeySystems(&key_systems_info); 199
192 // Clear Key is always supported.
193 AddClearKey(&key_systems_info);
194 AddConcreteSupportedKeySystems(key_systems_info);
195 #if defined(WIDEVINE_CDM_AVAILABLE) 200 #if defined(WIDEVINE_CDM_AVAILABLE)
196 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem); 201 key_systems_support_uma_.AddKeySystemToReport(kWidevineKeySystem);
197 #endif // defined(WIDEVINE_CDM_AVAILABLE) 202 #endif // defined(WIDEVINE_CDM_AVAILABLE)
198 } 203 }
199 204
205 void KeySystems::UpdateIfNeeded() {
206 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
207 if (IsConcreteSupportedKeySystem(kWidevineKeySystem))
208 return;
209
210 // The update could involve a sync IPC to the browser process. Use a minimum
211 // update interval to avoid unnecessary frequent IPC to the browser.
212 static const int kMinUpdateIntervalInSeconds = 5;
213 base::Time now = base::Time::Now();
214 if (now - last_update_time_ <
215 base::TimeDelta::FromSeconds(kMinUpdateIntervalInSeconds)) {
216 return;
217 }
218
219 UpdateSupportedKeySystems();
220 #endif
221 }
222
223 void KeySystems::UpdateSupportedKeySystems() {
224 DVLOG(2) << __FUNCTION__;
xhwang 2014/07/18 00:44:15 I'll remove this.
225 concrete_key_system_map_.clear();
226 parent_key_system_map_.clear();
227
228 // Build KeySystemInfo.
229 std::vector<KeySystemInfo> key_systems_info;
230 GetContentClient()->renderer()->AddKeySystems(&key_systems_info);
231 // Clear Key is always supported.
232 AddClearKey(&key_systems_info);
233
234 AddConcreteSupportedKeySystems(key_systems_info);
235
236 last_update_time_ = base::Time::Now();
237 }
238
200 void KeySystems::AddConcreteSupportedKeySystems( 239 void KeySystems::AddConcreteSupportedKeySystems(
201 const std::vector<KeySystemInfo>& concrete_key_systems) { 240 const std::vector<KeySystemInfo>& concrete_key_systems) {
202 for (size_t i = 0; i < concrete_key_systems.size(); ++i) { 241 for (size_t i = 0; i < concrete_key_systems.size(); ++i) {
203 const KeySystemInfo& key_system_info = concrete_key_systems[i]; 242 const KeySystemInfo& key_system_info = concrete_key_systems[i];
204 AddConcreteSupportedKeySystem(key_system_info.key_system, 243 AddConcreteSupportedKeySystem(key_system_info.key_system,
205 key_system_info.use_aes_decryptor, 244 key_system_info.use_aes_decryptor,
206 #if defined(ENABLE_PEPPER_CDMS) 245 #if defined(ENABLE_PEPPER_CDMS)
207 key_system_info.pepper_type, 246 key_system_info.pepper_type,
208 #endif 247 #endif
209 key_system_info.supported_codecs, 248 key_system_info.supported_codecs,
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 CONTENT_EXPORT void AddContainerMask(const std::string& container, 493 CONTENT_EXPORT void AddContainerMask(const std::string& container,
455 uint32 mask) { 494 uint32 mask) {
456 KeySystems::GetInstance().AddContainerMask(container, mask); 495 KeySystems::GetInstance().AddContainerMask(container, mask);
457 } 496 }
458 497
459 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) { 498 CONTENT_EXPORT void AddCodecMask(const std::string& codec, uint32 mask) {
460 KeySystems::GetInstance().AddCodecMask(codec, mask); 499 KeySystems::GetInstance().AddCodecMask(codec, mask);
461 } 500 }
462 501
463 } // namespace content 502 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698