Commit 51bf2653 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer Committed by Thomas Jahns

buffer output and filter in one go

parent 874139b8
This diff is collapsed.
......@@ -12,8 +12,8 @@
#define M_CONTINUE 1
#define M_EXIT 0
#define SAFE (strm->avail_in >= state->in_blklen \
&& strm->avail_out >= state->out_blklen)
#define SAFE(strm) (strm->avail_in >= strm->state->in_blklen \
&& strm->avail_out >= strm->state->out_blklen)
#define ROS 5
#define MIN(a, b) (((a) < (b))? (a): (b))
......@@ -23,7 +23,7 @@ struct internal_state {
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);
void (*flush_output)(struct aec_stream *);
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 */
......@@ -40,8 +40,12 @@ struct internal_state {
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;
int *se_table;
uint32_t *buf_out;
uint32_t buf_next_out;
uint32_t buf_size;
uint32_t flush_start;
uint32_t flush_end;
} decode_state;
#endif /* DECODE_H */
......@@ -60,27 +60,51 @@ int update_state(struct test_state *state)
int encode_decode_small(struct test_state *state)
{
int status, i, to, Bps;
int status, i, compressed_size;
int n_in, avail_in, avail_out, total_out;
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;
n_in = 0;
avail_in = 1;
avail_out = 1;
total_out = 0;
strm->next_in = state->ubuf;
strm->avail_in = state->byte_per_sample;
strm->avail_out = 1;
strm->next_out = state->cbuf;
while ((avail_in || avail_out) && total_out < state->cbuf_len) {
if (strm->avail_in == 0 && avail_in) {
n_in += state->byte_per_sample;
if (n_in < state->buf_len) {
strm->avail_in = state->byte_per_sample;
strm->next_in = state->ubuf + n_in;
} else {
avail_in = 0;
}
}
status = aec_encode(strm, AEC_NO_FLUSH);
if (status != AEC_OK) {
printf("Encode failed.\n");
printf("Decode failed.\n");
return 99;
}
if (strm->total_out - total_out > 0
&& total_out < state->cbuf_len) {
total_out = strm->total_out;
strm->avail_out = 1;
strm->next_out = state->cbuf + total_out;
avail_out = 1;
} else {
avail_out = 0;
}
}
status = aec_encode(strm, AEC_FLUSH);
......@@ -91,9 +115,13 @@ int encode_decode_small(struct test_state *state)
aec_encode_end(strm);
strm->avail_out = state->buf_len;
compressed_size = strm->total_out;
strm->avail_in = 1;
strm->next_in = state->cbuf;
strm->avail_out = state->byte_per_sample;
strm->next_out = state->obuf;
to = strm->total_out;
status = aec_decode_init(strm);
if (status != AEC_OK) {
......@@ -101,14 +129,41 @@ int encode_decode_small(struct test_state *state)
return 99;
}
for (i = 0; i < to; i++) {
strm->avail_in = 1;
strm->next_in = state->cbuf + i;
n_in = 0;
avail_in = 1;
avail_out = 1;
total_out = 0;
strm->next_in = state->cbuf;
strm->avail_in = 1;
strm->avail_out = state->byte_per_sample;
strm->next_out = state->obuf;
while ((avail_in || avail_out) && total_out < state->buf_len) {
if (strm->avail_in == 0 && avail_in) {
n_in++;
if (n_in < compressed_size) {
strm->avail_in = 1;
strm->next_in = state->cbuf + n_in;
} else {
avail_in = 0;
}
}
status = aec_decode(strm, AEC_NO_FLUSH);
if (status != AEC_OK) {
printf("Decode failed.\n");
return 99;
}
if (strm->total_out - total_out > 0
&& total_out < state->buf_len) {
total_out = strm->total_out;
strm->avail_out = state->byte_per_sample;
strm->next_out = state->obuf + total_out;
avail_out = 1;
} else {
avail_out = 0;
}
}
status = aec_decode(strm, AEC_FLUSH);
......@@ -126,7 +181,7 @@ int encode_decode_small(struct test_state *state)
printf("\n");
printf("%02x ", state->ubuf[i]);
}
printf("\n\ncompressed buf len %i", to);
printf("\n\ncompressed buf len %i", compressed_size);
for (i = 0; i < 80; i++) {
if (i % 8 == 0)
printf("\n");
......@@ -135,7 +190,7 @@ int encode_decode_small(struct test_state *state)
printf("\n\ndecompressed buf");
for (i = 0; i < 80; i++) {
if (i % 8 == 0)
printf("\n");
printf("\n%04i ", i);
printf("%02x ", state->obuf[i]);
}
printf("\n");
......@@ -145,7 +200,7 @@ int encode_decode_small(struct test_state *state)
return 0;
}
int encode_decode(struct test_state *state)
int encode_decode_large(struct test_state *state)
{
int status, i, to;
struct aec_stream *strm = state->strm;
......
......@@ -20,7 +20,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);
int encode_decode_large(struct test_state *state);
#endif /* CHECK_AEC_H */
......@@ -15,7 +15,7 @@ int check_block_sizes(struct test_state *state)
state->strm->block_size = bs;
state->strm->rsi = state->buf_len / (bs * state->byte_per_sample);
status = encode_decode(state);
status = encode_decode_large(state);
if (status)
return status;
}
......@@ -32,7 +32,7 @@ int check_block_sizes_short(struct test_state *state)
state->strm->block_size = bs;
state->strm->rsi = state->buf_len / (bs * state->byte_per_sample);
state->ibuf_len = state->buf_len - 2 * bs + 4;
status = encode_decode(state);
status = encode_decode_large(state);
if (status)
return status;
if (state->strm->total_out != state->buf_len) {
......
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