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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) { | 174 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) { |
175 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 175 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
176 | 176 |
177 bool handled = true; | 177 bool handled = true; |
178 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message) | 178 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message) |
179 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket, | 179 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket, |
180 OnAudioPacket) | 180 OnAudioPacket) |
181 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureCompleted, | 181 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureResult, |
182 OnCaptureCompleted) | 182 OnCaptureResult) |
183 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_MouseCursor, | 183 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_MouseCursor, |
184 OnMouseCursor) | 184 OnMouseCursor) |
185 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CreateSharedBuffer, | 185 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CreateSharedBuffer, |
186 OnCreateSharedBuffer) | 186 OnCreateSharedBuffer) |
187 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_ReleaseSharedBuffer, | 187 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_ReleaseSharedBuffer, |
188 OnReleaseSharedBuffer) | 188 OnReleaseSharedBuffer) |
189 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_InjectClipboardEvent, | 189 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_InjectClipboardEvent, |
190 OnInjectClipboardEvent) | 190 OnInjectClipboardEvent) |
191 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_DisconnectSession, | 191 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_DisconnectSession, |
192 DisconnectSession); | 192 DisconnectSession); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 desktop_channel_.reset(); | 255 desktop_channel_.reset(); |
256 | 256 |
257 if (desktop_process_.IsValid()) | 257 if (desktop_process_.IsValid()) |
258 desktop_process_.Close(); | 258 desktop_process_.Close(); |
259 | 259 |
260 shared_buffers_.clear(); | 260 shared_buffers_.clear(); |
261 | 261 |
262 // Generate fake responses to keep the video capturer in sync. | 262 // Generate fake responses to keep the video capturer in sync. |
263 while (pending_capture_frame_requests_) { | 263 while (pending_capture_frame_requests_) { |
264 --pending_capture_frame_requests_; | 264 --pending_capture_frame_requests_; |
265 video_capturer_->OnCaptureCompleted(nullptr); | 265 video_capturer_->OnCaptureResult( |
| 266 webrtc::DesktopCapturer::Result::ERROR_PERMANENT, nullptr); |
266 } | 267 } |
267 } | 268 } |
268 | 269 |
269 void DesktopSessionProxy::SetAudioCapturer( | 270 void DesktopSessionProxy::SetAudioCapturer( |
270 const base::WeakPtr<IpcAudioCapturer>& audio_capturer) { | 271 const base::WeakPtr<IpcAudioCapturer>& audio_capturer) { |
271 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); | 272 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); |
272 | 273 |
273 audio_capturer_ = audio_capturer; | 274 audio_capturer_ = audio_capturer; |
274 } | 275 } |
275 | 276 |
276 void DesktopSessionProxy::CaptureFrame() { | 277 void DesktopSessionProxy::CaptureFrame() { |
277 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 278 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
278 | 279 |
279 if (desktop_channel_) { | 280 if (desktop_channel_) { |
280 ++pending_capture_frame_requests_; | 281 ++pending_capture_frame_requests_; |
281 SendToDesktop(new ChromotingNetworkDesktopMsg_CaptureFrame()); | 282 SendToDesktop(new ChromotingNetworkDesktopMsg_CaptureFrame()); |
282 } else { | 283 } else { |
283 video_capturer_->OnCaptureCompleted(nullptr); | 284 video_capturer_->OnCaptureResult( |
| 285 webrtc::DesktopCapturer::Result::ERROR_PERMANENT, nullptr); |
284 } | 286 } |
285 } | 287 } |
286 | 288 |
287 void DesktopSessionProxy::SetVideoCapturer( | 289 void DesktopSessionProxy::SetVideoCapturer( |
288 const base::WeakPtr<IpcVideoFrameCapturer> video_capturer) { | 290 const base::WeakPtr<IpcVideoFrameCapturer> video_capturer) { |
289 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 291 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
290 | 292 |
291 video_capturer_ = video_capturer; | 293 video_capturer_ = video_capturer; |
292 } | 294 } |
293 | 295 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 462 } |
461 } | 463 } |
462 | 464 |
463 void DesktopSessionProxy::OnReleaseSharedBuffer(int id) { | 465 void DesktopSessionProxy::OnReleaseSharedBuffer(int id) { |
464 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 466 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
465 | 467 |
466 // Drop the cached reference to the buffer. | 468 // Drop the cached reference to the buffer. |
467 shared_buffers_.erase(id); | 469 shared_buffers_.erase(id); |
468 } | 470 } |
469 | 471 |
470 void DesktopSessionProxy::OnCaptureCompleted( | 472 void DesktopSessionProxy::OnCaptureResult( |
| 473 webrtc::DesktopCapturer::Result result, |
471 const SerializedDesktopFrame& serialized_frame) { | 474 const SerializedDesktopFrame& serialized_frame) { |
472 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 475 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
473 | 476 |
474 --pending_capture_frame_requests_; | 477 --pending_capture_frame_requests_; |
475 | 478 |
476 // If the input serialized_frame does not have a screen size, it means the | 479 if (result != webrtc::DesktopCapturer::Result::SUCCESS) { |
477 // capturer returns a nullptr for OnCaptureCompleted call. | 480 video_capturer_->OnCaptureResult(result, nullptr); |
478 if (serialized_frame.dimensions.is_empty()) { | |
479 video_capturer_->OnCaptureCompleted(nullptr); | |
480 return; | 481 return; |
481 } | 482 } |
482 | 483 |
483 // Assume that |serialized_frame| is well-formed because it was received from | 484 // Assume that |serialized_frame| is well-formed because it was received from |
484 // a more privileged process. | 485 // a more privileged process. |
485 scoped_refptr<IpcSharedBufferCore> shared_buffer_core = | 486 scoped_refptr<IpcSharedBufferCore> shared_buffer_core = |
486 GetSharedBufferCore(serialized_frame.shared_buffer_id); | 487 GetSharedBufferCore(serialized_frame.shared_buffer_id); |
487 CHECK(shared_buffer_core.get()); | 488 CHECK(shared_buffer_core.get()); |
488 | 489 |
489 std::unique_ptr<webrtc::DesktopFrame> frame( | 490 std::unique_ptr<webrtc::DesktopFrame> frame( |
490 new webrtc::SharedMemoryDesktopFrame( | 491 new webrtc::SharedMemoryDesktopFrame( |
491 serialized_frame.dimensions, serialized_frame.bytes_per_row, | 492 serialized_frame.dimensions, serialized_frame.bytes_per_row, |
492 new IpcSharedBuffer(shared_buffer_core))); | 493 new IpcSharedBuffer(shared_buffer_core))); |
493 frame->set_capture_time_ms(serialized_frame.capture_time_ms); | 494 frame->set_capture_time_ms(serialized_frame.capture_time_ms); |
494 frame->set_dpi(serialized_frame.dpi); | 495 frame->set_dpi(serialized_frame.dpi); |
495 | 496 |
496 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { | 497 for (size_t i = 0; i < serialized_frame.dirty_region.size(); ++i) { |
497 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); | 498 frame->mutable_updated_region()->AddRect(serialized_frame.dirty_region[i]); |
498 } | 499 } |
499 | 500 |
500 video_capturer_->OnCaptureCompleted(std::move(frame)); | 501 video_capturer_->OnCaptureResult(result, std::move(frame)); |
501 } | 502 } |
502 | 503 |
503 void DesktopSessionProxy::OnMouseCursor( | 504 void DesktopSessionProxy::OnMouseCursor( |
504 const webrtc::MouseCursor& mouse_cursor) { | 505 const webrtc::MouseCursor& mouse_cursor) { |
505 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 506 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
506 | 507 |
507 if (mouse_cursor_monitor_) { | 508 if (mouse_cursor_monitor_) { |
508 mouse_cursor_monitor_->OnMouseCursor( | 509 mouse_cursor_monitor_->OnMouseCursor( |
509 base::WrapUnique(webrtc::MouseCursor::CopyOf(mouse_cursor))); | 510 base::WrapUnique(webrtc::MouseCursor::CopyOf(mouse_cursor))); |
510 } | 511 } |
(...skipping 25 matching lines...) Expand all Loading... |
536 } | 537 } |
537 | 538 |
538 // static | 539 // static |
539 void DesktopSessionProxyTraits::Destruct( | 540 void DesktopSessionProxyTraits::Destruct( |
540 const DesktopSessionProxy* desktop_session_proxy) { | 541 const DesktopSessionProxy* desktop_session_proxy) { |
541 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, | 542 desktop_session_proxy->caller_task_runner_->DeleteSoon(FROM_HERE, |
542 desktop_session_proxy); | 543 desktop_session_proxy); |
543 } | 544 } |
544 | 545 |
545 } // namespace remoting | 546 } // namespace remoting |
OLD | NEW |