1<html> 2 3<head> 4<title>Vorbisfile - function - ov_open_callbacks</title> 5<link rel=stylesheet href="style.css" type="text/css"> 6</head> 7 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>Vorbisfile documentation</p></td> 12<td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td> 13</tr> 14</table> 15 16<h1>ov_open_callbacks</h1> 17 18<p><i>declared in "vorbis/vorbisfile.h";</i></p> 19 20<p>This is an alternative function used to open and initialize an 21OggVorbis_File structure when using a data source other than a file, 22when its necessary to modify default file access behavior, or to 23initialize a Vorbis decode from a <tt>FILE *</tt> pointer under 24Windows where <a href="ov_open.html">ov_open()</a> cannot be used. It 25allows the application to specify custom file manipulation routines 26and sets up all the related decoding structures. 27 28<p>Once ov_open_callbacks() has been called, the same 29<tt>OggVorbis_File</tt> struct should be passed to all the 30libvorbisfile functions. Unlike <a 31href="ov_fopen.html">ov_fopen()</a> and <a 32href="ov_open.html">ov_open()</a>, ov_open_callbacks() may be used to 33instruct vorbisfile to either automatically close or not to close the 34file/data access handle in <a href="ov_clear.html">ov_clear()</a>. 35Automatic closure is disabled by passing NULL as the close callback, 36or using one of the predefined callback sets that specify a NULL close 37callback. The application is responsible for closing a file when a 38call to ov_open_callbacks() is unsuccessful.<p> 39 40See also <a href="callbacks.html">Callbacks and Non-stdio I/O</a> for 41information on designing and specifying custom callback functions.<p> 42 43<br><br> 44<table border=0 color=black cellspacing=0 cellpadding=7> 45<tr bgcolor=#cccccc> 46 <td> 47<pre><b> 48int ov_open_callbacks(void *datasource, <a href="OggVorbis_File.html">OggVorbis_File</a> *vf, char *initial, long ibytes, <a href="ov_callbacks.html">ov_callbacks</a> callbacks); 49</b></pre> 50 </td> 51</tr> 52</table> 53 54<h3>Parameters</h3> 55<dl> 56<dt><i>datasource</i></dt> 57<dd>Pointer to a data structure allocated by the calling application, containing any state needed by the callbacks provided.</dd> 58<dt><i>vf</i></dt> 59<dd>A pointer to the OggVorbis_File structure--this is used for ALL the externally visible libvorbisfile 60functions. Once this has been called, the same <tt>OggVorbis_File</tt> 61struct should be passed to all the libvorbisfile functions.</dd> 62<dt><i>initial</i></dt> 63<dd>Typically set to NULL. This parameter is useful if some data has already been 64read from the stream and the stream is not seekable. It is used in conjunction with <tt>ibytes</tt>. In this case, <tt>initial</tt> 65should be a pointer to a buffer containing the data read.</dd> 66<dt><i>ibytes</i></dt> 67<dd>Typically set to 0. This parameter is useful if some data has already been 68read from the stream and the stream is not seekable. In this case, <tt>ibytes</tt> 69should contain the length (in bytes) of the buffer. Used together with <tt>initial</tt>.</dd> 70<dt><i>callbacks</i></dt> 71<dd>A completed <a href="ov_callbacks.html">ov_callbacks</a> struct which indicates desired custom file manipulation routines. vorbisfile.h defines several preprovided callback sets; see <a href="ov_callbacks.html">ov_callbacks</a> for details.</dd> 72</dl> 73 74 75<h3>Return Values</h3> 76<blockquote> 77<li>0 for success</li> 78<li>less than zero for failure:</li> 79<ul> 80<li>OV_EREAD - A read from media returned an error.</li> 81<li>OV_ENOTVORBIS - Bitstream does not contain any Vorbis data.</li> 82<li>OV_EVERSION - Vorbis version mismatch.</li> 83<li>OV_EBADHEADER - Invalid Vorbis bitstream header.</li> 84<li>OV_EFAULT - Internal logic fault; indicates a bug or heap/stack corruption.</li> 85</ul> 86</blockquote> 87<p> 88 89<h3>Notes</h3> 90<dl> 91 92<dt><b>[a] Windows and use as an ov_open() substitute</b><p> Windows 93applications should not use <a href="ov_open.html">ov_open()</a> due 94to the likelihood of <a href="ov_open.html#winfoot">CRT linking 95mismatches and runtime protection faults 96[ov_open:a]</a>. ov_open_callbacks() is a safe substitute; specifically: 97 98<pre><tt>ov_open_callbacks(f, vf, initial, ibytes, OV_CALLBACKS_DEFAULT);</tt> 99</pre> 100 101... provides exactly the same functionality as <a 102href="ov_open.html">ov_open()</a> but will always work correctly under 103Windows, regardless of linking setup details.<p> 104 105<dt><b>[b] Threaded decode</b><p> 106<dd>If your decoder is threaded, it is recommended that you NOT call 107<tt>ov_open_callbacks()</tt> 108in the main control thread--instead, call <tt>ov_open_callbacks()</tt> in your decode/playback 109thread. This is important because <tt>ov_open_callbacks()</tt> may be a fairly time-consuming 110call, given that the full structure of the file is determined at this point, 111which may require reading large parts of the file under certain circumstances 112(determining all the logical bitstreams in one physical bitstream, for 113example). See <a href="threads.html">Thread Safety</a> for other information on using libvorbisfile with threads. 114<p> 115 116<dt><b>[c] Mixed media streams</b><p> 117<dd> 118As of Vorbisfile release 1.2.0, Vorbisfile is able to access the 119Vorbis content in mixed-media Ogg streams, not just Vorbis-only 120streams. For example, Vorbisfile may be used to open and access the 121audio from an Ogg stream consisting of Theora video and Vorbis audio. 122Vorbisfile 1.2.0 decodes the first logical audio stream of each 123physical stream section.<p> 124 125<dt><b>[d] Faster testing for Vorbis files</b><p> 126<dd><a href="ov_test.html">ov_test()</a> and <a 127href="ov_test_callbacks.html">ov_test_callbacks()</a> provide less 128computationally expensive ways to test a file for Vorbisness, but 129require more setup code.<p> 130 131</dl> 132 133<br><br> 134<hr noshade> 135<table border=0 width=100%> 136<tr valign=top> 137<td><p class=tiny>copyright © 2007 Xiph.org</p></td> 138<td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td> 139</tr><tr> 140<td><p class=tiny>Vorbisfile documentation</p></td> 141<td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td> 142</tr> 143</table> 144 145</body> 146 147</html> 148