diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 03:26:53 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-18 03:26:53 +0000 |
commit | 2149befbff640e5a050bb50acdbbfd95501ab9b1 (patch) | |
tree | 6c60699960b23fdbf4d0f17fd3d83dc394156f44 /remoting/base | |
parent | fb03b64b14315feaf008e89bc3abeb0b0c2576c4 (diff) | |
download | chromium_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/base')
-rw-r--r-- | remoting/base/compressor.h | 60 | ||||
-rw-r--r-- | remoting/base/compressor_verbatim.cc | 32 | ||||
-rw-r--r-- | remoting/base/compressor_verbatim.h | 33 | ||||
-rw-r--r-- | remoting/base/compressor_zlib.cc | 84 | ||||
-rw-r--r-- | remoting/base/compressor_zlib.h | 38 | ||||
-rw-r--r-- | remoting/base/compressor_zlib_unittest.cc | 70 | ||||
-rw-r--r-- | remoting/base/decompressor.h | 44 | ||||
-rw-r--r-- | remoting/base/decompressor_verbatim.cc | 31 | ||||
-rw-r--r-- | remoting/base/decompressor_verbatim.h | 29 | ||||
-rw-r--r-- | remoting/base/decompressor_zlib.cc | 66 | ||||
-rw-r--r-- | remoting/base/decompressor_zlib.h | 35 | ||||
-rw-r--r-- | remoting/base/decompressor_zlib_unittest.cc | 142 |
12 files changed, 0 insertions, 664 deletions
diff --git a/remoting/base/compressor.h b/remoting/base/compressor.h deleted file mode 100644 index 1678255..0000000 --- a/remoting/base/compressor.h +++ /dev/null @@ -1,60 +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. - -#ifndef REMOTING_BASE_COMPRESSOR_H_ -#define REMOTING_BASE_COMPRESSOR_H_ - -#include "base/basictypes.h" - -namespace remoting { - -// An object to compress data losslessly. Compressed data can be fully -// recovered by a Decompressor. -// -// Note that a Compressor can only be used on one stream during its -// lifetime. This object should be destroyed after use. -class Compressor { - public: - - // Defines the flush modes for a compressor. - enum CompressorFlush { - CompressorNoFlush, - CompressorSyncFlush, - CompressorFinish, - }; - virtual ~Compressor() {} - - // Resets all the internal state so the compressor behaves as if it - // was just created. - virtual void Reset() = 0; - - // Compress |input_data| with |input_size| bytes. - // - // |output_data| is provided by the caller and |output_size| is the - // size of |output_data|. |output_size| must be greater than 0. - // - // |flush| is set to one of the three value: - // - CompressorNoFlush - // No flushing is requested - // - CompressorSyncFlush - // Write all pending output and write a synchronization point in the - // output data stream. - // - CompressorFinish - // Mark the end of stream. - // - // Compressed data is written to |output_data|. |consumed| will - // contain the number of bytes consumed from the input. |written| - // contains the number of bytes written to output. - // - // Returns true if this method needs to be called again because - // there is more data to be written out. This is particularly - // useful for end of the compression stream. - virtual bool Process(const uint8* input_data, int input_size, - uint8* output_data, int output_size, - CompressorFlush flush, int* consumed, int* written) = 0; -}; - -} // namespace remoting - -#endif // REMOTING_BASE_COMPRESSOR_H_ diff --git a/remoting/base/compressor_verbatim.cc b/remoting/base/compressor_verbatim.cc deleted file mode 100644 index 97b71e1..0000000 --- a/remoting/base/compressor_verbatim.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 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 "base/logging.h" -#include "remoting/base/compressor_verbatim.h" - -namespace remoting { - -CompressorVerbatim::CompressorVerbatim() { -} - -CompressorVerbatim::~CompressorVerbatim() { -} - -void CompressorVerbatim::Reset() { -} - -bool CompressorVerbatim::Process(const uint8* input_data, int input_size, - uint8* output_data, int output_size, - CompressorFlush flush, int* consumed, - int* written) { - DCHECK_GT(output_size, 0); - int bytes_to_copy = std::min(input_size, output_size); - memcpy(output_data, input_data, bytes_to_copy); - - // Since we're just a memcpy, consumed and written are the same. - *consumed = *written = bytes_to_copy; - return (flush != CompressorFinish) || (output_size < bytes_to_copy); -} - -} // namespace remoting diff --git a/remoting/base/compressor_verbatim.h b/remoting/base/compressor_verbatim.h deleted file mode 100644 index 93cbd3c..0000000 --- a/remoting/base/compressor_verbatim.h +++ /dev/null @@ -1,33 +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_BASE_COMPRESSOR_VERBATIM_H_ -#define REMOTING_BASE_COMPRESSOR_VERBATIM_H_ - -#include "base/compiler_specific.h" -#include "remoting/base/compressor.h" - -namespace remoting { - -// Compressor for verbatim streams. -class CompressorVerbatim : public Compressor { - public: - CompressorVerbatim(); - virtual ~CompressorVerbatim(); - - // Compressor implementations. - virtual bool Process(const uint8* input_data, - int input_size, - uint8* output_data, - int output_size, - CompressorFlush flush, - int* consumed, - int* written) OVERRIDE; - - virtual void Reset() OVERRIDE; -}; - -} // namespace remoting - -#endif // REMOTING_BASE_COMPRESSOR_VERBATIM_H_ diff --git a/remoting/base/compressor_zlib.cc b/remoting/base/compressor_zlib.cc deleted file mode 100644 index 05ad621..0000000 --- a/remoting/base/compressor_zlib.cc +++ /dev/null @@ -1,84 +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/base/compressor_zlib.h" - -#if defined(USE_SYSTEM_ZLIB) -#include <zlib.h> -#else -#include "third_party/zlib/zlib.h" -#endif -#include "base/logging.h" - -namespace remoting { - -CompressorZlib::CompressorZlib() { - Reset(); -} - -CompressorZlib::~CompressorZlib() { - deflateEnd(stream_.get()); -} - -void CompressorZlib::Reset() { - if (stream_.get()) - deflateEnd(stream_.get()); - - stream_.reset(new z_stream()); - - stream_->next_in = Z_NULL; - stream_->zalloc = Z_NULL; - stream_->zfree = Z_NULL; - stream_->opaque = Z_NULL; - - deflateInit(stream_.get(), Z_BEST_SPEED); -} - -bool CompressorZlib::Process(const uint8* input_data, int input_size, - uint8* output_data, int output_size, - CompressorFlush flush, int* consumed, - int* written) { - DCHECK_GT(output_size, 0); - - // Setup I/O parameters. - stream_->avail_in = input_size; - stream_->next_in = (Bytef*)input_data; - stream_->avail_out = output_size; - stream_->next_out = (Bytef*)output_data; - - 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"; - } - - *consumed = input_size - stream_->avail_in; - *written = output_size - stream_->avail_out; - - // 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 diff --git a/remoting/base/compressor_zlib.h b/remoting/base/compressor_zlib.h deleted file mode 100644 index 32ac6c4..0000000 --- a/remoting/base/compressor_zlib.h +++ /dev/null @@ -1,38 +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_BASE_COMPRESSOR_ZLIB_H_ -#define REMOTING_BASE_COMPRESSOR_ZLIB_H_ - -#include "base/memory/scoped_ptr.h" -#include "remoting/base/compressor.h" - -typedef struct z_stream_s z_stream; - -namespace remoting { - -// A lossless compressor using zlib. -class CompressorZlib : public Compressor { - public: - CompressorZlib(); - virtual ~CompressorZlib(); - - // Compressor implementations. - virtual bool Process(const uint8* input_data, - int input_size, - uint8* output_data, - int output_size, - CompressorFlush flush, - int* consumed, - int* written) OVERRIDE; - - virtual void Reset() OVERRIDE; - - private: - scoped_ptr<z_stream> stream_; -}; - -} // namespace remoting - -#endif // REMOTING_BASE_COMPRESSOR_ZLIB_H_ diff --git a/remoting/base/compressor_zlib_unittest.cc b/remoting/base/compressor_zlib_unittest.cc deleted file mode 100644 index 0b9eade..0000000 --- a/remoting/base/compressor_zlib_unittest.cc +++ /dev/null @@ -1,70 +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 <stdlib.h> - -#include "remoting/base/compressor_zlib.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace remoting { - -static void GenerateTestData(uint8* data, int size, int seed) { - srand(seed); - for (int i = 0; i < size; ++i) - data[i] = rand() % 256; -} - -// Keep compressing |input_data| into |output_data| until the last -// bytes is consumed. -static void Compress(remoting::Compressor* compressor, - const uint8* input_data, int input_size, - uint8* output_data, int output_size) { - - // Feed data into the compress until the end. - // This loop will rewrite |output_data| continuously. - int consumed = 0; - int written = 0; - while (compressor->Process( - input_data, input_size, output_data, output_size, - input_size == 0 ? - Compressor::CompressorFinish : Compressor::CompressorNoFlush, - &consumed, &written)) { - input_data += consumed; - input_size -= consumed; - } -} - -TEST(CompressorZlibTest, Compress) { - static const int kRawDataSize = 1024 * 128; - static const int kCompressedDataSize = 256; - uint8 raw_data[kRawDataSize]; - uint8 compressed_data[kCompressedDataSize]; - - // Generate the test data.g - GenerateTestData(raw_data, kRawDataSize, 99); - - // Then use the compressor to compress. - remoting::CompressorZlib compressor; - Compress(&compressor, raw_data, kRawDataSize, - compressed_data, kCompressedDataSize); -} - -// Checks that zlib can work with a small output buffer by reading -// less from the input. -TEST(CompressorZlibTest, SmallOutputBuffer) { - static const int kRawDataSize = 1024 * 128; - static const int kCompressedDataSize = 1; - uint8 raw_data[kRawDataSize]; - uint8 compressed_data[kCompressedDataSize]; - - // Generate the test data.g - GenerateTestData(raw_data, kRawDataSize, 99); - - // Then use the compressor to compress. - remoting::CompressorZlib compressor; - Compress(&compressor, raw_data, kRawDataSize, - compressed_data, kCompressedDataSize); -} - -} // namespace remoting diff --git a/remoting/base/decompressor.h b/remoting/base/decompressor.h deleted file mode 100644 index 025850e..0000000 --- a/remoting/base/decompressor.h +++ /dev/null @@ -1,44 +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. - -#ifndef REMOTING_BASE_DECOMPRESSOR_H_ -#define REMOTING_BASE_DECOMPRESSOR_H_ - -#include "base/basictypes.h" - -namespace remoting { - -// An object to decompress data losslessly. This is used in pair with -// a compressor. -// -// Note that a decompressor can only be used on one stream during its -// lifetime. This object should be destroyed after use. -class Decompressor { - public: - virtual ~Decompressor() {} - - // Resets all the internal state so the decompressor behaves as if it was - // just created. - virtual void Reset() = 0; - - // Decompress |input_data| with |input_size| bytes. - // - // |output_data| is provided by the caller and |output_size| is the - // size of |output_data|. |output_size| must be greater than 0. - // - // Decompressed data is written to |output_data|. |consumed| will - // contain the number of bytes consumed from the input. |written| - // contains the number of bytes written to output. - // - // Returns true if this method needs to be called again because - // there is more bytes to be decompressed or more input data is - // needed. - virtual bool Process(const uint8* input_data, int input_size, - uint8* output_data, int output_size, - int* consumed, int* written) = 0; -}; - -} // namespace remoting - -#endif // REMOTING_BASE_DECOMPRESSOR_H_ diff --git a/remoting/base/decompressor_verbatim.cc b/remoting/base/decompressor_verbatim.cc deleted file mode 100644 index d0d2271..0000000 --- a/remoting/base/decompressor_verbatim.cc +++ /dev/null @@ -1,31 +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/base/decompressor_verbatim.h" - -#include "base/logging.h" - -namespace remoting { - -DecompressorVerbatim::DecompressorVerbatim() { -} - -DecompressorVerbatim::~DecompressorVerbatim() { -} - -void DecompressorVerbatim::Reset() { -} - -bool DecompressorVerbatim::Process(const uint8* input_data, int input_size, - uint8* output_data, int output_size, - int* consumed, int* written) { - DCHECK_GT(output_size, 0); - int bytes_to_copy = std::min(input_size, output_size); - memcpy(output_data, input_data, bytes_to_copy); - - // Since we're just a memcpy, consumed and written are the same. - *consumed = *written = bytes_to_copy; - return true; -} -} // namespace remoting diff --git a/remoting/base/decompressor_verbatim.h b/remoting/base/decompressor_verbatim.h deleted file mode 100644 index 7cc8885..0000000 --- a/remoting/base/decompressor_verbatim.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2012 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_BASE_DECOMPRESSOR_VERBATIM_H_ -#define REMOTING_BASE_DECOMPRESSOR_VERBATIM_H_ - -#include "base/compiler_specific.h" -#include "remoting/base/decompressor.h" - -namespace remoting { - -// A lossless decompressor using zlib. -class DecompressorVerbatim : public Decompressor { - public: - DecompressorVerbatim(); - virtual ~DecompressorVerbatim(); - - virtual void Reset() OVERRIDE; - - // Decompressor implementations. - virtual bool Process(const uint8* input_data, int input_size, - uint8* output_data, int output_size, - int* consumed, int* written) OVERRIDE; -}; - -} // namespace remoting - -#endif // REMOTING_BASE_DECOMPRESSOR_VERBATIM_H_ diff --git a/remoting/base/decompressor_zlib.cc b/remoting/base/decompressor_zlib.cc deleted file mode 100644 index 6dbc21b..0000000 --- a/remoting/base/decompressor_zlib.cc +++ /dev/null @@ -1,66 +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. - -#include "remoting/base/decompressor_zlib.h" - -#if defined(USE_SYSTEM_ZLIB) -#include <zlib.h> -#else -#include "third_party/zlib/zlib.h" -#endif -#include "base/logging.h" - -namespace remoting { - -DecompressorZlib::DecompressorZlib() { - InitStream(); -} - -DecompressorZlib::~DecompressorZlib() { - inflateEnd(stream_.get()); -} - -void DecompressorZlib::Reset() { - inflateEnd(stream_.get()); - InitStream(); -} - -bool DecompressorZlib::Process(const uint8* input_data, int input_size, - uint8* output_data, int output_size, - int* consumed, int* written) { - DCHECK_GT(output_size, 0); - - // Setup I/O parameters. - stream_->avail_in = input_size; - stream_->next_in = (Bytef*)input_data; - stream_->avail_out = output_size; - stream_->next_out = (Bytef*)output_data; - - int ret = inflate(stream_.get(), Z_NO_FLUSH); - if (ret == Z_STREAM_ERROR) { - NOTREACHED() << "zlib compression failed"; - } - - *consumed = input_size - stream_->avail_in; - *written = output_size - stream_->avail_out; - - // Since we check that output is always greater than 0, the only - // reason for us to get Z_BUF_ERROR is when zlib requires more input - // data. - return ret == Z_OK || ret == Z_BUF_ERROR; -} - -void DecompressorZlib::InitStream() { - stream_.reset(new z_stream()); - - stream_->next_in = Z_NULL; - stream_->zalloc = Z_NULL; - stream_->zfree = Z_NULL; - stream_->opaque = Z_NULL; - - int ret = inflateInit(stream_.get()); - DCHECK_EQ(ret, Z_OK); -} - -} // namespace remoting diff --git a/remoting/base/decompressor_zlib.h b/remoting/base/decompressor_zlib.h deleted file mode 100644 index 5d1a88b..0000000 --- a/remoting/base/decompressor_zlib.h +++ /dev/null @@ -1,35 +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_BASE_DECOMPRESSOR_ZLIB_H_ -#define REMOTING_BASE_DECOMPRESSOR_ZLIB_H_ - -#include "base/memory/scoped_ptr.h" -#include "remoting/base/decompressor.h" - -typedef struct z_stream_s z_stream; - -namespace remoting { - -// A lossless decompressor using zlib. -class DecompressorZlib : public Decompressor { - public: - DecompressorZlib(); - virtual ~DecompressorZlib(); - - virtual void Reset() OVERRIDE; - - // Decompressor implementations. - virtual bool Process(const uint8* input_data, int input_size, - uint8* output_data, int output_size, - int* consumed, int* written) OVERRIDE; - - private: - void InitStream(); - scoped_ptr<z_stream> stream_; -}; - -} // namespace remoting - -#endif // REMOTING_BASE_DECOMPRESSOR_ZLIB_H_ diff --git a/remoting/base/decompressor_zlib_unittest.cc b/remoting/base/decompressor_zlib_unittest.cc deleted file mode 100644 index aebaa5a..0000000 --- a/remoting/base/decompressor_zlib_unittest.cc +++ /dev/null @@ -1,142 +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 <stdlib.h> - -#include "remoting/base/compressor_zlib.h" -#include "remoting/base/decompressor_zlib.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace remoting { - -static void GenerateTestData(uint8* data, int size, int seed) { - srand(seed); - for (int i = 0; i < size; ++i) - data[i] = rand() % 256; -} - -// Keep compressing |input_data| into |output_data| until the last -// bytes is consumed. -// -// The compressed size is written to |compressed_size|. -static void Compress(remoting::Compressor* compressor, - const uint8* input_data, int input_size, - uint8* output_data, int output_size, - int* compressed_size) { - *compressed_size = 0; - while (true) { - int consumed, written; - bool ret = compressor->Process( - input_data, input_size, output_data, output_size, - input_size == 0 ? - Compressor::CompressorFinish : Compressor::CompressorNoFlush, - &consumed, &written); - input_data += consumed; - input_size -= consumed; - output_data += written; - output_size -= written; - *compressed_size += written; - - if (!ret) - break; - } -} - -// The decompressed size is written to |decompressed_size|. -static void Decompress(remoting::Decompressor* decompressor, - const uint8* input_data, int input_size, - uint8* output_data, int output_size, - int* decompressed_size) { - *decompressed_size = 0; - while (true) { - int consumed, written; - bool ret = decompressor->Process(input_data, input_size, - output_data, output_size, - &consumed, &written); - input_data += consumed; - input_size -= consumed; - output_data += written; - output_size -= written; - *decompressed_size += written; - - if (!ret) - break; - } -} - -TEST(DecompressorZlibTest, CompressAndDecompress) { - static const int kRawDataSize = 1024 * 128; - static const int kCompressedDataSize = 2 * kRawDataSize; - static const int kDecompressedDataSize = kRawDataSize; - - uint8 raw_data[kRawDataSize]; - uint8 compressed_data[kCompressedDataSize]; - uint8 decompressed_data[kDecompressedDataSize]; - - // Generate the test data.g - GenerateTestData(raw_data, kRawDataSize, 99); - - // Then use the compressor. - remoting::CompressorZlib compressor; - int compressed_size = 0; - Compress(&compressor, raw_data, kRawDataSize, - compressed_data, kCompressedDataSize, - &compressed_size); - - // Then use the decompressor. - remoting::DecompressorZlib decompressor; - int decompressed_size = 0; - Decompress(&decompressor, compressed_data, compressed_size, - decompressed_data, kDecompressedDataSize, - &decompressed_size); - - EXPECT_EQ(kRawDataSize, decompressed_size); - EXPECT_EQ(0, memcmp(raw_data, decompressed_data, decompressed_size)); -} - -// Checks that zlib can work with a small output buffer by limiting -// number of bytes it gets from the input. -TEST(DecompressorZlibTest, SmallOutputBuffer) { - static const int kRawDataSize = 1024 * 128; - static const int kCompressedDataSize = 2 * kRawDataSize; - - uint8 raw_data[kRawDataSize]; - uint8 compressed_data[kCompressedDataSize]; - - // Generate the test data. - GenerateTestData(raw_data, kRawDataSize, 99); - - // Then use the compressor to compress. - remoting::CompressorZlib compressor; - int compressed_size = 0; - Compress(&compressor, raw_data, kRawDataSize, - compressed_data, kCompressedDataSize, - &compressed_size); - - // Then use the decompressor. We decompress into a 1 byte buffer - // every time. - remoting::DecompressorZlib decompressor; - uint8* input_data = compressed_data; - int input_size = compressed_size; - int decompressed_size = 0; - while (true) { - int consumed, written; - uint8 output_data; - bool ret = decompressor.Process(input_data, input_size, - &output_data, 1, - &consumed, &written); - input_data += consumed; - input_size -= consumed; - - // Expect that there's only one byte written. - EXPECT_EQ(1, written); - decompressed_size += written; - - if (!ret) - break; - } - EXPECT_EQ(kRawDataSize, decompressed_size); -} - -} // namespace remoting |