Michael Smith
2000-Apr-21 03:35 UTC
[vorbis-dev] vorbisfile updates, and a couple of questions
The changes to vorbisfile that I suggested earlier have now been committed - this is mostly a merge of my code with a similar patch from Martin Vogt (thanks Martin). The old ov_open() interface remains untouched - and for many people, this is all you'll need to use, ever. It now calls the new interface with appropriate arguments. The new ov_open_callbacks() function adds an extra argument to ov_open() - a struct of callback functions, which basically follow the stdio functions. They do have one difference, however - the FILE * arguments have been changed to void *, so that the user can pass arbitrary data to the functions. This allows easy use of non-stdio-based vorbisfile. Yay! If you want to use this new functionality: look at the ov_callbacks struct in vorbisfile.h, then create appropriate functions, and continue... The functions you write should follow their stdio counterparts in terms of return values as closely as possible. Most importantly, seek_func() MUST return -1 if the stream is unseekable. In this case, tell_func() isn't going to be used, but be consistent and implement it - it might get used in the future. If you can't give a result, return -1 from this too. When I get around to it, I'll convert the winamp plugin over to use normal windows functions instead of stdio, mostly as an example of how to use the new interface. If anyone has any questions before I get to this, please DO ask. Martin - I also applied the kmpg patch you sent to Monty, but I had to change some things to match the modified vorbisfile interface - please check that it works and send me another patch if it's broken. Additionally, I added appropriate c++ incantations to the header files, so that you can use vorbisfile from c++ (thanks to Martin for this, too). Now, onto the questions: Firstly, I've seen xmms lock up under the following circumstances: play track, wait until it's right near the end (<< 1 second remaining), then try and seek. All of xmms locks hard. It looks like either vorbis_ip.output->flush() or ov_time_seek() aren't returning, but I haven't looked further yet. If anyone else can confirm this, and/or has a fix, let me know. Secondly, ov_open() now uses the new interface internally. It creates a struct consisting of fread, fseek, fclose, and ftell, then passes that appropriately. This all works fine, but the compiler complains, because the ov_callbacks functions take a void * in the place of the FILE *. Since they're otherwise identical, this works - but I can't figure out how to cast the arguments appropriately so as to shut the compiler up. Casting function pointers appears to be a rather arcane sort of thing to do. Anyone with more C clues than I care to speak up? Michael --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/
Jonathan Blow
2000-Apr-21 05:15 UTC
[vorbis-dev] vorbisfile updates, and a couple of questions
> Casting function pointers appears > to be a rather arcane sort of thing to do. Anyone with more C clues than I > care to speak up?The syntax for that has got to be hairy... what I would do is make typedefs for both types, and then cast one to the other. So... typedef void (*stdio_func)(FILE *file1, FILE *file2); typedef void (*voidp_func)(void *pointer1, void *pointer2); voidp_func uncasted = /* get this however you get it */; stdio_func casted = (stdio_func)uncasted; casted((FILE *)argument1, (FILE *)argument2); I may have gotten that slightly wrong, but hey. Now if the compiler doesn't let you do that, you'll have to do something more nasty but I think that should work. -J. --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/
> Firstly, I've seen xmms lock up under the following circumstances: play > track, wait until it's right near the end (<< 1 second remaining), then try and > seek. All of xmms locks hard. > It looks like either vorbis_ip.output->flush() or ov_time_seek() aren't > returning, but I haven't looked further yet. If anyone else can confirm this, > and/or has a fix, let me know.If you can construct a test case that causes a vorbisfile function not to return, I'll debug this. When you say all of xmms... you mean UI threads too? That would suggest "not vorbisfile", but that's a guess. (can you make vorbisfile not return by adding read to the end then seek in examples/seeking_test?) Monty --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/
Greg Stark
2000-Apr-22 13:27 UTC
[vorbis-dev] Re: vorbisfile updates, and a couple of questions
Jonathan Blow <jon@bolt-action.com> writes:> > Casting function pointers appears > > to be a rather arcane sort of thing to do. Anyone with more C clues than I > > care to speak up? > > The syntax for that has got to be hairy... what I would do is make typedefs > for both types, and then cast one to the other. So...You might be better off keeping this simpler: typedef int (*vorbis_callback)(void *closure, vorbis_op *op); int my_read_callback(void *closure, vorbis_op *op) { FILE *input = (FILE*)closure; assert(op->operation == VORBIS_READ); ... } int my_write_callback(void *closure, vorbis_op *op) { ... This means you can't just pass fread et al as callbacks, but it avoids having hairy casts and different callbacks depending on whether the closure is a FILE* or an opaque object. It does have one major disadvantage, you can't add stuff to the vorbis_op structure without invalidating old code, which is annoying. -- greg --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/