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_proxy.h" | 5 #include "remoting/host/desktop_session_proxy.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 72 matching lines...) Loading... |
83 private: | 83 private: |
84 scoped_refptr<IpcSharedBufferCore> core_; | 84 scoped_refptr<IpcSharedBufferCore> core_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(IpcSharedBuffer); | 86 DISALLOW_COPY_AND_ASSIGN(IpcSharedBuffer); |
87 }; | 87 }; |
88 | 88 |
89 DesktopSessionProxy::DesktopSessionProxy( | 89 DesktopSessionProxy::DesktopSessionProxy( |
90 scoped_refptr<base::SingleThreadTaskRunner> audio_capture_task_runner, | 90 scoped_refptr<base::SingleThreadTaskRunner> audio_capture_task_runner, |
91 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 91 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
92 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 92 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
93 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, | |
94 base::WeakPtr<ClientSessionControl> client_session_control, | 93 base::WeakPtr<ClientSessionControl> client_session_control, |
95 base::WeakPtr<DesktopSessionConnector> desktop_session_connector, | 94 base::WeakPtr<DesktopSessionConnector> desktop_session_connector, |
96 bool virtual_terminal, | 95 bool virtual_terminal, |
97 bool supports_touch_events) | 96 bool supports_touch_events) |
98 : audio_capture_task_runner_(audio_capture_task_runner), | 97 : audio_capture_task_runner_(audio_capture_task_runner), |
99 caller_task_runner_(caller_task_runner), | 98 caller_task_runner_(caller_task_runner), |
100 io_task_runner_(io_task_runner), | 99 io_task_runner_(io_task_runner), |
101 video_capture_task_runner_(video_capture_task_runner), | |
102 client_session_control_(client_session_control), | 100 client_session_control_(client_session_control), |
103 desktop_session_connector_(desktop_session_connector), | 101 desktop_session_connector_(desktop_session_connector), |
104 pending_capture_frame_requests_(0), | 102 pending_capture_frame_requests_(0), |
105 is_desktop_session_connected_(false), | 103 is_desktop_session_connected_(false), |
106 virtual_terminal_(virtual_terminal), | 104 virtual_terminal_(virtual_terminal), |
107 supports_touch_events_(supports_touch_events) { | 105 supports_touch_events_(supports_touch_events) { |
108 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 106 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
109 } | 107 } |
110 | 108 |
111 scoped_ptr<AudioCapturer> DesktopSessionProxy::CreateAudioCapturer() { | 109 scoped_ptr<AudioCapturer> DesktopSessionProxy::CreateAudioCapturer() { |
(...skipping 157 matching lines...) Loading... |
269 desktop_channel_.reset(); | 267 desktop_channel_.reset(); |
270 | 268 |
271 if (desktop_process_.IsValid()) | 269 if (desktop_process_.IsValid()) |
272 desktop_process_.Close(); | 270 desktop_process_.Close(); |
273 | 271 |
274 shared_buffers_.clear(); | 272 shared_buffers_.clear(); |
275 | 273 |
276 // Generate fake responses to keep the video capturer in sync. | 274 // Generate fake responses to keep the video capturer in sync. |
277 while (pending_capture_frame_requests_) { | 275 while (pending_capture_frame_requests_) { |
278 --pending_capture_frame_requests_; | 276 --pending_capture_frame_requests_; |
279 PostCaptureCompleted(nullptr); | 277 video_capturer_->OnCaptureCompleted(nullptr); |
280 } | 278 } |
281 } | 279 } |
282 | 280 |
283 void DesktopSessionProxy::SetAudioCapturer( | 281 void DesktopSessionProxy::SetAudioCapturer( |
284 const base::WeakPtr<IpcAudioCapturer>& audio_capturer) { | 282 const base::WeakPtr<IpcAudioCapturer>& audio_capturer) { |
285 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); | 283 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); |
286 | 284 |
287 audio_capturer_ = audio_capturer; | 285 audio_capturer_ = audio_capturer; |
288 } | 286 } |
289 | 287 |
290 void DesktopSessionProxy::CaptureFrame() { | 288 void DesktopSessionProxy::CaptureFrame() { |
291 if (!caller_task_runner_->BelongsToCurrentThread()) { | 289 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
292 caller_task_runner_->PostTask( | |
293 FROM_HERE, base::Bind(&DesktopSessionProxy::CaptureFrame, this)); | |
294 return; | |
295 } | |
296 | 290 |
297 if (desktop_channel_) { | 291 if (desktop_channel_) { |
298 ++pending_capture_frame_requests_; | 292 ++pending_capture_frame_requests_; |
299 SendToDesktop(new ChromotingNetworkDesktopMsg_CaptureFrame()); | 293 SendToDesktop(new ChromotingNetworkDesktopMsg_CaptureFrame()); |
300 } else { | 294 } else { |
301 PostCaptureCompleted(nullptr); | 295 video_capturer_->OnCaptureCompleted(nullptr); |
302 } | 296 } |
303 } | 297 } |
304 | 298 |
305 void DesktopSessionProxy::SetVideoCapturer( | 299 void DesktopSessionProxy::SetVideoCapturer( |
306 const base::WeakPtr<IpcVideoFrameCapturer> video_capturer) { | 300 const base::WeakPtr<IpcVideoFrameCapturer> video_capturer) { |
307 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); | 301 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
308 | 302 |
309 video_capturer_ = video_capturer; | 303 video_capturer_ = video_capturer; |
310 } | 304 } |
311 | 305 |
312 void DesktopSessionProxy::SetMouseCursorMonitor( | 306 void DesktopSessionProxy::SetMouseCursorMonitor( |
313 const base::WeakPtr<IpcMouseCursorMonitor>& mouse_cursor_monitor) { | 307 const base::WeakPtr<IpcMouseCursorMonitor>& mouse_cursor_monitor) { |
314 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); | 308 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
315 | 309 |
316 mouse_cursor_monitor_ = mouse_cursor_monitor; | 310 mouse_cursor_monitor_ = mouse_cursor_monitor; |
317 } | 311 } |
318 | 312 |
319 void DesktopSessionProxy::DisconnectSession(protocol::ErrorCode error) { | 313 void DesktopSessionProxy::DisconnectSession(protocol::ErrorCode error) { |
320 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 314 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
321 | 315 |
322 // Disconnect the client session if it hasn't been disconnected yet. | 316 // Disconnect the client session if it hasn't been disconnected yet. |
323 if (client_session_control_.get()) | 317 if (client_session_control_.get()) |
324 client_session_control_->DisconnectSession(error); | 318 client_session_control_->DisconnectSession(error); |
(...skipping 175 matching lines...) Loading... |
500 serialized_frame.dimensions, serialized_frame.bytes_per_row, | 494 serialized_frame.dimensions, serialized_frame.bytes_per_row, |
501 new IpcSharedBuffer(shared_buffer_core))); | 495 new IpcSharedBuffer(shared_buffer_core))); |
502 frame->set_capture_time_ms(serialized_frame.capture_time_ms); | 496 frame->set_capture_time_ms(serialized_frame.capture_time_ms); |
503 frame->set_dpi(serialized_frame.dpi); | 497 frame->set_dpi(serialized_frame.dpi); |
504 | 498 |
505 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { | 499 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { |
506 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); | 500 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); |
507 } | 501 } |
508 | 502 |
509 --pending_capture_frame_requests_; | 503 --pending_capture_frame_requests_; |
510 PostCaptureCompleted(std::move(frame)); | 504 video_capturer_->OnCaptureCompleted(std::move(frame)); |
511 } | 505 } |
512 | 506 |
513 void DesktopSessionProxy::OnMouseCursor( | 507 void DesktopSessionProxy::OnMouseCursor( |
514 const webrtc::MouseCursor& mouse_cursor) { | 508 const webrtc::MouseCursor& mouse_cursor) { |
515 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 509 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
516 PostMouseCursor(make_scoped_ptr(webrtc::MouseCursor::CopyOf(mouse_cursor))); | 510 |
| 511 if (mouse_cursor_monitor_) { |
| 512 mouse_cursor_monitor_->OnMouseCursor( |
| 513 make_scoped_ptr(webrtc::MouseCursor::CopyOf(mouse_cursor))); |
| 514 } |
517 } | 515 } |
518 | 516 |
519 void DesktopSessionProxy::OnInjectClipboardEvent( | 517 void DesktopSessionProxy::OnInjectClipboardEvent( |
520 const std::string& serialized_event) { | 518 const std::string& serialized_event) { |
521 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 519 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
522 | 520 |
523 if (client_clipboard_) { | 521 if (client_clipboard_) { |
524 protocol::ClipboardEvent event; | 522 protocol::ClipboardEvent event; |
525 if (!event.ParseFromString(serialized_event)) { | 523 if (!event.ParseFromString(serialized_event)) { |
526 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent."; | 524 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent."; |
527 return; | 525 return; |
528 } | 526 } |
529 | 527 |
530 client_clipboard_->InjectClipboardEvent(event); | 528 client_clipboard_->InjectClipboardEvent(event); |
531 } | 529 } |
532 } | 530 } |
533 | 531 |
534 void DesktopSessionProxy::PostCaptureCompleted( | |
535 scoped_ptr<webrtc::DesktopFrame> frame) { | |
536 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | |
537 | |
538 video_capture_task_runner_->PostTask( | |
539 FROM_HERE, | |
540 base::Bind(&IpcVideoFrameCapturer::OnCaptureCompleted, video_capturer_, | |
541 base::Passed(&frame))); | |
542 } | |
543 | |
544 void DesktopSessionProxy::PostMouseCursor( | |
545 scoped_ptr<webrtc::MouseCursor> mouse_cursor) { | |
546 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | |
547 | |
548 video_capture_task_runner_->PostTask( | |
549 FROM_HERE, | |
550 base::Bind(&IpcMouseCursorMonitor::OnMouseCursor, mouse_cursor_monitor_, | |
551 base::Passed(&mouse_cursor))); | |
552 } | |
553 | |
554 void DesktopSessionProxy::SendToDesktop(IPC::Message* message) { | 532 void DesktopSessionProxy::SendToDesktop(IPC::Message* message) { |
555 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 533 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
556 | 534 |
557 if (desktop_channel_) { | 535 if (desktop_channel_) { |
558 desktop_channel_->Send(message); | 536 desktop_channel_->Send(message); |
559 } else { | 537 } else { |
560 delete message; | 538 delete message; |
561 } | 539 } |
562 } | 540 } |
563 | 541 |
564 // static | 542 // static |
565 void DesktopSessionProxyTraits::Destruct( | 543 void DesktopSessionProxyTraits::Destruct( |
566 const DesktopSessionProxy* desktop_session_proxy) { | 544 const DesktopSessionProxy* desktop_session_proxy) { |
567 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, | 545 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, |
568 desktop_session_proxy); | 546 desktop_session_proxy); |
569 } | 547 } |
570 | 548 |
571 } // namespace remoting | 549 } // namespace remoting |
OLD | NEW |