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

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

Issue 92473002: Use webrtc::MouseCursorMonitor for cursor shapes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux build Created 6 years, 4 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/desktop_session_agent.h ('k') | remoting/host/desktop_session_proxy.h » ('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/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"
30 #include "third_party/webrtc/modules/desktop_capture/shared_memory.h" 31 #include "third_party/webrtc/modules/desktop_capture/shared_memory.h"
31 32
32 namespace remoting { 33 namespace remoting {
33 34
34 namespace { 35 namespace {
35 36
36 // Routes local clipboard events though the IPC channel to the network process. 37 // Routes local clipboard events though the IPC channel to the network process.
37 class DesktopSesssionClipboardStub : public protocol::ClipboardStub { 38 class DesktopSesssionClipboardStub : public protocol::ClipboardStub {
38 public: 39 public:
39 explicit DesktopSesssionClipboardStub( 40 explicit DesktopSesssionClipboardStub(
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 new DesktopSesssionClipboardStub(this)); 292 new DesktopSesssionClipboardStub(this));
292 input_injector_->Start(clipboard_stub.Pass()); 293 input_injector_->Start(clipboard_stub.Pass());
293 294
294 // Start the audio capturer. 295 // Start the audio capturer.
295 if (delegate_->desktop_environment_factory().SupportsAudioCapture()) { 296 if (delegate_->desktop_environment_factory().SupportsAudioCapture()) {
296 audio_capturer_ = desktop_environment_->CreateAudioCapturer(); 297 audio_capturer_ = desktop_environment_->CreateAudioCapturer();
297 audio_capture_task_runner_->PostTask( 298 audio_capture_task_runner_->PostTask(
298 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this)); 299 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this));
299 } 300 }
300 301
301 // Start the video capturer. 302 // Start the video capturer and mouse cursor monitor.
302 video_capturer_ = desktop_environment_->CreateVideoCapturer(); 303 video_capturer_ = desktop_environment_->CreateVideoCapturer();
304 mouse_cursor_monitor_ = desktop_environment_->CreateMouseCursorMonitor();
303 video_capture_task_runner_->PostTask( 305 video_capture_task_runner_->PostTask(
304 FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this)); 306 FROM_HERE, base::Bind(
307 &DesktopSessionAgent::StartVideoCapturerAndMouseMonitor, this));
305 } 308 }
306 309
307 void DesktopSessionAgent::OnCaptureCompleted(webrtc::DesktopFrame* frame) { 310 void DesktopSessionAgent::OnCaptureCompleted(webrtc::DesktopFrame* frame) {
308 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 311 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
309 312
310 last_frame_.reset(frame); 313 last_frame_.reset(frame);
311 314
312 current_size_ = frame->size(); 315 current_size_ = frame->size();
313 316
314 // Serialize webrtc::DesktopFrame. 317 // Serialize webrtc::DesktopFrame.
315 SerializedDesktopFrame serialized_frame; 318 SerializedDesktopFrame serialized_frame;
316 serialized_frame.shared_buffer_id = frame->shared_memory()->id(); 319 serialized_frame.shared_buffer_id = frame->shared_memory()->id();
317 serialized_frame.bytes_per_row = frame->stride(); 320 serialized_frame.bytes_per_row = frame->stride();
318 serialized_frame.dimensions = frame->size(); 321 serialized_frame.dimensions = frame->size();
319 serialized_frame.capture_time_ms = frame->capture_time_ms(); 322 serialized_frame.capture_time_ms = frame->capture_time_ms();
320 serialized_frame.dpi = frame->dpi(); 323 serialized_frame.dpi = frame->dpi();
321 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); 324 for (webrtc::DesktopRegion::Iterator i(frame->updated_region());
322 !i.IsAtEnd(); i.Advance()) { 325 !i.IsAtEnd(); i.Advance()) {
323 serialized_frame.dirty_region.push_back(i.rect()); 326 serialized_frame.dirty_region.push_back(i.rect());
324 } 327 }
325 328
326 SendToNetwork( 329 SendToNetwork(
327 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_frame)); 330 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_frame));
328 } 331 }
329 332
330 void DesktopSessionAgent::OnCursorShapeChanged( 333 void DesktopSessionAgent::OnMouseCursor(webrtc::MouseCursor* cursor) {
331 webrtc::MouseCursorShape* cursor_shape) {
332 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 334 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
333 335
334 scoped_ptr<webrtc::MouseCursorShape> owned_cursor(cursor_shape); 336 scoped_ptr<webrtc::MouseCursor> owned_cursor(cursor);
335 337
336 SendToNetwork(new ChromotingDesktopNetworkMsg_CursorShapeChanged( 338 SendToNetwork(
337 *cursor_shape)); 339 new ChromotingDesktopNetworkMsg_MouseCursor(*owned_cursor));
340 }
341
342 void DesktopSessionAgent::OnMouseCursorPosition(
343 webrtc::MouseCursorMonitor::CursorState state,
344 const webrtc::DesktopVector& position) {
345 // We're not subscribing to mouse position changes.
346 NOTREACHED();
338 } 347 }
339 348
340 void DesktopSessionAgent::InjectClipboardEvent( 349 void DesktopSessionAgent::InjectClipboardEvent(
341 const protocol::ClipboardEvent& event) { 350 const protocol::ClipboardEvent& event) {
342 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 351 DCHECK(caller_task_runner_->BelongsToCurrentThread());
343 352
344 std::string serialized_event; 353 std::string serialized_event;
345 if (!event.SerializeToString(&serialized_event)) { 354 if (!event.SerializeToString(&serialized_event)) {
346 LOG(ERROR) << "Failed to serialize protocol::ClipboardEvent."; 355 LOG(ERROR) << "Failed to serialize protocol::ClipboardEvent.";
347 return; 356 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 desktop_environment_.reset(); 419 desktop_environment_.reset();
411 input_injector_.reset(); 420 input_injector_.reset();
412 screen_controls_.reset(); 421 screen_controls_.reset();
413 422
414 // Stop the audio capturer. 423 // Stop the audio capturer.
415 audio_capture_task_runner_->PostTask( 424 audio_capture_task_runner_->PostTask(
416 FROM_HERE, base::Bind(&DesktopSessionAgent::StopAudioCapturer, this)); 425 FROM_HERE, base::Bind(&DesktopSessionAgent::StopAudioCapturer, this));
417 426
418 // Stop the video capturer. 427 // Stop the video capturer.
419 video_capture_task_runner_->PostTask( 428 video_capture_task_runner_->PostTask(
420 FROM_HERE, base::Bind(&DesktopSessionAgent::StopVideoCapturer, this)); 429 FROM_HERE, base::Bind(
430 &DesktopSessionAgent::StopVideoCapturerAndMouseMonitor, this));
421 } 431 }
422 } 432 }
423 433
424 void DesktopSessionAgent::OnCaptureFrame() { 434 void DesktopSessionAgent::OnCaptureFrame() {
425 if (!video_capture_task_runner_->BelongsToCurrentThread()) { 435 if (!video_capture_task_runner_->BelongsToCurrentThread()) {
426 video_capture_task_runner_->PostTask( 436 video_capture_task_runner_->PostTask(
427 FROM_HERE, 437 FROM_HERE,
428 base::Bind(&DesktopSessionAgent::OnCaptureFrame, this)); 438 base::Bind(&DesktopSessionAgent::OnCaptureFrame, this));
429 return; 439 return;
430 } 440 }
431 441
442 mouse_cursor_monitor_->Capture();
443
432 // webrtc::ScreenCapturer supports a very few (currently 2) outstanding 444 // webrtc::ScreenCapturer supports a very few (currently 2) outstanding
433 // capture requests. The requests are serialized on 445 // capture requests. The requests are serialized on
434 // |video_capture_task_runner()| task runner. If the client issues more 446 // |video_capture_task_runner()| task runner. If the client issues more
435 // requests, pixel data in captured frames will likely be corrupted but 447 // requests, pixel data in captured frames will likely be corrupted but
436 // stability of webrtc::ScreenCapturer will not be affected. 448 // stability of webrtc::ScreenCapturer will not be affected.
437 video_capturer_->Capture(webrtc::DesktopRegion()); 449 video_capturer_->Capture(webrtc::DesktopRegion());
438 } 450 }
439 451
440 void DesktopSessionAgent::OnInjectClipboardEvent( 452 void DesktopSessionAgent::OnInjectClipboardEvent(
441 const std::string& serialized_event) { 453 const std::string& serialized_event) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 this)); 550 this));
539 } 551 }
540 } 552 }
541 553
542 void DesktopSessionAgent::StopAudioCapturer() { 554 void DesktopSessionAgent::StopAudioCapturer() {
543 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); 555 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread());
544 556
545 audio_capturer_.reset(); 557 audio_capturer_.reset();
546 } 558 }
547 559
548 void DesktopSessionAgent::StartVideoCapturer() { 560 void DesktopSessionAgent::StartVideoCapturerAndMouseMonitor() {
549 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 561 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
550 562
551 if (video_capturer_) { 563 if (video_capturer_) {
552 video_capturer_->SetMouseShapeObserver(this);
553 video_capturer_->Start(this); 564 video_capturer_->Start(this);
554 } 565 }
566
567 if (mouse_cursor_monitor_) {
568 mouse_cursor_monitor_->Init(this, webrtc::MouseCursorMonitor::SHAPE_ONLY);
569 }
555 } 570 }
556 571
557 void DesktopSessionAgent::StopVideoCapturer() { 572 void DesktopSessionAgent::StopVideoCapturerAndMouseMonitor() {
558 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 573 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
559 574
560 video_capturer_.reset(); 575 video_capturer_.reset();
561 last_frame_.reset(); 576 last_frame_.reset();
577 mouse_cursor_monitor_.reset();
562 578
563 // Video capturer must delete all buffers. 579 // Video capturer must delete all buffers.
564 DCHECK_EQ(shared_buffers_, 0); 580 DCHECK_EQ(shared_buffers_, 0);
565 } 581 }
566 582
567 void DesktopSessionAgent::OnSharedBufferDeleted(int id) { 583 void DesktopSessionAgent::OnSharedBufferDeleted(int id) {
568 DCHECK(video_capture_task_runner_->BelongsToCurrentThread()); 584 DCHECK(video_capture_task_runner_->BelongsToCurrentThread());
569 DCHECK(id != 0); 585 DCHECK(id != 0);
570 586
571 shared_buffers_--; 587 shared_buffers_--;
572 DCHECK_GE(shared_buffers_, 0); 588 DCHECK_GE(shared_buffers_, 0);
573 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id)); 589 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id));
574 } 590 }
575 591
576 } // namespace remoting 592 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/desktop_session_agent.h ('k') | remoting/host/desktop_session_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698