| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 | <html><head><title>Tremor - 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>Tremor documentation</p></td><td align=right><p class=tiny>Tremor version 1.0 - 20020403</p></td></tr></table><h1>Callbacks and non-stdio I/O</h1>Although stdio is convenient and nearly universally implemented as perANSI C, it is not suited to all or even most potential uses of Vorbis.For additional flexibility, embedded applications may provide theirown I/O functions for use with Tremor when stdio is unavailable or notsuitable.  One common example is decoding a Vorbis stream from amemory buffer.<p>Use custom I/O functions by populating an <ahref="ov_callbacks.html">ov_callbacks</a> structure and calling <ahref="ov_open_callbacks.html">ov_open_callbacks()</a> or <ahref="ov_test_callbacks.html">ov_test_callbacks()</a> rather than thetypical <a href="ov_open.html">ov_open()</a> or <ahref="ov_test.html">ov_test()</a>.  Past the open call, use oflibvorbisidec is identical to using it with stdio.<h2>Read function</h2> The read-like function provided in the <tt>read_func</tt> field isused to fetch the requested amount of data.  It expects the fetchoperation to function similar to file-access, that is, a multiple readoperations 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 isused to request non-sequential data access by libvorbisidec, movingthe access cursor to the requested position.<p>libvorbisidec expects the following behavior:<ul><li>The seek function must always return -1 (failure) if the givendata abstraction is not seekable.  It may choose to always return -1if the application desires libvorbisidec to treat the Vorbis datastrictly as a stream (which makes for a less expensive openoperation).<p><li>If the seek function initially indicates seekability, it mustalways succeed upon being given a valid seek request.<p><li>The seek function must implement all of SEEK_SET, SEEK_CUR andSEEK_END.  The implementation of SEEK_END should set the access cursorone 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 thepassed in instance of the data access abstraction and invalidate theinstance handle.  The close function is assumed to succeed.<p>One common use of callbacks and the close function is to change thebehavior of libvorbisidec with respect to file closure for applicationsthat <em>must</em> <tt>fclose</tt> data files themselves. By passingthe normal stdio calls as callback functions, but passing a<tt>close_func</tt> that does nothing, an application may call <ahref="ov_clear.html">ov_clear()</a> and then <tt>fclose()</tt> thefile originally passed to libvorbisidec.<h2>Tell function</h2> The tell function is intended to mimic thebehavior of <tt>ftell()</tt> and must return the byte position of thenext data byte that would be read.  If the data access cursor is atthe end of the 'file' (pointing to one past the last byte of data, asit would be after calling <tt>fseek(file,SEEK_END,0)</tt>), the tellfunction 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 isnot seekable.<p.<br><br><hr noshade><table border=0 width=100%><tr valign=top><td><p class=tiny>copyright © 2002 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>Tremor documentation</p></td><td align=right><p class=tiny>Tremor version 1.0 - 20020403</p></td></tr></table></body></html>
 |