blob: 933ded3e4748c51d4895e3d01d2f4bf9ec7ed012 [file] [log] [blame]
[email protected]91e4b7f62012-01-25 23:23:021// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]44f60762011-03-23 12:13:352// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "remoting/host/client_session.h"
6
[email protected]4fe827a2011-08-10 03:30:197#include <algorithm>
8
[email protected]7ccb7072013-06-10 20:56:289#include "base/message_loop/message_loop_proxy.h"
[email protected]a5d181f2013-04-19 14:55:3710#include "remoting/base/capabilities.h"
[email protected]170cba42012-09-12 22:28:3911#include "remoting/codec/audio_encoder.h"
[email protected]a6ccb7722012-10-23 21:10:4312#include "remoting/codec/audio_encoder_opus.h"
[email protected]170cba42012-09-12 22:28:3913#include "remoting/codec/audio_encoder_speex.h"
14#include "remoting/codec/audio_encoder_verbatim.h"
15#include "remoting/codec/video_encoder.h"
[email protected]2149bef2012-10-18 03:26:5316#include "remoting/codec/video_encoder_verbatim.h"
[email protected]170cba42012-09-12 22:28:3917#include "remoting/codec/video_encoder_vp8.h"
[email protected]ce404ca2013-01-16 17:23:5318#include "remoting/host/audio_capturer.h"
[email protected]170cba42012-09-12 22:28:3919#include "remoting/host/audio_scheduler.h"
20#include "remoting/host/desktop_environment.h"
[email protected]b0b72f112013-03-24 03:42:4221#include "remoting/host/input_injector.h"
[email protected]231316a2013-03-25 06:01:1222#include "remoting/host/screen_controls.h"
[email protected]739e2802013-03-18 01:03:4823#include "remoting/host/screen_resolution.h"
[email protected]2ce80252012-10-26 07:23:1224#include "remoting/host/video_scheduler.h"
[email protected]50d71c72012-05-03 01:28:5525#include "remoting/proto/control.pb.h"
[email protected]c78669c92011-06-13 22:42:3826#include "remoting/proto/event.pb.h"
[email protected]ff3761a12012-05-22 22:29:2427#include "remoting/protocol/client_stub.h"
[email protected]7f44ba42012-05-31 20:26:2928#include "remoting/protocol/clipboard_thread_proxy.h"
[email protected]88356922013-06-04 06:26:0129#include "remoting/protocol/pairing_registry.h"
[email protected]3aef7222013-06-07 22:39:5030#include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
[email protected]c78669c92011-06-13 22:42:3831
[email protected]48a8ca32013-02-13 04:31:0132// Default DPI to assume for old clients that use notifyClientDimensions.
33const int kDefaultDPI = 96;
[email protected]739e2802013-03-18 01:03:4834
35namespace remoting {
[email protected]48a8ca32013-02-13 04:31:0136
[email protected]44f60762011-03-23 12:13:3537ClientSession::ClientSession(
38 EventHandler* event_handler,
[email protected]032d9dd2012-11-01 17:55:0439 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
[email protected]ce404ca2013-01-16 17:23:5340 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
[email protected]16dbfb0e2012-11-14 04:11:1941 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner,
42 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner,
[email protected]170cba42012-09-12 22:28:3943 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
[email protected]ce404ca2013-01-16 17:23:5344 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
[email protected]3361e1f2012-03-20 20:31:4445 scoped_ptr<protocol::ConnectionToClient> connection,
[email protected]81904792012-10-18 04:16:2846 DesktopEnvironmentFactory* desktop_environment_factory,
[email protected]88356922013-06-04 06:26:0147 const base::TimeDelta& max_duration,
48 scoped_refptr<protocol::PairingRegistry> pairing_registry)
[email protected]44f60762011-03-23 12:13:3549 : event_handler_(event_handler),
[email protected]3361e1f2012-03-20 20:31:4450 connection_(connection.Pass()),
51 client_jid_(connection_->session()->jid()),
[email protected]aa46ba52013-04-27 00:00:4452 control_factory_(this),
[email protected]233bb942013-03-15 07:18:1753 desktop_environment_factory_(desktop_environment_factory),
[email protected]eccc2d42013-01-10 19:35:1454 input_tracker_(&host_input_filter_),
[email protected]86cbe6b2012-04-03 00:56:1855 remote_input_filter_(&input_tracker_),
[email protected]58f1ad42013-01-10 23:49:5156 mouse_clamping_filter_(&remote_input_filter_),
[email protected]eccc2d42013-01-10 19:35:1457 disable_input_filter_(mouse_clamping_filter_.input_filter()),
[email protected]750ae6b2012-08-20 22:52:4058 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()),
59 auth_input_filter_(&disable_input_filter_),
60 auth_clipboard_filter_(&disable_clipboard_filter_),
[email protected]7f44ba42012-05-31 20:26:2961 client_clipboard_factory_(clipboard_echo_filter_.client_filter()),
[email protected]170cba42012-09-12 22:28:3962 max_duration_(max_duration),
[email protected]032d9dd2012-11-01 17:55:0463 audio_task_runner_(audio_task_runner),
[email protected]ce404ca2013-01-16 17:23:5364 input_task_runner_(input_task_runner),
[email protected]16dbfb0e2012-11-14 04:11:1965 video_capture_task_runner_(video_capture_task_runner),
66 video_encode_task_runner_(video_encode_task_runner),
[email protected]170cba42012-09-12 22:28:3967 network_task_runner_(network_task_runner),
[email protected]88356922013-06-04 06:26:0168 ui_task_runner_(ui_task_runner),
69 pairing_registry_(pairing_registry) {
[email protected]ee910fd2011-11-10 18:23:3170 connection_->SetEventHandler(this);
71
72 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be
73 // set before channels are connected. Make it possible to set stubs
74 // later and set them only when connection is authenticated.
[email protected]34df2ab2012-08-19 06:54:2375 connection_->set_clipboard_stub(&auth_clipboard_filter_);
[email protected]ee910fd2011-11-10 18:23:3176 connection_->set_host_stub(this);
[email protected]880c6cd2012-08-21 04:35:0777 connection_->set_input_stub(&auth_input_filter_);
[email protected]750ae6b2012-08-20 22:52:4078
79 // |auth_*_filter_|'s states reflect whether the session is authenticated.
80 auth_input_filter_.set_enabled(false);
81 auth_clipboard_filter_.set_enabled(false);
[email protected]2f4084892013-02-25 20:30:2082
83#if defined(OS_WIN)
84 // LocalInputMonitorWin filters out an echo of the injected input before it
85 // reaches |remote_input_filter_|.
86 remote_input_filter_.SetExpectLocalEcho(false);
87#endif // defined(OS_WIN)
[email protected]44f60762011-03-23 12:13:3588}
89
[email protected]f19f09ca2013-03-13 11:10:2990ClientSession::~ClientSession() {
91 DCHECK(CalledOnValidThread());
[email protected]f9d8a772013-06-01 04:33:1792 DCHECK(!audio_scheduler_.get());
[email protected]231316a2013-03-25 06:01:1293 DCHECK(!desktop_environment_);
[email protected]b0b72f112013-03-24 03:42:4294 DCHECK(!input_injector_);
[email protected]231316a2013-03-25 06:01:1295 DCHECK(!screen_controls_);
[email protected]f9d8a772013-06-01 04:33:1796 DCHECK(!video_scheduler_.get());
[email protected]f19f09ca2013-03-13 11:10:2997
98 connection_.reset();
99}
100
[email protected]48a8ca32013-02-13 04:31:01101void ClientSession::NotifyClientResolution(
102 const protocol::ClientResolution& resolution) {
[email protected]a5d181f2013-04-19 14:55:37103 DCHECK(CalledOnValidThread());
104
[email protected]b9ed58f2013-05-16 10:45:24105 // TODO(sergeyu): Move these checks to protocol layer.
106 if (!resolution.has_dips_width() || !resolution.has_dips_height() ||
107 resolution.dips_width() < 0 || resolution.dips_height() < 0 ||
108 resolution.width() <= 0 || resolution.height() <= 0) {
109 LOG(ERROR) << "Received invalid ClientResolution message.";
[email protected]739e2802013-03-18 01:03:48110 return;
[email protected]b9ed58f2013-05-16 10:45:24111 }
[email protected]739e2802013-03-18 01:03:48112
113 VLOG(1) << "Received ClientResolution (dips_width="
114 << resolution.dips_width() << ", dips_height="
115 << resolution.dips_height() << ")";
116
[email protected]231316a2013-03-25 06:01:12117 if (!screen_controls_)
[email protected]739e2802013-03-18 01:03:48118 return;
119
120 ScreenResolution client_resolution(
[email protected]b9ed58f2013-05-16 10:45:24121 webrtc::DesktopSize(resolution.dips_width(), resolution.dips_height()),
122 webrtc::DesktopVector(kDefaultDPI, kDefaultDPI));
[email protected]739e2802013-03-18 01:03:48123
124 // Try to match the client's resolution.
[email protected]b9ed58f2013-05-16 10:45:24125 screen_controls_->SetScreenResolution(client_resolution);
[email protected]50d71c72012-05-03 01:28:55126}
127
128void ClientSession::ControlVideo(const protocol::VideoControl& video_control) {
[email protected]a5d181f2013-04-19 14:55:37129 DCHECK(CalledOnValidThread());
130
[email protected]50d71c72012-05-03 01:28:55131 if (video_control.has_enable()) {
132 VLOG(1) << "Received VideoControl (enable="
133 << video_control.enable() << ")";
[email protected]324b1962013-05-01 19:30:22134 video_scheduler_->Pause(!video_control.enable());
[email protected]50d71c72012-05-03 01:28:55135 }
[email protected]f2b9cf32012-04-27 00:13:43136}
137
[email protected]f458bed2012-10-18 03:27:59138void ClientSession::ControlAudio(const protocol::AudioControl& audio_control) {
[email protected]a5d181f2013-04-19 14:55:37139 DCHECK(CalledOnValidThread());
140
[email protected]f458bed2012-10-18 03:27:59141 if (audio_control.has_enable()) {
142 VLOG(1) << "Received AudioControl (enable="
143 << audio_control.enable() << ")";
[email protected]f9d8a772013-06-01 04:33:17144 if (audio_scheduler_.get())
[email protected]ce404ca2013-01-16 17:23:53145 audio_scheduler_->Pause(!audio_control.enable());
[email protected]f458bed2012-10-18 03:27:59146 }
147}
148
[email protected]a5d181f2013-04-19 14:55:37149void ClientSession::SetCapabilities(
150 const protocol::Capabilities& capabilities) {
151 DCHECK(CalledOnValidThread());
152
153 // The client should not send protocol::Capabilities if it is not supported by
154 // the config channel.
155 if (!connection_->session()->config().SupportsCapabilities()) {
156 LOG(ERROR) << "Unexpected protocol::Capabilities has been received.";
157 return;
158 }
159
160 // Ignore all the messages but the 1st one.
161 if (client_capabilities_) {
162 LOG(WARNING) << "protocol::Capabilities has been received already.";
163 return;
164 }
165
166 client_capabilities_ = make_scoped_ptr(new std::string());
167 if (capabilities.has_capabilities())
168 *client_capabilities_ = capabilities.capabilities();
169
170 VLOG(1) << "Client capabilities: " << *client_capabilities_;
171
172 // Calculate the set of capabilities enabled by both client and host and
173 // pass it to the desktop environment if it is available.
[email protected]324b1962013-05-01 19:30:22174 desktop_environment_->SetCapabilities(
175 IntersectCapabilities(*client_capabilities_, host_capabilities_));
[email protected]a5d181f2013-04-19 14:55:37176}
177
[email protected]88356922013-06-04 06:26:01178void ClientSession::RequestPairing(
179 const protocol::PairingRequest& pairing_request) {
180 if (pairing_request.has_client_name()) {
181 protocol::PairingRegistry::Pairing pairing =
182 pairing_registry_->CreatePairing(pairing_request.client_name());
183 protocol::PairingResponse pairing_response;
[email protected]df5189f2013-06-18 12:12:05184 pairing_response.set_client_id(pairing.client_id());
185 pairing_response.set_shared_secret(pairing.shared_secret());
[email protected]88356922013-06-04 06:26:01186 connection_->client_stub()->SetPairingResponse(pairing_response);
187 }
188}
189
[email protected]09eabd65c2013-08-13 00:13:48190void ClientSession::DeliverClientMessage(
191 const protocol::ExtensionMessage& message) {
192 // No messages are currently supported.
193 LOG(INFO) << "Unexpected message received: "
194 << message.type() << ": " << message.data();
195}
196
[email protected]cba6f812012-03-27 01:01:50197void ClientSession::OnConnectionAuthenticated(
[email protected]ee910fd2011-11-10 18:23:31198 protocol::ConnectionToClient* connection) {
[email protected]86cbe6b2012-04-03 00:56:18199 DCHECK(CalledOnValidThread());
200 DCHECK_EQ(connection_.get(), connection);
[email protected]f9d8a772013-06-01 04:33:17201 DCHECK(!audio_scheduler_.get());
[email protected]a5d181f2013-04-19 14:55:37202 DCHECK(!desktop_environment_);
[email protected]324b1962013-05-01 19:30:22203 DCHECK(!input_injector_);
204 DCHECK(!screen_controls_);
[email protected]f9d8a772013-06-01 04:33:17205 DCHECK(!video_scheduler_.get());
[email protected]34df2ab2012-08-19 06:54:23206
[email protected]750ae6b2012-08-20 22:52:40207 auth_input_filter_.set_enabled(true);
208 auth_clipboard_filter_.set_enabled(true);
[email protected]34df2ab2012-08-19 06:54:23209
[email protected]ff3761a12012-05-22 22:29:24210 clipboard_echo_filter_.set_client_stub(connection_->client_stub());
[email protected]58f1ad42013-01-10 23:49:51211 mouse_clamping_filter_.set_video_stub(connection_->video_stub());
[email protected]34df2ab2012-08-19 06:54:23212
[email protected]5dc5b12a2012-06-23 01:05:14213 if (max_duration_ > base::TimeDelta()) {
214 // TODO(simonmorris): Let Disconnect() tell the client that the
215 // disconnection was caused by the session exceeding its maximum duration.
216 max_duration_timer_.Start(FROM_HERE, max_duration_,
[email protected]231316a2013-03-25 06:01:12217 this, &ClientSession::DisconnectSession);
[email protected]5dc5b12a2012-06-23 01:05:14218 }
[email protected]34df2ab2012-08-19 06:54:23219
[email protected]324b1962013-05-01 19:30:22220 // Disconnect the session if the connection was rejected by the host.
221 if (!event_handler_->OnSessionAuthenticated(this)) {
222 DisconnectSession();
223 return;
224 }
[email protected]ce404ca2013-01-16 17:23:53225
[email protected]96361d02013-05-08 18:26:18226 // Create the desktop environment. Drop the connection if it could not be
227 // created for any reason (for instance the curtain could not initialize).
[email protected]231316a2013-03-25 06:01:12228 desktop_environment_ =
229 desktop_environment_factory_->Create(control_factory_.GetWeakPtr());
[email protected]96361d02013-05-08 18:26:18230 if (!desktop_environment_) {
231 DisconnectSession();
232 return;
233 }
234
[email protected]a5d181f2013-04-19 14:55:37235 host_capabilities_ = desktop_environment_->GetCapabilities();
236
[email protected]324b1962013-05-01 19:30:22237 // Ignore protocol::Capabilities messages from the client if it does not
238 // support any capabilities.
239 if (!connection_->session()->config().SupportsCapabilities()) {
[email protected]a5d181f2013-04-19 14:55:37240 VLOG(1) << "The client does not support any capabilities.";
241
242 client_capabilities_ = make_scoped_ptr(new std::string());
243 desktop_environment_->SetCapabilities(*client_capabilities_);
244 }
[email protected]233bb942013-03-15 07:18:17245
[email protected]231316a2013-03-25 06:01:12246 // Create the object that controls the screen resolution.
247 screen_controls_ = desktop_environment_->CreateScreenControls();
[email protected]61cfdc52013-03-09 03:04:56248
[email protected]324b1962013-05-01 19:30:22249 // Create the event executor.
[email protected]231316a2013-03-25 06:01:12250 input_injector_ = desktop_environment_->CreateInputInjector();
[email protected]eccc2d42013-01-10 19:35:14251
252 // Connect the host clipboard and input stubs.
[email protected]b0b72f112013-03-24 03:42:42253 host_input_filter_.set_input_stub(input_injector_.get());
254 clipboard_echo_filter_.set_host_stub(input_injector_.get());
[email protected]eccc2d42013-01-10 19:35:14255
[email protected]2ce80252012-10-26 07:23:12256 // Create a VideoEncoder based on the session's video channel configuration.
257 scoped_ptr<VideoEncoder> video_encoder =
[email protected]170cba42012-09-12 22:28:39258 CreateVideoEncoder(connection_->session()->config());
[email protected]2ce80252012-10-26 07:23:12259
[email protected]cdd1c9e2012-10-26 21:14:04260 // Create a VideoScheduler to pump frames from the capturer to the client.
[email protected]324b1962013-05-01 19:30:22261 video_scheduler_ = new VideoScheduler(
[email protected]c18ad892012-12-08 03:39:24262 video_capture_task_runner_,
263 video_encode_task_runner_,
264 network_task_runner_,
[email protected]231316a2013-03-25 06:01:12265 desktop_environment_->CreateVideoCapturer(),
[email protected]c18ad892012-12-08 03:39:24266 video_encoder.Pass(),
267 connection_->client_stub(),
[email protected]eccc2d42013-01-10 19:35:14268 &mouse_clamping_filter_);
[email protected]170cba42012-09-12 22:28:39269
[email protected]cdd1c9e2012-10-26 21:14:04270 // Create an AudioScheduler if audio is enabled, to pump audio samples.
[email protected]170cba42012-09-12 22:28:39271 if (connection_->session()->config().is_audio_enabled()) {
272 scoped_ptr<AudioEncoder> audio_encoder =
273 CreateAudioEncoder(connection_->session()->config());
[email protected]324b1962013-05-01 19:30:22274 audio_scheduler_ = new AudioScheduler(
[email protected]032d9dd2012-11-01 17:55:04275 audio_task_runner_,
[email protected]170cba42012-09-12 22:28:39276 network_task_runner_,
[email protected]231316a2013-03-25 06:01:12277 desktop_environment_->CreateAudioCapturer(),
[email protected]170cba42012-09-12 22:28:39278 audio_encoder.Pass(),
279 connection_->audio_stub());
[email protected]170cba42012-09-12 22:28:39280 }
[email protected]324b1962013-05-01 19:30:22281}
282
283void ClientSession::OnConnectionChannelsConnected(
284 protocol::ConnectionToClient* connection) {
285 DCHECK(CalledOnValidThread());
286 DCHECK_EQ(connection_.get(), connection);
287
288 // Negotiate capabilities with the client.
289 if (connection_->session()->config().SupportsCapabilities()) {
290 VLOG(1) << "Host capabilities: " << host_capabilities_;
291
292 protocol::Capabilities capabilities;
293 capabilities.set_capabilities(host_capabilities_);
294 connection_->client_stub()->SetCapabilities(capabilities);
295 }
296
297 // Start the event executor.
298 input_injector_->Start(CreateClipboardProxy());
299 SetDisableInputs(false);
300
301 // Start capturing the screen.
302 video_scheduler_->Start();
303
304 // Start recording audio.
305 if (connection_->session()->config().is_audio_enabled())
306 audio_scheduler_->Start();
[email protected]170cba42012-09-12 22:28:39307
[email protected]cdd1c9e2012-10-26 21:14:04308 // Notify the event handler that all our channels are now connected.
[email protected]cba6f812012-03-27 01:01:50309 event_handler_->OnSessionChannelsConnected(this);
[email protected]ee910fd2011-11-10 18:23:31310}
311
[email protected]cba6f812012-03-27 01:01:50312void ClientSession::OnConnectionClosed(
[email protected]1f249e22011-11-29 20:19:59313 protocol::ConnectionToClient* connection,
[email protected]204a9e32012-03-02 05:42:58314 protocol::ErrorCode error) {
[email protected]ec6411872011-11-11 03:28:55315 DCHECK(CalledOnValidThread());
[email protected]ee910fd2011-11-10 18:23:31316 DCHECK_EQ(connection_.get(), connection);
[email protected]750ae6b2012-08-20 22:52:40317
[email protected]231316a2013-03-25 06:01:12318 // Ignore any further callbacks.
319 control_factory_.InvalidateWeakPtrs();
[email protected]a031c972012-12-27 20:10:40320
[email protected]24a2a9d22012-12-07 09:06:47321 // If the client never authenticated then the session failed.
[email protected]750ae6b2012-08-20 22:52:40322 if (!auth_input_filter_.enabled())
[email protected]1f249e22011-11-29 20:19:59323 event_handler_->OnSessionAuthenticationFailed(this);
[email protected]750ae6b2012-08-20 22:52:40324
325 // Block any further input events from the client.
326 // TODO(wez): Fix ChromotingHost::OnSessionClosed not to check our
327 // is_authenticated(), so that we can disable |auth_*_filter_| here.
328 disable_input_filter_.set_enabled(false);
329 disable_clipboard_filter_.set_enabled(false);
[email protected]86cbe6b2012-04-03 00:56:18330
331 // Ensure that any pressed keys or buttons are released.
332 input_tracker_.ReleaseAll();
333
[email protected]24a2a9d22012-12-07 09:06:47334 // Stop components access the client, audio or video stubs, which are no
335 // longer valid once ConnectionToClient calls OnConnectionClosed().
[email protected]f9d8a772013-06-01 04:33:17336 if (audio_scheduler_.get()) {
[email protected]ce404ca2013-01-16 17:23:53337 audio_scheduler_->Stop();
[email protected]24a2a9d22012-12-07 09:06:47338 audio_scheduler_ = NULL;
339 }
[email protected]f9d8a772013-06-01 04:33:17340 if (video_scheduler_.get()) {
[email protected]ce404ca2013-01-16 17:23:53341 video_scheduler_->Stop();
[email protected]24a2a9d22012-12-07 09:06:47342 video_scheduler_ = NULL;
343 }
[email protected]ce404ca2013-01-16 17:23:53344
[email protected]24a2a9d22012-12-07 09:06:47345 client_clipboard_factory_.InvalidateWeakPtrs();
[email protected]b0b72f112013-03-24 03:42:42346 input_injector_.reset();
[email protected]231316a2013-03-25 06:01:12347 screen_controls_.reset();
348 desktop_environment_.reset();
[email protected]24a2a9d22012-12-07 09:06:47349
350 // Notify the ChromotingHost that this client is disconnected.
[email protected]ee910fd2011-11-10 18:23:31351 // TODO(sergeyu): Log failure reason?
[email protected]ee910fd2011-11-10 18:23:31352 event_handler_->OnSessionClosed(this);
[email protected]ee910fd2011-11-10 18:23:31353}
354
355void ClientSession::OnSequenceNumberUpdated(
356 protocol::ConnectionToClient* connection, int64 sequence_number) {
[email protected]ec6411872011-11-11 03:28:55357 DCHECK(CalledOnValidThread());
[email protected]ee910fd2011-11-10 18:23:31358 DCHECK_EQ(connection_.get(), connection);
[email protected]170cba42012-09-12 22:28:39359
[email protected]f9d8a772013-06-01 04:33:17360 if (video_scheduler_.get())
[email protected]2ce80252012-10-26 07:23:12361 video_scheduler_->UpdateSequenceNumber(sequence_number);
[email protected]170cba42012-09-12 22:28:39362
[email protected]ee910fd2011-11-10 18:23:31363 event_handler_->OnSessionSequenceNumber(this, sequence_number);
364}
365
[email protected]17af2ab2012-02-02 04:07:52366void ClientSession::OnRouteChange(
367 protocol::ConnectionToClient* connection,
368 const std::string& channel_name,
[email protected]be451c82012-03-20 22:24:47369 const protocol::TransportRoute& route) {
[email protected]91e4b7f62012-01-25 23:23:02370 DCHECK(CalledOnValidThread());
371 DCHECK_EQ(connection_.get(), connection);
[email protected]be451c82012-03-20 22:24:47372 event_handler_->OnSessionRouteChange(this, channel_name, route);
[email protected]91e4b7f62012-01-25 23:23:02373}
374
[email protected]231316a2013-03-25 06:01:12375const std::string& ClientSession::client_jid() const {
376 return client_jid_;
377}
378
379void ClientSession::DisconnectSession() {
[email protected]ec6411872011-11-11 03:28:55380 DCHECK(CalledOnValidThread());
381 DCHECK(connection_.get());
[email protected]a46bcef2011-11-11 01:27:23382
[email protected]5dc5b12a2012-06-23 01:05:14383 max_duration_timer_.Stop();
[email protected]24a2a9d22012-12-07 09:06:47384
[email protected]86cbe6b2012-04-03 00:56:18385 // This triggers OnConnectionClosed(), and the session may be destroyed
[email protected]a46bcef2011-11-11 01:27:23386 // as the result, so this call must be the last in this method.
387 connection_->Disconnect();
[email protected]44f60762011-03-23 12:13:35388}
389
[email protected]231316a2013-03-25 06:01:12390void ClientSession::OnLocalMouseMoved(const SkIPoint& position) {
[email protected]ec6411872011-11-11 03:28:55391 DCHECK(CalledOnValidThread());
[email protected]231316a2013-03-25 06:01:12392 remote_input_filter_.LocalMouseMoved(position);
[email protected]86cbe6b2012-04-03 00:56:18393}
[email protected]ec6411872011-11-11 03:28:55394
[email protected]86cbe6b2012-04-03 00:56:18395void ClientSession::SetDisableInputs(bool disable_inputs) {
396 DCHECK(CalledOnValidThread());
397
[email protected]750ae6b2012-08-20 22:52:40398 if (disable_inputs)
[email protected]86cbe6b2012-04-03 00:56:18399 input_tracker_.ReleaseAll();
[email protected]750ae6b2012-08-20 22:52:40400
401 disable_input_filter_.set_enabled(!disable_inputs);
402 disable_clipboard_filter_.set_enabled(!disable_inputs);
[email protected]c78669c92011-06-13 22:42:38403}
404
[email protected]7f44ba42012-05-31 20:26:29405scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() {
406 DCHECK(CalledOnValidThread());
407
408 return scoped_ptr<protocol::ClipboardStub>(
409 new protocol::ClipboardThreadProxy(
410 client_clipboard_factory_.GetWeakPtr(),
411 base::MessageLoopProxy::current()));
412}
413
[email protected]170cba42012-09-12 22:28:39414// TODO(sergeyu): Move this to SessionManager?
415// static
[email protected]2ce80252012-10-26 07:23:12416scoped_ptr<VideoEncoder> ClientSession::CreateVideoEncoder(
[email protected]170cba42012-09-12 22:28:39417 const protocol::SessionConfig& config) {
418 const protocol::ChannelConfig& video_config = config.video_config();
419
420 if (video_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) {
[email protected]2ce80252012-10-26 07:23:12421 return scoped_ptr<VideoEncoder>(new remoting::VideoEncoderVerbatim());
[email protected]170cba42012-09-12 22:28:39422 } else if (video_config.codec == protocol::ChannelConfig::CODEC_VP8) {
[email protected]2ce80252012-10-26 07:23:12423 return scoped_ptr<VideoEncoder>(new remoting::VideoEncoderVp8());
[email protected]170cba42012-09-12 22:28:39424 }
425
426 NOTIMPLEMENTED();
[email protected]3c2dc952013-06-14 00:35:13427 return scoped_ptr<VideoEncoder>();
[email protected]170cba42012-09-12 22:28:39428}
429
430// static
431scoped_ptr<AudioEncoder> ClientSession::CreateAudioEncoder(
432 const protocol::SessionConfig& config) {
433 const protocol::ChannelConfig& audio_config = config.audio_config();
434
435 if (audio_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) {
436 return scoped_ptr<AudioEncoder>(new AudioEncoderVerbatim());
437 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_SPEEX) {
438 return scoped_ptr<AudioEncoder>(new AudioEncoderSpeex());
[email protected]a6ccb7722012-10-23 21:10:43439 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) {
440 return scoped_ptr<AudioEncoder>(new AudioEncoderOpus());
[email protected]170cba42012-09-12 22:28:39441 }
442
443 NOTIMPLEMENTED();
[email protected]3c2dc952013-06-14 00:35:13444 return scoped_ptr<AudioEncoder>();
[email protected]170cba42012-09-12 22:28:39445}
446
[email protected]44f60762011-03-23 12:13:35447} // namespace remoting