annotate osx/include/opus/opusfile.h @ 69:7aeed7906520

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