diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 22:17:44 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 22:17:44 +0000 |
commit | bfb6a560ee1f95a5350e280e61a5a3d2e01b92c2 (patch) | |
tree | 2c4c231716b6aa30ace2c3dd1f83f172337368f0 /remoting/base/decompressor_zlib.cc | |
parent | 2e7c2aa7179907202155d4714913e0a0724e11a5 (diff) | |
download | chromium_src-bfb6a560ee1f95a5350e280e61a5a3d2e01b92c2.zip chromium_src-bfb6a560ee1f95a5350e280e61a5a3d2e01b92c2.tar.gz chromium_src-bfb6a560ee1f95a5350e280e61a5a3d2e01b92c2.tar.bz2 |
zlib decompression for chromoting
Using zlib for decompression. Also revised the API and usage of zlib
for compression.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/2815043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51785 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base/decompressor_zlib.cc')
-rw-r--r-- | remoting/base/decompressor_zlib.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/remoting/base/decompressor_zlib.cc b/remoting/base/decompressor_zlib.cc new file mode 100644 index 0000000..e3060bd --- /dev/null +++ b/remoting/base/decompressor_zlib.cc @@ -0,0 +1,63 @@ +// 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_zlib.h" + +#if defined(USE_SYSTEM_ZLIB) +#include <zlib.h> +// The code below uses the MOZ_Z_ forms of these functions in order that things +// should work on Windows. In order to make this code cross platform, we map +// back to the normal functions here in the case that we are using the system +// zlib. +#define MOZ_Z_inflate inflate +#define MOZ_Z_inflateEnd inflateEnd +#define MOZ_Z_inflateInit_ inflateInit_ +#else +#include "third_party/zlib/zlib.h" +#endif +#include "base/logging.h" + +namespace remoting { + +DecompressorZlib::DecompressorZlib() { + stream_.reset(new z_stream()); + + stream_->next_in = Z_NULL; + stream_->zalloc = Z_NULL; + stream_->zfree = Z_NULL; + stream_->opaque = Z_NULL; + + inflateInit(stream_.get()); +} + +DecompressorZlib::~DecompressorZlib() { + inflateEnd(stream_.get()); +} + +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; +} + +} // namespace remoting |