summaryrefslogtreecommitdiffhomepage
path: root/doc/vorbisfile/ov_open_callbacks.html
blob: 6d59e0b660e0df8e87453f19f80cbe3f6e8c899a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<html>

<head>
<title>Vorbisfile - function - ov_open_callbacks</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>ov_open_callbacks</h1>

<p><i>declared in "vorbis/vorbisfile.h";</i></p>

<p>This is an alternative function used to open and initialize an
OggVorbis_File structure when using a data source other than a file,
when its necessary to modify default file access behavior, or to
initialize a Vorbis decode from a <tt>FILE *</tt> pointer under
Windows where <a href="ov_open.html">ov_open()</a> cannot be used.  It
allows the application to specify custom file manipulation routines
and sets up all the related decoding structures.

<p>Once ov_open_callbacks() has been called, the same
<tt>OggVorbis_File</tt> struct should be passed to all the
libvorbisfile functions.  Unlike <a
href="ov_fopen.html">ov_fopen()</a> and <a
href="ov_open.html">ov_open()</a>, ov_open_callbacks() may be used to
instruct vorbisfile to either automatically close or not to close the
file/data access handle in <a href="ov_clear.html">ov_clear()</a>.
Automatic closure is disabled by passing NULL as the close callback,
or using one of the predefined callback sets that specify a NULL close
callback.  The application is responsible for closing a file when a
call to ov_open_callbacks() is unsuccessful.<p>

See also <a href="callbacks.html">Callbacks and Non-stdio I/O</a> for
information on designing and specifying custom callback functions.<p>

<br><br>
<table border=0 color=black cellspacing=0 cellpadding=7>
<tr bgcolor=#cccccc>
	<td>
<pre><b>
int 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);
</b></pre>
	</td>
</tr>
</table>

<h3>Parameters</h3>
<dl>
<dt><i>datasource</i></dt>
<dd>Pointer to a data structure allocated by the calling application, containing any state needed by the callbacks provided.</dd>
<dt><i>vf</i></dt>
<dd>A pointer to the OggVorbis_File structure--this is used for ALL the externally visible libvorbisfile
functions. Once this has been called, the same <tt>OggVorbis_File</tt>
struct should be passed to all the libvorbisfile functions.</dd>
<dt><i>initial</i></dt>
<dd>Typically set to NULL.  This parameter is useful if some data has already been
read from the stream and the stream is not seekable. It is used in conjunction with <tt>ibytes</tt>.  In this case, <tt>initial</tt>
should be a pointer to a buffer containing the data read.</dd>
<dt><i>ibytes</i></dt>
<dd>Typically set to 0.  This parameter is useful if some data has already been
read from the stream and the stream is not seekable. In this case, <tt>ibytes</tt>
should contain the length (in bytes) of the buffer.  Used together with <tt>initial</tt>.</dd>
<dt><i>callbacks</i></dt>
<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>
</dl>


<h3>Return Values</h3>
<blockquote>
<li>0 for success</li>
<li>less than zero for failure:</li>
<ul>
<li>OV_EREAD - A read from media returned an error.</li>
<li>OV_ENOTVORBIS - Bitstream does not contain any Vorbis data.</li>
<li>OV_EVERSION - Vorbis version mismatch.</li>
<li>OV_EBADHEADER - Invalid Vorbis bitstream header.</li>
<li>OV_EFAULT - Internal logic fault; indicates a bug or heap/stack corruption.</li>
</ul>
</blockquote>
<p>

<h3>Notes</h3>
<dl>

<dt><b>[a] Windows and use as an ov_open() substitute</b><p> Windows
applications should not use <a href="ov_open.html">ov_open()</a> due
to the likelihood of <a href="ov_open.html#winfoot">CRT linking
mismatches and runtime protection faults
[ov_open:a]</a>. ov_open_callbacks() is a safe substitute; specifically:

<pre><tt>ov_open_callbacks(f, vf, initial, ibytes, OV_CALLBACKS_DEFAULT);</tt>
</pre>

... provides exactly the same functionality as <a
href="ov_open.html">ov_open()</a> but will always work correctly under
Windows, regardless of linking setup details.<p>

<dt><b>[b] Threaded decode</b><p>
<dd>If your decoder is threaded, it is recommended that you NOT call
<tt>ov_open_callbacks()</tt>
in the main control thread--instead, call <tt>ov_open_callbacks()</tt> in your decode/playback
thread. This is important because <tt>ov_open_callbacks()</tt> may be a fairly time-consuming
call, given that the full structure of the file is determined at this point,
which may require reading large parts of the file under certain circumstances
(determining all the logical bitstreams in one physical bitstream, for
example).  See <a href="threads.html">Thread Safety</a> for other information on using libvorbisfile with threads.
<p>

<dt><b>[c] Mixed media streams</b><p>
<dd>
As of Vorbisfile release 1.2.0, Vorbisfile is able to access the
Vorbis content in mixed-media Ogg streams, not just Vorbis-only
streams.  For example, Vorbisfile may be used to open and access the
audio from an Ogg stream consisting of Theora video and Vorbis audio.
Vorbisfile 1.2.0 decodes the first logical audio stream of each
physical stream section.<p>

<dt><b>[d] Faster testing for Vorbis files</b><p>
<dd><a href="ov_test.html">ov_test()</a> and <a
href="ov_test_callbacks.html">ov_test_callbacks()</a> provide less
computationally expensive ways to test a file for Vorbisness, but
require more setup code.<p>

</dl>

<br><br>
<hr noshade>
<table border=0 width=100%>
<tr valign=top>
<td><p class=tiny>copyright &copy; 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>