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

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

Issue 12047101: Move screen capturers from remoting/capturer to media/video/capturer/screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
« no previous file with comments | « remoting/host/desktop_session_proxy.h ('k') | remoting/host/event_executor_mac.cc » ('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_proxy.h" 5 #include "remoting/host/desktop_session_proxy.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/platform_file.h" 9 #include "base/platform_file.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "ipc/ipc_channel_proxy.h" 11 #include "ipc/ipc_channel_proxy.h"
12 #include "ipc/ipc_message_macros.h" 12 #include "ipc/ipc_message_macros.h"
13 #include "remoting/capturer/capture_data.h" 13 #include "media/video/capture/screen/screen_capture_data.h"
14 #include "remoting/host/audio_capturer.h" 14 #include "remoting/host/audio_capturer.h"
15 #include "remoting/host/chromoting_messages.h" 15 #include "remoting/host/chromoting_messages.h"
16 #include "remoting/host/client_session.h" 16 #include "remoting/host/client_session.h"
17 #include "remoting/host/ipc_audio_capturer.h" 17 #include "remoting/host/ipc_audio_capturer.h"
18 #include "remoting/host/ipc_event_executor.h" 18 #include "remoting/host/ipc_event_executor.h"
19 #include "remoting/host/ipc_video_frame_capturer.h" 19 #include "remoting/host/ipc_video_frame_capturer.h"
20 #include "remoting/proto/audio.pb.h" 20 #include "remoting/proto/audio.pb.h"
21 #include "remoting/proto/control.pb.h" 21 #include "remoting/proto/control.pb.h"
22 #include "remoting/proto/event.pb.h" 22 #include "remoting/proto/event.pb.h"
23 23
(...skipping 28 matching lines...) Expand all
52 } 52 }
53 53
54 scoped_ptr<EventExecutor> DesktopSessionProxy::CreateEventExecutor( 54 scoped_ptr<EventExecutor> DesktopSessionProxy::CreateEventExecutor(
55 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, 55 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
56 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { 56 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
57 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 57 DCHECK(caller_task_runner_->BelongsToCurrentThread());
58 58
59 return scoped_ptr<EventExecutor>(new IpcEventExecutor(this)); 59 return scoped_ptr<EventExecutor>(new IpcEventExecutor(this));
60 } 60 }
61 61
62 scoped_ptr<VideoFrameCapturer> DesktopSessionProxy::CreateVideoCapturer( 62 scoped_ptr<media::ScreenCapturer> DesktopSessionProxy::CreateVideoCapturer(
63 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 63 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
64 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) { 64 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner) {
65 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 65 DCHECK(caller_task_runner_->BelongsToCurrentThread());
66 DCHECK(!video_capture_task_runner_.get()); 66 DCHECK(!video_capture_task_runner_.get());
67 67
68 video_capture_task_runner_ = capture_task_runner; 68 video_capture_task_runner_ = capture_task_runner;
69 return scoped_ptr<VideoFrameCapturer>(new IpcVideoFrameCapturer(this)); 69 return scoped_ptr<media::ScreenCapturer>(new IpcVideoFrameCapturer(this));
70 } 70 }
71 71
72 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) { 72 bool DesktopSessionProxy::OnMessageReceived(const IPC::Message& message) {
73 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 73 DCHECK(caller_task_runner_->BelongsToCurrentThread());
74 74
75 bool handled = true; 75 bool handled = true;
76 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message) 76 IPC_BEGIN_MESSAGE_MAP(DesktopSessionProxy, message)
77 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket, 77 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_AudioPacket,
78 OnAudioPacket) 78 OnAudioPacket)
79 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureCompleted, 79 IPC_MESSAGE_HANDLER(ChromotingDesktopNetworkMsg_CaptureCompleted,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 #if defined(OS_WIN) 163 #if defined(OS_WIN)
164 desktop_process_.Close(); 164 desktop_process_.Close();
165 #endif // defined(OS_WIN) 165 #endif // defined(OS_WIN)
166 166
167 shared_buffers_.clear(); 167 shared_buffers_.clear();
168 168
169 // Generate fake responses to keep the video capturer in sync. 169 // Generate fake responses to keep the video capturer in sync.
170 while (pending_capture_frame_requests_) { 170 while (pending_capture_frame_requests_) {
171 --pending_capture_frame_requests_; 171 --pending_capture_frame_requests_;
172 PostCaptureCompleted(scoped_refptr<CaptureData>()); 172 PostCaptureCompleted(scoped_refptr<media::ScreenCaptureData>());
173 } 173 }
174 } 174 }
175 175
176 void DesktopSessionProxy::StartAudioCapturer(IpcAudioCapturer* audio_capturer) { 176 void DesktopSessionProxy::StartAudioCapturer(IpcAudioCapturer* audio_capturer) {
177 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread()); 177 DCHECK(audio_capture_task_runner_->BelongsToCurrentThread());
178 DCHECK(audio_capturer_ == NULL); 178 DCHECK(audio_capturer_ == NULL);
179 179
180 audio_capturer_ = audio_capturer; 180 audio_capturer_ = audio_capturer;
181 } 181 }
182 182
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 void DesktopSessionProxy::StartEventExecutor( 277 void DesktopSessionProxy::StartEventExecutor(
278 scoped_ptr<protocol::ClipboardStub> client_clipboard) { 278 scoped_ptr<protocol::ClipboardStub> client_clipboard) {
279 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 279 DCHECK(caller_task_runner_->BelongsToCurrentThread());
280 280
281 client_clipboard_ = client_clipboard.Pass(); 281 client_clipboard_ = client_clipboard.Pass();
282 } 282 }
283 283
284 DesktopSessionProxy::~DesktopSessionProxy() { 284 DesktopSessionProxy::~DesktopSessionProxy() {
285 } 285 }
286 286
287 scoped_refptr<SharedBuffer> DesktopSessionProxy::GetSharedBuffer(int id) { 287 scoped_refptr<media::SharedBuffer> DesktopSessionProxy::GetSharedBuffer(
288 int id) {
288 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 289 DCHECK(caller_task_runner_->BelongsToCurrentThread());
289 290
290 SharedBuffers::const_iterator i = shared_buffers_.find(id); 291 SharedBuffers::const_iterator i = shared_buffers_.find(id);
291 if (i != shared_buffers_.end()) { 292 if (i != shared_buffers_.end()) {
292 return i->second; 293 return i->second;
293 } else { 294 } else {
294 LOG(ERROR) << "Failed to find the shared buffer " << id; 295 LOG(ERROR) << "Failed to find the shared buffer " << id;
295 return scoped_refptr<SharedBuffer>(); 296 return scoped_refptr<media::SharedBuffer>();
296 } 297 }
297 } 298 }
298 299
299 void DesktopSessionProxy::OnAudioPacket(const std::string& serialized_packet) { 300 void DesktopSessionProxy::OnAudioPacket(const std::string& serialized_packet) {
300 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 301 DCHECK(caller_task_runner_->BelongsToCurrentThread());
301 302
302 // Parse the serialized audio packet. No further validation is done since 303 // Parse the serialized audio packet. No further validation is done since
303 // the message was send by more privileged process. 304 // the message was send by more privileged process.
304 scoped_ptr<AudioPacket> packet(new AudioPacket()); 305 scoped_ptr<AudioPacket> packet(new AudioPacket());
305 if (!packet->ParseFromString(serialized_packet)) { 306 if (!packet->ParseFromString(serialized_packet)) {
306 LOG(ERROR) << "Failed to parse AudioPacket."; 307 LOG(ERROR) << "Failed to parse AudioPacket.";
307 return; 308 return;
308 } 309 }
309 310
310 PostAudioPacket(packet.Pass()); 311 PostAudioPacket(packet.Pass());
311 } 312 }
312 313
313 void DesktopSessionProxy::OnCreateSharedBuffer( 314 void DesktopSessionProxy::OnCreateSharedBuffer(
314 int id, 315 int id,
315 IPC::PlatformFileForTransit handle, 316 IPC::PlatformFileForTransit handle,
316 uint32 size) { 317 uint32 size) {
317 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 318 DCHECK(caller_task_runner_->BelongsToCurrentThread());
318 319
319 scoped_refptr<SharedBuffer> shared_buffer; 320 scoped_refptr<media::SharedBuffer> shared_buffer;
320 321
321 #if defined(OS_WIN) 322 #if defined(OS_WIN)
322 shared_buffer = new SharedBuffer(id, handle, desktop_process_, size); 323 shared_buffer = new media::SharedBuffer(id, handle, desktop_process_, size);
323 #elif defined(OS_POSIX) 324 #elif defined(OS_POSIX)
324 shared_buffer = new SharedBuffer(id, handle, size); 325 shared_buffer = new media::SharedBuffer(id, handle, size);
325 #else 326 #else
326 #error Unsupported platform. 327 #error Unsupported platform.
327 #endif 328 #endif
328 329
329 // Check if the buffer has been successfully mapped. 330 // Check if the buffer has been successfully mapped.
330 bool mapped = shared_buffer->ptr() != NULL; 331 bool mapped = shared_buffer->ptr() != NULL;
331 if (!mapped) { 332 if (!mapped) {
332 #if defined(OS_WIN) 333 #if defined(OS_WIN)
333 LOG(ERROR) << "Failed to map a shared buffer: id=" << id 334 LOG(ERROR) << "Failed to map a shared buffer: id=" << id
334 << ", handle=" << handle 335 << ", handle=" << handle
(...skipping 21 matching lines...) Expand all
356 // Drop the cached reference to the buffer. 357 // Drop the cached reference to the buffer.
357 shared_buffers_.erase(id); 358 shared_buffers_.erase(id);
358 } 359 }
359 360
360 void DesktopSessionProxy::OnCaptureCompleted( 361 void DesktopSessionProxy::OnCaptureCompleted(
361 const SerializedCapturedData& serialized_data) { 362 const SerializedCapturedData& serialized_data) {
362 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 363 DCHECK(caller_task_runner_->BelongsToCurrentThread());
363 364
364 // Assume that |serialized_data| is well formed because it was received from 365 // Assume that |serialized_data| is well formed because it was received from
365 // a more privileged process. 366 // a more privileged process.
366 scoped_refptr<CaptureData> capture_data; 367 scoped_refptr<media::ScreenCaptureData> capture_data;
367 scoped_refptr<SharedBuffer> shared_buffer = 368 scoped_refptr<media::SharedBuffer> shared_buffer =
368 GetSharedBuffer(serialized_data.shared_buffer_id); 369 GetSharedBuffer(serialized_data.shared_buffer_id);
369 CHECK(shared_buffer); 370 CHECK(shared_buffer);
370 371
371 capture_data = new CaptureData(reinterpret_cast<uint8*>(shared_buffer->ptr()), 372 capture_data = new media::ScreenCaptureData(
372 serialized_data.bytes_per_row, 373 reinterpret_cast<uint8*>(shared_buffer->ptr()),
373 serialized_data.dimensions); 374 serialized_data.bytes_per_row,
375 serialized_data.dimensions);
374 capture_data->set_capture_time_ms(serialized_data.capture_time_ms); 376 capture_data->set_capture_time_ms(serialized_data.capture_time_ms);
375 capture_data->set_client_sequence_number( 377 capture_data->set_client_sequence_number(
376 serialized_data.client_sequence_number); 378 serialized_data.client_sequence_number);
377 capture_data->set_dpi(serialized_data.dpi); 379 capture_data->set_dpi(serialized_data.dpi);
378 capture_data->set_shared_buffer(shared_buffer); 380 capture_data->set_shared_buffer(shared_buffer);
379 381
380 if (!serialized_data.dirty_region.empty()) { 382 if (!serialized_data.dirty_region.empty()) {
381 capture_data->mutable_dirty_region().setRects( 383 capture_data->mutable_dirty_region().setRects(
382 &serialized_data.dirty_region[0], 384 &serialized_data.dirty_region[0],
383 serialized_data.dirty_region.size()); 385 serialized_data.dirty_region.size());
384 } 386 }
385 387
386 --pending_capture_frame_requests_; 388 --pending_capture_frame_requests_;
387 PostCaptureCompleted(capture_data); 389 PostCaptureCompleted(capture_data);
388 } 390 }
389 391
390 void DesktopSessionProxy::OnCursorShapeChanged( 392 void DesktopSessionProxy::OnCursorShapeChanged(
391 const MouseCursorShape& cursor_shape) { 393 const media::MouseCursorShape& cursor_shape) {
392 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 394 DCHECK(caller_task_runner_->BelongsToCurrentThread());
393 PostCursorShape( 395 PostCursorShape(scoped_ptr<media::MouseCursorShape>(
394 scoped_ptr<MouseCursorShape>(new MouseCursorShape(cursor_shape))); 396 new media::MouseCursorShape(cursor_shape)));
395 } 397 }
396 398
397 void DesktopSessionProxy::OnInjectClipboardEvent( 399 void DesktopSessionProxy::OnInjectClipboardEvent(
398 const std::string& serialized_event) { 400 const std::string& serialized_event) {
399 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 401 DCHECK(caller_task_runner_->BelongsToCurrentThread());
400 402
401 if (client_clipboard_) { 403 if (client_clipboard_) {
402 protocol::ClipboardEvent event; 404 protocol::ClipboardEvent event;
403 if (!event.ParseFromString(serialized_event)) { 405 if (!event.ParseFromString(serialized_event)) {
404 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent."; 406 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent.";
(...skipping 10 matching lines...) Expand all
415 FROM_HERE, base::Bind(&DesktopSessionProxy::PostAudioPacket, 417 FROM_HERE, base::Bind(&DesktopSessionProxy::PostAudioPacket,
416 this, base::Passed(&packet))); 418 this, base::Passed(&packet)));
417 return; 419 return;
418 } 420 }
419 421
420 if (audio_capturer_) 422 if (audio_capturer_)
421 audio_capturer_->OnAudioPacket(packet.Pass()); 423 audio_capturer_->OnAudioPacket(packet.Pass());
422 } 424 }
423 425
424 void DesktopSessionProxy::PostCaptureCompleted( 426 void DesktopSessionProxy::PostCaptureCompleted(
425 scoped_refptr<CaptureData> capture_data) { 427 scoped_refptr<media::ScreenCaptureData> capture_data) {
426 if (!video_capture_task_runner_->BelongsToCurrentThread()) { 428 if (!video_capture_task_runner_->BelongsToCurrentThread()) {
427 video_capture_task_runner_->PostTask( 429 video_capture_task_runner_->PostTask(
428 FROM_HERE, base::Bind(&DesktopSessionProxy::PostCaptureCompleted, 430 FROM_HERE, base::Bind(&DesktopSessionProxy::PostCaptureCompleted,
429 this, capture_data)); 431 this, capture_data));
430 return; 432 return;
431 } 433 }
432 434
433 if (video_capturer_) 435 if (video_capturer_)
434 video_capturer_->OnCaptureCompleted(capture_data); 436 video_capturer_->OnCaptureCompleted(capture_data);
435 } 437 }
436 438
437 void DesktopSessionProxy::PostCursorShape( 439 void DesktopSessionProxy::PostCursorShape(
438 scoped_ptr<MouseCursorShape> cursor_shape) { 440 scoped_ptr<media::MouseCursorShape> cursor_shape) {
439 if (!video_capture_task_runner_->BelongsToCurrentThread()) { 441 if (!video_capture_task_runner_->BelongsToCurrentThread()) {
440 video_capture_task_runner_->PostTask( 442 video_capture_task_runner_->PostTask(
441 FROM_HERE, base::Bind(&DesktopSessionProxy::PostCursorShape, 443 FROM_HERE, base::Bind(&DesktopSessionProxy::PostCursorShape,
442 this, base::Passed(&cursor_shape))); 444 this, base::Passed(&cursor_shape)));
443 return; 445 return;
444 } 446 }
445 447
446 if (video_capturer_) 448 if (video_capturer_)
447 video_capturer_->OnCursorShapeChanged(cursor_shape.Pass()); 449 video_capturer_->OnCursorShapeChanged(cursor_shape.Pass());
448 } 450 }
449 451
450 void DesktopSessionProxy::SendToDesktop(IPC::Message* message) { 452 void DesktopSessionProxy::SendToDesktop(IPC::Message* message) {
451 DCHECK(caller_task_runner_->BelongsToCurrentThread()); 453 DCHECK(caller_task_runner_->BelongsToCurrentThread());
452 454
453 if (desktop_channel_) { 455 if (desktop_channel_) {
454 desktop_channel_->Send(message); 456 desktop_channel_->Send(message);
455 } else { 457 } else {
456 delete message; 458 delete message;
457 } 459 }
458 } 460 }
459 461
460 } // namespace remoting 462 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/desktop_session_proxy.h ('k') | remoting/host/event_executor_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698