[xiph-commits] r14413 - trunk/ghost/libentcode

jm at svn.xiph.org jm at svn.xiph.org
Thu Jan 17 20:24:11 PST 2008


Author: jm
Date: 2008-01-17 20:24:09 -0800 (Thu, 17 Jan 2008)
New Revision: 14413

Modified:
   trunk/ghost/libentcode/mfrngdec.c
   trunk/ghost/libentcode/rangedec.c
Log:
Reverted some of Timothy's changes to the range decoding that were causing
decode random decode problems at the end of the stream (but only once in a
while).


Modified: trunk/ghost/libentcode/mfrngdec.c
===================================================================
--- trunk/ghost/libentcode/mfrngdec.c	2008-01-18 02:07:42 UTC (rev 14412)
+++ trunk/ghost/libentcode/mfrngdec.c	2008-01-18 04:24:09 UTC (rev 14413)
@@ -137,24 +137,26 @@
   int ret;
   ret=ec_byte_read1(_this->buf);
   if(ret<0){
-    long bytes;
+    unsigned char *buf;
+    long           bytes;
     bytes=ec_byte_bytes(_this->buf);
+    buf=ec_byte_get_buffer(_this->buf);
     /*Breaking abstraction: don't do this at home, kids.*/
-    if(_this->buf->storage==bytes&&bytes>0){
-      unsigned char *buf;
-      buf=ec_byte_get_buffer(_this->buf);
-      /*If we end in a string of 0 or more EC_FOF_RSV1 bytes preceded by a
-         zero, return an extra EC_FOF_RSV1 byte.*/
-      do bytes--;
-      while(bytes>0&&buf[bytes]==EC_FOF_RSV1);
-      if(!buf[bytes])ret=EC_FOF_RSV1;
+    if(_this->buf->storage==bytes){
+      ec_byte_adv1(_this->buf);
+      if(bytes>0){
+        unsigned char *p;
+        p=buf+bytes;
+        /*If we end in a string of 0 or more EC_FOF_RSV1 bytes preceded by a
+           zero, return an extra EC_FOF_RSV1 byte.*/
+        do p--;
+        while(p>buf&&p[0]==EC_FOF_RSV1);
+        if(!p[0])return EC_FOF_RSV1;
+      }
     }
-    else ret=0;
-    /*Needed to make sure the above conditional only triggers once, and to keep
-       oc_dec_tell() operating correctly.*/
-    ec_byte_adv1(_this->buf);
+    return 0;
   }
-  return ret;
+  else return ret;
 }
 
 /*Normalizes the contents of dif and rng so that rng lies entirely in the

Modified: trunk/ghost/libentcode/rangedec.c
===================================================================
--- trunk/ghost/libentcode/rangedec.c	2008-01-18 02:07:42 UTC (rev 14412)
+++ trunk/ghost/libentcode/rangedec.c	2008-01-18 04:24:09 UTC (rev 14413)
@@ -120,24 +120,26 @@
   int ret;
   ret=ec_byte_read1(_this->buf);
   if(ret<0){
-    long bytes;
+    unsigned char *buf;
+    long           bytes;
     bytes=ec_byte_bytes(_this->buf);
+    buf=ec_byte_get_buffer(_this->buf);
     /*Breaking abstraction: don't do this at home, kids.*/
-    if(_this->buf->storage==bytes&&bytes>0){
-      unsigned char *buf;
-      buf=ec_byte_get_buffer(_this->buf);
-      /*If we end in a string of 0 or more EC_FOF_RSV1 bytes preceded by a
-         zero, return an extra EC_FOF_RSV1 byte.*/
-      do bytes--;
-      while(bytes>0&&buf[bytes]==EC_FOF_RSV1);
-      if(!buf[bytes])ret=EC_FOF_RSV1;
+    if(_this->buf->storage==bytes){
+      ec_byte_adv1(_this->buf);
+      if(bytes>0){
+        unsigned char *p;
+        p=buf+bytes;
+        /*If we end in a string of 0 or more EC_FOF_RSV1 bytes preceded by a
+           zero, return an extra EC_FOF_RSV1 byte.*/
+        do p--;
+        while(p>buf&&p[0]==EC_FOF_RSV1);
+        if(!p[0])return EC_FOF_RSV1;
+      }
     }
-    else ret=0;
-    /*Needed to make sure the above conditional only triggers once, and to keep
-       oc_dec_tell() operating correctly.*/
-    ec_byte_adv1(_this->buf);
+    return 0;
   }
-  return ret;
+  else return ret;
 }
 
 /*Normalizes the contents of dif and rng so that rng lies entirely in the



More information about the commits mailing list