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 virtual ~Compressor() {} | 19 virtual ~Compressor() {} |
20 | 20 |
21 // Compress |input_data| with |input_size| bytes. | 21 // Compress |input_data| with |input_size| bytes. |
22 // | 22 // |
23 // |output_data| is provided by the caller and |output_size| is the | 23 // |output_data| is provided by the caller and |output_size| is the |
24 // size of |output_data|. | 24 // size of |output_data|. |output_size| must be greater than 0. |
| 25 // |
| 26 // |input_size| is set to 0 to indicate the end of input stream. |
25 // | 27 // |
26 // Compressed data is written to |output_data|. |consumed| will | 28 // Compressed data is written to |output_data|. |consumed| will |
27 // contain the number of bytes consumed from the input. |written| | 29 // contain the number of bytes consumed from the input. |written| |
28 // contains the number of bytes written to output. | 30 // contains the number of bytes written to output. |
29 virtual void Write(const uint8* input_data, int input_size, | |
30 uint8* output_data, int output_size, | |
31 int* consumed, int* written) = 0; | |
32 | |
33 // Flush all the remaining data in the compressor. | |
34 // | 31 // |
35 // |output_data| is provided by the caller and |output_size| is called | 32 // Returns true if this method needs to be called again because |
36 // with the size of |output_data|. | 33 // there is more data to be written out. This is particularly |
37 // | 34 // useful for end of the compression stream. |
38 // Output data is written to |output_data| and |written| contains the | 35 virtual bool Process(const uint8* input_data, int input_size, |
39 // number of bytes written. | 36 uint8* output_data, int output_size, |
40 // | 37 int* consumed, int* written) = 0; |
41 // Returns true if |output_data| is not large enough to carry all | |
42 // compressed data and caller needs to call Flush() again. | |
43 virtual bool Flush(uint8* output_data, int output_size, | |
44 int* written) = 0; | |
45 }; | 38 }; |
46 | 39 |
47 } // namespace remoting | 40 } // namespace remoting |
48 | 41 |
49 #endif // REMOTING_BASE_COMPRESSOR_H_ | 42 #endif // REMOTING_BASE_COMPRESSOR_H_ |
OLD | NEW |