Commit fca3dc1f authored by Mathis Rosenhauer's avatar Mathis Rosenhauer Committed by Thomas Jahns

Decoder: turn FSM switch into functions

parent ec53d5ad
lib_LTLIBRARIES = libaec.la libsz.la
libaec_la_SOURCES = encode.c encode_accessors.c decode.c encode.h \
encode_accessors.h
libaec_la_SOURCES = encode.c encode_accessors.c decode.c \
encode.h encode_accessors.h decode.h
libsz_la_SOURCES = sz_compat.c
libsz_la_LIBADD = libaec.la
......
This diff is collapsed.
#ifndef DECODE_H
#define DECODE_H
#include <config.h>
#if HAVE_STDINT_H
# include <stdint.h>
#endif
#include "libaec.h"
#define M_CONTINUE 1
#define M_EXIT 0
#define SAFE (strm->avail_in >= state->in_blklen \
&& strm->avail_out >= state->out_blklen)
#define ROS 5
#define MIN(a, b) (((a) < (b))? (a): (b))
struct internal_state {
int (*mode)(struct aec_stream *);
int id; /* option ID */
int id_len; /* bit length of code option identification key */
int (**id_table)(struct aec_stream *); /* table maps IDs to states */
void (*put_sample)(struct aec_stream *, int64_t);
int ref_int; /* reference sample is every ref_int samples */
int64_t last_out; /* previous output for post-processing */
int64_t xmin; /* minimum integer for post-processing */
int64_t xmax; /* maximum integer for post-processing */
int in_blklen; /* length of uncompressed input block
should be the longest possible block */
int out_blklen; /* length of output block in bytes */
int n, i; /* counter for samples */
int64_t *block; /* block buffer for split-sample options */
int se; /* set if second extension option is selected */
uint64_t acc; /* accumulator for currently used bit sequence */
int bitp; /* bit pointer to the next unused bit in accumulator */
int fs; /* last fundamental sequence in accumulator */
int ref; /* 1 if current block has reference sample */
int pp; /* 1 if postprocessor has to be used */
int byte_per_sample;
size_t samples_out;
} decode_state;
#endif /* DECODE_H */
......@@ -58,6 +58,93 @@ int update_state(struct test_state *state)
return 0;
}
int encode_decode_small(struct test_state *state)
{
int status, i, to, Bps;
struct aec_stream *strm = state->strm;
strm->avail_out = state->cbuf_len;
strm->next_out = state->cbuf;
status = aec_encode_init(strm);
if (status != AEC_OK) {
printf("Init failed.\n");
return 99;
}
Bps = strm->bit_per_sample / 8;
for (i = 0; i < state->ibuf_len / Bps; i++) {
strm->avail_in = Bps;
strm->next_in = state->ubuf + i * Bps;
status = aec_encode(strm, AEC_NO_FLUSH);
if (status != AEC_OK) {
printf("Encode failed.\n");
return 99;
}
}
status = aec_encode(strm, AEC_FLUSH);
if (status != AEC_OK) {
printf("Encode failed.\n");
return 99;
}
aec_encode_end(strm);
strm->avail_out = state->buf_len;
strm->next_out = state->obuf;
to = strm->total_out;
status = aec_decode_init(strm);
if (status != AEC_OK) {
printf("Init failed.\n");
return 99;
}
for (i = 0; i < to; i++) {
strm->avail_in = 1;
strm->next_in = state->cbuf + i;
status = aec_decode(strm, AEC_NO_FLUSH);
if (status != AEC_OK) {
printf("Decode failed.\n");
return 99;
}
}
status = aec_decode(strm, AEC_FLUSH);
if (status != AEC_OK) {
printf("Decode failed.\n");
return 99;
}
if (memcmp(state->ubuf, state->obuf, state->ibuf_len)) {
printf("FAIL: Uncompressed output differs from input.\n");
printf("\nuncompressed buf");
for (i = 0; i < 80; i++) {
if (i % 8 == 0)
printf("\n");
printf("%02x ", state->ubuf[i]);
}
printf("\n\ncompressed buf len %i", to);
for (i = 0; i < 80; i++) {
if (i % 8 == 0)
printf("\n");
printf("%02x ", state->cbuf[i]);
}
printf("\n\ndecompressed buf");
for (i = 0; i < 80; i++) {
if (i % 8 == 0)
printf("\n");
printf("%02x ", state->obuf[i]);
}
printf("\n");
return 99;
}
aec_decode_end(strm);
return 0;
}
int encode_decode(struct test_state *state)
{
int status, i, to;
......
......@@ -3,6 +3,7 @@
#include "libaec.h"
struct test_state {
int (* codec)(struct test_state *state);
int id_len;
int byte_per_sample;
unsigned char *ubuf;
......@@ -18,6 +19,7 @@ struct test_state {
};
int update_state(struct test_state *state);
int encode_decode_small(struct test_state *state);
int encode_decode(struct test_state *state);
......
......@@ -20,7 +20,7 @@ int check_block_sizes(struct test_state *state, int id, int id_len)
for (rsi = 1; rsi <= max_rsi; rsi++) {
state->strm->rsi = rsi;
status = encode_decode(state);
status = state->codec(state);
if (status)
return status;
......@@ -212,6 +212,7 @@ int main (void)
strm.flags = AEC_DATA_PREPROCESS;
state.strm = &strm;
state.codec = encode_decode_small;
printf("----------------------------\n");
printf("Checking LSB first, unsigned\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment