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/desktop_session_agent.h" | 5 #include "remoting/host/desktop_session_agent.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ipc/ipc_channel_proxy.h" | 8 #include "ipc/ipc_channel_proxy.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
11 #include "media/video/capture/screen/screen_capture_data.h" | 11 #include "media/video/capture/screen/screen_capture_data.h" |
12 #include "remoting/base/auto_thread_task_runner.h" | 12 #include "remoting/base/auto_thread_task_runner.h" |
13 #include "remoting/base/constants.h" | 13 #include "remoting/base/constants.h" |
14 #include "remoting/base/util.h" | 14 #include "remoting/base/util.h" |
15 #include "remoting/host/audio_capturer.h" | 15 #include "remoting/host/audio_capturer.h" |
16 #include "remoting/host/chromoting_messages.h" | 16 #include "remoting/host/chromoting_messages.h" |
| 17 #include "remoting/host/desktop_environment.h" |
17 #include "remoting/host/disconnect_window.h" | 18 #include "remoting/host/disconnect_window.h" |
18 #include "remoting/host/event_executor.h" | 19 #include "remoting/host/event_executor.h" |
19 #include "remoting/host/local_input_monitor.h" | 20 #include "remoting/host/local_input_monitor.h" |
20 #include "remoting/host/remote_input_filter.h" | 21 #include "remoting/host/remote_input_filter.h" |
21 #include "remoting/proto/audio.pb.h" | 22 #include "remoting/proto/audio.pb.h" |
22 #include "remoting/proto/control.pb.h" | 23 #include "remoting/proto/control.pb.h" |
23 #include "remoting/proto/event.pb.h" | 24 #include "remoting/proto/event.pb.h" |
24 #include "remoting/protocol/clipboard_stub.h" | 25 #include "remoting/protocol/clipboard_stub.h" |
25 #include "remoting/protocol/input_event_tracker.h" | 26 #include "remoting/protocol/input_event_tracker.h" |
26 #include "third_party/skia/include/core/SkRegion.h" | 27 #include "third_party/skia/include/core/SkRegion.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 DCHECK(buffer->id() != 0); | 170 DCHECK(buffer->id() != 0); |
170 | 171 |
171 SendToNetwork( | 172 SendToNetwork( |
172 new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(buffer->id())); | 173 new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(buffer->id())); |
173 } | 174 } |
174 | 175 |
175 void DesktopSessionAgent::OnStartSessionAgent( | 176 void DesktopSessionAgent::OnStartSessionAgent( |
176 const std::string& authenticated_jid) { | 177 const std::string& authenticated_jid) { |
177 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 178 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
178 DCHECK(!started_); | 179 DCHECK(!started_); |
| 180 DCHECK(!audio_capturer_); |
| 181 DCHECK(!event_executor_); |
| 182 DCHECK(!video_capturer_); |
179 | 183 |
180 started_ = true; | 184 started_ = true; |
181 | 185 |
| 186 // Create a desktop environment for the new session. |
| 187 base::Closure disconnect_session = |
| 188 base::Bind(&DesktopSessionAgent::DisconnectSession, this); |
| 189 scoped_ptr<DesktopEnvironment> desktop_environment = |
| 190 delegate_->desktop_environment_factory().Create(authenticated_jid, |
| 191 disconnect_session); |
| 192 |
182 // Create the event executor. | 193 // Create the event executor. |
183 event_executor_ = CreateEventExecutor(); | 194 event_executor_ = |
| 195 desktop_environment->CreateEventExecutor(input_task_runner(), |
| 196 caller_task_runner()); |
184 | 197 |
185 // Hook up the input filter | 198 // Hook up the input filter |
186 input_tracker_.reset(new protocol::InputEventTracker(event_executor_.get())); | 199 input_tracker_.reset(new protocol::InputEventTracker(event_executor_.get())); |
187 remote_input_filter_.reset(new RemoteInputFilter(input_tracker_.get())); | 200 remote_input_filter_.reset(new RemoteInputFilter(input_tracker_.get())); |
188 | 201 |
189 // Start the event executor. | 202 // Start the event executor. |
190 scoped_ptr<protocol::ClipboardStub> clipboard_stub( | 203 scoped_ptr<protocol::ClipboardStub> clipboard_stub( |
191 new DesktopSesssionClipboardStub(this)); | 204 new DesktopSesssionClipboardStub(this)); |
192 event_executor_->Start(clipboard_stub.Pass()); | 205 event_executor_->Start(clipboard_stub.Pass()); |
193 | 206 |
194 base::Closure disconnect_session = | |
195 base::Bind(&DesktopSessionAgent::DisconnectSession, this); | |
196 | |
197 // Create the disconnect window. | 207 // Create the disconnect window. |
198 disconnect_window_ = DisconnectWindow::Create(&ui_strings_); | 208 disconnect_window_ = DisconnectWindow::Create(&ui_strings_); |
199 disconnect_window_->Show( | 209 disconnect_window_->Show( |
200 disconnect_session, | 210 disconnect_session, |
201 authenticated_jid.substr(0, authenticated_jid.find('/'))); | 211 authenticated_jid.substr(0, authenticated_jid.find('/'))); |
202 | 212 |
203 // Start monitoring local input. | 213 // Start monitoring local input. |
204 local_input_monitor_ = LocalInputMonitor::Create(); | 214 local_input_monitor_ = LocalInputMonitor::Create(); |
205 local_input_monitor_->Start(this, disconnect_session); | 215 local_input_monitor_->Start(this, disconnect_session); |
206 | 216 |
207 // Start the audio capturer. | 217 // Start the audio capturer. |
208 audio_capture_task_runner()->PostTask( | 218 if (delegate_->desktop_environment_factory().SupportsAudioCapture()) { |
209 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this)); | 219 audio_capturer_ = desktop_environment->CreateAudioCapturer( |
| 220 audio_capture_task_runner()); |
| 221 audio_capture_task_runner()->PostTask( |
| 222 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this)); |
| 223 } |
210 | 224 |
211 // Start the video capturer. | 225 // Start the video capturer. |
| 226 video_capturer_ = desktop_environment->CreateVideoCapturer( |
| 227 video_capture_task_runner(), caller_task_runner()); |
212 video_capture_task_runner()->PostTask( | 228 video_capture_task_runner()->PostTask( |
213 FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this)); | 229 FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this)); |
214 } | 230 } |
215 | 231 |
216 void DesktopSessionAgent::OnCaptureCompleted( | 232 void DesktopSessionAgent::OnCaptureCompleted( |
217 scoped_refptr<media::ScreenCaptureData> capture_data) { | 233 scoped_refptr<media::ScreenCaptureData> capture_data) { |
218 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 234 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
219 | 235 |
220 current_size_ = capture_data->size(); | 236 current_size_ = capture_data->size(); |
221 | 237 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 if (network_channel_) { | 479 if (network_channel_) { |
464 network_channel_->Send(message); | 480 network_channel_->Send(message); |
465 } else { | 481 } else { |
466 delete message; | 482 delete message; |
467 } | 483 } |
468 } | 484 } |
469 | 485 |
470 void DesktopSessionAgent::StartAudioCapturer() { | 486 void DesktopSessionAgent::StartAudioCapturer() { |
471 DCHECK(audio_capture_task_runner()->BelongsToCurrentThread()); | 487 DCHECK(audio_capture_task_runner()->BelongsToCurrentThread()); |
472 | 488 |
473 audio_capturer_ = AudioCapturer::Create(); | |
474 if (audio_capturer_) { | 489 if (audio_capturer_) { |
475 audio_capturer_->Start(base::Bind(&DesktopSessionAgent::ProcessAudioPacket, | 490 audio_capturer_->Start(base::Bind(&DesktopSessionAgent::ProcessAudioPacket, |
476 this)); | 491 this)); |
477 } | 492 } |
478 } | 493 } |
479 | 494 |
480 void DesktopSessionAgent::StopAudioCapturer() { | 495 void DesktopSessionAgent::StopAudioCapturer() { |
481 DCHECK(audio_capture_task_runner()->BelongsToCurrentThread()); | 496 DCHECK(audio_capture_task_runner()->BelongsToCurrentThread()); |
482 | 497 |
483 audio_capturer_.reset(); | 498 audio_capturer_.reset(); |
484 } | 499 } |
485 | 500 |
486 void DesktopSessionAgent::StartVideoCapturer() { | 501 void DesktopSessionAgent::StartVideoCapturer() { |
487 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 502 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
488 | 503 |
489 video_capturer_ = media::ScreenCapturer::Create(); | |
490 if (video_capturer_) | 504 if (video_capturer_) |
491 video_capturer_->Start(this); | 505 video_capturer_->Start(this); |
492 } | 506 } |
493 | 507 |
494 void DesktopSessionAgent::StopVideoCapturer() { | 508 void DesktopSessionAgent::StopVideoCapturer() { |
495 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 509 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
496 | 510 |
497 if (video_capturer_) { | 511 if (video_capturer_) { |
498 video_capturer_->Stop(); | 512 video_capturer_->Stop(); |
499 video_capturer_.reset(); | 513 video_capturer_.reset(); |
(...skipping 14 matching lines...) Expand all Loading... |
514 input_task_runner_(input_task_runner), | 528 input_task_runner_(input_task_runner), |
515 io_task_runner_(io_task_runner), | 529 io_task_runner_(io_task_runner), |
516 video_capture_task_runner_(video_capture_task_runner), | 530 video_capture_task_runner_(video_capture_task_runner), |
517 current_size_(SkISize::Make(0, 0)), | 531 current_size_(SkISize::Make(0, 0)), |
518 next_shared_buffer_id_(1), | 532 next_shared_buffer_id_(1), |
519 started_(false) { | 533 started_(false) { |
520 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 534 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
521 } | 535 } |
522 | 536 |
523 } // namespace remoting | 537 } // namespace remoting |
OLD | NEW |