diff options
Diffstat (limited to 'doc/vorbisfile/callbacks.html')
-rw-r--r-- | doc/vorbisfile/callbacks.html | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/doc/vorbisfile/callbacks.html b/doc/vorbisfile/callbacks.html new file mode 100644 index 0000000..20ae55a --- /dev/null +++ b/doc/vorbisfile/callbacks.html @@ -0,0 +1,121 @@ +<html> + +<head> +<title>Vorbisfile - Callbacks and non-stdio I/O</title> +<link rel=stylesheet href="style.css" type="text/css"> +</head> + +<body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff"> +<table border=0 width=100%> +<tr> +<td><p class=tiny>Vorbisfile documentation</p></td> +<td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td> +</tr> +</table> + +<h1>Callbacks and non-stdio I/O</h1> + +Although stdio is convenient and nearly universally implemented as per +ANSI C, it is not suited to all or even most potential uses of Vorbis. +For additional flexibility, embedded applications may provide their +own I/O functions for use with Vorbisfile when stdio is unavailable or not +suitable. One common example is decoding a Vorbis stream from a +memory buffer.<p> + +Use custom I/O functions by populating an <a +href="ov_callbacks.html">ov_callbacks</a> structure and calling <a +href="ov_open_callbacks.html">ov_open_callbacks()</a> or <a +href="ov_test_callbacks.html">ov_test_callbacks()</a> rather than the +typical <a href="ov_open.html">ov_open()</a> or <a +href="ov_test.html">ov_test()</a>. Past the open call, use of +libvorbisfile is identical to using it with stdio. + +<h2>Read function</h2> + +The read-like function provided in the <tt>read_func</tt> field is +used to fetch the requested amount of data. It expects the fetch +operation to function similar to file-access, that is, a multiple read +operations will retrieve contiguous sequential pieces of data, +advancing a position cursor after each read.<p> + +The following behaviors are also expected:<p> +<ul> +<li>a return of '0' indicates end-of-data (if the by-thread errno is unset) +<li>short reads mean nothing special (short reads are not treated as error conditions) +<li>a return of zero with the by-thread errno set to nonzero indicates a read error +</ul> +<p> + +<h2>Seek function</h2> + +The seek-like function provided in the <tt>seek_func</tt> field is +used to request non-sequential data access by libvorbisfile, moving +the access cursor to the requested position. The seek function is +optional; if callbacks are only to handle non-seeking (streaming) data +or the application wishes to force streaming behavior, +<tt>seek_func</tt> and <tt>tell_func</tt> should be set to NULL. If +the seek function is non-NULL, libvorbisfile mandates the following +behavior: + +<ul> +<li>The seek function must always return -1 (failure) if the given +data abstraction is not seekable. It may choose to always return -1 +if the application desires libvorbisfile to treat the Vorbis data +strictly as a stream (which makes for a less expensive open +operation).<p> + +<li>If the seek function initially indicates seekability, it must +always succeed upon being given a valid seek request.<p> + +<li>The seek function must implement all of SEEK_SET, SEEK_CUR and +SEEK_END. The implementation of SEEK_END should set the access cursor +one past the last byte of accessible data, as would stdio +<tt>fseek()</tt><p> +</ul> + +<h2>Close function</h2> + +The close function should deallocate any access state used by the +passed in instance of the data access abstraction and invalidate the +instance handle. The close function is assumed to succeed; its return +code is not checked.<p> + +The <tt>close_func</tt> may be set to NULL to indicate that libvorbis +should not attempt to close the file/data handle in <a +href="ov_clear.html">ov_clear</a> but allow the application to handle +file/data access cleanup itself. For example, by passing the normal +stdio calls as callback functions, but passing a <tt>close_func</tt> +that is NULL or does nothing (as in the case of OV_CALLBACKS_NOCLOSE), an +application may call <a href="ov_clear.html">ov_clear()</a> and then +later <tt>fclose()</tt> the file originally passed to libvorbisfile. + +<h2>Tell function</h2> + +The tell function is intended to mimic the +behavior of <tt>ftell()</tt> and must return the byte position of the +next data byte that would be read. If the data access cursor is at +the end of the 'file' (pointing to one past the last byte of data, as +it would be after calling <tt>fseek(file,SEEK_END,0)</tt>), the tell +function must return the data position (and thus the total file size), +not an error.<p> + +The tell function need not be provided if the data IO abstraction is +not seekable, or the application wishes to force streaming +behavior. In this case, the <tt>tell_func</tt> and <tt>seek_func</tt> +fields should be set to NULL.<p> + +<br><br> +<hr noshade> +<table border=0 width=100%> +<tr valign=top> +<td><p class=tiny>copyright © 2000-2010 Xiph.Org</p></td> +<td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td> +</tr><tr> +<td><p class=tiny>Vorbisfile documentation</p></td> +<td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td> +</tr> +</table> + +</body> + +</html> |