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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 desktop_environment_factory_(desktop_environment_factory), | 72 desktop_environment_factory_(desktop_environment_factory), |
73 input_tracker_(&host_input_filter_), | 73 input_tracker_(&host_input_filter_), |
74 remote_input_filter_(&input_tracker_), | 74 remote_input_filter_(&input_tracker_), |
75 mouse_clamping_filter_(&remote_input_filter_), | 75 mouse_clamping_filter_(&remote_input_filter_), |
76 disable_input_filter_(&mouse_clamping_filter_), | 76 disable_input_filter_(&mouse_clamping_filter_), |
77 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()), | 77 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()), |
78 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), | 78 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), |
79 max_duration_(max_duration), | 79 max_duration_(max_duration), |
80 audio_task_runner_(audio_task_runner), | 80 audio_task_runner_(audio_task_runner), |
81 pairing_registry_(pairing_registry), | 81 pairing_registry_(pairing_registry), |
82 is_authenticated_(false), | |
83 pause_video_(false), | |
84 lossless_video_encode_(false), | |
85 // Note that |lossless_video_color_| defaults to true, but actually only | 82 // Note that |lossless_video_color_| defaults to true, but actually only |
86 // controls VP9 video stream color quality. | 83 // controls VP9 video stream color quality. |
87 lossless_video_color_(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 84 lossless_video_color_(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
88 kDisableI444SwitchName)), | 85 kDisableI444SwitchName)), |
89 weak_factory_(this) { | 86 weak_factory_(this) { |
90 connection_->SetEventHandler(this); | 87 connection_->SetEventHandler(this); |
91 | 88 |
92 // Create a manager for the configured extensions, if any. | 89 // Create a manager for the configured extensions, if any. |
93 extension_manager_.reset(new HostExtensionSessionManager(extensions, this)); | 90 extension_manager_.reset(new HostExtensionSessionManager(extensions, this)); |
94 | 91 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 client_capabilities_ = make_scoped_ptr(new std::string()); | 187 client_capabilities_ = make_scoped_ptr(new std::string()); |
191 if (capabilities.has_capabilities()) | 188 if (capabilities.has_capabilities()) |
192 *client_capabilities_ = capabilities.capabilities(); | 189 *client_capabilities_ = capabilities.capabilities(); |
193 capabilities_ = IntersectCapabilities(*client_capabilities_, | 190 capabilities_ = IntersectCapabilities(*client_capabilities_, |
194 host_capabilities_); | 191 host_capabilities_); |
195 extension_manager_->OnNegotiatedCapabilities( | 192 extension_manager_->OnNegotiatedCapabilities( |
196 connection_->client_stub(), capabilities_); | 193 connection_->client_stub(), capabilities_); |
197 | 194 |
198 VLOG(1) << "Client capabilities: " << *client_capabilities_; | 195 VLOG(1) << "Client capabilities: " << *client_capabilities_; |
199 | 196 |
200 // Calculate the set of capabilities enabled by both client and host and | |
201 // pass it to the desktop environment if it is available. | |
202 desktop_environment_->SetCapabilities(capabilities_); | 197 desktop_environment_->SetCapabilities(capabilities_); |
203 } | 198 } |
204 | 199 |
205 void ClientSession::RequestPairing( | 200 void ClientSession::RequestPairing( |
206 const protocol::PairingRequest& pairing_request) { | 201 const protocol::PairingRequest& pairing_request) { |
207 if (pairing_registry_.get() && pairing_request.has_client_name()) { | 202 if (pairing_registry_.get() && pairing_request.has_client_name()) { |
208 protocol::PairingRegistry::Pairing pairing = | 203 protocol::PairingRegistry::Pairing pairing = |
209 pairing_registry_->CreatePairing(pairing_request.client_name()); | 204 pairing_registry_->CreatePairing(pairing_request.client_name()); |
210 protocol::PairingResponse pairing_response; | 205 protocol::PairingResponse pairing_response; |
211 pairing_response.set_client_id(pairing.client_id()); | 206 pairing_response.set_client_id(pairing.client_id()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // Connect the host input stubs. | 283 // Connect the host input stubs. |
289 connection_->set_input_stub(&disable_input_filter_); | 284 connection_->set_input_stub(&disable_input_filter_); |
290 host_input_filter_.set_input_stub(input_injector_.get()); | 285 host_input_filter_.set_input_stub(input_injector_.get()); |
291 | 286 |
292 // Connect the clipboard stubs. | 287 // Connect the clipboard stubs. |
293 connection_->set_clipboard_stub(&disable_clipboard_filter_); | 288 connection_->set_clipboard_stub(&disable_clipboard_filter_); |
294 clipboard_echo_filter_.set_host_stub(input_injector_.get()); | 289 clipboard_echo_filter_.set_host_stub(input_injector_.get()); |
295 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); | 290 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); |
296 } | 291 } |
297 | 292 |
293 void ClientSession::CreateVideoStreams( | |
294 protocol::ConnectionToClient* connection) { | |
295 DCHECK(CalledOnValidThread()); | |
296 DCHECK_EQ(connection_.get(), connection); | |
297 | |
298 // Create a VideoStream to pump frames from the capturer to the client. | |
299 video_stream_ = connection_->StartVideoStream( | |
300 desktop_environment_->CreateVideoCapturer()); | |
301 | |
302 video_stream_->SetSizeCallback( | |
303 base::Bind(&ClientSession::OnScreenSizeChanged, base::Unretained(this))); | |
304 | |
305 // Apply video-control parameters to the new stream. | |
306 video_stream_->SetLosslessEncode(lossless_video_encode_); | |
307 video_stream_->SetLosslessColor(lossless_video_color_); | |
308 | |
309 // Pause capturing if necessary. | |
310 video_stream_->Pause(pause_video_); | |
311 } | |
312 | |
298 void ClientSession::OnConnectionChannelsConnected( | 313 void ClientSession::OnConnectionChannelsConnected( |
299 protocol::ConnectionToClient* connection) { | 314 protocol::ConnectionToClient* connection) { |
300 DCHECK(CalledOnValidThread()); | 315 DCHECK(CalledOnValidThread()); |
301 DCHECK_EQ(connection_.get(), connection); | 316 DCHECK_EQ(connection_.get(), connection); |
302 | 317 |
318 DCHECK(!channels_connected_); | |
319 channels_connected_ = true; | |
320 | |
303 // Negotiate capabilities with the client. | 321 // Negotiate capabilities with the client. |
304 VLOG(1) << "Host capabilities: " << host_capabilities_; | 322 VLOG(1) << "Host capabilities: " << host_capabilities_; |
305 protocol::Capabilities capabilities; | 323 protocol::Capabilities capabilities; |
306 capabilities.set_capabilities(host_capabilities_); | 324 capabilities.set_capabilities(host_capabilities_); |
307 connection_->client_stub()->SetCapabilities(capabilities); | 325 connection_->client_stub()->SetCapabilities(capabilities); |
308 | 326 |
309 // Start the event executor. | 327 // Start the event executor. |
310 input_injector_->Start(CreateClipboardProxy()); | 328 input_injector_->Start(CreateClipboardProxy()); |
311 SetDisableInputs(false); | 329 SetDisableInputs(false); |
312 | 330 |
313 // Create MouseShapePump to send mouse cursor shape. | 331 // Create MouseShapePump to send mouse cursor shape. |
314 mouse_shape_pump_.reset( | 332 mouse_shape_pump_.reset( |
315 new MouseShapePump(desktop_environment_->CreateMouseCursorMonitor(), | 333 new MouseShapePump(desktop_environment_->CreateMouseCursorMonitor(), |
316 connection_->client_stub())); | 334 connection_->client_stub())); |
317 | 335 |
318 // Create a VideoStream to pump frames from the capturer to the client. | |
319 video_stream_ = connection_->StartVideoStream( | |
320 desktop_environment_->CreateVideoCapturer()); | |
321 | |
322 video_stream_->SetSizeCallback( | |
323 base::Bind(&ClientSession::OnScreenSizeChanged, base::Unretained(this))); | |
324 | |
325 // Apply video-control parameters to the new stream. | |
326 video_stream_->SetLosslessEncode(lossless_video_encode_); | |
327 video_stream_->SetLosslessColor(lossless_video_color_); | |
328 | |
329 // Pause capturing if necessary. | |
330 video_stream_->Pause(pause_video_); | |
331 | |
332 // Create an AudioPump if audio is enabled, to pump audio samples. | 336 // Create an AudioPump if audio is enabled, to pump audio samples. |
333 if (connection_->session()->config().is_audio_enabled()) { | 337 if (connection_->session()->config().is_audio_enabled()) { |
334 scoped_ptr<AudioEncoder> audio_encoder = | 338 scoped_ptr<AudioEncoder> audio_encoder = |
335 CreateAudioEncoder(connection_->session()->config()); | 339 CreateAudioEncoder(connection_->session()->config()); |
336 audio_pump_.reset(new AudioPump( | 340 audio_pump_.reset(new AudioPump( |
337 audio_task_runner_, desktop_environment_->CreateAudioCapturer(), | 341 audio_task_runner_, desktop_environment_->CreateAudioCapturer(), |
338 std::move(audio_encoder), connection_->audio_stub())); | 342 std::move(audio_encoder), connection_->audio_stub())); |
339 } | 343 } |
340 | 344 |
345 if (pending_video_layout_message_) { | |
346 connection_->client_stub()->SetVideoLayout(*pending_video_layout_message_); | |
347 pending_video_layout_message_.reset(); | |
348 } | |
349 | |
341 // Notify the event handler that all our channels are now connected. | 350 // Notify the event handler that all our channels are now connected. |
342 event_handler_->OnSessionChannelsConnected(this); | 351 event_handler_->OnSessionChannelsConnected(this); |
343 } | 352 } |
344 | 353 |
345 void ClientSession::OnConnectionClosed( | 354 void ClientSession::OnConnectionClosed( |
346 protocol::ConnectionToClient* connection, | 355 protocol::ConnectionToClient* connection, |
347 protocol::ErrorCode error) { | 356 protocol::ErrorCode error) { |
348 DCHECK(CalledOnValidThread()); | 357 DCHECK(CalledOnValidThread()); |
349 DCHECK_EQ(connection_.get(), connection); | 358 DCHECK_EQ(connection_.get(), connection); |
350 | 359 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 if (connection_->session()->config().protocol() == | 450 if (connection_->session()->config().protocol() == |
442 protocol::SessionConfig::Protocol::WEBRTC) { | 451 protocol::SessionConfig::Protocol::WEBRTC) { |
443 protocol::VideoLayout layout; | 452 protocol::VideoLayout layout; |
444 protocol::VideoTrackLayout* video_track = layout.add_video_track(); | 453 protocol::VideoTrackLayout* video_track = layout.add_video_track(); |
445 video_track->set_position_x(0); | 454 video_track->set_position_x(0); |
446 video_track->set_position_y(0); | 455 video_track->set_position_y(0); |
447 video_track->set_width(size.width() * kDefaultDpi / dpi.x()); | 456 video_track->set_width(size.width() * kDefaultDpi / dpi.x()); |
448 video_track->set_height(size.height() * kDefaultDpi / dpi.y()); | 457 video_track->set_height(size.height() * kDefaultDpi / dpi.y()); |
449 video_track->set_x_dpi(dpi.x()); | 458 video_track->set_x_dpi(dpi.x()); |
450 video_track->set_y_dpi(dpi.y()); | 459 video_track->set_y_dpi(dpi.y()); |
451 connection_->client_stub()->SetVideoLayout(layout); | 460 |
461 // VideoLayout can be sent only after the control channel is connected. This | |
462 // is necessary for the case in the future. | |
Jamie
2016/04/05 21:46:35
I don't understand this second sentence. Are you s
Sergey Ulanov
2016/04/06 21:23:50
I don't understand it either :-/. Removed.
| |
463 if (channels_connected_) { | |
464 connection_->client_stub()->SetVideoLayout(layout); | |
465 } else { | |
466 pending_video_layout_message_.reset(new protocol::VideoLayout(layout)); | |
467 } | |
452 } | 468 } |
453 } | 469 } |
454 | 470 |
455 } // namespace remoting | 471 } // namespace remoting |
OLD | NEW |