Andre Krause
2004-Apr-21 12:01 UTC
[vorbis] Streaming ogg from filepointer pointing to archive of many oggs. Ogg stream does not stop after end of one ogg file - what to do ?
Hello, I'm currently trying to implement streaming off ogg-files out of an archive file using SDL and SDL_mixer for playback. Therefore i create a FILE * filepointer, place it to the beginning of an ogg file inside the archive and hand over the filepointer to ov_open. ( command: ov_open(fp, &music->vf, NULL, 0) ). This works fine so far. The problem is: if i put many oggs together in one archive, the playback stops only after the last ogg file. Why is this a problem ? Suppose i want to play the ogg files in random order. The playback must end after the current ogg, so the user can select a random new ogg file, place the filepointer to it and play the ogg. So is there a method to determine when one ogg file ended and the other begins ? Current code looks like this: /* Load an OGG stream from the given file pointer */ OGG_music *OGG_new(FILE *fp) { OGG_music *music;int xx; music = (OGG_music *)malloc(sizeof *music); if ( music ) { /* Initialize the music structure */ memset(music, 0, (sizeof *music)); OGG_stop(music); OGG_setvolume(music, MIX_MAX_VOLUME); music->section = -1; if ( ov_open(fp, &music->vf, NULL, 0) < 0 ) { SDL_SetError("Not an Ogg Vorbis audio stream"); free(music); return(NULL); ..... <p>And playing the ogg: /* Read some Ogg stream data and convert it for output */ static void OGG_getsome(OGG_music *music) { int section; int len; char data[4096]; SDL_AudioCVT *cvt; len = ov_read(&music->vf, data, sizeof(data), 0, 2, 1, §ion); if ( len <= 0 ) { if ( len == 0 ) { music->playing = 0; } return; } ..... <p><p>Any idea please ? Thanks, andre <p><p><p>_________________________________________ Andre Krause Dipl. Inform. Department of Biological Cybernetics Faculty of Biology University of Bielefeld PO Box 10 01 31 33501 Bielefeld Germany Phone: +49-521-106-5519 Mobil: +49-177-7465055 Home : +49-521-3044776 Email: post@andre-krause.net ICQ# : 68306404 More ways to contact me: http://wwp.icq.com/68306404 Homepage: http://www.andre-krause.net http://www.andre-krause.de _________________________________________ War isn't politics, my dear. It is indeed he only human activity that is rottener than politics. RexStout _________________________________________ --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Andre Krause
2004-Apr-21 12:46 UTC
[vorbis] Streaming ogg from filepointer pointing to archive of many oggs. Ogg stream does not stop after end of one ogg file - what to do ?
Hello, I'm currently trying to implement streaming off ogg-files out of an archive file using SDL and SDL_mixer for playback. Therefore i create a FILE * filepointer, place it to the beginning of an ogg file inside the archive and hand over the filepointer to ov_open. ( command: ov_open(fp, &music->vf, NULL, 0) ). This works fine so far. The problem is: if i put many oggs together in one archive, the playback stops only after the last ogg file. Why is this a problem ? Suppose i want to play the ogg files in random order. The playback must end after the current ogg, so the user can select a random new ogg file, place the filepointer to it and play the ogg. So is there a method to determine when one ogg file ended and the other begins ? Current code looks like this: /* Load an OGG stream from the given file pointer */ OGG_music *OGG_new(FILE *fp) { OGG_music *music;int xx; music = (OGG_music *)malloc(sizeof *music); if ( music ) { /* Initialize the music structure */ memset(music, 0, (sizeof *music)); OGG_stop(music); OGG_setvolume(music, MIX_MAX_VOLUME); music->section = -1; if ( ov_open(fp, &music->vf, NULL, 0) < 0 ) { SDL_SetError("Not an Ogg Vorbis audio stream"); free(music); return(NULL); ..... <p>And playing the ogg: /* Read some Ogg stream data and convert it for output */ static void OGG_getsome(OGG_music *music) { int section; int len; char data[4096]; SDL_AudioCVT *cvt; len = ov_read(&music->vf, data, sizeof(data), 0, 2, 1, §ion); if ( len <= 0 ) { if ( len == 0 ) { music->playing = 0; } return; } ..... <p><p>Any idea please ? Thanks, andre <p><p><p>_________________________________________ Andre Krause Dipl. Inform. Department of Biological Cybernetics Faculty of Biology University of Bielefeld PO Box 10 01 31 33501 Bielefeld Germany Phone: +49-521-106-5519 Mobil: +49-177-7465055 Home : +49-521-3044776 Email: post@andre-krause.net ICQ# : 68306404 More ways to contact me: http://wwp.icq.com/68306404 Homepage: http://www.andre-krause.net http://www.andre-krause.de _________________________________________ War isn't politics, my dear. It is indeed he only human activity that is rottener than politics. RexStout _________________________________________ --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Ralph Giles
2004-Apr-21 12:54 UTC
[vorbis] Streaming ogg from filepointer pointing to archive of many oggs. Ogg stream does not stop after end of one ogg file - what to do ?
On Wed, Apr 21, 2004 at 09:01:31PM +0200, Andre Krause wrote:> I'm currently trying to implement streaming off ogg-files out of an archive > file using SDL and SDL_mixer for playback. Therefore i create a FILE * > filepointer, place it to the beginning of an ogg file inside the archive and > hand over the filepointer to ov_open. ( command: ov_open(fp, &music->vf, > NULL, 0) ). This works fine so far. The problem is: if i put many oggs > together in one archive, the playback stops only after the last ogg file. > Why is this a problem ? Suppose i want to play the ogg files in random > order. The playback must end after the current ogg, so the user can select a > random new ogg file, place the filepointer to it and play the ogg.The ogg vorbis libraries are written to 'do their best' when presented with corrupt data streams. Likely what's happening is that after reaching the end of the whatever segment you've started playback of, it just scans ahead and continues playing with the next valid ogg vorbis data it finds, and so on until EOF.> So is there a method to determine when one ogg file ended and the other > begins ?This information is available from the vorbisfile internals (the ogg layer reports the gaps and segment changes). However, in an application where you've packed multiple independent files together in a wrapper, the best approach is probably to use the vorbisfile callback interface to just unwrap and hand it the data for the segment you want to play. HTH, -r --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Michael Smith
2004-Apr-21 18:25 UTC
[vorbis] Streaming ogg from filepointer pointing to archive of many oggs. Ogg stream does not stop after end of one ogg file - what to do ?
On Thursday 22 April 2004 05:01, Andre Krause wrote:> Hello, > I'm currently trying to implement streaming off ogg-files out of an archive > file using SDL and SDL_mixer for playback. Therefore i create a FILE * > filepointer, place it to the beginning of an ogg file inside the archive > and hand over the filepointer to ov_open. ( command: ov_open(fp, > &music->vf, NULL, 0) ). This works fine so far. The problem is: if i put > many oggs together in one archive, the playback stops only after the last > ogg file. Why is this a problem ? Suppose i want to play the ogg files in > random order. The playback must end after the current ogg, so the user can > select a random new ogg file, place the filepointer to it and play the ogg. > > So is there a method to determine when one ogg file ended and the other > begins ? >There are two ways you can do this: 1) Check the 'section' variable after each call to ov_read(). If it has changed, then you've moved to a new ogg stream. 2) Use ov_open_callbacks() rather than ov_open(), and provide appropriate callbacks. The close callback can just do nothing (because you probably want to keep it open for playing some other file from the archive. The seek/tell/read callbacks should be simple wrappers, they just have to take into account the offset from the start of the archive that the individual file starts/ends. You'll want to return EOF appropriately from the read callback when you get to the end. I'd recommend option 2. Mike --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.