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_environment.h" | 20 #include "remoting/host/desktop_environment.h" |
21 #include "remoting/host/host_extension_session.h" | 21 #include "remoting/host/host_extension_session.h" |
22 #include "remoting/host/input_injector.h" | 22 #include "remoting/host/input_injector.h" |
23 #include "remoting/host/screen_controls.h" | 23 #include "remoting/host/screen_controls.h" |
24 #include "remoting/host/screen_resolution.h" | 24 #include "remoting/host/screen_resolution.h" |
25 #include "remoting/host/video_scheduler.h" | 25 #include "remoting/host/video_frame_pump.h" |
26 #include "remoting/proto/control.pb.h" | 26 #include "remoting/proto/control.pb.h" |
27 #include "remoting/proto/event.pb.h" | 27 #include "remoting/proto/event.pb.h" |
28 #include "remoting/protocol/client_stub.h" | 28 #include "remoting/protocol/client_stub.h" |
29 #include "remoting/protocol/clipboard_thread_proxy.h" | 29 #include "remoting/protocol/clipboard_thread_proxy.h" |
30 #include "remoting/protocol/pairing_registry.h" | 30 #include "remoting/protocol/pairing_registry.h" |
31 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 31 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
32 | 32 |
33 // Default DPI to assume for old clients that use notifyClientDimensions. | 33 // Default DPI to assume for old clients that use notifyClientDimensions. |
34 const int kDefaultDPI = 96; | 34 const int kDefaultDPI = 96; |
35 | 35 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 remote_input_filter_.SetExpectLocalEcho(false); | 94 remote_input_filter_.SetExpectLocalEcho(false); |
95 #endif // defined(OS_WIN) | 95 #endif // defined(OS_WIN) |
96 } | 96 } |
97 | 97 |
98 ClientSession::~ClientSession() { | 98 ClientSession::~ClientSession() { |
99 DCHECK(CalledOnValidThread()); | 99 DCHECK(CalledOnValidThread()); |
100 DCHECK(!audio_scheduler_.get()); | 100 DCHECK(!audio_scheduler_.get()); |
101 DCHECK(!desktop_environment_); | 101 DCHECK(!desktop_environment_); |
102 DCHECK(!input_injector_); | 102 DCHECK(!input_injector_); |
103 DCHECK(!screen_controls_); | 103 DCHECK(!screen_controls_); |
104 DCHECK(!video_scheduler_.get()); | 104 DCHECK(!video_frame_pump_.get()); |
105 | 105 |
106 connection_.reset(); | 106 connection_.reset(); |
107 } | 107 } |
108 | 108 |
109 void ClientSession::NotifyClientResolution( | 109 void ClientSession::NotifyClientResolution( |
110 const protocol::ClientResolution& resolution) { | 110 const protocol::ClientResolution& resolution) { |
111 DCHECK(CalledOnValidThread()); | 111 DCHECK(CalledOnValidThread()); |
112 | 112 |
113 // TODO(sergeyu): Move these checks to protocol layer. | 113 // TODO(sergeyu): Move these checks to protocol layer. |
114 if (!resolution.has_dips_width() || !resolution.has_dips_height() || | 114 if (!resolution.has_dips_width() || !resolution.has_dips_height() || |
(...skipping 14 matching lines...) Expand all Loading... |
129 webrtc::DesktopSize(resolution.dips_width(), resolution.dips_height()), | 129 webrtc::DesktopSize(resolution.dips_width(), resolution.dips_height()), |
130 webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)); | 130 webrtc::DesktopVector(kDefaultDPI, kDefaultDPI)); |
131 | 131 |
132 // Try to match the client's resolution. | 132 // Try to match the client's resolution. |
133 screen_controls_->SetScreenResolution(client_resolution); | 133 screen_controls_->SetScreenResolution(client_resolution); |
134 } | 134 } |
135 | 135 |
136 void ClientSession::ControlVideo(const protocol::VideoControl& video_control) { | 136 void ClientSession::ControlVideo(const protocol::VideoControl& video_control) { |
137 DCHECK(CalledOnValidThread()); | 137 DCHECK(CalledOnValidThread()); |
138 | 138 |
139 // Note that |video_scheduler_| may be null, depending upon whether extensions | 139 // Note that |video_frame_pump_| may be null, depending upon whether |
140 // choose to wrap or "steal" the video capturer or encoder. | 140 // extensions choose to wrap or "steal" the video capturer or encoder. |
141 if (video_control.has_enable()) { | 141 if (video_control.has_enable()) { |
142 VLOG(1) << "Received VideoControl (enable=" | 142 VLOG(1) << "Received VideoControl (enable=" |
143 << video_control.enable() << ")"; | 143 << video_control.enable() << ")"; |
144 pause_video_ = !video_control.enable(); | 144 pause_video_ = !video_control.enable(); |
145 if (video_scheduler_.get()) | 145 if (video_frame_pump_.get()) |
146 video_scheduler_->Pause(pause_video_); | 146 video_frame_pump_->Pause(pause_video_); |
147 } | 147 } |
148 if (video_control.has_lossless_encode()) { | 148 if (video_control.has_lossless_encode()) { |
149 VLOG(1) << "Received VideoControl (lossless_encode=" | 149 VLOG(1) << "Received VideoControl (lossless_encode=" |
150 << video_control.lossless_encode() << ")"; | 150 << video_control.lossless_encode() << ")"; |
151 lossless_video_encode_ = video_control.lossless_encode(); | 151 lossless_video_encode_ = video_control.lossless_encode(); |
152 if (video_scheduler_.get()) | 152 if (video_frame_pump_.get()) |
153 video_scheduler_->SetLosslessEncode(lossless_video_encode_); | 153 video_frame_pump_->SetLosslessEncode(lossless_video_encode_); |
154 } | 154 } |
155 if (video_control.has_lossless_color()) { | 155 if (video_control.has_lossless_color()) { |
156 VLOG(1) << "Received VideoControl (lossless_color=" | 156 VLOG(1) << "Received VideoControl (lossless_color=" |
157 << video_control.lossless_color() << ")"; | 157 << video_control.lossless_color() << ")"; |
158 lossless_video_color_ = video_control.lossless_color(); | 158 lossless_video_color_ = video_control.lossless_color(); |
159 if (video_scheduler_.get()) | 159 if (video_frame_pump_.get()) |
160 video_scheduler_->SetLosslessColor(lossless_video_color_); | 160 video_frame_pump_->SetLosslessColor(lossless_video_color_); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 void ClientSession::ControlAudio(const protocol::AudioControl& audio_control) { | 164 void ClientSession::ControlAudio(const protocol::AudioControl& audio_control) { |
165 DCHECK(CalledOnValidThread()); | 165 DCHECK(CalledOnValidThread()); |
166 | 166 |
167 if (audio_control.has_enable()) { | 167 if (audio_control.has_enable()) { |
168 VLOG(1) << "Received AudioControl (enable=" | 168 VLOG(1) << "Received AudioControl (enable=" |
169 << audio_control.enable() << ")"; | 169 << audio_control.enable() << ")"; |
170 if (audio_scheduler_.get()) | 170 if (audio_scheduler_.get()) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 243 } |
244 | 244 |
245 void ClientSession::OnConnectionAuthenticated( | 245 void ClientSession::OnConnectionAuthenticated( |
246 protocol::ConnectionToClient* connection) { | 246 protocol::ConnectionToClient* connection) { |
247 DCHECK(CalledOnValidThread()); | 247 DCHECK(CalledOnValidThread()); |
248 DCHECK_EQ(connection_.get(), connection); | 248 DCHECK_EQ(connection_.get(), connection); |
249 DCHECK(!audio_scheduler_.get()); | 249 DCHECK(!audio_scheduler_.get()); |
250 DCHECK(!desktop_environment_); | 250 DCHECK(!desktop_environment_); |
251 DCHECK(!input_injector_); | 251 DCHECK(!input_injector_); |
252 DCHECK(!screen_controls_); | 252 DCHECK(!screen_controls_); |
253 DCHECK(!video_scheduler_.get()); | 253 DCHECK(!video_frame_pump_.get()); |
254 | 254 |
255 auth_input_filter_.set_enabled(true); | 255 auth_input_filter_.set_enabled(true); |
256 auth_clipboard_filter_.set_enabled(true); | 256 auth_clipboard_filter_.set_enabled(true); |
257 | 257 |
258 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); | 258 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); |
259 mouse_clamping_filter_.set_video_stub(connection_->video_stub()); | 259 mouse_clamping_filter_.set_video_stub(connection_->video_stub()); |
260 | 260 |
261 if (max_duration_ > base::TimeDelta()) { | 261 if (max_duration_ > base::TimeDelta()) { |
262 // TODO(simonmorris): Let Disconnect() tell the client that the | 262 // TODO(simonmorris): Let Disconnect() tell the client that the |
263 // disconnection was caused by the session exceeding its maximum duration. | 263 // disconnection was caused by the session exceeding its maximum duration. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 361 |
362 // Ensure that any pressed keys or buttons are released. | 362 // Ensure that any pressed keys or buttons are released. |
363 input_tracker_.ReleaseAll(); | 363 input_tracker_.ReleaseAll(); |
364 | 364 |
365 // Stop components access the client, audio or video stubs, which are no | 365 // Stop components access the client, audio or video stubs, which are no |
366 // longer valid once ConnectionToClient calls OnConnectionClosed(). | 366 // longer valid once ConnectionToClient calls OnConnectionClosed(). |
367 if (audio_scheduler_.get()) { | 367 if (audio_scheduler_.get()) { |
368 audio_scheduler_->Stop(); | 368 audio_scheduler_->Stop(); |
369 audio_scheduler_ = nullptr; | 369 audio_scheduler_ = nullptr; |
370 } | 370 } |
371 if (video_scheduler_.get()) { | 371 if (video_frame_pump_.get()) { |
372 video_scheduler_->Stop(); | 372 video_frame_pump_->Stop(); |
373 video_scheduler_ = nullptr; | 373 video_frame_pump_ = nullptr; |
374 } | 374 } |
375 | 375 |
376 client_clipboard_factory_.InvalidateWeakPtrs(); | 376 client_clipboard_factory_.InvalidateWeakPtrs(); |
377 input_injector_.reset(); | 377 input_injector_.reset(); |
378 screen_controls_.reset(); | 378 screen_controls_.reset(); |
379 desktop_environment_.reset(); | 379 desktop_environment_.reset(); |
380 | 380 |
381 // Notify the ChromotingHost that this client is disconnected. | 381 // Notify the ChromotingHost that this client is disconnected. |
382 // TODO(sergeyu): Log failure reason? | 382 // TODO(sergeyu): Log failure reason? |
383 event_handler_->OnSessionClosed(this); | 383 event_handler_->OnSessionClosed(this); |
384 } | 384 } |
385 | 385 |
386 void ClientSession::OnEventTimestamp(protocol::ConnectionToClient* connection, | 386 void ClientSession::OnEventTimestamp(protocol::ConnectionToClient* connection, |
387 int64 timestamp) { | 387 int64 timestamp) { |
388 DCHECK(CalledOnValidThread()); | 388 DCHECK(CalledOnValidThread()); |
389 DCHECK_EQ(connection_.get(), connection); | 389 DCHECK_EQ(connection_.get(), connection); |
390 | 390 |
391 if (video_scheduler_.get()) | 391 if (video_frame_pump_.get()) |
392 video_scheduler_->SetLatestEventTimestamp(timestamp); | 392 video_frame_pump_->SetLatestEventTimestamp(timestamp); |
393 } | 393 } |
394 | 394 |
395 void ClientSession::OnRouteChange( | 395 void ClientSession::OnRouteChange( |
396 protocol::ConnectionToClient* connection, | 396 protocol::ConnectionToClient* connection, |
397 const std::string& channel_name, | 397 const std::string& channel_name, |
398 const protocol::TransportRoute& route) { | 398 const protocol::TransportRoute& route) { |
399 DCHECK(CalledOnValidThread()); | 399 DCHECK(CalledOnValidThread()); |
400 DCHECK_EQ(connection_.get(), connection); | 400 DCHECK_EQ(connection_.get(), connection); |
401 event_handler_->OnSessionRouteChange(this, channel_name, route); | 401 event_handler_->OnSessionRouteChange(this, channel_name, route); |
402 } | 402 } |
(...skipping 24 matching lines...) Expand all Loading... |
427 if (disable_inputs) | 427 if (disable_inputs) |
428 input_tracker_.ReleaseAll(); | 428 input_tracker_.ReleaseAll(); |
429 | 429 |
430 disable_input_filter_.set_enabled(!disable_inputs); | 430 disable_input_filter_.set_enabled(!disable_inputs); |
431 disable_clipboard_filter_.set_enabled(!disable_inputs); | 431 disable_clipboard_filter_.set_enabled(!disable_inputs); |
432 } | 432 } |
433 | 433 |
434 void ClientSession::ResetVideoPipeline() { | 434 void ClientSession::ResetVideoPipeline() { |
435 DCHECK(CalledOnValidThread()); | 435 DCHECK(CalledOnValidThread()); |
436 | 436 |
437 if (video_scheduler_.get()) { | 437 if (video_frame_pump_.get()) { |
438 video_scheduler_->Stop(); | 438 video_frame_pump_->Stop(); |
439 video_scheduler_ = nullptr; | 439 video_frame_pump_ = nullptr; |
440 } | 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 VideoScheduler 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 VideoScheduler to pump frames from the capturer to the client. | 455 // Create a VideoFramePump to pump frames from the capturer to the client. |
456 video_scheduler_ = new VideoScheduler( | 456 video_frame_pump_ = new VideoFramePump( |
457 video_capture_task_runner_, | 457 video_capture_task_runner_, |
458 video_encode_task_runner_, | 458 video_encode_task_runner_, |
459 network_task_runner_, | 459 network_task_runner_, |
460 video_capturer.Pass(), | 460 video_capturer.Pass(), |
461 desktop_environment_->CreateMouseCursorMonitor(), | 461 desktop_environment_->CreateMouseCursorMonitor(), |
462 video_encoder.Pass(), | 462 video_encoder.Pass(), |
463 connection_->client_stub(), | 463 connection_->client_stub(), |
464 &mouse_clamping_filter_); | 464 &mouse_clamping_filter_); |
465 | 465 |
466 // Apply video-control parameters to the new scheduler. | 466 // Apply video-control parameters to the new scheduler. |
467 video_scheduler_->SetLosslessEncode(lossless_video_encode_); | 467 video_frame_pump_->SetLosslessEncode(lossless_video_encode_); |
468 video_scheduler_->SetLosslessColor(lossless_video_color_); | 468 video_frame_pump_->SetLosslessColor(lossless_video_color_); |
469 | 469 |
470 // Start capturing the screen. | 470 // Start capturing the screen. |
471 video_scheduler_->Start(); | 471 video_frame_pump_->Start(); |
472 | 472 |
473 // Pause capturing if necessary. | 473 // Pause capturing if necessary. |
474 video_scheduler_->Pause(pause_video_); | 474 video_frame_pump_->Pause(pause_video_); |
475 } | 475 } |
476 | 476 |
477 void ClientSession::SetGnubbyAuthHandlerForTesting( | 477 void ClientSession::SetGnubbyAuthHandlerForTesting( |
478 GnubbyAuthHandler* gnubby_auth_handler) { | 478 GnubbyAuthHandler* gnubby_auth_handler) { |
479 DCHECK(CalledOnValidThread()); | 479 DCHECK(CalledOnValidThread()); |
480 gnubby_auth_handler_.reset(gnubby_auth_handler); | 480 gnubby_auth_handler_.reset(gnubby_auth_handler); |
481 } | 481 } |
482 | 482 |
483 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { | 483 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { |
484 DCHECK(CalledOnValidThread()); | 484 DCHECK(CalledOnValidThread()); |
(...skipping 30 matching lines...) Expand all Loading... |
515 return make_scoped_ptr(new AudioEncoderVerbatim()); | 515 return make_scoped_ptr(new AudioEncoderVerbatim()); |
516 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { | 516 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { |
517 return make_scoped_ptr(new AudioEncoderOpus()); | 517 return make_scoped_ptr(new AudioEncoderOpus()); |
518 } | 518 } |
519 | 519 |
520 NOTREACHED(); | 520 NOTREACHED(); |
521 return nullptr; | 521 return nullptr; |
522 } | 522 } |
523 | 523 |
524 } // namespace remoting | 524 } // namespace remoting |
OLD | NEW |