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

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

Issue 5382008: Refactor ZLib and Verbatim encoders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « remoting/base/compressor_zlib.h ('k') | remoting/base/encoder_row_based.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/base/compressor_zlib.h" 5 #include "remoting/base/compressor_zlib.h"
6 6
7 #if defined(USE_SYSTEM_ZLIB) 7 #if defined(USE_SYSTEM_ZLIB)
8 #include <zlib.h> 8 #include <zlib.h>
9 // The code below uses the MOZ_Z_ forms of these functions in order that things 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 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 11 // back to the normal functions here in the case that we are using the system
12 // zlib. 12 // zlib.
13 #define MOZ_Z_deflate deflate 13 #define MOZ_Z_deflate deflate
14 #define MOZ_Z_deflateEnd deflateEnd 14 #define MOZ_Z_deflateEnd deflateEnd
15 #define MOZ_Z_deflateInit_ deflateInit_ 15 #define MOZ_Z_deflateInit_ deflateInit_
16 #else 16 #else
17 #include "third_party/zlib/zlib.h" 17 #include "third_party/zlib/zlib.h"
18 #endif 18 #endif
19 #include "base/logging.h" 19 #include "base/logging.h"
20 20
21 namespace remoting { 21 namespace remoting {
22 22
23 CompressorZlib::CompressorZlib() { 23 CompressorZlib::CompressorZlib() {
24 Reset();
25 }
26
27 CompressorZlib::~CompressorZlib() {
28 deflateEnd(stream_.get());
29 }
30
31 void CompressorZlib::Reset() {
32 if (stream_.get())
33 deflateEnd(stream_.get());
34
24 stream_.reset(new z_stream()); 35 stream_.reset(new z_stream());
25 36
26 stream_->next_in = Z_NULL; 37 stream_->next_in = Z_NULL;
27 stream_->zalloc = Z_NULL; 38 stream_->zalloc = Z_NULL;
28 stream_->zfree = Z_NULL; 39 stream_->zfree = Z_NULL;
29 stream_->opaque = Z_NULL; 40 stream_->opaque = Z_NULL;
30 41
31 deflateInit(stream_.get(), Z_BEST_SPEED); 42 deflateInit(stream_.get(), Z_BEST_SPEED);
32 } 43 }
33 44
34 CompressorZlib::~CompressorZlib() {
35 deflateEnd(stream_.get());
36 }
37
38 bool CompressorZlib::Process(const uint8* input_data, int input_size, 45 bool CompressorZlib::Process(const uint8* input_data, int input_size,
39 uint8* output_data, int output_size, 46 uint8* output_data, int output_size,
40 CompressorFlush flush, int* consumed, 47 CompressorFlush flush, int* consumed,
41 int* written) { 48 int* written) {
42 DCHECK_GT(output_size, 0); 49 DCHECK_GT(output_size, 0);
43 50
44 // Setup I/O parameters. 51 // Setup I/O parameters.
45 stream_->avail_in = input_size; 52 stream_->avail_in = input_size;
46 stream_->next_in = (Bytef*)input_data; 53 stream_->next_in = (Bytef*)input_data;
47 stream_->avail_out = output_size; 54 stream_->avail_out = output_size;
(...skipping 27 matching lines...) Expand all
75 return false; 82 return false;
76 } else if (ret == Z_BUF_ERROR) { 83 } else if (ret == Z_BUF_ERROR) {
77 return stream_->avail_out == 0; 84 return stream_->avail_out == 0;
78 } else { 85 } else {
79 NOTREACHED() << "Unexpected zlib error: " << ret; 86 NOTREACHED() << "Unexpected zlib error: " << ret;
80 return false; 87 return false;
81 } 88 }
82 } 89 }
83 90
84 } // namespace remoting 91 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/compressor_zlib.h ('k') | remoting/base/encoder_row_based.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698