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

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

Issue 17289006: Separate CDM initialization from GenerateKeyRequest & remove key_system parameters. (Closed) Base URL: master
Patch Set: rebase only 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/ppapi_decryptor.h" 5 #include "webkit/renderer/media/crypto/ppapi_decryptor.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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/message_loop/message_loop_proxy.h" 14 #include "base/message_loop/message_loop_proxy.h"
15 #include "media/base/audio_decoder_config.h" 15 #include "media/base/audio_decoder_config.h"
16 #include "media/base/data_buffer.h" 16 #include "media/base/data_buffer.h"
17 #include "media/base/decoder_buffer.h" 17 #include "media/base/decoder_buffer.h"
18 #include "media/base/video_decoder_config.h" 18 #include "media/base/video_decoder_config.h"
19 #include "media/base/video_frame.h" 19 #include "media/base/video_frame.h"
20 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" 20 #include "webkit/plugins/ppapi/content_decryptor_delegate.h"
21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
22 #include "webkit/renderer/media/crypto/key_systems.h"
23 22
24 namespace webkit_media { 23 namespace webkit_media {
25 24
25 scoped_ptr<webkit_media::PpapiDecryptor> PpapiDecryptor::Create(
26 const std::string& key_system,
27 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance,
28 const media::KeyAddedCB& key_added_cb,
29 const media::KeyErrorCB& key_error_cb,
30 const media::KeyMessageCB& key_message_cb,
31 const media::NeedKeyCB& need_key_cb,
32 const base::Closure& destroy_plugin_cb) {
33 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate =
34 plugin_instance->GetContentDecryptorDelegate();
35 if (!plugin_cdm_delegate) {
36 DVLOG(1) << "PpapiDecryptor: plugin cdm delegate creation failed.";
37 return scoped_ptr<webkit_media::PpapiDecryptor>();
38 }
39
40 plugin_cdm_delegate->Initialize(key_system);
41
42 return scoped_ptr<webkit_media::PpapiDecryptor>(
43 new PpapiDecryptor(plugin_instance,
44 plugin_cdm_delegate,
45 key_added_cb,
46 key_error_cb,
47 key_message_cb,
48 need_key_cb,
49 destroy_plugin_cb));
50 }
51
26 PpapiDecryptor::PpapiDecryptor( 52 PpapiDecryptor::PpapiDecryptor(
27 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance, 53 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance,
54 webkit::ppapi::ContentDecryptorDelegate* plugin_cdm_delegate,
28 const media::KeyAddedCB& key_added_cb, 55 const media::KeyAddedCB& key_added_cb,
29 const media::KeyErrorCB& key_error_cb, 56 const media::KeyErrorCB& key_error_cb,
30 const media::KeyMessageCB& key_message_cb, 57 const media::KeyMessageCB& key_message_cb,
31 const media::NeedKeyCB& need_key_cb, 58 const media::NeedKeyCB& need_key_cb,
32 const base::Closure& destroy_plugin_cb) 59 const base::Closure& destroy_plugin_cb)
33 : plugin_instance_(plugin_instance), 60 : plugin_instance_(plugin_instance),
61 plugin_cdm_delegate_(plugin_cdm_delegate),
34 key_added_cb_(key_added_cb), 62 key_added_cb_(key_added_cb),
35 key_error_cb_(key_error_cb), 63 key_error_cb_(key_error_cb),
36 key_message_cb_(key_message_cb), 64 key_message_cb_(key_message_cb),
37 need_key_cb_(need_key_cb), 65 need_key_cb_(need_key_cb),
38 destroy_plugin_cb_(destroy_plugin_cb), 66 destroy_plugin_cb_(destroy_plugin_cb),
39 plugin_cdm_delegate_(NULL),
40 render_loop_proxy_(base::MessageLoopProxy::current()), 67 render_loop_proxy_(base::MessageLoopProxy::current()),
41 weak_ptr_factory_(this), 68 weak_ptr_factory_(this),
42 weak_this_(weak_ptr_factory_.GetWeakPtr()) { 69 weak_this_(weak_ptr_factory_.GetWeakPtr()) {
43 DCHECK(plugin_instance_.get()); 70 DCHECK(plugin_instance_.get());
71
72 plugin_cdm_delegate_->SetKeyEventCallbacks(
73 base::Bind(&PpapiDecryptor::KeyAdded, weak_this_),
74 base::Bind(&PpapiDecryptor::KeyError, weak_this_),
75 base::Bind(&PpapiDecryptor::KeyMessage, weak_this_),
76 base::Bind(&PpapiDecryptor::NeedKey, weak_this_));
44 } 77 }
45 78
46 PpapiDecryptor::~PpapiDecryptor() { 79 PpapiDecryptor::~PpapiDecryptor() {
47 plugin_cdm_delegate_ = NULL; 80 plugin_cdm_delegate_ = NULL;
48 plugin_instance_ = NULL; 81 plugin_instance_ = NULL;
49 destroy_plugin_cb_.Run(); 82 destroy_plugin_cb_.Run();
50 } 83 }
51 84
52 bool PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, 85 bool PpapiDecryptor::GenerateKeyRequest(const std::string& type,
53 const std::string& type,
54 const uint8* init_data, 86 const uint8* init_data,
55 int init_data_length) { 87 int init_data_length) {
56 DVLOG(2) << "GenerateKeyRequest()"; 88 DVLOG(2) << "GenerateKeyRequest()";
57 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 89 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
58 90 DCHECK(plugin_cdm_delegate_);
59 if (!plugin_cdm_delegate_) {
60 plugin_cdm_delegate_ = plugin_instance_->GetContentDecryptorDelegate();
61 if (!plugin_cdm_delegate_) {
62 DVLOG(1) << "PpapiDecryptor: plugin cdm delegate creation failed.";
63 return false;
64 }
65 plugin_cdm_delegate_->SetKeyEventCallbacks(
66 base::Bind(&PpapiDecryptor::KeyAdded, weak_this_),
67 base::Bind(&PpapiDecryptor::KeyError, weak_this_),
68 base::Bind(&PpapiDecryptor::KeyMessage, weak_this_),
69 base::Bind(&PpapiDecryptor::NeedKey, weak_this_));
70 }
71 91
72 if (!plugin_cdm_delegate_->GenerateKeyRequest( 92 if (!plugin_cdm_delegate_->GenerateKeyRequest(
73 key_system, type, init_data, init_data_length)) { 93 type, init_data, init_data_length)) {
74 ReportFailureToCallPlugin(key_system, std::string()); 94 ReportFailureToCallPlugin(std::string());
75 return false; 95 return false;
76 } 96 }
77 97
78 return true; 98 return true;
79 } 99 }
80 100
81 void PpapiDecryptor::AddKey(const std::string& key_system, 101 void PpapiDecryptor::AddKey(const uint8* key,
82 const uint8* key,
83 int key_length, 102 int key_length,
84 const uint8* init_data, 103 const uint8* init_data,
85 int init_data_length, 104 int init_data_length,
86 const std::string& session_id) { 105 const std::string& session_id) {
87 DVLOG(2) << "AddKey()"; 106 DVLOG(2) << "AddKey()";
88 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 107 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
89 108
90 if (!plugin_cdm_delegate_->AddKey( 109 if (!plugin_cdm_delegate_->AddKey(
91 session_id, key, key_length, init_data, init_data_length)) { 110 session_id, key, key_length, init_data, init_data_length)) {
92 ReportFailureToCallPlugin(key_system, session_id); 111 ReportFailureToCallPlugin(session_id);
93 } 112 }
94 113
95 if (!new_audio_key_cb_.is_null()) 114 if (!new_audio_key_cb_.is_null())
96 new_audio_key_cb_.Run(); 115 new_audio_key_cb_.Run();
97 116
98 if (!new_video_key_cb_.is_null()) 117 if (!new_video_key_cb_.is_null())
99 new_video_key_cb_.Run(); 118 new_video_key_cb_.Run();
100 } 119 }
101 120
102 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, 121 void PpapiDecryptor::CancelKeyRequest(const std::string& session_id) {
103 const std::string& session_id) {
104 DVLOG(2) << "CancelKeyRequest()"; 122 DVLOG(2) << "CancelKeyRequest()";
105 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 123 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
106 124
107 if (!plugin_cdm_delegate_->CancelKeyRequest(session_id)) 125 if (!plugin_cdm_delegate_->CancelKeyRequest(session_id))
108 ReportFailureToCallPlugin(key_system, session_id); 126 ReportFailureToCallPlugin(session_id);
109 } 127 }
110 128
111 media::MediaKeys* PpapiDecryptor::GetMediaKeys() { 129 media::MediaKeys* PpapiDecryptor::GetMediaKeys() {
112 return this; 130 return this;
113 } 131 }
114 132
115 void PpapiDecryptor::RegisterNewKeyCB(StreamType stream_type, 133 void PpapiDecryptor::RegisterNewKeyCB(StreamType stream_type,
116 const NewKeyCB& new_key_cb) { 134 const NewKeyCB& new_key_cb) {
117 switch (stream_type) { 135 switch (stream_type) {
118 case kAudio: 136 case kAudio:
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 if (!render_loop_proxy_->BelongsToCurrentThread()) { 252 if (!render_loop_proxy_->BelongsToCurrentThread()) {
235 render_loop_proxy_->PostTask(FROM_HERE, base::Bind( 253 render_loop_proxy_->PostTask(FROM_HERE, base::Bind(
236 &PpapiDecryptor::DeinitializeDecoder, weak_this_, stream_type)); 254 &PpapiDecryptor::DeinitializeDecoder, weak_this_, stream_type));
237 return; 255 return;
238 } 256 }
239 257
240 DVLOG(2) << "DeinitializeDecoder() - stream_type: " << stream_type; 258 DVLOG(2) << "DeinitializeDecoder() - stream_type: " << stream_type;
241 plugin_cdm_delegate_->DeinitializeDecoder(stream_type); 259 plugin_cdm_delegate_->DeinitializeDecoder(stream_type);
242 } 260 }
243 261
244 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, 262 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& session_id) {
245 const std::string& session_id) {
246 DVLOG(1) << "Failed to call plugin."; 263 DVLOG(1) << "Failed to call plugin.";
247 key_error_cb_.Run(key_system, session_id, kUnknownError, 0); 264 key_error_cb_.Run(session_id, kUnknownError, 0);
248 } 265 }
249 266
250 void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type, 267 void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type,
251 bool success) { 268 bool success) {
252 switch (stream_type) { 269 switch (stream_type) {
253 case kAudio: 270 case kAudio:
254 DCHECK(!audio_decoder_init_cb_.is_null()); 271 DCHECK(!audio_decoder_init_cb_.is_null());
255 base::ResetAndReturn(&audio_decoder_init_cb_).Run(success); 272 base::ResetAndReturn(&audio_decoder_init_cb_).Run(success);
256 break; 273 break;
257 case kVideo: 274 case kVideo:
258 DCHECK(!video_decoder_init_cb_.is_null()); 275 DCHECK(!video_decoder_init_cb_.is_null());
259 base::ResetAndReturn(&video_decoder_init_cb_).Run(success); 276 base::ResetAndReturn(&video_decoder_init_cb_).Run(success);
260 break; 277 break;
261 default: 278 default:
262 NOTREACHED(); 279 NOTREACHED();
263 } 280 }
264 } 281 }
265 282
266 void PpapiDecryptor::KeyAdded(const std::string& key_system, 283 void PpapiDecryptor::KeyAdded(const std::string& session_id) {
267 const std::string& session_id) {
268 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 284 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
269 key_added_cb_.Run(key_system, session_id); 285 key_added_cb_.Run(session_id);
270 } 286 }
271 287
272 void PpapiDecryptor::KeyError(const std::string& key_system, 288 void PpapiDecryptor::KeyError(const std::string& session_id,
273 const std::string& session_id,
274 media::MediaKeys::KeyError error_code, 289 media::MediaKeys::KeyError error_code,
275 int system_code) { 290 int system_code) {
276 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 291 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
277 key_error_cb_.Run(key_system, session_id, error_code, system_code); 292 key_error_cb_.Run(session_id, error_code, system_code);
278 } 293 }
279 294
280 void PpapiDecryptor::KeyMessage(const std::string& key_system, 295 void PpapiDecryptor::KeyMessage(const std::string& session_id,
281 const std::string& session_id,
282 const std::string& message, 296 const std::string& message,
283 const std::string& default_url) { 297 const std::string& default_url) {
284 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 298 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
285 key_message_cb_.Run(key_system, session_id, message, default_url); 299 key_message_cb_.Run(session_id, message, default_url);
286 } 300 }
287 301
288 void PpapiDecryptor::NeedKey(const std::string& key_system, 302 void PpapiDecryptor::NeedKey(const std::string& session_id,
289 const std::string& session_id,
290 const std::string& type, 303 const std::string& type,
291 scoped_ptr<uint8[]> init_data, 304 scoped_ptr<uint8[]> init_data,
292 int init_data_size) { 305 int init_data_size) {
293 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 306 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
294 need_key_cb_.Run(key_system, session_id, type, 307 need_key_cb_.Run(session_id, type, init_data.Pass(), init_data_size);
295 init_data.Pass(), init_data_size);
296 } 308 }
297 309
298 } // namespace webkit_media 310 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/renderer/media/crypto/ppapi_decryptor.h ('k') | webkit/renderer/media/crypto/proxy_decryptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698