summaryrefslogtreecommitdiffstats
path: root/remoting/base/codec_test.cc
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-27 01:42:46 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-27 01:42:46 +0000
commit66db1af9f23041dd22f821cdee8f470e20bd2650 (patch)
treeb284e9776df8cafc55629c5c75f5d7df4846f5eb /remoting/base/codec_test.cc
parent60b7dda9b3a35d038b7ac0f04ca8f242266eb2c6 (diff)
downloadchromium_src-66db1af9f23041dd22f821cdee8f470e20bd2650.zip
chromium_src-66db1af9f23041dd22f821cdee8f470e20bd2650.tar.gz
chromium_src-66db1af9f23041dd22f821cdee8f470e20bd2650.tar.bz2
EncoderZlib/DecoderZlib for chromoting
Encoder and decoder using zlib for chromoting. This implementation has zero copy out of the decoder and encoder. The consequence is that we have to break out the zlib stream into rect boundaries which requires the synchronication flush feature in zlib. This feature will hurt compression ratio but the effect still need to be measured. This patch also provides tests for testing the Encoder and Decoder pair with zlib. TEST=remoting_unittests Review URL: http://codereview.chromium.org/2868062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base/codec_test.cc')
-rw-r--r--remoting/base/codec_test.cc43
1 files changed, 41 insertions, 2 deletions
diff --git a/remoting/base/codec_test.cc b/remoting/base/codec_test.cc
index 26a3f65..4085b28 100644
--- a/remoting/base/codec_test.cc
+++ b/remoting/base/codec_test.cc
@@ -10,6 +10,7 @@
#include "remoting/base/codec_test.h"
#include "remoting/base/encoder.h"
#include "remoting/base/mock_objects.h"
+#include "remoting/base/protocol_util.h"
#include "testing/gtest/include/gtest/gtest.h"
static const int kWidth = 320;
@@ -22,7 +23,7 @@ static const gfx::Rect kTestRects[] = {
gfx::Rect(0, 0, kWidth / 2, kHeight / 2),
gfx::Rect(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
gfx::Rect(16, 16, 16, 16),
- gfx::Rect(128, 64, 32, 32)
+ gfx::Rect(128, 64, 32, 32),
};
namespace remoting {
@@ -70,6 +71,7 @@ class EncoderMessageTester {
: begin_rect_(0),
rect_data_(0),
end_rect_(0),
+ added_rects_(0),
state_(kWaitingForBeginRect),
strict_(false) {
}
@@ -77,6 +79,9 @@ class EncoderMessageTester {
~EncoderMessageTester() {
EXPECT_EQ(begin_rect_, end_rect_);
EXPECT_EQ(kWaitingForBeginRect, state_);
+ if (strict_){
+ EXPECT_EQ(begin_rect_, added_rects_);
+ }
}
// Test that we received the correct message.
@@ -123,6 +128,7 @@ class EncoderMessageTester {
void AddRects(const gfx::Rect* rects, int count) {
rects_.insert(rects_.begin() + rects_.size(), rects, rects + count);
+ added_rects_ += count;
}
private:
@@ -134,6 +140,7 @@ class EncoderMessageTester {
int begin_rect_;
int rect_data_;
int end_rect_;
+ int added_rects_;
State state_;
bool strict_;
@@ -172,7 +179,6 @@ class DecoderTester {
decoder_->EndDecode();
}
delete message;
- return;
}
void set_strict(bool strict) {
@@ -194,11 +200,28 @@ class DecoderTester {
void OnPartialDecodeDone() {
if (!strict_)
return;
+
+ // Test the content of the update rect.
for (size_t i = 0; i < update_rects_.size(); ++i) {
+ LOG(INFO) << "Testing Rect " << i;
EXPECT_FALSE(rects_.empty());
gfx::Rect rect = rects_.front();
rects_.pop_front();
EXPECT_EQ(rect, update_rects_[i]);
+
+ EXPECT_EQ(frame_->stride(0), capture_data_->data_planes().strides[0]);
+ const int stride = frame_->stride(0);
+ const int offset = stride * update_rects_[i].y() +
+ kBytesPerPixel * update_rects_[i].x();
+ const uint8* original = capture_data_->data_planes().data[0] + offset;
+ const uint8* decoded = frame_->data(0) + offset;
+ const int row_size = kBytesPerPixel * update_rects_[i].width();
+ for (int y = 0; y < update_rects_[i].height(); ++y) {
+ EXPECT_EQ(0, memcmp(original, decoded, row_size))
+ << "Row " << y << " is different";
+ original += stride;
+ decoded += stride;
+ }
}
}
@@ -354,6 +377,22 @@ static void TestEncodingRects(Encoder* encoder,
decoder_tester->AddRects(rects, count);
decoder_tester->reset_decode_done();
+ // Generate random data for the updated rects.
+ srand(0);
+ for (int i = 0; i < count; ++i) {
+ const gfx::Rect rect = rects[i];
+ const int bytes_per_pixel = GetBytesPerPixel(data->pixel_format());
+ const int row_size = bytes_per_pixel * rect.width();
+ uint8* memory = data->data_planes().data[0] +
+ data->data_planes().strides[0] * rect.y() +
+ bytes_per_pixel * rect.x();
+ for (int y = 0; y < rect.height(); ++y) {
+ for (int x = 0; x < row_size; ++x)
+ memory[x] = rand() % 256;
+ memory += data->data_planes().strides[0];
+ }
+ }
+
encoder->Encode(data, true,
NewCallback(encoder_tester, &EncoderTester::DataAvailable));
EXPECT_TRUE(decoder_tester->decode_done());