[vorbis] Using vorbisfile with an in-memory file instead of FILE*

Monty xiphmont at xiph.org
Mon Jan 1 12:31:23 PST 2001



> > This doesn't change the fact that this isn't how vorbisfile is meant to be
> > used, and doing it this way isn't terribly sensible.

Eh, ignore Mike here.  Vorbisfile is not the most efficient way to
handle an in-memory file, but it's sensible to do it this way if you
don't want to get dragged into maintaining seperate code for doing
files.  Vorbisfile is designed to be able to do this via the
callbacks.  It should work just fine.

> As I've said in another posts, the callbacks are done and the function is
> working ok at this point.
> I just thought you would like to be interested to hear about this, as it's
> not completely ok.

int ogg_test() 
      { 
       int error = 0; 
       FILE* g = fopen("c:/temp/bp.ogg", "rb"); 
       fseek(g, 0, SEEK_END); 
       int cb_d = ftell(g); 
       rewind(g); 
       char* d = new char[cb_d]; 
       fread(d, 1, cb_d, g); 
       fclose(g); 
       FILE* f = tmpfile(); 
       OggVorbis_File vf; 
       if (!f) 
        error = 1; 
       else 
       { 
        if (ov_open(f, &vf, d, cb_d) < 0) 

Ah, OK, *this* is not kosher actually.  You can get away with stuffing
the whole file into cb_d *only* if the 'file' is to be ov_opened
non-seekable.  The temp file is seekable, and thus ov_open's design
constraint is violated.  I'm putting "make this very explicit" note on
my docs to-do list.

Really, just write callbacks to simulate file access on the in-memory
buffer and this will work.  It will even be reasonably efficient.

Monty

--- >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 at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis mailing list