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