Commit 5c932b03 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Faster decoding if buffer space available

parent d991d495
...@@ -13,9 +13,12 @@ clean: ...@@ -13,9 +13,12 @@ clean:
rm -f mytest ../data/ae_out $(objects) rm -f mytest ../data/ae_out $(objects)
test: mytest test: mytest
./mytest < ../data/example_data.szip > ../data/ae_out ./mytest 1 1 < ../data/example_data.szip > ../data/ae_out
diff ../data/ae_out ../data/example_data
./mytest 9478 16384 < ../data/example_data.szip > ../data/ae_out
diff ../data/ae_out ../data/example_data diff ../data/ae_out ../data/example_data
vtest: mytest vtest: mytest
valgrind -v ./mytest < example_data.szip > ae_out valgrind -v ./mytest < ../data/example_data.szip > ../data/ae_out
diff ae_out example_data diff ../data/ae_out ../data/example_data
...@@ -7,7 +7,7 @@ struct internal_state; ...@@ -7,7 +7,7 @@ struct internal_state;
typedef struct _ae_stream typedef struct _ae_stream
{ {
uint8_t *next_in; const uint8_t *next_in;
size_t avail_in; /* number of bytes available at next_in */ size_t avail_in; /* number of bytes available at next_in */
size_t total_in; /* total number of input bytes read so far */ size_t total_in; /* total number of input bytes read so far */
...@@ -15,12 +15,12 @@ typedef struct _ae_stream ...@@ -15,12 +15,12 @@ typedef struct _ae_stream
size_t avail_out; /* remaining free space at next_out */ size_t avail_out; /* remaining free space at next_out */
size_t total_out; /* total number of bytes output so far */ size_t total_out; /* total number of bytes output so far */
uint32_t bit_per_sample; /* resolution in bits per sample (n = 1,..., 32) */ uint32_t bit_per_sample; /* resolution in bits per sample (n = 1,..., 32) */
uint32_t block_size; /* block size in samples (J = 8 or 16) */ uint32_t block_size; /* block size in samples (J = 8 or 16) */
uint32_t segment_size; /* set of blocks between consecutive reference samples */ uint32_t segment_size; /* set of blocks between consecutive reference samples */
uint8_t pp; /* pre/post-processor used? */ uint8_t pp; /* pre/post-processor used? */
struct internal_state *state; struct internal_state *state;
} ae_stream; } ae_stream;
typedef ae_stream *ae_streamp; typedef ae_stream *ae_streamp;
......
This diff is collapsed.
...@@ -10,74 +10,85 @@ ...@@ -10,74 +10,85 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
ae_stream strm; ae_stream strm;
int c, i, n, status, todo; int c, i, n, status, todo;
uint8_t *in; uint8_t *in;
uint32_t *out; uint32_t *out;
size_t total_out; size_t total_out;
int chunk_in, chunk_out;
in = (uint8_t *)malloc(ALL_IN); chunk_in = CHUNK_IN;
out = (uint32_t *)malloc(CHUNK_OUT * sizeof(uint32_t)); chunk_out = CHUNK_OUT;
if (in == NULL || out == NULL)
return 1; if (argc == 3)
{
chunk_in = atoi(argv[1]);
chunk_out = atoi(argv[2]);
}
n = 0; fprintf(stderr, "chunk_in: %i\nchunk_out: %i\n", chunk_in, chunk_out);
while ((c = getc(stdin)) != EOF) in = (uint8_t *)malloc(ALL_IN);
{ out = (uint32_t *)malloc(chunk_out * sizeof(uint32_t));
*in++ = c; if (in == NULL || out == NULL)
n++; return 1;
}
in -= n;
strm.bit_per_sample = 8; n = 0;
strm.block_size = 8; while ((c = getc(stdin)) != EOF)
strm.segment_size = 2; {
strm.pp = 1; *in++ = c;
n++;
}
in -= n;
if (ae_decode_init(&strm) != AE_OK) strm.bit_per_sample = 8;
return 1; strm.block_size = 8;
strm.segment_size = 2;
strm.next_in = in; strm.pp = 1;
strm.avail_in = CHUNK_IN;
strm.next_out = out;
strm.avail_out = CHUNK_OUT;
todo = 1;
total_out = 0;
while(todo)
{
todo = 0;
if ((status = ae_decode(&strm, 0)) != AE_OK)
{
fprintf(stderr, "error is %i\n", status);
return 1;
}
fprintf(stderr, "avail in %li total in %li avail out %li total out %lx\n", strm.avail_in, strm.total_in, strm.avail_out, strm.total_out);
if (strm.avail_in == 0 && strm.total_in < ALL_IN) if (ae_decode_init(&strm) != AE_OK)
{ return 1;
in += CHUNK_IN;
strm.next_in = in;
strm.avail_in = chunk_in;
strm.next_out = out;
strm.avail_out = chunk_out;
todo = 1;
total_out = 0;
while(todo)
{
todo = 0;
if ((status = ae_decode(&strm, 0)) != AE_OK)
{
fprintf(stderr, "error is %i\n", status);
return 1;
}
// fprintf(stderr, "avail in %li total in %li avail out %li total out %lx\n", strm.avail_in, strm.total_in, strm.avail_out, strm.total_out);
strm.next_in = in; if (strm.avail_in == 0 && strm.total_in < ALL_IN)
if (ALL_IN - strm.total_in < CHUNK_IN) {
strm.avail_in = ALL_IN - strm.total_in; in += chunk_in;
else
strm.avail_in = CHUNK_IN;
todo = 1;
}
if (strm.total_out - total_out > 0) strm.next_in = in;
{ if (ALL_IN - strm.total_in < chunk_in)
for (i=0; i < strm.total_out - total_out; i++) strm.avail_in = ALL_IN - strm.total_in;
{ else
putc(out[i], stdout); strm.avail_in = chunk_in;
} todo = 1;
total_out = strm.total_out; }
strm.next_out = out;
strm.avail_out = CHUNK_OUT;
todo = 1;
}
}
return 0; if (strm.total_out - total_out > 0)
{
for (i=0; i < strm.total_out - total_out; i++)
{
putc(out[i], stdout);
}
total_out = strm.total_out;
strm.next_out = out;
strm.avail_out = chunk_out;
todo = 1;
}
}
return 0;
} }
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