diff options
author | garykac@google.com <garykac@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-07 19:58:23 +0000 |
---|---|---|
committer | garykac@google.com <garykac@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-07 19:58:23 +0000 |
commit | cb3b1f93130040a150e7fcc57cd4d5a75569685a (patch) | |
tree | ff93665e3c1478c61663d1107cd42dc25b31448d /remoting/host/encoder_verbatim.cc | |
parent | b0110e822ac2b2db56d1b1542aad06da573cd544 (diff) | |
download | chromium_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/host/encoder_verbatim.cc')
-rw-r--r-- | remoting/host/encoder_verbatim.cc | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/remoting/host/encoder_verbatim.cc b/remoting/host/encoder_verbatim.cc new file mode 100644 index 0000000..0ef7677 --- /dev/null +++ b/remoting/host/encoder_verbatim.cc @@ -0,0 +1,97 @@ +// 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/host/encoder_verbatim.h" + +#include "gfx/rect.h" +#include "media/base/data_buffer.h" +#include "remoting/base/protocol/chromotocol.pb.h" + +namespace remoting { + +using chromotocol_pb::UpdateStreamPacketHeader; +using media::DataBuffer; + +void EncoderVerbatim::Encode(const DirtyRects& dirty_rects, + const uint8** input_data, + const int* strides, + bool key_frame, + UpdateStreamPacketHeader* header, + scoped_refptr<DataBuffer>* output_data, + bool* encode_done, + Task* data_available_task) { + int num_rects = dirty_rects.size(); + for (int i = 0; i < num_rects; i++) { + if (EncodeRect(dirty_rects[i], input_data, strides, header, output_data)) { + *encode_done = (i == num_rects - 1); // Set for last rect. + data_available_task->Run(); + } + } + + delete data_available_task; +} + +void EncoderVerbatim::SetSize(int width, int height) { + width_ = width; + height_ = height; +} + +void EncoderVerbatim::SetPixelFormat(chromotocol_pb::PixelFormat pixel_format) { + // These are sorted so that the most common formats are checked first. + 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"; + } +} + +bool EncoderVerbatim::EncodeRect(const gfx::Rect& dirty, + const uint8** input_data, + const int* strides, + UpdateStreamPacketHeader* header, + scoped_refptr<DataBuffer>* output_data) { + const int kPlanes = 3; + + // Calculate the size of output. + int output_size = 0; + for (int i = 0; i < kPlanes; ++i) { + // TODO(hclam): Handle YUV since the height would be different. + output_size += strides[i] * height_; + } + + header->set_x(dirty.x()); + header->set_y(dirty.y()); + header->set_width(dirty.width()); + header->set_height(dirty.height()); + header->set_encoding(chromotocol_pb::EncodingNone); + + *output_data = new DataBuffer(output_size); + (*output_data)->SetDataSize(output_size); + + uint8* out = (*output_data)->GetWritableData(); + for (int i = 0; i < kPlanes; ++i) { + const uint8* in = input_data[i]; + // Skip over planes that don't have data. + if (!in) + continue; + + // TODO(hclam): Handle YUV since the height would be different. + for (int j = 0; j < height_; ++j) { + int row_size = width_ * bytes_per_pixel_; + DCHECK_LE(row_size, strides[i]); + memcpy(out, in, row_size); + in += strides[i]; + out += row_size; + } + } + return true; +} + +} // namespace remoting |