From 30df6cf3f84c81eb0d3e6940670fda729e22d873 Mon Sep 17 00:00:00 2001 From: "Timothy B. Terriberry" Date: Tue, 21 Dec 2010 08:42:26 -0800 Subject: Entropy coder clean-up. This simplifies a good bit of the error handling, and should make it impossible to overrun the buffer in the encoder or decoder, while still allowing tell() to operate correctly after a bust. The encoder now tries to keep the range coder data intact after a bust instead of corrupting it with extra bits data, though this is not a guarantee (too many extra bits may have already been flushed). It also now correctly reports errors when the bust occurs merging the last byte of range coder and extra bits. A number of abstraction barrier violations were cleaned up, as well. This patch also includes a number of minor performance improvements: ec_{enc|dec}_bits() in particular should be much faster. Finally, tf_select was changed to be coded with the range coder rather than extra bits, so that it is at the front of the packet (for unequal error protection robustness). --- tests/ectest.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/ectest.c b/tests/ectest.c index 76c3f4e..eebab32 100644 --- a/tests/ectest.c +++ b/tests/ectest.c @@ -77,7 +77,7 @@ int main(int _argc,char **_argv){ fprintf(stderr, "Encoded %0.2lf bits of entropy to %0.2lf bits (%0.3lf%% wasted).\n", entropy,ldexp(nbits,-4),100*(nbits-ldexp(entropy,4))/nbits); - fprintf(stderr,"Packed to %li bytes.\n",(long)(buf.ptr-buf.buf)); + fprintf(stderr,"Packed to %li bytes.\n",(long)ec_byte_bytes(&buf)); ec_byte_readinit(&buf,ptr,DATA_SIZE); ec_dec_init(&dec,&buf); for(ft=2;ft<1024;ft++){ @@ -109,27 +109,36 @@ int main(int _argc,char **_argv){ fprintf(stderr,"Testing random streams... Random seed: %u (%.4X)\n", seed, rand() % 65536); for(i=0;i<409600;i++){ unsigned *data; + unsigned *tell; int j; int tell_bits; int zeros; ft=rand()/((RAND_MAX>>(rand()%11))+1)+10; sz=rand()/((RAND_MAX>>(rand()%9))+1); data=(unsigned *)malloc(sz*sizeof(*data)); + tell=(unsigned *)malloc((sz+1)*sizeof(*tell)); ec_byte_writeinit_buffer(&buf, ptr, DATA_SIZE2); ec_enc_init(&enc,&buf); zeros = rand()%13==0; + tell[0]=ec_enc_tell(&enc, 3); for(j=0;j