[email protected] | 5526773 | 2010-07-01 18:11:20 | [diff] [blame] | 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 | #ifndef REMOTING_BASE_COMPRESSOR_H_ |
| 6 | #define REMOTING_BASE_COMPRESSOR_H_ |
| 7 | |
| 8 | #include "base/basictypes.h" |
| 9 | |
| 10 | namespace remoting { |
| 11 | |
| 12 | // An object to compress data losslessly. Compressed data can be fully |
| 13 | // recovered by a Decompressor. |
| 14 | // |
| 15 | // Note that a Compressor can only be used on one stream during its |
| 16 | // lifetime. This object should be destroyed after use. |
| 17 | class Compressor { |
| 18 | public: |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 19 | |
| 20 | // Defines the flush modes for a compressor. |
| 21 | enum CompressorFlush { |
| 22 | CompressorNoFlush, |
| 23 | CompressorSyncFlush, |
| 24 | CompressorFinish, |
| 25 | }; |
[email protected] | 5526773 | 2010-07-01 18:11:20 | [diff] [blame] | 26 | virtual ~Compressor() {} |
| 27 | |
[email protected] | b53ab229 | 2010-12-06 22:46:27 | [diff] [blame] | 28 | // Resets all the internal state so the compressor behaves as if it |
| 29 | // was just created. |
| 30 | virtual void Reset() = 0; |
| 31 | |
[email protected] | 5526773 | 2010-07-01 18:11:20 | [diff] [blame] | 32 | // Compress |input_data| with |input_size| bytes. |
| 33 | // |
| 34 | // |output_data| is provided by the caller and |output_size| is the |
[email protected] | bfb6a56 | 2010-07-07 22:17:44 | [diff] [blame] | 35 | // size of |output_data|. |output_size| must be greater than 0. |
| 36 | // |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 37 | // |flush| is set to one of the three value: |
| 38 | // - CompressorNoFlush |
| 39 | // No flushing is requested |
| 40 | // - CompressorSyncFlush |
| 41 | // Write all pending output and write a synchronization point in the |
| 42 | // output data stream. |
| 43 | // - CompressorFinish |
| 44 | // Mark the end of stream. |
[email protected] | 5526773 | 2010-07-01 18:11:20 | [diff] [blame] | 45 | // |
| 46 | // Compressed data is written to |output_data|. |consumed| will |
| 47 | // contain the number of bytes consumed from the input. |written| |
| 48 | // contains the number of bytes written to output. |
[email protected] | 5526773 | 2010-07-01 18:11:20 | [diff] [blame] | 49 | // |
[email protected] | bfb6a56 | 2010-07-07 22:17:44 | [diff] [blame] | 50 | // Returns true if this method needs to be called again because |
| 51 | // there is more data to be written out. This is particularly |
| 52 | // useful for end of the compression stream. |
| 53 | virtual bool Process(const uint8* input_data, int input_size, |
| 54 | uint8* output_data, int output_size, |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 55 | CompressorFlush flush, int* consumed, int* written) = 0; |
[email protected] | 5526773 | 2010-07-01 18:11:20 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | } // namespace remoting |
| 59 | |
| 60 | #endif // REMOTING_BASE_COMPRESSOR_H_ |