lib functions for simple buffer encoding/decoding
[platform/upstream/libaec.git] / src / libaec.h
1 #ifndef LIBAEC_H
2 #define LIBAEC_H
3
4 #include <stddef.h>
5
6 struct internal_state;
7
8 struct aec_stream {
9     const unsigned char *next_in;
10     size_t avail_in;            /* number of bytes available at
11                                  * next_in
12                                  */
13     size_t total_in;            /* total number of input bytes read so
14                                  * far
15                                  */
16     unsigned char *next_out;
17     size_t avail_out;           /* remaining free space at next_out */
18     size_t total_out;           /* total number of bytes output so far */
19     int bit_per_sample;         /* resolution in bits per sample (n =
20                                  * 1, ..., 32)
21                                  */
22     int block_size;             /* block size in samples */
23     int rsi;                    /* Reference sample interval, the number
24                                  * of _blocks_ between consecutive
25                                  * reference samples (up to 4096).
26                                  */
27     int flags;
28
29     struct internal_state *state;
30 };
31
32 /* Sample data description flags */
33 #define AEC_DATA_UNSIGNED     0  /* Samples are unsigned integers (default) */
34 #define AEC_DATA_SIGNED       1  /* Samples are signed. Telling libaec
35                                   * this results in a slightly better
36                                   * compression ratio.
37                                   */
38 #define AEC_DATA_3BYTE        2  /* 24 bit samples are coded in 3 bytes */
39 #define AEC_DATA_MSB         16  /* Samples are stored with their most
40                                   * significant bit first. This has
41                                   * nothing to do with the endianness
42                                   * of the host.
43                                   */
44 #define AEC_DATA_LSB          0  /* Samples are stored LSB first (default) */
45 #define AEC_DATA_PREPROCESS  32  /* Set if preprocessor should be used */
46
47 /* Return codes of library functions */
48 #define AEC_OK            0
49 #define AEC_CONF_ERROR   (-1)
50 #define AEC_STREAM_ERROR (-2)
51 #define AEC_DATA_ERROR   (-3)
52 #define AEC_MEM_ERROR    (-4)
53
54 /* Options for flushing */
55 #define AEC_NO_FLUSH      0      /* Do not enforce output
56                                   * flushing. More input may be
57                                   * provided with later calls. So far
58                                   * only relevant for encoding.
59                                   */
60 #define AEC_FLUSH         1      /* Flush output and end encoding. The
61                                   * last call to aec_encode() must set
62                                   * AEC_FLUSH to drain all output.
63                                   *
64                                   * It is not possible to continue
65                                   * encoding of the same stream after it
66                                   * has been flushed because the last byte
67                                   * may be padded with fill bits.
68                                   */
69
70 /* Streaming encoding and decoding functions */
71 int aec_encode_init(struct aec_stream *strm);
72 int aec_encode(struct aec_stream *strm, int flush);
73 int aec_encode_end(struct aec_stream *strm);
74
75 int aec_decode_init(struct aec_stream *strm);
76 int aec_decode(struct aec_stream *strm, int flush);
77 int aec_decode_end(struct aec_stream *strm);
78
79 /* Utility functions for encoding or decoding a memory buffer. */
80 int aec_buffer_encode(struct aec_stream *strm);
81 int aec_buffer_decode(struct aec_stream *strm);
82
83 #endif /* LIBAEC_H */