Loading...
Searching...
No Matches
opusfile.h
/********************************************************************
* *
* THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE libopusfile SOURCE CODE IS (C) COPYRIGHT 1994-2012 *
* by the Xiph.Org Foundation and contributors https://xiph.org/ *
* *
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
last mod: $Id: vorbisfile.h 17182 2010-04-29 03:48:32Z xiphmont $
********************************************************************/
#if !defined(_opusfile_h)
# define _opusfile_h (1)
# if defined(__cplusplus)
extern "C" {
# endif
# include <stdarg.h>
# include <stdio.h>
# include <ogg/ogg.h>
# include <opus_multistream.h>
/*Enable special features for gcc and gcc-compatible compilers.*/
# if !defined(OP_GNUC_PREREQ)
# if defined(__GNUC__)&&defined(__GNUC_MINOR__)
# define OP_GNUC_PREREQ(_maj,_min) \
((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
# else
# define OP_GNUC_PREREQ(_maj,_min) 0
# endif
# endif
# if OP_GNUC_PREREQ(4,0)
# pragma GCC visibility push(default)
# endif
typedef struct OpusHead OpusHead;
typedef struct OpusTags OpusTags;
typedef struct OpusPictureTag OpusPictureTag;
typedef struct OpusServerInfo OpusServerInfo;
typedef struct OpusFileCallbacks OpusFileCallbacks;
typedef struct OggOpusFile OggOpusFile;
/*Warning attributes for libopusfile functions.*/
# if OP_GNUC_PREREQ(3,4)
# define OP_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
# else
# define OP_WARN_UNUSED_RESULT
# endif
# if OP_GNUC_PREREQ(3,4)
# define OP_ARG_NONNULL(_x) __attribute__((__nonnull__(_x)))
# else
# define OP_ARG_NONNULL(_x)
# endif
#define OP_FALSE (-1)
/*Currently not used externally.*/
#define OP_EOF (-2)
#define OP_HOLE (-3)
#define OP_EREAD (-128)
#define OP_EFAULT (-129)
#define OP_EIMPL (-130)
#define OP_EINVAL (-131)
#define OP_ENOTFORMAT (-132)
#define OP_EBADHEADER (-133)
#define OP_EVERSION (-134)
/*Currently not used at all.*/
#define OP_ENOTAUDIO (-135)
#define OP_EBADPACKET (-136)
#define OP_EBADLINK (-137)
#define OP_ENOSEEK (-138)
#define OP_EBADTIMESTAMP (-139)
#define OPUS_CHANNEL_COUNT_MAX (255)
struct OpusHead{
int version;
int channel_count;
unsigned pre_skip;
opus_uint32 input_sample_rate;
int output_gain;
int mapping_family;
int stream_count;
int coupled_count;
unsigned char mapping[OPUS_CHANNEL_COUNT_MAX];
};
struct OpusTags{
char **user_comments;
int *comment_lengths;
int comments;
char *vendor;
};
#define OP_PIC_FORMAT_UNKNOWN (-1)
#define OP_PIC_FORMAT_URL (0)
#define OP_PIC_FORMAT_JPEG (1)
#define OP_PIC_FORMAT_PNG (2)
#define OP_PIC_FORMAT_GIF (3)
struct OpusPictureTag{
opus_int32 type;
char *mime_type;
char *description;
opus_uint32 width;
opus_uint32 height;
opus_uint32 depth;
opus_uint32 colors;
opus_uint32 data_length;
unsigned char *data;
int format;
};
OP_WARN_UNUSED_RESULT int opus_head_parse(OpusHead *_head,
const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2);
ogg_int64_t opus_granule_sample(const OpusHead *_head,ogg_int64_t _gp)
OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT int opus_tags_parse(OpusTags *_tags,
const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2);
int opus_tags_copy(OpusTags *_dst,const OpusTags *_src) OP_ARG_NONNULL(1);
void opus_tags_init(OpusTags *_tags) OP_ARG_NONNULL(1);
int opus_tags_add(OpusTags *_tags,const char *_tag,const char *_value)
OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) OP_ARG_NONNULL(3);
int opus_tags_add_comment(OpusTags *_tags,const char *_comment)
OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
int opus_tags_set_binary_suffix(OpusTags *_tags,
const unsigned char *_data,int _len) OP_ARG_NONNULL(1);
const char *opus_tags_query(const OpusTags *_tags,const char *_tag,int _count)
OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
int opus_tags_query_count(const OpusTags *_tags,const char *_tag)
OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
const unsigned char *opus_tags_get_binary_suffix(const OpusTags *_tags,
int *_len) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
int opus_tags_get_album_gain(const OpusTags *_tags,int *_gain_q8)
OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
int opus_tags_get_track_gain(const OpusTags *_tags,int *_gain_q8)
OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
void opus_tags_clear(OpusTags *_tags) OP_ARG_NONNULL(1);
int opus_tagcompare(const char *_tag_name,const char *_comment);
int opus_tagncompare(const char *_tag_name,int _tag_len,const char *_comment);
OP_WARN_UNUSED_RESULT int opus_picture_tag_parse(OpusPictureTag *_pic,
const char *_tag) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
void opus_picture_tag_init(OpusPictureTag *_pic) OP_ARG_NONNULL(1);
void opus_picture_tag_clear(OpusPictureTag *_pic) OP_ARG_NONNULL(1);
/*These are the raw numbers used to define the request codes.
They should not be used directly.*/
#define OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST (6464)
#define OP_HTTP_PROXY_HOST_REQUEST (6528)
#define OP_HTTP_PROXY_PORT_REQUEST (6592)
#define OP_HTTP_PROXY_USER_REQUEST (6656)
#define OP_HTTP_PROXY_PASS_REQUEST (6720)
#define OP_GET_SERVER_INFO_REQUEST (6784)
#define OP_URL_OPT(_request) ((char *)(_request))
/*These macros trigger compilation errors or warnings if the wrong types are
provided to one of the URL options.*/
#define OP_CHECK_INT(_x) ((void)((_x)==(opus_int32)0),(opus_int32)(_x))
#define OP_CHECK_CONST_CHAR_PTR(_x) ((_x)+((_x)-(const char *)(_x)))
#define OP_CHECK_SERVER_INFO_PTR(_x) ((_x)+((_x)-(OpusServerInfo *)(_x)))
struct OpusServerInfo{
char *name;
char *description;
char *genre;
char *url;
char *server;
char *content_type;
opus_int32 bitrate_kbps;
int is_public;
int is_ssl;
};
void opus_server_info_init(OpusServerInfo *_info) OP_ARG_NONNULL(1);
void opus_server_info_clear(OpusServerInfo *_info) OP_ARG_NONNULL(1);
#define OP_SSL_SKIP_CERTIFICATE_CHECK(_b) \
OP_URL_OPT(OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST),OP_CHECK_INT(_b)
#define OP_HTTP_PROXY_HOST(_host) \
OP_URL_OPT(OP_HTTP_PROXY_HOST_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host)
#define OP_HTTP_PROXY_PORT(_port) \
OP_URL_OPT(OP_HTTP_PROXY_PORT_REQUEST),OP_CHECK_INT(_port)
#define OP_HTTP_PROXY_USER(_user) \
OP_URL_OPT(OP_HTTP_PROXY_USER_REQUEST),OP_CHECK_CONST_CHAR_PTR(_user)
#define OP_HTTP_PROXY_PASS(_pass) \
OP_URL_OPT(OP_HTTP_PROXY_PASS_REQUEST),OP_CHECK_CONST_CHAR_PTR(_pass)
#define OP_GET_SERVER_INFO(_info) \
OP_URL_OPT(OP_GET_SERVER_INFO_REQUEST),OP_CHECK_SERVER_INFO_PTR(_info)
typedef int (*op_read_func)(void *_stream,unsigned char *_ptr,int _nbytes);
typedef int (*op_seek_func)(void *_stream,opus_int64 _offset,int _whence);
typedef opus_int64 (*op_tell_func)(void *_stream);
typedef int (*op_close_func)(void *_stream);
struct OpusFileCallbacks{
op_read_func read;
op_seek_func seek;
op_tell_func tell;
op_close_func close;
};
OP_WARN_UNUSED_RESULT void *op_fopen(OpusFileCallbacks *_cb,
const char *_path,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2)
OP_ARG_NONNULL(3);
OP_WARN_UNUSED_RESULT void *op_fdopen(OpusFileCallbacks *_cb,
int _fd,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(3);
OP_WARN_UNUSED_RESULT void *op_freopen(OpusFileCallbacks *_cb,
const char *_path,const char *_mode,void *_stream) OP_ARG_NONNULL(1)
OP_ARG_NONNULL(2) OP_ARG_NONNULL(3) OP_ARG_NONNULL(4);
OP_WARN_UNUSED_RESULT void *op_mem_stream_create(OpusFileCallbacks *_cb,
const unsigned char *_data,size_t _size) OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT void *op_url_stream_vcreate(OpusFileCallbacks *_cb,
const char *_url,va_list _ap) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
OP_WARN_UNUSED_RESULT void *op_url_stream_create(OpusFileCallbacks *_cb,
const char *_url,...) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
int op_test(OpusHead *_head,
const unsigned char *_initial_data,size_t _initial_bytes);
OP_WARN_UNUSED_RESULT OggOpusFile *op_open_file(const char *_path,int *_error)
OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT OggOpusFile *op_open_memory(const unsigned char *_data,
size_t _size,int *_error);
OP_WARN_UNUSED_RESULT OggOpusFile *op_vopen_url(const char *_url,
int *_error,va_list _ap) OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT OggOpusFile *op_open_url(const char *_url,
int *_error,...) OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT OggOpusFile *op_open_callbacks(void *_stream,
const OpusFileCallbacks *_cb,const unsigned char *_initial_data,
size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2);
OP_WARN_UNUSED_RESULT OggOpusFile *op_test_file(const char *_path,int *_error)
OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT OggOpusFile *op_test_memory(const unsigned char *_data,
size_t _size,int *_error);
OP_WARN_UNUSED_RESULT OggOpusFile *op_vtest_url(const char *_url,
int *_error,va_list _ap) OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT OggOpusFile *op_test_url(const char *_url,
int *_error,...) OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT OggOpusFile *op_test_callbacks(void *_stream,
const OpusFileCallbacks *_cb,const unsigned char *_initial_data,
size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2);
int op_test_open(OggOpusFile *_of) OP_ARG_NONNULL(1);
void op_free(OggOpusFile *_of);
int op_seekable(const OggOpusFile *_of) OP_ARG_NONNULL(1);
int op_link_count(const OggOpusFile *_of) OP_ARG_NONNULL(1);
opus_uint32 op_serialno(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
int op_channel_count(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
opus_int64 op_raw_total(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
ogg_int64_t op_pcm_total(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
const OpusHead *op_head(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
const OpusTags *op_tags(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
int op_current_link(const OggOpusFile *_of) OP_ARG_NONNULL(1);
opus_int32 op_bitrate(const OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
opus_int32 op_bitrate_instant(OggOpusFile *_of) OP_ARG_NONNULL(1);
opus_int64 op_raw_tell(const OggOpusFile *_of) OP_ARG_NONNULL(1);
ogg_int64_t op_pcm_tell(const OggOpusFile *_of) OP_ARG_NONNULL(1);
int op_raw_seek(OggOpusFile *_of,opus_int64 _byte_offset) OP_ARG_NONNULL(1);
int op_pcm_seek(OggOpusFile *_of,ogg_int64_t _pcm_offset) OP_ARG_NONNULL(1);
#define OP_DEC_FORMAT_SHORT (7008)
#define OP_DEC_FORMAT_FLOAT (7040)
#define OP_DEC_USE_DEFAULT (6720)
typedef int (*op_decode_cb_func)(void *_ctx,OpusMSDecoder *_decoder,void *_pcm,
const ogg_packet *_op,int _nsamples,int _nchannels,int _format,int _li);
void op_set_decode_callback(OggOpusFile *_of,
op_decode_cb_func _decode_cb,void *_ctx) OP_ARG_NONNULL(1);
#define OP_HEADER_GAIN (0)
#define OP_ALBUM_GAIN (3007)
#define OP_TRACK_GAIN (3008)
#define OP_ABSOLUTE_GAIN (3009)
int op_set_gain_offset(OggOpusFile *_of,
int _gain_type,opus_int32 _gain_offset_q8) OP_ARG_NONNULL(1);
void op_set_dither_enabled(OggOpusFile *_of,int _enabled) OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT int op_read(OggOpusFile *_of,
opus_int16 *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of,
float *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT int op_read_stereo(OggOpusFile *_of,
opus_int16 *_pcm,int _buf_size) OP_ARG_NONNULL(1);
OP_WARN_UNUSED_RESULT int op_read_float_stereo(OggOpusFile *_of,
float *_pcm,int _buf_size) OP_ARG_NONNULL(1);
# if OP_GNUC_PREREQ(4,0)
# pragma GCC visibility pop
# endif
# if defined(__cplusplus)
}
# endif
#endif
OpusFileCallbacks
The callbacks used to access non-FILE stream resources.
Definition opusfile.h:901
OpusFileCallbacks::close
op_close_func close
Used to close the stream when the decoder is freed.
Definition opusfile.h:913
OpusFileCallbacks::tell
op_tell_func tell
Used to return the current read position in the stream.
Definition opusfile.h:910
OpusFileCallbacks::read
op_read_func read
Used to read data from the stream.
Definition opusfile.h:904
OpusFileCallbacks::seek
op_seek_func seek
Used to seek in the stream.
Definition opusfile.h:907
OpusHead
Ogg Opus bitstream information.
Definition opusfile.h:215
OpusHead::coupled_count
int coupled_count
The number of coupled Opus streams in each Ogg packet, in the range 0...127.
Definition opusfile.h:260
OpusHead::output_gain
int output_gain
The gain to apply to the decoded output, in dB, as a Q8 value in the range -32768....
Definition opusfile.h:244
OpusHead::stream_count
int stream_count
The number of Opus streams in each Ogg packet, in the range 1...255.
Definition opusfile.h:253
OpusHead::mapping_family
int mapping_family
The channel mapping family, in the range 0...255.
Definition opusfile.h:251
OpusHead::input_sample_rate
opus_uint32 input_sample_rate
The sampling rate of the original input.
Definition opusfile.h:237
OpusHead::version
int version
The Ogg Opus format version, in the range 0...255.
Definition opusfile.h:225
OpusHead::pre_skip
unsigned pre_skip
The number of samples that should be discarded from the beginning of the stream.
Definition opusfile.h:230
OpusHead::mapping
unsigned char mapping[OPUS_CHANNEL_COUNT_MAX]
The mapping from coded stream channels to output channels.
Definition opusfile.h:268
OpusHead::channel_count
int channel_count
The number of channels, in the range 1...255.
Definition opusfile.h:227
OpusPictureTag
The contents of a METADATA_BLOCK_PICTURE tag.
Definition opusfile.h:331
OpusPictureTag::data
unsigned char * data
The binary picture data.
Definition opusfile.h:381
OpusPictureTag::height
opus_uint32 height
The height of the picture in pixels.
Definition opusfile.h:371
OpusPictureTag::type
opus_int32 type
The picture type according to the ID3v2 APIC frame:
Definition opusfile.h:358
OpusPictureTag::colors
opus_uint32 colors
For indexed-color pictures (e.g., GIF), the number of colors used, or 0 for non-indexed pictures.
Definition opusfile.h:377
OpusPictureTag::width
opus_uint32 width
The width of the picture in pixels.
Definition opusfile.h:369
OpusPictureTag::depth
opus_uint32 depth
The color depth of the picture in bits-per-pixel (not bits-per-channel).
Definition opusfile.h:374
OpusPictureTag::description
char * description
The description of the picture, in UTF-8.
Definition opusfile.h:367
OpusPictureTag::data_length
opus_uint32 data_length
The length of the picture data in bytes.
Definition opusfile.h:379
OpusPictureTag::format
int format
The format of the picture data, if known.
Definition opusfile.h:391
OpusPictureTag::mime_type
char * mime_type
The MIME type of the picture, in printable ASCII characters 0x20-0x7E.
Definition opusfile.h:365
OpusServerInfo
HTTP/Shoutcast/Icecast server information associated with a URL.
Definition opusfile.h:712
OpusServerInfo::bitrate_kbps
opus_int32 bitrate_kbps
The nominal stream bitrate in kbps (icy-br/ice-bitrate).
Definition opusfile.h:739
OpusServerInfo::genre
char * genre
The genre the server falls under (icy-genre/ice-genre).
Definition opusfile.h:724
OpusServerInfo::is_ssl
int is_ssl
Flag indicating whether the server is using HTTPS instead of HTTP.
Definition opusfile.h:749
OpusServerInfo::content_type
char * content_type
The media type of the entity sent to the recepient (Content-Type).
Definition opusfile.h:735
OpusServerInfo::name
char * name
The name of the server (icy-name/ice-name).
Definition opusfile.h:716
OpusServerInfo::server
char * server
The software used by the origin server (Server).
Definition opusfile.h:731
OpusServerInfo::url
char * url
The homepage for the server (icy-url/ice-url).
Definition opusfile.h:728
OpusServerInfo::is_public
int is_public
Flag indicating whether the server is public (1) or not (0) (icy-pub/ice-public).
Definition opusfile.h:744
OpusServerInfo::description
char * description
A short description of the server (icy-description/ice-description).
Definition opusfile.h:720
OpusTags
The metadata from an Ogg Opus stream.
Definition opusfile.h:301
OpusTags::comments
int comments
The total number of comment streams.
Definition opusfile.h:307
OpusTags::comment_lengths
int * comment_lengths
An array of the corresponding length of each vector, in bytes.
Definition opusfile.h:305
OpusTags::user_comments
char ** user_comments
The array of comment string vectors.
Definition opusfile.h:303
OpusTags::vendor
char * vendor
The null-terminated vendor string.
Definition opusfile.h:310