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 "remoting/client/plugin/chromoting_instance.h" | 5 #include "remoting/client/plugin/chromoting_instance.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #if defined(OS_NACL) | 10 #if defined(OS_NACL) |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "ppapi/cpp/image_data.h" | 32 #include "ppapi/cpp/image_data.h" |
33 #include "ppapi/cpp/input_event.h" | 33 #include "ppapi/cpp/input_event.h" |
34 #include "ppapi/cpp/rect.h" | 34 #include "ppapi/cpp/rect.h" |
35 #include "ppapi/cpp/var_array_buffer.h" | 35 #include "ppapi/cpp/var_array_buffer.h" |
36 #include "ppapi/cpp/var_dictionary.h" | 36 #include "ppapi/cpp/var_dictionary.h" |
37 #include "remoting/base/constants.h" | 37 #include "remoting/base/constants.h" |
38 #include "remoting/base/util.h" | 38 #include "remoting/base/util.h" |
39 #include "remoting/client/chromoting_client.h" | 39 #include "remoting/client/chromoting_client.h" |
40 #include "remoting/client/frame_consumer_proxy.h" | 40 #include "remoting/client/frame_consumer_proxy.h" |
41 #include "remoting/client/plugin/delegating_signal_strategy.h" | 41 #include "remoting/client/plugin/delegating_signal_strategy.h" |
42 #include "remoting/client/plugin/media_source_video_renderer.h" | |
43 #include "remoting/client/plugin/normalizing_input_filter_cros.h" | 42 #include "remoting/client/plugin/normalizing_input_filter_cros.h" |
44 #include "remoting/client/plugin/normalizing_input_filter_mac.h" | 43 #include "remoting/client/plugin/normalizing_input_filter_mac.h" |
45 #include "remoting/client/plugin/pepper_audio_player.h" | 44 #include "remoting/client/plugin/pepper_audio_player.h" |
46 #include "remoting/client/plugin/pepper_mouse_locker.h" | 45 #include "remoting/client/plugin/pepper_mouse_locker.h" |
47 #include "remoting/client/plugin/pepper_port_allocator.h" | 46 #include "remoting/client/plugin/pepper_port_allocator.h" |
48 #include "remoting/client/plugin/pepper_view.h" | 47 #include "remoting/client/plugin/pepper_view.h" |
49 #include "remoting/client/software_video_renderer.h" | 48 #include "remoting/client/software_video_renderer.h" |
50 #include "remoting/client/token_fetcher_proxy.h" | 49 #include "remoting/client/token_fetcher_proxy.h" |
51 #include "remoting/protocol/connection_to_host.h" | 50 #include "remoting/protocol/connection_to_host.h" |
52 #include "remoting/protocol/host_stub.h" | 51 #include "remoting/protocol/host_stub.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 base::LazyInstance<base::Lock>::Leaky | 169 base::LazyInstance<base::Lock>::Leaky |
171 g_logging_lock = LAZY_INSTANCE_INITIALIZER; | 170 g_logging_lock = LAZY_INSTANCE_INITIALIZER; |
172 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; | 171 logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
173 | 172 |
174 } // namespace | 173 } // namespace |
175 | 174 |
176 // String sent in the "hello" message to the webapp to describe features. | 175 // String sent in the "hello" message to the webapp to describe features. |
177 const char ChromotingInstance::kApiFeatures[] = | 176 const char ChromotingInstance::kApiFeatures[] = |
178 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " | 177 "highQualityScaling injectKeyEvent sendClipboardItem remapKey trapKey " |
179 "notifyClientResolution pauseVideo pauseAudio asyncPin thirdPartyAuth " | 178 "notifyClientResolution pauseVideo pauseAudio asyncPin thirdPartyAuth " |
180 "pinlessAuth extensionMessage allowMouseLock mediaSourceRendering " | 179 "pinlessAuth extensionMessage allowMouseLock videoControl"; |
181 "videoControl"; | |
182 | 180 |
183 const char ChromotingInstance::kRequestedCapabilities[] = ""; | 181 const char ChromotingInstance::kRequestedCapabilities[] = ""; |
184 const char ChromotingInstance::kSupportedCapabilities[] = "desktopShape"; | 182 const char ChromotingInstance::kSupportedCapabilities[] = "desktopShape"; |
185 | 183 |
186 ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) | 184 ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) |
187 : pp::Instance(pp_instance), | 185 : pp::Instance(pp_instance), |
188 initialized_(false), | 186 initialized_(false), |
189 plugin_task_runner_(new PluginThreadTaskRunner(&plugin_thread_delegate_)), | 187 plugin_task_runner_(new PluginThreadTaskRunner(&plugin_thread_delegate_)), |
190 context_(plugin_task_runner_.get()), | 188 context_(plugin_task_runner_.get()), |
191 input_tracker_(&mouse_input_filter_), | 189 input_tracker_(&mouse_input_filter_), |
192 key_mapper_(&input_tracker_), | 190 key_mapper_(&input_tracker_), |
193 cursor_setter_(this), | 191 cursor_setter_(this), |
194 empty_cursor_filter_(&cursor_setter_), | 192 empty_cursor_filter_(&cursor_setter_), |
195 text_input_controller_(this), | 193 text_input_controller_(this), |
196 use_async_pin_dialog_(false), | 194 use_async_pin_dialog_(false), |
197 use_media_source_rendering_(false), | |
198 weak_factory_(this) { | 195 weak_factory_(this) { |
199 #if defined(OS_NACL) | 196 #if defined(OS_NACL) |
200 // In NaCl global resources need to be initialized differently because they | 197 // In NaCl global resources need to be initialized differently because they |
201 // are not shared with Chrome. | 198 // are not shared with Chrome. |
202 thread_task_runner_handle_.reset( | 199 thread_task_runner_handle_.reset( |
203 new base::ThreadTaskRunnerHandle(plugin_task_runner_)); | 200 new base::ThreadTaskRunnerHandle(plugin_task_runner_)); |
204 thread_wrapper_.reset( | 201 thread_wrapper_.reset( |
205 new jingle_glue::JingleThreadWrapper(plugin_task_runner_)); | 202 new jingle_glue::JingleThreadWrapper(plugin_task_runner_)); |
206 media::InitializeCPUSpecificYUVConversions(); | 203 media::InitializeCPUSpecificYUVConversions(); |
207 | 204 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } else if (method == "onPinFetched") { | 342 } else if (method == "onPinFetched") { |
346 HandleOnPinFetched(*data); | 343 HandleOnPinFetched(*data); |
347 } else if (method == "onThirdPartyTokenFetched") { | 344 } else if (method == "onThirdPartyTokenFetched") { |
348 HandleOnThirdPartyTokenFetched(*data); | 345 HandleOnThirdPartyTokenFetched(*data); |
349 } else if (method == "requestPairing") { | 346 } else if (method == "requestPairing") { |
350 HandleRequestPairing(*data); | 347 HandleRequestPairing(*data); |
351 } else if (method == "extensionMessage") { | 348 } else if (method == "extensionMessage") { |
352 HandleExtensionMessage(*data); | 349 HandleExtensionMessage(*data); |
353 } else if (method == "allowMouseLock") { | 350 } else if (method == "allowMouseLock") { |
354 HandleAllowMouseLockMessage(); | 351 HandleAllowMouseLockMessage(); |
355 } else if (method == "enableMediaSourceRendering") { | |
356 HandleEnableMediaSourceRendering(); | |
357 } else if (method == "sendMouseInputWhenUnfocused") { | 352 } else if (method == "sendMouseInputWhenUnfocused") { |
358 HandleSendMouseInputWhenUnfocused(); | 353 HandleSendMouseInputWhenUnfocused(); |
359 } else if (method == "delegateLargeCursors") { | 354 } else if (method == "delegateLargeCursors") { |
360 HandleDelegateLargeCursors(); | 355 HandleDelegateLargeCursors(); |
361 } | 356 } |
362 } | 357 } |
363 | 358 |
364 void ChromotingInstance::DidChangeFocus(bool has_focus) { | 359 void ChromotingInstance::DidChangeFocus(bool has_focus) { |
365 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 360 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
366 | 361 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 } | 621 } |
627 #elif defined(OS_MACOSX) | 622 #elif defined(OS_MACOSX) |
628 normalizing_input_filter_.reset(new NormalizingInputFilterMac(&key_mapper_)); | 623 normalizing_input_filter_.reset(new NormalizingInputFilterMac(&key_mapper_)); |
629 #elif defined(OS_CHROMEOS) | 624 #elif defined(OS_CHROMEOS) |
630 normalizing_input_filter_.reset(new NormalizingInputFilterCros(&key_mapper_)); | 625 normalizing_input_filter_.reset(new NormalizingInputFilterCros(&key_mapper_)); |
631 #else | 626 #else |
632 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); | 627 normalizing_input_filter_.reset(new protocol::InputFilter(&key_mapper_)); |
633 #endif | 628 #endif |
634 input_handler_.set_input_stub(normalizing_input_filter_.get()); | 629 input_handler_.set_input_stub(normalizing_input_filter_.get()); |
635 | 630 |
636 if (use_media_source_rendering_) { | 631 view_.reset(new PepperView(this, &context_)); |
637 video_renderer_.reset(new MediaSourceVideoRenderer(this)); | 632 view_weak_factory_.reset( |
638 } else { | 633 new base::WeakPtrFactory<FrameConsumer>(view_.get())); |
639 view_.reset(new PepperView(this, &context_)); | |
640 view_weak_factory_.reset( | |
641 new base::WeakPtrFactory<FrameConsumer>(view_.get())); | |
642 | 634 |
643 // SoftwareVideoRenderer runs on a separate thread so for now we wrap | 635 // SoftwareVideoRenderer runs on a separate thread so for now we wrap |
644 // PepperView with a ref-counted proxy object. | 636 // PepperView with a ref-counted proxy object. |
645 scoped_refptr<FrameConsumerProxy> consumer_proxy = | 637 scoped_refptr<FrameConsumerProxy> consumer_proxy = |
646 new FrameConsumerProxy(plugin_task_runner_, | 638 new FrameConsumerProxy(plugin_task_runner_, |
647 view_weak_factory_->GetWeakPtr()); | 639 view_weak_factory_->GetWeakPtr()); |
648 | 640 |
649 SoftwareVideoRenderer* renderer = | 641 SoftwareVideoRenderer* renderer = |
650 new SoftwareVideoRenderer(context_.main_task_runner(), | 642 new SoftwareVideoRenderer(context_.main_task_runner(), |
651 context_.decode_task_runner(), | 643 context_.decode_task_runner(), |
652 consumer_proxy); | 644 consumer_proxy); |
653 view_->Initialize(renderer); | 645 view_->Initialize(renderer); |
654 if (!plugin_view_.is_null()) | 646 if (!plugin_view_.is_null()) |
655 view_->SetView(plugin_view_); | 647 view_->SetView(plugin_view_); |
656 video_renderer_.reset(renderer); | 648 video_renderer_.reset(renderer); |
657 } | |
658 | 649 |
659 scoped_ptr<AudioPlayer> audio_player(new PepperAudioPlayer(this)); | 650 scoped_ptr<AudioPlayer> audio_player(new PepperAudioPlayer(this)); |
660 client_.reset(new ChromotingClient(&context_, this, video_renderer_.get(), | 651 client_.reset(new ChromotingClient(&context_, this, video_renderer_.get(), |
661 audio_player.Pass())); | 652 audio_player.Pass())); |
662 | 653 |
663 // Connect the input pipeline to the protocol stub & initialize components. | 654 // Connect the input pipeline to the protocol stub & initialize components. |
664 mouse_input_filter_.set_input_stub(client_->input_stub()); | 655 mouse_input_filter_.set_input_stub(client_->input_stub()); |
665 if (!plugin_view_.is_null()) { | 656 if (!plugin_view_.is_null()) { |
666 mouse_input_filter_.set_input_size(webrtc::DesktopSize( | 657 mouse_input_filter_.set_input_size(webrtc::DesktopSize( |
667 plugin_view_.GetRect().width(), plugin_view_.GetRect().height())); | 658 plugin_view_.GetRect().width(), plugin_view_.GetRect().height())); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 | 927 |
937 void ChromotingInstance::HandleAllowMouseLockMessage() { | 928 void ChromotingInstance::HandleAllowMouseLockMessage() { |
938 // Create the mouse lock handler and route cursor shape messages through it. | 929 // Create the mouse lock handler and route cursor shape messages through it. |
939 mouse_locker_.reset(new PepperMouseLocker( | 930 mouse_locker_.reset(new PepperMouseLocker( |
940 this, base::Bind(&PepperInputHandler::set_send_mouse_move_deltas, | 931 this, base::Bind(&PepperInputHandler::set_send_mouse_move_deltas, |
941 base::Unretained(&input_handler_)), | 932 base::Unretained(&input_handler_)), |
942 &cursor_setter_)); | 933 &cursor_setter_)); |
943 empty_cursor_filter_.set_cursor_stub(mouse_locker_.get()); | 934 empty_cursor_filter_.set_cursor_stub(mouse_locker_.get()); |
944 } | 935 } |
945 | 936 |
946 void ChromotingInstance::HandleEnableMediaSourceRendering() { | |
947 use_media_source_rendering_ = true; | |
948 } | |
949 | |
950 void ChromotingInstance::HandleSendMouseInputWhenUnfocused() { | 937 void ChromotingInstance::HandleSendMouseInputWhenUnfocused() { |
951 input_handler_.set_send_mouse_input_when_unfocused(true); | 938 input_handler_.set_send_mouse_input_when_unfocused(true); |
952 } | 939 } |
953 | 940 |
954 void ChromotingInstance::HandleDelegateLargeCursors() { | 941 void ChromotingInstance::HandleDelegateLargeCursors() { |
955 cursor_setter_.set_delegate_stub(this); | 942 cursor_setter_.set_delegate_stub(this); |
956 } | 943 } |
957 | 944 |
958 ChromotingStats* ChromotingInstance::GetStats() { | 945 ChromotingStats* ChromotingInstance::GetStats() { |
959 if (!video_renderer_.get()) | 946 if (!video_renderer_.get()) |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 std::string url_scheme = url.substr(url_components.scheme.begin, | 1119 std::string url_scheme = url.substr(url_components.scheme.begin, |
1133 url_components.scheme.len); | 1120 url_components.scheme.len); |
1134 return url_scheme == kChromeExtensionUrlScheme; | 1121 return url_scheme == kChromeExtensionUrlScheme; |
1135 } | 1122 } |
1136 | 1123 |
1137 bool ChromotingInstance::IsConnected() { | 1124 bool ChromotingInstance::IsConnected() { |
1138 return client_ && | 1125 return client_ && |
1139 (client_->connection_state() == protocol::ConnectionToHost::CONNECTED); | 1126 (client_->connection_state() == protocol::ConnectionToHost::CONNECTED); |
1140 } | 1127 } |
1141 | 1128 |
1142 void ChromotingInstance::OnMediaSourceSize(const webrtc::DesktopSize& size, | |
1143 const webrtc::DesktopVector& dpi) { | |
1144 SetDesktopSize(size, dpi); | |
1145 } | |
1146 | |
1147 void ChromotingInstance::OnMediaSourceShape( | |
1148 const webrtc::DesktopRegion& shape) { | |
1149 SetDesktopShape(shape); | |
1150 } | |
1151 | |
1152 void ChromotingInstance::OnMediaSourceReset(const std::string& format) { | |
1153 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | |
1154 data->SetString("format", format); | |
1155 PostLegacyJsonMessage("mediaSourceReset", data.Pass()); | |
1156 } | |
1157 | |
1158 void ChromotingInstance::OnMediaSourceData(uint8_t* buffer, size_t buffer_size, | |
1159 bool keyframe) { | |
1160 pp::VarArrayBuffer array_buffer(buffer_size); | |
1161 void* data_ptr = array_buffer.Map(); | |
1162 memcpy(data_ptr, buffer, buffer_size); | |
1163 array_buffer.Unmap(); | |
1164 pp::VarDictionary data_dictionary; | |
1165 data_dictionary.Set(pp::Var("buffer"), array_buffer); | |
1166 data_dictionary.Set(pp::Var("keyframe"), keyframe); | |
1167 PostChromotingMessage("mediaSourceData", data_dictionary); | |
1168 } | |
1169 | |
1170 } // namespace remoting | 1129 } // namespace remoting |
OLD | NEW |