summaryrefslogtreecommitdiffstats
path: root/remoting/client/decoder_verbatim.cc
diff options
context:
space:
mode:
authorgarykac@google.com <garykac@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-07 19:58:23 +0000
committergarykac@google.com <garykac@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-07 19:58:23 +0000
commitcb3b1f93130040a150e7fcc57cd4d5a75569685a (patch)
treeff93665e3c1478c61663d1107cd42dc25b31448d /remoting/client/decoder_verbatim.cc
parentb0110e822ac2b2db56d1b1542aad06da573cd544 (diff)
downloadchromium_src-cb3b1f93130040a150e7fcc57cd4d5a75569685a.zip
chromium_src-cb3b1f93130040a150e7fcc57cd4d5a75569685a.tar.gz
chromium_src-cb3b1f93130040a150e7fcc57cd4d5a75569685a.tar.bz2
Copy the (early prototype of) remoting in Chrome into the public tree.
At the moment, this is a semi-functional demo. BUG=none TEST=build/run all unittests on linux Review URL: http://codereview.chromium.org/2690003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49087 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client/decoder_verbatim.cc')
-rw-r--r--remoting/client/decoder_verbatim.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/remoting/client/decoder_verbatim.cc b/remoting/client/decoder_verbatim.cc
new file mode 100644
index 0000000..7cbf428
--- /dev/null
+++ b/remoting/client/decoder_verbatim.cc
@@ -0,0 +1,67 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/client/decoder_verbatim.h"
+
+namespace remoting {
+
+bool DecoderVerbatim::BeginDecode(scoped_refptr<media::VideoFrame> frame) {
+ // TODO(hclam): Check if we can accept the codec.
+ frame_ = frame;
+ return true;
+}
+
+bool DecoderVerbatim::PartialDecode(chromotocol_pb::HostMessage* message) {
+ scoped_ptr<chromotocol_pb::HostMessage> msg_deleter(message);
+
+ // TODO(hclam): Support YUV.
+ if (static_cast<int>(message->update_stream_packet().header().pixel_format())
+ != static_cast<int>(frame_->format())) {
+ return false;
+ }
+ int width = message->update_stream_packet().header().width();
+ int height = message->update_stream_packet().header().height();
+ int x = message->update_stream_packet().header().x();
+ int y = message->update_stream_packet().header().y();
+ chromotocol_pb::PixelFormat pixel_format =
+ message->update_stream_packet().header().pixel_format();
+ int bytes_per_pixel = 0;
+
+ // TODO(hclam): Extract the following to an util function.
+ if (pixel_format == chromotocol_pb::PixelFormatRgb24) {
+ bytes_per_pixel = 3;
+ } else if (pixel_format == chromotocol_pb::PixelFormatRgb565) {
+ bytes_per_pixel = 2;
+ } else if (pixel_format == chromotocol_pb::PixelFormatRgb32) {
+ bytes_per_pixel = 4;
+ } else if (pixel_format != chromotocol_pb::PixelFormatAscii) {
+ bytes_per_pixel = 1;
+ } else {
+ NOTREACHED() << "Pixel format not supported";
+ }
+
+ // Copy the data line by line.
+ const int src_stride = bytes_per_pixel * width;
+ const char* src = message->update_stream_packet().data().c_str();
+ const int dest_stride = frame_->stride(media::VideoFrame::kRGBPlane);
+ uint8* dest = frame_->data(media::VideoFrame::kRGBPlane) +
+ dest_stride * y + bytes_per_pixel * x;
+ for (int i = 0; i < height; ++i) {
+ memcpy(dest, src, src_stride);
+ dest += dest_stride;
+ src += src_stride;
+ }
+
+ UpdatedRects rects;
+ rects.push_back(gfx::Rect(x, y, width, height));
+ partial_decode_done()->Run(frame_, rects);
+ return true;
+}
+
+void DecoderVerbatim::EndDecode() {
+ decode_done()->Run(frame_);
+ frame_ = NULL;
+}
+
+} // namespace remoting