Index: remoting/host/client_session.cc |
diff --git a/remoting/host/client_session.cc b/remoting/host/client_session.cc |
index 58320c9f4101ff7a628d0235730d2cd4d2cf619e..e98feafccc325f6b25c2148c41f19d8198aa53d8 100644 |
--- a/remoting/host/client_session.cc |
+++ b/remoting/host/client_session.cc |
@@ -15,6 +15,7 @@ |
#include "remoting/codec/video_encoder.h" |
#include "remoting/codec/video_encoder_verbatim.h" |
#include "remoting/codec/video_encoder_vp8.h" |
+#include "remoting/host/audio_capturer.h" |
#include "remoting/host/audio_scheduler.h" |
#include "remoting/host/desktop_environment.h" |
#include "remoting/host/desktop_environment_factory.h" |
@@ -30,17 +31,22 @@ namespace remoting { |
ClientSession::ClientSession( |
EventHandler* event_handler, |
scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
+ scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, |
scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, |
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
scoped_ptr<protocol::ConnectionToClient> connection, |
DesktopEnvironmentFactory* desktop_environment_factory, |
const base::TimeDelta& max_duration) |
: event_handler_(event_handler), |
connection_(connection.Pass()), |
connection_factory_(connection_.get()), |
- desktop_environment_(desktop_environment_factory->Create()), |
client_jid_(connection_->session()->jid()), |
+ desktop_environment_(desktop_environment_factory->Create( |
+ client_jid_, |
+ base::Bind(&protocol::ConnectionToClient::Disconnect, |
+ connection_factory_.GetWeakPtr()))), |
input_tracker_(&host_input_filter_), |
remote_input_filter_(&input_tracker_), |
mouse_clamping_filter_(&remote_input_filter_, connection_->video_stub()), |
@@ -51,10 +57,11 @@ ClientSession::ClientSession( |
client_clipboard_factory_(clipboard_echo_filter_.client_filter()), |
max_duration_(max_duration), |
audio_task_runner_(audio_task_runner), |
+ input_task_runner_(input_task_runner), |
video_capture_task_runner_(video_capture_task_runner), |
video_encode_task_runner_(video_encode_task_runner), |
network_task_runner_(network_task_runner), |
- active_recorders_(0) { |
+ ui_task_runner_(ui_task_runner) { |
connection_->SetEventHandler(this); |
// TODO(sergeyu): Currently ConnectionToClient expects stubs to be |
@@ -83,9 +90,8 @@ void ClientSession::ControlVideo(const protocol::VideoControl& video_control) { |
if (video_control.has_enable()) { |
VLOG(1) << "Received VideoControl (enable=" |
<< video_control.enable() << ")"; |
- if (video_scheduler_.get()) { |
+ if (video_scheduler_.get()) |
video_scheduler_->Pause(!video_control.enable()); |
- } |
} |
} |
@@ -93,9 +99,8 @@ void ClientSession::ControlAudio(const protocol::AudioControl& audio_control) { |
if (audio_control.has_enable()) { |
VLOG(1) << "Received AudioControl (enable=" |
<< audio_control.enable() << ")"; |
- if (audio_scheduler_.get()) { |
- audio_scheduler_->SetEnabled(audio_control.enable()); |
- } |
+ if (audio_scheduler_.get()) |
+ audio_scheduler_->Pause(!audio_control.enable()); |
} |
} |
@@ -123,20 +128,21 @@ void ClientSession::OnConnectionChannelsConnected( |
protocol::ConnectionToClient* connection) { |
DCHECK(CalledOnValidThread()); |
DCHECK_EQ(connection_.get(), connection); |
+ DCHECK(!audio_scheduler_.get()); |
+ DCHECK(!event_executor_); |
+ DCHECK(!video_scheduler_.get()); |
+ |
+ // Create and start the event executor. |
+ event_executor_ = desktop_environment_->CreateEventExecutor( |
+ input_task_runner_, ui_task_runner_); |
+ event_executor_->Start(CreateClipboardProxy()); |
// Connect the host clipboard and input stubs. |
- host_input_filter_.set_input_stub(desktop_environment_->event_executor()); |
- clipboard_echo_filter_.set_host_stub(desktop_environment_->event_executor()); |
+ host_input_filter_.set_input_stub(event_executor_.get()); |
+ clipboard_echo_filter_.set_host_stub(event_executor_.get()); |
SetDisableInputs(false); |
- // Let the desktop environment notify us of local clipboard changes. |
- desktop_environment_->Start( |
- CreateClipboardProxy(), |
- client_jid(), |
- base::Bind(&protocol::ConnectionToClient::Disconnect, |
- connection_factory_.GetWeakPtr())); |
- |
// Create a VideoEncoder based on the session's video channel configuration. |
scoped_ptr<VideoEncoder> video_encoder = |
CreateVideoEncoder(connection_->session()->config()); |
@@ -146,11 +152,11 @@ void ClientSession::OnConnectionChannelsConnected( |
video_capture_task_runner_, |
video_encode_task_runner_, |
network_task_runner_, |
- desktop_environment_->video_capturer(), |
+ desktop_environment_->CreateVideoCapturer(video_capture_task_runner_, |
+ video_encode_task_runner_), |
video_encoder.Pass(), |
connection_->client_stub(), |
&mouse_clamping_filter_); |
- ++active_recorders_; |
// Create an AudioScheduler if audio is enabled, to pump audio samples. |
if (connection_->session()->config().is_audio_enabled()) { |
@@ -159,10 +165,9 @@ void ClientSession::OnConnectionChannelsConnected( |
audio_scheduler_ = AudioScheduler::Create( |
audio_task_runner_, |
network_task_runner_, |
- desktop_environment_->audio_capturer(), |
+ desktop_environment_->CreateAudioCapturer(audio_task_runner_), |
audio_encoder.Pass(), |
connection_->audio_stub()); |
- ++active_recorders_; |
} |
// Notify the event handler that all our channels are now connected. |
@@ -194,14 +199,17 @@ void ClientSession::OnConnectionClosed( |
// Stop components access the client, audio or video stubs, which are no |
// longer valid once ConnectionToClient calls OnConnectionClosed(). |
if (audio_scheduler_.get()) { |
- audio_scheduler_->Stop(base::Bind(&ClientSession::OnRecorderStopped, this)); |
+ audio_scheduler_->Stop(); |
audio_scheduler_ = NULL; |
} |
if (video_scheduler_.get()) { |
- video_scheduler_->Stop(base::Bind(&ClientSession::OnRecorderStopped, this)); |
+ video_scheduler_->Stop(); |
video_scheduler_ = NULL; |
} |
+ |
client_clipboard_factory_.InvalidateWeakPtrs(); |
+ event_executor_.reset(); |
+ desktop_environment_.reset(); |
// Notify the ChromotingHost that this client is disconnected. |
// TODO(sergeyu): Log failure reason? |
@@ -239,21 +247,14 @@ void ClientSession::Disconnect() { |
connection_->Disconnect(); |
} |
-void ClientSession::Stop(const base::Closure& stopped_task) { |
+void ClientSession::Stop() { |
DCHECK(CalledOnValidThread()); |
- DCHECK(stopped_task_.is_null()); |
- DCHECK(!stopped_task.is_null()); |
DCHECK(audio_scheduler_.get() == NULL); |
+ DCHECK(!desktop_environment_); |
+ DCHECK(!event_executor_); |
DCHECK(video_scheduler_.get() == NULL); |
- stopped_task_ = stopped_task; |
- |
- if (active_recorders_ == 0) { |
- // |stopped_task_| may tear down the signalling layer, so tear-down |
- // |connection_| before invoking it. |
- connection_.reset(); |
- stopped_task_.Run(); |
- } |
+ connection_.reset(); |
} |
void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { |
@@ -272,8 +273,9 @@ void ClientSession::SetDisableInputs(bool disable_inputs) { |
} |
ClientSession::~ClientSession() { |
- DCHECK_EQ(active_recorders_, 0); |
DCHECK(audio_scheduler_.get() == NULL); |
+ DCHECK(!desktop_environment_); |
+ DCHECK(!event_executor_); |
DCHECK(video_scheduler_.get() == NULL); |
} |
@@ -286,25 +288,6 @@ scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { |
base::MessageLoopProxy::current())); |
} |
-void ClientSession::OnRecorderStopped() { |
- if (!network_task_runner_->BelongsToCurrentThread()) { |
- network_task_runner_->PostTask( |
- FROM_HERE, base::Bind(&ClientSession::OnRecorderStopped, this)); |
- return; |
- } |
- |
- --active_recorders_; |
- DCHECK_GE(active_recorders_, 0); |
- |
- DCHECK(!stopped_task_.is_null()); |
- if (active_recorders_ == 0) { |
- // |stopped_task_| may result in the signalling layer being torn down, so |
- // tear down the ConnectionToClient first. |
- connection_.reset(); |
- stopped_task_.Run(); |
- } |
-} |
- |
// TODO(sergeyu): Move this to SessionManager? |
// static |
scoped_ptr<VideoEncoder> ClientSession::CreateVideoEncoder( |