Recognizes if input is ogg or not.
[xiph.git] / Tremor / doc / callbacks.html
blob9a6d3920fe83c4d9954bedde4e427e1974f7c87a
1 <html>
3 <head>
4 <title>Tremor - Callbacks and non-stdio I/O</title>
5 <link rel=stylesheet href="style.css" type="text/css">
6 </head>
8 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
9 <table border=0 width=100%>
10 <tr>
11 <td><p class=tiny>Tremor documentation</p></td>
12 <td align=right><p class=tiny>Tremor version 1.0 - 20020403</p></td>
13 </tr>
14 </table>
16 <h1>Callbacks and non-stdio I/O</h1>
18 Although stdio is convenient and nearly universally implemented as per
19 ANSI C, it is not suited to all or even most potential uses of Vorbis.
20 For additional flexibility, embedded applications may provide their
21 own I/O functions for use with Tremor when stdio is unavailable or not
22 suitable. One common example is decoding a Vorbis stream from a
23 memory buffer.<p>
25 Use custom I/O functions by populating an <a
26 href="ov_callbacks.html">ov_callbacks</a> structure and calling <a
27 href="ov_open_callbacks.html">ov_open_callbacks()</a> or <a
28 href="ov_test_callbacks.html">ov_test_callbacks()</a> rather than the
29 typical <a href="ov_open.html">ov_open()</a> or <a
30 href="ov_test.html">ov_test()</a>. Past the open call, use of
31 libvorbisidec is identical to using it with stdio.
33 <h2>Read function</h2>
35 The read-like function provided in the <tt>read_func</tt> field is
36 used to fetch the requested amount of data. It expects the fetch
37 operation to function similar to file-access, that is, a multiple read
38 operations will retrieve contiguous sequential pieces of data,
39 advancing a position cursor after each read.<p>
41 The following behaviors are also expected:<p>
42 <ul>
43 <li>a return of '0' indicates end-of-data (if the by-thread errno is unset)
44 <li>short reads mean nothing special (short reads are not treated as error conditions)
45 <li>a return of zero with the by-thread errno set to nonzero indicates a read error
46 </ul>
47 <p>
49 <h2>Seek function</h2>
51 The seek-like function provided in the <tt>seek_func</tt> field is
52 used to request non-sequential data access by libvorbisidec, moving
53 the access cursor to the requested position.<p>
55 libvorbisidec expects the following behavior:
56 <ul>
57 <li>The seek function must always return -1 (failure) if the given
58 data abstraction is not seekable. It may choose to always return -1
59 if the application desires libvorbisidec to treat the Vorbis data
60 strictly as a stream (which makes for a less expensive open
61 operation).<p>
63 <li>If the seek function initially indicates seekability, it must
64 always succeed upon being given a valid seek request.<p>
66 <li>The seek function must implement all of SEEK_SET, SEEK_CUR and
67 SEEK_END. The implementation of SEEK_END should set the access cursor
68 one past the last byte of accessible data, as would stdio
69 <tt>fseek()</tt><p>
70 </ul>
72 <h2>Close function</h2>
74 The close function should deallocate any access state used by the
75 passed in instance of the data access abstraction and invalidate the
76 instance handle. The close function is assumed to succeed.<p>
78 One common use of callbacks and the close function is to change the
79 behavior of libvorbisidec with respect to file closure for applications
80 that <em>must</em> <tt>fclose</tt> data files themselves. By passing
81 the normal stdio calls as callback functions, but passing a
82 <tt>close_func</tt> that does nothing, an application may call <a
83 href="ov_clear.html">ov_clear()</a> and then <tt>fclose()</tt> the
84 file originally passed to libvorbisidec.
86 <h2>Tell function</h2>
88 The tell function is intended to mimic the
89 behavior of <tt>ftell()</tt> and must return the byte position of the
90 next data byte that would be read. If the data access cursor is at
91 the end of the 'file' (pointing to one past the last byte of data, as
92 it would be after calling <tt>fseek(file,SEEK_END,0)</tt>), the tell
93 function must return the data position (and thus the total file size),
94 not an error.<p>
96 The tell function need not be provided if the data IO abstraction is
97 not seekable.<p.
99 <br><br>
100 <hr noshade>
101 <table border=0 width=100%>
102 <tr valign=top>
103 <td><p class=tiny>copyright &copy; 2002 Xiph.org</p></td>
104 <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td>
105 </tr><tr>
106 <td><p class=tiny>Tremor documentation</p></td>
107 <td align=right><p class=tiny>Tremor version 1.0 - 20020403</p></td>
108 </tr>
109 </table>
111 </body>
113 </html>