Vorbisfile - function - ov_open

Vorbisfile documentation | vorbisfile version 1.3.2 - 20101101

# ov_open

declared in "vorbis/vorbisfile.h";

ov_open is one of three initialization functions used to initialize an OggVorbis_File structure and prepare a bitstream for playback.

WARNING for Windows developers: Do not use ov_open() in Windows applications; Windows linking places restrictions on passing `FILE *` handles successfully, and ov_open() runs afoul of these restrictions [a]. See the ov_open_callbacks() page for details on using ov_open_callbacks() instead.

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 libvorbisfile functions. Once this has been called, the same OggVorbis_File struct should be passed to all the libvorbisfile functions.

The `vf` structure initialized using ov_fopen() must eventually be cleaned using ov_clear(). Once a `FILE *` handle is passed to ov_open() successfully, the application MUST NOT `fclose()` or in any other way manipulate that file handle. Vorbisfile will close the file in ov_clear(). If the application must be able to close the `FILE *` handle itself, see ov_open_callbacks() with the use of `OV_CALLBACKS_NOCLOSE`.

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 Vorbis. If the call succeeds but the initialized `vf` structure will not be used, the application is responsible for calling ov_clear() to clear the decoder's buffers and close the file.

If [and only if] an `ov_open()` call fails, the application must explicitly `fclose()` the `FILE *` pointer itself.

    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 libvorbisfile functions. Once this has been called, the same `OggVorbis_File` struct should be passed to all the libvorbisfile 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 indicates 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

[a] Windows and ov_open()

  Under Windows, stdio file access is implemented in each of many variants of crt.o, several of which are typically installed on any one Windows machine. If libvorbisfile and the application using libvorbisfile are not linked against the exact same version/variant/build of crt.o (and they usually won't be, especially using a prebuilt libvorbis DLL), `FILE *` handles cannot be opened in the application and then passed to vorbisfile to be used by stdio calls from vorbisfile's different version of CRT. For this reason, using ov_open() under Windows without careful, expert linking will typically cause a protection fault. Windows programmers should use ov_fopen() (which will only use libvorbis's crt.o) or ov_open_callbacks() (which will only use the application's crt.o) instead.

  This warning only applies to Windows and only applies to ov_open(). It is perfectly safe to use ov_open() on all other platforms.

  For more information, see the following microsoft pages on C runtime library linking and a specific description of restrictions on passing CRT objects across DLL boundaries.

[b] Threaded decode

  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). See Thread Safety for other information on using libvorbisfile with threads.

[c] Mixed media streams

  As of Vorbisfile release 1.2.0, Vorbisfile is able to access the Vorbis content in mixed-media Ogg streams, not just Vorbis-only streams. For example, Vorbisfile may be used to open and access the audio from an Ogg stream consisting of Theora video and Vorbis audio. Vorbisfile 1.2.0 decodes the first logical audio stream of each physical stream section.

[d] Faster testing for Vorbis files

  ov_test() and ov_test_callbacks() provide less computationally expensive ways to test a file for Vorbisness, but require more setup code.

copyright © 2000-2010 Xiph.Org | Ogg Vorbis
Vorbisfile documentation | vorbisfile version 1.3.2 - 20101101