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

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

Issue 17381007: EME: ProxyDecryptor creates MediaKeys instead of Decryptor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 key_error_cb_(key_error_cb), 63 key_error_cb_(key_error_cb),
64 key_message_cb_(key_message_cb), 64 key_message_cb_(key_message_cb),
65 need_key_cb_(need_key_cb), 65 need_key_cb_(need_key_cb),
66 weak_ptr_factory_(this) { 66 weak_ptr_factory_(this) {
67 } 67 }
68 68
69 ProxyDecryptor::~ProxyDecryptor() { 69 ProxyDecryptor::~ProxyDecryptor() {
70 // Destroy the decryptor explicitly before destroying the plugin. 70 // Destroy the decryptor explicitly before destroying the plugin.
71 { 71 {
72 base::AutoLock auto_lock(lock_); 72 base::AutoLock auto_lock(lock_);
73 decryptor_.reset(); 73 media_keys_.reset();
74 } 74 }
75 } 75 }
76 76
77 // TODO(xhwang): Support multiple decryptor notification request (e.g. from 77 // TODO(xhwang): Support multiple decryptor notification request (e.g. from
78 // video and audio decoders). The current implementation is okay for the current 78 // video and audio decoders). The current implementation is okay for the current
79 // media pipeline since we initialize audio and video decoders in sequence. 79 // media pipeline since we initialize audio and video decoders in sequence.
80 // But ProxyDecryptor should not depend on media pipeline's implementation 80 // But ProxyDecryptor should not depend on media pipeline's implementation
81 // detail. 81 // detail.
82 void ProxyDecryptor::SetDecryptorReadyCB( 82 void ProxyDecryptor::SetDecryptorReadyCB(
83 const media::DecryptorReadyCB& decryptor_ready_cb) { 83 const media::DecryptorReadyCB& decryptor_ready_cb) {
84 base::AutoLock auto_lock(lock_); 84 base::AutoLock auto_lock(lock_);
85 85
86 // Cancels the previous decryptor request. 86 // Cancels the previous decryptor request.
87 if (decryptor_ready_cb.is_null()) { 87 if (decryptor_ready_cb.is_null()) {
88 if (!decryptor_ready_cb_.is_null()) 88 if (!decryptor_ready_cb_.is_null())
89 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL); 89 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL);
90 return; 90 return;
91 } 91 }
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 (media_keys_) {
96 decryptor_ready_cb.Run(decryptor_.get()); 96 decryptor_ready_cb.Run(media_keys_->GetDecryptor());
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::GenerateKeyRequest(const std::string& key_system,
103 const std::string& type, 103 const std::string& type,
104 const uint8* init_data, 104 const uint8* init_data,
105 int init_data_length) { 105 int init_data_length) {
106 // We do not support run-time switching of decryptors. GenerateKeyRequest() 106 // We do not support run-time switching of decryptors. GenerateKeyRequest()
107 // only creates a new decryptor when |decryptor_| is not initialized. 107 // only creates a new decryptor when |decryptor_| is not initialized.
108 DVLOG(1) << "GenerateKeyRequest: key_system = " << key_system; 108 DVLOG(1) << "GenerateKeyRequest: key_system = " << key_system;
109 109
110 base::AutoLock auto_lock(lock_); 110 base::AutoLock auto_lock(lock_);
111 111
112 if (!decryptor_) { 112 if (!media_keys_) {
113 decryptor_ = CreateDecryptor(key_system); 113 media_keys_ = CreateMediaKeys(key_system);
114 if (!decryptor_) { 114 if (!media_keys_) {
115 key_error_cb_.Run( 115 key_error_cb_.Run(
116 key_system, std::string(), media::MediaKeys::kClientError, 0); 116 key_system, std::string(), media::MediaKeys::kClientError, 0);
117 return false; 117 return false;
118 } 118 }
119 } 119 }
120 120
121 if (!decryptor_->GetMediaKeys()->GenerateKeyRequest( 121 if (!media_keys_->GenerateKeyRequest(
122 key_system, type, init_data, init_data_length)) { 122 key_system, type, init_data, init_data_length)) {
123 decryptor_.reset(); 123 media_keys_.reset();
124 return false; 124 return false;
125 } 125 }
126 126
127 if (!decryptor_ready_cb_.is_null()) 127 if (!decryptor_ready_cb_.is_null())
128 base::ResetAndReturn(&decryptor_ready_cb_).Run(decryptor_.get()); 128 base::ResetAndReturn(&decryptor_ready_cb_).Run(media_keys_->GetDecryptor());
129 129
130 return true; 130 return true;
131 } 131 }
132 132
133 void ProxyDecryptor::AddKey(const std::string& key_system, 133 void ProxyDecryptor::AddKey(const std::string& key_system,
134 const uint8* key, 134 const uint8* key,
135 int key_length, 135 int key_length,
136 const uint8* init_data, 136 const uint8* init_data,
137 int init_data_length, 137 int init_data_length,
138 const std::string& session_id) { 138 const std::string& session_id) {
139 DVLOG(1) << "AddKey()"; 139 DVLOG(1) << "AddKey()";
140 140
141 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. 141 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called.
142 decryptor_->GetMediaKeys()->AddKey( 142 media_keys_->AddKey(
143 key_system, key, key_length, init_data, init_data_length, session_id); 143 key_system, key, key_length, init_data, init_data_length, session_id);
144 } 144 }
145 145
146 void ProxyDecryptor::CancelKeyRequest(const std::string& key_system, 146 void ProxyDecryptor::CancelKeyRequest(const std::string& key_system,
147 const std::string& session_id) { 147 const std::string& session_id) {
148 DVLOG(1) << "CancelKeyRequest()"; 148 DVLOG(1) << "CancelKeyRequest()";
149 149
150 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. 150 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called.
151 decryptor_->GetMediaKeys()->CancelKeyRequest(key_system, session_id); 151 media_keys_->CancelKeyRequest(key_system, session_id);
152 } 152 }
153 153
154 #if defined(ENABLE_PEPPER_CDMS) 154 #if defined(ENABLE_PEPPER_CDMS)
155 scoped_ptr<media::Decryptor> ProxyDecryptor::CreatePpapiDecryptor( 155 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreatePpapiDecryptor(
156 const std::string& key_system) { 156 const std::string& key_system) {
157 DCHECK(web_media_player_client_); 157 DCHECK(web_media_player_client_);
158 DCHECK(web_frame_); 158 DCHECK(web_frame_);
159 159
160 std::string plugin_type = GetPepperType(key_system); 160 std::string plugin_type = GetPepperType(key_system);
161 DCHECK(!plugin_type.empty()); 161 DCHECK(!plugin_type.empty());
162 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance = 162 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance =
163 CreateHelperPlugin(plugin_type, web_media_player_client_, web_frame_); 163 CreateHelperPlugin(plugin_type, web_media_player_client_, web_frame_);
164 if (!plugin_instance.get()) { 164 if (!plugin_instance.get()) {
165 DVLOG(1) << "ProxyDecryptor: plugin instance creation failed."; 165 DVLOG(1) << "ProxyDecryptor: plugin instance creation failed.";
166 return scoped_ptr<media::Decryptor>(); 166 return scoped_ptr<media::MediaKeys>();
167 } 167 }
168 168
169 // The new object will call destroy_plugin_cb to destroy Helper Plugin. 169 // The new object will call destroy_plugin_cb to destroy Helper Plugin.
170 return scoped_ptr<media::Decryptor>(new PpapiDecryptor( 170 return scoped_ptr<media::MediaKeys>(new PpapiDecryptor(
171 plugin_instance, 171 plugin_instance,
172 base::Bind(&ProxyDecryptor::KeyAdded, weak_ptr_factory_.GetWeakPtr()), 172 base::Bind(&ProxyDecryptor::KeyAdded, weak_ptr_factory_.GetWeakPtr()),
173 base::Bind(&ProxyDecryptor::KeyError, weak_ptr_factory_.GetWeakPtr()), 173 base::Bind(&ProxyDecryptor::KeyError, weak_ptr_factory_.GetWeakPtr()),
174 base::Bind(&ProxyDecryptor::KeyMessage, weak_ptr_factory_.GetWeakPtr()), 174 base::Bind(&ProxyDecryptor::KeyMessage, weak_ptr_factory_.GetWeakPtr()),
175 base::Bind(&ProxyDecryptor::NeedKey, weak_ptr_factory_.GetWeakPtr()), 175 base::Bind(&ProxyDecryptor::NeedKey, weak_ptr_factory_.GetWeakPtr()),
176 base::Bind(&ProxyDecryptor::DestroyHelperPlugin, 176 base::Bind(&ProxyDecryptor::DestroyHelperPlugin,
177 weak_ptr_factory_.GetWeakPtr()))); 177 weak_ptr_factory_.GetWeakPtr())));
178 } 178 }
179 #endif // defined(ENABLE_PEPPER_CDMS) 179 #endif // defined(ENABLE_PEPPER_CDMS)
180 180
181 scoped_ptr<media::Decryptor> ProxyDecryptor::CreateDecryptor( 181 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys(
182 const std::string& key_system) { 182 const std::string& key_system) {
183 if (CanUseAesDecryptor(key_system)) 183 if (CanUseAesDecryptor(key_system))
184 return scoped_ptr<media::Decryptor>(new media::AesDecryptor( 184 return scoped_ptr<media::MediaKeys>(new media::AesDecryptor(
185 base::Bind(&ProxyDecryptor::KeyAdded, weak_ptr_factory_.GetWeakPtr()), 185 base::Bind(&ProxyDecryptor::KeyAdded, weak_ptr_factory_.GetWeakPtr()),
186 base::Bind(&ProxyDecryptor::KeyError, weak_ptr_factory_.GetWeakPtr()), 186 base::Bind(&ProxyDecryptor::KeyError, weak_ptr_factory_.GetWeakPtr()),
187 base::Bind(&ProxyDecryptor::KeyMessage, weak_ptr_factory_.GetWeakPtr()), 187 base::Bind(&ProxyDecryptor::KeyMessage, weak_ptr_factory_.GetWeakPtr()),
188 base::Bind(&ProxyDecryptor::NeedKey, weak_ptr_factory_.GetWeakPtr()))); 188 base::Bind(&ProxyDecryptor::NeedKey, weak_ptr_factory_.GetWeakPtr())));
189 189
190 #if defined(ENABLE_PEPPER_CDMS) 190 #if defined(ENABLE_PEPPER_CDMS)
191 // We only support AesDecryptor and PpapiDecryptor. So if we cannot 191 // We only support AesDecryptor and PpapiDecryptor. So if we cannot
192 // use the AesDecryptor, then we'll try to create a PpapiDecryptor for given 192 // use the AesDecryptor, then we'll try to create a PpapiDecryptor for given
193 // |key_system|. 193 // |key_system|.
194 return CreatePpapiDecryptor(key_system); 194 return CreatePpapiDecryptor(key_system);
195 #else 195 #else
196 return scoped_ptr<media::Decryptor>(); 196 return scoped_ptr<media::MediaKeys>();
197 #endif // defined(ENABLE_PEPPER_CDMS) 197 #endif // defined(ENABLE_PEPPER_CDMS)
198 } 198 }
199 199
200 void ProxyDecryptor::KeyAdded(const std::string& key_system, 200 void ProxyDecryptor::KeyAdded(const std::string& key_system,
201 const std::string& session_id) { 201 const std::string& session_id) {
202 key_added_cb_.Run(key_system, session_id); 202 key_added_cb_.Run(key_system, session_id);
203 } 203 }
204 204
205 void ProxyDecryptor::KeyError(const std::string& key_system, 205 void ProxyDecryptor::KeyError(const std::string& key_system,
206 const std::string& session_id, 206 const std::string& session_id,
(...skipping 12 matching lines...) Expand all
219 void ProxyDecryptor::NeedKey(const std::string& key_system, 219 void ProxyDecryptor::NeedKey(const std::string& key_system,
220 const std::string& session_id, 220 const std::string& session_id,
221 const std::string& type, 221 const std::string& type,
222 scoped_ptr<uint8[]> init_data, 222 scoped_ptr<uint8[]> init_data,
223 int init_data_size) { 223 int init_data_size) {
224 need_key_cb_.Run(key_system, session_id, type, 224 need_key_cb_.Run(key_system, session_id, type,
225 init_data.Pass(), init_data_size); 225 init_data.Pass(), init_data_size);
226 } 226 }
227 227
228 } // namespace webkit_media 228 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698