 Chromium Code Reviews
 Chromium Code Reviews Issue 11413022:
  DesktopSessionAgent now hosts the video capturer and provides necessary plumbing to drive it via an…  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 11413022:
  DesktopSessionAgent now hosts the video capturer and provides necessary plumbing to drive it via an…  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 "remoting/base/auto_thread_task_runner.h" | 11 #include "remoting/base/auto_thread_task_runner.h" | 
| 12 #include "remoting/base/capture_data.h" | |
| 12 #include "remoting/host/chromoting_messages.h" | 13 #include "remoting/host/chromoting_messages.h" | 
| 14 #include "remoting/proto/control.pb.h" | |
| 13 | 15 | 
| 14 namespace remoting { | 16 namespace remoting { | 
| 15 | 17 | 
| 16 DesktopSessionAgent::~DesktopSessionAgent() { | 18 DesktopSessionAgent::~DesktopSessionAgent() { | 
| 17 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 19 DCHECK(!video_capturer_); | 
| 18 } | 20 } | 
| 19 | 21 | 
| 20 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { | 22 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { | 
| 21 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 23 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 
| 22 | 24 | 
| 23 NOTIMPLEMENTED(); | 25 bool handled = true; | 
| 24 return false; | 26 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) | 
| 27 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, | |
| 28 OnCaptureFrame) | |
| 29 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InvalidateRegion, | |
| 30 OnInvalidateRegion) | |
| 31 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SharedBufferRegistered, | |
| 32 OnSharedBufferRegistered) | |
| 33 IPC_END_MESSAGE_MAP() | |
| 34 return handled; | |
| 25 } | 35 } | 
| 26 | 36 | 
| 27 void DesktopSessionAgent::OnChannelConnected(int32 peer_pid) { | 37 void DesktopSessionAgent::OnChannelConnected(int32 peer_pid) { | 
| 28 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 38 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 
| 29 | 39 | 
| 30 VLOG(1) << "IPC: desktop <- network (" << peer_pid << ")"; | 40 VLOG(1) << "IPC: desktop <- network (" << peer_pid << ")"; | 
| 31 | |
| 32 NOTIMPLEMENTED(); | |
| 33 } | 41 } | 
| 34 | 42 | 
| 35 void DesktopSessionAgent::OnChannelError() { | 43 void DesktopSessionAgent::OnChannelError() { | 
| 36 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 44 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 
| 37 | 45 | 
| 38 // Make sure the channel is closed. | 46 // Make sure the channel is closed. | 
| 39 network_channel_.reset(); | 47 network_channel_.reset(); | 
| 40 | 48 | 
| 41 // Notify the caller that |this| can be destroyed now. | 49 // Notify the caller that |this| can be destroyed now. | 
| 42 done_task_.Run(); | 50 done_task_.Run(); | 
| 43 } | 51 } | 
| 44 | 52 | 
| 53 void DesktopSessionAgent::RegisterSharedBuffer( | |
| 54 scoped_refptr<SharedBuffer> buffer) { | |
| 55 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | |
| 56 DCHECK(buffer->id() == 0); | |
| 57 | |
| 58 // Use buffer's address as its ID. | |
| 
Wez
2012/11/16 23:37:31
Do we care that that discloses information about t
 
alexeypa (please no reviews)
2012/11/19 21:46:25
I don't see how it can be exploited.
 | |
| 59 buffer->set_id(reinterpret_cast<intptr_t>(buffer.get())); | |
| 60 shared_buffers_.push_back(buffer); | |
| 61 | |
| 62 SendToNetwork(new ChromotingDesktopNetworkMsg_RegisterSharedBuffer( | |
| 63 buffer->id(), buffer->handle(), buffer->size())); | |
| 64 } | |
| 65 | |
| 66 void DesktopSessionAgent::DropSharedBuffer(intptr_t id) { | |
| 67 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | |
| 68 DCHECK(id != 0); | |
| 69 | |
| 70 SendToNetwork(new ChromotingDesktopNetworkMsg_DropSharedBuffer(id)); | |
| 71 } | |
| 72 | |
| 73 void DesktopSessionAgent::OnCaptureCompleted( | |
| 74 scoped_refptr<CaptureData> capture_data) { | |
| 75 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | |
| 76 | |
| 77 // Serialize CaptureData | |
| 78 SerializedCapturedData serialized_data; | |
| 79 serialized_data.shared_buffer_id = capture_data->shared_buffer()->id(); | |
| 80 serialized_data.dimensions = capture_data->size(); | |
| 81 serialized_data.pixel_format = capture_data->pixel_format(); | |
| 82 serialized_data.capture_time_ms = capture_data->capture_time_ms(); | |
| 83 serialized_data.client_sequence_number = | |
| 84 capture_data->client_sequence_number(); | |
| 85 serialized_data.dpi = capture_data->dpi(); | |
| 86 for (SkRegion::Iterator i(capture_data->dirty_region()); !i.done(); i.next()) | |
| 87 serialized_data.dirty_region.push_back(i.rect()); | |
| 88 | |
| 89 SendToNetwork( | |
| 90 new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_data)); | |
| 91 } | |
| 92 | |
| 93 void DesktopSessionAgent::OnCursorShapeChanged( | |
| 94 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) { | |
| 95 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | |
| 96 | |
| 97 NOTIMPLEMENTED(); | |
| 98 } | |
| 99 | |
| 45 bool DesktopSessionAgent::Start(const base::Closure& done_task, | 100 bool DesktopSessionAgent::Start(const base::Closure& done_task, | 
| 46 IPC::PlatformFileForTransit* desktop_pipe_out) { | 101 IPC::PlatformFileForTransit* desktop_pipe_out) { | 
| 47 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 102 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 
| 48 | 103 | 
| 49 done_task_ = done_task; | 104 done_task_ = done_task; | 
| 50 return DoCreateNetworkChannel(desktop_pipe_out, &network_channel_); | 105 if (!DoCreateNetworkChannel(desktop_pipe_out, &network_channel_)) | 
| 106 return false; | |
| 107 | |
| 108 // Start the video capturer. | |
| 109 video_capture_task_runner()->PostTask( | |
| 110 FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this)); | |
| 111 return true; | |
| 112 } | |
| 113 | |
| 114 void DesktopSessionAgent::Stop() { | |
| 
Wez
2012/11/16 23:37:31
Thread check?
 
alexeypa (please no reviews)
2012/11/19 21:46:25
Done.
 | |
| 115 // Stop the video capturer. | |
| 116 video_capture_task_runner()->PostTask( | |
| 117 FROM_HERE, base::Bind(&DesktopSessionAgent::StopVideoCapturer, this)); | |
| 118 } | |
| 119 | |
| 120 void DesktopSessionAgent::InvalidateRegion( | |
| 121 scoped_ptr<SkRegion> invalid_region) { | |
| 122 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | |
| 123 | |
| 124 video_capturer_->InvalidateRegion(*invalid_region); | |
| 125 } | |
| 126 | |
| 127 void DesktopSessionAgent::OnCaptureFrame() { | |
| 128 if (!video_capture_task_runner()->BelongsToCurrentThread()) { | |
| 129 video_capture_task_runner()->PostTask( | |
| 130 FROM_HERE, | |
| 131 base::Bind(&DesktopSessionAgent::OnCaptureFrame, this)); | |
| 132 return; | |
| 133 } | |
| 134 | |
| 135 video_capturer_->CaptureInvalidRegion(); | |
| 136 } | |
| 137 | |
| 138 void DesktopSessionAgent::OnInvalidateRegion( | |
| 139 const std::vector<SkIRect>& invalid_region) { | |
| 
Wez
2012/11/16 23:37:31
nit: invalid_rects or region_rects
 
alexeypa (please no reviews)
2012/11/19 21:46:25
Done.
 | |
| 140 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | |
| 141 | |
| 142 scoped_ptr<SkRegion> region(new SkRegion()); | |
| 143 region->setRects(&invalid_region[0], invalid_region.size()); | |
| 144 | |
| 145 video_capture_task_runner()->PostTask( | |
| 146 FROM_HERE, base::Bind(&DesktopSessionAgent::InvalidateRegion, this, | |
| 147 base::Passed(®ion))); | |
| 
Wez
2012/11/16 23:37:31
Hmmmm; this is the sort of glue I'd hoped to avoid
 
alexeypa (please no reviews)
2012/11/19 21:46:25
VideoFrameCapturer is designed to run on a single
 | |
| 148 } | |
| 149 | |
| 150 void DesktopSessionAgent::OnSharedBufferRegistered(intptr_t id) { | |
| 151 if (!video_capture_task_runner()->BelongsToCurrentThread()) { | |
| 152 video_capture_task_runner()->PostTask( | |
| 153 FROM_HERE, | |
| 154 base::Bind(&DesktopSessionAgent::OnSharedBufferRegistered, this, id)); | |
| 155 return; | |
| 156 } | |
| 157 | |
| 158 // Drop the cached reference to the buffer. | |
| 159 SharedBuffers::iterator i = shared_buffers_.begin(); | |
| 160 for (; i != shared_buffers_.end(); ++i) { | |
| 161 if ((*i)->id() == id) { | |
| 162 shared_buffers_.erase(i); | |
| 163 break; | |
| 164 } | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 void DesktopSessionAgent::SendToNetwork(IPC::Message* message) { | |
| 
Wez
2012/11/16 23:37:31
nit: SendIpcToNetwork?
 
alexeypa (please no reviews)
2012/11/19 21:46:25
I don't think so:
1. There are other SendToXxx wr
 | |
| 169 if (!caller_task_runner()->BelongsToCurrentThread()) { | |
| 170 caller_task_runner()->PostTask( | |
| 171 FROM_HERE, | |
| 172 base::Bind(&DesktopSessionAgent::SendToNetwork, this, message)); | |
| 173 return; | |
| 174 } | |
| 175 | |
| 176 if (network_channel_) { | |
| 177 network_channel_->Send(message); | |
| 178 } else { | |
| 179 delete message; | |
| 180 } | |
| 181 } | |
| 182 | |
| 183 void DesktopSessionAgent::StartVideoCapturer() { | |
| 184 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | |
| 185 | |
| 186 video_capturer_.reset(VideoFrameCapturer::Create()); | |
| 187 video_capturer_->UseSharedBuffers(this); | |
| 188 video_capturer_->Start(this); | |
| 189 } | |
| 190 | |
| 191 void DesktopSessionAgent::StopVideoCapturer() { | |
| 192 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | |
| 193 | |
| 194 video_capturer_->Stop(); | |
| 195 video_capturer_->UseSharedBuffers(NULL); | |
| 
Wez
2012/11/16 23:37:31
Why do you need to NULL the buffer allocator / sen
 
alexeypa (please no reviews)
2012/11/19 21:46:25
Done.
 | |
| 196 video_capturer_.reset(); | |
| 197 | |
| 198 // Free any shared buffers left. | |
| 199 shared_buffers_.clear(); | |
| 51 } | 200 } | 
| 52 | 201 | 
| 53 DesktopSessionAgent::DesktopSessionAgent( | 202 DesktopSessionAgent::DesktopSessionAgent( | 
| 54 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 203 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 
| 55 scoped_refptr<AutoThreadTaskRunner> io_task_runner) | 204 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 
| 205 scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner) | |
| 56 : caller_task_runner_(caller_task_runner), | 206 : caller_task_runner_(caller_task_runner), | 
| 57 io_task_runner_(io_task_runner) { | 207 io_task_runner_(io_task_runner), | 
| 208 video_capture_task_runner_(video_capture_task_runner) { | |
| 58 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 209 DCHECK(caller_task_runner_->BelongsToCurrentThread()); | 
| 59 } | 210 } | 
| 60 | 211 | 
| 61 } // namespace remoting | 212 } // namespace remoting | 
| OLD | NEW |