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

Side by Side Diff: trunk/src/remoting/host/desktop_session_agent.cc

Issue 151163002: Revert 248045 "Use webrtc::MouseCursorMonitor for cursor shapes" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 10 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
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/desktop_session_agent.h" 5 #include "remoting/host/desktop_session_agent.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "ipc/ipc_channel_proxy.h" 10 #include "ipc/ipc_channel_proxy.h"
11 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
12 #include "ipc/ipc_message_macros.h" 12 #include "ipc/ipc_message_macros.h"
13 #include "remoting/base/auto_thread_task_runner.h" 13 #include "remoting/base/auto_thread_task_runner.h"
14 #include "remoting/base/constants.h" 14 #include "remoting/base/constants.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/desktop_environment.h"
18 #include "remoting/host/input_injector.h" 18 #include "remoting/host/input_injector.h"
19 #include "remoting/host/ipc_util.h" 19 #include "remoting/host/ipc_util.h"
20 #include "remoting/host/remote_input_filter.h" 20 #include "remoting/host/remote_input_filter.h"
21 #include "remoting/host/screen_controls.h" 21 #include "remoting/host/screen_controls.h"
22 #include "remoting/host/screen_resolution.h" 22 #include "remoting/host/screen_resolution.h"
23 #include "remoting/proto/audio.pb.h" 23 #include "remoting/proto/audio.pb.h"
24 #include "remoting/proto/control.pb.h" 24 #include "remoting/proto/control.pb.h"
25 #include "remoting/proto/event.pb.h" 25 #include "remoting/proto/event.pb.h"
26 #include "remoting/protocol/clipboard_stub.h" 26 #include "remoting/protocol/clipboard_stub.h"
27 #include "remoting/protocol/input_event_tracker.h" 27 #include "remoting/protocol/input_event_tracker.h"
28 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 28 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
29 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 29 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
30 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h"
31 #include "third_party/webrtc/modules/desktop_capture/shared_memory.h" 30 #include "third_party/webrtc/modules/desktop_capture/shared_memory.h"
32 31
33 namespace remoting { 32 namespace remoting {
34 33
35 namespace { 34 namespace {
36 35
37 // Routes local clipboard events though the IPC channel to the network process. 36 // Routes local clipboard events though the IPC channel to the network process.
38 class DesktopSesssionClipboardStub : public protocol::ClipboardStub { 37 class DesktopSesssionClipboardStub : public protocol::ClipboardStub {
39 public: 38 public:
40 explicit DesktopSesssionClipboardStub( 39 explicit DesktopSesssionClipboardStub(
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 new DesktopSesssionClipboardStub(this)); 285 new DesktopSesssionClipboardStub(this));
287 input_injector_->Start(clipboard_stub.Pass()); 286 input_injector_->Start(clipboard_stub.Pass());
288 287
289 // Start the audio capturer. 288 // Start the audio capturer.
290 if (delegate_->desktop_environment_factory().SupportsAudioCapture()) { 289 if (delegate_->desktop_environment_factory().SupportsAudioCapture()) {
291 audio_capturer_ = desktop_environment_->CreateAudioCapturer(); 290 audio_capturer_ = desktop_environment_->CreateAudioCapturer();
292 audio_capture_task_runner_->PostTask( 291 audio_capture_task_runner_->PostTask(
293 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this)); 292 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this));
294 } 293 }
295 294
296 // Start the video capturer and mouse cursor monitor. 295 // Start the video capturer.
297 video_capturer_ = desktop_environment_->CreateVideoCapturer(); 296 video_capturer_ = desktop_environment_->CreateVideoCapturer();
298 mouse_cursor_monitor_ = desktop_environment_->CreateMouseCursorMonitor();
299 video_capture_task_runner_->PostTask( 297 video_capture_task_runner_->PostTask(
300 FROM_HERE, base::Bind( 298 FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this));
301 &DesktopSessionAgent::StartVideoCapturerAndMouseMonitor, this));
302 } 299 }
303 300
304 void DesktopSessionAgent::OnCaptureCompleted(webrtc::DesktopFrame* frame) { 301 void DesktopSessionAgent::OnCaptureCompleted(webrtc::DesktopFrame* frame) {
305 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 302 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
306 303
307 last_frame_.reset(frame); 304 last_frame_.reset(frame);
308 305
309 current_size_ = frame->size(); 306 current_size_ = frame->size();
310 307
311 // Serialize webrtc::DesktopFrame. 308 // Serialize webrtc::DesktopFrame.
312 SerializedDesktopFrame serialized_frame; 309 SerializedDesktopFrame serialized_frame;
313 serialized_frame.shared_buffer_id = frame->shared_memory()->id(); 310 serialized_frame.shared_buffer_id = frame->shared_memory()->id();
314 serialized_frame.bytes_per_row = frame->stride(); 311 serialized_frame.bytes_per_row = frame->stride();
315 serialized_frame.dimensions = frame->size(); 312 serialized_frame.dimensions = frame->size();
316 serialized_frame.capture_time_ms = frame->capture_time_ms(); 313 serialized_frame.capture_time_ms = frame->capture_time_ms();
317 serialized_frame.dpi = frame->dpi(); 314 serialized_frame.dpi = frame->dpi();
318 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); 315 for (webrtc::DesktopRegion::Iterator i(frame->updated_region());
319 !i.IsAtEnd(); i.Advance()) { 316 !i.IsAtEnd(); i.Advance()) {
320 serialized_frame.dirty_region.push_back(i.rect()); 317 serialized_frame.dirty_region.push_back(i.rect());
321 } 318 }
322 319
323 SendToNetwork( 320 SendToNetwork(
324 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_frame)); 321 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_frame));
325 } 322 }
326 323
327 void DesktopSessionAgent::OnMouseCursor(webrtc::MouseCursor* cursor) { 324 void DesktopSessionAgent::OnCursorShapeChanged(
325 webrtc::MouseCursorShape* cursor_shape) {
328 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 326 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
329 327
330 scoped_ptr<webrtc::MouseCursor> owned_cursor(cursor); 328 scoped_ptr<webrtc::MouseCursorShape> owned_cursor(cursor_shape);
331 329
332 SendToNetwork( 330 SendToNetwork(new ChromotingDesktopNetworkMsg_CursorShapeChanged(
333 new ChromotingDesktopNetworkMsg_MouseCursor(*owned_cursor)); 331 *cursor_shape));
334 }
335
336 void DesktopSessionAgent::OnMouseCursorPosition(
337 webrtc::MouseCursorMonitor::CursorState state,
338 const webrtc::DesktopVector& position) {
339 // We're not subscribing to mouse position changes.
340 NOTREACHED();
341 } 332 }
342 333
343 void DesktopSessionAgent::InjectClipboardEvent( 334 void DesktopSessionAgent::InjectClipboardEvent(
344 const protocol::ClipboardEvent& event) { 335 const protocol::ClipboardEvent& event) {
345 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 336 DCHECK(caller_task_runner_->BelongsToCurrentThread());
346 337
347 std::string serialized_event; 338 std::string serialized_event;
348 if (!event.SerializeToString(&serialized_event)) { 339 if (!event.SerializeToString(&serialized_event)) {
349 LOG(ERROR) << "Failed to serialize protocol::ClipboardEvent."; 340 LOG(ERROR) << "Failed to serialize protocol::ClipboardEvent.";
350 return; 341 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 desktop_environment_.reset(); 397 desktop_environment_.reset();
407 input_injector_.reset(); 398 input_injector_.reset();
408 screen_controls_.reset(); 399 screen_controls_.reset();
409 400
410 // Stop the audio capturer. 401 // Stop the audio capturer.
411 audio_capture_task_runner_->PostTask( 402 audio_capture_task_runner_->PostTask(
412 FROM_HERE, base::Bind(&DesktopSessionAgent::StopAudioCapturer, this)); 403 FROM_HERE, base::Bind(&DesktopSessionAgent::StopAudioCapturer, this));
413 404
414 // Stop the video capturer. 405 // Stop the video capturer.
415 video_capture_task_runner_->PostTask( 406 video_capture_task_runner_->PostTask(
416 FROM_HERE, base::Bind( 407 FROM_HERE, base::Bind(&DesktopSessionAgent::StopVideoCapturer, this));
417 &DesktopSessionAgent::StopVideoCapturerAndMouseMonitor, this));
418 } 408 }
419 } 409 }
420 410
421 void DesktopSessionAgent::OnCaptureFrame() { 411 void DesktopSessionAgent::OnCaptureFrame() {
422 if (!video_capture_task_runner_->BelongsToCurrentThread()) { 412 if (!video_capture_task_runner_->BelongsToCurrentThread()) {
423 video_capture_task_runner_->PostTask( 413 video_capture_task_runner_->PostTask(
424 FROM_HERE, 414 FROM_HERE,
425 base::Bind(&DesktopSessionAgent::OnCaptureFrame, this)); 415 base::Bind(&DesktopSessionAgent::OnCaptureFrame, this));
426 return; 416 return;
427 } 417 }
428 418
429 mouse_cursor_monitor_->Capture();
430
431 // webrtc::ScreenCapturer supports a very few (currently 2) outstanding 419 // webrtc::ScreenCapturer supports a very few (currently 2) outstanding
432 // capture requests. The requests are serialized on 420 // capture requests. The requests are serialized on
433 // |video_capture_task_runner()| task runner. If the client issues more 421 // |video_capture_task_runner()| task runner. If the client issues more
434 // requests, pixel data in captured frames will likely be corrupted but 422 // requests, pixel data in captured frames will likely be corrupted but
435 // stability of webrtc::ScreenCapturer will not be affected. 423 // stability of webrtc::ScreenCapturer will not be affected.
436 video_capturer_->Capture(webrtc::DesktopRegion()); 424 video_capturer_->Capture(webrtc::DesktopRegion());
437 } 425 }
438 426
439 void DesktopSessionAgent::OnInjectClipboardEvent( 427 void DesktopSessionAgent::OnInjectClipboardEvent(
440 const std::string& serialized_event) { 428 const std::string& serialized_event) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 this)); 505 this));
518 } 506 }
519 } 507 }
520 508
521 void DesktopSessionAgent::StopAudioCapturer() { 509 void DesktopSessionAgent::StopAudioCapturer() {
522 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); 510 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread());
523 511
524 audio_capturer_.reset(); 512 audio_capturer_.reset();
525 } 513 }
526 514
527 void DesktopSessionAgent::StartVideoCapturerAndMouseMonitor() { 515 void DesktopSessionAgent::StartVideoCapturer() {
528 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 516 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
529 517
530 if (video_capturer_) { 518 if (video_capturer_) {
519 video_capturer_->SetMouseShapeObserver(this);
531 video_capturer_->Start(this); 520 video_capturer_->Start(this);
532 } 521 }
533
534 if (mouse_cursor_monitor_) {
535 mouse_cursor_monitor_->Init(this, webrtc::MouseCursorMonitor::SHAPE_ONLY);
536 }
537 } 522 }
538 523
539 void DesktopSessionAgent::StopVideoCapturerAndMouseMonitor() { 524 void DesktopSessionAgent::StopVideoCapturer() {
540 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 525 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
541 526
542 video_capturer_.reset(); 527 video_capturer_.reset();
543 last_frame_.reset(); 528 last_frame_.reset();
544 mouse_cursor_monitor_.reset();
545 529
546 // Video capturer must delete all buffers. 530 // Video capturer must delete all buffers.
547 DCHECK_EQ(shared_buffers_, 0); 531 DCHECK_EQ(shared_buffers_, 0);
548 } 532 }
549 533
550 void DesktopSessionAgent::OnSharedBufferDeleted(int id) { 534 void DesktopSessionAgent::OnSharedBufferDeleted(int id) {
551 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 535 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
552 DCHECK(id != 0); 536 DCHECK(id != 0);
553 537
554 shared_buffers_--; 538 shared_buffers_--;
555 DCHECK_GE(shared_buffers_, 0); 539 DCHECK_GE(shared_buffers_, 0);
556 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id)); 540 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id));
557 } 541 }
558 542
559 void DesktopSessionAgent::CloseDesktopPipeHandle() { 543 void DesktopSessionAgent::CloseDesktopPipeHandle() {
560 if (!(desktop_pipe_ == IPC::InvalidPlatformFileForTransit())) { 544 if (!(desktop_pipe_ == IPC::InvalidPlatformFileForTransit())) {
561 #if defined(OS_WIN) 545 #if defined(OS_WIN)
562 base::ClosePlatformFile(desktop_pipe_); 546 base::ClosePlatformFile(desktop_pipe_);
563 #elif defined(OS_POSIX) 547 #elif defined(OS_POSIX)
564 base::ClosePlatformFile(desktop_pipe_.fd); 548 base::ClosePlatformFile(desktop_pipe_.fd);
565 #else // !defined(OS_POSIX) 549 #else // !defined(OS_POSIX)
566 #error Unsupported platform. 550 #error Unsupported platform.
567 #endif // !defined(OS_POSIX) 551 #endif // !defined(OS_POSIX)
568 552
569 desktop_pipe_ = IPC::InvalidPlatformFileForTransit(); 553 desktop_pipe_ = IPC::InvalidPlatformFileForTransit();
570 } 554 }
571 } 555 }
572 556
573 } // namespace remoting 557 } // namespace remoting
OLDNEW
« no previous file with comments | « trunk/src/remoting/host/desktop_session_agent.h ('k') | trunk/src/remoting/host/desktop_session_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698