annotate osx/include/opus/opusfile.h @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 4664ac0c1032
children
rev   line source
cannam@154 1 /********************************************************************
cannam@154 2 * *
cannam@154 3 * THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. *
cannam@154 4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
cannam@154 5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
cannam@154 6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
cannam@154 7 * *
cannam@154 8 * THE libopusfile SOURCE CODE IS (C) COPYRIGHT 1994-2012 *
cannam@154 9 * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
cannam@154 10 * *
cannam@154 11 ********************************************************************
cannam@154 12
cannam@154 13 function: stdio-based convenience library for opening/seeking/decoding
cannam@154 14 last mod: $Id: vorbisfile.h 17182 2010-04-29 03:48:32Z xiphmont $
cannam@154 15
cannam@154 16 ********************************************************************/
cannam@154 17 #if !defined(_opusfile_h)
cannam@154 18 # define _opusfile_h (1)
cannam@154 19
cannam@154 20 /**\mainpage
cannam@154 21 \section Introduction
cannam@154 22
cannam@154 23 This is the documentation for the <tt>libopusfile</tt> C API.
cannam@154 24
cannam@154 25 The <tt>libopusfile</tt> package provides a convenient high-level API for
cannam@154 26 decoding and basic manipulation of all Ogg Opus audio streams.
cannam@154 27 <tt>libopusfile</tt> is implemented as a layer on top of Xiph.Org's
cannam@154 28 reference
cannam@154 29 <tt><a href="https://www.xiph.org/ogg/doc/libogg/reference.html">libogg</a></tt>
cannam@154 30 and
cannam@154 31 <tt><a href="https://mf4.xiph.org/jenkins/view/opus/job/opus/ws/doc/html/index.html">libopus</a></tt>
cannam@154 32 libraries.
cannam@154 33
cannam@154 34 <tt>libopusfile</tt> provides several sets of built-in routines for
cannam@154 35 file/stream access, and may also use custom stream I/O routines provided by
cannam@154 36 the embedded environment.
cannam@154 37 There are built-in I/O routines provided for ANSI-compliant
cannam@154 38 <code>stdio</code> (<code>FILE *</code>), memory buffers, and URLs
cannam@154 39 (including <file:> URLs, plus optionally <http:> and <https:> URLs).
cannam@154 40
cannam@154 41 \section Organization
cannam@154 42
cannam@154 43 The main API is divided into several sections:
cannam@154 44 - \ref stream_open_close
cannam@154 45 - \ref stream_info
cannam@154 46 - \ref stream_decoding
cannam@154 47 - \ref stream_seeking
cannam@154 48
cannam@154 49 Several additional sections are not tied to the main API.
cannam@154 50 - \ref stream_callbacks
cannam@154 51 - \ref header_info
cannam@154 52 - \ref error_codes
cannam@154 53
cannam@154 54 \section Overview
cannam@154 55
cannam@154 56 The <tt>libopusfile</tt> API always decodes files to 48&nbsp;kHz.
cannam@154 57 The original sample rate is not preserved by the lossy compression, though
cannam@154 58 it is stored in the header to allow you to resample to it after decoding
cannam@154 59 (the <tt>libopusfile</tt> API does not currently provide a resampler,
cannam@154 60 but the
cannam@154 61 <a href="http://www.speex.org/docs/manual/speex-manual/node7.html#SECTION00760000000000000000">the
cannam@154 62 Speex resampler</a> is a good choice if you need one).
cannam@154 63 In general, if you are playing back the audio, you should leave it at
cannam@154 64 48&nbsp;kHz, provided your audio hardware supports it.
cannam@154 65 When decoding to a file, it may be worth resampling back to the original
cannam@154 66 sample rate, so as not to surprise users who might not expect the sample
cannam@154 67 rate to change after encoding to Opus and decoding.
cannam@154 68
cannam@154 69 Opus files can contain anywhere from 1 to 255 channels of audio.
cannam@154 70 The channel mappings for up to 8 channels are the same as the
cannam@154 71 <a href="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.3.9">Vorbis
cannam@154 72 mappings</a>.
cannam@154 73 A special stereo API can convert everything to 2 channels, making it simple
cannam@154 74 to support multichannel files in an application which only has stereo
cannam@154 75 output.
cannam@154 76 Although the <tt>libopusfile</tt> ABI provides support for the theoretical
cannam@154 77 maximum number of channels, the current implementation does not support
cannam@154 78 files with more than 8 channels, as they do not have well-defined channel
cannam@154 79 mappings.
cannam@154 80
cannam@154 81 Like all Ogg files, Opus files may be "chained".
cannam@154 82 That is, multiple Opus files may be combined into a single, longer file just
cannam@154 83 by concatenating the original files.
cannam@154 84 This is commonly done in internet radio streaming, as it allows the title
cannam@154 85 and artist to be updated each time the song changes, since each link in the
cannam@154 86 chain includes its own set of metadata.
cannam@154 87
cannam@154 88 <tt>libopusfile</tt> fully supports chained files.
cannam@154 89 It will decode the first Opus stream found in each link of a chained file
cannam@154 90 (ignoring any other streams that might be concurrently multiplexed with it,
cannam@154 91 such as a video stream).
cannam@154 92
cannam@154 93 The channel count can also change between links.
cannam@154 94 If your application is not prepared to deal with this, it can use the stereo
cannam@154 95 API to ensure the audio from all links will always get decoded into a
cannam@154 96 common format.
cannam@154 97 Since <tt>libopusfile</tt> always decodes to 48&nbsp;kHz, you do not have to
cannam@154 98 worry about the sample rate changing between links (as was possible with
cannam@154 99 Vorbis).
cannam@154 100 This makes application support for chained files with <tt>libopusfile</tt>
cannam@154 101 very easy.*/
cannam@154 102
cannam@154 103 # if defined(__cplusplus)
cannam@154 104 extern "C" {
cannam@154 105 # endif
cannam@154 106
cannam@154 107 # include <stdarg.h>
cannam@154 108 # include <stdio.h>
cannam@154 109 # include <ogg/ogg.h>
cannam@154 110 # include <opus_multistream.h>
cannam@154 111
cannam@154 112 /**@cond PRIVATE*/
cannam@154 113
cannam@154 114 /*Enable special features for gcc and gcc-compatible compilers.*/
cannam@154 115 # if !defined(OP_GNUC_PREREQ)
cannam@154 116 # if defined(__GNUC__)&&defined(__GNUC_MINOR__)
cannam@154 117 # define OP_GNUC_PREREQ(_maj,_min) \
cannam@154 118 ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
cannam@154 119 # else
cannam@154 120 # define OP_GNUC_PREREQ(_maj,_min) 0
cannam@154 121 # endif
cannam@154 122 # endif
cannam@154 123
cannam@154 124 # if OP_GNUC_PREREQ(4,0)
cannam@154 125 # pragma GCC visibility push(default)
cannam@154 126 # endif
cannam@154 127
cannam@154 128 typedef struct OpusHead OpusHead;
cannam@154 129 typedef struct OpusTags OpusTags;
cannam@154 130 typedef struct OpusPictureTag OpusPictureTag;
cannam@154 131 typedef struct OpusServerInfo OpusServerInfo;
cannam@154 132 typedef struct OpusFileCallbacks OpusFileCallbacks;
cannam@154 133 typedef struct OggOpusFile OggOpusFile;
cannam@154 134
cannam@154 135 /*Warning attributes for libopusfile functions.*/
cannam@154 136 # if OP_GNUC_PREREQ(3,4)
cannam@154 137 # define OP_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
cannam@154 138 # else
cannam@154 139 # define OP_WARN_UNUSED_RESULT
cannam@154 140 # endif
cannam@154 141 # if OP_GNUC_PREREQ(3,4)
cannam@154 142 # define OP_ARG_NONNULL(_x) __attribute__((__nonnull__(_x)))
cannam@154 143 # else
cannam@154 144 # define OP_ARG_NONNULL(_x)
cannam@154 145 # endif
cannam@154 146
cannam@154 147 /**@endcond*/
cannam@154 148
cannam@154 149 /**\defgroup error_codes Error Codes*/
cannam@154 150 /*@{*/
cannam@154 151 /**\name List of possible error codes
cannam@154 152 Many of the functions in this library return a negative error code when a
cannam@154 153 function fails.
cannam@154 154 This list provides a brief explanation of the common errors.
cannam@154 155 See each individual function for more details on what a specific error code
cannam@154 156 means in that context.*/
cannam@154 157 /*@{*/
cannam@154 158
cannam@154 159 /**A request did not succeed.*/
cannam@154 160 #define OP_FALSE (-1)
cannam@154 161 /*Currently not used externally.*/
cannam@154 162 #define OP_EOF (-2)
cannam@154 163 /**There was a hole in the page sequence numbers (e.g., a page was corrupt or
cannam@154 164 missing).*/
cannam@154 165 #define OP_HOLE (-3)
cannam@154 166 /**An underlying read, seek, or tell operation failed when it should have
cannam@154 167 succeeded.*/
cannam@154 168 #define OP_EREAD (-128)
cannam@154 169 /**A <code>NULL</code> pointer was passed where one was unexpected, or an
cannam@154 170 internal memory allocation failed, or an internal library error was
cannam@154 171 encountered.*/
cannam@154 172 #define OP_EFAULT (-129)
cannam@154 173 /**The stream used a feature that is not implemented, such as an unsupported
cannam@154 174 channel family.*/
cannam@154 175 #define OP_EIMPL (-130)
cannam@154 176 /**One or more parameters to a function were invalid.*/
cannam@154 177 #define OP_EINVAL (-131)
cannam@154 178 /**A purported Ogg Opus stream did not begin with an Ogg page, a purported
cannam@154 179 header packet did not start with one of the required strings, "OpusHead" or
cannam@154 180 "OpusTags", or a link in a chained file was encountered that did not
cannam@154 181 contain any logical Opus streams.*/
cannam@154 182 #define OP_ENOTFORMAT (-132)
cannam@154 183 /**A required header packet was not properly formatted, contained illegal
cannam@154 184 values, or was missing altogether.*/
cannam@154 185 #define OP_EBADHEADER (-133)
cannam@154 186 /**The ID header contained an unrecognized version number.*/
cannam@154 187 #define OP_EVERSION (-134)
cannam@154 188 /*Currently not used at all.*/
cannam@154 189 #define OP_ENOTAUDIO (-135)
cannam@154 190 /**An audio packet failed to decode properly.
cannam@154 191 This is usually caused by a multistream Ogg packet where the durations of
cannam@154 192 the individual Opus packets contained in it are not all the same.*/
cannam@154 193 #define OP_EBADPACKET (-136)
cannam@154 194 /**We failed to find data we had seen before, or the bitstream structure was
cannam@154 195 sufficiently malformed that seeking to the target destination was
cannam@154 196 impossible.*/
cannam@154 197 #define OP_EBADLINK (-137)
cannam@154 198 /**An operation that requires seeking was requested on an unseekable stream.*/
cannam@154 199 #define OP_ENOSEEK (-138)
cannam@154 200 /**The first or last granule position of a link failed basic validity checks.*/
cannam@154 201 #define OP_EBADTIMESTAMP (-139)
cannam@154 202
cannam@154 203 /*@}*/
cannam@154 204 /*@}*/
cannam@154 205
cannam@154 206 /**\defgroup header_info Header Information*/
cannam@154 207 /*@{*/
cannam@154 208
cannam@154 209 /**The maximum number of channels in an Ogg Opus stream.*/
cannam@154 210 #define OPUS_CHANNEL_COUNT_MAX (255)
cannam@154 211
cannam@154 212 /**Ogg Opus bitstream information.
cannam@154 213 This contains the basic playback parameters for a stream, and corresponds to
cannam@154 214 the initial ID header packet of an Ogg Opus stream.*/
cannam@154 215 struct OpusHead{
cannam@154 216 /**The Ogg Opus format version, in the range 0...255.
cannam@154 217 The top 4 bits represent a "major" version, and the bottom four bits
cannam@154 218 represent backwards-compatible "minor" revisions.
cannam@154 219 The current specification describes version 1.
cannam@154 220 This library will recognize versions up through 15 as backwards compatible
cannam@154 221 with the current specification.
cannam@154 222 An earlier draft of the specification described a version 0, but the only
cannam@154 223 difference between version 1 and version 0 is that version 0 did
cannam@154 224 not specify the semantics for handling the version field.*/
cannam@154 225 int version;
cannam@154 226 /**The number of channels, in the range 1...255.*/
cannam@154 227 int channel_count;
cannam@154 228 /**The number of samples that should be discarded from the beginning of the
cannam@154 229 stream.*/
cannam@154 230 unsigned pre_skip;
cannam@154 231 /**The sampling rate of the original input.
cannam@154 232 All Opus audio is coded at 48 kHz, and should also be decoded at 48 kHz
cannam@154 233 for playback (unless the target hardware does not support this sampling
cannam@154 234 rate).
cannam@154 235 However, this field may be used to resample the audio back to the original
cannam@154 236 sampling rate, for example, when saving the output to a file.*/
cannam@154 237 opus_uint32 input_sample_rate;
cannam@154 238 /**The gain to apply to the decoded output, in dB, as a Q8 value in the range
cannam@154 239 -32768...32767.
cannam@154 240 The <tt>libopusfile</tt> API will automatically apply this gain to the
cannam@154 241 decoded output before returning it, scaling it by
cannam@154 242 <code>pow(10,output_gain/(20.0*256))</code>.
cannam@154 243 You can adjust this behavior with op_set_gain_offset().*/
cannam@154 244 int output_gain;
cannam@154 245 /**The channel mapping family, in the range 0...255.
cannam@154 246 Channel mapping family 0 covers mono or stereo in a single stream.
cannam@154 247 Channel mapping family 1 covers 1 to 8 channels in one or more streams,
cannam@154 248 using the Vorbis speaker assignments.
cannam@154 249 Channel mapping family 255 covers 1 to 255 channels in one or more
cannam@154 250 streams, but without any defined speaker assignment.*/
cannam@154 251 int mapping_family;
cannam@154 252 /**The number of Opus streams in each Ogg packet, in the range 1...255.*/
cannam@154 253 int stream_count;
cannam@154 254 /**The number of coupled Opus streams in each Ogg packet, in the range
cannam@154 255 0...127.
cannam@154 256 This must satisfy <code>0 <= coupled_count <= stream_count</code> and
cannam@154 257 <code>coupled_count + stream_count <= 255</code>.
cannam@154 258 The coupled streams appear first, before all uncoupled streams, in an Ogg
cannam@154 259 Opus packet.*/
cannam@154 260 int coupled_count;
cannam@154 261 /**The mapping from coded stream channels to output channels.
cannam@154 262 Let <code>index=mapping[k]</code> be the value for channel <code>k</code>.
cannam@154 263 If <code>index<2*coupled_count</code>, then it refers to the left channel
cannam@154 264 from stream <code>(index/2)</code> if even, and the right channel from
cannam@154 265 stream <code>(index/2)</code> if odd.
cannam@154 266 Otherwise, it refers to the output of the uncoupled stream
cannam@154 267 <code>(index-coupled_count)</code>.*/
cannam@154 268 unsigned char mapping[OPUS_CHANNEL_COUNT_MAX];
cannam@154 269 };
cannam@154 270
cannam@154 271 /**The metadata from an Ogg Opus stream.
cannam@154 272
cannam@154 273 This structure holds the in-stream metadata corresponding to the 'comment'
cannam@154 274 header packet of an Ogg Opus stream.
cannam@154 275 The comment header is meant to be used much like someone jotting a quick
cannam@154 276 note on the label of a CD.
cannam@154 277 It should be a short, to the point text note that can be more than a couple
cannam@154 278 words, but not more than a short paragraph.
cannam@154 279
cannam@154 280 The metadata is stored as a series of (tag, value) pairs, in length-encoded
cannam@154 281 string vectors, using the same format as Vorbis (without the final "framing
cannam@154 282 bit"), Theora, and Speex, except for the packet header.
cannam@154 283 The first occurrence of the '=' character delimits the tag and value.
cannam@154 284 A particular tag may occur more than once, and order is significant.
cannam@154 285 The character set encoding for the strings is always UTF-8, but the tag
cannam@154 286 names are limited to ASCII, and treated as case-insensitive.
cannam@154 287 See <a href="http://www.xiph.org/vorbis/doc/v-comment.html">the Vorbis
cannam@154 288 comment header specification</a> for details.
cannam@154 289
cannam@154 290 In filling in this structure, <tt>libopusfile</tt> will null-terminate the
cannam@154 291 #user_comments strings for safety.
cannam@154 292 However, the bitstream format itself treats them as 8-bit clean vectors,
cannam@154 293 possibly containing NUL characters, so the #comment_lengths array should be
cannam@154 294 treated as their authoritative length.
cannam@154 295
cannam@154 296 This structure is binary and source-compatible with a
cannam@154 297 <code>vorbis_comment</code>, and pointers to it may be freely cast to
cannam@154 298 <code>vorbis_comment</code> pointers, and vice versa.
cannam@154 299 It is provided as a separate type to avoid introducing a compile-time
cannam@154 300 dependency on the libvorbis headers.*/
cannam@154 301 struct OpusTags{
cannam@154 302 /**The array of comment string vectors.*/
cannam@154 303 char **user_comments;
cannam@154 304 /**An array of the corresponding length of each vector, in bytes.*/
cannam@154 305 int *comment_lengths;
cannam@154 306 /**The total number of comment streams.*/
cannam@154 307 int comments;
cannam@154 308 /**The null-terminated vendor string.
cannam@154 309 This identifies the software used to encode the stream.*/
cannam@154 310 char *vendor;
cannam@154 311 };
cannam@154 312
cannam@154 313 /**\name Picture tag image formats*/
cannam@154 314 /*@{*/
cannam@154 315
cannam@154 316 /**The MIME type was not recognized, or the image data did not match the
cannam@154 317 declared MIME type.*/
cannam@154 318 #define OP_PIC_FORMAT_UNKNOWN (-1)
cannam@154 319 /**The MIME type indicates the image data is really a URL.*/
cannam@154 320 #define OP_PIC_FORMAT_URL (0)
cannam@154 321 /**The image is a JPEG.*/
cannam@154 322 #define OP_PIC_FORMAT_JPEG (1)
cannam@154 323 /**The image is a PNG.*/
cannam@154 324 #define OP_PIC_FORMAT_PNG (2)
cannam@154 325 /**The image is a GIF.*/
cannam@154 326 #define OP_PIC_FORMAT_GIF (3)
cannam@154 327
cannam@154 328 /*@}*/
cannam@154 329
cannam@154 330 /**The contents of a METADATA_BLOCK_PICTURE tag.*/
cannam@154 331 struct OpusPictureTag{
cannam@154 332 /**The picture type according to the ID3v2 APIC frame:
cannam@154 333 <ol start="0">
cannam@154 334 <li>Other</li>
cannam@154 335 <li>32x32 pixels 'file icon' (PNG only)</li>
cannam@154 336 <li>Other file icon</li>
cannam@154 337 <li>Cover (front)</li>
cannam@154 338 <li>Cover (back)</li>
cannam@154 339 <li>Leaflet page</li>
cannam@154 340 <li>Media (e.g. label side of CD)</li>
cannam@154 341 <li>Lead artist/lead performer/soloist</li>
cannam@154 342 <li>Artist/performer</li>
cannam@154 343 <li>Conductor</li>
cannam@154 344 <li>Band/Orchestra</li>
cannam@154 345 <li>Composer</li>
cannam@154 346 <li>Lyricist/text writer</li>
cannam@154 347 <li>Recording Location</li>
cannam@154 348 <li>During recording</li>
cannam@154 349 <li>During performance</li>
cannam@154 350 <li>Movie/video screen capture</li>
cannam@154 351 <li>A bright colored fish</li>
cannam@154 352 <li>Illustration</li>
cannam@154 353 <li>Band/artist logotype</li>
cannam@154 354 <li>Publisher/Studio logotype</li>
cannam@154 355 </ol>
cannam@154 356 Others are reserved and should not be used.
cannam@154 357 There may only be one each of picture type 1 and 2 in a file.*/
cannam@154 358 opus_int32 type;
cannam@154 359 /**The MIME type of the picture, in printable ASCII characters 0x20-0x7E.
cannam@154 360 The MIME type may also be <code>"-->"</code> to signify that the data part
cannam@154 361 is a URL pointing to the picture instead of the picture data itself.
cannam@154 362 In this case, a terminating NUL is appended to the URL string in #data,
cannam@154 363 but #data_length is set to the length of the string excluding that
cannam@154 364 terminating NUL.*/
cannam@154 365 char *mime_type;
cannam@154 366 /**The description of the picture, in UTF-8.*/
cannam@154 367 char *description;
cannam@154 368 /**The width of the picture in pixels.*/
cannam@154 369 opus_uint32 width;
cannam@154 370 /**The height of the picture in pixels.*/
cannam@154 371 opus_uint32 height;
cannam@154 372 /**The color depth of the picture in bits-per-pixel (<em>not</em>
cannam@154 373 bits-per-channel).*/
cannam@154 374 opus_uint32 depth;
cannam@154 375 /**For indexed-color pictures (e.g., GIF), the number of colors used, or 0
cannam@154 376 for non-indexed pictures.*/
cannam@154 377 opus_uint32 colors;
cannam@154 378 /**The length of the picture data in bytes.*/
cannam@154 379 opus_uint32 data_length;
cannam@154 380 /**The binary picture data.*/
cannam@154 381 unsigned char *data;
cannam@154 382 /**The format of the picture data, if known.
cannam@154 383 One of
cannam@154 384 <ul>
cannam@154 385 <li>#OP_PIC_FORMAT_UNKNOWN,</li>
cannam@154 386 <li>#OP_PIC_FORMAT_URL,</li>
cannam@154 387 <li>#OP_PIC_FORMAT_JPEG,</li>
cannam@154 388 <li>#OP_PIC_FORMAT_PNG, or</li>
cannam@154 389 <li>#OP_PIC_FORMAT_GIF.</li>
cannam@154 390 </ul>*/
cannam@154 391 int format;
cannam@154 392 };
cannam@154 393
cannam@154 394 /**\name Functions for manipulating header data
cannam@154 395
cannam@154 396 These functions manipulate the #OpusHead and #OpusTags structures,
cannam@154 397 which describe the audio parameters and tag-value metadata, respectively.
cannam@154 398 These can be used to query the headers returned by <tt>libopusfile</tt>, or
cannam@154 399 to parse Opus headers from sources other than an Ogg Opus stream, provided
cannam@154 400 they use the same format.*/
cannam@154 401 /*@{*/
cannam@154 402
cannam@154 403 /**Parses the contents of the ID header packet of an Ogg Opus stream.
cannam@154 404 \param[out] _head Returns the contents of the parsed packet.
cannam@154 405 The contents of this structure are untouched on error.
cannam@154 406 This may be <code>NULL</code> to merely test the header
cannam@154 407 for validity.
cannam@154 408 \param[in] _data The contents of the ID header packet.
cannam@154 409 \param _len The number of bytes of data in the ID header packet.
cannam@154 410 \return 0 on success or a negative value on error.
cannam@154 411 \retval #OP_ENOTFORMAT If the data does not start with the "OpusHead"
cannam@154 412 string.
cannam@154 413 \retval #OP_EVERSION If the version field signaled a version this library
cannam@154 414 does not know how to parse.
cannam@154 415 \retval #OP_EIMPL If the channel mapping family was 255, which general
cannam@154 416 purpose players should not attempt to play.
cannam@154 417 \retval #OP_EBADHEADER If the contents of the packet otherwise violate the
cannam@154 418 Ogg Opus specification:
cannam@154 419 <ul>
cannam@154 420 <li>Insufficient data,</li>
cannam@154 421 <li>Too much data for the known minor versions,</li>
cannam@154 422 <li>An unrecognized channel mapping family,</li>
cannam@154 423 <li>Zero channels or too many channels,</li>
cannam@154 424 <li>Zero coded streams,</li>
cannam@154 425 <li>Too many coupled streams, or</li>
cannam@154 426 <li>An invalid channel mapping index.</li>
cannam@154 427 </ul>*/
cannam@154 428 OP_WARN_UNUSED_RESULT int opus_head_parse(OpusHead *_head,
cannam@154 429 const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2);
cannam@154 430
cannam@154 431 /**Converts a granule position to a sample offset for a given Ogg Opus stream.
cannam@154 432 The sample offset is simply <code>_gp-_head->pre_skip</code>.
cannam@154 433 Granule position values smaller than OpusHead#pre_skip correspond to audio
cannam@154 434 that should never be played, and thus have no associated sample offset.
cannam@154 435 This function returns -1 for such values.
cannam@154 436 This function also correctly handles extremely large granule positions,
cannam@154 437 which may have wrapped around to a negative number when stored in a signed
cannam@154 438 ogg_int64_t value.
cannam@154 439 \param _head The #OpusHead information from the ID header of the stream.
cannam@154 440 \param _gp The granule position to convert.
cannam@154 441 \return The sample offset associated with the given granule position
cannam@154 442 (counting at a 48 kHz sampling rate), or the special value -1 on
cannam@154 443 error (i.e., the granule position was smaller than the pre-skip
cannam@154 444 amount).*/
cannam@154 445 ogg_int64_t opus_granule_sample(const OpusHead *_head,ogg_int64_t _gp)
cannam@154 446 OP_ARG_NONNULL(1);
cannam@154 447
cannam@154 448 /**Parses the contents of the 'comment' header packet of an Ogg Opus stream.
cannam@154 449 \param[out] _tags An uninitialized #OpusTags structure.
cannam@154 450 This returns the contents of the parsed packet.
cannam@154 451 The contents of this structure are untouched on error.
cannam@154 452 This may be <code>NULL</code> to merely test the header
cannam@154 453 for validity.
cannam@154 454 \param[in] _data The contents of the 'comment' header packet.
cannam@154 455 \param _len The number of bytes of data in the 'info' header packet.
cannam@154 456 \retval 0 Success.
cannam@154 457 \retval #OP_ENOTFORMAT If the data does not start with the "OpusTags"
cannam@154 458 string.
cannam@154 459 \retval #OP_EBADHEADER If the contents of the packet otherwise violate the
cannam@154 460 Ogg Opus specification.
cannam@154 461 \retval #OP_EFAULT If there wasn't enough memory to store the tags.*/
cannam@154 462 OP_WARN_UNUSED_RESULT int opus_tags_parse(OpusTags *_tags,
cannam@154 463 const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2);
cannam@154 464
cannam@154 465 /**Performs a deep copy of an #OpusTags structure.
cannam@154 466 \param _dst The #OpusTags structure to copy into.
cannam@154 467 If this function fails, the contents of this structure remain
cannam@154 468 untouched.
cannam@154 469 \param _src The #OpusTags structure to copy from.
cannam@154 470 \retval 0 Success.
cannam@154 471 \retval #OP_EFAULT If there wasn't enough memory to copy the tags.*/
cannam@154 472 int opus_tags_copy(OpusTags *_dst,const OpusTags *_src) OP_ARG_NONNULL(1);
cannam@154 473
cannam@154 474 /**Initializes an #OpusTags structure.
cannam@154 475 This should be called on a freshly allocated #OpusTags structure before
cannam@154 476 attempting to use it.
cannam@154 477 \param _tags The #OpusTags structure to initialize.*/
cannam@154 478 void opus_tags_init(OpusTags *_tags) OP_ARG_NONNULL(1);
cannam@154 479
cannam@154 480 /**Add a (tag, value) pair to an initialized #OpusTags structure.
cannam@154 481 \note Neither opus_tags_add() nor opus_tags_add_comment() support values
cannam@154 482 containing embedded NULs, although the bitstream format does support them.
cannam@154 483 To add such tags, you will need to manipulate the #OpusTags structure
cannam@154 484 directly.
cannam@154 485 \param _tags The #OpusTags structure to add the (tag, value) pair to.
cannam@154 486 \param _tag A NUL-terminated, case-insensitive, ASCII string containing
cannam@154 487 the tag to add (without an '=' character).
cannam@154 488 \param _value A NUL-terminated UTF-8 containing the corresponding value.
cannam@154 489 \return 0 on success, or a negative value on failure.
cannam@154 490 \retval #OP_EFAULT An internal memory allocation failed.*/
cannam@154 491 int opus_tags_add(OpusTags *_tags,const char *_tag,const char *_value)
cannam@154 492 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) OP_ARG_NONNULL(3);
cannam@154 493
cannam@154 494 /**Add a comment to an initialized #OpusTags structure.
cannam@154 495 \note Neither opus_tags_add_comment() nor opus_tags_add() support comments
cannam@154 496 containing embedded NULs, although the bitstream format does support them.
cannam@154 497 To add such tags, you will need to manipulate the #OpusTags structure
cannam@154 498 directly.
cannam@154 499 \param _tags The #OpusTags structure to add the comment to.
cannam@154 500 \param _comment A NUL-terminated UTF-8 string containing the comment in
cannam@154 501 "TAG=value" form.
cannam@154 502 \return 0 on success, or a negative value on failure.
cannam@154 503 \retval #OP_EFAULT An internal memory allocation failed.*/
cannam@154 504 int opus_tags_add_comment(OpusTags *_tags,const char *_comment)
cannam@154 505 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
cannam@154 506
cannam@154 507 /**Replace the binary suffix data at the end of the packet (if any).
cannam@154 508 \param _tags An initialized #OpusTags structure.
cannam@154 509 \param _data A buffer of binary data to append after the encoded user
cannam@154 510 comments.
cannam@154 511 The least significant bit of the first byte of this data must
cannam@154 512 be set (to ensure the data is preserved by other editors).
cannam@154 513 \param _len The number of bytes of binary data to append.
cannam@154 514 This may be zero to remove any existing binary suffix data.
cannam@154 515 \return 0 on success, or a negative value on error.
cannam@154 516 \retval #OP_EINVAL \a _len was negative, or \a _len was positive but
cannam@154 517 \a _data was <code>NULL</code> or the least significant
cannam@154 518 bit of the first byte was not set.
cannam@154 519 \retval #OP_EFAULT An internal memory allocation failed.*/
cannam@154 520 int opus_tags_set_binary_suffix(OpusTags *_tags,
cannam@154 521 const unsigned char *_data,int _len) OP_ARG_NONNULL(1);
cannam@154 522
cannam@154 523 /**Look up a comment value by its tag.
cannam@154 524 \param _tags An initialized #OpusTags structure.
cannam@154 525 \param _tag The tag to look up.
cannam@154 526 \param _count The instance of the tag.
cannam@154 527 The same tag can appear multiple times, each with a distinct
cannam@154 528 value, so an index is required to retrieve them all.
cannam@154 529 The order in which these values appear is significant and
cannam@154 530 should be preserved.
cannam@154 531 Use opus_tags_query_count() to get the legal range for the
cannam@154 532 \a _count parameter.
cannam@154 533 \return A pointer to the queried tag's value.
cannam@154 534 This points directly to data in the #OpusTags structure.
cannam@154 535 It should not be modified or freed by the application, and
cannam@154 536 modifications to the structure may invalidate the pointer.
cannam@154 537 \retval NULL If no matching tag is found.*/
cannam@154 538 const char *opus_tags_query(const OpusTags *_tags,const char *_tag,int _count)
cannam@154 539 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
cannam@154 540
cannam@154 541 /**Look up the number of instances of a tag.
cannam@154 542 Call this first when querying for a specific tag and then iterate over the
cannam@154 543 number of instances with separate calls to opus_tags_query() to retrieve
cannam@154 544 all the values for that tag in order.
cannam@154 545 \param _tags An initialized #OpusTags structure.
cannam@154 546 \param _tag The tag to look up.
cannam@154 547 \return The number of instances of this particular tag.*/
cannam@154 548 int opus_tags_query_count(const OpusTags *_tags,const char *_tag)
cannam@154 549 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
cannam@154 550
cannam@154 551 /**Retrieve the binary suffix data at the end of the packet (if any).
cannam@154 552 \param _tags An initialized #OpusTags structure.
cannam@154 553 \param[out] _len Returns the number of bytes of binary suffix data returned.
cannam@154 554 \return A pointer to the binary suffix data, or <code>NULL</code> if none
cannam@154 555 was present.*/
cannam@154 556 const unsigned char *opus_tags_get_binary_suffix(const OpusTags *_tags,
cannam@154 557 int *_len) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
cannam@154 558
cannam@154 559 /**Get the album gain from an R128_ALBUM_GAIN tag, if one was specified.
cannam@154 560 This searches for the first R128_ALBUM_GAIN tag with a valid signed,
cannam@154 561 16-bit decimal integer value and returns the value.
cannam@154 562 This routine is exposed merely for convenience for applications which wish
cannam@154 563 to do something special with the album gain (i.e., display it).
cannam@154 564 If you simply wish to apply the album gain instead of the header gain, you
cannam@154 565 can use op_set_gain_offset() with an #OP_ALBUM_GAIN type and no offset.
cannam@154 566 \param _tags An initialized #OpusTags structure.
cannam@154 567 \param[out] _gain_q8 The album gain, in 1/256ths of a dB.
cannam@154 568 This will lie in the range [-32768,32767], and should
cannam@154 569 be applied in <em>addition</em> to the header gain.
cannam@154 570 On error, no value is returned, and the previous
cannam@154 571 contents remain unchanged.
cannam@154 572 \return 0 on success, or a negative value on error.
cannam@154 573 \retval #OP_FALSE There was no album gain available in the given tags.*/
cannam@154 574 int opus_tags_get_album_gain(const OpusTags *_tags,int *_gain_q8)
cannam@154 575 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
cannam@154 576
cannam@154 577 /**Get the track gain from an R128_TRACK_GAIN tag, if one was specified.
cannam@154 578 This searches for the first R128_TRACK_GAIN tag with a valid signed,
cannam@154 579 16-bit decimal integer value and returns the value.
cannam@154 580 This routine is exposed merely for convenience for applications which wish
cannam@154 581 to do something special with the track gain (i.e., display it).
cannam@154 582 If you simply wish to apply the track gain instead of the header gain, you
cannam@154 583 can use op_set_gain_offset() with an #OP_TRACK_GAIN type and no offset.
cannam@154 584 \param _tags An initialized #OpusTags structure.
cannam@154 585 \param[out] _gain_q8 The track gain, in 1/256ths of a dB.
cannam@154 586 This will lie in the range [-32768,32767], and should
cannam@154 587 be applied in <em>addition</em> to the header gain.
cannam@154 588 On error, no value is returned, and the previous
cannam@154 589 contents remain unchanged.
cannam@154 590 \return 0 on success, or a negative value on error.
cannam@154 591 \retval #OP_FALSE There was no track gain available in the given tags.*/
cannam@154 592 int opus_tags_get_track_gain(const OpusTags *_tags,int *_gain_q8)
cannam@154 593 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
cannam@154 594
cannam@154 595 /**Clears the #OpusTags structure.
cannam@154 596 This should be called on an #OpusTags structure after it is no longer
cannam@154 597 needed.
cannam@154 598 It will free all memory used by the structure members.
cannam@154 599 \param _tags The #OpusTags structure to clear.*/
cannam@154 600 void opus_tags_clear(OpusTags *_tags) OP_ARG_NONNULL(1);
cannam@154 601
cannam@154 602 /**Check if \a _comment is an instance of a \a _tag_name tag.
cannam@154 603 \see opus_tagncompare
cannam@154 604 \param _tag_name A NUL-terminated, case-insensitive, ASCII string containing
cannam@154 605 the name of the tag to check for (without the terminating
cannam@154 606 '=' character).
cannam@154 607 \param _comment The comment string to check.
cannam@154 608 \return An integer less than, equal to, or greater than zero if \a _comment
cannam@154 609 is found respectively, to be less than, to match, or be greater
cannam@154 610 than a "tag=value" string whose tag matches \a _tag_name.*/
cannam@154 611 int opus_tagcompare(const char *_tag_name,const char *_comment);
cannam@154 612
cannam@154 613 /**Check if \a _comment is an instance of a \a _tag_name tag.
cannam@154 614 This version is slightly more efficient than opus_tagcompare() if the length
cannam@154 615 of the tag name is already known (e.g., because it is a constant).
cannam@154 616 \see opus_tagcompare
cannam@154 617 \param _tag_name A case-insensitive ASCII string containing the name of the
cannam@154 618 tag to check for (without the terminating '=' character).
cannam@154 619 \param _tag_len The number of characters in the tag name.
cannam@154 620 This must be non-negative.
cannam@154 621 \param _comment The comment string to check.
cannam@154 622 \return An integer less than, equal to, or greater than zero if \a _comment
cannam@154 623 is found respectively, to be less than, to match, or be greater
cannam@154 624 than a "tag=value" string whose tag matches the first \a _tag_len
cannam@154 625 characters of \a _tag_name.*/
cannam@154 626 int opus_tagncompare(const char *_tag_name,int _tag_len,const char *_comment);
cannam@154 627
cannam@154 628 /**Parse a single METADATA_BLOCK_PICTURE tag.
cannam@154 629 This decodes the BASE64-encoded content of the tag and returns a structure
cannam@154 630 with the MIME type, description, image parameters (if known), and the
cannam@154 631 compressed image data.
cannam@154 632 If the MIME type indicates the presence of an image format we recognize
cannam@154 633 (JPEG, PNG, or GIF) and the actual image data contains the magic signature
cannam@154 634 associated with that format, then the OpusPictureTag::format field will be
cannam@154 635 set to the corresponding format.
cannam@154 636 This is provided as a convenience to avoid requiring applications to parse
cannam@154 637 the MIME type and/or do their own format detection for the commonly used
cannam@154 638 formats.
cannam@154 639 In this case, we also attempt to extract the image parameters directly from
cannam@154 640 the image data (overriding any that were present in the tag, which the
cannam@154 641 specification says applications are not meant to rely on).
cannam@154 642 The application must still provide its own support for actually decoding the
cannam@154 643 image data and, if applicable, retrieving that data from URLs.
cannam@154 644 \param[out] _pic Returns the parsed picture data.
cannam@154 645 No sanitation is done on the type, MIME type, or
cannam@154 646 description fields, so these might return invalid values.
cannam@154 647 The contents of this structure are left unmodified on
cannam@154 648 failure.
cannam@154 649 \param _tag The METADATA_BLOCK_PICTURE tag contents.
cannam@154 650 The leading "METADATA_BLOCK_PICTURE=" portion is optional,
cannam@154 651 to allow the function to be used on either directly on the
cannam@154 652 values in OpusTags::user_comments or on the return value
cannam@154 653 of opus_tags_query().
cannam@154 654 \return 0 on success or a negative value on error.
cannam@154 655 \retval #OP_ENOTFORMAT The METADATA_BLOCK_PICTURE contents were not valid.
cannam@154 656 \retval #OP_EFAULT There was not enough memory to store the picture tag
cannam@154 657 contents.*/
cannam@154 658 OP_WARN_UNUSED_RESULT int opus_picture_tag_parse(OpusPictureTag *_pic,
cannam@154 659 const char *_tag) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
cannam@154 660
cannam@154 661 /**Initializes an #OpusPictureTag structure.
cannam@154 662 This should be called on a freshly allocated #OpusPictureTag structure
cannam@154 663 before attempting to use it.
cannam@154 664 \param _pic The #OpusPictureTag structure to initialize.*/
cannam@154 665 void opus_picture_tag_init(OpusPictureTag *_pic) OP_ARG_NONNULL(1);
cannam@154 666
cannam@154 667 /**Clears the #OpusPictureTag structure.
cannam@154 668 This should be called on an #OpusPictureTag structure after it is no longer
cannam@154 669 needed.
cannam@154 670 It will free all memory used by the structure members.
cannam@154 671 \param _pic The #OpusPictureTag structure to clear.*/
cannam@154 672 void opus_picture_tag_clear(OpusPictureTag *_pic) OP_ARG_NONNULL(1);
cannam@154 673
cannam@154 674 /*@}*/
cannam@154 675
cannam@154 676 /*@}*/
cannam@154 677
cannam@154 678 /**\defgroup url_options URL Reading Options*/
cannam@154 679 /*@{*/
cannam@154 680 /**\name URL reading options
cannam@154 681 Options for op_url_stream_create() and associated functions.
cannam@154 682 These allow you to provide proxy configuration parameters, skip SSL
cannam@154 683 certificate checks, etc.
cannam@154 684 Options are processed in order, and if the same option is passed multiple
cannam@154 685 times, only the value specified by the last occurrence has an effect
cannam@154 686 (unless otherwise specified).
cannam@154 687 They may be expanded in the future.*/
cannam@154 688 /*@{*/
cannam@154 689
cannam@154 690 /**@cond PRIVATE*/
cannam@154 691
cannam@154 692 /*These are the raw numbers used to define the request codes.
cannam@154 693 They should not be used directly.*/
cannam@154 694 #define OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST (6464)
cannam@154 695 #define OP_HTTP_PROXY_HOST_REQUEST (6528)
cannam@154 696 #define OP_HTTP_PROXY_PORT_REQUEST (6592)
cannam@154 697 #define OP_HTTP_PROXY_USER_REQUEST (6656)
cannam@154 698 #define OP_HTTP_PROXY_PASS_REQUEST (6720)
cannam@154 699 #define OP_GET_SERVER_INFO_REQUEST (6784)
cannam@154 700
cannam@154 701 #define OP_URL_OPT(_request) ((_request)+(char *)0)
cannam@154 702
cannam@154 703 /*These macros trigger compilation errors or warnings if the wrong types are
cannam@154 704 provided to one of the URL options.*/
cannam@154 705 #define OP_CHECK_INT(_x) ((void)((_x)==(opus_int32)0),(opus_int32)(_x))
cannam@154 706 #define OP_CHECK_CONST_CHAR_PTR(_x) ((_x)+((_x)-(const char *)(_x)))
cannam@154 707 #define OP_CHECK_SERVER_INFO_PTR(_x) ((_x)+((_x)-(OpusServerInfo *)(_x)))
cannam@154 708
cannam@154 709 /**@endcond*/
cannam@154 710
cannam@154 711 /**HTTP/Shoutcast/Icecast server information associated with a URL.*/
cannam@154 712 struct OpusServerInfo{
cannam@154 713 /**The name of the server (icy-name/ice-name).
cannam@154 714 This is <code>NULL</code> if there was no <code>icy-name</code> or
cannam@154 715 <code>ice-name</code> header.*/
cannam@154 716 char *name;
cannam@154 717 /**A short description of the server (icy-description/ice-description).
cannam@154 718 This is <code>NULL</code> if there was no <code>icy-description</code> or
cannam@154 719 <code>ice-description</code> header.*/
cannam@154 720 char *description;
cannam@154 721 /**The genre the server falls under (icy-genre/ice-genre).
cannam@154 722 This is <code>NULL</code> if there was no <code>icy-genre</code> or
cannam@154 723 <code>ice-genre</code> header.*/
cannam@154 724 char *genre;
cannam@154 725 /**The homepage for the server (icy-url/ice-url).
cannam@154 726 This is <code>NULL</code> if there was no <code>icy-url</code> or
cannam@154 727 <code>ice-url</code> header.*/
cannam@154 728 char *url;
cannam@154 729 /**The software used by the origin server (Server).
cannam@154 730 This is <code>NULL</code> if there was no <code>Server</code> header.*/
cannam@154 731 char *server;
cannam@154 732 /**The media type of the entity sent to the recepient (Content-Type).
cannam@154 733 This is <code>NULL</code> if there was no <code>Content-Type</code>
cannam@154 734 header.*/
cannam@154 735 char *content_type;
cannam@154 736 /**The nominal stream bitrate in kbps (icy-br/ice-bitrate).
cannam@154 737 This is <code>-1</code> if there was no <code>icy-br</code> or
cannam@154 738 <code>ice-bitrate</code> header.*/
cannam@154 739 opus_int32 bitrate_kbps;
cannam@154 740 /**Flag indicating whether the server is public (<code>1</code>) or not
cannam@154 741 (<code>0</code>) (icy-pub/ice-public).
cannam@154 742 This is <code>-1</code> if there was no <code>icy-pub</code> or
cannam@154 743 <code>ice-public</code> header.*/
cannam@154 744 int is_public;
cannam@154 745 /**Flag indicating whether the server is using HTTPS instead of HTTP.
cannam@154 746 This is <code>0</code> unless HTTPS is being used.
cannam@154 747 This may not match the protocol used in the original URL if there were
cannam@154 748 redirections.*/
cannam@154 749 int is_ssl;
cannam@154 750 };
cannam@154 751
cannam@154 752 /**Initializes an #OpusServerInfo structure.
cannam@154 753 All fields are set as if the corresponding header was not available.
cannam@154 754 \param _info The #OpusServerInfo structure to initialize.
cannam@154 755 \note If you use this function, you must link against <tt>libopusurl</tt>.*/
cannam@154 756 void opus_server_info_init(OpusServerInfo *_info) OP_ARG_NONNULL(1);
cannam@154 757
cannam@154 758 /**Clears the #OpusServerInfo structure.
cannam@154 759 This should be called on an #OpusServerInfo structure after it is no longer
cannam@154 760 needed.
cannam@154 761 It will free all memory used by the structure members.
cannam@154 762 \param _info The #OpusServerInfo structure to clear.
cannam@154 763 \note If you use this function, you must link against <tt>libopusurl</tt>.*/
cannam@154 764 void opus_server_info_clear(OpusServerInfo *_info) OP_ARG_NONNULL(1);
cannam@154 765
cannam@154 766 /**Skip the certificate check when connecting via TLS/SSL (https).
cannam@154 767 \param _b <code>opus_int32</code>: Whether or not to skip the certificate
cannam@154 768 check.
cannam@154 769 The check will be skipped if \a _b is non-zero, and will not be
cannam@154 770 skipped if \a _b is zero.
cannam@154 771 \hideinitializer*/
cannam@154 772 #define OP_SSL_SKIP_CERTIFICATE_CHECK(_b) \
cannam@154 773 OP_URL_OPT(OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST),OP_CHECK_INT(_b)
cannam@154 774
cannam@154 775 /**Proxy connections through the given host.
cannam@154 776 If no port is specified via #OP_HTTP_PROXY_PORT, the port number defaults
cannam@154 777 to 8080 (http-alt).
cannam@154 778 All proxy parameters are ignored for non-http and non-https URLs.
cannam@154 779 \param _host <code>const char *</code>: The proxy server hostname.
cannam@154 780 This may be <code>NULL</code> to disable the use of a proxy
cannam@154 781 server.
cannam@154 782 \hideinitializer*/
cannam@154 783 #define OP_HTTP_PROXY_HOST(_host) \
cannam@154 784 OP_URL_OPT(OP_HTTP_PROXY_HOST_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host)
cannam@154 785
cannam@154 786 /**Use the given port when proxying connections.
cannam@154 787 This option only has an effect if #OP_HTTP_PROXY_HOST is specified with a
cannam@154 788 non-<code>NULL</code> \a _host.
cannam@154 789 If this option is not provided, the proxy port number defaults to 8080
cannam@154 790 (http-alt).
cannam@154 791 All proxy parameters are ignored for non-http and non-https URLs.
cannam@154 792 \param _port <code>opus_int32</code>: The proxy server port.
cannam@154 793 This must be in the range 0...65535 (inclusive), or the
cannam@154 794 URL function this is passed to will fail.
cannam@154 795 \hideinitializer*/
cannam@154 796 #define OP_HTTP_PROXY_PORT(_port) \
cannam@154 797 OP_URL_OPT(OP_HTTP_PROXY_PORT_REQUEST),OP_CHECK_INT(_port)
cannam@154 798
cannam@154 799 /**Use the given user name for authentication when proxying connections.
cannam@154 800 All proxy parameters are ignored for non-http and non-https URLs.
cannam@154 801 \param _user const char *: The proxy server user name.
cannam@154 802 This may be <code>NULL</code> to disable proxy
cannam@154 803 authentication.
cannam@154 804 A non-<code>NULL</code> value only has an effect
cannam@154 805 if #OP_HTTP_PROXY_HOST and #OP_HTTP_PROXY_PASS
cannam@154 806 are also specified with non-<code>NULL</code>
cannam@154 807 arguments.
cannam@154 808 \hideinitializer*/
cannam@154 809 #define OP_HTTP_PROXY_USER(_user) \
cannam@154 810 OP_URL_OPT(OP_HTTP_PROXY_USER_REQUEST),OP_CHECK_CONST_CHAR_PTR(_user)
cannam@154 811
cannam@154 812 /**Use the given password for authentication when proxying connections.
cannam@154 813 All proxy parameters are ignored for non-http and non-https URLs.
cannam@154 814 \param _pass const char *: The proxy server password.
cannam@154 815 This may be <code>NULL</code> to disable proxy
cannam@154 816 authentication.
cannam@154 817 A non-<code>NULL</code> value only has an effect
cannam@154 818 if #OP_HTTP_PROXY_HOST and #OP_HTTP_PROXY_USER
cannam@154 819 are also specified with non-<code>NULL</code>
cannam@154 820 arguments.
cannam@154 821 \hideinitializer*/
cannam@154 822 #define OP_HTTP_PROXY_PASS(_pass) \
cannam@154 823 OP_URL_OPT(OP_HTTP_PROXY_PASS_REQUEST),OP_CHECK_CONST_CHAR_PTR(_pass)
cannam@154 824
cannam@154 825 /**Parse information about the streaming server (if any) and return it.
cannam@154 826 Very little validation is done.
cannam@154 827 In particular, OpusServerInfo::url may not be a valid URL,
cannam@154 828 OpusServerInfo::bitrate_kbps may not really be in kbps, and
cannam@154 829 OpusServerInfo::content_type may not be a valid MIME type.
cannam@154 830 The character set of the string fields is not specified anywhere, and should
cannam@154 831 not be assumed to be valid UTF-8.
cannam@154 832 \param _info OpusServerInfo *: Returns information about the server.
cannam@154 833 If there is any error opening the stream, the
cannam@154 834 contents of this structure remain
cannam@154 835 unmodified.
cannam@154 836 On success, fills in the structure with the
cannam@154 837 server information that was available, if
cannam@154 838 any.
cannam@154 839 After a successful return, the contents of
cannam@154 840 this structure should be freed by calling
cannam@154 841 opus_server_info_clear().
cannam@154 842 \hideinitializer*/
cannam@154 843 #define OP_GET_SERVER_INFO(_info) \
cannam@154 844 OP_URL_OPT(OP_GET_SERVER_INFO_REQUEST),OP_CHECK_SERVER_INFO_PTR(_info)
cannam@154 845
cannam@154 846 /*@}*/
cannam@154 847 /*@}*/
cannam@154 848
cannam@154 849 /**\defgroup stream_callbacks Abstract Stream Reading Interface*/
cannam@154 850 /*@{*/
cannam@154 851 /**\name Functions for reading from streams
cannam@154 852 These functions define the interface used to read from and seek in a stream
cannam@154 853 of data.
cannam@154 854 A stream does not need to implement seeking, but the decoder will not be
cannam@154 855 able to seek if it does not do so.
cannam@154 856 These functions also include some convenience routines for working with
cannam@154 857 standard <code>FILE</code> pointers, complete streams stored in a single
cannam@154 858 block of memory, or URLs.*/
cannam@154 859 /*@{*/
cannam@154 860
cannam@154 861 /**Reads up to \a _nbytes bytes of data from \a _stream.
cannam@154 862 \param _stream The stream to read from.
cannam@154 863 \param[out] _ptr The buffer to store the data in.
cannam@154 864 \param _nbytes The maximum number of bytes to read.
cannam@154 865 This function may return fewer, though it will not
cannam@154 866 return zero unless it reaches end-of-file.
cannam@154 867 \return The number of bytes successfully read, or a negative value on
cannam@154 868 error.*/
cannam@154 869 typedef int (*op_read_func)(void *_stream,unsigned char *_ptr,int _nbytes);
cannam@154 870
cannam@154 871 /**Sets the position indicator for \a _stream.
cannam@154 872 The new position, measured in bytes, is obtained by adding \a _offset
cannam@154 873 bytes to the position specified by \a _whence.
cannam@154 874 If \a _whence is set to <code>SEEK_SET</code>, <code>SEEK_CUR</code>, or
cannam@154 875 <code>SEEK_END</code>, the offset is relative to the start of the stream,
cannam@154 876 the current position indicator, or end-of-file, respectively.
cannam@154 877 \retval 0 Success.
cannam@154 878 \retval -1 Seeking is not supported or an error occurred.
cannam@154 879 <code>errno</code> need not be set.*/
cannam@154 880 typedef int (*op_seek_func)(void *_stream,opus_int64 _offset,int _whence);
cannam@154 881
cannam@154 882 /**Obtains the current value of the position indicator for \a _stream.
cannam@154 883 \return The current position indicator.*/
cannam@154 884 typedef opus_int64 (*op_tell_func)(void *_stream);
cannam@154 885
cannam@154 886 /**Closes the underlying stream.
cannam@154 887 \retval 0 Success.
cannam@154 888 \retval EOF An error occurred.
cannam@154 889 <code>errno</code> need not be set.*/
cannam@154 890 typedef int (*op_close_func)(void *_stream);
cannam@154 891
cannam@154 892 /**The callbacks used to access non-<code>FILE</code> stream resources.
cannam@154 893 The function prototypes are basically the same as for the stdio functions
cannam@154 894 <code>fread()</code>, <code>fseek()</code>, <code>ftell()</code>, and
cannam@154 895 <code>fclose()</code>.
cannam@154 896 The differences are that the <code>FILE *</code> arguments have been
cannam@154 897 replaced with a <code>void *</code>, which is to be used as a pointer to
cannam@154 898 whatever internal data these functions might need, that #seek and #tell
cannam@154 899 take and return 64-bit offsets, and that #seek <em>must</em> return -1 if
cannam@154 900 the stream is unseekable.*/
cannam@154 901 struct OpusFileCallbacks{
cannam@154 902 /**Used to read data from the stream.
cannam@154 903 This must not be <code>NULL</code>.*/
cannam@154 904 op_read_func read;
cannam@154 905 /**Used to seek in the stream.
cannam@154 906 This may be <code>NULL</code> if seeking is not implemented.*/
cannam@154 907 op_seek_func seek;
cannam@154 908 /**Used to return the current read position in the stream.
cannam@154 909 This may be <code>NULL</code> if seeking is not implemented.*/
cannam@154 910 op_tell_func tell;
cannam@154 911 /**Used to close the stream when the decoder is freed.
cannam@154 912 This may be <code>NULL</code> to leave the stream open.*/
cannam@154 913 op_close_func close;
cannam@154 914 };
cannam@154 915
cannam@154 916 /**Opens a stream with <code>fopen()</code> and fills in a set of callbacks
cannam@154 917 that can be used to access it.
cannam@154 918 This is useful to avoid writing your own portable 64-bit seeking wrappers,
cannam@154 919 and also avoids cross-module linking issues on Windows, where a
cannam@154 920 <code>FILE *</code> must be accessed by routines defined in the same module
cannam@154 921 that opened it.
cannam@154 922 \param[out] _cb The callbacks to use for this file.
cannam@154 923 If there is an error opening the file, nothing will be
cannam@154 924 filled in here.
cannam@154 925 \param _path The path to the file to open.
cannam@154 926 On Windows, this string must be UTF-8 (to allow access to
cannam@154 927 files whose names cannot be represented in the current
cannam@154 928 MBCS code page).
cannam@154 929 All other systems use the native character encoding.
cannam@154 930 \param _mode The mode to open the file in.
cannam@154 931 \return A stream handle to use with the callbacks, or <code>NULL</code> on
cannam@154 932 error.*/
cannam@154 933 OP_WARN_UNUSED_RESULT void *op_fopen(OpusFileCallbacks *_cb,
cannam@154 934 const char *_path,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2)
cannam@154 935 OP_ARG_NONNULL(3);
cannam@154 936
cannam@154 937 /**Opens a stream with <code>fdopen()</code> and fills in a set of callbacks
cannam@154 938 that can be used to access it.
cannam@154 939 This is useful to avoid writing your own portable 64-bit seeking wrappers,
cannam@154 940 and also avoids cross-module linking issues on Windows, where a
cannam@154 941 <code>FILE *</code> must be accessed by routines defined in the same module
cannam@154 942 that opened it.
cannam@154 943 \param[out] _cb The callbacks to use for this file.
cannam@154 944 If there is an error opening the file, nothing will be
cannam@154 945 filled in here.
cannam@154 946 \param _fd The file descriptor to open.
cannam@154 947 \param _mode The mode to open the file in.
cannam@154 948 \return A stream handle to use with the callbacks, or <code>NULL</code> on
cannam@154 949 error.*/
cannam@154 950 OP_WARN_UNUSED_RESULT void *op_fdopen(OpusFileCallbacks *_cb,
cannam@154 951 int _fd,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(3);
cannam@154 952
cannam@154 953 /**Opens a stream with <code>freopen()</code> and fills in a set of callbacks
cannam@154 954 that can be used to access it.
cannam@154 955 This is useful to avoid writing your own portable 64-bit seeking wrappers,
cannam@154 956 and also avoids cross-module linking issues on Windows, where a
cannam@154 957 <code>FILE *</code> must be accessed by routines defined in the same module
cannam@154 958 that opened it.
cannam@154 959 \param[out] _cb The callbacks to use for this file.
cannam@154 960 If there is an error opening the file, nothing will be
cannam@154 961 filled in here.
cannam@154 962 \param _path The path to the file to open.
cannam@154 963 On Windows, this string must be UTF-8 (to allow access
cannam@154 964 to files whose names cannot be represented in the
cannam@154 965 current MBCS code page).
cannam@154 966 All other systems use the native character encoding.
cannam@154 967 \param _mode The mode to open the file in.
cannam@154 968 \param _stream A stream previously returned by op_fopen(), op_fdopen(),
cannam@154 969 or op_freopen().
cannam@154 970 \return A stream handle to use with the callbacks, or <code>NULL</code> on
cannam@154 971 error.*/
cannam@154 972 OP_WARN_UNUSED_RESULT void *op_freopen(OpusFileCallbacks *_cb,
cannam@154 973 const char *_path,const char *_mode,void *_stream) OP_ARG_NONNULL(1)
cannam@154 974 OP_ARG_NONNULL(2) OP_ARG_NONNULL(3) OP_ARG_NONNULL(4);
cannam@154 975
cannam@154 976 /**Creates a stream that reads from the given block of memory.
cannam@154 977 This block of memory must contain the complete stream to decode.
cannam@154 978 This is useful for caching small streams (e.g., sound effects) in RAM.
cannam@154 979 \param[out] _cb The callbacks to use for this stream.
cannam@154 980 If there is an error creating the stream, nothing will be
cannam@154 981 filled in here.
cannam@154 982 \param _data The block of memory to read from.
cannam@154 983 \param _size The size of the block of memory.
cannam@154 984 \return A stream handle to use with the callbacks, or <code>NULL</code> on
cannam@154 985 error.*/
cannam@154 986 OP_WARN_UNUSED_RESULT void *op_mem_stream_create(OpusFileCallbacks *_cb,
cannam@154 987 const unsigned char *_data,size_t _size) OP_ARG_NONNULL(1);
cannam@154 988
cannam@154 989 /**Creates a stream that reads from the given URL.
cannam@154 990 This function behaves identically to op_url_stream_create(), except that it
cannam@154 991 takes a va_list instead of a variable number of arguments.
cannam@154 992 It does not call the <code>va_end</code> macro, and because it invokes the
cannam@154 993 <code>va_arg</code> macro, the value of \a _ap is undefined after the call.
cannam@154 994 \note If you use this function, you must link against <tt>libopusurl</tt>.
cannam@154 995 \param[out] _cb The callbacks to use for this stream.
cannam@154 996 If there is an error creating the stream, nothing will
cannam@154 997 be filled in here.
cannam@154 998 \param _url The URL to read from.
cannam@154 999 Currently only the <file:>, <http:>, and <https:>
cannam@154 1000 schemes are supported.
cannam@154 1001 Both <http:> and <https:> may be disabled at compile
cannam@154 1002 time, in which case opening such URLs will always fail.
cannam@154 1003 Currently this only supports URIs.
cannam@154 1004 IRIs should be converted to UTF-8 and URL-escaped, with
cannam@154 1005 internationalized domain names encoded in punycode,
cannam@154 1006 before passing them to this function.
cannam@154 1007 \param[in,out] _ap A list of the \ref url_options "optional flags" to use.
cannam@154 1008 This is a variable-length list of options terminated
cannam@154 1009 with <code>NULL</code>.
cannam@154 1010 \return A stream handle to use with the callbacks, or <code>NULL</code> on
cannam@154 1011 error.*/
cannam@154 1012 OP_WARN_UNUSED_RESULT void *op_url_stream_vcreate(OpusFileCallbacks *_cb,
cannam@154 1013 const char *_url,va_list _ap) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
cannam@154 1014
cannam@154 1015 /**Creates a stream that reads from the given URL.
cannam@154 1016 \note If you use this function, you must link against <tt>libopusurl</tt>.
cannam@154 1017 \param[out] _cb The callbacks to use for this stream.
cannam@154 1018 If there is an error creating the stream, nothing will be
cannam@154 1019 filled in here.
cannam@154 1020 \param _url The URL to read from.
cannam@154 1021 Currently only the <file:>, <http:>, and <https:> schemes
cannam@154 1022 are supported.
cannam@154 1023 Both <http:> and <https:> may be disabled at compile time,
cannam@154 1024 in which case opening such URLs will always fail.
cannam@154 1025 Currently this only supports URIs.
cannam@154 1026 IRIs should be converted to UTF-8 and URL-escaped, with
cannam@154 1027 internationalized domain names encoded in punycode, before
cannam@154 1028 passing them to this function.
cannam@154 1029 \param ... The \ref url_options "optional flags" to use.
cannam@154 1030 This is a variable-length list of options terminated with
cannam@154 1031 <code>NULL</code>.
cannam@154 1032 \return A stream handle to use with the callbacks, or <code>NULL</code> on
cannam@154 1033 error.*/
cannam@154 1034 OP_WARN_UNUSED_RESULT void *op_url_stream_create(OpusFileCallbacks *_cb,
cannam@154 1035 const char *_url,...) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
cannam@154 1036
cannam@154 1037 /*@}*/
cannam@154 1038 /*@}*/
cannam@154 1039
cannam@154 1040 /**\defgroup stream_open_close Opening and Closing*/
cannam@154 1041 /*@{*/
cannam@154 1042 /**\name Functions for opening and closing streams
cannam@154 1043
cannam@154 1044 These functions allow you to test a stream to see if it is Opus, open it,
cannam@154 1045 and close it.
cannam@154 1046 Several flavors are provided for each of the built-in stream types, plus a
cannam@154 1047 more general version which takes a set of application-provided callbacks.*/
cannam@154 1048 /*@{*/
cannam@154 1049
cannam@154 1050 /**Test to see if this is an Opus stream.
cannam@154 1051 For good results, you will need at least 57 bytes (for a pure Opus-only
cannam@154 1052 stream).
cannam@154 1053 Something like 512 bytes will give more reliable results for multiplexed
cannam@154 1054 streams.
cannam@154 1055 This function is meant to be a quick-rejection filter.
cannam@154 1056 Its purpose is not to guarantee that a stream is a valid Opus stream, but to
cannam@154 1057 ensure that it looks enough like Opus that it isn't going to be recognized
cannam@154 1058 as some other format (except possibly an Opus stream that is also
cannam@154 1059 multiplexed with other codecs, such as video).
cannam@154 1060 \param[out] _head The parsed ID header contents.
cannam@154 1061 You may pass <code>NULL</code> if you do not need
cannam@154 1062 this information.
cannam@154 1063 If the function fails, the contents of this structure
cannam@154 1064 remain untouched.
cannam@154 1065 \param _initial_data An initial buffer of data from the start of the
cannam@154 1066 stream.
cannam@154 1067 \param _initial_bytes The number of bytes in \a _initial_data.
cannam@154 1068 \return 0 if the data appears to be Opus, or a negative value on error.
cannam@154 1069 \retval #OP_FALSE There was not enough data to tell if this was an Opus
cannam@154 1070 stream or not.
cannam@154 1071 \retval #OP_EFAULT An internal memory allocation failed.
cannam@154 1072 \retval #OP_EIMPL The stream used a feature that is not implemented,
cannam@154 1073 such as an unsupported channel family.
cannam@154 1074 \retval #OP_ENOTFORMAT If the data did not contain a recognizable ID
cannam@154 1075 header for an Opus stream.
cannam@154 1076 \retval #OP_EVERSION If the version field signaled a version this library
cannam@154 1077 does not know how to parse.
cannam@154 1078 \retval #OP_EBADHEADER The ID header was not properly formatted or contained
cannam@154 1079 illegal values.*/
cannam@154 1080 int op_test(OpusHead *_head,
cannam@154 1081 const unsigned char *_initial_data,size_t _initial_bytes);
cannam@154 1082
cannam@154 1083 /**Open a stream from the given file path.
cannam@154 1084 \param _path The path to the file to open.
cannam@154 1085 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1086 You may pass in <code>NULL</code> if you don't want the
cannam@154 1087 failure code.
cannam@154 1088 The failure code will be #OP_EFAULT if the file could not
cannam@154 1089 be opened, or one of the other failure codes from
cannam@154 1090 op_open_callbacks() otherwise.
cannam@154 1091 \return A freshly opened \c OggOpusFile, or <code>NULL</code> on error.*/
cannam@154 1092 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_file(const char *_path,int *_error)
cannam@154 1093 OP_ARG_NONNULL(1);
cannam@154 1094
cannam@154 1095 /**Open a stream from a memory buffer.
cannam@154 1096 \param _data The memory buffer to open.
cannam@154 1097 \param _size The number of bytes in the buffer.
cannam@154 1098 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1099 You may pass in <code>NULL</code> if you don't want the
cannam@154 1100 failure code.
cannam@154 1101 See op_open_callbacks() for a full list of failure codes.
cannam@154 1102 \return A freshly opened \c OggOpusFile, or <code>NULL</code> on error.*/
cannam@154 1103 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_memory(const unsigned char *_data,
cannam@154 1104 size_t _size,int *_error);
cannam@154 1105
cannam@154 1106 /**Open a stream from a URL.
cannam@154 1107 This function behaves identically to op_open_url(), except that it
cannam@154 1108 takes a va_list instead of a variable number of arguments.
cannam@154 1109 It does not call the <code>va_end</code> macro, and because it invokes the
cannam@154 1110 <code>va_arg</code> macro, the value of \a _ap is undefined after the call.
cannam@154 1111 \note If you use this function, you must link against <tt>libopusurl</tt>.
cannam@154 1112 \param _url The URL to open.
cannam@154 1113 Currently only the <file:>, <http:>, and <https:>
cannam@154 1114 schemes are supported.
cannam@154 1115 Both <http:> and <https:> may be disabled at compile
cannam@154 1116 time, in which case opening such URLs will always
cannam@154 1117 fail.
cannam@154 1118 Currently this only supports URIs.
cannam@154 1119 IRIs should be converted to UTF-8 and URL-escaped,
cannam@154 1120 with internationalized domain names encoded in
cannam@154 1121 punycode, before passing them to this function.
cannam@154 1122 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1123 You may pass in <code>NULL</code> if you don't want
cannam@154 1124 the failure code.
cannam@154 1125 See op_open_callbacks() for a full list of failure
cannam@154 1126 codes.
cannam@154 1127 \param[in,out] _ap A list of the \ref url_options "optional flags" to
cannam@154 1128 use.
cannam@154 1129 This is a variable-length list of options terminated
cannam@154 1130 with <code>NULL</code>.
cannam@154 1131 \return A freshly opened \c OggOpusFile, or <code>NULL</code> on error.*/
cannam@154 1132 OP_WARN_UNUSED_RESULT OggOpusFile *op_vopen_url(const char *_url,
cannam@154 1133 int *_error,va_list _ap) OP_ARG_NONNULL(1);
cannam@154 1134
cannam@154 1135 /**Open a stream from a URL.
cannam@154 1136 \note If you use this function, you must link against <tt>libopusurl</tt>.
cannam@154 1137 \param _url The URL to open.
cannam@154 1138 Currently only the <file:>, <http:>, and <https:> schemes
cannam@154 1139 are supported.
cannam@154 1140 Both <http:> and <https:> may be disabled at compile
cannam@154 1141 time, in which case opening such URLs will always fail.
cannam@154 1142 Currently this only supports URIs.
cannam@154 1143 IRIs should be converted to UTF-8 and URL-escaped, with
cannam@154 1144 internationalized domain names encoded in punycode,
cannam@154 1145 before passing them to this function.
cannam@154 1146 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1147 You may pass in <code>NULL</code> if you don't want the
cannam@154 1148 failure code.
cannam@154 1149 See op_open_callbacks() for a full list of failure codes.
cannam@154 1150 \param ... The \ref url_options "optional flags" to use.
cannam@154 1151 This is a variable-length list of options terminated with
cannam@154 1152 <code>NULL</code>.
cannam@154 1153 \return A freshly opened \c OggOpusFile, or <code>NULL</code> on error.*/
cannam@154 1154 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_url(const char *_url,
cannam@154 1155 int *_error,...) OP_ARG_NONNULL(1);
cannam@154 1156
cannam@154 1157 /**Open a stream using the given set of callbacks to access it.
cannam@154 1158 \param _stream The stream to read from (e.g., a <code>FILE *</code>).
cannam@154 1159 This value will be passed verbatim as the first
cannam@154 1160 argument to all of the callbacks.
cannam@154 1161 \param _cb The callbacks with which to access the stream.
cannam@154 1162 <code><a href="#op_read_func">read()</a></code> must
cannam@154 1163 be implemented.
cannam@154 1164 <code><a href="#op_seek_func">seek()</a></code> and
cannam@154 1165 <code><a href="#op_tell_func">tell()</a></code> may
cannam@154 1166 be <code>NULL</code>, or may always return -1 to
cannam@154 1167 indicate a stream is unseekable, but if
cannam@154 1168 <code><a href="#op_seek_func">seek()</a></code> is
cannam@154 1169 implemented and succeeds on a particular stream, then
cannam@154 1170 <code><a href="#op_tell_func">tell()</a></code> must
cannam@154 1171 also.
cannam@154 1172 <code><a href="#op_close_func">close()</a></code> may
cannam@154 1173 be <code>NULL</code>, but if it is not, it will be
cannam@154 1174 called when the \c OggOpusFile is destroyed by
cannam@154 1175 op_free().
cannam@154 1176 It will not be called if op_open_callbacks() fails
cannam@154 1177 with an error.
cannam@154 1178 \param _initial_data An initial buffer of data from the start of the
cannam@154 1179 stream.
cannam@154 1180 Applications can read some number of bytes from the
cannam@154 1181 start of the stream to help identify this as an Opus
cannam@154 1182 stream, and then provide them here to allow the
cannam@154 1183 stream to be opened, even if it is unseekable.
cannam@154 1184 \param _initial_bytes The number of bytes in \a _initial_data.
cannam@154 1185 If the stream is seekable, its current position (as
cannam@154 1186 reported by
cannam@154 1187 <code><a href="#opus_tell_func">tell()</a></code>
cannam@154 1188 at the start of this function) must be equal to
cannam@154 1189 \a _initial_bytes.
cannam@154 1190 Otherwise, seeking to absolute positions will
cannam@154 1191 generate inconsistent results.
cannam@154 1192 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1193 You may pass in <code>NULL</code> if you don't want
cannam@154 1194 the failure code.
cannam@154 1195 The failure code will be one of
cannam@154 1196 <dl>
cannam@154 1197 <dt>#OP_EREAD</dt>
cannam@154 1198 <dd>An underlying read, seek, or tell operation
cannam@154 1199 failed when it should have succeeded, or we failed
cannam@154 1200 to find data in the stream we had seen before.</dd>
cannam@154 1201 <dt>#OP_EFAULT</dt>
cannam@154 1202 <dd>There was a memory allocation failure, or an
cannam@154 1203 internal library error.</dd>
cannam@154 1204 <dt>#OP_EIMPL</dt>
cannam@154 1205 <dd>The stream used a feature that is not
cannam@154 1206 implemented, such as an unsupported channel
cannam@154 1207 family.</dd>
cannam@154 1208 <dt>#OP_EINVAL</dt>
cannam@154 1209 <dd><code><a href="#op_seek_func">seek()</a></code>
cannam@154 1210 was implemented and succeeded on this source, but
cannam@154 1211 <code><a href="#op_tell_func">tell()</a></code>
cannam@154 1212 did not, or the starting position indicator was
cannam@154 1213 not equal to \a _initial_bytes.</dd>
cannam@154 1214 <dt>#OP_ENOTFORMAT</dt>
cannam@154 1215 <dd>The stream contained a link that did not have
cannam@154 1216 any logical Opus streams in it.</dd>
cannam@154 1217 <dt>#OP_EBADHEADER</dt>
cannam@154 1218 <dd>A required header packet was not properly
cannam@154 1219 formatted, contained illegal values, or was missing
cannam@154 1220 altogether.</dd>
cannam@154 1221 <dt>#OP_EVERSION</dt>
cannam@154 1222 <dd>An ID header contained an unrecognized version
cannam@154 1223 number.</dd>
cannam@154 1224 <dt>#OP_EBADLINK</dt>
cannam@154 1225 <dd>We failed to find data we had seen before after
cannam@154 1226 seeking.</dd>
cannam@154 1227 <dt>#OP_EBADTIMESTAMP</dt>
cannam@154 1228 <dd>The first or last timestamp in a link failed
cannam@154 1229 basic validity checks.</dd>
cannam@154 1230 </dl>
cannam@154 1231 \return A freshly opened \c OggOpusFile, or <code>NULL</code> on error.
cannam@154 1232 <tt>libopusfile</tt> does <em>not</em> take ownership of the stream
cannam@154 1233 if the call fails.
cannam@154 1234 The calling application is responsible for closing the stream if
cannam@154 1235 this call returns an error.*/
cannam@154 1236 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_callbacks(void *_stream,
cannam@154 1237 const OpusFileCallbacks *_cb,const unsigned char *_initial_data,
cannam@154 1238 size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2);
cannam@154 1239
cannam@154 1240 /**Partially open a stream from the given file path.
cannam@154 1241 \see op_test_callbacks
cannam@154 1242 \param _path The path to the file to open.
cannam@154 1243 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1244 You may pass in <code>NULL</code> if you don't want the
cannam@154 1245 failure code.
cannam@154 1246 The failure code will be #OP_EFAULT if the file could not
cannam@154 1247 be opened, or one of the other failure codes from
cannam@154 1248 op_open_callbacks() otherwise.
cannam@154 1249 \return A partially opened \c OggOpusFile, or <code>NULL</code> on error.*/
cannam@154 1250 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_file(const char *_path,int *_error)
cannam@154 1251 OP_ARG_NONNULL(1);
cannam@154 1252
cannam@154 1253 /**Partially open a stream from a memory buffer.
cannam@154 1254 \see op_test_callbacks
cannam@154 1255 \param _data The memory buffer to open.
cannam@154 1256 \param _size The number of bytes in the buffer.
cannam@154 1257 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1258 You may pass in <code>NULL</code> if you don't want the
cannam@154 1259 failure code.
cannam@154 1260 See op_open_callbacks() for a full list of failure codes.
cannam@154 1261 \return A partially opened \c OggOpusFile, or <code>NULL</code> on error.*/
cannam@154 1262 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_memory(const unsigned char *_data,
cannam@154 1263 size_t _size,int *_error);
cannam@154 1264
cannam@154 1265 /**Partially open a stream from a URL.
cannam@154 1266 This function behaves identically to op_test_url(), except that it
cannam@154 1267 takes a va_list instead of a variable number of arguments.
cannam@154 1268 It does not call the <code>va_end</code> macro, and because it invokes the
cannam@154 1269 <code>va_arg</code> macro, the value of \a _ap is undefined after the call.
cannam@154 1270 \note If you use this function, you must link against <tt>libopusurl</tt>.
cannam@154 1271 \see op_test_url
cannam@154 1272 \see op_test_callbacks
cannam@154 1273 \param _url The URL to open.
cannam@154 1274 Currently only the <file:>, <http:>, and <https:>
cannam@154 1275 schemes are supported.
cannam@154 1276 Both <http:> and <https:> may be disabled at compile
cannam@154 1277 time, in which case opening such URLs will always
cannam@154 1278 fail.
cannam@154 1279 Currently this only supports URIs.
cannam@154 1280 IRIs should be converted to UTF-8 and URL-escaped,
cannam@154 1281 with internationalized domain names encoded in
cannam@154 1282 punycode, before passing them to this function.
cannam@154 1283 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1284 You may pass in <code>NULL</code> if you don't want
cannam@154 1285 the failure code.
cannam@154 1286 See op_open_callbacks() for a full list of failure
cannam@154 1287 codes.
cannam@154 1288 \param[in,out] _ap A list of the \ref url_options "optional flags" to
cannam@154 1289 use.
cannam@154 1290 This is a variable-length list of options terminated
cannam@154 1291 with <code>NULL</code>.
cannam@154 1292 \return A partially opened \c OggOpusFile, or <code>NULL</code> on error.*/
cannam@154 1293 OP_WARN_UNUSED_RESULT OggOpusFile *op_vtest_url(const char *_url,
cannam@154 1294 int *_error,va_list _ap) OP_ARG_NONNULL(1);
cannam@154 1295
cannam@154 1296 /**Partially open a stream from a URL.
cannam@154 1297 \note If you use this function, you must link against <tt>libopusurl</tt>.
cannam@154 1298 \see op_test_callbacks
cannam@154 1299 \param _url The URL to open.
cannam@154 1300 Currently only the <file:>, <http:>, and <https:>
cannam@154 1301 schemes are supported.
cannam@154 1302 Both <http:> and <https:> may be disabled at compile
cannam@154 1303 time, in which case opening such URLs will always fail.
cannam@154 1304 Currently this only supports URIs.
cannam@154 1305 IRIs should be converted to UTF-8 and URL-escaped, with
cannam@154 1306 internationalized domain names encoded in punycode,
cannam@154 1307 before passing them to this function.
cannam@154 1308 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1309 You may pass in <code>NULL</code> if you don't want the
cannam@154 1310 failure code.
cannam@154 1311 See op_open_callbacks() for a full list of failure
cannam@154 1312 codes.
cannam@154 1313 \param ... The \ref url_options "optional flags" to use.
cannam@154 1314 This is a variable-length list of options terminated
cannam@154 1315 with <code>NULL</code>.
cannam@154 1316 \return A partially opened \c OggOpusFile, or <code>NULL</code> on error.*/
cannam@154 1317 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_url(const char *_url,
cannam@154 1318 int *_error,...) OP_ARG_NONNULL(1);
cannam@154 1319
cannam@154 1320 /**Partially open a stream using the given set of callbacks to access it.
cannam@154 1321 This tests for Opusness and loads the headers for the first link.
cannam@154 1322 It does not seek (although it tests for seekability).
cannam@154 1323 You can query a partially open stream for the few pieces of basic
cannam@154 1324 information returned by op_serialno(), op_channel_count(), op_head(), and
cannam@154 1325 op_tags() (but only for the first link).
cannam@154 1326 You may also determine if it is seekable via a call to op_seekable().
cannam@154 1327 You cannot read audio from the stream, seek, get the size or duration,
cannam@154 1328 get information from links other than the first one, or even get the total
cannam@154 1329 number of links until you finish opening the stream with op_test_open().
cannam@154 1330 If you do not need to do any of these things, you can dispose of it with
cannam@154 1331 op_free() instead.
cannam@154 1332
cannam@154 1333 This function is provided mostly to simplify porting existing code that used
cannam@154 1334 <tt>libvorbisfile</tt>.
cannam@154 1335 For new code, you are likely better off using op_test() instead, which
cannam@154 1336 is less resource-intensive, requires less data to succeed, and imposes a
cannam@154 1337 hard limit on the amount of data it examines (important for unseekable
cannam@154 1338 streams, where all such data must be buffered until you are sure of the
cannam@154 1339 stream type).
cannam@154 1340 \param _stream The stream to read from (e.g., a <code>FILE *</code>).
cannam@154 1341 This value will be passed verbatim as the first
cannam@154 1342 argument to all of the callbacks.
cannam@154 1343 \param _cb The callbacks with which to access the stream.
cannam@154 1344 <code><a href="#op_read_func">read()</a></code> must
cannam@154 1345 be implemented.
cannam@154 1346 <code><a href="#op_seek_func">seek()</a></code> and
cannam@154 1347 <code><a href="#op_tell_func">tell()</a></code> may
cannam@154 1348 be <code>NULL</code>, or may always return -1 to
cannam@154 1349 indicate a stream is unseekable, but if
cannam@154 1350 <code><a href="#op_seek_func">seek()</a></code> is
cannam@154 1351 implemented and succeeds on a particular stream, then
cannam@154 1352 <code><a href="#op_tell_func">tell()</a></code> must
cannam@154 1353 also.
cannam@154 1354 <code><a href="#op_close_func">close()</a></code> may
cannam@154 1355 be <code>NULL</code>, but if it is not, it will be
cannam@154 1356 called when the \c OggOpusFile is destroyed by
cannam@154 1357 op_free().
cannam@154 1358 It will not be called if op_open_callbacks() fails
cannam@154 1359 with an error.
cannam@154 1360 \param _initial_data An initial buffer of data from the start of the
cannam@154 1361 stream.
cannam@154 1362 Applications can read some number of bytes from the
cannam@154 1363 start of the stream to help identify this as an Opus
cannam@154 1364 stream, and then provide them here to allow the
cannam@154 1365 stream to be tested more thoroughly, even if it is
cannam@154 1366 unseekable.
cannam@154 1367 \param _initial_bytes The number of bytes in \a _initial_data.
cannam@154 1368 If the stream is seekable, its current position (as
cannam@154 1369 reported by
cannam@154 1370 <code><a href="#opus_tell_func">tell()</a></code>
cannam@154 1371 at the start of this function) must be equal to
cannam@154 1372 \a _initial_bytes.
cannam@154 1373 Otherwise, seeking to absolute positions will
cannam@154 1374 generate inconsistent results.
cannam@154 1375 \param[out] _error Returns 0 on success, or a failure code on error.
cannam@154 1376 You may pass in <code>NULL</code> if you don't want
cannam@154 1377 the failure code.
cannam@154 1378 See op_open_callbacks() for a full list of failure
cannam@154 1379 codes.
cannam@154 1380 \return A partially opened \c OggOpusFile, or <code>NULL</code> on error.
cannam@154 1381 <tt>libopusfile</tt> does <em>not</em> take ownership of the stream
cannam@154 1382 if the call fails.
cannam@154 1383 The calling application is responsible for closing the stream if
cannam@154 1384 this call returns an error.*/
cannam@154 1385 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_callbacks(void *_stream,
cannam@154 1386 const OpusFileCallbacks *_cb,const unsigned char *_initial_data,
cannam@154 1387 size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2);
cannam@154 1388
cannam@154 1389 /**Finish opening a stream partially opened with op_test_callbacks() or one of
cannam@154 1390 the associated convenience functions.
cannam@154 1391 If this function fails, you are still responsible for freeing the
cannam@154 1392 \c OggOpusFile with op_free().
cannam@154 1393 \param _of The \c OggOpusFile to finish opening.
cannam@154 1394 \return 0 on success, or a negative value on error.
cannam@154 1395 \retval #OP_EREAD An underlying read, seek, or tell operation failed
cannam@154 1396 when it should have succeeded.
cannam@154 1397 \retval #OP_EFAULT There was a memory allocation failure, or an
cannam@154 1398 internal library error.
cannam@154 1399 \retval #OP_EIMPL The stream used a feature that is not implemented,
cannam@154 1400 such as an unsupported channel family.
cannam@154 1401 \retval #OP_EINVAL The stream was not partially opened with
cannam@154 1402 op_test_callbacks() or one of the associated
cannam@154 1403 convenience functions.
cannam@154 1404 \retval #OP_ENOTFORMAT The stream contained a link that did not have any
cannam@154 1405 logical Opus streams in it.
cannam@154 1406 \retval #OP_EBADHEADER A required header packet was not properly
cannam@154 1407 formatted, contained illegal values, or was
cannam@154 1408 missing altogether.
cannam@154 1409 \retval #OP_EVERSION An ID header contained an unrecognized version
cannam@154 1410 number.
cannam@154 1411 \retval #OP_EBADLINK We failed to find data we had seen before after
cannam@154 1412 seeking.
cannam@154 1413 \retval #OP_EBADTIMESTAMP The first or last timestamp in a link failed basic
cannam@154 1414 validity checks.*/
cannam@154 1415 int op_test_open(OggOpusFile *_of) OP_ARG_NONNULL(1);
cannam@154 1416
cannam@154 1417 /**Release all memory used by an \c OggOpusFile.
cannam@154 1418 \param _of The \c OggOpusFile to free.*/
cannam@154 1419 void op_free(OggOpusFile *_of);
cannam@154 1420
cannam@154 1421 /*@}*/
cannam@154 1422 /*@}*/
cannam@154 1423
cannam@154 1424 /**\defgroup stream_info Stream Information*/
cannam@154 1425 /*@{*/
cannam@154 1426 /**\name Functions for obtaining information about streams
cannam@154 1427
cannam@154 1428 These functions allow you to get basic information about a stream, including
cannam@154 1429 seekability, the number of links (for chained streams), plus the size,
cannam@154 1430 duration, bitrate, header parameters, and meta information for each link
cannam@154 1431 (or, where available, the stream as a whole).
cannam@154 1432 Some of these (size, duration) are only available for seekable streams.
cannam@154 1433 You can also query the current stream position, link, and playback time,
cannam@154 1434 and instantaneous bitrate during playback.
cannam@154 1435
cannam@154 1436 Some of these functions may be used successfully on the partially open
cannam@154 1437 streams returned by op_test_callbacks() or one of the associated
cannam@154 1438 convenience functions.
cannam@154 1439 Their documention will indicate so explicitly.*/
cannam@154 1440 /*@{*/
cannam@154 1441
cannam@154 1442 /**Returns whether or not the stream being read is seekable.
cannam@154 1443 This is true if
cannam@154 1444 <ol>
cannam@154 1445 <li>The <code><a href="#op_seek_func">seek()</a></code> and
cannam@154 1446 <code><a href="#op_tell_func">tell()</a></code> callbacks are both
cannam@154 1447 non-<code>NULL</code>,</li>
cannam@154 1448 <li>The <code><a href="#op_seek_func">seek()</a></code> callback was
cannam@154 1449 successfully executed at least once, and</li>
cannam@154 1450 <li>The <code><a href="#op_tell_func">tell()</a></code> callback was
cannam@154 1451 successfully able to report the position indicator afterwards.</li>
cannam@154 1452 </ol>
cannam@154 1453 This function may be called on partially-opened streams.
cannam@154 1454 \param _of The \c OggOpusFile whose seekable status is to be returned.
cannam@154 1455 \return A non-zero value if seekable, and 0 if unseekable.*/
cannam@154 1456 int op_seekable(const OggOpusFile *_of) OP_ARG_NONNULL(1);
cannam@154 1457
cannam@154 1458 /**Returns the number of links in this chained stream.
cannam@154 1459 This function may be called on partially-opened streams, but it will always
cannam@154 1460 return 1.
cannam@154 1461 The actual number of links is not known until the stream is fully opened.
cannam@154 1462 \param _of The \c OggOpusFile from which to retrieve the link count.
cannam@154 1463 \return For fully-open seekable streams, this returns the total number of
cannam@154 1464 links in the whole stream, which will be at least 1.
cannam@154 1465 For partially-open or unseekable streams, this always returns 1.*/
cannam@154 1466 int op_link_count(const OggOpusFile *_of) OP_ARG_NONNULL(1);
cannam@154 1467
cannam@154 1468 /**Get the serial number of the given link in a (possibly-chained) Ogg Opus
cannam@154 1469 stream.
cannam@154 1470 This function may be called on partially-opened streams, but it will always
cannam@154 1471 return the serial number of the Opus stream in the first link.
cannam@154 1472 \param _of The \c OggOpusFile from which to retrieve the serial number.
cannam@154 1473 \param _li The index of the link whose serial number should be retrieved.
cannam@154 1474 Use a negative number to get the serial number of the current
cannam@154 1475 link.
cannam@154 1476 \return The serial number of the given link.
cannam@154 1477 If \a _li is greater than the total number of links, this returns
cannam@154 1478 the serial number of the last link.
cannam@154 1479 If the stream is not seekable, this always returns the serial number
cannam@154 1480 of the current link.*/
cannam@154 1481 opus_uint32 op_serialno(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
cannam@154 1482
cannam@154 1483 /**Get the channel count of the given link in a (possibly-chained) Ogg Opus
cannam@154 1484 stream.
cannam@154 1485 This is equivalent to <code>op_head(_of,_li)->channel_count</code>, but
cannam@154 1486 is provided for convenience.
cannam@154 1487 This function may be called on partially-opened streams, but it will always
cannam@154 1488 return the channel count of the Opus stream in the first link.
cannam@154 1489 \param _of The \c OggOpusFile from which to retrieve the channel count.
cannam@154 1490 \param _li The index of the link whose channel count should be retrieved.
cannam@154 1491 Use a negative number to get the channel count of the current
cannam@154 1492 link.
cannam@154 1493 \return The channel count of the given link.
cannam@154 1494 If \a _li is greater than the total number of links, this returns
cannam@154 1495 the channel count of the last link.
cannam@154 1496 If the stream is not seekable, this always returns the channel count
cannam@154 1497 of the current link.*/
cannam@154 1498 int op_channel_count(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
cannam@154 1499
cannam@154 1500 /**Get the total (compressed) size of the stream, or of an individual link in
cannam@154 1501 a (possibly-chained) Ogg Opus stream, including all headers and Ogg muxing
cannam@154 1502 overhead.
cannam@154 1503 \warning If the Opus stream (or link) is concurrently multiplexed with other
cannam@154 1504 logical streams (e.g., video), this returns the size of the entire stream
cannam@154 1505 (or link), not just the number of bytes in the first logical Opus stream.
cannam@154 1506 Returning the latter would require scanning the entire file.
cannam@154 1507 \param _of The \c OggOpusFile from which to retrieve the compressed size.
cannam@154 1508 \param _li The index of the link whose compressed size should be computed.
cannam@154 1509 Use a negative number to get the compressed size of the entire
cannam@154 1510 stream.
cannam@154 1511 \return The compressed size of the entire stream if \a _li is negative, the
cannam@154 1512 compressed size of link \a _li if it is non-negative, or a negative
cannam@154 1513 value on error.
cannam@154 1514 The compressed size of the entire stream may be smaller than that
cannam@154 1515 of the underlying stream if trailing garbage was detected in the
cannam@154 1516 file.
cannam@154 1517 \retval #OP_EINVAL The stream is not seekable (so we can't know the length),
cannam@154 1518 \a _li wasn't less than the total number of links in
cannam@154 1519 the stream, or the stream was only partially open.*/
cannam@154 1520 opus_int64 op_raw_total(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
cannam@154 1521
cannam@154 1522 /**Get the total PCM length (number of samples at 48 kHz) of the stream, or of
cannam@154 1523 an individual link in a (possibly-chained) Ogg Opus stream.
cannam@154 1524 Users looking for <code>op_time_total()</code> should use op_pcm_total()
cannam@154 1525 instead.
cannam@154 1526 Because timestamps in Opus are fixed at 48 kHz, there is no need for a
cannam@154 1527 separate function to convert this to seconds (and leaving it out avoids
cannam@154 1528 introducing floating point to the API, for those that wish to avoid it).
cannam@154 1529 \param _of The \c OggOpusFile from which to retrieve the PCM offset.
cannam@154 1530 \param _li The index of the link whose PCM length should be computed.
cannam@154 1531 Use a negative number to get the PCM length of the entire stream.
cannam@154 1532 \return The PCM length of the entire stream if \a _li is negative, the PCM
cannam@154 1533 length of link \a _li if it is non-negative, or a negative value on
cannam@154 1534 error.
cannam@154 1535 \retval #OP_EINVAL The stream is not seekable (so we can't know the length),
cannam@154 1536 \a _li wasn't less than the total number of links in
cannam@154 1537 the stream, or the stream was only partially open.*/
cannam@154 1538 ogg_int64_t op_pcm_total(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
cannam@154 1539
cannam@154 1540 /**Get the ID header information for the given link in a (possibly chained) Ogg
cannam@154 1541 Opus stream.
cannam@154 1542 This function may be called on partially-opened streams, but it will always
cannam@154 1543 return the ID header information of the Opus stream in the first link.
cannam@154 1544 \param _of The \c OggOpusFile from which to retrieve the ID header
cannam@154 1545 information.
cannam@154 1546 \param _li The index of the link whose ID header information should be
cannam@154 1547 retrieved.
cannam@154 1548 Use a negative number to get the ID header information of the
cannam@154 1549 current link.
cannam@154 1550 For an unseekable stream, \a _li is ignored, and the ID header
cannam@154 1551 information for the current link is always returned, if
cannam@154 1552 available.
cannam@154 1553 \return The contents of the ID header for the given link.*/
cannam@154 1554 const OpusHead *op_head(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
cannam@154 1555
cannam@154 1556 /**Get the comment header information for the given link in a (possibly
cannam@154 1557 chained) Ogg Opus stream.
cannam@154 1558 This function may be called on partially-opened streams, but it will always
cannam@154 1559 return the tags from the Opus stream in the first link.
cannam@154 1560 \param _of The \c OggOpusFile from which to retrieve the comment header
cannam@154 1561 information.
cannam@154 1562 \param _li The index of the link whose comment header information should be
cannam@154 1563 retrieved.
cannam@154 1564 Use a negative number to get the comment header information of
cannam@154 1565 the current link.
cannam@154 1566 For an unseekable stream, \a _li is ignored, and the comment
cannam@154 1567 header information for the current link is always returned, if
cannam@154 1568 available.
cannam@154 1569 \return The contents of the comment header for the given link, or
cannam@154 1570 <code>NULL</code> if this is an unseekable stream that encountered
cannam@154 1571 an invalid link.*/
cannam@154 1572 const OpusTags *op_tags(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
cannam@154 1573
cannam@154 1574 /**Retrieve the index of the current link.
cannam@154 1575 This is the link that produced the data most recently read by
cannam@154 1576 op_read_float() or its associated functions, or, after a seek, the link
cannam@154 1577 that the seek target landed in.
cannam@154 1578 Reading more data may advance the link index (even on the first read after a
cannam@154 1579 seek).
cannam@154 1580 \param _of The \c OggOpusFile from which to retrieve the current link index.
cannam@154 1581 \return The index of the current link on success, or a negative value on
cannam@154 1582 failure.
cannam@154 1583 For seekable streams, this is a number between 0 (inclusive) and the
cannam@154 1584 value returned by op_link_count() (exclusive).
cannam@154 1585 For unseekable streams, this value starts at 0 and increments by one
cannam@154 1586 each time a new link is encountered (even though op_link_count()
cannam@154 1587 always returns 1).
cannam@154 1588 \retval #OP_EINVAL The stream was only partially open.*/
cannam@154 1589 int op_current_link(const OggOpusFile *_of) OP_ARG_NONNULL(1);
cannam@154 1590
cannam@154 1591 /**Computes the bitrate of the stream, or of an individual link in a
cannam@154 1592 (possibly-chained) Ogg Opus stream.
cannam@154 1593 The stream must be seekable to compute the bitrate.
cannam@154 1594 For unseekable streams, use op_bitrate_instant() to get periodic estimates.
cannam@154 1595 \warning If the Opus stream (or link) is concurrently multiplexed with other
cannam@154 1596 logical streams (e.g., video), this uses the size of the entire stream (or
cannam@154 1597 link) to compute the bitrate, not just the number of bytes in the first
cannam@154 1598 logical Opus stream.
cannam@154 1599 Returning the latter requires scanning the entire file, but this may be done
cannam@154 1600 by decoding the whole file and calling op_bitrate_instant() once at the
cannam@154 1601 end.
cannam@154 1602 Install a trivial decoding callback with op_set_decode_callback() if you
cannam@154 1603 wish to skip actual decoding during this process.
cannam@154 1604 \param _of The \c OggOpusFile from which to retrieve the bitrate.
cannam@154 1605 \param _li The index of the link whose bitrate should be computed.
cannam@154 1606 Use a negative number to get the bitrate of the whole stream.
cannam@154 1607 \return The bitrate on success, or a negative value on error.
cannam@154 1608 \retval #OP_EINVAL The stream was only partially open, the stream was not
cannam@154 1609 seekable, or \a _li was larger than the number of
cannam@154 1610 links.*/
cannam@154 1611 opus_int32 op_bitrate(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
cannam@154 1612
cannam@154 1613 /**Compute the instantaneous bitrate, measured as the ratio of bits to playable
cannam@154 1614 samples decoded since a) the last call to op_bitrate_instant(), b) the last
cannam@154 1615 seek, or c) the start of playback, whichever was most recent.
cannam@154 1616 This will spike somewhat after a seek or at the start/end of a chain
cannam@154 1617 boundary, as pre-skip, pre-roll, and end-trimming causes samples to be
cannam@154 1618 decoded but not played.
cannam@154 1619 \param _of The \c OggOpusFile from which to retrieve the bitrate.
cannam@154 1620 \return The bitrate, in bits per second, or a negative value on error.
cannam@154 1621 \retval #OP_FALSE No data has been decoded since any of the events
cannam@154 1622 described above.
cannam@154 1623 \retval #OP_EINVAL The stream was only partially open.*/
cannam@154 1624 opus_int32 op_bitrate_instant(OggOpusFile *_of) OP_ARG_NONNULL(1);
cannam@154 1625
cannam@154 1626 /**Obtain the current value of the position indicator for \a _of.
cannam@154 1627 \param _of The \c OggOpusFile from which to retrieve the position indicator.
cannam@154 1628 \return The byte position that is currently being read from.
cannam@154 1629 \retval #OP_EINVAL The stream was only partially open.*/
cannam@154 1630 opus_int64 op_raw_tell(const OggOpusFile *_of) OP_ARG_NONNULL(1);
cannam@154 1631
cannam@154 1632 /**Obtain the PCM offset of the next sample to be read.
cannam@154 1633 If the stream is not properly timestamped, this might not increment by the
cannam@154 1634 proper amount between reads, or even return monotonically increasing
cannam@154 1635 values.
cannam@154 1636 \param _of The \c OggOpusFile from which to retrieve the PCM offset.
cannam@154 1637 \return The PCM offset of the next sample to be read.
cannam@154 1638 \retval #OP_EINVAL The stream was only partially open.*/
cannam@154 1639 ogg_int64_t op_pcm_tell(const OggOpusFile *_of) OP_ARG_NONNULL(1);
cannam@154 1640
cannam@154 1641 /*@}*/
cannam@154 1642 /*@}*/
cannam@154 1643
cannam@154 1644 /**\defgroup stream_seeking Seeking*/
cannam@154 1645 /*@{*/
cannam@154 1646 /**\name Functions for seeking in Opus streams
cannam@154 1647
cannam@154 1648 These functions let you seek in Opus streams, if the underlying stream
cannam@154 1649 support it.
cannam@154 1650 Seeking is implemented for all built-in stream I/O routines, though some
cannam@154 1651 individual streams may not be seekable (pipes, live HTTP streams, or HTTP
cannam@154 1652 streams from a server that does not support <code>Range</code> requests).
cannam@154 1653
cannam@154 1654 op_raw_seek() is the fastest: it is guaranteed to perform at most one
cannam@154 1655 physical seek, but, since the target is a byte position, makes no guarantee
cannam@154 1656 how close to a given time it will come.
cannam@154 1657 op_pcm_seek() provides sample-accurate seeking.
cannam@154 1658 The number of physical seeks it requires is still quite small (often 1 or
cannam@154 1659 2, even in highly variable bitrate streams).
cannam@154 1660
cannam@154 1661 Seeking in Opus requires decoding some pre-roll amount before playback to
cannam@154 1662 allow the internal state to converge (as if recovering from packet loss).
cannam@154 1663 This is handled internally by <tt>libopusfile</tt>, but means there is
cannam@154 1664 little extra overhead for decoding up to the exact position requested
cannam@154 1665 (since it must decode some amount of audio anyway).
cannam@154 1666 It also means that decoding after seeking may not return exactly the same
cannam@154 1667 values as would be obtained by decoding the stream straight through.
cannam@154 1668 However, such differences are expected to be smaller than the loss
cannam@154 1669 introduced by Opus's lossy compression.*/
cannam@154 1670 /*@{*/
cannam@154 1671
cannam@154 1672 /**Seek to a byte offset relative to the <b>compressed</b> data.
cannam@154 1673 This also scans packets to update the PCM cursor.
cannam@154 1674 It will cross a logical bitstream boundary, but only if it can't get any
cannam@154 1675 packets out of the tail of the link to which it seeks.
cannam@154 1676 \param _of The \c OggOpusFile in which to seek.
cannam@154 1677 \param _byte_offset The byte position to seek to.
cannam@154 1678 This must be between 0 and #op_raw_total(\a _of,\c -1)
cannam@154 1679 (inclusive).
cannam@154 1680 \return 0 on success, or a negative error code on failure.
cannam@154 1681 \retval #OP_EREAD The underlying seek operation failed.
cannam@154 1682 \retval #OP_EINVAL The stream was only partially open, or the target was
cannam@154 1683 outside the valid range for the stream.
cannam@154 1684 \retval #OP_ENOSEEK This stream is not seekable.
cannam@154 1685 \retval #OP_EBADLINK Failed to initialize a decoder for a stream for an
cannam@154 1686 unknown reason.*/
cannam@154 1687 int op_raw_seek(OggOpusFile *_of,opus_int64 _byte_offset) OP_ARG_NONNULL(1);
cannam@154 1688
cannam@154 1689 /**Seek to the specified PCM offset, such that decoding will begin at exactly
cannam@154 1690 the requested position.
cannam@154 1691 \param _of The \c OggOpusFile in which to seek.
cannam@154 1692 \param _pcm_offset The PCM offset to seek to.
cannam@154 1693 This is in samples at 48 kHz relative to the start of the
cannam@154 1694 stream.
cannam@154 1695 \return 0 on success, or a negative value on error.
cannam@154 1696 \retval #OP_EREAD An underlying read or seek operation failed.
cannam@154 1697 \retval #OP_EINVAL The stream was only partially open, or the target was
cannam@154 1698 outside the valid range for the stream.
cannam@154 1699 \retval #OP_ENOSEEK This stream is not seekable.
cannam@154 1700 \retval #OP_EBADLINK We failed to find data we had seen before, or the
cannam@154 1701 bitstream structure was sufficiently malformed that
cannam@154 1702 seeking to the target destination was impossible.*/
cannam@154 1703 int op_pcm_seek(OggOpusFile *_of,ogg_int64_t _pcm_offset) OP_ARG_NONNULL(1);
cannam@154 1704
cannam@154 1705 /*@}*/
cannam@154 1706 /*@}*/
cannam@154 1707
cannam@154 1708 /**\defgroup stream_decoding Decoding*/
cannam@154 1709 /*@{*/
cannam@154 1710 /**\name Functions for decoding audio data
cannam@154 1711
cannam@154 1712 These functions retrieve actual decoded audio data from the stream.
cannam@154 1713 The general functions, op_read() and op_read_float() return 16-bit or
cannam@154 1714 floating-point output, both using native endian ordering.
cannam@154 1715 The number of channels returned can change from link to link in a chained
cannam@154 1716 stream.
cannam@154 1717 There are special functions, op_read_stereo() and op_read_float_stereo(),
cannam@154 1718 which always output two channels, to simplify applications which do not
cannam@154 1719 wish to handle multichannel audio.
cannam@154 1720 These downmix multichannel files to two channels, so they can always return
cannam@154 1721 samples in the same format for every link in a chained file.
cannam@154 1722
cannam@154 1723 If the rest of your audio processing chain can handle floating point, the
cannam@154 1724 floating-point routines should be preferred, as they prevent clipping and
cannam@154 1725 other issues which might be avoided entirely if, e.g., you scale down the
cannam@154 1726 volume at some other stage.
cannam@154 1727 However, if you intend to consume 16-bit samples directly, the conversion in
cannam@154 1728 <tt>libopusfile</tt> provides noise-shaping dithering and, if compiled
cannam@154 1729 against <tt>libopus</tt>&nbsp;1.1 or later, soft-clipping prevention.
cannam@154 1730
cannam@154 1731 <tt>libopusfile</tt> can also be configured at compile time to use the
cannam@154 1732 fixed-point <tt>libopus</tt> API.
cannam@154 1733 If so, <tt>libopusfile</tt>'s floating-point API may also be disabled.
cannam@154 1734 In that configuration, nothing in <tt>libopusfile</tt> will use any
cannam@154 1735 floating-point operations, to simplify support on devices without an
cannam@154 1736 adequate FPU.
cannam@154 1737
cannam@154 1738 \warning HTTPS streams may be be vulnerable to truncation attacks if you do
cannam@154 1739 not check the error return code from op_read_float() or its associated
cannam@154 1740 functions.
cannam@154 1741 If the remote peer does not close the connection gracefully (with a TLS
cannam@154 1742 "close notify" message), these functions will return #OP_EREAD instead of 0
cannam@154 1743 when they reach the end of the file.
cannam@154 1744 If you are reading from an <https:> URL (particularly if seeking is not
cannam@154 1745 supported), you should make sure to check for this error and warn the user
cannam@154 1746 appropriately.*/
cannam@154 1747 /*@{*/
cannam@154 1748
cannam@154 1749 /**Indicates that the decoding callback should produce signed 16-bit
cannam@154 1750 native-endian output samples.*/
cannam@154 1751 #define OP_DEC_FORMAT_SHORT (7008)
cannam@154 1752 /**Indicates that the decoding callback should produce 32-bit native-endian
cannam@154 1753 float samples.*/
cannam@154 1754 #define OP_DEC_FORMAT_FLOAT (7040)
cannam@154 1755
cannam@154 1756 /**Indicates that the decoding callback did not decode anything, and that
cannam@154 1757 <tt>libopusfile</tt> should decode normally instead.*/
cannam@154 1758 #define OP_DEC_USE_DEFAULT (6720)
cannam@154 1759
cannam@154 1760 /**Called to decode an Opus packet.
cannam@154 1761 This should invoke the functional equivalent of opus_multistream_decode() or
cannam@154 1762 opus_multistream_decode_float(), except that it returns 0 on success
cannam@154 1763 instead of the number of decoded samples (which is known a priori).
cannam@154 1764 \param _ctx The application-provided callback context.
cannam@154 1765 \param _decoder The decoder to use to decode the packet.
cannam@154 1766 \param[out] _pcm The buffer to decode into.
cannam@154 1767 This will always have enough room for \a _nchannels of
cannam@154 1768 \a _nsamples samples, which should be placed into this
cannam@154 1769 buffer interleaved.
cannam@154 1770 \param _op The packet to decode.
cannam@154 1771 This will always have its granule position set to a valid
cannam@154 1772 value.
cannam@154 1773 \param _nsamples The number of samples expected from the packet.
cannam@154 1774 \param _nchannels The number of channels expected from the packet.
cannam@154 1775 \param _format The desired sample output format.
cannam@154 1776 This is either #OP_DEC_FORMAT_SHORT or
cannam@154 1777 #OP_DEC_FORMAT_FLOAT.
cannam@154 1778 \param _li The index of the link from which this packet was decoded.
cannam@154 1779 \return A non-negative value on success, or a negative value on error.
cannam@154 1780 Any error codes should be the same as those returned by
cannam@154 1781 opus_multistream_decode() or opus_multistream_decode_float().
cannam@154 1782 Success codes are as follows:
cannam@154 1783 \retval 0 Decoding was successful.
cannam@154 1784 The application has filled the buffer with
cannam@154 1785 exactly <code>\a _nsamples*\a
cannam@154 1786 _nchannels</code> samples in the requested
cannam@154 1787 format.
cannam@154 1788 \retval #OP_DEC_USE_DEFAULT No decoding was done.
cannam@154 1789 <tt>libopusfile</tt> should do the decoding
cannam@154 1790 by itself instead.*/
cannam@154 1791 typedef int (*op_decode_cb_func)(void *_ctx,OpusMSDecoder *_decoder,void *_pcm,
cannam@154 1792 const ogg_packet *_op,int _nsamples,int _nchannels,int _format,int _li);
cannam@154 1793
cannam@154 1794 /**Sets the packet decode callback function.
cannam@154 1795 If set, this is called once for each packet that needs to be decoded.
cannam@154 1796 This can be used by advanced applications to do additional processing on the
cannam@154 1797 compressed or uncompressed data.
cannam@154 1798 For example, an application might save the final entropy coder state for
cannam@154 1799 debugging and testing purposes, or it might apply additional filters
cannam@154 1800 before the downmixing, dithering, or soft-clipping performed by
cannam@154 1801 <tt>libopusfile</tt>, so long as these filters do not introduce any
cannam@154 1802 latency.
cannam@154 1803
cannam@154 1804 A call to this function is no guarantee that the audio will eventually be
cannam@154 1805 delivered to the application.
cannam@154 1806 <tt>libopusfile</tt> may discard some or all of the decoded audio data
cannam@154 1807 (i.e., at the beginning or end of a link, or after a seek), however the
cannam@154 1808 callback is still required to provide all of it.
cannam@154 1809 \param _of The \c OggOpusFile on which to set the decode callback.
cannam@154 1810 \param _decode_cb The callback function to call.
cannam@154 1811 This may be <code>NULL</code> to disable calling the
cannam@154 1812 callback.
cannam@154 1813 \param _ctx The application-provided context pointer to pass to the
cannam@154 1814 callback on each call.*/
cannam@154 1815 void op_set_decode_callback(OggOpusFile *_of,
cannam@154 1816 op_decode_cb_func _decode_cb,void *_ctx) OP_ARG_NONNULL(1);
cannam@154 1817
cannam@154 1818 /**Gain offset type that indicates that the provided offset is relative to the
cannam@154 1819 header gain.
cannam@154 1820 This is the default.*/
cannam@154 1821 #define OP_HEADER_GAIN (0)
cannam@154 1822
cannam@154 1823 /**Gain offset type that indicates that the provided offset is relative to the
cannam@154 1824 R128_ALBUM_GAIN value (if any), in addition to the header gain.*/
cannam@154 1825 #define OP_ALBUM_GAIN (3007)
cannam@154 1826
cannam@154 1827 /**Gain offset type that indicates that the provided offset is relative to the
cannam@154 1828 R128_TRACK_GAIN value (if any), in addition to the header gain.*/
cannam@154 1829 #define OP_TRACK_GAIN (3008)
cannam@154 1830
cannam@154 1831 /**Gain offset type that indicates that the provided offset should be used as
cannam@154 1832 the gain directly, without applying any the header or track gains.*/
cannam@154 1833 #define OP_ABSOLUTE_GAIN (3009)
cannam@154 1834
cannam@154 1835 /**Sets the gain to be used for decoded output.
cannam@154 1836 By default, the gain in the header is applied with no additional offset.
cannam@154 1837 The total gain (including header gain and/or track gain, if applicable, and
cannam@154 1838 this offset), will be clamped to [-32768,32767]/256 dB.
cannam@154 1839 This is more than enough to saturate or underflow 16-bit PCM.
cannam@154 1840 \note The new gain will not be applied to any already buffered, decoded
cannam@154 1841 output.
cannam@154 1842 This means you cannot change it sample-by-sample, as at best it will be
cannam@154 1843 updated packet-by-packet.
cannam@154 1844 It is meant for setting a target volume level, rather than applying smooth
cannam@154 1845 fades, etc.
cannam@154 1846 \param _of The \c OggOpusFile on which to set the gain offset.
cannam@154 1847 \param _gain_type One of #OP_HEADER_GAIN, #OP_ALBUM_GAIN,
cannam@154 1848 #OP_TRACK_GAIN, or #OP_ABSOLUTE_GAIN.
cannam@154 1849 \param _gain_offset_q8 The gain offset to apply, in 1/256ths of a dB.
cannam@154 1850 \return 0 on success or a negative value on error.
cannam@154 1851 \retval #OP_EINVAL The \a _gain_type was unrecognized.*/
cannam@154 1852 int op_set_gain_offset(OggOpusFile *_of,
cannam@154 1853 int _gain_type,opus_int32 _gain_offset_q8) OP_ARG_NONNULL(1);
cannam@154 1854
cannam@154 1855 /**Sets whether or not dithering is enabled for 16-bit decoding.
cannam@154 1856 By default, when <tt>libopusfile</tt> is compiled to use floating-point
cannam@154 1857 internally, calling op_read() or op_read_stereo() will first decode to
cannam@154 1858 float, and then convert to fixed-point using noise-shaping dithering.
cannam@154 1859 This flag can be used to disable that dithering.
cannam@154 1860 When the application uses op_read_float() or op_read_float_stereo(), or when
cannam@154 1861 the library has been compiled to decode directly to fixed point, this flag
cannam@154 1862 has no effect.
cannam@154 1863 \param _of The \c OggOpusFile on which to enable or disable dithering.
cannam@154 1864 \param _enabled A non-zero value to enable dithering, or 0 to disable it.*/
cannam@154 1865 void op_set_dither_enabled(OggOpusFile *_of,int _enabled) OP_ARG_NONNULL(1);
cannam@154 1866
cannam@154 1867 /**Reads more samples from the stream.
cannam@154 1868 \note Although \a _buf_size must indicate the total number of values that
cannam@154 1869 can be stored in \a _pcm, the return value is the number of samples
cannam@154 1870 <em>per channel</em>.
cannam@154 1871 This is done because
cannam@154 1872 <ol>
cannam@154 1873 <li>The channel count cannot be known a priori (reading more samples might
cannam@154 1874 advance us into the next link, with a different channel count), so
cannam@154 1875 \a _buf_size cannot also be in units of samples per channel,</li>
cannam@154 1876 <li>Returning the samples per channel matches the <code>libopus</code> API
cannam@154 1877 as closely as we're able,</li>
cannam@154 1878 <li>Returning the total number of values instead of samples per channel
cannam@154 1879 would mean the caller would need a division to compute the samples per
cannam@154 1880 channel, and might worry about the possibility of getting back samples
cannam@154 1881 for some channels and not others, and</li>
cannam@154 1882 <li>This approach is relatively fool-proof: if an application passes too
cannam@154 1883 small a value to \a _buf_size, they will simply get fewer samples back,
cannam@154 1884 and if they assume the return value is the total number of values, then
cannam@154 1885 they will simply read too few (rather than reading too many and going
cannam@154 1886 off the end of the buffer).</li>
cannam@154 1887 </ol>
cannam@154 1888 \param _of The \c OggOpusFile from which to read.
cannam@154 1889 \param[out] _pcm A buffer in which to store the output PCM samples, as
cannam@154 1890 signed native-endian 16-bit values at 48&nbsp;kHz
cannam@154 1891 with a nominal range of <code>[-32768,32767)</code>.
cannam@154 1892 Multiple channels are interleaved using the
cannam@154 1893 <a href="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.3.9">Vorbis
cannam@154 1894 channel ordering</a>.
cannam@154 1895 This must have room for at least \a _buf_size values.
cannam@154 1896 \param _buf_size The number of values that can be stored in \a _pcm.
cannam@154 1897 It is recommended that this be large enough for at
cannam@154 1898 least 120 ms of data at 48 kHz per channel (5760
cannam@154 1899 values per channel).
cannam@154 1900 Smaller buffers will simply return less data, possibly
cannam@154 1901 consuming more memory to buffer the data internally.
cannam@154 1902 <tt>libopusfile</tt> may return less data than
cannam@154 1903 requested.
cannam@154 1904 If so, there is no guarantee that the remaining data
cannam@154 1905 in \a _pcm will be unmodified.
cannam@154 1906 \param[out] _li The index of the link this data was decoded from.
cannam@154 1907 You may pass <code>NULL</code> if you do not need this
cannam@154 1908 information.
cannam@154 1909 If this function fails (returning a negative value),
cannam@154 1910 this parameter is left unset.
cannam@154 1911 \return The number of samples read per channel on success, or a negative
cannam@154 1912 value on failure.
cannam@154 1913 The channel count can be retrieved on success by calling
cannam@154 1914 <code>op_head(_of,*_li)</code>.
cannam@154 1915 The number of samples returned may be 0 if the buffer was too small
cannam@154 1916 to store even a single sample for all channels, or if end-of-file
cannam@154 1917 was reached.
cannam@154 1918 The list of possible failure codes follows.
cannam@154 1919 Most of them can only be returned by unseekable, chained streams
cannam@154 1920 that encounter a new link.
cannam@154 1921 \retval #OP_HOLE There was a hole in the data, and some samples
cannam@154 1922 may have been skipped.
cannam@154 1923 Call this function again to continue decoding
cannam@154 1924 past the hole.
cannam@154 1925 \retval #OP_EREAD An underlying read operation failed.
cannam@154 1926 This may signal a truncation attack from an
cannam@154 1927 <https:> source.
cannam@154 1928 \retval #OP_EFAULT An internal memory allocation failed.
cannam@154 1929 \retval #OP_EIMPL An unseekable stream encountered a new link that
cannam@154 1930 used a feature that is not implemented, such as
cannam@154 1931 an unsupported channel family.
cannam@154 1932 \retval #OP_EINVAL The stream was only partially open.
cannam@154 1933 \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that
cannam@154 1934 did not have any logical Opus streams in it.
cannam@154 1935 \retval #OP_EBADHEADER An unseekable stream encountered a new link with a
cannam@154 1936 required header packet that was not properly
cannam@154 1937 formatted, contained illegal values, or was
cannam@154 1938 missing altogether.
cannam@154 1939 \retval #OP_EVERSION An unseekable stream encountered a new link with
cannam@154 1940 an ID header that contained an unrecognized
cannam@154 1941 version number.
cannam@154 1942 \retval #OP_EBADPACKET Failed to properly decode the next packet.
cannam@154 1943 \retval #OP_EBADLINK We failed to find data we had seen before.
cannam@154 1944 \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with
cannam@154 1945 a starting timestamp that failed basic validity
cannam@154 1946 checks.*/
cannam@154 1947 OP_WARN_UNUSED_RESULT int op_read(OggOpusFile *_of,
cannam@154 1948 opus_int16 *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1);
cannam@154 1949
cannam@154 1950 /**Reads more samples from the stream.
cannam@154 1951 \note Although \a _buf_size must indicate the total number of values that
cannam@154 1952 can be stored in \a _pcm, the return value is the number of samples
cannam@154 1953 <em>per channel</em>.
cannam@154 1954 <ol>
cannam@154 1955 <li>The channel count cannot be known a priori (reading more samples might
cannam@154 1956 advance us into the next link, with a different channel count), so
cannam@154 1957 \a _buf_size cannot also be in units of samples per channel,</li>
cannam@154 1958 <li>Returning the samples per channel matches the <code>libopus</code> API
cannam@154 1959 as closely as we're able,</li>
cannam@154 1960 <li>Returning the total number of values instead of samples per channel
cannam@154 1961 would mean the caller would need a division to compute the samples per
cannam@154 1962 channel, and might worry about the possibility of getting back samples
cannam@154 1963 for some channels and not others, and</li>
cannam@154 1964 <li>This approach is relatively fool-proof: if an application passes too
cannam@154 1965 small a value to \a _buf_size, they will simply get fewer samples back,
cannam@154 1966 and if they assume the return value is the total number of values, then
cannam@154 1967 they will simply read too few (rather than reading too many and going
cannam@154 1968 off the end of the buffer).</li>
cannam@154 1969 </ol>
cannam@154 1970 \param _of The \c OggOpusFile from which to read.
cannam@154 1971 \param[out] _pcm A buffer in which to store the output PCM samples as
cannam@154 1972 signed floats at 48&nbsp;kHz with a nominal range of
cannam@154 1973 <code>[-1.0,1.0]</code>.
cannam@154 1974 Multiple channels are interleaved using the
cannam@154 1975 <a href="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.3.9">Vorbis
cannam@154 1976 channel ordering</a>.
cannam@154 1977 This must have room for at least \a _buf_size floats.
cannam@154 1978 \param _buf_size The number of floats that can be stored in \a _pcm.
cannam@154 1979 It is recommended that this be large enough for at
cannam@154 1980 least 120 ms of data at 48 kHz per channel (5760
cannam@154 1981 samples per channel).
cannam@154 1982 Smaller buffers will simply return less data, possibly
cannam@154 1983 consuming more memory to buffer the data internally.
cannam@154 1984 If less than \a _buf_size values are returned,
cannam@154 1985 <tt>libopusfile</tt> makes no guarantee that the
cannam@154 1986 remaining data in \a _pcm will be unmodified.
cannam@154 1987 \param[out] _li The index of the link this data was decoded from.
cannam@154 1988 You may pass <code>NULL</code> if you do not need this
cannam@154 1989 information.
cannam@154 1990 If this function fails (returning a negative value),
cannam@154 1991 this parameter is left unset.
cannam@154 1992 \return The number of samples read per channel on success, or a negative
cannam@154 1993 value on failure.
cannam@154 1994 The channel count can be retrieved on success by calling
cannam@154 1995 <code>op_head(_of,*_li)</code>.
cannam@154 1996 The number of samples returned may be 0 if the buffer was too small
cannam@154 1997 to store even a single sample for all channels, or if end-of-file
cannam@154 1998 was reached.
cannam@154 1999 The list of possible failure codes follows.
cannam@154 2000 Most of them can only be returned by unseekable, chained streams
cannam@154 2001 that encounter a new link.
cannam@154 2002 \retval #OP_HOLE There was a hole in the data, and some samples
cannam@154 2003 may have been skipped.
cannam@154 2004 Call this function again to continue decoding
cannam@154 2005 past the hole.
cannam@154 2006 \retval #OP_EREAD An underlying read operation failed.
cannam@154 2007 This may signal a truncation attack from an
cannam@154 2008 <https:> source.
cannam@154 2009 \retval #OP_EFAULT An internal memory allocation failed.
cannam@154 2010 \retval #OP_EIMPL An unseekable stream encountered a new link that
cannam@154 2011 used a feature that is not implemented, such as
cannam@154 2012 an unsupported channel family.
cannam@154 2013 \retval #OP_EINVAL The stream was only partially open.
cannam@154 2014 \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that
cannam@154 2015 did not have any logical Opus streams in it.
cannam@154 2016 \retval #OP_EBADHEADER An unseekable stream encountered a new link with a
cannam@154 2017 required header packet that was not properly
cannam@154 2018 formatted, contained illegal values, or was
cannam@154 2019 missing altogether.
cannam@154 2020 \retval #OP_EVERSION An unseekable stream encountered a new link with
cannam@154 2021 an ID header that contained an unrecognized
cannam@154 2022 version number.
cannam@154 2023 \retval #OP_EBADPACKET Failed to properly decode the next packet.
cannam@154 2024 \retval #OP_EBADLINK We failed to find data we had seen before.
cannam@154 2025 \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with
cannam@154 2026 a starting timestamp that failed basic validity
cannam@154 2027 checks.*/
cannam@154 2028 OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of,
cannam@154 2029 float *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1);
cannam@154 2030
cannam@154 2031 /**Reads more samples from the stream and downmixes to stereo, if necessary.
cannam@154 2032 This function is intended for simple players that want a uniform output
cannam@154 2033 format, even if the channel count changes between links in a chained
cannam@154 2034 stream.
cannam@154 2035 \note \a _buf_size indicates the total number of values that can be stored
cannam@154 2036 in \a _pcm, while the return value is the number of samples <em>per
cannam@154 2037 channel</em>, even though the channel count is known, for consistency with
cannam@154 2038 op_read().
cannam@154 2039 \param _of The \c OggOpusFile from which to read.
cannam@154 2040 \param[out] _pcm A buffer in which to store the output PCM samples, as
cannam@154 2041 signed native-endian 16-bit values at 48&nbsp;kHz
cannam@154 2042 with a nominal range of <code>[-32768,32767)</code>.
cannam@154 2043 The left and right channels are interleaved in the
cannam@154 2044 buffer.
cannam@154 2045 This must have room for at least \a _buf_size values.
cannam@154 2046 \param _buf_size The number of values that can be stored in \a _pcm.
cannam@154 2047 It is recommended that this be large enough for at
cannam@154 2048 least 120 ms of data at 48 kHz per channel (11520
cannam@154 2049 values total).
cannam@154 2050 Smaller buffers will simply return less data, possibly
cannam@154 2051 consuming more memory to buffer the data internally.
cannam@154 2052 If less than \a _buf_size values are returned,
cannam@154 2053 <tt>libopusfile</tt> makes no guarantee that the
cannam@154 2054 remaining data in \a _pcm will be unmodified.
cannam@154 2055 \return The number of samples read per channel on success, or a negative
cannam@154 2056 value on failure.
cannam@154 2057 The number of samples returned may be 0 if the buffer was too small
cannam@154 2058 to store even a single sample for both channels, or if end-of-file
cannam@154 2059 was reached.
cannam@154 2060 The list of possible failure codes follows.
cannam@154 2061 Most of them can only be returned by unseekable, chained streams
cannam@154 2062 that encounter a new link.
cannam@154 2063 \retval #OP_HOLE There was a hole in the data, and some samples
cannam@154 2064 may have been skipped.
cannam@154 2065 Call this function again to continue decoding
cannam@154 2066 past the hole.
cannam@154 2067 \retval #OP_EREAD An underlying read operation failed.
cannam@154 2068 This may signal a truncation attack from an
cannam@154 2069 <https:> source.
cannam@154 2070 \retval #OP_EFAULT An internal memory allocation failed.
cannam@154 2071 \retval #OP_EIMPL An unseekable stream encountered a new link that
cannam@154 2072 used a feature that is not implemented, such as
cannam@154 2073 an unsupported channel family.
cannam@154 2074 \retval #OP_EINVAL The stream was only partially open.
cannam@154 2075 \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that
cannam@154 2076 did not have any logical Opus streams in it.
cannam@154 2077 \retval #OP_EBADHEADER An unseekable stream encountered a new link with a
cannam@154 2078 required header packet that was not properly
cannam@154 2079 formatted, contained illegal values, or was
cannam@154 2080 missing altogether.
cannam@154 2081 \retval #OP_EVERSION An unseekable stream encountered a new link with
cannam@154 2082 an ID header that contained an unrecognized
cannam@154 2083 version number.
cannam@154 2084 \retval #OP_EBADPACKET Failed to properly decode the next packet.
cannam@154 2085 \retval #OP_EBADLINK We failed to find data we had seen before.
cannam@154 2086 \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with
cannam@154 2087 a starting timestamp that failed basic validity
cannam@154 2088 checks.*/
cannam@154 2089 OP_WARN_UNUSED_RESULT int op_read_stereo(OggOpusFile *_of,
cannam@154 2090 opus_int16 *_pcm,int _buf_size) OP_ARG_NONNULL(1);
cannam@154 2091
cannam@154 2092 /**Reads more samples from the stream and downmixes to stereo, if necessary.
cannam@154 2093 This function is intended for simple players that want a uniform output
cannam@154 2094 format, even if the channel count changes between links in a chained
cannam@154 2095 stream.
cannam@154 2096 \note \a _buf_size indicates the total number of values that can be stored
cannam@154 2097 in \a _pcm, while the return value is the number of samples <em>per
cannam@154 2098 channel</em>, even though the channel count is known, for consistency with
cannam@154 2099 op_read_float().
cannam@154 2100 \param _of The \c OggOpusFile from which to read.
cannam@154 2101 \param[out] _pcm A buffer in which to store the output PCM samples, as
cannam@154 2102 signed floats at 48&nbsp;kHz with a nominal range of
cannam@154 2103 <code>[-1.0,1.0]</code>.
cannam@154 2104 The left and right channels are interleaved in the
cannam@154 2105 buffer.
cannam@154 2106 This must have room for at least \a _buf_size values.
cannam@154 2107 \param _buf_size The number of values that can be stored in \a _pcm.
cannam@154 2108 It is recommended that this be large enough for at
cannam@154 2109 least 120 ms of data at 48 kHz per channel (11520
cannam@154 2110 values total).
cannam@154 2111 Smaller buffers will simply return less data, possibly
cannam@154 2112 consuming more memory to buffer the data internally.
cannam@154 2113 If less than \a _buf_size values are returned,
cannam@154 2114 <tt>libopusfile</tt> makes no guarantee that the
cannam@154 2115 remaining data in \a _pcm will be unmodified.
cannam@154 2116 \return The number of samples read per channel on success, or a negative
cannam@154 2117 value on failure.
cannam@154 2118 The number of samples returned may be 0 if the buffer was too small
cannam@154 2119 to store even a single sample for both channels, or if end-of-file
cannam@154 2120 was reached.
cannam@154 2121 The list of possible failure codes follows.
cannam@154 2122 Most of them can only be returned by unseekable, chained streams
cannam@154 2123 that encounter a new link.
cannam@154 2124 \retval #OP_HOLE There was a hole in the data, and some samples
cannam@154 2125 may have been skipped.
cannam@154 2126 Call this function again to continue decoding
cannam@154 2127 past the hole.
cannam@154 2128 \retval #OP_EREAD An underlying read operation failed.
cannam@154 2129 This may signal a truncation attack from an
cannam@154 2130 <https:> source.
cannam@154 2131 \retval #OP_EFAULT An internal memory allocation failed.
cannam@154 2132 \retval #OP_EIMPL An unseekable stream encountered a new link that
cannam@154 2133 used a feature that is not implemented, such as
cannam@154 2134 an unsupported channel family.
cannam@154 2135 \retval #OP_EINVAL The stream was only partially open.
cannam@154 2136 \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that
cannam@154 2137 that did not have any logical Opus streams in it.
cannam@154 2138 \retval #OP_EBADHEADER An unseekable stream encountered a new link with a
cannam@154 2139 required header packet that was not properly
cannam@154 2140 formatted, contained illegal values, or was
cannam@154 2141 missing altogether.
cannam@154 2142 \retval #OP_EVERSION An unseekable stream encountered a new link with
cannam@154 2143 an ID header that contained an unrecognized
cannam@154 2144 version number.
cannam@154 2145 \retval #OP_EBADPACKET Failed to properly decode the next packet.
cannam@154 2146 \retval #OP_EBADLINK We failed to find data we had seen before.
cannam@154 2147 \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with
cannam@154 2148 a starting timestamp that failed basic validity
cannam@154 2149 checks.*/
cannam@154 2150 OP_WARN_UNUSED_RESULT int op_read_float_stereo(OggOpusFile *_of,
cannam@154 2151 float *_pcm,int _buf_size) OP_ARG_NONNULL(1);
cannam@154 2152
cannam@154 2153 /*@}*/
cannam@154 2154 /*@}*/
cannam@154 2155
cannam@154 2156 # if OP_GNUC_PREREQ(4,0)
cannam@154 2157 # pragma GCC visibility pop
cannam@154 2158 # endif
cannam@154 2159
cannam@154 2160 # if defined(__cplusplus)
cannam@154 2161 }
cannam@154 2162 # endif
cannam@154 2163
cannam@154 2164 #endif