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

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

Issue 2868062: EncoderZlib/DecoderZlib for chromoting (Closed)
Patch Set: from .cc to .c Created 10 years, 4 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/compressor_zlib.h ('k') | remoting/base/compressor_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
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
(...skipping 19 matching lines...) Expand all
30 30
31 deflateInit(stream_.get(), Z_BEST_SPEED); 31 deflateInit(stream_.get(), Z_BEST_SPEED);
32 } 32 }
33 33
34 CompressorZlib::~CompressorZlib() { 34 CompressorZlib::~CompressorZlib() {
35 deflateEnd(stream_.get()); 35 deflateEnd(stream_.get());
36 } 36 }
37 37
38 bool CompressorZlib::Process(const uint8* input_data, int input_size, 38 bool CompressorZlib::Process(const uint8* input_data, int input_size,
39 uint8* output_data, int output_size, 39 uint8* output_data, int output_size,
40 int* consumed, int* written) { 40 CompressorFlush flush, int* consumed,
41 int* written) {
41 DCHECK_GT(output_size, 0); 42 DCHECK_GT(output_size, 0);
42 43
43 // Setup I/O parameters. 44 // Setup I/O parameters.
44 stream_->avail_in = input_size; 45 stream_->avail_in = input_size;
45 stream_->next_in = (Bytef*)input_data; 46 stream_->next_in = (Bytef*)input_data;
46 stream_->avail_out = output_size; 47 stream_->avail_out = output_size;
47 stream_->next_out = (Bytef*)output_data; 48 stream_->next_out = (Bytef*)output_data;
48 49
49 int ret = deflate(stream_.get(), input_size ? Z_NO_FLUSH : Z_FINISH); 50 int z_flush = 0;
51 if (flush == CompressorSyncFlush) {
52 z_flush = Z_SYNC_FLUSH;
53 } else if (flush == CompressorFinish) {
54 z_flush = Z_FINISH;
55 } else if (flush == CompressorNoFlush) {
56 z_flush = Z_NO_FLUSH;
57 } else {
58 NOTREACHED() << "Unsupported flush mode";
59 }
60
61 int ret = deflate(stream_.get(), z_flush);
50 if (ret == Z_STREAM_ERROR) { 62 if (ret == Z_STREAM_ERROR) {
51 NOTREACHED() << "zlib compression failed"; 63 NOTREACHED() << "zlib compression failed";
52 } 64 }
53 65
54 *consumed = input_size - stream_->avail_in; 66 *consumed = input_size - stream_->avail_in;
55 *written = output_size - stream_->avail_out; 67 *written = output_size - stream_->avail_out;
56 68
57 // Return true when we get Z_BUF_ERROR, this way we can feed more data 69 // If |ret| equals Z_STREAM_END we have reached the end of stream.
58 // to zlib. 70 // If |ret| equals Z_BUF_ERROR we have the end of the synchronication point.
59 return ret == Z_OK || ret == Z_BUF_ERROR; 71 // For these two cases we need to stop compressing.
72 if (ret == Z_OK) {
73 return true;
74 } else if (ret == Z_STREAM_END) {
75 return false;
76 } else if (ret == Z_BUF_ERROR) {
77 return stream_->avail_out == 0;
78 } else {
79 NOTREACHED() << "Unexpected zlib error: " << ret;
80 return false;
81 }
60 } 82 }
61 83
62 } // namespace remoting 84 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/compressor_zlib.h ('k') | remoting/base/compressor_zlib_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698