| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/host/local_desktop_environment.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/single_thread_task_runner.h" |
| 9 #include "remoting/capturer/video_frame_capturer.h" |
| 10 #include "remoting/codec/audio_encoder.h" |
| 11 #include "remoting/host/audio_capturer.h" |
| 12 #include "remoting/host/audio_scheduler.h" |
| 13 #include "remoting/host/event_executor.h" |
| 14 #include "remoting/host/video_scheduler.h" |
| 15 #include "remoting/protocol/clipboard_thread_proxy.h" |
| 16 |
| 17 namespace remoting { |
| 18 |
| 19 LocalDesktopEnvironment::LocalDesktopEnvironment( |
| 20 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 21 const CreateEventExecutorCallback& create_event_executor_callback) |
| 22 : caller_task_runner_(caller_task_runner), |
| 23 create_event_executor_callback_(create_event_executor_callback) { |
| 24 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 25 } |
| 26 |
| 27 LocalDesktopEnvironment::~LocalDesktopEnvironment() { |
| 28 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 29 |
| 30 // Stop the video scheduler and clear references to the client's stubs. |
| 31 if (video_scheduler_.get()) { |
| 32 video_scheduler_->Stop(); |
| 33 video_scheduler_ = NULL; |
| 34 } |
| 35 |
| 36 // Stop the audio scheduler and clear references to the client's stubs. |
| 37 if (audio_scheduler_.get()) { |
| 38 audio_scheduler_->Stop(); |
| 39 audio_scheduler_ = NULL; |
| 40 } |
| 41 } |
| 42 |
| 43 void LocalDesktopEnvironment::InjectClipboardEvent( |
| 44 const protocol::ClipboardEvent& event) { |
| 45 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 46 |
| 47 event_executor_->InjectClipboardEvent(event); |
| 48 } |
| 49 |
| 50 void LocalDesktopEnvironment::InjectKeyEvent(const protocol::KeyEvent& event) { |
| 51 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 52 |
| 53 event_executor_->InjectKeyEvent(event); |
| 54 } |
| 55 |
| 56 void LocalDesktopEnvironment::InjectMouseEvent( |
| 57 const protocol::MouseEvent& event) { |
| 58 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 59 |
| 60 event_executor_->InjectMouseEvent(event); |
| 61 } |
| 62 |
| 63 void LocalDesktopEnvironment::StartAudio( |
| 64 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, |
| 65 scoped_ptr<AudioEncoder> audio_encoder, |
| 66 protocol::AudioStub* audio_stub) { |
| 67 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 68 DCHECK(!audio_scheduler_.get()); |
| 69 |
| 70 // Create and start the audio scheduler. The |audio_stub| reference is cleared |
| 71 // by ~LocalDesktopEnvironment(). |
| 72 audio_scheduler_ = AudioScheduler::Create(audio_task_runner, |
| 73 caller_task_runner_, |
| 74 AudioCapturer::Create(), |
| 75 audio_encoder.Pass(), |
| 76 audio_stub); |
| 77 } |
| 78 |
| 79 void LocalDesktopEnvironment::PauseAudio(bool pause) { |
| 80 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 81 |
| 82 if (audio_scheduler_.get()) |
| 83 audio_scheduler_->Pause(pause); |
| 84 } |
| 85 |
| 86 void LocalDesktopEnvironment::StartInput( |
| 87 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 88 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 89 protocol::ClipboardStub* clipboard_stub) { |
| 90 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 91 DCHECK(!clipboard_factory_); |
| 92 DCHECK(!event_executor_); |
| 93 |
| 94 event_executor_ = create_event_executor_callback_.Run(input_task_runner, |
| 95 ui_task_runner); |
| 96 create_event_executor_callback_.Reset(); |
| 97 |
| 98 // Create a weak pointer from |clipboard_stub| so that we can stop receiving |
| 99 // local clipboard events during shutdown. |
| 100 clipboard_factory_.reset( |
| 101 new base::WeakPtrFactory<protocol::ClipboardStub>(clipboard_stub)); |
| 102 event_executor_->Start(scoped_ptr<protocol::ClipboardStub>( |
| 103 new protocol::ClipboardThreadProxy( |
| 104 clipboard_factory_->GetWeakPtr(), caller_task_runner_))); |
| 105 } |
| 106 |
| 107 void LocalDesktopEnvironment::StartVideo( |
| 108 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
| 109 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
| 110 scoped_ptr<VideoEncoder> video_encoder, |
| 111 protocol::CursorShapeStub* cursor_shape_stub, |
| 112 protocol::VideoStub* video_stub) { |
| 113 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 114 DCHECK(!video_scheduler_.get()); |
| 115 |
| 116 // Create and start video scheduler. The |cursor_shape_stub| and |video_stub| |
| 117 // references are cleared by ~LocalDesktopEnvironment(). |
| 118 video_scheduler_ = VideoScheduler::Create(capture_task_runner, |
| 119 encode_task_runner, |
| 120 caller_task_runner_, |
| 121 VideoFrameCapturer::Create(), |
| 122 video_encoder.Pass(), |
| 123 cursor_shape_stub, |
| 124 video_stub); |
| 125 } |
| 126 |
| 127 SkISize LocalDesktopEnvironment::GetScreenSize() const { |
| 128 if (video_scheduler_.get()) |
| 129 return video_scheduler_->size_most_recent(); |
| 130 else |
| 131 return SkISize::Make(0, 0); |
| 132 } |
| 133 |
| 134 void LocalDesktopEnvironment::PauseVideo(bool pause) { |
| 135 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 136 |
| 137 if (video_scheduler_.get()) |
| 138 video_scheduler_->Pause(pause); |
| 139 } |
| 140 |
| 141 void LocalDesktopEnvironment::UpdateSequenceNumber(int64 sequence_number) { |
| 142 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 143 |
| 144 if (video_scheduler_.get()) |
| 145 video_scheduler_->UpdateSequenceNumber(sequence_number); |
| 146 } |
| 147 |
| 148 } // namespace remoting |
| OLD | NEW |