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

Side by Side Diff: webkit/renderer/media/crypto/proxy_decryptor.cc

Issue 17289006: Separate CDM initialization from GenerateKeyRequest & remove key_system parameters. (Closed) Base URL: master
Patch Set: minor changes Created 7 years, 6 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
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 "webkit/renderer/media/crypto/proxy_decryptor.h" 5 #include "webkit/renderer/media/crypto/proxy_decryptor.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/crypto/aes_decryptor.h" 10 #include "media/crypto/aes_decryptor.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 // Normal decryptor request. 93 // Normal decryptor request.
94 DCHECK(decryptor_ready_cb_.is_null()); 94 DCHECK(decryptor_ready_cb_.is_null());
95 if (decryptor_) { 95 if (decryptor_) {
96 decryptor_ready_cb.Run(decryptor_.get()); 96 decryptor_ready_cb.Run(decryptor_.get());
97 return; 97 return;
98 } 98 }
99 decryptor_ready_cb_ = decryptor_ready_cb; 99 decryptor_ready_cb_ = decryptor_ready_cb;
100 } 100 }
101 101
102 bool ProxyDecryptor::GenerateKeyRequest(const std::string& key_system, 102 bool ProxyDecryptor::InitializeCDM(const std::string& key_system) {
103 const std::string& type, 103 DVLOG(1) << "InitializeCDM: key_system = " << key_system;
104 const uint8* init_data,
105 int init_data_length) {
106 // We do not support run-time switching of decryptors. GenerateKeyRequest()
107 // only creates a new decryptor when |decryptor_| is not initialized.
108 DVLOG(1) << "GenerateKeyRequest: key_system = " << key_system;
109 104
110 base::AutoLock auto_lock(lock_); 105 base::AutoLock auto_lock(lock_);
111 106
112 if (!decryptor_) { 107 DCHECK(!decryptor_);
113 decryptor_ = CreateDecryptor(key_system); 108 decryptor_ = CreateDecryptor(key_system);
114 if (!decryptor_) { 109
115 key_error_cb_.Run( 110 return decryptor_ != NULL;
116 key_system, std::string(), media::MediaKeys::kClientError, 0); 111 }
117 return false; 112
118 } 113
119 } 114 bool ProxyDecryptor::GenerateKeyRequest(const std::string& type,
115 const uint8* init_data,
116 int init_data_length) {
117 DCHECK(decryptor_);
120 118
121 if (!decryptor_->GetMediaKeys()->GenerateKeyRequest( 119 if (!decryptor_->GetMediaKeys()->GenerateKeyRequest(
122 key_system, type, init_data, init_data_length)) { 120 type, init_data, init_data_length)) {
123 decryptor_.reset(); 121 decryptor_.reset();
124 return false; 122 return false;
125 } 123 }
126 124
127 if (!decryptor_ready_cb_.is_null()) 125 if (!decryptor_ready_cb_.is_null())
128 base::ResetAndReturn(&decryptor_ready_cb_).Run(decryptor_.get()); 126 base::ResetAndReturn(&decryptor_ready_cb_).Run(decryptor_.get());
129 127
130 return true; 128 return true;
131 } 129 }
132 130
133 void ProxyDecryptor::AddKey(const std::string& key_system, 131 void ProxyDecryptor::AddKey(const uint8* key,
134 const uint8* key,
135 int key_length, 132 int key_length,
136 const uint8* init_data, 133 const uint8* init_data,
137 int init_data_length, 134 int init_data_length,
138 const std::string& session_id) { 135 const std::string& session_id) {
139 DVLOG(1) << "AddKey()"; 136 DVLOG(1) << "AddKey()";
140 137
141 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. 138 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called.
142 decryptor_->GetMediaKeys()->AddKey( 139 decryptor_->GetMediaKeys()->AddKey(
143 key_system, key, key_length, init_data, init_data_length, session_id); 140 key, key_length, init_data, init_data_length, session_id);
144 } 141 }
145 142
146 void ProxyDecryptor::CancelKeyRequest(const std::string& key_system, 143 void ProxyDecryptor::CancelKeyRequest(const std::string& session_id) {
147 const std::string& session_id) {
148 DVLOG(1) << "CancelKeyRequest()"; 144 DVLOG(1) << "CancelKeyRequest()";
149 145
150 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. 146 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called.
151 decryptor_->GetMediaKeys()->CancelKeyRequest(key_system, session_id); 147 decryptor_->GetMediaKeys()->CancelKeyRequest(session_id);
152 } 148 }
153 149
154 #if defined(ENABLE_PEPPER_CDMS) 150 #if defined(ENABLE_PEPPER_CDMS)
155 scoped_ptr<media::Decryptor> ProxyDecryptor::CreatePpapiDecryptor( 151 scoped_ptr<media::Decryptor> ProxyDecryptor::CreatePpapiDecryptor(
156 const std::string& key_system) { 152 const std::string& key_system) {
157 DCHECK(web_media_player_client_); 153 DCHECK(web_media_player_client_);
158 DCHECK(web_frame_); 154 DCHECK(web_frame_);
159 155
160 std::string plugin_type = GetPepperType(key_system); 156 std::string plugin_type = GetPepperType(key_system);
161 DCHECK(!plugin_type.empty()); 157 DCHECK(!plugin_type.empty());
162 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance = 158 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance =
163 CreateHelperPlugin(plugin_type, web_media_player_client_, web_frame_); 159 CreateHelperPlugin(plugin_type, web_media_player_client_, web_frame_);
164 if (!plugin_instance.get()) { 160 if (!plugin_instance.get()) {
165 DVLOG(1) << "ProxyDecryptor: plugin instance creation failed."; 161 DVLOG(1) << "ProxyDecryptor: plugin instance creation failed.";
166 return scoped_ptr<media::Decryptor>(); 162 return scoped_ptr<media::Decryptor>();
167 } 163 }
168 164
169 // The new object will call destroy_plugin_cb to destroy Helper Plugin. 165 webkit_media::PpapiDecryptor* decryptor = PpapiDecryptor::Create(
170 return scoped_ptr<media::Decryptor>(new PpapiDecryptor( 166 key_system,
171 plugin_instance, 167 plugin_instance,
172 base::Bind(&ProxyDecryptor::KeyAdded, weak_ptr_factory_.GetWeakPtr()), 168 base::Bind(&ProxyDecryptor::KeyAdded, weak_ptr_factory_.GetWeakPtr()),
173 base::Bind(&ProxyDecryptor::KeyError, weak_ptr_factory_.GetWeakPtr()), 169 base::Bind(&ProxyDecryptor::KeyError, weak_ptr_factory_.GetWeakPtr()),
174 base::Bind(&ProxyDecryptor::KeyMessage, weak_ptr_factory_.GetWeakPtr()), 170 base::Bind(&ProxyDecryptor::KeyMessage, weak_ptr_factory_.GetWeakPtr()),
175 base::Bind(&ProxyDecryptor::NeedKey, weak_ptr_factory_.GetWeakPtr()), 171 base::Bind(&ProxyDecryptor::NeedKey, weak_ptr_factory_.GetWeakPtr()),
176 base::Bind(&ProxyDecryptor::DestroyHelperPlugin, 172 base::Bind(&ProxyDecryptor::DestroyHelperPlugin,
177 weak_ptr_factory_.GetWeakPtr()))); 173 weak_ptr_factory_.GetWeakPtr()));
174
175 if (!decryptor)
176 DestroyHelperPlugin();
177 // Else the new object will call destroy_plugin_cb to destroy Helper Plugin.
178
179 return scoped_ptr<media::Decryptor>(decryptor);
xhwang 2013/06/18 00:43:42 Can PpapiDecryptor::Create() return scoped_ptr dir
ddorwin 2013/06/18 16:46:21 Done.
178 } 180 }
179 #endif // defined(ENABLE_PEPPER_CDMS) 181 #endif // defined(ENABLE_PEPPER_CDMS)
180 182
181 scoped_ptr<media::Decryptor> ProxyDecryptor::CreateDecryptor( 183 scoped_ptr<media::Decryptor> ProxyDecryptor::CreateDecryptor(
182 const std::string& key_system) { 184 const std::string& key_system) {
183 if (CanUseAesDecryptor(key_system)) 185 if (CanUseAesDecryptor(key_system))
184 return scoped_ptr<media::Decryptor>(new media::AesDecryptor( 186 return scoped_ptr<media::Decryptor>(new media::AesDecryptor(
185 base::Bind(&ProxyDecryptor::KeyAdded, weak_ptr_factory_.GetWeakPtr()), 187 base::Bind(&ProxyDecryptor::KeyAdded, weak_ptr_factory_.GetWeakPtr()),
186 base::Bind(&ProxyDecryptor::KeyError, weak_ptr_factory_.GetWeakPtr()), 188 base::Bind(&ProxyDecryptor::KeyError, weak_ptr_factory_.GetWeakPtr()),
187 base::Bind(&ProxyDecryptor::KeyMessage, weak_ptr_factory_.GetWeakPtr()), 189 base::Bind(&ProxyDecryptor::KeyMessage, weak_ptr_factory_.GetWeakPtr()),
188 base::Bind(&ProxyDecryptor::NeedKey, weak_ptr_factory_.GetWeakPtr()))); 190 base::Bind(&ProxyDecryptor::NeedKey, weak_ptr_factory_.GetWeakPtr())));
189 191
190 #if defined(ENABLE_PEPPER_CDMS) 192 #if defined(ENABLE_PEPPER_CDMS)
191 // We only support AesDecryptor and PpapiDecryptor. So if we cannot 193 // We only support AesDecryptor and PpapiDecryptor. So if we cannot
192 // use the AesDecryptor, then we'll try to create a PpapiDecryptor for given 194 // use the AesDecryptor, then we'll try to create a PpapiDecryptor for given
193 // |key_system|. 195 // |key_system|.
194 return CreatePpapiDecryptor(key_system); 196 return CreatePpapiDecryptor(key_system);
195 #else 197 #else
196 return scoped_ptr<media::Decryptor>(); 198 return scoped_ptr<media::Decryptor>();
197 #endif // defined(ENABLE_PEPPER_CDMS) 199 #endif // defined(ENABLE_PEPPER_CDMS)
198 } 200 }
199 201
200 void ProxyDecryptor::KeyAdded(const std::string& key_system, 202 void ProxyDecryptor::KeyAdded(const std::string& session_id) {
201 const std::string& session_id) { 203 key_added_cb_.Run(session_id);
202 key_added_cb_.Run(key_system, session_id);
203 } 204 }
204 205
205 void ProxyDecryptor::KeyError(const std::string& key_system, 206 void ProxyDecryptor::KeyError(const std::string& session_id,
206 const std::string& session_id,
207 media::MediaKeys::KeyError error_code, 207 media::MediaKeys::KeyError error_code,
208 int system_code) { 208 int system_code) {
209 key_error_cb_.Run(key_system, session_id, error_code, system_code); 209 key_error_cb_.Run(session_id, error_code, system_code);
210 } 210 }
211 211
212 void ProxyDecryptor::KeyMessage(const std::string& key_system, 212 void ProxyDecryptor::KeyMessage(const std::string& session_id,
213 const std::string& session_id,
214 const std::string& message, 213 const std::string& message,
215 const std::string& default_url) { 214 const std::string& default_url) {
216 key_message_cb_.Run(key_system, session_id, message, default_url); 215 key_message_cb_.Run(session_id, message, default_url);
217 } 216 }
218 217
219 void ProxyDecryptor::NeedKey(const std::string& key_system, 218 void ProxyDecryptor::NeedKey(const std::string& session_id,
220 const std::string& session_id,
221 const std::string& type, 219 const std::string& type,
222 scoped_ptr<uint8[]> init_data, 220 scoped_ptr<uint8[]> init_data,
223 int init_data_size) { 221 int init_data_size) {
224 need_key_cb_.Run(key_system, session_id, type, 222 need_key_cb_.Run(session_id, type, init_data.Pass(), init_data_size);
225 init_data.Pass(), init_data_size);
226 } 223 }
227 224
228 } // namespace webkit_media 225 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698