Blame doc/vorbisfile/callbacks.html

Packit 06404a
<html>
Packit 06404a
Packit 06404a
<head>
Packit 06404a
<title>Vorbisfile - Callbacks and non-stdio I/O</title>
Packit 06404a
<link rel=stylesheet href="style.css" type="text/css">
Packit 06404a
</head>
Packit 06404a
Packit 06404a
<body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
Packit 06404a
Packit 06404a
Packit 06404a

Vorbisfile documentation

Packit 06404a

vorbisfile version 1.3.2 - 20101101

Packit 06404a
Packit 06404a
Packit 06404a
Packit 06404a

Callbacks and non-stdio I/O

Packit 06404a
Packit 06404a
Although stdio is convenient and nearly universally implemented as per
Packit 06404a
ANSI C, it is not suited to all or even most potential uses of Vorbis.
Packit 06404a
For additional flexibility, embedded applications may provide their
Packit 06404a
own I/O functions for use with Vorbisfile when stdio is unavailable or not
Packit 06404a
suitable.  One common example is decoding a Vorbis stream from a
Packit 06404a
memory buffer.

Packit 06404a
Packit 06404a
Use custom I/O functions by populating an 
Packit 06404a
href="ov_callbacks.html">ov_callbacks structure and calling 
Packit 06404a
href="ov_open_callbacks.html">ov_open_callbacks() or 
Packit 06404a
href="ov_test_callbacks.html">ov_test_callbacks() rather than the
Packit 06404a
typical ov_open() or 
Packit 06404a
href="ov_test.html">ov_test().  Past the open call, use of
Packit 06404a
libvorbisfile is identical to using it with stdio.
Packit 06404a
Packit 06404a

Read function

Packit 06404a
Packit 06404a
The read-like function provided in the <tt>read_func</tt> field is
Packit 06404a
used to fetch the requested amount of data.  It expects the fetch
Packit 06404a
operation to function similar to file-access, that is, a multiple read
Packit 06404a
operations will retrieve contiguous sequential pieces of data,
Packit 06404a
advancing a position cursor after each read.

Packit 06404a
Packit 06404a
The following behaviors are also expected:

Packit 06404a
    Packit 06404a
  • a return of '0' indicates end-of-data (if the by-thread errno is unset)
  • Packit 06404a
  • short reads mean nothing special (short reads are not treated as error conditions)
  • Packit 06404a
  • a return of zero with the by-thread errno set to nonzero indicates a read error
  • Packit 06404a
    Packit 06404a

    Packit 06404a
    Packit 06404a

    Seek function

    Packit 06404a
    Packit 06404a
    The seek-like function provided in the <tt>seek_func</tt> field is
    Packit 06404a
    used to request non-sequential data access by libvorbisfile, moving
    Packit 06404a
    the access cursor to the requested position. The seek function is
    Packit 06404a
    optional; if callbacks are only to handle non-seeking (streaming) data
    Packit 06404a
    or the application wishes to force streaming behavior,
    Packit 06404a
    <tt>seek_func</tt> and <tt>tell_func</tt> should be set to NULL. If
    Packit 06404a
    the seek function is non-NULL, libvorbisfile mandates the following
    Packit 06404a
    behavior:
    Packit 06404a
    Packit 06404a
      Packit 06404a
    • The seek function must always return -1 (failure) if the given
    • Packit 06404a
      data abstraction is not seekable.  It may choose to always return -1
      Packit 06404a
      if the application desires libvorbisfile to treat the Vorbis data
      Packit 06404a
      strictly as a stream (which makes for a less expensive open
      Packit 06404a
      operation).

      Packit 06404a
      Packit 06404a
    • If the seek function initially indicates seekability, it must
    • Packit 06404a
      always succeed upon being given a valid seek request.

      Packit 06404a
      Packit 06404a
    • The seek function must implement all of SEEK_SET, SEEK_CUR and
    • Packit 06404a
      SEEK_END.  The implementation of SEEK_END should set the access cursor
      Packit 06404a
      one past the last byte of accessible data, as would stdio
      Packit 06404a
      <tt>fseek()</tt>

      Packit 06404a
      Packit 06404a
      Packit 06404a

      Close function

      Packit 06404a
      Packit 06404a
      The close function should deallocate any access state used by the
      Packit 06404a
      passed in instance of the data access abstraction and invalidate the
      Packit 06404a
      instance handle.  The close function is assumed to succeed; its return
      Packit 06404a
      code is not checked.

      Packit 06404a
      Packit 06404a
      The <tt>close_func</tt> may be set to NULL to indicate that libvorbis
      Packit 06404a
      should not attempt to close the file/data handle in 
      Packit 06404a
      href="ov_clear.html">ov_clear but allow the application to handle
      Packit 06404a
      file/data access cleanup itself. For example, by passing the normal
      Packit 06404a
      stdio calls as callback functions, but passing a <tt>close_func</tt>
      Packit 06404a
      that is NULL or does nothing (as in the case of OV_CALLBACKS_NOCLOSE), an
      Packit 06404a
      application may call ov_clear() and then
      Packit 06404a
      later <tt>fclose()</tt> the file originally passed to libvorbisfile.
      Packit 06404a
      Packit 06404a

      Tell function

      Packit 06404a
      Packit 06404a
      The tell function is intended to mimic the
      Packit 06404a
      behavior of <tt>ftell()</tt> and must return the byte position of the
      Packit 06404a
      next data byte that would be read.  If the data access cursor is at
      Packit 06404a
      the end of the 'file' (pointing to one past the last byte of data, as
      Packit 06404a
      it would be after calling <tt>fseek(file,SEEK_END,0)</tt>), the tell
      Packit 06404a
      function must return the data position (and thus the total file size),
      Packit 06404a
      not an error.

      Packit 06404a
      Packit 06404a
      The tell function need not be provided if the data IO abstraction is
      Packit 06404a
      not seekable, or the application wishes to force streaming
      Packit 06404a
      behavior. In this case, the <tt>tell_func</tt> and <tt>seek_func</tt>
      Packit 06404a
      fields should be set to NULL.

      Packit 06404a
      Packit 06404a


      Packit 06404a

      Packit 06404a
      Packit 06404a
      Packit 06404a

      copyright © 2000-2010 Xiph.Org

      Packit 06404a

      Ogg Vorbis

      Packit 06404a
      Packit 06404a

      Vorbisfile documentation

      Packit 06404a

      vorbisfile version 1.3.2 - 20101101

      Packit 06404a
      Packit 06404a
      Packit 06404a
      Packit 06404a
      </body>
      Packit 06404a
      Packit 06404a
      </html>