[xiph-commits] r13183 - branches/lowmem-no-byte/Tremor

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sat Jun 23 02:14:45 PDT 2007


Author: xiphmont
Date: 2007-06-23 02:14:45 -0700 (Sat, 23 Jun 2007)
New Revision: 13183

Modified:
   branches/lowmem-no-byte/Tremor/codebook.c
   branches/lowmem-no-byte/Tremor/floor1.c
   branches/lowmem-no-byte/Tremor/misc.c
   branches/lowmem-no-byte/Tremor/misc.h
   branches/lowmem-no-byte/Tremor/res012.c
Log:
Fix bug #340 for no-byte branch

fix several examples of speculative codebook read not forcing eop when running out of bits

Increase debugging mallog head alignment to work by default on 64 bit systems.




Modified: branches/lowmem-no-byte/Tremor/codebook.c
===================================================================
--- branches/lowmem-no-byte/Tremor/codebook.c	2007-06-23 08:50:50 UTC (rev 13182)
+++ branches/lowmem-no-byte/Tremor/codebook.c	2007-06-23 09:14:45 UTC (rev 13183)
@@ -98,6 +98,12 @@
 /* choose the smallest supported node size that fits our decode table.
    Legal bytewidths are 1/1 1/2 2/2 2/4 4/4 */
 static int _determine_node_bytes(long used, int leafwidth){
+
+  /* special case small books to size 4 to avoid multiple special
+     cases in repack */
+  if(used<2)
+    return 4;
+
   if(leafwidth==3)leafwidth=4;
   if(_ilog(3*used-6)+1 <= leafwidth*4) 
     return leafwidth/2?leafwidth/2:1;
@@ -183,14 +189,19 @@
 			      oggpack_buffer *opb,int maptype){
   int i;
   ogg_uint32_t *work;
-  if(s->dec_nodeb==4)
-    work=s->dec_table=_ogg_malloc((s->used_entries*2-2)*4);
-  else
-    work=alloca((s->used_entries*2-2)*sizeof(*work));
 
+  if(s->dec_nodeb==4){
+    s->dec_table=_ogg_malloc((s->used_entries*2+1)*sizeof(*work));
+    /* +1 (rather than -2) is to accommodate 0 and 1 sized books,
+       which are specialcased to nodeb==4 */
+    if(_make_words(lengthlist,s->entries,
+		   s->dec_table,quantvals,s,opb,maptype))return 1;
+    
+    return 0;
+  }
+
+  work=alloca((s->used_entries*2-2)*sizeof(*work));
   if(_make_words(lengthlist,s->entries,work,quantvals,s,opb,maptype))return 1;
-  if(s->dec_nodeb==4) return 0;
-
   s->dec_table=_ogg_malloc((s->used_entries*(s->dec_leafw+1)-2)*
 			   s->dec_nodeb);
     
@@ -544,8 +555,12 @@
   
   while(lok<0 && read>1)
     lok = oggpack_look(b, --read);
-  if(lok<0)return -1;
 
+  if(lok<0){
+    oggpack_adv(b,1); /* force eop */
+    return -1;
+  }
+
   /* chase the tree with the bits we got */
   if(book->dec_nodeb==1){
     if(book->dec_leafw==1){
@@ -616,7 +631,7 @@
     oggpack_adv(b,i+1);
     return chase;
   }
-  oggpack_adv(b,read);
+  oggpack_adv(b,read+1);
   return(-1);
 }
 
@@ -698,41 +713,53 @@
 /* returns 0 on OK or -1 on eof *************************************/
 long vorbis_book_decodevs_add(codebook *book,ogg_int32_t *a,
 			      oggpack_buffer *b,int n,int point){
-  int step=n/book->dim;
-  ogg_int32_t *v = (ogg_int32_t *)alloca(sizeof(*v)*book->dim);
-  int i,j,o;
-
-  for (j=0;j<step;j++){
-    if(decode_map(book,b,v,point))return -1;
-    for(i=0,o=j;i<book->dim;i++,o+=step)
-      a[o]+=v[i];
+  if(book->used_entries>0){
+    int step=n/book->dim;
+    ogg_int32_t *v = (ogg_int32_t *)alloca(sizeof(*v)*book->dim);
+    int i,j,o;
+    
+    for (j=0;j<step;j++){
+      if(decode_map(book,b,v,point))return -1;
+      for(i=0,o=j;i<book->dim;i++,o+=step)
+	a[o]+=v[i];
+    }
   }
   return 0;
 }
 
 long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a,
 			     oggpack_buffer *b,int n,int point){
-  ogg_int32_t *v = (ogg_int32_t *)alloca(sizeof(*v)*book->dim);
-  int i,j;
-  
-  for(i=0;i<n;){
-    if(decode_map(book,b,v,point))return -1;
-    for (j=0;j<book->dim;j++)
-      a[i++]+=v[j];
+  if(book->used_entries>0){
+    ogg_int32_t *v = (ogg_int32_t *)alloca(sizeof(*v)*book->dim);
+    int i,j;
+    
+    for(i=0;i<n;){
+      if(decode_map(book,b,v,point))return -1;
+      for (j=0;j<book->dim;j++)
+	a[i++]+=v[j];
+    }
   }
-  
   return 0;
 }
 
 long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a,
 			     oggpack_buffer *b,int n,int point){
-  ogg_int32_t *v = (ogg_int32_t *)alloca(sizeof(*v)*book->dim);
-  int i,j;
-
-  for(i=0;i<n;){
-    if(decode_map(book,b,v,point))return -1;
-    for (j=0;j<book->dim;j++)
-      a[i++]=v[j];
+  if(book->used_entries>0){
+    ogg_int32_t *v = (ogg_int32_t *)alloca(sizeof(*v)*book->dim);
+    int i,j;
+    
+    for(i=0;i<n;){
+      if(decode_map(book,b,v,point))return -1;
+      for (j=0;j<book->dim;j++)
+	a[i++]=v[j];
+    }
+  }else{
+    int i,j;
+    
+    for(i=0;i<n;){
+      for (j=0;j<book->dim;j++)
+	a[i++]=0;
+    }
   }
 
   return 0;
@@ -742,20 +769,21 @@
 			      long offset,int ch,
 			      oggpack_buffer *b,int n,int point){
 
-  ogg_int32_t *v = (ogg_int32_t *)alloca(sizeof(*v)*book->dim);
-  long i,j;
-  int chptr=0;
+  if(book->used_entries>0){
+    ogg_int32_t *v = (ogg_int32_t *)alloca(sizeof(*v)*book->dim);
+    long i,j;
+    int chptr=0;
     
-  for(i=offset;i<offset+n;){
-    if(decode_map(book,b,v,point))return -1;
-    for (j=0;j<book->dim;j++){
-      a[chptr++][i]+=v[j];
-      if(chptr==ch){
-	chptr=0;
-	i++;
+    for(i=offset;i<offset+n;){
+      if(decode_map(book,b,v,point))return -1;
+      for (j=0;j<book->dim;j++){
+	a[chptr++][i]+=v[j];
+	if(chptr==ch){
+	  chptr=0;
+	  i++;
+	}
       }
     }
   }
-  
   return 0;
 }

Modified: branches/lowmem-no-byte/Tremor/floor1.c
===================================================================
--- branches/lowmem-no-byte/Tremor/floor1.c	2007-06-23 08:50:50 UTC (rev 13182)
+++ branches/lowmem-no-byte/Tremor/floor1.c	2007-06-23 09:14:45 UTC (rev 13183)
@@ -81,6 +81,8 @@
     if(oggpack_eop(opb)<0) goto err_out;
     if(info->class[j].class_subs)
       info->class[j].class_book=oggpack_read(opb,8);
+    else
+      info->class[j].class_book=0;
     if(info->class[j].class_book>=ci->books)goto err_out;
     for(k=0;k<(1<<info->class[j].class_subs);k++){
       info->class[j].class_subbook[k]=oggpack_read(opb,8)-1;

Modified: branches/lowmem-no-byte/Tremor/misc.c
===================================================================
--- branches/lowmem-no-byte/Tremor/misc.c	2007-06-23 08:50:50 UTC (rev 13182)
+++ branches/lowmem-no-byte/Tremor/misc.c	2007-06-23 09:14:45 UTC (rev 13183)
@@ -10,7 +10,7 @@
  *                                                                  *
  ********************************************************************/
 
-#define HEAD_ALIGN 32
+#define HEAD_ALIGN 64
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -187,6 +187,7 @@
 }
 
 extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line){
+  if(bytes<0) abort();
   bytes+=HEAD_ALIGN;
   if(ptr){
     ptr-=HEAD_ALIGN;

Modified: branches/lowmem-no-byte/Tremor/misc.h
===================================================================
--- branches/lowmem-no-byte/Tremor/misc.h	2007-06-23 08:50:50 UTC (rev 13182)
+++ branches/lowmem-no-byte/Tremor/misc.h	2007-06-23 09:14:45 UTC (rev 13183)
@@ -20,7 +20,6 @@
 #include "ivorbiscodec.h"
 #include "os_types.h"
 
-
 /*#define _VDBG_GRAPHFILE "_0.m"*/
 
 #ifdef _VDBG_GRAPHFILE

Modified: branches/lowmem-no-byte/Tremor/res012.c
===================================================================
--- branches/lowmem-no-byte/Tremor/res012.c	2007-06-23 08:50:50 UTC (rev 13182)
+++ branches/lowmem-no-byte/Tremor/res012.c	2007-06-23 09:14:45 UTC (rev 13183)
@@ -199,7 +199,7 @@
 	    
 	    /* fetch the partition word */
 	    temp=vorbis_book_decode(phrasebook,&vd->opb);
-	    if(oggpack_eop(&vd->opb))goto eopbreak;
+	    if(temp==-1)goto eopbreak;
 	    
 	    /* this can be done quickly in assembly due to the quotient
 	       always being at most six bits */
@@ -211,7 +211,7 @@
 	  }
 	  
 	  /* now we decode residual values for the partitions */
-	  for(k=0;k<partitions_per_word && i<partvals;k++,i++)
+	  for(k=0;k<partitions_per_word && i<partvals;k++,i++){
 	    if(info->stagemasks[partword[i]]&(1<<s)){
 	      codebook *stagebook=ci->book_param+
 		info->stagebooks[(partword[i]<<3)+s];
@@ -221,6 +221,7 @@
 					  samples_per_partition,-8)==-1)
 		goto eopbreak;
 	    }
+	  }
 	}
       } 
     }



More information about the commits mailing list