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 @@ ...@@ -12,8 +12,8 @@
#define M_CONTINUE 1 #define M_CONTINUE 1
#define M_EXIT 0 #define M_EXIT 0
#define SAFE (strm->avail_in >= state->in_blklen \ #define SAFE(strm) (strm->avail_in >= strm->state->in_blklen \
&& strm->avail_out >= state->out_blklen) && strm->avail_out >= strm->state->out_blklen)
#define ROS 5 #define ROS 5
#define MIN(a, b) (((a) < (b))? (a): (b)) #define MIN(a, b) (((a) < (b))? (a): (b))
...@@ -23,7 +23,7 @@ struct internal_state { ...@@ -23,7 +23,7 @@ struct internal_state {
int id; /* option ID */ int id; /* option ID */
int id_len; /* bit length of code option identification key */ int id_len; /* bit length of code option identification key */
int (**id_table)(struct aec_stream *); /* table maps IDs to states */ 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 */ int ref_int; /* reference sample is every ref_int samples */
int64_t last_out; /* previous output for post-processing */ int64_t last_out; /* previous output for post-processing */
int64_t xmin; /* minimum integer for post-processing */ int64_t xmin; /* minimum integer for post-processing */
...@@ -40,8 +40,12 @@ struct internal_state { ...@@ -40,8 +40,12 @@ struct internal_state {
int ref; /* 1 if current block has reference sample */ int ref; /* 1 if current block has reference sample */
int pp; /* 1 if postprocessor has to be used */ int pp; /* 1 if postprocessor has to be used */
int byte_per_sample; int byte_per_sample;
size_t samples_out;
int *se_table; 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; } decode_state;
#endif /* DECODE_H */ #endif /* DECODE_H */
...@@ -60,27 +60,51 @@ int update_state(struct test_state *state) ...@@ -60,27 +60,51 @@ int update_state(struct test_state *state)
int encode_decode_small(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; struct aec_stream *strm = state->strm;
strm->avail_out = state->cbuf_len;
strm->next_out = state->cbuf;
status = aec_encode_init(strm); status = aec_encode_init(strm);
if (status != AEC_OK) { if (status != AEC_OK) {
printf("Init failed.\n"); printf("Init failed.\n");
return 99; return 99;
} }
Bps = strm->bit_per_sample / 8; n_in = 0;
for (i = 0; i < state->ibuf_len / Bps; i++) { avail_in = 1;
strm->avail_in = Bps; avail_out = 1;
strm->next_in = state->ubuf + i * Bps; 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); status = aec_encode(strm, AEC_NO_FLUSH);
if (status != AEC_OK) { if (status != AEC_OK) {
printf("Encode failed.\n"); printf("Decode failed.\n");
return 99; 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); status = aec_encode(strm, AEC_FLUSH);
...@@ -91,9 +115,13 @@ int encode_decode_small(struct test_state *state) ...@@ -91,9 +115,13 @@ int encode_decode_small(struct test_state *state)
aec_encode_end(strm); 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; strm->next_out = state->obuf;
to = strm->total_out;
status = aec_decode_init(strm); status = aec_decode_init(strm);
if (status != AEC_OK) { if (status != AEC_OK) {
...@@ -101,14 +129,41 @@ int encode_decode_small(struct test_state *state) ...@@ -101,14 +129,41 @@ int encode_decode_small(struct test_state *state)
return 99; return 99;
} }
for (i = 0; i < to; i++) { n_in = 0;
strm->avail_in = 1; avail_in = 1;
strm->next_in = state->cbuf + i; 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); status = aec_decode(strm, AEC_NO_FLUSH);
if (status != AEC_OK) { if (status != AEC_OK) {
printf("Decode failed.\n"); printf("Decode failed.\n");
return 99; 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); status = aec_decode(strm, AEC_FLUSH);
...@@ -126,7 +181,7 @@ int encode_decode_small(struct test_state *state) ...@@ -126,7 +181,7 @@ int encode_decode_small(struct test_state *state)
printf("\n"); printf("\n");
printf("%02x ", state->ubuf[i]); 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++) { for (i = 0; i < 80; i++) {
if (i % 8 == 0) if (i % 8 == 0)
printf("\n"); printf("\n");
...@@ -135,7 +190,7 @@ int encode_decode_small(struct test_state *state) ...@@ -135,7 +190,7 @@ int encode_decode_small(struct test_state *state)
printf("\n\ndecompressed buf"); printf("\n\ndecompressed buf");
for (i = 0; i < 80; i++) { for (i = 0; i < 80; i++) {
if (i % 8 == 0) if (i % 8 == 0)
printf("\n"); printf("\n%04i ", i);
printf("%02x ", state->obuf[i]); printf("%02x ", state->obuf[i]);
} }
printf("\n"); printf("\n");
...@@ -145,7 +200,7 @@ int encode_decode_small(struct test_state *state) ...@@ -145,7 +200,7 @@ int encode_decode_small(struct test_state *state)
return 0; return 0;
} }
int encode_decode(struct test_state *state) int encode_decode_large(struct test_state *state)
{ {
int status, i, to; int status, i, to;
struct aec_stream *strm = state->strm; struct aec_stream *strm = state->strm;
......
...@@ -20,7 +20,7 @@ struct test_state { ...@@ -20,7 +20,7 @@ struct test_state {
int update_state(struct test_state *state); int update_state(struct test_state *state);
int encode_decode_small(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 */ #endif /* CHECK_AEC_H */
...@@ -15,7 +15,7 @@ int check_block_sizes(struct test_state *state) ...@@ -15,7 +15,7 @@ int check_block_sizes(struct test_state *state)
state->strm->block_size = bs; state->strm->block_size = bs;
state->strm->rsi = state->buf_len / (bs * state->byte_per_sample); state->strm->rsi = state->buf_len / (bs * state->byte_per_sample);
status = encode_decode(state); status = encode_decode_large(state);
if (status) if (status)
return status; return status;
} }
...@@ -32,7 +32,7 @@ int check_block_sizes_short(struct test_state *state) ...@@ -32,7 +32,7 @@ int check_block_sizes_short(struct test_state *state)
state->strm->block_size = bs; state->strm->block_size = bs;
state->strm->rsi = state->buf_len / (bs * state->byte_per_sample); state->strm->rsi = state->buf_len / (bs * state->byte_per_sample);
state->ibuf_len = state->buf_len - 2 * bs + 4; state->ibuf_len = state->buf_len - 2 * bs + 4;
status = encode_decode(state); status = encode_decode_large(state);
if (status) if (status)
return status; return status;
if (state->strm->total_out != state->buf_len) { 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