summaryrefslogtreecommitdiffstats
path: root/remoting/base/compressor_zlib.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/compressor_zlib.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/compressor_zlib.cc')
-rw-r--r--remoting/base/compressor_zlib.cc32
1 files changed, 27 insertions, 5 deletions
diff --git a/remoting/base/compressor_zlib.cc b/remoting/base/compressor_zlib.cc
index ae5b388..6f700731 100644
--- a/remoting/base/compressor_zlib.cc
+++ b/remoting/base/compressor_zlib.cc
@@ -37,7 +37,8 @@ CompressorZlib::~CompressorZlib() {
bool CompressorZlib::Process(const uint8* input_data, int input_size,
uint8* output_data, int output_size,
- int* consumed, int* written) {
+ CompressorFlush flush, int* consumed,
+ int* written) {
DCHECK_GT(output_size, 0);
// Setup I/O parameters.
@@ -46,7 +47,18 @@ bool CompressorZlib::Process(const uint8* input_data, int input_size,
stream_->avail_out = output_size;
stream_->next_out = (Bytef*)output_data;
- int ret = deflate(stream_.get(), input_size ? Z_NO_FLUSH : Z_FINISH);
+ int z_flush = 0;
+ if (flush == CompressorSyncFlush) {
+ z_flush = Z_SYNC_FLUSH;
+ } else if (flush == CompressorFinish) {
+ z_flush = Z_FINISH;
+ } else if (flush == CompressorNoFlush) {
+ z_flush = Z_NO_FLUSH;
+ } else {
+ NOTREACHED() << "Unsupported flush mode";
+ }
+
+ int ret = deflate(stream_.get(), z_flush);
if (ret == Z_STREAM_ERROR) {
NOTREACHED() << "zlib compression failed";
}
@@ -54,9 +66,19 @@ bool CompressorZlib::Process(const uint8* input_data, int input_size,
*consumed = input_size - stream_->avail_in;
*written = output_size - stream_->avail_out;
- // Return true when we get Z_BUF_ERROR, this way we can feed more data
- // to zlib.
- return ret == Z_OK || ret == Z_BUF_ERROR;
+ // If |ret| equals Z_STREAM_END we have reached the end of stream.
+ // If |ret| equals Z_BUF_ERROR we have the end of the synchronication point.
+ // For these two cases we need to stop compressing.
+ if (ret == Z_OK) {
+ return true;
+ } else if (ret == Z_STREAM_END) {
+ return false;
+ } else if (ret == Z_BUF_ERROR) {
+ return stream_->avail_out == 0;
+ } else {
+ NOTREACHED() << "Unexpected zlib error: " << ret;
+ return false;
+ }
}
} // namespace remoting