[Vorbis-dev] patch for non-seekable streams on Windows

Vidur Apparao vidur at slimdevices.com
Thu Oct 14 16:59:34 PDT 2004


I've been trying to get oggdec to work with input streamed in through a 
pipe or a socket. This seems to work on Linux and OS X, but not on 
Windows. I've found that code in vorbisfile.c tests the input stream for 
seekability by invoking fseek in the following way:

  int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR) : -1);

Unfortunately, fseek succeeds for a socket on Windows (even though it's 
not seekable) with the parameters specified. A more definitive test (and 
one that does work on Windows) is to attempt to seek to the end. I've 
attached a patch to vorbisfile.c that fixes my problem.


-------------- next part --------------
Index: vorbisfile.c
===================================================================
--- vorbisfile.c	(revision 8002)
+++ vorbisfile.c	(working copy)
@@ -632,7 +632,7 @@
 
 static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
 		     long ibytes, ov_callbacks callbacks){
-  int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
+  int offsettest=(f?callbacks.seek_func(f,0,SEEK_END):-1);
   int ret;
 
   memset(vf,0,sizeof(*vf));
@@ -655,7 +655,10 @@
   /* can we seek? Stevens suggests the seek test was portable */
   if(offsettest!=-1)vf->seekable=1;
 
-  /* No seeking yet; Set up a 'single' (current) logical bitstream
+  /* seek to the beginning follwing the test */
+  if (vf->seekable) callbacks.seek_func(f,0,SEEK_SET);
+
+  /* Set up a 'single' (current) logical bitstream
      entry for partial open */
   vf->links=1;
   vf->vi=_ogg_calloc(vf->links,sizeof(*vf->vi));


More information about the Vorbis-dev mailing list