OLD | NEW |
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_); | 40 DCHECK(client_); |
36 DCHECK(plugin_instance_); | 41 DCHECK(plugin_instance_); |
37 } | 42 } |
38 | 43 |
39 PpapiDecryptor::~PpapiDecryptor() { | 44 PpapiDecryptor::~PpapiDecryptor() { |
40 if (plugin_cdm_delegate_) | |
41 plugin_cdm_delegate_->set_decrypt_client(NULL); | |
42 plugin_cdm_delegate_ = NULL; | 45 plugin_cdm_delegate_ = NULL; |
43 plugin_instance_ = NULL; | 46 plugin_instance_ = NULL; |
44 } | 47 } |
45 | 48 |
46 bool PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, | 49 bool PpapiDecryptor::GenerateKeyRequest(const std::string& key_system, |
47 const std::string& type, | 50 const std::string& type, |
48 const uint8* init_data, | 51 const uint8* init_data, |
49 int init_data_length) { | 52 int init_data_length) { |
50 DVLOG(2) << "GenerateKeyRequest()"; | 53 DVLOG(2) << "GenerateKeyRequest()"; |
51 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 54 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
52 | 55 |
53 if (!plugin_cdm_delegate_) { | 56 if (!plugin_cdm_delegate_) { |
54 plugin_cdm_delegate_ = plugin_instance_->GetContentDecryptorDelegate(); | 57 plugin_cdm_delegate_ = plugin_instance_->GetContentDecryptorDelegate(); |
55 if (!plugin_cdm_delegate_) { | 58 if (!plugin_cdm_delegate_) { |
56 DVLOG(1) << "PpapiDecryptor: plugin cdm delegate creation failed."; | 59 DVLOG(1) << "PpapiDecryptor: plugin cdm delegate creation failed."; |
57 return false; | 60 return false; |
58 } | 61 } |
59 plugin_cdm_delegate_->set_decrypt_client(client_); | 62 plugin_cdm_delegate_->SetKeyEventCallbacks( |
| 63 base::Bind(&PpapiDecryptor::KeyAdded, weak_this_), |
| 64 base::Bind(&PpapiDecryptor::KeyError, weak_this_), |
| 65 base::Bind(&PpapiDecryptor::KeyMessage, weak_this_), |
| 66 base::Bind(&PpapiDecryptor::NeedKey, weak_this_)); |
60 } | 67 } |
61 | 68 |
62 if (!plugin_cdm_delegate_->GenerateKeyRequest( | 69 if (!plugin_cdm_delegate_->GenerateKeyRequest( |
63 key_system, type, init_data, init_data_length)) { | 70 key_system, type, init_data, init_data_length)) { |
64 ReportFailureToCallPlugin(key_system, ""); | 71 ReportFailureToCallPlugin(key_system, ""); |
65 return false; | 72 return false; |
66 } | 73 } |
67 | 74 |
68 return true; | 75 return true; |
69 } | 76 } |
70 | 77 |
71 void PpapiDecryptor::AddKey(const std::string& key_system, | 78 void PpapiDecryptor::AddKey(const std::string& key_system, |
72 const uint8* key, | 79 const uint8* key, |
73 int key_length, | 80 int key_length, |
74 const uint8* init_data, | 81 const uint8* init_data, |
75 int init_data_length, | 82 int init_data_length, |
76 const std::string& session_id) { | 83 const std::string& session_id) { |
77 DVLOG(2) << "AddKey()"; | 84 DVLOG(2) << "AddKey()"; |
78 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 85 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
79 | 86 |
80 if (!plugin_cdm_delegate_->AddKey( | 87 if (!plugin_cdm_delegate_->AddKey( |
81 session_id, key, key_length, init_data, init_data_length)) { | 88 session_id, key, key_length, init_data, init_data_length)) { |
82 ReportFailureToCallPlugin(key_system, session_id); | 89 ReportFailureToCallPlugin(key_system, session_id); |
83 } | 90 } |
84 | 91 |
85 if (!audio_key_added_cb_.is_null()) | 92 if (!new_audio_key_cb_.is_null()) |
86 audio_key_added_cb_.Run(); | 93 new_audio_key_cb_.Run(); |
87 | 94 |
88 if (!video_key_added_cb_.is_null()) | 95 if (!new_video_key_cb_.is_null()) |
89 video_key_added_cb_.Run(); | 96 new_video_key_cb_.Run(); |
90 } | 97 } |
91 | 98 |
92 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, | 99 void PpapiDecryptor::CancelKeyRequest(const std::string& key_system, |
93 const std::string& session_id) { | 100 const std::string& session_id) { |
94 DVLOG(2) << "CancelKeyRequest()"; | 101 DVLOG(2) << "CancelKeyRequest()"; |
95 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); | 102 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
96 | 103 |
97 if (!plugin_cdm_delegate_->CancelKeyRequest(session_id)) | 104 if (!plugin_cdm_delegate_->CancelKeyRequest(session_id)) |
98 ReportFailureToCallPlugin(key_system, session_id); | 105 ReportFailureToCallPlugin(key_system, session_id); |
99 } | 106 } |
100 | 107 |
101 void PpapiDecryptor::RegisterKeyAddedCB(StreamType stream_type, | 108 void PpapiDecryptor::RegisterNewKeyCB(StreamType stream_type, |
102 const KeyAddedCB& key_added_cb) { | 109 const NewKeyCB& new_key_cb) { |
103 switch (stream_type) { | 110 switch (stream_type) { |
104 case kAudio: | 111 case kAudio: |
105 audio_key_added_cb_ = key_added_cb; | 112 new_audio_key_cb_ = new_key_cb; |
106 break; | 113 break; |
107 case kVideo: | 114 case kVideo: |
108 video_key_added_cb_ = key_added_cb; | 115 new_video_key_cb_ = new_key_cb; |
109 break; | 116 break; |
110 default: | 117 default: |
111 NOTREACHED(); | 118 NOTREACHED(); |
112 } | 119 } |
113 } | 120 } |
114 | 121 |
115 void PpapiDecryptor::Decrypt( | 122 void PpapiDecryptor::Decrypt( |
116 StreamType stream_type, | 123 StreamType stream_type, |
117 const scoped_refptr<media::DecoderBuffer>& encrypted, | 124 const scoped_refptr<media::DecoderBuffer>& encrypted, |
118 const DecryptCB& decrypt_cb) { | 125 const DecryptCB& decrypt_cb) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 return; | 232 return; |
226 } | 233 } |
227 | 234 |
228 DVLOG(2) << "DeinitializeDecoder() - stream_type: " << stream_type; | 235 DVLOG(2) << "DeinitializeDecoder() - stream_type: " << stream_type; |
229 plugin_cdm_delegate_->DeinitializeDecoder(stream_type); | 236 plugin_cdm_delegate_->DeinitializeDecoder(stream_type); |
230 } | 237 } |
231 | 238 |
232 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, | 239 void PpapiDecryptor::ReportFailureToCallPlugin(const std::string& key_system, |
233 const std::string& session_id) { | 240 const std::string& session_id) { |
234 DVLOG(1) << "Failed to call plugin."; | 241 DVLOG(1) << "Failed to call plugin."; |
235 client_->KeyError(key_system, session_id, kUnknownError, 0); | 242 key_error_cb_.Run(key_system, session_id, kUnknownError, 0); |
236 } | 243 } |
237 | 244 |
238 void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type, | 245 void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type, |
239 bool success) { | 246 bool success) { |
240 switch (stream_type) { | 247 switch (stream_type) { |
241 case kAudio: | 248 case kAudio: |
242 DCHECK(!audio_decoder_init_cb_.is_null()); | 249 DCHECK(!audio_decoder_init_cb_.is_null()); |
243 base::ResetAndReturn(&audio_decoder_init_cb_).Run(success); | 250 base::ResetAndReturn(&audio_decoder_init_cb_).Run(success); |
244 break; | 251 break; |
245 case kVideo: | 252 case kVideo: |
246 DCHECK(!video_decoder_init_cb_.is_null()); | 253 DCHECK(!video_decoder_init_cb_.is_null()); |
247 base::ResetAndReturn(&video_decoder_init_cb_).Run(success); | 254 base::ResetAndReturn(&video_decoder_init_cb_).Run(success); |
248 break; | 255 break; |
249 default: | 256 default: |
250 NOTREACHED(); | 257 NOTREACHED(); |
251 } | 258 } |
252 } | 259 } |
253 | 260 |
| 261 void PpapiDecryptor::KeyAdded(const std::string& key_system, |
| 262 const std::string& session_id) { |
| 263 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 264 key_added_cb_.Run(key_system, session_id); |
| 265 } |
| 266 |
| 267 void PpapiDecryptor::KeyError(const std::string& key_system, |
| 268 const std::string& session_id, |
| 269 media::Decryptor::KeyError error_code, |
| 270 int system_code) { |
| 271 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 272 key_error_cb_.Run(key_system, session_id, error_code, system_code); |
| 273 } |
| 274 |
| 275 void PpapiDecryptor::KeyMessage(const std::string& key_system, |
| 276 const std::string& session_id, |
| 277 const std::string& message, |
| 278 const std::string& default_url) { |
| 279 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 280 key_message_cb_.Run(key_system, session_id, message, default_url); |
| 281 } |
| 282 |
| 283 void PpapiDecryptor::NeedKey(const std::string& key_system, |
| 284 const std::string& session_id, |
| 285 const std::string& type, |
| 286 scoped_array<uint8> init_data, |
| 287 int init_data_size) { |
| 288 DCHECK(render_loop_proxy_->BelongsToCurrentThread()); |
| 289 need_key_cb_.Run(key_system, session_id, type, |
| 290 init_data.Pass(), init_data_size); |
| 291 } |
| 292 |
254 } // namespace webkit_media | 293 } // namespace webkit_media |
OLD | NEW |