annotate src/libvorbis-1.3.3/doc/vorbisfile/callbacks.html @ 86:98c1576536ae

Bring in flac, ogg, vorbis
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 19 Mar 2013 17:37:49 +0000
parents
children
rev   line source
cannam@86 1 <html>
cannam@86 2
cannam@86 3 <head>
cannam@86 4 <title>Vorbisfile - Callbacks and non-stdio I/O</title>
cannam@86 5 <link rel=stylesheet href="style.css" type="text/css">
cannam@86 6 </head>
cannam@86 7
cannam@86 8 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
cannam@86 9 <table border=0 width=100%>
cannam@86 10 <tr>
cannam@86 11 <td><p class=tiny>Vorbisfile documentation</p></td>
cannam@86 12 <td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td>
cannam@86 13 </tr>
cannam@86 14 </table>
cannam@86 15
cannam@86 16 <h1>Callbacks and non-stdio I/O</h1>
cannam@86 17
cannam@86 18 Although stdio is convenient and nearly universally implemented as per
cannam@86 19 ANSI C, it is not suited to all or even most potential uses of Vorbis.
cannam@86 20 For additional flexibility, embedded applications may provide their
cannam@86 21 own I/O functions for use with Vorbisfile when stdio is unavailable or not
cannam@86 22 suitable. One common example is decoding a Vorbis stream from a
cannam@86 23 memory buffer.<p>
cannam@86 24
cannam@86 25 Use custom I/O functions by populating an <a
cannam@86 26 href="ov_callbacks.html">ov_callbacks</a> structure and calling <a
cannam@86 27 href="ov_open_callbacks.html">ov_open_callbacks()</a> or <a
cannam@86 28 href="ov_test_callbacks.html">ov_test_callbacks()</a> rather than the
cannam@86 29 typical <a href="ov_open.html">ov_open()</a> or <a
cannam@86 30 href="ov_test.html">ov_test()</a>. Past the open call, use of
cannam@86 31 libvorbisfile is identical to using it with stdio.
cannam@86 32
cannam@86 33 <h2>Read function</h2>
cannam@86 34
cannam@86 35 The read-like function provided in the <tt>read_func</tt> field is
cannam@86 36 used to fetch the requested amount of data. It expects the fetch
cannam@86 37 operation to function similar to file-access, that is, a multiple read
cannam@86 38 operations will retrieve contiguous sequential pieces of data,
cannam@86 39 advancing a position cursor after each read.<p>
cannam@86 40
cannam@86 41 The following behaviors are also expected:<p>
cannam@86 42 <ul>
cannam@86 43 <li>a return of '0' indicates end-of-data (if the by-thread errno is unset)
cannam@86 44 <li>short reads mean nothing special (short reads are not treated as error conditions)
cannam@86 45 <li>a return of zero with the by-thread errno set to nonzero indicates a read error
cannam@86 46 </ul>
cannam@86 47 <p>
cannam@86 48
cannam@86 49 <h2>Seek function</h2>
cannam@86 50
cannam@86 51 The seek-like function provided in the <tt>seek_func</tt> field is
cannam@86 52 used to request non-sequential data access by libvorbisfile, moving
cannam@86 53 the access cursor to the requested position. The seek function is
cannam@86 54 optional; if callbacks are only to handle non-seeking (streaming) data
cannam@86 55 or the application wishes to force streaming behavior,
cannam@86 56 <tt>seek_func</tt> and <tt>tell_func</tt> should be set to NULL. If
cannam@86 57 the seek function is non-NULL, libvorbisfile mandates the following
cannam@86 58 behavior:
cannam@86 59
cannam@86 60 <ul>
cannam@86 61 <li>The seek function must always return -1 (failure) if the given
cannam@86 62 data abstraction is not seekable. It may choose to always return -1
cannam@86 63 if the application desires libvorbisfile to treat the Vorbis data
cannam@86 64 strictly as a stream (which makes for a less expensive open
cannam@86 65 operation).<p>
cannam@86 66
cannam@86 67 <li>If the seek function initially indicates seekability, it must
cannam@86 68 always succeed upon being given a valid seek request.<p>
cannam@86 69
cannam@86 70 <li>The seek function must implement all of SEEK_SET, SEEK_CUR and
cannam@86 71 SEEK_END. The implementation of SEEK_END should set the access cursor
cannam@86 72 one past the last byte of accessible data, as would stdio
cannam@86 73 <tt>fseek()</tt><p>
cannam@86 74 </ul>
cannam@86 75
cannam@86 76 <h2>Close function</h2>
cannam@86 77
cannam@86 78 The close function should deallocate any access state used by the
cannam@86 79 passed in instance of the data access abstraction and invalidate the
cannam@86 80 instance handle. The close function is assumed to succeed; its return
cannam@86 81 code is not checked.<p>
cannam@86 82
cannam@86 83 The <tt>close_func</tt> may be set to NULL to indicate that libvorbis
cannam@86 84 should not attempt to close the file/data handle in <a
cannam@86 85 href="ov_clear.html">ov_clear</a> but allow the application to handle
cannam@86 86 file/data access cleanup itself. For example, by passing the normal
cannam@86 87 stdio calls as callback functions, but passing a <tt>close_func</tt>
cannam@86 88 that is NULL or does nothing (as in the case of OV_CALLBACKS_NOCLOSE), an
cannam@86 89 application may call <a href="ov_clear.html">ov_clear()</a> and then
cannam@86 90 later <tt>fclose()</tt> the file originally passed to libvorbisfile.
cannam@86 91
cannam@86 92 <h2>Tell function</h2>
cannam@86 93
cannam@86 94 The tell function is intended to mimic the
cannam@86 95 behavior of <tt>ftell()</tt> and must return the byte position of the
cannam@86 96 next data byte that would be read. If the data access cursor is at
cannam@86 97 the end of the 'file' (pointing to one past the last byte of data, as
cannam@86 98 it would be after calling <tt>fseek(file,SEEK_END,0)</tt>), the tell
cannam@86 99 function must return the data position (and thus the total file size),
cannam@86 100 not an error.<p>
cannam@86 101
cannam@86 102 The tell function need not be provided if the data IO abstraction is
cannam@86 103 not seekable, or the application wishes to force streaming
cannam@86 104 behavior. In this case, the <tt>tell_func</tt> and <tt>seek_func</tt>
cannam@86 105 fields should be set to NULL.<p>
cannam@86 106
cannam@86 107 <br><br>
cannam@86 108 <hr noshade>
cannam@86 109 <table border=0 width=100%>
cannam@86 110 <tr valign=top>
cannam@86 111 <td><p class=tiny>copyright &copy; 2000-2010 Xiph.Org</p></td>
cannam@86 112 <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td>
cannam@86 113 </tr><tr>
cannam@86 114 <td><p class=tiny>Vorbisfile documentation</p></td>
cannam@86 115 <td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td>
cannam@86 116 </tr>
cannam@86 117 </table>
cannam@86 118
cannam@86 119 </body>
cannam@86 120
cannam@86 121 </html>