summaryrefslogtreecommitdiffstats
path: root/remoting/codec
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 03:26:53 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 03:26:53 +0000
commit2149befbff640e5a050bb50acdbbfd95501ab9b1 (patch)
tree6c60699960b23fdbf4d0f17fd3d83dc394156f44 /remoting/codec
parentfb03b64b14315feaf008e89bc3abeb0b0c2576c4 (diff)
downloadchromium_src-2149befbff640e5a050bb50acdbbfd95501ab9b1.zip
chromium_src-2149befbff640e5a050bb50acdbbfd95501ab9b1.tar.gz
chromium_src-2149befbff640e5a050bb50acdbbfd95501ab9b1.tar.bz2
Remove ZLib codec support from chromoting host and client.
We were not using ZLIB codec anyway, so there is no reason to keep it around. Review URL: https://chromiumcodereview.appspot.com/11195029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162635 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/codec')
-rw-r--r--remoting/codec/video_decoder_verbatim.cc (renamed from remoting/codec/video_decoder_row_based.cc)56
-rw-r--r--remoting/codec/video_decoder_verbatim.h (renamed from remoting/codec/video_decoder_row_based.h)29
-rw-r--r--remoting/codec/video_encode_decode_unittest.cc38
-rw-r--r--remoting/codec/video_encoder_row_based.h73
-rw-r--r--remoting/codec/video_encoder_row_based_unittest.cc24
-rw-r--r--remoting/codec/video_encoder_verbatim.cc (renamed from remoting/codec/video_encoder_row_based.cc)106
-rw-r--r--remoting/codec/video_encoder_verbatim.h56
-rw-r--r--remoting/codec/video_encoder_verbatim_unittest.cc37
8 files changed, 154 insertions, 265 deletions
diff --git a/remoting/codec/video_decoder_row_based.cc b/remoting/codec/video_decoder_verbatim.cc
index 35ed573..f9a5e11 100644
--- a/remoting/codec/video_decoder_row_based.cc
+++ b/remoting/codec/video_decoder_verbatim.cc
@@ -2,12 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "remoting/codec/video_decoder_row_based.h"
+#include "remoting/codec/video_decoder_verbatim.h"
#include "base/logging.h"
-#include "remoting/base/decompressor.h"
-#include "remoting/base/decompressor_zlib.h"
-#include "remoting/base/decompressor_verbatim.h"
#include "remoting/base/util.h"
namespace remoting {
@@ -15,33 +12,21 @@ namespace remoting {
namespace {
// Both input and output data are assumed to be RGBA32.
const int kBytesPerPixel = 4;
-}
+} // namespace
-VideoDecoderRowBased* VideoDecoderRowBased::CreateZlibDecoder() {
- return new VideoDecoderRowBased(new DecompressorZlib(),
- VideoPacketFormat::ENCODING_ZLIB);
-}
-VideoDecoderRowBased* VideoDecoderRowBased::CreateVerbatimDecoder() {
- return new VideoDecoderRowBased(new DecompressorVerbatim(),
- VideoPacketFormat::ENCODING_VERBATIM);
-}
-
-VideoDecoderRowBased::VideoDecoderRowBased(Decompressor* decompressor,
- VideoPacketFormat::Encoding encoding)
+VideoDecoderVerbatim::VideoDecoderVerbatim()
: state_(kUninitialized),
clip_(SkIRect::MakeEmpty()),
- decompressor_(decompressor),
- encoding_(encoding),
row_pos_(0),
row_y_(0),
screen_size_(SkISize::Make(0, 0)) {
}
-VideoDecoderRowBased::~VideoDecoderRowBased() {
+VideoDecoderVerbatim::~VideoDecoderVerbatim() {
}
-bool VideoDecoderRowBased::IsReadyForData() {
+bool VideoDecoderVerbatim::IsReadyForData() {
switch (state_) {
case kUninitialized:
case kError:
@@ -56,8 +41,7 @@ bool VideoDecoderRowBased::IsReadyForData() {
return false;
}
-void VideoDecoderRowBased::Initialize(const SkISize& screen_size) {
- decompressor_->Reset();
+void VideoDecoderVerbatim::Initialize(const SkISize& screen_size) {
updated_region_.setEmpty();
screen_buffer_.reset(NULL);
@@ -71,7 +55,7 @@ void VideoDecoderRowBased::Initialize(const SkISize& screen_size) {
state_ = kReady;
}
-VideoDecoder::DecodeResult VideoDecoderRowBased::DecodePacket(
+VideoDecoder::DecodeResult VideoDecoderVerbatim::DecodePacket(
const VideoPacket* packet) {
UpdateStateForPacket(packet);
@@ -88,22 +72,19 @@ VideoDecoder::DecodeResult VideoDecoderRowBased::DecodePacket(
kBytesPerPixel * clip_.left();
// Consume all the data in the message.
- bool decompress_again = true;
int used = 0;
- while (decompress_again && used < in_size) {
+ while (used < in_size) {
if (row_y_ >= clip_.height()) {
state_ = kError;
LOG(WARNING) << "Too much data is received for the given rectangle.";
return DECODE_ERROR;
}
- int written = 0;
- int consumed = 0;
- decompress_again = decompressor_->Process(
- in + used, in_size - used, out + row_pos_, row_size - row_pos_,
- &consumed, &written);
- used += consumed;
- row_pos_ += written;
+ int bytes_to_copy = std::min(in_size - used, row_size - row_pos_);
+ memcpy(out + row_pos_, in + used, bytes_to_copy);
+
+ used += bytes_to_copy;
+ row_pos_ += bytes_to_copy;
// If this row is completely filled then move onto the next row.
if (row_pos_ == row_size) {
@@ -121,7 +102,6 @@ VideoDecoder::DecodeResult VideoDecoderRowBased::DecodePacket(
}
updated_region_.op(clip_, SkRegion::kUnion_Op);
- decompressor_->Reset();
}
if (state_ == kDone) {
@@ -131,7 +111,7 @@ VideoDecoder::DecodeResult VideoDecoderRowBased::DecodePacket(
}
}
-void VideoDecoderRowBased::UpdateStateForPacket(const VideoPacket* packet) {
+void VideoDecoderVerbatim::UpdateStateForPacket(const VideoPacket* packet) {
if (state_ == kError) {
return;
}
@@ -184,16 +164,16 @@ void VideoDecoderRowBased::UpdateStateForPacket(const VideoPacket* packet) {
return;
}
-VideoPacketFormat::Encoding VideoDecoderRowBased::Encoding() {
- return encoding_;
+VideoPacketFormat::Encoding VideoDecoderVerbatim::Encoding() {
+ return VideoPacketFormat::ENCODING_VERBATIM;
}
-void VideoDecoderRowBased::Invalidate(const SkISize& view_size,
+void VideoDecoderVerbatim::Invalidate(const SkISize& view_size,
const SkRegion& region) {
updated_region_.op(region, SkRegion::kUnion_Op);
}
-void VideoDecoderRowBased::RenderFrame(const SkISize& view_size,
+void VideoDecoderVerbatim::RenderFrame(const SkISize& view_size,
const SkIRect& clip_area,
uint8* image_buffer,
int image_stride,
diff --git a/remoting/codec/video_decoder_row_based.h b/remoting/codec/video_decoder_verbatim.h
index 3e017e3..8c25013 100644
--- a/remoting/codec/video_decoder_row_based.h
+++ b/remoting/codec/video_decoder_verbatim.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef REMOTING_CODEC_VIDEO_DECODER_ROW_BASED_H_
-#define REMOTING_CODEC_VIDEO_DECODER_ROW_BASED_H_
+#ifndef REMOTING_CODEC_VIDEO_DECODER_VERBATIM_H_
+#define REMOTING_CODEC_VIDEO_DECODER_VERBATIM_H_
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
@@ -11,14 +11,14 @@
namespace remoting {
-class Decompressor;
-
-class VideoDecoderRowBased : public VideoDecoder {
+// Video decoder implementations that decodes video packet encoded by
+// VideoEncoderVerbatim. It just copies data from incoming packets to the
+// video frames.
+class VideoDecoderVerbatim : public VideoDecoder {
public:
- virtual ~VideoDecoderRowBased();
+ virtual ~VideoDecoderVerbatim();
- static VideoDecoderRowBased* CreateZlibDecoder();
- static VideoDecoderRowBased* CreateVerbatimDecoder();
+ VideoDecoderVerbatim();
// VideoDecoder implementation.
virtual bool IsReadyForData() OVERRIDE;
@@ -43,9 +43,6 @@ class VideoDecoderRowBased : public VideoDecoder {
kError,
};
- VideoDecoderRowBased(Decompressor* decompressor,
- VideoPacketFormat::Encoding encoding);
-
// Helper method. Called from DecodePacket to updated state of the decoder.
void UpdateStateForPacket(const VideoPacket* packet);
@@ -55,12 +52,6 @@ class VideoDecoderRowBased : public VideoDecoder {
// Keeps track of the updating rect.
SkIRect clip_;
- // The compression for the input byte stream.
- scoped_ptr<Decompressor> decompressor_;
-
- // The encoding of the incoming stream.
- VideoPacketFormat::Encoding encoding_;
-
// The position in the row that we are updating.
int row_pos_;
@@ -76,9 +67,9 @@ class VideoDecoderRowBased : public VideoDecoder {
// The bitmap holding the remote screen bits.
scoped_array<uint8> screen_buffer_;
- DISALLOW_COPY_AND_ASSIGN(VideoDecoderRowBased);
+ DISALLOW_COPY_AND_ASSIGN(VideoDecoderVerbatim);
};
} // namespace remoting
-#endif // REMOTING_CODEC_VIDEO_DECODER_ROW_BASED_H_
+#endif // REMOTING_CODEC_VIDEO_DECODER_VERBATIM_H_
diff --git a/remoting/codec/video_encode_decode_unittest.cc b/remoting/codec/video_encode_decode_unittest.cc
deleted file mode 100644
index 5b24293..0000000
--- a/remoting/codec/video_encode_decode_unittest.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-// 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/codec/video_encoder_row_based.h"
-
-#include "media/base/video_frame.h"
-#include "remoting/codec/codec_test.h"
-#include "remoting/codec/video_decoder_row_based.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace remoting {
-
-TEST(EncodeDecodeTest, EncodeAndDecodeZlib) {
- scoped_ptr<VideoEncoderRowBased> encoder(
- VideoEncoderRowBased::CreateZlibEncoder());
- scoped_ptr<VideoDecoderRowBased> decoder(
- VideoDecoderRowBased::CreateZlibDecoder());
- TestVideoEncoderDecoder(encoder.get(), decoder.get(), true);
-}
-
-TEST(EncodeDecodeTest, EncodeAndDecodeSmallOutputBufferZlib) {
- scoped_ptr<VideoEncoderRowBased> encoder(
- VideoEncoderRowBased::CreateZlibEncoder(64));
- scoped_ptr<VideoDecoderRowBased> decoder(
- VideoDecoderRowBased::CreateZlibDecoder());
- TestVideoEncoderDecoder(encoder.get(), decoder.get(), true);
-}
-
-TEST(EncodeDecodeTest, EncodeAndDecodeNoneStrictZlib) {
- scoped_ptr<VideoEncoderRowBased> encoder(
- VideoEncoderRowBased::CreateZlibEncoder());
- scoped_ptr<VideoDecoderRowBased> decoder(
- VideoDecoderRowBased::CreateZlibDecoder());
- TestVideoEncoderDecoder(encoder.get(), decoder.get(), false);
-}
-
-} // namespace remoting
diff --git a/remoting/codec/video_encoder_row_based.h b/remoting/codec/video_encoder_row_based.h
deleted file mode 100644
index 342327b..0000000
--- a/remoting/codec/video_encoder_row_based.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef REMOTING_CODEC_VIDEO_ENCODER_ROW_BASED_H_
-#define REMOTING_CODEC_VIDEO_ENCODER_ROW_BASED_H_
-
-#include "remoting/codec/video_encoder.h"
-#include "remoting/proto/video.pb.h"
-#include "third_party/skia/include/core/SkRect.h"
-
-namespace remoting {
-
-class Compressor;
-
-// VideoEncoderRowBased implements a VideoEncoder using zlib or verbatim
-// compression. Zlib-based encoder must be created using
-// CreateZlibEncoder(), verbatim encoder is created with
-// CreateVerbatimEncoder().
-//
-// Compressor is reset before encoding each rectangle, so that each
-// rectangle can be decoded independently.
-class VideoEncoderRowBased : public VideoEncoder {
- public:
- static VideoEncoderRowBased* CreateZlibEncoder();
- static VideoEncoderRowBased* CreateZlibEncoder(int packet_size);
- static VideoEncoderRowBased* CreateVerbatimEncoder();
- static VideoEncoderRowBased* CreateVerbatimEncoder(int packet_size);
-
- virtual ~VideoEncoderRowBased();
-
- virtual void Encode(
- scoped_refptr<CaptureData> capture_data,
- bool key_frame,
- const DataAvailableCallback& data_available_callback) OVERRIDE;
-
- private:
- VideoEncoderRowBased(Compressor* compressor,
- VideoPacketFormat::Encoding encoding);
- VideoEncoderRowBased(Compressor* compressor,
- VideoPacketFormat::Encoding encoding,
- int packet_size);
-
- // Encode a single dirty rect using compressor.
- void EncodeRect(const SkIRect& rect, bool last);
-
- // Marks a packet as the first in a series of rectangle updates.
- void PrepareUpdateStart(const SkIRect& rect, VideoPacket* packet);
-
- // Retrieves a pointer to the output buffer in |update| used for storing the
- // encoded rectangle data. Will resize the buffer to |size|.
- uint8* GetOutputBuffer(VideoPacket* packet, size_t size);
-
- // Submit |message| to |callback_|.
- void SubmitMessage(VideoPacket* packet, size_t rect_index);
-
- // The encoding of the incoming stream.
- VideoPacketFormat::Encoding encoding_;
-
- scoped_ptr<Compressor> compressor_;
-
- scoped_refptr<CaptureData> capture_data_;
- DataAvailableCallback callback_;
-
- // The most recent screen size.
- SkISize screen_size_;
-
- int packet_size_;
-};
-
-} // namespace remoting
-
-#endif // REMOTING_CODEC_VIDEO_ENCODER_ROW_BASED_H_
diff --git a/remoting/codec/video_encoder_row_based_unittest.cc b/remoting/codec/video_encoder_row_based_unittest.cc
deleted file mode 100644
index e94d18d..0000000
--- a/remoting/codec/video_encoder_row_based_unittest.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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/codec/video_encoder_row_based.h"
-
-#include "remoting/codec/codec_test.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace remoting {
-
-TEST(VideoEncoderZlibTest, TestVideoEncoder) {
- scoped_ptr<VideoEncoderRowBased> encoder(
- VideoEncoderRowBased::CreateZlibEncoder());
- TestVideoEncoder(encoder.get(), true);
-}
-
-TEST(VideoEncoderZlibTest, TestVideoEncoderSmallOutputBuffer) {
- scoped_ptr<VideoEncoderRowBased> encoder(
- VideoEncoderRowBased::CreateZlibEncoder(16));
- TestVideoEncoder(encoder.get(), true);
-}
-
-} // namespace remoting
diff --git a/remoting/codec/video_encoder_row_based.cc b/remoting/codec/video_encoder_verbatim.cc
index b2454aa..25f2217 100644
--- a/remoting/codec/video_encoder_row_based.cc
+++ b/remoting/codec/video_encoder_verbatim.cc
@@ -2,12 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "remoting/codec/video_encoder_row_based.h"
+#include "remoting/codec/video_encoder_verbatim.h"
#include "base/logging.h"
#include "remoting/base/capture_data.h"
-#include "remoting/base/compressor_verbatim.h"
-#include "remoting/base/compressor_zlib.h"
#include "remoting/base/util.h"
#include "remoting/proto/video.pb.h"
@@ -15,49 +13,19 @@ namespace remoting {
static const int kPacketSize = 1024 * 1024;
-VideoEncoderRowBased* VideoEncoderRowBased::CreateZlibEncoder() {
- return new VideoEncoderRowBased(new CompressorZlib(),
- VideoPacketFormat::ENCODING_ZLIB);
+VideoEncoderVerbatim::VideoEncoderVerbatim()
+ : screen_size_(SkISize::Make(0,0)),
+ max_packet_size_(kPacketSize) {
}
-VideoEncoderRowBased* VideoEncoderRowBased::CreateZlibEncoder(int packet_size) {
- return new VideoEncoderRowBased(new CompressorZlib(),
- VideoPacketFormat::ENCODING_ZLIB,
- packet_size);
+void VideoEncoderVerbatim::SetMaxPacketSize(int size) {
+ max_packet_size_ = size;
}
-VideoEncoderRowBased* VideoEncoderRowBased::CreateVerbatimEncoder() {
- return new VideoEncoderRowBased(new CompressorVerbatim(),
- VideoPacketFormat::ENCODING_VERBATIM);
+VideoEncoderVerbatim::~VideoEncoderVerbatim() {
}
-VideoEncoderRowBased* VideoEncoderRowBased::CreateVerbatimEncoder(
- int packet_size) {
- return new VideoEncoderRowBased(new CompressorVerbatim(),
- VideoPacketFormat::ENCODING_VERBATIM,
- packet_size);
-}
-
-VideoEncoderRowBased::VideoEncoderRowBased(Compressor* compressor,
- VideoPacketFormat::Encoding encoding)
- : encoding_(encoding),
- compressor_(compressor),
- screen_size_(SkISize::Make(0,0)),
- packet_size_(kPacketSize) {
-}
-
-VideoEncoderRowBased::VideoEncoderRowBased(Compressor* compressor,
- VideoPacketFormat::Encoding encoding,
- int packet_size)
- : encoding_(encoding),
- compressor_(compressor),
- screen_size_(SkISize::Make(0,0)),
- packet_size_(packet_size) {
-}
-
-VideoEncoderRowBased::~VideoEncoderRowBased() {}
-
-void VideoEncoderRowBased::Encode(
+void VideoEncoderVerbatim::Encode(
scoped_refptr<CaptureData> capture_data,
bool key_frame,
const DataAvailableCallback& data_available_callback) {
@@ -79,48 +47,49 @@ void VideoEncoderRowBased::Encode(
callback_.Reset();
}
-void VideoEncoderRowBased::EncodeRect(const SkIRect& rect, bool last) {
+void VideoEncoderVerbatim::EncodeRect(const SkIRect& rect, bool last) {
CHECK(capture_data_->data_planes().data[0]);
CHECK_EQ(capture_data_->pixel_format(), media::VideoFrame::RGB32);
const int strides = capture_data_->data_planes().strides[0];
const int bytes_per_pixel = 4;
const int row_size = bytes_per_pixel * rect.width();
- compressor_->Reset();
-
scoped_ptr<VideoPacket> packet(new VideoPacket());
PrepareUpdateStart(rect, packet.get());
const uint8* in = capture_data_->data_planes().data[0] +
rect.fTop * strides + rect.fLeft * bytes_per_pixel;
// TODO(hclam): Fill in the sequence number.
- uint8* out = GetOutputBuffer(packet.get(), packet_size_);
+ uint8* out = GetOutputBuffer(packet.get(), max_packet_size_);
int filled = 0;
int row_pos = 0; // Position in the current row in bytes.
int row_y = 0; // Current row.
- bool compress_again = true;
- while (compress_again) {
+ while (row_y < rect.height()) {
// Prepare a message for sending out.
if (!packet.get()) {
packet.reset(new VideoPacket());
- out = GetOutputBuffer(packet.get(), packet_size_);
+ out = GetOutputBuffer(packet.get(), max_packet_size_);
filled = 0;
}
- Compressor::CompressorFlush flush = Compressor::CompressorNoFlush;
- if (row_y == rect.height() - 1) {
- flush = Compressor::CompressorFinish;
+ if (row_y < rect.height()) {
+ int bytes_to_copy =
+ std::min(row_size - row_pos, max_packet_size_ - filled);
+ memcpy(out + filled, in + row_pos, bytes_to_copy);
+ row_pos += bytes_to_copy;
+ filled += bytes_to_copy;
+
+ // Jump to the next row when we've reached the end of the current row.
+ if (row_pos == row_size) {
+ row_pos = 0;
+ in += strides;
+ ++row_y;
+ }
}
- int consumed = 0;
- int written = 0;
- compress_again = compressor_->Process(in + row_pos, row_size - row_pos,
- out + filled, packet_size_ - filled,
- flush, &consumed, &written);
- row_pos += consumed;
- filled += written;
+ if (row_y == rect.height()) {
+ DCHECK_EQ(row_pos, 0);
- // We have reached the end of stream.
- if (!compress_again) {
+ packet->mutable_data()->resize(filled);
packet->set_flags(packet->flags() | VideoPacket::LAST_PACKET);
packet->set_capture_time_ms(capture_data_->capture_time_ms());
packet->set_client_sequence_number(
@@ -132,26 +101,17 @@ void VideoEncoderRowBased::EncodeRect(const SkIRect& rect, bool last) {
packet->mutable_format()->set_y_dpi(dpi.y());
if (last)
packet->set_flags(packet->flags() | VideoPacket::LAST_PARTITION);
- DCHECK(row_pos == row_size);
- DCHECK(row_y == rect.height() - 1);
}
- // If we have filled the message or we have reached the end of stream.
- if (filled == packet_size_ || !compress_again) {
+ // If we have filled the current packet, then send it.
+ if (filled == max_packet_size_ || row_y == rect.height()) {
packet->mutable_data()->resize(filled);
callback_.Run(packet.Pass());
}
-
- // Reached the end of input row and we're not at the last row.
- if (row_pos == row_size && row_y < rect.height() - 1) {
- row_pos = 0;
- in += strides;
- ++row_y;
- }
}
}
-void VideoEncoderRowBased::PrepareUpdateStart(const SkIRect& rect,
+void VideoEncoderVerbatim::PrepareUpdateStart(const SkIRect& rect,
VideoPacket* packet) {
packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET);
@@ -160,7 +120,7 @@ void VideoEncoderRowBased::PrepareUpdateStart(const SkIRect& rect,
format->set_y(rect.fTop);
format->set_width(rect.width());
format->set_height(rect.height());
- format->set_encoding(encoding_);
+ format->set_encoding(VideoPacketFormat::ENCODING_VERBATIM);
if (capture_data_->size() != screen_size_) {
screen_size_ = capture_data_->size();
format->set_screen_width(screen_size_.width());
@@ -168,7 +128,7 @@ void VideoEncoderRowBased::PrepareUpdateStart(const SkIRect& rect,
}
}
-uint8* VideoEncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) {
+uint8* VideoEncoderVerbatim::GetOutputBuffer(VideoPacket* packet, size_t size) {
packet->mutable_data()->resize(size);
// TODO(ajwong): Is there a better way to do this at all???
return const_cast<uint8*>(reinterpret_cast<const uint8*>(
diff --git a/remoting/codec/video_encoder_verbatim.h b/remoting/codec/video_encoder_verbatim.h
new file mode 100644
index 0000000..02c5814
--- /dev/null
+++ b/remoting/codec/video_encoder_verbatim.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2011 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.
+
+#ifndef REMOTING_CODEC_VIDEO_ENCODER_VERBATIM_H_
+#define REMOTING_CODEC_VIDEO_ENCODER_VERBATIM_H_
+
+#include "remoting/codec/video_encoder.h"
+#include "remoting/proto/video.pb.h"
+#include "third_party/skia/include/core/SkRect.h"
+
+namespace remoting {
+
+// VideoEncoderVerbatim implements a VideoEncoder that sends image data as a
+// sequence of RGB values, without compression.
+class VideoEncoderVerbatim : public VideoEncoder {
+ public:
+ VideoEncoderVerbatim();
+ virtual ~VideoEncoderVerbatim();
+
+ // Sets maximum size of data in video packets. Used by unittests.
+ void SetMaxPacketSize(int size);
+
+ // VideoEncoder interface.
+ virtual void Encode(
+ scoped_refptr<CaptureData> capture_data,
+ bool key_frame,
+ const DataAvailableCallback& data_available_callback) OVERRIDE;
+
+ private:
+ // Encode a single dirty |rect|.
+ void EncodeRect(const SkIRect& rect, bool last);
+
+ // Initializes first packet in a sequence of video packets to update screen
+ // rectangle |rect|.
+ void PrepareUpdateStart(const SkIRect& rect, VideoPacket* packet);
+
+ // Allocates a buffer of the specified |size| inside |packet| and returns the
+ // pointer to it.
+ uint8* GetOutputBuffer(VideoPacket* packet, size_t size);
+
+ // Submit |packet| to |callback_|.
+ void SubmitMessage(VideoPacket* packet, size_t rect_index);
+
+ scoped_refptr<CaptureData> capture_data_;
+ DataAvailableCallback callback_;
+
+ // The most recent screen size.
+ SkISize screen_size_;
+
+ int max_packet_size_;
+};
+
+} // namespace remoting
+
+#endif // REMOTING_CODEC_VIDEO_ENCODER_VERBATIM_H_
diff --git a/remoting/codec/video_encoder_verbatim_unittest.cc b/remoting/codec/video_encoder_verbatim_unittest.cc
new file mode 100644
index 0000000..d6315ee
--- /dev/null
+++ b/remoting/codec/video_encoder_verbatim_unittest.cc
@@ -0,0 +1,37 @@
+// 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/codec/video_encoder_verbatim.h"
+
+#include "remoting/codec/codec_test.h"
+#include "remoting/codec/video_decoder_verbatim.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+TEST(VideoEncoderVerbatimTest, TestVideoEncoder) {
+ scoped_ptr<VideoEncoderVerbatim> encoder(new VideoEncoderVerbatim());
+ TestVideoEncoder(encoder.get(), true);
+}
+
+TEST(VideoEncoderVerbatimTest, TestVideoEncoderSmallOutputBuffer) {
+ scoped_ptr<VideoEncoderVerbatim> encoder(new VideoEncoderVerbatim());
+ encoder->SetMaxPacketSize(16);
+ TestVideoEncoder(encoder.get(), true);
+}
+
+TEST(VideoEncoderVerbatimTest, EncodeAndDecode) {
+ scoped_ptr<VideoEncoderVerbatim> encoder(new VideoEncoderVerbatim());
+ scoped_ptr<VideoDecoderVerbatim> decoder(new VideoDecoderVerbatim());
+ TestVideoEncoderDecoder(encoder.get(), decoder.get(), false);
+}
+
+TEST(VideoEncoderVerbatimTest, EncodeAndDecodeSmallOutputBuffer) {
+ scoped_ptr<VideoEncoderVerbatim> encoder(new VideoEncoderVerbatim());
+ encoder->SetMaxPacketSize(16);
+ scoped_ptr<VideoDecoderVerbatim> decoder(new VideoDecoderVerbatim());
+ TestVideoEncoderDecoder(encoder.get(), decoder.get(), false);
+}
+
+} // namespace remoting