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

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

Issue 11226019: Encrypted Media: Replace DecryptorClient with key event callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: tests updated; ready for review Created 8 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/media/crypto/ppapi_decryptor.h" 5 #include "webkit/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_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "media/base/audio_decoder_config.h" 15 #include "media/base/audio_decoder_config.h"
16 #include "media/base/decoder_buffer.h" 16 #include "media/base/decoder_buffer.h"
17 #include "media/base/decryptor_client.h"
18 #include "media/base/video_decoder_config.h" 17 #include "media/base/video_decoder_config.h"
19 #include "media/base/video_frame.h" 18 #include "media/base/video_frame.h"
20 #include "webkit/media/crypto/key_systems.h" 19 #include "webkit/media/crypto/key_systems.h"
21 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" 20 #include "webkit/plugins/ppapi/content_decryptor_delegate.h"
22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
23 22
24 namespace webkit_media { 23 namespace webkit_media {
25 24
26 PpapiDecryptor::PpapiDecryptor( 25 PpapiDecryptor::PpapiDecryptor(
27 media::DecryptorClient* client, 26 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance,
28 const scoped_refptr<webkit::ppapi::PluginInstance>& plugin_instance) 27 const media::KeyAddedCB& key_added_cb,
29 : client_(client), 28 const media::KeyErrorCB& key_error_cb,
30 plugin_instance_(plugin_instance), 29 const media::KeyMessageCB& key_message_cb,
30 const media::NeedKeyCB& need_key_cb)
31 : plugin_instance_(plugin_instance),
32 key_added_cb_(key_added_cb),
33 key_error_cb_(key_error_cb),
34 key_message_cb_(key_message_cb),
35 need_key_cb_(need_key_cb),
31 plugin_cdm_delegate_(NULL), 36 plugin_cdm_delegate_(NULL),
32 render_loop_proxy_(base::MessageLoopProxy::current()), 37 render_loop_proxy_(base::MessageLoopProxy::current()),
33 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 38 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
34 weak_this_(weak_ptr_factory_.GetWeakPtr()) { 39 weak_this_(weak_ptr_factory_.GetWeakPtr()) {
35 DCHECK(client_);
36 DCHECK(plugin_instance_); 40 DCHECK(plugin_instance_);
37 } 41 }
38 42
39 PpapiDecryptor::~PpapiDecryptor() { 43 PpapiDecryptor::~PpapiDecryptor() {
40 if (plugin_cdm_delegate_)
41 plugin_cdm_delegate_->set_decrypt_client(NULL);
42 plugin_cdm_delegate_ = NULL; 44 plugin_cdm_delegate_ = NULL;
43 plugin_instance_ = NULL; 45 plugin_instance_ = NULL;
44 } 46 }
45 47
46 bool PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, 48 bool PpapiDecryptor::GenerateKeyRequest(const std::string& key_system,
47 const std::string& type, 49 const std::string& type,
48 const uint8* init_data, 50 const uint8* init_data,
49 int init_data_length) { 51 int init_data_length) {
50 DVLOG(2) << "GenerateKeyRequest()"; 52 DVLOG(2) << "GenerateKeyRequest()";
51 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 53 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
52 54
53 if (!plugin_cdm_delegate_) { 55 if (!plugin_cdm_delegate_) {
54 plugin_cdm_delegate_ = plugin_instance_->GetContentDecryptorDelegate(); 56 plugin_cdm_delegate_ = plugin_instance_->GetContentDecryptorDelegate();
55 if (!plugin_cdm_delegate_) { 57 if (!plugin_cdm_delegate_) {
56 DVLOG(1) << "PpapiDecryptor: plugin cdm delegate creation failed."; 58 DVLOG(1) << "PpapiDecryptor: plugin cdm delegate creation failed.";
57 return false; 59 return false;
58 } 60 }
59 plugin_cdm_delegate_->set_decrypt_client(client_); 61 plugin_cdm_delegate_->SetKeyEventCallbacks(
62 base::Bind(&PpapiDecryptor::KeyAdded, weak_this_),
63 base::Bind(&PpapiDecryptor::KeyError, weak_this_),
64 base::Bind(&PpapiDecryptor::KeyMessage, weak_this_),
65 base::Bind(&PpapiDecryptor::NeedKey, weak_this_));
60 } 66 }
61 67
62 if (!plugin_cdm_delegate_->GenerateKeyRequest( 68 if (!plugin_cdm_delegate_->GenerateKeyRequest(
63 key_system, type, init_data, init_data_length)) { 69 key_system, type, init_data, init_data_length)) {
64 ReportFailureToCallPlugin(key_system, ""); 70 ReportFailureToCallPlugin(key_system, "");
65 return false; 71 return false;
66 } 72 }
67 73
68 return true; 74 return true;
69 } 75 }
70 76
71 void PpapiDecryptor::AddKey(const std::string& key_system, 77 void PpapiDecryptor::AddKey(const std::string& key_system,
72 const uint8* key, 78 const uint8* key,
73 int key_length, 79 int key_length,
74 const uint8* init_data, 80 const uint8* init_data,
75 int init_data_length, 81 int init_data_length,
76 const std::string& session_id) { 82 const std::string& session_id) {
77 DVLOG(2) << "AddKey()"; 83 DVLOG(2) << "AddKey()";
78 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 84 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
79 85
80 if (!plugin_cdm_delegate_->AddKey( 86 if (!plugin_cdm_delegate_->AddKey(
81 session_id, key, key_length, init_data, init_data_length)) { 87 session_id, key, key_length, init_data, init_data_length)) {
82 ReportFailureToCallPlugin(key_system, session_id); 88 ReportFailureToCallPlugin(key_system, session_id);
83 } 89 }
84 90
85 if (!audio_key_added_cb_.is_null()) 91 if (!new_audio_key_cb_.is_null())
86 audio_key_added_cb_.Run(); 92 new_audio_key_cb_.Run();
87 93
88 if (!video_key_added_cb_.is_null()) 94 if (!new_video_key_cb_.is_null())
89 video_key_added_cb_.Run(); 95 new_video_key_cb_.Run();
90 } 96 }
91 97
92 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, 98 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system,
93 const std::string& session_id) { 99 const std::string& session_id) {
94 DVLOG(2) << "CancelKeyRequest()"; 100 DVLOG(2) << "CancelKeyRequest()";
95 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); 101 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
96 102
97 if (!plugin_cdm_delegate_->CancelKeyRequest(session_id)) 103 if (!plugin_cdm_delegate_->CancelKeyRequest(session_id))
98 ReportFailureToCallPlugin(key_system, session_id); 104 ReportFailureToCallPlugin(key_system, session_id);
99 } 105 }
100 106
101 void PpapiDecryptor::RegisterKeyAddedCB(StreamType stream_type, 107 void PpapiDecryptor::RegisterNewKeyCB(StreamType stream_type,
102 const KeyAddedCB& key_added_cb) { 108 const NewKeyCB& new_key_cb) {
103 switch (stream_type) { 109 switch (stream_type) {
104 case kAudio: 110 case kAudio:
105 audio_key_added_cb_ = key_added_cb; 111 new_audio_key_cb_ = new_key_cb;
106 break; 112 break;
107 case kVideo: 113 case kVideo:
108 video_key_added_cb_ = key_added_cb; 114 new_video_key_cb_ = new_key_cb;
109 break; 115 break;
110 default: 116 default:
111 NOTREACHED(); 117 NOTREACHED();
112 } 118 }
113 } 119 }
114 120
115 void PpapiDecryptor::Decrypt( 121 void PpapiDecryptor::Decrypt(
116 StreamType stream_type, 122 StreamType stream_type,
117 const scoped_refptr<media::DecoderBuffer>& encrypted, 123 const scoped_refptr<media::DecoderBuffer>& encrypted,
118 const DecryptCB& decrypt_cb) { 124 const DecryptCB& decrypt_cb) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 return; 231 return;
226 } 232 }
227 233
228 DVLOG(2) << "DeinitializeDecoder() - stream_type: " << stream_type; 234 DVLOG(2) << "DeinitializeDecoder() - stream_type: " << stream_type;
229 plugin_cdm_delegate_->DeinitializeDecoder(stream_type); 235 plugin_cdm_delegate_->DeinitializeDecoder(stream_type);
230 } 236 }
231 237
232 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, 238 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system,
233 const std::string& session_id) { 239 const std::string& session_id) {
234 DVLOG(1) << "Failed to call plugin."; 240 DVLOG(1) << "Failed to call plugin.";
235 client_->KeyError(key_system, session_id, kUnknownError, 0); 241 key_error_cb_.Run(key_system, session_id, kUnknownError, 0);
236 } 242 }
237 243
238 void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type, 244 void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type,
239 bool success) { 245 bool success) {
240 switch (stream_type) { 246 switch (stream_type) {
241 case kAudio: 247 case kAudio:
242 DCHECK(!audio_decoder_init_cb_.is_null()); 248 DCHECK(!audio_decoder_init_cb_.is_null());
243 base::ResetAndReturn(&audio_decoder_init_cb_).Run(success); 249 base::ResetAndReturn(&audio_decoder_init_cb_).Run(success);
244 break; 250 break;
245 case kVideo: 251 case kVideo:
246 DCHECK(!video_decoder_init_cb_.is_null()); 252 DCHECK(!video_decoder_init_cb_.is_null());
247 base::ResetAndReturn(&video_decoder_init_cb_).Run(success); 253 base::ResetAndReturn(&video_decoder_init_cb_).Run(success);
248 break; 254 break;
249 default: 255 default:
250 NOTREACHED(); 256 NOTREACHED();
251 } 257 }
252 } 258 }
253 259
260 void PpapiDecryptor::KeyAdded(const std::string& key_system,
xhwang 2012/12/20 00:06:01 Now PpapiDecryptor is implementing these callbacks
261 const std::string& session_id) {
262 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
263 key_added_cb_.Run(key_system, session_id);
264 }
265
266 void PpapiDecryptor::KeyError(const std::string& key_system,
267 const std::string& session_id,
268 media::Decryptor::KeyError error_code,
269 int system_code) {
270 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
271 key_error_cb_.Run(key_system, session_id, error_code, system_code);
272 }
273
274 void PpapiDecryptor::KeyMessage(const std::string& key_system,
275 const std::string& session_id,
276 const std::string& message,
277 const std::string& default_url) {
278 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
279 key_message_cb_.Run(key_system, session_id, message, default_url);
280 }
281
282 void PpapiDecryptor::NeedKey(const std::string& key_system,
283 const std::string& session_id,
284 const std::string& type,
285 scoped_array<uint8> init_data,
286 int init_data_size) {
287 DCHECK(render_loop_proxy_->BelongsToCurrentThread());
288 need_key_cb_.Run(key_system, session_id, type,
289 init_data.Pass(), init_data_size);
290 }
291
254 } // namespace webkit_media 292 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698