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/plugins/ppapi/content_decryptor_delegate.h" | 5 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
11 #include "media/base/bind_to_loop.h" | 11 #include "media/base/bind_to_loop.h" |
12 #include "media/base/channel_layout.h" | 12 #include "media/base/channel_layout.h" |
13 #include "media/base/data_buffer.h" | 13 #include "media/base/data_buffer.h" |
14 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
15 #include "media/base/decryptor_client.h" | |
16 #include "media/base/video_decoder_config.h" | 15 #include "media/base/video_decoder_config.h" |
17 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
18 #include "media/base/video_util.h" | 17 #include "media/base/video_util.h" |
19 #include "ppapi/shared_impl/scoped_pp_resource.h" | 18 #include "ppapi/shared_impl/scoped_pp_resource.h" |
20 #include "ppapi/shared_impl/var.h" | 19 #include "ppapi/shared_impl/var.h" |
21 #include "ppapi/shared_impl/var_tracker.h" | 20 #include "ppapi/shared_impl/var_tracker.h" |
22 #include "ppapi/thunk/enter.h" | 21 #include "ppapi/thunk/enter.h" |
23 #include "ppapi/thunk/ppb_buffer_api.h" | 22 #include "ppapi/thunk/ppb_buffer_api.h" |
24 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
25 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 24 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 264 } |
266 } | 265 } |
267 | 266 |
268 } // namespace | 267 } // namespace |
269 | 268 |
270 ContentDecryptorDelegate::ContentDecryptorDelegate( | 269 ContentDecryptorDelegate::ContentDecryptorDelegate( |
271 PP_Instance pp_instance, | 270 PP_Instance pp_instance, |
272 const PPP_ContentDecryptor_Private* plugin_decryption_interface) | 271 const PPP_ContentDecryptor_Private* plugin_decryption_interface) |
273 : pp_instance_(pp_instance), | 272 : pp_instance_(pp_instance), |
274 plugin_decryption_interface_(plugin_decryption_interface), | 273 plugin_decryption_interface_(plugin_decryption_interface), |
275 decryptor_client_(NULL), | |
276 next_decryption_request_id_(1), | 274 next_decryption_request_id_(1), |
277 pending_audio_decrypt_request_id_(0), | 275 pending_audio_decrypt_request_id_(0), |
278 pending_video_decrypt_request_id_(0), | 276 pending_video_decrypt_request_id_(0), |
279 pending_audio_decoder_init_request_id_(0), | 277 pending_audio_decoder_init_request_id_(0), |
280 pending_video_decoder_init_request_id_(0), | 278 pending_video_decoder_init_request_id_(0), |
281 pending_audio_decode_request_id_(0), | 279 pending_audio_decode_request_id_(0), |
282 pending_video_decode_request_id_(0), | 280 pending_video_decode_request_id_(0), |
283 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 281 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
284 weak_this_(weak_ptr_factory_.GetWeakPtr()) { | 282 weak_this_(weak_ptr_factory_.GetWeakPtr()) { |
285 } | 283 } |
286 | 284 |
287 void ContentDecryptorDelegate::set_decrypt_client( | 285 void ContentDecryptorDelegate::SetKeyEventCallbacks( |
288 media::DecryptorClient* decryptor_client) { | 286 const media::KeyAddedCB& key_added_cb, |
289 decryptor_client_ = decryptor_client; | 287 const media::KeyErrorCB& key_error_cb, |
| 288 const media::KeyMessageCB& key_message_cb, |
| 289 const media::NeedKeyCB& need_key_cb) { |
| 290 key_added_cb_ = key_added_cb; |
| 291 key_error_cb_ = key_error_cb; |
| 292 key_message_cb_ = key_message_cb; |
| 293 need_key_cb_ = need_key_cb; |
290 } | 294 } |
291 | 295 |
292 bool ContentDecryptorDelegate::GenerateKeyRequest(const std::string& key_system, | 296 bool ContentDecryptorDelegate::GenerateKeyRequest(const std::string& key_system, |
293 const std::string& type, | 297 const std::string& type, |
294 const uint8* init_data, | 298 const uint8* init_data, |
295 int init_data_length) { | 299 int init_data_length) { |
296 if (key_system.empty()) | 300 if (key_system.empty()) |
297 return false; | 301 return false; |
298 | 302 |
299 PP_Var init_data_array = | 303 PP_Var init_data_array = |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 } | 634 } |
631 | 635 |
632 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, | 636 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, |
633 PP_Var session_id_var, | 637 PP_Var session_id_var, |
634 PP_Var init_data_var) { | 638 PP_Var init_data_var) { |
635 // TODO(tomfinegan): send the data to media stack. | 639 // TODO(tomfinegan): send the data to media stack. |
636 } | 640 } |
637 | 641 |
638 void ContentDecryptorDelegate::KeyAdded(PP_Var key_system_var, | 642 void ContentDecryptorDelegate::KeyAdded(PP_Var key_system_var, |
639 PP_Var session_id_var) { | 643 PP_Var session_id_var) { |
640 if (!decryptor_client_) | 644 if (key_added_cb_.is_null()) |
641 return; | 645 return; |
642 | 646 |
643 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 647 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
644 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 648 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
645 if (!key_system_string || !session_id_string) { | 649 if (!key_system_string || !session_id_string) { |
646 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); | 650 key_error_cb_.Run("", "", media::Decryptor::kUnknownError, 0); |
647 return; | 651 return; |
648 } | 652 } |
649 | 653 |
650 decryptor_client_->KeyAdded(key_system_string->value(), | 654 key_added_cb_.Run(key_system_string->value(), session_id_string->value()); |
651 session_id_string->value()); | |
652 } | 655 } |
653 | 656 |
654 void ContentDecryptorDelegate::KeyMessage(PP_Var key_system_var, | 657 void ContentDecryptorDelegate::KeyMessage(PP_Var key_system_var, |
655 PP_Var session_id_var, | 658 PP_Var session_id_var, |
656 PP_Var message_var, | 659 PP_Var message_var, |
657 PP_Var default_url_var) { | 660 PP_Var default_url_var) { |
658 if (!decryptor_client_) | 661 if (key_message_cb_.is_null()) |
659 return; | 662 return; |
660 | 663 |
661 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 664 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
662 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 665 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
663 | 666 |
664 ArrayBufferVar* message_array_buffer = | 667 ArrayBufferVar* message_array_buffer = |
665 ArrayBufferVar::FromPPVar(message_var); | 668 ArrayBufferVar::FromPPVar(message_var); |
666 | 669 |
667 std::string message; | 670 std::string message; |
668 if (message_array_buffer) { | 671 if (message_array_buffer) { |
669 const char* data = static_cast<const char*>(message_array_buffer->Map()); | 672 const char* data = static_cast<const char*>(message_array_buffer->Map()); |
670 message.assign(data, message_array_buffer->ByteLength()); | 673 message.assign(data, message_array_buffer->ByteLength()); |
671 } | 674 } |
672 | 675 |
673 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); | 676 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); |
674 | 677 |
675 if (!key_system_string || !session_id_string || !default_url_string) { | 678 if (!key_system_string || !session_id_string || !default_url_string) { |
676 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); | 679 key_error_cb_.Run("", "", media::Decryptor::kUnknownError, 0); |
677 return; | 680 return; |
678 } | 681 } |
679 | 682 |
680 decryptor_client_->KeyMessage(key_system_string->value(), | 683 key_message_cb_.Run(key_system_string->value(), |
681 session_id_string->value(), | 684 session_id_string->value(), |
682 message, | 685 message, |
683 default_url_string->value()); | 686 default_url_string->value()); |
684 } | 687 } |
685 | 688 |
686 void ContentDecryptorDelegate::KeyError(PP_Var key_system_var, | 689 void ContentDecryptorDelegate::KeyError(PP_Var key_system_var, |
687 PP_Var session_id_var, | 690 PP_Var session_id_var, |
688 int32_t media_error, | 691 int32_t media_error, |
689 int32_t system_code) { | 692 int32_t system_code) { |
690 if (!decryptor_client_) | 693 if (key_error_cb_.is_null()) |
691 return; | 694 return; |
692 | 695 |
693 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 696 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); |
694 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 697 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
695 if (!key_system_string || !session_id_string) { | 698 if (!key_system_string || !session_id_string) { |
696 decryptor_client_->KeyError("", "", media::Decryptor::kUnknownError, 0); | 699 key_error_cb_.Run("", "", media::Decryptor::kUnknownError, 0); |
697 return; | 700 return; |
698 } | 701 } |
699 | 702 |
700 decryptor_client_->KeyError( | 703 key_error_cb_.Run( |
701 key_system_string->value(), | 704 key_system_string->value(), |
702 session_id_string->value(), | 705 session_id_string->value(), |
703 static_cast<media::Decryptor::KeyError>(media_error), | 706 static_cast<media::Decryptor::KeyError>(media_error), |
704 system_code); | 707 system_code); |
705 } | 708 } |
706 | 709 |
707 void ContentDecryptorDelegate::DecoderInitializeDone( | 710 void ContentDecryptorDelegate::DecoderInitializeDone( |
708 PP_DecryptorStreamType decoder_type, | 711 PP_DecryptorStreamType decoder_type, |
709 uint32_t request_id, | 712 uint32_t request_id, |
710 PP_Bool success) { | 713 PP_Bool success) { |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 | 1042 |
1040 if (free_buffers_.empty()) | 1043 if (free_buffers_.empty()) |
1041 return; | 1044 return; |
1042 | 1045 |
1043 tracking_info->buffer_id = free_buffers_.front(); | 1046 tracking_info->buffer_id = free_buffers_.front(); |
1044 free_buffers_.pop(); | 1047 free_buffers_.pop(); |
1045 } | 1048 } |
1046 | 1049 |
1047 } // namespace ppapi | 1050 } // namespace ppapi |
1048 } // namespace webkit | 1051 } // namespace webkit |
OLD | NEW |