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/host/client_session.h" | 5 #include "remoting/host/client_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "remoting/base/capabilities.h" | 10 #include "remoting/base/capabilities.h" |
11 #include "remoting/base/logging.h" | 11 #include "remoting/base/logging.h" |
12 #include "remoting/codec/audio_encoder.h" | 12 #include "remoting/codec/audio_encoder.h" |
13 #include "remoting/codec/audio_encoder_opus.h" | 13 #include "remoting/codec/audio_encoder_opus.h" |
14 #include "remoting/codec/audio_encoder_verbatim.h" | 14 #include "remoting/codec/audio_encoder_verbatim.h" |
15 #include "remoting/codec/video_encoder.h" | 15 #include "remoting/codec/video_encoder.h" |
16 #include "remoting/codec/video_encoder_verbatim.h" | 16 #include "remoting/codec/video_encoder_verbatim.h" |
17 #include "remoting/codec/video_encoder_vpx.h" | 17 #include "remoting/codec/video_encoder_vpx.h" |
18 #include "remoting/host/audio_capturer.h" | 18 #include "remoting/host/audio_capturer.h" |
19 #include "remoting/host/audio_scheduler.h" | 19 #include "remoting/host/audio_scheduler.h" |
| 20 #include "remoting/host/desktop_capturer_proxy.h" |
20 #include "remoting/host/desktop_environment.h" | 21 #include "remoting/host/desktop_environment.h" |
21 #include "remoting/host/host_extension_session.h" | 22 #include "remoting/host/host_extension_session.h" |
22 #include "remoting/host/input_injector.h" | 23 #include "remoting/host/input_injector.h" |
| 24 #include "remoting/host/mouse_shape_pump.h" |
23 #include "remoting/host/screen_controls.h" | 25 #include "remoting/host/screen_controls.h" |
24 #include "remoting/host/screen_resolution.h" | 26 #include "remoting/host/screen_resolution.h" |
25 #include "remoting/host/video_frame_pump.h" | 27 #include "remoting/host/video_frame_pump.h" |
26 #include "remoting/proto/control.pb.h" | 28 #include "remoting/proto/control.pb.h" |
27 #include "remoting/proto/event.pb.h" | 29 #include "remoting/proto/event.pb.h" |
28 #include "remoting/protocol/client_stub.h" | 30 #include "remoting/protocol/client_stub.h" |
29 #include "remoting/protocol/clipboard_thread_proxy.h" | 31 #include "remoting/protocol/clipboard_thread_proxy.h" |
30 #include "remoting/protocol/pairing_registry.h" | 32 #include "remoting/protocol/pairing_registry.h" |
31 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 33 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
| 34 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h" |
32 | 35 |
33 // Default DPI to assume for old clients that use notifyClientDimensions. | 36 // Default DPI to assume for old clients that use notifyClientDimensions. |
34 const int kDefaultDPI = 96; | 37 const int kDefaultDPI = 96; |
35 | 38 |
36 namespace remoting { | 39 namespace remoting { |
37 | 40 |
38 ClientSession::ClientSession( | 41 ClientSession::ClientSession( |
39 EventHandler* event_handler, | 42 EventHandler* event_handler, |
40 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, | 43 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
41 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 44 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 138 |
136 void ClientSession::ControlVideo(const protocol::VideoControl& video_control) { | 139 void ClientSession::ControlVideo(const protocol::VideoControl& video_control) { |
137 DCHECK(CalledOnValidThread()); | 140 DCHECK(CalledOnValidThread()); |
138 | 141 |
139 // Note that |video_frame_pump_| may be null, depending upon whether | 142 // Note that |video_frame_pump_| may be null, depending upon whether |
140 // extensions choose to wrap or "steal" the video capturer or encoder. | 143 // extensions choose to wrap or "steal" the video capturer or encoder. |
141 if (video_control.has_enable()) { | 144 if (video_control.has_enable()) { |
142 VLOG(1) << "Received VideoControl (enable=" | 145 VLOG(1) << "Received VideoControl (enable=" |
143 << video_control.enable() << ")"; | 146 << video_control.enable() << ")"; |
144 pause_video_ = !video_control.enable(); | 147 pause_video_ = !video_control.enable(); |
145 if (video_frame_pump_.get()) | 148 if (video_frame_pump_) |
146 video_frame_pump_->Pause(pause_video_); | 149 video_frame_pump_->Pause(pause_video_); |
147 } | 150 } |
148 if (video_control.has_lossless_encode()) { | 151 if (video_control.has_lossless_encode()) { |
149 VLOG(1) << "Received VideoControl (lossless_encode=" | 152 VLOG(1) << "Received VideoControl (lossless_encode=" |
150 << video_control.lossless_encode() << ")"; | 153 << video_control.lossless_encode() << ")"; |
151 lossless_video_encode_ = video_control.lossless_encode(); | 154 lossless_video_encode_ = video_control.lossless_encode(); |
152 if (video_frame_pump_.get()) | 155 if (video_frame_pump_) |
153 video_frame_pump_->SetLosslessEncode(lossless_video_encode_); | 156 video_frame_pump_->SetLosslessEncode(lossless_video_encode_); |
154 } | 157 } |
155 if (video_control.has_lossless_color()) { | 158 if (video_control.has_lossless_color()) { |
156 VLOG(1) << "Received VideoControl (lossless_color=" | 159 VLOG(1) << "Received VideoControl (lossless_color=" |
157 << video_control.lossless_color() << ")"; | 160 << video_control.lossless_color() << ")"; |
158 lossless_video_color_ = video_control.lossless_color(); | 161 lossless_video_color_ = video_control.lossless_color(); |
159 if (video_frame_pump_.get()) | 162 if (video_frame_pump_) |
160 video_frame_pump_->SetLosslessColor(lossless_video_color_); | 163 video_frame_pump_->SetLosslessColor(lossless_video_color_); |
161 } | 164 } |
162 } | 165 } |
163 | 166 |
164 void ClientSession::ControlAudio(const protocol::AudioControl& audio_control) { | 167 void ClientSession::ControlAudio(const protocol::AudioControl& audio_control) { |
165 DCHECK(CalledOnValidThread()); | 168 DCHECK(CalledOnValidThread()); |
166 | 169 |
167 if (audio_control.has_enable()) { | 170 if (audio_control.has_enable()) { |
168 VLOG(1) << "Received AudioControl (enable=" | 171 VLOG(1) << "Received AudioControl (enable=" |
169 << audio_control.enable() << ")"; | 172 << audio_control.enable() << ")"; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 364 |
362 // Ensure that any pressed keys or buttons are released. | 365 // Ensure that any pressed keys or buttons are released. |
363 input_tracker_.ReleaseAll(); | 366 input_tracker_.ReleaseAll(); |
364 | 367 |
365 // Stop components access the client, audio or video stubs, which are no | 368 // Stop components access the client, audio or video stubs, which are no |
366 // longer valid once ConnectionToClient calls OnConnectionClosed(). | 369 // longer valid once ConnectionToClient calls OnConnectionClosed(). |
367 if (audio_scheduler_.get()) { | 370 if (audio_scheduler_.get()) { |
368 audio_scheduler_->Stop(); | 371 audio_scheduler_->Stop(); |
369 audio_scheduler_ = nullptr; | 372 audio_scheduler_ = nullptr; |
370 } | 373 } |
371 if (video_frame_pump_.get()) { | 374 |
372 video_frame_pump_->Stop(); | 375 video_frame_pump_.reset(); |
373 video_frame_pump_ = nullptr; | 376 mouse_shape_pump_.reset(); |
374 } | |
375 | 377 |
376 client_clipboard_factory_.InvalidateWeakPtrs(); | 378 client_clipboard_factory_.InvalidateWeakPtrs(); |
377 input_injector_.reset(); | 379 input_injector_.reset(); |
378 screen_controls_.reset(); | 380 screen_controls_.reset(); |
379 desktop_environment_.reset(); | 381 desktop_environment_.reset(); |
380 | 382 |
381 // Notify the ChromotingHost that this client is disconnected. | 383 // Notify the ChromotingHost that this client is disconnected. |
382 // TODO(sergeyu): Log failure reason? | 384 // TODO(sergeyu): Log failure reason? |
383 event_handler_->OnSessionClosed(this); | 385 event_handler_->OnSessionClosed(this); |
384 } | 386 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 if (disable_inputs) | 429 if (disable_inputs) |
428 input_tracker_.ReleaseAll(); | 430 input_tracker_.ReleaseAll(); |
429 | 431 |
430 disable_input_filter_.set_enabled(!disable_inputs); | 432 disable_input_filter_.set_enabled(!disable_inputs); |
431 disable_clipboard_filter_.set_enabled(!disable_inputs); | 433 disable_clipboard_filter_.set_enabled(!disable_inputs); |
432 } | 434 } |
433 | 435 |
434 void ClientSession::ResetVideoPipeline() { | 436 void ClientSession::ResetVideoPipeline() { |
435 DCHECK(CalledOnValidThread()); | 437 DCHECK(CalledOnValidThread()); |
436 | 438 |
437 if (video_frame_pump_.get()) { | 439 mouse_shape_pump_.reset(); |
438 video_frame_pump_->Stop(); | 440 video_frame_pump_.reset(); |
439 video_frame_pump_ = nullptr; | |
440 } | |
441 | 441 |
442 // Create VideoEncoder and DesktopCapturer to match the session's video | 442 // Create VideoEncoder and DesktopCapturer to match the session's video |
443 // channel configuration. | 443 // channel configuration. |
444 scoped_ptr<webrtc::DesktopCapturer> video_capturer = | 444 scoped_ptr<webrtc::DesktopCapturer> video_capturer = |
445 desktop_environment_->CreateVideoCapturer(); | 445 desktop_environment_->CreateVideoCapturer(); |
446 extension_manager_->OnCreateVideoCapturer(&video_capturer); | 446 extension_manager_->OnCreateVideoCapturer(&video_capturer); |
447 scoped_ptr<VideoEncoder> video_encoder = | 447 scoped_ptr<VideoEncoder> video_encoder = |
448 CreateVideoEncoder(connection_->session()->config()); | 448 CreateVideoEncoder(connection_->session()->config()); |
449 extension_manager_->OnCreateVideoEncoder(&video_encoder); | 449 extension_manager_->OnCreateVideoEncoder(&video_encoder); |
450 | 450 |
451 // Don't start the VideoFramePump if either capturer or encoder are missing. | 451 // Don't start the VideoFramePump if either capturer or encoder are missing. |
452 if (!video_capturer || !video_encoder) | 452 if (!video_capturer || !video_encoder) |
453 return; | 453 return; |
454 | 454 |
455 // Create a VideoFramePump to pump frames from the capturer to the client. | 455 // Create MouseShapePump to send mouse cursor shape. |
456 video_frame_pump_ = new VideoFramePump( | 456 mouse_shape_pump_.reset( |
457 video_capture_task_runner_, | 457 new MouseShapePump(video_capture_task_runner_, |
458 video_encode_task_runner_, | 458 desktop_environment_->CreateMouseCursorMonitor(), |
459 network_task_runner_, | 459 connection_->client_stub())); |
460 video_capturer.Pass(), | 460 |
461 desktop_environment_->CreateMouseCursorMonitor(), | 461 // Create a VideoFramePump to pump frames from the capturer to the client.' |
462 video_encoder.Pass(), | 462 // |
463 connection_->client_stub(), | 463 // TODO(sergeyu): Move DesktopCapturerProxy creation to DesktopEnvironment. |
464 &mouse_clamping_filter_); | 464 // When using IpcDesktopCapturer the capture thread is not useful. |
| 465 scoped_ptr<DesktopCapturerProxy> capturer_proxy(new DesktopCapturerProxy( |
| 466 video_capture_task_runner_, video_capturer.Pass())); |
| 467 video_frame_pump_.reset( |
| 468 new VideoFramePump(video_encode_task_runner_, capturer_proxy.Pass(), |
| 469 video_encoder.Pass(), &mouse_clamping_filter_)); |
465 | 470 |
466 // Apply video-control parameters to the new scheduler. | 471 // Apply video-control parameters to the new scheduler. |
467 video_frame_pump_->SetLosslessEncode(lossless_video_encode_); | 472 video_frame_pump_->SetLosslessEncode(lossless_video_encode_); |
468 video_frame_pump_->SetLosslessColor(lossless_video_color_); | 473 video_frame_pump_->SetLosslessColor(lossless_video_color_); |
469 | 474 |
470 // Start capturing the screen. | |
471 video_frame_pump_->Start(); | |
472 | |
473 // Pause capturing if necessary. | 475 // Pause capturing if necessary. |
474 video_frame_pump_->Pause(pause_video_); | 476 video_frame_pump_->Pause(pause_video_); |
475 } | 477 } |
476 | 478 |
477 void ClientSession::SetGnubbyAuthHandlerForTesting( | 479 void ClientSession::SetGnubbyAuthHandlerForTesting( |
478 GnubbyAuthHandler* gnubby_auth_handler) { | 480 GnubbyAuthHandler* gnubby_auth_handler) { |
479 DCHECK(CalledOnValidThread()); | 481 DCHECK(CalledOnValidThread()); |
480 gnubby_auth_handler_.reset(gnubby_auth_handler); | 482 gnubby_auth_handler_.reset(gnubby_auth_handler); |
481 } | 483 } |
482 | 484 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 return make_scoped_ptr(new AudioEncoderVerbatim()); | 517 return make_scoped_ptr(new AudioEncoderVerbatim()); |
516 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { | 518 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { |
517 return make_scoped_ptr(new AudioEncoderOpus()); | 519 return make_scoped_ptr(new AudioEncoderOpus()); |
518 } | 520 } |
519 | 521 |
520 NOTREACHED(); | 522 NOTREACHED(); |
521 return nullptr; | 523 return nullptr; |
522 } | 524 } |
523 | 525 |
524 } // namespace remoting | 526 } // namespace remoting |
OLD | NEW |