Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: remoting/base/decompressor_zlib.cc

Issue 2815043: zlib decompression for chromoting (Closed)
Patch Set: git try Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/base/decompressor_zlib.h ('k') | remoting/base/decompressor_zlib_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/base/decompressor_zlib.h"
6
7 #if defined(USE_SYSTEM_ZLIB)
8 #include <zlib.h>
9 // The code below uses the MOZ_Z_ forms of these functions in order that things
10 // should work on Windows. In order to make this code cross platform, we map
11 // back to the normal functions here in the case that we are using the system
12 // zlib.
13 #define MOZ_Z_inflate inflate
14 #define MOZ_Z_inflateEnd inflateEnd
15 #define MOZ_Z_inflateInit_ inflateInit_
16 #else
17 #include "third_party/zlib/zlib.h"
18 #endif
19 #include "base/logging.h"
20
21 namespace remoting {
22
23 DecompressorZlib::DecompressorZlib() {
24 stream_.reset(new z_stream());
25
26 stream_->next_in = Z_NULL;
27 stream_->zalloc = Z_NULL;
28 stream_->zfree = Z_NULL;
29 stream_->opaque = Z_NULL;
30
31 inflateInit(stream_.get());
32 }
33
34 DecompressorZlib::~DecompressorZlib() {
35 inflateEnd(stream_.get());
36 }
37
38 bool DecompressorZlib::Process(const uint8* input_data, int input_size,
39 uint8* output_data, int output_size,
40 int* consumed, int* written) {
41 DCHECK_GT(output_size, 0);
42
43 // Setup I/O parameters.
44 stream_->avail_in = input_size;
45 stream_->next_in = (Bytef*)input_data;
46 stream_->avail_out = output_size;
47 stream_->next_out = (Bytef*)output_data;
48
49 int ret = inflate(stream_.get(), Z_NO_FLUSH);
50 if (ret == Z_STREAM_ERROR) {
51 NOTREACHED() << "zlib compression failed";
52 }
53
54 *consumed = input_size - stream_->avail_in;
55 *written = output_size - stream_->avail_out;
56
57 // Since we check that output is always greater than 0, the only
58 // reason for us to get Z_BUF_ERROR is when zlib requires more input
59 // data.
60 return ret == Z_OK || ret == Z_BUF_ERROR;
61 }
62
63 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/decompressor_zlib.h ('k') | remoting/base/decompressor_zlib_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698