[xiph-commits] r13214 - trunk/vorbis/lib

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue Jul 3 14:31:53 PDT 2007


Author: xiphmont
Date: 2007-07-03 14:31:52 -0700 (Tue, 03 Jul 2007)
New Revision: 13214

Modified:
   trunk/vorbis/lib/vorbisfile.c
Log:
Multiplex support fixes; basic functions test OK on single stream files 
now, time to test chains and multiplexing.



Modified: trunk/vorbis/lib/vorbisfile.c
===================================================================
--- trunk/vorbis/lib/vorbisfile.c	2007-07-03 08:59:28 UTC (rev 13213)
+++ trunk/vorbis/lib/vorbisfile.c	2007-07-03 21:31:52 UTC (rev 13214)
@@ -278,7 +278,6 @@
     if(searched>=end || next_serialnos==0){
       vf->links=m+1;
       vf->offsets=_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
-      vf->serialnos=_ogg_malloc(vf->links*sizeof(*vf->serialnos));
       vf->offsets[m+1]=searched;
     }else{
       ret=_bisect_forward_serialno(vf,next,vf->offset,
@@ -326,14 +325,9 @@
     ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
     ogg_stream_pagein(&vf->os,og_ptr);
 
-    /* look for Vorbis ID header */
-    {
-      if(ogg_stream_packetout(&vf->os,&op) <= 0)
-	break; /* an error, yes, but try again */
+    if(ogg_stream_packetout(&vf->os,&op) > 0 &&
+       vorbis_synthesis_idheader(&op)){
 
-      if(!vorbis_synthesis_idheader(&op))
-	break; /* not a vorbis ID header; keep looking */
-
       /* continue Vorbis header load; past this point, any error will
 	 render this link useless (we won't continue looking for more
 	 Vorbis streams */
@@ -385,9 +379,16 @@
 	  /* otherwise, keep looking */
 	}
       }
+
+      return 0; 
     }
-    return 0; 
-  
+
+    /* this wasn't vorbis, get next page, try again */
+    {
+      ogg_int64_t llret=_get_next_page(vf,og_ptr,CHUNKSIZE);
+      if(llret==OV_EREAD)return(OV_EREAD);
+      if(llret<0)return(OV_ENOTVORBIS);
+    } 
   }
 
  bail_header:
@@ -414,12 +415,14 @@
 
   vf->vi=_ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
   vf->vc=_ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
+  vf->serialnos=_ogg_malloc(vf->links*sizeof(*vf->serialnos));
   vf->dataoffsets=_ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
   vf->pcmlengths=_ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
   
   for(i=0;i<vf->links;i++){
     if(i==0){
       /* we already grabbed the initial header earlier.  Just set the offset */
+      vf->serialnos[i]=vf->current_serialno;
       vf->dataoffsets[i]=dataoffset;
       ret=_seek_helper(vf,dataoffset);
       if(ret)
@@ -459,8 +462,10 @@
              truncated/mangled */
 	  break;
        
+	if(ogg_page_bos(&og)) break;
+
 	if(ogg_page_serialno(&og)!=vf->serialnos[i])
-	  break;
+	  continue;
 	
 	/* count blocksizes of all frames in the page */
 	ogg_stream_pagein(&vf->os,&og);
@@ -506,6 +511,9 @@
 	    vorbis_comment_clear(vf->vc+i);
 	    break;
 	  }
+	  if(ogg_page_serialno(&og)!=vf->serialnos[i])
+	    continue;
+
 	  if(ogg_page_granulepos(&og)!=-1){
 	    vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
 	    break;
@@ -539,6 +547,7 @@
   long *serialno_list=NULL;
   int serialnos=0;
   int ret;
+  ogg_page og;
 
   /* we're partially open and have a first link header state in
      storage in vf */
@@ -549,8 +558,13 @@
   /* If seek_func is implemented, tell_func must also be implemented */
   if(vf->end==-1) return(OV_EINVAL);
 
+  /* We get the offset for the last page of the physical bitstream.
+     Most OggVorbis files will contain a single logical bitstream */
+  end=_get_prev_page(vf,&og);
+  if(end<0)return(end);
+
   /* back to beginning, learn all serialnos of first link */
-  ret=ov_raw_seek(vf,0);
+  ret=_seek_helper(vf,0);
   if(ret)return(ret);
   ret=_get_serialnos(vf,&serialno_list,&serialnos);
   if(ret)return(ret);
@@ -1196,25 +1210,35 @@
       }
       
       /* has our decoding just traversed a bitstream boundary? */
-      if(vf->ready_state>=STREAMSET)
+      if(vf->ready_state>=STREAMSET){
 	if(vf->current_serialno!=ogg_page_serialno(&og)){
-	  _decode_clear(vf); /* clear out stream state */
-	  ogg_stream_clear(&work_os);
+	  
+	  /* two possibilities: 
+	     1) our decoding just traversed a bitstream boundary
+	     2) another stream is multiplexed into this logical section? */
+            
+	  if(ogg_page_bos(&og)){
+	    /* we traversed */
+	    _decode_clear(vf); /* clear out stream state */
+	    ogg_stream_clear(&work_os);
+	  } /* else, do nothing; next loop will scoop another page */
 	}
+      }
 
       if(vf->ready_state<STREAMSET){
 	int link;
-	
-	vf->current_serialno=ogg_page_serialno(&og);
+	long serialno = ogg_page_serialno(&og);
+
 	for(link=0;link<vf->links;link++)
-	  if(vf->serialnos[link]==vf->current_serialno)break;
-	if(link==vf->links)goto seek_error; /* sign of a bogus stream.
-					       error out, leave
-					       machine uninitialized */
+	  if(vf->serialnos[link]==serialno)break;
+
+	if(link==vf->links) continue; /* not the desired Vorbis
+					 bitstream section; keep
+					 trying */
 	vf->current_link=link;
-	
-	ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
-	ogg_stream_reset_serialno(&work_os,vf->current_serialno); 
+	vf->current_serialno=serialno;
+	ogg_stream_reset_serialno(&vf->os,serialno);
+	ogg_stream_reset_serialno(&work_os,serialno); 
 	vf->ready_state=STREAMSET;
 	
       }



More information about the commits mailing list