Chromium Code Reviews| 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 "content/renderer/pepper/content_decryptor_delegate.h" | 5 #include "content/renderer/pepper/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/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "content/renderer/pepper/ppb_buffer_impl.h" | 12 #include "content/renderer/pepper/ppb_buffer_impl.h" |
| 13 #include "media/base/audio_buffer.h" | 13 #include "media/base/audio_buffer.h" |
| 14 #include "media/base/audio_decoder_config.h" | 14 #include "media/base/audio_decoder_config.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 15 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/cdm_key_information.h" | 16 #include "media/base/cdm_key_information.h" |
| 17 #include "media/base/cdm_promise.h" | |
| 18 #include "media/base/channel_layout.h" | 17 #include "media/base/channel_layout.h" |
| 19 #include "media/base/data_buffer.h" | 18 #include "media/base/data_buffer.h" |
| 20 #include "media/base/decoder_buffer.h" | 19 #include "media/base/decoder_buffer.h" |
| 21 #include "media/base/decrypt_config.h" | 20 #include "media/base/decrypt_config.h" |
| 22 #include "media/base/key_systems.h" | 21 #include "media/base/key_systems.h" |
| 23 #include "media/base/limits.h" | 22 #include "media/base/limits.h" |
| 24 #include "media/base/video_decoder_config.h" | 23 #include "media/base/video_decoder_config.h" |
| 25 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
| 26 #include "media/base/video_util.h" | 25 #include "media/base/video_util.h" |
| 27 #include "ppapi/shared_impl/array_var.h" | 26 #include "ppapi/shared_impl/array_var.h" |
| 28 #include "ppapi/shared_impl/scoped_pp_resource.h" | 27 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 29 #include "ppapi/shared_impl/time_conversion.h" | 28 #include "ppapi/shared_impl/time_conversion.h" |
| 30 #include "ppapi/shared_impl/var.h" | 29 #include "ppapi/shared_impl/var.h" |
| 31 #include "ppapi/shared_impl/var_tracker.h" | 30 #include "ppapi/shared_impl/var_tracker.h" |
| 32 #include "ppapi/thunk/enter.h" | 31 #include "ppapi/thunk/enter.h" |
| 33 #include "ppapi/thunk/ppb_buffer_api.h" | 32 #include "ppapi/thunk/ppb_buffer_api.h" |
| 34 #include "ui/gfx/geometry/rect.h" | 33 #include "ui/gfx/geometry/rect.h" |
| 35 | 34 |
| 36 using media::CdmPromise; | |
| 37 using media::Decryptor; | 35 using media::Decryptor; |
| 38 using media::MediaKeys; | 36 using media::MediaKeys; |
| 39 using media::NewSessionCdmPromise; | 37 using media::NewSessionCdmPromise; |
| 40 using media::SimpleCdmPromise; | 38 using media::SimpleCdmPromise; |
| 41 using ppapi::ArrayBufferVar; | 39 using ppapi::ArrayBufferVar; |
| 42 using ppapi::ArrayVar; | 40 using ppapi::ArrayVar; |
| 43 using ppapi::PpapiGlobals; | 41 using ppapi::PpapiGlobals; |
| 44 using ppapi::ScopedPPResource; | 42 using ppapi::ScopedPPResource; |
| 45 using ppapi::StringVar; | 43 using ppapi::StringVar; |
| 46 using ppapi::thunk::EnterResourceNoLock; | 44 using ppapi::thunk::EnterResourceNoLock; |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 video_decode_cb_.Set(request_id, video_decode_cb); | 707 video_decode_cb_.Set(request_id, video_decode_cb); |
| 710 | 708 |
| 711 // TODO(tomfinegan): Need to get stream type from media stack. | 709 // TODO(tomfinegan): Need to get stream type from media stack. |
| 712 ScopedPPResource pp_resource(encrypted_resource.get()); | 710 ScopedPPResource pp_resource(encrypted_resource.get()); |
| 713 plugin_decryption_interface_->DecryptAndDecode( | 711 plugin_decryption_interface_->DecryptAndDecode( |
| 714 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); | 712 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); |
| 715 return true; | 713 return true; |
| 716 } | 714 } |
| 717 | 715 |
| 718 void ContentDecryptorDelegate::OnPromiseResolved(uint32 promise_id) { | 716 void ContentDecryptorDelegate::OnPromiseResolved(uint32 promise_id) { |
| 719 scoped_ptr<CdmPromise> promise = cdm_promise_adapter_.TakePromise(promise_id); | 717 cdm_promise_adapter_.ResolvePromise(promise_id); |
|
xhwang
2015/01/09 23:51:03
The template type is automatically deduced.
| |
| 720 if (!promise || | |
| 721 promise->GetResolveParameterType() != media::CdmPromise::VOID_TYPE) { | |
| 722 NOTREACHED(); | |
| 723 return; | |
| 724 } | |
| 725 | |
| 726 SimpleCdmPromise* simple_promise = | |
| 727 static_cast<SimpleCdmPromise*>(promise.get()); | |
| 728 simple_promise->resolve(); | |
| 729 } | 718 } |
| 730 | 719 |
| 731 void ContentDecryptorDelegate::OnPromiseResolvedWithSession( | 720 void ContentDecryptorDelegate::OnPromiseResolvedWithSession( |
| 732 uint32 promise_id, | 721 uint32 promise_id, |
| 733 PP_Var web_session_id) { | 722 PP_Var web_session_id) { |
| 734 scoped_ptr<CdmPromise> promise = cdm_promise_adapter_.TakePromise(promise_id); | |
| 735 if (!promise || | |
| 736 promise->GetResolveParameterType() != media::CdmPromise::STRING_TYPE) { | |
| 737 NOTREACHED(); | |
| 738 return; | |
| 739 } | |
| 740 | |
| 741 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 723 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
| 742 DCHECK(web_session_id_string); | 724 DCHECK(web_session_id_string); |
| 743 | 725 cdm_promise_adapter_.ResolvePromise(promise_id, |
| 744 NewSessionCdmPromise* session_promise = | 726 web_session_id_string->value()); |
| 745 static_cast<NewSessionCdmPromise*>(promise.get()); | |
| 746 session_promise->resolve(web_session_id_string->value()); | |
| 747 } | 727 } |
| 748 | 728 |
| 749 void ContentDecryptorDelegate::OnPromiseRejected( | 729 void ContentDecryptorDelegate::OnPromiseRejected( |
| 750 uint32 promise_id, | 730 uint32 promise_id, |
| 751 PP_CdmExceptionCode exception_code, | 731 PP_CdmExceptionCode exception_code, |
| 752 uint32 system_code, | 732 uint32 system_code, |
| 753 PP_Var error_description) { | 733 PP_Var error_description) { |
| 754 ReportSystemCodeUMA(key_system_, system_code); | 734 ReportSystemCodeUMA(key_system_, system_code); |
| 755 | 735 |
| 756 StringVar* error_description_string = StringVar::FromPPVar(error_description); | 736 StringVar* error_description_string = StringVar::FromPPVar(error_description); |
| 757 DCHECK(error_description_string); | 737 DCHECK(error_description_string); |
| 758 | 738 cdm_promise_adapter_.RejectPromise( |
| 759 scoped_ptr<CdmPromise> promise = cdm_promise_adapter_.TakePromise(promise_id); | 739 promise_id, PpExceptionTypeToMediaException(exception_code), system_code, |
| 760 DCHECK(promise); | 740 error_description_string->value()); |
| 761 if (promise) { | |
| 762 promise->reject(PpExceptionTypeToMediaException(exception_code), | |
| 763 system_code, | |
| 764 error_description_string->value()); | |
| 765 } | |
| 766 } | 741 } |
| 767 | 742 |
| 768 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, | 743 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, |
| 769 PP_CdmMessageType message_type, | 744 PP_CdmMessageType message_type, |
| 770 PP_Var message) { | 745 PP_Var message) { |
| 771 if (session_message_cb_.is_null()) | 746 if (session_message_cb_.is_null()) |
| 772 return; | 747 return; |
| 773 | 748 |
| 774 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 749 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
| 775 DCHECK(web_session_id_string); | 750 DCHECK(web_session_id_string); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1280 empty_frames); | 1255 empty_frames); |
| 1281 } | 1256 } |
| 1282 | 1257 |
| 1283 if (!video_decode_cb_.is_null()) | 1258 if (!video_decode_cb_.is_null()) |
| 1284 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); | 1259 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
| 1285 | 1260 |
| 1286 cdm_promise_adapter_.Clear(); | 1261 cdm_promise_adapter_.Clear(); |
| 1287 } | 1262 } |
| 1288 | 1263 |
| 1289 } // namespace content | 1264 } // namespace content |
| OLD | NEW |