| 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/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 "ipc/ipc_channel_proxy.h" | 10 #include "ipc/ipc_channel_proxy.h" |
| 10 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 11 #include "ipc/ipc_message_macros.h" | 12 #include "ipc/ipc_message_macros.h" |
| 12 #include "media/video/capture/screen/screen_capture_data.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/remote_input_filter.h" | 19 #include "remoting/host/remote_input_filter.h" |
| 20 #include "remoting/host/screen_controls.h" | 20 #include "remoting/host/screen_controls.h" |
| 21 #include "remoting/host/screen_resolution.h" | 21 #include "remoting/host/screen_resolution.h" |
| 22 #include "remoting/proto/audio.pb.h" | 22 #include "remoting/proto/audio.pb.h" |
| 23 #include "remoting/proto/control.pb.h" | 23 #include "remoting/proto/control.pb.h" |
| 24 #include "remoting/proto/event.pb.h" | 24 #include "remoting/proto/event.pb.h" |
| 25 #include "remoting/protocol/clipboard_stub.h" | 25 #include "remoting/protocol/clipboard_stub.h" |
| 26 #include "remoting/protocol/input_event_tracker.h" | 26 #include "remoting/protocol/input_event_tracker.h" |
| 27 #include "third_party/skia/include/core/SkRegion.h" | 27 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 28 #include "third_party/webrtc/modules/desktop_capture/shared_memory.h" |
| 28 | 29 |
| 29 namespace remoting { | 30 namespace remoting { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 // Routes local clipboard events though the IPC channel to the network process. | 34 // Routes local clipboard events though the IPC channel to the network process. |
| 34 class DesktopSesssionClipboardStub : public protocol::ClipboardStub { | 35 class DesktopSesssionClipboardStub : public protocol::ClipboardStub { |
| 35 public: | 36 public: |
| 36 explicit DesktopSesssionClipboardStub( | 37 explicit DesktopSesssionClipboardStub( |
| 37 scoped_refptr<DesktopSessionAgent> desktop_session_agent); | 38 scoped_refptr<DesktopSessionAgent> desktop_session_agent); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 55 DesktopSesssionClipboardStub::~DesktopSesssionClipboardStub() { | 56 DesktopSesssionClipboardStub::~DesktopSesssionClipboardStub() { |
| 56 } | 57 } |
| 57 | 58 |
| 58 void DesktopSesssionClipboardStub::InjectClipboardEvent( | 59 void DesktopSesssionClipboardStub::InjectClipboardEvent( |
| 59 const protocol::ClipboardEvent& event) { | 60 const protocol::ClipboardEvent& event) { |
| 60 desktop_session_agent_->InjectClipboardEvent(event); | 61 desktop_session_agent_->InjectClipboardEvent(event); |
| 61 } | 62 } |
| 62 | 63 |
| 63 } // namespace | 64 } // namespace |
| 64 | 65 |
| 66 // webrtc::SharedMemory implementation that notifies creating |
| 67 // DesktopSessionAgent when it's deleted. |
| 68 class DesktopSessionAgent::SharedBuffer : public webrtc::SharedMemory { |
| 69 public: |
| 70 static scoped_ptr<SharedBuffer> Create(DesktopSessionAgent* agent, |
| 71 size_t size, |
| 72 int id) { |
| 73 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory()); |
| 74 if (!memory->CreateAndMapAnonymous(size)) |
| 75 return scoped_ptr<SharedBuffer>(); |
| 76 return scoped_ptr<SharedBuffer>( |
| 77 new SharedBuffer(agent, memory.Pass(), size, id)); |
| 78 } |
| 79 |
| 80 virtual ~SharedBuffer() { |
| 81 agent_->OnSharedBufferDeleted(id()); |
| 82 } |
| 83 |
| 84 private: |
| 85 SharedBuffer(DesktopSessionAgent* agent, |
| 86 scoped_ptr<base::SharedMemory> memory, |
| 87 size_t size, |
| 88 int id) |
| 89 : SharedMemory(memory->memory(), size, |
| 90 #if defined(OS_WIN) |
| 91 memory->handle(), |
| 92 #else |
| 93 memory->handle().fd, |
| 94 #endif |
| 95 id), |
| 96 agent_(agent), |
| 97 shared_memory_(memory.Pass()) { |
| 98 } |
| 99 |
| 100 DesktopSessionAgent* agent_; |
| 101 scoped_ptr<base::SharedMemory> shared_memory_; |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(SharedBuffer); |
| 104 }; |
| 105 |
| 65 DesktopSessionAgent::Delegate::~Delegate() { | 106 DesktopSessionAgent::Delegate::~Delegate() { |
| 66 } | 107 } |
| 67 | 108 |
| 68 DesktopSessionAgent::~DesktopSessionAgent() { | 109 DesktopSessionAgent::~DesktopSessionAgent() { |
| 69 DCHECK(!audio_capturer_); | 110 DCHECK(!audio_capturer_); |
| 70 DCHECK(!desktop_environment_); | 111 DCHECK(!desktop_environment_); |
| 71 DCHECK(!network_channel_); | 112 DCHECK(!network_channel_); |
| 72 DCHECK(!screen_controls_); | 113 DCHECK(!screen_controls_); |
| 73 DCHECK(!video_capturer_); | 114 DCHECK(!video_capturer_); |
| 74 | 115 |
| 75 CloseDesktopPipeHandle(); | 116 CloseDesktopPipeHandle(); |
| 76 } | 117 } |
| 77 | 118 |
| 78 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { | 119 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { |
| 79 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 120 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 80 | 121 |
| 81 bool handled = true; | 122 bool handled = true; |
| 82 if (started_) { | 123 if (started_) { |
| 83 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) | 124 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) |
| 84 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, | 125 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, |
| 85 OnCaptureFrame) | 126 OnCaptureFrame) |
| 86 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SharedBufferCreated, | |
| 87 OnSharedBufferCreated) | |
| 88 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectClipboardEvent, | 127 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectClipboardEvent, |
| 89 OnInjectClipboardEvent) | 128 OnInjectClipboardEvent) |
| 90 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectKeyEvent, | 129 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectKeyEvent, |
| 91 OnInjectKeyEvent) | 130 OnInjectKeyEvent) |
| 92 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectMouseEvent, | 131 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectMouseEvent, |
| 93 OnInjectMouseEvent) | 132 OnInjectMouseEvent) |
| 94 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SetScreenResolution, | 133 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SetScreenResolution, |
| 95 SetScreenResolution) | 134 SetScreenResolution) |
| 96 IPC_MESSAGE_UNHANDLED(handled = false) | 135 IPC_MESSAGE_UNHANDLED(handled = false) |
| 97 IPC_END_MESSAGE_MAP() | 136 IPC_END_MESSAGE_MAP() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 120 | 159 |
| 121 // Make sure the channel is closed. | 160 // Make sure the channel is closed. |
| 122 network_channel_.reset(); | 161 network_channel_.reset(); |
| 123 CloseDesktopPipeHandle(); | 162 CloseDesktopPipeHandle(); |
| 124 | 163 |
| 125 // Notify the caller that the channel has been disconnected. | 164 // Notify the caller that the channel has been disconnected. |
| 126 if (delegate_.get()) | 165 if (delegate_.get()) |
| 127 delegate_->OnNetworkProcessDisconnected(); | 166 delegate_->OnNetworkProcessDisconnected(); |
| 128 } | 167 } |
| 129 | 168 |
| 130 scoped_refptr<media::SharedBuffer> DesktopSessionAgent::CreateSharedBuffer( | 169 webrtc::SharedMemory* DesktopSessionAgent::CreateSharedMemory(size_t size) { |
| 131 uint32 size) { | |
| 132 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 170 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
| 133 | 171 |
| 134 scoped_refptr<media::SharedBuffer> buffer = new media::SharedBuffer(size); | 172 scoped_ptr<SharedBuffer> buffer = |
| 135 if (buffer->ptr() != NULL) { | 173 SharedBuffer::Create(this, size, next_shared_buffer_id_); |
| 136 buffer->set_id(next_shared_buffer_id_); | 174 if (buffer) { |
| 137 shared_buffers_.push_back(buffer); | 175 shared_buffers_++; |
| 138 | 176 |
| 139 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes | 177 // |next_shared_buffer_id_| starts from 1 and incrementing it by 2 makes |
| 140 // sure it is always odd and therefore zero is never used as a valid buffer | 178 // sure it is always odd and therefore zero is never used as a valid buffer |
| 141 // ID. | 179 // ID. |
| 142 // | 180 // |
| 143 // It is very unlikely (though theoretically possible) to allocate the same | 181 // It is very unlikely (though theoretically possible) to allocate the same |
| 144 // ID for two different buffers due to integer overflow. It should take | 182 // ID for two different buffers due to integer overflow. It should take |
| 145 // about a year of allocating 100 new buffers every second. Practically | 183 // about a year of allocating 100 new buffers every second. Practically |
| 146 // speaking it never happens. | 184 // speaking it never happens. |
| 147 next_shared_buffer_id_ += 2; | 185 next_shared_buffer_id_ += 2; |
| 148 | 186 |
| 187 IPC::PlatformFileForTransit handle; |
| 188 #if defined(OS_WIN) |
| 189 handle = buffer->handle(); |
| 190 #else |
| 191 handle = base::FileDescriptor(buffer->handle(), false); |
| 192 #endif |
| 149 SendToNetwork(new ChromotingDesktopNetworkMsg_CreateSharedBuffer( | 193 SendToNetwork(new ChromotingDesktopNetworkMsg_CreateSharedBuffer( |
| 150 buffer->id(), buffer->handle(), buffer->size())); | 194 buffer->id(), handle, buffer->size())); |
| 151 } | 195 } |
| 152 | 196 |
| 153 return buffer; | 197 return buffer.release(); |
| 154 } | |
| 155 | |
| 156 void DesktopSessionAgent::ReleaseSharedBuffer( | |
| 157 scoped_refptr<media::SharedBuffer> buffer) { | |
| 158 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | |
| 159 DCHECK(buffer->id() != 0); | |
| 160 | |
| 161 SendToNetwork( | |
| 162 new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(buffer->id())); | |
| 163 } | 198 } |
| 164 | 199 |
| 165 const std::string& DesktopSessionAgent::client_jid() const { | 200 const std::string& DesktopSessionAgent::client_jid() const { |
| 166 return client_jid_; | 201 return client_jid_; |
| 167 } | 202 } |
| 168 | 203 |
| 169 void DesktopSessionAgent::DisconnectSession() { | 204 void DesktopSessionAgent::DisconnectSession() { |
| 170 SendToNetwork(new ChromotingDesktopNetworkMsg_DisconnectSession()); | 205 SendToNetwork(new ChromotingDesktopNetworkMsg_DisconnectSession()); |
| 171 } | 206 } |
| 172 | 207 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 audio_capture_task_runner()->PostTask( | 269 audio_capture_task_runner()->PostTask( |
| 235 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this)); | 270 FROM_HERE, base::Bind(&DesktopSessionAgent::StartAudioCapturer, this)); |
| 236 } | 271 } |
| 237 | 272 |
| 238 // Start the video capturer. | 273 // Start the video capturer. |
| 239 video_capturer_ = desktop_environment_->CreateVideoCapturer(); | 274 video_capturer_ = desktop_environment_->CreateVideoCapturer(); |
| 240 video_capture_task_runner()->PostTask( | 275 video_capture_task_runner()->PostTask( |
| 241 FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this)); | 276 FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this)); |
| 242 } | 277 } |
| 243 | 278 |
| 244 void DesktopSessionAgent::OnCaptureCompleted( | 279 void DesktopSessionAgent::OnCaptureCompleted(webrtc::DesktopFrame* frame) { |
| 245 scoped_refptr<media::ScreenCaptureData> capture_data) { | |
| 246 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 280 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
| 247 | 281 |
| 248 current_size_ = capture_data->size(); | 282 last_frame_.reset(frame); |
| 249 | 283 |
| 250 // Serialize media::ScreenCaptureData | 284 current_size_ = frame->size(); |
| 251 SerializedCapturedData serialized_data; | 285 |
| 252 serialized_data.shared_buffer_id = capture_data->shared_buffer()->id(); | 286 // Serialize webrtc::DesktopFrame. |
| 253 serialized_data.bytes_per_row = capture_data->stride(); | 287 SerializedDesktopFrame serialized_frame; |
| 254 serialized_data.dimensions = capture_data->size(); | 288 serialized_frame.shared_buffer_id = frame->shared_memory()->id(); |
| 255 serialized_data.capture_time_ms = capture_data->capture_time_ms(); | 289 serialized_frame.bytes_per_row = frame->stride(); |
| 256 serialized_data.client_sequence_number = | 290 serialized_frame.dimensions = frame->size(); |
| 257 capture_data->client_sequence_number(); | 291 serialized_frame.capture_time_ms = frame->capture_time_ms(); |
| 258 serialized_data.dpi = capture_data->dpi(); | 292 serialized_frame.dpi = frame->dpi(); |
| 259 for (SkRegion::Iterator i(capture_data->dirty_region()); !i.done(); i.next()) | 293 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); |
| 260 serialized_data.dirty_region.push_back(i.rect()); | 294 !i.IsAtEnd(); i.Advance()) { |
| 295 serialized_frame.dirty_region.push_back(i.rect()); |
| 296 } |
| 261 | 297 |
| 262 SendToNetwork( | 298 SendToNetwork( |
| 263 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_data)); | 299 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_frame)); |
| 264 } | 300 } |
| 265 | 301 |
| 266 void DesktopSessionAgent::OnCursorShapeChanged( | 302 void DesktopSessionAgent::OnCursorShapeChanged( |
| 267 scoped_ptr<media::MouseCursorShape> cursor_shape) { | 303 scoped_ptr<media::MouseCursorShape> cursor_shape) { |
| 268 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 304 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
| 269 | 305 |
| 270 SendToNetwork(new ChromotingDesktopNetworkMsg_CursorShapeChanged( | 306 SendToNetwork(new ChromotingDesktopNetworkMsg_CursorShapeChanged( |
| 271 *cursor_shape)); | 307 *cursor_shape)); |
| 272 } | 308 } |
| 273 | 309 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 FROM_HERE, | 388 FROM_HERE, |
| 353 base::Bind(&DesktopSessionAgent::OnCaptureFrame, this)); | 389 base::Bind(&DesktopSessionAgent::OnCaptureFrame, this)); |
| 354 return; | 390 return; |
| 355 } | 391 } |
| 356 | 392 |
| 357 // media::ScreenCapturer supports a very few (currently 2) outstanding capture | 393 // media::ScreenCapturer supports a very few (currently 2) outstanding capture |
| 358 // requests. The requests are serialized on |video_capture_task_runner()| task | 394 // requests. The requests are serialized on |video_capture_task_runner()| task |
| 359 // runner. If the client issues more requests, pixel data in captured frames | 395 // runner. If the client issues more requests, pixel data in captured frames |
| 360 // will likely be corrupted but stability of media::ScreenCapturer will not be | 396 // will likely be corrupted but stability of media::ScreenCapturer will not be |
| 361 // affected. | 397 // affected. |
| 362 video_capturer_->CaptureFrame(); | 398 video_capturer_->Capture(webrtc::DesktopRegion()); |
| 363 } | |
| 364 | |
| 365 void DesktopSessionAgent::OnSharedBufferCreated(int id) { | |
| 366 if (!video_capture_task_runner()->BelongsToCurrentThread()) { | |
| 367 video_capture_task_runner()->PostTask( | |
| 368 FROM_HERE, | |
| 369 base::Bind(&DesktopSessionAgent::OnSharedBufferCreated, this, id)); | |
| 370 return; | |
| 371 } | |
| 372 | |
| 373 // Drop the cached reference to the buffer. | |
| 374 SharedBuffers::iterator i = shared_buffers_.begin(); | |
| 375 for (; i != shared_buffers_.end(); ++i) { | |
| 376 if ((*i)->id() == id) { | |
| 377 shared_buffers_.erase(i); | |
| 378 break; | |
| 379 } | |
| 380 } | |
| 381 } | 399 } |
| 382 | 400 |
| 383 void DesktopSessionAgent::OnInjectClipboardEvent( | 401 void DesktopSessionAgent::OnInjectClipboardEvent( |
| 384 const std::string& serialized_event) { | 402 const std::string& serialized_event) { |
| 385 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 403 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 386 | 404 |
| 387 protocol::ClipboardEvent event; | 405 protocol::ClipboardEvent event; |
| 388 if (!event.ParseFromString(serialized_event)) { | 406 if (!event.ParseFromString(serialized_event)) { |
| 389 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent."; | 407 LOG(ERROR) << "Failed to parse protocol::ClipboardEvent."; |
| 390 return; | 408 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 | 445 |
| 428 // InputStub implementations must verify events themselves, so we don't need | 446 // InputStub implementations must verify events themselves, so we don't need |
| 429 // verification here. This matches HostEventDispatcher. | 447 // verification here. This matches HostEventDispatcher. |
| 430 remote_input_filter_->InjectMouseEvent(event); | 448 remote_input_filter_->InjectMouseEvent(event); |
| 431 } | 449 } |
| 432 | 450 |
| 433 void DesktopSessionAgent::SetScreenResolution( | 451 void DesktopSessionAgent::SetScreenResolution( |
| 434 const ScreenResolution& resolution) { | 452 const ScreenResolution& resolution) { |
| 435 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 453 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 436 | 454 |
| 437 if (screen_controls_ && resolution.IsValid()) | 455 if (screen_controls_ && resolution.IsEmpty()) |
| 438 screen_controls_->SetScreenResolution(resolution); | 456 screen_controls_->SetScreenResolution(resolution); |
| 439 } | 457 } |
| 440 | 458 |
| 441 void DesktopSessionAgent::SendToNetwork(IPC::Message* message) { | 459 void DesktopSessionAgent::SendToNetwork(IPC::Message* message) { |
| 442 if (!caller_task_runner()->BelongsToCurrentThread()) { | 460 if (!caller_task_runner()->BelongsToCurrentThread()) { |
| 443 caller_task_runner()->PostTask( | 461 caller_task_runner()->PostTask( |
| 444 FROM_HERE, | 462 FROM_HERE, |
| 445 base::Bind(&DesktopSessionAgent::SendToNetwork, this, message)); | 463 base::Bind(&DesktopSessionAgent::SendToNetwork, this, message)); |
| 446 return; | 464 return; |
| 447 } | 465 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 464 | 482 |
| 465 void DesktopSessionAgent::StopAudioCapturer() { | 483 void DesktopSessionAgent::StopAudioCapturer() { |
| 466 DCHECK(audio_capture_task_runner()->BelongsToCurrentThread()); | 484 DCHECK(audio_capture_task_runner()->BelongsToCurrentThread()); |
| 467 | 485 |
| 468 audio_capturer_.reset(); | 486 audio_capturer_.reset(); |
| 469 } | 487 } |
| 470 | 488 |
| 471 void DesktopSessionAgent::StartVideoCapturer() { | 489 void DesktopSessionAgent::StartVideoCapturer() { |
| 472 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 490 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
| 473 | 491 |
| 474 if (video_capturer_) | 492 if (video_capturer_) { |
| 493 video_capturer_->SetMouseShapeObserver(this); |
| 475 video_capturer_->Start(this); | 494 video_capturer_->Start(this); |
| 495 } |
| 476 } | 496 } |
| 477 | 497 |
| 478 void DesktopSessionAgent::StopVideoCapturer() { | 498 void DesktopSessionAgent::StopVideoCapturer() { |
| 479 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 499 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
| 480 | 500 |
| 481 video_capturer_.reset(); | 501 video_capturer_.reset(); |
| 502 last_frame_.reset(); |
| 482 | 503 |
| 483 // Free any shared buffers left. | 504 // Video capturer must delete all buffers. |
| 484 shared_buffers_.clear(); | 505 DCHECK_EQ(shared_buffers_, 0); |
| 485 } | 506 } |
| 486 | 507 |
| 487 DesktopSessionAgent::DesktopSessionAgent( | 508 DesktopSessionAgent::DesktopSessionAgent( |
| 488 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, | 509 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, |
| 489 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 510 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 490 scoped_refptr<AutoThreadTaskRunner> input_task_runner, | 511 scoped_refptr<AutoThreadTaskRunner> input_task_runner, |
| 491 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 512 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| 492 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner) | 513 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner) |
| 493 : audio_capture_task_runner_(audio_capture_task_runner), | 514 : audio_capture_task_runner_(audio_capture_task_runner), |
| 494 caller_task_runner_(caller_task_runner), | 515 caller_task_runner_(caller_task_runner), |
| 495 input_task_runner_(input_task_runner), | 516 input_task_runner_(input_task_runner), |
| 496 io_task_runner_(io_task_runner), | 517 io_task_runner_(io_task_runner), |
| 497 video_capture_task_runner_(video_capture_task_runner), | 518 video_capture_task_runner_(video_capture_task_runner), |
| 498 control_factory_(this), | 519 control_factory_(this), |
| 499 desktop_pipe_(IPC::InvalidPlatformFileForTransit()), | 520 desktop_pipe_(IPC::InvalidPlatformFileForTransit()), |
| 500 current_size_(SkISize::Make(0, 0)), | |
| 501 next_shared_buffer_id_(1), | 521 next_shared_buffer_id_(1), |
| 522 shared_buffers_(0), |
| 502 started_(false) { | 523 started_(false) { |
| 503 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 524 DCHECK(caller_task_runner_->BelongsToCurrentThread()); |
| 504 } | 525 } |
| 505 | 526 |
| 527 void DesktopSessionAgent::OnSharedBufferDeleted(int id) { |
| 528 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
| 529 DCHECK(id != 0); |
| 530 |
| 531 shared_buffers_--; |
| 532 DCHECK_GE(shared_buffers_, 0); |
| 533 SendToNetwork(new ChromotingDesktopNetworkMsg_ReleaseSharedBuffer(id)); |
| 534 } |
| 535 |
| 506 void DesktopSessionAgent::CloseDesktopPipeHandle() { | 536 void DesktopSessionAgent::CloseDesktopPipeHandle() { |
| 507 if (!(desktop_pipe_ == IPC::InvalidPlatformFileForTransit())) { | 537 if (!(desktop_pipe_ == IPC::InvalidPlatformFileForTransit())) { |
| 508 #if defined(OS_WIN) | 538 #if defined(OS_WIN) |
| 509 base::ClosePlatformFile(desktop_pipe_); | 539 base::ClosePlatformFile(desktop_pipe_); |
| 510 #elif defined(OS_POSIX) | 540 #elif defined(OS_POSIX) |
| 511 base::ClosePlatformFile(desktop_pipe_.fd); | 541 base::ClosePlatformFile(desktop_pipe_.fd); |
| 512 #else // !defined(OS_POSIX) | 542 #else // !defined(OS_POSIX) |
| 513 #error Unsupported platform. | 543 #error Unsupported platform. |
| 514 #endif // !defined(OS_POSIX) | 544 #endif // !defined(OS_POSIX) |
| 515 | 545 |
| 516 desktop_pipe_ = IPC::InvalidPlatformFileForTransit(); | 546 desktop_pipe_ = IPC::InvalidPlatformFileForTransit(); |
| 517 } | 547 } |
| 518 } | 548 } |
| 519 | 549 |
| 520 } // namespace remoting | 550 } // namespace remoting |
| OLD | NEW |