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_agent.h" | 5 #include "remoting/host/desktop_session_agent.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ipc/ipc_channel_proxy.h" | 8 #include "ipc/ipc_channel_proxy.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
| 11 #include "media/video/capture/screen/screen_capture_data.h" |
11 #include "remoting/base/auto_thread_task_runner.h" | 12 #include "remoting/base/auto_thread_task_runner.h" |
12 #include "remoting/base/constants.h" | 13 #include "remoting/base/constants.h" |
13 #include "remoting/base/util.h" | 14 #include "remoting/base/util.h" |
14 #include "remoting/capturer/capture_data.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/disconnect_window.h" | 17 #include "remoting/host/disconnect_window.h" |
18 #include "remoting/host/event_executor.h" | 18 #include "remoting/host/event_executor.h" |
19 #include "remoting/host/local_input_monitor.h" | 19 #include "remoting/host/local_input_monitor.h" |
20 #include "remoting/host/remote_input_filter.h" | 20 #include "remoting/host/remote_input_filter.h" |
21 #include "remoting/proto/audio.pb.h" | 21 #include "remoting/proto/audio.pb.h" |
22 #include "remoting/proto/control.pb.h" | 22 #include "remoting/proto/control.pb.h" |
23 #include "remoting/proto/event.pb.h" | 23 #include "remoting/proto/event.pb.h" |
24 #include "remoting/protocol/clipboard_stub.h" | 24 #include "remoting/protocol/clipboard_stub.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if (delegate_.get()) | 130 if (delegate_.get()) |
131 delegate_->OnNetworkProcessDisconnected(); | 131 delegate_->OnNetworkProcessDisconnected(); |
132 } | 132 } |
133 | 133 |
134 void DesktopSessionAgent::OnLocalMouseMoved(const SkIPoint& new_pos) { | 134 void DesktopSessionAgent::OnLocalMouseMoved(const SkIPoint& new_pos) { |
135 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 135 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
136 | 136 |
137 remote_input_filter_->LocalMouseMoved(new_pos); | 137 remote_input_filter_->LocalMouseMoved(new_pos); |
138 } | 138 } |
139 | 139 |
140 scoped_refptr<SharedBuffer> DesktopSessionAgent::CreateSharedBuffer( | 140 scoped_refptr<media::SharedBuffer> DesktopSessionAgent::CreateSharedBuffer( |
141 uint32 size) { | 141 uint32 size) { |
142 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 142 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
143 | 143 |
144 scoped_refptr<SharedBuffer> buffer = new SharedBuffer(size); | 144 scoped_refptr<media::SharedBuffer> buffer = new media::SharedBuffer(size); |
145 if (buffer->ptr() != NULL) { | 145 if (buffer->ptr() != NULL) { |
146 buffer->set_id(next_shared_buffer_id_); | 146 buffer->set_id(next_shared_buffer_id_); |
147 shared_buffers_.push_back(buffer); | 147 shared_buffers_.push_back(buffer); |
148 | 148 |
149 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes | 149 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes |
150 // sure it is always odd and therefore zero is never used as a valid buffer | 150 // sure it is always odd and therefore zero is never used as a valid buffer |
151 // ID. | 151 // ID. |
152 // | 152 // |
153 // It is very unlikely (though theoretically possible) to allocate the same | 153 // It is very unlikely (though theoretically possible) to allocate the same |
154 // ID for two different buffers due to integer overflow. It should take | 154 // ID for two different buffers due to integer overflow. It should take |
155 // about a year of allocating 100 new buffers every second. Practically | 155 // about a year of allocating 100 new buffers every second. Practically |
156 // speaking it never happens. | 156 // speaking it never happens. |
157 next_shared_buffer_id_ += 2; | 157 next_shared_buffer_id_ += 2; |
158 | 158 |
159 SendToNetwork(new ChromotingDesktopNetworkMsg_CreateSharedBuffer( | 159 SendToNetwork(new ChromotingDesktopNetworkMsg_CreateSharedBuffer( |
160 buffer->id(), buffer->handle(), buffer->size())); | 160 buffer->id(), buffer->handle(), buffer->size())); |
161 } | 161 } |
162 | 162 |
163 return buffer; | 163 return buffer; |
164 } | 164 } |
165 | 165 |
166 void DesktopSessionAgent::ReleaseSharedBuffer( | 166 void DesktopSessionAgent::ReleaseSharedBuffer( |
167 scoped_refptr<SharedBuffer> buffer) { | 167 scoped_refptr<media::SharedBuffer> buffer) { |
168 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 168 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
169 DCHECK(buffer->id() != 0); | 169 DCHECK(buffer->id() != 0); |
170 | 170 |
171 SendToNetwork( | 171 SendToNetwork( |
172 new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(buffer->id())); | 172 new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(buffer->id())); |
173 } | 173 } |
174 | 174 |
175 void DesktopSessionAgent::OnStartSessionAgent( | 175 void DesktopSessionAgent::OnStartSessionAgent( |
176 const std::string& authenticated_jid) { | 176 const std::string& authenticated_jid) { |
177 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 177 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
(...skipping 29 matching lines...) Expand all Loading... |
207 // Start the audio capturer. | 207 // Start the audio capturer. |
208 audio_capture_task_runner()->PostTask( | 208 audio_capture_task_runner()->PostTask( |
209 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this)); | 209 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this)); |
210 | 210 |
211 // Start the video capturer. | 211 // Start the video capturer. |
212 video_capture_task_runner()->PostTask( | 212 video_capture_task_runner()->PostTask( |
213 FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this)); | 213 FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this)); |
214 } | 214 } |
215 | 215 |
216 void DesktopSessionAgent::OnCaptureCompleted( | 216 void DesktopSessionAgent::OnCaptureCompleted( |
217 scoped_refptr<CaptureData> capture_data) { | 217 scoped_refptr<media::ScreenCaptureData> capture_data) { |
218 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 218 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
219 | 219 |
220 current_size_ = capture_data->size(); | 220 current_size_ = capture_data->size(); |
221 | 221 |
222 // Serialize CaptureData | 222 // Serialize media::ScreenCaptureData |
223 SerializedCapturedData serialized_data; | 223 SerializedCapturedData serialized_data; |
224 serialized_data.shared_buffer_id = capture_data->shared_buffer()->id(); | 224 serialized_data.shared_buffer_id = capture_data->shared_buffer()->id(); |
225 serialized_data.bytes_per_row = capture_data->stride(); | 225 serialized_data.bytes_per_row = capture_data->stride(); |
226 serialized_data.dimensions = capture_data->size(); | 226 serialized_data.dimensions = capture_data->size(); |
227 serialized_data.capture_time_ms = capture_data->capture_time_ms(); | 227 serialized_data.capture_time_ms = capture_data->capture_time_ms(); |
228 serialized_data.client_sequence_number = | 228 serialized_data.client_sequence_number = |
229 capture_data->client_sequence_number(); | 229 capture_data->client_sequence_number(); |
230 serialized_data.dpi = capture_data->dpi(); | 230 serialized_data.dpi = capture_data->dpi(); |
231 for (SkRegion::Iterator i(capture_data->dirty_region()); !i.done(); i.next()) | 231 for (SkRegion::Iterator i(capture_data->dirty_region()); !i.done(); i.next()) |
232 serialized_data.dirty_region.push_back(i.rect()); | 232 serialized_data.dirty_region.push_back(i.rect()); |
233 | 233 |
234 SendToNetwork( | 234 SendToNetwork( |
235 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_data)); | 235 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_data)); |
236 } | 236 } |
237 | 237 |
238 void DesktopSessionAgent::OnCursorShapeChanged( | 238 void DesktopSessionAgent::OnCursorShapeChanged( |
239 scoped_ptr<MouseCursorShape> cursor_shape) { | 239 scoped_ptr<media::MouseCursorShape> cursor_shape) { |
240 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 240 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
241 | 241 |
242 SendToNetwork(new ChromotingDesktopNetworkMsg_CursorShapeChanged( | 242 SendToNetwork(new ChromotingDesktopNetworkMsg_CursorShapeChanged( |
243 *cursor_shape)); | 243 *cursor_shape)); |
244 } | 244 } |
245 | 245 |
246 void DesktopSessionAgent::InjectClipboardEvent( | 246 void DesktopSessionAgent::InjectClipboardEvent( |
247 const protocol::ClipboardEvent& event) { | 247 const protocol::ClipboardEvent& event) { |
248 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 248 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
249 | 249 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 318 } |
319 | 319 |
320 void DesktopSessionAgent::OnCaptureFrame() { | 320 void DesktopSessionAgent::OnCaptureFrame() { |
321 if (!video_capture_task_runner()->BelongsToCurrentThread()) { | 321 if (!video_capture_task_runner()->BelongsToCurrentThread()) { |
322 video_capture_task_runner()->PostTask( | 322 video_capture_task_runner()->PostTask( |
323 FROM_HERE, | 323 FROM_HERE, |
324 base::Bind(&DesktopSessionAgent::OnCaptureFrame, this)); | 324 base::Bind(&DesktopSessionAgent::OnCaptureFrame, this)); |
325 return; | 325 return; |
326 } | 326 } |
327 | 327 |
328 // VideoFrameCapturer supports a very few (currently 2) outstanding capture | 328 // media::ScreenCapturer supports a very few (currently 2) outstanding capture |
329 // requests. The requests are serialized on |video_capture_task_runner()| task | 329 // requests. The requests are serialized on |video_capture_task_runner()| task |
330 // runner. If the client issues more requests, pixel data in captured frames | 330 // runner. If the client issues more requests, pixel data in captured frames |
331 // will likely be corrupted but stability of VideoFrameCapturer will not be | 331 // will likely be corrupted but stability of media::ScreenCapturer will not be |
332 // affected. | 332 // affected. |
333 video_capturer_->CaptureFrame(); | 333 video_capturer_->CaptureFrame(); |
334 } | 334 } |
335 | 335 |
336 void DesktopSessionAgent::OnInvalidateRegion( | 336 void DesktopSessionAgent::OnInvalidateRegion( |
337 const std::vector<SkIRect>& invalid_rects) { | 337 const std::vector<SkIRect>& invalid_rects) { |
338 if (!video_capture_task_runner()->BelongsToCurrentThread()) { | 338 if (!video_capture_task_runner()->BelongsToCurrentThread()) { |
339 video_capture_task_runner()->PostTask( | 339 video_capture_task_runner()->PostTask( |
340 FROM_HERE, | 340 FROM_HERE, |
341 base::Bind(&DesktopSessionAgent::OnInvalidateRegion, this, | 341 base::Bind(&DesktopSessionAgent::OnInvalidateRegion, this, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 479 |
480 void DesktopSessionAgent::StopAudioCapturer() { | 480 void DesktopSessionAgent::StopAudioCapturer() { |
481 DCHECK(audio_capture_task_runner()->BelongsToCurrentThread()); | 481 DCHECK(audio_capture_task_runner()->BelongsToCurrentThread()); |
482 | 482 |
483 audio_capturer_.reset(); | 483 audio_capturer_.reset(); |
484 } | 484 } |
485 | 485 |
486 void DesktopSessionAgent::StartVideoCapturer() { | 486 void DesktopSessionAgent::StartVideoCapturer() { |
487 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 487 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
488 | 488 |
489 video_capturer_ = VideoFrameCapturer::CreateWithFactory(this); | 489 video_capturer_ = media::ScreenCapturer::CreateWithFactory(this); |
490 if (video_capturer_) | 490 if (video_capturer_) |
491 video_capturer_->Start(this); | 491 video_capturer_->Start(this); |
492 } | 492 } |
493 | 493 |
494 void DesktopSessionAgent::StopVideoCapturer() { | 494 void DesktopSessionAgent::StopVideoCapturer() { |
495 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 495 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
496 | 496 |
497 if (video_capturer_) { | 497 if (video_capturer_) { |
498 video_capturer_->Stop(); | 498 video_capturer_->Stop(); |
499 video_capturer_.reset(); | 499 video_capturer_.reset(); |
(...skipping 14 matching lines...) Expand all Loading... |
514 input_task_runner_(input_task_runner), | 514 input_task_runner_(input_task_runner), |
515 io_task_runner_(io_task_runner), | 515 io_task_runner_(io_task_runner), |
516 video_capture_task_runner_(video_capture_task_runner), | 516 video_capture_task_runner_(video_capture_task_runner), |
517 current_size_(SkISize::Make(0, 0)), | 517 current_size_(SkISize::Make(0, 0)), |
518 next_shared_buffer_id_(1), | 518 next_shared_buffer_id_(1), |
519 started_(false) { | 519 started_(false) { |
520 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 520 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
521 } | 521 } |
522 | 522 |
523 } // namespace remoting | 523 } // namespace remoting |
OLD | NEW |