diff options
author | Mathis Rosenhauer <rosenhauer@dkrz.de> | 2012-11-05 16:28:20 +0100 |
---|---|---|
committer | Thomas Jahns <jahns@dkrz.de> | 2013-02-19 11:33:00 +0100 |
commit | 51bf26530fb205a4ced83a38854378d9ca8fb2b3 (patch) | |
tree | d4ed1f88708d67c49a53d58e99de90453f10c060 /tests | |
parent | 874139b80f06659e3c46c8e84aaade290328a33a (diff) | |
download | libaec-51bf26530fb205a4ced83a38854378d9ca8fb2b3.tar.gz libaec-51bf26530fb205a4ced83a38854378d9ca8fb2b3.tar.bz2 libaec-51bf26530fb205a4ced83a38854378d9ca8fb2b3.zip |
buffer output and filter in one go
Diffstat (limited to 'tests')
-rw-r--r-- | tests/check_aec.c | 89 | ||||
-rw-r--r-- | tests/check_aec.h | 2 | ||||
-rw-r--r-- | tests/check_buffer_sizes.c | 4 |
3 files changed, 75 insertions, 20 deletions
diff --git a/tests/check_aec.c b/tests/check_aec.c index c7ce581..d54c6e8 100644 --- a/tests/check_aec.c +++ b/tests/check_aec.c @@ -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; diff --git a/tests/check_aec.h b/tests/check_aec.h index 8b9847a..2ee231f 100644 --- a/tests/check_aec.h +++ b/tests/check_aec.h @@ -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 */ diff --git a/tests/check_buffer_sizes.c b/tests/check_buffer_sizes.c index 9db3808..4da4816 100644 --- a/tests/check_buffer_sizes.c +++ b/tests/check_buffer_sizes.c @@ -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) { |