opusfile
0.2
Stand-alone decoder library for .opus files.
|
00001 /******************************************************************** 00002 * * 00003 * THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. * 00004 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 00005 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 00006 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 00007 * * 00008 * THE libopusfile SOURCE CODE IS (C) COPYRIGHT 1994-2012 * 00009 * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * 00010 * * 00011 ******************************************************************** 00012 00013 function: stdio-based convenience library for opening/seeking/decoding 00014 last mod: $Id: vorbisfile.h 17182 2010-04-29 03:48:32Z xiphmont $ 00015 00016 ********************************************************************/ 00017 #if !defined(_opusfile_h) 00018 # define _opusfile_h (1) 00019 # include <stdarg.h> 00020 00056 # if defined(__cplusplus) 00057 extern "C" { 00058 # endif 00059 00060 # include <stdio.h> 00061 # include <ogg/ogg.h> 00062 # include <opus_multistream.h> 00063 00064 /*Enable special features for gcc and gcc-compatible compilers.*/ 00065 # if !defined(OP_GNUC_PREREQ) 00066 # if defined(__GNUC__)&&defined(__GNUC_MINOR__) 00067 # define OP_GNUC_PREREQ(_maj,_min) \ 00068 ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) 00069 # else 00070 # define OP_GNUC_PREREQ(_maj,_min) 0 00071 # endif 00072 # endif 00073 00074 # if OP_GNUC_PREREQ(4,0) 00075 # pragma GCC visibility push(default) 00076 # endif 00077 00078 typedef struct OpusHead OpusHead; 00079 typedef struct OpusTags OpusTags; 00080 typedef struct OggOpusFile OggOpusFile; 00081 00082 /*Warning attributes for libopusfile functions.*/ 00083 # if OP_GNUC_PREREQ(3,4) 00084 # define OP_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) 00085 # else 00086 # define OP_WARN_UNUSED_RESULT 00087 # endif 00088 # if OP_GNUC_PREREQ(3,4) 00089 # define OP_ARG_NONNULL(_x) __attribute__((__nonnull__(_x))) 00090 # else 00091 # define OP_ARG_NONNULL(_x) 00092 # endif 00093 00103 00105 #define OP_FALSE (-1) 00106 /*Currently not used externally.*/ 00107 #define OP_EOF (-2) 00108 00110 #define OP_HOLE (-3) 00111 00113 #define OP_EREAD (-128) 00114 00117 #define OP_EFAULT (-129) 00118 00120 #define OP_EIMPL (-130) 00121 00122 #define OP_EINVAL (-131) 00123 00127 #define OP_ENOTFORMAT (-132) 00128 00130 #define OP_EBADHEADER (-133) 00131 00132 #define OP_EVERSION (-134) 00133 /*Currently not used at all.*/ 00134 #define OP_ENOTAUDIO (-135) 00135 00138 #define OP_EBADPACKET (-136) 00139 00142 #define OP_EBADLINK (-137) 00143 00144 #define OP_ENOSEEK (-138) 00145 00146 #define OP_EBADTIMESTAMP (-139) 00147 00150 00153 00155 #define OPUS_CHANNEL_COUNT_MAX (255) 00156 00160 struct OpusHead{ 00170 int version; 00172 int channel_count; 00175 unsigned pre_skip; 00182 opus_uint32 input_sample_rate; 00187 int output_gain; 00194 int mapping_family; 00196 int stream_count; 00203 int coupled_count; 00211 unsigned char mapping[OPUS_CHANNEL_COUNT_MAX]; 00212 }; 00213 00244 struct OpusTags{ 00246 char **user_comments; 00248 int *comment_lengths; 00250 int comments; 00253 char *vendor; 00254 }; 00255 00264 00290 OP_WARN_UNUSED_RESULT int opus_head_parse(OpusHead *_head, 00291 const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2); 00292 00307 ogg_int64_t opus_granule_sample(const OpusHead *_head,ogg_int64_t _gp) 00308 OP_ARG_NONNULL(1); 00309 00324 OP_WARN_UNUSED_RESULT int opus_tags_parse(OpusTags *_tags, 00325 const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2); 00326 00331 void opus_tags_init(OpusTags *_tags) OP_ARG_NONNULL(1); 00332 00344 int opus_tags_add(OpusTags *_tags,const char *_tag,const char *_value) 00345 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) OP_ARG_NONNULL(3); 00346 00357 int opus_tags_add_comment(OpusTags *_tags,const char *_comment) 00358 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); 00359 00375 const char *opus_tags_query(const OpusTags *_tags,const char *_tag,int _count) 00376 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); 00377 00385 int opus_tags_query_count(const OpusTags *_tags,const char *_tag) 00386 OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); 00387 00393 void opus_tags_clear(OpusTags *_tags) OP_ARG_NONNULL(1); 00394 00398 00410 00411 /*These are the raw numbers used to define the request codes. 00412 They should not be used directly.*/ 00413 #define OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST (6464) 00414 #define OP_HTTP_PROXY_HOST_REQUEST (6528) 00415 #define OP_HTTP_PROXY_PORT_REQUEST (6592) 00416 #define OP_HTTP_PROXY_USER_REQUEST (6656) 00417 #define OP_HTTP_PROXY_PASS_REQUEST (6720) 00418 00419 #define OP_URL_OPT(_request) ((_request)+(char *)0) 00420 00421 /*These macros trigger compilation errors or warnings if the wrong types are 00422 provided to one of the URL options.*/ 00423 #define OP_CHECK_INT(_x) ((void)((_x)==(opus_int32)0),(opus_int32)(_x)) 00424 #define OP_CHECK_CONST_CHAR_PTR(_x) ((_x)+((_x)-(const char *)(_x))) 00425 00432 #define OP_SSL_SKIP_CERTIFICATE_CHECK(_b) \ 00433 OP_URL_OPT(OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST),OP_CHECK_INT(_b) 00434 00443 #define OP_HTTP_PROXY_HOST(_host) \ 00444 OP_URL_OPT(OP_HTTP_PROXY_HOST_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host) 00445 00456 #define OP_HTTP_PROXY_PORT(_port) \ 00457 OP_URL_OPT(OP_HTTP_PROXY_PORT_REQUEST),OP_CHECK_INT(_port) 00458 00469 #define OP_HTTP_PROXY_USER(_user) \ 00470 OP_URL_OPT(OP_HTTP_PROXY_USER_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host) 00471 00482 #define OP_HTTP_PROXY_PASS(_pass) \ 00483 OP_URL_OPT(OP_HTTP_PROXY_PASS_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host) 00484 00487 00499 00500 typedef struct OpusFileCallbacks OpusFileCallbacks; 00501 00510 typedef int (*op_read_func)(void *_stream,unsigned char *_ptr,int _nbytes); 00511 00521 typedef int (*op_seek_func)(void *_stream,opus_int64 _offset,int _whence); 00522 00525 typedef opus_int64 (*op_tell_func)(void *_stream); 00526 00531 typedef int (*op_close_func)(void *_stream); 00532 00542 struct OpusFileCallbacks{ 00545 op_read_func read; 00548 op_seek_func seek; 00551 op_tell_func tell; 00554 op_close_func close; 00555 }; 00556 00570 OP_WARN_UNUSED_RESULT void *op_fopen(OpusFileCallbacks *_cb, 00571 const char *_path,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) 00572 OP_ARG_NONNULL(3); 00573 00587 OP_WARN_UNUSED_RESULT void *op_fdopen(OpusFileCallbacks *_cb, 00588 int _fd,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(3); 00589 00605 OP_WARN_UNUSED_RESULT void *op_freopen(OpusFileCallbacks *_cb, 00606 const char *_path,const char *_mode,void *_stream) OP_ARG_NONNULL(1) 00607 OP_ARG_NONNULL(2) OP_ARG_NONNULL(3) OP_ARG_NONNULL(4); 00608 00619 OP_WARN_UNUSED_RESULT void *op_mem_stream_create(OpusFileCallbacks *_cb, 00620 const unsigned char *_data,size_t _size) OP_ARG_NONNULL(1); 00621 00640 OP_WARN_UNUSED_RESULT void *op_url_stream_vcreate(OpusFileCallbacks *_cb, 00641 const char *_url,va_list _ap) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); 00642 00657 OP_WARN_UNUSED_RESULT void *op_url_stream_create(OpusFileCallbacks *_cb, 00658 const char *_url,...) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2); 00659 00662 00672 00703 int op_test(OpusHead *_head, 00704 const unsigned char *_initial_data,size_t _initial_bytes); 00705 00715 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_file(const char *_path,int *_error) 00716 OP_ARG_NONNULL(1); 00717 00726 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_memory(const unsigned char *_data, 00727 size_t _size,int *_error); 00728 00750 OP_WARN_UNUSED_RESULT OggOpusFile *op_vopen_url(const char *_url, 00751 int *_error,va_list _ap) OP_ARG_NONNULL(1); 00752 00769 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_url(const char *_url, 00770 int *_error,...) OP_ARG_NONNULL(1); 00771 00845 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_callbacks(void *_source, 00846 const OpusFileCallbacks *_cb,const unsigned char *_initial_data, 00847 size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2); 00848 00859 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_file(const char *_path,int *_error) 00860 OP_ARG_NONNULL(1); 00861 00871 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_memory(const unsigned char *_data, 00872 size_t _size,int *_error); 00873 00897 OP_WARN_UNUSED_RESULT OggOpusFile *op_vtest_url(const char *_url, 00898 int *_error,va_list _ap) OP_ARG_NONNULL(1); 00899 00916 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_url(const char *_url, 00917 int *_error,...) OP_ARG_NONNULL(1); 00918 00978 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_callbacks(void *_source, 00979 const OpusFileCallbacks *_cb,const unsigned char *_initial_data, 00980 size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2); 00981 01008 int op_test_open(OggOpusFile *_of) OP_ARG_NONNULL(1); 01009 01012 void op_free(OggOpusFile *_of); 01013 01016 01034 01049 int op_seekable(OggOpusFile *_of) OP_ARG_NONNULL(1); 01050 01059 int op_link_count(OggOpusFile *_of) OP_ARG_NONNULL(1); 01060 01074 opus_uint32 op_serialno(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); 01075 01091 int op_channel_count(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); 01092 01109 opus_int64 op_raw_total(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); 01110 01127 ogg_int64_t op_pcm_total(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); 01128 01143 const OpusHead *op_head(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); 01144 01161 const OpusTags *op_tags(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); 01162 01178 int op_current_link(OggOpusFile *_of) OP_ARG_NONNULL(1); 01179 01191 opus_int32 op_bitrate(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1); 01192 01204 opus_int32 op_bitrate_instant(OggOpusFile *_of) OP_ARG_NONNULL(1); 01205 01210 opus_int64 op_raw_tell(OggOpusFile *_of) OP_ARG_NONNULL(1); 01211 01219 ogg_int64_t op_pcm_tell(OggOpusFile *_of) OP_ARG_NONNULL(1); 01220 01223 01251 01265 int op_raw_seek(OggOpusFile *_of,opus_int64 _byte_offset) OP_ARG_NONNULL(1); 01266 01281 int op_pcm_seek(OggOpusFile *_of,ogg_int64_t _pcm_offset) OP_ARG_NONNULL(1); 01282 01285 01325 01406 OP_WARN_UNUSED_RESULT int op_read(OggOpusFile *_of, 01407 opus_int16 *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1); 01408 01487 OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of, 01488 float *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1); 01489 01548 OP_WARN_UNUSED_RESULT int op_read_stereo(OggOpusFile *_of, 01549 opus_int16 *_pcm,int _buf_size) OP_ARG_NONNULL(1); 01550 01609 OP_WARN_UNUSED_RESULT int op_read_float_stereo(OggOpusFile *_of, 01610 float *_pcm,int _buf_size) OP_ARG_NONNULL(1); 01611 01614 01615 # if OP_GNUC_PREREQ(4,0) 01616 # pragma GCC visibility pop 01617 # endif 01618 01619 # if defined(__cplusplus) 01620 } 01621 # endif 01622 01623 #endif