cannam@155: /******************************************************************** cannam@155: * * cannam@155: * THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. * cannam@155: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * cannam@155: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * cannam@155: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * cannam@155: * * cannam@155: * THE libopusfile SOURCE CODE IS (C) COPYRIGHT 1994-2012 * cannam@155: * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * cannam@155: * * cannam@155: ******************************************************************** cannam@155: cannam@155: function: stdio-based convenience library for opening/seeking/decoding cannam@155: last mod: $Id: vorbisfile.h 17182 2010-04-29 03:48:32Z xiphmont $ cannam@155: cannam@155: ********************************************************************/ cannam@155: #if !defined(_opusfile_h) cannam@155: # define _opusfile_h (1) cannam@155: cannam@155: /**\mainpage cannam@155: \section Introduction cannam@155: cannam@155: This is the documentation for the libopusfile C API. cannam@155: cannam@155: The libopusfile package provides a convenient high-level API for cannam@155: decoding and basic manipulation of all Ogg Opus audio streams. cannam@155: libopusfile is implemented as a layer on top of Xiph.Org's cannam@155: reference cannam@155: libogg cannam@155: and cannam@155: libopus cannam@155: libraries. cannam@155: cannam@155: libopusfile provides several sets of built-in routines for cannam@155: file/stream access, and may also use custom stream I/O routines provided by cannam@155: the embedded environment. cannam@155: There are built-in I/O routines provided for ANSI-compliant cannam@155: stdio (FILE *), memory buffers, and URLs cannam@155: (including URLs, plus optionally and URLs). cannam@155: cannam@155: \section Organization cannam@155: cannam@155: The main API is divided into several sections: cannam@155: - \ref stream_open_close cannam@155: - \ref stream_info cannam@155: - \ref stream_decoding cannam@155: - \ref stream_seeking cannam@155: cannam@155: Several additional sections are not tied to the main API. cannam@155: - \ref stream_callbacks cannam@155: - \ref header_info cannam@155: - \ref error_codes cannam@155: cannam@155: \section Overview cannam@155: cannam@155: The libopusfile API always decodes files to 48 kHz. cannam@155: The original sample rate is not preserved by the lossy compression, though cannam@155: it is stored in the header to allow you to resample to it after decoding cannam@155: (the libopusfile API does not currently provide a resampler, cannam@155: but the cannam@155: the cannam@155: Speex resampler is a good choice if you need one). cannam@155: In general, if you are playing back the audio, you should leave it at cannam@155: 48 kHz, provided your audio hardware supports it. cannam@155: When decoding to a file, it may be worth resampling back to the original cannam@155: sample rate, so as not to surprise users who might not expect the sample cannam@155: rate to change after encoding to Opus and decoding. cannam@155: cannam@155: Opus files can contain anywhere from 1 to 255 channels of audio. cannam@155: The channel mappings for up to 8 channels are the same as the cannam@155: Vorbis cannam@155: mappings. cannam@155: A special stereo API can convert everything to 2 channels, making it simple cannam@155: to support multichannel files in an application which only has stereo cannam@155: output. cannam@155: Although the libopusfile ABI provides support for the theoretical cannam@155: maximum number of channels, the current implementation does not support cannam@155: files with more than 8 channels, as they do not have well-defined channel cannam@155: mappings. cannam@155: cannam@155: Like all Ogg files, Opus files may be "chained". cannam@155: That is, multiple Opus files may be combined into a single, longer file just cannam@155: by concatenating the original files. cannam@155: This is commonly done in internet radio streaming, as it allows the title cannam@155: and artist to be updated each time the song changes, since each link in the cannam@155: chain includes its own set of metadata. cannam@155: cannam@155: libopusfile fully supports chained files. cannam@155: It will decode the first Opus stream found in each link of a chained file cannam@155: (ignoring any other streams that might be concurrently multiplexed with it, cannam@155: such as a video stream). cannam@155: cannam@155: The channel count can also change between links. cannam@155: If your application is not prepared to deal with this, it can use the stereo cannam@155: API to ensure the audio from all links will always get decoded into a cannam@155: common format. cannam@155: Since libopusfile always decodes to 48 kHz, you do not have to cannam@155: worry about the sample rate changing between links (as was possible with cannam@155: Vorbis). cannam@155: This makes application support for chained files with libopusfile cannam@155: very easy.*/ cannam@155: cannam@155: # if defined(__cplusplus) cannam@155: extern "C" { cannam@155: # endif cannam@155: cannam@155: # include cannam@155: # include cannam@155: # include cannam@155: # include cannam@155: cannam@155: /**@cond PRIVATE*/ cannam@155: cannam@155: /*Enable special features for gcc and gcc-compatible compilers.*/ cannam@155: # if !defined(OP_GNUC_PREREQ) cannam@155: # if defined(__GNUC__)&&defined(__GNUC_MINOR__) cannam@155: # define OP_GNUC_PREREQ(_maj,_min) \ cannam@155: ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) cannam@155: # else cannam@155: # define OP_GNUC_PREREQ(_maj,_min) 0 cannam@155: # endif cannam@155: # endif cannam@155: cannam@155: # if OP_GNUC_PREREQ(4,0) cannam@155: # pragma GCC visibility push(default) cannam@155: # endif cannam@155: cannam@155: typedef struct OpusHead OpusHead; cannam@155: typedef struct OpusTags OpusTags; cannam@155: typedef struct OpusPictureTag OpusPictureTag; cannam@155: typedef struct OpusServerInfo OpusServerInfo; cannam@155: typedef struct OpusFileCallbacks OpusFileCallbacks; cannam@155: typedef struct OggOpusFile OggOpusFile; cannam@155: cannam@155: /*Warning attributes for libopusfile functions.*/ cannam@155: # if OP_GNUC_PREREQ(3,4) cannam@155: # define OP_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) cannam@155: # else cannam@155: # define OP_WARN_UNUSED_RESULT cannam@155: # endif cannam@155: # if OP_GNUC_PREREQ(3,4) cannam@155: # define OP_ARG_NONNULL(_x) __attribute__((__nonnull__(_x))) cannam@155: # else cannam@155: # define OP_ARG_NONNULL(_x) cannam@155: # endif cannam@155: cannam@155: /**@endcond*/ cannam@155: cannam@155: /**\defgroup error_codes Error Codes*/ cannam@155: /*@{*/ cannam@155: /**\name List of possible error codes cannam@155: Many of the functions in this library return a negative error code when a cannam@155: function fails. cannam@155: This list provides a brief explanation of the common errors. cannam@155: See each individual function for more details on what a specific error code cannam@155: means in that context.*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**A request did not succeed.*/ cannam@155: #define OP_FALSE (-1) cannam@155: /*Currently not used externally.*/ cannam@155: #define OP_EOF (-2) cannam@155: /**There was a hole in the page sequence numbers (e.g., a page was corrupt or cannam@155: missing).*/ cannam@155: #define OP_HOLE (-3) cannam@155: /**An underlying read, seek, or tell operation failed when it should have cannam@155: succeeded.*/ cannam@155: #define OP_EREAD (-128) cannam@155: /**A NULL pointer was passed where one was unexpected, or an cannam@155: internal memory allocation failed, or an internal library error was cannam@155: encountered.*/ cannam@155: #define OP_EFAULT (-129) cannam@155: /**The stream used a feature that is not implemented, such as an unsupported cannam@155: channel family.*/ cannam@155: #define OP_EIMPL (-130) cannam@155: /**One or more parameters to a function were invalid.*/ cannam@155: #define OP_EINVAL (-131) cannam@155: /**A purported Ogg Opus stream did not begin with an Ogg page, a purported cannam@155: header packet did not start with one of the required strings, "OpusHead" or cannam@155: "OpusTags", or a link in a chained file was encountered that did not cannam@155: contain any logical Opus streams.*/ cannam@155: #define OP_ENOTFORMAT (-132) cannam@155: /**A required header packet was not properly formatted, contained illegal cannam@155: values, or was missing altogether.*/ cannam@155: #define OP_EBADHEADER (-133) cannam@155: /**The ID header contained an unrecognized version number.*/ cannam@155: #define OP_EVERSION (-134) cannam@155: /*Currently not used at all.*/ cannam@155: #define OP_ENOTAUDIO (-135) cannam@155: /**An audio packet failed to decode properly. cannam@155: This is usually caused by a multistream Ogg packet where the durations of cannam@155: the individual Opus packets contained in it are not all the same.*/ cannam@155: #define OP_EBADPACKET (-136) cannam@155: /**We failed to find data we had seen before, or the bitstream structure was cannam@155: sufficiently malformed that seeking to the target destination was cannam@155: impossible.*/ cannam@155: #define OP_EBADLINK (-137) cannam@155: /**An operation that requires seeking was requested on an unseekable stream.*/ cannam@155: #define OP_ENOSEEK (-138) cannam@155: /**The first or last granule position of a link failed basic validity checks.*/ cannam@155: #define OP_EBADTIMESTAMP (-139) cannam@155: cannam@155: /*@}*/ cannam@155: /*@}*/ cannam@155: cannam@155: /**\defgroup header_info Header Information*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**The maximum number of channels in an Ogg Opus stream.*/ cannam@155: #define OPUS_CHANNEL_COUNT_MAX (255) cannam@155: cannam@155: /**Ogg Opus bitstream information. cannam@155: This contains the basic playback parameters for a stream, and corresponds to cannam@155: the initial ID header packet of an Ogg Opus stream.*/ cannam@155: struct OpusHead{ cannam@155: /**The Ogg Opus format version, in the range 0...255. cannam@155: The top 4 bits represent a "major" version, and the bottom four bits cannam@155: represent backwards-compatible "minor" revisions. cannam@155: The current specification describes version 1. cannam@155: This library will recognize versions up through 15 as backwards compatible cannam@155: with the current specification. cannam@155: An earlier draft of the specification described a version 0, but the only cannam@155: difference between version 1 and version 0 is that version 0 did cannam@155: not specify the semantics for handling the version field.*/ cannam@155: int version; cannam@155: /**The number of channels, in the range 1...255.*/ cannam@155: int channel_count; cannam@155: /**The number of samples that should be discarded from the beginning of the cannam@155: stream.*/ cannam@155: unsigned pre_skip; cannam@155: /**The sampling rate of the original input. cannam@155: All Opus audio is coded at 48 kHz, and should also be decoded at 48 kHz cannam@155: for playback (unless the target hardware does not support this sampling cannam@155: rate). cannam@155: However, this field may be used to resample the audio back to the original cannam@155: sampling rate, for example, when saving the output to a file.*/ cannam@155: opus_uint32 input_sample_rate; cannam@155: /**The gain to apply to the decoded output, in dB, as a Q8 value in the range cannam@155: -32768...32767. cannam@155: The libopusfile API will automatically apply this gain to the cannam@155: decoded output before returning it, scaling it by cannam@155: pow(10,output_gain/(20.0*256)). cannam@155: You can adjust this behavior with op_set_gain_offset().*/ cannam@155: int output_gain; cannam@155: /**The channel mapping family, in the range 0...255. cannam@155: Channel mapping family 0 covers mono or stereo in a single stream. cannam@155: Channel mapping family 1 covers 1 to 8 channels in one or more streams, cannam@155: using the Vorbis speaker assignments. cannam@155: Channel mapping family 255 covers 1 to 255 channels in one or more cannam@155: streams, but without any defined speaker assignment.*/ cannam@155: int mapping_family; cannam@155: /**The number of Opus streams in each Ogg packet, in the range 1...255.*/ cannam@155: int stream_count; cannam@155: /**The number of coupled Opus streams in each Ogg packet, in the range cannam@155: 0...127. cannam@155: This must satisfy 0 <= coupled_count <= stream_count and cannam@155: coupled_count + stream_count <= 255. cannam@155: The coupled streams appear first, before all uncoupled streams, in an Ogg cannam@155: Opus packet.*/ cannam@155: int coupled_count; cannam@155: /**The mapping from coded stream channels to output channels. cannam@155: Let index=mapping[k] be the value for channel k. cannam@155: If index<2*coupled_count, then it refers to the left channel cannam@155: from stream (index/2) if even, and the right channel from cannam@155: stream (index/2) if odd. cannam@155: Otherwise, it refers to the output of the uncoupled stream cannam@155: (index-coupled_count).*/ cannam@155: unsigned char mapping[OPUS_CHANNEL_COUNT_MAX]; cannam@155: }; cannam@155: cannam@155: /**The metadata from an Ogg Opus stream. cannam@155: cannam@155: This structure holds the in-stream metadata corresponding to the 'comment' cannam@155: header packet of an Ogg Opus stream. cannam@155: The comment header is meant to be used much like someone jotting a quick cannam@155: note on the label of a CD. cannam@155: It should be a short, to the point text note that can be more than a couple cannam@155: words, but not more than a short paragraph. cannam@155: cannam@155: The metadata is stored as a series of (tag, value) pairs, in length-encoded cannam@155: string vectors, using the same format as Vorbis (without the final "framing cannam@155: bit"), Theora, and Speex, except for the packet header. cannam@155: The first occurrence of the '=' character delimits the tag and value. cannam@155: A particular tag may occur more than once, and order is significant. cannam@155: The character set encoding for the strings is always UTF-8, but the tag cannam@155: names are limited to ASCII, and treated as case-insensitive. cannam@155: See the Vorbis cannam@155: comment header specification for details. cannam@155: cannam@155: In filling in this structure, libopusfile will null-terminate the cannam@155: #user_comments strings for safety. cannam@155: However, the bitstream format itself treats them as 8-bit clean vectors, cannam@155: possibly containing NUL characters, so the #comment_lengths array should be cannam@155: treated as their authoritative length. cannam@155: cannam@155: This structure is binary and source-compatible with a cannam@155: vorbis_comment, and pointers to it may be freely cast to cannam@155: vorbis_comment pointers, and vice versa. cannam@155: It is provided as a separate type to avoid introducing a compile-time cannam@155: dependency on the libvorbis headers.*/ cannam@155: struct OpusTags{ cannam@155: /**The array of comment string vectors.*/ cannam@155: char **user_comments; cannam@155: /**An array of the corresponding length of each vector, in bytes.*/ cannam@155: int *comment_lengths; cannam@155: /**The total number of comment streams.*/ cannam@155: int comments; cannam@155: /**The null-terminated vendor string. cannam@155: This identifies the software used to encode the stream.*/ cannam@155: char *vendor; cannam@155: }; cannam@155: cannam@155: /**\name Picture tag image formats*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**The MIME type was not recognized, or the image data did not match the cannam@155: declared MIME type.*/ cannam@155: #define OP_PIC_FORMAT_UNKNOWN (-1) cannam@155: /**The MIME type indicates the image data is really a URL.*/ cannam@155: #define OP_PIC_FORMAT_URL (0) cannam@155: /**The image is a JPEG.*/ cannam@155: #define OP_PIC_FORMAT_JPEG (1) cannam@155: /**The image is a PNG.*/ cannam@155: #define OP_PIC_FORMAT_PNG (2) cannam@155: /**The image is a GIF.*/ cannam@155: #define OP_PIC_FORMAT_GIF (3) cannam@155: cannam@155: /*@}*/ cannam@155: cannam@155: /**The contents of a METADATA_BLOCK_PICTURE tag.*/ cannam@155: struct OpusPictureTag{ cannam@155: /**The picture type according to the ID3v2 APIC frame: cannam@155:
    cannam@155:
  1. Other
  2. cannam@155:
  3. 32x32 pixels 'file icon' (PNG only)
  4. cannam@155:
  5. Other file icon
  6. cannam@155:
  7. Cover (front)
  8. cannam@155:
  9. Cover (back)
  10. cannam@155:
  11. Leaflet page
  12. cannam@155:
  13. Media (e.g. label side of CD)
  14. cannam@155:
  15. Lead artist/lead performer/soloist
  16. cannam@155:
  17. Artist/performer
  18. cannam@155:
  19. Conductor
  20. cannam@155:
  21. Band/Orchestra
  22. cannam@155:
  23. Composer
  24. cannam@155:
  25. Lyricist/text writer
  26. cannam@155:
  27. Recording Location
  28. cannam@155:
  29. During recording
  30. cannam@155:
  31. During performance
  32. cannam@155:
  33. Movie/video screen capture
  34. cannam@155:
  35. A bright colored fish
  36. cannam@155:
  37. Illustration
  38. cannam@155:
  39. Band/artist logotype
  40. cannam@155:
  41. Publisher/Studio logotype
  42. cannam@155:
