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