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

Unified Diff: remoting/host/desktop_session_agent.cc

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
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/desktop_session_agent.cc
diff --git a/remoting/host/desktop_session_agent.cc b/remoting/host/desktop_session_agent.cc
index 36643695a99f0b5360ffd63b0154fa1b3549cc31..1927c4f9a060a3300c14cc4b5ac65e7fe590b392 100644
--- a/remoting/host/desktop_session_agent.cc
+++ b/remoting/host/desktop_session_agent.cc
@@ -9,27 +9,35 @@
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_macros.h"
#include "remoting/base/auto_thread_task_runner.h"
+#include "remoting/base/capture_data.h"
#include "remoting/host/chromoting_messages.h"
+#include "remoting/proto/control.pb.h"
namespace remoting {
DesktopSessionAgent::~DesktopSessionAgent() {
- DCHECK(caller_task_runner()->BelongsToCurrentThread());
+ DCHECK(!video_capturer_);
}
bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) {
DCHECK(caller_task_runner()->BelongsToCurrentThread());
- NOTIMPLEMENTED();
- return false;
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message)
+ IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame,
+ OnCaptureFrame)
+ IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InvalidateRegion,
+ OnInvalidateRegion)
+ IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SharedBufferRegistered,
+ OnSharedBufferRegistered)
+ IPC_END_MESSAGE_MAP()
+ return handled;
}
void DesktopSessionAgent::OnChannelConnected(int32 peer_pid) {
DCHECK(caller_task_runner()->BelongsToCurrentThread());
VLOG(1) << "IPC: desktop <- network (" << peer_pid << ")";
-
- NOTIMPLEMENTED();
}
void DesktopSessionAgent::OnChannelError() {
@@ -42,19 +50,162 @@ void DesktopSessionAgent::OnChannelError() {
done_task_.Run();
}
+void DesktopSessionAgent::RegisterSharedBuffer(
+ scoped_refptr<SharedBuffer> buffer) {
+ DCHECK(video_capture_task_runner()->BelongsToCurrentThread());
+ DCHECK(buffer->id() == 0);
+
+ // 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.
+ buffer->set_id(reinterpret_cast<intptr_t>(buffer.get()));
+ shared_buffers_.push_back(buffer);
+
+ SendToNetwork(new ChromotingDesktopNetworkMsg_RegisterSharedBuffer(
+ buffer->id(), buffer->handle(), buffer->size()));
+}
+
+void DesktopSessionAgent::DropSharedBuffer(intptr_t id) {
+ DCHECK(video_capture_task_runner()->BelongsToCurrentThread());
+ DCHECK(id != 0);
+
+ SendToNetwork(new ChromotingDesktopNetworkMsg_DropSharedBuffer(id));
+}
+
+void DesktopSessionAgent::OnCaptureCompleted(
+ scoped_refptr<CaptureData> capture_data) {
+ DCHECK(video_capture_task_runner()->BelongsToCurrentThread());
+
+ // Serialize CaptureData
+ SerializedCapturedData serialized_data;
+ serialized_data.shared_buffer_id = capture_data->shared_buffer()->id();
+ serialized_data.dimensions = capture_data->size();
+ serialized_data.pixel_format = capture_data->pixel_format();
+ serialized_data.capture_time_ms = capture_data->capture_time_ms();
+ serialized_data.client_sequence_number =
+ capture_data->client_sequence_number();
+ serialized_data.dpi = capture_data->dpi();
+ for (SkRegion::Iterator i(capture_data->dirty_region()); !i.done(); i.next())
+ serialized_data.dirty_region.push_back(i.rect());
+
+ SendToNetwork(
+ new ChromotingDesktopNetworkMsg_CaptureCompleted(serialized_data));
+}
+
+void DesktopSessionAgent::OnCursorShapeChanged(
+ scoped_ptr<protocol::CursorShapeInfo> cursor_shape) {
+ DCHECK(video_capture_task_runner()->BelongsToCurrentThread());
+
+ NOTIMPLEMENTED();
+}
+
bool DesktopSessionAgent::Start(const base::Closure& done_task,
IPC::PlatformFileForTransit* desktop_pipe_out) {
DCHECK(caller_task_runner()->BelongsToCurrentThread());
done_task_ = done_task;
- return DoCreateNetworkChannel(desktop_pipe_out, &network_channel_);
+ if (!DoCreateNetworkChannel(desktop_pipe_out, &network_channel_))
+ return false;
+
+ // Start the video capturer.
+ video_capture_task_runner()->PostTask(
+ FROM_HERE, base::Bind(&DesktopSessionAgent::StartVideoCapturer, this));
+ return true;
+}
+
+void DesktopSessionAgent::Stop() {
Wez 2012/11/16 23:37:31 Thread check?
alexeypa (please no reviews) 2012/11/19 21:46:25 Done.
+ // Stop the video capturer.
+ video_capture_task_runner()->PostTask(
+ FROM_HERE, base::Bind(&DesktopSessionAgent::StopVideoCapturer, this));
+}
+
+void DesktopSessionAgent::InvalidateRegion(
+ scoped_ptr<SkRegion> invalid_region) {
+ DCHECK(video_capture_task_runner()->BelongsToCurrentThread());
+
+ video_capturer_->InvalidateRegion(*invalid_region);
+}
+
+void DesktopSessionAgent::OnCaptureFrame() {
+ if (!video_capture_task_runner()->BelongsToCurrentThread()) {
+ video_capture_task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&DesktopSessionAgent::OnCaptureFrame, this));
+ return;
+ }
+
+ video_capturer_->CaptureInvalidRegion();
+}
+
+void DesktopSessionAgent::OnInvalidateRegion(
+ 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.
+ DCHECK(caller_task_runner()->BelongsToCurrentThread());
+
+ scoped_ptr<SkRegion> region(new SkRegion());
+ region->setRects(&invalid_region[0], invalid_region.size());
+
+ video_capture_task_runner()->PostTask(
+ FROM_HERE, base::Bind(&DesktopSessionAgent::InvalidateRegion, this,
+ base::Passed(&region)));
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
+}
+
+void DesktopSessionAgent::OnSharedBufferRegistered(intptr_t id) {
+ if (!video_capture_task_runner()->BelongsToCurrentThread()) {
+ video_capture_task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&DesktopSessionAgent::OnSharedBufferRegistered, this, id));
+ return;
+ }
+
+ // Drop the cached reference to the buffer.
+ SharedBuffers::iterator i = shared_buffers_.begin();
+ for (; i != shared_buffers_.end(); ++i) {
+ if ((*i)->id() == id) {
+ shared_buffers_.erase(i);
+ break;
+ }
+ }
+}
+
+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
+ if (!caller_task_runner()->BelongsToCurrentThread()) {
+ caller_task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&DesktopSessionAgent::SendToNetwork, this, message));
+ return;
+ }
+
+ if (network_channel_) {
+ network_channel_->Send(message);
+ } else {
+ delete message;
+ }
+}
+
+void DesktopSessionAgent::StartVideoCapturer() {
+ DCHECK(video_capture_task_runner()->BelongsToCurrentThread());
+
+ video_capturer_.reset(VideoFrameCapturer::Create());
+ video_capturer_->UseSharedBuffers(this);
+ video_capturer_->Start(this);
+}
+
+void DesktopSessionAgent::StopVideoCapturer() {
+ DCHECK(video_capture_task_runner()->BelongsToCurrentThread());
+
+ video_capturer_->Stop();
+ 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.
+ video_capturer_.reset();
+
+ // Free any shared buffers left.
+ shared_buffers_.clear();
}
DesktopSessionAgent::DesktopSessionAgent(
scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
- scoped_refptr<AutoThreadTaskRunner> io_task_runner)
+ scoped_refptr<AutoThreadTaskRunner> io_task_runner,
+ scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner)
: caller_task_runner_(caller_task_runner),
- io_task_runner_(io_task_runner) {
+ io_task_runner_(io_task_runner),
+ video_capture_task_runner_(video_capture_task_runner) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());
}

Powered by Google App Engine
This is Rietveld 408576698