1 <html> 2 3 <head> 4 <title>Vorbisfile - function - ov_open</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</h1> 17 18 <p><i>declared in "vorbis/vorbisfile.h";</i></p> 19 20 <p>ov_open is one of three initialization functions used to initialize 21 an OggVorbis_File structure and prepare a bitstream for playback. 22 23 <p><em><b> WARNING for Windows developers: </b> Do not use ov_open() in 24 Windows applications; Windows linking places restrictions on 25 passing <tt>FILE *</tt> handles successfully, and ov_open() runs 26 afoul of these restrictions <a href="#winfoot">[a]</a>. See the <a 27 href="ov_open_callbacks.html">ov_open_callbacks() page </a> for 28 details on using <a 29 href="ov_open_callbacks.html">ov_open_callbacks()</a> instead. </em> 30 31 <p>The first argument must be a file pointer to an already opened file 32 or pipe (it need not be seekable--though this obviously restricts what 33 can be done with the bitstream). <tt>vf</tt> should be a pointer to the 34 OggVorbis_File structure -- this is used for ALL the externally visible libvorbisfile 35 functions. Once this has been called, the same <a href="OggVorbis_File.html">OggVorbis_File</a> 36 struct should be passed to all the libvorbisfile functions.<p> 37 38 The <tt>vf</tt> structure initialized using ov_fopen() must eventually 39 be cleaned using <a href="ov_clear.html">ov_clear()</a>. Once a 40 <tt>FILE *</tt> handle is passed to ov_open() successfully, the 41 application MUST NOT <tt>fclose()</tt> or in any other way manipulate 42 that file handle. Vorbisfile will close the file in <a 43 href="ov_clear.html">ov_clear()</a>. If the application must be able 44 to close the <tt>FILE *</tt> handle itself, see <a 45 href="ov_open_callbacks.html">ov_open_callbacks()</a> with the use of 46 <tt>OV_CALLBACKS_NOCLOSE</tt>. 47 48 <p>It is often useful to call <tt>ov_open()</tt> simply to determine 49 whether a given file is a Vorbis bitstream. If the <tt>ov_open()</tt> 50 call fails, then the file is not recognizable as Vorbis. If the call 51 succeeds but the initialized <tt>vf</tt> structure will not be used, 52 the application is responsible for calling <a 53 href="ov_clear.html">ov_clear()</a> to clear the decoder's buffers and 54 close the file.<p> 55 56 If [and only if] an <tt>ov_open()</tt> call fails, the application 57 must explicitly <tt>fclose()</tt> the <tt>FILE *</tt> pointer itself. 58 59 60 <br><br> 61 <table border=0 color=black cellspacing=0 cellpadding=7> 62 <tr bgcolor=#cccccc> 63 <td> 64 <pre><b> 65 int ov_open(FILE *f,<a href="OggVorbis_File.html">OggVorbis_File</a> *vf,char *initial,long ibytes); 66 </b></pre> 67 </td> 68 </tr> 69 </table> 70 71 <h3>Parameters</h3> 72 <dl> 73 <dt><i>f</i></dt> 74 <dd>File pointer to an already opened file 75 or pipe (it need not be seekable--though this obviously restricts what 76 can be done with the bitstream).</dd> 77 <dt><i>vf</i></dt> 78 <dd>A pointer to the OggVorbis_File structure--this is used for ALL the externally visible libvorbisfile 79 functions. Once this has been called, the same <tt>OggVorbis_File</tt> 80 struct should be passed to all the libvorbisfile functions.</dd> 81 <dt><i>initial</i></dt> 82 <dd>Typically set to NULL. This parameter is useful if some data has already been 83 read from the file and the stream is not seekable. It is used in conjunction with <tt>ibytes</tt>. In this case, <tt>initial</tt> 84 should be a pointer to a buffer containing the data read.</dd> 85 <dt><i>ibytes</i></dt> 86 <dd>Typically set to 0. This parameter is useful if some data has already been 87 read from the file and the stream is not seekable. In this case, <tt>ibytes</tt> 88 should contain the length (in bytes) of the buffer. Used together with <tt>initial</tt></dd> 89 </dl> 90 91 92 <h3>Return Values</h3> 93 <blockquote> 94 <li>0 indicates success</li> 95 96 <li>less than zero for failure:</li> 97 <ul> 98 <li>OV_EREAD - A read from media returned an error.</li> 99 <li>OV_ENOTVORBIS - Bitstream is not Vorbis data.</li> 100 <li>OV_EVERSION - Vorbis version mismatch.</li> 101 <li>OV_EBADHEADER - Invalid Vorbis bitstream header.</li> 102 <li>OV_EFAULT - Internal logic fault; indicates a bug or heap/stack corruption.</li> 103 </ul> 104 </blockquote> 105 <p> 106 107 <a name="notes"></a> 108 <h3>Notes</h3> 109 <dl> 110 111 <a name="winfoot"></a> 112 <dt><b>[a] Windows and ov_open()</b><p> 113 114 <dd>Under Windows, stdio file access is implemented in each of many 115 variants of crt.o, several of which are typically installed on any one 116 Windows machine. If libvorbisfile and the application using 117 libvorbisfile are not linked against the exact same 118 version/variant/build of crt.o (and they usually won't be, especially 119 using a prebuilt libvorbis DLL), <tt>FILE *</tt> handles cannot be 120 opened in the application and then passed to vorbisfile to be used 121 by stdio calls from vorbisfile's different version of CRT. For this 122 reason, using <a href="ov_open.html">ov_open()</a> under Windows 123 without careful, expert linking will typically cause a protection 124 fault. Windows programmers should use <a 125 href="ov_fopen.html">ov_fopen()</a> (which will only use libvorbis's 126 crt.o) or <a href="ov_open_callbacks.html">ov_open_callbacks()</a> 127 (which will only use the application's crt.o) instead.<p> 128 129 This warning only applies to Windows and only applies to <a 130 href="ov_open.html">ov_open()</a>. It is perfectly safe to use <a 131 href="ov_open.html">ov_open()</a> on all other platforms.<p> 132 133 For more information, see the following microsoft pages on <a 134 href="http://msdn2.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx">C 135 runtime library linking</a> and a specific description of <a 136 href="http://msdn2.microsoft.com/en-us/library/ms235460(VS.80).aspx">restrictions 137 on passing CRT objects across DLL boundaries</a>. 138 139 <p> 140 141 <dt><b>[b] Threaded decode</b><p> 142 <dd>If your decoder is threaded, it is recommended that you NOT call 143 <tt>ov_open()</tt> 144 in the main control thread--instead, call <tt>ov_open()</tt> in your decode/playback 145 thread. This is important because <tt>ov_open()</tt> may be a fairly time-consuming 146 call, given that the full structure of the file is determined at this point, 147 which may require reading large parts of the file under certain circumstances 148 (determining all the logical bitstreams in one physical bitstream, for 149 example). See <a href="threads.html">Thread Safety</a> for other information on using libvorbisfile with threads. 150 <p> 151 152 <dt><b>[c] Mixed media streams</b><p> 153 <dd> 154 As of Vorbisfile release 1.2.0, Vorbisfile is able to access the 155 Vorbis content in mixed-media Ogg streams, not just Vorbis-only 156 streams. For example, Vorbisfile may be used to open and access the 157 audio from an Ogg stream consisting of Theora video and Vorbis audio. 158 Vorbisfile 1.2.0 decodes the first logical audio stream of each 159 physical stream section.<p> 160 161 <dt><b>[d] Faster testing for Vorbis files</b><p> 162 <dd><a href="ov_test.html">ov_test()</a> and <a 163 href="ov_test_callbacks.html">ov_test_callbacks()</a> provide less 164 computationally expensive ways to test a file for Vorbisness, but 165 require more setup code.<p> 166 167 </dl> 168 169 <br><br> 170 <hr noshade> 171 <table border=0 width=100%> 172 <tr valign=top> 173 <td><p class=tiny>copyright © 2007 Xiph.org</p></td> 174 <td align=right><p class=tiny><a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a></p></td> 175 </tr><tr> 176 <td><p class=tiny>Vorbisfile documentation</p></td> 177 <td align=right><p class=tiny>vorbisfile version 1.2.0 - 20070723</p></td> 178 </tr> 179 </table> 180 181 </body> 182 183 </html> 184