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