Vidur Apparao
2004-Oct-14 17:00 UTC
[Vorbis-dev] patch for non-seekable streams on Windows
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));
On Thu, Oct 14, 2004 at 04:59:34PM -0700, Vidur Apparao wrote:> > 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.Note that the line we're using is the authoritative/suggested technique straight from ANSI and Stevens (and more recently POSIX) for testing seekability. Windows getting it wrong is not surprising, but it's in violation of its conformance claims if that is true. I make that point only because blindly changing the line to work on Windows does not guarantee it will work properly on any other platform. We may need to #ifdef this; I'll consult my ANSI and POSIX refs tonight. Sigh. You'd think after thirty years of ANSI stdio, Win32 would get the simple stuff right.... Monty
On Thu, Oct 14, 2004 at 04:59:34PM -0700, Vidur Apparao wrote:> > 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.Oh, and I forgot to say: Thanks for tracking it down :-) Perhaps only some versions of windows have this bug? Monty
Dimitry Andric
2004-Oct-15 13:56 UTC
[Vorbis-dev] patch for non-seekable streams on Windows
On 2004-10-15 at 01:59:34 Vidur Apparao wrote:> 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.AFAIK, Windows sockets are not normal C/C++ file handles, in the sense that you can call read() and write() on them. You have to use recv() and send(). At least, this is the case with Microsoft Visual C++. Or are you testing this under Cygwin? -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 183 bytes Desc: not available Url : http://lists.xiph.org/pipermail/vorbis-dev/attachments/20041015/6fe57dce/attachment.pgp