opusfile  0.4
Stand-alone decoder library for .opus files.
 All Data Structures Functions Variables Typedefs Groups
opusfile.h
1 /********************************************************************
2  * *
3  * THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7  * *
8  * THE libopusfile SOURCE CODE IS (C) COPYRIGHT 1994-2012 *
9  * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
10  * *
11  ********************************************************************
12 
13  function: stdio-based convenience library for opening/seeking/decoding
14  last mod: $Id: vorbisfile.h 17182 2010-04-29 03:48:32Z xiphmont $
15 
16  ********************************************************************/
17 #if !defined(_opusfile_h)
18 # define _opusfile_h (1)
19 
102 # if defined(__cplusplus)
103 extern "C" {
104 # endif
105 
106 # include <stdarg.h>
107 # include <stdio.h>
108 # include <ogg/ogg.h>
109 # include <opus_multistream.h>
110 
111 /*Enable special features for gcc and gcc-compatible compilers.*/
112 # if !defined(OP_GNUC_PREREQ)
113 # if defined(__GNUC__)&&defined(__GNUC_MINOR__)
114 # define OP_GNUC_PREREQ(_maj,_min) \
115  ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
116 # else
117 # define OP_GNUC_PREREQ(_maj,_min) 0
118 # endif
119 # endif
120 
121 # if OP_GNUC_PREREQ(4,0)
122 # pragma GCC visibility push(default)
123 # endif
124 
125 typedef struct OpusHead OpusHead;
126 typedef struct OpusTags OpusTags;
127 typedef struct OpusPictureTag OpusPictureTag;
128 typedef struct OggOpusFile OggOpusFile;
129 
130 /*Warning attributes for libopusfile functions.*/
131 # if OP_GNUC_PREREQ(3,4)
132 # define OP_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
133 # else
134 # define OP_WARN_UNUSED_RESULT
135 # endif
136 # if OP_GNUC_PREREQ(3,4)
137 # define OP_ARG_NONNULL(_x) __attribute__((__nonnull__(_x)))
138 # else
139 # define OP_ARG_NONNULL(_x)
140 # endif
141 
151 
153 #define OP_FALSE (-1)
154 /*Currently not used externally.*/
155 #define OP_EOF (-2)
156 
158 #define OP_HOLE (-3)
159 
161 #define OP_EREAD (-128)
162 
165 #define OP_EFAULT (-129)
166 
168 #define OP_EIMPL (-130)
169 
170 #define OP_EINVAL (-131)
171 
175 #define OP_ENOTFORMAT (-132)
176 
178 #define OP_EBADHEADER (-133)
179 
180 #define OP_EVERSION (-134)
181 /*Currently not used at all.*/
182 #define OP_ENOTAUDIO (-135)
183 
186 #define OP_EBADPACKET (-136)
187 
190 #define OP_EBADLINK (-137)
191 
192 #define OP_ENOSEEK (-138)
193 
194 #define OP_EBADTIMESTAMP (-139)
195 
198 
201 
203 #define OPUS_CHANNEL_COUNT_MAX (255)
204 
208 struct OpusHead{
218  int version;
223  unsigned pre_skip;
230  opus_uint32 input_sample_rate;
261 };
262 
293 struct OpusTags{
299  int comments;
302  char *vendor;
303 };
304 
307 
310 #define OP_PIC_FORMAT_UNKNOWN (-1)
311 
312 #define OP_PIC_FORMAT_URL (0)
313 
314 #define OP_PIC_FORMAT_JPEG (1)
315 
316 #define OP_PIC_FORMAT_PNG (2)
317 
318 #define OP_PIC_FORMAT_GIF (3)
319 
350  opus_int32 type;
357  char *mime_type;
359  char *description;
361  opus_uint32 width;
363  opus_uint32 height;
366  opus_uint32 depth;
369  opus_uint32 colors;
371  opus_uint32 data_length;
373  unsigned char *data;
383  int format;
384 };
385 
394 
420 OP_WARN_UNUSED_RESULT int opus_head_parse(OpusHead *_head,
421  const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2);
422 
437 ogg_int64_t opus_granule_sample(const OpusHead *_head,ogg_int64_t _gp)
438  OP_ARG_NONNULL(1);
439 
454 OP_WARN_UNUSED_RESULT int opus_tags_parse(OpusTags *_tags,
455  const unsigned char *_data,size_t _len) OP_ARG_NONNULL(2);
456 
461 void opus_tags_init(OpusTags *_tags) OP_ARG_NONNULL(1);
462 
474 int opus_tags_add(OpusTags *_tags,const char *_tag,const char *_value)
475  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2) OP_ARG_NONNULL(3);
476 
487 int opus_tags_add_comment(OpusTags *_tags,const char *_comment)
488  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
489 
505 const char *opus_tags_query(const OpusTags *_tags,const char *_tag,int _count)
506  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
507 
515 int opus_tags_query_count(const OpusTags *_tags,const char *_tag)
516  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
517 
533 int opus_tags_get_track_gain(const OpusTags *_tags,int *_gain_q8)
534  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
535 
541 void opus_tags_clear(OpusTags *_tags) OP_ARG_NONNULL(1);
542 
572 int opus_picture_tag_parse(OpusPictureTag *_pic,const char *_tag)
573  OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
574 
579 void opus_picture_tag_init(OpusPictureTag *_pic) OP_ARG_NONNULL(1);
580 
586 void opus_picture_tag_clear(OpusPictureTag *_pic) OP_ARG_NONNULL(1);
587 
591 
603 
604 /*These are the raw numbers used to define the request codes.
605  They should not be used directly.*/
606 #define OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST (6464)
607 #define OP_HTTP_PROXY_HOST_REQUEST (6528)
608 #define OP_HTTP_PROXY_PORT_REQUEST (6592)
609 #define OP_HTTP_PROXY_USER_REQUEST (6656)
610 #define OP_HTTP_PROXY_PASS_REQUEST (6720)
611 
612 #define OP_URL_OPT(_request) ((_request)+(char *)0)
613 
614 /*These macros trigger compilation errors or warnings if the wrong types are
615  provided to one of the URL options.*/
616 #define OP_CHECK_INT(_x) ((void)((_x)==(opus_int32)0),(opus_int32)(_x))
617 #define OP_CHECK_CONST_CHAR_PTR(_x) ((_x)+((_x)-(const char *)(_x)))
618 
625 #define OP_SSL_SKIP_CERTIFICATE_CHECK(_b) \
626  OP_URL_OPT(OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST),OP_CHECK_INT(_b)
627 
636 #define OP_HTTP_PROXY_HOST(_host) \
637  OP_URL_OPT(OP_HTTP_PROXY_HOST_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host)
638 
649 #define OP_HTTP_PROXY_PORT(_port) \
650  OP_URL_OPT(OP_HTTP_PROXY_PORT_REQUEST),OP_CHECK_INT(_port)
651 
662 #define OP_HTTP_PROXY_USER(_user) \
663  OP_URL_OPT(OP_HTTP_PROXY_USER_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host)
664 
675 #define OP_HTTP_PROXY_PASS(_pass) \
676  OP_URL_OPT(OP_HTTP_PROXY_PASS_REQUEST),OP_CHECK_CONST_CHAR_PTR(_host)
677 
680 
692 
693 typedef struct OpusFileCallbacks OpusFileCallbacks;
694 
703 typedef int (*op_read_func)(void *_stream,unsigned char *_ptr,int _nbytes);
704 
714 typedef int (*op_seek_func)(void *_stream,opus_int64 _offset,int _whence);
715 
718 typedef opus_int64 (*op_tell_func)(void *_stream);
719 
724 typedef int (*op_close_func)(void *_stream);
725 
748 };
749 
767 OP_WARN_UNUSED_RESULT void *op_fopen(OpusFileCallbacks *_cb,
768  const char *_path,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2)
769  OP_ARG_NONNULL(3);
770 
784 OP_WARN_UNUSED_RESULT void *op_fdopen(OpusFileCallbacks *_cb,
785  int _fd,const char *_mode) OP_ARG_NONNULL(1) OP_ARG_NONNULL(3);
786 
806 OP_WARN_UNUSED_RESULT void *op_freopen(OpusFileCallbacks *_cb,
807  const char *_path,const char *_mode,void *_stream) OP_ARG_NONNULL(1)
808  OP_ARG_NONNULL(2) OP_ARG_NONNULL(3) OP_ARG_NONNULL(4);
809 
820 OP_WARN_UNUSED_RESULT void *op_mem_stream_create(OpusFileCallbacks *_cb,
821  const unsigned char *_data,size_t _size) OP_ARG_NONNULL(1);
822 
841 OP_WARN_UNUSED_RESULT void *op_url_stream_vcreate(OpusFileCallbacks *_cb,
842  const char *_url,va_list _ap) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
843 
858 OP_WARN_UNUSED_RESULT void *op_url_stream_create(OpusFileCallbacks *_cb,
859  const char *_url,...) OP_ARG_NONNULL(1) OP_ARG_NONNULL(2);
860 
863 
873 
904 int op_test(OpusHead *_head,
905  const unsigned char *_initial_data,size_t _initial_bytes);
906 
916 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_file(const char *_path,int *_error)
917  OP_ARG_NONNULL(1);
918 
927 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_memory(const unsigned char *_data,
928  size_t _size,int *_error);
929 
951 OP_WARN_UNUSED_RESULT OggOpusFile *op_vopen_url(const char *_url,
952  int *_error,va_list _ap) OP_ARG_NONNULL(1);
953 
970 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_url(const char *_url,
971  int *_error,...) OP_ARG_NONNULL(1);
972 
1050 OP_WARN_UNUSED_RESULT OggOpusFile *op_open_callbacks(void *_source,
1051  const OpusFileCallbacks *_cb,const unsigned char *_initial_data,
1052  size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2);
1053 
1064 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_file(const char *_path,int *_error)
1065  OP_ARG_NONNULL(1);
1066 
1076 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_memory(const unsigned char *_data,
1077  size_t _size,int *_error);
1078 
1102 OP_WARN_UNUSED_RESULT OggOpusFile *op_vtest_url(const char *_url,
1103  int *_error,va_list _ap) OP_ARG_NONNULL(1);
1104 
1121 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_url(const char *_url,
1122  int *_error,...) OP_ARG_NONNULL(1);
1123 
1187 OP_WARN_UNUSED_RESULT OggOpusFile *op_test_callbacks(void *_source,
1188  const OpusFileCallbacks *_cb,const unsigned char *_initial_data,
1189  size_t _initial_bytes,int *_error) OP_ARG_NONNULL(2);
1190 
1217 int op_test_open(OggOpusFile *_of) OP_ARG_NONNULL(1);
1218 
1221 void op_free(OggOpusFile *_of);
1222 
1225 
1243 
1258 int op_seekable(OggOpusFile *_of) OP_ARG_NONNULL(1);
1259 
1268 int op_link_count(OggOpusFile *_of) OP_ARG_NONNULL(1);
1269 
1283 opus_uint32 op_serialno(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1284 
1300 int op_channel_count(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1301 
1318 opus_int64 op_raw_total(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1319 
1336 ogg_int64_t op_pcm_total(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1337 
1352 const OpusHead *op_head(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1353 
1370 const OpusTags *op_tags(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1371 
1387 int op_current_link(OggOpusFile *_of) OP_ARG_NONNULL(1);
1388 
1400 opus_int32 op_bitrate(OggOpusFile *_of,int _li) OP_ARG_NONNULL(1);
1401 
1413 opus_int32 op_bitrate_instant(OggOpusFile *_of) OP_ARG_NONNULL(1);
1414 
1419 opus_int64 op_raw_tell(OggOpusFile *_of) OP_ARG_NONNULL(1);
1420 
1428 ogg_int64_t op_pcm_tell(OggOpusFile *_of) OP_ARG_NONNULL(1);
1429 
1432 
1460 
1474 int op_raw_seek(OggOpusFile *_of,opus_int64 _byte_offset) OP_ARG_NONNULL(1);
1475 
1490 int op_pcm_seek(OggOpusFile *_of,ogg_int64_t _pcm_offset) OP_ARG_NONNULL(1);
1491 
1494 
1535 
1539 #define OP_HEADER_GAIN (0)
1540 
1543 #define OP_TRACK_GAIN (3008)
1544 
1547 #define OP_ABSOLUTE_GAIN (3009)
1548 
1566 int op_set_gain_offset(OggOpusFile *_of,
1567  int _gain_type,opus_int32 _gain_offset_q8);
1568 
1649 OP_WARN_UNUSED_RESULT int op_read(OggOpusFile *_of,
1650  opus_int16 *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1);
1651 
1730 OP_WARN_UNUSED_RESULT int op_read_float(OggOpusFile *_of,
1731  float *_pcm,int _buf_size,int *_li) OP_ARG_NONNULL(1);
1732 
1791 OP_WARN_UNUSED_RESULT int op_read_stereo(OggOpusFile *_of,
1792  opus_int16 *_pcm,int _buf_size) OP_ARG_NONNULL(1);
1793 
1852 OP_WARN_UNUSED_RESULT int op_read_float_stereo(OggOpusFile *_of,
1853  float *_pcm,int _buf_size) OP_ARG_NONNULL(1);
1854 
1857 
1858 # if OP_GNUC_PREREQ(4,0)
1859 # pragma GCC visibility pop
1860 # endif
1861 
1862 # if defined(__cplusplus)
1863 }
1864 # endif
1865 
1866 #endif