vorbisfile - function - ov_open

vorbisfile documentation | vorbisfile version 1.25 - 20000615

# ov_open

declared in "vorbis/vorbisfile.h";

This is the main function used to open and initialize an OggVorbis_File structure. It sets up all the related decoding structure.

The first argument must be a file pointer to an already opened file or pipe (it need not be seekable--though this obviously restricts what can be done with the bitstream). `vf` should be a pointer to the OggVorbis_File structure--this is used for ALL the externally visible vorbisfile functions. Once this has been called, the same OggVorbis_File struct should be passed to all the vorbisfile functions.

Also, you should be aware that ov_open(), once successful, takes complete possession of the file resource. After you have opened a file using ov_open(), you MUST close it using ov_clear(), not fclose() or any other function.

It is often useful to call `ov_open()` simply to determine whether a given file is a vorbis bitstream. If the `ov_open()` call fails, then the file is not recognizable as such. When you use `ov_open()` for this, you should `fclose()` the file pointer if, and only if, the `ov_open()` call fails. If it succeeds, you must call ov_clear() to clear the decoder's buffers and close the file for you.

    int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);

### Parameters

f
  File pointer to an already opened file or pipe (it need not be seekable--though this obviously restricts what can be done with the bitstream).
vf
  A pointer to the OggVorbis_File structure--this is used for ALL the externally visible vorbisfile functions. Once this has been called, the same `OggVorbis_File` struct should be passed to all the vorbisfile functions.
initial
  Typically set to NULL. This parameter is useful if some data has already been read from the file and the stream is not seekable. It is used in conjunction with `ibytes`. In this case, `initial` should be a pointer to a buffer containing the data read.
ibytes
  Typically set to 0. This parameter is useful if some data has already been read from the file and the stream is not seekable. In this case, `ibytes` should contain the length (in bytes) of the buffer. Used together with `initial`

### Return Values

> - 0 for success
> - less than zero for failure:
> - OV_EREAD - A read from media returned an error.
> - OV_ENOTVORBIS - Bitstream is not Vorbis data.
> - OV_EVERSION - Vorbis version mismatch.
> - OV_EBADHEADER - Invalid Vorbis bitstream header.
> - OV_EFAULT - Internal logic fault; indicates a bug or heap/stack corruption.

### Notes

If your decoder is threaded, it is recommended that you NOT call `ov_open()` in the main control thread--instead, call `ov_open()` IN your decode/playback thread. This is important because `ov_open()` may be a fairly time-consuming call, given that the full structure of the file is determined at this point, which may require reading large parts of the file under certain circumstances (determining all the logical bitstreams in one physical bitstream, for example).

copyright © 2000 vorbis team | Ogg Vorbis team@vorbis.org
vorbisfile documentation | vorbisfile version 1.25 - 20000615