Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/celt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTimothy B. Terriberry <tterribe@xiph.org>2010-12-21 19:42:26 +0300
committerJean-Marc Valin <jean-marc.valin@octasic.com>2010-12-21 22:23:45 +0300
commit30df6cf3f84c81eb0d3e6940670fda729e22d873 (patch)
tree030f19536685f9e262cfe8179080cd2fdd3c8a4c /tests
parent59858633fb4ffc5fe797e885be058e6270a32aef (diff)
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).
Diffstat (limited to 'tests')
-rw-r--r--tests/ectest.c21
1 files changed, 20 insertions, 1 deletions
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<sz;j++){
if (zeros)
data[j]=0;
else
data[j]=rand()%ft;
ec_enc_uint(&enc,data[j],ft);
+ tell[j+1]=ec_enc_tell(&enc, 3);
}
if (rand()%2==0)
while(ec_enc_tell(&enc, 0)%8 != 0)
ec_enc_uint(&enc, rand()%2, 2);
tell_bits = ec_enc_tell(&enc, 0);
ec_enc_done(&enc);
+ if(tell_bits!=ec_enc_tell(&enc,0)){
+ fprintf(stderr,"tell() changed after ec_enc_done(): %i instead of %i (Random seed: %u)\n",
+ ec_enc_tell(&enc,0),tell_bits,seed);
+ ret=-1;
+ }
if ((tell_bits+7)/8 < ec_byte_bytes(&buf))
{
fprintf (stderr, "tell() lied, there's %i bytes instead of %d (Random seed: %u)\n",
@@ -139,6 +148,11 @@ int main(int _argc,char **_argv){
tell_bits -= 8*ec_byte_bytes(&buf);
ec_byte_readinit(&buf,ptr,DATA_SIZE2);
ec_dec_init(&dec,&buf);
+ if(ec_dec_tell(&dec,3)!=tell[0]){
+ fprintf(stderr,
+ "Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n",
+ 0,ec_dec_tell(&dec,3),tell[0],seed);
+ }
for(j=0;j<sz;j++){
sym=ec_dec_uint(&dec,ft);
if(sym!=data[j]){
@@ -147,6 +161,11 @@ int main(int _argc,char **_argv){
sym,data[j],ft,j,sz,seed);
ret=-1;
}
+ if(ec_dec_tell(&dec,3)!=tell[j+1]){
+ fprintf(stderr,
+ "Tell mismatch between encoder and decoder at symbol %i: %i instead of %i (Random seed: %u).\n",
+ j+1,ec_dec_tell(&dec,3),tell[j+1],seed);
+ }
}
free(data);
}