[xiph-commits] r11543 - in branches/vorbis-tahseen: include/vorbis lib

tahseen at svn.xiph.org tahseen at svn.xiph.org
Wed Jun 7 22:37:42 PDT 2006


Author: tahseen
Date: 2006-06-07 22:37:27 -0700 (Wed, 07 Jun 2006)
New Revision: 11543

Modified:
   branches/vorbis-tahseen/include/vorbis/vorbisfile.h
   branches/vorbis-tahseen/lib/vorbisfile.c
Log:
Priliminary skeleton support added. Allows limited access to vorbis stream
from other ogg streams like theora. Seems to break chaining and also binary
compatibility.


Modified: branches/vorbis-tahseen/include/vorbis/vorbisfile.h
===================================================================
--- branches/vorbis-tahseen/include/vorbis/vorbisfile.h	2006-06-08 05:27:41 UTC (rev 11542)
+++ branches/vorbis-tahseen/include/vorbis/vorbisfile.h	2006-06-08 05:37:27 UTC (rev 11543)
@@ -49,6 +49,11 @@
 #define  STREAMSET 3
 #define  INITSET   4
 
+typedef struct OggBitstreamInfo {
+	long serialno;		/* serialno of this logical bitstream */
+	char signature[8];	/* header signature of this logical bitstream, like 0x1vorbis */
+} OggBitstreamInfo;
+
 typedef struct OggVorbis_File {
   void            *datasource; /* Pointer to a FILE *, etc. */
   int              seekable;
@@ -84,8 +89,11 @@
 
   ov_callbacks callbacks;
 
+  OggBitstreamInfo *obi; /* holds information on all logical bitstream contained in the file */
+  int obilen;		/* holds the size of OggBitstreamInfo array */
 } OggVorbis_File;
 
+
 extern int ov_clear(OggVorbis_File *vf);
 extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
 extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,

Modified: branches/vorbis-tahseen/lib/vorbisfile.c
===================================================================
--- branches/vorbis-tahseen/lib/vorbisfile.c	2006-06-08 05:27:41 UTC (rev 11542)
+++ branches/vorbis-tahseen/lib/vorbisfile.c	2006-06-08 05:37:27 UTC (rev 11543)
@@ -230,7 +230,7 @@
 			  long *serialno,ogg_page *og_ptr){
   ogg_page og;
   ogg_packet op;
-  int i,ret;
+  int i,j,ret,skip;
   
   if(!og_ptr){
     ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
@@ -248,28 +248,58 @@
   
   vorbis_info_init(vi);
   vorbis_comment_init(vc);
+
   
   i=0;
   while(i<3){
     ogg_stream_pagein(&vf->os,og_ptr);
     while(i<3){
+      skip = 0;    
       int result=ogg_stream_packetout(&vf->os,&op);
       if(result==0)break;
       if(result==-1){
 	ret=OV_EBADHEADER;
 	goto bail_header;
       }
-      if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
-	goto bail_header;
+      /* trying to find OggBitstreamInfo (obi) has info on this stream. matching info on
+       * existing stream by using the serialno.
+       */
+      for(j = 0; j < vf->obilen; ++j) {
+	      if (vf->obi[j].serialno == ogg_page_serialno(og_ptr))
+		      break;
       }
-      i++;
+      /* IMPORTANT: shouldn't use variable j, the value is used later. */
+      if (j == vf->obilen) {
+	     /* haven't seen this logical stream before, adding it to the OggBitstreamInfo structure */ 
+	     if (j == 0) { 
+		     vf->obi = _ogg_calloc(1, sizeof(OggBitstreamInfo)); 
+	     } else {
+		     vf->obi = _ogg_realloc(vf->obi, (j+1)*sizeof(OggBitstreamInfo));
+	     }
+	     vf->obi[j].serialno = ogg_page_serialno(og_ptr);
+	     memcpy(vf->obi[j].signature, op.packet, 8);
+	     ++vf->obilen;
+      }
+      if(memcmp(op.packet+1,"vorbis",6)){
+	skip = 1;
+      } else {
+	++i;
+      }
+      if(skip == 0){
+	      if((ret=vorbis_synthesis_headerin(vi,vc,&op)))
+		goto bail_header;
+      }
     }
     if(i<3)
       if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
 	ret=OV_EBADHEADER;
 	goto bail_header;
       }
+    if (vf->os.serialno != ogg_page_serialno(og_ptr)) {
+	    ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
+    }
   }
+
   return 0; 
 
  bail_header:
@@ -293,7 +323,7 @@
   ogg_page og;
   int i;
   ogg_int64_t ret;
-  
+
   vf->vi=_ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
   vf->vc=_ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
   vf->dataoffsets=_ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
@@ -462,7 +492,16 @@
 				     int readp,
 				     int spanp){
   ogg_page og;
+  int i;
 
+  /* finding the serialno of the first vorbis stream. */
+  for (i = 0; i < vf->obilen; ++i) {
+	  if (!memcmp(vf->obi[i].signature+1, "vorbis", 6))
+		  break;
+  }
+  /* set the serialno of ogg_stream_state in OggVorbis_File */
+  vf->os.serialno=vf->obi[i].serialno;
+
   /* handle one packet.  Try to fetch it from current stream state */
   /* extract packets from page */
   while(1){
@@ -555,7 +594,11 @@
       
       /* has our decoding just traversed a bitstream boundary? */
       if(vf->ready_state==INITSET){
-	if(vf->current_serialno!=ogg_page_serialno(&og)){
+	if(vf->os.serialno!=ogg_page_serialno(&og)){
+	  /* found a packet we are not going to decode, its non-vorbis 
+	   * or not part of the first vorbis stream. so try getting the next page.
+	   */	
+	  goto try_next_page;
 	  if(!spanp)
 	    return(OV_EOF);
 
@@ -619,6 +662,7 @@
 	if(ret<0)return ret;
       }
     }
+    try_next_page:
     ogg_stream_pagein(&vf->os,&og);
   }
 }
@@ -634,7 +678,7 @@
 		     long ibytes, ov_callbacks callbacks){
   int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
   int ret;
-
+  
   memset(vf,0,sizeof(*vf));
   vf->datasource=f;
   vf->callbacks = callbacks;
@@ -710,6 +754,7 @@
     if(vf->offsets)_ogg_free(vf->offsets);
     ogg_sync_clear(&vf->oy);
     if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
+    if(vf->obi)_ogg_free(vf->obi);
     memset(vf,0,sizeof(*vf));
   }
 #ifdef DEBUG_LEAKS



More information about the commits mailing list