annotate win32-msvc/include/opus/opusfile.h @ 70:9e21af8f0420

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