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

Side by Side Diff: media/blink/encrypted_media_player_support.cc

Issue 1070853004: media: CdmFactory creates CDM (MediaKeys) asynchronously. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use ScopedVector Created 5 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "media/blink/encrypted_media_player_support.h" 5 #include "media/blink/encrypted_media_player_support.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 if (init_data_length == 16) 109 if (init_data_length == 16)
110 return EmeInitDataType::WEBM; 110 return EmeInitDataType::WEBM;
111 111
112 return EmeInitDataType::CENC; 112 return EmeInitDataType::CENC;
113 } 113 }
114 114
115 EncryptedMediaPlayerSupport::EncryptedMediaPlayerSupport( 115 EncryptedMediaPlayerSupport::EncryptedMediaPlayerSupport(
116 CdmFactory* cdm_factory, 116 CdmFactory* cdm_factory,
117 blink::WebMediaPlayerClient* client, 117 blink::WebMediaPlayerClient* client,
118 MediaPermission* media_permission, 118 MediaPermission* media_permission,
119 const SetCdmContextCB& set_cdm_context_cb) 119 const CdmContextReadyCB& cdm_context_ready_cb)
120 : cdm_factory_(cdm_factory), 120 : cdm_factory_(cdm_factory),
121 client_(client), 121 client_(client),
122 media_permission_(media_permission), 122 media_permission_(media_permission),
123 init_data_type_(EmeInitDataType::UNKNOWN), 123 init_data_type_(EmeInitDataType::UNKNOWN),
124 set_cdm_context_cb_(set_cdm_context_cb) { 124 cdm_context_ready_cb_(cdm_context_ready_cb) {
125 } 125 }
126 126
127 EncryptedMediaPlayerSupport::~EncryptedMediaPlayerSupport() { 127 EncryptedMediaPlayerSupport::~EncryptedMediaPlayerSupport() {
128 } 128 }
129 129
130 WebMediaPlayer::MediaKeyException 130 WebMediaPlayer::MediaKeyException
131 EncryptedMediaPlayerSupport::GenerateKeyRequest( 131 EncryptedMediaPlayerSupport::GenerateKeyRequest(
132 blink::WebLocalFrame* frame, 132 blink::WebLocalFrame* frame,
133 const WebString& key_system, 133 const WebString& key_system,
134 const unsigned char* init_data, 134 const unsigned char* init_data,
(...skipping 13 matching lines...) Expand all
148 148
149 WebMediaPlayer::MediaKeyException 149 WebMediaPlayer::MediaKeyException
150 EncryptedMediaPlayerSupport::GenerateKeyRequestInternal( 150 EncryptedMediaPlayerSupport::GenerateKeyRequestInternal(
151 blink::WebLocalFrame* frame, 151 blink::WebLocalFrame* frame,
152 const std::string& key_system, 152 const std::string& key_system,
153 const unsigned char* init_data, 153 const unsigned char* init_data,
154 unsigned init_data_length) { 154 unsigned init_data_length) {
155 if (!PrefixedIsSupportedConcreteKeySystem(key_system)) 155 if (!PrefixedIsSupportedConcreteKeySystem(key_system))
156 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 156 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
157 157
158 // We do not support run-time switching between key systems for now. 158 if (!proxy_decryptor_) {
159 if (current_key_system_.empty()) { 159 DCHECK(current_key_system_.empty());
160 if (!proxy_decryptor_) { 160 DCHECK(!cdm_context_ready_cb_.is_null());
161 proxy_decryptor_.reset(new ProxyDecryptor( 161 proxy_decryptor_.reset(new ProxyDecryptor(
162 media_permission_, 162 media_permission_,
163 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupport::OnKeyAdded), 163 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupport::OnKeyAdded),
164 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupport::OnKeyError), 164 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupport::OnKeyError),
165 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupport::OnKeyMessage))); 165 BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupport::OnKeyMessage)));
166 }
167 166
168 GURL security_origin(frame->document().securityOrigin().toString()); 167 GURL security_origin(frame->document().securityOrigin().toString());
168 proxy_decryptor_->CreateCdm(cdm_factory_, key_system, security_origin,
169 cdm_context_ready_cb_);
170 current_key_system_ = key_system;
171 }
169 172
170 if (!proxy_decryptor_->InitializeCDM(cdm_factory_, key_system, 173 // We do not support run-time switching between key systems for now.
171 security_origin)) { 174 DCHECK(!current_key_system_.empty());
172 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 175 if (key_system != current_key_system_)
173 }
174
175 if (proxy_decryptor_ && !set_cdm_context_cb_.is_null()) {
176 base::ResetAndReturn(&set_cdm_context_cb_)
177 .Run(proxy_decryptor_->GetCdmContext(),
178 base::Bind(&IgnoreCdmAttached));
179 }
180
181 current_key_system_ = key_system;
182 } else if (key_system != current_key_system_) {
183 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; 176 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
184 }
185 177
186 EmeInitDataType init_data_type = init_data_type_; 178 EmeInitDataType init_data_type = init_data_type_;
187 if (init_data_type == EmeInitDataType::UNKNOWN) 179 if (init_data_type == EmeInitDataType::UNKNOWN)
188 init_data_type = GuessInitDataType(init_data, init_data_length); 180 init_data_type = GuessInitDataType(init_data, init_data_length);
189 181
190 if (!proxy_decryptor_->GenerateKeyRequest(init_data_type, init_data, 182 proxy_decryptor_->GenerateKeyRequest(init_data_type, init_data,
191 init_data_length)) { 183 init_data_length);
192 current_key_system_.clear();
193 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
194 }
195 184
196 return WebMediaPlayer::MediaKeyExceptionNoError; 185 return WebMediaPlayer::MediaKeyExceptionNoError;
197 } 186 }
198 187
199 WebMediaPlayer::MediaKeyException EncryptedMediaPlayerSupport::AddKey( 188 WebMediaPlayer::MediaKeyException EncryptedMediaPlayerSupport::AddKey(
200 const WebString& key_system, 189 const WebString& key_system,
201 const unsigned char* key, 190 const unsigned char* key,
202 unsigned key_length, 191 unsigned key_length,
203 const unsigned char* init_data, 192 const unsigned char* init_data,
204 unsigned init_data_length, 193 unsigned init_data_length,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 316
328 client_->keyMessage( 317 client_->keyMessage(
329 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), 318 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)),
330 WebString::fromUTF8(session_id), 319 WebString::fromUTF8(session_id),
331 message.empty() ? NULL : &message[0], 320 message.empty() ? NULL : &message[0],
332 base::saturated_cast<unsigned int>(message.size()), 321 base::saturated_cast<unsigned int>(message.size()),
333 destination_url); 322 destination_url);
334 } 323 }
335 324
336 } // namespace media 325 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/encrypted_media_player_support.h ('k') | media/blink/webcontentdecryptionmodule_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698