cannam@155: Others are reserved and should not be used. cannam@155: There may only be one each of picture type 1 and 2 in a file.*/ cannam@155: opus_int32 type; cannam@155: /**The MIME type of the picture, in printable ASCII characters 0x20-0x7E. cannam@155: The MIME type may also be "-->" to signify that the data part cannam@155: is a URL pointing to the picture instead of the picture data itself. cannam@155: In this case, a terminating NUL is appended to the URL string in #data, cannam@155: but #data_length is set to the length of the string excluding that cannam@155: terminating NUL.*/ cannam@155: char *mime_type; cannam@155: /**The description of the picture, in UTF-8.*/ cannam@155: char *description; cannam@155: /**The width of the picture in pixels.*/ cannam@155: opus_uint32 width; cannam@155: /**The height of the picture in pixels.*/ cannam@155: opus_uint32 height; cannam@155: /**The color depth of the picture in bits-per-pixel (not cannam@155: bits-per-channel).*/ cannam@155: opus_uint32 depth; cannam@155: /**For indexed-color pictures (e.g., GIF), the number of colors used, or 0 cannam@155: for non-indexed pictures.*/ cannam@155: opus_uint32 colors; cannam@155: /**The length of the picture data in bytes.*/ cannam@155: opus_uint32 data_length; cannam@155: /**The binary picture data.*/ cannam@155: unsigned char *data; cannam@155: /**The format of the picture data, if known. cannam@155: One of cannam@155:
    cannam@155:
  • #OP_PIC_FORMAT_UNKNOWN,
  • cannam@155:
  • #OP_PIC_FORMAT_URL,
  • cannam@155:
  • #OP_PIC_FORMAT_JPEG,
  • cannam@155:
  • #OP_PIC_FORMAT_PNG, or
  • cannam@155:
  • #OP_PIC_FORMAT_GIF.
  • cannam@155:
*/ cannam@155: int format; cannam@155: }; cannam@155: cannam@155: /**\name Functions for manipulating header data cannam@155: cannam@155: These functions manipulate the #OpusHead and #OpusTags structures, cannam@155: which describe the audio parameters and tag-value metadata, respectively. cannam@155: These can be used to query the headers returned by libopusfile, or cannam@155: to parse Opus headers from sources other than an Ogg Opus stream, provided cannam@155: they use the same format.*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**Parses the contents of the ID header packet of an Ogg Opus stream. cannam@155: \param[out] _head Returns the contents of the parsed packet. cannam@155: The contents of this structure are untouched on error. cannam@155: This may be NULL to merely test the header cannam@155: for validity. cannam@155: \param[in] _data The contents of the ID header packet. cannam@155: \param _len The number of bytes of data in the ID header packet. cannam@155: \return 0 on success or a negative value on error. cannam@155: \retval #OP_ENOTFORMAT If the data does not start with the "OpusHead" cannam@155: string. cannam@155: \retval #OP_EVERSION If the version field signaled a version this library cannam@155: does not know how to parse. cannam@155: \retval #OP_EIMPL If the channel mapping family was 255, which general cannam@155: purpose players should not attempt to play. cannam@155: \retval #OP_EBADHEADER If the contents of the packet otherwise violate the cannam@155: Ogg Opus specification: cannam@155:
    cannam@155:
  • Insufficient data,
  • cannam@155:
  • Too much data for the known minor versions,
  • cannam@155:
  • An unrecognized channel mapping family,
  • cannam@155:
  • Zero channels or too many channels,
  • cannam@155:
  • Zero coded streams,
  • cannam@155:
  • Too many coupled streams, or
  • cannam@155:
  • An invalid channel mapping index.
  • cannam@155:
*/ cannam@155: OP_WARN_UNUSED_RESULT int opus_head_parse(OpusHead *_head, cannam@155: const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Converts a granule position to a sample offset for a given Ogg Opus stream. cannam@155: The sample offset is simply _gp-_head->pre_skip. cannam@155: Granule position values smaller than OpusHead#pre_skip correspond to audio cannam@155: that should never be played, and thus have no associated sample offset. cannam@155: This function returns -1 for such values. cannam@155: This function also correctly handles extremely large granule positions, cannam@155: which may have wrapped around to a negative number when stored in a signed cannam@155: ogg_int64_t value. cannam@155: \param _head The #OpusHead information from the ID header of the stream. cannam@155: \param _gp The granule position to convert. cannam@155: \return The sample offset associated with the given granule position cannam@155: (counting at a 48 kHz sampling rate), or the special value -1 on cannam@155: error (i.e., the granule position was smaller than the pre-skip cannam@155: amount).*/ cannam@155: ogg_int64_t opus_granule_sample(const OpusHead *_head,ogg_int64_t _gp) cannam@155: OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Parses the contents of the 'comment' header packet of an Ogg Opus stream. cannam@155: \param[out] _tags An uninitialized #OpusTags structure. cannam@155: This returns the contents of the parsed packet. cannam@155: The contents of this structure are untouched on error. cannam@155: This may be NULL to merely test the header cannam@155: for validity. cannam@155: \param[in] _data The contents of the 'comment' header packet. cannam@155: \param _len The number of bytes of data in the 'info' header packet. cannam@155: \retval 0 Success. cannam@155: \retval #OP_ENOTFORMAT If the data does not start with the "OpusTags" cannam@155: string. cannam@155: \retval #OP_EBADHEADER If the contents of the packet otherwise violate the cannam@155: Ogg Opus specification. cannam@155: \retval #OP_EFAULT If there wasn't enough memory to store the tags.*/ cannam@155: OP_WARN_UNUSED_RESULT int opus_tags_parse(OpusTags *_tags, cannam@155: const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Performs a deep copy of an #OpusTags structure. cannam@155: \param _dst The #OpusTags structure to copy into. cannam@155: If this function fails, the contents of this structure remain cannam@155: untouched. cannam@155: \param _src The #OpusTags structure to copy from. cannam@155: \retval 0 Success. cannam@155: \retval #OP_EFAULT If there wasn't enough memory to copy the tags.*/ cannam@155: int opus_tags_copy(OpusTags *_dst,const OpusTags *_src) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Initializes an #OpusTags structure. cannam@155: This should be called on a freshly allocated #OpusTags structure before cannam@155: attempting to use it. cannam@155: \param _tags The #OpusTags structure to initialize.*/ cannam@155: void opus_tags_init(OpusTags *_tags) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Add a (tag, value) pair to an initialized #OpusTags structure. cannam@155: \note Neither opus_tags_add() nor opus_tags_add_comment() support values cannam@155: containing embedded NULs, although the bitstream format does support them. cannam@155: To add such tags, you will need to manipulate the #OpusTags structure cannam@155: directly. cannam@155: \param _tags The #OpusTags structure to add the (tag, value) pair to. cannam@155: \param _tag A NUL-terminated, case-insensitive, ASCII string containing cannam@155: the tag to add (without an '=' character). cannam@155: \param _value A NUL-terminated UTF-8 containing the corresponding value. cannam@155: \return 0 on success, or a negative value on failure. cannam@155: \retval #OP_EFAULT An internal memory allocation failed.*/ cannam@155: int opus_tags_add(OpusTags *_tags,const char *_tag,const char *_value) cannam@155: OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) OP_ARG_NONNULL(3); cannam@155: cannam@155: /**Add a comment to an initialized #OpusTags structure. cannam@155: \note Neither opus_tags_add_comment() nor opus_tags_add() support comments cannam@155: containing embedded NULs, although the bitstream format does support them. cannam@155: To add such tags, you will need to manipulate the #OpusTags structure cannam@155: directly. cannam@155: \param _tags The #OpusTags structure to add the comment to. cannam@155: \param _comment A NUL-terminated UTF-8 string containing the comment in cannam@155: "TAG=value" form. cannam@155: \return 0 on success, or a negative value on failure. cannam@155: \retval #OP_EFAULT An internal memory allocation failed.*/ cannam@155: int opus_tags_add_comment(OpusTags *_tags,const char *_comment) cannam@155: OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Replace the binary suffix data at the end of the packet (if any). cannam@155: \param _tags An initialized #OpusTags structure. cannam@155: \param _data A buffer of binary data to append after the encoded user cannam@155: comments. cannam@155: The least significant bit of the first byte of this data must cannam@155: be set (to ensure the data is preserved by other editors). cannam@155: \param _len The number of bytes of binary data to append. cannam@155: This may be zero to remove any existing binary suffix data. cannam@155: \return 0 on success, or a negative value on error. cannam@155: \retval #OP_EINVAL \a _len was negative, or \a _len was positive but cannam@155: \a _data was NULL or the least significant cannam@155: bit of the first byte was not set. cannam@155: \retval #OP_EFAULT An internal memory allocation failed.*/ cannam@155: int opus_tags_set_binary_suffix(OpusTags *_tags, cannam@155: const unsigned char *_data,int _len) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Look up a comment value by its tag. cannam@155: \param _tags An initialized #OpusTags structure. cannam@155: \param _tag The tag to look up. cannam@155: \param _count The instance of the tag. cannam@155: The same tag can appear multiple times, each with a distinct cannam@155: value, so an index is required to retrieve them all. cannam@155: The order in which these values appear is significant and cannam@155: should be preserved. cannam@155: Use opus_tags_query_count() to get the legal range for the cannam@155: \a _count parameter. cannam@155: \return A pointer to the queried tag's value. cannam@155: This points directly to data in the #OpusTags structure. cannam@155: It should not be modified or freed by the application, and cannam@155: modifications to the structure may invalidate the pointer. cannam@155: \retval NULL If no matching tag is found.*/ cannam@155: const char *opus_tags_query(const OpusTags *_tags,const char *_tag,int _count) cannam@155: OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Look up the number of instances of a tag. cannam@155: Call this first when querying for a specific tag and then iterate over the cannam@155: number of instances with separate calls to opus_tags_query() to retrieve cannam@155: all the values for that tag in order. cannam@155: \param _tags An initialized #OpusTags structure. cannam@155: \param _tag The tag to look up. cannam@155: \return The number of instances of this particular tag.*/ cannam@155: int opus_tags_query_count(const OpusTags *_tags,const char *_tag) cannam@155: OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Retrieve the binary suffix data at the end of the packet (if any). cannam@155: \param _tags An initialized #OpusTags structure. cannam@155: \param[out] _len Returns the number of bytes of binary suffix data returned. cannam@155: \return A pointer to the binary suffix data, or NULL if none cannam@155: was present.*/ cannam@155: const unsigned char *opus_tags_get_binary_suffix(const OpusTags *_tags, cannam@155: int *_len) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Get the album gain from an R128_ALBUM_GAIN tag, if one was specified. cannam@155: This searches for the first R128_ALBUM_GAIN tag with a valid signed, cannam@155: 16-bit decimal integer value and returns the value. cannam@155: This routine is exposed merely for convenience for applications which wish cannam@155: to do something special with the album gain (i.e., display it). cannam@155: If you simply wish to apply the album gain instead of the header gain, you cannam@155: can use op_set_gain_offset() with an #OP_ALBUM_GAIN type and no offset. cannam@155: \param _tags An initialized #OpusTags structure. cannam@155: \param[out] _gain_q8 The album gain, in 1/256ths of a dB. cannam@155: This will lie in the range [-32768,32767], and should cannam@155: be applied in addition to the header gain. cannam@155: On error, no value is returned, and the previous cannam@155: contents remain unchanged. cannam@155: \return 0 on success, or a negative value on error. cannam@155: \retval #OP_FALSE There was no album gain available in the given tags.*/ cannam@155: int opus_tags_get_album_gain(const OpusTags *_tags,int *_gain_q8) cannam@155: OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Get the track gain from an R128_TRACK_GAIN tag, if one was specified. cannam@155: This searches for the first R128_TRACK_GAIN tag with a valid signed, cannam@155: 16-bit decimal integer value and returns the value. cannam@155: This routine is exposed merely for convenience for applications which wish cannam@155: to do something special with the track gain (i.e., display it). cannam@155: If you simply wish to apply the track gain instead of the header gain, you cannam@155: can use op_set_gain_offset() with an #OP_TRACK_GAIN type and no offset. cannam@155: \param _tags An initialized #OpusTags structure. cannam@155: \param[out] _gain_q8 The track gain, in 1/256ths of a dB. cannam@155: This will lie in the range [-32768,32767], and should cannam@155: be applied in addition to the header gain. cannam@155: On error, no value is returned, and the previous cannam@155: contents remain unchanged. cannam@155: \return 0 on success, or a negative value on error. cannam@155: \retval #OP_FALSE There was no track gain available in the given tags.*/ cannam@155: int opus_tags_get_track_gain(const OpusTags *_tags,int *_gain_q8) cannam@155: OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Clears the #OpusTags structure. cannam@155: This should be called on an #OpusTags structure after it is no longer cannam@155: needed. cannam@155: It will free all memory used by the structure members. cannam@155: \param _tags The #OpusTags structure to clear.*/ cannam@155: void opus_tags_clear(OpusTags *_tags) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Check if \a _comment is an instance of a \a _tag_name tag. cannam@155: \see opus_tagncompare cannam@155: \param _tag_name A NUL-terminated, case-insensitive, ASCII string containing cannam@155: the name of the tag to check for (without the terminating cannam@155: '=' character). cannam@155: \param _comment The comment string to check. cannam@155: \return An integer less than, equal to, or greater than zero if \a _comment cannam@155: is found respectively, to be less than, to match, or be greater cannam@155: than a "tag=value" string whose tag matches \a _tag_name.*/ cannam@155: int opus_tagcompare(const char *_tag_name,const char *_comment); cannam@155: cannam@155: /**Check if \a _comment is an instance of a \a _tag_name tag. cannam@155: This version is slightly more efficient than opus_tagcompare() if the length cannam@155: of the tag name is already known (e.g., because it is a constant). cannam@155: \see opus_tagcompare cannam@155: \param _tag_name A case-insensitive ASCII string containing the name of the cannam@155: tag to check for (without the terminating '=' character). cannam@155: \param _tag_len The number of characters in the tag name. cannam@155: This must be non-negative. cannam@155: \param _comment The comment string to check. cannam@155: \return An integer less than, equal to, or greater than zero if \a _comment cannam@155: is found respectively, to be less than, to match, or be greater cannam@155: than a "tag=value" string whose tag matches the first \a _tag_len cannam@155: characters of \a _tag_name.*/ cannam@155: int opus_tagncompare(const char *_tag_name,int _tag_len,const char *_comment); cannam@155: cannam@155: /**Parse a single METADATA_BLOCK_PICTURE tag. cannam@155: This decodes the BASE64-encoded content of the tag and returns a structure cannam@155: with the MIME type, description, image parameters (if known), and the cannam@155: compressed image data. cannam@155: If the MIME type indicates the presence of an image format we recognize cannam@155: (JPEG, PNG, or GIF) and the actual image data contains the magic signature cannam@155: associated with that format, then the OpusPictureTag::format field will be cannam@155: set to the corresponding format. cannam@155: This is provided as a convenience to avoid requiring applications to parse cannam@155: the MIME type and/or do their own format detection for the commonly used cannam@155: formats. cannam@155: In this case, we also attempt to extract the image parameters directly from cannam@155: the image data (overriding any that were present in the tag, which the cannam@155: specification says applications are not meant to rely on). cannam@155: The application must still provide its own support for actually decoding the cannam@155: image data and, if applicable, retrieving that data from URLs. cannam@155: \param[out] _pic Returns the parsed picture data. cannam@155: No sanitation is done on the type, MIME type, or cannam@155: description fields, so these might return invalid values. cannam@155: The contents of this structure are left unmodified on cannam@155: failure. cannam@155: \param _tag The METADATA_BLOCK_PICTURE tag contents. cannam@155: The leading "METADATA_BLOCK_PICTURE=" portion is optional, cannam@155: to allow the function to be used on either directly on the cannam@155: values in OpusTags::user_comments or on the return value cannam@155: of opus_tags_query(). cannam@155: \return 0 on success or a negative value on error. cannam@155: \retval #OP_ENOTFORMAT The METADATA_BLOCK_PICTURE contents were not valid. cannam@155: \retval #OP_EFAULT There was not enough memory to store the picture tag cannam@155: contents.*/ cannam@155: OP_WARN_UNUSED_RESULT int opus_picture_tag_parse(OpusPictureTag *_pic, cannam@155: const char *_tag) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Initializes an #OpusPictureTag structure. cannam@155: This should be called on a freshly allocated #OpusPictureTag structure cannam@155: before attempting to use it. cannam@155: \param _pic The #OpusPictureTag structure to initialize.*/ cannam@155: void opus_picture_tag_init(OpusPictureTag *_pic) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Clears the #OpusPictureTag structure. cannam@155: This should be called on an #OpusPictureTag structure after it is no longer cannam@155: needed. cannam@155: It will free all memory used by the structure members. cannam@155: \param _pic The #OpusPictureTag structure to clear.*/ cannam@155: void opus_picture_tag_clear(OpusPictureTag *_pic) OP_ARG_NONNULL(1); cannam@155: cannam@155: /*@}*/ cannam@155: cannam@155: /*@}*/ cannam@155: cannam@155: /**\defgroup url_options URL Reading Options*/ cannam@155: /*@{*/ cannam@155: /**\name URL reading options cannam@155: Options for op_url_stream_create() and associated functions. cannam@155: These allow you to provide proxy configuration parameters, skip SSL cannam@155: certificate checks, etc. cannam@155: Options are processed in order, and if the same option is passed multiple cannam@155: times, only the value specified by the last occurrence has an effect cannam@155: (unless otherwise specified). cannam@155: They may be expanded in the future.*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**@cond PRIVATE*/ cannam@155: cannam@155: /*These are the raw numbers used to define the request codes. cannam@155: They should not be used directly.*/ cannam@155: #define OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST (6464) cannam@155: #define OP_HTTP_PROXY_HOST_REQUEST (6528) cannam@155: #define OP_HTTP_PROXY_PORT_REQUEST (6592) cannam@155: #define OP_HTTP_PROXY_USER_REQUEST (6656) cannam@155: #define OP_HTTP_PROXY_PASS_REQUEST (6720) cannam@155: #define OP_GET_SERVER_INFO_REQUEST (6784) cannam@155: cannam@155: #define OP_URL_OPT(_request) ((_request)+(char *)0) cannam@155: cannam@155: /*These macros trigger compilation errors or warnings if the wrong types are cannam@155: provided to one of the URL options.*/ cannam@155: #define OP_CHECK_INT(_x) ((void)((_x)==(opus_int32)0),(opus_int32)(_x)) cannam@155: #define OP_CHECK_CONST_CHAR_PTR(_x) ((_x)+((_x)-(const char *)(_x))) cannam@155: #define OP_CHECK_SERVER_INFO_PTR(_x) ((_x)+((_x)-(OpusServerInfo *)(_x))) cannam@155: cannam@155: /**@endcond*/ cannam@155: cannam@155: /**HTTP/Shoutcast/Icecast server information associated with a URL.*/ cannam@155: struct OpusServerInfo{ cannam@155: /**The name of the server (icy-name/ice-name). cannam@155: This is NULL if there was no icy-name or cannam@155: ice-name header.*/ cannam@155: char *name; cannam@155: /**A short description of the server (icy-description/ice-description). cannam@155: This is NULL if there was no icy-description or cannam@155: ice-description header.*/ cannam@155: char *description; cannam@155: /**The genre the server falls under (icy-genre/ice-genre). cannam@155: This is NULL if there was no icy-genre or cannam@155: ice-genre header.*/ cannam@155: char *genre; cannam@155: /**The homepage for the server (icy-url/ice-url). cannam@155: This is NULL if there was no icy-url or cannam@155: ice-url header.*/ cannam@155: char *url; cannam@155: /**The software used by the origin server (Server). cannam@155: This is NULL if there was no Server header.*/ cannam@155: char *server; cannam@155: /**The media type of the entity sent to the recepient (Content-Type). cannam@155: This is NULL if there was no Content-Type cannam@155: header.*/ cannam@155: char *content_type; cannam@155: /**The nominal stream bitrate in kbps (icy-br/ice-bitrate). cannam@155: This is -1 if there was no icy-br or cannam@155: ice-bitrate header.*/ cannam@155: opus_int32 bitrate_kbps; cannam@155: /**Flag indicating whether the server is public (1) or not cannam@155: (0) (icy-pub/ice-public). cannam@155: This is -1 if there was no icy-pub or cannam@155: ice-public header.*/ cannam@155: int is_public; cannam@155: /**Flag indicating whether the server is using HTTPS instead of HTTP. cannam@155: This is 0 unless HTTPS is being used. cannam@155: This may not match the protocol used in the original URL if there were cannam@155: redirections.*/ cannam@155: int is_ssl; cannam@155: }; cannam@155: cannam@155: /**Initializes an #OpusServerInfo structure. cannam@155: All fields are set as if the corresponding header was not available. cannam@155: \param _info The #OpusServerInfo structure to initialize. cannam@155: \note If you use this function, you must link against libopusurl.*/ cannam@155: void opus_server_info_init(OpusServerInfo *_info) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Clears the #OpusServerInfo structure. cannam@155: This should be called on an #OpusServerInfo structure after it is no longer cannam@155: needed. cannam@155: It will free all memory used by the structure members. cannam@155: \param _info The #OpusServerInfo structure to clear. cannam@155: \note If you use this function, you must link against libopusurl.*/ cannam@155: void opus_server_info_clear(OpusServerInfo *_info) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Skip the certificate check when connecting via TLS/SSL (https). cannam@155: \param _b opus_int32: Whether or not to skip the certificate cannam@155: check. cannam@155: The check will be skipped if \a _b is non-zero, and will not be cannam@155: skipped if \a _b is zero. cannam@155: \hideinitializer*/ cannam@155: #define OP_SSL_SKIP_CERTIFICATE_CHECK(_b) \ cannam@155: OP_URL_OPT(OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST),OP_CHECK_INT(_b) cannam@155: cannam@155: /**Proxy connections through the given host. cannam@155: If no port is specified via #OP_HTTP_PROXY_PORT, the port number defaults cannam@155: to 8080 (http-alt). cannam@155: All proxy parameters are ignored for non-http and non-https URLs. cannam@155: \param _host const char *: The proxy server hostname. cannam@155: This may be NULL to disable the use of a proxy cannam@155: server. cannam@155: \hideinitializer*/ cannam@155: #define OP_HTTP_PROXY_HOST(_host) \ cannam@155: OP_URL_OPT(OP_HTTP_PROXY_HOST_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host) cannam@155: cannam@155: /**Use the given port when proxying connections. cannam@155: This option only has an effect if #OP_HTTP_PROXY_HOST is specified with a cannam@155: non-NULL \a _host. cannam@155: If this option is not provided, the proxy port number defaults to 8080 cannam@155: (http-alt). cannam@155: All proxy parameters are ignored for non-http and non-https URLs. cannam@155: \param _port opus_int32: The proxy server port. cannam@155: This must be in the range 0...65535 (inclusive), or the cannam@155: URL function this is passed to will fail. cannam@155: \hideinitializer*/ cannam@155: #define OP_HTTP_PROXY_PORT(_port) \ cannam@155: OP_URL_OPT(OP_HTTP_PROXY_PORT_REQUEST),OP_CHECK_INT(_port) cannam@155: cannam@155: /**Use the given user name for authentication when proxying connections. cannam@155: All proxy parameters are ignored for non-http and non-https URLs. cannam@155: \param _user const char *: The proxy server user name. cannam@155: This may be NULL to disable proxy cannam@155: authentication. cannam@155: A non-NULL value only has an effect cannam@155: if #OP_HTTP_PROXY_HOST and #OP_HTTP_PROXY_PASS cannam@155: are also specified with non-NULL cannam@155: arguments. cannam@155: \hideinitializer*/ cannam@155: #define OP_HTTP_PROXY_USER(_user) \ cannam@155: OP_URL_OPT(OP_HTTP_PROXY_USER_REQUEST),OP_CHECK_CONST_CHAR_PTR(_user) cannam@155: cannam@155: /**Use the given password for authentication when proxying connections. cannam@155: All proxy parameters are ignored for non-http and non-https URLs. cannam@155: \param _pass const char *: The proxy server password. cannam@155: This may be NULL to disable proxy cannam@155: authentication. cannam@155: A non-NULL value only has an effect cannam@155: if #OP_HTTP_PROXY_HOST and #OP_HTTP_PROXY_USER cannam@155: are also specified with non-NULL cannam@155: arguments. cannam@155: \hideinitializer*/ cannam@155: #define OP_HTTP_PROXY_PASS(_pass) \ cannam@155: OP_URL_OPT(OP_HTTP_PROXY_PASS_REQUEST),OP_CHECK_CONST_CHAR_PTR(_pass) cannam@155: cannam@155: /**Parse information about the streaming server (if any) and return it. cannam@155: Very little validation is done. cannam@155: In particular, OpusServerInfo::url may not be a valid URL, cannam@155: OpusServerInfo::bitrate_kbps may not really be in kbps, and cannam@155: OpusServerInfo::content_type may not be a valid MIME type. cannam@155: The character set of the string fields is not specified anywhere, and should cannam@155: not be assumed to be valid UTF-8. cannam@155: \param _info OpusServerInfo *: Returns information about the server. cannam@155: If there is any error opening the stream, the cannam@155: contents of this structure remain cannam@155: unmodified. cannam@155: On success, fills in the structure with the cannam@155: server information that was available, if cannam@155: any. cannam@155: After a successful return, the contents of cannam@155: this structure should be freed by calling cannam@155: opus_server_info_clear(). cannam@155: \hideinitializer*/ cannam@155: #define OP_GET_SERVER_INFO(_info) \ cannam@155: OP_URL_OPT(OP_GET_SERVER_INFO_REQUEST),OP_CHECK_SERVER_INFO_PTR(_info) cannam@155: cannam@155: /*@}*/ cannam@155: /*@}*/ cannam@155: cannam@155: /**\defgroup stream_callbacks Abstract Stream Reading Interface*/ cannam@155: /*@{*/ cannam@155: /**\name Functions for reading from streams cannam@155: These functions define the interface used to read from and seek in a stream cannam@155: of data. cannam@155: A stream does not need to implement seeking, but the decoder will not be cannam@155: able to seek if it does not do so. cannam@155: These functions also include some convenience routines for working with cannam@155: standard FILE pointers, complete streams stored in a single cannam@155: block of memory, or URLs.*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**Reads up to \a _nbytes bytes of data from \a _stream. cannam@155: \param _stream The stream to read from. cannam@155: \param[out] _ptr The buffer to store the data in. cannam@155: \param _nbytes The maximum number of bytes to read. cannam@155: This function may return fewer, though it will not cannam@155: return zero unless it reaches end-of-file. cannam@155: \return The number of bytes successfully read, or a negative value on cannam@155: error.*/ cannam@155: typedef int (*op_read_func)(void *_stream,unsigned char *_ptr,int _nbytes); cannam@155: cannam@155: /**Sets the position indicator for \a _stream. cannam@155: The new position, measured in bytes, is obtained by adding \a _offset cannam@155: bytes to the position specified by \a _whence. cannam@155: If \a _whence is set to SEEK_SET, SEEK_CUR, or cannam@155: SEEK_END, the offset is relative to the start of the stream, cannam@155: the current position indicator, or end-of-file, respectively. cannam@155: \retval 0 Success. cannam@155: \retval -1 Seeking is not supported or an error occurred. cannam@155: errno need not be set.*/ cannam@155: typedef int (*op_seek_func)(void *_stream,opus_int64 _offset,int _whence); cannam@155: cannam@155: /**Obtains the current value of the position indicator for \a _stream. cannam@155: \return The current position indicator.*/ cannam@155: typedef opus_int64 (*op_tell_func)(void *_stream); cannam@155: cannam@155: /**Closes the underlying stream. cannam@155: \retval 0 Success. cannam@155: \retval EOF An error occurred. cannam@155: errno need not be set.*/ cannam@155: typedef int (*op_close_func)(void *_stream); cannam@155: cannam@155: /**The callbacks used to access non-FILE stream resources. cannam@155: The function prototypes are basically the same as for the stdio functions cannam@155: fread(), fseek(), ftell(), and cannam@155: fclose(). cannam@155: The differences are that the FILE * arguments have been cannam@155: replaced with a void *, which is to be used as a pointer to cannam@155: whatever internal data these functions might need, that #seek and #tell cannam@155: take and return 64-bit offsets, and that #seek must return -1 if cannam@155: the stream is unseekable.*/ cannam@155: struct OpusFileCallbacks{ cannam@155: /**Used to read data from the stream. cannam@155: This must not be NULL.*/ cannam@155: op_read_func read; cannam@155: /**Used to seek in the stream. cannam@155: This may be NULL if seeking is not implemented.*/ cannam@155: op_seek_func seek; cannam@155: /**Used to return the current read position in the stream. cannam@155: This may be NULL if seeking is not implemented.*/ cannam@155: op_tell_func tell; cannam@155: /**Used to close the stream when the decoder is freed. cannam@155: This may be NULL to leave the stream open.*/ cannam@155: op_close_func close; cannam@155: }; cannam@155: cannam@155: /**Opens a stream with fopen() and fills in a set of callbacks cannam@155: that can be used to access it. cannam@155: This is useful to avoid writing your own portable 64-bit seeking wrappers, cannam@155: and also avoids cross-module linking issues on Windows, where a cannam@155: FILE * must be accessed by routines defined in the same module cannam@155: that opened it. cannam@155: \param[out] _cb The callbacks to use for this file. cannam@155: If there is an error opening the file, nothing will be cannam@155: filled in here. cannam@155: \param _path The path to the file to open. cannam@155: On Windows, this string must be UTF-8 (to allow access to cannam@155: files whose names cannot be represented in the current cannam@155: MBCS code page). cannam@155: All other systems use the native character encoding. cannam@155: \param _mode The mode to open the file in. cannam@155: \return A stream handle to use with the callbacks, or NULL on cannam@155: error.*/ cannam@155: OP_WARN_UNUSED_RESULT void *op_fopen(OpusFileCallbacks *_cb, cannam@155: const char *_path,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) cannam@155: OP_ARG_NONNULL(3); cannam@155: cannam@155: /**Opens a stream with fdopen() and fills in a set of callbacks cannam@155: that can be used to access it. cannam@155: This is useful to avoid writing your own portable 64-bit seeking wrappers, cannam@155: and also avoids cross-module linking issues on Windows, where a cannam@155: FILE * must be accessed by routines defined in the same module cannam@155: that opened it. cannam@155: \param[out] _cb The callbacks to use for this file. cannam@155: If there is an error opening the file, nothing will be cannam@155: filled in here. cannam@155: \param _fd The file descriptor to open. cannam@155: \param _mode The mode to open the file in. cannam@155: \return A stream handle to use with the callbacks, or NULL on cannam@155: error.*/ cannam@155: OP_WARN_UNUSED_RESULT void *op_fdopen(OpusFileCallbacks *_cb, cannam@155: int _fd,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(3); cannam@155: cannam@155: /**Opens a stream with freopen() and fills in a set of callbacks cannam@155: that can be used to access it. cannam@155: This is useful to avoid writing your own portable 64-bit seeking wrappers, cannam@155: and also avoids cross-module linking issues on Windows, where a cannam@155: FILE * must be accessed by routines defined in the same module cannam@155: that opened it. cannam@155: \param[out] _cb The callbacks to use for this file. cannam@155: If there is an error opening the file, nothing will be cannam@155: filled in here. cannam@155: \param _path The path to the file to open. cannam@155: On Windows, this string must be UTF-8 (to allow access cannam@155: to files whose names cannot be represented in the cannam@155: current MBCS code page). cannam@155: All other systems use the native character encoding. cannam@155: \param _mode The mode to open the file in. cannam@155: \param _stream A stream previously returned by op_fopen(), op_fdopen(), cannam@155: or op_freopen(). cannam@155: \return A stream handle to use with the callbacks, or NULL on cannam@155: error.*/ cannam@155: OP_WARN_UNUSED_RESULT void *op_freopen(OpusFileCallbacks *_cb, cannam@155: const char *_path,const char *_mode,void *_stream) OP_ARG_NONNULL(1) cannam@155: OP_ARG_NONNULL(2) OP_ARG_NONNULL(3) OP_ARG_NONNULL(4); cannam@155: cannam@155: /**Creates a stream that reads from the given block of memory. cannam@155: This block of memory must contain the complete stream to decode. cannam@155: This is useful for caching small streams (e.g., sound effects) in RAM. cannam@155: \param[out] _cb The callbacks to use for this stream. cannam@155: If there is an error creating the stream, nothing will be cannam@155: filled in here. cannam@155: \param _data The block of memory to read from. cannam@155: \param _size The size of the block of memory. cannam@155: \return A stream handle to use with the callbacks, or NULL on cannam@155: error.*/ cannam@155: OP_WARN_UNUSED_RESULT void *op_mem_stream_create(OpusFileCallbacks *_cb, cannam@155: const unsigned char *_data,size_t _size) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Creates a stream that reads from the given URL. cannam@155: This function behaves identically to op_url_stream_create(), except that it cannam@155: takes a va_list instead of a variable number of arguments. cannam@155: It does not call the va_end macro, and because it invokes the cannam@155: va_arg macro, the value of \a _ap is undefined after the call. cannam@155: \note If you use this function, you must link against libopusurl. cannam@155: \param[out] _cb The callbacks to use for this stream. cannam@155: If there is an error creating the stream, nothing will cannam@155: be filled in here. cannam@155: \param _url The URL to read from. cannam@155: Currently only the , , and cannam@155: schemes are supported. cannam@155: Both and may be disabled at compile cannam@155: time, in which case opening such URLs will always fail. cannam@155: Currently this only supports URIs. cannam@155: IRIs should be converted to UTF-8 and URL-escaped, with cannam@155: internationalized domain names encoded in punycode, cannam@155: before passing them to this function. cannam@155: \param[in,out] _ap A list of the \ref url_options "optional flags" to use. cannam@155: This is a variable-length list of options terminated cannam@155: with NULL. cannam@155: \return A stream handle to use with the callbacks, or NULL on cannam@155: error.*/ cannam@155: OP_WARN_UNUSED_RESULT void *op_url_stream_vcreate(OpusFileCallbacks *_cb, cannam@155: const char *_url,va_list _ap) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Creates a stream that reads from the given URL. cannam@155: \note If you use this function, you must link against libopusurl. cannam@155: \param[out] _cb The callbacks to use for this stream. cannam@155: If there is an error creating the stream, nothing will be cannam@155: filled in here. cannam@155: \param _url The URL to read from. cannam@155: Currently only the , , and schemes cannam@155: are supported. cannam@155: Both and may be disabled at compile time, cannam@155: in which case opening such URLs will always fail. cannam@155: Currently this only supports URIs. cannam@155: IRIs should be converted to UTF-8 and URL-escaped, with cannam@155: internationalized domain names encoded in punycode, before cannam@155: passing them to this function. cannam@155: \param ... The \ref url_options "optional flags" to use. cannam@155: This is a variable-length list of options terminated with cannam@155: NULL. cannam@155: \return A stream handle to use with the callbacks, or NULL on cannam@155: error.*/ cannam@155: OP_WARN_UNUSED_RESULT void *op_url_stream_create(OpusFileCallbacks *_cb, cannam@155: const char *_url,...) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); cannam@155: cannam@155: /*@}*/ cannam@155: /*@}*/ cannam@155: cannam@155: /**\defgroup stream_open_close Opening and Closing*/ cannam@155: /*@{*/ cannam@155: /**\name Functions for opening and closing streams cannam@155: cannam@155: These functions allow you to test a stream to see if it is Opus, open it, cannam@155: and close it. cannam@155: Several flavors are provided for each of the built-in stream types, plus a cannam@155: more general version which takes a set of application-provided callbacks.*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**Test to see if this is an Opus stream. cannam@155: For good results, you will need at least 57 bytes (for a pure Opus-only cannam@155: stream). cannam@155: Something like 512 bytes will give more reliable results for multiplexed cannam@155: streams. cannam@155: This function is meant to be a quick-rejection filter. cannam@155: Its purpose is not to guarantee that a stream is a valid Opus stream, but to cannam@155: ensure that it looks enough like Opus that it isn't going to be recognized cannam@155: as some other format (except possibly an Opus stream that is also cannam@155: multiplexed with other codecs, such as video). cannam@155: \param[out] _head The parsed ID header contents. cannam@155: You may pass NULL if you do not need cannam@155: this information. cannam@155: If the function fails, the contents of this structure cannam@155: remain untouched. cannam@155: \param _initial_data An initial buffer of data from the start of the cannam@155: stream. cannam@155: \param _initial_bytes The number of bytes in \a _initial_data. cannam@155: \return 0 if the data appears to be Opus, or a negative value on error. cannam@155: \retval #OP_FALSE There was not enough data to tell if this was an Opus cannam@155: stream or not. cannam@155: \retval #OP_EFAULT An internal memory allocation failed. cannam@155: \retval #OP_EIMPL The stream used a feature that is not implemented, cannam@155: such as an unsupported channel family. cannam@155: \retval #OP_ENOTFORMAT If the data did not contain a recognizable ID cannam@155: header for an Opus stream. cannam@155: \retval #OP_EVERSION If the version field signaled a version this library cannam@155: does not know how to parse. cannam@155: \retval #OP_EBADHEADER The ID header was not properly formatted or contained cannam@155: illegal values.*/ cannam@155: int op_test(OpusHead *_head, cannam@155: const unsigned char *_initial_data,size_t _initial_bytes); cannam@155: cannam@155: /**Open a stream from the given file path. cannam@155: \param _path The path to the file to open. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want the cannam@155: failure code. cannam@155: The failure code will be #OP_EFAULT if the file could not cannam@155: be opened, or one of the other failure codes from cannam@155: op_open_callbacks() otherwise. cannam@155: \return A freshly opened \c OggOpusFile, or NULL on error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_open_file(const char *_path,int *_error) cannam@155: OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Open a stream from a memory buffer. cannam@155: \param _data The memory buffer to open. cannam@155: \param _size The number of bytes in the buffer. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want the cannam@155: failure code. cannam@155: See op_open_callbacks() for a full list of failure codes. cannam@155: \return A freshly opened \c OggOpusFile, or NULL on error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_open_memory(const unsigned char *_data, cannam@155: size_t _size,int *_error); cannam@155: cannam@155: /**Open a stream from a URL. cannam@155: This function behaves identically to op_open_url(), except that it cannam@155: takes a va_list instead of a variable number of arguments. cannam@155: It does not call the va_end macro, and because it invokes the cannam@155: va_arg macro, the value of \a _ap is undefined after the call. cannam@155: \note If you use this function, you must link against libopusurl. cannam@155: \param _url The URL to open. cannam@155: Currently only the , , and cannam@155: schemes are supported. cannam@155: Both and may be disabled at compile cannam@155: time, in which case opening such URLs will always cannam@155: fail. cannam@155: Currently this only supports URIs. cannam@155: IRIs should be converted to UTF-8 and URL-escaped, cannam@155: with internationalized domain names encoded in cannam@155: punycode, before passing them to this function. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want cannam@155: the failure code. cannam@155: See op_open_callbacks() for a full list of failure cannam@155: codes. cannam@155: \param[in,out] _ap A list of the \ref url_options "optional flags" to cannam@155: use. cannam@155: This is a variable-length list of options terminated cannam@155: with NULL. cannam@155: \return A freshly opened \c OggOpusFile, or NULL on error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_vopen_url(const char *_url, cannam@155: int *_error,va_list _ap) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Open a stream from a URL. cannam@155: \note If you use this function, you must link against libopusurl. cannam@155: \param _url The URL to open. cannam@155: Currently only the , , and schemes cannam@155: are supported. cannam@155: Both and may be disabled at compile cannam@155: time, in which case opening such URLs will always fail. cannam@155: Currently this only supports URIs. cannam@155: IRIs should be converted to UTF-8 and URL-escaped, with cannam@155: internationalized domain names encoded in punycode, cannam@155: before passing them to this function. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want the cannam@155: failure code. cannam@155: See op_open_callbacks() for a full list of failure codes. cannam@155: \param ... The \ref url_options "optional flags" to use. cannam@155: This is a variable-length list of options terminated with cannam@155: NULL. cannam@155: \return A freshly opened \c OggOpusFile, or NULL on error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_open_url(const char *_url, cannam@155: int *_error,...) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Open a stream using the given set of callbacks to access it. cannam@155: \param _stream The stream to read from (e.g., a FILE *). cannam@155: This value will be passed verbatim as the first cannam@155: argument to all of the callbacks. cannam@155: \param _cb The callbacks with which to access the stream. cannam@155: read() must cannam@155: be implemented. cannam@155: seek() and cannam@155: tell() may cannam@155: be NULL, or may always return -1 to cannam@155: indicate a stream is unseekable, but if cannam@155: seek() is cannam@155: implemented and succeeds on a particular stream, then cannam@155: tell() must cannam@155: also. cannam@155: close() may cannam@155: be NULL, but if it is not, it will be cannam@155: called when the \c OggOpusFile is destroyed by cannam@155: op_free(). cannam@155: It will not be called if op_open_callbacks() fails cannam@155: with an error. cannam@155: \param _initial_data An initial buffer of data from the start of the cannam@155: stream. cannam@155: Applications can read some number of bytes from the cannam@155: start of the stream to help identify this as an Opus cannam@155: stream, and then provide them here to allow the cannam@155: stream to be opened, even if it is unseekable. cannam@155: \param _initial_bytes The number of bytes in \a _initial_data. cannam@155: If the stream is seekable, its current position (as cannam@155: reported by cannam@155: tell() cannam@155: at the start of this function) must be equal to cannam@155: \a _initial_bytes. cannam@155: Otherwise, seeking to absolute positions will cannam@155: generate inconsistent results. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want cannam@155: the failure code. cannam@155: The failure code will be one of cannam@155:
cannam@155:
#OP_EREAD
cannam@155:
An underlying read, seek, or tell operation cannam@155: failed when it should have succeeded, or we failed cannam@155: to find data in the stream we had seen before.
cannam@155:
#OP_EFAULT
cannam@155:
There was a memory allocation failure, or an cannam@155: internal library error.
cannam@155:
#OP_EIMPL
cannam@155:
The stream used a feature that is not cannam@155: implemented, such as an unsupported channel cannam@155: family.
cannam@155:
#OP_EINVAL
cannam@155:
seek() cannam@155: was implemented and succeeded on this source, but cannam@155: tell() cannam@155: did not, or the starting position indicator was cannam@155: not equal to \a _initial_bytes.
cannam@155:
#OP_ENOTFORMAT
cannam@155:
The stream contained a link that did not have cannam@155: any logical Opus streams in it.
cannam@155:
#OP_EBADHEADER
cannam@155:
A required header packet was not properly cannam@155: formatted, contained illegal values, or was missing cannam@155: altogether.
cannam@155:
#OP_EVERSION
cannam@155:
An ID header contained an unrecognized version cannam@155: number.
cannam@155:
#OP_EBADLINK
cannam@155:
We failed to find data we had seen before after cannam@155: seeking.
cannam@155:
#OP_EBADTIMESTAMP
cannam@155:
The first or last timestamp in a link failed cannam@155: basic validity checks.
cannam@155:
cannam@155: \return A freshly opened \c OggOpusFile, or NULL on error. cannam@155: libopusfile does not take ownership of the stream cannam@155: if the call fails. cannam@155: The calling application is responsible for closing the stream if cannam@155: this call returns an error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_open_callbacks(void *_stream, cannam@155: const OpusFileCallbacks *_cb,const unsigned char *_initial_data, cannam@155: size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Partially open a stream from the given file path. cannam@155: \see op_test_callbacks cannam@155: \param _path The path to the file to open. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want the cannam@155: failure code. cannam@155: The failure code will be #OP_EFAULT if the file could not cannam@155: be opened, or one of the other failure codes from cannam@155: op_open_callbacks() otherwise. cannam@155: \return A partially opened \c OggOpusFile, or NULL on error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_test_file(const char *_path,int *_error) cannam@155: OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Partially open a stream from a memory buffer. cannam@155: \see op_test_callbacks cannam@155: \param _data The memory buffer to open. cannam@155: \param _size The number of bytes in the buffer. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want the cannam@155: failure code. cannam@155: See op_open_callbacks() for a full list of failure codes. cannam@155: \return A partially opened \c OggOpusFile, or NULL on error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_test_memory(const unsigned char *_data, cannam@155: size_t _size,int *_error); cannam@155: cannam@155: /**Partially open a stream from a URL. cannam@155: This function behaves identically to op_test_url(), except that it cannam@155: takes a va_list instead of a variable number of arguments. cannam@155: It does not call the va_end macro, and because it invokes the cannam@155: va_arg macro, the value of \a _ap is undefined after the call. cannam@155: \note If you use this function, you must link against libopusurl. cannam@155: \see op_test_url cannam@155: \see op_test_callbacks cannam@155: \param _url The URL to open. cannam@155: Currently only the , , and cannam@155: schemes are supported. cannam@155: Both and may be disabled at compile cannam@155: time, in which case opening such URLs will always cannam@155: fail. cannam@155: Currently this only supports URIs. cannam@155: IRIs should be converted to UTF-8 and URL-escaped, cannam@155: with internationalized domain names encoded in cannam@155: punycode, before passing them to this function. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want cannam@155: the failure code. cannam@155: See op_open_callbacks() for a full list of failure cannam@155: codes. cannam@155: \param[in,out] _ap A list of the \ref url_options "optional flags" to cannam@155: use. cannam@155: This is a variable-length list of options terminated cannam@155: with NULL. cannam@155: \return A partially opened \c OggOpusFile, or NULL on error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_vtest_url(const char *_url, cannam@155: int *_error,va_list _ap) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Partially open a stream from a URL. cannam@155: \note If you use this function, you must link against libopusurl. cannam@155: \see op_test_callbacks cannam@155: \param _url The URL to open. cannam@155: Currently only the , , and cannam@155: schemes are supported. cannam@155: Both and may be disabled at compile cannam@155: time, in which case opening such URLs will always fail. cannam@155: Currently this only supports URIs. cannam@155: IRIs should be converted to UTF-8 and URL-escaped, with cannam@155: internationalized domain names encoded in punycode, cannam@155: before passing them to this function. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want the cannam@155: failure code. cannam@155: See op_open_callbacks() for a full list of failure cannam@155: codes. cannam@155: \param ... The \ref url_options "optional flags" to use. cannam@155: This is a variable-length list of options terminated cannam@155: with NULL. cannam@155: \return A partially opened \c OggOpusFile, or NULL on error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_test_url(const char *_url, cannam@155: int *_error,...) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Partially open a stream using the given set of callbacks to access it. cannam@155: This tests for Opusness and loads the headers for the first link. cannam@155: It does not seek (although it tests for seekability). cannam@155: You can query a partially open stream for the few pieces of basic cannam@155: information returned by op_serialno(), op_channel_count(), op_head(), and cannam@155: op_tags() (but only for the first link). cannam@155: You may also determine if it is seekable via a call to op_seekable(). cannam@155: You cannot read audio from the stream, seek, get the size or duration, cannam@155: get information from links other than the first one, or even get the total cannam@155: number of links until you finish opening the stream with op_test_open(). cannam@155: If you do not need to do any of these things, you can dispose of it with cannam@155: op_free() instead. cannam@155: cannam@155: This function is provided mostly to simplify porting existing code that used cannam@155: libvorbisfile. cannam@155: For new code, you are likely better off using op_test() instead, which cannam@155: is less resource-intensive, requires less data to succeed, and imposes a cannam@155: hard limit on the amount of data it examines (important for unseekable cannam@155: streams, where all such data must be buffered until you are sure of the cannam@155: stream type). cannam@155: \param _stream The stream to read from (e.g., a FILE *). cannam@155: This value will be passed verbatim as the first cannam@155: argument to all of the callbacks. cannam@155: \param _cb The callbacks with which to access the stream. cannam@155: read() must cannam@155: be implemented. cannam@155: seek() and cannam@155: tell() may cannam@155: be NULL, or may always return -1 to cannam@155: indicate a stream is unseekable, but if cannam@155: seek() is cannam@155: implemented and succeeds on a particular stream, then cannam@155: tell() must cannam@155: also. cannam@155: close() may cannam@155: be NULL, but if it is not, it will be cannam@155: called when the \c OggOpusFile is destroyed by cannam@155: op_free(). cannam@155: It will not be called if op_open_callbacks() fails cannam@155: with an error. cannam@155: \param _initial_data An initial buffer of data from the start of the cannam@155: stream. cannam@155: Applications can read some number of bytes from the cannam@155: start of the stream to help identify this as an Opus cannam@155: stream, and then provide them here to allow the cannam@155: stream to be tested more thoroughly, even if it is cannam@155: unseekable. cannam@155: \param _initial_bytes The number of bytes in \a _initial_data. cannam@155: If the stream is seekable, its current position (as cannam@155: reported by cannam@155: tell() cannam@155: at the start of this function) must be equal to cannam@155: \a _initial_bytes. cannam@155: Otherwise, seeking to absolute positions will cannam@155: generate inconsistent results. cannam@155: \param[out] _error Returns 0 on success, or a failure code on error. cannam@155: You may pass in NULL if you don't want cannam@155: the failure code. cannam@155: See op_open_callbacks() for a full list of failure cannam@155: codes. cannam@155: \return A partially opened \c OggOpusFile, or NULL on error. cannam@155: libopusfile does not take ownership of the stream cannam@155: if the call fails. cannam@155: The calling application is responsible for closing the stream if cannam@155: this call returns an error.*/ cannam@155: OP_WARN_UNUSED_RESULT OggOpusFile *op_test_callbacks(void *_stream, cannam@155: const OpusFileCallbacks *_cb,const unsigned char *_initial_data, cannam@155: size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2); cannam@155: cannam@155: /**Finish opening a stream partially opened with op_test_callbacks() or one of cannam@155: the associated convenience functions. cannam@155: If this function fails, you are still responsible for freeing the cannam@155: \c OggOpusFile with op_free(). cannam@155: \param _of The \c OggOpusFile to finish opening. cannam@155: \return 0 on success, or a negative value on error. cannam@155: \retval #OP_EREAD An underlying read, seek, or tell operation failed cannam@155: when it should have succeeded. cannam@155: \retval #OP_EFAULT There was a memory allocation failure, or an cannam@155: internal library error. cannam@155: \retval #OP_EIMPL The stream used a feature that is not implemented, cannam@155: such as an unsupported channel family. cannam@155: \retval #OP_EINVAL The stream was not partially opened with cannam@155: op_test_callbacks() or one of the associated cannam@155: convenience functions. cannam@155: \retval #OP_ENOTFORMAT The stream contained a link that did not have any cannam@155: logical Opus streams in it. cannam@155: \retval #OP_EBADHEADER A required header packet was not properly cannam@155: formatted, contained illegal values, or was cannam@155: missing altogether. cannam@155: \retval #OP_EVERSION An ID header contained an unrecognized version cannam@155: number. cannam@155: \retval #OP_EBADLINK We failed to find data we had seen before after cannam@155: seeking. cannam@155: \retval #OP_EBADTIMESTAMP The first or last timestamp in a link failed basic cannam@155: validity checks.*/ cannam@155: int op_test_open(OggOpusFile *_of) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Release all memory used by an \c OggOpusFile. cannam@155: \param _of The \c OggOpusFile to free.*/ cannam@155: void op_free(OggOpusFile *_of); cannam@155: cannam@155: /*@}*/ cannam@155: /*@}*/ cannam@155: cannam@155: /**\defgroup stream_info Stream Information*/ cannam@155: /*@{*/ cannam@155: /**\name Functions for obtaining information about streams cannam@155: cannam@155: These functions allow you to get basic information about a stream, including cannam@155: seekability, the number of links (for chained streams), plus the size, cannam@155: duration, bitrate, header parameters, and meta information for each link cannam@155: (or, where available, the stream as a whole). cannam@155: Some of these (size, duration) are only available for seekable streams. cannam@155: You can also query the current stream position, link, and playback time, cannam@155: and instantaneous bitrate during playback. cannam@155: cannam@155: Some of these functions may be used successfully on the partially open cannam@155: streams returned by op_test_callbacks() or one of the associated cannam@155: convenience functions. cannam@155: Their documention will indicate so explicitly.*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**Returns whether or not the stream being read is seekable. cannam@155: This is true if cannam@155:
    cannam@155:
  1. The seek() and cannam@155: tell() callbacks are both cannam@155: non-NULL,
  2. cannam@155:
  3. The seek() callback was cannam@155: successfully executed at least once, and
  4. cannam@155:
  5. The tell() callback was cannam@155: successfully able to report the position indicator afterwards.
  6. cannam@155:
cannam@155: This function may be called on partially-opened streams. cannam@155: \param _of The \c OggOpusFile whose seekable status is to be returned. cannam@155: \return A non-zero value if seekable, and 0 if unseekable.*/ cannam@155: int op_seekable(const OggOpusFile *_of) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Returns the number of links in this chained stream. cannam@155: This function may be called on partially-opened streams, but it will always cannam@155: return 1. cannam@155: The actual number of links is not known until the stream is fully opened. cannam@155: \param _of The \c OggOpusFile from which to retrieve the link count. cannam@155: \return For fully-open seekable streams, this returns the total number of cannam@155: links in the whole stream, which will be at least 1. cannam@155: For partially-open or unseekable streams, this always returns 1.*/ cannam@155: int op_link_count(const OggOpusFile *_of) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Get the serial number of the given link in a (possibly-chained) Ogg Opus cannam@155: stream. cannam@155: This function may be called on partially-opened streams, but it will always cannam@155: return the serial number of the Opus stream in the first link. cannam@155: \param _of The \c OggOpusFile from which to retrieve the serial number. cannam@155: \param _li The index of the link whose serial number should be retrieved. cannam@155: Use a negative number to get the serial number of the current cannam@155: link. cannam@155: \return The serial number of the given link. cannam@155: If \a _li is greater than the total number of links, this returns cannam@155: the serial number of the last link. cannam@155: If the stream is not seekable, this always returns the serial number cannam@155: of the current link.*/ cannam@155: opus_uint32 op_serialno(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Get the channel count of the given link in a (possibly-chained) Ogg Opus cannam@155: stream. cannam@155: This is equivalent to op_head(_of,_li)->channel_count, but cannam@155: is provided for convenience. cannam@155: This function may be called on partially-opened streams, but it will always cannam@155: return the channel count of the Opus stream in the first link. cannam@155: \param _of The \c OggOpusFile from which to retrieve the channel count. cannam@155: \param _li The index of the link whose channel count should be retrieved. cannam@155: Use a negative number to get the channel count of the current cannam@155: link. cannam@155: \return The channel count of the given link. cannam@155: If \a _li is greater than the total number of links, this returns cannam@155: the channel count of the last link. cannam@155: If the stream is not seekable, this always returns the channel count cannam@155: of the current link.*/ cannam@155: int op_channel_count(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Get the total (compressed) size of the stream, or of an individual link in cannam@155: a (possibly-chained) Ogg Opus stream, including all headers and Ogg muxing cannam@155: overhead. cannam@155: \warning If the Opus stream (or link) is concurrently multiplexed with other cannam@155: logical streams (e.g., video), this returns the size of the entire stream cannam@155: (or link), not just the number of bytes in the first logical Opus stream. cannam@155: Returning the latter would require scanning the entire file. cannam@155: \param _of The \c OggOpusFile from which to retrieve the compressed size. cannam@155: \param _li The index of the link whose compressed size should be computed. cannam@155: Use a negative number to get the compressed size of the entire cannam@155: stream. cannam@155: \return The compressed size of the entire stream if \a _li is negative, the cannam@155: compressed size of link \a _li if it is non-negative, or a negative cannam@155: value on error. cannam@155: The compressed size of the entire stream may be smaller than that cannam@155: of the underlying stream if trailing garbage was detected in the cannam@155: file. cannam@155: \retval #OP_EINVAL The stream is not seekable (so we can't know the length), cannam@155: \a _li wasn't less than the total number of links in cannam@155: the stream, or the stream was only partially open.*/ cannam@155: opus_int64 op_raw_total(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Get the total PCM length (number of samples at 48 kHz) of the stream, or of cannam@155: an individual link in a (possibly-chained) Ogg Opus stream. cannam@155: Users looking for op_time_total() should use op_pcm_total() cannam@155: instead. cannam@155: Because timestamps in Opus are fixed at 48 kHz, there is no need for a cannam@155: separate function to convert this to seconds (and leaving it out avoids cannam@155: introducing floating point to the API, for those that wish to avoid it). cannam@155: \param _of The \c OggOpusFile from which to retrieve the PCM offset. cannam@155: \param _li The index of the link whose PCM length should be computed. cannam@155: Use a negative number to get the PCM length of the entire stream. cannam@155: \return The PCM length of the entire stream if \a _li is negative, the PCM cannam@155: length of link \a _li if it is non-negative, or a negative value on cannam@155: error. cannam@155: \retval #OP_EINVAL The stream is not seekable (so we can't know the length), cannam@155: \a _li wasn't less than the total number of links in cannam@155: the stream, or the stream was only partially open.*/ cannam@155: ogg_int64_t op_pcm_total(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Get the ID header information for the given link in a (possibly chained) Ogg cannam@155: Opus stream. cannam@155: This function may be called on partially-opened streams, but it will always cannam@155: return the ID header information of the Opus stream in the first link. cannam@155: \param _of The \c OggOpusFile from which to retrieve the ID header cannam@155: information. cannam@155: \param _li The index of the link whose ID header information should be cannam@155: retrieved. cannam@155: Use a negative number to get the ID header information of the cannam@155: current link. cannam@155: For an unseekable stream, \a _li is ignored, and the ID header cannam@155: information for the current link is always returned, if cannam@155: available. cannam@155: \return The contents of the ID header for the given link.*/ cannam@155: const OpusHead *op_head(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Get the comment header information for the given link in a (possibly cannam@155: chained) Ogg Opus stream. cannam@155: This function may be called on partially-opened streams, but it will always cannam@155: return the tags from the Opus stream in the first link. cannam@155: \param _of The \c OggOpusFile from which to retrieve the comment header cannam@155: information. cannam@155: \param _li The index of the link whose comment header information should be cannam@155: retrieved. cannam@155: Use a negative number to get the comment header information of cannam@155: the current link. cannam@155: For an unseekable stream, \a _li is ignored, and the comment cannam@155: header information for the current link is always returned, if cannam@155: available. cannam@155: \return The contents of the comment header for the given link, or cannam@155: NULL if this is an unseekable stream that encountered cannam@155: an invalid link.*/ cannam@155: const OpusTags *op_tags(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Retrieve the index of the current link. cannam@155: This is the link that produced the data most recently read by cannam@155: op_read_float() or its associated functions, or, after a seek, the link cannam@155: that the seek target landed in. cannam@155: Reading more data may advance the link index (even on the first read after a cannam@155: seek). cannam@155: \param _of The \c OggOpusFile from which to retrieve the current link index. cannam@155: \return The index of the current link on success, or a negative value on cannam@155: failure. cannam@155: For seekable streams, this is a number between 0 (inclusive) and the cannam@155: value returned by op_link_count() (exclusive). cannam@155: For unseekable streams, this value starts at 0 and increments by one cannam@155: each time a new link is encountered (even though op_link_count() cannam@155: always returns 1). cannam@155: \retval #OP_EINVAL The stream was only partially open.*/ cannam@155: int op_current_link(const OggOpusFile *_of) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Computes the bitrate of the stream, or of an individual link in a cannam@155: (possibly-chained) Ogg Opus stream. cannam@155: The stream must be seekable to compute the bitrate. cannam@155: For unseekable streams, use op_bitrate_instant() to get periodic estimates. cannam@155: \warning If the Opus stream (or link) is concurrently multiplexed with other cannam@155: logical streams (e.g., video), this uses the size of the entire stream (or cannam@155: link) to compute the bitrate, not just the number of bytes in the first cannam@155: logical Opus stream. cannam@155: Returning the latter requires scanning the entire file, but this may be done cannam@155: by decoding the whole file and calling op_bitrate_instant() once at the cannam@155: end. cannam@155: Install a trivial decoding callback with op_set_decode_callback() if you cannam@155: wish to skip actual decoding during this process. cannam@155: \param _of The \c OggOpusFile from which to retrieve the bitrate. cannam@155: \param _li The index of the link whose bitrate should be computed. cannam@155: Use a negative number to get the bitrate of the whole stream. cannam@155: \return The bitrate on success, or a negative value on error. cannam@155: \retval #OP_EINVAL The stream was only partially open, the stream was not cannam@155: seekable, or \a _li was larger than the number of cannam@155: links.*/ cannam@155: opus_int32 op_bitrate(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Compute the instantaneous bitrate, measured as the ratio of bits to playable cannam@155: samples decoded since a) the last call to op_bitrate_instant(), b) the last cannam@155: seek, or c) the start of playback, whichever was most recent. cannam@155: This will spike somewhat after a seek or at the start/end of a chain cannam@155: boundary, as pre-skip, pre-roll, and end-trimming causes samples to be cannam@155: decoded but not played. cannam@155: \param _of The \c OggOpusFile from which to retrieve the bitrate. cannam@155: \return The bitrate, in bits per second, or a negative value on error. cannam@155: \retval #OP_FALSE No data has been decoded since any of the events cannam@155: described above. cannam@155: \retval #OP_EINVAL The stream was only partially open.*/ cannam@155: opus_int32 op_bitrate_instant(OggOpusFile *_of) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Obtain the current value of the position indicator for \a _of. cannam@155: \param _of The \c OggOpusFile from which to retrieve the position indicator. cannam@155: \return The byte position that is currently being read from. cannam@155: \retval #OP_EINVAL The stream was only partially open.*/ cannam@155: opus_int64 op_raw_tell(const OggOpusFile *_of) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Obtain the PCM offset of the next sample to be read. cannam@155: If the stream is not properly timestamped, this might not increment by the cannam@155: proper amount between reads, or even return monotonically increasing cannam@155: values. cannam@155: \param _of The \c OggOpusFile from which to retrieve the PCM offset. cannam@155: \return The PCM offset of the next sample to be read. cannam@155: \retval #OP_EINVAL The stream was only partially open.*/ cannam@155: ogg_int64_t op_pcm_tell(const OggOpusFile *_of) OP_ARG_NONNULL(1); cannam@155: cannam@155: /*@}*/ cannam@155: /*@}*/ cannam@155: cannam@155: /**\defgroup stream_seeking Seeking*/ cannam@155: /*@{*/ cannam@155: /**\name Functions for seeking in Opus streams cannam@155: cannam@155: These functions let you seek in Opus streams, if the underlying stream cannam@155: support it. cannam@155: Seeking is implemented for all built-in stream I/O routines, though some cannam@155: individual streams may not be seekable (pipes, live HTTP streams, or HTTP cannam@155: streams from a server that does not support Range requests). cannam@155: cannam@155: op_raw_seek() is the fastest: it is guaranteed to perform at most one cannam@155: physical seek, but, since the target is a byte position, makes no guarantee cannam@155: how close to a given time it will come. cannam@155: op_pcm_seek() provides sample-accurate seeking. cannam@155: The number of physical seeks it requires is still quite small (often 1 or cannam@155: 2, even in highly variable bitrate streams). cannam@155: cannam@155: Seeking in Opus requires decoding some pre-roll amount before playback to cannam@155: allow the internal state to converge (as if recovering from packet loss). cannam@155: This is handled internally by libopusfile, but means there is cannam@155: little extra overhead for decoding up to the exact position requested cannam@155: (since it must decode some amount of audio anyway). cannam@155: It also means that decoding after seeking may not return exactly the same cannam@155: values as would be obtained by decoding the stream straight through. cannam@155: However, such differences are expected to be smaller than the loss cannam@155: introduced by Opus's lossy compression.*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**Seek to a byte offset relative to the compressed data. cannam@155: This also scans packets to update the PCM cursor. cannam@155: It will cross a logical bitstream boundary, but only if it can't get any cannam@155: packets out of the tail of the link to which it seeks. cannam@155: \param _of The \c OggOpusFile in which to seek. cannam@155: \param _byte_offset The byte position to seek to. cannam@155: This must be between 0 and #op_raw_total(\a _of,\c -1) cannam@155: (inclusive). cannam@155: \return 0 on success, or a negative error code on failure. cannam@155: \retval #OP_EREAD The underlying seek operation failed. cannam@155: \retval #OP_EINVAL The stream was only partially open, or the target was cannam@155: outside the valid range for the stream. cannam@155: \retval #OP_ENOSEEK This stream is not seekable. cannam@155: \retval #OP_EBADLINK Failed to initialize a decoder for a stream for an cannam@155: unknown reason.*/ cannam@155: int op_raw_seek(OggOpusFile *_of,opus_int64 _byte_offset) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Seek to the specified PCM offset, such that decoding will begin at exactly cannam@155: the requested position. cannam@155: \param _of The \c OggOpusFile in which to seek. cannam@155: \param _pcm_offset The PCM offset to seek to. cannam@155: This is in samples at 48 kHz relative to the start of the cannam@155: stream. cannam@155: \return 0 on success, or a negative value on error. cannam@155: \retval #OP_EREAD An underlying read or seek operation failed. cannam@155: \retval #OP_EINVAL The stream was only partially open, or the target was cannam@155: outside the valid range for the stream. cannam@155: \retval #OP_ENOSEEK This stream is not seekable. cannam@155: \retval #OP_EBADLINK We failed to find data we had seen before, or the cannam@155: bitstream structure was sufficiently malformed that cannam@155: seeking to the target destination was impossible.*/ cannam@155: int op_pcm_seek(OggOpusFile *_of,ogg_int64_t _pcm_offset) OP_ARG_NONNULL(1); cannam@155: cannam@155: /*@}*/ cannam@155: /*@}*/ cannam@155: cannam@155: /**\defgroup stream_decoding Decoding*/ cannam@155: /*@{*/ cannam@155: /**\name Functions for decoding audio data cannam@155: cannam@155: These functions retrieve actual decoded audio data from the stream. cannam@155: The general functions, op_read() and op_read_float() return 16-bit or cannam@155: floating-point output, both using native endian ordering. cannam@155: The number of channels returned can change from link to link in a chained cannam@155: stream. cannam@155: There are special functions, op_read_stereo() and op_read_float_stereo(), cannam@155: which always output two channels, to simplify applications which do not cannam@155: wish to handle multichannel audio. cannam@155: These downmix multichannel files to two channels, so they can always return cannam@155: samples in the same format for every link in a chained file. cannam@155: cannam@155: If the rest of your audio processing chain can handle floating point, the cannam@155: floating-point routines should be preferred, as they prevent clipping and cannam@155: other issues which might be avoided entirely if, e.g., you scale down the cannam@155: volume at some other stage. cannam@155: However, if you intend to consume 16-bit samples directly, the conversion in cannam@155: libopusfile provides noise-shaping dithering and, if compiled cannam@155: against libopus 1.1 or later, soft-clipping prevention. cannam@155: cannam@155: libopusfile can also be configured at compile time to use the cannam@155: fixed-point libopus API. cannam@155: If so, libopusfile's floating-point API may also be disabled. cannam@155: In that configuration, nothing in libopusfile will use any cannam@155: floating-point operations, to simplify support on devices without an cannam@155: adequate FPU. cannam@155: cannam@155: \warning HTTPS streams may be be vulnerable to truncation attacks if you do cannam@155: not check the error return code from op_read_float() or its associated cannam@155: functions. cannam@155: If the remote peer does not close the connection gracefully (with a TLS cannam@155: "close notify" message), these functions will return #OP_EREAD instead of 0 cannam@155: when they reach the end of the file. cannam@155: If you are reading from an URL (particularly if seeking is not cannam@155: supported), you should make sure to check for this error and warn the user cannam@155: appropriately.*/ cannam@155: /*@{*/ cannam@155: cannam@155: /**Indicates that the decoding callback should produce signed 16-bit cannam@155: native-endian output samples.*/ cannam@155: #define OP_DEC_FORMAT_SHORT (7008) cannam@155: /**Indicates that the decoding callback should produce 32-bit native-endian cannam@155: float samples.*/ cannam@155: #define OP_DEC_FORMAT_FLOAT (7040) cannam@155: cannam@155: /**Indicates that the decoding callback did not decode anything, and that cannam@155: libopusfile should decode normally instead.*/ cannam@155: #define OP_DEC_USE_DEFAULT (6720) cannam@155: cannam@155: /**Called to decode an Opus packet. cannam@155: This should invoke the functional equivalent of opus_multistream_decode() or cannam@155: opus_multistream_decode_float(), except that it returns 0 on success cannam@155: instead of the number of decoded samples (which is known a priori). cannam@155: \param _ctx The application-provided callback context. cannam@155: \param _decoder The decoder to use to decode the packet. cannam@155: \param[out] _pcm The buffer to decode into. cannam@155: This will always have enough room for \a _nchannels of cannam@155: \a _nsamples samples, which should be placed into this cannam@155: buffer interleaved. cannam@155: \param _op The packet to decode. cannam@155: This will always have its granule position set to a valid cannam@155: value. cannam@155: \param _nsamples The number of samples expected from the packet. cannam@155: \param _nchannels The number of channels expected from the packet. cannam@155: \param _format The desired sample output format. cannam@155: This is either #OP_DEC_FORMAT_SHORT or cannam@155: #OP_DEC_FORMAT_FLOAT. cannam@155: \param _li The index of the link from which this packet was decoded. cannam@155: \return A non-negative value on success, or a negative value on error. cannam@155: Any error codes should be the same as those returned by cannam@155: opus_multistream_decode() or opus_multistream_decode_float(). cannam@155: Success codes are as follows: cannam@155: \retval 0 Decoding was successful. cannam@155: The application has filled the buffer with cannam@155: exactly \a _nsamples*\a cannam@155: _nchannels samples in the requested cannam@155: format. cannam@155: \retval #OP_DEC_USE_DEFAULT No decoding was done. cannam@155: libopusfile should do the decoding cannam@155: by itself instead.*/ cannam@155: typedef int (*op_decode_cb_func)(void *_ctx,OpusMSDecoder *_decoder,void *_pcm, cannam@155: const ogg_packet *_op,int _nsamples,int _nchannels,int _format,int _li); cannam@155: cannam@155: /**Sets the packet decode callback function. cannam@155: If set, this is called once for each packet that needs to be decoded. cannam@155: This can be used by advanced applications to do additional processing on the cannam@155: compressed or uncompressed data. cannam@155: For example, an application might save the final entropy coder state for cannam@155: debugging and testing purposes, or it might apply additional filters cannam@155: before the downmixing, dithering, or soft-clipping performed by cannam@155: libopusfile, so long as these filters do not introduce any cannam@155: latency. cannam@155: cannam@155: A call to this function is no guarantee that the audio will eventually be cannam@155: delivered to the application. cannam@155: libopusfile may discard some or all of the decoded audio data cannam@155: (i.e., at the beginning or end of a link, or after a seek), however the cannam@155: callback is still required to provide all of it. cannam@155: \param _of The \c OggOpusFile on which to set the decode callback. cannam@155: \param _decode_cb The callback function to call. cannam@155: This may be NULL to disable calling the cannam@155: callback. cannam@155: \param _ctx The application-provided context pointer to pass to the cannam@155: callback on each call.*/ cannam@155: void op_set_decode_callback(OggOpusFile *_of, cannam@155: op_decode_cb_func _decode_cb,void *_ctx) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Gain offset type that indicates that the provided offset is relative to the cannam@155: header gain. cannam@155: This is the default.*/ cannam@155: #define OP_HEADER_GAIN (0) cannam@155: cannam@155: /**Gain offset type that indicates that the provided offset is relative to the cannam@155: R128_ALBUM_GAIN value (if any), in addition to the header gain.*/ cannam@155: #define OP_ALBUM_GAIN (3007) cannam@155: cannam@155: /**Gain offset type that indicates that the provided offset is relative to the cannam@155: R128_TRACK_GAIN value (if any), in addition to the header gain.*/ cannam@155: #define OP_TRACK_GAIN (3008) cannam@155: cannam@155: /**Gain offset type that indicates that the provided offset should be used as cannam@155: the gain directly, without applying any the header or track gains.*/ cannam@155: #define OP_ABSOLUTE_GAIN (3009) cannam@155: cannam@155: /**Sets the gain to be used for decoded output. cannam@155: By default, the gain in the header is applied with no additional offset. cannam@155: The total gain (including header gain and/or track gain, if applicable, and cannam@155: this offset), will be clamped to [-32768,32767]/256 dB. cannam@155: This is more than enough to saturate or underflow 16-bit PCM. cannam@155: \note The new gain will not be applied to any already buffered, decoded cannam@155: output. cannam@155: This means you cannot change it sample-by-sample, as at best it will be cannam@155: updated packet-by-packet. cannam@155: It is meant for setting a target volume level, rather than applying smooth cannam@155: fades, etc. cannam@155: \param _of The \c OggOpusFile on which to set the gain offset. cannam@155: \param _gain_type One of #OP_HEADER_GAIN, #OP_ALBUM_GAIN, cannam@155: #OP_TRACK_GAIN, or #OP_ABSOLUTE_GAIN. cannam@155: \param _gain_offset_q8 The gain offset to apply, in 1/256ths of a dB. cannam@155: \return 0 on success or a negative value on error. cannam@155: \retval #OP_EINVAL The \a _gain_type was unrecognized.*/ cannam@155: int op_set_gain_offset(OggOpusFile *_of, cannam@155: int _gain_type,opus_int32 _gain_offset_q8) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Sets whether or not dithering is enabled for 16-bit decoding. cannam@155: By default, when libopusfile is compiled to use floating-point cannam@155: internally, calling op_read() or op_read_stereo() will first decode to cannam@155: float, and then convert to fixed-point using noise-shaping dithering. cannam@155: This flag can be used to disable that dithering. cannam@155: When the application uses op_read_float() or op_read_float_stereo(), or when cannam@155: the library has been compiled to decode directly to fixed point, this flag cannam@155: has no effect. cannam@155: \param _of The \c OggOpusFile on which to enable or disable dithering. cannam@155: \param _enabled A non-zero value to enable dithering, or 0 to disable it.*/ cannam@155: void op_set_dither_enabled(OggOpusFile *_of,int _enabled) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Reads more samples from the stream. cannam@155: \note Although \a _buf_size must indicate the total number of values that cannam@155: can be stored in \a _pcm, the return value is the number of samples cannam@155: per channel. cannam@155: This is done because cannam@155:
    cannam@155:
  1. The channel count cannot be known a priori (reading more samples might cannam@155: advance us into the next link, with a different channel count), so cannam@155: \a _buf_size cannot also be in units of samples per channel,
  2. cannam@155:
  3. Returning the samples per channel matches the libopus API cannam@155: as closely as we're able,
  4. cannam@155:
  5. Returning the total number of values instead of samples per channel cannam@155: would mean the caller would need a division to compute the samples per cannam@155: channel, and might worry about the possibility of getting back samples cannam@155: for some channels and not others, and
  6. cannam@155:
  7. This approach is relatively fool-proof: if an application passes too cannam@155: small a value to \a _buf_size, they will simply get fewer samples back, cannam@155: and if they assume the return value is the total number of values, then cannam@155: they will simply read too few (rather than reading too many and going cannam@155: off the end of the buffer).
  8. cannam@155:
cannam@155: \param _of The \c OggOpusFile from which to read. cannam@155: \param[out] _pcm A buffer in which to store the output PCM samples, as cannam@155: signed native-endian 16-bit values at 48 kHz cannam@155: with a nominal range of [-32768,32767). cannam@155: Multiple channels are interleaved using the cannam@155: Vorbis cannam@155: channel ordering. cannam@155: This must have room for at least \a _buf_size values. cannam@155: \param _buf_size The number of values that can be stored in \a _pcm. cannam@155: It is recommended that this be large enough for at cannam@155: least 120 ms of data at 48 kHz per channel (5760 cannam@155: values per channel). cannam@155: Smaller buffers will simply return less data, possibly cannam@155: consuming more memory to buffer the data internally. cannam@155: libopusfile may return less data than cannam@155: requested. cannam@155: If so, there is no guarantee that the remaining data cannam@155: in \a _pcm will be unmodified. cannam@155: \param[out] _li The index of the link this data was decoded from. cannam@155: You may pass NULL if you do not need this cannam@155: information. cannam@155: If this function fails (returning a negative value), cannam@155: this parameter is left unset. cannam@155: \return The number of samples read per channel on success, or a negative cannam@155: value on failure. cannam@155: The channel count can be retrieved on success by calling cannam@155: op_head(_of,*_li). cannam@155: The number of samples returned may be 0 if the buffer was too small cannam@155: to store even a single sample for all channels, or if end-of-file cannam@155: was reached. cannam@155: The list of possible failure codes follows. cannam@155: Most of them can only be returned by unseekable, chained streams cannam@155: that encounter a new link. cannam@155: \retval #OP_HOLE There was a hole in the data, and some samples cannam@155: may have been skipped. cannam@155: Call this function again to continue decoding cannam@155: past the hole. cannam@155: \retval #OP_EREAD An underlying read operation failed. cannam@155: This may signal a truncation attack from an cannam@155: source. cannam@155: \retval #OP_EFAULT An internal memory allocation failed. cannam@155: \retval #OP_EIMPL An unseekable stream encountered a new link that cannam@155: used a feature that is not implemented, such as cannam@155: an unsupported channel family. cannam@155: \retval #OP_EINVAL The stream was only partially open. cannam@155: \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that cannam@155: did not have any logical Opus streams in it. cannam@155: \retval #OP_EBADHEADER An unseekable stream encountered a new link with a cannam@155: required header packet that was not properly cannam@155: formatted, contained illegal values, or was cannam@155: missing altogether. cannam@155: \retval #OP_EVERSION An unseekable stream encountered a new link with cannam@155: an ID header that contained an unrecognized cannam@155: version number. cannam@155: \retval #OP_EBADPACKET Failed to properly decode the next packet. cannam@155: \retval #OP_EBADLINK We failed to find data we had seen before. cannam@155: \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with cannam@155: a starting timestamp that failed basic validity cannam@155: checks.*/ cannam@155: OP_WARN_UNUSED_RESULT int op_read(OggOpusFile *_of, cannam@155: opus_int16 *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Reads more samples from the stream. cannam@155: \note Although \a _buf_size must indicate the total number of values that cannam@155: can be stored in \a _pcm, the return value is the number of samples cannam@155: per channel. cannam@155:
    cannam@155:
  1. The channel count cannot be known a priori (reading more samples might cannam@155: advance us into the next link, with a different channel count), so cannam@155: \a _buf_size cannot also be in units of samples per channel,
  2. cannam@155:
  3. Returning the samples per channel matches the libopus API cannam@155: as closely as we're able,
  4. cannam@155:
  5. Returning the total number of values instead of samples per channel cannam@155: would mean the caller would need a division to compute the samples per cannam@155: channel, and might worry about the possibility of getting back samples cannam@155: for some channels and not others, and
  6. cannam@155:
  7. This approach is relatively fool-proof: if an application passes too cannam@155: small a value to \a _buf_size, they will simply get fewer samples back, cannam@155: and if they assume the return value is the total number of values, then cannam@155: they will simply read too few (rather than reading too many and going cannam@155: off the end of the buffer).
  8. cannam@155:
cannam@155: \param _of The \c OggOpusFile from which to read. cannam@155: \param[out] _pcm A buffer in which to store the output PCM samples as cannam@155: signed floats at 48 kHz with a nominal range of cannam@155: [-1.0,1.0]. cannam@155: Multiple channels are interleaved using the cannam@155: Vorbis cannam@155: channel ordering. cannam@155: This must have room for at least \a _buf_size floats. cannam@155: \param _buf_size The number of floats that can be stored in \a _pcm. cannam@155: It is recommended that this be large enough for at cannam@155: least 120 ms of data at 48 kHz per channel (5760 cannam@155: samples per channel). cannam@155: Smaller buffers will simply return less data, possibly cannam@155: consuming more memory to buffer the data internally. cannam@155: If less than \a _buf_size values are returned, cannam@155: libopusfile makes no guarantee that the cannam@155: remaining data in \a _pcm will be unmodified. cannam@155: \param[out] _li The index of the link this data was decoded from. cannam@155: You may pass NULL if you do not need this cannam@155: information. cannam@155: If this function fails (returning a negative value), cannam@155: this parameter is left unset. cannam@155: \return The number of samples read per channel on success, or a negative cannam@155: value on failure. cannam@155: The channel count can be retrieved on success by calling cannam@155: op_head(_of,*_li). cannam@155: The number of samples returned may be 0 if the buffer was too small cannam@155: to store even a single sample for all channels, or if end-of-file cannam@155: was reached. cannam@155: The list of possible failure codes follows. cannam@155: Most of them can only be returned by unseekable, chained streams cannam@155: that encounter a new link. cannam@155: \retval #OP_HOLE There was a hole in the data, and some samples cannam@155: may have been skipped. cannam@155: Call this function again to continue decoding cannam@155: past the hole. cannam@155: \retval #OP_EREAD An underlying read operation failed. cannam@155: This may signal a truncation attack from an cannam@155: source. cannam@155: \retval #OP_EFAULT An internal memory allocation failed. cannam@155: \retval #OP_EIMPL An unseekable stream encountered a new link that cannam@155: used a feature that is not implemented, such as cannam@155: an unsupported channel family. cannam@155: \retval #OP_EINVAL The stream was only partially open. cannam@155: \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that cannam@155: did not have any logical Opus streams in it. cannam@155: \retval #OP_EBADHEADER An unseekable stream encountered a new link with a cannam@155: required header packet that was not properly cannam@155: formatted, contained illegal values, or was cannam@155: missing altogether. cannam@155: \retval #OP_EVERSION An unseekable stream encountered a new link with cannam@155: an ID header that contained an unrecognized cannam@155: version number. cannam@155: \retval #OP_EBADPACKET Failed to properly decode the next packet. cannam@155: \retval #OP_EBADLINK We failed to find data we had seen before. cannam@155: \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with cannam@155: a starting timestamp that failed basic validity cannam@155: checks.*/ cannam@155: OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of, cannam@155: float *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Reads more samples from the stream and downmixes to stereo, if necessary. cannam@155: This function is intended for simple players that want a uniform output cannam@155: format, even if the channel count changes between links in a chained cannam@155: stream. cannam@155: \note \a _buf_size indicates the total number of values that can be stored cannam@155: in \a _pcm, while the return value is the number of samples per cannam@155: channel, even though the channel count is known, for consistency with cannam@155: op_read(). cannam@155: \param _of The \c OggOpusFile from which to read. cannam@155: \param[out] _pcm A buffer in which to store the output PCM samples, as cannam@155: signed native-endian 16-bit values at 48 kHz cannam@155: with a nominal range of [-32768,32767). cannam@155: The left and right channels are interleaved in the cannam@155: buffer. cannam@155: This must have room for at least \a _buf_size values. cannam@155: \param _buf_size The number of values that can be stored in \a _pcm. cannam@155: It is recommended that this be large enough for at cannam@155: least 120 ms of data at 48 kHz per channel (11520 cannam@155: values total). cannam@155: Smaller buffers will simply return less data, possibly cannam@155: consuming more memory to buffer the data internally. cannam@155: If less than \a _buf_size values are returned, cannam@155: libopusfile makes no guarantee that the cannam@155: remaining data in \a _pcm will be unmodified. cannam@155: \return The number of samples read per channel on success, or a negative cannam@155: value on failure. cannam@155: The number of samples returned may be 0 if the buffer was too small cannam@155: to store even a single sample for both channels, or if end-of-file cannam@155: was reached. cannam@155: The list of possible failure codes follows. cannam@155: Most of them can only be returned by unseekable, chained streams cannam@155: that encounter a new link. cannam@155: \retval #OP_HOLE There was a hole in the data, and some samples cannam@155: may have been skipped. cannam@155: Call this function again to continue decoding cannam@155: past the hole. cannam@155: \retval #OP_EREAD An underlying read operation failed. cannam@155: This may signal a truncation attack from an cannam@155: source. cannam@155: \retval #OP_EFAULT An internal memory allocation failed. cannam@155: \retval #OP_EIMPL An unseekable stream encountered a new link that cannam@155: used a feature that is not implemented, such as cannam@155: an unsupported channel family. cannam@155: \retval #OP_EINVAL The stream was only partially open. cannam@155: \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that cannam@155: did not have any logical Opus streams in it. cannam@155: \retval #OP_EBADHEADER An unseekable stream encountered a new link with a cannam@155: required header packet that was not properly cannam@155: formatted, contained illegal values, or was cannam@155: missing altogether. cannam@155: \retval #OP_EVERSION An unseekable stream encountered a new link with cannam@155: an ID header that contained an unrecognized cannam@155: version number. cannam@155: \retval #OP_EBADPACKET Failed to properly decode the next packet. cannam@155: \retval #OP_EBADLINK We failed to find data we had seen before. cannam@155: \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with cannam@155: a starting timestamp that failed basic validity cannam@155: checks.*/ cannam@155: OP_WARN_UNUSED_RESULT int op_read_stereo(OggOpusFile *_of, cannam@155: opus_int16 *_pcm,int _buf_size) OP_ARG_NONNULL(1); cannam@155: cannam@155: /**Reads more samples from the stream and downmixes to stereo, if necessary. cannam@155: This function is intended for simple players that want a uniform output cannam@155: format, even if the channel count changes between links in a chained cannam@155: stream. cannam@155: \note \a _buf_size indicates the total number of values that can be stored cannam@155: in \a _pcm, while the return value is the number of samples per cannam@155: channel, even though the channel count is known, for consistency with cannam@155: op_read_float(). cannam@155: \param _of The \c OggOpusFile from which to read. cannam@155: \param[out] _pcm A buffer in which to store the output PCM samples, as cannam@155: signed floats at 48 kHz with a nominal range of cannam@155: [-1.0,1.0]. cannam@155: The left and right channels are interleaved in the cannam@155: buffer. cannam@155: This must have room for at least \a _buf_size values. cannam@155: \param _buf_size The number of values that can be stored in \a _pcm. cannam@155: It is recommended that this be large enough for at cannam@155: least 120 ms of data at 48 kHz per channel (11520 cannam@155: values total). cannam@155: Smaller buffers will simply return less data, possibly cannam@155: consuming more memory to buffer the data internally. cannam@155: If less than \a _buf_size values are returned, cannam@155: libopusfile makes no guarantee that the cannam@155: remaining data in \a _pcm will be unmodified. cannam@155: \return The number of samples read per channel on success, or a negative cannam@155: value on failure. cannam@155: The number of samples returned may be 0 if the buffer was too small cannam@155: to store even a single sample for both channels, or if end-of-file cannam@155: was reached. cannam@155: The list of possible failure codes follows. cannam@155: Most of them can only be returned by unseekable, chained streams cannam@155: that encounter a new link. cannam@155: \retval #OP_HOLE There was a hole in the data, and some samples cannam@155: may have been skipped. cannam@155: Call this function again to continue decoding cannam@155: past the hole. cannam@155: \retval #OP_EREAD An underlying read operation failed. cannam@155: This may signal a truncation attack from an cannam@155: source. cannam@155: \retval #OP_EFAULT An internal memory allocation failed. cannam@155: \retval #OP_EIMPL An unseekable stream encountered a new link that cannam@155: used a feature that is not implemented, such as cannam@155: an unsupported channel family. cannam@155: \retval #OP_EINVAL The stream was only partially open. cannam@155: \retval #OP_ENOTFORMAT An unseekable stream encountered a new link that cannam@155: that did not have any logical Opus streams in it. cannam@155: \retval #OP_EBADHEADER An unseekable stream encountered a new link with a cannam@155: required header packet that was not properly cannam@155: formatted, contained illegal values, or was cannam@155: missing altogether. cannam@155: \retval #OP_EVERSION An unseekable stream encountered a new link with cannam@155: an ID header that contained an unrecognized cannam@155: version number. cannam@155: \retval #OP_EBADPACKET Failed to properly decode the next packet. cannam@155: \retval #OP_EBADLINK We failed to find data we had seen before. cannam@155: \retval #OP_EBADTIMESTAMP An unseekable stream encountered a new link with cannam@155: a starting timestamp that failed basic validity cannam@155: checks.*/ cannam@155: OP_WARN_UNUSED_RESULT int op_read_float_stereo(OggOpusFile *_of, cannam@155: float *_pcm,int _buf_size) OP_ARG_NONNULL(1); cannam@155: cannam@155: /*@}*/ cannam@155: /*@}*/ cannam@155: cannam@155: # if OP_GNUC_PREREQ(4,0) cannam@155: # pragma GCC visibility pop cannam@155: # endif cannam@155: cannam@155: # if defined(__cplusplus) cannam@155: } cannam@155: # endif cannam@155: cannam@155: #endif