proper truncated packet support
authorMonty <xiphmont@xiph.org>
Thu, 15 Jun 2000 09:18:34 +0000 (09:18 +0000)
committerMonty <xiphmont@xiph.org>
Thu, 15 Jun 2000 09:18:34 +0000 (09:18 +0000)
Monty

svn path=/trunk/vorbis/; revision=450

examples/decoder_example.c
examples/encoder_example.c
lib/floor0.c
lib/res0.c
lib/synthesis.c
todo.txt

index 4180b40..656bf80 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: simple example decoder
- last mod: $Id: decoder_example.c,v 1.8 2000/06/14 10:13:35 xiphmont Exp $
+ last mod: $Id: decoder_example.c,v 1.9 2000/06/15 09:18:34 xiphmont Exp $
 
  ********************************************************************/
 
@@ -210,8 +210,8 @@ int main(int argc, char **argv){
              double **pcm;
              int samples;
              
-             vorbis_synthesis(&vb,&op);
-             vorbis_synthesis_blockin(&vd,&vb);
+             if(vorbis_synthesis(&vb,&op)==0) /* test for success! */
+               vorbis_synthesis_blockin(&vd,&vb);
              /* 
                 
              **pcm is a multichannel double vector.  In stereo, for
index a2851bf..7963ce6 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: simple example encoder
- last mod: $Id: encoder_example.c,v 1.7 2000/05/12 08:38:20 msmith Exp $
+ last mod: $Id: encoder_example.c,v 1.8 2000/06/15 09:18:34 xiphmont Exp $
 
  ********************************************************************/
 
@@ -142,7 +142,7 @@ int main(){
 
       /* analysis */
       vorbis_analysis(&vb,&op);
-
+      
       /* weld the packet into the bitstream */
       ogg_stream_packetin(&os,&op);
 
index 1654ba4..0e1247f 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.15 2000/06/14 01:38:31 xiphmont Exp $
+ last mod: $Id: floor0.c,v 1.16 2000/06/15 09:18:34 xiphmont Exp $
 
  ********************************************************************/
 
@@ -417,31 +417,35 @@ static int inverse(vorbis_block *vb,vorbis_look_floor *i,double *out){
   int j,k;
   
   int ampraw=_oggpack_read(&vb->opb,info->ampbits);
-  if(ampraw>0){
+  if(ampraw>0){ /* also handles the -1 out of data case */
     long maxval=(1<<info->ampbits)-1;
     double amp=(float)ampraw/maxval*info->ampdB;
     int booknum=_oggpack_read(&vb->opb,_ilog(info->numbooks));
-    codebook *b=vb->vd->fullbooks+info->books[booknum];
-    double last=0.;
 
-    memset(out,0,sizeof(double)*look->m);    
-
-    for(j=0;j<look->m;j+=b->dim)
-      vorbis_book_decodevs(b,out+j,&vb->opb,1,-1);
-    for(j=0;j<look->m;){
-      for(k=0;k<b->dim;k++,j++)out[j]+=last;
-      last=out[j-1];
+    if(booknum!=-1){
+      codebook *b=vb->vd->fullbooks+info->books[booknum];
+      double last=0.;
+      
+      memset(out,0,sizeof(double)*look->m);    
+      
+      for(j=0;j<look->m;j+=b->dim)
+       if(vorbis_book_decodevs(b,out+j,&vb->opb,1,-1)==-1)goto eop;
+      for(j=0;j<look->m;){
+       for(k=0;k<b->dim;k++,j++)out[j]+=last;
+       last=out[j-1];
+      }
+      
+      /* take the coefficients back to a spectral envelope curve */
+      vorbis_lsp_to_lpc(out,out,look->m); 
+      _lpc_to_curve(out,out,amp,look,"",0);
+      
+      for(j=0;j<look->n;j++)out[j]= fromdB(out[j]-info->ampdB);
+      return(1);
     }
+  }
 
-    /* take the coefficients back to a spectral envelope curve */
-    vorbis_lsp_to_lpc(out,out,look->m); 
-    _lpc_to_curve(out,out,amp,look,"",0);
-
-    for(j=0;j<look->n;j++)out[j]= fromdB(out[j]-info->ampdB);
-    return(1);
-  }else
-    memset(out,0,sizeof(double)*look->n);
-
+ eop:
+  memset(out,0,sizeof(double)*look->n);
   return(0);
 }
 
index e821722..16eee10 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: residue backend 0 implementation
- last mod: $Id: res0.c,v 1.14 2000/06/14 08:19:22 xiphmont Exp $
+ last mod: $Id: res0.c,v 1.15 2000/06/15 09:18:34 xiphmont Exp $
 
  ********************************************************************/
 
@@ -217,7 +217,8 @@ static int _decodepart(oggpack_buffer *opb,double *work,double *vec, int n,
     int dim=books[j]->dim;
     int step=n/dim;
     for(i=0;i<step;i++)
-      vorbis_book_decodevs(books[j],work+i,opb,step,0);
+      if(vorbis_book_decodevs(books[j],work+i,opb,step,0)==-1)
+       return(-1);
   }
   
   for(i=0;i<n;i++)
@@ -303,8 +304,9 @@ int forward(vorbis_block *vb,vorbis_look_residue *vl,
   return(0);
 }
 
+/* a truncated packet here just means 'stop working'; it's not an error */
 int inverse(vorbis_block *vb,vorbis_look_residue *vl,double **in,int ch){
-  long i,j,k,l;
+  long i,j,k,l,transend=vb->pcmend/2;
   vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
   vorbis_info_residue0 *info=look->info;
 
@@ -319,24 +321,40 @@ int inverse(vorbis_block *vb,vorbis_look_residue *vl,double **in,int ch){
   double *work=alloca(sizeof(double)*samples_per_partition);
   partvals=partwords*partitions_per_word;
 
+  /* make sure we're zeroed up to the start */
+  for(j=0;j<ch;j++)
+    memset(in[j],0,sizeof(double)*info->begin);
+
   for(i=info->begin,l=0;i<info->end;){
     /* fetch the partition word for each channel */
     for(j=0;j<ch;j++){
       int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
+      if(temp==-1)goto eopbreak;
       partword[j]=look->decodemap[temp];
-      if(partword[j]==NULL)exit(1);
+      if(partword[j]==NULL)goto errout;
     }
     
     /* now we decode interleaved residual values for the partitions */
     for(k=0;k<partitions_per_word;k++,l++,i+=samples_per_partition)
       for(j=0;j<ch;j++){
        int part=partword[j][k];
-       _decodepart(&vb->opb,work,in[j]+i,samples_per_partition,
+       if(_decodepart(&vb->opb,work,in[j]+i,samples_per_partition,
                    info->secondstages[part],
-                   look->partbooks[part]);
+                      look->partbooks[part])==-1)goto eopbreak;
       }
   }
 
+ eopbreak:
+  if(i<transend){
+    for(j=0;j<ch;j++)
+      memset(in[j]+i,0,sizeof(double)*(transend-i));
+  }
+
+  return(0);
+
+ errout:
+  for(j=0;j<ch;j++)
+    memset(in[j],0,sizeof(double)*transend);
   return(0);
 }
 
index 031d6cd..7812149 100644 (file)
@@ -12,7 +12,7 @@
  ********************************************************************
 
  function: single-block PCM synthesis
- last mod: $Id: synthesis.c,v 1.15 2000/02/12 08:33:10 xiphmont Exp $
+ last mod: $Id: synthesis.c,v 1.16 2000/06/15 09:18:34 xiphmont Exp $
 
  ********************************************************************/
 
@@ -27,7 +27,7 @@ int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
   vorbis_info      *vi=vd->vi;
   oggpack_buffer   *opb=&vb->opb;
   int              type,mode,i;
-
   /* first things first.  Make sure decode is ready */
   _vorbis_block_ripcord(vb);
   _oggpack_readinit(opb,op->packet,op->bytes);
@@ -40,11 +40,14 @@ int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
 
   /* read our mode and pre/post windowsize */
   mode=_oggpack_read(opb,vd->modebits);
+  if(mode==-1)return(-1);
+  
   vb->mode=mode;
   vb->W=vi->mode_param[mode]->blockflag;
   if(vb->W){
     vb->lW=_oggpack_read(opb,1);
     vb->nW=_oggpack_read(opb,1);
+    if(vb->nW==-1)   return(-1);
   }else{
     vb->lW=0;
     vb->nW=0;
index 2dbbf1e..bb90db9 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -2,9 +2,6 @@ Development hit list for 1.0:
 
 libvorbis:
 
-libvorbis isn't doing the 'how much data in the last frame' trick from
-the PCM counter/last page flag.
-
 Implement correct truncated packet handling; this is mostly a case of
 'intiialize vectors and check return values' in res0.c:inverse (but
 not entirely)
@@ -14,6 +11,10 @@ Meaningful error code returns
 Option for brute-forcing vq search on maptype 2 (helps on undertrained
 sets).
 
+vorbisfile instantaneous bitrate info
+
+encoder switch interface for binary compat through changes; ioctl()-like?
+
 API changes: 
   break up some of the more monolithic calls (eg, allow access
        to MDCT domain data, additional low level framing capability)
@@ -22,3 +23,4 @@ API changes:
 other:
 
 command line suite
+'crashme'
\ No newline at end of file