6 static void out_lsb(unsigned char *dest, unsigned long long int val, int size)
10 for (i = 0; i < size; i++)
11 dest[i] = (unsigned char)(val >> (8 * i));
14 static void out_msb(unsigned char *dest, unsigned long long int val, int size)
18 for (i = 0; i < size; i++)
19 dest[i] = (unsigned char)(val >> (8 * (size - 1 - i)));
22 int update_state(struct test_state *state)
24 struct aec_stream *strm = state->strm;
26 if (strm->bits_per_sample > 16) {
29 if (strm->bits_per_sample <= 24 && strm->flags & AEC_DATA_3BYTE) {
30 state->bytes_per_sample = 3;
32 state->bytes_per_sample = 4;
35 else if (strm->bits_per_sample > 8) {
37 state->bytes_per_sample = 2;
40 state->bytes_per_sample = 1;
43 if (strm->flags & AEC_DATA_MSB)
48 if (strm->flags & AEC_DATA_SIGNED) {
49 state->xmin = -(1LL << (strm->bits_per_sample - 1));
50 state->xmax = (1ULL << (strm->bits_per_sample - 1)) - 1;
53 state->xmax = (1ULL << strm->bits_per_sample) - 1;
59 int encode_decode_small(struct test_state *state)
62 size_t compressed_size;
63 size_t n_in, avail_in, avail_out, total_out;
64 struct aec_stream *strm = state->strm;
66 status = aec_encode_init(strm);
67 if (status != AEC_OK) {
68 printf("Init failed.\n");
76 strm->next_in = state->ubuf;
77 strm->avail_in = state->bytes_per_sample;
79 strm->next_out = state->cbuf;
81 while ((avail_in || avail_out) && total_out < state->cbuf_len) {
82 if (strm->avail_in == 0 && avail_in) {
83 n_in += state->bytes_per_sample;
84 if (n_in < state->buf_len) {
85 strm->avail_in = state->bytes_per_sample;
86 strm->next_in = state->ubuf + n_in;
92 status = aec_encode(strm, AEC_NO_FLUSH);
93 if (status != AEC_OK) {
94 printf("Decode failed.\n");
98 if (strm->total_out - total_out > 0
99 && total_out < state->cbuf_len) {
100 total_out = strm->total_out;
102 strm->next_out = state->cbuf + total_out;
109 status = aec_encode(strm, AEC_FLUSH);
110 if (status != AEC_OK) {
111 printf("Encode failed.\n");
115 aec_encode_end(strm);
117 compressed_size = strm->total_out;
120 strm->next_in = state->cbuf;
122 strm->avail_out = state->bytes_per_sample;
123 strm->next_out = state->obuf;
125 status = aec_decode_init(strm);
126 if (status != AEC_OK) {
127 printf("Init failed.\n");
135 strm->next_in = state->cbuf;
137 strm->avail_out = state->bytes_per_sample;
138 strm->next_out = state->obuf;
140 while ((avail_in || avail_out) && total_out < state->buf_len) {
141 if (strm->avail_in == 0 && avail_in) {
143 if (n_in < compressed_size) {
145 strm->next_in = state->cbuf + n_in;
151 status = aec_decode(strm, AEC_NO_FLUSH);
152 if (status != AEC_OK) {
153 printf("Decode failed.\n");
157 if (strm->total_out - total_out > 0
158 && total_out < state->buf_len) {
159 total_out = strm->total_out;
160 strm->avail_out = state->bytes_per_sample;
161 strm->next_out = state->obuf + total_out;
168 status = aec_decode(strm, AEC_FLUSH);
169 if (status != AEC_OK) {
170 printf("Decode failed.\n");
174 if (memcmp(state->ubuf, state->obuf, state->ibuf_len)) {
175 printf("\n%s: Uncompressed output differs from input.\n", CHECK_FAIL);
177 printf("\nuncompressed buf");
178 for (i = 0; i < 80; i++) {
181 printf("%02x ", state->ubuf[i]);
183 printf("\n\ncompressed buf len %li", compressed_size);
184 for (i = 0; i < 80; i++) {
187 printf("%02x ", state->cbuf[i]);
189 printf("\n\ndecompressed buf");
190 for (i = 0; i < 80; i++) {
192 printf("\n%04i ", i);
193 printf("%02x ", state->obuf[i]);
198 aec_decode_end(strm);
202 int encode_decode_large(struct test_state *state)
206 struct aec_stream *strm = state->strm;
208 strm->avail_in = state->ibuf_len;
209 strm->avail_out = state->cbuf_len;
210 strm->next_in = state->ubuf;
211 strm->next_out = state->cbuf;
213 status = aec_encode_init(strm);
214 if (status != AEC_OK) {
215 printf("Init failed.\n");
219 status = aec_encode(strm, AEC_FLUSH);
220 if (status != AEC_OK) {
221 printf("Encode failed.\n");
225 aec_encode_end(strm);
227 strm->avail_in = strm->total_out;
228 strm->avail_out = state->buf_len;
229 strm->next_in = state->cbuf;
230 strm->next_out = state->obuf;
231 to = strm->total_out;
233 status = aec_decode_init(strm);
234 if (status != AEC_OK) {
235 printf("Init failed.\n");
239 status = aec_decode(strm, AEC_FLUSH);
240 if (status != AEC_OK) {
241 printf("Decode failed.\n");
245 if (memcmp(state->ubuf, state->obuf, state->ibuf_len)) {
246 printf("\n%s: Uncompressed output differs from input.\n", CHECK_FAIL);
248 printf("\nuncompressed buf");
249 for (i = 0; i < 80; i++) {
252 printf("%02x ", state->ubuf[i]);
254 printf("\n\ncompressed buf len %li", to);
255 for (i = 0; i < 80; i++) {
258 printf("%02x ", state->cbuf[i]);
260 printf("\n\ndecompressed buf");
261 for (i = 0; i < 80; i++) {
264 printf("%02x ", state->obuf[i]);
269 aec_decode_end(strm);