Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: remoting/host/client_session.cc

Issue 10909143: Revert 155574 - [Chromoting] Refactoring DesktopEnvironment and moving screen/audio recorders to Cl… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/client_session.h ('k') | remoting/host/client_session_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "remoting/codec/audio_encoder.h"
11 #include "remoting/codec/audio_encoder_speex.h"
12 #include "remoting/codec/audio_encoder_verbatim.h"
13 #include "remoting/codec/video_encoder.h"
14 #include "remoting/codec/video_encoder_row_based.h"
15 #include "remoting/codec/video_encoder_vp8.h"
16 #include "remoting/host/audio_scheduler.h"
17 #include "remoting/host/desktop_environment.h"
18 #include "remoting/host/event_executor.h"
19 #include "remoting/host/screen_recorder.h"
20 #include "remoting/host/video_frame_capturer.h" 10 #include "remoting/host/video_frame_capturer.h"
21 #include "remoting/proto/control.pb.h" 11 #include "remoting/proto/control.pb.h"
22 #include "remoting/proto/event.pb.h" 12 #include "remoting/proto/event.pb.h"
23 #include "remoting/protocol/client_stub.h" 13 #include "remoting/protocol/client_stub.h"
24 #include "remoting/protocol/clipboard_thread_proxy.h" 14 #include "remoting/protocol/clipboard_thread_proxy.h"
25 15
26 namespace remoting { 16 namespace remoting {
27 17
28 ClientSession::ClientSession( 18 ClientSession::ClientSession(
29 EventHandler* event_handler, 19 EventHandler* event_handler,
30 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
31 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner,
32 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
33 scoped_ptr<protocol::ConnectionToClient> connection, 20 scoped_ptr<protocol::ConnectionToClient> connection,
34 scoped_ptr<DesktopEnvironment> desktop_environment, 21 protocol::ClipboardStub* host_clipboard_stub,
22 protocol::InputStub* host_input_stub,
23 VideoFrameCapturer* capturer,
35 const base::TimeDelta& max_duration) 24 const base::TimeDelta& max_duration)
36 : event_handler_(event_handler), 25 : event_handler_(event_handler),
37 connection_(connection.Pass()), 26 connection_(connection.Pass()),
38 desktop_environment_(desktop_environment.Pass()),
39 client_jid_(connection_->session()->jid()), 27 client_jid_(connection_->session()->jid()),
40 host_clipboard_stub_(desktop_environment_->event_executor()), 28 host_clipboard_stub_(host_clipboard_stub),
41 host_input_stub_(desktop_environment_->event_executor()), 29 host_input_stub_(host_input_stub),
42 input_tracker_(host_input_stub_), 30 input_tracker_(host_input_stub_),
43 remote_input_filter_(&input_tracker_), 31 remote_input_filter_(&input_tracker_),
44 mouse_clamping_filter_(desktop_environment_->video_capturer(), 32 mouse_clamping_filter_(capturer, &remote_input_filter_),
45 &remote_input_filter_),
46 disable_input_filter_(&mouse_clamping_filter_), 33 disable_input_filter_(&mouse_clamping_filter_),
47 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()), 34 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()),
48 auth_input_filter_(&disable_input_filter_), 35 auth_input_filter_(&disable_input_filter_),
49 auth_clipboard_filter_(&disable_clipboard_filter_), 36 auth_clipboard_filter_(&disable_clipboard_filter_),
50 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), 37 client_clipboard_factory_(clipboard_echo_filter_.client_filter()),
51 max_duration_(max_duration), 38 capturer_(capturer),
52 capture_task_runner_(capture_task_runner), 39 max_duration_(max_duration) {
53 encode_task_runner_(encode_task_runner),
54 network_task_runner_(network_task_runner),
55 active_recorders_(0) {
56 connection_->SetEventHandler(this); 40 connection_->SetEventHandler(this);
57 41
58 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be 42 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be
59 // set before channels are connected. Make it possible to set stubs 43 // set before channels are connected. Make it possible to set stubs
60 // later and set them only when connection is authenticated. 44 // later and set them only when connection is authenticated.
61 connection_->set_clipboard_stub(&auth_clipboard_filter_); 45 connection_->set_clipboard_stub(&auth_clipboard_filter_);
62 connection_->set_host_stub(this); 46 connection_->set_host_stub(this);
63 connection_->set_input_stub(&auth_input_filter_); 47 connection_->set_input_stub(&auth_input_filter_);
64 clipboard_echo_filter_.set_host_stub(host_clipboard_stub_); 48 clipboard_echo_filter_.set_host_stub(host_clipboard_stub_);
65 49
66 // |auth_*_filter_|'s states reflect whether the session is authenticated. 50 // |auth_*_filter_|'s states reflect whether the session is authenticated.
67 auth_input_filter_.set_enabled(false); 51 auth_input_filter_.set_enabled(false);
68 auth_clipboard_filter_.set_enabled(false); 52 auth_clipboard_filter_.set_enabled(false);
69 } 53 }
70 54
55 ClientSession::~ClientSession() {
56 }
57
71 void ClientSession::NotifyClientDimensions( 58 void ClientSession::NotifyClientDimensions(
72 const protocol::ClientDimensions& dimensions) { 59 const protocol::ClientDimensions& dimensions) {
73 // TODO(wez): Use the dimensions, e.g. to resize the host desktop to match. 60 // TODO(wez): Use the dimensions, e.g. to resize the host desktop to match.
74 if (dimensions.has_width() && dimensions.has_height()) { 61 if (dimensions.has_width() && dimensions.has_height()) {
75 VLOG(1) << "Received ClientDimensions (width=" 62 VLOG(1) << "Received ClientDimensions (width="
76 << dimensions.width() << ", height=" << dimensions.height() << ")"; 63 << dimensions.width() << ", height=" << dimensions.height() << ")";
77 } 64 }
78 } 65 }
79 66
80 void ClientSession::ControlVideo(const protocol::VideoControl& video_control) { 67 void ClientSession::ControlVideo(const protocol::VideoControl& video_control) {
(...skipping 23 matching lines...) Expand all
104 } 91 }
105 92
106 event_handler_->OnSessionAuthenticated(this); 93 event_handler_->OnSessionAuthenticated(this);
107 } 94 }
108 95
109 void ClientSession::OnConnectionChannelsConnected( 96 void ClientSession::OnConnectionChannelsConnected(
110 protocol::ConnectionToClient* connection) { 97 protocol::ConnectionToClient* connection) {
111 DCHECK(CalledOnValidThread()); 98 DCHECK(CalledOnValidThread());
112 DCHECK_EQ(connection_.get(), connection); 99 DCHECK_EQ(connection_.get(), connection);
113 SetDisableInputs(false); 100 SetDisableInputs(false);
114
115 // Create a ScreenRecorder, passing the message loops that it should run on.
116 VideoEncoder* video_encoder =
117 CreateVideoEncoder(connection_->session()->config());
118 video_recorder_ = new ScreenRecorder(capture_task_runner_,
119 encode_task_runner_,
120 network_task_runner_,
121 desktop_environment_->video_capturer(),
122 video_encoder);
123 ++active_recorders_;
124
125 if (connection_->session()->config().is_audio_enabled()) {
126 scoped_ptr<AudioEncoder> audio_encoder =
127 CreateAudioEncoder(connection_->session()->config());
128 audio_scheduler_ = new AudioScheduler(
129 capture_task_runner_,
130 network_task_runner_,
131 desktop_environment_->audio_capturer(),
132 audio_encoder.Pass(),
133 connection_->audio_stub());
134 ++active_recorders_;
135 }
136
137 // Start the session.
138 video_recorder_->AddConnection(connection_.get());
139 video_recorder_->Start();
140 desktop_environment_->Start(CreateClipboardProxy());
141
142 event_handler_->OnSessionChannelsConnected(this); 101 event_handler_->OnSessionChannelsConnected(this);
143 } 102 }
144 103
145 void ClientSession::OnConnectionClosed( 104 void ClientSession::OnConnectionClosed(
146 protocol::ConnectionToClient* connection, 105 protocol::ConnectionToClient* connection,
147 protocol::ErrorCode error) { 106 protocol::ErrorCode error) {
148 DCHECK(CalledOnValidThread()); 107 DCHECK(CalledOnValidThread());
149 DCHECK_EQ(connection_.get(), connection); 108 DCHECK_EQ(connection_.get(), connection);
150 109
151 if (!auth_input_filter_.enabled()) 110 if (!auth_input_filter_.enabled())
152 event_handler_->OnSessionAuthenticationFailed(this); 111 event_handler_->OnSessionAuthenticationFailed(this);
153 112
154 // Block any further input events from the client. 113 // Block any further input events from the client.
155 // TODO(wez): Fix ChromotingHost::OnSessionClosed not to check our 114 // TODO(wez): Fix ChromotingHost::OnSessionClosed not to check our
156 // is_authenticated(), so that we can disable |auth_*_filter_| here. 115 // is_authenticated(), so that we can disable |auth_*_filter_| here.
157 disable_input_filter_.set_enabled(false); 116 disable_input_filter_.set_enabled(false);
158 disable_clipboard_filter_.set_enabled(false); 117 disable_clipboard_filter_.set_enabled(false);
159 118
160 // Ensure that any pressed keys or buttons are released. 119 // Ensure that any pressed keys or buttons are released.
161 input_tracker_.ReleaseAll(); 120 input_tracker_.ReleaseAll();
162 121
163 // TODO(sergeyu): Log failure reason? 122 // TODO(sergeyu): Log failure reason?
164 event_handler_->OnSessionClosed(this); 123 event_handler_->OnSessionClosed(this);
165 } 124 }
166 125
167 void ClientSession::OnSequenceNumberUpdated( 126 void ClientSession::OnSequenceNumberUpdated(
168 protocol::ConnectionToClient* connection, int64 sequence_number) { 127 protocol::ConnectionToClient* connection, int64 sequence_number) {
169 DCHECK(CalledOnValidThread()); 128 DCHECK(CalledOnValidThread());
170 DCHECK_EQ(connection_.get(), connection); 129 DCHECK_EQ(connection_.get(), connection);
171
172 if (video_recorder_.get())
173 video_recorder_->UpdateSequenceNumber(sequence_number);
174
175 event_handler_->OnSessionSequenceNumber(this, sequence_number); 130 event_handler_->OnSessionSequenceNumber(this, sequence_number);
176 } 131 }
177 132
178 void ClientSession::OnRouteChange( 133 void ClientSession::OnRouteChange(
179 protocol::ConnectionToClient* connection, 134 protocol::ConnectionToClient* connection,
180 const std::string& channel_name, 135 const std::string& channel_name,
181 const protocol::TransportRoute& route) { 136 const protocol::TransportRoute& route) {
182 DCHECK(CalledOnValidThread()); 137 DCHECK(CalledOnValidThread());
183 DCHECK_EQ(connection_.get(), connection); 138 DCHECK_EQ(connection_.get(), connection);
184 event_handler_->OnSessionRouteChange(this, channel_name, route); 139 event_handler_->OnSessionRouteChange(this, channel_name, route);
185 } 140 }
186 141
187 void ClientSession::Disconnect() { 142 void ClientSession::Disconnect() {
188 DCHECK(CalledOnValidThread()); 143 DCHECK(CalledOnValidThread());
189 DCHECK(connection_.get()); 144 DCHECK(connection_.get());
190 145
191 max_duration_timer_.Stop(); 146 max_duration_timer_.Stop();
192 // This triggers OnConnectionClosed(), and the session may be destroyed 147 // This triggers OnConnectionClosed(), and the session may be destroyed
193 // as the result, so this call must be the last in this method. 148 // as the result, so this call must be the last in this method.
194 connection_->Disconnect(); 149 connection_->Disconnect();
195 } 150 }
196 151
197 void ClientSession::StopAndDelete(const base::Closure& done_task) {
198 DCHECK(CalledOnValidThread());
199 DCHECK(done_task_.is_null());
200
201 done_task_ = done_task;
202 if (audio_scheduler_.get()) {
203 audio_scheduler_->OnClientDisconnected();
204 audio_scheduler_->Stop(base::Bind(&ClientSession::OnRecorderStopped,
205 base::Unretained(this)));
206 audio_scheduler_ = NULL;
207 }
208
209 if (video_recorder_.get()) {
210 video_recorder_->RemoveConnection(connection_.get());
211 video_recorder_->Stop(base::Bind(&ClientSession::OnRecorderStopped,
212 base::Unretained(this)));
213 video_recorder_ = NULL;
214 }
215
216 if (!active_recorders_) {
217 base::Closure done_task = done_task_;
218 delete this;
219 done_task.Run();
220 }
221 }
222
223 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { 152 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) {
224 DCHECK(CalledOnValidThread()); 153 DCHECK(CalledOnValidThread());
225 remote_input_filter_.LocalMouseMoved(mouse_pos); 154 remote_input_filter_.LocalMouseMoved(mouse_pos);
226 } 155 }
227 156
228 void ClientSession::SetDisableInputs(bool disable_inputs) { 157 void ClientSession::SetDisableInputs(bool disable_inputs) {
229 DCHECK(CalledOnValidThread()); 158 DCHECK(CalledOnValidThread());
230 159
231 if (disable_inputs) 160 if (disable_inputs)
232 input_tracker_.ReleaseAll(); 161 input_tracker_.ReleaseAll();
233 162
234 disable_input_filter_.set_enabled(!disable_inputs); 163 disable_input_filter_.set_enabled(!disable_inputs);
235 disable_clipboard_filter_.set_enabled(!disable_inputs); 164 disable_clipboard_filter_.set_enabled(!disable_inputs);
236 } 165 }
237 166
238 ClientSession::~ClientSession() {
239 DCHECK(audio_scheduler_.get() == NULL);
240 DCHECK(video_recorder_.get() == NULL);
241 }
242
243 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { 167 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() {
244 DCHECK(CalledOnValidThread()); 168 DCHECK(CalledOnValidThread());
245 169
246 return scoped_ptr<protocol::ClipboardStub>( 170 return scoped_ptr<protocol::ClipboardStub>(
247 new protocol::ClipboardThreadProxy( 171 new protocol::ClipboardThreadProxy(
248 client_clipboard_factory_.GetWeakPtr(), 172 client_clipboard_factory_.GetWeakPtr(),
249 base::MessageLoopProxy::current())); 173 base::MessageLoopProxy::current()));
250 } 174 }
251 175
252 void ClientSession::OnRecorderStopped() {
253 if (!network_task_runner_->BelongsToCurrentThread()) {
254 network_task_runner_->PostTask(
255 FROM_HERE, base::Bind(&ClientSession::OnRecorderStopped,
256 base::Unretained(this)));
257 return;
258 }
259
260 DCHECK(!done_task_.is_null());
261
262 --active_recorders_;
263 DCHECK_GE(active_recorders_, 0);
264
265 if (!active_recorders_) {
266 base::Closure done_task = done_task_;
267 delete this;
268 done_task.Run();
269 }
270 }
271
272 // TODO(sergeyu): Move this to SessionManager?
273 // static
274 VideoEncoder* ClientSession::CreateVideoEncoder(
275 const protocol::SessionConfig& config) {
276 const protocol::ChannelConfig& video_config = config.video_config();
277
278 if (video_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) {
279 return VideoEncoderRowBased::CreateVerbatimEncoder();
280 } else if (video_config.codec == protocol::ChannelConfig::CODEC_ZIP) {
281 return VideoEncoderRowBased::CreateZlibEncoder();
282 } else if (video_config.codec == protocol::ChannelConfig::CODEC_VP8) {
283 return new remoting::VideoEncoderVp8();
284 }
285
286 NOTIMPLEMENTED();
287 return NULL;
288 }
289
290 // static
291 scoped_ptr<AudioEncoder> ClientSession::CreateAudioEncoder(
292 const protocol::SessionConfig& config) {
293 const protocol::ChannelConfig& audio_config = config.audio_config();
294
295 if (audio_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) {
296 return scoped_ptr<AudioEncoder>(new AudioEncoderVerbatim());
297 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_SPEEX) {
298 return scoped_ptr<AudioEncoder>(new AudioEncoderSpeex());
299 }
300
301 NOTIMPLEMENTED();
302 return scoped_ptr<AudioEncoder>(NULL);
303 }
304
305 } // namespace remoting 176 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_session.h ('k') | remoting/host/client_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698